@catchlight/editor-web 0.0.0 → 0.6.0
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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +26 -2
- package/THIRD-PARTY-NOTICES.md +331 -0
- package/dist/editor/CatchlightEditor.d.ts +21 -0
- package/dist/editor/CatchlightEditor.js +720 -0
- package/dist/editor/dialogs.d.ts +18 -0
- package/dist/editor/dialogs.js +71 -0
- package/dist/editor/import-panel.d.ts +6 -0
- package/dist/editor/import-panel.js +98 -0
- package/dist/editor/logo.svg +11 -0
- package/dist/editor/notification.d.ts +4 -0
- package/dist/editor/notification.js +24 -0
- package/dist/editor/stage.d.ts +13 -0
- package/dist/editor/stage.js +23 -0
- package/dist/editor/test/setup.d.ts +5 -0
- package/dist/editor/test/setup.js +5 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/lib/animations-panel.d.ts +10 -0
- package/dist/lib/animations-panel.js +48 -0
- package/dist/lib/authoring.d.ts +17 -0
- package/dist/lib/authoring.js +116 -0
- package/dist/lib/binding-grid.d.ts +19 -0
- package/dist/lib/binding-grid.js +92 -0
- package/dist/lib/bindings.d.ts +21 -0
- package/dist/lib/bindings.js +100 -0
- package/dist/lib/camera.d.ts +21 -0
- package/dist/lib/camera.js +61 -0
- package/dist/lib/controls-panel.d.ts +36 -0
- package/dist/lib/controls-panel.js +201 -0
- package/dist/lib/controls.d.ts +103 -0
- package/dist/lib/controls.js +163 -0
- package/dist/lib/editing.d.ts +126 -0
- package/dist/lib/editing.js +415 -0
- package/dist/lib/editor-context.d.ts +15 -0
- package/dist/lib/editor-context.js +23 -0
- package/dist/lib/expressions-panel.d.ts +10 -0
- package/dist/lib/expressions-panel.js +120 -0
- package/dist/lib/file-open.d.ts +11 -0
- package/dist/lib/file-open.js +25 -0
- package/dist/lib/file-save.d.ts +29 -0
- package/dist/lib/file-save.js +68 -0
- package/dist/lib/gizmo.d.ts +13 -0
- package/dist/lib/gizmo.js +247 -0
- package/dist/lib/image-markup.d.ts +12 -0
- package/dist/lib/image-markup.js +153 -0
- package/dist/lib/index.d.ts +71 -0
- package/dist/lib/index.js +44 -0
- package/dist/lib/inspector.d.ts +19 -0
- package/dist/lib/inspector.js +161 -0
- package/dist/lib/latest.d.ts +3 -0
- package/dist/lib/latest.js +9 -0
- package/dist/lib/layer-import.d.ts +38 -0
- package/dist/lib/layer-import.js +187 -0
- package/dist/lib/mesh-editor.d.ts +13 -0
- package/dist/lib/mesh-editor.js +337 -0
- package/dist/lib/model-panels.d.ts +23 -0
- package/dist/lib/model-panels.js +180 -0
- package/dist/lib/node-actions.d.ts +42 -0
- package/dist/lib/node-actions.js +115 -0
- package/dist/lib/node-drag.d.ts +18 -0
- package/dist/lib/node-drag.js +65 -0
- package/dist/lib/node-patch.d.ts +8 -0
- package/dist/lib/node-patch.js +10 -0
- package/dist/lib/node-tree.d.ts +36 -0
- package/dist/lib/node-tree.js +221 -0
- package/dist/lib/official.d.ts +82 -0
- package/dist/lib/official.js +197 -0
- package/dist/lib/param-actions.d.ts +48 -0
- package/dist/lib/param-actions.js +106 -0
- package/dist/lib/param-list.d.ts +36 -0
- package/dist/lib/param-list.js +73 -0
- package/dist/lib/param-slider.d.ts +44 -0
- package/dist/lib/param-slider.js +149 -0
- package/dist/lib/pose.d.ts +13 -0
- package/dist/lib/pose.js +32 -0
- package/dist/lib/posing-panel.d.ts +40 -0
- package/dist/lib/posing-panel.js +154 -0
- package/dist/lib/presence.d.ts +27 -0
- package/dist/lib/presence.js +98 -0
- package/dist/lib/properties-panel.d.ts +13 -0
- package/dist/lib/properties-panel.js +63 -0
- package/dist/lib/recording-panel.d.ts +4 -0
- package/dist/lib/recording-panel.js +161 -0
- package/dist/lib/replica.d.ts +18 -0
- package/dist/lib/replica.js +34 -0
- package/dist/lib/review.d.ts +113 -0
- package/dist/lib/review.js +529 -0
- package/dist/lib/rigging.d.ts +10 -0
- package/dist/lib/rigging.js +116 -0
- package/dist/lib/selection.d.ts +3 -0
- package/dist/lib/selection.js +2 -0
- package/dist/lib/session-list.d.ts +16 -0
- package/dist/lib/session-list.js +7 -0
- package/dist/lib/sessions.d.ts +8 -0
- package/dist/lib/sessions.js +29 -0
- package/dist/lib/test/harness.d.ts +32 -0
- package/dist/lib/test/harness.js +139 -0
- package/dist/lib/test/setup.d.ts +4 -0
- package/dist/lib/test/setup.js +5 -0
- package/dist/lib/versions.d.ts +69 -0
- package/dist/lib/versions.js +250 -0
- package/dist/lib/viewport.d.ts +57 -0
- package/dist/lib/viewport.js +315 -0
- package/dist/lib/workspace-layout.d.ts +24 -0
- package/dist/lib/workspace-layout.js +145 -0
- package/dist/lib/workspace.d.ts +29 -0
- package/dist/lib/workspace.js +263 -0
- package/dist/theme.css +4577 -0
- package/package.json +32 -6
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useEditing } from "./editing.js";
|
|
4
|
+
import { fitCamera, panTo, screenAt, worldAt, zoomAbout, wheelNotches, ZOOM_PER_NOTCH, } from "./camera.js";
|
|
5
|
+
import { Disclosure, EmptyState, Field, Icon, IconButton, NumberField, } from "./controls.js";
|
|
6
|
+
export function meshBounds(mesh) {
|
|
7
|
+
if (!mesh.mesh.verts.length) {
|
|
8
|
+
const [x0, y0, x1, y1] = mesh.texture_rect;
|
|
9
|
+
return [
|
|
10
|
+
Math.min(x0, x1),
|
|
11
|
+
Math.min(y0, y1),
|
|
12
|
+
Math.max(x0, x1),
|
|
13
|
+
Math.max(y0, y1),
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
const bounds = [
|
|
17
|
+
Infinity,
|
|
18
|
+
Infinity,
|
|
19
|
+
-Infinity,
|
|
20
|
+
-Infinity,
|
|
21
|
+
];
|
|
22
|
+
for (const [x, y] of mesh.mesh.verts) {
|
|
23
|
+
bounds[0] = Math.min(bounds[0], x);
|
|
24
|
+
bounds[1] = Math.min(bounds[1], y);
|
|
25
|
+
bounds[2] = Math.max(bounds[2], x);
|
|
26
|
+
bounds[3] = Math.max(bounds[3], y);
|
|
27
|
+
}
|
|
28
|
+
return bounds;
|
|
29
|
+
}
|
|
30
|
+
export function MeshCanvas({ camera, onCameraChange, onFit, onResize, panMode, }) {
|
|
31
|
+
const edit = useEditing();
|
|
32
|
+
const { mesh, session } = edit;
|
|
33
|
+
const box = useRef(null);
|
|
34
|
+
const [size, setSize] = useState({ width: 0, height: 0 });
|
|
35
|
+
const [source, setSource] = useState();
|
|
36
|
+
const [space, setSpace] = useState(false);
|
|
37
|
+
const [opacity, setOpacity] = useState(1);
|
|
38
|
+
const gesture = useRef(undefined);
|
|
39
|
+
const last = useRef({ edit, camera, size, onCameraChange, onFit, onResize });
|
|
40
|
+
last.current = { edit, camera, size, onCameraChange, onFit, onResize };
|
|
41
|
+
const framed = useRef(false);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const element = box.current;
|
|
44
|
+
if (!element)
|
|
45
|
+
return;
|
|
46
|
+
const resize = () => {
|
|
47
|
+
const next = { width: element.clientWidth, height: element.clientHeight };
|
|
48
|
+
setSize(next);
|
|
49
|
+
last.current.onResize?.(next);
|
|
50
|
+
if (!framed.current &&
|
|
51
|
+
next.width > 0 &&
|
|
52
|
+
next.height > 0 &&
|
|
53
|
+
last.current.edit.mesh) {
|
|
54
|
+
framed.current = true;
|
|
55
|
+
const bounds = meshBounds(last.current.edit.mesh);
|
|
56
|
+
const fitted = fitCamera(bounds, next);
|
|
57
|
+
if (fitted) {
|
|
58
|
+
last.current.onCameraChange(fitted);
|
|
59
|
+
last.current.onFit(fitted, bounds);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const observer = new ResizeObserver(resize);
|
|
64
|
+
observer.observe(element);
|
|
65
|
+
resize();
|
|
66
|
+
return () => observer.disconnect();
|
|
67
|
+
}, []);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
let live = true, url;
|
|
70
|
+
setSource(undefined);
|
|
71
|
+
if (!session || !mesh)
|
|
72
|
+
return;
|
|
73
|
+
try {
|
|
74
|
+
const image = session.textureImage(mesh.texture);
|
|
75
|
+
if (!image)
|
|
76
|
+
throw new Error("The artwork could not be opened.");
|
|
77
|
+
const canvas = document.createElement("canvas");
|
|
78
|
+
canvas.width = image.width;
|
|
79
|
+
canvas.height = image.height;
|
|
80
|
+
canvas
|
|
81
|
+
.getContext("2d")
|
|
82
|
+
.putImageData(new ImageData(new Uint8ClampedArray(image.rgba), image.width, image.height), 0, 0);
|
|
83
|
+
canvas.toBlob((blob) => {
|
|
84
|
+
if (!blob || !live)
|
|
85
|
+
return;
|
|
86
|
+
url = URL.createObjectURL(blob);
|
|
87
|
+
setSource(url);
|
|
88
|
+
}, "image/png");
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
edit.meshAction(() => {
|
|
92
|
+
throw e;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return () => {
|
|
96
|
+
live = false;
|
|
97
|
+
if (url)
|
|
98
|
+
URL.revokeObjectURL(url);
|
|
99
|
+
};
|
|
100
|
+
}, [session, mesh?.texture]);
|
|
101
|
+
const cancel = () => {
|
|
102
|
+
if (!gesture.current)
|
|
103
|
+
return;
|
|
104
|
+
if (gesture.current.index !== undefined)
|
|
105
|
+
last.current.edit.meshAction((d) => d.handle.endGesture(false));
|
|
106
|
+
gesture.current = undefined;
|
|
107
|
+
};
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
const down = (e) => {
|
|
110
|
+
if (e.target instanceof HTMLElement &&
|
|
111
|
+
(e.target.matches("input,textarea,select,button,summary") ||
|
|
112
|
+
e.target.isContentEditable))
|
|
113
|
+
return;
|
|
114
|
+
if (e.code === "Space") {
|
|
115
|
+
setSpace(true);
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
}
|
|
118
|
+
if ((e.key === "Escape" ||
|
|
119
|
+
((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z")) &&
|
|
120
|
+
gesture.current) {
|
|
121
|
+
cancel();
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
e.stopImmediatePropagation();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const up = (e) => {
|
|
127
|
+
if (e.code === "Space")
|
|
128
|
+
setSpace(false);
|
|
129
|
+
};
|
|
130
|
+
const blur = () => {
|
|
131
|
+
setSpace(false);
|
|
132
|
+
cancel();
|
|
133
|
+
};
|
|
134
|
+
window.addEventListener("keydown", down, true);
|
|
135
|
+
window.addEventListener("keyup", up);
|
|
136
|
+
window.addEventListener("blur", blur);
|
|
137
|
+
return () => {
|
|
138
|
+
cancel();
|
|
139
|
+
window.removeEventListener("keydown", down, true);
|
|
140
|
+
window.removeEventListener("keyup", up);
|
|
141
|
+
window.removeEventListener("blur", blur);
|
|
142
|
+
};
|
|
143
|
+
}, []);
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
const element = box.current;
|
|
146
|
+
if (!element)
|
|
147
|
+
return;
|
|
148
|
+
const wheel = (e) => {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
if (gesture.current)
|
|
151
|
+
return;
|
|
152
|
+
const rect = element.getBoundingClientRect();
|
|
153
|
+
const current = last.current;
|
|
154
|
+
current.onCameraChange(zoomAbout(current.camera, current.size, [e.clientX - rect.left, e.clientY - rect.top], ZOOM_PER_NOTCH ** wheelNotches(e.deltaY, e.deltaMode)));
|
|
155
|
+
};
|
|
156
|
+
element.addEventListener("wheel", wheel, { passive: false });
|
|
157
|
+
return () => element.removeEventListener("wheel", wheel);
|
|
158
|
+
}, []);
|
|
159
|
+
if (!mesh)
|
|
160
|
+
return null;
|
|
161
|
+
const local = (e) => {
|
|
162
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
163
|
+
return worldAt(camera, size, [e.clientX - rect.left, e.clientY - rect.top]);
|
|
164
|
+
};
|
|
165
|
+
const start = (e) => {
|
|
166
|
+
if (e.button !== 0 && e.button !== 1)
|
|
167
|
+
return;
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
e.currentTarget.focus();
|
|
170
|
+
const from = local(e);
|
|
171
|
+
if (panMode || space || e.button === 1) {
|
|
172
|
+
gesture.current = {
|
|
173
|
+
pointer: e.pointerId,
|
|
174
|
+
from: [e.clientX, e.clientY],
|
|
175
|
+
camera,
|
|
176
|
+
moved: false,
|
|
177
|
+
};
|
|
178
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (edit.stale || edit.busy)
|
|
182
|
+
return;
|
|
183
|
+
const index = Number(e.target.getAttribute("data-mesh-vertex"));
|
|
184
|
+
const hit = e.target.hasAttribute("data-mesh-vertex");
|
|
185
|
+
if (!hit) {
|
|
186
|
+
if (edit.meshTool === "add")
|
|
187
|
+
edit.meshAction((d) => edit.setMeshSelection([d.handle.addVertex(...from)]));
|
|
188
|
+
else if (!e.shiftKey)
|
|
189
|
+
edit.setMeshSelection([]);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (edit.meshTool === "connect") {
|
|
193
|
+
const previous = edit.meshSelection.at(-1);
|
|
194
|
+
if (previous !== undefined && previous !== index)
|
|
195
|
+
edit.meshAction((d) => d.handle.toggleEdge(previous, index));
|
|
196
|
+
edit.setMeshSelection([index]);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (e.shiftKey) {
|
|
200
|
+
edit.setMeshSelection(edit.meshSelection.includes(index)
|
|
201
|
+
? edit.meshSelection.filter((v) => v !== index)
|
|
202
|
+
: [...edit.meshSelection, index]);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const indices = edit.meshSelection.includes(index)
|
|
206
|
+
? edit.meshSelection
|
|
207
|
+
: [index];
|
|
208
|
+
edit.setMeshSelection(indices);
|
|
209
|
+
edit.meshAction((d) => d.handle.beginGesture());
|
|
210
|
+
gesture.current = {
|
|
211
|
+
pointer: e.pointerId,
|
|
212
|
+
index,
|
|
213
|
+
indices,
|
|
214
|
+
from,
|
|
215
|
+
camera,
|
|
216
|
+
moved: false,
|
|
217
|
+
};
|
|
218
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
219
|
+
};
|
|
220
|
+
const move = (e) => {
|
|
221
|
+
const active = gesture.current;
|
|
222
|
+
if (!active || active.pointer !== e.pointerId)
|
|
223
|
+
return;
|
|
224
|
+
if (active.index === undefined) {
|
|
225
|
+
onCameraChange(panTo(active.camera, active.from, size, [e.clientX, e.clientY]));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const at = local(e), dx = at[0] - active.from[0], dy = at[1] - active.from[1];
|
|
229
|
+
if (Math.hypot(dx, dy) < 1e-6 && !active.moved)
|
|
230
|
+
return;
|
|
231
|
+
active.moved = true;
|
|
232
|
+
edit.moveMesh(active.indices, [dx, dy]);
|
|
233
|
+
};
|
|
234
|
+
const end = (e) => {
|
|
235
|
+
if (gesture.current?.pointer !== e.pointerId)
|
|
236
|
+
return;
|
|
237
|
+
if (gesture.current.index !== undefined)
|
|
238
|
+
edit.meshAction((d) => d.handle.endGesture(true));
|
|
239
|
+
gesture.current = undefined;
|
|
240
|
+
if (e.currentTarget.hasPointerCapture(e.pointerId))
|
|
241
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
242
|
+
};
|
|
243
|
+
const points = mesh.mesh.verts.map((p) => screenAt(camera, size, p));
|
|
244
|
+
const a = screenAt(camera, size, [
|
|
245
|
+
mesh.texture_rect[0],
|
|
246
|
+
mesh.texture_rect[1],
|
|
247
|
+
]);
|
|
248
|
+
const b = screenAt(camera, size, [
|
|
249
|
+
mesh.texture_rect[2],
|
|
250
|
+
mesh.texture_rect[3],
|
|
251
|
+
]);
|
|
252
|
+
const nudge = (dx, dy) => edit.meshAction((d) => {
|
|
253
|
+
d.handle.beginGesture();
|
|
254
|
+
try {
|
|
255
|
+
d.handle.translateVertices(new Uint32Array(edit.meshSelection), dx, dy);
|
|
256
|
+
d.handle.endGesture(true);
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
d.handle.endGesture(false);
|
|
260
|
+
throw e;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return (_jsxs("div", { ref: box, "data-catchlight-mesh-canvas": "", "data-tool": panMode || space ? "hand" : edit.meshTool, children: [_jsxs("svg", { width: size.width, height: size.height, role: "application", "aria-label": "Mesh on original artwork", tabIndex: 0, onPointerDown: start, onPointerMove: move, onPointerUp: end, onPointerCancel: cancel, onLostPointerCapture: cancel, onKeyDown: (e) => {
|
|
264
|
+
const n = e.shiftKey ? 10 : 1;
|
|
265
|
+
const deltas = {
|
|
266
|
+
ArrowLeft: [-n, 0],
|
|
267
|
+
ArrowRight: [n, 0],
|
|
268
|
+
ArrowUp: [0, n],
|
|
269
|
+
ArrowDown: [0, -n],
|
|
270
|
+
};
|
|
271
|
+
if (deltas[e.key]) {
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
e.stopPropagation();
|
|
274
|
+
nudge(...deltas[e.key]);
|
|
275
|
+
}
|
|
276
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
e.stopPropagation();
|
|
279
|
+
edit.meshAction((d) => {
|
|
280
|
+
d.handle.deleteVertices(new Uint32Array(edit.meshSelection));
|
|
281
|
+
edit.setMeshSelection([]);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "a") {
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
e.stopPropagation();
|
|
287
|
+
edit.setMeshSelection(points.map((_, i) => i));
|
|
288
|
+
}
|
|
289
|
+
}, children: [source && (_jsx("image", { "data-catchlight-mesh-artwork": "", href: source, width: "1", height: "1", preserveAspectRatio: "none", opacity: opacity, transform: `matrix(${b[0] - a[0]},0,0,${b[1] - a[1]},${a[0]},${a[1]})` })), _jsx("g", { "data-catchlight-draft-triangles": "", children: mesh.mesh.indices.map((tri, i) => (_jsx("polygon", { points: tri.map((index) => points[index]?.join(",")).join(" ") }, i))) }), edit.meshTool === "connect" && (_jsx("g", { "data-catchlight-draft-constraints": "", children: mesh.constraints.map(([a, b]) => (_jsx("line", { x1: points[a]?.[0], y1: points[a]?.[1], x2: points[b]?.[0], y2: points[b]?.[1] }, `${a}:${b}`))) })), points.map((p, i) => (_jsxs("g", { "data-selected": edit.meshSelection.includes(i) ? "" : undefined, "data-catchlight-draft-vertex": "", children: [_jsx("circle", { cx: p[0], cy: p[1], r: "4" }), _jsx("circle", { cx: p[0], cy: p[1], r: "11", "data-mesh-vertex": i, "aria-label": `Mesh vertex ${i + 1}`, role: "button", tabIndex: i === (edit.meshSelection[0] ?? 0) ? 0 : -1, onFocus: () => {
|
|
290
|
+
if (!edit.meshSelection.includes(i))
|
|
291
|
+
edit.setMeshSelection([i]);
|
|
292
|
+
}, "data-catchlight-mesh-hit": "" })] }, i)))] }), _jsxs("div", { "data-catchlight-stage-caption": "", children: [_jsxs("span", { children: [_jsx(Icon, { name: "part", width: "13", height: "13" }), "Original artwork"] }), _jsx("span", { children: edit.meshTool === "connect"
|
|
293
|
+
? "Solid edges are pinned · select two vertices to toggle"
|
|
294
|
+
: "Texture space · image stays fixed" })] }), _jsx("div", { "data-catchlight-mesh-opacity": "", children: _jsxs("label", { children: ["Artwork", _jsx("input", { "aria-label": "Artwork preview opacity", type: "range", min: "0.1", max: "1", step: "0.05", value: opacity, onChange: (e) => setOpacity(Number(e.currentTarget.value)) })] }) }), !source && (_jsx("div", { "data-catchlight-stage-loading": "", role: "status", children: "Opening artwork\u2026" }))] }));
|
|
295
|
+
}
|
|
296
|
+
export function MeshTools() {
|
|
297
|
+
const edit = useEditing();
|
|
298
|
+
return (_jsxs("div", { "data-catchlight-mesh-tools": "", role: "toolbar", "aria-label": "Mesh tools", children: [[
|
|
299
|
+
["move", "select", "Move vertices"],
|
|
300
|
+
["add", "plus", "Add vertex"],
|
|
301
|
+
["connect", "link", "Connect vertices"],
|
|
302
|
+
].map(([tool, icon, label]) => (_jsxs("button", { type: "button", "aria-pressed": edit.meshTool === tool, disabled: edit.busy || edit.stale, onClick: () => edit.setMeshTool(tool), children: [_jsx(Icon, { name: icon, width: "15", height: "15" }), label] }, tool))), _jsx(IconButton, { icon: "trash", label: "Delete selected vertices", disabled: !edit.meshSelection.length ||
|
|
303
|
+
edit.busy ||
|
|
304
|
+
edit.stale ||
|
|
305
|
+
(edit.mesh?.mesh.verts.length ?? 0) - edit.meshSelection.length < 3, onClick: () => edit.meshAction((d) => {
|
|
306
|
+
d.handle.deleteVertices(new Uint32Array(edit.meshSelection));
|
|
307
|
+
edit.setMeshSelection([]);
|
|
308
|
+
}) })] }));
|
|
309
|
+
}
|
|
310
|
+
export function MeshInspector() {
|
|
311
|
+
const edit = useEditing(), mesh = edit.mesh;
|
|
312
|
+
const [method, setMethod] = useState("contour");
|
|
313
|
+
const [spacing, setSpacing] = useState(32), [margin, setMargin] = useState(4), [cols, setCols] = useState(8), [rows, setRows] = useState(8);
|
|
314
|
+
if (!mesh)
|
|
315
|
+
return (_jsx(EmptyState, { title: "Select artwork", children: "Choose a textured part to edit its mesh." }));
|
|
316
|
+
const index = edit.meshSelection.length === 1 ? edit.meshSelection[0] : undefined;
|
|
317
|
+
const vertex = index === undefined ? undefined : mesh.mesh.verts[index];
|
|
318
|
+
return (_jsxs("div", { "data-catchlight-mesh-inspector": "", children: [_jsxs("div", { "data-catchlight-selection-heading": "", children: [_jsx(Icon, { name: "mesh" }), _jsxs("div", { children: [_jsx("strong", { children: edit.info?.name ?? "Mesh" }), _jsx("small", { children: "Editing base mesh" })] })] }), _jsxs("div", { "data-catchlight-edit-explainer": "", children: [_jsx("strong", { children: "Place the mesh on your artwork" }), _jsx("p", { children: "Vertices move over the image. Your drawing stays fixed." })] }), _jsxs("div", { "data-catchlight-metrics": "", children: [_jsxs("span", { children: [_jsx("b", { children: mesh.mesh.verts.length }), " vertices"] }), _jsxs("span", { children: [_jsx("b", { children: mesh.mesh.indices.length }), " triangles"] })] }), edit.stale && (_jsxs("div", { "data-catchlight-warning": "", role: "alert", children: [_jsx("strong", { children: "The model changed" }), _jsx("p", { children: "This draft is preserved, but it can\u2019t overwrite newer edits." }), _jsx("button", { type: "button", onClick: edit.reloadMesh, children: "Reload mesh" })] })), edit.meshError && (_jsx("p", { "data-catchlight-warning": "", role: "status", children: edit.meshError })), _jsxs(Disclosure, { title: "Selection", children: [vertex && index !== undefined ? (_jsxs(_Fragment, { children: [_jsxs("p", { "data-catchlight-hint": "", children: ["Vertex ", index + 1] }), _jsx(Field, { label: "Position", children: [0, 1].map((axis) => (_jsx(NumberField, { label: `Mesh vertex ${axis === 0 ? "X" : "Y"}`, prefix: axis === 0 ? "X" : "Y", value: vertex[axis], disabled: edit.stale || edit.busy, onCommit: (value) => edit.meshAction((d) => {
|
|
319
|
+
d.handle.beginGesture();
|
|
320
|
+
try {
|
|
321
|
+
d.handle.moveVertex(index, axis === 0 ? value : vertex[0], axis === 1 ? value : vertex[1]);
|
|
322
|
+
d.handle.endGesture(true);
|
|
323
|
+
}
|
|
324
|
+
catch (e) {
|
|
325
|
+
d.handle.endGesture(false);
|
|
326
|
+
throw e;
|
|
327
|
+
}
|
|
328
|
+
}) }, axis))) })] })) : (_jsx("p", { "data-catchlight-hint": "", children: edit.meshSelection.length
|
|
329
|
+
? `${edit.meshSelection.length} vertices selected`
|
|
330
|
+
: "Click a vertex to select it. Shift-click to select several." })), _jsx("p", { "data-catchlight-hint": "", children: "Arrow keys nudge by 1. Hold Shift for 10. Escape cancels a drag." })] }), _jsx(Disclosure, { title: "Generate mesh", defaultOpen: false, children: _jsxs("fieldset", { disabled: edit.busy || edit.stale, children: [_jsx(Field, { label: "Method", children: _jsxs("select", { "aria-label": "Draft mesh method", value: method, onChange: (e) => setMethod(e.currentTarget.value), children: [_jsx("option", { value: "contour", children: "Trace artwork" }), _jsx("option", { value: "grid", children: "Regular grid" })] }) }), method === "contour" ? (_jsxs(_Fragment, { children: [_jsx(Field, { label: "Spacing", children: _jsx(NumberField, { label: "Draft mesh spacing", value: spacing, min: 1, max: 4096, unit: "px", onCommit: setSpacing }) }), _jsx(Field, { label: "Margin", children: _jsx(NumberField, { label: "Draft mesh margin", value: margin, min: 0, max: 128, unit: "px", onCommit: setMargin }) })] })) : (_jsxs(Field, { label: "Grid", children: [_jsx(NumberField, { label: "Draft mesh columns", value: cols, min: 2, max: 128, step: 1, prefix: "C", onCommit: setCols }), _jsx(NumberField, { label: "Draft mesh rows", value: rows, min: 2, max: 128, step: 1, prefix: "R", onCommit: setRows })] })), _jsxs("button", { type: "button", "data-catchlight-action": "", onClick: () => edit.meshAction((d) => {
|
|
331
|
+
if (method === "contour")
|
|
332
|
+
d.handle.generateContour(spacing, margin);
|
|
333
|
+
else
|
|
334
|
+
d.handle.generateGrid(cols, rows);
|
|
335
|
+
edit.setMeshSelection([]);
|
|
336
|
+
}), children: [_jsx(Icon, { name: "mesh" }), "Generate draft"] }), _jsx("p", { "data-catchlight-hint": "", children: "Replaces this draft\u2019s topology. You can Undo or Cancel before applying." })] }) }), _jsxs("div", { "data-catchlight-edit-footer": "", children: [_jsx("p", { children: "Apply saves one mesh edit and refits existing shape keys. Filled slots will need reassignment." }), _jsx("span", { "data-catchlight-draft-state": "", children: mesh.dirty ? "Unsaved mesh changes" : "No mesh changes" })] })] }));
|
|
337
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Session, NodeInfo } from "@catchlight/editor-core";
|
|
2
|
+
import { type ErrorHandler } from "./authoring.js";
|
|
3
|
+
export declare function MaskPanel({ session, info, onError, }: {
|
|
4
|
+
session: Session;
|
|
5
|
+
info: NodeInfo;
|
|
6
|
+
onError: ErrorHandler;
|
|
7
|
+
}): import("react").JSX.Element | null;
|
|
8
|
+
export declare function SlotsPanel({ session, info, onError, }: {
|
|
9
|
+
session: Session;
|
|
10
|
+
info: NodeInfo;
|
|
11
|
+
onError: ErrorHandler;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
export declare function WeldsPanel({ session, onError }: {
|
|
14
|
+
session: Session;
|
|
15
|
+
onError: ErrorHandler;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
export declare function ModelHealth({ session }: {
|
|
18
|
+
session: Session;
|
|
19
|
+
}): import("react").JSX.Element;
|
|
20
|
+
export declare function ExtensionsPanel({ session, onError }: {
|
|
21
|
+
session: Session;
|
|
22
|
+
onError: ErrorHandler;
|
|
23
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ReviewBadge, ReviewCommentButton } from "./review.js";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useCommand, useModelQuery, useSessionStatus, flattenTree, } from "./authoring.js";
|
|
5
|
+
import { Disclosure, EmptyState, Field, Icon, IconButton, Modal, NumberField } from "./controls.js";
|
|
6
|
+
import { useTree, useReplica } from "./replica.js";
|
|
7
|
+
export function MaskPanel({ session, info, onError, }) {
|
|
8
|
+
const tree = useTree(session);
|
|
9
|
+
const { run, busy } = useCommand(session, onError);
|
|
10
|
+
const [source, setSource] = useState("");
|
|
11
|
+
if (info.kind !== "part" && info.kind !== "composite")
|
|
12
|
+
return null;
|
|
13
|
+
const parts = flattenTree(tree).filter((n) => n.kind === "part" && n.id !== info.id);
|
|
14
|
+
const masks = info.masks ?? [];
|
|
15
|
+
return (_jsx(Disclosure, { title: "Masks", defaultOpen: masks.length > 0, badge: _jsx("span", { "data-catchlight-badge": "", children: masks.length }), children: _jsxs("fieldset", { disabled: busy, children: [masks.map((mask, i) => (_jsxs("div", { "data-catchlight-mask": "", children: [_jsx(Icon, { name: "part" }), _jsx("span", { title: mask.source, children: parts.find((p) => p.id === mask.source)?.name ?? mask.source }), _jsxs("select", { "aria-label": `Mask ${i + 1} mode`, value: mask.mode, onChange: (e) => void run({
|
|
16
|
+
cmd: "edit_apply",
|
|
17
|
+
if_rev: session.getRevision(),
|
|
18
|
+
edits: [
|
|
19
|
+
...masks.map((_, index) => ({ op: "mask_delete", node: info.id, index: masks.length - index - 1 })),
|
|
20
|
+
...masks.map((item, index) => ({ op: "mask_add", node: info.id, source: item.source, mode: index === i ? e.currentTarget.value : item.mode })),
|
|
21
|
+
],
|
|
22
|
+
}), children: [_jsx("option", { value: "mask", children: "Keep inside" }), _jsx("option", { value: "dodge", children: "Cut out" })] }), _jsx(IconButton, { icon: "close", label: `Remove mask ${i + 1}`, onClick: () => void run({ cmd: "mask_delete", node: info.id, index: i }) })] }, `${i}:${mask.source}`))), _jsxs("div", { "data-catchlight-inline": "", children: [_jsxs("select", { "aria-label": "Mask source", value: source, onChange: (e) => setSource(e.currentTarget.value), children: [_jsx("option", { value: "", children: "Choose a source part\u2026" }), parts.map((p) => (_jsx("option", { value: p.id, children: p.name }, p.id)))] }), _jsx(IconButton, { icon: "plus", label: "Add mask", disabled: !source, onClick: () => void run({
|
|
23
|
+
cmd: "mask_add",
|
|
24
|
+
node: info.id,
|
|
25
|
+
source,
|
|
26
|
+
mode: "mask",
|
|
27
|
+
}).then(() => setSource("")) })] }), !masks.length && (_jsx("p", { "data-catchlight-hint": "", children: "Clip this artwork to another part\u2019s silhouette." }))] }) }));
|
|
28
|
+
}
|
|
29
|
+
export function SlotsPanel({ session, info, onError, }) {
|
|
30
|
+
const { slots } = useModelQuery(session, { cmd: "slot_list", node: info.id }, "slots");
|
|
31
|
+
const { run, busy } = useCommand(session, onError);
|
|
32
|
+
return (_jsxs(Disclosure, { title: "Vertex slots", defaultOpen: false, badge: _jsx("span", { "data-catchlight-badge": "", children: slots.length }), children: [_jsx("p", { "data-catchlight-hint": "", children: "Give a vertex an Id so welds and motion responses can refer to it." }), _jsxs("fieldset", { disabled: busy, children: [slots.map((slot) => (_jsxs("div", { "data-catchlight-slot": "", children: [_jsx("span", { title: slot.id, children: slot.id }), _jsx(ReviewBadge, { target: { kind: "slot", node: info.id, slot: slot.id }, label: slot.id }), _jsx(ReviewCommentButton, { target: { kind: "slot", node: info.id, slot: slot.id }, label: `slot ${slot.id}` }), _jsx(NumberField, { label: `${slot.id} vertex`, value: slot.vertex ?? 0, min: 0, max: Math.max(0, (info.vertex_count ?? 1) - 1), step: 1, onCommit: (vertex) => void run({
|
|
33
|
+
cmd: "slot_fill",
|
|
34
|
+
node: info.id,
|
|
35
|
+
slot: slot.id,
|
|
36
|
+
vertex,
|
|
37
|
+
}) }), slot.vertex == null ? (_jsx("button", { type: "button", onClick: () => void run({
|
|
38
|
+
cmd: "slot_fill",
|
|
39
|
+
node: info.id,
|
|
40
|
+
slot: slot.id,
|
|
41
|
+
vertex: 0,
|
|
42
|
+
}), disabled: !info.vertex_count, children: "Fill" })) : (_jsx(IconButton, { icon: "minus", label: `Clear ${slot.id}`, onClick: () => void run({ cmd: "slot_clear", node: info.id, slot: slot.id }) })), _jsx(IconButton, { icon: "trash", label: `Delete ${slot.id}`, onClick: () => void run({ cmd: "slot_delete", node: info.id, slot: slot.id }) })] }, slot.id))), _jsxs("button", { type: "button", "data-catchlight-action": "", onClick: () => void run({ cmd: "slot_add", node: info.id }), children: [_jsx(Icon, { name: "plus" }), "Add slot"] })] })] }));
|
|
43
|
+
}
|
|
44
|
+
export function WeldsPanel({ session, onError }) {
|
|
45
|
+
const { welds } = useModelQuery(session, { cmd: "weld_list" }, "welds");
|
|
46
|
+
const parts = flattenTree(useTree(session)).filter((n) => n.kind === "part");
|
|
47
|
+
const { run, busy } = useCommand(session, onError);
|
|
48
|
+
const [adding, setAdding] = useState(false);
|
|
49
|
+
const name = (id) => parts.find((p) => p.id === id)?.name ?? id;
|
|
50
|
+
return (_jsxs(_Fragment, { children: [!welds.length && (_jsx(EmptyState, { icon: "link", title: "No connected parts", children: "Weld pairs of slots to keep a join closed as the artwork deforms." })), welds.map((w) => (_jsxs(Disclosure, { title: `${name(w.a)} ↔ ${name(w.b)}`, children: [w.pairs.map((pair) => (_jsx(Field, { label: `${pair.a} → ${pair.b}`, children: _jsx(NumberField, { label: `${pair.a} weld weight`, value: pair.weight, min: 0, max: 1, step: 0.05, onCommit: (weight) => void run({
|
|
51
|
+
cmd: "edit_apply",
|
|
52
|
+
if_rev: session.getRevision(),
|
|
53
|
+
edits: [{
|
|
54
|
+
op: "weld_set",
|
|
55
|
+
a: w.a,
|
|
56
|
+
b: w.b,
|
|
57
|
+
pairs: w.pairs.map((item) => item.a === pair.a ? { ...item, weight } : item),
|
|
58
|
+
}],
|
|
59
|
+
}) }) }, pair.a))), _jsx("button", { type: "button", "data-catchlight-danger": "", disabled: busy, onClick: () => void run({ cmd: "weld_delete", a: w.a, b: w.b }), children: "Remove weld" })] }, `${w.a}:${w.b}`))), _jsxs("button", { type: "button", "data-catchlight-action": "", disabled: parts.length < 2, onClick: () => setAdding(true), children: [_jsx(Icon, { name: "plus" }), "Connect parts"] }), adding && (_jsx(WeldDialog, { session: session, onError: onError, onClose: () => setAdding(false) }))] }));
|
|
60
|
+
}
|
|
61
|
+
function WeldDialog({ session, onError, onClose, }) {
|
|
62
|
+
const parts = flattenTree(useTree(session)).filter((n) => n.kind === "part");
|
|
63
|
+
const [a, setA] = useState(parts[0]?.id ?? "");
|
|
64
|
+
const [b, setB] = useState(parts[1]?.id ?? "");
|
|
65
|
+
const [pairs, setPairs] = useState([]);
|
|
66
|
+
const left = useModelQuery(session, { cmd: "slot_list", node: a }, "slots").slots;
|
|
67
|
+
const right = useModelQuery(session, { cmd: "slot_list", node: b }, "slots").slots;
|
|
68
|
+
const { run, busy } = useCommand(session, onError);
|
|
69
|
+
return (_jsxs(Modal, { title: "Connect two parts", onClose: onClose, children: [_jsx("p", { "data-catchlight-hint": "", children: "Choose the parts, then pair their named slots. A weight of 0.5 meets halfway." }), _jsx(Field, { label: "First part", children: _jsx("select", { "aria-label": "First weld part", value: a, onChange: (e) => {
|
|
70
|
+
const next = e.currentTarget.value;
|
|
71
|
+
setA(next);
|
|
72
|
+
if (next === b)
|
|
73
|
+
setB(a);
|
|
74
|
+
setPairs([]);
|
|
75
|
+
}, children: parts.map((p) => (_jsx("option", { value: p.id, children: p.name }, p.id))) }) }), _jsx(Field, { label: "Second part", children: _jsx("select", { "aria-label": "Second weld part", value: b, onChange: (e) => {
|
|
76
|
+
setB(e.currentTarget.value);
|
|
77
|
+
setPairs([]);
|
|
78
|
+
}, children: parts
|
|
79
|
+
.filter((p) => p.id !== a)
|
|
80
|
+
.map((p) => (_jsx("option", { value: p.id, children: p.name }, p.id))) }) }), left.map((slot) => (_jsx(Field, { label: slot.id, children: _jsxs("select", { "aria-label": `Pair ${slot.id}`, value: pairs.find((p) => p.a === slot.id)?.b ?? "", onChange: (e) => {
|
|
81
|
+
const to = e.currentTarget.value;
|
|
82
|
+
setPairs((previous) => [
|
|
83
|
+
...previous.filter((p) => p.a !== slot.id),
|
|
84
|
+
...(to ? [{ a: slot.id, b: to, weight: 0.5 }] : []),
|
|
85
|
+
]);
|
|
86
|
+
}, children: [_jsx("option", { value: "", children: "Not paired" }), right
|
|
87
|
+
.filter((r) => !pairs.some((p) => p.b === r.id && p.a !== slot.id))
|
|
88
|
+
.map((r) => (_jsx("option", { value: r.id, children: r.id }, r.id)))] }) }, slot.id))), (!left.length || !right.length) && (_jsx("p", { "data-catchlight-warning": "", children: "Both parts need slots. Add them in the properties panel first." })), _jsxs("div", { "data-catchlight-dialog-actions": "", children: [_jsx("button", { type: "button", onClick: onClose, children: "Cancel" }), _jsx("button", { type: "button", "data-primary": "", disabled: busy || a === b || !pairs.length, onClick: () => void run({ cmd: "weld_set", a, b, pairs }).then((body) => {
|
|
89
|
+
if (body)
|
|
90
|
+
onClose();
|
|
91
|
+
}), children: "Create weld" })] })] }));
|
|
92
|
+
}
|
|
93
|
+
export function ModelHealth({ session }) {
|
|
94
|
+
const { warnings: checked } = useModelQuery(session, { cmd: "model_check" }, "warnings");
|
|
95
|
+
const warnings = [...session.openWarnings, ...checked];
|
|
96
|
+
const tree = useTree(session);
|
|
97
|
+
const count = flattenTree(tree).length;
|
|
98
|
+
const params = useReplica(session, (s) => s.params());
|
|
99
|
+
const textures = useReplica(session, (s) => s.textures());
|
|
100
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { "data-catchlight-model-stats": "", children: [_jsxs("div", { children: [_jsx("b", { children: count }), _jsx("span", { children: "nodes" })] }), _jsxs("div", { children: [_jsx("b", { children: params.length }), _jsx("span", { children: "params" })] }), _jsxs("div", { children: [_jsx("b", { children: textures.length }), _jsx("span", { children: "textures" })] })] }), !warnings.length ? (_jsxs("div", { "data-catchlight-health": "", children: [_jsx(Icon, { name: "check" }), _jsxs("div", { children: [_jsx("strong", { children: "Validation passed" }), _jsx("p", { children: "No warnings." })] })] })) : (_jsxs(_Fragment, { children: [_jsxs("p", { "data-catchlight-hint": "", children: [warnings.length, " ", warnings.length === 1 ? "warning" : "warnings"] }), warnings.map((w, i) => (_jsxs("p", { "data-catchlight-warning": "", children: [_jsx(Icon, { name: "warning" }), w] }, i)))] }))] }));
|
|
101
|
+
}
|
|
102
|
+
function describeExtension(value) {
|
|
103
|
+
switch (value.kind) {
|
|
104
|
+
case "json":
|
|
105
|
+
return "JSON";
|
|
106
|
+
case "bytes":
|
|
107
|
+
return `${value.size.toLocaleString()} bytes`;
|
|
108
|
+
case "maintained": {
|
|
109
|
+
const refs = `${value.refs.length} ${value.refs.length === 1 ? "reference" : "references"}`;
|
|
110
|
+
return value.size == null
|
|
111
|
+
? `Version ${value.version}, ${refs}`
|
|
112
|
+
: `Version ${value.version}, ${refs}, ${value.size.toLocaleString()} bytes`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function describeRef(ref) {
|
|
117
|
+
if ("node" in ref)
|
|
118
|
+
return `Node ${ref.node}`;
|
|
119
|
+
if ("param" in ref)
|
|
120
|
+
return `Param ${ref.param}`;
|
|
121
|
+
if ("texture" in ref)
|
|
122
|
+
return `Texture ${ref.texture}`;
|
|
123
|
+
if ("slot" in ref)
|
|
124
|
+
return `Vertex slot ${ref.slot[1]} on ${ref.slot[0]}`;
|
|
125
|
+
return `Removed: ${describeRef(ref.removed)}`;
|
|
126
|
+
}
|
|
127
|
+
const noop = () => { };
|
|
128
|
+
/** The format's own; the editor refuses to change one through this panel. */
|
|
129
|
+
function isOfficial(key) {
|
|
130
|
+
return key.startsWith("catchlight.");
|
|
131
|
+
}
|
|
132
|
+
export function ExtensionsPanel({ session, onError }) {
|
|
133
|
+
const { extensions } = useModelQuery(session, { cmd: "extension_list" }, "extensions");
|
|
134
|
+
const { run, busy } = useCommand(session, onError);
|
|
135
|
+
const [editing, setEditing] = useState(null);
|
|
136
|
+
const [problem, setProblem] = useState("");
|
|
137
|
+
const update = (patch) => setEditing((e) => (e ? { ...e, ...patch } : e));
|
|
138
|
+
return (_jsxs(_Fragment, { children: [_jsx("p", { "data-catchlight-hint": "", children: "Optional data for your tools and pipeline. Stored with the model." }), extensions.map((ext) => {
|
|
139
|
+
const official = isOfficial(ext.key);
|
|
140
|
+
const value = ext.value;
|
|
141
|
+
const payload = value.kind === "json" || (value.kind === "maintained" && value.value != null)
|
|
142
|
+
? value.value
|
|
143
|
+
: undefined;
|
|
144
|
+
return (_jsxs("div", { "data-catchlight-extension": "", children: [_jsx(Icon, { name: "code" }), _jsxs("span", { children: [ext.key, _jsx("small", { children: describeExtension(value) })] }), payload !== undefined && (_jsx("button", { type: "button", onClick: () => {
|
|
145
|
+
setProblem("");
|
|
146
|
+
setEditing({
|
|
147
|
+
key: ext.key,
|
|
148
|
+
value: JSON.stringify(payload, null, 2),
|
|
149
|
+
...(value.kind === "maintained"
|
|
150
|
+
? { maintained: { version: value.version, refs: value.refs } }
|
|
151
|
+
: {}),
|
|
152
|
+
readOnly: official,
|
|
153
|
+
});
|
|
154
|
+
}, children: official ? "View" : "Edit" })), !official && (_jsx(IconButton, { icon: "trash", label: `Remove ${ext.key}`, onClick: () => void run({ cmd: "extension_delete", key: ext.key }) }))] }, ext.key));
|
|
155
|
+
}), _jsxs("button", { type: "button", "data-catchlight-action": "", onClick: () => {
|
|
156
|
+
setProblem("");
|
|
157
|
+
setEditing({ key: "", value: "{\n \n}", readOnly: false });
|
|
158
|
+
}, children: [_jsx(Icon, { name: "plus" }), "Add extension"] }), editing && (_jsx(Modal, { title: "Extension", onClose: () => setEditing(null), children: _jsxs("form", { onSubmit: (e) => {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
if (editing.readOnly)
|
|
161
|
+
return;
|
|
162
|
+
try {
|
|
163
|
+
const parsed = JSON.parse(editing.value);
|
|
164
|
+
setProblem("");
|
|
165
|
+
void run({
|
|
166
|
+
cmd: "extension_set",
|
|
167
|
+
key: editing.key,
|
|
168
|
+
value: editing.maintained
|
|
169
|
+
? { kind: "maintained", ...editing.maintained, value: parsed }
|
|
170
|
+
: { kind: "json", value: parsed },
|
|
171
|
+
}).then((body) => {
|
|
172
|
+
if (body)
|
|
173
|
+
setEditing(null);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
setProblem("Enter valid JSON before saving.");
|
|
178
|
+
}
|
|
179
|
+
}, children: [_jsxs("label", { "data-catchlight-form-label": "", children: ["Key", _jsx("input", { autoFocus: true, required: true, readOnly: !!editing.maintained || editing.readOnly, value: editing.key, placeholder: "editor.notes", pattern: "[^.]+\\..+", onChange: (e) => update({ key: e.currentTarget.value }) })] }), editing.maintained && (_jsxs("div", { "data-catchlight-extension-refs": "", children: [_jsxs("p", { "data-catchlight-hint": "", children: ["Version ", editing.maintained.version, ". The editor keeps these references current as the model changes."] }), editing.maintained.refs.length === 0 ? (_jsx("p", { "data-catchlight-hint": "", children: "No references." })) : (_jsx("ul", { "aria-label": "References", children: editing.maintained.refs.map((ref, i) => (_jsx("li", { children: describeRef(ref) }, i))) }))] })), _jsxs("label", { "data-catchlight-form-label": "", children: [editing.maintained ? "JSON payload" : "JSON value", _jsx("textarea", { required: true, readOnly: editing.readOnly, spellCheck: false, rows: 10, value: editing.value, onInput: (e) => update({ value: e.currentTarget.value }), onChange: noop })] }), problem && (_jsx("p", { role: "alert", "data-catchlight-warning": "", children: problem })), _jsxs("div", { "data-catchlight-dialog-actions": "", children: [_jsx("button", { type: "button", onClick: () => setEditing(null), children: editing.readOnly ? "Close" : "Cancel" }), !editing.readOnly && (_jsx("button", { type: "submit", "data-primary": "", disabled: busy, children: "Save extension" }))] })] }) }))] }));
|
|
180
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree edits as commands. Indices are read from the replica at call time, not
|
|
3
|
+
* captured, since another client may have reordered the tree since render.
|
|
4
|
+
*/
|
|
5
|
+
import type { NodeId, NodeKindArg, ResponseBody, Session, TreeNode } from "@catchlight/editor-core";
|
|
6
|
+
export type DropAt = "into" | "before" | "after";
|
|
7
|
+
export interface NodeActions {
|
|
8
|
+
addChild(parent: NodeId, kind: NodeKindArg, name?: string): Promise<NodeId>;
|
|
9
|
+
/** Deletes the node and its subtree, clearing the selection if it was in it. */
|
|
10
|
+
remove(node: NodeId): Promise<ResponseBody>;
|
|
11
|
+
/** Deep-copies the node's subtree as its next sibling. */
|
|
12
|
+
duplicate(node: NodeId): Promise<ResponseBody>;
|
|
13
|
+
rename(node: NodeId, name: string): Promise<ResponseBody>;
|
|
14
|
+
setEnabled(node: NodeId, enabled: boolean): Promise<ResponseBody>;
|
|
15
|
+
/** Puts the node under `parent` at `index`, counted with the node removed. */
|
|
16
|
+
move(node: NodeId, parent: NodeId, index: number): Promise<ResponseBody>;
|
|
17
|
+
moveUp(node: NodeId): Promise<ResponseBody>;
|
|
18
|
+
moveDown(node: NodeId): Promise<ResponseBody>;
|
|
19
|
+
}
|
|
20
|
+
/** Must sit under a `<SelectionProvider>`: deleting the selected node clears the selection. */
|
|
21
|
+
export declare function useNodeActions(session: Session): NodeActions;
|
|
22
|
+
export declare function findNode(tree: TreeNode, node: NodeId): TreeNode | undefined;
|
|
23
|
+
export interface SiblingIndex {
|
|
24
|
+
parent: TreeNode;
|
|
25
|
+
index: number;
|
|
26
|
+
}
|
|
27
|
+
/** `undefined` for the root and for a node the tree does not carry. */
|
|
28
|
+
export declare function siblingIndex(tree: TreeNode, node: NodeId): SiblingIndex | undefined;
|
|
29
|
+
/** Whether `node` is `held`'s subtree root or anywhere inside it. */
|
|
30
|
+
export declare function subtreeHolds(held: TreeNode | undefined, node: NodeId | undefined): boolean;
|
|
31
|
+
/** Every Id in this subtree, its own included — what a drop may not land on. */
|
|
32
|
+
export declare function subtreeIds(tree: TreeNode): Set<NodeId>;
|
|
33
|
+
export interface Drop {
|
|
34
|
+
parent: NodeId;
|
|
35
|
+
index: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A drop beside a row counts the target's siblings with the dragged node
|
|
39
|
+
* already removed, the list the model reinserts into. `undefined` for a drop
|
|
40
|
+
* onto the node itself, into its own subtree, or beside the root.
|
|
41
|
+
*/
|
|
42
|
+
export declare function dropIndex(tree: TreeNode, node: NodeId, target: NodeId, where: DropAt): Drop | undefined;
|