types.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React from "react";
  2. import { ExcalidrawElement } from "../element/types";
  3. import { AppState } from "../types";
  4. import { TFunction } from "i18next";
  5. export type ActionResult = {
  6. elements?: ExcalidrawElement[];
  7. appState?: AppState;
  8. };
  9. type ActionFn = (
  10. elements: readonly ExcalidrawElement[],
  11. appState: AppState,
  12. formData: any,
  13. ) => ActionResult;
  14. export type UpdaterFn = (res: ActionResult) => void;
  15. export type ActionFilterFn = (action: Action) => void;
  16. export interface Action {
  17. name: string;
  18. PanelComponent?: React.FC<{
  19. elements: readonly ExcalidrawElement[];
  20. appState: AppState;
  21. updateData: (formData: any) => void;
  22. t: TFunction;
  23. }>;
  24. perform: ActionFn;
  25. keyPriority?: number;
  26. keyTest?: (
  27. event: KeyboardEvent,
  28. elements?: readonly ExcalidrawElement[],
  29. appState?: AppState,
  30. ) => boolean;
  31. contextItemLabel?: string;
  32. contextMenuOrder?: number;
  33. }
  34. export interface ActionsManagerInterface {
  35. actions: {
  36. [keyProp: string]: Action;
  37. };
  38. registerAction: (action: Action) => void;
  39. handleKeyDown: (
  40. event: KeyboardEvent,
  41. elements: readonly ExcalidrawElement[],
  42. appState: AppState,
  43. ) => ActionResult | {};
  44. getContextMenuItems: (
  45. elements: readonly ExcalidrawElement[],
  46. appState: AppState,
  47. updater: UpdaterFn,
  48. actionFilter: ActionFilterFn,
  49. ) => { label: string; action: () => void }[];
  50. renderAction: (
  51. name: string,
  52. elements: readonly ExcalidrawElement[],
  53. appState: AppState,
  54. updater: UpdaterFn,
  55. t: TFunction,
  56. ) => React.ReactElement | null;
  57. }