2020-01-12 02:22:03 +04: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-12 02:22:03 +04:00
|
|
|
|
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 15:05:16 +05:30
|
|
|
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-12 02:22:03 +04:00
|
|
|
|
|
|
|
type ActionFn = (
|
|
|
|
elements: readonly ExcalidrawElement[],
|
2020-08-08 22:35:34 +02:00
|
|
|
appState: Readonly<AppState>,
|
2020-01-24 12:04:54 +02: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-12 02:22:03 +04:00
|
|
|
|
2020-10-19 10:53:37 +02:00
|
|
|
export type UpdaterFn = (res: ActionResult) => void;
|
2020-01-12 07:10:15 -08:00
|
|
|
export type ActionFilterFn = (action: Action) => void;
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-25 14:13:59 +01:00
|
|
|
export type ActionName =
|
2021-01-28 00:41:17 +05:30
|
|
|
| "copy"
|
|
|
|
| "cut"
|
|
|
|
| "paste"
|
|
|
|
| "copyAsPng"
|
|
|
|
| "copyAsSvg"
|
2020-03-25 14:13:59 +01:00
|
|
|
| "sendBackward"
|
|
|
|
| "bringForward"
|
|
|
|
| "sendToBack"
|
|
|
|
| "bringToFront"
|
|
|
|
| "copyStyles"
|
|
|
|
| "selectAll"
|
|
|
|
| "pasteStyles"
|
2021-01-28 00:41:17 +05:30
|
|
|
| "gridMode"
|
|
|
|
| "zenMode"
|
|
|
|
| "stats"
|
2020-03-25 14:13:59 +01:00
|
|
|
| "changeStrokeColor"
|
|
|
|
| "changeBackgroundColor"
|
|
|
|
| "changeFillStyle"
|
|
|
|
| "changeStrokeWidth"
|
2021-05-09 16:42:10 +01:00
|
|
|
| "changeStrokeShape"
|
2020-03-25 14:13:59 +01:00
|
|
|
| "changeSloppiness"
|
2020-05-14 17:04:33 +02:00
|
|
|
| "changeStrokeStyle"
|
2020-12-08 15:02:55 +00: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 15:31:12 +01:00
|
|
|
| "changeExportScale"
|
2021-05-28 02:10:33 +05:30
|
|
|
| "saveToActiveFile"
|
2021-05-29 02:56:25 +05:30
|
|
|
| "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 14:54:35 -06:00
|
|
|
| "zoomToSelection"
|
2020-04-06 03:17:13 +05:30
|
|
|
| "changeFontFamily"
|
2020-04-08 21:00:27 +01:00
|
|
|
| "changeTextAlign"
|
2020-04-07 16:12:10 +05:30
|
|
|
| "toggleFullScreen"
|
2020-05-26 13:07:46 -07:00
|
|
|
| "toggleShortcuts"
|
|
|
|
| "group"
|
2020-06-19 11:36:49 +01:00
|
|
|
| "ungroup"
|
2020-07-10 02:20:23 -07:00
|
|
|
| "goToCollaborator"
|
2020-08-15 00:59:43 +09:00
|
|
|
| "addToLibrary"
|
2020-10-31 11:40:06 +01:00
|
|
|
| "changeSharpness"
|
|
|
|
| "alignTop"
|
|
|
|
| "alignBottom"
|
|
|
|
| "alignLeft"
|
|
|
|
| "alignRight"
|
|
|
|
| "alignVerticallyCentered"
|
2020-11-23 18:16:23 +00:00
|
|
|
| "alignHorizontallyCentered"
|
|
|
|
| "distributeHorizontally"
|
2021-02-02 02:26:42 +05:30
|
|
|
| "distributeVertically"
|
2021-03-26 11:45:08 -04:00
|
|
|
| "flipHorizontal"
|
|
|
|
| "flipVertical"
|
2021-02-24 19:52:17 +05:30
|
|
|
| "viewMode"
|
2021-05-08 15:17:30 +05:30
|
|
|
| "exportWithDarkMode"
|
|
|
|
| "toggleTheme";
|
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-12 02:22:03 +04: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-12 02:22:03 +04:00
|
|
|
perform: ActionFn;
|
|
|
|
keyPriority?: number;
|
|
|
|
keyTest?: (
|
2021-04-13 01:29:25 +05:30
|
|
|
event: React.KeyboardEvent | KeyboardEvent,
|
2020-02-01 15:49:18 +04:00
|
|
|
appState: AppState,
|
|
|
|
elements: readonly ExcalidrawElement[],
|
2020-01-12 02:22:03 +04:00
|
|
|
) => boolean;
|
|
|
|
contextItemLabel?: string;
|
2020-07-09 22:32:27 +02:00
|
|
|
contextItemPredicate?: (
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
appState: AppState,
|
|
|
|
) => boolean;
|
2021-01-29 23:38:37 +05:30
|
|
|
checked?: (appState: Readonly<AppState>) => boolean;
|
2020-01-12 02:22:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ActionsManagerInterface {
|
2020-12-08 15:02:55 +00:00
|
|
|
actions: Record<ActionName, Action>;
|
2020-01-12 02:22:03 +04:00
|
|
|
registerAction: (action: Action) => void;
|
2021-04-13 01:29:25 +05:30
|
|
|
handleKeyDown: (event: React.KeyboardEvent | KeyboardEvent) => boolean;
|
2020-03-25 14:13:59 +01:00
|
|
|
renderAction: (name: ActionName) => React.ReactElement | null;
|
2021-05-25 21:37:14 +02:00
|
|
|
executeAction: (action: Action) => void;
|
2020-01-12 02:22:03 +04:00
|
|
|
}
|