@yuzhouu/canvas-kit 0.1.2

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 (263) hide show
  1. package/README.md +145 -0
  2. package/_vendor/canvas-core/bindings/BindingUtil.ts +92 -0
  3. package/_vendor/canvas-core/bindings/BindingUtilRegistry.ts +22 -0
  4. package/_vendor/canvas-core/bindings/arrow/arrowBindingHelpers.ts +52 -0
  5. package/_vendor/canvas-core/contextMenu.ts +85 -0
  6. package/_vendor/canvas-core/editor/Editor.ts +2614 -0
  7. package/_vendor/canvas-core/editor/HistoryManager.ts +83 -0
  8. package/_vendor/canvas-core/editor/StateNode.ts +162 -0
  9. package/_vendor/canvas-core/editor/camera.ts +6 -0
  10. package/_vendor/canvas-core/editor/clipboard.ts +478 -0
  11. package/_vendor/canvas-core/editor/commands.ts +833 -0
  12. package/_vendor/canvas-core/editor/edgeScroll.ts +37 -0
  13. package/_vendor/canvas-core/editor/editorComputedHelpers.ts +257 -0
  14. package/_vendor/canvas-core/editor/editorSelectionTransforms.ts +116 -0
  15. package/_vendor/canvas-core/editor/events.ts +93 -0
  16. package/_vendor/canvas-core/editor/index.ts +12 -0
  17. package/_vendor/canvas-core/editor/interactions.ts +101 -0
  18. package/_vendor/canvas-core/editor/internal.ts +22 -0
  19. package/_vendor/canvas-core/editor/managers/BindingManager.ts +262 -0
  20. package/_vendor/canvas-core/editor/managers/CameraManager.ts +147 -0
  21. package/_vendor/canvas-core/editor/managers/ClipboardManager.ts +32 -0
  22. package/_vendor/canvas-core/editor/managers/DocumentSnapshotManager.ts +256 -0
  23. package/_vendor/canvas-core/editor/managers/InputsManager.ts +319 -0
  24. package/_vendor/canvas-core/editor/managers/InteractionTransientManager.ts +218 -0
  25. package/_vendor/canvas-core/editor/managers/QueryManager.ts +837 -0
  26. package/_vendor/canvas-core/editor/managers/RenderWindowManager.ts +347 -0
  27. package/_vendor/canvas-core/editor/managers/SelectionLayoutManager.ts +196 -0
  28. package/_vendor/canvas-core/editor/managers/SelectionManager.ts +98 -0
  29. package/_vendor/canvas-core/editor/managers/SelectionOverlayManager.ts +308 -0
  30. package/_vendor/canvas-core/editor/managers/ShapeEditingManager.ts +226 -0
  31. package/_vendor/canvas-core/editor/managers/ShapeGeometryManager.ts +162 -0
  32. package/_vendor/canvas-core/editor/managers/ShapeHierarchyManager.ts +797 -0
  33. package/_vendor/canvas-core/editor/managers/SideEffectManager.ts +83 -0
  34. package/_vendor/canvas-core/editor/managers/SnapManager.ts +433 -0
  35. package/_vendor/canvas-core/editor/managers/SnapSnapshotBuilder.ts +430 -0
  36. package/_vendor/canvas-core/editor/managers/SpatialIndexManager.ts +354 -0
  37. package/_vendor/canvas-core/editor/managers/ToolManager.ts +81 -0
  38. package/_vendor/canvas-core/editor/managers/queryState.ts +583 -0
  39. package/_vendor/canvas-core/editor/managers/selectionGeometry.ts +287 -0
  40. package/_vendor/canvas-core/editor/managers/shapeOrder.ts +350 -0
  41. package/_vendor/canvas-core/editor/managers/shapeReparenting.ts +160 -0
  42. package/_vendor/canvas-core/editor/managers/snapCalculations.ts +412 -0
  43. package/_vendor/canvas-core/editor/managers/snapGeometry.ts +202 -0
  44. package/_vendor/canvas-core/editor/managers/snapIndicators.ts +403 -0
  45. package/_vendor/canvas-core/editor/managers/snapTypes.ts +122 -0
  46. package/_vendor/canvas-core/editor/queries/shapeTransforms.ts +171 -0
  47. package/_vendor/canvas-core/editor/renderWindow.ts +439 -0
  48. package/_vendor/canvas-core/editor/resizeGeometry.ts +654 -0
  49. package/_vendor/canvas-core/editor/selection.ts +489 -0
  50. package/_vendor/canvas-core/editor/selectionHandleInteractions.ts +43 -0
  51. package/_vendor/canvas-core/editor/selectionOverlay.ts +567 -0
  52. package/_vendor/canvas-core/exports/integrity.ts +174 -0
  53. package/_vendor/canvas-core/exports/svg.ts +494 -0
  54. package/_vendor/canvas-core/geometry/Box.ts +80 -0
  55. package/_vendor/canvas-core/geometry/Ellipse2d.ts +67 -0
  56. package/_vendor/canvas-core/geometry/Geometry2d.ts +52 -0
  57. package/_vendor/canvas-core/geometry/Mat.ts +92 -0
  58. package/_vendor/canvas-core/geometry/Polyline2d.ts +63 -0
  59. package/_vendor/canvas-core/geometry/Rectangle2d.ts +64 -0
  60. package/_vendor/canvas-core/geometry/Vec.ts +123 -0
  61. package/_vendor/canvas-core/geometry/index.ts +13 -0
  62. package/_vendor/canvas-core/geometry/segments.ts +65 -0
  63. package/_vendor/canvas-core/index.ts +391 -0
  64. package/_vendor/canvas-core/plugins/index.ts +5 -0
  65. package/_vendor/canvas-core/plugins/types.ts +53 -0
  66. package/_vendor/canvas-core/reactivity.ts +16 -0
  67. package/_vendor/canvas-core/schema/records.ts +221 -0
  68. package/_vendor/canvas-core/schema/snapshots.ts +527 -0
  69. package/_vendor/canvas-core/shapes/ShapeUtil.ts +516 -0
  70. package/_vendor/canvas-core/shapes/ShapeUtilRegistry.ts +26 -0
  71. package/_vendor/canvas-core/shapes/capabilities.ts +67 -0
  72. package/_vendor/canvas-core/shapes/types.ts +20 -0
  73. package/_vendor/canvas-core/toolbar.ts +148 -0
  74. package/_vendor/canvas-core/tools/hand/HandTool.ts +75 -0
  75. package/_vendor/canvas-core/tools/index.ts +2 -0
  76. package/_vendor/canvas-core/tools/select/SelectTool.ts +33 -0
  77. package/_vendor/canvas-core/tools/select/selectContainment.ts +104 -0
  78. package/_vendor/canvas-core/tools/select/selectToolHelpers.ts +801 -0
  79. package/_vendor/canvas-core/tools/select/states/BrushingState.ts +145 -0
  80. package/_vendor/canvas-core/tools/select/states/DraggingSelectionHandleInteractionState.ts +116 -0
  81. package/_vendor/canvas-core/tools/select/states/IdleState.ts +159 -0
  82. package/_vendor/canvas-core/tools/select/states/PointingCanvasState.ts +41 -0
  83. package/_vendor/canvas-core/tools/select/states/PointingResizeHandleState.ts +78 -0
  84. package/_vendor/canvas-core/tools/select/states/PointingRotateHandleState.ts +64 -0
  85. package/_vendor/canvas-core/tools/select/states/PointingSelectionHandleInteractionState.ts +34 -0
  86. package/_vendor/canvas-core/tools/select/states/PointingShapeState.ts +140 -0
  87. package/_vendor/canvas-core/tools/select/states/ResizingState.ts +171 -0
  88. package/_vendor/canvas-core/tools/select/states/RotatingState.ts +124 -0
  89. package/_vendor/canvas-core/tools/select/states/SelectStateNode.ts +128 -0
  90. package/_vendor/canvas-core/tools/select/states/TranslatingState.ts +139 -0
  91. package/_vendor/canvas-core/tools/select/states/index.ts +11 -0
  92. package/_vendor/canvas-plugin-api/feature.ts +204 -0
  93. package/_vendor/canvas-plugin-api/index.ts +142 -0
  94. package/_vendor/canvas-product-react/api/apiRegistry.ts +35 -0
  95. package/_vendor/canvas-product-react/api/canvasProductApi.ts +422 -0
  96. package/_vendor/canvas-product-react/api/index.ts +31 -0
  97. package/_vendor/canvas-product-react/capabilities/clipboard/clipboardService.ts +36 -0
  98. package/_vendor/canvas-product-react/capabilities/clipboard/systemClipboard.ts +245 -0
  99. package/_vendor/canvas-product-react/capabilities/context-menu/systemContextMenu.ts +396 -0
  100. package/_vendor/canvas-product-react/capabilities/context-menu/useContextMenuSurface.ts +59 -0
  101. package/_vendor/canvas-product-react/capabilities/export/useSvgExport.ts +156 -0
  102. package/_vendor/canvas-product-react/capabilities/history/useHistoryControls.ts +23 -0
  103. package/_vendor/canvas-product-react/capabilities/pages/usePageControls.ts +41 -0
  104. package/_vendor/canvas-product-react/capabilities/toolbar/systemToolbar.ts +490 -0
  105. package/_vendor/canvas-product-react/capabilities/toolbar/useToolbarSurfaces.ts +92 -0
  106. package/_vendor/canvas-product-react/capabilities/zoom/useZoomControls.ts +27 -0
  107. package/_vendor/canvas-product-react/index.ts +84 -0
  108. package/_vendor/canvas-product-react/persistence/index.ts +18 -0
  109. package/_vendor/canvas-product-react/persistence/localSnapshotPersistence.ts +294 -0
  110. package/_vendor/canvas-product-react/runtime/CanvasProductRoot.tsx +250 -0
  111. package/_vendor/canvas-product-react/runtime/productDefinition.ts +72 -0
  112. package/_vendor/canvas-product-react/runtime/productServices.ts +96 -0
  113. package/_vendor/canvas-react/components/CanvasView.tsx +796 -0
  114. package/_vendor/canvas-react/components/OverlayLayer.tsx +879 -0
  115. package/_vendor/canvas-react/components/PageSpace.tsx +34 -0
  116. package/_vendor/canvas-react/components/ShapeLayer.tsx +428 -0
  117. package/_vendor/canvas-react/components/index.ts +4 -0
  118. package/_vendor/canvas-react/hooks/useEditor.ts +11 -0
  119. package/_vendor/canvas-react/hooks/useValue.ts +14 -0
  120. package/_vendor/canvas-react/host/CanvasRendererRegistryContext.tsx +14 -0
  121. package/_vendor/canvas-react/host/contextMenuRegistry.ts +61 -0
  122. package/_vendor/canvas-react/host/domEventGuards.ts +61 -0
  123. package/_vendor/canvas-react/host/index.ts +38 -0
  124. package/_vendor/canvas-react/host/pluginHost.ts +635 -0
  125. package/_vendor/canvas-react/host/rendererRegistry.tsx +58 -0
  126. package/_vendor/canvas-react/host/toolbarRegistry.ts +100 -0
  127. package/_vendor/canvas-react/index.ts +3 -0
  128. package/_vendor/plugin-arrow/ArrowBindingUtil.ts +239 -0
  129. package/_vendor/plugin-arrow/ArrowShapeUtil.ts +311 -0
  130. package/_vendor/plugin-arrow/ArrowTool.ts +208 -0
  131. package/_vendor/plugin-arrow/arrowGeometry.ts +441 -0
  132. package/_vendor/plugin-arrow/arrowTerminalBindingResolver.ts +253 -0
  133. package/_vendor/plugin-arrow/arrowTerminalCommands.ts +230 -0
  134. package/_vendor/plugin-arrow/canvas.tsx +92 -0
  135. package/_vendor/plugin-arrow/core.ts +409 -0
  136. package/_vendor/plugin-arrow/feature.ts +20 -0
  137. package/_vendor/plugin-arrow/index.ts +28 -0
  138. package/_vendor/plugin-arrow/selectionHandleInteractions.ts +154 -0
  139. package/_vendor/plugin-arrow/types.ts +63 -0
  140. package/_vendor/plugin-draw/DrawShapeRenderer.tsx +60 -0
  141. package/_vendor/plugin-draw/DrawShapeUtil.ts +372 -0
  142. package/_vendor/plugin-draw/DrawTool.ts +444 -0
  143. package/_vendor/plugin-draw/canvas.tsx +24 -0
  144. package/_vendor/plugin-draw/core.ts +515 -0
  145. package/_vendor/plugin-draw/drawGeometry.ts +491 -0
  146. package/_vendor/plugin-draw/drawHitTest.ts +271 -0
  147. package/_vendor/plugin-draw/drawInterpolation.ts +250 -0
  148. package/_vendor/plugin-draw/drawPath.ts +550 -0
  149. package/_vendor/plugin-draw/drawSegments.ts +106 -0
  150. package/_vendor/plugin-draw/drawSelectionTransform.ts +67 -0
  151. package/_vendor/plugin-draw/drawShapeGeometry.ts +307 -0
  152. package/_vendor/plugin-draw/drawStrokeGeometry.ts +454 -0
  153. package/_vendor/plugin-draw/feature.ts +20 -0
  154. package/_vendor/plugin-draw/index.ts +31 -0
  155. package/_vendor/plugin-draw/types.ts +36 -0
  156. package/_vendor/plugin-eraser/EraserTool.ts +297 -0
  157. package/_vendor/plugin-eraser/canvas.tsx +616 -0
  158. package/_vendor/plugin-eraser/core.ts +49 -0
  159. package/_vendor/plugin-eraser/feature.ts +20 -0
  160. package/_vendor/plugin-eraser/index.ts +4 -0
  161. package/_vendor/plugin-frame/FrameShapeUtil.ts +173 -0
  162. package/_vendor/plugin-frame/FrameTool.ts +225 -0
  163. package/_vendor/plugin-frame/canvas.tsx +75 -0
  164. package/_vendor/plugin-frame/core.ts +534 -0
  165. package/_vendor/plugin-frame/feature.ts +20 -0
  166. package/_vendor/plugin-frame/index.ts +6 -0
  167. package/_vendor/plugin-geo/GeoShapeUtil.ts +463 -0
  168. package/_vendor/plugin-geo/GeoTools.ts +247 -0
  169. package/_vendor/plugin-geo/canvas.tsx +90 -0
  170. package/_vendor/plugin-geo/core.ts +495 -0
  171. package/_vendor/plugin-geo/feature.ts +20 -0
  172. package/_vendor/plugin-geo/index.ts +7 -0
  173. package/_vendor/plugin-geo/types.ts +27 -0
  174. package/_vendor/plugin-group/GroupShapeUtil.ts +59 -0
  175. package/_vendor/plugin-group/canvas.tsx +59 -0
  176. package/_vendor/plugin-group/core.ts +40 -0
  177. package/_vendor/plugin-group/feature.ts +20 -0
  178. package/_vendor/plugin-group/index.ts +5 -0
  179. package/_vendor/plugin-image/ImageShapeUtil.ts +95 -0
  180. package/_vendor/plugin-image/canvas.tsx +212 -0
  181. package/_vendor/plugin-image/core.ts +542 -0
  182. package/_vendor/plugin-image/crop.ts +770 -0
  183. package/_vendor/plugin-image/cropInteractions.ts +350 -0
  184. package/_vendor/plugin-image/cropSession.ts +38 -0
  185. package/_vendor/plugin-image/feature.ts +20 -0
  186. package/_vendor/plugin-image/index.ts +29 -0
  187. package/_vendor/plugin-image/types.ts +55 -0
  188. package/_vendor/plugin-image-product-react/ImageImportController.tsx +143 -0
  189. package/_vendor/plugin-image-product-react/imageAssetService.ts +52 -0
  190. package/_vendor/plugin-image-product-react/imageBlobStore.ts +315 -0
  191. package/_vendor/plugin-image-product-react/imageHostActions.ts +438 -0
  192. package/_vendor/plugin-image-product-react/imageProductApi.ts +88 -0
  193. package/_vendor/plugin-image-product-react/imageToolbarHostBridge.ts +48 -0
  194. package/_vendor/plugin-image-product-react/imageToolbarRuntime.ts +21 -0
  195. package/_vendor/plugin-image-product-react/index.ts +60 -0
  196. package/_vendor/plugin-image-product-react/snapshotGuards.ts +33 -0
  197. package/_vendor/plugin-image-product-react/svgImageAssetInliner.ts +54 -0
  198. package/_vendor/plugin-image-product-react/useImageImport.ts +64 -0
  199. package/_vendor/plugin-laser/LaserTool.ts +154 -0
  200. package/_vendor/plugin-laser/canvas.tsx +645 -0
  201. package/_vendor/plugin-laser/core.ts +49 -0
  202. package/_vendor/plugin-laser/feature.ts +20 -0
  203. package/_vendor/plugin-laser/index.ts +4 -0
  204. package/_vendor/plugin-text/ArrowLabelBindingUtil.ts +336 -0
  205. package/_vendor/plugin-text/GeoLabelBindingUtil.ts +391 -0
  206. package/_vendor/plugin-text/TextShapeSvgExporter.ts +101 -0
  207. package/_vendor/plugin-text/TextShapeUtil.ts +284 -0
  208. package/_vendor/plugin-text/TextTool.ts +228 -0
  209. package/_vendor/plugin-text/canvas.tsx +115 -0
  210. package/_vendor/plugin-text/core.ts +422 -0
  211. package/_vendor/plugin-text/feature.ts +20 -0
  212. package/_vendor/plugin-text/host/RichTextEditingBox.tsx +144 -0
  213. package/_vendor/plugin-text/host/RichTextToolbar.tsx +266 -0
  214. package/_vendor/plugin-text/host/TiptapTextEditor.tsx +191 -0
  215. package/_vendor/plugin-text/host/richTextRendering.tsx +49 -0
  216. package/_vendor/plugin-text/host/textDomSelection.ts +93 -0
  217. package/_vendor/plugin-text/host/textEditingBoxStyle.ts +36 -0
  218. package/_vendor/plugin-text/host/textEntryFocus.ts +307 -0
  219. package/_vendor/plugin-text/host/textFontLoader.ts +149 -0
  220. package/_vendor/plugin-text/host/textMeasurement.ts +258 -0
  221. package/_vendor/plugin-text/host/textMeasurementSync.ts +77 -0
  222. package/_vendor/plugin-text/host/textRangeSelection.ts +134 -0
  223. package/_vendor/plugin-text/host/textShapeRendererRuntime.tsx +89 -0
  224. package/_vendor/plugin-text/host/textShapeSync.ts +173 -0
  225. package/_vendor/plugin-text/host/tiptapTextEditorController.ts +148 -0
  226. package/_vendor/plugin-text/index.ts +18 -0
  227. package/_vendor/plugin-text/richTextUtils.ts +259 -0
  228. package/_vendor/plugin-text/textInteractions.ts +366 -0
  229. package/_vendor/plugin-text/textLabelHelpers.ts +235 -0
  230. package/_vendor/plugin-text/textShapeHelpers.ts +123 -0
  231. package/_vendor/plugin-text/textStyle.ts +96 -0
  232. package/_vendor/plugin-text/textTypes.ts +48 -0
  233. package/_vendor/signals/atom.ts +74 -0
  234. package/_vendor/signals/computed.ts +132 -0
  235. package/_vendor/signals/core.ts +130 -0
  236. package/_vendor/signals/effect.ts +117 -0
  237. package/_vendor/signals/index.ts +9 -0
  238. package/_vendor/signals/types.ts +17 -0
  239. package/_vendor/store/Store.ts +171 -0
  240. package/_vendor/store/diff.ts +229 -0
  241. package/_vendor/store/history.ts +177 -0
  242. package/_vendor/store/index.ts +32 -0
  243. package/_vendor/store/types.ts +37 -0
  244. package/api/canvasKitApi.d.ts +29 -0
  245. package/index.css +3 -0
  246. package/index.d.ts +16 -0
  247. package/index.mjs +1 -0
  248. package/internal-modules.d.ts +187 -0
  249. package/package.json +48 -0
  250. package/product/Shell.d.ts +19 -0
  251. package/product/chromeContext.d.ts +70 -0
  252. package/product/createCanvasKitEditor.d.ts +6 -0
  253. package/product/index.d.ts +7 -0
  254. package/product/persistence.d.ts +3 -0
  255. package/product/product.d.ts +22 -0
  256. package/product/useCanvasClipboardShortcuts.d.ts +6 -0
  257. package/product-iyBbEPIs.mjs +4 -0
  258. package/product.mjs +1 -0
  259. package/standard/extensions.d.ts +1 -0
  260. package/standard/index.d.ts +3 -0
  261. package/standard/standardApi.d.ts +91 -0
  262. package/standard-BmrxwqpJ.mjs +44 -0
  263. package/standard.mjs +1 -0
