create-pmos 0.402.0 → 0.404.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 (110) hide show
  1. package/package.json +25 -30
  2. package/payload/AGENTS.md +2 -0
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/mods/pmos-cockpit/hooks/lib/session-facts.mjs +1 -1
  5. package/payload/planning/evals/eval-calibration.md +1 -1
  6. package/payload/planning/okrs/health-budgets.md +1 -1
  7. package/payload/state/discoveries.md +1 -1
  8. package/workspace/board-programs-test.js +32 -5
  9. package/workspace/briefing-premium-adddoc-test.js +28 -22
  10. package/workspace/briefing-premium-board-test.js +91 -73
  11. package/workspace/briefing-premium-calendar-2-test.js +23 -10
  12. package/workspace/briefing-premium-calendar-3-test.js +23 -19
  13. package/workspace/briefing-premium-calendar-test.js +19 -17
  14. package/workspace/briefing-premium-initiative-test.js +25 -12
  15. package/workspace/briefing-premium-insights-test.js +31 -18
  16. package/workspace/briefing-premium-metrics-test.js +8 -8
  17. package/workspace/briefing-premium-test.js +4 -3
  18. package/workspace/changelog.json +24 -0
  19. package/workspace/fixtures/premium-viewer-fixtures.js +24 -2
  20. package/workspace/guide/jira.md +38 -6
  21. package/workspace/guide/programs.md +2 -0
  22. package/workspace/home-rows-test.js +184 -0
  23. package/workspace/lib/briefing-premium-agent.js +3 -0
  24. package/workspace/lib/calendar-layers.js +8 -4
  25. package/workspace/lib/initiative-layout.js +4 -3
  26. package/workspace/lib/jira-cli.js +17 -12
  27. package/workspace/lib/jira-status.js +1 -1
  28. package/workspace/lib/jira-tickets.js +126 -24
  29. package/workspace/lib/meeting-files.js +58 -0
  30. package/workspace/lib/meeting-learn.js +139 -0
  31. package/workspace/lib/meeting-material.js +12 -5
  32. package/workspace/lib/notes.js +3 -0
  33. package/workspace/lib/program-chat.js +32 -0
  34. package/workspace/lib/routes-brief-page.js +8 -1
  35. package/workspace/lib/routes-calendar-views.js +24 -3
  36. package/workspace/lib/routes-meeting-material.js +38 -0
  37. package/workspace/lib/routes-meeting-points.js +23 -3
  38. package/workspace/package-lock.json +2 -2
  39. package/workspace/package.json +1 -1
  40. package/workspace/premium-board-actions-test.js +30 -24
  41. package/workspace/premium-chat-context-test.js +1 -1
  42. package/workspace/premium-chat-goal-view-test.js +1 -1
  43. package/workspace/premium-chat-viewer-test.js +1 -1
  44. package/workspace/premium-core-doc-issue-test.js +13 -7
  45. package/workspace/premium-discuss-landing-test.js +83 -0
  46. package/workspace/premium-link-suggest-test.js +103 -0
  47. package/workspace/premium-report-read-test.js +86 -82
  48. package/workspace/premium-vw-backlog-test.js +6 -5
  49. package/workspace/premium-vw-cal-test.js +46 -23
  50. package/workspace/premium-vw-item-test.js +8 -6
  51. package/workspace/premium-vw-jira-test.js +3 -2
  52. package/workspace/premium-vw-meet-test.js +122 -66
  53. package/workspace/premium-vw-notes-test.js +7 -6
  54. package/workspace/premium-vw-rec-test.js +14 -13
  55. package/workspace/premium-vw-slides-test.js +11 -5
  56. package/workspace/program-panel-test.js +64 -55
  57. package/workspace/public/pm/bd-acts.js +1 -1
  58. package/workspace/public/pm/bd-asks.js +22 -7
  59. package/workspace/public/pm/bd-ini-panel.js +232 -0
  60. package/workspace/public/pm/bd-pop.js +2 -2
  61. package/workspace/public/pm/bd-prog-panel.js +176 -191
  62. package/workspace/public/pm/cozy-board.css +5 -28
  63. package/workspace/public/pm/cozy-evui.js +4 -2
  64. package/workspace/public/pm/cozy-home-rows.css +54 -0
  65. package/workspace/public/pm/cozy-home.css +9 -0
  66. package/workspace/public/pm/cozy-insights.css +1 -2
  67. package/workspace/public/pm/cozy-mtg-present.css +160 -0
  68. package/workspace/public/pm/cozy-panel.css +11 -34
  69. package/workspace/public/pm/cozy-rec-pill.css +12 -0
  70. package/workspace/public/pm/cozy-rec-pill.js +46 -0
  71. package/workspace/public/pm/cozy-viewer.js +307 -43
  72. package/workspace/public/pm/cozy-vw-mtg.css +96 -94
  73. package/workspace/public/pm/cozy-vw-rp.css +40 -25
  74. package/workspace/public/pm/cozy-vw-shell.css +127 -0
  75. package/workspace/public/pm/cozy-xv.css +51 -0
  76. package/workspace/public/pm/cozy-xv.js +34 -0
  77. package/workspace/public/pm/goal-chat.js +1 -1
  78. package/workspace/public/pm/home-app.js +122 -58
  79. package/workspace/public/pm/home-chat.js +11 -2
  80. package/workspace/public/pm/home-day.js +64 -0
  81. package/workspace/public/pm/home-ini-model.js +1 -1
  82. package/workspace/public/pm/home-ini.js +197 -54
  83. package/workspace/public/pm/home-list.js +6 -14
  84. package/workspace/public/pm/home-mentions.js +187 -0
  85. package/workspace/public/pm/home-rec-row.js +67 -0
  86. package/workspace/public/pm/home-review.js +20 -10
  87. package/workspace/public/pm/home-task.js +19 -18
  88. package/workspace/public/pm/home-today.js +3 -3
  89. package/workspace/public/pm/premium-board.js +83 -235
  90. package/workspace/public/pm/premium-insights.js +118 -82
  91. package/workspace/public/pm/premium-mtg-present.js +408 -100
  92. package/workspace/public/pm/premium-mtg-replay.js +70 -10
  93. package/workspace/public/pm/premium-report-read.js +118 -63
  94. package/workspace/public/pm/premium-vw-cal.js +62 -34
  95. package/workspace/public/pm/premium-vw-mtg.js +348 -192
  96. package/workspace/public/pm/rec-state.js +63 -0
  97. package/workspace/public/pm/rp-parts.js +33 -8
  98. package/workspace/public/pm/tk-draft.js +107 -0
  99. package/workspace/public/pm/tk-model.js +134 -0
  100. package/workspace/public/pm/tk-send.js +124 -0
  101. package/workspace/public/pm/tk-tasks.css +120 -0
  102. package/workspace/public/premium-board.html +0 -1
  103. package/workspace/server.js +4 -2
  104. package/workspace/skills/jira-push.skill +3 -3
  105. package/workspace/test-lists/prd-to-jira.json +6 -0
  106. package/workspace/test-lists/program-chat.json +6 -0
  107. package/workspace/test-lists/viewer-home-rows.json +9 -0
  108. package/workspace/test-lists/viewer-meetings.json +9 -0
  109. package/workspace/test-lists/viewer-shell-a.json +15 -0
  110. package/workspace/tk-tasks-test.js +199 -0
