@tangle-network/agent-app 0.60.236 → 0.60.238
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/dist/{DesignCanvas-SNE3H3TH.js → DesignCanvas-OW3W2QXW.js} +2 -2
- package/dist/{DesignCanvasEditor-G5O75CUT.js → DesignCanvasEditor-TCHZF25W.js} +3 -3
- package/dist/VaultPane-RXL3WLA2.js +7 -0
- package/dist/assistant/index.js +2 -2
- package/dist/chat-routes/attachment-store.d.ts +28 -2
- package/dist/chat-routes/dispatch-parts.d.ts +12 -1
- package/dist/chat-routes/index.js +41 -2
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-store/index.js +3 -1
- package/dist/chat-store/index.js.map +1 -1
- package/dist/chat-store/parts.d.ts +6 -0
- package/dist/{chunk-BGDQ7245.js → chunk-2UIRJPC6.js} +2 -2
- package/dist/{chunk-I57SNMX4.js → chunk-EWOJATDS.js} +3 -3
- package/dist/{chunk-P2NJIDLE.js → chunk-JH3CKHF4.js} +380 -366
- package/dist/chunk-JH3CKHF4.js.map +1 -0
- package/dist/{chunk-E6UTFXKQ.js → chunk-PYG2N2JX.js} +12 -1
- package/dist/{chunk-E6UTFXKQ.js.map → chunk-PYG2N2JX.js.map} +1 -1
- package/dist/{chunk-MX3RI3MO.js → chunk-QW6PFYJS.js} +2 -2
- package/dist/{chunk-IDQU36M5.js → chunk-RL3Z747H.js} +708 -659
- package/dist/chunk-RL3Z747H.js.map +1 -0
- package/dist/{chunk-3KXYYAY4.js → chunk-VBWYH7UZ.js} +243 -232
- package/dist/chunk-VBWYH7UZ.js.map +1 -0
- package/dist/design-canvas-react/components/Toolbar.d.ts +1 -2
- package/dist/design-canvas-react/components/toolbar-fields.d.ts +65 -0
- package/dist/design-canvas-react/components/toolbar-page-controls.d.ts +20 -0
- package/dist/design-canvas-react/components/toolbar-selection-controls.d.ts +22 -0
- package/dist/design-canvas-react/components/use-workspace-keyboard.d.ts +24 -0
- package/dist/design-canvas-react/components/use-workspace-viewport.d.ts +16 -0
- package/dist/design-canvas-react/components/workspace-gesture-state.d.ts +10 -0
- package/dist/design-canvas-react/index.js +3 -3
- package/dist/design-canvas-react/lazy.js +1 -1
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +2 -2
- package/dist/vault/SourceEditor.d.ts +8 -0
- package/dist/vault/VaultCreateDialog.d.ts +14 -0
- package/dist/vault/VaultDocumentToolbar.d.ts +29 -0
- package/dist/vault/VaultPaneNavigation.d.ts +10 -0
- package/dist/vault/VaultPaneStates.d.ts +59 -0
- package/dist/vault/VaultTreePanel.d.ts +19 -0
- package/dist/vault/index.js +1 -1
- package/dist/vault/lazy.js +1 -1
- package/dist/vault/useVaultDockPlacement.d.ts +5 -0
- package/dist/vault/useVaultSearch.d.ts +13 -0
- package/dist/vault/vault-tree-paths.d.ts +12 -0
- package/dist/web-react/index.js +2 -2
- package/package.json +1 -1
- package/dist/VaultPane-QEG35UAZ.js +0 -7
- package/dist/chunk-3KXYYAY4.js.map +0 -1
- package/dist/chunk-IDQU36M5.js.map +0 -1
- package/dist/chunk-P2NJIDLE.js.map +0 -1
- /package/dist/{DesignCanvas-SNE3H3TH.js.map → DesignCanvas-OW3W2QXW.js.map} +0 -0
- /package/dist/{DesignCanvasEditor-G5O75CUT.js.map → DesignCanvasEditor-TCHZF25W.js.map} +0 -0
- /package/dist/{VaultPane-QEG35UAZ.js.map → VaultPane-RXL3WLA2.js.map} +0 -0
- /package/dist/{chunk-BGDQ7245.js.map → chunk-2UIRJPC6.js.map} +0 -0
- /package/dist/{chunk-I57SNMX4.js.map → chunk-EWOJATDS.js.map} +0 -0
- /package/dist/{chunk-MX3RI3MO.js.map → chunk-QW6PFYJS.js.map} +0 -0
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
DesignCanvas,
|
|
5
5
|
PlusGlyph,
|
|
6
6
|
ShapesGlyph
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VBWYH7UZ.js";
|
|
8
8
|
import {
|
|
9
9
|
lightTheme
|
|
10
10
|
} from "./chunk-UTF7H6BK.js";
|
|
@@ -40,14 +40,92 @@ import {
|
|
|
40
40
|
// src/design-canvas-react/components/Workspace.tsx
|
|
41
41
|
import {
|
|
42
42
|
useCallback,
|
|
43
|
-
useEffect as
|
|
44
|
-
useLayoutEffect,
|
|
43
|
+
useEffect as useEffect5,
|
|
45
44
|
useMemo,
|
|
46
|
-
useRef as
|
|
47
|
-
useState as
|
|
45
|
+
useRef as useRef6,
|
|
46
|
+
useState as useState3
|
|
48
47
|
} from "react";
|
|
49
48
|
import { Stage, Layer as Layer4, Rect as Rect2, Group as Group3 } from "react-konva";
|
|
50
49
|
|
|
50
|
+
// src/design-canvas-react/components/CanvasEmptyState.tsx
|
|
51
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
52
|
+
function SparkleGlyph({ className }) {
|
|
53
|
+
return /* @__PURE__ */ jsx("svg", { className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M12 3v3m0 12v3M3 12h3m12 0h3M5.6 5.6l2.1 2.1m8.6 8.6 2.1 2.1m0-12.8-2.1 2.1M7.7 16.3l-2.1 2.1" }) });
|
|
54
|
+
}
|
|
55
|
+
function CanvasEmptyState({
|
|
56
|
+
onStartTemplate,
|
|
57
|
+
onAddElement,
|
|
58
|
+
onAskAgent,
|
|
59
|
+
title = "Start your design",
|
|
60
|
+
subtitle = "Drop in a template, add an element by hand, or let the agent draft it for you.",
|
|
61
|
+
className
|
|
62
|
+
}) {
|
|
63
|
+
const doors = [
|
|
64
|
+
{
|
|
65
|
+
key: "template",
|
|
66
|
+
label: "Start with a template",
|
|
67
|
+
hint: "A headline, shape, or block to build on",
|
|
68
|
+
Icon: ShapesGlyph,
|
|
69
|
+
onClick: onStartTemplate
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
key: "element",
|
|
73
|
+
label: "Add an element",
|
|
74
|
+
hint: "Place text on the page and edit it",
|
|
75
|
+
Icon: PlusGlyph,
|
|
76
|
+
onClick: onAddElement
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
if (onAskAgent) {
|
|
80
|
+
doors.push({
|
|
81
|
+
key: "agent",
|
|
82
|
+
label: "Ask the agent",
|
|
83
|
+
hint: "Describe what you want made",
|
|
84
|
+
Icon: SparkleGlyph,
|
|
85
|
+
onClick: onAskAgent
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return (
|
|
89
|
+
// Overlay is non-interactive so empty-space clicks reach the canvas; the
|
|
90
|
+
// centered card re-enables pointer events for its own controls.
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
"div",
|
|
93
|
+
{
|
|
94
|
+
className: `pointer-events-none absolute inset-0 z-20 flex items-center justify-center p-4 ${className ?? ""}`,
|
|
95
|
+
role: "group",
|
|
96
|
+
"aria-label": "Start your design",
|
|
97
|
+
children: /* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex w-full max-w-lg flex-col items-center gap-5 rounded-xl border border-[var(--card-edge)] bg-[hsl(var(--popover))] px-6 py-7 text-center shadow-[var(--shadow-overlay)] sm:px-8", children: [
|
|
98
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-[var(--text-muted)]", children: [
|
|
99
|
+
/* @__PURE__ */ jsx(BrandKnot, { size: 22, className: "shrink-0" }),
|
|
100
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold uppercase tracking-[0.05em]", children: "Tangle Design" })
|
|
101
|
+
] }),
|
|
102
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
|
|
103
|
+
/* @__PURE__ */ jsx("h2", { className: "text-xl font-semibold text-[var(--text-primary)]", children: title }),
|
|
104
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm leading-5 text-[var(--text-secondary)]", children: subtitle })
|
|
105
|
+
] }),
|
|
106
|
+
/* @__PURE__ */ jsx("div", { className: "grid w-full gap-2 sm:grid-cols-3", children: doors.map(({ key, label, hint, Icon, onClick }) => /* @__PURE__ */ jsxs(
|
|
107
|
+
"button",
|
|
108
|
+
{
|
|
109
|
+
type: "button",
|
|
110
|
+
onClick,
|
|
111
|
+
className: "group flex min-h-[44px] flex-col items-center gap-2 rounded-lg border border-[var(--border-default)] bg-[hsl(var(--card))] px-3 py-4 text-center transition-colors hover:border-[var(--brand-primary)]",
|
|
112
|
+
children: [
|
|
113
|
+
/* @__PURE__ */ jsx("span", { className: "flex h-9 w-9 items-center justify-center rounded-full bg-[color-mix(in_srgb,var(--brand-primary)_10%,transparent)] text-[var(--brand-primary)] transition-colors group-hover:bg-[color-mix(in_srgb,var(--brand-primary)_15%,transparent)]", children: /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4" }) }),
|
|
114
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-[var(--text-primary)]", children: label }),
|
|
115
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs leading-4 text-[var(--text-muted)]", children: hint })
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
key
|
|
119
|
+
)) })
|
|
120
|
+
] })
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/design-canvas-react/components/use-workspace-viewport.ts
|
|
127
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
128
|
+
|
|
51
129
|
// src/design-canvas-react/export.ts
|
|
52
130
|
function clearNodeCaches(stage) {
|
|
53
131
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
@@ -141,85 +219,75 @@ function exportDocumentJson(document) {
|
|
|
141
219
|
return JSON.stringify(document, null, 2);
|
|
142
220
|
}
|
|
143
221
|
|
|
144
|
-
// src/design-canvas-react/components/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
key: "element",
|
|
167
|
-
label: "Add an element",
|
|
168
|
-
hint: "Place text on the page and edit it",
|
|
169
|
-
Icon: PlusGlyph,
|
|
170
|
-
onClick: onAddElement
|
|
171
|
-
}
|
|
172
|
-
];
|
|
173
|
-
if (onAskAgent) {
|
|
174
|
-
doors.push({
|
|
175
|
-
key: "agent",
|
|
176
|
-
label: "Ask the agent",
|
|
177
|
-
hint: "Describe what you want made",
|
|
178
|
-
Icon: SparkleGlyph,
|
|
179
|
-
onClick: onAskAgent
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
return (
|
|
183
|
-
// Overlay is non-interactive so empty-space clicks reach the canvas; the
|
|
184
|
-
// centered card re-enables pointer events for its own controls.
|
|
185
|
-
/* @__PURE__ */ jsx(
|
|
186
|
-
"div",
|
|
187
|
-
{
|
|
188
|
-
className: `pointer-events-none absolute inset-0 z-20 flex items-center justify-center p-4 ${className ?? ""}`,
|
|
189
|
-
role: "group",
|
|
190
|
-
"aria-label": "Start your design",
|
|
191
|
-
children: /* @__PURE__ */ jsxs("div", { className: "pointer-events-auto flex w-full max-w-lg flex-col items-center gap-5 rounded-xl border border-[var(--card-edge)] bg-[hsl(var(--popover))] px-6 py-7 text-center shadow-[var(--shadow-overlay)] sm:px-8", children: [
|
|
192
|
-
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-[var(--text-muted)]", children: [
|
|
193
|
-
/* @__PURE__ */ jsx(BrandKnot, { size: 22, className: "shrink-0" }),
|
|
194
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold uppercase tracking-[0.05em]", children: "Tangle Design" })
|
|
195
|
-
] }),
|
|
196
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
|
|
197
|
-
/* @__PURE__ */ jsx("h2", { className: "text-xl font-semibold text-[var(--text-primary)]", children: title }),
|
|
198
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm leading-5 text-[var(--text-secondary)]", children: subtitle })
|
|
199
|
-
] }),
|
|
200
|
-
/* @__PURE__ */ jsx("div", { className: "grid w-full gap-2 sm:grid-cols-3", children: doors.map(({ key, label, hint, Icon, onClick }) => /* @__PURE__ */ jsxs(
|
|
201
|
-
"button",
|
|
202
|
-
{
|
|
203
|
-
type: "button",
|
|
204
|
-
onClick,
|
|
205
|
-
className: "group flex min-h-[44px] flex-col items-center gap-2 rounded-lg border border-[var(--border-default)] bg-[hsl(var(--card))] px-3 py-4 text-center transition-colors hover:border-[var(--brand-primary)]",
|
|
206
|
-
children: [
|
|
207
|
-
/* @__PURE__ */ jsx("span", { className: "flex h-9 w-9 items-center justify-center rounded-full bg-[color-mix(in_srgb,var(--brand-primary)_10%,transparent)] text-[var(--brand-primary)] transition-colors group-hover:bg-[color-mix(in_srgb,var(--brand-primary)_15%,transparent)]", children: /* @__PURE__ */ jsx(Icon, { className: "h-4 w-4" }) }),
|
|
208
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-[var(--text-primary)]", children: label }),
|
|
209
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs leading-4 text-[var(--text-muted)]", children: hint })
|
|
210
|
-
]
|
|
211
|
-
},
|
|
212
|
-
key
|
|
213
|
-
)) })
|
|
214
|
-
] })
|
|
222
|
+
// src/design-canvas-react/components/use-workspace-viewport.ts
|
|
223
|
+
function useWorkspaceViewport({ stack, activePage, activePageId, fitOnMount, onReady, onFitRef, onExport, onExportRef, zoomPanMath }) {
|
|
224
|
+
const containerRef = useRef(null);
|
|
225
|
+
const [containerSize, setContainerSize] = useState({ width: 800, height: 600 });
|
|
226
|
+
const autoFitRef = useRef(true);
|
|
227
|
+
const lastAutoFitRef = useRef(null);
|
|
228
|
+
const readyRef = useRef(false);
|
|
229
|
+
useLayoutEffect(() => {
|
|
230
|
+
const el = containerRef.current;
|
|
231
|
+
if (!el) return;
|
|
232
|
+
const ro = new ResizeObserver((entries) => {
|
|
233
|
+
const entry = entries[0];
|
|
234
|
+
if (!entry) return;
|
|
235
|
+
const { width, height } = entry.contentRect;
|
|
236
|
+
setContainerSize({ width, height });
|
|
237
|
+
if (width <= 0 || height <= 0) return;
|
|
238
|
+
const view = stack.getState();
|
|
239
|
+
const last = lastAutoFitRef.current;
|
|
240
|
+
if (last && (view.zoom !== last.zoom || view.panX !== last.panX || view.panY !== last.panY)) {
|
|
241
|
+
autoFitRef.current = false;
|
|
215
242
|
}
|
|
216
|
-
|
|
217
|
-
|
|
243
|
+
if (autoFitRef.current && fitOnMount && activePage.width > 0 && activePage.height > 0 && (!last || last.width !== width || last.height !== height)) {
|
|
244
|
+
const fit = zoomPanMath.fitPage(activePage, { width, height });
|
|
245
|
+
stack.setView(fit);
|
|
246
|
+
lastAutoFitRef.current = { ...fit, width, height };
|
|
247
|
+
}
|
|
248
|
+
if (!readyRef.current) {
|
|
249
|
+
readyRef.current = true;
|
|
250
|
+
onReady?.();
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
ro.observe(el);
|
|
254
|
+
return () => ro.disconnect();
|
|
255
|
+
}, [activePage, fitOnMount, onReady, stack, zoomPanMath]);
|
|
256
|
+
const stageRef = useRef(null);
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
if (!onFitRef) return;
|
|
259
|
+
onFitRef.current = () => {
|
|
260
|
+
const { width, height } = containerSize;
|
|
261
|
+
if (width <= 0 || height <= 0) return;
|
|
262
|
+
const view = zoomPanMath.fitPage(activePage, { width, height });
|
|
263
|
+
stack.setView(view);
|
|
264
|
+
};
|
|
265
|
+
return () => {
|
|
266
|
+
if (onFitRef.current !== null) onFitRef.current = null;
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
if (!onExportRef || !onExport) return;
|
|
271
|
+
onExportRef.current = ({ format, pixelRatio }) => {
|
|
272
|
+
const stage = stageRef.current;
|
|
273
|
+
if (!stage) return;
|
|
274
|
+
void (async () => {
|
|
275
|
+
const dataUrl = await exportPageDataUrl(stage, activePage, { format, pixelRatio });
|
|
276
|
+
await onExport({ pageId: activePageId, format, dataUrl, pixelRatio });
|
|
277
|
+
})();
|
|
278
|
+
};
|
|
279
|
+
return () => {
|
|
280
|
+
if (onExportRef.current !== null) onExportRef.current = null;
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
return { containerRef, containerSize, stageRef };
|
|
218
284
|
}
|
|
219
285
|
|
|
220
|
-
// src/design-canvas-react/components/
|
|
221
|
-
import {
|
|
222
|
-
|
|
286
|
+
// src/design-canvas-react/components/use-workspace-keyboard.ts
|
|
287
|
+
import { useRef as useRef2 } from "react";
|
|
288
|
+
|
|
289
|
+
// src/design-canvas-react/components/workspace-gesture-state.ts
|
|
290
|
+
var NO_MARQUEE = { active: false, startDocX: 0, startDocY: 0, endDocX: 0, endDocY: 0 };
|
|
223
291
|
|
|
224
292
|
// src/design-canvas-react/components/transform-math.ts
|
|
225
293
|
function bakeRectTransform(node) {
|
|
@@ -303,26 +371,190 @@ function snapRotation(angleDeg, thresholdDeg = 5) {
|
|
|
303
371
|
best = snap % 360;
|
|
304
372
|
}
|
|
305
373
|
}
|
|
306
|
-
return bestDist <= thresholdDeg ? best : normalized;
|
|
307
|
-
}
|
|
308
|
-
function nudgeDelta(key, shift) {
|
|
309
|
-
const step = shift ? 10 : 1;
|
|
310
|
-
switch (key) {
|
|
311
|
-
case "ArrowLeft":
|
|
312
|
-
return { dx: -step, dy: 0 };
|
|
313
|
-
case "ArrowRight":
|
|
314
|
-
return { dx: step, dy: 0 };
|
|
315
|
-
case "ArrowUp":
|
|
316
|
-
return { dx: 0, dy: -step };
|
|
317
|
-
case "ArrowDown":
|
|
318
|
-
return { dx: 0, dy: step };
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
function gridVisible(gridSize, zoom, minScreenPx = 4) {
|
|
322
|
-
return gridSize * zoom >= minScreenPx;
|
|
374
|
+
return bestDist <= thresholdDeg ? best : normalized;
|
|
375
|
+
}
|
|
376
|
+
function nudgeDelta(key, shift) {
|
|
377
|
+
const step = shift ? 10 : 1;
|
|
378
|
+
switch (key) {
|
|
379
|
+
case "ArrowLeft":
|
|
380
|
+
return { dx: -step, dy: 0 };
|
|
381
|
+
case "ArrowRight":
|
|
382
|
+
return { dx: step, dy: 0 };
|
|
383
|
+
case "ArrowUp":
|
|
384
|
+
return { dx: 0, dy: -step };
|
|
385
|
+
case "ArrowDown":
|
|
386
|
+
return { dx: 0, dy: step };
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function gridVisible(gridSize, zoom, minScreenPx = 4) {
|
|
390
|
+
return gridSize * zoom >= minScreenPx;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/design-canvas-react/components/use-workspace-keyboard.ts
|
|
394
|
+
var DUPLICATE_OFFSET = 10;
|
|
395
|
+
function useWorkspaceKeyboard({ stack, state, activePage, canWrite, onApplyOperations, persist, gestureRef, spaceHeldRef, setMarquee, setActiveSnap, editingElementId, setEditingElementId }) {
|
|
396
|
+
const { document, activePageId, selectedElementIds } = state;
|
|
397
|
+
const nudgeHeldRef = useRef2(null);
|
|
398
|
+
function handleKeyDown(e) {
|
|
399
|
+
if (e.key === " ") {
|
|
400
|
+
e.preventDefault();
|
|
401
|
+
spaceHeldRef.current = true;
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const mod = e.metaKey || e.ctrlKey;
|
|
405
|
+
if (e.key === "Escape") {
|
|
406
|
+
e.preventDefault();
|
|
407
|
+
if (gestureRef.current !== "idle") {
|
|
408
|
+
gestureRef.current = "idle";
|
|
409
|
+
setMarquee(NO_MARQUEE);
|
|
410
|
+
setActiveSnap(null);
|
|
411
|
+
} else if (editingElementId) {
|
|
412
|
+
setEditingElementId(null);
|
|
413
|
+
} else {
|
|
414
|
+
stack.setView({ selectedElementIds: [] });
|
|
415
|
+
}
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (editingElementId) return;
|
|
419
|
+
if ((e.key === "Delete" || e.key === "Backspace") && selectedElementIds.length > 0) {
|
|
420
|
+
e.preventDefault();
|
|
421
|
+
e.stopPropagation();
|
|
422
|
+
for (const id of [...selectedElementIds]) {
|
|
423
|
+
try {
|
|
424
|
+
persist(deleteElementCommand({ document, pageId: activePageId, elementId: id }));
|
|
425
|
+
} catch {
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
stack.setView({ selectedElementIds: [] });
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (mod && e.key === "z" && !e.shiftKey) {
|
|
432
|
+
e.preventDefault();
|
|
433
|
+
e.stopPropagation();
|
|
434
|
+
if (stack.canUndo()) stack.undo();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (mod && (e.key === "z" && e.shiftKey || e.key === "y")) {
|
|
438
|
+
e.preventDefault();
|
|
439
|
+
e.stopPropagation();
|
|
440
|
+
if (stack.canRedo()) stack.redo();
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (mod && e.key === "a") {
|
|
444
|
+
e.preventDefault();
|
|
445
|
+
const ids = activePage.elements.filter((el) => !el.locked && el.visible).map((el) => el.id);
|
|
446
|
+
stack.setView({ selectedElementIds: ids });
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (mod && e.key === "d" && selectedElementIds.length > 0) {
|
|
450
|
+
e.preventDefault();
|
|
451
|
+
for (const id of selectedElementIds) {
|
|
452
|
+
const found = findElement(activePage, id);
|
|
453
|
+
if (!found) continue;
|
|
454
|
+
const clone = {
|
|
455
|
+
...structuredClone(found.element),
|
|
456
|
+
id: crypto.randomUUID(),
|
|
457
|
+
x: found.element.x + DUPLICATE_OFFSET,
|
|
458
|
+
y: found.element.y + DUPLICATE_OFFSET
|
|
459
|
+
};
|
|
460
|
+
persist(addElementCommand({ pageId: activePageId, element: clone }));
|
|
461
|
+
}
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (mod && !e.shiftKey && e.key === "g" && selectedElementIds.length >= 2) {
|
|
465
|
+
e.preventDefault();
|
|
466
|
+
persist(groupElementsCommand({
|
|
467
|
+
document,
|
|
468
|
+
pageId: activePageId,
|
|
469
|
+
elementIds: selectedElementIds,
|
|
470
|
+
groupId: crypto.randomUUID()
|
|
471
|
+
}));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (mod && e.shiftKey && e.key === "g" && selectedElementIds.length === 1) {
|
|
475
|
+
e.preventDefault();
|
|
476
|
+
const id = selectedElementIds[0];
|
|
477
|
+
persist(ungroupElementCommand({ document, pageId: activePageId, groupId: id }));
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key) && selectedElementIds.length > 0) {
|
|
481
|
+
e.preventDefault();
|
|
482
|
+
const key = e.key;
|
|
483
|
+
if (nudgeHeldRef.current && nudgeHeldRef.current.key !== key) {
|
|
484
|
+
flushNudge();
|
|
485
|
+
}
|
|
486
|
+
if (!nudgeHeldRef.current) {
|
|
487
|
+
const origins = /* @__PURE__ */ new Map();
|
|
488
|
+
for (const id of selectedElementIds) {
|
|
489
|
+
const found = findElement(activePage, id);
|
|
490
|
+
if (found) origins.set(id, { x: found.element.x, y: found.element.y });
|
|
491
|
+
}
|
|
492
|
+
nudgeHeldRef.current = { key, ids: selectedElementIds.slice(), origin: origins };
|
|
493
|
+
}
|
|
494
|
+
const { dx, dy } = nudgeDelta(key, e.shiftKey);
|
|
495
|
+
const entries = [];
|
|
496
|
+
for (const [id, orig] of nudgeHeldRef.current.origin) {
|
|
497
|
+
const found = findElement(activePage, id);
|
|
498
|
+
if (!found) continue;
|
|
499
|
+
entries.push({
|
|
500
|
+
pageId: activePageId,
|
|
501
|
+
elementId: id,
|
|
502
|
+
attrs: { x: found.element.x + dx, y: found.element.y + dy },
|
|
503
|
+
priorAttrs: { x: found.element.x, y: found.element.y }
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
if (entries.length > 0) {
|
|
507
|
+
stack.execute(multiSetAttrsCommand(entries));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function handleKeyUp(e) {
|
|
512
|
+
if (e.key === " ") {
|
|
513
|
+
spaceHeldRef.current = false;
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
517
|
+
flushNudge();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function flushNudge() {
|
|
521
|
+
const held = nudgeHeldRef.current;
|
|
522
|
+
if (!held) return;
|
|
523
|
+
nudgeHeldRef.current = null;
|
|
524
|
+
if (!canWrite || held.ids.length === 0) return;
|
|
525
|
+
const entries = [];
|
|
526
|
+
for (const id of held.ids) {
|
|
527
|
+
const orig = held.origin.get(id);
|
|
528
|
+
const found = findElement(activePage, id);
|
|
529
|
+
if (!orig || !found) continue;
|
|
530
|
+
entries.push({
|
|
531
|
+
pageId: activePageId,
|
|
532
|
+
elementId: id,
|
|
533
|
+
attrs: { x: found.element.x, y: found.element.y },
|
|
534
|
+
priorAttrs: { x: orig.x, y: orig.y }
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
if (entries.length > 0) {
|
|
538
|
+
onApplyOperations(multiSetAttrsCommand(entries).operations()).catch(() => {
|
|
539
|
+
for (const [id, orig] of held.origin) {
|
|
540
|
+
const found = findElement(activePage, id);
|
|
541
|
+
if (!found) continue;
|
|
542
|
+
persist(setAttrsCommand({
|
|
543
|
+
pageId: activePageId,
|
|
544
|
+
elementId: id,
|
|
545
|
+
attrs: { x: orig.x, y: orig.y },
|
|
546
|
+
priorAttrs: { x: found.element.x, y: found.element.y }
|
|
547
|
+
}));
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return { handleKeyDown, handleKeyUp };
|
|
323
553
|
}
|
|
324
554
|
|
|
325
555
|
// src/design-canvas-react/components/ElementNode.tsx
|
|
556
|
+
import { memo, useEffect as useEffect2, useRef as useRef3, useState as useState2 } from "react";
|
|
557
|
+
import { Group, Rect, Ellipse, Line, Text, Image as KonvaImage } from "react-konva";
|
|
326
558
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
327
559
|
var IMAGE_CACHE_MAX = 256;
|
|
328
560
|
var imageCache = /* @__PURE__ */ new Map();
|
|
@@ -334,8 +566,8 @@ function imageCacheSet(src, img) {
|
|
|
334
566
|
imageCache.set(src, img);
|
|
335
567
|
}
|
|
336
568
|
function useImage(src) {
|
|
337
|
-
const [, setVersion] =
|
|
338
|
-
|
|
569
|
+
const [, setVersion] = useState2(0);
|
|
570
|
+
useEffect2(() => {
|
|
339
571
|
if (imageCache.has(src)) return;
|
|
340
572
|
const img = new window.Image();
|
|
341
573
|
img.crossOrigin = "anonymous";
|
|
@@ -375,9 +607,9 @@ var ElementNode = memo(ElementNodeImpl);
|
|
|
375
607
|
function useDragBindings(props, originX, originY) {
|
|
376
608
|
const { element, onClick, onDragStart, onDragMove, onDragEnd, onDoubleClick } = props;
|
|
377
609
|
const isDraggable = !element.locked && !!onDragEnd;
|
|
378
|
-
const originRef =
|
|
610
|
+
const originRef = useRef3({ x: originX, y: originY });
|
|
379
611
|
originRef.current = { x: originX, y: originY };
|
|
380
|
-
const [dragging, setDragging] =
|
|
612
|
+
const [dragging, setDragging] = useState2(false);
|
|
381
613
|
return {
|
|
382
614
|
draggable: isDraggable,
|
|
383
615
|
// locked elements still receive click for selection; listening must be true.
|
|
@@ -399,7 +631,7 @@ function useDragBindings(props, originX, originY) {
|
|
|
399
631
|
};
|
|
400
632
|
}
|
|
401
633
|
function useNodeCache(ref, isSelected, dragging, zoom, invalidateKey) {
|
|
402
|
-
|
|
634
|
+
useEffect2(() => {
|
|
403
635
|
const node = ref.current;
|
|
404
636
|
if (!node) return;
|
|
405
637
|
if (isSelected || dragging) {
|
|
@@ -415,7 +647,7 @@ function useNodeCache(ref, isSelected, dragging, zoom, invalidateKey) {
|
|
|
415
647
|
}
|
|
416
648
|
function RectNode({ element, ...rest }) {
|
|
417
649
|
const { dragging, ...drag } = useDragBindings({ element, ...rest }, element.x, element.y);
|
|
418
|
-
const ref =
|
|
650
|
+
const ref = useRef3(null);
|
|
419
651
|
useNodeCache(ref, rest.isSelected, dragging, rest.zoom, element);
|
|
420
652
|
return /* @__PURE__ */ jsx2(
|
|
421
653
|
Rect,
|
|
@@ -439,7 +671,7 @@ function RectNode({ element, ...rest }) {
|
|
|
439
671
|
function EllipseNode({ element, ...rest }) {
|
|
440
672
|
const { x: cx, y: cy, radiusX, radiusY } = ellipseCenterFromTopLeft(element);
|
|
441
673
|
const { dragging, ...drag } = useDragBindings({ element, ...rest }, element.x, element.y);
|
|
442
|
-
const ref =
|
|
674
|
+
const ref = useRef3(null);
|
|
443
675
|
useNodeCache(ref, rest.isSelected, dragging, rest.zoom, element);
|
|
444
676
|
return /* @__PURE__ */ jsx2(
|
|
445
677
|
Ellipse,
|
|
@@ -461,7 +693,7 @@ function EllipseNode({ element, ...rest }) {
|
|
|
461
693
|
}
|
|
462
694
|
function LineNode({ element, ...rest }) {
|
|
463
695
|
const { dragging, ...drag } = useDragBindings({ element, ...rest }, element.x, element.y);
|
|
464
|
-
const ref =
|
|
696
|
+
const ref = useRef3(null);
|
|
465
697
|
useNodeCache(ref, rest.isSelected, dragging, rest.zoom, element);
|
|
466
698
|
return /* @__PURE__ */ jsx2(
|
|
467
699
|
Line,
|
|
@@ -488,7 +720,7 @@ var FONT_STYLE_MAP = {
|
|
|
488
720
|
};
|
|
489
721
|
function TextNode({ element, ...rest }) {
|
|
490
722
|
const { dragging, ...drag } = useDragBindings({ element, ...rest }, element.x, element.y);
|
|
491
|
-
const ref =
|
|
723
|
+
const ref = useRef3(null);
|
|
492
724
|
useNodeCache(ref, rest.isSelected, dragging, rest.zoom, element);
|
|
493
725
|
const { fontStyle, fontWeight } = FONT_STYLE_MAP[element.fontStyle];
|
|
494
726
|
return /* @__PURE__ */ jsx2(
|
|
@@ -517,7 +749,7 @@ function ImageNode({ element, ...rest }) {
|
|
|
517
749
|
const render = rest.render ?? lightTheme.canvasRender;
|
|
518
750
|
const img = useImage(element.src);
|
|
519
751
|
const { dragging, ...drag } = useDragBindings({ element, ...rest }, element.x, element.y);
|
|
520
|
-
const ref =
|
|
752
|
+
const ref = useRef3(null);
|
|
521
753
|
const imgReady = !!img && img.complete && img.naturalWidth > 0;
|
|
522
754
|
useNodeCache(
|
|
523
755
|
ref,
|
|
@@ -592,7 +824,7 @@ function VideoNode({ element, ...rest }) {
|
|
|
592
824
|
const render = rest.render ?? lightTheme.canvasRender;
|
|
593
825
|
const img = useImage(element.posterSrc ?? "");
|
|
594
826
|
const { dragging, ...drag } = useDragBindings({ element, ...rest }, element.x, element.y);
|
|
595
|
-
const ref =
|
|
827
|
+
const ref = useRef3(null);
|
|
596
828
|
const posterReady = !!element.posterSrc && !!img && img.complete && img.naturalWidth > 0;
|
|
597
829
|
useNodeCache(
|
|
598
830
|
ref,
|
|
@@ -654,7 +886,7 @@ function GroupNode({ element, ...rest }) {
|
|
|
654
886
|
}
|
|
655
887
|
|
|
656
888
|
// src/design-canvas-react/components/SelectionLayer.tsx
|
|
657
|
-
import { useEffect as
|
|
889
|
+
import { useEffect as useEffect3, useRef as useRef4 } from "react";
|
|
658
890
|
import { Layer, Transformer } from "react-konva";
|
|
659
891
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
660
892
|
var MIN_SIZE = 4;
|
|
@@ -667,8 +899,8 @@ function SelectionLayer({
|
|
|
667
899
|
pageId,
|
|
668
900
|
render = lightTheme.canvasRender
|
|
669
901
|
}) {
|
|
670
|
-
const trRef =
|
|
671
|
-
|
|
902
|
+
const trRef = useRef4(null);
|
|
903
|
+
useEffect3(() => {
|
|
672
904
|
const tr = trRef.current;
|
|
673
905
|
const stage = stageRef.current;
|
|
674
906
|
if (!tr || !stage) return;
|
|
@@ -928,7 +1160,7 @@ function SnapGuidesOverlay({
|
|
|
928
1160
|
}
|
|
929
1161
|
|
|
930
1162
|
// src/design-canvas-react/components/InlineTextEditor.tsx
|
|
931
|
-
import { useEffect as
|
|
1163
|
+
import { useEffect as useEffect4, useRef as useRef5 } from "react";
|
|
932
1164
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
933
1165
|
function InlineTextEditor({
|
|
934
1166
|
element,
|
|
@@ -938,7 +1170,7 @@ function InlineTextEditor({
|
|
|
938
1170
|
onCommit,
|
|
939
1171
|
onCancel
|
|
940
1172
|
}) {
|
|
941
|
-
const ref =
|
|
1173
|
+
const ref = useRef5(null);
|
|
942
1174
|
const pos = computeTextOverlayPosition({
|
|
943
1175
|
elementX: element.x,
|
|
944
1176
|
elementY: element.y,
|
|
@@ -950,7 +1182,7 @@ function InlineTextEditor({
|
|
|
950
1182
|
panY,
|
|
951
1183
|
elementFontSize: element.fontSize
|
|
952
1184
|
});
|
|
953
|
-
|
|
1185
|
+
useEffect4(() => {
|
|
954
1186
|
const el = ref.current;
|
|
955
1187
|
if (!el) return;
|
|
956
1188
|
el.focus();
|
|
@@ -1017,11 +1249,9 @@ function InlineTextEditor({
|
|
|
1017
1249
|
// src/design-canvas-react/components/Workspace.tsx
|
|
1018
1250
|
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1019
1251
|
var SNAP_THRESHOLD_SCREEN_PX = 8;
|
|
1020
|
-
var DUPLICATE_OFFSET = 10;
|
|
1021
1252
|
var ZOOM_FACTOR_WHEEL = 0.998;
|
|
1022
1253
|
var ZOOM_MIN = 0.05;
|
|
1023
1254
|
var ZOOM_MAX = 32;
|
|
1024
|
-
var NO_MARQUEE = { active: false, startDocX: 0, startDocY: 0, endDocX: 0, endDocY: 0 };
|
|
1025
1255
|
function WorkspaceView({
|
|
1026
1256
|
canWrite,
|
|
1027
1257
|
onApplyOperations,
|
|
@@ -1038,82 +1268,23 @@ function WorkspaceView({
|
|
|
1038
1268
|
showEmptyState = true,
|
|
1039
1269
|
onAskAgent
|
|
1040
1270
|
}) {
|
|
1041
|
-
const [, setTick] =
|
|
1271
|
+
const [, setTick] = useState3(0);
|
|
1042
1272
|
const forceRender = useCallback(() => setTick((t) => t + 1), []);
|
|
1043
|
-
|
|
1273
|
+
useEffect5(() => stack.subscribe(forceRender), [stack, forceRender]);
|
|
1044
1274
|
const state = stack.getState();
|
|
1045
1275
|
const { document, activePageId, selectedElementIds, zoom, panX, panY, gridEnabled, gridSize, snapEnabled, showBleed } = state;
|
|
1046
1276
|
const zoomPanMath = useMemo(() => createZoomPanMath({ minZoom: ZOOM_MIN, maxZoom: ZOOM_MAX }), []);
|
|
1047
1277
|
const snapEngine = useMemo(() => createSnapEngine(), []);
|
|
1048
|
-
const containerRef =
|
|
1049
|
-
const
|
|
1050
|
-
const
|
|
1051
|
-
const
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
if (!entry) return;
|
|
1059
|
-
const { width, height } = entry.contentRect;
|
|
1060
|
-
setContainerSize({ width, height });
|
|
1061
|
-
if (width <= 0 || height <= 0) return;
|
|
1062
|
-
const view = stack.getState();
|
|
1063
|
-
const last = lastAutoFitRef.current;
|
|
1064
|
-
if (last && (view.zoom !== last.zoom || view.panX !== last.panX || view.panY !== last.panY)) {
|
|
1065
|
-
autoFitRef.current = false;
|
|
1066
|
-
}
|
|
1067
|
-
if (autoFitRef.current && fitOnMount && activePage.width > 0 && activePage.height > 0 && (!last || last.width !== width || last.height !== height)) {
|
|
1068
|
-
const fit = zoomPanMath.fitPage(activePage, { width, height });
|
|
1069
|
-
stack.setView(fit);
|
|
1070
|
-
lastAutoFitRef.current = { ...fit, width, height };
|
|
1071
|
-
}
|
|
1072
|
-
if (!readyRef.current) {
|
|
1073
|
-
readyRef.current = true;
|
|
1074
|
-
onReady?.();
|
|
1075
|
-
}
|
|
1076
|
-
});
|
|
1077
|
-
ro.observe(el);
|
|
1078
|
-
return () => ro.disconnect();
|
|
1079
|
-
}, [activePage, fitOnMount, onReady, stack, zoomPanMath]);
|
|
1080
|
-
const stageRef = useRef4(null);
|
|
1081
|
-
useEffect4(() => {
|
|
1082
|
-
if (!onFitRef) return;
|
|
1083
|
-
onFitRef.current = () => {
|
|
1084
|
-
const { width, height } = containerSize;
|
|
1085
|
-
if (width <= 0 || height <= 0) return;
|
|
1086
|
-
const view = zoomPanMath.fitPage(activePage, { width, height });
|
|
1087
|
-
stack.setView(view);
|
|
1088
|
-
};
|
|
1089
|
-
return () => {
|
|
1090
|
-
if (onFitRef.current !== null) onFitRef.current = null;
|
|
1091
|
-
};
|
|
1092
|
-
});
|
|
1093
|
-
useEffect4(() => {
|
|
1094
|
-
if (!onExportRef || !onExport) return;
|
|
1095
|
-
onExportRef.current = ({ format, pixelRatio }) => {
|
|
1096
|
-
const stage = stageRef.current;
|
|
1097
|
-
if (!stage) return;
|
|
1098
|
-
void (async () => {
|
|
1099
|
-
const dataUrl = await exportPageDataUrl(stage, activePage, { format, pixelRatio });
|
|
1100
|
-
await onExport({ pageId: activePageId, format, dataUrl, pixelRatio });
|
|
1101
|
-
})();
|
|
1102
|
-
};
|
|
1103
|
-
return () => {
|
|
1104
|
-
if (onExportRef.current !== null) onExportRef.current = null;
|
|
1105
|
-
};
|
|
1106
|
-
});
|
|
1107
|
-
const gestureRef = useRef4("idle");
|
|
1108
|
-
const panOriginRef = useRef4({ screenX: 0, screenY: 0, panX: 0, panY: 0 });
|
|
1109
|
-
const [marquee, setMarquee] = useState2(NO_MARQUEE);
|
|
1110
|
-
const marqueeRef = useRef4(NO_MARQUEE);
|
|
1111
|
-
const spaceHeldRef = useRef4(false);
|
|
1112
|
-
const dragOriginRef = useRef4(/* @__PURE__ */ new Map());
|
|
1113
|
-
const [activeSnap, setActiveSnap] = useState2(null);
|
|
1114
|
-
const [editingElementId, setEditingElementId] = useState2(null);
|
|
1115
|
-
const editingPreRef = useRef4("");
|
|
1116
|
-
const nudgeHeldRef = useRef4(null);
|
|
1278
|
+
const { containerRef, containerSize, stageRef } = useWorkspaceViewport({ stack, activePage, activePageId, fitOnMount, onReady, onFitRef, onExport, onExportRef, zoomPanMath });
|
|
1279
|
+
const gestureRef = useRef6("idle");
|
|
1280
|
+
const panOriginRef = useRef6({ screenX: 0, screenY: 0, panX: 0, panY: 0 });
|
|
1281
|
+
const [marquee, setMarquee] = useState3(NO_MARQUEE);
|
|
1282
|
+
const marqueeRef = useRef6(NO_MARQUEE);
|
|
1283
|
+
const spaceHeldRef = useRef6(false);
|
|
1284
|
+
const dragOriginRef = useRef6(/* @__PURE__ */ new Map());
|
|
1285
|
+
const [activeSnap, setActiveSnap] = useState3(null);
|
|
1286
|
+
const [editingElementId, setEditingElementId] = useState3(null);
|
|
1287
|
+
const editingPreRef = useRef6("");
|
|
1117
1288
|
async function persist(command) {
|
|
1118
1289
|
if (!canWrite) return;
|
|
1119
1290
|
stack.execute(command);
|
|
@@ -1188,6 +1359,16 @@ function WorkspaceView({
|
|
|
1188
1359
|
setActiveSnap(null);
|
|
1189
1360
|
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
1190
1361
|
}
|
|
1362
|
+
function snapDragBounds(snapBounds, draggingIds) {
|
|
1363
|
+
const targets = snapEngine.collectTargets(state, draggingIds);
|
|
1364
|
+
if (gridEnabled) {
|
|
1365
|
+
const thresholdDoc = SNAP_THRESHOLD_SCREEN_PX / zoom;
|
|
1366
|
+
const gt = collectGridTargets(snapBounds, gridSize, activePage, thresholdDoc);
|
|
1367
|
+
targets.vertical.push(...gt.vertical);
|
|
1368
|
+
targets.horizontal.push(...gt.horizontal);
|
|
1369
|
+
}
|
|
1370
|
+
return snapEngine.apply(snapBounds, targets, SNAP_THRESHOLD_SCREEN_PX, zoom);
|
|
1371
|
+
}
|
|
1191
1372
|
function handleElementDragStart(elementId) {
|
|
1192
1373
|
if (!canWrite) return;
|
|
1193
1374
|
const ids = selectedElementIds.includes(elementId) ? selectedElementIds : [elementId];
|
|
@@ -1214,14 +1395,7 @@ function WorkspaceView({
|
|
|
1214
1395
|
const proposedY = origin.y + dy;
|
|
1215
1396
|
const snapBounds = { x: proposedX, y: proposedY, width: origin.width, height: origin.height };
|
|
1216
1397
|
if (snapEnabled) {
|
|
1217
|
-
const
|
|
1218
|
-
if (gridEnabled) {
|
|
1219
|
-
const thresholdDoc = SNAP_THRESHOLD_SCREEN_PX / zoom;
|
|
1220
|
-
const gt = collectGridTargets(snapBounds, gridSize, activePage, thresholdDoc);
|
|
1221
|
-
targets.vertical.push(...gt.vertical);
|
|
1222
|
-
targets.horizontal.push(...gt.horizontal);
|
|
1223
|
-
}
|
|
1224
|
-
const snapResult = snapEngine.apply(snapBounds, targets, SNAP_THRESHOLD_SCREEN_PX, zoom);
|
|
1398
|
+
const snapResult = snapDragBounds(snapBounds, dragging);
|
|
1225
1399
|
setActiveSnap(snapResult);
|
|
1226
1400
|
}
|
|
1227
1401
|
}
|
|
@@ -1236,14 +1410,7 @@ function WorkspaceView({
|
|
|
1236
1410
|
let snappedY = finalY;
|
|
1237
1411
|
if (snapEnabled) {
|
|
1238
1412
|
const snapBounds = { x: finalX, y: finalY, width: origin.width, height: origin.height };
|
|
1239
|
-
const
|
|
1240
|
-
if (gridEnabled) {
|
|
1241
|
-
const thresholdDoc = SNAP_THRESHOLD_SCREEN_PX / zoom;
|
|
1242
|
-
const gt = collectGridTargets(snapBounds, gridSize, activePage, thresholdDoc);
|
|
1243
|
-
targets.vertical.push(...gt.vertical);
|
|
1244
|
-
targets.horizontal.push(...gt.horizontal);
|
|
1245
|
-
}
|
|
1246
|
-
const snapResult = snapEngine.apply(snapBounds, targets, SNAP_THRESHOLD_SCREEN_PX, zoom);
|
|
1413
|
+
const snapResult = snapDragBounds(snapBounds, draggingIds);
|
|
1247
1414
|
snappedX = snapResult.x;
|
|
1248
1415
|
snappedY = snapResult.y;
|
|
1249
1416
|
}
|
|
@@ -1355,161 +1522,8 @@ function WorkspaceView({
|
|
|
1355
1522
|
await persist(addElementCommand({ pageId: activePageId, element }));
|
|
1356
1523
|
stack.setView({ selectedElementIds: [element.id] });
|
|
1357
1524
|
}
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
e.preventDefault();
|
|
1361
|
-
spaceHeldRef.current = true;
|
|
1362
|
-
return;
|
|
1363
|
-
}
|
|
1364
|
-
const mod = e.metaKey || e.ctrlKey;
|
|
1365
|
-
if (e.key === "Escape") {
|
|
1366
|
-
e.preventDefault();
|
|
1367
|
-
if (gestureRef.current !== "idle") {
|
|
1368
|
-
gestureRef.current = "idle";
|
|
1369
|
-
setMarquee(NO_MARQUEE);
|
|
1370
|
-
setActiveSnap(null);
|
|
1371
|
-
} else if (editingElementId) {
|
|
1372
|
-
setEditingElementId(null);
|
|
1373
|
-
} else {
|
|
1374
|
-
stack.setView({ selectedElementIds: [] });
|
|
1375
|
-
}
|
|
1376
|
-
return;
|
|
1377
|
-
}
|
|
1378
|
-
if (editingElementId) return;
|
|
1379
|
-
if ((e.key === "Delete" || e.key === "Backspace") && selectedElementIds.length > 0) {
|
|
1380
|
-
e.preventDefault();
|
|
1381
|
-
e.stopPropagation();
|
|
1382
|
-
for (const id of [...selectedElementIds]) {
|
|
1383
|
-
try {
|
|
1384
|
-
persist(deleteElementCommand({ document, pageId: activePageId, elementId: id }));
|
|
1385
|
-
} catch {
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
stack.setView({ selectedElementIds: [] });
|
|
1389
|
-
return;
|
|
1390
|
-
}
|
|
1391
|
-
if (mod && e.key === "z" && !e.shiftKey) {
|
|
1392
|
-
e.preventDefault();
|
|
1393
|
-
e.stopPropagation();
|
|
1394
|
-
if (stack.canUndo()) stack.undo();
|
|
1395
|
-
return;
|
|
1396
|
-
}
|
|
1397
|
-
if (mod && (e.key === "z" && e.shiftKey || e.key === "y")) {
|
|
1398
|
-
e.preventDefault();
|
|
1399
|
-
e.stopPropagation();
|
|
1400
|
-
if (stack.canRedo()) stack.redo();
|
|
1401
|
-
return;
|
|
1402
|
-
}
|
|
1403
|
-
if (mod && e.key === "a") {
|
|
1404
|
-
e.preventDefault();
|
|
1405
|
-
const ids = activePage.elements.filter((el) => !el.locked && el.visible).map((el) => el.id);
|
|
1406
|
-
stack.setView({ selectedElementIds: ids });
|
|
1407
|
-
return;
|
|
1408
|
-
}
|
|
1409
|
-
if (mod && e.key === "d" && selectedElementIds.length > 0) {
|
|
1410
|
-
e.preventDefault();
|
|
1411
|
-
for (const id of selectedElementIds) {
|
|
1412
|
-
const found = findElement(activePage, id);
|
|
1413
|
-
if (!found) continue;
|
|
1414
|
-
const clone = {
|
|
1415
|
-
...structuredClone(found.element),
|
|
1416
|
-
id: crypto.randomUUID(),
|
|
1417
|
-
x: found.element.x + DUPLICATE_OFFSET,
|
|
1418
|
-
y: found.element.y + DUPLICATE_OFFSET
|
|
1419
|
-
};
|
|
1420
|
-
persist(addElementCommand({ pageId: activePageId, element: clone }));
|
|
1421
|
-
}
|
|
1422
|
-
return;
|
|
1423
|
-
}
|
|
1424
|
-
if (mod && !e.shiftKey && e.key === "g" && selectedElementIds.length >= 2) {
|
|
1425
|
-
e.preventDefault();
|
|
1426
|
-
persist(groupElementsCommand({
|
|
1427
|
-
document,
|
|
1428
|
-
pageId: activePageId,
|
|
1429
|
-
elementIds: selectedElementIds,
|
|
1430
|
-
groupId: crypto.randomUUID()
|
|
1431
|
-
}));
|
|
1432
|
-
return;
|
|
1433
|
-
}
|
|
1434
|
-
if (mod && e.shiftKey && e.key === "g" && selectedElementIds.length === 1) {
|
|
1435
|
-
e.preventDefault();
|
|
1436
|
-
const id = selectedElementIds[0];
|
|
1437
|
-
persist(ungroupElementCommand({ document, pageId: activePageId, groupId: id }));
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key) && selectedElementIds.length > 0) {
|
|
1441
|
-
e.preventDefault();
|
|
1442
|
-
const key = e.key;
|
|
1443
|
-
if (nudgeHeldRef.current && nudgeHeldRef.current.key !== key) {
|
|
1444
|
-
flushNudge();
|
|
1445
|
-
}
|
|
1446
|
-
if (!nudgeHeldRef.current) {
|
|
1447
|
-
const origins = /* @__PURE__ */ new Map();
|
|
1448
|
-
for (const id of selectedElementIds) {
|
|
1449
|
-
const found = findElement(activePage, id);
|
|
1450
|
-
if (found) origins.set(id, { x: found.element.x, y: found.element.y });
|
|
1451
|
-
}
|
|
1452
|
-
nudgeHeldRef.current = { key, ids: selectedElementIds.slice(), origin: origins };
|
|
1453
|
-
}
|
|
1454
|
-
const { dx, dy } = nudgeDelta(key, e.shiftKey);
|
|
1455
|
-
const entries = [];
|
|
1456
|
-
for (const [id, orig] of nudgeHeldRef.current.origin) {
|
|
1457
|
-
const found = findElement(activePage, id);
|
|
1458
|
-
if (!found) continue;
|
|
1459
|
-
entries.push({
|
|
1460
|
-
pageId: activePageId,
|
|
1461
|
-
elementId: id,
|
|
1462
|
-
attrs: { x: found.element.x + dx, y: found.element.y + dy },
|
|
1463
|
-
priorAttrs: { x: found.element.x, y: found.element.y }
|
|
1464
|
-
});
|
|
1465
|
-
}
|
|
1466
|
-
if (entries.length > 0) {
|
|
1467
|
-
stack.execute(multiSetAttrsCommand(entries));
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
function handleKeyUp(e) {
|
|
1472
|
-
if (e.key === " ") {
|
|
1473
|
-
spaceHeldRef.current = false;
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
|
|
1477
|
-
flushNudge();
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
function flushNudge() {
|
|
1481
|
-
const held = nudgeHeldRef.current;
|
|
1482
|
-
if (!held) return;
|
|
1483
|
-
nudgeHeldRef.current = null;
|
|
1484
|
-
if (!canWrite || held.ids.length === 0) return;
|
|
1485
|
-
const entries = [];
|
|
1486
|
-
for (const id of held.ids) {
|
|
1487
|
-
const orig = held.origin.get(id);
|
|
1488
|
-
const found = findElement(activePage, id);
|
|
1489
|
-
if (!orig || !found) continue;
|
|
1490
|
-
entries.push({
|
|
1491
|
-
pageId: activePageId,
|
|
1492
|
-
elementId: id,
|
|
1493
|
-
attrs: { x: found.element.x, y: found.element.y },
|
|
1494
|
-
priorAttrs: { x: orig.x, y: orig.y }
|
|
1495
|
-
});
|
|
1496
|
-
}
|
|
1497
|
-
if (entries.length > 0) {
|
|
1498
|
-
onApplyOperations(multiSetAttrsCommand(entries).operations()).catch(() => {
|
|
1499
|
-
for (const [id, orig] of held.origin) {
|
|
1500
|
-
const found = findElement(activePage, id);
|
|
1501
|
-
if (!found) continue;
|
|
1502
|
-
persist(setAttrsCommand({
|
|
1503
|
-
pageId: activePageId,
|
|
1504
|
-
elementId: id,
|
|
1505
|
-
attrs: { x: orig.x, y: orig.y },
|
|
1506
|
-
priorAttrs: { x: found.element.x, y: found.element.y }
|
|
1507
|
-
}));
|
|
1508
|
-
}
|
|
1509
|
-
});
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
useEffect4(() => {
|
|
1525
|
+
const { handleKeyDown, handleKeyUp } = useWorkspaceKeyboard({ stack, state, activePage, canWrite, onApplyOperations, persist, gestureRef, spaceHeldRef, setMarquee, setActiveSnap, editingElementId, setEditingElementId });
|
|
1526
|
+
useEffect5(() => {
|
|
1513
1527
|
if (!onSelectionChange) return;
|
|
1514
1528
|
const elements = selectedElementIds.map((id) => findElement(activePage, id)?.element).filter((el) => !!el);
|
|
1515
1529
|
onSelectionChange(elements);
|
|
@@ -1527,7 +1541,7 @@ function WorkspaceView({
|
|
|
1527
1541
|
const activeVerticalGuide = activeSnap?.activeVertical ?? null;
|
|
1528
1542
|
const activeHorizontalGuide = activeSnap?.activeHorizontal ?? null;
|
|
1529
1543
|
const normalizedMarquee = marquee.active ? normalizeMarquee(marquee.startDocX, marquee.startDocY, marquee.endDocX, marquee.endDocY) : null;
|
|
1530
|
-
const handlerImplRef =
|
|
1544
|
+
const handlerImplRef = useRef6({
|
|
1531
1545
|
onClick: handleElementClick,
|
|
1532
1546
|
onDragStart: handleElementDragStart,
|
|
1533
1547
|
onDragMove: handleElementDragMove,
|
|
@@ -1720,19 +1734,19 @@ function WorkspaceView({
|
|
|
1720
1734
|
);
|
|
1721
1735
|
}
|
|
1722
1736
|
function Workspace(props) {
|
|
1723
|
-
const stackRef =
|
|
1737
|
+
const stackRef = useRef6(
|
|
1724
1738
|
createSceneCommandStack(
|
|
1725
1739
|
props.document,
|
|
1726
1740
|
props.document.pages[0]?.id ?? ""
|
|
1727
1741
|
)
|
|
1728
1742
|
);
|
|
1729
|
-
const [, setTick] =
|
|
1743
|
+
const [, setTick] = useState3(0);
|
|
1730
1744
|
const forceRender = useCallback(() => setTick((t) => t + 1), []);
|
|
1731
|
-
|
|
1745
|
+
useEffect5(() => {
|
|
1732
1746
|
return stackRef.current.subscribe(forceRender);
|
|
1733
1747
|
}, [forceRender]);
|
|
1734
|
-
const prevRevRef =
|
|
1735
|
-
|
|
1748
|
+
const prevRevRef = useRef6(props.rev);
|
|
1749
|
+
useEffect5(() => {
|
|
1736
1750
|
if (props.rev !== prevRevRef.current) {
|
|
1737
1751
|
prevRevRef.current = props.rev;
|
|
1738
1752
|
stackRef.current.reset(props.document);
|
|
@@ -1937,4 +1951,4 @@ export {
|
|
|
1937
1951
|
Workspace,
|
|
1938
1952
|
DesignCanvasEditor
|
|
1939
1953
|
};
|
|
1940
|
-
//# sourceMappingURL=chunk-
|
|
1954
|
+
//# sourceMappingURL=chunk-JH3CKHF4.js.map
|