@whzxc/agent-design-gallery 0.9.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/package.json +4 -1
- package/public/annotations.js +816 -0
- package/public/app.js +245 -12
- package/public/assets.js +4 -13
- package/public/frame-identity.js +223 -0
- package/public/icons.js +1 -0
- package/public/index.html +3 -0
- package/public/selection.js +1 -1
- package/public/style.css +72 -2
- package/src/annotations.mjs +238 -0
- package/src/cli-output.mjs +49 -2
- package/src/cli.mjs +83 -12
- package/src/http.mjs +2 -1
- package/src/hub/instances.mjs +1 -1
- package/src/hub/registry.mjs +1 -1
- package/src/hub.mjs +2 -2
- package/src/server.mjs +59 -11
- package/src/service.mjs +1 -1
- package/src/toolkit/arch-git.mjs +19 -0
- package/src/toolkit/arch-overlay.mjs +1 -1
- package/src/toolkit/asset-rules.mjs +42 -3
- package/src/toolkit/build-store.mjs +5 -3
- package/src/toolkit/build-worker.mjs +5 -2
- package/src/toolkit/build.mjs +36 -14
- package/src/toolkit/commands.mjs +85 -22
- package/src/toolkit/config.mjs +8 -6
- package/src/toolkit/diff-inputs.mjs +5 -5
- package/src/toolkit/diff.mjs +18 -11
- package/src/toolkit/document.mjs +6 -6
- package/src/toolkit/frame-document.mjs +6 -0
- package/src/toolkit/frame-facets.mjs +167 -0
- package/src/toolkit/frame-identity.mjs +100 -0
- package/src/toolkit/frame-observation.mjs +147 -0
- package/src/toolkit/frame-primitives.mjs +85 -0
- package/src/toolkit/html.mjs +1 -0
- package/src/toolkit/impact-eligibility.mjs +136 -0
- package/src/toolkit/impact-inputs.mjs +52 -0
- package/src/toolkit/impact-output.mjs +46 -0
- package/src/toolkit/impact-proof.mjs +67 -0
- package/src/toolkit/impact-selection.mjs +96 -0
- package/src/toolkit/impact.mjs +382 -0
- package/src/toolkit/implementation-query.mjs +53 -0
- package/src/toolkit/input-generation.mjs +51 -0
- package/src/toolkit/inspect-encoding.mjs +459 -0
- package/src/toolkit/inspect-observation.mjs +56 -0
- package/src/toolkit/inspect-output.mjs +169 -0
- package/src/toolkit/inspect-styles.mjs +34 -0
- package/src/toolkit/inspect.d.ts +118 -0
- package/src/toolkit/inspect.mjs +125 -0
- package/src/toolkit/owner-observation.mjs +23 -189
- package/src/toolkit/owner-search.mjs +2 -2
- package/src/toolkit/owner.mjs +37 -45
- package/src/toolkit/part-diff.mjs +2 -0
- package/src/toolkit/part-snapshot.mjs +15 -23
- package/src/toolkit/project-index.mjs +100 -22
- package/src/toolkit/project.mjs +52 -6
- package/src/toolkit/results.mjs +2 -2
- package/src/toolkit/runtime.d.ts +7 -5
- package/src/toolkit/runtime.mjs +20 -7
- package/src/toolkit/token-reachability.mjs +71 -0
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
import { dataFetch } from './auth.js';
|
|
2
|
+
import { icon } from './icons.js';
|
|
3
|
+
|
|
4
|
+
export const READABLE_ANNOTATION_SCALE = 0.45;
|
|
5
|
+
|
|
6
|
+
const clamp01 = value => Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0));
|
|
7
|
+
const quoteShell = value => /^[A-Za-z0-9_./:=+-]+$/.test(value) ? value : `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
8
|
+
const toProjectSource = (sourcePrefix, value) => !value ? '' : (!sourcePrefix || value === sourcePrefix || value.startsWith(sourcePrefix + '/')) ? value : `${sourcePrefix}/${value}`;
|
|
9
|
+
|
|
10
|
+
export function formatElementReference({ sourcePrefix = '', source, owner, frame, elementId }) {
|
|
11
|
+
const sourcePath = toProjectSource(sourcePrefix, source);
|
|
12
|
+
const ownerPath = owner?.source ? toProjectSource(sourcePrefix, owner.source) : '';
|
|
13
|
+
const exportName = owner?.export ? (ownerPath && ownerPath !== sourcePath ? `${ownerPath}#${owner.export}` : owner.export) : 'none';
|
|
14
|
+
return `source=${sourcePath} export=${exportName} frame=${JSON.stringify(frame)} element=${elementId}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function formatAgentPrompt({ projectRoot, sourcePrefix = '', notes }) {
|
|
18
|
+
const root = projectRoot || '.';
|
|
19
|
+
const header = [
|
|
20
|
+
`Handle the following ADG design ${notes.length === 1 ? 'annotation' : `annotations (${notes.length})`} in project ${root}.`,
|
|
21
|
+
`Run ADG CLI commands from ${root}. Keep the user's notes verbatim, inspect each target, apply the requested code/design changes, and mark each annotation addressed with a summary.`,
|
|
22
|
+
].join('\n');
|
|
23
|
+
const blocks = notes.map(({ row, stale = false }) => {
|
|
24
|
+
const sourcePath = toProjectSource(sourcePrefix, row.source);
|
|
25
|
+
const owner = row.element?.owner ?? null;
|
|
26
|
+
const ownerPath = owner?.source ? toProjectSource(sourcePrefix, owner.source) : '';
|
|
27
|
+
const exportLabel = owner?.export ? (ownerPath && ownerPath !== sourcePath ? `${ownerPath}#${owner.export}` : owner.export) : 'none';
|
|
28
|
+
const elementId = row.element?.id ?? null;
|
|
29
|
+
const inspectFlag = elementId && !stale ? ` --element=${quoteShell(elementId)}` : '';
|
|
30
|
+
const lines = [
|
|
31
|
+
`## Annotation #${row.number} (id: ${row.id}, status: ${row.status}${stale ? ', stale: true' : ''})`,
|
|
32
|
+
`- Project: ${root}`,
|
|
33
|
+
`- Source: ${sourcePath}`,
|
|
34
|
+
`- Export: ${exportLabel}`,
|
|
35
|
+
`- Frame: ${row.frame}`,
|
|
36
|
+
`- Element ID: ${elementId ? `${elementId}${stale ? ' (stale — element no longer matches; use fallback coordinates)' : ''}` : 'none (frame note)'}`,
|
|
37
|
+
`- Coordinates: frame (${row.x.toFixed(3)}, ${row.y.toFixed(3)})${row.element ? `, element (${row.element.x.toFixed(3)}, ${row.element.y.toFixed(3)})` : ''}`,
|
|
38
|
+
`- Note (verbatim):`,
|
|
39
|
+
row.note,
|
|
40
|
+
];
|
|
41
|
+
if (row.replies?.length) {
|
|
42
|
+
lines.push(`- Thread (${row.replies.length}):`);
|
|
43
|
+
for (const reply of row.replies) lines.push(` - [${reply.author}] ${reply.message}`);
|
|
44
|
+
}
|
|
45
|
+
lines.push(
|
|
46
|
+
`- CLI commands:`,
|
|
47
|
+
` adg annotations read ${quoteShell(row.id)} --json`,
|
|
48
|
+
` adg inspect ${quoteShell(sourcePath)} --frame=${quoteShell(row.frame)}${inspectFlag} --json`,
|
|
49
|
+
` adg annotations reply ${quoteShell(row.id)} --message="<reply>"`,
|
|
50
|
+
` adg annotations address ${quoteShell(row.id)} --message="<summary of changes>"`,
|
|
51
|
+
);
|
|
52
|
+
return lines.join('\n');
|
|
53
|
+
});
|
|
54
|
+
return [header, ...blocks].join('\n\n') + '\n';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createContextMenu(menu, { viewport, onOverlayChange }) {
|
|
58
|
+
let restoreTarget = null;
|
|
59
|
+
let suppressAutoRestore = false;
|
|
60
|
+
|
|
61
|
+
const enabledItems = () => [...menu.querySelectorAll('button[role="menuitem"]:not(:disabled)')];
|
|
62
|
+
|
|
63
|
+
menu.addEventListener('toggle', event => {
|
|
64
|
+
if (event.newState === 'open') {
|
|
65
|
+
for (const other of document.querySelectorAll(':popover-open')) {
|
|
66
|
+
if (other !== menu) other.hidePopover();
|
|
67
|
+
}
|
|
68
|
+
} else if (!suppressAutoRestore && restoreTarget?.isConnected) {
|
|
69
|
+
if (!document.activeElement || document.activeElement === document.body || menu.contains(document.activeElement)) {
|
|
70
|
+
restoreTarget.focus({ preventScroll: true });
|
|
71
|
+
}
|
|
72
|
+
restoreTarget = null;
|
|
73
|
+
}
|
|
74
|
+
onOverlayChange?.();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
menu.addEventListener('keydown', event => {
|
|
78
|
+
const items = enabledItems();
|
|
79
|
+
const index = items.indexOf(document.activeElement);
|
|
80
|
+
if (event.key === 'ArrowDown' && items.length) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
items[(index + 1 + items.length) % items.length].focus();
|
|
84
|
+
} else if (event.key === 'ArrowUp' && items.length) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
event.stopPropagation();
|
|
87
|
+
items[(index - 1 + items.length) % items.length].focus();
|
|
88
|
+
} else if (event.key === 'Home' && items.length) {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
items[0].focus();
|
|
92
|
+
} else if (event.key === 'End' && items.length) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
event.stopPropagation();
|
|
95
|
+
items.at(-1).focus();
|
|
96
|
+
} else if ((event.key === 'Enter' || event.key === ' ') && index >= 0) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
items[index].click();
|
|
100
|
+
} else if (event.key === 'Escape' || event.key === 'Tab') {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
event.stopPropagation();
|
|
103
|
+
close(true);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function close(restore = true) {
|
|
108
|
+
const target = restoreTarget;
|
|
109
|
+
suppressAutoRestore = true;
|
|
110
|
+
if (menu.matches(':popover-open')) menu.hidePopover();
|
|
111
|
+
suppressAutoRestore = false;
|
|
112
|
+
restoreTarget = null;
|
|
113
|
+
if (restore && target?.isConnected) target.focus({ preventScroll: true });
|
|
114
|
+
onOverlayChange?.();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function open(items, { x, y, returnFocus } = {}) {
|
|
118
|
+
restoreTarget = returnFocus ?? (document.activeElement instanceof HTMLElement ? document.activeElement : viewport);
|
|
119
|
+
const nodes = items.map(entry => {
|
|
120
|
+
if (entry.separator) {
|
|
121
|
+
const rule = document.createElement('div');
|
|
122
|
+
rule.className = 'rule';
|
|
123
|
+
rule.setAttribute('role', 'separator');
|
|
124
|
+
return rule;
|
|
125
|
+
}
|
|
126
|
+
const button = document.createElement('button');
|
|
127
|
+
button.type = 'button';
|
|
128
|
+
button.setAttribute('role', 'menuitem');
|
|
129
|
+
button.textContent = entry.label;
|
|
130
|
+
button.disabled = !!entry.disabled;
|
|
131
|
+
button.onclick = () => {
|
|
132
|
+
const target = restoreTarget;
|
|
133
|
+
close(false);
|
|
134
|
+
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
135
|
+
entry.action?.();
|
|
136
|
+
};
|
|
137
|
+
return button;
|
|
138
|
+
});
|
|
139
|
+
menu.replaceChildren(...nodes);
|
|
140
|
+
menu.style.left = '0px';
|
|
141
|
+
menu.style.top = '0px';
|
|
142
|
+
if (!menu.matches(':popover-open')) menu.showPopover();
|
|
143
|
+
const mw = menu.offsetWidth || 220, mh = menu.offsetHeight || 160;
|
|
144
|
+
const left = Math.max(8, Math.min(window.innerWidth - mw - 8, Math.round(x)));
|
|
145
|
+
const top = Math.max(8, Math.min(window.innerHeight - mh - 8, Math.round(y)));
|
|
146
|
+
menu.style.left = `${left}px`;
|
|
147
|
+
menu.style.top = `${top}px`;
|
|
148
|
+
enabledItems()[0]?.focus({ preventScroll: true });
|
|
149
|
+
onOverlayChange?.();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return { open, close, isOpen: () => menu.matches(':popover-open') };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function createAnnotations({
|
|
156
|
+
viewport,
|
|
157
|
+
panel,
|
|
158
|
+
toggleButton,
|
|
159
|
+
contextMenu,
|
|
160
|
+
getState,
|
|
161
|
+
hitFrameAt,
|
|
162
|
+
navigateToNote,
|
|
163
|
+
selectNoteTarget,
|
|
164
|
+
inspectFrame,
|
|
165
|
+
onChromeChange,
|
|
166
|
+
copyText,
|
|
167
|
+
fail,
|
|
168
|
+
}) {
|
|
169
|
+
let rows = [];
|
|
170
|
+
let rowsVersion = 0;
|
|
171
|
+
let panelOpen = false;
|
|
172
|
+
let statusFilter = 'all';
|
|
173
|
+
let scopeFilter = 'all';
|
|
174
|
+
let movingId = null;
|
|
175
|
+
let highlightedId = null;
|
|
176
|
+
let signature = '';
|
|
177
|
+
let panelSignature = '';
|
|
178
|
+
let renderedView = null;
|
|
179
|
+
let renderedSceneKey = '';
|
|
180
|
+
const knownParts = new Map();
|
|
181
|
+
|
|
182
|
+
const layer = document.createElement('div');
|
|
183
|
+
layer.className = 'annotation-layer';
|
|
184
|
+
viewport.append(layer);
|
|
185
|
+
|
|
186
|
+
panel.innerHTML = `
|
|
187
|
+
<div class="annotations-header">
|
|
188
|
+
<div class="annotations-title"><h2>Annotations</h2><span id="annotations-count" class="count">0</span></div>
|
|
189
|
+
<button type="button" id="copy-open-annotations" class="annotations-copy-prompt" aria-label="Copy open annotations as agent prompt">${icon('copy', 12)}<span>Copy prompt</span></button>
|
|
190
|
+
</div>
|
|
191
|
+
<div class="annotations-filters">
|
|
192
|
+
<div class="annotations-filter-group" role="group" aria-label="Filter by status">
|
|
193
|
+
<button type="button" data-filter-status="open" aria-pressed="false">Open</button>
|
|
194
|
+
<button type="button" data-filter-status="addressed" aria-pressed="false">Addressed</button>
|
|
195
|
+
<button type="button" data-filter-status="resolved" aria-pressed="false">Resolved</button>
|
|
196
|
+
<button type="button" data-filter-status="all" aria-pressed="true">All</button>
|
|
197
|
+
</div>
|
|
198
|
+
<div class="annotations-filter-group" role="group" aria-label="Filter by scope">
|
|
199
|
+
<button type="button" data-filter-scope="frame" aria-pressed="false">Current frame</button>
|
|
200
|
+
<button type="button" data-filter-scope="all" aria-pressed="true">All frames</button>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
<div class="annotation-list" role="list"></div>
|
|
204
|
+
`;
|
|
205
|
+
|
|
206
|
+
const dialog = document.createElement('dialog');
|
|
207
|
+
dialog.className = 'annotation-editor';
|
|
208
|
+
dialog.setAttribute('aria-labelledby', 'annotation-editor-title');
|
|
209
|
+
dialog.innerHTML = `
|
|
210
|
+
<form method="dialog">
|
|
211
|
+
<h2 id="annotation-editor-title">Add annotation</h2>
|
|
212
|
+
<p class="annotation-editor-meta"></p>
|
|
213
|
+
<textarea aria-label="Annotation note" maxlength="10000" rows="4"></textarea>
|
|
214
|
+
<div class="annotation-editor-footer">
|
|
215
|
+
<span class="annotation-editor-hint">Enter saves · Shift+Enter newline · Esc cancels</span>
|
|
216
|
+
<div class="annotation-editor-buttons">
|
|
217
|
+
<button type="button" data-editor-cancel>Cancel</button>
|
|
218
|
+
<button type="submit" value="save" class="primary">Save</button>
|
|
219
|
+
</div>
|
|
220
|
+
</div>
|
|
221
|
+
</form>
|
|
222
|
+
`;
|
|
223
|
+
document.body.append(dialog);
|
|
224
|
+
|
|
225
|
+
const textarea = dialog.querySelector('textarea');
|
|
226
|
+
const editorTitle = dialog.querySelector('#annotation-editor-title');
|
|
227
|
+
const editorMeta = dialog.querySelector('.annotation-editor-meta');
|
|
228
|
+
dialog.querySelector('[data-editor-cancel]').onclick = () => dialog.close('cancel');
|
|
229
|
+
textarea.addEventListener('keydown', event => {
|
|
230
|
+
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
if (textarea.value.trim()) dialog.close('save');
|
|
233
|
+
} else if (event.key === 'Escape') {
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
event.stopPropagation();
|
|
236
|
+
dialog.close('cancel');
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
dialog.addEventListener('cancel', event => {
|
|
240
|
+
event.preventDefault();
|
|
241
|
+
dialog.close('cancel');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
function openEditor({ title = 'Add annotation', label = 'Annotation note', meta = '', initial = '', returnFocus } = {}) {
|
|
245
|
+
const previousFocus = returnFocus ?? (document.activeElement instanceof HTMLElement ? document.activeElement : viewport);
|
|
246
|
+
editorTitle.textContent = title;
|
|
247
|
+
editorMeta.textContent = meta;
|
|
248
|
+
editorMeta.hidden = !meta;
|
|
249
|
+
textarea.setAttribute('aria-label', label);
|
|
250
|
+
textarea.value = initial;
|
|
251
|
+
dialog.returnValue = 'cancel';
|
|
252
|
+
dialog.showModal();
|
|
253
|
+
onChromeChange?.();
|
|
254
|
+
textarea.focus();
|
|
255
|
+
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
256
|
+
return new Promise(resolve => {
|
|
257
|
+
dialog.addEventListener('close', () => {
|
|
258
|
+
const saved = dialog.returnValue === 'save' ? textarea.value : null;
|
|
259
|
+
if (previousFocus?.isConnected) previousFocus.focus({ preventScroll: true });
|
|
260
|
+
else viewport.focus({ preventScroll: true });
|
|
261
|
+
onChromeChange?.();
|
|
262
|
+
resolve(saved);
|
|
263
|
+
}, { once: true });
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function rememberKnownParts(state) {
|
|
268
|
+
for (const asset of state.manifestAssets) {
|
|
269
|
+
if (asset.parts) knownParts.set(asset.path, asset.parts);
|
|
270
|
+
}
|
|
271
|
+
if (!state.loading && state.scope === 'all') {
|
|
272
|
+
const present = new Set(state.manifestAssets.map(a => a.path));
|
|
273
|
+
for (const key of knownParts.keys()) if (!present.has(key)) knownParts.delete(key);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function resolveRow(row, state = getState()) {
|
|
278
|
+
const sourceAsset = state.manifestAssets.find(a => a.path === row.source);
|
|
279
|
+
const parts = sourceAsset?.parts ?? knownParts.get(row.source);
|
|
280
|
+
if (!parts) {
|
|
281
|
+
const stale = !state.loading && state.scope === 'all';
|
|
282
|
+
return { row, stale, fx: row.x, fy: row.y, element: null };
|
|
283
|
+
}
|
|
284
|
+
const part = parts.find(p => p.name === row.frame);
|
|
285
|
+
if (!part) return { row, stale: true, fx: row.x, fy: row.y, element: null };
|
|
286
|
+
if (!row.element) return { row, stale: false, fx: row.x, fy: row.y, element: null };
|
|
287
|
+
const found = (part.elements ?? []).find(e => e.id === row.element.id);
|
|
288
|
+
if (!found) return { row, stale: true, fx: row.x, fy: row.y, element: null };
|
|
289
|
+
const fx = part.width > 0 ? clamp01((found.x + row.element.x * found.width) / part.width) : row.x;
|
|
290
|
+
const fy = part.height > 0 ? clamp01((found.y + row.element.y * found.height) / part.height) : row.y;
|
|
291
|
+
return { row, stale: false, fx, fy, element: found };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function refresh() {
|
|
295
|
+
const response = await dataFetch('api/annotations');
|
|
296
|
+
if (!response.ok) throw Error('Cannot load annotations.');
|
|
297
|
+
rows = await response.json();
|
|
298
|
+
rowsVersion++;
|
|
299
|
+
signature = '';
|
|
300
|
+
panelSignature = '';
|
|
301
|
+
renderedSceneKey = '';
|
|
302
|
+
render();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function mutate(action, payload) {
|
|
306
|
+
const response = await dataFetch('api/annotations', {
|
|
307
|
+
method: 'POST',
|
|
308
|
+
headers: { 'Content-Type': 'application/json' },
|
|
309
|
+
body: JSON.stringify({ ...payload, action }),
|
|
310
|
+
});
|
|
311
|
+
if (!response.ok) throw Error((await response.json()).error ?? 'Cannot save annotation.');
|
|
312
|
+
const result = await response.json();
|
|
313
|
+
await refresh();
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function cancelMove() {
|
|
318
|
+
if (!movingId) return false;
|
|
319
|
+
movingId = null;
|
|
320
|
+
viewport.classList.remove('annotating');
|
|
321
|
+
signature = '';
|
|
322
|
+
renderedSceneKey = '';
|
|
323
|
+
render();
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function startMove(row) {
|
|
328
|
+
movingId = row.id;
|
|
329
|
+
highlightedId = row.id;
|
|
330
|
+
viewport.classList.add('annotating');
|
|
331
|
+
signature = '';
|
|
332
|
+
renderedSceneKey = '';
|
|
333
|
+
render();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async function annotateAt({ source, frame, fx, fy, element = null, returnFocus } = {}) {
|
|
337
|
+
cancelMove();
|
|
338
|
+
const state = getState();
|
|
339
|
+
const sourcePath = toProjectSource(state.sourcePrefix, source);
|
|
340
|
+
const meta = element
|
|
341
|
+
? `${sourcePath} · ${frame} · ${element.owner?.export ? `${element.owner.export} (${element.id})` : element.id}`
|
|
342
|
+
: `${sourcePath} · ${frame}`;
|
|
343
|
+
try {
|
|
344
|
+
const note = await openEditor({ title: element ? 'Annotate element' : 'Annotate frame', label: 'Annotation note', meta, returnFocus });
|
|
345
|
+
if (note?.trim()) {
|
|
346
|
+
const created = await mutate('create', { source, frame, x: clamp01(fx), y: clamp01(fy), element, note: note.trim() });
|
|
347
|
+
highlightedId = created.id;
|
|
348
|
+
signature = '';
|
|
349
|
+
panelSignature = '';
|
|
350
|
+
renderedSceneKey = '';
|
|
351
|
+
render();
|
|
352
|
+
}
|
|
353
|
+
} catch (e) {
|
|
354
|
+
fail(e);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async function editNote(row, returnFocus) {
|
|
359
|
+
const state = getState();
|
|
360
|
+
const meta = `#${row.number} · ${toProjectSource(state.sourcePrefix, row.source)} · ${row.frame}`;
|
|
361
|
+
try {
|
|
362
|
+
const note = await openEditor({ title: `Edit annotation #${row.number}`, label: 'Annotation note', meta, initial: row.note, returnFocus });
|
|
363
|
+
if (note?.trim() && note.trim() !== row.note) {
|
|
364
|
+
await mutate('update', { id: row.id, note: note.trim() });
|
|
365
|
+
}
|
|
366
|
+
} catch (e) {
|
|
367
|
+
fail(e);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async function replyToNote(row, returnFocus) {
|
|
372
|
+
const state = getState();
|
|
373
|
+
const meta = `#${row.number} · ${toProjectSource(state.sourcePrefix, row.source)} · ${row.frame}`;
|
|
374
|
+
try {
|
|
375
|
+
const message = await openEditor({ title: `Reply to annotation #${row.number}`, label: 'Reply message', meta, initial: '', returnFocus });
|
|
376
|
+
if (message?.trim()) {
|
|
377
|
+
await mutate('reply', { id: row.id, message: message.trim(), author: 'user' });
|
|
378
|
+
}
|
|
379
|
+
} catch (e) {
|
|
380
|
+
fail(e);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function copyNotesPrompt(targetRows) {
|
|
385
|
+
const state = getState();
|
|
386
|
+
if (!targetRows.length) return;
|
|
387
|
+
const notes = targetRows.map(r => resolveRow(r, state));
|
|
388
|
+
const text = formatAgentPrompt({ projectRoot: state.projectRoot, sourcePrefix: state.sourcePrefix, notes });
|
|
389
|
+
copyText(text);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function copyOpenForFrame(source, frame) {
|
|
393
|
+
const openRows = rows.filter(r => r.source === source && r.frame === frame && r.status === 'open').sort((a, b) => a.number - b.number);
|
|
394
|
+
copyNotesPrompt(openRows);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function openRowsForPanel(state = getState()) {
|
|
398
|
+
return rows
|
|
399
|
+
.filter(r => r.status === 'open' && (scopeFilter !== 'frame' || (state.selectedFrame && r.source === state.selectedFrame.source && r.frame === state.selectedFrame.frame)))
|
|
400
|
+
.sort((a, b) => a.number - b.number);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function noteMenuItems(row) {
|
|
404
|
+
const items = [
|
|
405
|
+
{ label: 'Edit', action: () => editNote(row) },
|
|
406
|
+
{ label: 'Reply', action: () => replyToNote(row) },
|
|
407
|
+
];
|
|
408
|
+
if (row.status === 'open' || row.status === 'addressed') {
|
|
409
|
+
items.push({ label: 'Resolve', action: () => mutate('resolve', { id: row.id }).catch(fail) });
|
|
410
|
+
}
|
|
411
|
+
if (row.status === 'addressed' || row.status === 'resolved') {
|
|
412
|
+
items.push({ label: 'Reopen', action: () => mutate('reopen', { id: row.id }).catch(fail) });
|
|
413
|
+
}
|
|
414
|
+
items.push(
|
|
415
|
+
{ label: 'Move', disabled: row.status === 'resolved', action: () => startMove(row) },
|
|
416
|
+
{ label: 'Copy as agent prompt', action: () => copyNotesPrompt([row]) },
|
|
417
|
+
{ separator: true },
|
|
418
|
+
{ label: 'Delete', action: () => mutate('delete', { id: row.id }).catch(fail) },
|
|
419
|
+
);
|
|
420
|
+
return items;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function openNoteMenu(row, { x, y, returnFocus } = {}) {
|
|
424
|
+
highlightedId = row.id;
|
|
425
|
+
selectNoteTarget?.(row, resolveRow(row));
|
|
426
|
+
render();
|
|
427
|
+
contextMenu.open(noteMenuItems(row), { x, y, returnFocus });
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
toggleButton.onclick = () => {
|
|
431
|
+
panelOpen = !panelOpen;
|
|
432
|
+
onChromeChange?.();
|
|
433
|
+
render();
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
panel.querySelector('#copy-open-annotations').onclick = () => copyNotesPrompt(openRowsForPanel());
|
|
437
|
+
for (const btn of panel.querySelectorAll('[data-filter-status]')) {
|
|
438
|
+
btn.onclick = () => {
|
|
439
|
+
statusFilter = btn.dataset.filterStatus;
|
|
440
|
+
panelSignature = '';
|
|
441
|
+
renderPanel(getState());
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
for (const btn of panel.querySelectorAll('[data-filter-scope]')) {
|
|
445
|
+
btn.onclick = () => {
|
|
446
|
+
scopeFilter = btn.dataset.filterScope;
|
|
447
|
+
panelSignature = '';
|
|
448
|
+
renderPanel(getState());
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function renderPanel(state) {
|
|
453
|
+
const canShow = state.opened && panelOpen;
|
|
454
|
+
if (panel.hidden !== !canShow) panel.hidden = !canShow;
|
|
455
|
+
toggleButton.disabled = !state.opened;
|
|
456
|
+
toggleButton.setAttribute('aria-expanded', String(canShow));
|
|
457
|
+
if (!canShow) return;
|
|
458
|
+
|
|
459
|
+
const resolvedAll = rows.map(r => resolveRow(r, state));
|
|
460
|
+
const pKey = JSON.stringify([
|
|
461
|
+
rowsVersion,
|
|
462
|
+
statusFilter,
|
|
463
|
+
scopeFilter,
|
|
464
|
+
highlightedId,
|
|
465
|
+
state.selectedFrame?.source ?? null,
|
|
466
|
+
state.selectedFrame?.frame ?? null,
|
|
467
|
+
resolvedAll.map(x => [x.row.id, x.row.updatedAt, x.row.status, x.stale]),
|
|
468
|
+
]);
|
|
469
|
+
if (pKey === panelSignature) return;
|
|
470
|
+
panelSignature = pKey;
|
|
471
|
+
|
|
472
|
+
for (const btn of panel.querySelectorAll('[data-filter-status]')) {
|
|
473
|
+
btn.setAttribute('aria-pressed', String(btn.dataset.filterStatus === statusFilter));
|
|
474
|
+
}
|
|
475
|
+
for (const btn of panel.querySelectorAll('[data-filter-scope]')) {
|
|
476
|
+
btn.setAttribute('aria-pressed', String(btn.dataset.filterScope === scopeFilter));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const openInScope = openRowsForPanel(state);
|
|
480
|
+
const copyBtn = panel.querySelector('#copy-open-annotations');
|
|
481
|
+
copyBtn.disabled = !openInScope.length;
|
|
482
|
+
|
|
483
|
+
const scoped = scopeFilter === 'frame'
|
|
484
|
+
? (state.selectedFrame ? resolvedAll.filter(x => x.row.source === state.selectedFrame.source && x.row.frame === state.selectedFrame.frame) : [])
|
|
485
|
+
: resolvedAll;
|
|
486
|
+
const filtered = (statusFilter === 'all' ? scoped : scoped.filter(x => x.row.status === statusFilter))
|
|
487
|
+
.sort((a, b) => a.row.number - b.row.number);
|
|
488
|
+
|
|
489
|
+
panel.querySelector('#annotations-count').textContent = String(filtered.length);
|
|
490
|
+
const list = panel.querySelector('.annotation-list');
|
|
491
|
+
const focusedId = list.contains(document.activeElement) ? document.activeElement.closest('[data-annotation-id]')?.dataset.annotationId : null;
|
|
492
|
+
|
|
493
|
+
if (!filtered.length) {
|
|
494
|
+
const empty = document.createElement('p');
|
|
495
|
+
empty.className = 'annotation-empty';
|
|
496
|
+
empty.textContent = scopeFilter === 'frame' && !state.selectedFrame
|
|
497
|
+
? 'Select a frame to filter annotations.'
|
|
498
|
+
: 'No matching annotations.';
|
|
499
|
+
list.replaceChildren(empty);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
list.replaceChildren(...filtered.map(entry => {
|
|
504
|
+
const { row: r, stale } = entry;
|
|
505
|
+
const wrapper = document.createElement('div');
|
|
506
|
+
wrapper.className = 'annotation-row-item';
|
|
507
|
+
wrapper.setAttribute('role', 'listitem');
|
|
508
|
+
|
|
509
|
+
const btn = document.createElement('button');
|
|
510
|
+
btn.type = 'button';
|
|
511
|
+
btn.className = 'annotation-row';
|
|
512
|
+
btn.dataset.annotationId = r.id;
|
|
513
|
+
btn.dataset.status = r.status;
|
|
514
|
+
btn.dataset.stale = String(stale);
|
|
515
|
+
btn.dataset.highlighted = String(highlightedId === r.id);
|
|
516
|
+
|
|
517
|
+
const meta = document.createElement('span');
|
|
518
|
+
meta.className = 'annotation-row-meta';
|
|
519
|
+
const num = document.createElement('span');
|
|
520
|
+
num.className = 'annotation-number';
|
|
521
|
+
num.textContent = `#${r.number}`;
|
|
522
|
+
const statusBadge = document.createElement('span');
|
|
523
|
+
statusBadge.className = 'annotation-badge';
|
|
524
|
+
statusBadge.dataset.status = r.status;
|
|
525
|
+
statusBadge.textContent = r.status;
|
|
526
|
+
meta.append(num, statusBadge);
|
|
527
|
+
if (stale) {
|
|
528
|
+
const staleBadge = document.createElement('span');
|
|
529
|
+
staleBadge.className = 'annotation-badge';
|
|
530
|
+
staleBadge.dataset.stale = 'true';
|
|
531
|
+
staleBadge.textContent = 'stale';
|
|
532
|
+
meta.append(staleBadge);
|
|
533
|
+
}
|
|
534
|
+
const frameSpan = document.createElement('span');
|
|
535
|
+
frameSpan.className = 'annotation-row-frame';
|
|
536
|
+
frameSpan.textContent = r.frame;
|
|
537
|
+
frameSpan.title = `${r.source} · ${r.frame}`;
|
|
538
|
+
const replySpan = document.createElement('span');
|
|
539
|
+
replySpan.className = 'annotation-row-replies';
|
|
540
|
+
replySpan.textContent = `${r.replies.length} ${r.replies.length === 1 ? 'reply' : 'replies'}`;
|
|
541
|
+
meta.append(frameSpan, replySpan);
|
|
542
|
+
|
|
543
|
+
const excerpt = document.createElement('span');
|
|
544
|
+
excerpt.className = 'annotation-row-excerpt';
|
|
545
|
+
excerpt.textContent = r.note;
|
|
546
|
+
|
|
547
|
+
btn.append(meta, excerpt);
|
|
548
|
+
btn.onclick = () => {
|
|
549
|
+
highlightedId = r.id;
|
|
550
|
+
navigateToNote?.(r, entry);
|
|
551
|
+
signature = '';
|
|
552
|
+
panelSignature = '';
|
|
553
|
+
renderedSceneKey = '';
|
|
554
|
+
render();
|
|
555
|
+
};
|
|
556
|
+
btn.oncontextmenu = event => {
|
|
557
|
+
event.preventDefault();
|
|
558
|
+
event.stopPropagation();
|
|
559
|
+
openNoteMenu(r, { x: event.clientX, y: event.clientY, returnFocus: btn });
|
|
560
|
+
};
|
|
561
|
+
wrapper.append(btn);
|
|
562
|
+
|
|
563
|
+
if (r.status === 'resolved') {
|
|
564
|
+
const reopen = document.createElement('button');
|
|
565
|
+
reopen.type = 'button';
|
|
566
|
+
reopen.className = 'annotation-row-action';
|
|
567
|
+
reopen.textContent = 'Reopen';
|
|
568
|
+
reopen.setAttribute('aria-label', `Reopen annotation ${r.number}`);
|
|
569
|
+
reopen.onclick = () => mutate('reopen', { id: r.id }).catch(fail);
|
|
570
|
+
wrapper.append(reopen);
|
|
571
|
+
}
|
|
572
|
+
return wrapper;
|
|
573
|
+
}));
|
|
574
|
+
|
|
575
|
+
if (focusedId) {
|
|
576
|
+
list.querySelector(`.annotation-row[data-annotation-id="${CSS.escape(focusedId)}"]`)?.focus({ preventScroll: true });
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function render() {
|
|
581
|
+
const state = getState();
|
|
582
|
+
rememberKnownParts(state);
|
|
583
|
+
renderPanel(state);
|
|
584
|
+
|
|
585
|
+
if (!state.opened) {
|
|
586
|
+
if (layer.childElementCount) layer.replaceChildren();
|
|
587
|
+
layer.style.transform = '';
|
|
588
|
+
signature = 'closed';
|
|
589
|
+
renderedSceneKey = '';
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const activeRows = rows.filter(r => r.status !== 'resolved');
|
|
594
|
+
const sceneKey = `${rowsVersion}|${state.revision ?? 0}|${state.scope}|${state.view.scale}|${movingId ?? ''}|${highlightedId ?? ''}|${state.visibleFrames.map(f => `${f.source}#${f.frame}@${f.world.x},${f.world.y},${f.world.width},${f.world.height}`).join(';')}`;
|
|
595
|
+
|
|
596
|
+
if (state.moving && renderedView && renderedSceneKey === sceneKey) {
|
|
597
|
+
layer.style.transform = `translate(${state.view.x - renderedView.x}px, ${state.view.y - renderedView.y}px)`;
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const fullKey = `${sceneKey}|${state.view.x},${state.view.y}`;
|
|
602
|
+
if (fullKey === signature) return;
|
|
603
|
+
signature = fullKey;
|
|
604
|
+
renderedSceneKey = sceneKey;
|
|
605
|
+
renderedView = { ...state.view };
|
|
606
|
+
layer.style.transform = '';
|
|
607
|
+
layer.replaceChildren();
|
|
608
|
+
|
|
609
|
+
if (!activeRows.length || !state.visibleFrames.length) return;
|
|
610
|
+
|
|
611
|
+
if (state.view.scale < READABLE_ANNOTATION_SCALE) {
|
|
612
|
+
for (const vf of state.visibleFrames) {
|
|
613
|
+
const frameNotes = activeRows.filter(r => r.source === vf.source && r.frame === vf.frame);
|
|
614
|
+
if (!frameNotes.length) continue;
|
|
615
|
+
const resolvedList = frameNotes.map(r => resolveRow(r, state));
|
|
616
|
+
const badge = document.createElement('button');
|
|
617
|
+
badge.type = 'button';
|
|
618
|
+
badge.className = 'annotation-frame-badge';
|
|
619
|
+
badge.dataset.source = vf.source;
|
|
620
|
+
badge.dataset.frame = vf.frame;
|
|
621
|
+
badge.dataset.status = frameNotes.some(r => r.status === 'open') ? 'open' : 'addressed';
|
|
622
|
+
badge.dataset.stale = String(resolvedList.some(x => x.stale));
|
|
623
|
+
badge.textContent = String(frameNotes.length);
|
|
624
|
+
badge.setAttribute('aria-label', `${frameNotes.length} ${frameNotes.length === 1 ? 'annotation' : 'annotations'} on ${vf.frame}`);
|
|
625
|
+
Object.assign(badge.style, { left: `${vf.box.x + vf.box.width - 2}px`, top: `${vf.box.y + 2}px` });
|
|
626
|
+
badge.onclick = event => {
|
|
627
|
+
event.stopPropagation();
|
|
628
|
+
inspectFrame?.(vf.asset, vf.part, READABLE_ANNOTATION_SCALE);
|
|
629
|
+
};
|
|
630
|
+
layer.append(badge);
|
|
631
|
+
}
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
636
|
+
layer.append(svg);
|
|
637
|
+
|
|
638
|
+
for (const vf of state.visibleFrames) {
|
|
639
|
+
const frameNotes = activeRows
|
|
640
|
+
.filter(r => r.source === vf.source && r.frame === vf.frame)
|
|
641
|
+
.map(r => resolveRow(r, state))
|
|
642
|
+
.sort((a, b) => a.fy - b.fy || a.fx - b.fx || a.row.number - b.row.number);
|
|
643
|
+
if (!frameNotes.length) continue;
|
|
644
|
+
|
|
645
|
+
const b = vf.box;
|
|
646
|
+
let bottom = b.y;
|
|
647
|
+
for (const entry of frameNotes) {
|
|
648
|
+
const { row: r, stale, fx, fy } = entry;
|
|
649
|
+
const x = b.x + fx * b.width;
|
|
650
|
+
const y = b.y + fy * b.height;
|
|
651
|
+
const cy = Math.max(y - 14, bottom);
|
|
652
|
+
const cardGap = 114 + Math.min(r.replies.length, 3) * 38;
|
|
653
|
+
bottom = cy + cardGap;
|
|
654
|
+
|
|
655
|
+
const line = document.createElementNS(svg.namespaceURI, 'polyline');
|
|
656
|
+
line.setAttribute('points', `${x},${y} ${b.x + b.width + 12},${y} ${b.x + b.width + 26},${cy + 16}`);
|
|
657
|
+
line.dataset.state = r.status;
|
|
658
|
+
line.dataset.stale = String(stale);
|
|
659
|
+
svg.append(line);
|
|
660
|
+
|
|
661
|
+
const point = document.createElement('button');
|
|
662
|
+
point.type = 'button';
|
|
663
|
+
point.className = 'annotation-point';
|
|
664
|
+
point.dataset.annotationId = r.id;
|
|
665
|
+
point.dataset.state = r.status;
|
|
666
|
+
point.dataset.stale = String(stale);
|
|
667
|
+
point.dataset.highlighted = String(highlightedId === r.id);
|
|
668
|
+
point.textContent = String(r.number);
|
|
669
|
+
point.setAttribute('aria-label', `Edit annotation ${r.number}`);
|
|
670
|
+
Object.assign(point.style, { left: `${x}px`, top: `${y}px` });
|
|
671
|
+
point.onclick = () => {
|
|
672
|
+
highlightedId = r.id;
|
|
673
|
+
selectNoteTarget?.(r, entry);
|
|
674
|
+
editNote(r, point);
|
|
675
|
+
};
|
|
676
|
+
point.oncontextmenu = event => {
|
|
677
|
+
event.preventDefault();
|
|
678
|
+
event.stopPropagation();
|
|
679
|
+
openNoteMenu(r, { x: event.clientX, y: event.clientY, returnFocus: point });
|
|
680
|
+
};
|
|
681
|
+
layer.append(point);
|
|
682
|
+
|
|
683
|
+
const card = document.createElement('article');
|
|
684
|
+
card.className = 'annotation-card';
|
|
685
|
+
card.dataset.annotationId = r.id;
|
|
686
|
+
card.dataset.state = r.status;
|
|
687
|
+
card.dataset.stale = String(stale);
|
|
688
|
+
card.dataset.highlighted = String(highlightedId === r.id);
|
|
689
|
+
Object.assign(card.style, { left: `${b.x + b.width + 26}px`, top: `${cy}px` });
|
|
690
|
+
card.oncontextmenu = event => {
|
|
691
|
+
event.preventDefault();
|
|
692
|
+
event.stopPropagation();
|
|
693
|
+
openNoteMenu(r, { x: event.clientX, y: event.clientY, returnFocus: card.querySelector('.annotation-note') ?? point });
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const header = document.createElement('div');
|
|
697
|
+
header.className = 'annotation-card-header';
|
|
698
|
+
const num = document.createElement('span');
|
|
699
|
+
num.className = 'annotation-number';
|
|
700
|
+
num.textContent = `#${r.number}`;
|
|
701
|
+
const badge = document.createElement('span');
|
|
702
|
+
badge.className = 'annotation-badge';
|
|
703
|
+
badge.dataset.status = r.status;
|
|
704
|
+
badge.textContent = r.status;
|
|
705
|
+
header.append(num, badge);
|
|
706
|
+
if (stale) {
|
|
707
|
+
const staleBadge = document.createElement('span');
|
|
708
|
+
staleBadge.className = 'annotation-badge';
|
|
709
|
+
staleBadge.dataset.stale = 'true';
|
|
710
|
+
staleBadge.textContent = 'stale';
|
|
711
|
+
header.append(staleBadge);
|
|
712
|
+
}
|
|
713
|
+
if (r.element?.owner?.export) {
|
|
714
|
+
const ownerSpan = document.createElement('span');
|
|
715
|
+
ownerSpan.className = 'annotation-owner';
|
|
716
|
+
ownerSpan.textContent = r.element.owner.export;
|
|
717
|
+
ownerSpan.title = r.element.id;
|
|
718
|
+
header.append(ownerSpan);
|
|
719
|
+
}
|
|
720
|
+
card.append(header);
|
|
721
|
+
|
|
722
|
+
const noteBtn = document.createElement('button');
|
|
723
|
+
noteBtn.type = 'button';
|
|
724
|
+
noteBtn.className = 'annotation-note';
|
|
725
|
+
noteBtn.textContent = r.note;
|
|
726
|
+
noteBtn.onclick = () => {
|
|
727
|
+
highlightedId = r.id;
|
|
728
|
+
selectNoteTarget?.(r, entry);
|
|
729
|
+
editNote(r, noteBtn);
|
|
730
|
+
};
|
|
731
|
+
card.append(noteBtn);
|
|
732
|
+
|
|
733
|
+
if (r.replies.length) {
|
|
734
|
+
const thread = document.createElement('div');
|
|
735
|
+
thread.className = 'annotation-thread';
|
|
736
|
+
for (const reply of r.replies) {
|
|
737
|
+
const item = document.createElement('div');
|
|
738
|
+
item.className = 'annotation-reply';
|
|
739
|
+
item.dataset.author = reply.author;
|
|
740
|
+
const author = document.createElement('span');
|
|
741
|
+
author.className = 'annotation-reply-author';
|
|
742
|
+
author.textContent = reply.author === 'agent' ? 'Agent' : 'You';
|
|
743
|
+
const body = document.createElement('p');
|
|
744
|
+
body.className = 'annotation-reply-body';
|
|
745
|
+
body.textContent = reply.message;
|
|
746
|
+
item.append(author, body);
|
|
747
|
+
thread.append(item);
|
|
748
|
+
}
|
|
749
|
+
card.append(thread);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const actions = document.createElement('div');
|
|
753
|
+
actions.className = 'annotation-actions';
|
|
754
|
+
const actionDefs = [
|
|
755
|
+
['Reply', () => replyToNote(r, noteBtn)],
|
|
756
|
+
...(r.status === 'open' || r.status === 'addressed' ? [['Resolve', () => mutate('resolve', { id: r.id })]] : []),
|
|
757
|
+
...(r.status === 'addressed' ? [['Reopen', () => mutate('reopen', { id: r.id })]] : []),
|
|
758
|
+
['Move', () => startMove(r)],
|
|
759
|
+
['Delete', () => mutate('delete', { id: r.id })],
|
|
760
|
+
];
|
|
761
|
+
for (const [label, handler] of actionDefs) {
|
|
762
|
+
const btn = document.createElement('button');
|
|
763
|
+
btn.type = 'button';
|
|
764
|
+
btn.textContent = label;
|
|
765
|
+
btn.onclick = () => Promise.resolve(handler()).catch(fail);
|
|
766
|
+
actions.append(btn);
|
|
767
|
+
}
|
|
768
|
+
card.append(actions);
|
|
769
|
+
layer.append(card);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
document.addEventListener('visibilitychange', () => {
|
|
775
|
+
if (!document.hidden && getState().opened) refresh().catch(fail);
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
refresh().catch(fail);
|
|
779
|
+
|
|
780
|
+
return {
|
|
781
|
+
render,
|
|
782
|
+
refresh,
|
|
783
|
+
annotateAt,
|
|
784
|
+
openNoteMenu,
|
|
785
|
+
copyOpenForFrame,
|
|
786
|
+
countOpenForFrame: (source, frame) => rows.filter(r => r.source === source && r.frame === frame && r.status === 'open').length,
|
|
787
|
+
getRow: id => rows.find(r => r.id === id) ?? null,
|
|
788
|
+
active: () => Boolean(movingId),
|
|
789
|
+
cancelMove,
|
|
790
|
+
async click(worldX, worldY) {
|
|
791
|
+
if (!movingId) return false;
|
|
792
|
+
const targetRow = rows.find(r => r.id === movingId);
|
|
793
|
+
if (!targetRow) { cancelMove(); return false; }
|
|
794
|
+
const hit = hitFrameAt(worldX, worldY);
|
|
795
|
+
if (!hit?.part) { cancelMove(); return true; }
|
|
796
|
+
const fb = hit.frameBox;
|
|
797
|
+
const fx = clamp01((worldX - fb.x) / fb.width);
|
|
798
|
+
const fy = clamp01((worldY - fb.y) / fb.height);
|
|
799
|
+
const el = hit.element;
|
|
800
|
+
const element = el ? {
|
|
801
|
+
id: el.id,
|
|
802
|
+
owner: el.owner ?? el.owners?.at(-1) ?? { source: hit.asset.path, export: null },
|
|
803
|
+
x: el.width > 0 ? clamp01((worldX - (fb.x + el.x)) / el.width) : 0.5,
|
|
804
|
+
y: el.height > 0 ? clamp01((worldY - (fb.y + el.y)) / el.height) : 0.5,
|
|
805
|
+
} : null;
|
|
806
|
+
const id = movingId;
|
|
807
|
+
cancelMove();
|
|
808
|
+
try {
|
|
809
|
+
await mutate('update', { id, source: hit.asset.path, frame: hit.part.name, x: fx, y: fy, element });
|
|
810
|
+
} catch (e) {
|
|
811
|
+
fail(e);
|
|
812
|
+
}
|
|
813
|
+
return true;
|
|
814
|
+
},
|
|
815
|
+
};
|
|
816
|
+
}
|