types.ts 1.5 KB

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