@khanglvm/relay 0.19.0 → 0.20.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 (131) hide show
  1. package/bin/rly.js +1 -1
  2. package/package.json +4 -4
  3. package/src/cli/args.js +46 -0
  4. package/src/cli/ask.js +12 -0
  5. package/src/cli/boards.js +326 -0
  6. package/src/cli/config.js +56 -0
  7. package/src/cli/context.js +13 -0
  8. package/src/cli/git.js +183 -0
  9. package/src/cli/help.js +90 -0
  10. package/src/cli/index.js +103 -0
  11. package/src/cli/install.js +197 -0
  12. package/src/cli/io.js +186 -0
  13. package/src/cli/mcp.js +94 -0
  14. package/src/cli/share.js +45 -0
  15. package/src/cli/skill.js +192 -0
  16. package/src/cli/upgrade.js +130 -0
  17. package/src/cli/wait.js +172 -0
  18. package/src/file-preview.js +1 -1
  19. package/src/index.js +1 -1
  20. package/src/mcp-ui/board/block-ctx.js +43 -0
  21. package/src/mcp-ui/board/bridge.js +165 -0
  22. package/src/mcp-ui/board/controls.js +310 -0
  23. package/src/mcp-ui/board/core.js +20 -0
  24. package/src/mcp-ui/board/lifecycle.js +118 -0
  25. package/src/mcp-ui/board/normalize.js +95 -0
  26. package/src/mcp-ui/board/render.js +200 -0
  27. package/src/mcp-ui/board/state.js +106 -0
  28. package/src/mcp-ui/board/vendors.js +86 -0
  29. package/src/mcp.js +12 -18
  30. package/src/{server.js → server/board.js} +15 -778
  31. package/src/server/files.js +141 -0
  32. package/src/server/http.js +114 -0
  33. package/src/server/index.js +2 -0
  34. package/src/server/page.js +183 -0
  35. package/src/server/paths.js +7 -0
  36. package/src/server/result.js +58 -0
  37. package/src/server/reviews.js +41 -0
  38. package/src/server/sanitize.js +231 -0
  39. package/src/spec/blocks/a2ui.js +25 -0
  40. package/src/spec/blocks/chart.js +49 -0
  41. package/src/spec/blocks/code.js +38 -0
  42. package/src/spec/blocks/diagram.js +39 -0
  43. package/src/spec/blocks/git-conflict.js +106 -0
  44. package/src/spec/blocks/image.js +32 -0
  45. package/src/spec/blocks/index.js +33 -0
  46. package/src/spec/blocks/markdown.js +13 -0
  47. package/src/spec/blocks/pdf.js +38 -0
  48. package/src/spec/blocks/table.js +122 -0
  49. package/src/spec/blocks/video.js +68 -0
  50. package/src/spec/blocks/widgets.js +98 -0
  51. package/src/spec/constants.js +65 -0
  52. package/src/spec/index.js +5 -0
  53. package/src/spec/normalize.js +285 -0
  54. package/src/spec/ready.js +106 -0
  55. package/src/spec/schema.js +182 -0
  56. package/src/spec/sources.js +83 -0
  57. package/src/ui/annotate/api.js +149 -0
  58. package/src/ui/annotate/badges.js +77 -0
  59. package/src/ui/annotate/chrome.js +158 -0
  60. package/src/ui/annotate/core.js +134 -0
  61. package/src/ui/annotate/highlights.js +129 -0
  62. package/src/ui/annotate/mutations.js +127 -0
  63. package/src/ui/annotate/popover.js +206 -0
  64. package/src/ui/annotate/summary.js +67 -0
  65. package/src/ui/app/annotations.js +88 -0
  66. package/src/ui/app/autosave.js +44 -0
  67. package/src/ui/app/core.js +74 -0
  68. package/src/ui/app/drafts.js +201 -0
  69. package/src/ui/app/heartbeat.js +150 -0
  70. package/src/ui/app/iframe-bridge.js +64 -0
  71. package/src/ui/app/persistence.js +117 -0
  72. package/src/ui/app/prefilled.js +21 -0
  73. package/src/ui/app/presence.js +38 -0
  74. package/src/ui/app/question-color.js +67 -0
  75. package/src/ui/app/questions.js +360 -0
  76. package/src/ui/app/render.js +135 -0
  77. package/src/ui/app/share.js +108 -0
  78. package/src/ui/app/submit.js +109 -0
  79. package/src/ui/app/theme.js +63 -0
  80. package/src/ui/blocks/api.js +1 -0
  81. package/src/ui/blocks/chart.js +222 -0
  82. package/src/ui/blocks/code.js +138 -0
  83. package/src/ui/blocks/compare.js +82 -0
  84. package/src/ui/blocks/core.js +74 -0
  85. package/src/ui/blocks/diff.js +361 -0
  86. package/src/ui/blocks/dispatch.js +111 -0
  87. package/src/ui/blocks/file-links.js +180 -0
  88. package/src/ui/blocks/git-conflict.js +151 -0
  89. package/src/ui/blocks/graphviz.js +57 -0
  90. package/src/ui/blocks/html.js +45 -0
  91. package/src/ui/blocks/image.js +371 -0
  92. package/src/ui/blocks/kpi.js +26 -0
  93. package/src/ui/blocks/markdown.js +223 -0
  94. package/src/ui/blocks/mermaid.js +242 -0
  95. package/src/ui/blocks/palette.js +59 -0
  96. package/src/ui/blocks/pdf.js +21 -0
  97. package/src/ui/blocks/plantuml.js +152 -0
  98. package/src/ui/blocks/table.js +155 -0
  99. package/src/ui/blocks/typography.js +25 -0
  100. package/src/ui/blocks/vendor.js +43 -0
  101. package/src/ui/blocks/video.js +43 -0
  102. package/src/ui/blocks/viewer-fullscreen.js +146 -0
  103. package/src/ui/blocks/viewer.js +324 -0
  104. package/src/ui/kit.js +1 -0
  105. package/src/ui/manifest.js +140 -0
  106. package/types/index.d.ts +1 -1
  107. package/types/spec/blocks/a2ui.d.ts +4 -0
  108. package/types/spec/blocks/chart.d.ts +4 -0
  109. package/types/spec/blocks/code.d.ts +10 -0
  110. package/types/spec/blocks/diagram.d.ts +15 -0
  111. package/types/spec/blocks/git-conflict.d.ts +7 -0
  112. package/types/spec/blocks/image.d.ts +5 -0
  113. package/types/spec/blocks/index.d.ts +30 -0
  114. package/types/spec/blocks/markdown.d.ts +5 -0
  115. package/types/spec/blocks/pdf.d.ts +4 -0
  116. package/types/spec/blocks/table.d.ts +9 -0
  117. package/types/spec/blocks/video.d.ts +4 -0
  118. package/types/spec/blocks/widgets.d.ts +21 -0
  119. package/types/spec/constants.d.ts +67 -0
  120. package/types/spec/index.d.ts +4 -0
  121. package/types/spec/normalize.d.ts +17 -0
  122. package/types/spec/ready.d.ts +1 -0
  123. package/types/{spec.d.ts → spec/schema.d.ts} +0 -20
  124. package/types/spec/sources.d.ts +14 -0
  125. package/types/ui/manifest.d.ts +62 -0
  126. package/src/cli.js +0 -1767
  127. package/src/mcp-ui/board.js +0 -1162
  128. package/src/spec.js +0 -1224
  129. package/src/ui/annotate.js +0 -1055
  130. package/src/ui/app.js +0 -1643
  131. package/src/ui/blocks.js +0 -3260