@@ -1,53 +1,50 @@
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).
1
+ /* pm/bd-prog-panel.js — the program panel on the Board (initiative program-hierarchy, P5, P9; canvas PgProgram, PgMilestones), in the Viewer's
2
+ * shell A since the second kit (initiative viewer-shell-a, V9): the shell's header, summary card and folding rows in place of the panel's own
3
+ * head and tabs. The content is the same. The shell floats at 560 px over the page's right edge and does not push the page.
3
4
  *
4
5
  * 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
+ * of a row of this board, close() what the shell shows for the Board, reload() reads the programs again, say(msg) the toast }
6
7
  *
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.
8
+ * The panel opens on document `bd:program` { id, from? }. A program row of the Board ([data-prog]) and ?program=<id> (Home links there) send
9
+ * that event through pm/bd-prog.js openProgram, the one path that opens it.
10
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
11
+ * What it shows, each part only when a record holds something for it:
12
+ * · the shell's header: the program icon, "title · goal" once, Discuss in chat (the question goes to Home), ⋯ and Close. ⋯ holds, in the
13
+ * shell's order: add an initiative, move one in, the charter, copy link, copy as text, and archive (red, last, with a confirmation)
14
+ * · the summary card: the next milestone, else what waits on you; the owner and the span; one primary, "Review the suggested homes", only
15
+ * after Turn into a program while tasks of the initiative it came from have no level yet; Claude sorts them in Home
13
16
  * · 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. */
