@myoc/common 0.19.502-ff5a131b0 → 0.19.503

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/dev/index.js +313 -21
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +3 -3
  4. package/dist/types/common/debug.d.ts +21 -0
  5. package/dist/types/common/src/appEventBus.d.ts +27 -0
  6. package/dist/types/common/src/colors.d.ts +13 -13
  7. package/dist/types/common/src/constants.d.ts +3 -0
  8. package/dist/types/common/src/index.d.ts +3 -0
  9. package/dist/types/common/src/utils.d.ts +4 -7
  10. package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
  11. package/dist/types/element/src/Scene.d.ts +2 -0
  12. package/dist/types/element/src/arrowheads.d.ts +3 -0
  13. package/dist/types/element/src/arrows/focus.d.ts +27 -0
  14. package/dist/types/element/src/arrows/helpers.d.ts +5 -0
  15. package/dist/types/element/src/binding.d.ts +13 -8
  16. package/dist/types/element/src/bounds.d.ts +1 -1
  17. package/dist/types/element/src/collision.d.ts +4 -3
  18. package/dist/types/element/src/distribute.d.ts +2 -1
  19. package/dist/types/element/src/elbowArrow.d.ts +2 -0
  20. package/dist/types/element/src/index.d.ts +4 -0
  21. package/dist/types/element/src/linearElementEditor.d.ts +5 -0
  22. package/dist/types/element/src/mutateElement.d.ts +2 -0
  23. package/dist/types/element/src/selection.d.ts +6 -2
  24. package/dist/types/element/src/shapes.d.ts +2 -22
  25. package/dist/types/element/src/textElement.d.ts +1 -1
  26. package/dist/types/element/src/textWrapping.d.ts +26 -0
  27. package/dist/types/element/src/types.d.ts +5 -2
  28. package/dist/types/element/src/utils.d.ts +5 -3
  29. package/dist/types/element/src/zindex.d.ts +1 -1
  30. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +38 -35
  31. package/dist/types/excalidraw/actions/actionBoundText.d.ts +27 -25
  32. package/dist/types/excalidraw/actions/actionCanvas.d.ts +143 -132
  33. package/dist/types/excalidraw/actions/actionClipboard.d.ts +26 -24
  34. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +13 -12
  35. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +42 -37
  36. package/dist/types/excalidraw/actions/actionElementLink.d.ts +9 -12
  37. package/dist/types/excalidraw/actions/actionElementLock.d.ts +26 -24
  38. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +13 -12
  39. package/dist/types/excalidraw/actions/actionExport.d.ts +112 -405
  40. package/dist/types/excalidraw/actions/actionFrame.d.ts +52 -48
  41. package/dist/types/excalidraw/actions/actionGroup.d.ts +29 -27
  42. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +15 -12
  43. package/dist/types/excalidraw/actions/actionLink.d.ts +13 -12
  44. package/dist/types/excalidraw/actions/actionMenu.d.ts +9 -12
  45. package/dist/types/excalidraw/actions/actionProperties.d.ts +29 -27
  46. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +14 -13
  47. package/dist/types/excalidraw/actions/actionStyles.d.ts +13 -11
  48. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
  49. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +181 -0
  50. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +13 -12
  51. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +181 -0
  52. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +13 -12
  53. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +9 -12
  54. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +13 -12
  55. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +13 -12
  56. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +13 -12
  57. package/dist/types/excalidraw/actions/index.d.ts +2 -0
  58. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  59. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  60. package/dist/types/excalidraw/appState.d.ts +34 -32
  61. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  62. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  63. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  64. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  65. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  66. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  67. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  68. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  69. package/dist/types/excalidraw/clipboard.d.ts +8 -9
  70. package/dist/types/excalidraw/components/App.d.ts +55 -13
  71. package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
  72. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -1
  73. package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
  74. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  75. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -1
  76. package/dist/types/excalidraw/components/Range.d.ts +10 -4
  77. package/dist/types/excalidraw/components/Toast.d.ts +8 -4
  78. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +1 -0
  79. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +30 -17
  80. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +3 -2
  81. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +11 -13
  82. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCheckbox.d.ts +5 -0
  83. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSub.d.ts +23 -0
  84. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubContent.d.ts +8 -0
  85. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubTrigger.d.ts +12 -0
  86. package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
  87. package/dist/types/excalidraw/components/dropdownMenu/dropdownMenuUtils.d.ts +2 -0
  88. package/dist/types/excalidraw/components/icons.d.ts +23 -9
  89. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +17 -0
  90. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +23 -13
  91. package/dist/types/excalidraw/data/blob.d.ts +163 -162
  92. package/dist/types/excalidraw/data/filesystem.d.ts +3 -5
  93. package/dist/types/excalidraw/data/index.d.ts +2 -3
  94. package/dist/types/excalidraw/data/json.d.ts +92 -83
  95. package/dist/types/excalidraw/data/resave.d.ts +7 -2
  96. package/dist/types/excalidraw/hooks/useAppStateValue.d.ts +29 -0
  97. package/dist/types/excalidraw/index.d.ts +25 -3
  98. package/dist/types/excalidraw/textAutoResizeHandle.d.ts +15 -0
  99. package/dist/types/excalidraw/types.d.ts +93 -16
  100. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +5 -1
  101. package/dist/types/math/src/point.d.ts +7 -2
  102. package/dist/types/math/src/types.d.ts +25 -1
  103. package/package.json +1 -1
  104. package/dist/types/excalidraw/charts.d.ts +0 -27
