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-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
|
|
|
|
|
|
|
export interface Action {
|
|
|
|
name: string;
|
|
|
|
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;
|
2020-02-05 22:47:10 +04:00
|
|
|
commitToHistory?: (
|
|
|
|
appState: AppState,
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
) => boolean;
|
2020-01-12 02:22:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ActionsManagerInterface {
|
|
|
|
actions: {
|
|
|
|
[keyProp: string]: Action;
|
|
|
|
};
|
|
|
|
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-02-05 22:47:10 +04:00
|
|
|
renderAction: (name: string) => React.ReactElement | null;
|
2020-01-12 02:22:03 +04:00
|
|
|
}
|