@@ -0,0 +1,833 @@
1
+ import type { Editor } from "./Editor";
2
+ import type { ChangeSource } from "@land/store";
3
+ import type {
4
+ AssetId,
5
+ AssetRecord,
6
+ AssetRecordBase,
7
+ BindingId,
8
+ BindingRecordBase,
9
+ BindingRecord,
10
+ Camera,
11
+ PageId,
12
+ PageRecord,
13
+ ShapeId,
14
+ ShapeParentId,
15
+ ShapeRecordBase,
16
+ ShapeRecord,
17
+ ShapeEditingEntryMode,
18
+ } from "../schema/records";
19
+ import { getEditorStore } from "./internal";
20
+
21
+ export interface EditorCommandOptions {
22
+ source?: ChangeSource;
23
+ }
24
+
25
+ export interface CreateShapeInput {
26
+ type: ShapeRecordBase["type"];
27
+ x: number;
28
+ y: number;
29
+ props?: Record<string, unknown>;
30
+ parentId?: ShapeParentId;
31
+ index?: string;
32
+ opacity?: number;
33
+ isHidden?: boolean;
34
+ rotation?: number;
35
+ scaleX?: number;
36
+ scaleY?: number;
37
+ isLocked?: boolean;
38
+ meta?: Record<string, unknown>;
39
+ }
40
+
41
+ export interface CreateAssetInput {
42
+ id?: AssetId;
43
+ type: AssetRecordBase["type"];
44
+ props?: Record<string, unknown>;
45
+ meta?: Record<string, unknown>;
46
+ }
47
+
48
+ export interface UpdateAssetInput {
49
+ id: AssetId;
50
+ props?: Record<string, unknown>;
51
+ meta?: Record<string, unknown>;
52
+ }
53
+
54
+ export interface ShapeUpdate {
55
+ id: ShapeId;
56
+ x?: number;
57
+ y?: number;
58
+ rotation?: number;
59
+ scaleX?: number;
60
+ scaleY?: number;
61
+ isHidden?: boolean;
62
+ isLocked?: boolean;
63
+ parentId?: ShapeParentId;
64
+ index?: string;
65
+ props?: Record<string, unknown>;
66
+ }
67
+
68
+ export interface ReparentShapesInput {
69
+ ids: ShapeId[];
70
+ parentId: ShapeParentId;
71
+ }
72
+
73
+ export interface StartEditingShapeInput {
74
+ shapeId: ShapeId;
75
+ entryMode?: ShapeEditingEntryMode;
76
+ caretPagePoint?: { x: number; y: number };
77
+ markId?: string;
78
+ reuseExistingMark?: boolean;
79
+ preserveInteraction?: boolean;
80
+ }
81
+
82
+ export interface CreateBindingInput {
83
+ id?: BindingId;
84
+ type: BindingRecordBase["type"];
85
+ fromId: ShapeId;
86
+ toId: ShapeId;
87
+ props?: Record<string, unknown>;
88
+ meta?: Record<string, unknown>;
89
+ }
90
+
91
+ export interface UpdateBindingInput {
92
+ id: BindingId;
93
+ fromId?: ShapeId;
94
+ toId?: ShapeId;
95
+ props?: Record<string, unknown>;
96
+ meta?: Record<string, unknown>;
97
+ }
98
+
99
+ export interface CreatePageInput {
100
+ name?: string;
101
+ index?: string;
102
+ meta?: Record<string, unknown>;
103
+ }
104
+
105
+ export interface RenamePageInput {
106
+ id: PageId;
107
+ name: string;
108
+ }
109
+
110
+ export interface MovePageInput {
111
+ id: PageId;
112
+ toIndex: number;
113
+ }
114
+
115
+ export interface SetCameraInput {
116
+ pageId?: PageId;
117
+ camera: Partial<Camera>;
118
+ }
119
+
120
+ export interface EditorCommands {
121
+ createPage(
122
+ input?: CreatePageInput,
123
+ options?: EditorCommandOptions,
124
+ ): PageRecord;
125
+ deletePage(id: PageId, options?: EditorCommandOptions): boolean;
126
+ renamePage(input: RenamePageInput, options?: EditorCommandOptions): void;
127
+ movePage(input: MovePageInput, options?: EditorCommandOptions): void;
128
+ createShapes(
129
+ inputs: CreateShapeInput[],
130
+ options?: EditorCommandOptions,
131
+ ): ShapeRecord[];
132
+ /**
133
+ * Persist already-built shape records (with their existing ids) through the
134
+ * command pipeline. Used by paste/duplicate where ids must be assigned before
135
+ * parent/binding remapping. Prefer `createShapes` for fresh shapes.
136
+ */
137
+ createShapesFromRecords(
138
+ records: ShapeRecord[],
139
+ options?: EditorCommandOptions,
140
+ ): ShapeRecord[];
141
+ updateShapes(updates: ShapeUpdate[], options?: EditorCommandOptions): void;
142
+ reparentShapes(
143
+ input: ReparentShapesInput,
144
+ options?: EditorCommandOptions,
145
+ ): void;
146
+ deleteShapes(ids: ShapeId[], options?: EditorCommandOptions): void;
147
+ createAsset(
148
+ input: CreateAssetInput,
149
+ options?: EditorCommandOptions,
150
+ ): AssetRecord;
151
+ /**
152
+ * Persist already-built asset records (with their existing ids) through the
153
+ * command pipeline. Used by paste/duplicate. Prefer `createAsset` otherwise.
154
+ */
155
+ createAssetsFromRecords(
156
+ records: AssetRecord[],
157
+ options?: EditorCommandOptions,
158
+ ): AssetRecord[];
159
+ updateAsset(
160
+ input: UpdateAssetInput,
161
+ options?: EditorCommandOptions,
162
+ ): AssetRecord | null;
163
+ deleteAsset(id: AssetId, options?: EditorCommandOptions): boolean;
164
+ createBinding(
165
+ input: CreateBindingInput,
166
+ options?: EditorCommandOptions,
167
+ ): BindingRecord;
168
+ updateBinding(
169
+ input: UpdateBindingInput,
170
+ options?: EditorCommandOptions,
171
+ ): BindingRecord | null;
172
+ deleteBinding(id: BindingId, options?: EditorCommandOptions): boolean;
173
+ setCurrentPageId(id: PageId, options?: EditorCommandOptions): void;
174
+ setCamera(input: SetCameraInput, options?: EditorCommandOptions): void;
175
+ setSelectedShapeIds(ids: ShapeId[], options?: EditorCommandOptions): void;
176
+ setActiveTool(toolId: string, options?: EditorCommandOptions): void;
177
+ setToolLocked(locked: boolean, options?: EditorCommandOptions): void;
178
+ }
179
+
180
+ export function createEditorCommands(editor: Editor): EditorCommands {
181
+ return {
182
+ createPage(input, options) {
183
+ return createPage(editor, input, options);
184
+ },
185
+ deletePage(id, options) {
186
+ return deletePage(editor, id, options);
187
+ },
188
+ renamePage(input, options) {
189
+ renamePage(editor, input, options);
190
+ },
191
+ movePage(input, options) {
192
+ movePage(editor, input, options);
193
+ },
194
+ createShapes(inputs, options) {
195
+ return createShapes(editor, inputs, options);
196
+ },
197
+ createShapesFromRecords(records, options) {
198
+ return createShapesFromRecords(editor, records, options);
199
+ },
200
+ updateShapes(updates, options) {
201
+ updateShapes(editor, updates, options);
202
+ },
203
+ reparentShapes(input, options) {
204
+ reparentShapes(editor, input, options);
205
+ },
206
+ deleteShapes(ids, options) {
207
+ deleteShapes(editor, ids, options);
208
+ },
209
+ createAsset(input, options) {
210
+ return createAsset(editor, input, options);
211
+ },
212
+ createAssetsFromRecords(records, options) {
213
+ return createAssetsFromRecords(editor, records, options);
214
+ },
215
+ updateAsset(input, options) {
216
+ return updateAsset(editor, input, options);
217
+ },
218
+ deleteAsset(id, options) {
219
+ return deleteAsset(editor, id, options);
220
+ },
221
+ createBinding(input, options) {
222
+ return createBinding(editor, input, options);
223
+ },
224
+ updateBinding(input, options) {
225
+ return updateBinding(editor, input, options);
226
+ },
227
+ deleteBinding(id, options) {
228
+ return deleteBinding(editor, id, options);
229
+ },
230
+ setCurrentPageId(id, options) {
231
+ setCurrentPageId(editor, id, options);
232
+ },
233
+ setCamera(input, options) {
234
+ setCamera(editor, input, options);
235
+ },
236
+ setSelectedShapeIds(ids, options) {
237
+ setSelectedShapeIds(editor, ids, options);
238
+ },
239
+ setActiveTool(toolId, options) {
240
+ setActiveTool(editor, toolId, options);
241
+ },
242
+ setToolLocked(locked, options) {
243
+ setToolLocked(editor, locked, options);
244
+ },
245
+ };
246
+ }
247
+
248
+ function normalizePageOrder(pages: PageRecord[]): PageRecord[] {
249
+ return pages.map((page, index) => ({
250
+ ...page,
251
+ index: String(index + 1).padStart(4, "0"),
252
+ }));
253
+ }
254
+
255
+ function createPage(
256
+ editor: Editor,
257
+ input?: CreatePageInput,
258
+ options?: EditorCommandOptions,
259
+ ): PageRecord {
260
+ const source = options?.source ?? "user";
261
+ const nextPage = editor.createPageRecord(input);
262
+ let createdPage = nextPage;
263
+
264
+ getEditorStore(editor).atomic(() => {
265
+ const pages = normalizePageOrder([...editor.getPages(), nextPage]);
266
+ createdPage = pages.find((page) => page.id === nextPage.id) ?? nextPage;
267
+ getEditorStore(editor).put(pages, source);
268
+ editor.ensurePageSessionState(createdPage.id, source);
269
+ }, source);
270
+
271
+ return createdPage;
272
+ }
273
+
274
+ function deletePage(
275
+ editor: Editor,
276
+ id: PageId,
277
+ options?: EditorCommandOptions,
278
+ ): boolean {
279
+ const source = options?.source ?? "user";
280
+ const pages = editor.getPages();
281
+ if (pages.length <= 1) {
282
+ return false;
283
+ }
284
+
285
+ const pageIndex = pages.findIndex((page) => page.id === id);
286
+ if (pageIndex < 0) {
287
+ return false;
288
+ }
289
+
290
+ const shapeIds = editor.getShapesForPage(id).map((shape) => shape.id);
291
+ const nextPages = normalizePageOrder(pages.filter((page) => page.id !== id));
292
+ const fallbackPageId =
293
+ pages[pageIndex + 1]?.id ?? pages[pageIndex - 1]?.id ?? pages[0]?.id;
294
+ const nextCurrentPageId =
295
+ editor.getCurrentPageId() === id && fallbackPageId
296
+ ? fallbackPageId
297
+ : editor.getCurrentPageId();
298
+
299
+ getEditorStore(editor).atomic(() => {
300
+ if (shapeIds.length > 0) {
301
+ deleteShapes(editor, shapeIds, options);
302
+ }
303
+ getEditorStore(editor).remove([id], source);
304
+ editor.removePageSessionState(id, nextCurrentPageId, source);
305
+ getEditorStore(editor).put(nextPages, source);
306
+ }, source);
307
+
308
+ return true;
309
+ }
310
+
311
+ function renamePage(
312
+ editor: Editor,
313
+ input: RenamePageInput,
314
+ options?: EditorCommandOptions,
315
+ ): void {
316
+ const source = options?.source ?? "user";
317
+ const current = editor.getPage(input.id);
318
+ if (!current) {
319
+ return;
320
+ }
321
+
322
+ const name = input.name.trim();
323
+ if (!name || name === current.name) {
324
+ return;
325
+ }
326
+
327
+ getEditorStore(editor).atomic(() => {
328
+ getEditorStore(editor).put([{ ...current, name }], source);
329
+ }, source);
330
+ }
331
+
332
+ function movePage(
333
+ editor: Editor,
334
+ input: MovePageInput,
335
+ options?: EditorCommandOptions,
336
+ ): void {
337
+ const source = options?.source ?? "user";
338
+ const pages = editor.getPages();
339
+ const fromIndex = pages.findIndex((page) => page.id === input.id);
340
+ if (fromIndex < 0) {
341
+ return;
342
+ }
343
+
344
+ const toIndex = Math.max(0, Math.min(input.toIndex, pages.length - 1));
345
+ if (fromIndex === toIndex) {
346
+ return;
347
+ }
348
+
349
+ const nextPages = [...pages];
350
+ const [movedPage] = nextPages.splice(fromIndex, 1);
351
+ if (!movedPage) {
352
+ return;
353
+ }
354
+ nextPages.splice(toIndex, 0, movedPage);
355
+
356
+ getEditorStore(editor).atomic(() => {
357
+ getEditorStore(editor).put(normalizePageOrder(nextPages), source);
358
+ }, source);
359
+ }
360
+
361
+ function createShapes(
362
+ editor: Editor,
363
+ inputs: CreateShapeInput[],
364
+ options?: EditorCommandOptions,
365
+ ): ShapeRecord[] {
366
+ const created: ShapeRecord[] = [];
367
+ const source = options?.source ?? "user";
368
+
369
+ getEditorStore(editor).atomic(() => {
370
+ const records = inputs.map((input) => {
371
+ const record = editor.createShapeRecord(input);
372
+ if (source !== "user" || input.parentId) {
373
+ return record;
374
+ }
375
+
376
+ const parentId = editor.getContainingParentIdForShapeRecord(record);
377
+ return parentId && parentId !== record.parentId
378
+ ? ({ ...record, parentId } as ShapeRecord)
379
+ : record;
380
+ });
381
+ created.push(...records);
382
+ getEditorStore(editor).put(records, source);
383
+ }, source);
384
+
385
+ return created;
386
+ }
387
+
388
+ function createShapesFromRecords(
389
+ editor: Editor,
390
+ records: ShapeRecord[],
391
+ options?: EditorCommandOptions,
392
+ ): ShapeRecord[] {
393
+ const source = options?.source ?? "user";
394
+ if (records.length === 0) {
395
+ return [];
396
+ }
397
+
398
+ getEditorStore(editor).atomic(() => {
399
+ getEditorStore(editor).put(records, source);
400
+ }, source);
401
+
402
+ return records;
403
+ }
404
+
405
+ export function reparentShapeToContainingParent(
406
+ editor: Editor,
407
+ shapeId: ShapeId,
408
+ options?: EditorCommandOptions,
409
+ ): void {
410
+ const shape = editor.getShape(shapeId);
411
+ if (!shape) {
412
+ return;
413
+ }
414
+
415
+ const parentId = editor.getContainingParentIdForShapeRecord(shape);
416
+ if (!parentId || parentId === shape.parentId) {
417
+ return;
418
+ }
419
+
420
+ editor.commands.reparentShapes({ ids: [shapeId], parentId }, options);
421
+ }
422
+
423
+ function updateShapes(
424
+ editor: Editor,
425
+ updates: ShapeUpdate[],
426
+ options?: EditorCommandOptions,
427
+ ): void {
428
+ const source = options?.source ?? "user";
429
+
430
+ getEditorStore(editor).atomic(() => {
431
+ const nextRecords: ShapeRecord[] = [];
432
+ const changes: Array<{ before: ShapeRecord; after: ShapeRecord }> = [];
433
+ for (const update of updates) {
434
+ const current = editor.getShape(update.id);
435
+ if (!current) continue;
436
+
437
+ const nextX = update.x ?? current.x;
438
+ const nextY = update.y ?? current.y;
439
+ const nextRotation = update.rotation ?? current.rotation;
440
+ const nextScaleX = update.scaleX ?? current.scaleX;
441
+ const nextScaleY = update.scaleY ?? current.scaleY;
442
+ const nextIsHidden = update.isHidden ?? current.isHidden;
443
+ const nextIsLocked = update.isLocked ?? current.isLocked;
444
+ const nextParentId = update.parentId ?? current.parentId;
445
+ const nextIndex = update.index ?? current.index;
446
+
447
+ if (!editor.canUseShapeParent(nextParentId, current.id)) {
448
+ throw new Error(`Invalid parent id for shape ${current.id}`);
449
+ }
450
+
451
+ if (
452
+ !update.props &&
453
+ nextX === current.x &&
454
+ nextY === current.y &&
455
+ nextRotation === current.rotation &&
456
+ nextScaleX === current.scaleX &&
457
+ nextScaleY === current.scaleY &&
458
+ nextIsHidden === current.isHidden &&
459
+ nextIsLocked === current.isLocked &&
460
+ nextParentId === current.parentId &&
461
+ nextIndex === current.index
462
+ ) {
463
+ continue;
464
+ }
465
+
466
+ const util = editor.shapeUtils.get(current.type);
467
+ const nextRecord: ShapeRecord = {
468
+ ...current,
469
+ x: nextX,
470
+ y: nextY,
471
+ rotation: nextRotation,
472
+ scaleX: nextScaleX,
473
+ scaleY: nextScaleY,
474
+ isHidden: nextIsHidden,
475
+ isLocked: nextIsLocked,
476
+ parentId: nextParentId,
477
+ index: nextIndex,
478
+ props: update.props
479
+ ? util.validateProps({
480
+ ...current.props,
481
+ ...update.props,
482
+ })
483
+ : current.props,
484
+ } as ShapeRecord;
485
+ nextRecords.push(nextRecord);
486
+ changes.push({ before: current, after: nextRecord });
487
+ }
488
+
489
+ if (nextRecords.length === 0) {
490
+ return;
491
+ }
492
+
493
+ getEditorStore(editor).put(nextRecords, source);
494
+ editor.bindings.handleShapeChanges(changes, source);
495
+ syncTransformDescendantAncestorBounds(editor, changes, source);
496
+ }, source);
497
+ }
498
+
499
+ function syncTransformDescendantAncestorBounds(
500
+ editor: Editor,
501
+ changes: Array<{ before: ShapeRecord; after: ShapeRecord }>,
502
+ source: ChangeSource,
503
+ ): void {
504
+ const changedIds = new Set(changes.map((change) => change.after.id));
505
+ const ancestorIds = new Set<ShapeId>();
506
+ for (const change of changes) {
507
+ collectTransformDescendantAncestorIds(editor, change.before, ancestorIds);
508
+ collectTransformDescendantAncestorIds(editor, change.after, ancestorIds);
509
+ }
510
+
511
+ const updates: ShapeRecord[] = [];
512
+ const bindingChanges: Array<{ before: ShapeRecord; after: ShapeRecord }> = [];
513
+ for (const ancestorId of ancestorIds) {
514
+ if (changedIds.has(ancestorId)) {
515
+ continue;
516
+ }
517
+
518
+ const ancestor = editor.getShape(ancestorId);
519
+ if (!ancestor || ancestor.rotation !== 0 || ancestor.scaleX !== 1 || ancestor.scaleY !== 1) {
520
+ continue;
521
+ }
522
+
523
+ const bounds = editor.getDescendantPageBounds(ancestor.id);
524
+ if (!bounds) {
525
+ continue;
526
+ }
527
+
528
+ const props = ancestor.props as Record<string, unknown>;
529
+ if (typeof props.w !== "number" || typeof props.h !== "number") {
530
+ continue;
531
+ }
532
+
533
+ if (
534
+ ancestor.x === bounds.x &&
535
+ ancestor.y === bounds.y &&
536
+ props.w === bounds.w &&
537
+ props.h === bounds.h
538
+ ) {
539
+ continue;
540
+ }
541
+
542
+ const util = editor.shapeUtils.get(ancestor.type);
543
+ const nextRecord = {
544
+ ...ancestor,
545
+ x: bounds.x,
546
+ y: bounds.y,
547
+ props: util.validateProps({
548
+ ...props,
549
+ w: bounds.w,
550
+ h: bounds.h,
551
+ }),
552
+ } as ShapeRecord;
553
+ updates.push(nextRecord);
554
+ bindingChanges.push({ before: ancestor, after: nextRecord });
555
+ }
556
+
557
+ if (updates.length === 0) {
558
+ return;
559
+ }
560
+
561
+ getEditorStore(editor).put(updates, source);
562
+ editor.bindings.handleShapeChanges(bindingChanges, source);
563
+ }
564
+
565
+ function collectTransformDescendantAncestorIds(
566
+ editor: Editor,
567
+ shape: ShapeRecord,
568
+ ids: Set<ShapeId>,
569
+ ): void {
570
+ const seen = new Set<ShapeId>([shape.id]);
571
+ let parentId = shape.parentId;
572
+ while (parentId.startsWith("shape:")) {
573
+ const parent = editor.getShape(parentId as ShapeId);
574
+ if (!parent || seen.has(parent.id)) {
575
+ return;
576
+ }
577
+ seen.add(parent.id);
578
+ if (editor.getShapeUtil(parent).shouldTransformDescendants(parent)) {
579
+ ids.add(parent.id);
580
+ }
581
+ parentId = parent.parentId;
582
+ }
583
+ }
584
+
585
+ function reparentShapes(
586
+ editor: Editor,
587
+ input: ReparentShapesInput,
588
+ options?: EditorCommandOptions,
589
+ ): void {
590
+ const ids = Array.from(new Set(input.ids));
591
+ if (ids.length === 0) {
592
+ return;
593
+ }
594
+
595
+ updateShapes(
596
+ editor,
597
+ ids.map((id) => ({ id, parentId: input.parentId })),
598
+ options,
599
+ );
600
+ }
601
+
602
+ function deleteShapes(
603
+ editor: Editor,
604
+ ids: ShapeId[],
605
+ options?: EditorCommandOptions,
606
+ ): void {
607
+ const source = options?.source ?? "user";
608
+ const idsWithDescendants = editor.getShapeIdsIncludingDescendants(ids);
609
+ const assetIdsToCleanup = editor.getUnreferencedAssetIdsAfterShapeDelete(
610
+ idsWithDescendants,
611
+ );
612
+
613
+ getEditorStore(editor).atomic(() => {
614
+ editor.sideEffects.runBeforeDelete(
615
+ "shape",
616
+ idsWithDescendants,
617
+ source,
618
+ );
619
+ getEditorStore(editor).remove(idsWithDescendants, source);
620
+ if (assetIdsToCleanup.length > 0) {
621
+ getEditorStore(editor).remove(assetIdsToCleanup, source);
622
+ }
623
+ editor.sideEffects.runAfterDelete("shape", idsWithDescendants, source);
624
+ }, source);
625
+ }
626
+
627
+ function createAsset(
628
+ editor: Editor,
629
+ input: CreateAssetInput,
630
+ options?: EditorCommandOptions,
631
+ ): AssetRecord {
632
+ const source = options?.source ?? "user";
633
+ const asset = editor.createAssetRecord(input);
634
+
635
+ getEditorStore(editor).atomic(() => {
636
+ getEditorStore(editor).put([asset], source);
637
+ }, source);
638
+
639
+ return asset;
640
+ }
641
+
642
+ function createAssetsFromRecords(
643
+ editor: Editor,
644
+ records: AssetRecord[],
645
+ options?: EditorCommandOptions,
646
+ ): AssetRecord[] {
647
+ const source = options?.source ?? "user";
648
+ if (records.length === 0) {
649
+ return [];
650
+ }
651
+
652
+ getEditorStore(editor).atomic(() => {
653
+ getEditorStore(editor).put(records, source);
654
+ }, source);
655
+
656
+ return records;
657
+ }
658
+
659
+ function updateAsset(
660
+ editor: Editor,
661
+ input: UpdateAssetInput,
662
+ options?: EditorCommandOptions,
663
+ ): AssetRecord | null {
664
+ const source = options?.source ?? "user";
665
+ const current = editor.getAsset(input.id);
666
+ if (!current) {
667
+ return null;
668
+ }
669
+
670
+ const next: AssetRecord = {
671
+ ...current,
672
+ props: input.props ? { ...current.props, ...input.props } : current.props,
673
+ meta: input.meta ?? current.meta,
674
+ };
675
+
676
+ getEditorStore(editor).atomic(() => {
677
+ getEditorStore(editor).put([next], source);
678
+ }, source);
679
+
680
+ return next;
681
+ }
682
+
683
+ function deleteAsset(
684
+ editor: Editor,
685
+ id: AssetId,
686
+ options?: EditorCommandOptions,
687
+ ): boolean {
688
+ const source = options?.source ?? "user";
689
+ if (!editor.getAsset(id)) {
690
+ return false;
691
+ }
692
+
693
+ getEditorStore(editor).atomic(() => {
694
+ getEditorStore(editor).remove([id], source);
695
+ }, source);
696
+
697
+ return true;
698
+ }
699
+
700
+ function canWriteBinding(editor: Editor, binding: BindingRecord): boolean {
701
+ return editor.bindings.canBind(binding);
702
+ }
703
+
704
+ function createBinding(
705
+ editor: Editor,
706
+ input: CreateBindingInput,
707
+ options?: EditorCommandOptions,
708
+ ): BindingRecord {
709
+ const source = options?.source ?? "user";
710
+ const binding = editor.createBindingRecord(input);
711
+ if (!canWriteBinding(editor, binding)) {
712
+ throw new Error(`Invalid binding endpoints for ${binding.type} binding`);
713
+ }
714
+
715
+ getEditorStore(editor).atomic(() => {
716
+ const conflictingIds = editor.bindings
717
+ .getConflictingBindings(binding)
718
+ .map((candidate) => candidate.id);
719
+ if (conflictingIds.length > 0) {
720
+ editor.bindings.cleanupBindings(conflictingIds, source);
721
+ }
722
+ getEditorStore(editor).put([binding], source);
723
+ editor.bindings.syncCreatedBinding(binding, source);
724
+ }, source);
725
+
726
+ return binding;
727
+ }
728
+
729
+ function updateBinding(
730
+ editor: Editor,
731
+ input: UpdateBindingInput,
732
+ options?: EditorCommandOptions,
733
+ ): BindingRecord | null {
734
+ const source = options?.source ?? "user";
735
+ const current = editor.getBinding(input.id);
736
+ if (!current) {
737
+ return null;
738
+ }
739
+
740
+ const util = editor.getBindingUtil(current);
741
+ const next: BindingRecord = {
742
+ ...current,
743
+ fromId: input.fromId ?? current.fromId,
744
+ toId: input.toId ?? current.toId,
745
+ props: input.props
746
+ ? util.validateProps({ ...current.props, ...input.props })
747
+ : current.props,
748
+ meta: input.meta ?? current.meta,
749
+ };
750
+ if (!canWriteBinding(editor, next)) {
751
+ throw new Error(`Invalid binding endpoints for ${next.type} binding`);
752
+ }
753
+
754
+ getEditorStore(editor).atomic(() => {
755
+ const conflictingIds = editor.bindings
756
+ .getConflictingBindings(next)
757
+ .map((candidate) => candidate.id);
758
+ if (conflictingIds.length > 0) {
759
+ editor.bindings.cleanupBindings(conflictingIds, source);
760
+ }
761
+ getEditorStore(editor).put([next], source);
762
+ editor.bindings.syncUpdatedBinding(current, next, source);
763
+ }, source);
764
+
765
+ return next;
766
+ }
767
+
768
+ function deleteBinding(
769
+ editor: Editor,
770
+ id: BindingId,
771
+ options?: EditorCommandOptions,
772
+ ): boolean {
773
+ const source = options?.source ?? "user";
774
+ const binding = editor.getBinding(id);
775
+ if (!binding) {
776
+ return false;
777
+ }
778
+
779
+ getEditorStore(editor).atomic(() => {
780
+ editor.bindings.cleanupBindings([binding.id], source);
781
+ getEditorStore(editor).remove([binding.id], source);
782
+ }, source);
783
+
784
+ return true;
785
+ }
786
+
787
+ function setCurrentPageId(
788
+ editor: Editor,
789
+ id: PageId,
790
+ options?: EditorCommandOptions,
791
+ ): void {
792
+ const source = options?.source ?? "system";
793
+ editor.setCurrentPage(id, source);
794
+ }
795
+
796
+ function setCamera(
797
+ editor: Editor,
798
+ input: SetCameraInput,
799
+ options?: EditorCommandOptions,
800
+ ): void {
801
+ const source = options?.source ?? "system";
802
+ editor.setCamera(input.camera, { pageId: input.pageId, source });
803
+ }
804
+
805
+ function setSelectedShapeIds(
806
+ editor: Editor,
807
+ ids: ShapeId[],
808
+ options?: EditorCommandOptions,
809
+ ): void {
810
+ const source = options?.source ?? "user";
811
+ editor.setSelectedShapeIds(ids, { source });
812
+ }
813
+
814
+ function setActiveTool(
815
+ editor: Editor,
816
+ toolId: string,
817
+ options?: EditorCommandOptions,
818
+ ): void {
819
+ const source = options?.source ?? "system";
820
+ editor.completeEditing(source);
821
+ editor.tools.setActiveTool(toolId);
822
+ editor.updateSession({ activeToolId: toolId }, source);
823
+ }
824
+
825
+ function setToolLocked(
826
+ editor: Editor,
827
+ locked: boolean,
828
+ options?: EditorCommandOptions,
829
+ ): void {
830
+ const source = options?.source ?? "system";
831
+ editor.tools.setToolLocked(locked);
832
+ editor.updateSession({ isToolLocked: locked }, source);
833
+ }