17
+ * · the milestone track: 3 milestones, the earlier done ones in a done cluster and the later ones in "N more"; both open Milestones
18
+ * · the folding rows (were tabs): Waits on you · On the program (its tasks, Done folded) · On its initiatives and On their epics (every
19
+ * open task, by level; each opens in Home) · Initiatives (per product, with their first tasks, what waits on you and their epics) · Milestones (Done, Next, Later; a program check's diamond marks it) · Documents (the charter, the PRDs, …)
20
+ * An initiative in another product is read from that product's board (GET /api/board-premium?ws=). Per product the panel also reads, once per
21
+ * page load: its KRs' names (GET /api/boards/anchors, the OKR files), whether each KR is met (GET /api/insights-premium, the goals Insights
22
+ * shows) and its PMOS tasks (GET /api/boards/items). A part whose read failed is left out, never guessed. Every fold is kept in this browser. */
23
23
  import { pmPost } from './http.js';
24
24
  import { esc, store } from './premium-shell.js';
25
25
  import { programState, milestoneTrack, milestoneGroups, goalsByPeriod, shortDay } from './program-model.js';
26
26
  import { STEPS } from './premium-initiative-head.js';
27
- import { open as viewerOpen } from './cozy-viewer.js';
27
+ import * as VW from './cozy-viewer.js';
28
+ import * as Pop from './bd-pop.js';
29
+ import { copyText } from './cozy-xv.js';
28
30
 
29
31
  const SV = (d, w) => `<svg viewBox="0 0 24 24" width="${w || 18}" height="${w || 18}" aria-hidden="true"><path d="${d}"/></svg>`;
30
32
  const I = {
31
33
  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
34
  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
35
  };
34
- const FOLD_KEY = 'pmos.board.ppfold', TAB_KEY = 'pmos.board.pptab', W_KEY = 'pmos.board.pkw';
36
+ const FOLD_KEY = 'pmos.board.ppfold';
35
37
  const PLAN = STEPS.findIndex((s) => s.key === 'plan');
36
38
  const plural = (n, a, b) => (n === 1 ? a : b);
37
39
  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
40
  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
41
  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
42
  const lateBy = (d) => -d + ' ' + plural(-d, 'day', 'days') + ' late';
41
- const PHONE = matchMedia('(max-width: 720px)');
42
43
 
43
44
  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';
45
+ let cur = null; // { id, from } the program shown and the element it was opened from
47
46
  let period = null; // the year half the goals show (null: the current one)
48
47
  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
48
  const fold = new Set((() => { try { return JSON.parse(store.get(FOLD_KEY) || '[]'); } catch { return []; } })());
52
49
  const keepFold = () => store.set(FOLD_KEY, JSON.stringify([...fold].slice(-200)));
53
50
  const AWAY = new Map(); // the boards of the other products: ws → { name, board, rows } | 'reading'
@@ -100,13 +97,13 @@ function readMore(p) {
100
97
  });
101
98
  }
102
99
  }
