create-pmos 0.388.0 → 0.390.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 (44) hide show
  1. package/package.json +25 -30
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/briefing-premium-insights-test.js +22 -27
  8. package/workspace/changelog.json +24 -0
  9. package/workspace/guide/briefing-premium.md +38 -19
  10. package/workspace/lib/briefing-premium-agent.js +3 -0
  11. package/workspace/lib/insights-premium.js +10 -8
  12. package/workspace/lib/report-chat.js +37 -0
  13. package/workspace/lib/routes-insights-premium.js +3 -1
  14. package/workspace/package-lock.json +2 -2
  15. package/workspace/package.json +1 -1
  16. package/workspace/premium-chat-chart-tab-test.js +150 -0
  17. package/workspace/premium-chat-report-tab-test.js +127 -0
  18. package/workspace/premium-report-read-test.js +99 -59
  19. package/workspace/premium-vw-slides-test.js +17 -19
  20. package/workspace/public/pm/goal-chat.js +2 -1
  21. package/workspace/public/pm/premium-chart-draw.js +58 -0
  22. package/workspace/public/pm/premium-chart-tab.js +157 -0
  23. package/workspace/public/pm/premium-chat.js +8 -2
  24. package/workspace/public/pm/premium-insights.js +39 -85
  25. package/workspace/public/pm/premium-report-brief.js +132 -0
  26. package/workspace/public/pm/premium-report-read.js +276 -103
  27. package/workspace/public/pm/premium-report-tab.js +235 -0
  28. package/workspace/public/pm/premium-shell.js +35 -3
  29. package/workspace/public/pm/premium-vw-doc.js +9 -1
  30. package/workspace/public/pm/premium-vw-report.css +60 -0
  31. package/workspace/public/pm/premium-vw-slides.js +14 -5
  32. package/workspace/public/pm/premium.css +71 -122
  33. package/workspace/public/pm/report-chat.js +89 -0
  34. package/workspace/test-lists/premium-chat-chart-tab.json +12 -0
  35. package/workspace/test-lists/premium-chat-report-tab.json +12 -0
  36. package/workspace/premium-studio-chart-test.js +0 -193
  37. package/workspace/premium-studio-report-test.js +0 -277
  38. package/workspace/premium-studio-test.js +0 -185
  39. package/workspace/public/pm/premium-studio-design.js +0 -298
  40. package/workspace/public/pm/premium-studio-report.js +0 -291
  41. package/workspace/public/pm/premium-studio.js +0 -453
  42. package/workspace/test-lists/premium-studio-chart.json +0 -13
  43. package/workspace/test-lists/premium-studio-report.json +0 -9
  44. package/workspace/test-lists/premium-studio.json +0 -9
