123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- import type React from "react";
- import type {
- ExcalidrawElement,
- OrderedExcalidrawElement,
- } from "../element/types";
- import type {
- AppClassProperties,
- AppState,
- ExcalidrawProps,
- BinaryFiles,
- UIAppState,
- } from "../types";
- import type { MarkOptional } from "../utility-types";
- import type { StoreActionType } from "../store";
- export type ActionSource =
- | "ui"
- | "keyboard"
- | "contextMenu"
- | "api"
- | "commandPalette";
- /** if false, the action should be prevented */
- export type ActionResult =
- | {
- elements?: readonly ExcalidrawElement[] | null;
- appState?: MarkOptional<
- AppState,
- "offsetTop" | "offsetLeft" | "width" | "height"
- > | null;
- files?: BinaryFiles | null;
- storeAction: StoreActionType;
- replaceFiles?: boolean;
- }
- | false;
- type ActionFn = (
- elements: readonly OrderedExcalidrawElement[],
- appState: Readonly<AppState>,
- formData: any,
- app: AppClassProperties,
- ) => ActionResult | Promise<ActionResult>;
- export type UpdaterFn = (res: ActionResult) => void;
- export type ActionFilterFn = (action: Action) => void;
- export type ActionName =
- | "copy"
- | "cut"
- | "paste"
- | "copyAsPng"
- | "copyAsSvg"
- | "copyText"
- | "sendBackward"
- | "bringForward"
- | "sendToBack"
- | "bringToFront"
- | "copyStyles"
- | "selectAll"
- | "pasteStyles"
- | "gridMode"
- | "zenMode"
- | "objectsSnapMode"
- | "stats"
- | "changeStrokeColor"
- | "changeBackgroundColor"
- | "changeFillStyle"
- | "changeStrokeWidth"
- | "changeStrokeShape"
- | "changeSloppiness"
- | "changeStrokeStyle"
- | "changeArrowhead"
- | "changeOpacity"
- | "changeFontSize"
- | "toggleCanvasMenu"
- | "toggleEditMenu"
- | "undo"
- | "redo"
- | "finalize"
- | "changeProjectName"
- | "changeExportBackground"
- | "changeExportEmbedScene"
- | "changeExportScale"
- | "saveToActiveFile"
- | "saveFileToDisk"
- | "loadScene"
- | "duplicateSelection"
- | "deleteSelectedElements"
- | "changeViewBackgroundColor"
- | "clearCanvas"
- | "zoomIn"
- | "zoomOut"
- | "resetZoom"
- | "zoomToFit"
- | "zoomToFitSelection"
- | "zoomToFitSelectionInViewport"
- | "changeFontFamily"
- | "changeTextAlign"
- | "changeVerticalAlign"
- | "toggleFullScreen"
- | "toggleShortcuts"
- | "group"
- | "ungroup"
- | "goToCollaborator"
- | "addToLibrary"
- | "changeRoundness"
- | "alignTop"
- | "alignBottom"
- | "alignLeft"
- | "alignRight"
- | "alignVerticallyCentered"
- | "alignHorizontallyCentered"
- | "distributeHorizontally"
- | "distributeVertically"
- | "flipHorizontal"
- | "flipVertical"
- | "viewMode"
- | "exportWithDarkMode"
- | "toggleTheme"
- | "increaseFontSize"
- | "decreaseFontSize"
- | "unbindText"
- | "hyperlink"
- | "bindText"
- | "unlockAllElements"
- | "toggleElementLock"
- | "toggleLinearEditor"
- | "toggleEraserTool"
- | "toggleHandTool"
- | "selectAllElementsInFrame"
- | "removeAllElementsFromFrame"
- | "updateFrameRendering"
- | "setFrameAsActiveTool"
- | "setEmbeddableAsActiveTool"
- | "createContainerFromText"
- | "wrapTextInContainer"
- | "commandPalette";
- export type PanelComponentProps = {
- elements: readonly ExcalidrawElement[];
- appState: AppState;
- updateData: <T = any>(formData?: T) => void;
- appProps: ExcalidrawProps;
- data?: Record<string, any>;
- app: AppClassProperties;
- };
- export interface Action {
- name: ActionName;
- label:
- | string
- | ((
- elements: readonly ExcalidrawElement[],
- appState: Readonly<AppState>,
- app: AppClassProperties,
- ) => string);
- keywords?: string[];
- icon?:
- | React.ReactNode
- | ((
- appState: UIAppState,
- elements: readonly ExcalidrawElement[],
- ) => React.ReactNode);
- PanelComponent?: React.FC<PanelComponentProps>;
- perform: ActionFn;
- keyPriority?: number;
- keyTest?: (
- event: React.KeyboardEvent | KeyboardEvent,
- appState: AppState,
- elements: readonly ExcalidrawElement[],
- app: AppClassProperties,
- ) => boolean;
- predicate?: (
- elements: readonly ExcalidrawElement[],
- appState: AppState,
- appProps: ExcalidrawProps,
- app: AppClassProperties,
- ) => boolean;
- checked?: (appState: Readonly<AppState>) => boolean;
- trackEvent:
- | false
- | {
- category:
- | "toolbar"
- | "element"
- | "canvas"
- | "export"
- | "history"
- | "menu"
- | "collab"
- | "hyperlink";
- action?: string;
- predicate?: (
- appState: Readonly<AppState>,
- elements: readonly ExcalidrawElement[],
- value: any,
- ) => boolean;
- };
- /** if set to `true`, allow action to be performed in viewMode.
- * Defaults to `false` */
- viewMode?: boolean;
- }
|