103
- const moreOf = (ws) => MORE.get(ws || board().ws || '') || {};
100
+ const moreAt = (ws) => MORE.get(ws || board().ws || '') || {};
104
101
  /** 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] || '';
102
+ const youOf = (i) => (i.row.track && i.row.track.you) || (moreAt(i.ws).you || {})[i.id] || '';
106
103
  /** 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
104
  * 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
105
  function krsOf(anchor, i) {
109
- const x = moreOf(i.ws), [, o, k] = String(anchor).split(':'), want = (o + '.' + k).toUpperCase(), out = {};
106
+ const x = moreAt(i.ws), [, o, k] = String(anchor).split(':'), want = (o + '.' + k).toUpperCase(), out = {};
110
107
  const a = (x.anchors || []).find((y) => y.kind === 'kr' && String(y.value).toUpperCase() === want);
111
108
  if (a) out.name = String(a.label || '').replace(/^\S+\s+/, '').replace(/\.$/, '');
112
109
  const raw = String((i.row && (i.row.anchor || i.row.parent_kr)) || '');
@@ -122,7 +119,7 @@ function krsOf(anchor, i) {
122
119
  function iniTasks(st) {
123
120
  const out = [];
124
121
  for (const i of st.inis) {
125
- const items = moreOf(i.ws).items || [];
122
+ const items = moreAt(i.ws).items || [];
126
123
  for (const t of items) {
127
124
  if (t.src !== 'pmos' || t.kind === 'Epic' || t.ini !== i.id || t.status === 'Done') continue;
128
125
  const e = t.epic ? items.find((y) => y.uid === t.epic) : null;
@@ -131,27 +128,14 @@ function iniTasks(st) {
131
128
  }
132
129
  return out.sort((a, b) => String(a.due || '9999').localeCompare(String(b.due || '9999')));
133
130
  }
131
+ /** After Turn into a program (p.from names the initiative it came from): that initiative's open tasks on no epic have no level yet. */
132
+ const unsorted = (p, st) => (p.from ? iniTasks(st).filter((t) => t.ini.id === p.from && (!t.ini.ws || !p.home || t.ini.ws === p.home) && t.level === 'initiative').length : 0);
134
133
  /** Your program task: its owner is the program's owner (the PM who keeps the charter), or it has none. */
135
134
  const mine = (p, t) => !t.owner || (p.owner && t.owner.toLowerCase() === p.owner.toLowerCase());
136
135
  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
136
  const boardHref = (ws, id) => '/premium-board.html?ws=' + encodeURIComponent(ws) + (id ? '&focus=' + encodeURIComponent(id) : '');
138
137
 
139
138
  /* ── 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
139
  /** The products' tiles: the first product blue, the second warm, the third grey, as the frames draw them. */
156
140
  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
