2020-01-12 02:22:03 +04:00
|
|
|
import React from "react";
|
|
|
|
import { ExcalidrawElement } from "../element/types";
|
|
|
|
import { AppState } from "../types";
|
2020-01-21 01:14:10 +02:00
|
|
|
import { TFunction } from "i18next";
|
2020-01-12 02:22:03 +04:00
|
|
|
|
|
|
|
export type ActionResult = {
|
|
|
|
elements?: ExcalidrawElement[];
|
|
|
|
appState?: AppState;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
export interface Action {
|
|
|
|
name: string;
|
|
|
|
PanelComponent?: React.FC<{
|
|
|
|
elements: readonly ExcalidrawElement[];
|
|
|
|
appState: AppState;
|
|
|
|
updateData: (formData: any) => void;
|
2020-01-21 01:14:10 +02:00
|
|
|
t: TFunction;
|
2020-01-12 02:22:03 +04:00
|
|
|
}>;
|
|
|
|
perform: ActionFn;
|
|
|
|
keyPriority?: number;
|
|
|
|
keyTest?: (
|
|
|
|
event: KeyboardEvent,
|
|
|
|
elements?: readonly ExcalidrawElement[],
|
2020-01-24 12:04:54 +02:00
|
|
|
appState?: AppState,
|
2020-01-12 02:22:03 +04:00
|
|
|
) => boolean;
|
|
|
|
contextItemLabel?: string;
|
|
|
|
contextMenuOrder?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ActionsManagerInterface {
|
|
|
|
actions: {
|
|
|
|
[keyProp: string]: Action;
|
|
|
|
};
|
|
|
|
registerAction: (action: Action) => void;
|
|
|
|
handleKeyDown: (
|
|
|
|
event: KeyboardEvent,
|
|
|
|
elements: readonly ExcalidrawElement[],
|
2020-01-24 12:04:54 +02:00
|
|
|
appState: AppState,
|
2020-01-27 22:14:35 +01:00
|
|
|
) => ActionResult | null;
|
2020-01-12 02:22:03 +04:00
|
|
|
getContextMenuItems: (
|
|
|
|
elements: readonly ExcalidrawElement[],
|
|
|
|
appState: AppState,
|
2020-01-12 07:10:15 -08:00
|
|
|
updater: UpdaterFn,
|
2020-01-24 12:04:54 +02:00
|
|
|
actionFilter: ActionFilterFn,
|
2020-01-12 02:22:03 +04:00
|
|
|
) => { label: string; action: () => void }[];
|
|
|
|
renderAction: (
|
|
|
|
name: string,
|
2020-01-15 20:42:02 +05:00
|
|
|
elements: readonly ExcalidrawElement[],
|
2020-01-12 02:22:03 +04:00
|
|
|
appState: AppState,
|
2020-01-21 01:14:10 +02:00
|
|
|
updater: UpdaterFn,
|
2020-01-24 12:04:54 +02:00
|
|
|
t: TFunction,
|
2020-01-12 02:22:03 +04:00
|
|
|
) => React.ReactElement | null;
|
|
|
|
}
|