@@ -0,0 +1,360 @@
1
+ // ---------- controls ----------
2
+ const cards = {};
3
+
4
+ function clearErr(qid) {
5
+ if (cards[qid]) cards[qid].classList.remove('error');
6
+ }
7
+
8
+ function syncOptSel(group) {
9
+ for (const lab of group.querySelectorAll('label.opt')) {
10
+ const input = lab.querySelector('input');
11
+ lab.classList.toggle('sel', input.checked);
12
+ // options with visuals: the bordered card is the wrapper, not the label
13
+ const wrap = lab.closest('.optwrap');
14
+ if (wrap) wrap.classList.toggle('sel', input.checked);
15
+ }
16
+ }
17
+
18
+ // Options may carry their own blocks (visual examples of the choice). The
19
+ // blocks render in a wrapper card OUTSIDE the <label> so interacting with a
20
+ // chart/diagram/image doesn't toggle the option.
21
+ function withOptionBlocks(labelEl, o, questionId) {
22
+ if (!Array.isArray(o.blocks) || !o.blocks.length) return labelEl;
23
+ const wrap = el('div', { class: 'optwrap' + (labelEl.classList.contains('sel') ? ' sel' : '') }, labelEl);
24
+ renderBlocks(wrap, o.blocks, questionId);
25
+ return wrap;
26
+ }
27
+
28
+ function controlSingle(q) {
29
+ const group = el('div');
30
+ const entries = [];
31
+ let otherRadio = null;
32
+ const otherOn = () => Boolean(state.other[q.id] && state.other[q.id].on);
33
+ const syncSingle = () => {
34
+ for (const { input, value } of entries) input.checked = state.answers[q.id] === value && !otherOn();
35
+ if (otherRadio) otherRadio.checked = otherOn();
36
+ syncOptSel(group);
37
+ clearErr(q.id);
38
+ scheduleSave();
39
+ };
40
+ for (const o of q.options) {
41
+ const input = el('input', { type: 'radio', name: q.id });
42
+ entries.push({ input, value: o.value });
43
+ input.checked = state.answers[q.id] === o.value && !otherOn();
44
+ // Click-to-toggle: clicking the selected option unselects it (answers
45
+ // are optional by default). preventDefault keeps `checked` ours to set.
46
+ input.addEventListener('click', (e) => {
47
+ e.preventDefault();
48
+ if (state.answers[q.id] === o.value && !otherOn()) {
49
+ delete state.answers[q.id];
50
+ } else {
51
+ state.answers[q.id] = o.value;
52
+ if (state.other[q.id]) state.other[q.id].on = false;
53
+ }
54
+ // Defer: after a canceled activation the browser restores the
55
+ // pre-click checked state AFTER this handler, clobbering direct sets.
56
+ setTimeout(syncSingle, 0);
57
+ });
58
+ input.addEventListener('change', () => {
59
+ // keyboard path (arrow keys / space) — no click event fires
60
+ if (!input.checked) return;
61
+ state.answers[q.id] = o.value;
62
+ if (state.other[q.id]) state.other[q.id].on = false;
63
+ syncSingle();
64
+ });
65
+ group.append(
66
+ withOptionBlocks(
67
+ el('label', { class: 'opt' + (input.checked ? ' sel' : '') },
68
+ input,
69
+ el('div', {},
70
+ el('div', { class: 'ol' }, o.label),
71
+ o.description ? el('div', { class: 'od' }, o.description) : null
72
+ )
73
+ ),
74
+ o,
75
+ q.id
76
+ )
77
+ );
78
+ }
79
+ if (q.other) {
80
+ otherRadio = el('input', { type: 'radio', name: q.id });
81
+ const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
82
+ text.value = (state.other[q.id] && state.other[q.id].text) || '';
83
+ otherRadio.checked = otherOn();
84
+ const ensureOther = () => state.other[q.id] || (state.other[q.id] = { on: false, text: text.value });
85
+ otherRadio.addEventListener('click', (e) => {
86
+ e.preventDefault();
87
+ const oth = ensureOther();
88
+ oth.on = !oth.on;
89
+ if (oth.on) delete state.answers[q.id];
90
+ setTimeout(syncSingle, 0);
91
+ });
92
+ otherRadio.addEventListener('change', () => {
93
+ if (!otherRadio.checked) return;
94
+ const oth = ensureOther();
95
+ oth.on = true;
96
+ delete state.answers[q.id];
97
+ syncSingle();
98
+ });
99
+ text.addEventListener('input', () => {
100
+ const oth = ensureOther();
101
+ oth.text = text.value;
102
+ if (!oth.on) {
103
+ oth.on = true;
104
+ delete state.answers[q.id];
105
+ }
106
+ syncSingle();
107
+ });
108
+ group.append(
109
+ el('label', { class: 'opt' + (otherRadio.checked ? ' sel' : '') },
110
+ otherRadio,
111
+ el('div', { style: 'flex:1' }, el('div', { class: 'ol' }, 'Other'), el('div', { class: 'otherbox' }, text))
112
+ )
113
+ );
114
+ }
115
+ return group;
116
+ }
117
+
118
+ function controlMulti(q) {
119
+ const group = el('div');
120
+ const selected = new Set(Array.isArray(state.answers[q.id]) ? state.answers[q.id] : []);
121
+ const readChecked = () => {
122
+ state.answers[q.id] = [...group.querySelectorAll('input[data-val]')]
123
+ .filter((i) => i.checked)
124
+ .map((i) => i.dataset.val);
125
+ syncOptSel(group);
126
+ clearErr(q.id);
127
+ scheduleSave();
128
+ };
129
+ for (const o of q.options) {
130
+ const input = el('input', { type: 'checkbox', 'data-val': o.value });
131
+ input.checked = selected.has(o.value);
132
+ input.addEventListener('change', readChecked);
133
+ group.append(
134
+ withOptionBlocks(
135
+ el('label', { class: 'opt' + (input.checked ? ' sel' : '') },
136
+ input,
137
+ el('div', {},
138
+ el('div', { class: 'ol' }, o.label),
139
+ o.description ? el('div', { class: 'od' }, o.description) : null
140
+ )
141
+ ),
142
+ o,
143
+ q.id
144
+ )
145
+ );
146
+ }
147
+ if (q.other) {
148
+ const oth = state.other[q.id];
149
+ const box = el('input', { type: 'checkbox' });
150
+ const text = el('textarea', { class: 'otherinput', rows: '2', placeholder: 'your own answer…' });
151
+ box.checked = Boolean(oth && oth.on);
152
+ text.value = (oth && oth.text) || '';
153
+ const sync = () => {
154
+ state.other[q.id] = { on: box.checked, text: text.value };
155
+ syncOptSel(group);
156
+ clearErr(q.id);
157
+ scheduleSave();
158
+ };
159
+ box.addEventListener('change', sync);
160
+ text.addEventListener('input', () => {
161
+ if (!box.checked) box.checked = true;
162
+ sync();
163
+ });
164
+ group.append(
165
+ el('label', { class: 'opt' + (box.checked ? ' sel' : '') },
166
+ box,
167
+ el('div', { style: 'flex:1' }, el('div', { class: 'ol' }, 'Other'), el('div', { class: 'otherbox' }, text))
168
+ )
169
+ );
170
+ }
171
+ return group;
172
+ }
173
+
174
+ function segButtons(q, values, labels) {
175
+ const seg = el('div', { class: q.type === 'scale' ? 'scale' : 'seg' });
176
+ const buttons = [];
177
+ values.forEach((v, i) => {
178
+ const b = el('button', { type: 'button' }, labels[i]);
179
+ if (state.answers[q.id] === v) b.classList.add('sel');
180
+ b.addEventListener('click', () => {
181
+ // click again to unselect (everything is optional by default)
182
+ if (state.answers[q.id] === v) delete state.answers[q.id];
183
+ else state.answers[q.id] = v;
184
+ for (const x of buttons) x.classList.toggle('sel', state.answers[q.id] === values[buttons.indexOf(x)]);
185
+ clearErr(q.id);
186
+ scheduleSave();
187
+ });
188
+ buttons.push(b);
189
+ seg.append(b);
190
+ });
191
+ return seg;
192
+ }
193
+
194
+ function controlScale(q) {
195
+ const values = [];
196
+ for (let i = q.min; i <= q.max; i++) values.push(i);
197
+ const seg = segButtons(q, values, values.map(String));
198
+ const row = el('div', { class: 'scale' });
199
+ if (q.minLabel) row.append(el('span', { class: 'slabel' }, q.minLabel));
200
+ row.append(...seg.children);
201
+ if (q.maxLabel) row.append(el('span', { class: 'slabel' }, q.maxLabel));
202
+ return row;
203
+ }
204
+
205
+ // Reorderable priority list. The user drags an item or uses ↑/↓; the answer is
206
+ // the ordered array of option values (highest priority first). state.answers[q.id]
207
+ // is kept a full, valid permutation by seedRankOrder so it's always submittable.
208
+ function controlRank(q) {
209
+ const wrap = el('div', { class: 'rank' });
210
+ const byVal = new Map(q.options.map((o) => [o.value, o]));
211
+ let dragFrom = null;
212
+ function move(from, to) {
213
+ if (!access.canEditAnswers) return;
214
+ const arr = state.answers[q.id];
215
+ if (!Array.isArray(arr) || to < 0 || to >= arr.length || from === to) return;
216
+ const [x] = arr.splice(from, 1);
217
+ arr.splice(to, 0, x);
218
+ paint();
219
+ clearErr(q.id);
220
+ scheduleSave();
221
+ }
222
+ function paint() {
223
+ wrap.replaceChildren();
224
+ const order = state.answers[q.id] || [];
225
+ order.forEach((val, i) => {
226
+ const o = byVal.get(val);
227
+ if (!o) return;
228
+ const up = el('button', { type: 'button', class: 'rank-btn', title: 'Move up', 'aria-label': `Move "${o.label}" up` }, '↑');
229
+ const down = el('button', { type: 'button', class: 'rank-btn', title: 'Move down', 'aria-label': `Move "${o.label}" down` }, '↓');
230
+ up.disabled = i === 0;
231
+ down.disabled = i === order.length - 1;
232
+ up.addEventListener('click', () => move(i, i - 1));
233
+ down.addEventListener('click', () => move(i, i + 1));
234
+ const item = el('div', { class: 'rank-item', draggable: access.canEditAnswers ? 'true' : 'false' },
235
+ el('span', { class: 'rank-badge', 'aria-hidden': 'true' }, String(i + 1)),
236
+ el('div', { class: 'rank-body' },
237
+ el('div', { class: 'ol' }, o.label),
238
+ o.description ? el('div', { class: 'od' }, o.description) : null),
239
+ el('div', { class: 'rank-ctrls' }, up, down)
240
+ );
241
+ item.addEventListener('dragstart', (e) => {
242
+ if (!access.canEditAnswers) { e.preventDefault(); return; }
243
+ dragFrom = i; item.classList.add('dragging');
244
+ try { e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', String(i)); } catch (_) {}
245
+ });
246
+ item.addEventListener('dragend', () => { dragFrom = null; item.classList.remove('dragging'); });
247
+ item.addEventListener('dragover', (e) => { if (dragFrom !== null) { e.preventDefault(); item.classList.add('drop-into'); } });
248
+ item.addEventListener('dragleave', () => item.classList.remove('drop-into'));
249
+ item.addEventListener('drop', (e) => {
250
+ e.preventDefault();
251
+ const from = dragFrom; dragFrom = null;
252
+ if (from !== null && from !== i) move(from, i);
253
+ });
254
+ wrap.append(item);
255
+ });
256
+ }
257
+ paint();
258
+ return wrap;
259
+ }
260
+
261
+ // Checklist: each option is a row with a segmented status control (Pass/Fail/
262
+ // N/A by default). Answer is a map {optionValue: statusValue} for set rows.
263
+ function controlChecklist(q) {
264
+ const wrap = el('div', { class: 'checklist' });
265
+ const cur = () => (state.answers[q.id] && typeof state.answers[q.id] === 'object' && !Array.isArray(state.answers[q.id])
266
+ ? state.answers[q.id]
267
+ : (state.answers[q.id] = {}));
268
+ for (const o of q.options) {
269
+ const seg = el('div', { class: 'chk-seg' });
270
+ const buttons = [];
271
+ for (const s of q.statuses) {
272
+ const b = el('button', { type: 'button', class: 'chk-status' + (s.tone ? ' tone-' + s.tone : '') }, s.label);
273
+ if (cur()[o.value] === s.value) b.classList.add('sel');
274
+ b.addEventListener('click', () => {
275
+ const m = cur();
276
+ if (m[o.value] === s.value) delete m[o.value];
277
+ else m[o.value] = s.value;
278
+ for (const x of buttons) x.btn.classList.toggle('sel', m[o.value] === x.val);
279
+ clearErr(q.id);
280
+ scheduleSave();
281
+ });
282
+ buttons.push({ btn: b, val: s.value });
283
+ seg.append(b);
284
+ }
285
+ wrap.append(el('div', { class: 'chk-row' },
286
+ el('div', { class: 'chk-body' },
287
+ el('div', { class: 'ol' }, o.label),
288
+ o.description ? el('div', { class: 'od' }, o.description) : null),
289
+ seg
290
+ ));
291
+ }
292
+ return wrap;
293
+ }
294
+
295
+ // Allocate: distribute q.total across the options with per-option sliders; a
296
+ // live total bar shows the running sum / remaining / overage. Answer is a map
297
+ // {optionValue: number}; an all-zero allocation submits as unanswered.
298
+ function controlAllocate(q) {
299
+ const wrap = el('div', { class: 'allocate' });
300
+ const total = q.total || 100;
301
+ const unit = q.unit ? ' ' + q.unit : '';
302
+ const cur = () => (state.answers[q.id] = seedAllocate(q, state.answers[q.id]));
303
+ const sumEl = el('span', { class: 'alloc-sum' });
304
+ const fill = el('div', { class: 'alloc-bar-fill' });
305
+ const nums = [];
306
+ const refresh = () => {
307
+ const m = cur();
308
+ const sum = (q.options || []).reduce((a, o) => a + (Number(m[o.value]) || 0), 0);
309
+ const tail = sum > total ? ` (over by ${sum - total})` : sum < total ? ` (${total - sum} left)` : ' ✓';
310
+ sumEl.textContent = `${sum} / ${total}${unit}${tail}`;
311
+ sumEl.classList.toggle('over', sum > total);
312
+ sumEl.classList.toggle('exact', sum === total);
313
+ fill.style.width = Math.min(100, (sum / total) * 100) + '%';
314
+ fill.classList.toggle('over', sum > total);
315
+ for (const n of nums) n.el.textContent = String(m[n.value] || 0);
316
+ };
317
+ for (const o of q.options) {
318
+ const m = cur();
319
+ const range = el('input', { type: 'range', min: '0', max: String(total), step: '1', class: 'alloc-range', 'aria-label': o.label });
320
+ range.value = String(m[o.value] || 0);
321
+ const num = el('span', { class: 'alloc-num' }, String(m[o.value] || 0));
322
+ range.addEventListener('input', () => {
323
+ cur()[o.value] = Number(range.value) || 0;
324
+ refresh();
325
+ clearErr(q.id);
326
+ scheduleSave();
327
+ });
328
+ nums.push({ value: o.value, el: num });
329
+ wrap.append(el('div', { class: 'alloc-row' },
330
+ el('div', { class: 'alloc-rowhead' },
331
+ el('div', { class: 'ol' }, o.label),
332
+ num),
333
+ range,
334
+ o.description ? el('div', { class: 'od' }, o.description) : null
335
+ ));
336
+ }
337
+ wrap.append(el('div', { class: 'alloc-total' },
338
+ el('div', { class: 'alloc-bar' }, fill),
339
+ el('div', { class: 'alloc-sumwrap' }, 'Total: ', sumEl)
340
+ ));
341
+ refresh();
342
+ return wrap;
343
+ }
344
+
345
+ function controlText(q, multiline) {
346
+ const input = multiline
347
+ ? el('textarea', { placeholder: q.placeholder || '' })
348
+ : el('input', { type: 'text', placeholder: q.placeholder || '' });
349
+ input.value = typeof state.answers[q.id] === 'string' ? state.answers[q.id] : '';
350
+ input.addEventListener('input', () => {
351
+ state.answers[q.id] = input.value;
352
+ clearErr(q.id);
353
+ scheduleSave();
354
+ });
355
+ return input;
356
+ }
357
+
358
+ // Resolve ANY CSS color (named / rgb() / hsl() / hex) to #rrggbb for the
359
+ // native <input type=color>, using the browser's own parser — multi color-
360
+ // system support with no library. Returns null for an unparseable color.
@@ -0,0 +1,135 @@
1
+ // ---------- render ----------
2
+ themeBtn = el('button', { class: 'theme-btn', type: 'button' }, '');
3
+ themeBtn.addEventListener('click', () => {
4
+ theme = THEMES[(THEMES.indexOf(theme) + 1) % THEMES.length];
5
+ localStorage.setItem(THEME_KEY, theme);
6
+ fetch('/api/pref', {
7
+ method: 'POST',
8
+ headers: { 'content-type': 'application/json' },
9
+ body: JSON.stringify({ theme }),
10
+ }).catch(() => {});
11
+ applyTheme();
12
+ });
13
+ applyTheme();
14
+
15
+ const fsDown = el('button', { class: 'fs-btn', type: 'button', title: 'Smaller text', 'aria-label': 'Decrease text size' }, 'A−');
16
+ const fsUp = el('button', { class: 'fs-btn', type: 'button', title: 'Larger text', 'aria-label': 'Increase text size' }, 'A+');
17
+ fsDown.addEventListener('click', () => setFontScale(fontScale - FS_STEP));
18
+ fsUp.addEventListener('click', () => setFontScale(fontScale + FS_STEP));
19
+ const fsCtrl = el('div', { class: 'fs-ctrl' }, fsDown, fsUp);
20
+
21
+ function buildShareControl() {
22
+ if (!access.canShare) return null;
23
+ const wrap = el('span', { class: 'share-wrap' });
24
+ const shareBtn = el('button', { class: 'share-btn icon-btn', type: 'button', title: 'Share board', 'aria-label': 'Share board' });
25
+ shareBtn.innerHTML =
26
+ '<svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">' +
27
+ '<path d="M6.5 9.5 9.5 11.2M9.5 4.8 6.5 6.5"/>' +
28
+ '<circle cx="4.5" cy="8" r="2"/><circle cx="11.5" cy="4" r="2"/><circle cx="11.5" cy="12" r="2"/>' +
29
+ '</svg>';
30
+ shareBtn.addEventListener('click', () => {
31
+ const existing = wrap.querySelector('.share-panel');
32
+ if (existing) existing.remove();
33
+ else openSharePanel(wrap);
34
+ });
35
+ wrap.append(shareBtn);
36
+ return wrap;
37
+ }
38
+
39
+ // Just reloaded after a live `rly update`? Flag set before reload below.
40
+ try {
41
+ if (sessionStorage.getItem('relay-updated') === '1') {
42
+ sessionStorage.removeItem('relay-updated');
43
+ showToast('Board updated by the agent');
44
+ }
45
+ if (sessionStorage.getItem('relay-draft-updated') === '1') {
46
+ sessionStorage.removeItem('relay-draft-updated');
47
+ showToast('Board refreshed with shared changes');
48
+ }
49
+ } catch {
50
+ // sessionStorage may be unavailable (privacy mode) — non-fatal
51
+ }
52
+
53
+ const titleEl = el('h1', {}, spec.title);
54
+ app.append(el('header', { class: 'qb-header' }, titleEl, el('div', { class: 'qb-controls' }, fsCtrl, buildShareControl(), themeBtn)));
55
+ // The board title is commentable too: hovering it shows the pin, like the
56
+ // intro and every other content element. (themeBtn stays out of it.)
57
+ if (spec.title) {
58
+ Annotate?.register(titleEl, { blockId: null, questionId: null, target: { kind: 'html-element', label: spec.title } });
59
+ }
60
+ if (spec.intro) {
61
+ // Render the intro as markdown (bold/italic/code/links/lists) — agents write
62
+ // markdown here by default. Falls back to plain text if blocks.js is absent.
63
+ // The .blk-markdown class scopes the shared markdown typography to it.
64
+ const md = typeof window.RelayBlocks !== 'undefined' && window.RelayBlocks.renderMarkdown;
65
+ const intro = md
66
+ ? el('div', { class: 'intro blk-markdown' }, window.RelayBlocks.renderMarkdown(spec.intro))
67
+ : el('p', { class: 'intro' }, spec.intro);
68
+ app.append(intro);
69
+ Annotate?.enableTextSelection(intro, { blockId: null, questionId: null });
70
+ }
71
+ // Board-level blocks render above the questions (async; never blocks submit).
72
+ renderBlocks(app, spec.blocks || [], null);
73
+
74
+ QS.forEach((q, idx) => {
75
+ const required = q.required || !spec.allowPartial;
76
+ const card = el('div', { class: 'card' },
77
+ el('div', { class: 'qnum' }, `Q${idx + 1}`),
78
+ el('p', { class: 'qlabel' }, q.label, required ? el('span', { class: 'req' }, ' *') : null),
79
+ q.description ? el('p', { class: 'qdesc' }, q.description) : null
80
+ );
81
+ // Per-question blocks render between the description and the control.
82
+ renderBlocks(card, q.blocks || [], q.id);
83
+ const control = el('div', { class: 'control' });
84
+ if (q.type === 'single') control.append(controlSingle(q));
85
+ else if (q.type === 'multi') control.append(controlMulti(q));
86
+ else if (q.type === 'yesno') control.append(segButtons(q, ['yes', 'no'], ['Yes', 'No']));
87
+ else if (q.type === 'scale') control.append(controlScale(q));
88
+ else if (q.type === 'color') control.append(controlColor(q));
89
+ else if (q.type === 'rank') control.append(controlRank(q));
90
+ else if (q.type === 'checklist') control.append(controlChecklist(q));
91
+ else if (q.type === 'allocate') control.append(controlAllocate(q));
92
+ else control.append(controlText(q, q.type === 'textarea'));
93
+ card.append(control);
94
+ if (q.note) {
95
+ const noteInput = el('textarea', { class: 'qnote', rows: 2, placeholder: 'optional note about this answer…' });
96
+ noteInput.value = typeof state.notes[q.id] === 'string' ? state.notes[q.id] : '';
97
+ noteInput.addEventListener('input', () => {
98
+ state.notes[q.id] = noteInput.value;
99
+ scheduleSave();
100
+ });
101
+ card.append(el('div', { class: 'qnotewrap' }, noteInput));
102
+ }
103
+ card.append(el('p', { class: 'errmsg' }, 'This question is required.'));
104
+ cards[q.id] = card;
105
+ app.append(card);
106
+ });
107
+
108
+ if (spec.note && responseRequired) {
109
+ const note = el('textarea', { placeholder: 'optional note back to the agent…' });
110
+ note.value = state.comment || '';
111
+ note.addEventListener('input', () => {
112
+ state.comment = note.value;
113
+ scheduleSave();
114
+ });
115
+ app.append(el('div', { class: 'card' },
116
+ el('p', { class: 'qlabel' }, 'Anything else?'),
117
+ el('p', { class: 'qdesc' }, 'Free-text note returned to the agent along with your answers.'),
118
+ el('div', { class: 'control' }, note)
119
+ ));
120
+ }
121
+
122
+ // Element-level comments live in the Outline-style right rail (created and
123
+ // managed by RelayAnnotate); no inline summary list here anymore.
124
+
125
+ const submitBtn = el('button', { class: 'submit', type: 'button' }, spec.submitLabel);
126
+ saveEl = el('span', { class: 'savestate' }, '');
127
+ const hint = el('span', { class: 'hint' },
128
+ QS.length && spec.allowPartial ? 'Unanswered questions are returned as skipped.' : '');
129
+ const submitbar = el('div', { class: 'submitbar' }, submitBtn, hint, saveEl);
130
+ if (!responseRequired) {
131
+ submitbar.replaceChildren(el('span', { class: 'hint' }, 'Display only · no response requested'));
132
+ submitbar.classList.add('display-only');
133
+ }
134
+ app.append(submitbar);
135
+
@@ -0,0 +1,108 @@
1
+ function copyText(text, btn) {
2
+ const done = () => {
3
+ if (!btn) return;
4
+ const old = btn.textContent;
5
+ btn.textContent = 'Copied';
6
+ setTimeout(() => { btn.textContent = old; }, 1800);
7
+ };
8
+ if (navigator.clipboard && navigator.clipboard.writeText) {
9
+ navigator.clipboard.writeText(text).then(done).catch(() => {});
10
+ return;
11
+ }
12
+ const ta = document.createElement('textarea');
13
+ ta.value = text;
14
+ ta.style.position = 'fixed';
15
+ ta.style.opacity = '0';
16
+ document.body.append(ta);
17
+ ta.select();
18
+ try { document.execCommand('copy'); done(); } catch {}
19
+ ta.remove();
20
+ }
21
+
22
+ function openSharePanel(host) {
23
+ const panel = el('div', { class: 'share-panel' },
24
+ el('div', { class: 'share-title' }, 'Share this board'),
25
+ el('div', { class: 'share-desc' }, 'Choose a permission. The link starts working immediately.'),
26
+ el('button', { class: 'share-choice', type: 'button', 'data-role': 'collab' },
27
+ el('span', { class: 'share-choice-title' }, 'Collaborator'),
28
+ el('span', { class: 'share-choice-sub' }, 'Can edit answers, comment, and submit as owner.')
29
+ ),
30
+ el('button', { class: 'share-choice', type: 'button', 'data-role': 'review' },
31
+ el('span', { class: 'share-choice-title' }, 'Reviewer'),
32
+ el('span', { class: 'share-choice-sub' }, 'Can answer, comment, and submit a reference-only side review. Does not finalize the board.')
33
+ ),
34
+ el('button', { class: 'share-choice', type: 'button', 'data-role': 'read' },
35
+ el('span', { class: 'share-choice-title' }, 'Read only'),
36
+ el('span', { class: 'share-choice-sub' }, 'Can view the board and existing feedback. Cannot answer, comment, edit, or submit.')
37
+ ),
38
+ el('div', { class: 'share-result' })
39
+ );
40
+ const close = () => panel.remove();
41
+ const closeBtn = el('button', { class: 'share-close', type: 'button', 'aria-label': 'Close share panel' }, '×');
42
+ closeBtn.addEventListener('click', close);
43
+ panel.prepend(closeBtn);
44
+ const result = panel.querySelector('.share-result');
45
+ for (const btn of panel.querySelectorAll('.share-choice')) {
46
+ btn.addEventListener('click', async () => {
47
+ const role = btn.getAttribute('data-role');
48
+ btn.disabled = true;
49
+ result.textContent = 'Activating...';
50
+ try {
51
+ const res = await fetch('/api/share', {
52
+ method: 'POST',
53
+ headers: { 'content-type': 'application/json' },
54
+ body: JSON.stringify({ role }),
55
+ });
56
+ const body = await res.json().catch(() => null);
57
+ if (!res.ok || !body || !body.url) throw new Error(body && body.error ? body.error : 'share failed');
58
+ const copy = el('button', { class: 'share-copy', type: 'button' }, 'Copy link');
59
+ copy.addEventListener('click', () => copyText(body.url, copy));
60
+ result.replaceChildren(
61
+ el('div', { class: 'share-ready' }, role === 'collab' ? 'Collaborator link active' : role === 'review' ? 'Reviewer link active' : 'Read-only link active'),
62
+ el('a', { class: 'share-url', href: body.url, target: '_blank', rel: 'noreferrer' }, body.url),
63
+ copy
64
+ );
65
+ } catch (err) {
66
+ result.textContent = err && err.message ? err.message : 'Could not activate sharing.';
67
+ } finally {
68
+ btn.disabled = false;
69
+ }
70
+ });
71
+ }
72
+ host.append(panel);
73
+ }
74
+
75
+ function buildFooter() {
76
+ const footer = el('footer', { class: 'qb-footer' }, el('span', {}, `relay · ${boot.boardId}`));
77
+ return footer;
78
+ }
79
+
80
+ function applyAccessRestrictions() {
81
+ if (!access.canSubmit) submitbar.style.display = 'none';
82
+ if (!access.canEditAnswers) {
83
+ for (const node of app.querySelectorAll('.card input, .card textarea, .card button, .card select')) {
84
+ // Viewer controls inside question/option blocks remain useful in a
85
+ // read-only board (zoom, fit, full-screen, filtering, diff view). Block
86
+ // mutation controls are independently gated by canEditBlocks.
87
+ if (node.closest('.blocks')) continue;
88
+ node.disabled = true;
89
+ }
90
+ for (const item of app.querySelectorAll('.rank-item')) {
91
+ item.draggable = false;
92
+ item.setAttribute('aria-disabled', 'true');
93
+ }
94
+ }
95
+ document.documentElement.classList.toggle('relay-review', access.canEditComments === false || access.canDeleteComments === false);
96
+ }
97
+ if (access.role === 'review') {
98
+ submitBtn.textContent = 'Submit side review';
99
+ hint.textContent = 'Reference only — the owner still submits the final answer.';
100
+ showNotice('Reviewer mode: your answers and comments are saved separately as a reference-only side review. Submitting here does not finalize the board or notify the waiting agent.', 'info');
101
+ } else if (access.role === 'read') {
102
+ showNotice('Read-only mode: you can view the board and existing feedback, but answers, comments, edits, and submission are disabled.', 'info');
103
+ } else if (access.role === 'collab') {
104
+ showNotice('Editor mode: answers, comments, and final submission are enabled for this shared board.', 'info');
105
+ }
106
+ applyAccessRestrictions();
107
+ app.append(buildFooter());
108
+