141
  function goalsHtml(st) {
@@ -180,7 +164,7 @@ function trackHtml(st) {
180
164
  const lastDone = T.shown.map((m) => m.done).lastIndexOf(true);
181
165
  // 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
166
  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>'; };
167
+ const cl = (L, done) => (L.length ? `<button type="button" class="pp-cap${done ? ' dn' : ''}" data-pp="ms" 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
168
  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
169
  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
170
  }
@@ -198,21 +182,7 @@ function needs(p, st) {
198
182
  }
199
183
  return out;
200
184
  }
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 ── */
185
+ /* ── the folding rows (were the tabs Tree, Tasks, Milestones, Documents) ── */
216
186
  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
187
  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
188
  function taskRow(p, t) {
@@ -225,7 +195,7 @@ function iniTaskRow(p, t, where) {
225
195
  const d = daysTo(t.due), late = d != null && d < 0;
226
196
  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
197
  }
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
198
+ const TREE_TASKS = 3; // an initiative shows its first 3 open tasks in the tree; the rest are one press away in "On its initiatives"
229
199
  function iniNode(p, st, i, tasks) {
230
200
  const k = 'i:' + p.id + ':' + i.id, r = i.row, t = r.track || {}, here = rowsOf(i.ws) && rowsOf(i.ws).here;
231
201
  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>`;
@@ -236,7 +206,7 @@ function iniNode(p, st, i, tasks) {
236
206
  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
207
  const mineT = (tasks || []).filter((x) => x.ini === i && x.level === 'initiative');
238
208
  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>`;
209
+ if (mineT.length > TREE_TASKS) kids += `<button type="button" class="pp-nd l2 pp-more" role="treeitem" data-pp="itasks">${mineT.length - TREE_TASKS} more ${plural(mineT.length - TREE_TASKS, 'task', 'tasks')}</button>`;
240
210
  const tk = t.tickets || [], done = tk.filter((x) => x.status === 'Done').length;
241
211
  const epics = r.epics || [];
242
212
  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>`; });
@@ -246,32 +216,28 @@ function iniNode(p, st, i, tasks) {
246
216
  }
247
217
  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
218
  }
219
+ /** The initiatives, per product, each with its first tasks, what waits on you and its epics; a member no read board holds is listed by its id. */
249
220
  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>' : '');
221
+ let h = '';
222
+ const tasks = iniTasks(st);
253
223
  const by = new Map();
254
224
  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
225
  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
226
  // a member no read board holds: listed by its id with its product's board, never guessed
258
227
  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>`;
228
+ return h ? `<div class="pp-tree" role="tree" aria-label="${esc(p.title)}">${h}</div>` : '';
260
229
  }
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. */
230
+ /** The program's own tasks: the open ones, the add line, and the done ones folded. */
263
231
  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>`;
232
+ const done = st.tasks.filter((t) => t.done), dk = 'd:' + p.id;
233
+ const add = adding ? addHtml() : `<button type="button" class="pp-nd pp-doc" data-pp="add">${SV(I.plus, 15)}<span class="x">Add a task</span></button>`;
234
+ if (!st.tasks.length && !adding) return `<div class="pp-tree"><div class="pp-nd q"><span class="x">No task on the program itself. Its initiatives keep their own tasks in Home.</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></div>`;
235
+ return `<div class="pp-tree" role="tree" aria-label="Tasks on the program">${st.openTasks.map((t) => taskRow(p, t)).join('')}${add}`
236
+ + (done.length ? `<div class="pp-nd ini" role="treeitem" aria-expanded="${!fold.has(dk)}">${twHtml(dk)}<span class="x">Done on the program</span><span class="r">${done.length}</span></div>${fold.has(dk) ? '' : done.map((t) => taskRow(p, t)).join('')}` : '') + '</div>';
237
+ }
238
+ /** The open tasks of its initiatives at one level (on the initiative, or on one of its epics); each opens in Home, where its initiative keeps it. */
239
+ function levelHtml(p, L, label) {
240
+ return `<div class="pp-tree" role="tree" aria-label="${esc(label)}">${L.map((t) => iniTaskRow(p, t, t.level === 'epic' ? [t.epic, t.ini.title].filter(Boolean).join(' · ') : t.ini.title)).join('')}</div>`;
275
241
  }