@@ -0,0 +1,235 @@
1
+ /* pm/premium-report-tab.js — the Report tab beside a chat (initiative premium-reports-from-chat, slice B; PRD R1–R4). It replaces the Insight Studio's
2
+ * Report mode: the PM asks in the chat, Claude ends its answer with a `pmos-report` block (public/pm/report-chat.js), and this tab shows it.
3
+ *
4
+ * A NEW REPORT (block.proposal): its name, what it answers, audience, format, the seven sections every new report has, and the Schedule chip.
5
+ * Set it up posts POST /api/report-setups/setup. A report with Schedule Off (none said) is then paused at once with POST /api/report-setups/edit,
6
+ * so it runs once (PM, 2026-10-21).
7
+ * A SET-UP REPORT (block.id): the Schedule chip (POST .../edit), Structure | Design with their versions, the cycles (drafts and issued reports) and
8
+ * Delete template (POST .../remove). A change Claude proposes in words (block.structure, block.design, block.schedule) shows as one press.
9
+ * Structure: GET /api/report-structure; turn, accept (Use this) and revert (Undo). Design: GET /api/report-design and its version renders;
10
+ * turn, accept (This is it) and revert. A draft is discarded (POST /api/report-documents/discard); an issued report is kept for good and can
11
+ * only be archived (POST /api/report-documents/archive). Share on a row opens the viewer's share popover (premium-vw-share.js) for that file.
12
+ *
13
+ * Every write is a press here, behind the launch nonce (http.js pmPost). Claude writes nothing: the routes refuse an agent session. A render is
14
+ * HTML the server sanitized, shown in a frame with an empty sandbox, so nothing in it runs. Nothing is sent outward. */
15
+ import { pmGet, pmPost } from './http.js';
16
+ import { vwOpen, vwStyle, vwConfirm } from './premium-viewer.js';
17
+
18
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
19
+ const OUT = { 'google-slides': 'Google Slides', 'google-doc': 'Google Doc', 'google-sheets': 'Google Sheets', confluence: 'Confluence page', pdf: 'PDF' };
20
+ const FRAME = [['Headline', 'The one thing the readers must know this cycle.'], ['Timeline', 'The dated items, written in full.'], ['Initiatives', 'Done, in progress, next and the key open item.'],
21
+ ['New since last report', 'What is new in the window, each with its date.'], ['Decided this cycle', 'The decisions, marked Decided or Acknowledged.'], ['Needs your call', 'The asks to the readers: what, who, by when.'], ['Sources', 'The sources reached and not reached.']];
22
+ const DAYN = { Mon: 'Mondays', Tue: 'Tuesdays', Wed: 'Wednesdays', Thu: 'Thursdays', Fri: 'Fridays', Sat: 'Saturdays', Sun: 'Sundays' };
23
+ const POLL_MS = 1200, POLL_MAX = 240000;
24
+ const ws = () => new URLSearchParams(location.search).get('ws') || '';
25
+ const qs = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
26
+ const post = (p, body) => pmPost(p, Object.assign(ws() ? { ws: ws() } : {}, body)).catch(() => null);
27
+ const get = (p, o) => pmGet(p + '?' + qs(Object.assign({ ws: ws() }, o))).catch(() => null);
28
+
29
+ /** The schedule in words: 'off' or null is Off. */
30
+ export function schedWords(s) {
31
+ if (!s || s === 'off') return 'Off · runs once';
32
+ const t = s.time || '09:00';
33
+ if (s.cadence === 'daily') return 'Daily at ' + t;
34
+ if (s.cadence === 'monthly') return 'Monthly on day ' + (s.dayOfMonth || 1) + ' at ' + t;
35
+ return (s.cadence === 'weekly' ? 'Weekly, ' : 'Every two weeks, ') + (DAYN[s.day] || 'Mondays') + ' at ' + t;
36
+ }
37
+ const sameSched = (a, b) => schedWords(a) === schedWords(b);
38
+ /** The choices of the Schedule chip, the current day kept for weekly ones. */
39
+ export function schedChoices(cur) {
40
+ const day = cur && cur !== 'off' && cur.day ? cur.day : 'Mon';
41
+ return ['off', { cadence: 'daily', time: '09:00' }, { cadence: 'weekly', day, time: '09:00' }, { cadence: 'bi-weekly', day, time: '09:00' }, { cadence: 'monthly', dayOfMonth: 1, time: '09:00' }];
42
+ }
43
+
44
+ const T = new Map(); // tab id → its state
45
+ /** Open (or refresh) the Report tab for a checked block (report-chat.js cleanBlock). */
46
+ export function openReportTab(block) {
47
+ if (!block) return null;
48
+ vwStyle('report');
49
+ const id = 'report:' + (block.id || block.proposal.name).toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 60);
50
+ let t = T.get(id);
51
+ if (!t || JSON.stringify(t.block) !== JSON.stringify(block)) {
52
+ t = { id, block, sched: block.proposal ? (block.proposal.schedule || 'off') : null, open: false, view: 'structure', busy: false, msg: '', setup: null, docs: [], S: null, Z: null, sv: null, dv: null, render: new Map(), gone: false, loaded: false };
53
+ T.set(id, t);
54
+ if (block.id) load(t);
55
+ }
56
+ return vwOpen({ id, title: 'Report', icon: 'doc', render: (el) => draw(t, el), wire: (el) => { el.onclick = (e) => press(t, e); } });
57
+ }
58
+ const paneOf = (t) => document.querySelector(`#dOut .obody.vw[data-vw="${CSS.escape(t.id)}"]`);
59
+ const redraw = (t) => { const el = paneOf(t); if (el) draw(t, el); };
60
+
61
+ async function load(t) {
62
+ const rid = t.block.id;
63
+ const [L, D, S] = await Promise.all([get('/api/report-setups'), get('/api/report-documents'), get('/api/report-structure', { id: rid })]);
64
+ t.setup = L && Array.isArray(L.setups) ? L.setups.find((s) => s.id === rid) || null : null;
65
+ t.gone = !!L && !t.setup;
66
+ t.docs = D && Array.isArray(D.docs) ? D.docs.filter((d) => d.id.startsWith(rid + '/')).sort((a, b) => (a.slot < b.slot ? 1 : -1)) : [];
67
+ if (S && S.ok) { t.S = S.structure; if (t.sv == null) t.sv = t.S.current; }
68
+ t.loaded = true;
69
+ if (t.view === 'design') await loadDesign(t);
70
+ redraw(t);
71
+ if (t.S && t.S.running) poll(t, 'structure');
72
+ }
73
+ async function loadDesign(t) {
74
+ const r = await get('/api/report-design', { id: t.block.id });
75
+ if (!r || !r.ok) { t.Z = { err: (r && r.error) || 'The design of this report could not be read.' }; return; }
76
+ t.Z = r.design;
77
+ if (t.dv == null) t.dv = t.Z.current != null ? t.Z.current : (t.Z.saved ? t.Z.saved.version : null);
78
+ await renderOf(t, t.dv);
79
+ if (t.Z.running) poll(t, 'design');
80
+ }
81
+ async function renderOf(t, n) {
82
+ if (n == null || t.render.has(n)) return;
83
+ try { const r = await fetch('/api/report-design/version?' + qs({ ws: ws(), id: t.block.id, n }), { credentials: 'same-origin' }); if (r.ok) t.render.set(n, await r.text()); } catch { /* shown as unread */ }
84
+ }
85
+ /* One structure or design job runs at a time; wait for it, then show its newest version. */
86
+ async function poll(t, kind) {
87
+ const end = Date.now() + POLL_MAX;
88
+ while (Date.now() < end && paneOf(t)) {
89
+ await new Promise((ok) => setTimeout(ok, POLL_MS));
90
+ if (kind === 'structure') {
91
+ const S = await get('/api/report-structure', { id: t.block.id });
92
+ if (S && S.ok && !S.structure.running) { t.S = S.structure; t.sv = t.S.current; t.busy = false; t.msg = lastSaid(t.S.log); redraw(t); return; }
93
+ } else {
94
+ const r = await get('/api/report-design', { id: t.block.id });
95
+ if (r && r.ok && !r.design.running) { t.Z = r.design; t.dv = t.Z.current; await renderOf(t, t.dv); t.busy = false; t.msg = lastSaid(t.Z.log); redraw(t); return; }
96
+ }
97
+ }
98
+ t.busy = false; t.msg = 'PMOS has not answered yet. The new version shows when you open this report again.'; redraw(t);
99
+ }
100
+ const lastSaid = (log) => { const l = (log || []).filter((x) => x.who === 'pmos').pop(); return l ? l.text : ''; };
101
+
102
+ /* ── drawing ── */
103
+ const btn = (a, label, o = {}) => `<button type="button" class="btn${o.sec ? ' sec' : ''}${o.cls ? ' ' + o.cls : ''}" data-rt="${esc(a)}"${o.off ? ' disabled' : ''}${o.pressed != null ? ` aria-pressed="${o.pressed}"` : ''}>${esc(label)}</button>`;
104
+ function schedHtml(t, cur) {
105
+ const chip = `<button type="button" class="rt-chip" data-rt="sched" aria-expanded="${t.open}"><em>Schedule</em><b>${esc(schedWords(cur))}</b></button>`;
106
+ if (!t.open) return chip;
107
+ const opts = schedChoices(cur).map((s, i) => `<button type="button" role="menuitemradio" aria-checked="${sameSched(s, cur)}" data-rt="pick|${i}">${esc(schedWords(s))}</button>`).join('');
108
+ const days = cur && cur !== 'off' && (cur.cadence === 'weekly' || cur.cadence === 'bi-weekly')
109
+ ? `<div class="rt-days" role="group" aria-label="Day">${Object.keys(DAYN).slice(0, 5).map((d) => btn('day|' + d, d, { sec: cur.day !== d, pressed: cur.day === d })).join('')}</div>` : '';
110
+ return chip + `<div class="rt-menu" role="menu" aria-label="Schedule">${opts}${days}<p class="rt-note">Or say it in the chat: “make it every two weeks”.</p></div>`;
111
+ }
112
+ const sectionsHtml = (L) => `<ol class="rt-secs">${L.map(([h, d]) => `<li><b>${esc(h)}</b>${d ? `<span>${esc(d)}</span>` : ''}</li>`).join('')}</ol>`;
113
+
114
+ function draw(t, el) {
115
+ const ask = el.querySelector(':scope > .vcf'); // an open confirm card outlives a redraw (a poll or a load), so its answer still lands
116
+ el.innerHTML = `<div class="rt">${t.block.proposal ? newHtml(t) : setupHtml(t)}${t.msg ? `<p class="rt-msg" role="status">${esc(t.msg)}</p>` : ''}</div>`;
117
+ if (ask) el.prepend(ask);
118
+ el.querySelectorAll('iframe[data-rt-frame]').forEach((f) => { f.srcdoc = t.render.get(+f.dataset.rtFrame) || ''; });
119
+ }
120
+ function newHtml(t) {
121
+ const p = t.block.proposal;
122
+ return `<p class="rt-eye">New report · from this chat</p><h3 class="rt-h">${esc(p.name)}</h3>${p.purpose ? `<p class="rt-sub">${esc(p.purpose)}</p>` : ''}`
123
+ + `<p class="rt-meta">For ${esc(p.audience)} · ${esc(OUT[p.output] || p.output)}</p><div class="rt-row">${schedHtml(t, t.sched)}</div>`
124
+ + `<p class="rt-label">Sections</p>${sectionsHtml(FRAME)}<p class="rt-note">Every new report has these sections. Once it is set up, ask in the chat to shape them.</p>`
125
+ + `<div class="rt-foot">${btn('setup', t.busy ? 'Setting it up' : 'Set it up', { off: t.busy })}</div>`;
126
+ }
127
+ function setupHtml(t) {
128
+ const s = t.setup;
129
+ if (!t.loaded) return '<p class="rt-note" role="status">Reading the report.</p>';
130
+ if (t.gone) return `<p class="rt-eye">Report</p><h3 class="rt-h">${esc(t.block.id)}</h3><p class="rt-note">This template is deleted, or it is not set up in this workspace. Its issued reports are kept.</p>${cyclesHtml(t)}`;
131
+ const cur = s.status === 'paused' ? 'off' : s.schedule;
132
+ const want = t.block.schedule && !sameSched(t.block.schedule, cur) ? `<div class="rt-ask"><p>Claude proposes: <b>${esc(schedWords(t.block.schedule))}</b></p>${btn('sched-use', 'Change the schedule', { off: t.busy })}</div>` : '';
133
+ return `<p class="rt-eye">Report template</p><h3 class="rt-h">${esc(s.name)}</h3><p class="rt-meta">For ${esc(s.audience || 'no one named')} · ${esc(OUT[s.output] || s.output)}${s.next_draft ? ' · next draft ' + esc(s.next_draft.slice(0, 10)) : ''}</p>`
134
+ + `<div class="rt-row">${schedHtml(t, cur)}</div>${want}`
135
+ + `<div class="rt-seg" role="group" aria-label="Step">${btn('view|structure', 'Structure', { sec: t.view !== 'structure', pressed: t.view === 'structure' })}${btn('view|design', 'Design', { sec: t.view !== 'design', pressed: t.view === 'design' })}</div>`
136
+ + (t.view === 'design' ? designHtml(t) : structureHtml(t)) + cyclesHtml(t)
137
+ + `<div class="rt-foot rt-end">${btn('remove', 'Delete template', { sec: true, cls: 'rt-del', off: t.busy })}</div>`;
138
+ }
139
+ function stepper(kind, n, list, saved) {
140
+ if (n == null || !list.length) return '';
141
+ const i = list.findIndex((v) => v.n === n);
142
+ return `<div class="rt-ver"><button type="button" class="rt-arrow" data-rt="${kind}|${list[i - 1] ? list[i - 1].n : n}" aria-label="Earlier version"${i <= 0 ? ' disabled' : ''}>‹</button>`
143
+ + `<span>${kind === 'sv' ? 'S' : 'D'}${n}${n === saved ? ' · saved' : ' · not saved'}</span><button type="button" class="rt-arrow" data-rt="${kind}|${list[i + 1] ? list[i + 1].n : n}" aria-label="Later version"${i >= list.length - 1 ? ' disabled' : ''}>›</button></div>`;
144
+ }
145
+ function structureHtml(t) {
146
+ const S = t.S, V = (S && S.versions) || [];
147
+ const plan = S && S.plan, shown = t.sv;
148
+ const L = plan && plan.outline ? plan.outline.map((x) => [x.title, x.notes || '']) : FRAME;
149
+ const ask = t.block.structure && !(S && S.running) ? `<div class="rt-ask"><p>Your change: <b>“${esc(t.block.structure)}”</b></p>${btn('s-turn', 'Make the next version', { off: t.busy })}</div>` : '';
150
+ const working = S && S.running ? '<p class="rt-note" role="status">PMOS is making the next version.</p>' : '';
151
+ const save = shown != null && S && shown !== S.saved ? btn('s-accept', 'Use this', { off: t.busy }) : '';
152
+ const undo = V.some((v) => v.n < (S ? S.current : 0)) ? btn('s-undo', 'Undo', { sec: true, off: t.busy }) : '';
153
+ return `${stepper('sv', shown, V, S && S.saved)}${ask}${working}${sectionsHtml(L)}${!V.length ? '<p class="rt-note">No structure version yet: each cycle uses these sections. Say in the chat how to shape them.</p>' : ''}${save || undo ? `<div class="rt-foot">${undo}${save}</div>` : ''}`;
154
+ }
155
+ function designHtml(t) {
156
+ const Z = t.Z;
157
+ if (!Z) return '<p class="rt-note" role="status">Reading the design.</p>';
158
+ if (Z.err) return `<p class="rt-note">${esc(Z.err)}</p>`;
159
+ const V = Z.versions || [], saved = Z.saved ? Z.saved.version : null;
160
+ const ask = t.block.design && !Z.running ? `<div class="rt-ask"><p>Your change: <b>“${esc(t.block.design)}”</b></p>${btn('d-turn', 'Make the next version', { off: t.busy })}</div>` : '';
161
+ const working = Z.running ? '<p class="rt-note" role="status">PMOS is making the next version.</p>' : '';
162
+ const frame = t.dv != null ? (t.render.has(t.dv) ? `<iframe class="rt-frame" sandbox="" title="Design version D${t.dv}" data-rt-frame="${t.dv}"></iframe>` : '<p class="rt-note">This version could not be read.</p>')
163
+ : '<p class="rt-note">No design version yet. Say in the chat how it should look, or attach a sample. Each cycle uses the standard look until then.</p>';
164
+ const save = t.dv != null && t.dv !== saved ? btn('d-accept', 'This is it', { off: t.busy }) : '';
165
+ const undo = V.some((v) => v.n < (Z.current || 0)) ? btn('d-undo', 'Undo', { sec: true, off: t.busy }) : '';
166
+ return `${stepper('dv', t.dv, V, saved)}${ask}${working}${frame}${save || undo ? `<div class="rt-foot">${undo}${save}</div>` : ''}`;
167
+ }
168
+ function cyclesHtml(t) {
169
+ if (!t.docs.length) return '';
170
+ const row = (d) => `<li><span class="rt-tag ${d.state}">${d.state === 'issued' ? 'Issued' : 'Draft'}</span><span class="rt-slot">${esc(d.slot)}${d.archived ? ' · archived' : ''}</span>`
171
+ + `<button type="button" class="btn sec" data-rt="share|${esc(d.path)}" data-fsh aria-haspopup="dialog" aria-expanded="false">Share</button>`
172
+ + (d.state === 'issued' ? btn((d.archived ? 'unarchive|' : 'archive|') + d.path, d.archived ? 'Bring back' : 'Archive', { sec: true, off: t.busy }) : btn('discard|' + d.path, 'Discard', { sec: true, off: t.busy })) + '</li>';
173
+ return `<p class="rt-label">Reports</p><ul class="rt-cyc">${t.docs.map(row).join('')}</ul><p class="rt-note">An issued report is kept for good. A draft can be discarded until it is issued.</p>`;
174
+ }
175
+
176
+ /* ── pressing ── */
177
+ async function act(t, fn) { t.busy = true; t.msg = ''; redraw(t); const m = await fn(); t.busy = false; if (m != null) t.msg = m; redraw(t); }
178
+ const why = (r, d) => (r && r.error) || d;
179
+ async function setSchedule(t, s) {
180
+ if (t.block.proposal) { t.sched = s; t.open = false; redraw(t); return; }
181
+ t.open = false;
182
+ await act(t, async () => {
183
+ const r = await post('/api/report-setups/edit', { id: t.block.id, schedule: s === 'off' ? { cadence: 'off' } : s });
184
+ if (!r || !r.ok) return 'The schedule did not change: ' + why(r, 'the page could not reach PMOS') + '.';
185
+ t.setup = r.setup; return 'Schedule: ' + schedWords(r.setup.status === 'paused' ? 'off' : r.setup.schedule) + '.';
186
+ });
187
+ }
188
+ async function press(t, e) {
189
+ const b = e.target.closest('[data-rt]'); if (!b || b.disabled) return;
190
+ const [a, v] = [b.dataset.rt.split('|')[0], b.dataset.rt.slice(b.dataset.rt.indexOf('|') + 1)];
191
+ const cur = t.block.proposal ? t.sched : t.setup && (t.setup.status === 'paused' ? 'off' : t.setup.schedule);
192
+ if (a === 'sched') { t.open = !t.open; redraw(t); return; }
193
+ if (a === 'pick') { await setSchedule(t, schedChoices(cur)[+v]); return; }
194
+ if (a === 'day') { await setSchedule(t, Object.assign({}, cur, { day: v })); return; }
195
+ if (a === 'sched-use') { await setSchedule(t, t.block.schedule); return; }
196
+ if (a === 'view') { t.view = v; redraw(t); if (v === 'design' && !t.Z) { await loadDesign(t); redraw(t); } return; }
197
+ if (a === 'sv') { t.sv = +v; redraw(t); return; }
198
+ if (a === 'dv') { t.dv = +v; await renderOf(t, t.dv); redraw(t); return; }
199
+ if (a === 'setup') { await setUp(t); return; }
200
+ const id = t.block.id;
201
+ if (a === 's-turn') { t.busy = true; t.msg = ''; redraw(t); const r = await post('/api/report-structure/turn', { id, text: t.block.structure }); if (!r || !r.ok) { t.busy = false; t.msg = 'That did not start: ' + why(r, 'no answer') + '.'; redraw(t); return; } t.S = Object.assign({}, t.S, { running: true }); t.block = Object.assign({}, t.block, { structure: undefined }); redraw(t); poll(t, 'structure'); return; }
202
+ if (a === 'd-turn') { t.busy = true; t.msg = ''; redraw(t); const r = await post('/api/report-design/turn', { id, text: t.block.design, points: [] }); if (!r || !r.ok) { t.busy = false; t.msg = 'That did not start: ' + why(r, 'no answer') + '.'; redraw(t); return; } t.Z = Object.assign({}, t.Z, { running: true }); t.block = Object.assign({}, t.block, { design: undefined }); redraw(t); poll(t, 'design'); return; }
203
+ if (a === 's-accept') { await act(t, async () => { const r = await post('/api/report-structure/accept', { id, n: t.sv }); if (!r || !r.ok) return why(r, 'The structure was not saved.'); t.S = r.structure; return 'S' + t.sv + ' is saved. The next cycle follows it.'; }); return; }
204
+ if (a === 's-undo') { const V = t.S.versions.filter((x) => x.n < t.S.current); const to = V[V.length - 1].n; await act(t, async () => { const r = await post('/api/report-structure/revert', { id, n: to }); if (!r || !r.ok) return why(r, 'Undo did not go through.'); t.S = r.structure; t.sv = t.S.current; return 'Back to S' + to + '.'; }); return; }
205
+ if (a === 'd-accept') { await act(t, async () => { const r = await post('/api/report-design/accept', { id, n: t.dv }); if (!r || !r.ok) return why(r, 'The design was not saved.'); t.Z = r.design; return 'D' + t.dv + ' is the saved design. The next cycle follows it.'; }); return; }
206
+ if (a === 'd-undo') { const V = t.Z.versions.filter((x) => x.n < t.Z.current); const to = V[V.length - 1].n; await act(t, async () => { const r = await post('/api/report-design/revert', { id, n: to }); if (!r || !r.ok) return why(r, 'Undo did not go through.'); t.Z = r.design; t.dv = t.Z.current; await renderOf(t, t.dv); return 'Back to D' + to + '.'; }); return; }
207
+ if (a === 'share') { vwStyle('doc'); const d = t.docs.find((x) => x.path === v); import('./premium-vw-share.js').then((M) => M.shareMenu(b, { name: (d && d.name ? d.name + ' · ' + d.slot : v.split('/').pop()), ws: ws(), rel: v, text: '' })); return; }
208
+ if (a === 'discard' || a === 'archive' || a === 'unarchive') {
209
+ if (a === 'discard' && !(await vwConfirm(paneOf(t), { text: 'Discard this draft? It is deleted. Issued reports are not touched.', yes: 'Discard', no: 'Keep it' }))) return;
210
+ await act(t, async () => {
211
+ const r = await post('/api/report-documents/' + (a === 'discard' ? 'discard' : 'archive'), a === 'discard' ? { path: v } : { path: v, archived: a === 'archive' });
212
+ if (!r || !r.ok) return why(r, 'That did not go through.');
213
+ await load(t); return a === 'discard' ? 'The draft is discarded.' : a === 'archive' ? 'Archived. It is kept, and hidden from the list.' : 'It is back in the list.';
214
+ });
215
+ return;
216
+ }
217
+ if (a === 'remove') {
218
+ if (!(await vwConfirm(paneOf(t), { text: 'Delete this template? Its schedule stops now. Its issued reports and its open draft stay.', yes: 'Delete template', no: 'Keep it' }))) return;
219
+ await act(t, async () => { const r = await post('/api/report-setups/remove', { id }); if (!r || !r.ok) return why(r, 'The template was not deleted.'); await load(t); return 'Template deleted. Its schedule stopped; its reports are kept.'; });
220
+ }
221
+ }
222
+ async function setUp(t) {
223
+ const p = t.block.proposal;
224
+ const schedule = t.sched === 'off' ? { cadence: 'weekly', day: 'Mon', time: '09:00' } : t.sched;
225
+ await act(t, async () => {
226
+ const r = await post('/api/report-setups/setup', { proposal: { name: p.name, purpose: p.purpose || p.name, audience: p.audience, source: 'work', output: p.output, schedule,
227
+ sources: p.sources.length ? p.sources : ['The records of this workspace'], learned_from: 'Set up from a chat.' } });
228
+ if (!r || !r.ok) return 'It was not set up: ' + why(r, 'the page could not reach PMOS') + '.';
229
+ if (t.sched === 'off') await post('/api/report-setups/edit', { id: r.setup.id, schedule: { cadence: 'off' } });
230
+ // the tab now shows the set-up report
231
+ t.block = { kind: 'report', id: r.setup.id }; t.loaded = false; await load(t);
232
+ const d = r.drafted || {};
233
+ return 'Set up. ' + (d.path ? 'The first draft is written.' : 'The first draft was not written' + (d.error ? ': ' + d.error : '') + '.') + (t.sched === 'off' ? ' Schedule is Off, so it runs once.' : '');
234
+ });
235
+ }
@@ -9,6 +9,11 @@ import { chipActs, openLive, openFocus, mountRecord, HL_LINE } from './premium-v
9
9
  import { lineItems, behindOf, whenRead } from './freshness-words.js';
