@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.
- package/README.md +145 -0
- package/_vendor/canvas-core/bindings/BindingUtil.ts +92 -0
- package/_vendor/canvas-core/bindings/BindingUtilRegistry.ts +22 -0
- package/_vendor/canvas-core/bindings/arrow/arrowBindingHelpers.ts +52 -0
- package/_vendor/canvas-core/contextMenu.ts +85 -0
- package/_vendor/canvas-core/editor/Editor.ts +2614 -0
- package/_vendor/canvas-core/editor/HistoryManager.ts +83 -0
- package/_vendor/canvas-core/editor/StateNode.ts +162 -0
- package/_vendor/canvas-core/editor/camera.ts +6 -0
- package/_vendor/canvas-core/editor/clipboard.ts +478 -0
- package/_vendor/canvas-core/editor/commands.ts +833 -0
- package/_vendor/canvas-core/editor/edgeScroll.ts +37 -0
- package/_vendor/canvas-core/editor/editorComputedHelpers.ts +257 -0
- package/_vendor/canvas-core/editor/editorSelectionTransforms.ts +116 -0
- package/_vendor/canvas-core/editor/events.ts +93 -0
- package/_vendor/canvas-core/editor/index.ts +12 -0
- package/_vendor/canvas-core/editor/interactions.ts +101 -0
- package/_vendor/canvas-core/editor/internal.ts +22 -0
- package/_vendor/canvas-core/editor/managers/BindingManager.ts +262 -0
- package/_vendor/canvas-core/editor/managers/CameraManager.ts +147 -0
- package/_vendor/canvas-core/editor/managers/ClipboardManager.ts +32 -0
- package/_vendor/canvas-core/editor/managers/DocumentSnapshotManager.ts +256 -0
- package/_vendor/canvas-core/editor/managers/InputsManager.ts +319 -0
- package/_vendor/canvas-core/editor/managers/InteractionTransientManager.ts +218 -0
- package/_vendor/canvas-core/editor/managers/QueryManager.ts +837 -0
- package/_vendor/canvas-core/editor/managers/RenderWindowManager.ts +347 -0
- package/_vendor/canvas-core/editor/managers/SelectionLayoutManager.ts +196 -0
- package/_vendor/canvas-core/editor/managers/SelectionManager.ts +98 -0
- package/_vendor/canvas-core/editor/managers/SelectionOverlayManager.ts +308 -0
- package/_vendor/canvas-core/editor/managers/ShapeEditingManager.ts +226 -0
- package/_vendor/canvas-core/editor/managers/ShapeGeometryManager.ts +162 -0
- package/_vendor/canvas-core/editor/managers/ShapeHierarchyManager.ts +797 -0
- package/_vendor/canvas-core/editor/managers/SideEffectManager.ts +83 -0
- package/_vendor/canvas-core/editor/managers/SnapManager.ts +433 -0
- package/_vendor/canvas-core/editor/managers/SnapSnapshotBuilder.ts +430 -0
- package/_vendor/canvas-core/editor/managers/SpatialIndexManager.ts +354 -0
- package/_vendor/canvas-core/editor/managers/ToolManager.ts +81 -0
- package/_vendor/canvas-core/editor/managers/queryState.ts +583 -0
- package/_vendor/canvas-core/editor/managers/selectionGeometry.ts +287 -0
- package/_vendor/canvas-core/editor/managers/shapeOrder.ts +350 -0
- package/_vendor/canvas-core/editor/managers/shapeReparenting.ts +160 -0
- package/_vendor/canvas-core/editor/managers/snapCalculations.ts +412 -0
- package/_vendor/canvas-core/editor/managers/snapGeometry.ts +202 -0
- package/_vendor/canvas-core/editor/managers/snapIndicators.ts +403 -0
- package/_vendor/canvas-core/editor/managers/snapTypes.ts +122 -0
- package/_vendor/canvas-core/editor/queries/shapeTransforms.ts +171 -0
- package/_vendor/canvas-core/editor/renderWindow.ts +439 -0
- package/_vendor/canvas-core/editor/resizeGeometry.ts +654 -0
- package/_vendor/canvas-core/editor/selection.ts +489 -0
- package/_vendor/canvas-core/editor/selectionHandleInteractions.ts +43 -0
- package/_vendor/canvas-core/editor/selectionOverlay.ts +567 -0
- package/_vendor/canvas-core/exports/integrity.ts +174 -0
- package/_vendor/canvas-core/exports/svg.ts +494 -0
- package/_vendor/canvas-core/geometry/Box.ts +80 -0
- package/_vendor/canvas-core/geometry/Ellipse2d.ts +67 -0
- package/_vendor/canvas-core/geometry/Geometry2d.ts +52 -0
- package/_vendor/canvas-core/geometry/Mat.ts +92 -0
- package/_vendor/canvas-core/geometry/Polyline2d.ts +63 -0
- package/_vendor/canvas-core/geometry/Rectangle2d.ts +64 -0
- package/_vendor/canvas-core/geometry/Vec.ts +123 -0
- package/_vendor/canvas-core/geometry/index.ts +13 -0
- package/_vendor/canvas-core/geometry/segments.ts +65 -0
- package/_vendor/canvas-core/index.ts +391 -0
- package/_vendor/canvas-core/plugins/index.ts +5 -0
- package/_vendor/canvas-core/plugins/types.ts +53 -0
- package/_vendor/canvas-core/reactivity.ts +16 -0
- package/_vendor/canvas-core/schema/records.ts +221 -0
- package/_vendor/canvas-core/schema/snapshots.ts +527 -0
- package/_vendor/canvas-core/shapes/ShapeUtil.ts +516 -0
- package/_vendor/canvas-core/shapes/ShapeUtilRegistry.ts +26 -0
- package/_vendor/canvas-core/shapes/capabilities.ts +67 -0
- package/_vendor/canvas-core/shapes/types.ts +20 -0
- package/_vendor/canvas-core/toolbar.ts +148 -0
- package/_vendor/canvas-core/tools/hand/HandTool.ts +75 -0
- package/_vendor/canvas-core/tools/index.ts +2 -0
- package/_vendor/canvas-core/tools/select/SelectTool.ts +33 -0
- package/_vendor/canvas-core/tools/select/selectContainment.ts +104 -0
- package/_vendor/canvas-core/tools/select/selectToolHelpers.ts +801 -0
- package/_vendor/canvas-core/tools/select/states/BrushingState.ts +145 -0
- package/_vendor/canvas-core/tools/select/states/DraggingSelectionHandleInteractionState.ts +116 -0
- package/_vendor/canvas-core/tools/select/states/IdleState.ts +159 -0
- package/_vendor/canvas-core/tools/select/states/PointingCanvasState.ts +41 -0
- package/_vendor/canvas-core/tools/select/states/PointingResizeHandleState.ts +78 -0
- package/_vendor/canvas-core/tools/select/states/PointingRotateHandleState.ts +64 -0
- package/_vendor/canvas-core/tools/select/states/PointingSelectionHandleInteractionState.ts +34 -0
- package/_vendor/canvas-core/tools/select/states/PointingShapeState.ts +140 -0
- package/_vendor/canvas-core/tools/select/states/ResizingState.ts +171 -0
- package/_vendor/canvas-core/tools/select/states/RotatingState.ts +124 -0
- package/_vendor/canvas-core/tools/select/states/SelectStateNode.ts +128 -0
- package/_vendor/canvas-core/tools/select/states/TranslatingState.ts +139 -0
- package/_vendor/canvas-core/tools/select/states/index.ts +11 -0
- package/_vendor/canvas-plugin-api/feature.ts +204 -0
- package/_vendor/canvas-plugin-api/index.ts +142 -0
- package/_vendor/canvas-product-react/api/apiRegistry.ts +35 -0
- package/_vendor/canvas-product-react/api/canvasProductApi.ts +422 -0
- package/_vendor/canvas-product-react/api/index.ts +31 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/clipboardService.ts +36 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/systemClipboard.ts +245 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/systemContextMenu.ts +396 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/useContextMenuSurface.ts +59 -0
- package/_vendor/canvas-product-react/capabilities/export/useSvgExport.ts +156 -0
- package/_vendor/canvas-product-react/capabilities/history/useHistoryControls.ts +23 -0
- package/_vendor/canvas-product-react/capabilities/pages/usePageControls.ts +41 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/systemToolbar.ts +490 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/useToolbarSurfaces.ts +92 -0
- package/_vendor/canvas-product-react/capabilities/zoom/useZoomControls.ts +27 -0
- package/_vendor/canvas-product-react/index.ts +84 -0
- package/_vendor/canvas-product-react/persistence/index.ts +18 -0
- package/_vendor/canvas-product-react/persistence/localSnapshotPersistence.ts +294 -0
- package/_vendor/canvas-product-react/runtime/CanvasProductRoot.tsx +250 -0
- package/_vendor/canvas-product-react/runtime/productDefinition.ts +72 -0
- package/_vendor/canvas-product-react/runtime/productServices.ts +96 -0
- package/_vendor/canvas-react/components/CanvasView.tsx +796 -0
- package/_vendor/canvas-react/components/OverlayLayer.tsx +879 -0
- package/_vendor/canvas-react/components/PageSpace.tsx +34 -0
- package/_vendor/canvas-react/components/ShapeLayer.tsx +428 -0
- package/_vendor/canvas-react/components/index.ts +4 -0
- package/_vendor/canvas-react/hooks/useEditor.ts +11 -0
- package/_vendor/canvas-react/hooks/useValue.ts +14 -0
- package/_vendor/canvas-react/host/CanvasRendererRegistryContext.tsx +14 -0
- package/_vendor/canvas-react/host/contextMenuRegistry.ts +61 -0
- package/_vendor/canvas-react/host/domEventGuards.ts +61 -0
- package/_vendor/canvas-react/host/index.ts +38 -0
- package/_vendor/canvas-react/host/pluginHost.ts +635 -0
- package/_vendor/canvas-react/host/rendererRegistry.tsx +58 -0
- package/_vendor/canvas-react/host/toolbarRegistry.ts +100 -0
- package/_vendor/canvas-react/index.ts +3 -0
- package/_vendor/plugin-arrow/ArrowBindingUtil.ts +239 -0
- package/_vendor/plugin-arrow/ArrowShapeUtil.ts +311 -0
- package/_vendor/plugin-arrow/ArrowTool.ts +208 -0
- package/_vendor/plugin-arrow/arrowGeometry.ts +441 -0
- package/_vendor/plugin-arrow/arrowTerminalBindingResolver.ts +253 -0
- package/_vendor/plugin-arrow/arrowTerminalCommands.ts +230 -0
- package/_vendor/plugin-arrow/canvas.tsx +92 -0
- package/_vendor/plugin-arrow/core.ts +409 -0
- package/_vendor/plugin-arrow/feature.ts +20 -0
- package/_vendor/plugin-arrow/index.ts +28 -0
- package/_vendor/plugin-arrow/selectionHandleInteractions.ts +154 -0
- package/_vendor/plugin-arrow/types.ts +63 -0
- package/_vendor/plugin-draw/DrawShapeRenderer.tsx +60 -0
- package/_vendor/plugin-draw/DrawShapeUtil.ts +372 -0
- package/_vendor/plugin-draw/DrawTool.ts +444 -0
- package/_vendor/plugin-draw/canvas.tsx +24 -0
- package/_vendor/plugin-draw/core.ts +515 -0
- package/_vendor/plugin-draw/drawGeometry.ts +491 -0
- package/_vendor/plugin-draw/drawHitTest.ts +271 -0
- package/_vendor/plugin-draw/drawInterpolation.ts +250 -0
- package/_vendor/plugin-draw/drawPath.ts +550 -0
- package/_vendor/plugin-draw/drawSegments.ts +106 -0
- package/_vendor/plugin-draw/drawSelectionTransform.ts +67 -0
- package/_vendor/plugin-draw/drawShapeGeometry.ts +307 -0
- package/_vendor/plugin-draw/drawStrokeGeometry.ts +454 -0
- package/_vendor/plugin-draw/feature.ts +20 -0
- package/_vendor/plugin-draw/index.ts +31 -0
- package/_vendor/plugin-draw/types.ts +36 -0
- package/_vendor/plugin-eraser/EraserTool.ts +297 -0
- package/_vendor/plugin-eraser/canvas.tsx +616 -0
- package/_vendor/plugin-eraser/core.ts +49 -0
- package/_vendor/plugin-eraser/feature.ts +20 -0
- package/_vendor/plugin-eraser/index.ts +4 -0
- package/_vendor/plugin-frame/FrameShapeUtil.ts +173 -0
- package/_vendor/plugin-frame/FrameTool.ts +225 -0
- package/_vendor/plugin-frame/canvas.tsx +75 -0
- package/_vendor/plugin-frame/core.ts +534 -0
- package/_vendor/plugin-frame/feature.ts +20 -0
- package/_vendor/plugin-frame/index.ts +6 -0
- package/_vendor/plugin-geo/GeoShapeUtil.ts +463 -0
- package/_vendor/plugin-geo/GeoTools.ts +247 -0
- package/_vendor/plugin-geo/canvas.tsx +90 -0
- package/_vendor/plugin-geo/core.ts +495 -0
- package/_vendor/plugin-geo/feature.ts +20 -0
- package/_vendor/plugin-geo/index.ts +7 -0
- package/_vendor/plugin-geo/types.ts +27 -0
- package/_vendor/plugin-group/GroupShapeUtil.ts +59 -0
- package/_vendor/plugin-group/canvas.tsx +59 -0
- package/_vendor/plugin-group/core.ts +40 -0
- package/_vendor/plugin-group/feature.ts +20 -0
- package/_vendor/plugin-group/index.ts +5 -0
- package/_vendor/plugin-image/ImageShapeUtil.ts +95 -0
- package/_vendor/plugin-image/canvas.tsx +212 -0
- package/_vendor/plugin-image/core.ts +542 -0
- package/_vendor/plugin-image/crop.ts +770 -0
- package/_vendor/plugin-image/cropInteractions.ts +350 -0
- package/_vendor/plugin-image/cropSession.ts +38 -0
- package/_vendor/plugin-image/feature.ts +20 -0
- package/_vendor/plugin-image/index.ts +29 -0
- package/_vendor/plugin-image/types.ts +55 -0
- package/_vendor/plugin-image-product-react/ImageImportController.tsx +143 -0
- package/_vendor/plugin-image-product-react/imageAssetService.ts +52 -0
- package/_vendor/plugin-image-product-react/imageBlobStore.ts +315 -0
- package/_vendor/plugin-image-product-react/imageHostActions.ts +438 -0
- package/_vendor/plugin-image-product-react/imageProductApi.ts +88 -0
- package/_vendor/plugin-image-product-react/imageToolbarHostBridge.ts +48 -0
- package/_vendor/plugin-image-product-react/imageToolbarRuntime.ts +21 -0
- package/_vendor/plugin-image-product-react/index.ts +60 -0
- package/_vendor/plugin-image-product-react/snapshotGuards.ts +33 -0
- package/_vendor/plugin-image-product-react/svgImageAssetInliner.ts +54 -0
- package/_vendor/plugin-image-product-react/useImageImport.ts +64 -0
- package/_vendor/plugin-laser/LaserTool.ts +154 -0
- package/_vendor/plugin-laser/canvas.tsx +645 -0
- package/_vendor/plugin-laser/core.ts +49 -0
- package/_vendor/plugin-laser/feature.ts +20 -0
- package/_vendor/plugin-laser/index.ts +4 -0
- package/_vendor/plugin-text/ArrowLabelBindingUtil.ts +336 -0
- package/_vendor/plugin-text/GeoLabelBindingUtil.ts +391 -0
- package/_vendor/plugin-text/TextShapeSvgExporter.ts +101 -0
- package/_vendor/plugin-text/TextShapeUtil.ts +284 -0
- package/_vendor/plugin-text/TextTool.ts +228 -0
- package/_vendor/plugin-text/canvas.tsx +115 -0
- package/_vendor/plugin-text/core.ts +422 -0
- package/_vendor/plugin-text/feature.ts +20 -0
- package/_vendor/plugin-text/host/RichTextEditingBox.tsx +144 -0
- package/_vendor/plugin-text/host/RichTextToolbar.tsx +266 -0
- package/_vendor/plugin-text/host/TiptapTextEditor.tsx +191 -0
- package/_vendor/plugin-text/host/richTextRendering.tsx +49 -0
- package/_vendor/plugin-text/host/textDomSelection.ts +93 -0
- package/_vendor/plugin-text/host/textEditingBoxStyle.ts +36 -0
- package/_vendor/plugin-text/host/textEntryFocus.ts +307 -0
- package/_vendor/plugin-text/host/textFontLoader.ts +149 -0
- package/_vendor/plugin-text/host/textMeasurement.ts +258 -0
- package/_vendor/plugin-text/host/textMeasurementSync.ts +77 -0
- package/_vendor/plugin-text/host/textRangeSelection.ts +134 -0
- package/_vendor/plugin-text/host/textShapeRendererRuntime.tsx +89 -0
- package/_vendor/plugin-text/host/textShapeSync.ts +173 -0
- package/_vendor/plugin-text/host/tiptapTextEditorController.ts +148 -0
- package/_vendor/plugin-text/index.ts +18 -0
- package/_vendor/plugin-text/richTextUtils.ts +259 -0
- package/_vendor/plugin-text/textInteractions.ts +366 -0
- package/_vendor/plugin-text/textLabelHelpers.ts +235 -0
- package/_vendor/plugin-text/textShapeHelpers.ts +123 -0
- package/_vendor/plugin-text/textStyle.ts +96 -0
- package/_vendor/plugin-text/textTypes.ts +48 -0
- package/_vendor/signals/atom.ts +74 -0
- package/_vendor/signals/computed.ts +132 -0
- package/_vendor/signals/core.ts +130 -0
- package/_vendor/signals/effect.ts +117 -0
- package/_vendor/signals/index.ts +9 -0
- package/_vendor/signals/types.ts +17 -0
- package/_vendor/store/Store.ts +171 -0
- package/_vendor/store/diff.ts +229 -0
- package/_vendor/store/history.ts +177 -0
- package/_vendor/store/index.ts +32 -0
- package/_vendor/store/types.ts +37 -0
- package/api/canvasKitApi.d.ts +29 -0
- package/index.css +3 -0
- package/index.d.ts +16 -0
- package/index.mjs +1 -0
- package/internal-modules.d.ts +187 -0
- package/package.json +48 -0
- package/product/Shell.d.ts +19 -0
- package/product/chromeContext.d.ts +70 -0
- package/product/createCanvasKitEditor.d.ts +6 -0
- package/product/index.d.ts +7 -0
- package/product/persistence.d.ts +3 -0
- package/product/product.d.ts +22 -0
- package/product/useCanvasClipboardShortcuts.d.ts +6 -0
- package/product-iyBbEPIs.mjs +4 -0
- package/product.mjs +1 -0
- package/standard/extensions.d.ts +1 -0
- package/standard/index.d.ts +3 -0
- package/standard/standardApi.d.ts +91 -0
- package/standard-BmrxwqpJ.mjs +44 -0
- 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
|
+
}
|