276
242
  function msHtml(st) {
277
243
  const G = milestoneGroups(st);
@@ -301,62 +267,119 @@ function docsHtml(p, st) {
301
267
  + 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
268
  + (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
269
  }
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>`;
270
+ /** The charter in the Viewer, as a drill-in: ← comes back to the program. Why, goal, owner, span and the Jira key, as the record holds them. */
271
+ function openCharter(p) {
272
+ const st = programState(p, rowsOf);
273
+ VW.open({ kind: 'Charter', title: p.title, icon: 'doc', id: 'charter:' + p.id, back: true, render: (body) => {
274
+ 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);
275
+ 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>';
276
+ } });
308
277
  }
309
278
 
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>`;
279
+ /* ── the shell: summary first, then the folding rows ── */
280
+ /** The summary card: the next milestone (else what waits on you); the owner and the span; one primary only when tasks from before Turn into a
281
+ * program (p.from) still have no level. */
282
+ function summaryOf(p, st) {
283
+ const N = needs(p, st), n = unsorted(p, st), nx = st.next;
284
+ const meta = [p.owner, st.span.label].filter(Boolean).join(' · ');
285
+ const sortText = n ? n + ' ' + plural(n, 'task', 'tasks') + ' from before the split ' + (n === 1 ? 'has' : 'have') + ' no level yet. Claude suggests a home for each: the program, an initiative or an epic.' : '';
286
+ const primary = n ? { label: 'Review the suggested homes', href: homeHref({ ws: p.home, ask: 'program:' + p.id, q: 'Suggest a home for each task of ' + p.title + ' that has no level yet' }) } : null;
287
+ const next = nx ? 'Next: ' + nx.name + (nx.day ? ' · ' + nx.day : '') : '';
288
+ // The Waits on you row already counts what waits on you (say it once), so the line is the next milestone while there is one.
289
+ if (!nx && N.length) return { line: N.length + ' ' + plural(N.length, 'waits', 'wait') + ' on you', tone: 'you', text: sortText, meta, primary };
290
+ if (nx) return { line: next, tone: nx.late ? 'warn' : '', text: sortText || waitsLine(nx) + (nx.check ? '.' : ' reaching Deliver.'), meta, primary };
291
+ return { line: '', text: sortText, meta, primary };
292
+ }
293
+ function needsList(p, st) {
294
+ const L = needs(p, st);
295
+ return 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('');
296
+ }
297
+ function bodyHtml(p) {
298
+ const st = programState(p, rowsOf), N = needs(p, st), D = docsOf(st), T = iniTasks(st);
299
+ const L = T.filter((t) => t.level === 'initiative'), E = T.filter((t) => t.level === 'epic');
300
+ const rows = [
301
+ N.length ? { id: 'needs', title: 'Waits on you', count: N.length, open: true, render: () => `<div class="pp-needs" role="group" aria-label="Waits on you">${needsList(p, st)}</div>` } : null,
302
+ { id: 'tasks', title: 'On the program', count: st.openTasks.length, open: adding, render: () => tasksHtml(p, st) },
303
+ // every open task of its initiatives, by level (PgProgram "Tasks"): on the initiative itself, then on their epics
304
+ L.length ? { id: 'itasks', title: 'On its initiatives', count: L.length, render: () => levelHtml(p, L, 'Tasks on its initiatives') } : null,
305
+ E.length ? { id: 'etasks', title: 'On their epics', count: E.length, render: () => levelHtml(p, E, 'Tasks on their epics') } : null,
306
+ st.inis.length || st.missing.length ? { id: 'tree', title: 'Initiatives', count: st.inis.length + st.missing.length, open: true, render: () => treeHtml(p, st) } : null,
307
+ st.milestones.length ? { id: 'ms', title: 'Milestones', count: st.milestones.length, render: () => msHtml(st) } : null,
308
+ { id: 'docs', title: 'Documents', count: D.length + 1, render: () => docsHtml(p, st) },
309
+ ];
310
+ return VW.czSummary(summaryOf(p, st)) + goalsHtml(st) + trackHtml(st) + VW.czSections(rows, { key: 'program' });
314
311
  }
312
+ const shownHere = () => { const c = VW.current && VW.current(); return !!(cur && c && c.id === 'program:' + cur.id); };
313
+ /** Draws the program again in place, keeping the scroll and the focus on the same press. */
315
314
  function draw(keepFocus) {
316
- if (!cur || !el) return;
317
- const p = progOf(cur.id); if (!p) { closePanel(); return; }
315
+ if (!cur || !shownHere()) return;
316
+ const p = progOf(cur.id); if (!p) { VW.close(); return; }
318
317
  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));
318
+ const b = VW.body(); if (!b) return;
319
+ const f = keepFocus && document.activeElement && b.contains(document.activeElement) ? document.activeElement : null;
320
+ const sel = f ? (f.dataset.pp ? `[data-pp="${f.dataset.pp}"]` + (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)}"]` : '') : f.dataset.czsFold ? `[data-czs-fold="${CSS.escape(f.dataset.czsFold)}"]` : null) : null;
321
+ const top = b.scrollTop;
322
+ b.innerHTML = bodyHtml(p);
323
+ b.scrollTop = top;
324
+ const again = sel && b.querySelector(sel); if (again) again.focus();
326
325
  }
