create-pmos 0.442.0 → 0.444.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 (81) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +1 -1
  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/workspace/briefing-premium-board-test.js +8 -2
  7. package/workspace/briefing-premium-insights-test.js +40 -38
  8. package/workspace/briefing-premium-test.js +2 -1
  9. package/workspace/changelog.json +24 -0
  10. package/workspace/goals-clear-ui-test.js +263 -0
  11. package/workspace/guide/home.md +12 -2
  12. package/workspace/guide/metric-drafts.md +8 -2
  13. package/workspace/home-railcard-test.js +193 -0
  14. package/workspace/intel-report-ui-test.js +1 -1
  15. package/workspace/intelligence-gaps-ui-test.js +16 -14
  16. package/workspace/lib/board-premium.js +1 -1
  17. package/workspace/lib/engine/boards.js +9 -2
  18. package/workspace/lib/engine/records/index.js +9 -2
  19. package/workspace/lib/initiative-layout.js +3 -1
  20. package/workspace/lib/insights-premium.js +22 -1
  21. package/workspace/lib/metric-drafts.js +37 -10
  22. package/workspace/lib/metric-read-runs.js +20 -13
  23. package/workspace/lib/metric-reads.js +208 -23
  24. package/workspace/lib/metrics-cli.js +62 -5
  25. package/workspace/lib/routes-boards.js +40 -1
  26. package/workspace/lib/routes-goal-status.js +89 -6
  27. package/workspace/lib/routes-insights-premium.js +1 -1
  28. package/workspace/lib/routes-metric-drafts.js +26 -3
  29. package/workspace/live-pill-round-test.js +178 -0
  30. package/workspace/metric-drafts-ui-test.js +5 -2
  31. package/workspace/okr-goals-ui-test.js +27 -23
  32. package/workspace/package-lock.json +2 -2
  33. package/workspace/package.json +1 -1
  34. package/workspace/panels-test.js +231 -0
  35. package/workspace/premium-board-actions-test.js +2 -2
  36. package/workspace/premium-rec-tab-test.js +2 -1
  37. package/workspace/premium-vw-item-test.js +10 -2
  38. package/workspace/premium-vw-jira-test.js +3 -0
  39. package/workspace/public/pm/bd-ini-panel.js +3 -2
  40. package/workspace/public/pm/cozy-adler.js +21 -0
  41. package/workspace/public/pm/cozy-divider.css +32 -0
  42. package/workspace/public/pm/cozy-divider.js +45 -0
  43. package/workspace/public/pm/cozy-insights.css +96 -0
  44. package/workspace/public/pm/cozy-live-pill.css +16 -17
  45. package/workspace/public/pm/cozy-live-pill.js +28 -17
  46. package/workspace/public/pm/cozy-panels.css +59 -0
  47. package/workspace/public/pm/cozy-panels.js +524 -0
  48. package/workspace/public/pm/cozy-today.css +15 -0
  49. package/workspace/public/pm/cozy-viewer.js +173 -69
  50. package/workspace/public/pm/cozy-vw-shell.css +4 -0
  51. package/workspace/public/pm/goals-clear.js +265 -0
  52. package/workspace/public/pm/home-app.js +73 -14
  53. package/workspace/public/pm/home-ini.js +9 -3
  54. package/workspace/public/pm/home-today.js +55 -12
  55. package/workspace/public/pm/ini-edit.js +401 -0
  56. package/workspace/public/pm/ini-groups.js +14 -8
  57. package/workspace/public/pm/ini-tasks.js +84 -26
  58. package/workspace/public/pm/ini-versions.js +18 -4
  59. package/workspace/public/pm/ini-view-model.js +45 -18
  60. package/workspace/public/pm/ini-view.css +117 -5
  61. package/workspace/public/pm/ini-view.js +51 -17
  62. package/workspace/public/pm/metric-drafts.js +4 -1
  63. package/workspace/public/pm/mission.js +11 -7
  64. package/workspace/public/pm/premium-board.js +8 -6
  65. package/workspace/public/pm/premium-insights.js +375 -59
  66. package/workspace/public/pm/task-card.css +2 -0
  67. package/workspace/public/pm/task-card.js +4 -1
  68. package/workspace/server.js +6 -2
  69. package/workspace/skills/metric-read.skill +7 -5
  70. package/workspace/stage-card-tasks-test.js +396 -0
  71. package/workspace/stage-card-test.js +12 -4
  72. package/workspace/task-delete-test.js +9 -1
  73. package/workspace/task-milestones-test.js +3 -3
  74. package/workspace/task-press-test.js +12 -4
  75. package/workspace/task-views-test.js +198 -5
  76. package/workspace/test-lists/batch18-live-pill-round.json +10 -0
  77. package/workspace/test-lists/batch18-panels.json +9 -0
  78. package/workspace/test-lists/goals-clear.json +15 -0
  79. package/workspace/test-lists/home-railcard.json +9 -0
  80. package/workspace/test-lists/stage-card-tasks.json +6 -0
  81. package/workspace/tk-tasks-test.js +2 -2
