create-pmos 0.400.0 → 0.402.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 (57) 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/board-programs-test.js +226 -0
  8. package/workspace/board-shot.js +54 -0
  9. package/workspace/briefing-premium-board-test.js +23 -16
  10. package/workspace/briefing-premium-calendar-test.js +6 -3
  11. package/workspace/briefing-premium-sources-test.js +17 -10
  12. package/workspace/briefing-premium-test.js +41 -16
  13. package/workspace/changelog.json +24 -0
  14. package/workspace/fixtures/board-premium-facts.js +20 -3
  15. package/workspace/fixtures/briefing-premium-facts.js +18 -2
  16. package/workspace/fixtures/program-ascent.js +101 -0
  17. package/workspace/guide/home.md +15 -8
  18. package/workspace/guide/index.md +1 -0
  19. package/workspace/guide/programs.md +37 -0
  20. package/workspace/lib/briefing-premium-products.js +4 -4
  21. package/workspace/lib/briefing-premium.js +2 -2
  22. package/workspace/lib/core-docs.js +2 -2
  23. package/workspace/lib/programs.js +129 -0
  24. package/workspace/lib/route-modules.js +1 -0
  25. package/workspace/lib/routes-briefing-premium.js +1 -1
  26. package/workspace/lib/routes-programs.js +122 -0
  27. package/workspace/package-lock.json +2 -2
  28. package/workspace/package.json +1 -1
  29. package/workspace/premium-board-actions-test.js +1 -1
  30. package/workspace/premium-phone-card-test.js +6 -1
  31. package/workspace/premium-vw-cal-test.js +10 -4
  32. package/workspace/program-panel-test.js +143 -0
  33. package/workspace/public/pm/bd-acts.js +23 -14
  34. package/workspace/public/pm/bd-asks.js +89 -23
  35. package/workspace/public/pm/bd-prog-panel.js +451 -0
  36. package/workspace/public/pm/bd-prog.js +191 -0
  37. package/workspace/public/pm/bd-span.js +98 -15
  38. package/workspace/public/pm/bd-views.js +93 -29
  39. package/workspace/public/pm/cozy-board.css +226 -9
  40. package/workspace/public/pm/cozy-home.css +27 -1
  41. package/workspace/public/pm/cozy-panel.css +178 -0
  42. package/workspace/public/pm/cozy-today.css +190 -3
  43. package/workspace/public/pm/home-app.js +93 -26
  44. package/workspace/public/pm/home-chat.js +35 -32
  45. package/workspace/public/pm/home-data.js +8 -2
  46. package/workspace/public/pm/home-ini.js +1 -1
  47. package/workspace/public/pm/home-list.js +100 -24
  48. package/workspace/public/pm/home-today.js +138 -61
  49. package/workspace/public/pm/home-work.js +1 -3
  50. package/workspace/public/pm/premium-board.js +225 -57
  51. package/workspace/public/pm/premium-vw-item.css +6 -0
  52. package/workspace/public/pm/program-model.js +192 -0
  53. package/workspace/public/premium-board.html +4 -1
  54. package/workspace/test-files.json +1 -0
  55. package/workspace/test-lists/board-programs.json +9 -0
  56. package/workspace/test-lists/program-hierarchy.json +11 -0
  57. package/workspace/test-lists/program-panel.json +9 -0
