2020-01-12 02:22:03 +04:00
|
|
|
import React from "react";
|
|
|
|
import { ExcalidrawElement } from "../element/types";
|
|
|
|
import { AppState } from "../types";
|
|
|
|
|
|
|
|
export type ActionResult = {
|
2020-02-07 23:46:19 +01:00
|
|
|
elements?: readonly ExcalidrawElement[] | null;
|
|
|
|
appState?: AppState | null;
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: boolean;
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
type ActionFn = (
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
appState: AppState,
|
2020-01-24 12:04:54 +02:00
|
|
|
formData: any,
|
2020-01-12 02:22:03 +04:00
|
|
|
) => ActionResult;
|
|
|
|
|
2020-02-07 23:46:19 +01:00
|
|
|
export type UpdaterFn = (res: ActionResult, commitToHistory?: boolean) => 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 =
|
|
|
|
| "sendBackward"
|
|
|
|
| "bringForward"
|
|
|
|
| "sendToBack"
|
|
|
|
| "bringToFront"
|
|
|
|
| "copyStyles"
|
|
|
|
| "selectAll"
|
|
|
|
| "pasteStyles"
|
|
|
|
| "changeStrokeColor"
|
|
|
|
| "changeBackgroundColor"
|
|
|
|
| "changeFillStyle"
|
|
|
|
| "changeStrokeWidth"
|
|
|
|
| "changeSloppiness"
|
|
|
|
| "changeOpacity"
|
|
|
|
| "changeFontSize"
|
|
|
|
| "toggleCanvasMenu"
|
|
|
|
| "toggleEditMenu"
|
|
|
|
| "undo"
|
|
|
|
| "redo"
|
|
|
|
| "finalize"
|
|
|
|
| "changeProjectName"
|
|
|
|
| "changeExportBackground"
|
|
|
|
| "saveScene"
|
|
|
|
| "loadScene"
|
|
|
|
| "duplicateSelection"
|
|
|
|
| "deleteSelectedElements"
|
|
|
|
| "changeViewBackgroundColor"
|
|
|
|
| "clearCanvas"
|
|
|
|
| "zoomIn"
|
|
|
|
| "zoomOut"
|
|
|
|
| "resetZoom"
|
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"
|
|
|
|
| "toggleShortcuts";
|
2020-03-25 14:13:59 +01:00
|
|
|
|
2020-01-12 02:22:03 +04:00
|
|
|
export interface Action {
|
2020-03-25 14:13:59 +01:00
|
|
|
name: ActionName;
|
2020-01-12 02:22:03 +04:00
|
|
|
PanelComponent?: React.FC<{
|
|
|
|
elements: readonly ExcalidrawElement[];
|
|
|
|
appState: AppState;
|
2020-03-01 14:39:03 -05:00
|
|
|
updateData: (formData?: any) => void;
|
2020-01-12 02:22:03 +04:00
|
|
|
}>;
|
|
|
|
perform: ActionFn;
|
|
|
|
keyPriority?: number;
|
|
|
|
keyTest?: (
|
|
|
|
event: 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;
|
|
|
|
contextMenuOrder?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ActionsManagerInterface {
|
|
|
|
actions: {
|
2020-03-25 14:13:59 +01:00
|
|
|
[actionName in ActionName]: Action;
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
registerAction: (action: Action) => void;
|
2020-02-07 23:46:19 +01:00
|
|
|
handleKeyDown: (event: KeyboardEvent) => boolean;
|
2020-01-12 02:22:03 +04:00
|
|
|
getContextMenuItems: (
|
2020-01-24 12:04:54 +02:00
|
|
|
actionFilter: ActionFilterFn,
|
2020-01-12 02:22:03 +04:00
|
|
|
) => { label: string; action: () => void }[];
|
2020-03-25 14:13:59 +01:00
|
|
|
renderAction: (name: ActionName) => React.ReactElement | null;
|
2020-01-12 02:22:03 +04:00
|
|
|
}
|