@@ -0,0 +1,524 @@
1
+ /* pm/cozy-panels.js — panels side by side, like a tablet (feedback batch 18 item 15, build 15-A; canvas In development TbT1Split to TbT9Divider,
2
+ * sticky "What to build").
3
+ *
4
+ * Home is already a split: the chat, a divider, the Viewer. This module arranges the panels on a page with a Viewer host (Home):
5
+ * Side by side up to 2 panels on a laptop and up to 3 at 1600 px and wider, in one row. A phone keeps today's one panel (the engine is off).
6
+ * Divider between two panels (role separator). A drag snaps at ⅓, ½ and ⅔ of the room; a drag to an edge closes that side (a Viewer
7
+ * closes, the chat slides away). Double-click resets it to ½. ← and → move it 24 px, Home resets it.
8
+ * Chat and one Viewer (today's split): the divider drives the Viewer's own width (cozy-viewer.js setWidth: the list folds to a
9
+ * rail first, the width is kept per kind). Anything else is laid out here with shares of the row.
10
+ * Open beside drag a list row (#hmList [data-hm-sel]), a Live pill row or a file or link chip in the chat to the left or right of the
11
+ * panels: that half turns blue, and on the drop the row opens in a panel of its own on that side. When a new panel would
12
+ * go over the limit, it replaces the panel used least recently (a Viewer closes, the chat slides over). A plain click
13
+ * still replaces the Viewer used last. Task rows in a stage card keep their own drag (item 16): they are not a source.
14
+ * ⧉ on every panel's header (icon-only, before ×): Full screen, Split, Slide over (TbT7Place). For people who do not drag.
15
+ * Slide over one panel at a time floats over the right side (the chat 400 px, a Viewer 560 px), with a grab bar. A drag or a swipe
16
+ * off the right edge puts it away; the Live pill brings it back (slideOver). Nothing pops open by itself.
17
+ * Remembered each initiative reopens with its panels and shares (localStorage 'cz-pn:<initiative id>', like Android app pairs). A
18
+ * private window forgets it, and the page falls back to today's split.
19
+ * Present while a recording presents (BroadcastChannel 'pmos-present': present or show), the chat slides away by itself; on Stop
20
+ * (off, or the recording ends) it comes back.
21
+ *
22
+ * mountPanels({ desk, chat, go?(item) → true, reopen?(item) }) once, on the page. go: the page opens a Live pill row in its chat (Home's
23
+ * own Live pill handler). reopen: the page opens a remembered Viewer item ({ id, kind, title }) again, or says false.
24
+ * window.czPanels = { list(), place(id, 'full'|'split'|'over'), slideOver(item?), putAway(), away(), onChange(fn), scope(id) }
25
+ * panel ids: 'chat', 'v0', 'v1', 'v2' (v0 is #czViewer). list() → [{ id, kind: 'chat'|'viewer', mode: 'split'|'over'|'away', full,
26
+ * title }]. slideOver(item): a Live pill row (item.sid, a session) opens in the chat, and the chat floats over when it is not in the row;
27
+ * a Viewer item ({ kind, title, render | html }) opens in a Viewer that floats over; no item brings back the panel put away. It returns
28
+ * false when it did nothing, so the caller falls back to its own open. away() → the panel put away last, or null. scope(id): the page
29
+ * shows that initiative now (null: none); its panels are restored.
30
+ * The document gets the event 'cz-panels' with { panels: list(), over, away } after each change.
31
+ * The divider's look (Adler's sprout, the day's charm) is cozy-divider.js's (build 15-B); this module owns the element, its drag and keys. */
32
+ import { panels as P, open as openViewer, PHONE } from './cozy-viewer.js';
33
+ import { dividerHtml } from './cozy-divider.js';
34
+ import { onRecording } from './rec-state.js';
35
+
36
+ const SHEET = new URL('./cozy-panels.css', import.meta.url).href;
37
+ const SNAP = [1 / 3, 1 / 2, 2 / 3], SNAPPX = 20, EDGE = 120, STEP = 24, WIDE = 1600, PANEL = 440, AWAYPX = 96;
38
+ const SRC = '#hmList button[data-hm-sel], #czLiveList a[data-lv], #hmChat [data-file], #hmChat [data-ctx], #hmChat [data-att]';
39
+ const IC = {
40
+ full: 'M3.5 5h17v14h-17z', split: 'M3.5 5h17v14h-17zM12 5v14', over: 'M3.5 5h17v14h-17zM14 8h4v8h-4z',
41
+ place: 'M3.5 5h17v14h-17zM12 5v14', close: 'M6 6l12 12M18 6L6 18',
42
+ };
43
+ const NAME = { full: 'Full screen', split: 'Split', over: 'Slide over' };
44
+ const svg = (d, w = 18) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
45
+ const store = {
46
+ get(k) { try { return JSON.parse(localStorage.getItem(k) || 'null'); } catch { return null; } },
47
+ set(k, v) { try { if (v == null) localStorage.removeItem(k); else localStorage.setItem(k, JSON.stringify(v)); } catch { /* a private window */ } },
48
+ };
49
+ const isPhone = () => innerWidth <= PHONE;
50
+ const maxRow = () => (innerWidth >= WIDE ? 3 : 2);
51
+ const S = { on: false, desk: null, chat: null, row: ['chat'], over: null, away: [], fr: [], used: {}, subs: [], go: null, reopen: null, pend: null, scope: null, auto: false, restoring: false, keepList: false, noClick: 0, divs: [] };
52
+
53
+ /* ── the panels and their elements ── */
54
+ const isV = (id) => /^v\d$/.test(id || '');
55
+ const vs = () => P.list().filter((p) => p.open);
56
+ const elOf = (id) => (id === 'chat' ? S.chat : (P.list().find((p) => p.id === id) || {}).el || null);
57
+ const visible = (id) => S.row.includes(id) || S.over === id;
58
+ const drop = (id) => { S.row = S.row.filter((x) => x !== id); if (S.over === id) S.over = null; S.away = S.away.filter((x) => x !== id); };
59
+ const mark = (id) => { if (id) S.used[id] = performance.now(); };
60
+ const lru = (ids) => ids.slice().sort((a, b) => (S.used[a] || 0) - (S.used[b] || 0))[0];
61
+ /** Today's split, laid out by cozy-viewer.js: the chat alone, or the chat then one Viewer, nothing over and nothing put away. */
62
+ const simple = () => !S.over && !S.away.length && S.row[0] === 'chat' && S.row.length <= 2;
63
+ const managed = () => S.on && !isPhone() && !simple();
64
+
65
+ /** The row and the open Viewers agree: a closed Viewer leaves, the row is never empty, and never over the limit. */
66
+ function sync() {
67
+ const open = vs().map((p) => p.id);
68
+ [...S.row, S.over, ...S.away].filter((id) => isV(id) && !open.includes(id)).forEach(drop);
69
+ if (!S.row.length) {
70
+ if (S.over) { S.row = [S.over]; S.over = null; }
71
+ else { const v = [...S.away].reverse().find(isV); if (v) { drop(v); S.row = [v]; } else { drop('chat'); S.row = ['chat']; } }
72
+ }
73
+ if (!open.length && !S.row.includes('chat')) { drop('chat'); S.row.unshift('chat'); } // no Viewer: the chat is the page, as today
74
+ fit();
75
+ }
76
+ /** Over the limit (a new panel, a narrower window): the panel used least recently gives way. The chat slides over (or away when a panel
77
+ * is over already); a Viewer is put away when soft (a narrower window), else it closes. */
78
+ function fit(keep, soft) {
79
+ while (S.row.length > maxRow()) {
80
+ const id = lru(S.row.filter((x) => x !== keep));
81
+ S.row = S.row.filter((x) => x !== id);
82
+ if (id === 'chat') { if (!S.over) S.over = 'chat'; else S.away.push('chat'); }
83
+ else if (soft) S.away.push(id);
84
+ else { S.away.push(id); setTimeout(() => P.close(id), 0); } // hidden until it closes
85
+ }
86
+ }
87
+ function shares() {
88
+ if (S.fr.length !== S.row.length) S.fr = S.row.map(() => 1 / S.row.length);
89
+ return S.fr;
90
+ }
91
+
92
+ /* ── the layout ── */
93
+ function layout() {
94
+ if (!S.on || !S.desk) return;
95
+ sync();
96
+ const B = document.body, phone = isPhone(), man = managed(), ids = ['chat', ...vs().map((p) => p.id)];
97
+ const back = S.man && !man; // back to today's split: cozy-viewer.js decides the width and the rail again
98
+ if (back) { S.keepList = false; P.rail(false); }
99
+ S.man = man;
100
+ B.classList.toggle('cz-pn', !phone);
101
+ B.classList.toggle('cz-pn-man', man);
102
+ const fr = shares();
103
+ ids.forEach((id) => {
104
+ const el = elOf(id); if (!el) return;
105
+ const at = S.row.indexOf(id);
106
+ el.classList.toggle('cz-pn-row', !phone && at >= 0);
107
+ el.classList.toggle('cz-pn-over', !phone && S.over === id);
108
+ el.classList.toggle('cz-pn-away', !phone && S.away.includes(id));
109
+ el.style.order = !phone && man && at >= 0 ? String(at * 2) : '';
110
+ el.style.flex = !phone && man && at >= 0 ? `${fr[at]} 1 0px` : '';
111
+ grab(el, !phone && S.over === id);
112
+ });
113
+ const host = S.desk.querySelector('[data-cz-viewer-host]');
114
+ if (host) host.style.order = !phone && !man ? '2' : '';
115
+ if (S.chat) S.chat.style.order = !phone && !man ? '0' : S.chat.style.order;
116
+ divs(phone ? 0 : man ? S.row.length - 1 : S.row.length - 1, man);
117
+ if (man && !phone) {
118
+ const room = S.desk.clientWidth - 64 - (S.row.length - 1) * 22; // the desk less its padding and the gaps
119
+ const list = document.getElementById('hmList'), lw = list ? list.offsetWidth || 316 : 0;
120
+ const fold = !S.keepList && (!S.row.includes('chat') || room - lw < S.row.length * PANEL);
121
+ if (fold !== P.railOn()) P.rail(fold);
122
+ }
123
+ if (back) P.rest(); else P.relayout();
124
+ tools();
125
+ emit();
126
+ if (S.scope && !S.restoring) store.set('cz-pn:' + S.scope, snapshot());
127
+ }
128
+ function emit() {
129
+ const d = { panels: list(), over: S.over, away: S.away.slice() };
130
+ S.subs.forEach((f) => { try { f(d); } catch { /* the listener's own */ } });
131
+ document.dispatchEvent(new CustomEvent('cz-panels', { detail: d }));
132
+ }
133
+ function list() {
134
+ const one = S.row.length === 1;
135
+ return ['chat', ...vs().map((p) => p.id)].map((id) => {
136
+ const v = P.list().find((p) => p.id === id);
137
+ const title = id === 'chat' ? ((document.getElementById('hmCh') || {}).textContent || '').trim() || 'Chat' : (v && v.item && v.item.title) || '';
138
+ return { id, kind: id === 'chat' ? 'chat' : 'viewer', mode: S.over === id ? 'over' : S.away.includes(id) ? 'away' : 'split', full: one && S.row[0] === id, title };
139
+ });
140
+ }
141
+
142
+ /* ── the dividers (TbT2Divider, TbT9Divider) ── */
143
+ function divs(n, man) {
144
+ while (S.divs.length > n) S.divs.pop().remove();
145
+ while (S.divs.length < n) S.divs.push(divider());
146
+ S.divs.forEach((d, k) => {
147
+ d.dataset.k = String(k);
148
+ d.style.order = man ? String(k * 2 + 1) : '1';
149
+ if (d.__first !== (k === 0)) { d.__first = k === 0; d.querySelector('.cz-pn-in').innerHTML = dividerHtml({ first: k === 0 }); }
150
+ if (d.parentNode !== S.desk) S.desk.appendChild(d);
151
+ });
152
+ }
153
+ function divider() {
154
+ const d = document.createElement('div');
155
+ d.className = 'cz-pn-div'; d.tabIndex = 0;
156
+ d.setAttribute('role', 'separator'); d.setAttribute('aria-orientation', 'vertical');
157
+ d.setAttribute('aria-label', 'Drag to resize the panels. Double-click to reset to half.'); d.title = 'Drag to resize. Double-click to reset.';
158
+ d.innerHTML = '<span class="cz-pn-in"></span>';
159
+ d.addEventListener('pointerenter', () => d.classList.add('hov'));
160
+ d.addEventListener('pointerleave', () => d.classList.remove('hov'));
161
+ d.addEventListener('pointerdown', (e) => dragDiv(d, e));
162
+ d.addEventListener('dblclick', () => resetDiv(+d.dataset.k));
163
+ d.addEventListener('keydown', (e) => {
164
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') { e.preventDefault(); nudge(+d.dataset.k, e.key === 'ArrowLeft' ? -STEP : STEP); }
165
+ else if (e.key === 'Home') { e.preventDefault(); resetDiv(+d.dataset.k); }
166
+ });
167
+ return d;
168
+ }
169
+ const rect = (id) => { const el = elOf(id); return el ? el.getBoundingClientRect() : null; };
170
+ /** Where the divider k may sit: the pair it parts, the row's left and right, the gap. */
171
+ function geo(k) {
172
+ const a = S.row[k], b = S.row[k + 1], ra = rect(a), rb = rect(b), r0 = rect(S.row[0]), r1 = rect(S.row[S.row.length - 1]);
173
+ if (!ra || !rb || !r0 || !r1) return null;
174
+ return { a, b, ra, rb, L: r0.left, R: r1.right, gap: Math.max(0, rb.left - ra.right) };
175
+ }
176
+ /** x snapped at ⅓, ½ or ⅔ of the row when it is near one. */
177
+ function snap(x, g) {
178
+ const total = g.R - g.L;
179
+ for (const q of SNAP) { const at = g.L + q * total; if (Math.abs(x - at) < SNAPPX) return { x: at, q }; }
180
+ return { x, q: 0 };
181
+ }
182
+ /** The divider k at x: the two panels share their room again (laid out here), or the Viewer takes the width (today's split). */
183
+ function setAt(k, x, g, keep) {
184
+ if (!managed()) { P.size(g.b, g.R - x - g.gap / 2, keep); return; }
185
+ const wa = Math.max(60, x - g.ra.left - g.gap / 2), wb = Math.max(60, g.rb.right - x - g.gap / 2), fr = shares(), s = fr[k] + fr[k + 1];
186
+ fr[k] = s * wa / (wa + wb); fr[k + 1] = s - fr[k];
187
+ [g.a, g.b].forEach((id, i) => { const el = elOf(id); if (el) el.style.flex = `${fr[k + i]} 1 0px`; });
188
+ if (keep) layout();
189
+ }
190
+ function dragDiv(d, e) {
191
+ if (e.button !== 0) return;
192
+ const k = +d.dataset.k, g = geo(k); if (!g) return;
193
+ e.preventDefault(); d.setPointerCapture(e.pointerId);
194
+ d.classList.add('drag'); document.body.classList.add('cz-pn-drag', 'cz-vw-drag');
195
+ mark(g.a); mark(g.b);
196
+ let last = null;
197
+ const mv = (ev) => {
198
+ const s = snap(ev.clientX, g);
199
+ const shut = ev.clientX - g.L < EDGE ? g.a : g.R - ev.clientX < EDGE ? g.b : null; // to an edge: that side closes on the drop
200
+ d.classList.toggle('snap', !!s.q); d.dataset.snap = s.q ? String(Math.round(s.q * 6)) : '';
201
+ [g.a, g.b].forEach((id) => { const el = elOf(id); if (el) el.classList.toggle('cz-pn-shut', id === shut); });
202
+ last = { x: s.x, shut };
203
+ if (!shut) setAt(k, s.x, g, false);
204
+ };
205
+ const up = () => {
206
+ d.removeEventListener('pointermove', mv); d.removeEventListener('pointerup', up); d.removeEventListener('pointercancel', up);
207
+ d.classList.remove('drag', 'snap'); document.body.classList.remove('cz-pn-drag', 'cz-vw-drag');
208
+ [g.a, g.b].forEach((id) => { const el = elOf(id); if (el) el.classList.remove('cz-pn-shut'); });
209
+ if (!last) return;
210
+ if (last.shut) shut(last.shut); else setAt(k, last.x, g, true);
211
+ };
212
+ d.addEventListener('pointermove', mv); d.addEventListener('pointerup', up); d.addEventListener('pointercancel', up);
213
+ }
214
+ function nudge(k, dx) {
215
+ const g = geo(k); if (!g) return;
216
+ setAt(k, g.ra.right + g.gap / 2 + dx, g, true);
217
+ }
218
+ function resetDiv(k) {
219
+ const g = geo(k); if (!g) return;
220
+ if (!managed()) { P.reset(g.b); layout(); return; }
221
+ S.fr = S.row.map(() => 1 / S.row.length); layout();
222
+ }
223
+ /** A panel leaves the row: a Viewer closes, the chat slides away (the Live pill brings it back). */
224
+ function shut(id) {
225
+ if (isV(id)) { P.close(id); return; }
226
+ drop('chat'); S.away.push('chat'); S.fr = []; layout();
227
+ }
228
+
229
+ /* ── the ⧉ menu (TbT7Place) ── */
230
+ let menu = null;
231
+ function closeMenu(focus) {
232
+ if (!menu) return;
233
+ const a = menu.__anchor; menu.remove(); menu = null;
234
+ document.removeEventListener('pointerdown', away, true);
235
+ if (a) { a.setAttribute('aria-expanded', 'false'); if (focus && a.isConnected) a.focus(); }
236
+ }
237
+ function away(e) { if (menu && !menu.contains(e.target) && !(menu.__anchor && menu.__anchor.contains(e.target))) closeMenu(false); }
238
+ function modeOf(id) { return S.over === id ? 'over' : S.row.length === 1 && S.row[0] === id ? 'full' : S.row.includes(id) ? 'split' : 'away'; }
239
+ function openMenu(id, anchor) {
240
+ if (menu) { const same = menu.__anchor === anchor; closeMenu(false); if (same) return; }
241
+ mark(id);
242
+ const now = modeOf(id);
243
+ const m = document.createElement('div');
244
+ m.className = 'cz-pn-menu'; m.setAttribute('role', 'menu'); m.setAttribute('aria-label', 'Arrange'); m.dataset.escLayer = '1';
245
+ m.innerHTML = ['full', 'split', 'over'].map((k) => `<button type="button" role="menuitemradio" aria-checked="${now === k}" data-cz-pn-place="${k}" aria-label="${NAME[k]}" title="${NAME[k]}">${svg(IC[k], 20)}</button>`).join('');
246
+ m.addEventListener('click', (e) => { const b = e.target.closest('[data-cz-pn-place]'); if (!b) return; closeMenu(false); place(id, b.dataset.czPnPlace); });
247
+ m.addEventListener('keydown', (e) => {
248
+ const bs = [...m.querySelectorAll('button')], at = bs.indexOf(document.activeElement);
249
+ if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeMenu(true); }
250
+ else if (/^Arrow(Left|Right|Up|Down)$/.test(e.key)) { e.preventDefault(); const f = /Right|Down/.test(e.key) ? 1 : -1; bs[(at + f + bs.length) % bs.length].focus(); }
251
+ });
252
+ m.__anchor = anchor; menu = m;
253
+ document.body.appendChild(m);
254
+ const r = anchor.getBoundingClientRect();
255
+ m.style.top = Math.round(r.bottom + 6) + 'px';
256
+ m.style.left = Math.round(Math.max(8, Math.min(innerWidth - m.offsetWidth - 8, r.right - m.offsetWidth / 2 - r.width / 2))) + 'px';
257
+ anchor.setAttribute('aria-expanded', 'true');
258
+ (m.querySelector('[aria-checked="true"]') || m.querySelector('button')).focus();
259
+ document.addEventListener('pointerdown', away, true);
260
+ }
261
+
262
+ /* ── placing a panel ── */
263
+ function known(id) { return id === 'chat' || vs().some((p) => p.id === id); }
264
+ function place(id, mode) {
265
+ if (!S.on || isPhone() || !known(id) || !['full', 'split', 'over'].includes(mode)) return false;
266
+ mark(id);
267
+ const was = S.row.slice();
268
+ drop(id);
269
+ if (mode === 'full') {
270
+ // the others give way: the chat slides away (the Live pill brings it back), the other Viewers close
271
+ [...S.row, S.over, ...S.away].filter(Boolean).forEach((x) => { if (x === 'chat') { drop('chat'); S.away.push('chat'); } else if (x !== id) { drop(x); P.close(x); } });
272
+ S.row = [id]; S.over = null;
273
+ } else if (mode === 'split') {
274
+ if (!S.row.length) { // it was full: the panel put away comes back beside it
275
+ const back = S.over || S.away.pop() || null; if (back) drop(back);
276
+ S.row = !back ? [id] : back === 'chat' ? ['chat', id] : [id, back];
277
+ } else if (id === 'chat') S.row.unshift(id); else S.row.push(id);
278
+ fit(id);
279
+ } else {
280
+ if (S.over) { const o = S.over; S.over = null; S.away.push(o); }
281
+ if (!S.row.length) { const back = [...S.away].reverse().find((x) => x !== id); if (back) { drop(back); S.row = [back]; } }
282
+ if (!S.row.length) { S.row = was.length ? was : [id]; layout(); return false; } // nothing to slide over
283
+ S.over = id;
284
+ }
285
+ S.fr = [];
286
+ layout();
287
+ return true;
288
+ }
289
+ function putAway() {
290
+ if (!S.over) return false;
291
+ const id = S.over; S.over = null; S.away.push(id);
292
+ layout();
293
+ return true;
294
+ }
295
+ function slideOver(item) {
296
+ if (!S.on || isPhone()) return false;
297
+ const pend = S.pend && Date.now() - S.pend.t < 6000 ? S.pend : null;
298
+ if (item && (item.sid || item.kind === 'rec' || item.kind === 'session')) {
299
+ // a Live pill row: the page opens the chat (Home's own handler); the chat comes where it can be seen
300
+ if (!S.go || !S.go(item)) return false;
301
+ if (item.kind === 'rec') return true;
302
+ mark('chat');
303
+ if (pend) { S.pend = null; P.unbeside(); drop('chat'); if (pend.side === 'left') S.row.unshift('chat'); else S.row.push('chat'); S.fr = []; fit('chat'); layout(); }
304
+ else if (!visible('chat')) place('chat', 'over');
305
+ return true;
306
+ }
307
+ if (item && (typeof item.render === 'function' || item.html)) { // a Viewer of its own, floating over
308
+ S.pend = { mode: 'over', t: Date.now() }; P.beside();
309
+ openViewer({ ...item, fresh: true });
310
+ return true;
311
+ }
312
+ const back = S.away.pop();
313
+ if (!back) return false;
314
+ if (S.over) S.away.push(S.over);
315
+ S.over = back; mark(back);
316
+ layout();
317
+ return true;
318
+ }
319
+
320
+ /* ── a new or closed Viewer ── */
321
+ function onViewer(d) {
322
+ if (!S.on || !d || !d.panel) return;
323
+ if (d.shut) { drop(d.panel); S.fr = []; layout(); return; }
324
+ mark(d.panel);
325
+ if (S.row.includes(d.panel) || S.over === d.panel || S.away.includes(d.panel)) { layout(); return; }
326
+ const pend = S.pend && Date.now() - S.pend.t < 6000 ? S.pend : null; S.pend = null;
327
+ if (pend && pend.mode === 'over') { if (S.over) S.away.push(S.over); S.over = d.panel; }
328
+ else if (pend && pend.side === 'left') S.row.unshift(d.panel);
329
+ else S.row.push(d.panel);
330
+ S.fr = [];
331
+ fit(d.panel);
332
+ layout();
333
+ }
334
+
335
+ /* ── the chat's own ⧉ and × (TbT1Split): only while a Viewer is open, when there is something to arrange ── */
336
+ function tools() {
337
+ if (!S.chat) return;
338
+ let t = S.chat.querySelector(':scope > .cz-pn-ct');
339
+ const want = S.on && !isPhone() && vs().length > 0;
340
+ document.body.classList.toggle('cz-pn-ctl', want);
341
+ if (!want) { if (t) t.remove(); return; }
342
+ if (!t) {
343
+ t = document.createElement('div'); t.className = 'cz-pn-ct';
344
+ t.innerHTML = `<button type="button" class="cz-vw-ib" data-cz-pn-chat="place" aria-label="Arrange the chat" title="Arrange" aria-haspopup="menu" aria-expanded="false">${svg(IC.place)}</button>`
345
+ + `<button type="button" class="cz-vw-ib" data-cz-pn-chat="away" aria-label="Put the chat away" title="Put the chat away. The Live pill brings it back.">${svg(IC.close)}</button>`;
346
+ t.addEventListener('click', (e) => {
347
+ const b = e.target.closest('[data-cz-pn-chat]'); if (!b) return;
348
+ if (b.dataset.czPnChat === 'place') openMenu('chat', b);
349
+ else if (S.over === 'chat') putAway(); else shut('chat');
350
+ });
351
+ S.chat.appendChild(t);
352
+ }
353
+ }
354
+ /** The grab bar on the panel that slides over: a drag or swipe off the right edge puts it away. */
355
+ function grab(el, want) {
356
+ let g = el.querySelector(':scope > .cz-pn-grab');
357
+ if (!want) { if (g) g.remove(); el.style.transform = ''; return; }
358
+ if (g) return;
359
+ g = document.createElement('div'); g.className = 'cz-pn-grab'; g.setAttribute('aria-hidden', 'true'); g.title = 'Drag to the right to put it away';
360
+ g.innerHTML = '<i></i>';
361
+ g.addEventListener('pointerdown', (e) => {
362
+ if (e.button !== 0) return;
363
+ e.preventDefault(); g.setPointerCapture(e.pointerId);
364
+ const x0 = e.clientX; let dx = 0;
365
+ el.classList.add('cz-pn-moving');
366
+ const mv = (ev) => { dx = Math.max(0, ev.clientX - x0); el.style.transform = `translateX(${dx}px)`; };
367
+ const up = () => {
368
+ g.removeEventListener('pointermove', mv); g.removeEventListener('pointerup', up); g.removeEventListener('pointercancel', up);
369
+ el.classList.remove('cz-pn-moving'); el.style.transform = '';
370
+ if (dx > AWAYPX) putAway();
371
+ };
372
+ g.addEventListener('pointermove', mv); g.addEventListener('pointerup', up); g.addEventListener('pointercancel', up);
373
+ });
374
+ el.prepend(g);
375
+ }
376
+
377
+ /* ── open beside: drag a row to the left or right of the panels (TbT5DragRow) ── */
378
+ let D = null;
379
+ function area() {
380
+ const r0 = rect(S.row[0]), r1 = rect(S.row[S.row.length - 1]);
381
+ if (!r0 || !r1) return null;
382
+ return { left: r0.left, right: r1.right, top: Math.min(r0.top, r1.top), bottom: Math.max(r0.bottom, r1.bottom) };
383
+ }
384
+ function dragStart() {
385
+ const label = (D.src.getAttribute('aria-label') || D.src.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 60);
386
+ D.ghost = document.createElement('div'); D.ghost.className = 'cz-pn-ghost'; D.ghost.textContent = label || 'Open beside';
387
+ D.zone = document.createElement('div'); D.zone.className = 'cz-pn-drop'; D.zone.hidden = true;
388
+ document.body.append(D.zone, D.ghost);
389
+ document.body.classList.add('cz-pn-dragrow');
390
+ D.on = true;
391
+ }
392
+ function dragMove(e) {
393
+ D.ghost.style.left = (e.clientX + 14) + 'px'; D.ghost.style.top = (e.clientY + 10) + 'px';
394
+ const a = area();
395
+ const inside = a && e.clientX >= a.left && e.clientX <= a.right && e.clientY >= a.top && e.clientY <= a.bottom;
396
+ D.side = inside ? (e.clientX < (a.left + a.right) / 2 ? 'left' : 'right') : null;
397
+ D.zone.hidden = !D.side;
398
+ if (D.side) {
399
+ const mid = (a.left + a.right) / 2;
400
+ Object.assign(D.zone.style, { top: a.top + 'px', height: (a.bottom - a.top) + 'px', left: (D.side === 'left' ? a.left : mid) + 'px', width: (D.side === 'left' ? mid - a.left : a.right - mid) + 'px' });
401
+ D.zone.dataset.side = D.side;
402
+ }
403
+ }
404
+ /** A selector that finds the row again: the list may draw itself anew while the row is dragged. */
405
+ function again(src) {
406
+ for (const k of ['hmSel', 'lv', 'file', 'ctx', 'att']) {
407
+ if (src.dataset[k] == null) continue;
408
+ const attr = 'data-' + k.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase());
409
+ return `${src.closest('#hmList') ? '#hmList ' : src.closest('#czLiveList') ? '#czLiveList ' : '#hmChat '}[${attr}="${CSS.escape(src.dataset[k])}"]`;
410
+ }
411
+ return null;
412
+ }
413
+ function dragEnd(d) {
414
+ d.ghost.remove(); d.zone.remove(); document.body.classList.remove('cz-pn-dragrow');
415
+ if (!d.side) return;
416
+ S.noClick = Date.now(); // the press that ends a drag is not also a click
417
+ S.pend = { side: d.side, t: Date.now() };
418
+ if (!d.src.matches('#czLiveList a[data-lv]')) P.beside();
419
+ setTimeout(() => { S.noClick = 0; const src = d.src.isConnected ? d.src : d.sel && document.querySelector(d.sel); if (src) src.click(); setTimeout(() => { if (S.pend && Date.now() - S.pend.t > 5500) { S.pend = null; P.unbeside(); } }, 6000); }, 0);
420
+ }
421
+ function dragWire() {
422
+ document.addEventListener('pointerdown', (e) => {
423
+ if (!S.on || isPhone() || e.button !== 0 || e.pointerType === 'touch') return;
424
+ const src = e.target.closest && e.target.closest(SRC); if (!src) return;
425
+ D = { src, sel: again(src), x0: e.clientX, y0: e.clientY, pid: e.pointerId, on: false };
426
+ }, true);
427
+ document.addEventListener('pointermove', (e) => {
428
+ if (!D || e.pointerId !== D.pid) return;
429
+ if (!D.on) { if (Math.hypot(e.clientX - D.x0, e.clientY - D.y0) < 8) return; dragStart(); }
430
+ e.preventDefault(); dragMove(e);
431
+ }, true);
432
+ document.addEventListener('pointerup', (e) => { if (!D || e.pointerId !== D.pid) return; const d = D; D = null; if (d.on) dragEnd(d); }, true);
433
+ document.addEventListener('pointercancel', () => { if (D && D.on) { D.ghost.remove(); D.zone.remove(); document.body.classList.remove('cz-pn-dragrow'); } D = null; }, true);
434
+ document.addEventListener('dragstart', (e) => { if (S.on && e.target.closest && e.target.closest(SRC)) e.preventDefault(); }, true); // a link drags our way
435
+ document.addEventListener('click', (e) => { if (e.isTrusted && S.noClick && Date.now() - S.noClick < 500) { e.preventDefault(); e.stopPropagation(); S.noClick = 0; } }, true);
436
+ }
437
+
438
+ /* ── remembered per initiative (rule 7) ── */
439
+ function snapshot() {
440
+ return {
441
+ v: 1, n: S.row.length, fr: S.fr.slice(), chat: S.over === 'chat' ? 'over' : S.away.includes('chat') ? 'away' : 'split', chatAt: Math.max(0, S.row.indexOf('chat')),
442
+ items: vs().map((p) => ({ ...(p.item || {}), at: S.row.indexOf(p.id), over: S.over === p.id })).filter((x) => x.id),
443
+ };
444
+ }
445
+ const nextOpen = (ms) => new Promise((res) => { const f = (e) => { if (e.detail && !e.detail.shut) { document.removeEventListener('cz-viewer', f); res(true); } }; document.addEventListener('cz-viewer', f); setTimeout(() => { document.removeEventListener('cz-viewer', f); res(false); }, ms); });
446
+ async function restore(id) {
447
+ const m = store.get('cz-pn:' + id);
448
+ if (!m || m.v !== 1 || isPhone()) return;
449
+ S.restoring = true;
450
+ try {
451
+ if (!vs().length) await nextOpen(2500); // the page opens the initiative's own Viewer first
452
+ if (S.scope !== id) return;
453
+ const open = vs().map((p) => p.item && p.item.id);
454
+ for (const it of (m.items || []).filter((x) => !open.includes(x.id)).slice(0, maxRow() - 1)) {
455
+ if (!S.reopen) break;
456
+ S.pend = it.over ? { mode: 'over', t: Date.now() } : { side: it.at === 0 ? 'left' : 'right', t: Date.now() };
457
+ P.beside();
458
+ const wait = nextOpen(2500);
459
+ let ok = false; try { ok = await S.reopen(it); } catch { ok = false; }
460
+ if (ok === false) { S.pend = null; P.unbeside(); continue; }
461
+ await wait;
462
+ if (S.scope !== id) return;
463
+ }
464
+ if (vs().length) {
465
+ if (m.chat === 'away' && visible('chat')) { drop('chat'); S.away.push('chat'); }
466
+ else if (m.chat === 'over' && S.over !== 'chat') { drop('chat'); if (S.over) S.away.push(S.over); S.over = 'chat'; }
467
+ if (S.row.length === m.n && Array.isArray(m.fr) && m.fr.length === m.n) S.fr = m.fr.slice();
468
+ }
469
+ } finally {
470
+ S.restoring = false;
471
+ layout();
472
+ }
473
+ }
474
+ function scope(id) {
475
+ id = id || null;
476
+ if (id === S.scope) return;
477
+ S.scope = id;
478
+ if (id) restore(id);
479
+ }
480
+
481
+ /* ── Present: the chat slides away while a recording presents, and comes back on Stop (rule 8) ── */
482
+ function presentOn() {
483
+ if (S.auto || isPhone() || !vs().length || !visible('chat')) return;
484
+ drop('chat'); S.away.push('chat'); S.auto = true; layout();
485
+ }
486
+ function presentOff() {
487
+ if (!S.auto) return;
488
+ S.auto = false;
489
+ if (S.away.includes('chat')) { drop('chat'); S.row.unshift('chat'); S.fr = []; fit('chat', true); }
490
+ layout();
491
+ }
492
+
493
+ export function mountPanels(o = {}) {
494
+ if (S.on || typeof document === 'undefined') return window.czPanels;
495
+ S.desk = o.desk || document.querySelector('[data-cz-viewer-host]') && document.querySelector('[data-cz-viewer-host]').parentNode;
496
+ S.chat = o.chat || document.getElementById('hmChat');
497
+ if (!S.desk || !S.chat) return null;
498
+ S.go = typeof o.go === 'function' ? o.go : null;
499
+ S.reopen = typeof o.reopen === 'function' ? o.reopen : null;
500
+ if (!document.querySelector(`link[href="${SHEET}"]`)) { const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = SHEET; document.head.appendChild(l); }
501
+ S.on = true;
502
+ P.config({ limit: 3, place: (id, b) => openMenu(id, b), managed: (id) => managed() && (S.row.includes(id) || S.over === id || S.away.includes(id)) });
503
+ document.addEventListener('cz-viewer', (e) => onViewer(e.detail));
504
+ document.addEventListener('cz:vw-rail', (e) => { if (managed() && e.detail && !e.detail.on) S.keepList = true; }); // the rail's list button: the list stays
505
+ ['pointerdown', 'focusin'].forEach((k) => document.addEventListener(k, (e) => {
506
+ const t = e.target; if (!t || !t.closest) return;
507
+ const p = t.closest('[data-cz-panel]'); if (p) mark(p.dataset.czPanel); else if (S.chat.contains(t)) mark('chat');
508
+ }, true));
509
+ dragWire();
510
+ let rz = 0;
511
+ addEventListener('resize', () => { cancelAnimationFrame(rz); rz = requestAnimationFrame(() => { fit(null, true); S.keepList = false; layout(); }); });
512
+ if (typeof BroadcastChannel === 'function') {
513
+ const ch = new BroadcastChannel('pmos-present');
514
+ ch.addEventListener('message', (e) => { const t = e.data && e.data.t; if (t === 'present' || t === 'show') presentOn(); else if (t === 'off') presentOff(); });
515
+ }
516
+ onRecording((s) => { if (!s || !s.on) presentOff(); });
517
+ window.czPanels = {
518
+ list, place, slideOver, putAway, scope,
519
+ away: () => S.away[S.away.length - 1] || null,
520
+ onChange(fn) { if (typeof fn === 'function') S.subs.push(fn); },
521
+ };
522
+ layout();
523
+ return window.czPanels;
524
+ }
@@ -525,3 +525,18 @@ body.cz-home .hm-hd.hv-bar > .hv-hi { flex: 1 0 auto; max-width: 100%; }
525
525
 