@@ -0,0 +1,451 @@
1
+ /* pm/bd-prog-panel.js — the program panel on the Board (initiative program-hierarchy, P5, P9; canvas PgProgram, PgMilestones), and the side
2
+ * panel's width (B1; canvas XnAgBoardPanel: 60 % of the width on desktop, 50 to 70 %, a bottom sheet on a phone).
3
+ *
4
+ * mount(o) once, from premium-board.js. o: { M() the Board model, programs() GET /api/programs' programs, openIni(id, from) the initiative
5
+ * panel of a row of this board, close() the Board's own side panel, reload() reads the programs again, say(msg) the toast }
6
+ *
7
+ * The panel opens on document `bd:program` { id, from? } and once on load when the address has ?program=<id> (Home links there). A program
8
+ * row of the Board ([data-prog]) sends that event. The panel is its own <aside class="bd-peek pp-peek">, so the Board's panel and this one
9
+ * share the place, the width and the phone sheet, and opening one closes the other.
10
+ *
11
+ * What it shows (PgProgram), each part only when a record holds something for it:
12
+ * · the head: the program icon, "title · goal", the owner and the span, then Ask in Home, the charter, ⋯ (add, move in, archive) and Close
13
+ * · the goals: the KRs its initiatives anchor to, for one year half with a period picker; the earlier halves fold into one chip
14
+ * · the milestone track: 3 milestones, the earlier done ones in a done cluster and the later ones in "N more"; both open the Milestones tab
15
+ * · waits on you: your program tasks (a check box) and what waits on you in its initiatives (a dot); each row opens in Home
16
+ * · the sort card after Turn into a program: how many tasks of the initiative it came from have no level yet; Claude sorts them in Home
17
+ * · the tabs: Tree (program tasks, then per product its initiatives with their tasks, what waits on you and their epics), Tasks (every open
18
+ * task of the program and its initiatives, by level), Milestones, Documents
19
+ * No chat box: the question goes to Home. An initiative in another product is read from that product's board (GET /api/board-premium?ws=).
20
+ * Per product the panel also reads, once per page load: its KRs' names (GET /api/boards/anchors, the OKR files), whether each KR is met (GET
21
+ * /api/insights-premium, the goals Insights shows) and its PMOS tasks (GET /api/boards/items). A part whose read failed is left out, never guessed.
22
+ * Every group folds, and the folds, the tab and the width are kept in this browser. */
23
+ import { pmPost } from './http.js';
24
+ import { esc, store } from './premium-shell.js';
25
+ import { programState, milestoneTrack, milestoneGroups, goalsByPeriod, shortDay } from './program-model.js';
26
+ import { STEPS } from './premium-initiative-head.js';
27
+ import { open as viewerOpen } from './cozy-viewer.js';
28
+
29
+ const SV = (d, w) => `<svg viewBox="0 0 24 24" width="${w || 18}" height="${w || 18}" aria-hidden="true"><path d="${d}"/></svg>`;
30
+ const I = {
31
+ prog: 'M12 3l9 5-9 5-9-5zM3 13l9 5 9-5M3 17.5l9 5 9-5', ask: 'M4 5h16v11H9l-5 4z', doc: 'M7 3h7l5 5v13H7zM14 3v5h5', more: 'M5 12h.01M12 12h.01M19 12h.01',
32
+ x: 'M6 6l12 12M18 6L6 18', chev: 'M7 10l5 5 5-5', chevR: 'M10 7l5 5-5 5', plus: 'M12 5v14M5 12h14', go: 'M5 12h14M13 6l6 6-6 6', out: 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6',
33
+ };
34
+ const FOLD_KEY = 'pmos.board.ppfold', TAB_KEY = 'pmos.board.pptab', W_KEY = 'pmos.board.pkw';
35
+ const PLAN = STEPS.findIndex((s) => s.key === 'plan');
36
+ const plural = (n, a, b) => (n === 1 ? a : b);
37
+ const initialsOf = (name) => { const w = String(name || '').trim().split(/[\s_-]+/).filter(Boolean); return (w.length > 1 ? w[0][0] + w[1][0] : String(name || '?').slice(0, 2)).toUpperCase(); };
38
+ const dayOf = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
39
+ const daysTo = (iso) => { const d = dayOf(iso); if (!d) return null; const t = new Date(); t.setHours(0, 0, 0, 0); return Math.round((d - t) / 86400000); };
40
+ const lateBy = (d) => -d + ' ' + plural(-d, 'day', 'days') + ' late';
41
+ const PHONE = matchMedia('(max-width: 720px)');
42
+
43
+ let O = null; // mount's options
44
+ let el = null; // the panel
45
+ let cur = null; // { id, back } the open program and the element it was opened from
46
+ let tab = ['tree', 'tasks', 'ms', 'docs'].includes(store.get(TAB_KEY)) ? store.get(TAB_KEY) : 'tree';
47
+ let period = null; // the year half the goals show (null: the current one)
48
+ let adding = false; // the add-a-task line of "On the program" is open
49
+ let menuOpen = false; // the ⋯ menu
50
+ let capOn = ''; // the track's cluster that opened the Milestones tab ('done' or 'more'): it stays marked while the tab shows
51
+ const fold = new Set((() => { try { return JSON.parse(store.get(FOLD_KEY) || '[]'); } catch { return []; } })());
52
+ const keepFold = () => store.set(FOLD_KEY, JSON.stringify([...fold].slice(-200)));
53
+ const AWAY = new Map(); // the boards of the other products: ws → { name, board, rows } | 'reading'
54
+ const MORE = new Map(); // per product: ws → { anchors, goals, items, you } (each null until read, or when its read failed)
55
+
56
+ /* ── what the panel reads ── */
57
+ const board = () => (O && O.M() && O.M().board) || {};
58
+ const progOf = (id) => ((O && O.programs()) || []).find((p) => p.id === id) || null;
59
+ /** A product's name and rows for programState. Each row keeps the Board model's own fields (anchor, track, epics, trail) beside its step key. */
60
+ function rowsOf(ws) {
61
+ const M = O.M(); if (!M) return null;
62
+ const steps = M.steps || [];
63
+ const shape = (rows) => (rows || []).filter((r) => r.id).map((r) => ({ ...r, stage: r.track && r.track.k >= 0 && steps[r.track.k] ? steps[r.track.k].key : r.stage }));
64
+ if (!ws || !board().ws || ws === board().ws) return { name: board().product || board().name || '', rows: shape(M.rows), here: true };
65
+ const a = AWAY.get(ws);
66
+ return a && a !== 'reading' ? { name: a.name, rows: shape(a.rows) } : null;
67
+ }
68
+ /** Reads the board of each product of the program that is not this one, once per page load; the panel draws again when one arrives. */
69
+ function readAway(p) {
70
+ for (const m of (p && p.members) || []) {
71
+ const ws = m.ws; if (!ws || ws === board().ws || AWAY.has(ws)) continue;
72
+ AWAY.set(ws, 'reading');
73
+ fetch('/api/board-premium?ws=' + encodeURIComponent(ws), { credentials: 'same-origin' }).then((r) => r.json()).catch(() => null).then((r) => {
74
+ if (!r || !r.ok || !r.model) { AWAY.delete(ws); return; } // still reading, or refused: the next open asks again
75
+ AWAY.set(ws, { name: (r.model.board && (r.model.board.product || r.model.board.name)) || ws, board: (r.model.board && r.model.board.id) || ws, rows: r.model.rows || [] });
76
+ if (cur && cur.id === p.id) draw();
77
+ });
78
+ }
79
+ }
80
+ /** Reads a product's KR names, its Insights goals and its PMOS tasks, once per page load; the panel draws again as each arrives. */
81
+ const getJson = (u) => fetch(u, { credentials: 'same-origin' }).then((r) => (r.status === 200 ? r.json() : null)).catch(() => null);
82
+ function readMore(p) {
83
+ const all = new Set([p.home, ...((p.members || []).map((m) => m.ws))].map((w) => w || board().ws || ''));
84
+ for (const ws of all) {
85
+ if (MORE.has(ws)) continue;
86
+ const here = !ws || ws === board().ws, a = here ? null : AWAY.get(ws);
87
+ const bid = here ? board().id : a && a !== 'reading' ? a.board : null;
88
+ if (!bid) continue; // the other product's board is still being read: asked again when it arrives
89
+ const one = { anchors: null, goals: null, items: null, you: null };
90
+ MORE.set(ws, one);
91
+ const q = 'ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(bid), again = () => { if (cur) draw(true); };
92
+ getJson('/api/boards/anchors?' + q).then((r) => { if (r && r.ok) { one.anchors = r.anchors || []; again(); } });
93
+ getJson('/api/insights-premium?ws=' + encodeURIComponent(ws)).then((r) => { if (r && r.ok && r.model) { one.goals = r.model.goals || []; again(); } });
94
+ getJson('/api/boards/items?' + q).then((r) => { if (r && r.ok) { one.items = r.items || []; again(); } });
95
+ // this board's rows carry what waits on you (the Board merges its trail); another product's rows do not, so its trail is read here
96
+ const ids = here ? [] : (p.members || []).filter((m) => m.ws === ws).map((m) => m.initiative);
97
+ if (ids.length) getJson('/api/board-trail?' + q + '&ids=' + ids.map(encodeURIComponent).join(',')).then((r) => {
98
+ if (!r || !r.ok) return;
99
+ one.you = Object.fromEntries(Object.entries(r.items || {}).filter(([, it]) => it && it.you && it.you.text).map(([id, it]) => [id, it.you.text])); again();
100
+ });
101
+ }
102
+ }
103
+ const moreOf = (ws) => MORE.get(ws || board().ws || '') || {};
104
+ /** What waits on you in an initiative: its track's next action that is yours (the Board's trail), or the one its own board's trail says. */
105
+ const youOf = (i) => (i.row.track && i.row.track.you) || (moreOf(i.ws).you || {})[i.id] || '';
106
+ /** What the page knows of a KR (pm/program-model.js goalsByPeriod krsOf): its name from the OKR files, and whether Insights reads it as met.
107
+ * met: its goal reached its target · tone: 'ok' (met or on course) or 'off' (behind); both left out when no Insights goal names the KR. */
108
+ function krsOf(anchor, i) {
109
+ const x = moreOf(i.ws), [, o, k] = String(anchor).split(':'), want = (o + '.' + k).toUpperCase(), out = {};
110
+ const a = (x.anchors || []).find((y) => y.kind === 'kr' && String(y.value).toUpperCase() === want);
111
+ if (a) out.name = String(a.label || '').replace(/^\S+\s+/, '').replace(/\.$/, '');
112
+ const raw = String((i.row && (i.row.anchor || i.row.parent_kr)) || '');
113
+ const g = (x.goals || []).find((y) => y.id === raw || y.title === raw || (y.moves || []).some((m) => m.id === i.id));
114
+ if (g && g.pace) {
115
+ out.met = /^(Reached|Done|Within)/.test(g.pace.head || '');
116
+ out.tone = out.met || g.pace.tone === 'ok' ? 'ok' : g.pace.tone === 'late' ? 'off' : '';
117
+ if (!out.name) out.name = g.title;
118
+ }
119
+ return out;
120
+ }
121
+ /** The open PMOS tasks of the program's initiatives (GET /api/boards/items), each with its level: on an epic, or on the initiative itself. */
122
+ function iniTasks(st) {
123
+ const out = [];
124
+ for (const i of st.inis) {
125
+ const items = moreOf(i.ws).items || [];
126
+ for (const t of items) {
127
+ if (t.src !== 'pmos' || t.kind === 'Epic' || t.ini !== i.id || t.status === 'Done') continue;
128
+ const e = t.epic ? items.find((y) => y.uid === t.epic) : null;
129
+ out.push({ uid: t.uid, title: t.title, owner: t.owner || '', due: t.end || '', ini: i, level: t.epic ? 'epic' : 'initiative', epic: e ? e.title || e.key : t.epic || '' });
130
+ }
131
+ }
132
+ return out.sort((a, b) => String(a.due || '9999').localeCompare(String(b.due || '9999')));
133
+ }
134
+ /** Your program task: its owner is the program's owner (the PM who keeps the charter), or it has none. */
135
+ const mine = (p, t) => !t.owner || (p.owner && t.owner.toLowerCase() === p.owner.toLowerCase());
136
+ const homeHref = (o) => { const q = new URLSearchParams(); for (const [k, v] of Object.entries(o)) if (v) q.set(k, v); return '/premium.html?' + q.toString(); };
137
+ const boardHref = (ws, id) => '/premium-board.html?ws=' + encodeURIComponent(ws) + (id ? '&focus=' + encodeURIComponent(id) : '');
138
+
139
+ /* ── the parts ── */
140
+ function headHtml(p, st) {
141
+ const line = [p.owner, st.span.label].filter(Boolean).join(' · ');
142
+ return `<div class="pk-h pp-h"><span class="pp-pi" aria-hidden="true">${SV(I.prog, 20)}</span><div class="pk-ht"><h2 id="ppTitle">${esc(p.title)}${p.goal ? ' · ' + esc(p.goal) : ''}</h2>${line ? `<p class="pp-ch">${esc(line)}</p>` : ''}</div>`
143
+ + `<div class="pk-tools"><a class="bd-ib" href="${esc(homeHref({ ws: p.home, ask: 'program:' + p.id, label: p.title }))}" aria-label="Ask about ${esc(p.title)} in Home" title="Ask in Home">${SV(I.ask)}</a>`
144
+ + `<button type="button" class="bd-ib" data-pp="charter" aria-label="Open the charter" title="Open the charter">${SV(I.doc)}</button>`
145
+ + `<button type="button" class="bd-ib" data-pp="menu" aria-haspopup="menu" aria-expanded="${menuOpen}" aria-label="More: add initiative, move initiative in, archive" title="More">${SV(I.more)}</button>`
146
+ + `<button type="button" class="bd-ib" data-pp="close" aria-label="Close" title="Close">${SV(I.x)}</button></div>${menuOpen ? menuHtml(p) : ''}</div>`;
147
+ }
148
+ function menuHtml(p) {
149
+ const M = O.M(), taken = new Set(((O.programs()) || []).flatMap((x) => (x.members || []).filter((m) => !m.ws || m.ws === board().ws).map((m) => m.initiative)));
150
+ const free = ((M && M.rows) || []).filter((r) => r.id && r.track && !taken.has(r.id)).slice(0, 8);
151
+ return `<div class="pp-menu" role="menu" aria-label="${esc(p.title)}"><button type="button" role="menuitem" data-pp="new">Add a new initiative</button>`
152
+ + (free.length ? `<p class="pp-mh">Move an initiative in</p>${free.map((r) => `<button type="button" role="menuitem" data-pp="join" data-ini="${esc(r.id)}">${esc(r.title)}</button>`).join('')}` : '')
153
+ + `<button type="button" role="menuitem" class="pp-mx" data-pp="archive">Archive the program</button></div>`;
154
+ }
155
+ /** The products' tiles: the first product blue, the second warm, the third grey, as the frames draw them. */
156
+ const tileHtml = (st, name, cls) => { const j = st.products.indexOf(name); return `<span class="pp-t2 t${j < 0 ? 2 : j % 3}${cls ? ' ' + cls : ''}" aria-hidden="true">${esc(initialsOf(name))}</span>`; };
157
+ function goalsHtml(st) {
158
+ const G = goalsByPeriod(st, krsOf);
159
+ const all = G.periods.concat(G.earlier ? G.earlier.periods : []);
160
+ if (!all.length) return '';
161
+ const on = all.find((h) => h.label === period) || G.periods[0] || all[all.length - 1];
162
+ // the dot: green when Insights reads the KR as met or on course, amber when it is behind; no dot when no goal names it (zero is silence)
163
+ const chip = (g) => { const k = krsOf(g.anchor, st.inis.find((i) => i.id === g.inis[0]) || {}), how = k.met ? 'met' : k.tone === 'ok' ? 'on course' : k.tone === 'off' ? 'behind' : '';
164
+ const dot = k.tone ? `<i class="pp-gd${k.tone === 'off' ? ' off' : ''}" aria-hidden="true"></i>` : '';
165
+ return `<span class="pp-kr" title="${esc([g.products.join(', '), how].filter(Boolean).join(' · '))}"${how ? ` aria-label="${esc(g.kr + (g.name ? ' ' + g.name : '') + ', ' + how)}"` : ''}>${dot}${g.products[0] ? tileHtml(st, g.products[0]) : ''}<b>${esc(g.kr)}</b>${g.name ? esc(g.name) : ''}</span>`; };
166
+ // the picker: only when there is more than one half to pick; the earlier halves fold into one chip that picks the latest of them
167
+ const pick = all.length > 1 ? `<button type="button" class="pp-per" data-pp="period" aria-haspopup="menu" aria-label="Period ${esc(on.label)}. Change period" title="KRs are set per half; the program spans several">${esc(on.label)}${SV(I.chev, 12)}</button>`
168
+ : `<span class="pp-per" title="KRs are set per half; the program spans several">${esc(on.label)}</span>`;
169
+ const early = G.earlier && !G.earlier.periods.includes(on)
170
+ ? `<button type="button" class="pp-kr ghost" data-pp="early" data-per="${esc(G.earlier.label)}" aria-label="${G.earlier.n} ${plural(G.earlier.n, 'KR', 'KRs')} from ${esc(G.earlier.label)}${G.earlier.periods.length > 1 ? ' and before' : ''}, ${G.earlier.met} met. Show them">${esc(G.earlier.label)} · ${G.earlier.met} met</button>` : '';
171
+ const menu = O._perOpen ? `<div class="pp-menu pp-pmenu" role="menu" aria-label="Period">${all.slice().sort((a, b) => b.key.localeCompare(a.key)).map((h) => `<button type="button" role="menuitemradio" aria-checked="${h === on}" data-pp="per" data-per="${esc(h.label)}">${esc(h.label)} <span>${h.goals.length}</span></button>`).join('')}</div>` : '';
172
+ return `<div class="pp-goal" role="group" aria-label="Goals: the KRs its initiatives anchor to">${pick}${on.goals.map(chip).join('')}${early}${menu}</div>`;
173
+ }
174
+ /** The readiness dots of a milestone: one per initiative it waits on, filled when that one is past Deliver. */
175
+ const rdHtml = (m) => (m.n ? `<span class="pp-rd" role="img" aria-label="${m.ready} of ${m.n} ${plural(m.n, 'initiative', 'initiatives')} ready">${Array.from({ length: m.n }, (_, j) => `<i${j < m.ready ? ' class="on"' : ''}></i>`).join('')}</span>` : '');
176
+ const waitsLine = (m) => (m.check ? 'A program check, no initiative to wait on' : 'Waits on ' + m.titles.join(' and '));
177
+ function trackHtml(st) {
178
+ if (!st.milestones.length) return '';
179
+ const T = milestoneTrack(st, 3), n = Math.max(1, T.shown.length);
180
+ const lastDone = T.shown.map((m) => m.done).lastIndexOf(true);
181
+ // the filled line runs to halfway between the last done milestone in view and the next one; with none in view, to the done cluster
182
+ const f = T.shown.length && lastDone === T.shown.length - 1 ? lastDone + 0.5 : lastDone >= 0 ? lastDone + 1 : T.done.length ? 0 : -1;
183
+ const cl = (L, done) => { const on = tab === 'ms' && capOn === (done ? 'done' : 'more'); return L.length ? `<button type="button" class="pp-cap${done ? ' dn' : ''}${on ? ' on' : ''}" data-pp="tab" data-tab="ms" data-cap="${done ? 'done' : 'more'}" aria-pressed="${on}" aria-label="${L.length} ${done ? 'earlier ' + plural(L.length, 'milestone', 'milestones') + ', done' : 'later ' + plural(L.length, 'milestone', 'milestones')}. Show all milestones"><span class="st3" aria-hidden="true">${L.slice(0, 3).map(() => '<i></i>').join('')}</span>${L.length} ${done ? 'done' : 'more'}</button>` : '<span></span>'; };
184
+ const one = (m) => `<div class="pp-m${m.late ? ' late' : ''}" title="${esc(waitsLine(m))}${m.check ? '' : ' reaching Deliver'}"><span class="pp-dm${m.done ? ' d' : st.next && m.id === st.next.id ? ' n' : ''}" aria-hidden="true"></span><b>${esc(m.name)}</b><span class="pp-md">${esc(m.day)}${m.done ? '' : rdHtml(m)}</span></div>`;
185
+ return `<div class="pp-sec"><p class="lbl">Program milestones</p><div class="pp-mt" style="--pp-n:${n};--pp-f:${f}"${f < 0 ? ' data-nofill' : ''}>${cl(T.done, true)}${T.shown.map(one).join('')}${cl(T.more, false)}</div></div>`;
186
+ }
187
+ /** What waits on you in the program: your open program tasks, then each initiative's next action that is yours. Each opens in Home. */
188
+ function needs(p, st) {
189
+ const out = [];
190
+ for (const t of st.openTasks.filter((x) => mine(p, x)).sort((a, b) => String(a.due || '9999').localeCompare(String(b.due || '9999')))) {
191
+ const d = daysTo(t.due);
192
+ out.push({ task: true, late: d != null && d < 0, title: t.title, sub: ['On the program', d == null ? '' : d < 0 ? lateBy(d) : d === 0 ? 'due today' : 'due ' + shortDay(t.due)].filter(Boolean).join(' · '),
193
+ href: homeHref({ ws: t.ws || p.home, item: 'pt:' + p.id + ':' + t.key }) });
194
+ }
195
+ for (const i of st.inis) {
196
+ const you = youOf(i); if (!you) continue;
197
+ out.push({ task: false, title: you, sub: i.title, href: homeHref({ ws: i.ws, ask: i.id }) });
198
+ }
199
+ return out;
200
+ }
201
+ function needsHtml(p, st) {
202
+ const L = needs(p, st); if (!L.length) return '';
203
+ return `<div class="pp-needs" role="group" aria-label="Waits on you">${L.map((x) => `<a class="pp-nr" href="${esc(x.href)}" aria-label="${x.task ? 'Task' : 'Waits on you'}: ${esc(x.title)}. Opens in Home"><span class="mk2">${x.task ? `<span class="pp-ck${x.late ? ' late' : ''}"></span>` : '<span class="pp-dt"></span>'}</span><span class="t"><b>${esc(x.title)}</b><span>${esc(x.sub)}</span></span><span class="go">${SV(I.out, 14)}</span></a>`).join('')}</div>`;
204
+ }
205
+ /** After Turn into a program (p.from names the initiative it came from): that initiative's open tasks on no epic are the tasks from before the
206
+ * split. Until they are sorted they have no level; Claude suggests a home for each in Home (?ask=program:<id>). A count only: zero is silence. */
207
+ function sortHtml(p, st) {
208
+ if (!p.from) return '';
209
+ const n = iniTasks(st).filter((t) => t.ini.id === p.from && (!t.ini.ws || !p.home || t.ini.ws === p.home) && t.level === 'initiative').length;
210
+ if (!n) return '';
211
+ return `<div class="pp-sort"><div class="t"><b>${n} ${plural(n, 'task', 'tasks')} from before the split ${n === 1 ? 'has' : 'have'} no level yet</b><div>Claude suggests a home for each: the program, an initiative or an epic</div></div>`
212
+ + `<a class="pp-cta" href="${esc(homeHref({ ws: p.home, ask: 'program:' + p.id, q: 'Suggest a home for each task of ' + p.title + ' that has no level yet' }))}" aria-label="Review the suggested homes in Home" title="Review the suggested homes">${SV(I.go, 16)}</a></div>`;
213
+ }
214
+
215
+ /* ── the tabs ── */
216
+ const avHtml = (p, who) => { const you = !who || (p.owner && who.toLowerCase() === p.owner.toLowerCase()); return `<span class="pp-av${you ? ' y' : ''}" role="img" aria-label="${esc(you ? 'You' : who)}">${esc(initialsOf(you ? p.owner || 'You' : who).slice(0, 1))}</span>`; };
217
+ const twHtml = (k) => `<button type="button" class="tw" data-pp="fold" data-fold="${esc(k)}" aria-expanded="${!fold.has(k)}" aria-label="${fold.has(k) ? 'Open' : 'Close'} the group">${SV(fold.has(k) ? I.chevR : I.chev, 14)}</button>`;
218
+ function taskRow(p, t) {
219
+ const d = daysTo(t.due), late = !t.done && d != null && d < 0;
220
+ return `<div class="pp-nd l2${t.done ? ' dn' : ''}" role="treeitem"><button type="button" class="pp-ck${late ? ' late' : ''}${t.done ? ' on' : ''}" data-pp="done" data-key="${esc(t.key)}" data-ws="${esc(t.ws || '')}" data-done="${t.done ? '0' : '1'}" aria-pressed="${!!t.done}" aria-label="${t.done ? 'Open again' : 'Mark done'}: ${esc(t.title)}" title="${t.done ? 'Open again' : 'Done'}"></button><span class="x">${esc(t.title)}</span>${t.due && !t.done ? `<span class="r${late ? ' late' : ''}">${esc(late ? lateBy(d) : shortDay(t.due))}</span>` : ''}${avHtml(p, t.owner)}</div>`;
221
+ }
222
+ const addHtml = () => (adding ? `<form class="pp-nd l2 pp-add" data-pp-form="task"><input name="t" maxlength="200" autocomplete="off" placeholder="A task on the program" aria-label="A task on the program"><button type="submit" class="bd-ib solid" aria-label="Add the task" title="Add">${SV(I.plus, 15)}</button></form>` : '');
223
+ /** An open task of an initiative or an epic: a check box (a task), its title, where it sits, its day and its owner. It opens in Home. */
224
+ function iniTaskRow(p, t, where) {
225
+ const d = daysTo(t.due), late = d != null && d < 0;
226
+ return `<a class="pp-nd l2 pp-tk" role="treeitem" href="${esc(homeHref({ ws: t.ini.ws, ini: t.ini.id }))}" aria-label="Task: ${esc(t.title)}. Opens in Home"><span class="pp-ck${late ? ' late' : ''}" aria-hidden="true"></span><span class="x">${esc(t.title)}</span>${where ? `<span class="r">${esc(where)}</span>` : ''}${t.due ? `<span class="r${late ? ' late' : ''}">${esc(late ? lateBy(d) : shortDay(t.due))}</span>` : ''}${avHtml(p, t.owner)}</a>`;
227
+ }
228
+ const TREE_TASKS = 3; // an initiative shows its first 3 open tasks in the tree; the rest are one press away in the Tasks tab
229
+ function iniNode(p, st, i, tasks) {
230
+ const k = 'i:' + p.id + ':' + i.id, r = i.row, t = r.track || {}, here = rowsOf(i.ws) && rowsOf(i.ws).here;
231
+ const name = here ? `<button type="button" class="x pp-open" data-pp="ini" data-ini="${esc(i.id)}" aria-haspopup="dialog">${esc(i.title)}</button>` : `<a class="x pp-open" href="${esc(boardHref(i.ws, i.id))}" title="Opens on its product's board">${esc(i.title)}</a>`;
232
+ const stg = t.label || (STEPS[i.at] && STEPS[i.at].label) || i.stage;
233
+ let kids = '';
234
+ if (!fold.has(k)) {
235
+ const you = youOf(i);
236
+ if (you) kids += `<div class="pp-nd l2" role="treeitem"><span class="pp-dt" aria-hidden="true"></span><span class="x">${esc(you)}</span>${avHtml(p, '')}</div>`;
237
+ const mineT = (tasks || []).filter((x) => x.ini === i && x.level === 'initiative');
238
+ kids += mineT.slice(0, TREE_TASKS).map((x) => iniTaskRow(p, x, '')).join('');
239
+ if (mineT.length > TREE_TASKS) kids += `<button type="button" class="pp-nd l2 pp-more" role="treeitem" data-pp="tab" data-tab="tasks">${mineT.length - TREE_TASKS} more ${plural(mineT.length - TREE_TASKS, 'task', 'tasks')}</button>`;
240
+ const tk = t.tickets || [], done = tk.filter((x) => x.status === 'Done').length;
241
+ const epics = r.epics || [];
242
+ epics.forEach((e, j) => { kids += `<div class="pp-nd l2" role="treeitem"><span class="k">${esc(e)}</span><span class="x">${j === 0 && epics.length === 1 && tk.length ? esc(tk.length + ' ' + plural(tk.length, 'ticket', 'tickets')) : ''}</span>${j === 0 && epics.length === 1 && tk.length ? `<span class="r">${done} of ${tk.length} done</span>` : ''}</div>`; });
243
+ const drafted = ((r.trail && r.trail.drafted) || []).filter((x) => !x.key).length;
244
+ if (drafted) kids += `<div class="pp-nd l2 q" role="treeitem"><span class="x">${drafted} draft ${plural(drafted, 'ticket', 'tickets')}, not in Jira yet</span></div>`;
245
+ if (!epics.length && !drafted) kids += `<div class="pp-nd l2 q" role="treeitem"><span class="x">${i.at >= 0 && i.at < PLAN ? 'No epics yet · they come from the work breakdown at Plan' : 'No epic in Jira yet'}</span></div>`;
246
+ }
247
+ return `<div class="pp-nd ini" role="treeitem" aria-expanded="${!fold.has(k)}">${twHtml(k)}${name}${stg ? `<span class="pp-stg">${esc(stg)}</span>` : ''}</div>${kids}`;
248
+ }
249
+ function treeHtml(p, st) {
250
+ const pk = 'p:' + p.id;
251
+ let h = `<div class="pp-nd ini pg" role="treeitem" aria-expanded="${!fold.has(pk)}">${twHtml(pk)}<span class="x">On the program</span>${st.openTasks.length ? `<span class="r">${st.openTasks.length}</span>` : ''}<button type="button" class="bd-ib pp-ibs" data-pp="add" aria-label="Add a task to the program" title="Add a task">${SV(I.plus, 15)}</button></div>`;
252
+ if (!fold.has(pk)) h += st.openTasks.map((t) => taskRow(p, t)).join('') + addHtml() + (!st.openTasks.length && !adding ? '<div class="pp-nd l2 q" role="treeitem"><span class="x">No task on the program itself</span></div>' : '');
253
+ const by = new Map();
254
+ for (const i of st.inis) { if (!by.has(i.product)) by.set(i.product, []); by.get(i.product).push(i); }
255
+ const tasks = iniTasks(st);
256
+ for (const [prod, list] of by) h += `<div class="pp-nd prd2" role="presentation">${tileHtml(st, prod)}${esc(prod || 'This board')}</div>` + list.map((i) => iniNode(p, st, i, tasks)).join('');
257
+ // a member no read board holds: listed by its id with its product's board, never guessed
258
+ for (const m of st.missing) h += `<div class="pp-nd ini q" role="treeitem"><span class="tw"></span><a class="x pp-open" href="${esc(boardHref(m.ws, m.initiative))}" title="Opens on its product's board">${esc(m.initiative)}</a><span class="r">${AWAY.get(m.ws) === 'reading' ? 'reading its board' : 'not read'}</span></div>`;
259
+ return `<div class="pp-tree" role="tree" aria-label="${esc(p.title)}">${h}</div>`;
260
+ }
261
+ /** Every open task of the program and its initiatives, by level (PgProgram "Tasks 54"): on the program, on its initiatives, on their epics. Each
262
+ * level folds. Program tasks are marked done here; the others open in Home, where their initiative keeps them. */
263
+ function tasksHtml(p, st) {
264
+ const done = st.tasks.filter((t) => t.done), dk = 'd:' + p.id, T = iniTasks(st);
265
+ const head = (k, label, n, extra, cls) => `<div class="pp-nd ini${cls || ''}" role="treeitem" aria-expanded="${!fold.has(k)}">${twHtml(k)}<span class="x">${esc(label)}</span>${n ? `<span class="r">${n}</span>` : ''}${extra || ''}</div>`;
266
+ const pk = 'tl:p:' + p.id, ik = 'tl:i:' + p.id, ek = 'tl:e:' + p.id;
267
+ const add = `<button type="button" class="bd-ib pp-ibs" data-pp="add" aria-label="Add a task to the program" title="Add a task">${SV(I.plus, 15)}</button>`;
268
+ let h = head(pk, 'On the program', st.openTasks.length, add, ' pg');
269
+ if (!fold.has(pk)) h += st.openTasks.map((t) => taskRow(p, t)).join('') + addHtml() + (!st.openTasks.length && !adding ? '<div class="pp-nd l2 q" role="treeitem"><span class="x">No task on the program itself</span></div>' : '');
270
+ const L = T.filter((t) => t.level === 'initiative'), E = T.filter((t) => t.level === 'epic');
271
+ if (L.length) h += head(ik, 'On its initiatives', L.length) + (fold.has(ik) ? '' : L.map((t) => iniTaskRow(p, t, t.ini.title)).join(''));
272
+ if (E.length) h += head(ek, 'On their epics', E.length) + (fold.has(ek) ? '' : E.map((t) => iniTaskRow(p, t, [t.epic, t.ini.title].filter(Boolean).join(' · '))).join(''));
273
+ if (done.length) h += head(dk, 'Done on the program', done.length) + (fold.has(dk) ? '' : done.map((t) => taskRow(p, t)).join(''));
274
+ return `<div class="pp-tree" role="tree" aria-label="Tasks of ${esc(p.title)}">${h}</div>`;
275
+ }
276
+ function msHtml(st) {
277
+ const G = milestoneGroups(st);
278
+ return `<div class="pp-ml" role="list">${G.map((g) => {
279
+ const k = 'm:' + st.id + ':' + g.key;
280
+ return `<button type="button" class="pp-mg" data-pp="fold" data-fold="${esc(k)}" aria-expanded="${!fold.has(k)}">${SV(fold.has(k) ? I.chevR : I.chev, 12)}${esc(g.label)} · ${g.items.length}</button>`
281
+ + (fold.has(k) ? '' : g.items.map((m) => {
282
+ // a program check's diamond is its own mark: a press marks it done or open again (POST /api/programs/check)
283
+ const dm = m.check ? `<button type="button" class="pp-dm${m.done ? ' d' : g.key === 'next' ? ' n' : ''}" data-pp="check" data-ms="${esc(m.id)}" data-done="${m.done ? '0' : '1'}" aria-pressed="${m.done}" aria-label="${m.done ? 'Open again' : 'Mark done'}: ${esc(m.name)}" title="${m.done ? 'Open again' : 'Mark done'}"></button>`
284
+ : `<span class="pp-dm${m.done ? ' d' : g.key === 'next' ? ' n' : ''}" aria-hidden="true"></span>`;
285
+ return `<div class="pp-mr${m.done ? ' done' : ''}${m.late ? ' late' : ''}" role="listitem">${dm}<b>${esc(m.name)}</b><span class="d">${m.done ? '' : rdHtml(m)}${esc(m.day)}${m.late ? ' · late' : ''}</span>${m.done ? '' : `<span class="w">${esc(waitsLine(m))}</span>`}</div>`;
286
+ }).join(''));
287
+ }).join('')}</div>`;
288
+ }
289
+ /** The documents of its initiatives on record (PRD, rubric, evaluation, release notes), each opening in the Viewer, and the charter. */
290
+ function docsOf(st) {
291
+ const out = [];
292
+ for (const i of st.inis) {
293
+ const L = (i.row.trail && i.row.trail.links) || {};
294
+ for (const [k, n] of [['prd', 'PRD'], ['rubric', 'Rubric'], ['evaluation', 'Evaluation'], ['notes', 'Release notes']]) if (L[k]) out.push({ name: n, path: L[k], ini: i.title });
295
+ }
296
+ return out;
297
+ }
298
+ function docsHtml(p, st) {
299
+ const D = docsOf(st);
300
+ return `<div class="pp-tree" role="list"><button type="button" class="pp-nd pp-doc" role="listitem" data-pp="charter">${SV(I.doc, 15)}<span class="x">Charter</span><span class="r">${esc(p.title)}</span></button>`
301
+ + D.map((d) => `<button type="button" class="pp-nd pp-doc" role="listitem" data-doc="${esc(d.path)}" title="${esc(d.path)}">${SV(I.doc, 15)}<span class="x">${esc(d.name)}</span><span class="r">${esc(d.ini)}</span></button>`).join('')
302
+ + (D.length ? '' : '<div class="pp-nd q"><span class="x">No PRD, rubric or release notes of its initiatives on this board yet</span></div>') + '</div>';
303
+ }
304
+ function tabsHtml(p, st) {
305
+ const T = [['tree', 'Tree', 0], ['tasks', 'Tasks', st.openTasks.length + iniTasks(st).length], ['ms', 'Milestones', st.milestones.length], ['docs', 'Documents', docsOf(st).length + 1]];
306
+ const body = tab === 'tasks' ? tasksHtml(p, st) : tab === 'ms' ? msHtml(st) : tab === 'docs' ? docsHtml(p, st) : treeHtml(p, st);
307
+ return `<div class="pp-sec"><div class="pp-tabs" role="tablist" aria-label="${esc(p.title)}">${T.map(([k, n, c]) => `<button type="button" role="tab" class="pp-tab" data-pp="tab" data-tab="${k}" aria-selected="${tab === k}">${n}${c ? ` <span class="n">${c}</span>` : ''}</button>`).join('')}</div>${body}</div>`;
308
+ }
309
+
310
+ /* ── drawing, opening, closing ── */
311
+ function html(p) {
312
+ const st = programState(p, rowsOf);
313
+ return headHtml(p, st) + `<div class="pk-b pp-b">${goalsHtml(st)}${trackHtml(st)}${needsHtml(p, st)}${sortHtml(p, st)}${tabsHtml(p, st)}</div>`;
314
+ }
315
+ function draw(keepFocus) {
316
+ if (!cur || !el) return;
317
+ const p = progOf(cur.id); if (!p) { closePanel(); return; }
318
+ readAway(p); readMore(p);
319
+ const f = keepFocus && document.activeElement && el.contains(document.activeElement) ? document.activeElement : null;
320
+ const sel = f ? (f.dataset.pp ? `[data-pp="${f.dataset.pp}"]` + (f.dataset.tab ? `[data-tab="${f.dataset.tab}"]` + (f.dataset.cap ? `[data-cap="${f.dataset.cap}"]` : ':not([data-cap])') : '') + (f.dataset.fold ? `[data-fold="${CSS.escape(f.dataset.fold)}"]` : '') + (f.dataset.key ? `[data-key="${CSS.escape(f.dataset.key)}"]` : '') + (f.dataset.ms ? `[data-ms="${CSS.escape(f.dataset.ms)}"]` : '') : null) : null;
321
+ const top = (el.querySelector('.pp-b') || {}).scrollTop || 0;
322
+ el.innerHTML = html(p);
323
+ const b = el.querySelector('.pp-b'); if (b) b.scrollTop = top;
324
+ const again = sel && el.querySelector(sel); if (again) again.focus();
325
+ document.querySelectorAll('#ibBody [data-prow]').forEach((x) => x.classList.toggle('sel', x.dataset.prow === cur.id));
326
+ }
327
+ function openPanel(id, back) {
328
+ if (!O || !O.M() || !progOf(id)) return false;
329
+ const peek = document.getElementById('peek');
330
+ if (peek && !peek.hidden) O.close();
331
+ cur = { id, back: back && !el.contains(back) ? back : (cur && cur.back) || null };
332
+ menuOpen = false; adding = false; period = null; O._perOpen = false;
333
+ el.hidden = false; document.body.classList.add('pk-on');
334
+ draw();
335
+ const h = el.querySelector('#ppTitle'); if (h) { h.tabIndex = -1; h.focus({ preventScroll: true }); }
336
+ return true;
337
+ }
338
+ function closePanel() {
339
+ if (!el || el.hidden) return;
340
+ el.hidden = true; el.innerHTML = '';
341
+ const peek = document.getElementById('peek');
342
+ if (!peek || peek.hidden) document.body.classList.remove('pk-on');
343
+ document.querySelectorAll('#ibBody [data-prow].sel').forEach((x) => x.classList.remove('sel'));
344
+ const back = cur && cur.back && document.contains(cur.back) ? cur.back : cur ? document.querySelector(`#ibBody [data-prog="${CSS.escape(cur.id)}"]`) : null;
345
+ cur = null;
346
+ if (back) back.focus();
347
+ }
348
+ function setFold(k) { if (fold.has(k)) fold.delete(k); else fold.add(k); keepFold(); draw(true); }
349
+
350
+ async function press(b) {
351
+ const a = b.dataset.pp, p = cur && progOf(cur.id); if (!p) return;
352
+ if (a === 'close') closePanel();
353
+ else if (a === 'menu') { menuOpen = !menuOpen; draw(true); }
354
+ else if (a === 'fold') setFold(b.dataset.fold);
355
+ else if (a === 'tab') { tab = b.dataset.tab; capOn = b.dataset.cap || ''; store.set(TAB_KEY, tab); draw(true); }
356
+ else if (a === 'period') { O._perOpen = !O._perOpen; draw(true); }
357
+ else if (a === 'per' || a === 'early') { period = b.dataset.per; O._perOpen = false; draw(); const pb = el.querySelector('[data-pp="period"]'); if (pb) pb.focus(); }
358
+ else if (a === 'ini') { const id = b.dataset.ini; closePanel(); O.openIni(id, document.querySelector(`#ibBody [data-prog="${CSS.escape(p.id)}"]`)); }
359
+ else if (a === 'add') { adding = true; if (tab !== 'tasks') { tab = 'tree'; fold.delete('p:' + p.id); } else fold.delete('tl:p:' + p.id); draw(); const i = el.querySelector('.pp-add input'); if (i) i.focus(); }
360
+ else if (a === 'charter') openCharter(p);
361
+ else if (a === 'done') {
362
+ const r = await pmPost('/api/programs/task-done', { ws: b.dataset.ws || p.home || board().ws || null, program: p.id, key: b.dataset.key, done: b.dataset.done === '1' });
363
+ if (!r || !r.ok) { O.say((r && r.error) || 'Not marked. The server did not say why.'); return; }
364
+ O.say(b.dataset.done === '1' ? 'Done.' : 'Open again.'); O.reload();
365
+ } else if (a === 'check') {
366
+ const r = await pmPost('/api/programs/check', { program: p.id, milestone: b.dataset.ms, done: b.dataset.done === '1' });
367
+ if (!r || !r.ok) { O.say((r && r.error) || 'Not marked. The server did not say why.'); return; }
368
+ O.say(b.dataset.done === '1' ? 'Marked done.' : 'Open again.'); O.reload();
369
+ } else if (a === 'new') { menuOpen = false; closePanel(); const n = document.getElementById('newIni'); if (n) n.click(); }
370
+ else if (a === 'join') {
371
+ menuOpen = false;
372
+ const r = await pmPost('/api/programs/member', { ws: board().ws || null, program: p.id, initiative: b.dataset.ini });
373
+ if (!r || !r.ok) { O.say((r && r.error) || 'It did not move in. The server did not say why.'); draw(); return; }
374
+ O.say('Moved into ' + p.title + '.'); O.reload();
375
+ } else if (a === 'archive') {
376
+ if (b.dataset.sure !== '1') { b.dataset.sure = '1'; b.textContent = 'Press again to archive ' + p.title; return; } // an inline confirmation, no browser dialog
377
+ const r = await pmPost('/api/programs/archive', { ws: p.home || board().ws || null, program: p.id });
378
+ if (!r || !r.ok) { O.say((r && r.error) || 'Not archived. The server did not say why.'); return; }
379
+ O.say(p.title + ' is archived. Its initiatives stay where they are.'); closePanel(); O.reload();
380
+ }
381
+ }
382
+ /** The charter in the Viewer: why, goal, owner, span and the Jira key, as the program record holds them. */
383
+ function openCharter(p) {
384
+ const st = programState(p, rowsOf);
385
+ viewerOpen({ kind: 'Charter', title: p.title, icon: 'doc', id: 'program:' + p.id, render: (body) => {
386
+ const rows = [['Goal', p.goal], ['Why', p.why], ['Owner', p.owner], ['Span', st.span.label], ['Products', st.products.join(', ')], ['Jira', p.jira]].filter(([, v]) => v);
387
+ body.innerHTML = rows.length ? `<dl class="pp-cdl">${rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`).join('')}</dl>` : '<p class="bd-amut">The charter holds only the program\'s name so far.</p>';
388
+ } });
389
+ }
390
+
391
+ /* ── the width: 60 % of the window on desktop, 50 to 70 % by the grip on the panel's edge (XnAgBoardPanel) ── */
392
+ let grip = null;
393
+ const widthOf = () => { const v = Number(store.get(W_KEY)); return v >= 50 && v <= 70 ? v : 60; };
394
+ function setWidth(v) {
395
+ const w = Math.max(50, Math.min(70, Math.round(v)));
396
+ document.documentElement.style.setProperty('--bd-pkw', w + 'vw');
397
+ if (grip) grip.setAttribute('aria-valuenow', String(w));
398
+ return w;
399
+ }
400
+ function mountGrip() {
401
+ grip = document.createElement('div');
402
+ grip.className = 'pk-grip'; grip.tabIndex = 0;
403
+ for (const [k, v] of [['role', 'separator'], ['aria-orientation', 'vertical'], ['aria-label', 'Panel width'], ['aria-valuemin', '50'], ['aria-valuemax', '70'], ['title', 'Drag to change the panel width']]) grip.setAttribute(k, v);
404
+ document.body.appendChild(grip);
405
+ setWidth(widthOf());
406
+ let drag = false;
407
+ grip.addEventListener('pointerdown', (e) => { if (PHONE.matches) return; drag = true; grip.setPointerCapture(e.pointerId); grip.classList.add('on'); });
408
+ grip.addEventListener('pointermove', (e) => { if (drag) setWidth(((innerWidth - 16 - e.clientX) / innerWidth) * 100); });
409
+ const end = () => { if (!drag) return; drag = false; grip.classList.remove('on'); store.set(W_KEY, String(Number(grip.getAttribute('aria-valuenow')))); };
410
+ grip.addEventListener('pointerup', end); grip.addEventListener('pointercancel', end);
411
+ grip.addEventListener('keydown', (e) => {
412
+ const d = e.key === 'ArrowLeft' ? 2 : e.key === 'ArrowRight' ? -2 : 0;
413
+ if (!d && e.key !== 'Home') return;
414
+ e.preventDefault(); store.set(W_KEY, String(setWidth(e.key === 'Home' ? 60 : Number(grip.getAttribute('aria-valuenow')) + d)));
415
+ });
416
+ }
417
+
418
+ export function mount(o) {
419
+ if (O) return;
420
+ O = o;
421
+ el = document.createElement('aside');
422
+ el.className = 'bd-peek pp-peek'; el.id = 'ppPeek'; el.hidden = true; el.setAttribute('aria-labelledby', 'ppTitle');
423
+ (document.getElementById('stage') || document.body).appendChild(el);
424
+ mountGrip();
425
+ el.addEventListener('click', (e) => {
426
+ if (menuOpen && !e.target.closest('.pp-menu, [data-pp="menu"]')) { menuOpen = false; draw(); }
427
+ const b = e.target.closest('[data-pp]'); if (b && el.contains(b)) press(b);
428
+ });
429
+ el.addEventListener('submit', async (e) => {
430
+ const f = e.target.closest('[data-pp-form="task"]'); if (!f) return;
431
+ e.preventDefault();
432
+ const p = cur && progOf(cur.id), title = f.t.value.trim(); if (!p) return;
433
+ if (!title) { adding = false; draw(); return; }
434
+ const r = await pmPost('/api/programs/task', { ws: p.home || board().ws || null, program: p.id, title });
435
+ if (!r || !r.ok) { O.say((r && r.error) || 'The task was not added. The server did not say why.'); return; }
436
+ adding = false; O.say('Added to ' + p.title + '.'); O.reload();
437
+ });
438
+ // a program row of the Board, and ?program=<id> once the Board has unfolded and scrolled to it, send bd:program (pm/bd-prog.js openProgram)
439
+ document.addEventListener('bd:program', (e) => { const d = e.detail || {}; if (d.id) openPanel(String(d.id), d.from || document.activeElement); });
440
+ document.addEventListener('keydown', (e) => {
441
+ if (e.key !== 'Escape' || !cur) return;
442
+ if (menuOpen || O._perOpen) { menuOpen = false; O._perOpen = false; draw(); return; }
443
+ closePanel();
444
+ });
445
+ // the Board's own panel and this one share the place: when the Board opens its panel, this one closes
446
+ const peek = document.getElementById('peek');
447
+ if (peek) new MutationObserver(() => { if (!peek.hidden && cur) { const keep = document.body.classList.contains('pk-on'); closePanel(); if (keep) document.body.classList.add('pk-on'); } }).observe(peek, { attributes: true, attributeFilter: ['hidden'] });
448
+ // a new read draws the rows again: the open panel follows it
449
+ const body = document.getElementById('ibBody');
450
+ if (body) new MutationObserver(() => { if (cur && !el.contains(document.activeElement)) draw(); }).observe(body, { childList: true });
451
+ }