10
10
  import { splitGoal, shownUser, goalBlockHtml, goalProgressHtml, goalChipHtml, goalViewHtml, goalNow, slashMatches } from './goal-chat.js';
11
11
  import { mdHtml, userHtml, toolLine, webKind } from './chat-md.js';
12
+ import { splitReport, reportChipHtml, blockSig } from './report-chat.js';
13
+ import { openReportTab } from './premium-report-tab.js';
14
+ import { openChartTab } from './premium-chart-tab.js';
15
+ /** A pmos-report block opens the Report tab, or the Chart tab for a chart or a dashboard (premium-reports-from-chat, slice C). */
16
+ export const openBlockTab = (b) => (b && b.kind === 'report' ? openReportTab(b) : openChartTab(b));
12
17
  import { mountNotes, openNotes, flushNotes, syncNotes } from './premium-notes.js';
13
18
  import { attachMarkup, attachRowMarkup, mountAttach, attachNames, clearAttach, syncAttach, dropFiles, splitFiles, filesHtml, openAttachment } from './premium-attach.js';
14
19
  import { railModel, railHtml, teaser, menuCount, loudestRow, factsOf, titleOf, endAsks, DOT, WORD } from './session-rail.js';
@@ -428,9 +433,9 @@ export function sessionHtml(c, goal = null) {
428
433
  const out = msgs.map((m, i) => {
429
434
  if (m.role === 'user') return turnUser(shownUser(m.text));
430
435
  if (m.role !== 'assistant') return `<p class="toolline" title="${esc((m.calls || []).map((x) => x.tool + (x.target ? ' ' + x.target : '')).join('\n'))}">${esc(toolLine(m.tools))}</p>`;
431
- const g = splitGoal(m.text);
436
+ const g = splitGoal(m.text), rp = splitReport(g.text); // premium-reports-from-chat: a pmos-report block becomes a chip that opens the Report tab
432
437
  const live = i === last && waiting && !!goal && goal.state === 'grilling';
433
- return turnAgent(`<p class="agtag">Claude</p>${g.text ? mdHtml(g.text) : ''}${goalBlockHtml(g.block, { live, state: goal && goal.state })}${chipsHtml(ctx.get(i))}`);
438
+ return turnAgent(`<p class="agtag">Claude</p>${rp.text ? mdHtml(rp.text) : ''}${goalBlockHtml(g.block, { live, state: goal && goal.state })}${reportChipHtml(rp.block, i)}${chipsHtml(ctx.get(i))}`);
434
439
  });
435
440
  if (goalProgressHtml(goal)) out.push(goalChipHtml(goal)); // the goal itself is in the viewer's Goal tab (goalView below)
436
441
  // item-chat-history: an ended session keeps its conversation on the item; the next message picks it up
@@ -478,6 +483,7 @@ export function drawThread(th, key, conv) {
478
483
  ctxAuto(key, conv);
479
484
  S.goal = th.goal || null; S.draft = readyDraft(conv); S.session = th.session || null;
480
485
  goalView(key, conv);
486
+ reportAuto(key, conv);
481
487
  const go = $('#askGo'); if (go) go.disabled = !!th.working; // an earlier read-only run still answering
482
488
  const n = $('#askNote'); if (n) n.textContent = th.working ? 'The agent is answering. You can write again when it has.' : conv && conv.ask ? 'Claude is waiting for your answer above.' : CHAT_NOTE;
483
489
  if (atEnd) b.scrollTop = b.scrollHeight;
@@ -518,7 +524,7 @@ function ctxPeek(it) {
518
524
  const f = $('#askF'); if (!f) return;
519
525
  if (!b) { f.insertAdjacentHTML('beforebegin', '<button type="button" class="ctxpeek" id="ctxPeek" hidden></button>'); b = $('#ctxPeek'); }
520
526
  b.innerHTML = `<span>${esc(it.sub)} · <b>${esc(it.title)}</b></span><em>View</em>`; b.hidden = false;
521
- b.onclick = () => { ctxPeek(null); if (it.kind === 'goal') openGoal(); else openCtx(it, ctxWhere()); };
527
+ b.onclick = () => { ctxPeek(null); if (it.kind === 'goal') openGoal(); else if (it.kind === 'report') openBlockTab(it.block); else openCtx(it, ctxWhere()); };
522
528
  CTX.peekTimer = setTimeout(() => ctxPeek(null), 15000);
523
529
  }
524
530
  $('#dBody').addEventListener('click', (e) => {
@@ -552,6 +558,32 @@ $('#dBody').addEventListener('click', (e) => {
552
558
  e.preventDefault(); openGoal();
553
559
  if (innerWidth < 1000 && !chatPage()) setTab('out');
554
560
  });
561
+ /* premium-reports-from-chat (R1): the newest pmos-report block in a finished answer opens the Report tab by itself, once, on a desktop, and is
562
+ * offered in the bar over the box on a phone. A block that was already there when the chat opened opens nothing; its chip opens it. */
563
+ const RV = { key: null, sig: null };
564
+ function newestReport(conv) {
565
+ const ms = (conv && conv.messages) || [];
566
+ for (let i = ms.length - 1; i >= 0; i--) { if (ms[i].role !== 'assistant') continue; const b = splitReport(splitGoal(ms[i].text).text).block; if (b) return b; }
567
+ return null;
568
+ }
569
+ function reportAuto(key, conv) {
570
+ const busy = !conv || conv.ask || conv.turn === 'agent' || conv.turn === 'tool';
571
+ if (busy && RV.key === key) return;
572
+ const b = newestReport(conv), sig = blockSig(b);
573
+ const first = RV.key !== key; RV.key = key;
574
+ const was = RV.sig; RV.sig = sig;
575
+ if (first || !b || sig === was) return;
576
+ const P = b.proposal, name = P ? (b.kind === 'chart' ? P.title || P.measure : P.name) : b.id;
577
+ if (desk()) openBlockTab(b); else ctxPeek({ kind: 'report', block: b, title: name, sub: b.kind === 'report' ? 'Report' : b.kind === 'chart' ? 'Chart' : 'Dashboard' });
578
+ }
579
+ $('#dBody').addEventListener('click', (e) => {
580
+ const c = e.target.closest('[data-report-open]'); if (!c) return;
581
+ e.preventDefault();
582
+ const m = ((S.conv && S.conv.messages) || [])[+c.dataset.reportOpen];
583
+ const b = m ? splitReport(splitGoal(m.text).text).block : null;
584
+ if (b) openBlockTab(b);
585
+ if (innerWidth < 1000 && !chatPage()) setTab('out');
586
+ });
555
587
  /** The draft of the newest ready goal block in the conversation, which Start sends as the confirmed goal. */
556
588
  function readyDraft(conv) {
557
589
  const ms = (conv && conv.messages) || [];
@@ -1,7 +1,9 @@
1
1
  /* pm/premium-vw-doc.js — a markdown document as a page in the premium viewer (initiative premium-viewer, S2; planning/prd/premium-viewer-prd.md R2).
2
2
  * One document, one page: read it, edit it in place (or as Markdown), and see an agent's proposed change applied and highlighted, with one Keep and one
3
3
  * Undo all. Built on the viewer frame (premium-viewer.js) and the existing /api/doc-sheet routes: log and at to read, edit to save, proposals, accept and
4
- * reject for an agent's edit, ask to request one. Nothing here is stored anywhere else. The pure half is premium-vw-doc-model.js. */
4
+ * reject for an agent's edit, ask to request one. Nothing here is stored anywhere else. The pure half is premium-vw-doc-model.js.
5
+ * ctx.host (an element) draws the page editor inside it instead of a viewer tab (the report dialog's Edit, PM 2026-10-22: one place to edit a
6
+ * report). It opens in Edit, offers only Edit and Markdown, and Cancel or a save calls ctx.onClose. No Health, Links, Copies, extras or Ask. */
5
7
  import { pmPost } from './http.js';
6
8
  import { vwOpen, vwStyle, vwConfirm } from './premium-viewer.js';
7
9
  import { $, $$, esc, toast, AI, CHECK } from './premium-shell.js';
@@ -79,6 +81,7 @@ const tb = (c, label, icon) => `<button type="button" class="vwtb" data-c="${c}"
79
81
  export function openDocPage(d, ctx = {}) {
80
82
  if (!d || !d.path) return null;
81
83
  vwStyle('doc');
84
+ if (ctx.host) return makePage(d, ctx);
82
85
  const id = 'doc:' + d.path, prior = OPEN.get(id);
83
86
  if (prior) return prior.show(ctx); // the same document opened again: show its tab and read it again; what is typed and not saved stays
84
87
  return makePage(d, ctx);
@@ -104,6 +107,7 @@ function makePage(d, ctx) {
104
107
  const at = revs.length ? await getJson('/api/doc-sheet/at?path=' + p + '&rev=' + revs[revs.length - 1].rev + wsq()) : null;
105
108
  if (at && at.ok) P.text = at.text; else { P.text = null; P.err = (at && at.error) || (lg && lg.error) || 'The file could not be read.'; }
106
109
  P.kept = null; draw();
110
+ if (ctx.host) return;
107
111
  loadHealth(); loadCopies(); if (P.more === 'links') loadLib();
108
112
  }
109
113
  /* ── Health, Links and Copies: the sheet's own reads (POST /api/doc-health/check, GET /api/docs/library, GET /api/docs), drawn under the bar ── */
@@ -196,6 +200,7 @@ function makePage(d, ctx) {
196
200
  function toolsHtml(p) {
197
201
  const lock = p ? ' disabled title="Keep or undo the agent\'s edit first"' : '';
198
202
  const seg = (m, label, icon) => `<button type="button" class="vwseg" data-vd="mode:${m}" aria-pressed="${P.mode === m}"${m !== 'read' ? lock : ''}>${IC[icon]}${label}</button>`;
203
+ if (ctx.host) return `<div class="vwdt" role="toolbar" aria-label="Document"><span class="vwsg">${seg('edit', 'Edit', 'pen')}${seg('md', 'Markdown', 'md')}</span></div>`;
199
204
  return `<div class="vwdt" role="toolbar" aria-label="Document"><span class="vwsg">${seg('read', 'Page', 'doc')}${seg('edit', 'Edit', 'pen')}${seg('md', 'Markdown', 'md')}</span><span class="gap"></span>`
200
205
  + (P.mode === 'read' ? extrasHtml() : '')
201
206
  + (P.mode === 'read' && !p ? `<button type="button" class="vwbtn" data-vd="askt" aria-expanded="${P.askOpen}">${AI}Ask the agent</button>` : '') + '</div>'
@@ -354,6 +359,7 @@ function makePage(d, ctx) {
354
359
  if (k === 'back') cur.delete(arg); else cur.add(arg);
355
360
  P.kept = o.live.filter((n) => cur.has(n)); draw(); return;
356
361
  }
362
+ if (k === 'cancel' && ctx.host) { if (ctx.onClose) ctx.onClose(); return; }
357
363
  if (k === 'cancel') { P.mode = 'read'; P.work = null; P.base = null; P.why = ''; P.msg = ''; draw(); return; }
358
364
  if (k === 'save') {
359
365
  const why = ($('#vwWhy', el) || {}).value || '';
@@ -365,6 +371,7 @@ function makePage(d, ctx) {
365
371
  if (!res || res.ok !== true) return fail((res && res.error) || 'The document could not be saved.');
366
372
  toast(`Saved as v${v() + 1}. The reason is in the Edit log.`);
367
373
  P.busy = false; P.mode = 'read'; P.base = null; P.work = null; P.why = '';
374
+ if (ctx.host) { if (ctx.onWrite) await ctx.onWrite(); if (ctx.onClose) ctx.onClose(); return; }
368
375
  await load(); if (ctx.onWrite) ctx.onWrite(); return;
369
376
  }
370
377
  if (k === 'ask') {
@@ -468,6 +475,7 @@ function makePage(d, ctx) {
468
475
  pane.addEventListener('mouseup', () => { if (P.mode === 'edit') setTimeout(syncBar, 0); });
469
476
  }
470
477
 
478
+ if (ctx.host) { P.mode = 'edit'; el = ctx.host; el.innerHTML = '<p class="vwempty">Reading the file.</p>'; if (!WIRED.has(el)) { WIRED.add(el); wire(el); } load(); return el; }
471
479
  const spec = { id, title: d.title || String(d.path).split('/').pop(), icon: 'doc', render(e) { el = e; draw(); }, wire(e) { if (WIRED.has(e)) return; WIRED.add(e); wire(e); } };
472
480
  const api = { show(c2) { if (!el || !el.isConnected) { OPEN.delete(id); return makePage(d, c2 || ctx); } if (c2) ctx = c2; el = vwOpen(spec) || el; if (P.mode === 'read') load(); return el; } };
473
481
  OPEN.set(id, api);
@@ -0,0 +1,60 @@
1
+ @font-face{font-family:"Space Grotesk";src:url(/vendor/space-grotesk-var.woff2) format("woff2");font-weight:300 700;font-display:swap}
2
+ @font-face{font-family:"IBM Plex Mono";src:url(/vendor/ibm-plex-mono-400.woff2) format("woff2");font-weight:400;font-display:swap}
3
+ @font-face{font-family:"IBM Plex Mono";src:url(/vendor/ibm-plex-mono-500.woff2) format("woff2");font-weight:500;font-display:swap}
4
+ @font-face{font-family:"IBM Plex Mono";src:url(/vendor/ibm-plex-mono-700.woff2) format("woff2");font-weight:600 700;font-display:swap}
5
+ :root{--fs-1:11px;--fs-2:12px;--fs-3:14px;--fs-4:16px;--fs-5:20px;--fs-6:28px}
6
+ /* pm/premium-vw-report.css — the Report tab beside a chat (initiative premium-reports-from-chat, slice B; premium-report-tab.js).
7
+ * Loaded once by vwStyle('report'). Sizes are only var(--fs-1..6), weights 400/500/600 (premium-console-type.test.js). */
8
+ .rt{max-width:760px;margin:0 auto;padding:4px 2px 24px;display:flex;flex-direction:column;align-items:stretch;gap:12px;text-align:left}
9
+ .rt>*{align-self:stretch}
10
+ .rt .btn,.obody:has(>.rt)>.vcf .btn{display:inline-flex;align-items:center;justify-content:center;min-height:40px;padding:0 16px;border:1px solid var(--solid);border-radius:6px;background:var(--solid);color:var(--on-solid);font-size:var(--fs-2);font-weight:600;white-space:nowrap}
11
+ .rt .btn.sec,.obody:has(>.rt)>.vcf .btn.sec{background:transparent;border-color:var(--hair);color:var(--ink)}
12
+ .rt .btn:disabled{opacity:.5;cursor:default}
13
+ .rt-eye{margin:0;font:500 var(--fs-1) var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3)}
14
+ .rt-h{margin:0;font-size:var(--fs-5);font-weight:600;color:var(--ink);overflow-wrap:anywhere}
15
+ .rt-sub{margin:0;font-size:var(--fs-3);color:var(--ink-2)}
16
+ .rt-meta,.rt-note{margin:0;font-size:var(--fs-2);color:var(--ink-3)}
17
+ .rt-label{margin:6px 0 0;font-size:var(--fs-2);font-weight:600;color:var(--ink-2)}
18
+ .rt-msg{margin:0;padding:10px 12px;border-radius:8px;background:var(--well);font-size:var(--fs-3);color:var(--ink)}
19
+ .rt-row{display:flex;flex-direction:column;gap:8px;align-items:flex-start}
20
+ .rt-chip{align-self:flex-start;display:inline-flex;flex-direction:column;align-items:flex-start;gap:1px;min-height:44px;padding:6px 14px;border:1px solid var(--hair);border-radius:6px;background:var(--card-solid,var(--card));color:var(--ink);text-align:left;cursor:pointer}
21
+ .rt-chip em{font-style:normal;font-size:var(--fs-1);color:var(--ink-3)}
22
+ .rt-chip b{font-size:var(--fs-3);font-weight:600}
23
+ .rt-menu{display:flex;flex-direction:column;gap:2px;width:100%;max-width:360px;padding:6px;border:1px solid var(--hair);border-radius:8px;background:var(--card-solid,var(--card));box-shadow:var(--card-shadow)}
24
+ .rt-menu>button{min-height:44px;padding:0 12px;border-radius:6px;text-align:left;font-size:var(--fs-3);color:var(--ink);background:none}
25
+ .rt-menu>button[aria-checked="true"]{background:var(--well);font-weight:600}
26
+ @media (hover:hover){.rt-menu>button:hover{background:var(--well)}}
27
+ .rt-menu .rt-note{padding:6px 12px}
28
+ .rt-days{display:flex;flex-wrap:wrap;gap:6px;padding:6px 6px 2px}
29
+ .rt-days .btn{min-height:44px;min-width:52px;padding:0 10px}
30
+ .rt-ask{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:10px;padding:10px 12px;border-radius:8px;background:var(--well)}
31
+ .rt-ask p{margin:0;font-size:var(--fs-3);color:var(--ink-2);flex:1 1 200px;min-width:0;overflow-wrap:anywhere}
32
+ .rt-ask b{color:var(--ink);font-weight:600}
33
+ .rt .rt-seg{display:inline-flex;gap:4px;padding:3px;border-radius:6px;background:var(--well);align-self:flex-start}
34
+ .rt-seg .btn.sec{border-color:transparent}
35
+ .rt-seg .btn{min-height:40px;border-radius:6px}
36
+ .rt-ver{display:flex;align-items:center;gap:6px;font:500 var(--fs-2) var(--mono);color:var(--ink-2)}
37
+ .rt-arrow{width:44px;height:44px;border:1px solid var(--hair);border-radius:6px;background:var(--card-solid,var(--card));color:var(--ink);font-size:var(--fs-4);cursor:pointer}
38
+ .rt-arrow:disabled{opacity:.4;cursor:default}
39
+ .rt-secs{margin:0;padding:0;list-style:none;border:1px solid var(--hair);border-radius:8px;background:var(--card-solid,var(--card))}
40
+ .rt-secs li{display:flex;flex-direction:column;gap:2px;padding:10px 14px;border-top:1px solid var(--hair)}
41
+ .rt-secs li:first-child{border-top:0}
42
+ .rt-secs b{font-size:var(--fs-3);font-weight:600;color:var(--ink)}
43
+ .rt-secs span{font-size:var(--fs-2);color:var(--ink-3)}
44
+ .rt-frame{width:100%;aspect-ratio:16/10;border:1px solid var(--hair);border-radius:8px;background:var(--card-solid,var(--card))}
45
+ .rt-cyc{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:6px}
46
+ .rt-cyc li{position:relative;display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-height:44px;padding:4px 4px 4px 10px;border:1px solid var(--hair);border-radius:8px}
47
+ .rt-slot{flex:1;min-width:0;font-size:var(--fs-3);color:var(--ink)}
48
+ .rt-tag{padding:2px 8px;border-radius:6px;font:500 var(--fs-1) var(--mono);text-transform:uppercase}
49
+ .rt-tag.draft{background:var(--well);color:var(--ink-2)}
50
+ .rt-tag.issued{background:color-mix(in srgb,var(--good) 16%,transparent);color:var(--ink)}
51
+ .rt-foot{display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end}
52
+ .rt-foot .btn{min-height:44px}
53
+ .rt-end{margin-top:6px;padding-top:12px;border-top:1px solid var(--hair)}
54
+ .rt-del{color:var(--bad)}
55
+ .rt button:focus-visible{outline:2px solid var(--ember);outline-offset:2px}
56
+ /* the Chart tab (premium-chart-tab.js, slice C): a chart at a readable size, a dashboard's charts side by side where they fit */
57
+ .rt .ct-tile{max-width:460px}
58
+ .rt .ct-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px;margin:0}
59
+ .rt .ct-grid .nempty{align-self:start;padding:12px 14px;border-radius:8px;background:var(--well)}
60
+ .rt .ct-grid .nempty p{margin:0;font-size:var(--fs-2);color:var(--ink-2)}
@@ -3,7 +3,9 @@
3
3
  * (pm/premium-deck.js has the format): the editor reads it through GET /api/doc and saves it through POST /api/doc-sheet/edit, which keeps a
4
4
  * revision with the PM's why. Nothing else is stored.
5
5
  *
6
- * openSlides({ ws, path, title, readOnly, onSaved }) opens the file as a Slides tab beside the dialog's own detail
6
+ * openSlides({ ws, path, title, readOnly, onSaved, host, onClose }) opens the file as a Slides tab beside the dialog's own detail. With host
7
+ * (an element), the editor is drawn inside it instead (the report dialog's Edit, PM 2026-10-22: one place to edit a report), with a Cancel
8
+ * that calls onClose, and a save that calls onSaved then onClose. Present stays: it is the presenter view, with the notes.
7
9
  *
8
10
  * On the slide: click to select, drag to move (centre guides), the corner handles to resize, double-click to type. The rail reorders by drag
9
11
  * (or Move up and Move down), adds a slide from a layout, duplicates and deletes. Undo and redo cover every change. Present opens the presenter
@@ -145,12 +147,13 @@ export function present(deck, ws, start, opt = {}) {
145
147
  /* ── the editor ── */
146
148
  const OPEN = new Map(); // path -> editor state, so the test hook can read it
147
149
 
148
- export async function openSlides({ ws, path, title, readOnly, onSaved } = {}) {
150
+ export async function openSlides({ ws, path, title, readOnly, onSaved, host, onClose } = {}) {
149
151
  if (!path) return null;
150
152
  vwStyle('slides');
151
- const S = { ws: ws || '', path, title: title || String(path).split('/').pop(), ro: !!readOnly, onSaved, text: null, deck: null, i: 0, sel: null, editing: null, drag: null, hist: [], fut: [], dirty: false, msg: '', busy: false, pop: null, root: null };
153
+ const S = { ws: ws || '', path, title: title || String(path).split('/').pop(), ro: !!readOnly, onSaved, onClose: host ? onClose : null, text: null, deck: null, i: 0, sel: null, editing: null, drag: null, hist: [], fut: [], dirty: false, msg: '', busy: false, pop: null, root: null };
152
154
  OPEN.set(path, S);
153
- const el = vwOpen({ id: 'slides:' + path, title: S.title + ' slides', icon: 'doc', html: '<p class="note">Reading the slides.</p>' });
155
+ const el = host || vwOpen({ id: 'slides:' + path, title: S.title + ' slides', icon: 'doc', html: '<p class="note">Reading the slides.</p>' });
156
+ if (host) host.innerHTML = '<p class="note">Reading the slides.</p>';
154
157
  S.root = el;
155
158
  try {
156
159
  const r = await fetch('/api/doc?' + new URLSearchParams({ ...(S.ws ? { ws: S.ws } : {}), path }).toString(), { credentials: 'same-origin' });
@@ -175,7 +178,7 @@ function build(S) {
175
178
  el.innerHTML = `<div class="sl${ro ? ' ro' : ''}" data-sl>`
176
179
  + `<div class="sl-tb" role="toolbar" aria-label="Slides">`
177
180
  + (ro ? '' : `${tb('undo', 'Undo', 'undo', ' disabled')}${tb('redo', 'Redo', 'redo', ' disabled')}<span class="sl-sep"></span>${tbl('text', 'Text', 'txt')}${tbl('img', 'Image', 'img')}${tbl('chart', 'Chart', 'chart')}${tbl('table', 'Table', 'tbl')}${tbl('shape', 'Shape', 'shape')}<span class="sl-sep"></span>${tbl('layout', 'Layout', 'lay', ' aria-haspopup="menu"')}${tbl('theme', 'Theme', 'pal', ' aria-haspopup="menu"')}`)
178
- + `<span class="sl-gap"></span>${tbl('present', 'Present', 'play')}${ro ? '' : `<button type="button" class="sl-b sl-pri" data-c="save">${I('save')}<span>Save</span></button>`}</div>`
181
+ + `<span class="sl-gap"></span>${tbl('present', 'Present', 'play')}${S.onClose ? `<button type="button" class="sl-b sl-bl" data-c="close"><span>Cancel</span></button>` : ''}${ro ? '' : `<button type="button" class="sl-b sl-pri" data-c="save">${I('save')}<span>Save</span></button>`}</div>`
179
182
  + (ro ? '' : '<div class="sl-ctx" role="toolbar" aria-label="Change the selected item"></div>')
180
183
  + `<p class="sl-msg" role="status"></p>`
181
184
  + `<div class="sl-body"><nav class="sl-rail" aria-label="Slides"></nav><div class="sl-main"><div class="sl-stage" tabindex="0" aria-label="Slide"></div>`
@@ -338,6 +341,11 @@ function onTop(S, c, b) {
338
341
  S.pres = present(S.deck, S.ws, S.i, { ro: S.ro, onNotes: (i, v, first) => { if (first) snap(S); S.deck.slides[i].notes = v; S.dirty = true; drawBar(S); }, onEnd: (i) => { S.pres = null; go(S, i); } });
339
342
  return;
340
343
  }
344
+ if (c === 'close') {
345
+ commitEdit(S);
346
+ if (S.dirty && !S.closing) { S.closing = true; b.innerHTML = '<span>Sure? Leave without saving</span>'; return; }
347
+ OPEN.delete(S.path); if (S.onClose) S.onClose(); return;
348
+ }
341
349
  if (S.ro) return;
342
350
  if (c === 'undo') return undo(S);
343
351
  if (c === 'redo') return redo(S);
@@ -451,6 +459,7 @@ function askSave(S, b) {
451
459
  const r = await save(S, why);
452
460
  if (!r.ok) { err.hidden = false; err.textContent = r.error; return; }
453
461
  closePop(S);
462
+ if (S.onClose) { OPEN.delete(S.path); S.onClose(); }
454
463
  };
455
464
  }
456
465
  async function save(S, why) {