526
526
  /* the weekly review done for the week (batch 17 item 4-B, AdM1): Adler calm beside the words */
527
527
  .rv-done { display: flex; align-items: center; gap: 10px; }
528
+
529
+ /* The folded rail's card (batch 18 item 14, FlA1–FlA5): beside the pressed tile, Home's popover look, Home's own rows inside. The pill's
530
+ * sessions open in place under the row (.hv-rcs), not as a second popover. Its left and top are set from the tile (home-app.js). */
531
+ .hv-rc { position: fixed; z-index: 60; width: 372px; max-width: calc(100vw - 96px); max-height: calc(100vh - 24px); overflow-y: auto; background: var(--cz-card); border-radius: 20px; padding: 6px; box-shadow: 0 24px 50px -20px rgba(42,46,53,.4), 0 0 0 1px var(--cz-hair); box-sizing: border-box; text-align: left; }
532
+ .hv-rch { display: flex; align-items: center; gap: 6px; min-height: 44px; }
533
+ .hv-rch .hv-pt { flex: 0 1 auto; gap: 8px; }
534
+ .hv-rch .hv-pt .hv-tl { width: 26px; height: 26px; border-radius: 8px; }
535
+ .hv-rch .hv-pt > svg { color: var(--cz-ink3); flex: none; }
536
+ .hv-rch .hv-msd { margin-left: auto; }
537
+ .hv-rch .hv-ib { margin-left: auto; flex: none; }
538
+ .hv-rch .hv-msd + .hv-ib { margin-left: 2px; }
539
+ .hv-rcb .hm-none { margin: 6px 10px 10px; }
540
+ .hv-rcs { margin: 0 0 4px; padding: 4px; background: color-mix(in srgb, var(--cz-well) 55%, var(--cz-card)); border-radius: 14px; }
541
+ .hv-rcs .hv-r::before { display: none; }
542
+ .hv-rcs .hv-r.safe { background: var(--cz-bluebg); border-radius: 14px; }