@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.
Files changed (111) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +26 -2
  4. package/THIRD-PARTY-NOTICES.md +331 -0
  5. package/dist/editor/CatchlightEditor.d.ts +21 -0
  6. package/dist/editor/CatchlightEditor.js +720 -0
  7. package/dist/editor/dialogs.d.ts +18 -0
  8. package/dist/editor/dialogs.js +71 -0
  9. package/dist/editor/import-panel.d.ts +6 -0
  10. package/dist/editor/import-panel.js +98 -0
  11. package/dist/editor/logo.svg +11 -0
  12. package/dist/editor/notification.d.ts +4 -0
  13. package/dist/editor/notification.js +24 -0
  14. package/dist/editor/stage.d.ts +13 -0
  15. package/dist/editor/stage.js +23 -0
  16. package/dist/editor/test/setup.d.ts +5 -0
  17. package/dist/editor/test/setup.js +5 -0
  18. package/dist/index.d.ts +11 -0
  19. package/dist/index.js +10 -0
  20. package/dist/lib/animations-panel.d.ts +10 -0
  21. package/dist/lib/animations-panel.js +48 -0
  22. package/dist/lib/authoring.d.ts +17 -0
  23. package/dist/lib/authoring.js +116 -0
  24. package/dist/lib/binding-grid.d.ts +19 -0
  25. package/dist/lib/binding-grid.js +92 -0
  26. package/dist/lib/bindings.d.ts +21 -0
  27. package/dist/lib/bindings.js +100 -0
  28. package/dist/lib/camera.d.ts +21 -0
  29. package/dist/lib/camera.js +61 -0
  30. package/dist/lib/controls-panel.d.ts +36 -0
  31. package/dist/lib/controls-panel.js +201 -0
  32. package/dist/lib/controls.d.ts +103 -0
  33. package/dist/lib/controls.js +163 -0
  34. package/dist/lib/editing.d.ts +126 -0
  35. package/dist/lib/editing.js +415 -0
  36. package/dist/lib/editor-context.d.ts +15 -0
  37. package/dist/lib/editor-context.js +23 -0
  38. package/dist/lib/expressions-panel.d.ts +10 -0
  39. package/dist/lib/expressions-panel.js +120 -0
  40. package/dist/lib/file-open.d.ts +11 -0
  41. package/dist/lib/file-open.js +25 -0
  42. package/dist/lib/file-save.d.ts +29 -0
  43. package/dist/lib/file-save.js +68 -0
  44. package/dist/lib/gizmo.d.ts +13 -0
  45. package/dist/lib/gizmo.js +247 -0
  46. package/dist/lib/image-markup.d.ts +12 -0
  47. package/dist/lib/image-markup.js +153 -0
  48. package/dist/lib/index.d.ts +71 -0
  49. package/dist/lib/index.js +44 -0
  50. package/dist/lib/inspector.d.ts +19 -0
  51. package/dist/lib/inspector.js +161 -0
  52. package/dist/lib/latest.d.ts +3 -0
  53. package/dist/lib/latest.js +9 -0
  54. package/dist/lib/layer-import.d.ts +38 -0
  55. package/dist/lib/layer-import.js +187 -0
  56. package/dist/lib/mesh-editor.d.ts +13 -0
  57. package/dist/lib/mesh-editor.js +337 -0
  58. package/dist/lib/model-panels.d.ts +23 -0
  59. package/dist/lib/model-panels.js +180 -0
  60. package/dist/lib/node-actions.d.ts +42 -0
  61. package/dist/lib/node-actions.js +115 -0
  62. package/dist/lib/node-drag.d.ts +18 -0
  63. package/dist/lib/node-drag.js +65 -0
  64. package/dist/lib/node-patch.d.ts +8 -0
  65. package/dist/lib/node-patch.js +10 -0
  66. package/dist/lib/node-tree.d.ts +36 -0
  67. package/dist/lib/node-tree.js +221 -0
  68. package/dist/lib/official.d.ts +82 -0
  69. package/dist/lib/official.js +197 -0
  70. package/dist/lib/param-actions.d.ts +48 -0
  71. package/dist/lib/param-actions.js +106 -0
  72. package/dist/lib/param-list.d.ts +36 -0
  73. package/dist/lib/param-list.js +73 -0
  74. package/dist/lib/param-slider.d.ts +44 -0
  75. package/dist/lib/param-slider.js +149 -0
  76. package/dist/lib/pose.d.ts +13 -0
  77. package/dist/lib/pose.js +32 -0
  78. package/dist/lib/posing-panel.d.ts +40 -0
  79. package/dist/lib/posing-panel.js +154 -0
  80. package/dist/lib/presence.d.ts +27 -0
  81. package/dist/lib/presence.js +98 -0
  82. package/dist/lib/properties-panel.d.ts +13 -0
  83. package/dist/lib/properties-panel.js +63 -0
  84. package/dist/lib/recording-panel.d.ts +4 -0
  85. package/dist/lib/recording-panel.js +161 -0
  86. package/dist/lib/replica.d.ts +18 -0
  87. package/dist/lib/replica.js +34 -0
  88. package/dist/lib/review.d.ts +113 -0
  89. package/dist/lib/review.js +529 -0
  90. package/dist/lib/rigging.d.ts +10 -0
  91. package/dist/lib/rigging.js +116 -0
  92. package/dist/lib/selection.d.ts +3 -0
  93. package/dist/lib/selection.js +2 -0
  94. package/dist/lib/session-list.d.ts +16 -0
  95. package/dist/lib/session-list.js +7 -0
  96. package/dist/lib/sessions.d.ts +8 -0
  97. package/dist/lib/sessions.js +29 -0
  98. package/dist/lib/test/harness.d.ts +32 -0
  99. package/dist/lib/test/harness.js +139 -0
  100. package/dist/lib/test/setup.d.ts +4 -0
  101. package/dist/lib/test/setup.js +5 -0
  102. package/dist/lib/versions.d.ts +69 -0
  103. package/dist/lib/versions.js +250 -0
  104. package/dist/lib/viewport.d.ts +57 -0
  105. package/dist/lib/viewport.js +315 -0
  106. package/dist/lib/workspace-layout.d.ts +24 -0
  107. package/dist/lib/workspace-layout.js +145 -0
  108. package/dist/lib/workspace.d.ts +29 -0
  109. package/dist/lib/workspace.js +263 -0
  110. package/dist/theme.css +4577 -0
  111. package/package.json +32 -6
