2020-01-11 22:22:03 +00:00
|
|
|
import React from "react";
|
|
|
|
import { ExcalidrawElement } from "../element/types";
|
2021-10-21 20:05:48 +00:00
|
|
|
import {
|
|
|
|
AppClassProperties,
|
|
|
|
AppState,
|
|
|
|
ExcalidrawProps,
|
|
|
|
BinaryFiles,
|
2024-03-28 16:16:32 +00:00
|
|
|
UIAppState,
|
2021-10-21 20:05:48 +00:00
|
|
|
} from "../types";
|
2023-03-04 18:21:57 +00:00
|
|
|
import { MarkOptional } from "../utility-types";
|
2020-01-11 22:22:03 +00:00
|
|
|
|
2024-03-28 16:16:32 +00:00
|
|
|
export type ActionSource =
|
|
|
|
| "ui"
|
|
|
|
| "keyboard"
|
|
|
|
| "contextMenu"
|
|
|
|
| "api"
|
|
|
|
| "commandPalette";
|
2022-03-28 12:46:40 +00:00
|
|
|
|
2020-07-07 11:53:44 +00:00
|
|
|
/** if false, the action should be prevented */
|
|
|
|
export type ActionResult =
|
|
|
|
| {
|
|
|
|
elements?: readonly ExcalidrawElement[] | null;
|
2021-04-04 09:35:16 +00:00
|
|
|
appState?: MarkOptional<
|
|
|
|
AppState,
|
|
|
|
"offsetTop" | "offsetLeft" | "width" | "height"
|
|
|
|
> | null;
|
2021-10-21 20:05:48 +00:00
|
|
|
files?: BinaryFiles | null;
|
2020-07-07 11:53:44 +00:00
|
|
|
commitToHistory: boolean;
|
|
|
|
syncHistory?: boolean;
|
2021-10-21 20:05:48 +00:00
|
|
|
replaceFiles?: boolean;
|
2020-07-07 11:53:44 +00:00
|
|
|
}
|
|
|
|
| false;
|
2020-01-11 22:22:03 +00:00
|
|
|
|
|
|
|
type ActionFn = (
|
|
|
|
elements: readonly ExcalidrawElement[],
|
2020-08-08 20:35:34 +00:00
|
|
|
appState: Readonly<AppState>,
|
2020-01-24 10:04:54 +00:00
|
|
|
formData: any,
|
2021-10-21 20:05:48 +00:00
|
|
|
app: AppClassProperties,
|
2020-10-19 08:53:37 +00:00
|
|
|
) => ActionResult | Promise<ActionResult>;
|
2020-01-11 22:22:03 +00:00
|
|
|
|
2020-10-19 08:53:37 +00:00
|
|
|
export type UpdaterFn = (res: ActionResult) => void;
|
2020-01-12 15:10:15 +00:00
|
|
|
export type ActionFilterFn = (action: Action) => void;
|
2020-01-11 22:22:03 +00:00
|
|
|
|
2020-03-25 13:13:59 +00:00
|
|
|
export type ActionName =
|
2021-01-27 19:11:17 +00:00
|
|
|
| "copy"
|
|
|
|
| "cut"
|
|
|
|
| "paste"
|
|
|
|
| "copyAsPng"
|
|
|
|
| "copyAsSvg"
|
2022-04-05 21:11:00 +00:00
|
|
|
| "copyText"
|
2020-03-25 13:13:59 +00:00
|
|
|
| "sendBackward"
|
|
|
|
| "bringForward"
|
|
|
|
| "sendToBack"
|
|
|
|
| "bringToFront"
|
|
|
|
| "copyStyles"
|
|
|
|
| "selectAll"
|
|
|
|
| "pasteStyles"
|
2021-01-27 19:11:17 +00:00
|
|
|
| "gridMode"
|
|
|
|
| "zenMode"
|
2023-09-28 14:28:08 +00:00
|
|
|
| "objectsSnapMode"
|
2021-01-27 19:11:17 +00:00
|
|
|
| "stats"
|
2020-03-25 13:13:59 +00:00
|
|
|
| "changeStrokeColor"
|
|
|
|
| "changeBackgroundColor"
|
|
|
|
| "changeFillStyle"
|
|
|
|
| "changeStrokeWidth"
|
2021-05-09 15:42:10 +00:00
|
|
|
| "changeStrokeShape"
|
2020-03-25 13:13:59 +00:00
|
|
|
| "changeSloppiness"
|
2020-05-14 15:04:33 +00:00
|
|
|
| "changeStrokeStyle"
|
2020-12-08 15:02:55 +00:00
|
|
|
| "changeArrowhead"
|
2020-03-25 13:13:59 +00:00
|
|
|
| "changeOpacity"
|
|
|
|
| "changeFontSize"
|
|
|
|
| "toggleCanvasMenu"
|
|
|
|
| "toggleEditMenu"
|
|
|
|
| "undo"
|
|
|
|
| "redo"
|
|
|
|
| "finalize"
|
2020-12-01 13:00:13 +00:00
|
|
|
| "changeProjectName"
|
2020-03-25 13:13:59 +00:00
|
|
|
| "changeExportBackground"
|
2020-10-13 12:47:07 +00:00
|
|
|
| "changeExportEmbedScene"
|
2021-05-30 14:31:12 +00:00
|
|
|
| "changeExportScale"
|
2021-05-27 20:40:33 +00:00
|
|
|
| "saveToActiveFile"
|
2021-05-28 21:26:25 +00:00
|
|
|
| "saveFileToDisk"
|
2020-03-25 13:13:59 +00:00
|
|
|
| "loadScene"
|
|
|
|
| "duplicateSelection"
|
|
|
|
| "deleteSelectedElements"
|
|
|
|
| "changeViewBackgroundColor"
|
|
|
|
| "clearCanvas"
|
|
|
|
| "zoomIn"
|
|
|
|
| "zoomOut"
|
|
|
|
| "resetZoom"
|
2020-04-18 13:50:30 +00:00
|
|
|
| "zoomToFit"
|
2023-06-29 10:36:38 +00:00
|
|
|
| "zoomToFitSelection"
|
|
|
|
| "zoomToFitSelectionInViewport"
|
2020-04-05 21:47:13 +00:00
|
|
|
| "changeFontFamily"
|
2020-04-08 20:00:27 +00:00
|
|
|
| "changeTextAlign"
|
2022-03-02 14:36:07 +00:00
|
|
|
| "changeVerticalAlign"
|
2020-04-07 10:42:10 +00:00
|
|
|
| "toggleFullScreen"
|
2020-05-26 20:07:46 +00:00
|
|
|
| "toggleShortcuts"
|
|
|
|
| "group"
|
2020-06-19 10:36:49 +00:00
|
|
|
| "ungroup"
|
2020-07-10 09:20:23 +00:00
|
|
|
| "goToCollaborator"
|
2020-08-14 15:59:43 +00:00
|
|
|
| "addToLibrary"
|
2022-12-08 15:48:49 +00:00
|
|
|
| "changeRoundness"
|
2020-10-31 10:40:06 +00:00
|
|
|
| "alignTop"
|
|
|
|
| "alignBottom"
|
|
|
|
| "alignLeft"
|
|
|
|
| "alignRight"
|
|
|
|
| "alignVerticallyCentered"
|
2020-11-23 18:16:23 +00:00
|
|
|
| "alignHorizontallyCentered"
|
|
|
|
| "distributeHorizontally"
|
2021-02-01 20:56:42 +00:00
|
|
|
| "distributeVertically"
|
2021-03-26 15:45:08 +00:00
|
|
|
| "flipHorizontal"
|
|
|
|
| "flipVertical"
|
2021-02-24 14:22:17 +00:00
|
|
|
| "viewMode"
|
2021-05-08 09:47:30 +00:00
|
|
|
| "exportWithDarkMode"
|
2022-01-12 14:21:36 +00:00
|
|
|
| "toggleTheme"
|
|
|
|
| "increaseFontSize"
|
2022-02-01 14:41:24 +00:00
|
|
|
| "decreaseFontSize"
|
2022-02-03 15:04:59 +00:00
|
|
|
| "unbindText"
|
2022-03-11 14:23:42 +00:00
|
|
|
| "hyperlink"
|
2022-04-07 11:43:29 +00:00
|
|
|
| "bindText"
|
2023-05-13 20:52:03 +00:00
|
|
|
| "unlockAllElements"
|
|
|
|
| "toggleElementLock"
|
2023-01-23 15:12:28 +00:00
|
|
|
| "toggleLinearEditor"
|
|
|
|
| "toggleEraserTool"
|
2023-03-03 12:10:42 +00:00
|
|
|
| "toggleHandTool"
|
2023-06-14 16:42:01 +00:00
|
|
|
| "selectAllElementsInFrame"
|
|
|
|
| "removeAllElementsFromFrame"
|
2023-07-10 15:13:44 +00:00
|
|
|
| "updateFrameRendering"
|
2023-06-14 16:42:01 +00:00
|
|
|
| "setFrameAsActiveTool"
|
2023-07-24 14:51:53 +00:00
|
|
|
| "setEmbeddableAsActiveTool"
|
2023-06-14 16:42:01 +00:00
|
|
|
| "createContainerFromText"
|
2024-03-28 16:16:32 +00:00
|
|
|
| "wrapTextInContainer"
|
|
|
|
| "commandPalette";
|
2020-03-25 13:13:59 +00:00
|
|
|
|
2021-07-15 16:48:03 +00:00
|
|
|
export type PanelComponentProps = {
|
|
|
|
elements: readonly ExcalidrawElement[];
|
|
|
|
appState: AppState;
|
2023-12-18 20:14:30 +00:00
|
|
|
updateData: <T = any>(formData?: T) => void;
|
2021-07-15 16:48:03 +00:00
|
|
|
appProps: ExcalidrawProps;
|
2022-06-15 13:35:57 +00:00
|
|
|
data?: Record<string, any>;
|
2023-07-16 23:09:44 +00:00
|
|
|
app: AppClassProperties;
|
2021-07-15 16:48:03 +00:00
|
|
|
};
|
|
|
|
|
2020-01-11 22:22:03 +00:00
|
|
|
export interface Action {
|
2020-03-25 13:13:59 +00:00
|
|
|
name: ActionName;
|
2024-03-28 16:16:32 +00:00
|
|
|
label:
|
|
|
|
| string
|
|
|
|
| ((
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
appState: Readonly<AppState>,
|
|
|
|
app: AppClassProperties,
|
|
|
|
) => string);
|
|
|
|
keywords?: string[];
|
|
|
|
icon?:
|
|
|
|
| React.ReactNode
|
|
|
|
| ((
|
|
|
|
appState: UIAppState,
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
) => React.ReactNode);
|
2023-01-06 13:32:55 +00:00
|
|
|
PanelComponent?: React.FC<PanelComponentProps>;
|
2020-01-11 22:22:03 +00:00
|
|
|
perform: ActionFn;
|
|
|
|
keyPriority?: number;
|
|
|
|
keyTest?: (
|
2021-04-12 19:59:25 +00:00
|
|
|
event: React.KeyboardEvent | KeyboardEvent,
|
2020-02-01 11:49:18 +00:00
|
|
|
appState: AppState,
|
|
|
|
elements: readonly ExcalidrawElement[],
|
2023-07-16 23:09:44 +00:00
|
|
|
app: AppClassProperties,
|
2020-01-11 22:22:03 +00:00
|
|
|
) => boolean;
|
2023-01-06 13:32:55 +00:00
|
|
|
predicate?: (
|
2020-07-09 20:32:27 +00:00
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
appState: AppState,
|
2022-12-21 11:47:09 +00:00
|
|
|
appProps: ExcalidrawProps,
|
|
|
|
app: AppClassProperties,
|
2020-07-09 20:32:27 +00:00
|
|
|
) => boolean;
|
2021-01-29 18:08:37 +00:00
|
|
|
checked?: (appState: Readonly<AppState>) => boolean;
|
2022-03-28 12:46:40 +00:00
|
|
|
trackEvent:
|
|
|
|
| false
|
|
|
|
| {
|
|
|
|
category:
|
|
|
|
| "toolbar"
|
|
|
|
| "element"
|
|
|
|
| "canvas"
|
|
|
|
| "export"
|
|
|
|
| "history"
|
|
|
|
| "menu"
|
|
|
|
| "collab"
|
|
|
|
| "hyperlink";
|
|
|
|
action?: string;
|
|
|
|
predicate?: (
|
|
|
|
appState: Readonly<AppState>,
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
value: any,
|
|
|
|
) => boolean;
|
|
|
|
};
|
2022-12-11 21:57:03 +00:00
|
|
|
/** if set to `true`, allow action to be performed in viewMode.
|
|
|
|
* Defaults to `false` */
|
|
|
|
viewMode?: boolean;
|
2020-01-11 22:22:03 +00:00
|
|
|
}
|