327
- function openPanel(id, back) {
326
+ /** ⋯ in the shell's order: change it (add, move in), look back (the charter), copy, then archive in red, last. */
327
+ function moreOf(p) {
328
+ 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)));
329
+ const free = ((M && M.rows) || []).filter((r) => r.id && r.track && !taken.has(r.id)).slice(0, 8);
330
+ const more = [{ label: 'Add a new initiative', on: () => { VW.close(); const n = document.getElementById('newIni'); if (n) n.click(); } }];
331
+ if (free.length) more.push({ label: 'Move an initiative in', on: (b) => Pop.open(`<p class="bd-mlbl">Move an initiative into ${esc(p.title)}</p>${free.map((r) => `<button type="button" class="bd-mi" role="menuitem" data-ppjoin="${esc(r.id)}">${esc(r.title)}</button>`).join('')}`, b, { label: 'Move an initiative in', role: 'menu', width: 280, align: 'right', cls: 'bd-menu', focus: '.bd-mi' }) });
332
+ more.push({ label: 'Add a task to the program', on: () => { adding = true; try { localStorage.setItem('cz-vw-fold:program:tasks', '1'); } catch { /* a private window */ } draw(); const i = VW.body() && VW.body().querySelector('.pp-add input'); if (i) i.focus(); } });
333
+ more.push({ sep: true }, { label: 'Open the charter', on: () => openCharter(p) });
334
+ more.push({ sep: true }, { label: 'Copy link', on: () => copyText(new URL('/premium-board.html?' + (p.home ? 'ws=' + encodeURIComponent(p.home) + '&' : '') + 'program=' + encodeURIComponent(p.id), location.href).href, 'Link copied.') },
335
+ { label: 'Copy as text', on: () => copyText(textOf(p), 'Copied as text.') });
336
+ more.push({ sep: true }, { label: 'Archive the program', danger: true, on: (b) => Pop.open(`<p class="bd-mlbl">Archive ${esc(p.title)}?</p><div class="bd-ppb"><p class="bd-amut">Its initiatives stay where they are.</p><div class="bd-arow"><button type="button" class="bd-btn sm solid" data-pparch="1">Archive</button><button type="button" class="bd-btn sm ghost" data-pparch="0">Not now</button></div></div>`, b, { label: 'Archive the program', width: 280, align: 'right', focus: '[data-pparch="1"]' }) });
337
+ return more;
338
+ }
339
+ /** The program as plain text, for Copy as text. */
340
+ function textOf(p) {
341
+ const st = programState(p, rowsOf), s = summaryOf(p, st);
342
+ const lines = [p.title + (p.goal ? ' · ' + p.goal : ''), [s.line, s.meta].filter(Boolean).join(' · ')];
343
+ for (const m of st.milestones) lines.push('Milestone: ' + m.name + ' · ' + m.day + (m.done ? ' · done' : ''));
344
+ for (const i of st.inis) lines.push('- ' + i.title + ' · ' + ((i.row.track && i.row.track.label) || i.stage || ''));
345
+ return lines.join('\n');
346
+ }
347
+ function openPanel(id, from) {
328
348
  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 }); }
349
+ const p = progOf(id);
350
+ adding = false; period = null; O._perOpen = false;
351
+ VW.open({ kind: 'Program', title: p.title + (p.goal ? ' · ' + p.goal : ''), icon: I.prog, id: 'program:' + id,
352
+ discuss: true, more: moreOf(p),
353
+ render: (body) => {
354
+ cur = { id, from: from && !(VW.body() && VW.body().contains(from)) ? from : (cur && cur.id === id && cur.from) || null };
355
+ body.classList.add('pp-vw');
356
+ const q = progOf(id); if (q) { readAway(q); readMore(q); body.innerHTML = bodyHtml(q); }
357
+ body.onclick = (e) => { const b = e.target.closest('[data-pp]'); if (b && body.contains(b)) press(b); };
358
+ body.onsubmit = submit;
359
+ document.querySelectorAll('#ibBody [data-prow]').forEach((x) => x.classList.toggle('sel', x.dataset.prow === id));
360
+ },
361
+ onClose: () => {
362
+ document.querySelectorAll('#ibBody [data-prow].sel').forEach((x) => x.classList.remove('sel'));
363
+ cur = null;
364
+ } });
336
365
  return true;
337
366
  }
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
367
  function setFold(k) { if (fold.has(k)) fold.delete(k); else fold.add(k); keepFold(); draw(true); }
368
+ /** Opens one folding row (the track's clusters open Milestones, "N more tasks" opens On its initiatives) and scrolls to it. */
369
+ function showRow(id) {
370
+ try { localStorage.setItem('cz-vw-fold:program:' + id, '1'); } catch { /* a private window */ }
371
+ draw();
372
+ const r = VW.body() && VW.body().querySelector(`[data-czs-fold="${id}"]`); if (r) { r.scrollIntoView({ block: 'start' }); r.focus({ preventScroll: true }); }
373
+ }
349
374
 
