create-pmos 0.610.0 → 0.612.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 (164) hide show
  1. package/package.json +135 -27
  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-columns-test.js +2 -1
  8. package/workspace/board-deliveries-test.js +2 -1
  9. package/workspace/board-programs-test.js +7 -3
  10. package/workspace/board-publish-ui-test.js +2 -1
  11. package/workspace/board-shared-ui-test.js +2 -1
  12. package/workspace/board-workflows-test.js +2 -1
  13. package/workspace/briefing-premium-board-test.js +3 -2
  14. package/workspace/briefing-premium-calendar-2-test.js +3 -2
  15. package/workspace/briefing-premium-calendar-3-test.js +1 -1
  16. package/workspace/briefing-premium-calendar-test.js +1 -1
  17. package/workspace/briefing-premium-doc-edit-test.js +2 -1
  18. package/workspace/briefing-premium-insights-test.js +4 -3
  19. package/workspace/briefing-premium-test.js +3 -2
  20. package/workspace/calm-timeline-test.js +2 -1
  21. package/workspace/changelog.json +134 -0
  22. package/workspace/core-docs-workflow-test.js +2 -1
  23. package/workspace/ev-everywhere-test.js +3 -2
  24. package/workspace/guide/home.md +2 -2
  25. package/workspace/guide/index.md +4 -0
  26. package/workspace/guide/layout.md +97 -3
  27. package/workspace/guide/programs.md +16 -2
  28. package/workspace/guide/routine.md +65 -0
  29. package/workspace/guide/scheduled-tasks-and-cli.md +1 -1
  30. package/workspace/guide/settings-and-switches.md +2 -2
  31. package/workspace/impact-screens-test.js +3 -1
  32. package/workspace/ini-workflow-test.js +2 -1
  33. package/workspace/lib/board-premium.js +12 -4
  34. package/workspace/lib/classic-board.js +15 -0
  35. package/workspace/lib/cos-chat.js +1 -0
  36. package/workspace/lib/doc-library.js +43 -12
  37. package/workspace/lib/doc-path.js +30 -0
  38. package/workspace/lib/engine/boards.js +4 -2
  39. package/workspace/lib/events-place.js +368 -0
  40. package/workspace/lib/events-stated.js +129 -0
  41. package/workspace/lib/initiative-chat.js +1 -0
  42. package/workspace/lib/insights-premium.js +13 -1
  43. package/workspace/lib/library-find.js +162 -0
  44. package/workspace/lib/library-items.js +250 -0
  45. package/workspace/lib/notes.js +9 -1
  46. package/workspace/lib/plan-items.js +17 -3
  47. package/workspace/lib/route-modules.js +4 -0
  48. package/workspace/lib/routes-artefacts.js +5 -2
  49. package/workspace/lib/routes-boards.js +6 -2
  50. package/workspace/lib/routes-doc-sheet.js +1 -0
  51. package/workspace/lib/routes-events-place.js +203 -0
  52. package/workspace/lib/routes-library.js +155 -0
  53. package/workspace/lib/routes-pop-work.js +39 -0
  54. package/workspace/lib/routes-report-setups.js +32 -1
  55. package/workspace/lib/routes-today-log.js +48 -0
  56. package/workspace/lib/routine-reports.js +84 -0
  57. package/workspace/lib/status-when.js +36 -0
  58. package/workspace/lib/task-items.js +5 -3
  59. package/workspace/lib/today-log.js +131 -0
  60. package/workspace/live-pill-round-test.js +10 -7
  61. package/workspace/metric-drafts-ui-test.js +3 -1
  62. package/workspace/milestone-pins-test.js +2 -1
  63. package/workspace/milestone-suggest-test.js +3 -1
  64. package/workspace/package-lock.json +2 -2
  65. package/workspace/package.json +1 -1
  66. package/workspace/panels-test.js +2 -1
  67. package/workspace/premium-board-actions-test.js +3 -1
  68. package/workspace/premium-rec-tab-test.js +2 -1
  69. package/workspace/premium-vw-backlog-test.js +3 -1
  70. package/workspace/premium-vw-item-test.js +3 -1
  71. package/workspace/premium-vw-jira-test.js +3 -1
  72. package/workspace/premium-vw-meet-test.js +2 -1
  73. package/workspace/premium-vw-notes-test.js +3 -2
  74. package/workspace/product-lane-test.js +2 -1
  75. package/workspace/program-charter-test.js +3 -1
  76. package/workspace/program-leave-test.js +2 -1
  77. package/workspace/program-order-test.js +2 -1
  78. package/workspace/program-panel-test.js +3 -1
  79. package/workspace/public/pm/artefact-kind.js +87 -0
  80. package/workspace/public/pm/bd-ini-panel.js +77 -12
  81. package/workspace/public/pm/bd-prog-panel.js +55 -8
  82. package/workspace/public/pm/bd-span.js +5 -0
  83. package/workspace/public/pm/bd-work.css +192 -0
  84. package/workspace/public/pm/bd-work.js +483 -0
  85. package/workspace/public/pm/cozy-bar.css +11 -0
  86. package/workspace/public/pm/cozy-bar.js +99 -0
  87. package/workspace/public/pm/cozy-day-pick.css +27 -0
  88. package/workspace/public/pm/cozy-day-pick.js +97 -0
  89. package/workspace/public/pm/cozy-ev.css +2 -5
  90. package/workspace/public/pm/cozy-events-view.js +274 -0
  91. package/workspace/public/pm/cozy-events.css +179 -0
  92. package/workspace/public/pm/cozy-events.js +278 -0
  93. package/workspace/public/pm/cozy-evmodel.js +1 -1
  94. package/workspace/public/pm/cozy-goals.css +172 -0
  95. package/workspace/public/pm/cozy-library.css +125 -0
  96. package/workspace/public/pm/cozy-live-pill.js +1 -0
  97. package/workspace/public/pm/cozy-nav.js +6 -7
  98. package/workspace/public/pm/cozy-pick.css +3 -0
  99. package/workspace/public/pm/cozy-pop-work.css +224 -0
  100. package/workspace/public/pm/cozy-pop-work.js +668 -0
  101. package/workspace/public/pm/cozy-popup.css +11 -2
  102. package/workspace/public/pm/cozy-popup.js +67 -9
  103. package/workspace/public/pm/cozy-routine-job.js +203 -0
  104. package/workspace/public/pm/cozy-routine-model.js +219 -0
  105. package/workspace/public/pm/cozy-routine-pop.js +318 -0
  106. package/workspace/public/pm/cozy-routine.css +155 -0
  107. package/workspace/public/pm/cozy-routine.js +335 -0
  108. package/workspace/public/pm/cozy-schedwork.js +6 -5
  109. package/workspace/public/pm/cozy-settings.js +1 -5
  110. package/workspace/public/pm/cozy-status-when.js +48 -0
  111. package/workspace/public/pm/cozy-today-app.js +236 -0
  112. package/workspace/public/pm/cozy-today-model.js +176 -0
  113. package/workspace/public/pm/cozy-today-page.css +100 -0
  114. package/workspace/public/pm/cozy-today-view.js +76 -0
  115. package/workspace/public/pm/cozy-viewer.js +19 -8
  116. package/workspace/public/pm/cozy-vw-mtg.css +39 -0
  117. package/workspace/public/pm/goals-model.js +205 -0
  118. package/workspace/public/pm/goals-open.js +124 -0
  119. package/workspace/public/pm/home-app.js +18 -3
  120. package/workspace/public/pm/home-chat.js +4 -2
  121. package/workspace/public/pm/home-ini.js +43 -10
  122. package/workspace/public/pm/ini-edit.js +3 -1
  123. package/workspace/public/pm/ini-view-model.js +1 -1
  124. package/workspace/public/pm/library-model.js +197 -0
  125. package/workspace/public/pm/library-open.js +37 -0
  126. package/workspace/public/pm/page-chat.js +12 -2
  127. package/workspace/public/pm/pop-work-model.js +493 -0
  128. package/workspace/public/pm/premium-board.js +204 -17
  129. package/workspace/public/pm/premium-goals.js +213 -0
  130. package/workspace/public/pm/premium-library.js +436 -0
  131. package/workspace/public/pm/premium-shell.js +1 -1
  132. package/workspace/public/pm/premium-vw-mtg.js +79 -1
  133. package/workspace/public/pm/scope-chip.js +204 -0
  134. package/workspace/public/premium-board.html +1 -0
  135. package/workspace/public/premium-events.html +44 -0
  136. package/workspace/public/premium-goals.html +37 -0
  137. package/workspace/public/premium-library.html +39 -0
  138. package/workspace/public/premium-routine.html +33 -0
  139. package/workspace/public/today.html +50 -0
  140. package/workspace/ready-dash-ui-test.js +3 -1
  141. package/workspace/rename-test.js +2 -1
  142. package/workspace/run-tests.js +4 -1
  143. package/workspace/server.js +4 -2
  144. package/workspace/sort-order-test.js +2 -1
  145. package/workspace/split-merge-ui-test.js +3 -1
  146. package/workspace/stage-card-tasks-test.js +3 -1
  147. package/workspace/stage-card-test.js +2 -1
  148. package/workspace/task-delete-test.js +2 -1
  149. package/workspace/task-links-test.js +2 -1
  150. package/workspace/task-milestones-test.js +4 -2
  151. package/workspace/task-plans-test.js +3 -1
  152. package/workspace/task-press-test.js +3 -1
  153. package/workspace/task-views-test.js +3 -1
  154. package/workspace/test-lists/doc-path.json +9 -0
  155. package/workspace/test-lists/events-place.json +11 -0
  156. package/workspace/test-lists/goals-place.json +9 -0
  157. package/workspace/test-lists/library-place.json +9 -0
  158. package/workspace/test-lists/pop-work.json +9 -0
  159. package/workspace/test-lists/routine-place.json +9 -0
  160. package/workspace/test-lists/status-when.json +9 -0
  161. package/workspace/test-lists/today-log.json +9 -0
  162. package/workspace/test-lists/work-view.json +9 -0
  163. package/workspace/timeline-holds-test.js +3 -1
  164. package/workspace/tk-tasks-test.js +2 -1
