@catchlight/editor-web 0.0.0 → 0.5.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 +24 -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 +162 -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 +9 -0
  37. package/dist/lib/editor-context.js +13 -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 +4573 -0
  111. package/package.json +32 -6
@@ -0,0 +1,161 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /** A shelf displays at most 256 combined cells; larger unions keep continuous
3
+ * pose controls and step each axis without expanding their product. */
4
+ import { useRef } from "react";
5
+ import { useEditing } from "./editing.js";
6
+ import { Disclosure, EmptyState, Field, Icon, IconButton, NumberField, } from "./controls.js";
7
+ import { ParamSliderRoot } from "./param-slider.js";
8
+ import { bindingCellAt, valueAtKey } from "./bindings.js";
9
+ const display = (n) => new Intl.NumberFormat("en", {
10
+ maximumFractionDigits: 5,
11
+ signDisplay: "exceptZero",
12
+ }).format(n);
13
+ const MAX_SHELF_CELLS = 256;
14
+ export function WorkspaceModes() {
15
+ const edit = useEditing();
16
+ const refs = useRef([]);
17
+ return (_jsx("div", { "data-catchlight-workspace-modes": "", role: "group", "aria-label": "Editor workspace", children: [
18
+ ["arrange", "select", "Arrange"],
19
+ ["mesh", "mesh", "Mesh"],
20
+ ["record", "key", "Record"],
21
+ ].map(([mode, icon, label], index) => (_jsxs("button", { ref: (el) => {
22
+ refs.current[index] = el;
23
+ }, type: "button", "aria-pressed": edit.mode === mode, title: mode === "mesh"
24
+ ? "Edit mesh on artwork (M)"
25
+ : mode === "record"
26
+ ? "Record parameter keypoints (R)"
27
+ : "Arrange the model", "data-recording": mode === "record" && edit.recording ? "" : undefined, disabled: !edit.session ||
28
+ edit.busy ||
29
+ (mode === "mesh" &&
30
+ edit.mode !== "mesh" &&
31
+ (edit.info?.kind !== "part" || !edit.info.texture)), onClick: () => edit.requestMode(mode), onKeyDown: (e) => {
32
+ if (e.key !== "ArrowLeft" && e.key !== "ArrowRight")
33
+ return;
34
+ e.preventDefault();
35
+ const direction = e.key === "ArrowRight" ? 1 : -1;
36
+ for (let step = 1; step < 4; step++) {
37
+ const next = refs.current[(index + step * direction + 6) % 3];
38
+ if (next && !next.disabled) {
39
+ next.focus();
40
+ next.click();
41
+ break;
42
+ }
43
+ }
44
+ }, children: [_jsx(Icon, { name: icon, width: "14", height: "14" }), label, mode === "record" && edit.recording && (_jsx("i", { "data-catchlight-record-dot": "" }))] }, mode))) }));
45
+ }
46
+ export function EditingBar() {
47
+ const edit = useEditing();
48
+ if (edit.mode === "arrange")
49
+ return null;
50
+ return (_jsxs("div", { "data-catchlight-editing-bar": "", "data-mode": edit.mode, "data-recording": edit.recording ? "" : undefined, children: [_jsxs("div", { "data-catchlight-editing-title": "", children: [_jsx(Icon, { name: edit.mode === "mesh" ? "mesh" : "key" }), _jsxs("div", { children: [_jsxs("strong", { children: [edit.mode === "mesh"
51
+ ? "Edit mesh"
52
+ : edit.recording
53
+ ? "Recording keypoint"
54
+ : "Record a keypoint", _jsxs("span", { children: [" \u00B7 ", edit.info?.name ?? "Choose a node"] })] }), _jsx("small", { children: edit.mode === "mesh"
55
+ ? "Original artwork · texture stays fixed"
56
+ : edit.primary
57
+ ? `${edit.primary.name} ${display(edit.xValue)}${edit.secondary ? ` × ${edit.secondary.name} ${display(edit.yValue)}` : ""} · ${edit.recordTool === "shape" ? "Mesh shape" : "Transform & appearance"}`
58
+ : "Choose a param to define the recording destination" })] })] }), _jsx("span", { "data-catchlight-editing-state": "", children: edit.mode === "mesh"
59
+ ? edit.mesh?.dirty
60
+ ? "Draft modified"
61
+ : "Mesh draft"
62
+ : "Motion responses paused" }), edit.mode === "mesh" ? (_jsxs("div", { "data-catchlight-editing-actions": "", children: [_jsx("button", { type: "button", disabled: edit.busy, onClick: edit.discardMesh, children: "Cancel" }), _jsx("button", { type: "button", "data-primary": "", disabled: edit.busy || (edit.stale && !!edit.mesh?.dirty), onClick: () => void edit.applyMesh(), children: edit.busy ? "Applying…" : edit.mesh?.dirty ? "Apply mesh" : "Done" })] })) : (_jsx(RecordButton, {}))] }));
63
+ }
64
+ function RecordButton() {
65
+ const edit = useEditing();
66
+ return (_jsxs("button", { type: "button", "data-catchlight-record-button": "", "data-recording": edit.recording ? "" : undefined, disabled: edit.busy ||
67
+ !edit.info ||
68
+ !edit.primary ||
69
+ (edit.recordTool === "shape" && !edit.info.vertex_count), onClick: edit.recording ? edit.stop : edit.arm, children: [_jsx("i", { "data-catchlight-record-dot": "" }), edit.busy
70
+ ? "Saving keypoint…"
71
+ : edit.recording
72
+ ? "Stop recording"
73
+ : "Start recording"] }));
74
+ }
75
+ export function RecordingInspector() {
76
+ const edit = useEditing();
77
+ if (!edit.info)
78
+ return (_jsx(EmptyState, { icon: "key", title: "Choose what to record", children: "Select a part or group in the tree. Then choose the param and keypoint it should respond to." }));
79
+ const selectedBindings = edit.target
80
+ ? edit.relevant.filter((b) => {
81
+ const cell = bindingCellAt(b, edit.target.position);
82
+ return cell && b.authored[cell[1]]?.[cell[0]];
83
+ })
84
+ : [];
85
+ return (_jsxs("div", { "data-catchlight-recording-inspector": "", "data-recording": edit.recording ? "" : undefined, children: [_jsxs("div", { "data-catchlight-selection-heading": "", children: [_jsx(Icon, { name: edit.recordTool === "shape" ? "mesh" : "key" }), _jsxs("div", { children: [_jsx("strong", { children: edit.info.name }), _jsx("small", { children: "Recording destination" })] })] }), _jsxs("div", { "data-catchlight-record-scope": "", role: "group", "aria-label": "Record properties", children: [_jsxs("button", { type: "button", "aria-pressed": edit.recordTool === "shape", disabled: edit.busy || !edit.info.vertex_count, onClick: () => edit.setRecordTool("shape"), children: [_jsx(Icon, { name: "mesh", width: "14", height: "14" }), "Mesh shape"] }), _jsxs("button", { type: "button", "aria-pressed": edit.recordTool === "transform", disabled: edit.busy, onClick: () => edit.setRecordTool("transform"), children: [_jsx(Icon, { name: "select", width: "14", height: "14" }), "Transform"] })] }), _jsx(Field, { label: "Driven by", children: _jsxs("select", { "aria-label": "Recording param", value: edit.param ?? "", disabled: edit.busy, onChange: (e) => edit.selectParam(e.currentTarget.value), children: [!edit.params.length && (_jsx("option", { value: "", children: "Create a param below" })), edit.params.map((p) => (_jsx("option", { value: p.id, children: p.name }, p.id)))] }) }), edit.secondary && (_jsxs("div", { "data-catchlight-pair-note": "", children: [_jsx(Icon, { name: "link", width: "13", height: "13" }), _jsxs("span", { children: ["Paired with", " ", _jsx("b", { children: edit.param === edit.secondary.id
86
+ ? edit.primary?.name
87
+ : edit.secondary.name })] })] })), edit.pairChoices.length > 1 && (_jsx(Field, { label: "Param pair", children: _jsx("select", { "aria-label": "Recording param pair", value: edit.pair?.join("|"), onChange: (e) => edit.setPair(e.currentTarget.value.split("|")), children: edit.pairChoices.map((pair) => (_jsx("option", { value: pair.join("|"), children: pair
88
+ .map((id) => edit.params.find((p) => p.id === id)?.name ?? id)
89
+ .join(" × ") }, pair.join("|")))) }) })), _jsxs("div", { "data-catchlight-record-target": "", children: [_jsx("small", { children: edit.recording ? "Recording here" : "Selected keypoint" }), _jsx("strong", { children: edit.recordTool === "shape"
90
+ ? "Mesh shape"
91
+ : "Transform & appearance" }), _jsx("p", { children: edit.primary
92
+ ? `${edit.primary.name} ${display(edit.xValue)}`
93
+ : "No param selected" }), edit.secondary && (_jsxs("p", { children: [edit.secondary.name, " ", display(edit.yValue)] })), _jsxs("span", { "data-catchlight-key-state": "", children: [_jsx(Icon, { name: "key", width: "12", height: "12", "data-authored": edit.authored ? "" : undefined }), !edit.target
94
+ ? "Choose a parameter"
95
+ : edit.authored
96
+ ? edit.recordTool === "shape"
97
+ ? "Authored keypoint"
98
+ : `${selectedBindings.length} ${selectedBindings.length === 1 ? "property" : "properties"} keyed`
99
+ : "Derived · no keypoint authored here"] })] }), _jsx("p", { "data-catchlight-hint": "", children: edit.recording
100
+ ? "Each completed gesture records this keypoint. Escape cancels the current drag."
101
+ : "Start recording to capture edits at this keypoint. Your first edit creates the keypoint." }), edit.recordTool === "shape" ? (_jsxs(_Fragment, { children: [_jsxs("div", { "data-catchlight-record-instructions": "", children: [_jsx(Icon, { name: "select" }), _jsx("p", { children: "Drag a vertex on the canvas to shape the artwork. The base mesh stays fixed." })] }), _jsxs(Disclosure, { title: "Keypoint actions", defaultOpen: false, children: [_jsxs("button", { type: "button", "data-catchlight-action": "", disabled: !edit.target || edit.busy, onClick: () => void edit.keyAction("neutral"), children: [_jsx(Icon, { name: "reset" }), "Set neutral shape"] }), _jsxs("button", { type: "button", "data-catchlight-action": "", disabled: !edit.target || !edit.authored || edit.busy, onClick: () => void edit.keyAction("clear"), children: [_jsx(Icon, { name: "minus" }), "Clear authored keypoint"] }), _jsx("p", { "data-catchlight-hint": "", children: "Neutral records zero offsets. Clear returns this cell to interpolation." })] })] })) : (_jsx(RecordedFields, {})), _jsx("div", { "data-catchlight-edit-footer": "", children: _jsx("p", { children: "Changing the selection or scrubbing a param stops recording. Stop recording keeps the keypoints you have already made." }) }), _jsxs("button", { type: "button", "data-catchlight-action": "", disabled: edit.busy || edit.info.kind !== "part" || !edit.info.texture, onClick: () => edit.requestMode("mesh"), children: [_jsx(Icon, { name: "mesh" }), "Edit base mesh\u2026"] })] }));
102
+ }
103
+ function RecordedFields() {
104
+ const edit = useEditing(), p = edit.posed;
105
+ if (!p)
106
+ return (_jsx("p", { "data-catchlight-hint": "", children: "Choose a key position to inspect and edit its posed values." }));
107
+ return (_jsxs("fieldset", { disabled: !edit.recording || edit.busy, "data-catchlight-recorded-fields": "", children: [_jsxs(Disclosure, { title: "Transform", children: [_jsx(Field, { label: "Position", children: [0, 1].map((i) => (_jsx(NumberField, { label: `Recorded position ${i === 0 ? "X" : "Y"}`, prefix: i === 0 ? "X" : "Y", value: p.translate?.[i] ?? 0, onCommit: (v) => {
108
+ const translate = [
109
+ ...(p.translate ?? [0, 0, 0]),
110
+ ];
111
+ translate[i] = v;
112
+ void edit.patch({ translate });
113
+ } }, i))) }), _jsx(Field, { label: "Rotation", children: _jsx(NumberField, { label: "Recorded rotation", value: ((p.rotate?.[2] ?? 0) * 180) / Math.PI, unit: "\u00B0", onCommit: (v) => void edit.patch({
114
+ rotate: [
115
+ p.rotate?.[0] ?? 0,
116
+ p.rotate?.[1] ?? 0,
117
+ (v * Math.PI) / 180,
118
+ ],
119
+ }) }) }), _jsx(Field, { label: "Scale", children: [0, 1].map((i) => (_jsx(NumberField, { label: `Recorded scale ${i === 0 ? "X" : "Y"}`, prefix: i === 0 ? "X" : "Y", value: p.scale?.[i] ?? 1, onCommit: (v) => {
120
+ const scale = [...(p.scale ?? [1, 1])];
121
+ scale[i] = v;
122
+ void edit.patch({ scale });
123
+ } }, i))) }), _jsx(Field, { label: "Draw order", children: _jsx(NumberField, { label: "Recorded draw order", value: p.z_order ?? 0, onCommit: (v) => void edit.patch({ z_order: v }) }) })] }), p.opacity != null && (_jsxs(Disclosure, { title: "Appearance", defaultOpen: false, children: [_jsx(Field, { label: "Opacity", children: _jsx(NumberField, { label: "Recorded opacity", value: p.opacity * 100, min: 0, max: 100, unit: "%", onCommit: (v) => void edit.patch({ opacity: v / 100 }) }) }), [
124
+ ["tint", "Tint"],
125
+ ["screen_tint", "Screen"],
126
+ ].map(([key, label]) => (_jsx(Field, { label: label, children: [0, 1, 2].map((i) => (_jsx(NumberField, { label: `Recorded ${label} ${["red", "green", "blue"][i]}`, value: p[key]?.[i] ?? 0, min: 0, prefix: ["R", "G", "B"][i], onCommit: (v) => {
127
+ const color = [
128
+ ...(p[key] ?? [0, 0, 0]),
129
+ ];
130
+ color[i] = v;
131
+ void edit.patch({ [key]: color });
132
+ } }, i))) }, key)))] }))] }));
133
+ }
134
+ export function RecordingKeys() {
135
+ const edit = useEditing(), { primary, secondary, session } = edit;
136
+ if (!session || !primary)
137
+ return (_jsx(EmptyState, { icon: "key", title: "No params", children: "Create a param in the Params tab before recording keypoints." }));
138
+ const compact = edit.xPositions.length * edit.yPositions.length > MAX_SHELF_CELLS;
139
+ const keyState = (x, y) => edit.keyAuthored([edit.xPositions[x], edit.yPositions[y]]);
140
+ const keyButton = (x, y, matrix = false) => {
141
+ const authored = keyState(x, y), selected = edit.x === x && edit.y === y;
142
+ const label = `${primary.name} ${display(valueAtKey(primary, x, edit.xPositions))}${secondary ? `, ${secondary.name} ${display(valueAtKey(secondary, y, edit.yPositions))}` : ""}`;
143
+ return (_jsxs("button", { type: "button", "aria-label": `${label}, ${authored ? "authored" : "derived"} keypoint`, "aria-pressed": selected, "data-catchlight-record-key": "", "data-key-x": x, "data-key-y": y, "data-authored": authored ? "" : undefined, "data-recording": selected && edit.recording ? "" : undefined, disabled: edit.busy, title: label, onClick: () => edit.selectCell(x, y), children: [_jsx(Icon, { name: "key", width: "13", height: "13" }), !matrix && (_jsxs(_Fragment, { children: [_jsx("span", { children: display(valueAtKey(primary, x, edit.xPositions)) }), _jsx("small", { children: authored ? "Authored" : "Derived" })] }))] }, `${x}:${y}`));
144
+ };
145
+ return (_jsxs("div", { "data-catchlight-recording-keys": "", "data-paired": secondary ? "" : undefined, children: [_jsxs("div", { "data-catchlight-key-shelf-heading": "", children: [_jsxs("span", { children: [_jsx("b", { children: edit.info?.name ?? "Selection" }), " /", " ", edit.recordTool === "shape"
146
+ ? "Mesh shape"
147
+ : "Transform & appearance"] }), _jsx("small", { children: "\u25C7 derived \u00A0 \u25C6 authored" })] }), _jsxs("div", { "data-catchlight-key-shelf-content": "", children: [_jsxs("div", { "data-catchlight-record-sliders": "", children: [[primary, ...(secondary ? [secondary] : [])].map((p) => (_jsxs("div", { "data-catchlight-record-slider": "", children: [_jsx("label", { children: p.name }), _jsx(ParamSliderRoot, { session: session, param: p, disabled: edit.busy }), _jsx(NumberField, { label: `${p.name} recording value`, value: session.paramValue(p.id) ?? p.default, min: p.min, max: p.max, disabled: edit.busy, onCommit: (v) => session.setParam(p.id, v) })] }, p.id))), !secondary && !compact && (_jsx("div", { "data-catchlight-record-key-strip": "", children: edit.xPositions.map((_, x) => keyButton(x, 0)) })), compact && (_jsxs(_Fragment, { children: [_jsx("p", { "data-catchlight-record-pose-hint": "", children: "Too many key positions to show together. Use the sliders or step through each param\u2019s key positions." }), [primary, ...(secondary ? [secondary] : [])].map((p, axis) => {
148
+ const positions = axis === 0 ? edit.xPositions : edit.yPositions;
149
+ const current = axis === 0 ? edit.x : edit.y;
150
+ const at = edit.target?.position[axis] ?? 0;
151
+ const next = current === undefined ? positions.findIndex((value) => value > at) : current + 1;
152
+ const previous = current === undefined ? (next < 0 ? positions.length : next) - 1 : current - 1;
153
+ return (_jsxs("div", { "data-catchlight-record-key-strip": "", role: "group", "aria-label": `${p.name} key positions`, children: [_jsxs("span", { children: [p.name, " \u00B7 ", positions.length, " positions"] }), [["Previous", previous], ["Next", next]].map(([label, index]) => (_jsx("button", { type: "button", "aria-label": `${label} ${p.name} key position`, disabled: edit.busy || index < 0 || index >= positions.length, onClick: () => session.setParam(p.id, valueAtKey(p, index, positions)), children: label }, label)))] }, p.id));
154
+ })] })), _jsx("p", { "data-catchlight-record-pose-hint": "", children: edit.recording
155
+ ? "Recording is on. Scrubbing stops capture; completed edits are kept."
156
+ : "Scrub to preview, then start recording at any value. Only edited properties receive a key." })] }), secondary && !compact && (_jsxs("div", { "data-catchlight-record-matrix-scroll": "", children: [_jsxs("div", { "data-catchlight-record-matrix-label": "", children: [_jsxs("span", { children: [secondary.name, " \u2191"] }), _jsxs("span", { children: [primary.name, " \u2192"] })] }), _jsxs("div", { "data-catchlight-record-matrix": "", style: {
157
+ gridTemplateColumns: `42px repeat(${edit.xPositions.length}, minmax(34px, 1fr))`,
158
+ }, children: [_jsx("span", {}), edit.xPositions.map((_, x) => (_jsx("span", { children: display(valueAtKey(primary, x, edit.xPositions)) }, x))), edit.yPositions
159
+ .map((_, y) => edit.yPositions.length - 1 - y)
160
+ .map((y) => (_jsxs("div", { "data-catchlight-matrix-row": "", children: [_jsx("span", { children: display(valueAtKey(secondary, y, edit.yPositions)) }), edit.xPositions.map((_, x) => keyButton(x, y, true))] }, y)))] })] }))] })] }));
161
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Replica reads from React. Nothing is mirrored into state; what React
3
+ * subscribes to is the session's revision.
4
+ */
5
+ import type { NodeId, NodeInfo, ParamInfo, Session, TreeNode } from "@catchlight/editor-core";
6
+ export declare function useRevision(session: Session): number;
7
+ /**
8
+ * Memoized on the session and revision, deliberately not on `read`, so an
9
+ * inline arrow does not re-read every render; the newest `read` runs.
10
+ */
11
+ export declare function useReplica<T>(session: Session, read: (session: Session) => T): T;
12
+ export declare function useParams(session: Session): ParamInfo[];
13
+ export declare function useTree(session: Session): TreeNode;
14
+ /**
15
+ * `undefined` when nothing is selected or the node is gone. Not
16
+ * [`useReplica`], which ignores a changed `read` at the same revision.
17
+ */
18
+ export declare function useNodeInfo(session: Session, node: NodeId | undefined): NodeInfo | undefined;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Replica reads from React. Nothing is mirrored into state; what React
3
+ * subscribes to is the session's revision.
4
+ */
5
+ import { useMemo, useSyncExternalStore } from "react";
6
+ import { useLatest } from "./latest.js";
7
+ export function useRevision(session) {
8
+ return useSyncExternalStore(session.subscribe, session.getRevision, session.getRevision);
9
+ }
10
+ /**
11
+ * Memoized on the session and revision, deliberately not on `read`, so an
12
+ * inline arrow does not re-read every render; the newest `read` runs.
13
+ */
14
+ export function useReplica(session, read) {
15
+ const revision = useRevision(session);
16
+ const latest = useLatest(read);
17
+ return useMemo(() => latest.current(session), [session, revision, latest]);
18
+ }
19
+ export function useParams(session) {
20
+ return useReplica(session, readParams);
21
+ }
22
+ export function useTree(session) {
23
+ return useReplica(session, readTree);
24
+ }
25
+ /**
26
+ * `undefined` when nothing is selected or the node is gone. Not
27
+ * [`useReplica`], which ignores a changed `read` at the same revision.
28
+ */
29
+ export function useNodeInfo(session, node) {
30
+ const revision = useRevision(session);
31
+ return useMemo(() => (node === undefined ? undefined : session.nodeInfo(node)), [session, revision, node]);
32
+ }
33
+ const readParams = (session) => session.params();
34
+ const readTree = (session) => session.tree();
@@ -0,0 +1,113 @@
1
+ /**
2
+ * A session's review: threads a person leaves on things in the model for a
3
+ * listening agent. Comments stay `unsent` until the person sends the review;
4
+ * the agent's replies arrive through `review_changed`.
5
+ */
6
+ import type { ParamInfo, Review, ReviewAgent, ReviewAuthor, ReviewTarget, Session, ThreadId, ThreadStatus, TreeNode } from "@catchlight/editor-core";
7
+ import type { ReactNode } from "react";
8
+ import type { ErrorHandler } from "./authoring.js";
9
+ import type { IconName } from "./controls.js";
10
+ /**
11
+ * `absent`: no agent has been heard from lately. `away`: some were, and none
12
+ * is waiting or holding a thread. `working`, any agent holding an open
13
+ * thread, wins over `listening`, any agent waiting.
14
+ */
15
+ export type AgentPhase = "absent" | "away" | "listening" | "working";
16
+ /** The person at this tab, as the host knows them. */
17
+ export interface Reviewer {
18
+ id: string;
19
+ name: string;
20
+ }
21
+ export interface ReviewState {
22
+ session: Session | undefined;
23
+ review: Review;
24
+ /** Recently heard from, most recent last. */
25
+ agents: readonly ReviewAgent[];
26
+ phase: AgentPhase;
27
+ reviewer: Reviewer | undefined;
28
+ /** Human comments on open threads still held back from the agent. */
29
+ unsent: number;
30
+ /** Threads sent and not yet taken by an agent. */
31
+ waiting: number;
32
+ /** Open threads whose last word is the agent's. */
33
+ replied: number;
34
+ busy: boolean;
35
+ /** What the composer is aimed at; `undefined` while it is closed. */
36
+ composing: ReviewTarget | undefined;
37
+ compose(target: ReviewTarget | undefined): void;
38
+ focused: ThreadId | undefined;
39
+ focus(thread: ThreadId | undefined): void;
40
+ open(target: ReviewTarget, body: string, images?: readonly Blob[]): Promise<boolean>;
41
+ reply(thread: ThreadId, body: string, images?: readonly Blob[]): Promise<boolean>;
42
+ /** Reports a failure the way a failed command is reported. */
43
+ fail(cause: unknown): void;
44
+ setStatus(thread: ThreadId, status: ThreadStatus): Promise<boolean>;
45
+ removeThread(thread: ThreadId): Promise<boolean>;
46
+ removeComment(thread: ThreadId, comment: number): Promise<boolean>;
47
+ send(): Promise<boolean>;
48
+ /** Shows a saved version a comment points at; absent when the host shows none. */
49
+ openVersion: ((version: number) => void) | undefined;
50
+ }
51
+ export interface ReviewProviderProps {
52
+ session: Session | undefined;
53
+ onError: ErrorHandler;
54
+ /**
55
+ * Stamped on the comments this tab writes. Without one, every comment from
56
+ * a person reads as the viewer's own.
57
+ */
58
+ reviewer?: Reviewer;
59
+ /** A thread was focused or a comment started from outside the panel. */
60
+ onAttention?: () => void;
61
+ /** Shows a saved version a comment points at, such as the one holding a fix. */
62
+ onOpenVersion?: (version: number) => void;
63
+ children?: ReactNode;
64
+ }
65
+ export declare function ReviewProvider({ session, onError, reviewer, onAttention, onOpenVersion, children, }: ReviewProviderProps): import("react").JSX.Element;
66
+ /** `undefined` outside a [`ReviewProvider`], so a part can be used without review. */
67
+ export declare function useReview(): ReviewState | undefined;
68
+ /** Whether a person's comment is the viewer's: same id, or neither has one. */
69
+ export declare function isViewer(author: ReviewAuthor, reviewer: Reviewer | undefined): boolean;
70
+ /** Who is attending, in a few words: one agent by name, several by count. */
71
+ export declare function agentsLabel(agents: readonly ReviewAgent[]): string | undefined;
72
+ export declare function sameTarget(a: ReviewTarget, b: ReviewTarget): boolean;
73
+ export interface TargetLabel {
74
+ icon: IconName;
75
+ kind: string;
76
+ name: string;
77
+ }
78
+ export declare function targetLabel(target: ReviewTarget, tree: TreeNode | undefined, params: readonly ParamInfo[]): TargetLabel;
79
+ /**
80
+ * How many open threads are about `target`; renders nothing at zero. Clicking
81
+ * focuses the newest. `data-attention` marks an agent reply waiting to be read.
82
+ */
83
+ export declare function ReviewBadge({ target, label }: {
84
+ target: ReviewTarget;
85
+ label: string;
86
+ }): import("react").JSX.Element | null;
87
+ /** Starts a comment on `target`; renders nothing outside a [`ReviewProvider`]. */
88
+ export declare function ReviewCommentButton({ target, label }: {
89
+ target: ReviewTarget;
90
+ label: string;
91
+ }): import("react").JSX.Element | null;
92
+ /** The agent's state and the send action, small enough for a toolbar. */
93
+ export declare function ReviewStatus({ onOpen }: {
94
+ onOpen?: () => void;
95
+ }): import("react").JSX.Element | null;
96
+ export interface ReviewPanelProps {
97
+ session: Session;
98
+ /**
99
+ * The host's way to bring an agent in, shown while none is listening or
100
+ * working: instructions for the person's own agent, a control that starts a
101
+ * hosted one, or both. How an agent reaches the editor is the host's to know.
102
+ */
103
+ connect?: ReactNode;
104
+ /** A picture of what the person is looking at, offered as an attachment. */
105
+ capture?: () => Promise<Blob>;
106
+ }
107
+ export declare function ReviewPanel({ session, connect, capture }: ReviewPanelProps): import("react").JSX.Element | null;
108
+ /** A message for the person to hand their own agent, with a copy button. */
109
+ export declare function AgentPrompt({ children, prompt }: {
110
+ children?: ReactNode;
111
+ prompt: string;
112
+ }): import("react").JSX.Element;
113
+ export declare const MAX_COMMENT_IMAGES = 4;