350
375
  async function press(b) {
351
376
  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); }
377
+ if (a === 'fold') setFold(b.dataset.fold);
378
+ else if (a === 'ms' || a === 'itasks') showRow(a);
356
379
  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(); }
380
+ else if (a === 'per' || a === 'early') { period = b.dataset.per; O._perOpen = false; draw(); const pb = VW.body() && VW.body().querySelector('[data-pp="period"]'); if (pb) pb.focus(); }
381
+ else if (a === 'ini') { const id = b.dataset.ini, from = document.querySelector(`#ibBody [data-prog="${CSS.escape(p.id)}"]`); VW.close(); O.openIni(id, from); }
382
+ else if (a === 'add') { adding = true; draw(); const i = VW.body() && VW.body().querySelector('.pp-add input'); if (i) i.focus(); }
360
383
  else if (a === 'charter') openCharter(p);
361
384
  else if (a === 'done') {
362
385
  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' });
@@ -366,86 +389,48 @@ async function press(b) {
366
389
  const r = await pmPost('/api/programs/check', { program: p.id, milestone: b.dataset.ms, done: b.dataset.done === '1' });
367
390
  if (!r || !r.ok) { O.say((r && r.error) || 'Not marked. The server did not say why.'); return; }
368
391
  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; }
392
+ }
393
+ }
394
+ async function submit(e) {
395
+ const f = e.target.closest('[data-pp-form="task"]'); if (!f) return;
396
+ e.preventDefault();
397
+ const p = cur && progOf(cur.id), title = f.t.value.trim(); if (!p) return;
398
+ if (!title) { adding = false; draw(); return; }
399
+ const r = await pmPost('/api/programs/task', { ws: p.home || board().ws || null, program: p.id, title });
400
+ if (!r || !r.ok) { O.say((r && r.error) || 'The task was not added. The server did not say why.'); return; }
401
+ adding = false; O.say('Added to ' + p.title + '.'); O.reload();
402
+ }
403
+ /** The presses in the popovers ⋯ opens: move an initiative in, archive. */
404
+ async function popPress(e) {
405
+ const j = e.target.closest('[data-ppjoin]'), x = e.target.closest('[data-pparch]'); if (!j && !x) return;
406
+ const p = cur && progOf(cur.id); Pop.close(true); if (!p) return;
407
+ if (j) {
408
+ const r = await pmPost('/api/programs/member', { ws: board().ws || null, program: p.id, initiative: j.dataset.ppjoin });
409
+ if (!r || !r.ok) { O.say((r && r.error) || 'It did not move in. The server did not say why.'); return; }
374
410
  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
411
+ } else if (x.dataset.pparch === '1') {
377
412
  const r = await pmPost('/api/programs/archive', { ws: p.home || board().ws || null, program: p.id });
378
413
  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();
414
+ O.say(p.title + ' is archived. Its initiatives stay where they are.'); VW.close(); O.reload();
380
415
  }
381
416
  }
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
417
 
418
418
  export function mount(o) {
419
419
  if (O) return;
420
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
- });
421
+ document.addEventListener('click', popPress);
438
422
  // 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
423
  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'] });
424
+ // the period menu is a layer inside the panel: Escape closes it first, then the shell closes the panel
425
+ window.addEventListener('keydown', (e) => {
426
+ if (e.key !== 'Escape' || !cur || !O._perOpen) return;
427
+ e.preventDefault(); e.stopImmediatePropagation(); O._perOpen = false; draw();
428
+ }, true);
448
429
  // a new read draws the rows again: the open panel follows it
449
430
  const body = document.getElementById('ibBody');
450
- if (body) new MutationObserver(() => { if (cur && !el.contains(document.activeElement)) draw(); }).observe(body, { childList: true });
431
+ if (body) new MutationObserver(() => {
432
+ const b = VW.body();
433
+ if (cur && shownHere() && !(b && b.contains(document.activeElement))) draw();
434
+ if (cur && shownHere()) document.querySelectorAll('#ibBody [data-prow]').forEach((x) => x.classList.toggle('sel', x.dataset.prow === cur.id));
435
+ }).observe(body, { childList: true });
451
436
  }