@@ -0,0 +1,483 @@
1
+ /* pm/bd-work.js — Work, one view (slice 4 of the six-place navigation, initiative work-one-view; boards 4, 5 and 24 on Exploring 2).
2
+ * One list of initiatives with the timeline on its right. No List / By stage / Track / Timeline tabs.
3
+ * · Columns, in one order: Initiative, Product, Stage, Next milestone, Date. Status, Program, Goal and Workflow can be shown. Initiative
4
+ * always shows. One text size, one row height; only the initiative name is bold.
5
+ * · Next milestone is the real milestone name; with none the cell is empty (never "Plan end", never a stage name), and Date is the plan end.
6
+ * · Only a late or at-risk date has colour: "4 Nov · 14 days late", "27 Nov · at risk". A closed initiative is never late.
7
+ * · The bar is the Board's own (Wawan, 2026-11-19, round 2; pm/bd-span.js rowBar, given by the page): done, now in blue, planned, every
8
+ * milestone ◇ with its popup, the gap line, the late line to today. A press on the bar opens the stage card (board 4): each stage of the
9
+ * row's own workflow with its date, and nothing where it has none. Nothing shows on a hover but the bar's own tooltip. PMOS does not invent a date.
10
+ * · Closed and completed initiatives fold into one last line, "11 closed", that opens them.
11
+ * · The span chooser sits on the timeline header beside the hide button: Quarter, Half, Year, 2 yr, 5 yr, Full (the default).
12
+ * · The view menu (board 5): Group by pills, the Timeline switch, the Columns with a switch each and drag to order, "PMOS remembers this"
13
+ * and Reset. The view is kept in this browser (localStorage pmos.work.view.2).
14
+ * · More than one product: the groups are the goals of all of them, and the Product column tells the rows apart; with one product the
15
+ * Product column hides by itself.
16
+ * The parts that decide (nextOf, dateOf, colsShown, groupsOf, windowOf, stagesOf) are pure and tested in work-view.test.js. The markup has no
17
+ * handlers: pm/premium-board.js wires the presses (pressOf and apply say what a press means; wireDrag does the menu's drag). */
18
+ import { stageOfRow, stagesOfRow, wfOf, catOfRow, posOf } from './bd-wf.js';
19
+ import { stageName as oneStageName } from './stage-chip.js';
20
+
21
+ export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
22
+ const SV = (d, n) => `<svg viewBox="0 0 24 24"${n ? ` width="${n}" height="${n}"` : ''} aria-hidden="true"><path d="${d}"/></svg>`;
23
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
24
+ const DAY = 864e5;
25
+
26
+ /* ── the columns ─────────────────────────────────────────────────────────────────────────────────────────────── */
27
+ /** Every column but Initiative, in its usual order, with its width in px. on: shown by default. */
28
+ export const COLS = [
29
+ { k: 'product', n: 'Product', w: 112, on: true },
30
+ { k: 'stage', n: 'Stage', w: 160, on: true },
31
+ { k: 'ms', n: 'Next milestone', w: 160, on: true },
32
+ { k: 'date', n: 'Date', w: 152, on: true },
33
+ { k: 'status', n: 'Status', w: 104, on: false },
34
+ { k: 'program', n: 'Program', w: 150, on: false },
35
+ { k: 'goal', n: 'Goal', w: 170, on: false },
36
+ { k: 'wf', n: 'Workflow', w: 140, on: false },
37
+ ];
38
+ const byK = Object.fromEntries(COLS.map((c) => [c.k, c]));
39
+ export const GROUPS = [['goal', 'Goal'], ['product', 'Product'], ['stage', 'Stage'], ['status', 'Status'], ['program', 'Program'], ['none', 'No groups']];
40
+ export const SPANS = [['quarter', 'Quarter', 91], ['half', 'Half', 182], ['year', 'Year', 365], ['y2', '2 yr', 730], ['y5', '5 yr', 1826], ['full', 'Full', 0]];
41
+ export const KEY = 'pmos.work.view.2'; // .2 (round 2, 2026-11-19): every kept view starts again from the usual one, so Date is back
42
+
43
+ /** The usual view: grouped by goal, the timeline on, the default columns in their order, Full. */
44
+ export const usual = () => ({ group: 'goal', tl: true, span: 'full', cols: COLS.map((c) => ({ k: c.k, on: c.on })), sorts: [] });
45
+
46
+ /** The view as kept, mended: an unknown key falls back to the usual one, a column missing from a kept list is added off at the end. */
47
+ export function mend(v) {
48
+ const u = usual();
49
+ if (!v || typeof v !== 'object') return u;
50
+ const seen = new Set(), cols = [];
51
+ for (const c of Array.isArray(v.cols) ? v.cols : []) if (c && byK[c.k] && !seen.has(c.k)) { seen.add(c.k); cols.push({ k: c.k, on: !!c.on }); }
52
+ for (const c of COLS) if (!seen.has(c.k)) cols.push({ k: c.k, on: cols.length ? false : c.on });
53
+ return {
54
+ group: GROUPS.some(([k]) => k === v.group) ? v.group : u.group,
55
+ tl: v.tl !== false,
56
+ span: SPANS.some(([k]) => k === v.span) ? v.span : u.span,
57
+ cols: cols.length ? cols : u.cols,
58
+ sorts: (Array.isArray(v.sorts) ? v.sorts : []).filter((x) => x && (x.k === 'title' || byK[x.k])).filter((x, i, a) => a.findIndex((y) => y.k === x.k) === i).slice(0, 3).map((x) => ({ k: x.k, up: x.up !== false })),
59
+ };
60
+ }
61
+ let mem = null;
62
+ const box = () => { try { return typeof localStorage !== 'undefined' ? localStorage : null; } catch { return null; } };
63
+ export function read() {
64
+ if (mem) return mem;
65
+ let v = null; try { const s = box(); v = s ? JSON.parse(s.getItem(KEY) || 'null') : null; } catch { v = null; }
66
+ mem = mend(v); return mem;
67
+ }
68
+ function write(v) { mem = mend(v); try { const s = box(); if (s) s.setItem(KEY, JSON.stringify(mem)); } catch { /* a private window keeps it for this page */ } return mem; }
69
+ export const setGroup = (g) => write({ ...read(), group: g });
70
+ export const setTimeline = (on) => write({ ...read(), tl: !!on });
71
+ export const setSpan = (s) => write({ ...read(), span: s });
72
+ export const reset = () => write(usual());
73
+ /** A column's switch. The columns that show stay on top, in their order; one switched on goes under them, one switched off goes on top of the others. */
74
+ export function setCol(k, on) {
75
+ const v = read(); if (!byK[k]) return v;
76
+ const rest = v.cols.filter((c) => c.k !== k), shown = rest.filter((c) => c.on), hid = rest.filter((c) => !c.on);
77
+ return write({ ...v, cols: [...shown, { k, on: !!on }, ...hid] });
78
+ }
79
+ /** Drag a column to the place of another: `k` moves before `before` (or to the end of the columns that show when before is null). */
80
+ export function moveCol(k, before) {
81
+ const v = read(), c = v.cols.find((x) => x.k === k); if (!c || k === before) return v;
82
+ const rest = v.cols.filter((x) => x.k !== k);
83
+ let i = before ? rest.findIndex((x) => x.k === before) : rest.filter((x) => x.on).length;
84
+ if (i < 0) i = rest.length;
85
+ const t = before ? rest[i] : null, moved = { ...c, on: t ? t.on : c.on };
86
+ rest.splice(i, 0, moved);
87
+ return write({ ...v, cols: rest });
88
+ }
89
+ /** The columns to draw beside Initiative: the ones switched on, in their order; Product leaves by itself with one product. */
90
+ export const colsShown = (v, o = {}) => v.cols.filter((c) => c.on && !(c.k === 'product' && !o.many)).map((c) => c.k);
91
+
92
+ /* ── dates ───────────────────────────────────────────────────────────────────────────────────────────────────── */
93
+ export const day = (v) => { if (v instanceof Date) return new Date(v.getFullYear(), v.getMonth(), v.getDate()); const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
94
+ const today = (now) => day(now || new Date());
95
+ /** "4 Nov", and the year when it is not this year: "20 Oct 2027" (boards 4 and 24). */
96
+ export const dm = (d, now = new Date()) => d.getDate() + ' ' + MON[d.getMonth()] + (d.getFullYear() !== now.getFullYear() ? ' ' + d.getFullYear() : '');
97
+ const plural = (n, a, b) => (n === 1 ? a : b);
98
+
99
+ /** A row's next milestone: the earliest milestone not done, by its own name; with none, "Plan end" and the end of its plan (plan: true).
100
+ * Never a stage name. null when the row has neither. → { name, d, plan } */
101
+ export function nextOf(r) {
102
+ const M = (r.milestones || []).filter((m) => m && !m.done && day(m.date)).sort((a, b) => day(a.date) - day(b.date));
103
+ if (M.length) return { name: String(M[0].name || 'Milestone'), d: day(M[0].date), plan: false };
104
+ const e = day(r.end);
105
+ return e ? { name: '', d: e, plan: true } : null; // the plan's end: its date is the Date cell's, but it is not a milestone the PM named
106
+ }
107
+ /** The Date cell: the date, and its tone only when late or at risk ("14 days late", "at risk"). A closed initiative is never late. */
108
+ export function dateOf(r, now = new Date()) {
109
+ const n = nextOf(r); if (!n) return { text: '', tone: '', note: '' };
110
+ const t = today(now), over = Math.round((t - n.d) / DAY), text = dm(n.d, now);
111
+ if (r.closed || r.status === 'done') return { text, tone: '', note: '' };
112
+ if (over > 0) return { text, tone: 'late', note: over + ' ' + plural(over, 'day', 'days') + ' late', over };
113
+ if (r.status === 'late') return { text, tone: 'late', note: 'late' };
114
+ if (r.status === 'at risk') return { text, tone: 'risk', note: 'at risk' };
115
+ return { text, tone: '', note: '' };
116
+ }
117
+
118
+ /* ── stages ──────────────────────────────────────────────────────────────────────────────────────────────────── */
119
+ const norm = (s) => String(s || '').trim().toLowerCase();
120
+ export const stageText = (r) => oneStageName(r) || ((s) => (s && s.name) || '')(stageOfRow(r)) || r.stage || '';
121
+ const STATUS = { todo: 'To do', doing: 'In progress', done: 'Done', wontdo: "Won't do", archived: 'Archived' };
122
+ export const statusText = (r) => STATUS[catOfRow(r)] || '';
123
+ /** The stages of a row's own workflow with their dates (the due date of the dated work in each, as the Board reads it) and where it stands:
124
+ * 'done' before the stage now, 'cur' the stage now, 'next' after. A stage the row skipped is left out. → [{ key, name, d, at, ms }] */
125
+ export function stagesOf(r) {
126
+ const L = (stagesOfRow(r) || []).filter((s) => s && !s.skipped && s.status !== 'skipped');
127
+ const cur = stageOfRow(r), ci = cur ? L.findIndex((s) => s.key === cur.key || norm(s.name) === norm(cur.name)) : -1;
128
+ const spans = Array.isArray(r.stageSpans) ? r.stageSpans : [];
129
+ return L.map((s, i) => {
130
+ const sp = spans.filter((x) => norm(x.stage) === norm(s.key) || norm(x.stage) === norm(s.name)).map((x) => day(x.due)).filter(Boolean).sort((a, b) => b - a)[0] || null;
131
+ return { key: s.key, name: s.name, d: sp, at: ci < 0 ? 'next' : i < ci ? 'done' : i === ci ? 'cur' : 'next', ms: !!s.milestone };
132
+ });
133
+ }
134
+
135
+ /* ── groups ──────────────────────────────────────────────────────────────────────────────────────────────────── */
136
+ /** The rows in groups: [{ key, name, rows }], or null with No groups. o: { goalGroups(rows) → [{ key, name, rows }] | null, goalOf(r),
137
+ * programOf(r), product(r) }. A row with no value goes in a last group ("No goal yet", "No program", "No stage"). */
138
+ export function groupsOf(rows, by, o = {}) {
139
+ if (by === 'none') return null;
140
+ if (by === 'goal' && o.goalGroups) { const G = o.goalGroups(rows); if (G && G.length) return G; }
141
+ const keyOf = {
142
+ goal: (r) => (o.goalOf && o.goalOf(r)) || '',
143
+ product: (r) => (o.product ? o.product(r) : r.product) || '',
144
+ stage: (r) => stageText(r),
145
+ status: (r) => statusText(r),
146
+ program: (r) => (o.programOf && o.programOf(r)) || '',
147
+ }[by];
148
+ if (!keyOf) return null;
149
+ const none = { goal: 'No goal yet', product: 'No product', stage: 'No stage', status: 'No status', program: 'No program' }[by];
150
+ const m = new Map();
151
+ for (const r of rows) { const k = keyOf(r) || ''; if (!m.has(k)) m.set(k, []); m.get(k).push(r); }
152
+ let G = [...m.entries()].map(([k, rs]) => ({ key: by + ':' + (k || '-'), name: k || none, rows: rs, empty: !k }));
153
+ if (by === 'stage') G.sort((a, b) => (a.empty - b.empty) || (Math.min(...a.rows.map(posOf)) - Math.min(...b.rows.map(posOf))));
154
+ else if (by === 'status') { const O = { 'To do': 0, 'In progress': 1, Done: 2 }; G.sort((a, b) => (O[a.name] ?? 9) - (O[b.name] ?? 9)); }
155
+ else G.sort((a, b) => a.empty - b.empty);
156
+ // one group that holds every row and names nothing (no goal yet anywhere) says nothing: the list is flat (zero is silence)
157
+ return G.length === 1 && G[0].empty ? null : G;
158
+ }
159
+
160
+ /* ── sort (round 3, Wawan: "user can do multiple sort and filter right from the same popup"): up to three keys, kept with the view. None is
161
+ * "PMOS order", what needs the PM first (the page's own order). A column title makes its column the one key, then turns it round, then
162
+ * gives PMOS order back. In the menu a pill adds a key after the others; pressed again it turns round; its × takes it out. ── */
163
+ export const MAX_SORTS = 3;
164
+ export const sorted = () => (read().sorts[0] || {}).k || null;
165
+ export const sortsOf = () => read().sorts;
166
+ /** The column title's press: the one key, then the other way, then PMOS order. */
167
+ export function setSort(k) {
168
+ if (k !== 'title' && !byK[k]) return write({ ...read(), sorts: [] });
169
+ const S = read().sorts, one = S.length === 1 && S[0].k === k;
170
+ return write({ ...read(), sorts: one ? (S[0].up ? [{ k, up: false }] : []) : [{ k, up: true }] });
171
+ }
172
+ /** The menu's pill: a new key goes after the others (the third is replaced when there are three); a key in use turns round. */
173
+ export function addSort(k) {
174
+ if (k !== 'title' && !byK[k]) return read();
175
+ const S = read().sorts.slice(), i = S.findIndex((x) => x.k === k);
176
+ if (i >= 0) S[i] = { k, up: !S[i].up }; else { if (S.length >= MAX_SORTS) S.pop(); S.push({ k, up: true }); }
177
+ return write({ ...read(), sorts: S });
178
+ }
179
+ export const dropSort = (k) => write({ ...read(), sorts: read().sorts.filter((x) => x.k !== k) });
180
+ export const SORT_KEYS = [['title', 'Initiative'], ['stage', 'Stage'], ['date', 'Date'], ['ms', 'Next milestone'], ['status', 'Status'], ['product', 'Product'], ['program', 'Program']];
181
+ const str = (v) => String(v || '~');
182
+ /** Stage order: the row's own workflow's place, else (no workflow on record) the lifecycle's order by name, so Discover comes before Build. */
183
+ const LIFE = ['triage', 'discover', 'discovery', 'plan', 'prioritize', 'build', 'deliver', 'monitor', 'evaluate', 'completed', 'closed'];
184
+ const lifeOf = (r) => { const i = LIFE.indexOf(norm(stageText(r))); return i < 0 ? LIFE.length : i; };
185
+ const stageCmp = (a, b) => posOf(a) - posOf(b) || lifeOf(a) - lifeOf(b);
186
+ const SORTS = {
187
+ title: (a, b) => String(a.title).localeCompare(String(b.title)),
188
+ product: (a, b, o) => str(o.product(a)).localeCompare(str(o.product(b))),
189
+ stage: (a, b) => stageCmp(a, b),
190
+ ms: (a, b) => { const x = nextOf(a), y = nextOf(b); return str(x && !x.plan ? x.name : '~').localeCompare(str(y && !y.plan ? y.name : '~')); },
191
+ date: (a, b) => { const x = nextOf(a), y = nextOf(b); return (x ? +x.d : Infinity) - (y ? +y.d : Infinity) || 0; },
192
+ status: (a, b) => str(statusText(a)).localeCompare(str(statusText(b))),
193
+ program: (a, b, o) => str(o.programOf && o.programOf(a)).localeCompare(str(o.programOf && o.programOf(b))),
194
+ goal: (a, b, o) => str(o.goalOf && o.goalOf(a)).localeCompare(str(o.goalOf && o.goalOf(b))),
195
+ wf: (a, b) => String(wfOf(a).name).localeCompare(String(wfOf(b).name)),
196
+ };
197
+ const sortRows = (rows, o) => {
198
+ const S = read().sorts.filter((x) => SORTS[x.k]); if (!S.length) return rows;
199
+ return rows.slice().sort((a, b) => { for (const x of S) { const d = SORTS[x.k](a, b, o); if (d) return x.up ? d : -d; } return String(a.title).localeCompare(String(b.title)); });
200
+ };
201
+
202
+ /* ── filter (round 3): every facet takes several values; each value says how many rows it holds, and one that holds none is not shown.
203
+ * The filter lives for this page (the view is what PMOS remembers). ── */
204
+ const FACETS = [['need', 'Needs'], ['stage', 'Stage'], ['status', 'Status'], ['product', 'Product'], ['program', 'Program'], ['owner', 'Owner'], ['sprint', 'Sprint']];
205
+ const NEEDS = [['you', 'Waits on you'], ['late', 'Late'], ['risk', 'At risk'], ['blocked', 'Blocked']];
206
+ const FL = Object.fromEntries(FACETS.map(([k]) => [k, new Set()]));
207
+ /** The values a row holds in a facet (a row can be in several sprints and several needs). */
208
+ function valuesOf(r, k, o) {
209
+ const t = r.track || {};
210
+ if (k === 'need') return NEEDS.map(([x]) => x).filter((x) => (x === 'you' ? !!t.you : x === 'late' ? !!r.late || dateOf(r, o.now).tone === 'late' : x === 'risk' ? r.status === 'at risk' || dateOf(r, o.now).tone === 'risk' : !!t.blocked));
211
+ if (k === 'stage') { const v = stageText(r); return v ? [v] : []; }
212
+ if (k === 'status') { const v = statusText(r); return v ? [v] : []; }
213
+ if (k === 'product') { const v = o.product ? o.product(r) : r.product; return v ? [v] : []; }
214
+ if (k === 'program') return [(o.programOf && o.programOf(r)) || 'No program'];
215
+ if (k === 'owner') return [r.owner || 'No owner'];
216
+ if (k === 'sprint') return [...new Set((t.tickets || []).map((x) => x.sprint).filter(Boolean))];
217
+ return [];
218
+ }
219
+ const needWord = (x) => (NEEDS.find(([k]) => k === x) || [x, x])[1];
220
+ /** Each facet with its values and counts over the rows, in the order the rows give them (stages in stage order); a facet with one value or
221
+ * none says nothing, except Needs and Sprint. → [{ k, n, vals: [{ v, word, n, on }] }] */
222
+ export function facetsOf(rows, o = {}) {
223
+ const oo = { now: new Date(), ...o };
224
+ return FACETS.map(([k, n]) => {
225
+ const m = new Map();
226
+ for (const r of rows) for (const v of valuesOf(r, k, oo)) m.set(v, (m.get(v) || 0) + 1);
227
+ let vals = [...m].map(([v, c]) => ({ v, word: k === 'need' ? needWord(v) : v, n: c, on: FL[k].has(v) }));
228
+ if (k === 'need') vals = NEEDS.map(([x]) => vals.find((y) => y.v === x)).filter(Boolean);
229
+ else if (k === 'stage') { const rep = (v) => rows.find((r) => stageText(r) === v); vals.sort((a, b) => stageCmp(rep(a.v), rep(b.v))); }
230
+ else if (k === 'sprint') vals.sort((a, b) => String(b.v).localeCompare(String(a.v), undefined, { numeric: true }));
231
+ else vals.sort((a, b) => b.n - a.n || String(a.v).localeCompare(String(b.v)));
232
+ // a value that is on but holds no row now stays, so it can be taken off
233
+ for (const v of FL[k]) if (!vals.some((y) => y.v === v)) vals.push({ v, word: k === 'need' ? needWord(v) : v, n: 0, on: true });
234
+ return { k, n, vals };
235
+ }).filter((f) => f.vals.length > (f.k === 'need' || f.k === 'sprint' ? 0 : 1) || f.vals.some((y) => y.on));
236
+ }
237
+ export const filterOn = () => FACETS.some(([k]) => FL[k].size > 0);
238
+ export const filterCount = () => FACETS.reduce((n, [k]) => n + FL[k].size, 0);
239
+ export const setFilter = (k, v) => { if (!FL[k]) return; if (FL[k].has(v)) FL[k].delete(v); else FL[k].add(v); };
240
+ export const clearFilter = () => { for (const [k] of FACETS) FL[k].clear(); };
241
+ /** The rows every facet that is on lets through: a value of the facet, any of them (several stages read "Build or Deliver"). */
242
+ export function filterRows(rows, o = {}) {
243
+ const oo = { now: new Date(), ...o }, on = FACETS.filter(([k]) => FL[k].size);
244
+ if (!on.length) return rows;
245
+ return rows.filter((r) => on.every(([k]) => valuesOf(r, k, oo).some((v) => FL[k].has(v))));
246
+ }
247
+ /** The quiet line above the table while a filter is on (Events' form): "Showing Build and Deliver of IDPF · 14 hidden · Show all". */
248
+ export function showingHtml(hidden) {
249
+ if (!filterOn()) return '';
250
+ const and = (k) => [...FL[k]].map((v) => (k === 'need' ? needWord(v) : v)).join(k === 'need' ? ' or ' : ' and ');
251
+ const what = ['need', 'stage', 'status', 'sprint'].filter((k) => FL[k].size).map(and).join(' · ') || 'the initiatives';
252
+ const of = ['product', 'program'].filter((k) => FL[k].size).map(and).join(' · '), by = FL.owner.size ? and('owner') : '';
253
+ return `<div class="wk-showing" role="status"><span>Showing ${esc(what)}${of ? ' of ' + esc(of) : ''}${by ? ' owned by ' + esc(by) : ''}</span>${hidden ? `<span class="q">· ${hidden} hidden</span>` : ''}<span class="q">·</span><button type="button" class="wk-sa" data-wkclear>Show all</button></div>`;
254
+ }
255
+
256
+ /* ── the timeline's window ───────────────────────────────────────────────────────────────────────────────────── */
257
+ /** The window of a span. Full: from the earliest start to the latest end of the rows (their milestones and today too), so no bar is cut.
258
+ * The other spans are a fixed length that starts a quarter of the way before today. → { from, to, span } (Dates) */
259
+ export function windowOf(span, rows, now = new Date()) {
260
+ const t = today(now), S = SPANS.find(([k]) => k === span) || SPANS[SPANS.length - 1];
261
+ if (S[2]) { const from = new Date(+t - Math.round(S[2] * 0.25) * DAY); return { from, to: new Date(+from + S[2] * DAY), span: S[0] }; }
262
+ const ds = [t];
263
+ for (const r of rows || []) { for (const v of [r.start, r.end]) { const d = day(v); if (d) ds.push(d); } for (const m of r.milestones || []) { const d = day(m && m.date); if (d) ds.push(d); } }
264
+ const lo = Math.min(...ds), hi = Math.max(...ds), pad = Math.max(7 * DAY, (hi - lo) * 0.03);
265
+ return { from: new Date(lo - pad), to: new Date(Math.max(hi + pad, lo + 60 * DAY)), span: 'full' };
266
+ }
267
+ const X = (W, d) => ((d - W.from) / (W.to - W.from)) * 100;
268
+ const P = (x) => Math.max(0, Math.min(100, x)).toFixed(2) + '%';
269
+ const inW = (W, d) => d && d >= W.from && d <= W.to;
270
+ /** The ticks of a window: months up to about half a year, quarters up to about two years, then years. [{ at, mid, label }] */
271
+ export function ticksOf(W) {
272
+ const len = (W.to - W.from) / DAY, out = [];
273
+ const unit = len <= 200 ? 'm' : len <= 800 ? 'q' : 'y', step = unit === 'm' ? 1 : unit === 'q' ? 3 : 12;
274
+ let d = new Date(W.from.getFullYear(), unit === 'y' ? 0 : W.from.getMonth() - (unit === 'q' ? W.from.getMonth() % 3 : 0), 1);
275
+ let first = true;
276
+ while (d < W.to) {
277
+ const nx = new Date(d.getFullYear(), d.getMonth() + step, 1), q = Math.floor(d.getMonth() / 3) + 1;
278
+ const label = unit === 'y' ? String(d.getFullYear()) : unit === 'q' ? 'Q' + q + (q === 1 || first ? ' ' + d.getFullYear() : '') : MON[d.getMonth()] + (d.getMonth() === 0 || first ? ' ' + d.getFullYear() : '');
279
+ const mid = new Date((Math.max(+d, +W.from) + Math.min(+nx, +W.to)) / 2);
280
+ out.push({ at: d, mid, label, show: Math.min(+nx, +W.to) - Math.max(+d, +W.from) > (W.to - W.from) * 0.05 });
281
+ d = nx; first = false;
282
+ }
283
+ return out;
284
+ }
285
+
286
+ /* ── markup ──────────────────────────────────────────────────────────────────────────────────────────────────── */
287
+ const I = { hide: 'M13 6l6 6-6 6M6 6l6 6-6 6', show: 'M11 6l-6 6 6 6M18 6l-6 6 6 6', chev: 'M7 10l5 5 5-5', sort: 'M12 5v14M6 13l6 6 6-6', x: 'M6 6l12 12M18 6L6 18' };
288
+
289
+ function cellHtml(r, k, o) {
290
+ if (k === 'product') return `<span role="cell">${esc(o.product(r))}</span>`;
291
+ if (k === 'stage') { const s = stageText(r); return `<span role="cell" class="wk-stc">${o.canMove && o.canMove(r) ? `<button type="button" class="wk-st" data-wkstage="${esc(r.key)}" aria-haspopup="menu" aria-label="Stage: ${esc(s || 'none')}. Change the stage" title="Change the stage">${esc(s)}</button>` : esc(s)}</span>`; }
292
+ if (k === 'ms') { const n = nextOf(r); return `<span role="cell">${n ? esc(n.name) : ''}</span>`; }
293
+ if (k === 'date') { const d = dateOf(r, o.now); return `<span role="cell" class="wk-d${d.tone ? ' ' + d.tone : ''}">${esc(d.text)}${d.note ? `<em> · ${esc(d.note)}</em>` : ''}</span>`; }
294
+ if (k === 'status') return `<span role="cell">${esc(statusText(r))}</span>`;
295
+ if (k === 'program') return `<span role="cell">${esc((o.programOf && o.programOf(r)) || '')}</span>`;
296
+ if (k === 'goal') return `<span role="cell">${esc((o.goalOf && o.goalOf(r)) || '')}</span>`;
297
+ if (k === 'wf') return `<span role="cell">${esc(wfOf(r).name)}</span>`;
298
+ return '<span role="cell"></span>';
299
+ }
300
+ const words = (r, keys, o) => keys.map((k) => {
301
+ if (k === 'product') return o.product(r);
302
+ if (k === 'stage') return stageText(r);
303
+ if (k === 'ms') { const n = nextOf(r); return n && n.name ? 'next ' + n.name : ''; }
304
+ if (k === 'date') { const d = dateOf(r, o.now); return d.text + (d.note ? ', ' + d.note : ''); }
305
+ if (k === 'status') return statusText(r);
306
+ if (k === 'program') return (o.programOf && o.programOf(r)) || '';
307
+ if (k === 'goal') return (o.goalOf && o.goalOf(r)) || '';
308
+ if (k === 'wf') return wfOf(r).name;
309
+ return '';
310
+ }).filter(Boolean).join(', ');
311
+
312
+ /** The grid lines and today's line of the timeline, the same on every row. */
313
+ const gridHtml = (W, T, now) => T.map((t) => (inW(W, t.at) ? `<i class="wk-gl" style="left:${P(X(W, t.at))}"></i>` : '')).join('') + (inW(W, today(now)) ? `<i class="wk-now" style="left:${P(X(W, today(now)))}"></i>` : '');
314
+ /** One row's bar when the page gives none (the unit test): the plan, the part that has passed, the late line, the next milestone. The page
315
+ * draws the Board's own bar instead (o.bar: pm/bd-span.js rowBar). */
316
+ export function barHtml(r, W, o = {}) {
317
+ const now = o.now || new Date(), t = today(now), s = day(r.start), e = day(r.end), n = nextOf(r), dt = dateOf(r, now);
318
+ let h = '';
319
+ if (s && e && e >= s && e >= W.from && s <= W.to) {
320
+ const a = X(W, s), b = X(W, e), pass = Math.min(+t, +e) > +s ? ((Math.min(+t, +e) - s) / (e - s)) * 100 : 0;
321
+ h += `<b class="wk-bar" style="left:${P(a)};width:${P(Math.min(100, b) - Math.max(0, a))}"><em style="width:${Math.max(0, Math.min(100, pass)).toFixed(1)}%"></em></b>`;
322
+ }
323
+ if (n && dt.tone === 'late' && dt.over > 0 && n.d < W.to) h += `<u class="wk-late" style="left:${P(X(W, n.d))};width:${P(X(W, t) - Math.max(0, X(W, n.d)))}" aria-hidden="true"></u>`;
324
+ if (n && inW(W, n.d)) h += `<s class="wk-ms${dt.tone ? ' ' + dt.tone : ''}" style="left:${P(X(W, n.d))}" title="${esc((n.name || 'Plan end') + ' · ' + dt.text)}"></s>`;
325
+ return h;
326
+ }
327
+ /** The stage card (board 4), open after a press of the bar: the stages of the row's own workflow, each with the due date of its work, the one in
328
+ * progress marked; and the stage dots on the bar. Esc or a press outside closes it. */
329
+ export function cardHtml(r, W, now = new Date()) {
330
+ const S = stagesOf(r), dt = dateOf(r, now); if (!S.length) return '';
331
+ const tone = (x) => (x.at === 'cur' && dt.tone ? ' ' + dt.tone : '');
332
+ return S.map((x) => (x.d && inW(W, x.d) ? `<i class="wk-sd ${x.at}${tone(x)}" style="left:${P(X(W, x.d))}" aria-hidden="true"></i>` : '')).join('')
333
+ + `<div class="wk-card" role="dialog" aria-label="${esc(r.title + ', its stages')}" style="--n:${S.length}"><p>${esc(r.title)} · its stages</p><div class="wk-cg" style="--n:${S.length}">${S.map((x) => `<div class="wk-cs ${x.at}${tone(x)}"><i></i><b>${esc(x.name)}</b><small>${x.d ? esc(dm(x.d, now)) : ''}</small></div>`).join('')}</div></div>`;
334
+ }
335
+ /** A closed or completed initiative (its workflow's done, won't do or archived step): they fold into one line at the end of the list. */
336
+ export const isClosed = (r) => !!(r.closed || ['done', 'wontdo', 'archived'].includes(catOfRow(r)));
337
+ let CARD = null, SHUT = true, COLS_OPEN = false, LAST = null; // the row whose stage card is open; the closed ones folded; the menu's Columns open; the rows last drawn
338
+
339
+ /** The whole list. rows: the initiatives on screen. o: { now, many, sel, canMove(r), product(r), programOf(r), goalOf(r), goalGroups(rows),
340
+ * bar(r, W): the Board's own bar for a row (else the plain one) } → html. The closed ones fold into one line at the end. */
341
+ export function listHtml(rows, o = {}) {
342
+ const v = read(), now = o.now || new Date(), keys = colsShown(v, o), tl = v.tl !== false;
343
+ const oo = { ...o, now, product: o.product || ((r) => r.product || '') };
344
+ LAST = { rows, o: oo };
345
+ const every = rows; rows = filterRows(rows, oo);
346
+ const W = windowOf(v.span, rows.length ? rows : every, now), T = ticksOf(W), grid = gridHtml(W, T, now);
347
+ const tpl = (tl ? 'minmax(160px,220px) ' : 'minmax(0,1fr) ') + keys.map((k) => byK[k].w + 'px').join(' ') + (tl ? ' minmax(240px,1fr)' : '');
348
+ const sortHd = (k, n) => { const x = v.sorts.find((y) => y.k === k), on = !!x, first = on && v.sorts[0].k === k; return `<span role="columnheader" aria-sort="${first ? (x.up ? 'ascending' : 'descending') : 'none'}"><button type="button" class="wk-hd${on ? ' on' : ''}" data-wksort="${k}" title="Sort by ${esc(n.toLowerCase())}">${esc(n)}${on ? `<span class="wk-sar${x.up ? '' : ' dn'}">${SV(I.sort, 12)}</span>` : ''}</button></span>`; };
349
+ const spanName = (SPANS.find(([k]) => k === v.span) || SPANS[5])[1];
350
+ const tlHead = !tl ? '' : `<span role="columnheader" class="wk-x wk-xh"><span class="wk-tl">${T.filter((t) => t.show && X(W, t.mid) > 14).map((t) => `<span class="wk-tk" style="left:${P(X(W, t.mid))}">${esc(t.label)}</span>`).join('')}`
351
+ + (inW(W, today(now)) ? `<i class="wk-nowl" style="left:${P(X(W, today(now)))}">Today</i>` : '') + `</span>`
352
+ + `<button type="button" class="wk-hide" data-wktl="off" aria-label="Hide the timeline" title="Hide the timeline">${SV(I.hide, 13)}</button>`
353
+ + `<span class="wk-spw"><button type="button" class="wk-span" data-wkspan aria-haspopup="menu" aria-expanded="false" aria-label="Span of the timeline: ${esc(spanName)}" title="Span of the timeline">${esc(spanName)}${SV(I.chev, 11)}</button>`
354
+ + `<span class="wk-spm" role="menu" aria-label="Span of the timeline" hidden><span class="h">Span</span>${SPANS.map(([k, n]) => `<button type="button" role="menuitemradio" aria-checked="${k === v.span}" class="o${k === v.span ? ' on' : ''}" data-wkspick="${k}">${esc(n)}</button>`).join('')}</span></span></span>`;
355
+ const showTl = tl ? '' : `<button type="button" class="wk-show" data-wktl="on" aria-label="Show the timeline" title="Show the timeline">${SV(I.show, 13)}</button>`;
356
+ let h = showingHtml(every.length - rows.length) + `<div class="wk${tl ? ' has-x' : ''}" role="table" aria-label="Initiatives" style="--wk-cols:${tpl}">`
357
+ + `<div class="wk-r wk-h" role="row">${sortHd('title', 'Initiative')}${keys.map((k) => sortHd(k, byK[k].n)).join('')}${tlHead}${showTl}</div>`;
358
+ const row = (r) => `<div class="wk-r wk-i${o.sel === r.key ? ' sel' : ''}${CARD === r.key ? ' hov' : ''}${isClosed(r) ? ' cl' : ''}" role="row" tabindex="0" data-key="${esc(r.key)}" aria-label="${esc(r.title + (keys.length ? ', ' + words(r, keys, oo) : ''))}">`
359
+ + `<span role="cell" class="n">${esc(r.title)}</span>${keys.map((k) => cellHtml(r, k, oo)).join('')}`
360
+ + (tl ? `<span role="cell" class="wk-x" data-wkbar="${esc(r.key)}"><span class="wk-bw">${grid}${o.bar ? o.bar(r, W) : barHtml(r, W, { now })}${CARD === r.key ? cardHtml(r, W, now) : ''}</span></span>` : '') + '</div>';
361
+ if (!rows.length && every.length) h += `<p class="wk-empty">No initiative matches these filters. <button type="button" class="wk-sa" data-wkclear>Show all</button></p>`;
362
+ const all = o.order ? o.order(rows) : rows, base = all.filter((r) => !isClosed(r)), shut = all.filter(isClosed), G = groupsOf(base, v.group, oo);
363
+ const gline = (inner) => `<div class="wk-r wk-g" role="row">${inner}${tl ? `<span class="wk-x" aria-hidden="true"><span class="wk-bw">${grid}</span></span>` : ''}</div>`;
364
+ if (!G) h += sortRows(base, oo).map(row).join('');
365
+ else for (const g of G) {
366
+ h += gline(`<span role="rowheader">${esc(g.name)}<small>${g.rows.length}</small></span>`);
367
+ h += sortRows(g.rows, oo).map(row).join('');
368
+ }
369
+ // the closed and completed ones: one last line that opens them, as done tasks fold in the Work breakdown
370
+ if (shut.length) {
371
+ h += gline(`<span role="rowheader"><button type="button" class="wk-fold" data-wkclosed aria-expanded="${!SHUT}">${SV(I.chev, 12)}${shut.length} closed</button></span>`);
372
+ if (!SHUT) h += sortRows(shut, oo).map(row).join('');
373
+ }
374
+ h += '</div>';
375
+ if (tl) h += `<div class="wk-key"><span><i class="k dn"></i>Done</span><span><i class="k nw"></i>Now</span><span><i class="k pl"></i>Planned</span><span><i class="k dlv"></i>Milestone</span><span><i class="k-late"></i>Late</span><span>Press a bar to see its stages and their dates</span></div>`;
376
+ return h;
377
+ }
378
+
379
+ /* ── the view menu (round 3; the design thread's order, 2026-11-19): Filter, Sort, View, then Columns folded; "PMOS remembers this" at the foot,
380
+ * with Reset only when something differs from the usual. About 360 px wide, small quiet titles, pills (no nested menu). ── */
381
+ const PILLS = 6; // a facet with more values shows its first six and "N more"
382
+ let MORE = new Set();
383
+ /** o: { many, sprint: the page's current sprint { name, passed, over, end } } → html */
384
+ export function menuHtml(o = {}) {
385
+ const v = read(), u = usual();
386
+ const sw = (on, label, data) => `<button type="button" class="wk-sw${on ? ' on' : ''}" role="switch" aria-checked="${on}" aria-label="${esc(label)}" ${data}></button>`;
387
+ const shown = v.cols.filter((c) => c.on), hid = v.cols.filter((c) => !c.on);
388
+ const rw = (c) => `<div class="wk-mr${c.on ? '' : ' off'}" draggable="true" data-wkcol="${c.k}"><i class="gp" aria-hidden="true"></i><span>${esc(byK[c.k].n)}</span>${sw(c.on, byK[c.k].n, `data-wkcolsw="${c.k}"`)}</div>`;
389
+ // Filter
390
+ const F = LAST ? facetsOf(LAST.rows, LAST.o) : [];
391
+ // the sprints: the current one first; one that has ended reads quiet, "MAD Sprint 115 · ended"
392
+ const sp = o.sprint, cmp = (a, b) => String(a).localeCompare(String(b), undefined, { numeric: true });
393
+ const ended = (v) => !!sp && (v === sp.passed || (v === sp.name ? !!sp.over : cmp(v, sp.name) < 0));
394
+ for (const f of F) if (f.k === 'sprint' && sp) f.vals.sort((a, b) => (b.v === sp.name) - (a.v === sp.name) || cmp(b.v, a.v));
395
+ const pill = (f, x) => { const end = f.k === 'sprint' && ended(x.v); return `<button type="button" class="${x.on ? 'on' : ''}${end ? ' q' : ''}" aria-pressed="${x.on}" data-wkf="${f.k}" data-wkv="${esc(x.v)}">${esc(x.word)}${end ? '<em> · ended</em>' : ''}<small>${x.n}</small></button>`; };
396
+ const facet = (f) => {
397
+ const all = MORE.has(f.k) || f.vals.length <= PILLS + 1, vals = all ? f.vals : f.vals.slice(0, PILLS);
398
+ return `<div class="wk-fg" role="group" aria-label="${esc(f.n)}"><span class="wk-fl">${esc(f.n)}</span><div class="wk-pl">${vals.map((x) => pill(f, x)).join('')}${all ? '' : `<button type="button" class="wk-mo" data-wkmore="${f.k}">${f.vals.length - PILLS} more</button>`}</div></div>`;
399
+ };
400
+ const later = sp && F.some((f) => f.k === 'sprint' && f.vals.some((x) => cmp(x.v, sp.name) > 0));
401
+ const spNote = !sp ? '' : sp.passed ? `<p class="wk-note">${esc(sp.passed)} has ended, showing ${esc(sp.name)}.</p>`
402
+ : sp.over && !later ? `<p class="wk-note">${esc(sp.name)} has ended${sp.end ? ' on ' + esc(dm(day(sp.end), new Date())) : ''}. <button type="button" class="wk-lk" data-wkx="jira">Read Jira again</button></p>` : '';
403
+ const filt = F.length ? F.map(facet).join('') + spNote : '<p class="wk-note">Nothing to filter yet.</p>';
404
+ // Sort
405
+ const S = v.sorts, word = (k) => (SORT_KEYS.find(([x]) => x === k) || [k, (byK[k] || {}).n || k])[1];
406
+ const sortPills = `<button type="button" class="${S.length ? '' : 'on'}" aria-pressed="${!S.length}" data-wksortp="">PMOS order</button>`
407
+ + SORT_KEYS.map(([k, n]) => { const i = S.findIndex((x) => x.k === k); if (i < 0) return `<button type="button" aria-pressed="false" data-wksortp="${k}">${esc(n)}</button>`;
408
+ return `<span class="wk-sk"><button type="button" class="on" aria-pressed="true" data-wksortp="${k}" aria-label="${esc((i + 1) + ': ' + n + ', ' + (S[i].up ? 'first to last' : 'last to first') + '. Turn it round')}"><b>${i + 1}</b>${esc(n)}<span class="wk-sar${S[i].up ? '' : ' dn'}">${SV(I.sort, 11)}</span></button><button type="button" class="x" data-wksortx="${k}" aria-label="Stop sorting by ${esc(n.toLowerCase())}">${SV(I.x, 11)}</button></span>`; }).join('');
409
+ const differs = JSON.stringify(v) !== JSON.stringify(u) || filterOn();
410
+ return `<div class="wk-menu" role="dialog" aria-label="Filter, sort and view">`
411
+ + `<section><h6>Filter${filterOn() ? ` <button type="button" class="wk-lk" data-wkclear>Clear</button>` : ''}</h6>${filt}</section>`
412
+ + `<section><h6>Sort${S.length ? ` <small>· ${esc(S.map((x) => word(x.k)).join(', then '))}</small>` : ''}</h6><div class="wk-pl wk-sorts">${sortPills}</div></section>`
413
+ + `<section><h6>View</h6><div class="wk-fg"><span class="wk-fl">Group by</span><div class="wk-pl" role="radiogroup" aria-label="Group by">${GROUPS.map(([k, n]) => `<button type="button" role="radio" aria-checked="${k === v.group}" class="${k === v.group ? 'on' : ''}" data-wkgroup="${k}">${esc(n)}</button>`).join('')}</div></div>`
414
+ + `<div class="wk-mr wk-tlr"><span>Timeline</span>${sw(v.tl, 'Timeline', 'data-wktlsw')}</div></section>`
415
+ + `<section><button type="button" class="wk-cx" data-wkcols aria-expanded="${COLS_OPEN}"><span>Columns</span><small>${shown.length + 1} of ${v.cols.length + 1}</small>${SV(I.chev, 12)}</button>`
416
+ + (COLS_OPEN ? `<p class="wk-note">Drag to change the order.</p><div class="wk-mr lk"><i></i><span>Initiative</span><small>always</small></div>${shown.map(rw).join('')}${hid.length && shown.length ? '<hr>' : ''}${hid.map(rw).join('')}` : '') + `</section>`
417
+ + `<div class="wk-ft"><span>PMOS remembers this</span>${differs ? '<button type="button" class="wk-rs" data-wkreset>Reset</button>' : ''}</div></div>`;
418
+ }
419
+
420
+ /** What a press in the list or the menu means, or null when it is not Work's own. → { kind, ... } */
421
+ export function pressOf(t) {
422
+ const q = (s) => t.closest && t.closest(s);
423
+ let b;
424
+ if ((b = q('[data-wksort]'))) return { kind: 'sort', k: b.dataset.wksort };
425
+ if ((b = q('[data-wksortx]'))) return { kind: 'unsort', k: b.dataset.wksortx };
426
+ if ((b = q('[data-wksortp]'))) return { kind: 'addsort', k: b.dataset.wksortp };
427
+ if ((b = q('[data-wkf]'))) return { kind: 'filter', k: b.dataset.wkf, v: b.dataset.wkv };
428
+ if ((b = q('[data-wkmore]'))) return { kind: 'more', k: b.dataset.wkmore };
429
+ if (q('[data-wkclear]')) return { kind: 'clear' };
430
+ if (q('[data-wkcols]')) return { kind: 'cols' };
431
+ if ((b = q('[data-wkspick]'))) return { kind: 'span', span: b.dataset.wkspick };
432
+ if (q('[data-wkspan]')) return { kind: 'spanmenu' };
433
+ if ((b = q('[data-wktl]'))) return { kind: 'timeline', on: b.dataset.wktl === 'on' };
434
+ if ((b = q('[data-wkstage]'))) return { kind: 'stage', key: b.dataset.wkstage, el: b };
435
+ if (q('[data-wkclosed]')) return { kind: 'closed' };
436
+ if (q('.wk-card')) return { kind: 'inside' };
437
+ // a press on the bar itself (not its ◇, its gap or its late line, which open their own popups) opens the stage card
438
+ if ((b = q('[data-wkbar]')) && q('.tg-bar, .wk-bar')) return { kind: 'card', key: b.dataset.wkbar };
439
+ if ((b = q('[data-wkgroup]'))) return { kind: 'group', group: b.dataset.wkgroup };
440
+ if (q('[data-wktlsw]')) return { kind: 'timeline', on: !read().tl };
441
+ if ((b = q('[data-wkcolsw]'))) { const c = read().cols.find((x) => x.k === b.dataset.wkcolsw); return { kind: 'col', k: b.dataset.wkcolsw, on: !(c && c.on) }; }
442
+ if (q('[data-wkreset]')) return { kind: 'reset' };
443
+ return null;
444
+ }
445
+ /** Apply a press that only changes the view. → true when the list must be drawn again. */
446
+ export function apply(p) {
447
+ if (p.kind === 'sort') setSort(p.k);
448
+ else if (p.kind === 'span') setSpan(p.span);
449
+ else if (p.kind === 'timeline') setTimeline(p.on);
450
+ else if (p.kind === 'group') setGroup(p.group);
451
+ else if (p.kind === 'col') setCol(p.k, p.on);
452
+ else if (p.kind === 'reset') { reset(); clearFilter(); }
453
+ else if (p.kind === 'addsort') { if (p.k) addSort(p.k); else write({ ...read(), sorts: [] }); }
454
+ else if (p.kind === 'unsort') dropSort(p.k);
455
+ else if (p.kind === 'filter') setFilter(p.k, p.v);
456
+ else if (p.kind === 'clear') clearFilter();
457
+ else if (p.kind === 'more') MORE.add(p.k);
458
+ else if (p.kind === 'cols') COLS_OPEN = !COLS_OPEN;
459
+ else if (p.kind === 'closed') SHUT = !SHUT;
460
+ else if (p.kind === 'card') CARD = CARD === p.key ? null : p.key;
461
+ else if (p.kind === 'inside') return false;
462
+ else return false;
463
+ return true;
464
+ }
465
+ /** The drag in the menu: a column row dropped on another moves before it. on(): draw again. */
466
+ export function wireDrag(menu, on) {
467
+ let from = null;
468
+ menu.addEventListener('dragstart', (e) => { const r = e.target.closest('[data-wkcol]'); if (!r) return; from = r.dataset.wkcol; r.classList.add('drag'); try { e.dataTransfer.setData('text/plain', from); e.dataTransfer.effectAllowed = 'move'; } catch { /* some browsers refuse */ } });
469
+ menu.addEventListener('dragover', (e) => { const r = from && e.target.closest('[data-wkcol]'); if (!r) return; e.preventDefault(); menu.querySelectorAll('.drop').forEach((x) => x.classList.remove('drop')); if (r.dataset.wkcol !== from) r.classList.add('drop'); });
470
+ menu.addEventListener('dragend', () => { from = null; menu.querySelectorAll('.drag, .drop').forEach((x) => x.classList.remove('drag', 'drop')); });
471
+ menu.addEventListener('drop', (e) => { const r = from && e.target.closest('[data-wkcol]'); if (!r) return; e.preventDefault(); const k = from; from = null; if (r.dataset.wkcol !== k) { moveCol(k, r.dataset.wkcol); on(); } });
472
+ // the keyboard: Alt+↑ and Alt+↓ on a column's switch move it
473
+ menu.addEventListener('keydown', (e) => {
474
+ if (!e.altKey || (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')) return;
475
+ const r = e.target.closest('[data-wkcol]'); if (!r) return;
476
+ e.preventDefault();
477
+ const v = read(), i = v.cols.findIndex((c) => c.k === r.dataset.wkcol), j = e.key === 'ArrowUp' ? i - 1 : i + 2;
478
+ moveCol(r.dataset.wkcol, j >= 0 && j < v.cols.length ? v.cols[j].k : null); on(r.dataset.wkcol);
479
+ });
480
+ }
481
+ /** The open stage card, or null; closeCard() shuts it. → true when one was open. */
482
+ export const cardOf = () => CARD;
483
+ export function closeCard() { const was = CARD; CARD = null; return !!was; }
@@ -0,0 +1,11 @@
1
+ /* pm/cozy-bar.css — the gap line and the milestone card of the one bar (pm/cozy-bar.js). The bars themselves keep the original classes of
2
+ * ini-view.css (iva-b, iva-tb, iva-md, iva-late). */
3
+ .cb-gap { position: absolute; top: 50%; height: 2px; margin-top: -1px; background: color-mix(in srgb, var(--cz-ink3) 45%, var(--cz-card)); z-index: 1; }
4
+ button.cb-md { cursor: pointer; }
5
+ button.cb-md:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
6
+ .cb-card { display: flex; flex-direction: column; gap: 2px; min-width: 200px; }
7
+ .cb-card p { margin: 0; }
8
+ .cb-k { font-size: var(--fs-label); font-weight: var(--fw-strong); color: var(--cz-ink3); }
9
+ .cb-t { font-size: var(--fs-row); font-weight: var(--fw-strong); color: var(--cz-ink); }
10
+ .cb-w { font-size: var(--fs-meta); color: var(--cz-ink2); }
11
+ .cb-late { color: var(--cz-late); }
@@ -0,0 +1,99 @@
1
+ /* pm/cozy-bar.js — one bar for every timeline of work: the original workspace bar (pm/ini-tasks.js allHtml, the All timeline of an initiative;
2
+ * pm/bd-span.js for the gap line), as pure markup, so Work and the popup's Work breakdown draw the same bar (Wawan, 2026-11-19: "the bar
3
+ * follows the original workspace bar design, with the milestone and its popup, with the gap line, with the proper colour for each status").
4
+ *
5
+ * stageBar(s, X, o) → markup a stage: s { start, end, tone: 'dn' | 'now' | '', late, ms (a ◆ stage: its ◇ only), gaps: [[a, b]], marks } — the bar in its
6
+ * stage tone (done grey, in progress blue, to do light), cut by a 2 px hairline in the To do grey where nothing is
7
+ * dated for two weeks or more (bd-span.js No activity / Nothing planned), with the gap's words as its title
8
+ * taskBar(x, X, today) → markup a task: x { uid, title, start, end, done, prog, wont, late, ms } — the task box's tone (To do hollow, In progress
9
+ * blue, Done grey, Won't do dashed); late keeps its fill and a 3 px late line runs on to Today and ends in a dot.
10
+ * A milestone is its ◇ on its date, a press (data-cb-ms) that opens its card (msCard)
11
+ * msMark(x, X) → markup one milestone ◇ (filled done, orange late) on a stage's bar
12
+ * gapsOf(dates, a, b, today, min) → [[a, b]] the stretches inside [a, b] with no dated work, min days or more (14)
13
+ * gapWords(a, b, today) → "No activity, 19 Sep to 18 Oct · 4 wk" | "Nothing planned, …" (split at today when it runs across)
14
+ * msCard(x, today) → markup the milestone's card: its name, its date (late in orange) and its state, with "Open the task" when it has one
15
+ * X(iso) → a position in % of the track (a number). Classes are the original ones (ini-view.css: iva-b, iva-tb, iva-md, iva-late); the hairline
16
+ * is cb-gap (cozy-bar.css). Positions are inline (left, width in %), so no place() step is needed. */
17
+ const DAY = 864e5;
18
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
19
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
20
+ const day = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
21
+ const iso = (n) => new Date(n).toISOString().slice(0, 10);
22
+ const md = (n) => { const d = new Date(n); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()]; };
23
+ const f = (n) => (Math.round(n * 100) / 100).toFixed(2);
24
+ const at = (l, w) => `style="left:${f(l)}%${w != null ? `;width:${f(Math.max(0.6, w))}%` : ''}"`;
25
+
26
+ if (typeof document !== 'undefined' && document.head) {
27
+ for (const n of ['./ini-view.css', './cozy-bar.css']) {
28
+ const href = new URL(n, import.meta.url).href;
29
+ if (![...document.querySelectorAll('link[rel="stylesheet"]')].some((l) => l.href === href)) { const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = href; document.head.appendChild(l); }
30
+ }
31
+ }
32
+
33
+ /** The stretches inside [a, b] with no dated work (each date range in dates covers its days), min days or more. */
34
+ export function gapsOf(dates, a, b, min = 14) {
35
+ const A = day(a), B = day(b); if (A == null || B == null || B <= A) return [];
36
+ const R = (dates || []).map(([s, e]) => [day(s || e), day(e || s)]).filter(([s, e]) => s != null && e != null).map(([s, e]) => [Math.min(s, e), Math.max(s, e)]).sort((p, q) => p[0] - q[0]);
37
+ if (!R.length) return [];
38
+ const out = []; let cur = A;
39
+ for (const [s, e] of R) { if (s - cur >= min * DAY) out.push([iso(cur), iso(s)]); if (e > cur) cur = e; }
40
+ if (B - cur >= min * DAY && cur < B) out.push([iso(cur), iso(B)]);
41
+ return out;
42
+ }
43
+ const lenOf = (a, b) => { const n = Math.round((b - a) / DAY) + 1; return n < 7 ? n + (n === 1 ? ' day' : ' days') : Math.round(n / 7) + ' wk'; };
44
+ /** A gap's words (bd-span.js gapWords): before today "No activity", after it "Nothing planned", split at today when it runs across. */
45
+ export function gapWords(a, b, today) {
46
+ const t = day(today), p = day(a) + DAY, q = day(b) - DAY;
47
+ const say = (w, u, v) => w + ', ' + md(u) + ' to ' + md(v) + ' · ' + lenOf(u, v);
48
+ if (q < p) return '';
49
+ if (t == null || q < t) return say('No activity', p, q);
50
+ if (p >= t) return say('Nothing planned', p, q);
51
+ return say('No activity', p, t - DAY) + '. ' + say('Nothing planned', t, q);
52
+ }
53
+ /** One milestone ◇ on a bar: filled when done, orange when late. A press opens its card. */
54
+ export function msMark(x, X) {
55
+ const b = day(x.end); if (b == null) return '';
56
+ const st = x.done ? ', done' : x.late ? ', late' : '';
57
+ return `<button type="button" class="iva-md cb-md${x.done ? ' dn' : x.late ? ' lt' : ''}" data-cb-ms="${esc(x.uid || '')}" ${at(X(x.end))} aria-haspopup="dialog" aria-label="${esc('Milestone ' + x.title + ', ' + md(b) + st)}" title="${esc(x.title + ' · ' + md(b))}"></button>`;
58
+ }
59
+ /** A stage: its bar in the stage's tone, cut where nothing is dated (the hairline), its milestones as ◇. */
60
+ export function stageBar(s, X, o = {}) {
61
+ const a = s.start || s.end, b = s.end || s.start; if (!a) return '';
62
+ if (s.ms) return `<i class="iva-md st${s.tone === 'dn' ? ' dn' : ''}" ${at(X(b))} role="img" aria-label="${esc((s.name || 'Milestone') + ', ' + md(day(b)))}"></i>`;
63
+ const tone = s.tone === 'dn' || s.tone === 'now' ? ' ' + s.tone : '';
64
+ const gaps = (s.gaps || []).filter(([p, q]) => q > a && p < b).sort((p, q) => (p[0] < q[0] ? -1 : 1));
65
+ const end = (v) => X(iso(day(v) + DAY));
66
+ let out = '', cur = a;
67
+ for (const [p, q] of gaps) {
68
+ if (p > cur) out += `<i class="iva-b${tone}" ${at(X(cur), end(p) - X(cur))} aria-hidden="true"></i>`;
69
+ const w = gapWords(p, q, o.today);
70
+ out += `<i class="cb-gap" ${at(end(p), X(q) - end(p))} role="img" aria-label="${esc(w)}" title="${esc(w)}"></i>`;
71
+ cur = q;
72
+ }
73
+ if (cur <= b) out += `<i class="iva-b${tone}" ${at(X(cur), end(b) - X(cur))} aria-hidden="true"></i>`;
74
+ // a stage still under way past its end: the late line runs on to Today (bd-span.js: a late row draws an orange line from its end to Today)
75
+ return out + lateLine({ end: b, late: !!s.late }, X, day(o.today)) + (s.marks || []).map((m) => msMark(m, X)).join('');
76
+ }
77
+ /** A task: its box's tone; late keeps the fill and a line runs on to Today; a milestone is its ◇. */
78
+ export function taskBar(x, X, today) {
79
+ const a = day(x.start), b = day(x.end); if (a == null && b == null) return '';
80
+ const t = day(today);
81
+ if (x.ms && b != null && !x.wont) return msMark(x, X) + lateLine(x, X, t);
82
+ const tone = x.wont ? 'wo' : x.done ? 'dn' : x.prog ? 'pr' : 'to';
83
+ const s0 = a == null ? b : a, e0 = b == null ? a : Math.max(a, b);
84
+ const lbl = [x.title, a != null && b != null && a !== b ? md(a) + ' to ' + md(b) : md(e0), x.done ? 'done' : x.late ? 'late' : x.prog ? 'in progress' : ''].filter(Boolean).join(', ');
85
+ const ln = lateLine(x, X, t);
86
+ return `<i class="iva-tb ${tone}" ${at(X(iso(s0)), X(iso(e0 + DAY)) - X(iso(s0)))} role="img" aria-label="${esc(lbl)}"></i>` + ln;
87
+ }
88
+ /** Late keeps its fill: a 3 px line in the late colour from the day after the due day to Today, ending in a dot. */
89
+ function lateLine(x, X, t) {
90
+ const b = day(x.end), n = x.late && !x.done && b != null && t != null && b < t ? Math.round((t - b) / DAY) : 0;
91
+ return n ? `<i class="iva-late" ${at(X(iso(b + DAY)), X(iso(t)) - X(iso(b + DAY)))} role="img" aria-label="${esc(n + (n === 1 ? ' day' : ' days') + ' late')}"></i>` : '';
92
+ }
93
+ /** The milestone's card: name, date, state, and "Open the task" when it is a task. */
94
+ export function msCard(x, today) {
95
+ const b = day(x.end), t = day(today), late = !x.done && b != null && t != null && b < t ? Math.round((t - b) / DAY) : 0;
96
+ const when = b == null ? 'No date yet' : md(b) + (new Date(b).getUTCFullYear() !== new Date(t || b).getUTCFullYear() ? ' ' + new Date(b).getUTCFullYear() : '');
97
+ return `<div class="cb-card"><p class="cb-k">Milestone</p><p class="cb-t">${esc(x.title)}</p><p class="cb-w">${esc(when)}${late ? ` · <span class="cb-late">${late} ${late === 1 ? 'day' : 'days'} late</span>` : x.done ? ' · Done' : ''}</p>`
98
+ + (x.uid ? `<div class="hi-acts"><button type="button" class="hi-btn" data-cb-open="${esc(x.uid)}">Open the task</button></div>` : '') + '</div>';
99
+ }