@@ -1,76 +1,37 @@
1
- import type { ExcalidrawElement } from "@excalidraw/element/types";
1
+ import type { ExcalidrawElement, NonDeleted } from "@excalidraw/element/types";
2
+ import type { MaybePromise } from "@excalidraw/common/utility-types";
2
3
  import type { AppState, BinaryFiles, LibraryItems } from "../types";
3
4
  import type { ImportedDataState, ImportedLibraryData } from "./types";
5
+ export type JSONExportData = {
6
+ elements: readonly NonDeleted<ExcalidrawElement>[];
7
+ appState: AppState;
8
+ files: BinaryFiles;
9
+ };
4
10
  export declare const serializeAsJSON: (elements: readonly ExcalidrawElement[], appState: Partial<AppState>, files: BinaryFiles, type: "local" | "database") => string;
5
- export declare const saveAsJSON: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles,
6
- /** filename */
7
- name?: string) => Promise<{
8
- fileHandle: import("browser-fs-access").FileSystemHandle | null;
11
+ export declare const saveAsJSON: ({ data, filename, fileHandle, }: {
12
+ data: MaybePromise<JSONExportData>;
13
+ filename: string;
14
+ fileHandle: AppState["fileHandle"];
15
+ }) => Promise<{
16
+ fileHandle: FileSystemFileHandle | null;
9
17
  }>;
10
18
  export declare const loadFromJSON: (localAppState: AppState, localElements: readonly ExcalidrawElement[] | null) => Promise<{
11
19
  elements: import("@excalidraw/element/types").OrderedExcalidrawElement[];
12
20
  appState: {
13
- viewBackgroundColor: string;
14
- theme: import("@excalidraw/element/types").Theme;
15
- frameRendering: {
16
- enabled: boolean;
17
- name: boolean;
18
- outline: boolean;
19
- clip: boolean;
20
- };
21
- name: string | null;
22
- zoom: import("../types").Zoom;
23
- scrollX: number;
24
- scrollY: number;
25
21
  viewModeEnabled: boolean;
26
- openDialog: null | {
27
- name: "imageExport" | "help" | "jsonExport";
28
- } | {
29
- name: "commandPalette";
30
- } | {
31
- name: "settings";
32
- } | {
33
- name: "elementLinkSelector";
34
- sourceElementId: ExcalidrawElement["id"];
35
- };
36
- editingGroupId: import("@excalidraw/element/types").GroupId | null;
37
- selectedElementIds: Readonly<{
38
- [id: string]: true;
39
- }>;
40
- frameToHighlight: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawFrameLikeElement> | null;
41
- activeEmbeddable: {
42
- element: import("@excalidraw/element/types").NonDeletedExcalidrawElement;
43
- state: "hover" | "active";
44
- } | null;
45
- selectionElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
46
- selectedGroupIds: {
47
- [groupId: string]: boolean;
48
- };
49
- selectedLinearElement: import("@excalidraw/element").LinearElementEditor | null;
50
- multiElement: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawLinearElement> | null;
51
- newElement: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawNonSelectionElement> | null;
52
- isBindingEnabled: boolean;
53
- suggestedBinding: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawBindableElement> | null;
54
- isRotating: boolean;
55
- elementsToHighlight: import("@excalidraw/element/types").NonDeleted<ExcalidrawElement>[] | null;
56
- collaborators: Map<import("../types").SocketId, import("../types").Collaborator>;
57
- snapLines: readonly import("../snapping").SnapLine[];
58
22
  zenModeEnabled: boolean;
59
- editingTextElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
60
- isCropping: boolean;
61
- croppingElementId: ExcalidrawElement["id"] | null;
62
- searchMatches: Readonly<{
63
- focusedId: ExcalidrawElement["id"] | null;
64
- matches: readonly import("../types").SearchMatch[];
65
- }> | null;
66
- activeLockedId: string | null;
67
- hoveredElementIds: Readonly<{
68
- [id: string]: true;
69
- }>;
70
- shouldCacheIgnoreZoom: boolean;
71
- exportScale: number;
72
- bindMode: import("@excalidraw/element/types").BindMode;
23
+ gridModeEnabled: boolean;
24
+ objectsSnapModeEnabled: boolean;
25
+ theme: import("@excalidraw/element/types").Theme;
26
+ name: string | null;
27
+ wheelZoomsOnDefault?: boolean | undefined;
28
+ currentItemArrowType: "sharp" | "round" | "elbow";
73
29
  gridSize: number;
30
+ activeTool: {
31
+ lastActiveTool: import("../types").ActiveTool | null;
32
+ locked: boolean;
33
+ fromSelection: boolean;
34
+ } & import("../types").ActiveTool;
74
35
  contextMenu: {
75
36
  items: import("../components/ContextMenu").ContextMenuItems;
76
37
  top: number;
@@ -81,7 +42,6 @@ export declare const loadFromJSON: (localAppState: AppState, localElements: read
81
42
  myocSimplifiedMode: boolean;
82
43
  dontResizeLimitMBs: number;
83
44
  hideMainMenus: boolean;
84
- wheelZoomsOnDefault?: boolean | undefined;
85
45
  arrangeConfiguration: {
86
46
  algorithm: import("@excalidraw/element/types").ArrangeAlgorithms;
87
47
  gap: number;
@@ -91,14 +51,32 @@ export declare const loadFromJSON: (localAppState: AppState, localElements: read
91
51
  metric: import("../types").NormaliseMetric;
92
52
  };
93
53
  errorMessage: React.ReactNode;
54
+ activeEmbeddable: {
55
+ element: import("@excalidraw/element/types").NonDeletedExcalidrawElement;
56
+ state: "hover" | "active";
57
+ } | null;
58
+ newElement: NonDeleted<import("@excalidraw/element/types").ExcalidrawNonSelectionElement> | null;
94
59
  resizingElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
95
- startBoundElement: import("@excalidraw/element/types").NonDeleted<import("@excalidraw/element/types").ExcalidrawBindableElement> | null;
60
+ multiElement: NonDeleted<import("@excalidraw/element/types").ExcalidrawLinearElement> | null;
61
+ selectionElement: import("@excalidraw/element/types").NonDeletedExcalidrawElement | null;
62
+ isBindingEnabled: boolean;
63
+ bindingPreference: "enabled" | "disabled";
64
+ isMidpointSnappingEnabled: boolean;
65
+ startBoundElement: NonDeleted<import("@excalidraw/element/types").ExcalidrawBindableElement> | null;
66
+ suggestedBinding: {
67
+ element: NonDeleted<import("@excalidraw/element/types").ExcalidrawBindableElement>;
68
+ midPoint?: import("@excalidraw/math").GlobalPoint;
69
+ } | null;
70
+ frameToHighlight: NonDeleted<import("@excalidraw/element/types").ExcalidrawFrameLikeElement> | null;
71
+ frameRendering: {
72
+ enabled: boolean;
73
+ name: boolean;
74
+ outline: boolean;
75
+ clip: boolean;
76
+ };
96
77
  editingFrame: string | null;
97
- activeTool: {
98
- lastActiveTool: import("../types").ActiveTool | null;
99
- locked: boolean;
100
- fromSelection: boolean;
101
- } & import("../types").ActiveTool;
78
+ elementsToHighlight: NonDeleted<ExcalidrawElement>[] | null;
79
+ editingTextElement: import("@excalidraw/element/types").ExcalidrawTextElement | null;
102
80
  preferredSelectionTool: {
103
81
  type: "selection" | "lasso";
104
82
  initialized: boolean;
@@ -108,6 +86,7 @@ export declare const loadFromJSON: (localAppState: AppState, localElements: read
108
86
  exportBackground: boolean;
109
87
  exportEmbedScene: boolean;
110
88
  exportWithDarkMode: boolean;
89
+ exportScale: number;
111
90
  currentItemStrokeColor: string;
112
91
  currentItemBackgroundColor: string;
113
92
  currentItemFillStyle: ExcalidrawElement["fillStyle"];
@@ -122,53 +101,83 @@ export declare const loadFromJSON: (localAppState: AppState, localElements: read
122
101
  currentItemEndArrowhead: import("@excalidraw/element/types").Arrowhead | null;
123
102
  currentHoveredFontFamily: import("@excalidraw/element/types").FontFamilyValues | null;
124
103
  currentItemRoundness: import("@excalidraw/element/types").StrokeRoundness;
125
- currentItemArrowType: "sharp" | "round" | "elbow";
104
+ viewBackgroundColor: string;
105
+ scrollX: number;
106
+ scrollY: number;
126
107
  cursorButton: "up" | "down";
127
108
  scrolledOutside: boolean;
128
109
  isResizing: boolean;
110
+ isRotating: boolean;
111
+ zoom: import("../types").Zoom;
129
112
  openMenu: "canvas" | null;
130
113
  openPopup: "canvasBackground" | "elementBackground" | "elementStroke" | "fontFamily" | "compactTextProperties" | "compactStrokeStyles" | "compactOtherProperties" | "compactArrowProperties" | null;
131
114
  openSidebar: {
132
115
  name: import("../types").SidebarName;
133
116
  tab?: import("../types").SidebarTabName;
134
117
  } | null;
118
+ openDialog: null | {
119
+ name: "imageExport" | "help" | "jsonExport";
120
+ } | {
121
+ name: "commandPalette";
122
+ } | {
123
+ name: "settings";
124
+ } | {
125
+ name: "elementLinkSelector";
126
+ sourceElementId: ExcalidrawElement["id"];
127
+ } | {
128
+ name: "charts";
129
+ data: import("../charts").Spreadsheet;
130
+ rawText: string;
131
+ };
135
132
  defaultSidebarDockedPreference: boolean;
136
133
  lastPointerDownWith: import("@excalidraw/element/types").PointerType;
134
+ selectedElementIds: Readonly<{
135
+ [id: string]: true;
136
+ }>;
137
+ hoveredElementIds: Readonly<{
138
+ [id: string]: true;
139
+ }>;
137
140
  previousSelectedElementIds: {
138
141
  [id: string]: true;
139
142
  };
140
143
  selectedElementsAreBeingDragged: boolean;
144
+ shouldCacheIgnoreZoom: boolean;
141
145
  toast: {
142
- message: string;
146
+ message: React.ReactNode;
143
147
  closable?: boolean;
144
148
  duration?: number;
145
149
  } | null;
146
150
  gridStep: number;
147
- gridModeEnabled: boolean;
148
- fileHandle: import("browser-fs-access").FileSystemHandle | null;
151
+ selectedGroupIds: {
152
+ [groupId: string]: boolean;
153
+ };
154
+ editingGroupId: import("@excalidraw/element/types").GroupId | null;
155
+ fileHandle: FileSystemFileHandle | null;
156
+ collaborators: Map<import("../types").SocketId, import("../types").Collaborator>;
149
157
  stats: {
150
158
  open: boolean;
151
159
  panels: number;
152
160
  };
153
- currentChartType: import("@excalidraw/element/types").ChartType;
154
- pasteDialog: {
155
- shown: false;
156
- data: null;
157
- } | {
158
- shown: true;
159
- data: import("../charts").Spreadsheet;
160
- };
161
161
  showHyperlinkPopup: false | "info" | "editor";
162
+ selectedLinearElement: import("@excalidraw/element").LinearElementEditor | null;
163
+ snapLines: readonly import("../snapping").SnapLine[];
162
164
  originSnapOffset: {
163
165
  x: number;
164
166
  y: number;
165
167
  } | null;
166
- objectsSnapModeEnabled: boolean;
167
168
  userToFollow: import("../types").UserToFollow | null;
168
169
  followedBy: Set<import("../types").SocketId>;
170
+ isCropping: boolean;
171
+ croppingElementId: ExcalidrawElement["id"] | null;
172
+ searchMatches: Readonly<{
173
+ focusedId: ExcalidrawElement["id"] | null;
174
+ matches: readonly import("../types").SearchMatch[];
175
+ }> | null;
176
+ activeLockedId: string | null;
169
177
  lockedMultiSelections: {
170
178
  [groupId: string]: true;
171
179
  };
180
+ bindMode: import("@excalidraw/element/types").BindMode;
172
181
  };
173
182
  files: BinaryFiles;
174
183
  }>;
@@ -1,5 +1,10 @@
1
+ import type { MaybePromise } from "@excalidraw/common/utility-types";
1
2
  import type { ExcalidrawElement } from "@excalidraw/element/types";
2
3
  import type { AppState, BinaryFiles } from "../types";
3
- export declare const resaveAsImageWithScene: (elements: readonly ExcalidrawElement[], appState: AppState, files: BinaryFiles, name: string) => Promise<{
4
- fileHandle: import("browser-fs-access").FileSystemHandle;
4
+ export declare const resaveAsImageWithScene: (data: MaybePromise<{
5
+ elements: readonly ExcalidrawElement[];
6
+ appState: AppState;
7
+ files: BinaryFiles;
8
+ }>, fileHandle: FileSystemFileHandle, filename: string) => Promise<{
9
+ fileHandle: FileSystemFileHandle;
5
10
  }>;
@@ -0,0 +1,29 @@
1
+ import type { AppState } from "../types";
2
+ /**
3
+ * Subscribes to specific appState changes. The component re-renders
4
+ * only when the specified prop(s) change — not on every appState update.
5
+ *
6
+ * Works both inside and outside the <Excalidraw> tree, as long as
7
+ * ExcalidrawAPIContext.Provider is an ancestor (automatically provided
8
+ * inside <Excalidraw>, or manually by the host app).
9
+ *
10
+ * Returns the narrowed value depending on prop form:
11
+ * - `keyof AppState` → `AppState[K]`
12
+ * - `(keyof AppState)[]` → whole `AppState`
13
+ * - selector function → selector's return type `T`
14
+ *
15
+ * If excalidrawAPI is not ready yet (host apps), hook is rerendered with latest
16
+ * value once available.
17
+ */
18
+ export declare function useAppStateValue<K extends keyof AppState>(prop: K, _internal?: boolean): AppState[K];
19
+ export declare function useAppStateValue(props: (keyof AppState)[], _internal?: boolean): AppState;
20
+ export declare function useAppStateValue<T>(selector: (appState: AppState) => T, _internal?: boolean): T;
21
+ /**
22
+ * Subscribes to specific appState changes without causing component rerenders.
23
+ *
24
+ * The callback is called on every matching change, but also on initial render
25
+ * so you can initialize your state.
26
+ */
27
+ export declare function useOnAppStateChange<K extends keyof AppState>(prop: K, callback: (value: AppState[K], appState: AppState) => void): undefined;
28
+ export declare function useOnAppStateChange(props: (keyof AppState)[], callback: (props: AppState, appState: AppState) => void): undefined;
29
+ export declare function useOnAppStateChange<T>(selector: (appState: AppState) => T, callback: (value: T, appState: AppState) => void): undefined;
@@ -3,10 +3,19 @@ import Footer from "./components/footer/FooterCenter";
3
3
  import LiveCollaborationTrigger from "./components/live-collaboration/LiveCollaborationTrigger";
4
4
  import MainMenu from "./components/main-menu/MainMenu";
5
5
  import WelcomeScreen from "./components/welcome-screen/WelcomeScreen";
6
+ import { useOnAppStateChange as _useOnAppStateChange } from "./hooks/useAppStateValue";
6
7
  import "./css/app.scss";
7
8
  import "./css/styles.scss";
8
9
  import "./fonts/fonts.css";
9
- import type { ExcalidrawProps } from "./types";
10
+ import type { AppState, ExcalidrawProps } from "./types";
11
+ /**
12
+ * Stateless provider that allows `useExcalidrawAPI()` (and hooks built
13
+ * on it, such as `useAppStateValue()` and `useOnAppStateChange()`) to work
14
+ * outside the <Excalidraw> component tree.
15
+ */
16
+ export declare const ExcalidrawAPIProvider: ({ children, }: {
17
+ children: React.ReactNode;
18
+ }) => import("react/jsx-runtime").JSX.Element;
10
19
  export declare const Excalidraw: React.MemoExoticComponent<(props: ExcalidrawProps) => import("react/jsx-runtime").JSX.Element>;
11
20
  export { getSceneVersion, hashElementsVersion, hashString, getNonDeletedElements, } from "@excalidraw/element";
12
21
  export { getTextFromElements } from "@excalidraw/element";
@@ -19,7 +28,7 @@ export { serializeAsJSON, serializeLibraryAsJSON } from "./data/json";
19
28
  export { loadFromBlob, loadSceneOrLibraryFromBlob, loadLibraryFromBlob, } from "./data/blob";
20
29
  export { mergeLibraryItems, getLibraryItemsHash } from "./data/library";
21
30
  export { isLinearElement } from "@excalidraw/element";
22
- export { FONT_FAMILY, THEME, MIME_TYPES, ROUNDNESS, DEFAULT_LASER_COLOR, UserIdleState, normalizeLink, sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, getFormFactor, } from "@excalidraw/common";
31
+ export { FONT_FAMILY, THEME, MIME_TYPES, ROUNDNESS, DEFAULT_LASER_COLOR, UserIdleState, normalizeLink, sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, getFormFactor, throttleRAF, } from "@excalidraw/common";
23
32
  export { mutateElement, newElementWith, bumpVersion, } from "@excalidraw/element";
24
33
  export { CaptureUpdateAction } from "@excalidraw/element";
25
34
  export { parseLibraryTokensFromUrl, useHandleLibrary } from "./data/library";
@@ -28,7 +37,7 @@ export { Button } from "./components/Button";
28
37
  export { Footer };
29
38
  export { MainMenu };
30
39
  export { Ellipsify } from "./components/Ellipsify";
31
- export { useEditorInterface, useStylesPanelMode } from "./components/App";
40
+ export { useEditorInterface, useStylesPanelMode, useExcalidrawAPI, ExcalidrawAPIContext, } from "./components/App";
32
41
  export { WelcomeScreen };
33
42
  export { LiveCollaborationTrigger };
34
43
  export { Stats } from "./components/Stats";
@@ -39,4 +48,17 @@ export { elementsOverlappingBBox, isElementInsideBBox, elementPartiallyOverlapsW
39
48
  export { DiagramToCodePlugin } from "./components/DiagramToCodePlugin/DiagramToCodePlugin";
40
49
  export { getDataURL } from "./data/blob";
41
50
  export { isElementLink } from "@excalidraw/element";
51
+ export { Fonts } from "./fonts/Fonts";
42
52
  export { setCustomTextMetricsProvider } from "@excalidraw/element";
53
+ export { CommandPalette } from "./components/CommandPalette/CommandPalette";
54
+ export { renderSpreadsheet, tryParseSpreadsheet, isSpreadsheetValidForChartType, } from "./charts";
55
+ /**
56
+ * hook that subscribes to specific appState prop(s)
57
+ *
58
+ * @param prop - appState prop(s) to subscribe to, or a selector function.
59
+ * NOTE `prop/selector` is memoized and will not change after initial render
60
+ */
61
+ export declare function useExcalidrawStateValue<K extends keyof AppState>(prop: K): AppState[K] | undefined;
62
+ export declare function useExcalidrawStateValue<T extends keyof AppState>(props: T[]): AppState | undefined;
63
+ export declare function useExcalidrawStateValue<T>(selector: (appState: AppState) => T): T | undefined;
64
+ export { _useOnAppStateChange as useOnExcalidrawStateChange };
@@ -0,0 +1,15 @@
1
+ import { type GlobalPoint } from "@excalidraw/math";
2
+ import type { EditorInterface } from "@excalidraw/common";
3
+ import type { ExcalidrawTextElement } from "@excalidraw/element/types";
4
+ export declare const getTextBoxPadding: (zoomValue: number) => number;
5
+ export declare const getTextAutoResizeHandle: (textElement: ExcalidrawTextElement, zoomValue: number, formFactor: EditorInterface["formFactor"]) => {
6
+ center: GlobalPoint | import("@excalidraw/math").LocalPoint;
7
+ start: GlobalPoint;
8
+ end: GlobalPoint;
9
+ hitboxWidth: number;
10
+ hitboxHeight: number;
11
+ } | null;
12
+ export declare const isPointHittingTextAutoResizeHandle: (point: Readonly<{
13
+ x: number;
14
+ y: number;
15
+ }>, textElement: ExcalidrawTextElement, zoomValue: number, formFactor: EditorInterface["formFactor"]) => boolean;
@@ -1,15 +1,15 @@
1
1
  import type { IMAGE_MIME_TYPES, UserIdleState, throttleRAF, MIME_TYPES, ColorTuple, EditorInterface } from "@excalidraw/common";
2
2
  import type { LinearElementEditor } from "@excalidraw/element";
3
3
  import type { MaybeTransformHandleType } from "@excalidraw/element";
4
- import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, ChartType, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement, ArrangeAlgorithms, BindMode } from "@excalidraw/element/types";
4
+ import type { PointerType, ExcalidrawLinearElement, NonDeletedExcalidrawElement, NonDeleted, TextAlign, ExcalidrawElement, GroupId, ExcalidrawBindableElement, Arrowhead, FontFamilyValues, FileId, Theme, StrokeRoundness, ExcalidrawEmbeddableElement, ExcalidrawMagicFrameElement, ExcalidrawFrameLikeElement, ExcalidrawElementType, ExcalidrawIframeLikeElement, OrderedExcalidrawElement, ExcalidrawNonSelectionElement, ArrangeAlgorithms, BindMode, ExcalidrawTextElement } from "@excalidraw/element/types";
5
5
  import type { Merge, MaybePromise, ValueOf, MakeBrand } from "@excalidraw/common/utility-types";
6
6
  import type { CaptureUpdateActionType, DurableIncrement, EphemeralIncrement } from "@excalidraw/element";
7
+ import type { GlobalPoint } from "@excalidraw/math";
7
8
  import type { Action } from "./actions/types";
8
9
  import type { Spreadsheet } from "./charts";
9
10
  import type { ClipboardData } from "./clipboard";
10
11
  import type App from "./components/App";
11
12
  import type Library from "./data/library";
12
- import type { FileSystemHandle } from "./data/filesystem";
13
13
  import type { ContextMenuItems } from "./components/ContextMenu";
14
14
  import type { SnapLine } from "./snapping";
15
15
  import type { ImportedDataState } from "./data/types";
@@ -17,6 +17,7 @@ import type { Language } from "./i18n";
17
17
  import type { isOverScrollBars } from "./scene/scrollbars";
18
18
  import type React from "react";
19
19
  import type { JSX } from "react";
20
+ export type { App };
20
21
  export type SocketId = string & {
21
22
  _brand: "SocketId";
22
23
  };
@@ -128,6 +129,7 @@ export type StaticCanvasAppState = Readonly<_CommonCanvasAppState & {
128
129
  croppingElementId: AppState["croppingElementId"];
129
130
  }>;
130
131
  export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
132
+ activeTool: AppState["activeTool"];
131
133
  activeEmbeddable: AppState["activeEmbeddable"];
132
134
  selectionElement: AppState["selectionElement"];
133
135
  selectedGroupIds: AppState["selectedGroupIds"];
@@ -135,6 +137,7 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
135
137
  multiElement: AppState["multiElement"];
136
138
  newElement: AppState["newElement"];
137
139
  isBindingEnabled: AppState["isBindingEnabled"];
140
+ isMidpointSnappingEnabled: AppState["isMidpointSnappingEnabled"];
138
141
  suggestedBinding: AppState["suggestedBinding"];
139
142
  isRotating: AppState["isRotating"];
140
143
  elementsToHighlight: AppState["elementsToHighlight"];
@@ -150,6 +153,7 @@ export type InteractiveCanvasAppState = Readonly<_CommonCanvasAppState & {
150
153
  frameRendering: AppState["frameRendering"];
151
154
  shouldCacheIgnoreZoom: AppState["shouldCacheIgnoreZoom"];
152
155
  exportScale: AppState["exportScale"];
156
+ currentItemArrowType: AppState["currentItemArrowType"];
153
157
  }>;
154
158
  export type ObservedAppState = ObservedStandaloneAppState & ObservedElementsAppState;
155
159
  export type ObservedStandaloneAppState = {
@@ -215,9 +219,20 @@ export interface AppState {
215
219
  * - set on pointer down, updated during pointer move
216
220
  */
217
221
  selectionElement: NonDeletedExcalidrawElement | null;
222
+ /**
223
+ * tracking current arrow binding editor state (takes into account
224
+ * `bindingPreference` and keyboard modifiers (ctrl/alt)
225
+ */
218
226
  isBindingEnabled: boolean;
227
+ /** user arrow binding preference */
228
+ bindingPreference: "enabled" | "disabled";
229
+ /** user preference whether arrow snap to midpoints while binding */
230
+ isMidpointSnappingEnabled: boolean;
219
231
  startBoundElement: NonDeleted<ExcalidrawBindableElement> | null;
220
- suggestedBinding: NonDeleted<ExcalidrawBindableElement> | null;
232
+ suggestedBinding: {
233
+ element: NonDeleted<ExcalidrawBindableElement>;
234
+ midPoint?: GlobalPoint;
235
+ } | null;
221
236
  frameToHighlight: NonDeleted<ExcalidrawFrameLikeElement> | null;
222
237
  frameRendering: {
223
238
  enabled: boolean;
@@ -230,7 +245,7 @@ export interface AppState {
230
245
  /**
231
246
  * set when a new text is created or when an existing text is being edited
232
247
  */
233
- editingTextElement: NonDeletedExcalidrawElement | null;
248
+ editingTextElement: ExcalidrawTextElement | null;
234
249
  activeTool: {
235
250
  /**
236
251
  * indicates a previous tool we should revert back to if we deselect the
@@ -289,6 +304,10 @@ export interface AppState {
289
304
  } | {
290
305
  name: "elementLinkSelector";
291
306
  sourceElementId: ExcalidrawElement["id"];
307
+ } | {
308
+ name: "charts";
309
+ data: Spreadsheet;
310
+ rawText: string;
292
311
  };
293
312
  /**
294
313
  * Reflects user preference for whether the default sidebar should be docked.
@@ -311,7 +330,7 @@ export interface AppState {
311
330
  selectedElementsAreBeingDragged: boolean;
312
331
  shouldCacheIgnoreZoom: boolean;
313
332
  toast: {
314
- message: string;
333
+ message: React.ReactNode;
315
334
  closable?: boolean;
316
335
  duration?: number;
317
336
  } | null;
@@ -333,21 +352,13 @@ export interface AppState {
333
352
  height: number;
334
353
  offsetTop: number;
335
354
  offsetLeft: number;
336
- fileHandle: FileSystemHandle | null;
355
+ fileHandle: FileSystemFileHandle | null;
337
356
  collaborators: Map<SocketId, Collaborator>;
338
357
  stats: {
339
358
  open: boolean;
340
359
  /** bitmap. Use `STATS_PANELS` bit values */
341
360
  panels: number;
342
361
  };
343
- currentChartType: ChartType;
344
- pasteDialog: {
345
- shown: false;
346
- data: null;
347
- } | {
348
- shown: true;
349
- data: Spreadsheet;
350
- };
351
362
  showHyperlinkPopup: false | "info" | "editor";
352
363
  selectedLinearElement: LinearElementEditor | null;
353
364
  snapLines: readonly SnapLine[];
@@ -434,11 +445,36 @@ export type OnUserFollowedPayload = {
434
445
  userToFollow: UserToFollow;
435
446
  action: "FOLLOW" | "UNFOLLOW";
436
447
  };
448
+ export type OnExportProgress = {
449
+ type: "progress";
450
+ message?: React.ReactNode;
451
+ /** 0-1 range */
452
+ progress?: number;
453
+ };
437
454
  export interface ExcalidrawProps {
438
455
  onChange?: (elements: readonly OrderedExcalidrawElement[], appState: AppState, files: BinaryFiles) => void;
456
+ /**
457
+ * note: only subscribes if the props.onIncrement is defined on initial render
458
+ */
439
459
  onIncrement?: (event: DurableIncrement | EphemeralIncrement) => void;
440
460
  initialData?: (() => MaybePromise<ExcalidrawInitialDataState | null>) | MaybePromise<ExcalidrawInitialDataState | null>;
441
- excalidrawAPI?: (api: ExcalidrawImperativeAPI) => void;
461
+ /**
462
+ * Invoked as soon as the Excalidraw API is available
463
+ * NOTE editor is not yet mounted, and state is not yet initialized
464
+ */
465
+ onExcalidrawAPI?: (api: ExcalidrawImperativeAPI | null) => void;
466
+ /**
467
+ * Invoked once the editor root is mounted.
468
+ */
469
+ onMount?: (payload: ExcalidrawMountPayload) => void;
470
+ /**
471
+ * Invoked when the editor root is unmounted.
472
+ */
473
+ onUnmount?: () => void;
474
+ /**
475
+ * Invoked once the initial scene is loaded.
476
+ */
477
+ onInitialize?: (api: ExcalidrawImperativeAPI) => void;
442
478
  isCollaborating?: boolean;
443
479
  onPointerUpdate?: (payload: {
444
480
  pointer: {
@@ -497,6 +533,29 @@ export interface ExcalidrawProps {
497
533
  strokeColorTopPicks?: ColorTuple;
498
534
  backgroundColorTopPicks?: ColorTuple;
499
535
  renderScrollbars?: boolean;
536
+ /**
537
+ * Called before exporting to a file.
538
+ *
539
+ * Allows the host app to intercept and delay saving until async operations
540
+ * (e.g., images are loaded) complete.
541
+ *
542
+ * If Promise/AsyncGenerator is returned, a progress toast will be shown
543
+ * until the operation completes. Generator can yield progress updates.
544
+ */
545
+ onExport?: (
546
+ /** type of export. Currently we only call for JSON exports or
547
+ * JSON-embedded PNG (which is also identified as `json` type here)*/
548
+ type: "json", data: {
549
+ elements: readonly ExcalidrawElement[];
550
+ appState: AppState;
551
+ files: BinaryFiles;
552
+ }, options: {
553
+ /** signal that gets aborted if user cancels the export (e.g. closes
554
+ * the native file picker dialog). In that case, you can either
555
+ * return immediately, or throw AbortError.
556
+ */
557
+ signal: AbortSignal;
558
+ }) => MaybePromise<void> | AsyncGenerator<OnExportProgress, void>;
500
559
  }
501
560
  export type SceneData = {
502
561
  elements?: ImportedDataState["elements"];
@@ -548,6 +607,8 @@ export type AppProps = Merge<ExcalidrawProps, {
548
607
  export type AppClassProperties = {
549
608
  props: AppProps;
550
609
  state: AppState;
610
+ api: App["api"];
611
+ sessionExportThemeOverride: App["sessionExportThemeOverride"];
551
612
  interactiveCanvas: HTMLCanvasElement | null;
552
613
  /** static canvas */
553
614
  canvas: HTMLCanvasElement;
@@ -588,7 +649,11 @@ export type AppClassProperties = {
588
649
  onPointerUpEmitter: App["onPointerUpEmitter"];
589
650
  updateEditorAtom: App["updateEditorAtom"];
590
651
  onPointerDownEmitter: App["onPointerDownEmitter"];
652
+ onEvent: App["onEvent"];
653
+ onStateChange: App["onStateChange"];
654
+ lastPointerMoveCoords: App["lastPointerMoveCoords"];
591
655
  bindModeHandler: App["bindModeHandler"];
656
+ setAppState: App["setAppState"];
592
657
  };
593
658
  export type PointerDownState = Readonly<{
594
659
  origin: Readonly<{
@@ -649,7 +714,18 @@ export type PointerDownState = Readonly<{
649
714
  };
650
715
  }>;
651
716
  export type UnsubscribeCallback = () => void;
717
+ export type ExcalidrawMountPayload = {
718
+ excalidrawAPI: ExcalidrawImperativeAPI;
719
+ container: HTMLDivElement | null;
720
+ };
721
+ export type ExcalidrawImperativeAPIEventMap = {
722
+ "editor:mount": [payload: ExcalidrawMountPayload];
723
+ "editor:initialize": [api: ExcalidrawImperativeAPI];
724
+ "editor:unmount": [];
725
+ };
652
726
  export interface ExcalidrawImperativeAPI {
727
+ /** Whether the editor has been unmounted and the API is no longer usable. */
728
+ isDestroyed: boolean;
653
729
  updateScene: InstanceType<typeof App>["updateScene"];
654
730
  applyDeltas: InstanceType<typeof App>["applyDeltas"];
655
731
  mutateElement: InstanceType<typeof App>["mutateElement"];
@@ -688,6 +764,8 @@ export interface ExcalidrawImperativeAPI {
688
764
  onPointerUp: (callback: (activeTool: AppState["activeTool"], pointerDownState: PointerDownState, event: PointerEvent) => void) => UnsubscribeCallback;
689
765
  onScrollChange: (callback: (scrollX: number, scrollY: number, zoom: Zoom) => void) => UnsubscribeCallback;
690
766
  onUserFollow: (callback: (payload: OnUserFollowedPayload) => void) => UnsubscribeCallback;
767
+ onStateChange: InstanceType<typeof App>["onStateChange"];
768
+ onEvent: InstanceType<typeof App>["onEvent"];
691
769
  }
692
770
  export type FrameNameBounds = {
693
771
  x: number;
@@ -728,4 +806,3 @@ export type Offsets = Partial<{
728
806
  bottom: number;
729
807
  left: number;
730
808
  }>;
731
- export {};
@@ -1,7 +1,7 @@
1
1
  import type { ExcalidrawElement, ExcalidrawTextElement } from "@excalidraw/element/types";
2
2
  import type App from "../components/App";
3
3
  type SubmitHandler = () => void;
4
- export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords, element, canvas, excalidrawContainer, app, autoSelect, }: {
4
+ export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords, element, canvas, excalidrawContainer, app, autoSelect, initialCaretSceneCoords, }: {
5
5
  id: ExcalidrawElement["id"];
6
6
  /**
7
7
  * textWysiwyg only deals with `originalText`
@@ -20,5 +20,9 @@ export declare const textWysiwyg: ({ id, onChange, onSubmit, getViewportCoords,
20
20
  excalidrawContainer: HTMLDivElement | null;
21
21
  app: App;
22
22
  autoSelect?: boolean;
23
+ initialCaretSceneCoords?: {
24
+ x: number;
25
+ y: number;
26
+ } | null;
23
27
  }) => SubmitHandler;
24
28
  export {};
@@ -1,4 +1,4 @@
1
- import type { LocalPoint, GlobalPoint, Radians, Degrees, Vector } from "./types";
1
+ import type { LocalPoint, GlobalPoint, Radians, Degrees, Vector, GlobalCoord, LocalCoord } from "./types";
2
2
  /**
3
3
  * Create a properly typed Point instance from the X and Y coordinates.
4
4
  *
@@ -7,6 +7,11 @@ import type { LocalPoint, GlobalPoint, Radians, Degrees, Vector } from "./types"
7
7
  * @returns The branded and created point
8
8
  */
9
9
  export declare function pointFrom<Point extends GlobalPoint | LocalPoint>(x: number, y: number): Point;
10
+ export declare function pointFrom<Coord extends GlobalCoord | LocalCoord>(coords: Coord): Coord extends GlobalCoord ? GlobalPoint : LocalPoint;
11
+ export declare function pointFrom<Point extends GlobalPoint | LocalPoint>(coords: {
12
+ x: number;
13
+ y: number;
14
+ }): Point;
10
15
  /**
11
16
  * Converts and remaps an array containing a pair of numbers to Point.
12
17
  *
@@ -52,7 +57,7 @@ export declare function pointsEqual<Point extends GlobalPoint | LocalPoint>(a: P
52
57
  * @param angle The radians to rotate the point by
53
58
  * @returns The rotated point
54
59
  */
55
- export declare function pointRotateRads<Point extends GlobalPoint | LocalPoint>([x, y]: Point, [cx, cy]: Point, angle: Radians): Point;
60
+ export declare function pointRotateRads<Point extends GlobalPoint | LocalPoint>(point: Point, center: Point, angle: Radians): Point;
56
61
  /**
57
62
  * Rotate a point by [angle] degree.
58
63
  *