@@ -0,0 +1,529 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore, } from "react";
3
+ import { kindIcons } from "./authoring.js";
4
+ import { useLatest } from "./latest.js";
5
+ import { Icon, IconButton, Modal } from "./controls.js";
6
+ import { useEditing } from "./editing.js";
7
+ import { ImageMarkup } from "./image-markup.js";
8
+ import { findNode } from "./node-actions.js";
9
+ import { readPose } from "./pose.js";
10
+ import { useSelection } from "./presence.js";
11
+ import { useRevision } from "./replica.js";
12
+ const NO_REVIEW = { threads: [], agents: [], kept: "stored" };
13
+ const neverChanges = () => () => { };
14
+ const noReview = () => NO_REVIEW;
15
+ const ReviewContext = createContext(undefined);
16
+ export function ReviewProvider({ session, onError, reviewer, onAttention, onOpenVersion, children, }) {
17
+ const review = useSyncExternalStore(session?.subscribeReview ?? neverChanges, session?.getReview ?? noReview, session?.getReview ?? noReview);
18
+ const [pending, setPending] = useState(0);
19
+ const [aim, setAim] = useState({
20
+ session,
21
+ });
22
+ const here = aim.session === session ? aim : { session };
23
+ // By value: a host passing a fresh object each render must not churn the context.
24
+ const reviewerId = reviewer?.id;
25
+ const reviewerName = reviewer?.name;
26
+ const live = useRef({ session, onError, onAttention, reviewer });
27
+ live.current = { session, onError, onAttention, reviewer };
28
+ const person = () => {
29
+ const who = live.current.reviewer;
30
+ return who ? { role: "human", id: who.id, name: who.name } : { role: "human" };
31
+ };
32
+ const run = useCallback(async (work) => {
33
+ const { session, onError } = live.current;
34
+ if (!session)
35
+ return false;
36
+ setPending((n) => n + 1);
37
+ try {
38
+ await work(session);
39
+ return true;
40
+ }
41
+ catch (cause) {
42
+ onError(cause);
43
+ return false;
44
+ }
45
+ finally {
46
+ setPending((n) => n - 1);
47
+ }
48
+ }, []);
49
+ const actions = useMemo(() => ({
50
+ fail(cause) {
51
+ live.current.onError(cause);
52
+ },
53
+ compose(target) {
54
+ setAim((was) => ({
55
+ session: live.current.session,
56
+ ...(target ? { target } : {}),
57
+ ...(was.thread !== undefined && was.session === live.current.session ? { thread: was.thread } : {}),
58
+ }));
59
+ if (target)
60
+ live.current.onAttention?.();
61
+ },
62
+ focus(thread) {
63
+ setAim((was) => ({
64
+ session: live.current.session,
65
+ ...(was.target && was.session === live.current.session ? { target: was.target } : {}),
66
+ ...(thread !== undefined ? { thread } : {}),
67
+ }));
68
+ if (thread !== undefined)
69
+ live.current.onAttention?.();
70
+ },
71
+ open: (target, body, images = []) => run(async (session) => {
72
+ const reply = await session.sendReview({
73
+ cmd: "review_thread_add",
74
+ target,
75
+ author: person(),
76
+ body,
77
+ pose: readPose(session),
78
+ images: await upload(session, images),
79
+ });
80
+ setAim({
81
+ session,
82
+ ...(reply.result === "review_thread" ? { thread: reply.thread.thread } : {}),
83
+ });
84
+ }),
85
+ reply: (thread, body, images = []) => run(async (session) => session.sendReview({
86
+ cmd: "review_comment_add",
87
+ thread,
88
+ author: person(),
89
+ body,
90
+ images: await upload(session, images),
91
+ })),
92
+ setStatus: (thread, status) => run((session) => session.sendReview({ cmd: "review_thread_set", thread, status })),
93
+ removeThread: (thread) => run((session) => session.sendReview({ cmd: "review_thread_delete", thread })),
94
+ removeComment: (thread, comment) => run((session) => session.sendReview({ cmd: "review_comment_delete", thread, comment })),
95
+ send: () => run((session) => session.sendReview({ cmd: "review_submit" })),
96
+ }), [run]);
97
+ const value = useMemo(() => {
98
+ const open = review.threads.filter((thread) => thread.status === "open");
99
+ const agents = review.agents;
100
+ return {
101
+ session,
102
+ review,
103
+ agents,
104
+ reviewer: reviewerId === undefined ? undefined : { id: reviewerId, name: reviewerName ?? "" },
105
+ phase: open.some((thread) => thread.holder)
106
+ ? "working"
107
+ : agents.some((agent) => agent.listening)
108
+ ? "listening"
109
+ : agents.length > 0
110
+ ? "away"
111
+ : "absent",
112
+ unsent: open.reduce((n, thread) => n + thread.comments.filter(isUnsent).length, 0),
113
+ waiting: open.filter((thread) => thread.comments.some((c) => c.delivery === "sent")).length,
114
+ replied: open.filter(agentSpokeLast).length,
115
+ busy: pending > 0,
116
+ composing: here.target,
117
+ focused: here.thread,
118
+ openVersion: onOpenVersion,
119
+ ...actions,
120
+ };
121
+ }, [session, review, pending, here.target, here.thread, actions, reviewerId, reviewerName, onOpenVersion]);
122
+ return _jsx(ReviewContext.Provider, { value: value, children: children });
123
+ }
124
+ async function upload(session, images) {
125
+ const ids = [];
126
+ // In order: a comment shows its images as they were attached.
127
+ for (const image of images) {
128
+ const held = await session.addReviewImage(new Uint8Array(await image.arrayBuffer()));
129
+ ids.push(held.image);
130
+ }
131
+ return ids;
132
+ }
133
+ /** `undefined` outside a [`ReviewProvider`], so a part can be used without review. */
134
+ export function useReview() {
135
+ return useContext(ReviewContext);
136
+ }
137
+ function isUnsent(comment) {
138
+ return comment.author.role === "human" && comment.delivery === "unsent";
139
+ }
140
+ function agentSpokeLast(thread) {
141
+ return thread.comments[thread.comments.length - 1]?.author.role === "agent";
142
+ }
143
+ /** Whether a person's comment is the viewer's: same id, or neither has one. */
144
+ export function isViewer(author, reviewer) {
145
+ return author.role === "human" && (author.id ?? undefined) === reviewer?.id;
146
+ }
147
+ /** Who is attending, in a few words: one agent by name, several by count. */
148
+ export function agentsLabel(agents) {
149
+ if (agents.length > 1)
150
+ return `${agents.length} agents`;
151
+ return agents[0]?.name;
152
+ }
153
+ export function sameTarget(a, b) {
154
+ if (a.kind !== b.kind)
155
+ return false;
156
+ switch (a.kind) {
157
+ case "model":
158
+ return true;
159
+ case "node":
160
+ return a.node === b.node;
161
+ case "param":
162
+ return a.param === b.param;
163
+ case "texture":
164
+ return a.texture === b.texture;
165
+ case "slot":
166
+ return a.node === b.node && a.slot === b.slot;
167
+ }
168
+ }
169
+ /** A slot's thread counts toward its node, so a tree row shows it. */
170
+ function isAbout(thread, target) {
171
+ if (sameTarget(thread.target, target))
172
+ return true;
173
+ return target.kind === "node" && thread.target.kind === "slot" && thread.target.node === target.node;
174
+ }
175
+ export function targetLabel(target, tree, params) {
176
+ switch (target.kind) {
177
+ case "model":
178
+ return { icon: "composite", kind: "Model", name: "Whole model" };
179
+ case "node": {
180
+ const node = tree && findNode(tree, target.node);
181
+ return {
182
+ icon: node ? kindIcons[node.kind] : "group",
183
+ kind: "Node",
184
+ name: node?.name ?? target.node,
185
+ };
186
+ }
187
+ case "param":
188
+ return {
189
+ icon: "settings",
190
+ kind: "Param",
191
+ name: params.find((param) => param.id === target.param)?.name ?? target.param,
192
+ };
193
+ case "texture":
194
+ return { icon: "part", kind: "Texture", name: target.texture };
195
+ case "slot": {
196
+ const node = tree && findNode(tree, target.node);
197
+ return { icon: "link", kind: "Vertex slot", name: `${node?.name ?? target.node} · ${target.slot}` };
198
+ }
199
+ }
200
+ }
201
+ /**
202
+ * How many open threads are about `target`; renders nothing at zero. Clicking
203
+ * focuses the newest. `data-attention` marks an agent reply waiting to be read.
204
+ */
205
+ export function ReviewBadge({ target, label }) {
206
+ const review = useReview();
207
+ if (!review)
208
+ return null;
209
+ const threads = review.review.threads.filter((thread) => thread.status === "open" && isAbout(thread, target));
210
+ const newest = threads[threads.length - 1];
211
+ if (!newest)
212
+ return null;
213
+ return (_jsxs("button", { type: "button", "data-catchlight-review-badge": "", "data-attention": threads.some(agentSpokeLast) ? "" : undefined, "data-working": threads.some((thread) => thread.holder) ? "" : undefined, "aria-label": `${threads.length} open ${threads.length === 1 ? "thread" : "threads"} on ${label}`, title: `${threads.length} open ${threads.length === 1 ? "thread" : "threads"}`, onClick: (event) => {
214
+ event.stopPropagation();
215
+ review.focus(newest.thread);
216
+ }, children: [_jsx(Icon, { name: "comment", width: "12", height: "12" }), threads.length] }));
217
+ }
218
+ /** Starts a comment on `target`; renders nothing outside a [`ReviewProvider`]. */
219
+ export function ReviewCommentButton({ target, label }) {
220
+ const review = useReview();
221
+ if (!review)
222
+ return null;
223
+ return (_jsx(IconButton, { icon: "comment", label: `Comment on ${label}`, "data-catchlight-review-comment-on": "", onClick: (event) => {
224
+ event.stopPropagation();
225
+ review.compose(target);
226
+ } }));
227
+ }
228
+ const PHASE_TEXT = {
229
+ absent: "No agent connected",
230
+ away: "Agent away",
231
+ listening: "Agent listening",
232
+ working: "Agent working",
233
+ };
234
+ /** The agent's state and the send action, small enough for a toolbar. */
235
+ export function ReviewStatus({ onOpen }) {
236
+ const review = useReview();
237
+ if (!review?.session)
238
+ return null;
239
+ const { phase, agents, unsent, replied } = review;
240
+ const who = agentsLabel(agents);
241
+ return (_jsxs("div", { "data-catchlight-review-status": "", "data-phase": phase, children: [_jsxs("button", { type: "button", "data-catchlight-review-agent": "", title: who ? `${agents.map((agent) => agent.name).join(", ")}: ${PHASE_TEXT[phase].toLowerCase()}` : PHASE_TEXT[phase], onClick: onOpen, children: [_jsx("i", { "data-catchlight-review-dot": "" }), _jsx("span", { children: phase === "absent" ? "Review" : (who ?? "Agent") }), _jsx("small", { children: phase === "absent" ? "" : PHASE_TEXT[phase].replace("Agent ", "") }), replied > 0 && _jsx("b", { "data-catchlight-review-count": "", children: replied })] }), unsent > 0 && (_jsxs("button", { type: "button", "data-primary": "", "data-catchlight-review-send": "", disabled: review.busy, onClick: () => void review.send(), children: [_jsx(Icon, { name: "send", width: "14", height: "14" }), "Send \u00B7 ", unsent] }))] }));
242
+ }
243
+ function useLabels(session) {
244
+ const revision = useRevision(session);
245
+ return useMemo(() => {
246
+ const tree = session.tree();
247
+ const params = session.params();
248
+ return (target) => targetLabel(target, tree, params);
249
+ }, [session, revision]);
250
+ }
251
+ export function ReviewPanel({ session, connect, capture }) {
252
+ const review = useReview();
253
+ const { node, select } = useSelection();
254
+ const editing = useEditing();
255
+ const label = useLabels(session);
256
+ const [tab, setTab] = useState("open");
257
+ const list = useRef(null);
258
+ const focused = review?.focused;
259
+ const focusedStatus = useLatest(review?.review.threads.find((thread) => thread.thread === focused)?.status);
260
+ // On focus only: resolving the focused thread must not drag the tab along.
261
+ useEffect(() => {
262
+ if (focusedStatus.current)
263
+ setTab(focusedStatus.current);
264
+ }, [focused, focusedStatus]);
265
+ useEffect(() => {
266
+ if (focused === undefined)
267
+ return;
268
+ list.current
269
+ ?.querySelector(`[data-thread="${focused}"]`)
270
+ ?.scrollIntoView?.({ block: "nearest" });
271
+ }, [focused, tab]);
272
+ if (!review)
273
+ return null;
274
+ const { phase, agents, unsent, waiting } = review;
275
+ const threads = review.review.threads
276
+ .filter((thread) => thread.status === tab)
277
+ .sort((a, b) => lastComment(b) - lastComment(a));
278
+ const count = (status) => review.review.threads.filter((thread) => thread.status === status).length;
279
+ const selected = node ? { kind: "node", node } : { kind: "model" };
280
+ const texture = node ? session.nodeInfo(node)?.texture : undefined;
281
+ const offers = [
282
+ ...(node ? [{ kind: "node", node }] : []),
283
+ ...(texture ? [{ kind: "texture", texture }] : []),
284
+ ...(editing?.param ? [{ kind: "param", param: editing.param }] : []),
285
+ { kind: "model" },
286
+ ];
287
+ const locate = (thread) => {
288
+ review.focus(thread.thread);
289
+ if (thread.target_missing)
290
+ return;
291
+ const target = thread.target;
292
+ if (target.kind === "node" || target.kind === "slot")
293
+ select(target.node);
294
+ else if (target.kind === "param")
295
+ editing?.selectParam(target.param);
296
+ };
297
+ const restorePose = (thread) => {
298
+ for (const { param, value } of thread.pose)
299
+ session.setParam(param, value);
300
+ };
301
+ return (_jsxs("section", { "data-catchlight-review": "", "data-phase": phase, "aria-label": "Review", children: [_jsxs("header", { "data-catchlight-review-header": "", children: [_jsxs("div", { "data-catchlight-review-agent": "", "data-phase": phase, children: [_jsx("i", { "data-catchlight-review-dot": "" }), _jsxs("span", { children: [_jsx("strong", { title: agents.map((agent) => agent.name).join(", "), children: agentsLabel(agents) ?? "No agent connected" }), _jsx("small", { children: phase === "absent"
302
+ ? "Comments wait here until one joins"
303
+ : phase === "working"
304
+ ? "Working on your comments"
305
+ : phase === "listening"
306
+ ? waiting > 0
307
+ ? "Picking up your comments…"
308
+ : "Listening for comments"
309
+ : waiting > 0
310
+ ? `${waiting} ${waiting === 1 ? "thread" : "threads"} waiting to be picked up`
311
+ : "Not listening right now" })] })] }), _jsxs("button", { type: "button", "data-primary": "", "data-catchlight-review-send": "", disabled: unsent === 0 || review.busy, title: unsent === 0 ? "Nothing new to send" : "Send your comments to the agent", onClick: () => void review.send(), children: [_jsx(Icon, { name: "send", width: "14", height: "14" }), unsent > 0 ? `Send to agent · ${unsent}` : "Send to agent"] })] }), _jsx(ReviewKeptNote, { review: review.review }), connect && (phase === "absent" || phase === "away") && (_jsx("div", { "data-catchlight-review-connect": "", children: connect })), _jsx("div", { "data-catchlight-review-tabs": "", role: "tablist", children: ["open", "resolved"].map((status) => (_jsxs("button", { type: "button", role: "tab", "aria-selected": tab === status, "data-active": tab === status ? "" : undefined, onClick: () => setTab(status), children: [status === "open" ? "Open" : "Resolved", _jsx("small", { children: count(status) })] }, status))) }), review.composing ? (_jsx(ReviewComposer, { target: review.composing, offers: offers, label: label, busy: review.busy, capture: capture, onError: review.fail, onTarget: review.compose, onCancel: () => review.compose(undefined), onSubmit: (body, images) => review.open(review.composing, body, images) }, JSON.stringify(review.composing))) : (_jsxs("button", { type: "button", "data-catchlight-review-new": "", onClick: () => review.compose(selected), children: [_jsx(Icon, { name: "comment", width: "15", height: "15" }), _jsxs("span", { children: ["Comment on ", _jsx("strong", { children: label(selected).name })] }), _jsx("kbd", { children: "C" })] })), _jsx("ol", { "data-catchlight-review-threads": "", ref: list, children: threads.map((thread) => (_jsx(ReviewThreadCard, { thread: thread, label: label(thread.target), session: session, reviewer: review.reviewer, focused: thread.thread === focused, busy: review.busy, capture: capture, onError: review.fail, onLocate: () => locate(thread), onPose: thread.pose.length ? () => restorePose(thread) : undefined, onReply: (body, images) => review.reply(thread.thread, body, images), onStatus: (status) => void review.setStatus(thread.thread, status), onDelete: () => void review.removeThread(thread.thread), onDeleteComment: (comment) => void review.removeComment(thread.thread, comment), onOpenVersion: review.openVersion }, thread.thread))) }), threads.length === 0 && !review.composing && (_jsx("p", { "data-catchlight-review-empty": "", children: tab === "open"
312
+ ? "Select anything in the model and leave a comment. Send them together when you are ready."
313
+ : "Resolved threads collect here." }))] }));
314
+ }
315
+ function lastComment(thread) {
316
+ return thread.comments[thread.comments.length - 1]?.comment ?? 0;
317
+ }
318
+ /** How long the comments last, said only when it is not "with the model". */
319
+ function ReviewKeptNote({ review }) {
320
+ if (review.kept === "unreadable")
321
+ return (_jsx("p", { "data-catchlight-review-kept": "unreadable", role: "status", title: review.kept_problem ?? undefined, children: "The comments saved with this model could not be read and were left untouched. New ones last until this editor closes." }));
322
+ if (review.kept === "stored" || review.threads.length === 0)
323
+ return null;
324
+ return (_jsx("p", { "data-catchlight-review-kept": review.kept, role: "status", children: review.kept === "unsaved"
325
+ ? "Save the model to keep these comments."
326
+ : "Comments last until this editor closes." }));
327
+ }
328
+ /** A message for the person to hand their own agent, with a copy button. */
329
+ export function AgentPrompt({ children, prompt }) {
330
+ const [copied, setCopied] = useState(false);
331
+ return (_jsxs("div", { "data-catchlight-agent-prompt": "", children: [children, _jsx("code", { children: prompt }), _jsxs("button", { type: "button", onClick: () => {
332
+ void navigator.clipboard?.writeText(prompt).then(() => setCopied(true));
333
+ }, children: [_jsx(Icon, { name: copied ? "check" : "duplicate", width: "14", height: "14" }), copied ? "Copied" : "Copy prompt"] })] }));
334
+ }
335
+ // A controlled field needs `onChange`; the native input event is handled once
336
+ // through `onInput`.
337
+ function noop() { }
338
+ function submitOnModEnter(event, submit) {
339
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
340
+ event.preventDefault();
341
+ submit();
342
+ }
343
+ }
344
+ function ReviewComposer({ target, offers, label, busy, capture, onError, onTarget, onCancel, onSubmit, }) {
345
+ const [body, setBody] = useState("");
346
+ const attached = useAttachments(capture, onError);
347
+ const choices = offers.some((offer) => sameTarget(offer, target)) ? offers : [target, ...offers];
348
+ const empty = body.trim() === "" && attached.blobs.length === 0;
349
+ const submit = () => {
350
+ if (empty || busy)
351
+ return;
352
+ void onSubmit(body.trim(), attached.blobs);
353
+ };
354
+ return (_jsxs("form", { "data-catchlight-review-composer": "", onDrop: attached.onDrop, onDragOver: allowImageDrop, onSubmit: (event) => {
355
+ event.preventDefault();
356
+ submit();
357
+ }, children: [_jsx("div", { "data-catchlight-review-targets": "", role: "radiogroup", "aria-label": "Comment on", children: choices.map((choice) => {
358
+ const text = label(choice);
359
+ const active = sameTarget(choice, target);
360
+ return (_jsxs("button", { type: "button", role: "radio", "aria-checked": active, "data-active": active ? "" : undefined, title: `${text.kind}: ${text.name}`, onClick: () => onTarget(choice), children: [_jsx(Icon, { name: text.icon, width: "13", height: "13" }), text.name] }, JSON.stringify(choice)));
361
+ }) }), _jsx("textarea", { autoFocus: true, rows: 3, "aria-label": `Comment on ${label(target).name}`, placeholder: "What should change?", value: body, onInput: (event) => setBody(event.currentTarget.value), onChange: noop, onPaste: attached.onPaste, onKeyDown: (event) => {
362
+ if (event.key === "Escape") {
363
+ event.preventDefault();
364
+ event.stopPropagation();
365
+ onCancel();
366
+ }
367
+ else
368
+ submitOnModEnter(event, submit);
369
+ } }), _jsx(AttachmentStrip, { attached: attached }), _jsxs("div", { "data-catchlight-review-composer-actions": "", children: [_jsx(AttachButtons, { attached: attached }), _jsx("button", { type: "button", onClick: onCancel, children: "Cancel" }), _jsx("button", { type: "submit", "data-primary": "", disabled: empty || busy, children: "Comment" })] })] }));
370
+ }
371
+ const DELIVERY_TEXT = { unsent: "Not sent", sent: "Sent", delivered: "Seen" };
372
+ function ReviewThreadCard({ thread, label, session, reviewer, focused, busy, capture, onError, onLocate, onPose, onReply, onStatus, onDelete, onDeleteComment, onOpenVersion, }) {
373
+ const [reply, setReply] = useState("");
374
+ const [replying, setReplying] = useState(false);
375
+ const attached = useAttachments(capture, onError);
376
+ const resolved = thread.status === "resolved";
377
+ const empty = reply.trim() === "" && attached.blobs.length === 0;
378
+ const submit = () => {
379
+ if (empty || busy)
380
+ return;
381
+ void onReply(reply.trim(), attached.blobs).then((sent) => {
382
+ if (!sent)
383
+ return;
384
+ setReply("");
385
+ attached.clear();
386
+ setReplying(false);
387
+ });
388
+ };
389
+ return (_jsxs("li", { "data-catchlight-review-thread": "", "data-thread": thread.thread, "data-status": thread.status, "data-focused": focused ? "" : undefined, "data-working": thread.holder ? "" : undefined, "data-attention": !resolved && agentSpokeLast(thread) ? "" : undefined, "data-missing": thread.target_missing ? "" : undefined, children: [_jsxs("header", { children: [_jsxs("button", { type: "button", "data-catchlight-review-target": "", title: thread.target_missing ? `${label.name} is no longer in the model` : `Show ${label.name}`, onClick: onLocate, children: [_jsx(Icon, { name: label.icon, width: "14", height: "14" }), _jsx("span", { children: label.name }), _jsx("small", { children: thread.target_missing ? "removed" : label.kind })] }), onPose && (_jsx(IconButton, { icon: "reset", label: "Restore the pose this was written at", onClick: onPose })), _jsx(IconButton, { icon: "trash", label: "Delete thread", disabled: busy, onClick: onDelete })] }), thread.comments.map((comment) => (_jsxs("article", { "data-catchlight-review-comment": "", "data-role": comment.author.role, "data-delivery": comment.delivery, children: [_jsxs("header", { children: [comment.author.role === "agent" ? (_jsxs(_Fragment, { children: [_jsx(Icon, { name: "spark", width: "13", height: "13" }), _jsx("strong", { children: comment.author.name })] })) : (_jsxs(_Fragment, { children: [_jsx("strong", { children: isViewer(comment.author, reviewer) ? "You" : (comment.author.name ?? "Reviewer") }), _jsx("small", { "data-catchlight-review-delivery": "", children: DELIVERY_TEXT[comment.delivery] })] })), isUnsent(comment) && (_jsx(IconButton, { icon: "close", label: "Delete comment", disabled: busy, onClick: () => onDeleteComment(comment.comment) }))] }), comment.body && _jsx("p", { children: comment.body }), comment.version != null && (_jsx(VersionChip, { version: comment.version, onOpen: onOpenVersion })), !!comment.images?.length && _jsx(ReviewImages, { session: session, images: comment.images })] }, comment.comment))), thread.holder && (_jsxs("p", { "data-catchlight-review-working": "", role: "status", title: thread.holder.id, children: [_jsx(Icon, { name: "spark", width: "13", height: "13" }), thread.holder.name, " is working on this\u2026"] })), replying ? (_jsxs("form", { "data-catchlight-review-reply": "", onDrop: attached.onDrop, onDragOver: allowImageDrop, onSubmit: (event) => {
390
+ event.preventDefault();
391
+ submit();
392
+ }, children: [_jsx("textarea", { autoFocus: true, rows: 2, "aria-label": `Reply on ${label.name}`, placeholder: "Reply\u2026", value: reply, onInput: (event) => setReply(event.currentTarget.value), onChange: noop, onPaste: attached.onPaste, onKeyDown: (event) => {
393
+ if (event.key === "Escape") {
394
+ event.preventDefault();
395
+ event.stopPropagation();
396
+ setReplying(false);
397
+ }
398
+ else
399
+ submitOnModEnter(event, submit);
400
+ } }), _jsx(AttachmentStrip, { attached: attached }), _jsxs("div", { "data-catchlight-review-composer-actions": "", children: [_jsx(AttachButtons, { attached: attached }), _jsx("button", { type: "button", onClick: () => setReplying(false), children: "Cancel" }), _jsx("button", { type: "submit", "data-primary": "", disabled: empty || busy, children: "Reply" })] })] })) : (_jsxs("footer", { children: [_jsx("button", { type: "button", "data-catchlight-review-reply-open": "", onClick: () => setReplying(true), children: "Reply" }), _jsxs("button", { type: "button", "data-catchlight-review-resolve": "", disabled: busy, onClick: () => onStatus(resolved ? "open" : "resolved"), children: [_jsx(Icon, { name: resolved ? "undo" : "check", width: "14", height: "14" }), resolved ? "Reopen" : "Resolve"] })] }))] }));
401
+ }
402
+ /** What the editor stores; anything else a clipboard offers is refused. */
403
+ const IMAGE_TYPES = ["image/png", "image/jpeg", "image/webp"];
404
+ export const MAX_COMMENT_IMAGES = 4;
405
+ function useAttachments(capture, onError) {
406
+ const [held, setHeld] = useState([]);
407
+ const latest = useLatest(held);
408
+ useEffect(() => () => {
409
+ for (const { url } of latest.current)
410
+ URL.revokeObjectURL(url);
411
+ }, [latest]);
412
+ return useMemo(() => {
413
+ const add = (files) => {
414
+ const images = [...files];
415
+ const usable = images.filter((file) => IMAGE_TYPES.includes(file.type));
416
+ if (usable.length < images.length)
417
+ onError(new Error("Attach PNG, JPEG or WebP images."));
418
+ const room = MAX_COMMENT_IMAGES - latest.current.length;
419
+ if (usable.length > room)
420
+ onError(new Error(`A comment holds up to ${MAX_COMMENT_IMAGES} images.`));
421
+ const taken = usable.slice(0, Math.max(0, room));
422
+ if (taken.length === 0)
423
+ return;
424
+ setHeld((was) => [
425
+ ...was,
426
+ ...taken.map((blob) => ({ blob, url: URL.createObjectURL(blob) })),
427
+ ]);
428
+ };
429
+ return {
430
+ blobs: held.map((each) => each.blob),
431
+ urls: held.map((each) => each.url),
432
+ full: held.length >= MAX_COMMENT_IMAGES,
433
+ add,
434
+ fail: onError,
435
+ replace(index, blob) {
436
+ setHeld((was) => was.map((each, at) => {
437
+ if (at !== index)
438
+ return each;
439
+ URL.revokeObjectURL(each.url);
440
+ return { blob, url: URL.createObjectURL(blob) };
441
+ }));
442
+ },
443
+ remove(index) {
444
+ setHeld((was) => {
445
+ const gone = was[index];
446
+ if (gone)
447
+ URL.revokeObjectURL(gone.url);
448
+ return was.filter((_, at) => at !== index);
449
+ });
450
+ },
451
+ clear() {
452
+ setHeld((was) => {
453
+ for (const { url } of was)
454
+ URL.revokeObjectURL(url);
455
+ return [];
456
+ });
457
+ },
458
+ capture: capture && (() => void capture().then((blob) => add([blob]), onError)),
459
+ onPaste(event) {
460
+ const files = [...event.clipboardData.files].filter((file) => file.type.startsWith("image/"));
461
+ if (files.length === 0)
462
+ return;
463
+ event.preventDefault();
464
+ add(files);
465
+ },
466
+ onDrop(event) {
467
+ const files = [...event.dataTransfer.files].filter((file) => file.type.startsWith("image/"));
468
+ if (files.length === 0)
469
+ return;
470
+ event.preventDefault();
471
+ event.stopPropagation();
472
+ add(files);
473
+ },
474
+ };
475
+ }, [held, latest, capture, onError]);
476
+ }
477
+ function allowImageDrop(event) {
478
+ if (!event.dataTransfer.types.includes("Files"))
479
+ return;
480
+ event.preventDefault();
481
+ event.stopPropagation();
482
+ }
483
+ function AttachmentStrip({ attached }) {
484
+ const [marking, setMarking] = useState();
485
+ const blob = marking === undefined ? undefined : attached.blobs[marking];
486
+ if (attached.urls.length === 0)
487
+ return null;
488
+ return (_jsxs("ul", { "data-catchlight-review-attachments": "", children: [attached.urls.map((url, index) => (_jsxs("li", { children: [_jsx("button", { type: "button", "data-catchlight-review-markup-open": "", title: "Mark up: box, arrow, draw or crop", "aria-label": `Mark up attachment ${index + 1}`, onClick: () => setMarking(index), children: _jsx("img", { src: url, alt: "" }) }), _jsx(IconButton, { icon: "close", label: `Remove attachment ${index + 1}`, onClick: () => attached.remove(index) })] }, url))), blob && marking !== undefined && (_jsx(ImageMarkup, { image: blob, onCancel: () => setMarking(undefined), onError: attached.fail, onDone: (marked) => {
489
+ attached.replace(marking, marked);
490
+ setMarking(undefined);
491
+ } }))] }));
492
+ }
493
+ function AttachButtons({ attached }) {
494
+ const file = useRef(null);
495
+ return (_jsxs("span", { "data-catchlight-review-attach": "", children: [_jsx("input", { ref: file, type: "file", hidden: true, multiple: true, accept: IMAGE_TYPES.join(","), "aria-label": "Attach images", onChange: (event) => {
496
+ attached.add(event.currentTarget.files ?? []);
497
+ event.currentTarget.value = "";
498
+ } }), _jsx(IconButton, { icon: "part", label: "Attach an image (or paste one)", disabled: attached.full, onClick: () => file.current?.click() }), attached.capture && (_jsx(IconButton, { icon: "fit", label: "Attach a capture of the canvas", "data-catchlight-review-capture": "", disabled: attached.full, onClick: attached.capture }))] }));
499
+ }
500
+ /** The saved version a comment points at; opens it where the host can show it. */
501
+ function VersionChip({ version, onOpen }) {
502
+ if (!onOpen)
503
+ return (_jsxs("span", { "data-catchlight-version-chip": "", title: `Points at saved version ${version}`, children: ["v", version] }));
504
+ return (_jsxs("button", { type: "button", "data-catchlight-version-chip": "", title: `Open saved version ${version}`, "aria-label": `Open version ${version}`, onClick: () => onOpen(version), children: [_jsx(Icon, { name: "history", width: "12", height: "12" }), "v", version] }));
505
+ }
506
+ function ReviewImages({ session, images }) {
507
+ const [open, setOpen] = useState();
508
+ return (_jsxs("ul", { "data-catchlight-review-images": "", children: [images.map((image) => (_jsx("li", { children: _jsx(ReviewImageThumb, { session: session, image: image, onOpen: setOpen }) }, image.image))), open && (_jsx(Modal, { title: "Attached image", wide: true, onClose: () => setOpen(undefined), children: _jsx("img", { "data-catchlight-review-image-full": "", src: open, alt: "Attached image, full size" }) }))] }));
509
+ }
510
+ function ReviewImageThumb({ session, image, onOpen, }) {
511
+ const [url, setUrl] = useState();
512
+ const [failed, setFailed] = useState(false);
513
+ useEffect(() => {
514
+ let live = true;
515
+ session.reviewImageUrl(image).then((made) => {
516
+ if (live)
517
+ setUrl(made);
518
+ }, () => {
519
+ if (live)
520
+ setFailed(true);
521
+ });
522
+ return () => {
523
+ live = false;
524
+ };
525
+ }, [session, image]);
526
+ if (failed)
527
+ return _jsx("small", { "data-catchlight-review-image-missing": "", children: "Image unavailable" });
528
+ return (_jsx("button", { type: "button", "data-catchlight-review-image": "", "data-image": image.image, disabled: !url, "aria-label": "Open attached image", onClick: () => url && onOpen(url), children: url && _jsx("img", { src: url, alt: "" }) }));
529
+ }
@@ -0,0 +1,10 @@
1
+ import type { NodeInfo, Session } from "@catchlight/editor-core";
2
+ import { type ErrorHandler } from "./authoring.js";
3
+ export interface AuthoringPanelProps {
4
+ session: Session;
5
+ info: NodeInfo;
6
+ onError: ErrorHandler;
7
+ }
8
+ export declare function MeshPanel({ session, info, onError }: AuthoringPanelProps): import("react").JSX.Element | null;
9
+ export declare function RiggingEmpty(): import("react").JSX.Element;
10
+ export declare function MotionResponsePanel(props: AuthoringPanelProps): import("react").JSX.Element | null;