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