create-pmos 0.443.0 → 0.445.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/package.json +25 -25
  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/adler-moments-test.js +8 -0
  8. package/workspace/adler-seasons-art-test.js +3 -0
  9. package/workspace/board-columns-test.js +168 -0
  10. package/workspace/board-programs-test.js +1 -1
  11. package/workspace/briefing-premium-board-test.js +91 -8
  12. package/workspace/briefing-premium-insights-test.js +83 -38
  13. package/workspace/briefing-premium-test.js +2 -1
  14. package/workspace/calm-timeline-test.js +3 -1
  15. package/workspace/changelog.json +24 -0
  16. package/workspace/goals-clear-ui-test.js +34 -20
  17. package/workspace/guide/home.md +5 -0
  18. package/workspace/guide/jira.md +13 -1
  19. package/workspace/guide/ready-made-dashboards.md +2 -2
  20. package/workspace/intel-report-ui-test.js +1 -1
  21. package/workspace/lib/board-fold.js +33 -5
  22. package/workspace/lib/board-premium.js +1 -1
  23. package/workspace/lib/console-state.js +5 -1
  24. package/workspace/lib/engine/boards.js +9 -2
  25. package/workspace/lib/factory-join.js +46 -14
  26. package/workspace/lib/freshness.js +14 -1
  27. package/workspace/lib/initiative-rows.js +38 -4
  28. package/workspace/lib/issues.js +8 -1
  29. package/workspace/lib/jira-cli.js +18 -2
  30. package/workspace/lib/jira-moves.js +119 -0
  31. package/workspace/lib/jira-tickets.js +23 -4
  32. package/workspace/lib/notes.js +4 -2
  33. package/workspace/lib/offloop.js +75 -29
  34. package/workspace/lib/page-build.js +97 -0
  35. package/workspace/lib/plan-items.js +24 -3
  36. package/workspace/lib/plan-tree.js +62 -9
  37. package/workspace/lib/ready-reports.js +22 -8
  38. package/workspace/lib/refresh.js +14 -2
  39. package/workspace/lib/routes-board-premium.js +9 -1
  40. package/workspace/lib/routes-boards.js +114 -16
  41. package/workspace/lib/routes-brief-page.js +3 -1
  42. package/workspace/lib/routes-calendar-import.js +13 -1
  43. package/workspace/lib/routes-ready-reports.js +28 -5
  44. package/workspace/lib/task-links.js +12 -1
  45. package/workspace/lib/workflows-store.js +14 -3
  46. package/workspace/live-pill-round-test.js +178 -0
  47. package/workspace/milestone-pins-test.js +1 -1
  48. package/workspace/okr-goals-ui-test.js +21 -19
  49. package/workspace/package-lock.json +2 -2
  50. package/workspace/package.json +1 -1
  51. package/workspace/panels-test.js +375 -0
  52. package/workspace/premium-rec-tab-test.js +2 -1
  53. package/workspace/premium-vw-item-test.js +10 -2
  54. package/workspace/premium-vw-jira-test.js +3 -0
  55. package/workspace/program-panel-test.js +6 -6
  56. package/workspace/public/pm/bd-cols.js +149 -0
  57. package/workspace/public/pm/bd-ini-panel.js +3 -2
  58. package/workspace/public/pm/bd-pane.js +41 -0
  59. package/workspace/public/pm/bd-span.js +29 -11
  60. package/workspace/public/pm/cozy-adler.js +21 -0
  61. package/workspace/public/pm/cozy-board.css +45 -0
  62. package/workspace/public/pm/cozy-divider.css +32 -0
  63. package/workspace/public/pm/cozy-divider.js +45 -0
  64. package/workspace/public/pm/cozy-insights.css +22 -0
  65. package/workspace/public/pm/cozy-live-pill.css +17 -22
  66. package/workspace/public/pm/cozy-live-pill.js +38 -18
  67. package/workspace/public/pm/cozy-panels.css +80 -0
  68. package/workspace/public/pm/cozy-panels.js +691 -0
  69. package/workspace/public/pm/cozy-viewer.js +148 -70
  70. package/workspace/public/pm/dash-view.js +5 -2
  71. package/workspace/public/pm/goals-clear.js +9 -2
  72. package/workspace/public/pm/home-app.js +30 -19
  73. package/workspace/public/pm/home-ini.js +9 -3
  74. package/workspace/public/pm/home-today.js +4 -2
  75. package/workspace/public/pm/ini-edit.js +405 -0
  76. package/workspace/public/pm/ini-tasks.js +175 -46
  77. package/workspace/public/pm/ini-versions.js +18 -4
  78. package/workspace/public/pm/ini-view-model.js +12 -7
  79. package/workspace/public/pm/ini-view.css +162 -26
  80. package/workspace/public/pm/ini-view.js +44 -13
  81. package/workspace/public/pm/ini-wf-model.js +9 -0
  82. package/workspace/public/pm/ini-wf.js +14 -9
  83. package/workspace/public/pm/ins-pane.js +55 -0
  84. package/workspace/public/pm/jira-move.js +50 -0
  85. package/workspace/public/pm/live-model.js +3 -2
  86. package/workspace/public/pm/pn-narrow.js +76 -0
  87. package/workspace/public/pm/premium-board.js +85 -32
  88. package/workspace/public/pm/premium-insights.js +211 -43
  89. package/workspace/public/pm/task-card.css +2 -0
  90. package/workspace/public/pm/task-card.js +4 -1
  91. package/workspace/public/premium-board.html +2 -0
  92. package/workspace/ready-dash-ui-test.js +4 -4
  93. package/workspace/server.js +71 -20
  94. package/workspace/skills/jira-move.skill +35 -0
  95. package/workspace/stage-card-tasks-test.js +397 -0
  96. package/workspace/stage-card-test.js +1 -1
  97. package/workspace/task-delete-test.js +9 -1
  98. package/workspace/task-links-test.js +1 -0
  99. package/workspace/task-milestones-test.js +3 -3
  100. package/workspace/task-plans-test.js +1 -1
  101. package/workspace/task-press-test.js +12 -4
  102. package/workspace/task-views-test.js +166 -13
  103. package/workspace/test-lists/batch18-live-pill-round.json +10 -0
  104. package/workspace/test-lists/batch18-panels.json +9 -0
  105. package/workspace/test-lists/board-columns.json +5 -0
  106. package/workspace/test-lists/jira-moves.json +11 -0
  107. package/workspace/test-lists/page-speed-fold.json +5 -0
  108. package/workspace/test-lists/page-speed-reads.json +5 -0
  109. package/workspace/test-lists/stage-card-tasks.json +6 -0
  110. package/workspace/timeline-holds-test.js +1 -1
@@ -98,7 +98,7 @@ const P = {
98
98
  add: 'M12 5v14M5 12h14', back: 'M14 6l-6 6 6 6', more: 'M5 12h.01M12 12h.01M19 12h.01', close: 'M6 6l12 12M18 6L6 18',
99
99
  wide: 'M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7', side: 'M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7',
100
100
  chat: 'M5 6.5A2.5 2.5 0 0 1 7.5 4h9A2.5 2.5 0 0 1 19 6.5v7a2.5 2.5 0 0 1-2.5 2.5H11l-4 3.5V16h.5A2.5 2.5 0 0 1 5 13.5z',
101
- fwd: 'M10 6l6 6-6 6', home: 'M4 11l8-7 8 7v9H4z', tab: 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6', chev: 'M10 7l5 5-5 5', down: 'M7 10l5 5 5-5', list: 'M3.5 4.5h17v15h-17zM14 4.5v15',
101
+ place: 'M3.5 5h17v14h-17zM12 5v14', fwd: 'M10 6l6 6-6 6', home: 'M4 11l8-7 8 7v9H4z', tab: 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6', chev: 'M10 7l5 5-5 5', down: 'M7 10l5 5 5-5', list: 'M3.5 4.5h17v15h-17zM14 4.5v15',
102
102
  };
103
103
  export const PHONE = 760;
104
104
  const NARROW = 1100, MIN = 420, CHAT = 360, RAIL = 64, MAXF = 0.7, W2 = 760, FLOAT = 560;
@@ -113,7 +113,35 @@ const isPhone = () => typeof innerWidth === 'number' && innerWidth <= PHONE;
113
113
  const onHome = () => typeof document !== 'undefined' && !!document.body && document.body.classList.contains('cz-home');
114
114
  const kindKey = (k) => String(k || 'item').trim().toLowerCase().replace(/^file · .*/, 'file').replace(/[^a-z0-9]+/g, '-').slice(0, 40) || 'item';
115
115
 
116
- const V = { el: null, cur: null, back: null, subs: [], stack: [], fwd: [], wide: false, rail: false, w: 0, drill: false, over: false, card: null, railKey: null, hold: 0 };
116
+ /* Several Viewers (batch 18 item 15, canvas TbT6TwoViewers, TbT8Wide): each is one instance. V is the instance in use: the one a press, a
117
+ * key or the last open() went to, so the exported API always speaks of the Viewer used last. G is what the page has once: its list's rail,
118
+ * the listeners, the rail's card. Only the first instance (#czViewer) writes the browser history; another keeps its own ← → trail.
119
+ * Without cozy-panels.js (Board, Intelligence) the limit stays 1 and there is one Viewer, as before. */
120
+ const G = { subs: [], card: null, railKey: null, rail: false, lw: 0, hold: 0, tick: 0, limit: 1, beside: null, place: null, managed: null };
121
+ const mk = (i) => ({ i, el: null, cur: null, back: null, stack: [], fwd: [], wide: false, w: 0, drill: false, over: false, used: 0, ph: false, via: '' });
122
+ let V = mk(0);
123
+ const ALL = [V];
124
+ const shown = (x) => !!(x && x.el && !x.el.hidden && x.cur);
125
+ /** The open Viewer used last (or null). */
126
+ const mru = () => ALL.filter(shown).sort((a, b) => b.used - a.used)[0] || null;
127
+ /** A press, a key or an open on this instance: it is the one in use now. */
128
+ function use(x) { V = x; x.used = ++G.tick; return x; }
129
+ /** Run fn on instance x without making it the one used last (a resize). */
130
+ function on(x, fn) { const was = V; V = x; try { return fn(); } finally { V = was; } }
131
+ /** Where an open() goes: a drop beside (cozy-panels.js) takes a free instance, a new one under the limit, else the least recently used;
132
+ * a press inside a Viewer drills in that Viewer; anything else replaces the Viewer used last. */
133
+ function pick(o) {
134
+ const b = G.beside; G.beside = null;
135
+ if (b && Date.now() - b.t < 6000) {
136
+ const free = ALL.find((x) => !shown(x));
137
+ if (free) return free;
138
+ if (ALL.length < G.limit) { const n = mk(ALL.length); ALL.push(n); return n; }
139
+ return ALL.filter(shown).sort((a, c) => a.used - c.used)[0];
140
+ }
141
+ const p = H.press && Date.now() - H.press.t < 10000 ? H.press : null;
142
+ if (p && p.inst && shown(p.inst) && !o.fresh) return p.inst;
143
+ return mru() || ALL[0];
144
+ }
117
145
 
118
146
  /** "PRD" over "PRD", or "File · plans/x.md" over "x.md": the kind is left out when it only repeats the title */
119
147
  const sameAs = (kind, title) => { const k = String(kind || '').trim().toLowerCase().replace(/^file · /, ''), t = String(title || '').trim().toLowerCase(); return !!t && (k === t || k.split('/').pop() === t || k.split('/').pop().replace(/\.[a-z]+$/, '') === t); };
@@ -148,7 +176,9 @@ export function headHtml(it) {
148
176
  : `<span class="cz-vw-tile" aria-hidden="true">${svg(path(o.icon), 17)}</span>`)
149
177
  + (o.renaming ? renHtml(o) : `<div class="cz-vw-t">${kind}<h3 class="cz-vw-title${chip ? ' has-chip' : ''}${o.wrap ? ' wrap' : ''}" id="czVwTitle">${o.rename ? `<button type="button" class="cz-vw-rn" data-cz-vw-rn aria-label="${esc('Rename ' + (o.title || ''))}" title="Rename">${esc(o.title || '')}</button>` : chip ? `<span class="cz-vw-tt">${esc(o.title || '')}</span>` : esc(o.title || '')}${chip}</h3>${sub}</div>`)
150
178
  + disc + own + add + more
151
- + (phone ? '' : ib('wide', o.isWide ? 'Back to the side' : 'Open wide', o.isWide ? P.side : P.wide, ` aria-pressed="${o.isWide ? 'true' : 'false'}"`))
179
+ // ⧉ (batch 18 item 15, TbT7Place): where a page arranges panels, one placement press takes the place of ⤢ (Full screen is in it)
180
+ + (phone ? '' : o.place ? ib('place', 'Arrange', P.place, ' aria-haspopup="menu" aria-expanded="false"')
181
+ : ib('wide', o.isWide ? 'Back to the side' : 'Open wide', o.isWide ? P.side : P.wide, ` aria-pressed="${o.isWide ? 'true' : 'false'}"`))
152
182
  + (phone ? '' : `<button type="button" class="cz-vw-ib" data-cz-vw="close" aria-label="Close the viewer" title="Close">${svg(P.close, 18)}</button>`);
153
183
  }
154
184
 
@@ -221,7 +251,7 @@ function room() {
221
251
  const desk = host.parentNode, cs = getComputedStyle(desk);
222
252
  const inner = desk.clientWidth - (parseFloat(cs.paddingLeft) || 0) - (parseFloat(cs.paddingRight) || 0);
223
253
  const gap = parseFloat(cs.columnGap || cs.gap) || 0;
224
- const list = listEl(), lw = list && list.parentNode === desk && !V.rail ? list.offsetWidth : list && list.parentNode === desk ? (V.lw || 316) : 0;
254
+ const list = listEl(), lw = list && list.parentNode === desk && !G.rail ? list.offsetWidth : list && list.parentNode === desk ? (G.lw || 316) : 0;
225
255
  const right = inner - (lw ? lw + gap : 0);
226
256
  const side = right - gap - CHAT;
227
257
  const wideMax = Math.min(Math.round(innerWidth * MAXF), inner - (list ? RAIL + gap : 0) - gap - CHAT);
@@ -230,24 +260,25 @@ function room() {
230
260
  export const widthOf = (kind) => { const n = parseInt(store.get('cz-vw-w:' + kindKey(kind)) || '', 10); return n > 0 ? n : null; };
231
261
  function setRail(on) {
232
262
  const list = listEl();
233
- if (!on && !V.rail) return;
234
- if (on && !V.rail && list) V.lw = list.offsetWidth;
235
- const was = V.rail;
236
- V.rail = !!on && !!list;
237
- document.body.classList.toggle('cz-vw-rail', V.rail);
238
- if (!V.rail) V.railKey = null;
239
- if (was !== V.rail) document.dispatchEvent(new CustomEvent('cz:vw-rail', { detail: { on: V.rail } })); // a page's rail card closes with the rail
263
+ if (!on && !G.rail) return;
264
+ if (on && !G.rail && list) G.lw = list.offsetWidth;
265
+ const was = G.rail;
266
+ G.rail = !!on && !!list;
267
+ document.body.classList.toggle('cz-vw-rail', G.rail);
268
+ if (!G.rail) G.railKey = null;
269
+ if (was !== G.rail) document.dispatchEvent(new CustomEvent('cz:vw-rail', { detail: { on: G.rail } })); // a page's rail card closes with the rail
240
270
  if (!list) return;
241
271
  let bar = list.querySelector(':scope > .cz-vw-railbar');
242
- if (!V.rail) { if (bar) bar.remove(); return; }
272
+ if (!G.rail) { if (bar) bar.remove(); return; }
243
273
  if (!bar) {
244
274
  bar = document.createElement('div'); bar.className = 'cz-vw-railbar';
245
275
  bar.innerHTML = `<button type="button" class="cz-vw-ib" data-cz-vw-rail="show" aria-label="Show the list" title="Show the list">${svg(P.list, 18)}</button><div class="cz-vw-railtiles"></div>`;
246
276
  bar.addEventListener('click', (e) => {
247
277
  const b = e.target.closest('[data-cz-vw-rail]'); if (!b) return;
278
+ if (b.dataset.czVwRail === 'show' && G.managed && ALL.some((x) => shown(x) && G.managed('v' + x.i))) { setRail(false); return; } // cozy-panels.js lays it out
248
279
  if (b.dataset.czVwRail === 'show') { V.wide = false; apply(Math.min(V.w, sideMax())); redraw(); return; }
249
280
  // a group's tile: the page's card of that group's rows, beside the tile (batch 18 item 14, FlA1); the rail and the Viewer stay
250
- if (V.card) { V.card(b.dataset.czVwRail, b, e.detail === 0); return; }
281
+ if (G.card) { G.card(b.dataset.czVwRail, b, e.detail === 0); return; }
251
282
  // a page without a card: the list comes back, at that group
252
283
  const src = list.querySelector('[data-cz-rail-tile="' + CSS.escape(b.dataset.czVwRail) + '"]');
253
284
  V.wide = false; apply(Math.min(V.w, sideMax())); redraw();
@@ -262,35 +293,37 @@ function setRail(on) {
262
293
  function railTiles(list, bar) {
263
294
  const tiles = [...list.querySelectorAll('[data-cz-rail-tile]')].slice(0, 8);
264
295
  const box = bar.querySelector('.cz-vw-railtiles');
265
- const sig = tiles.map((t) => t.outerHTML).join('') + '|' + !!V.card;
296
+ const sig = tiles.map((t) => t.outerHTML).join('') + '|' + !!G.card;
266
297
  if (box.__sig !== sig) {
267
298
  box.__sig = sig; box.innerHTML = '';
268
299
  tiles.forEach((t) => { // a copy of the tile itself (its tint, initials and dot), in a press that names the group
269
300
  const nm = t.dataset.czRailName || t.textContent.trim(), here = t.hasAttribute('data-cz-rail-here');
270
301
  const btn = document.createElement('button'); btn.type = 'button'; btn.className = 'cz-vw-railtile' + (here ? ' here' : ''); btn.dataset.czVwRail = t.dataset.czRailTile;
271
- btn.setAttribute('aria-label', (V.card ? nm + (here ? ' (open)' : '') + '. Show its initiatives' : 'Show the list at ' + nm)); btn.title = nm;
272
- if (V.card) btn.setAttribute('aria-haspopup', 'dialog');
302
+ btn.setAttribute('aria-label', (G.card ? nm + (here ? ' (open)' : '') + '. Show its initiatives' : 'Show the list at ' + nm)); btn.title = nm;
303
+ if (G.card) btn.setAttribute('aria-haspopup', 'dialog');
273
304
  const c = t.cloneNode(true); c.removeAttribute('data-cz-rail-tile'); c.removeAttribute('data-cz-rail-name'); c.removeAttribute('data-cz-rail-here'); btn.appendChild(c); box.appendChild(btn);
274
305
  });
275
306
  }
276
- box.querySelectorAll('.cz-vw-railtile').forEach((b) => { const on = b.dataset.czVwRail === V.railKey; b.classList.toggle('on', on); if (V.card) b.setAttribute('aria-expanded', String(on)); });
307
+ box.querySelectorAll('.cz-vw-railtile').forEach((b) => { const on = b.dataset.czVwRail === G.railKey; b.classList.toggle('on', on); if (G.card) b.setAttribute('aria-expanded', String(on)); });
277
308
  }
278
309
  /** A page that draws a card for a rail tile (Home): fn(key, tile, byKey) on a tile's press, in place of bringing the list back. */
279
- export function railCard(fn) { V.card = typeof fn === 'function' ? fn : null; railSync(); }
310
+ export function railCard(fn) { G.card = typeof fn === 'function' ? fn : null; railSync(); }
280
311
  /** The tile whose card is open (null: none): its ring and aria-expanded. The page calls it after a redraw of its list, so the rail's tiles
281
312
  * follow the list (a new "here" bar, a dot). */
282
313
  export function railSync(key) {
283
- if (key !== undefined) V.railKey = key || null;
284
- const list = listEl(), bar = V.rail && list && list.querySelector(':scope > .cz-vw-railbar');
314
+ if (key !== undefined) G.railKey = key || null;
315
+ const list = listEl(), bar = G.rail && list && list.querySelector(':scope > .cz-vw-railbar');
285
316
  if (bar) railTiles(list, bar);
286
317
  }
287
318
  /** The next open() keeps the Viewer as wide as it is and the rail folded (a pick from the rail's card, FlA4After). */
288
- export function keepWide() { V.hold = Date.now() + 2000; }
319
+ export function keepWide() { G.hold = Date.now() + 2000; }
289
320
  const sideMax = () => { const r = room(); return r.float ? r.side : Math.max(MIN, r.side); };
290
321
  /** Set the width in px: past what the chat leaves, the list folds to a rail first; never under 420 or over about 70%. */
291
322
  function apply(px) {
292
323
  const el = V.el; if (!el) return;
293
324
  if (isPhone()) { el.style.width = ''; el.style.flexBasis = ''; el.classList.remove('cz-vw-w2'); setRail(false); return; }
325
+ // cozy-panels.js lays the panels out itself (two Viewers, a Viewer full or sliding over): it sizes this one, the rail is its own call
326
+ if (G.managed && G.managed('v' + V.i)) { el.style.width = ''; el.classList.toggle('cz-vw-w2', el.offsetWidth >= W2); return; } // its flex is the engine's; V.w keeps the width beside the chat
294
327
  let r = room();
295
328
  // a host that keeps its list (Home, HbCNarrow): with no room beside the chat the Viewer lies over the chat, at most the room right of the list
296
329
  const over = !r.float && r.hasList && r.side < MIN && !V.wide && !!(el.parentNode && el.parentNode.hasAttribute('data-cz-vw-overlay'));
@@ -304,7 +337,7 @@ function apply(px) {
304
337
  const fold = Math.min(r.side, Math.max(MIN, r.def));
305
338
  if (w > fold && r.hasList && r.wideMax > fold) { setRail(true); r = room(); w = Math.min(w, r.wideMax); }
306
339
  else if (r.side >= MIN && w <= fold && !V.wide) { setRail(false); r = room(); w = Math.min(w, Math.max(MIN, r.side)); }
307
- else w = Math.min(w, Math.max(MIN, V.rail ? r.wideMax : r.side));
340
+ else w = Math.min(w, Math.max(MIN, G.rail ? r.wideMax : r.side));
308
341
  } else w = Math.min(w, r.wideMax);
309
342
  V.w = w;
310
343
  el.style.width = w + 'px'; el.style.flexBasis = w + 'px';
@@ -312,7 +345,7 @@ function apply(px) {
312
345
  const g = el.querySelector('.cz-vw-grip'); if (g) { g.setAttribute('aria-valuenow', String(w)); g.setAttribute('aria-valuemin', String(MIN)); g.setAttribute('aria-valuemax', String(r.wideMax)); }
313
346
  }
314
347
  export function setWidth(px, keep = true) { apply(px); if (keep && V.cur) store.set('cz-vw-w:' + kindKey(V.cur.kind), V.w); }
315
- export const railOn = () => V.rail;
348
+ export const railOn = () => G.rail;
316
349
  /** Open wide (the list folds to a rail, the Viewer takes about 70%), or back to the side at the width this kind keeps. */
317
350
  export function wide(on) {
318
351
  if (!V.cur || isPhone()) return false;
@@ -322,23 +355,26 @@ export function wide(on) {
322
355
  redraw();
323
356
  return V.wide;
324
357
  }
358
+ function resetW() { if (!V.cur) return; store.set('cz-vw-w:' + kindKey(V.cur.kind), null); V.wide = false; setRail(false); apply(room().def); redraw(); }
325
359
  function grip(el) {
326
- const g = document.createElement('div');
360
+ const g = document.createElement('div'), x = V;
327
361
  g.className = 'cz-vw-grip'; g.setAttribute('role', 'separator'); g.setAttribute('aria-orientation', 'vertical'); g.tabIndex = 0;
328
362
  g.setAttribute('aria-label', 'Drag to change the Viewer width. Double-click to reset.'); g.title = 'Drag to change the width. Double-click to reset.';
329
363
  g.innerHTML = '<i></i>';
330
364
  g.addEventListener('pointerdown', (e) => {
331
365
  if (e.button !== 0) return;
366
+ use(x);
332
367
  e.preventDefault(); g.setPointerCapture(e.pointerId); document.body.classList.add('cz-vw-drag');
333
368
  const right = el.getBoundingClientRect().right;
334
- const mv = (ev) => { V.wide = false; apply(right - ev.clientX); };
335
- const up = () => { g.removeEventListener('pointermove', mv); g.removeEventListener('pointerup', up); g.removeEventListener('pointercancel', up); document.body.classList.remove('cz-vw-drag'); if (V.cur) store.set('cz-vw-w:' + kindKey(V.cur.kind), V.w); redraw(); };
369
+ const mv = (ev) => on(x, () => { V.wide = false; apply(right - ev.clientX); });
370
+ const up = () => { g.removeEventListener('pointermove', mv); g.removeEventListener('pointerup', up); g.removeEventListener('pointercancel', up); document.body.classList.remove('cz-vw-drag'); on(x, () => { if (V.cur) store.set('cz-vw-w:' + kindKey(V.cur.kind), V.w); redraw(); }); };
336
371
  g.addEventListener('pointermove', mv); g.addEventListener('pointerup', up); g.addEventListener('pointercancel', up);
337
372
  });
338
- g.addEventListener('dblclick', () => { if (!V.cur) return; store.set('cz-vw-w:' + kindKey(V.cur.kind), null); V.wide = false; setRail(false); apply(room().def); redraw(); });
373
+ g.addEventListener('dblclick', () => { use(x); resetW(); });
339
374
  g.addEventListener('keydown', (e) => { // the grip is a separator: arrows move it 24 px, Home resets it
375
+ use(x);
340
376
  const d = e.key === 'ArrowLeft' ? 24 : e.key === 'ArrowRight' ? -24 : 0;
341
- if (d) { e.preventDefault(); V.wide = false; setWidth(V.w + d); redraw(); } else if (e.key === 'Home') { e.preventDefault(); g.dispatchEvent(new MouseEvent('dblclick')); }
377
+ if (d) { e.preventDefault(); V.wide = false; setWidth(V.w + d); redraw(); } else if (e.key === 'Home') { e.preventDefault(); resetW(); }
342
378
  });
343
379
  return g;
344
380
  }
@@ -394,12 +430,14 @@ function discuss() {
394
430
  function mount() {
395
431
  if (V.el && V.el.isConnected) return V.el;
396
432
  sheet();
397
- const el = document.createElement('section');
398
- el.className = 'cz-vw'; el.id = 'czViewer'; el.hidden = true;
399
- el.setAttribute('aria-labelledby', 'czVwTitle'); el.tabIndex = -1;
433
+ const el = document.createElement('section'), x = V;
434
+ el.className = 'cz-vw'; el.id = V.i ? 'czViewer' + (V.i + 1) : 'czViewer'; el.hidden = true; el.dataset.czPanel = 'v' + V.i;
435
+ if (!V.i) el.setAttribute('aria-labelledby', 'czVwTitle'); // a second Viewer is named by its aria-label (the title id is the first one's)
436
+ el.tabIndex = -1;
400
437
  el.innerHTML = '<header class="cz-vw-hd"></header><div class="cz-vw-body"></div>';
401
438
  el.prepend(grip(el));
402
439
  el.addEventListener('click', (e) => { // the header's presses, and the folds of czSections in the body
440
+ use(x);
403
441
  const f = e.target.closest('[data-czs-fold]'); if (f && el.contains(f)) { toggleFold(f); return; }
404
442
  if (e.target.closest('[data-cz-vw-rn]')) { startRename(); return; } // the title is the rename press (RnATask)
405
443
  const b = e.target.closest('[data-cz-vw]'); if (!b || b.disabled || !el.querySelector('.cz-vw-hd').contains(b)) return;
@@ -412,19 +450,21 @@ function mount() {
412
450
  else if (a === 'chip') { if (V.cur && V.cur.chip && typeof V.cur.chip.on === 'function') V.cur.chip.on(b); }
413
451
  else if (a === 'add') { if (V.cur && V.cur.add && typeof V.cur.add.on === 'function') V.cur.add.on(b); }
414
452
  else if (a === 'wide') wide();
453
+ else if (a === 'place') { if (G.place) G.place('v' + x.i, b); }
415
454
  else if (a === 'discuss') discuss();
416
455
  });
417
- holdable(el);
418
- el.addEventListener('submit', (e) => { if (e.target.closest('[data-cz-vw-ren]')) { e.preventDefault(); saveRename(); } });
419
- el.addEventListener('keydown', (e) => { if (e.key === 'Escape' && e.target.closest('[data-cz-vw-ren]')) { e.preventDefault(); e.stopPropagation(); endRename(); } });
420
- el.addEventListener('input', (e) => { if (e.target.id === 'czVwTitle' && V.cur && V.cur.renaming) V.cur.renValue = e.target.value; });
421
- el.addEventListener('change', (e) => { if (e.target.matches('[data-cz-vw-jira]') && V.cur) V.cur.renJira = e.target.checked; });
456
+ el.addEventListener('focusin', () => use(x));
457
+ holdable(el, x);
458
+ el.addEventListener('submit', (e) => { use(x); if (e.target.closest('[data-cz-vw-ren]')) { e.preventDefault(); saveRename(); } });
459
+ el.addEventListener('keydown', (e) => { use(x); if (e.key === 'Escape' && e.target.closest('[data-cz-vw-ren]')) { e.preventDefault(); e.stopPropagation(); endRename(); } });
460
+ el.addEventListener('input', (e) => { use(x); if (e.target.id === 'czVwTitle' && V.cur && V.cur.renaming) V.cur.renValue = e.target.value; });
461
+ el.addEventListener('change', (e) => { use(x); if (e.target.matches('[data-cz-vw-jira]') && V.cur) V.cur.renJira = e.target.checked; });
422
462
  place(el);
423
463
  V.el = el;
424
- if (typeof ResizeObserver !== 'undefined') new ResizeObserver(() => {
464
+ if (typeof ResizeObserver !== 'undefined') new ResizeObserver(() => on(x, () => {
425
465
  // crossing the phone width redraws the header too (← and no grip on a phone, × on a desk) without reopening the item
426
466
  if (isOpen() && !document.body.classList.contains('cz-vw-drag')) { const was = V.w, ph = V.ph; V.ph = isPhone(); apply(V.wide ? room().wideMax : V.w); if (V.w !== was || V.ph !== ph) redraw(); }
427
- }).observe(document.documentElement);
467
+ })).observe(document.documentElement);
428
468
  return el;
429
469
  }
430
470
  /** In the page's own place for it when there is one (data-cz-viewer-host), else at the end of the body, floating. */
@@ -433,10 +473,14 @@ function place(el) {
433
473
  if (host) { if (el.parentNode !== host) host.appendChild(el); el.classList.remove('cz-vw-float'); }
434
474
  else { if (el.parentNode !== document.body) document.body.appendChild(el); el.classList.add('cz-vw-float'); }
435
475
  }
436
- function emit() {
437
- const d = { open: !!V.cur, id: V.cur ? V.cur.id : null, kind: V.cur ? V.cur.kind : null, title: V.cur ? V.cur.title : null, via: V.cur ? '' : V.via || '' }; // via 'history': the browser's Back closed it
476
+ /** x: the instance that changed. The detail speaks of the Viewer used last (V): open is false only when no Viewer is open; panel names the
477
+ * one that changed and shut says it closed, for cozy-panels.js. */
478
+ function emit(x) {
479
+ x = x || V;
480
+ const d = { open: !!V.cur, id: V.cur ? V.cur.id : null, kind: V.cur ? V.cur.kind : null, title: V.cur ? V.cur.title : null, via: V.cur ? '' : x.via || '', // via 'history': the browser's Back closed it
481
+ panel: 'v' + x.i, shut: !shown(x) };
438
482
  document.body.classList.toggle('cz-vw-on', d.open);
439
- V.subs.forEach((f) => { try { f(d); } catch { /* a listener's fault stays its own */ } });
483
+ G.subs.forEach((f) => { try { f(d); } catch { /* a listener's fault stays its own */ } });
440
484
  document.dispatchEvent(new CustomEvent('cz-viewer', { detail: d }));
441
485
  }
442
486
  /** Runs go now, or after the item's guard says so (it holds unsaved changes and asks Save or Discard first). */
@@ -454,7 +498,7 @@ function redraw() {
454
498
  V.ph = isPhone();
455
499
  const hd = V.el.querySelector('.cz-vw-hd');
456
500
  const bk = V.stack[V.stack.length - 1], fw = V.fwd[V.fwd.length - 1];
457
- hd.innerHTML = headHtml({ ...V.cur, canBack: V.stack.length > 0, backTo: bk ? bk.title || '' : '', fwdTo: fw ? fw.title || 'the next item' : '', isWide: V.wide || V.rail, phone: V.ph, home: onHome() });
501
+ hd.innerHTML = headHtml({ ...V.cur, canBack: V.stack.length > 0, backTo: bk ? bk.title || '' : '', fwdTo: fw ? fw.title || 'the next item' : '', isWide: V.wide || G.rail, phone: V.ph, home: onHome(), place: !!G.place });
458
502
  hd.classList.toggle('cz-vw-renon', !!V.cur.renaming);
459
503
  }
460
504
 
@@ -485,26 +529,33 @@ async function saveRename() {
485
529
  endRename(); emit();
486
530
  }
487
531
  /** The item's own presses change while it is shown (the charter's Save shows only after a change). */
488
- export function setChip(id, chip) {
532
+ function setChip0(id, chip) {
489
533
  if (!V.cur || V.cur.id !== String(id)) return;
490
534
  const was = V.cur.chip, on = !!(chip && (chip.n > 0 || chip.looking)), n = on ? chip.n || 0 : -1;
491
535
  V.cur.chip = on ? chip : null;
492
536
  if (V.cur.args) V.cur.args = { ...V.cur.args, chip: V.cur.chip };
493
537
  if ((was ? was.n || 0 : -1) !== n || (was && chip && (was.label !== chip.label || !!was.looking !== !!chip.looking))) { if (!V.cur.renaming) redraw(); }
494
538
  }
495
- export function setPresses(id, list) { if (V.cur && V.cur.id === String(id)) { V.cur.presses = list || null; if (V.cur.args) V.cur.args = { ...V.cur.args, presses: list || null }; if (!V.cur.renaming) redraw(); } }
539
+ function setPresses0(id, list) { if (V.cur && V.cur.id === String(id)) { V.cur.presses = list || null; if (V.cur.args) V.cur.args = { ...V.cur.args, presses: list || null }; if (!V.cur.renaming) redraw(); } }
496
540
  /** A task's check box changes while it is shown (a status move from the card, canvas XetX1Done). */
497
- export function setCheck(id, check) { if (V.cur && V.cur.id === String(id)) { V.cur.check = check || null; if (V.cur.args) V.cur.args = { ...V.cur.args, check: check || null }; if (!V.cur.renaming) redraw(); } }
541
+ function setCheck0(id, check) { if (V.cur && V.cur.id === String(id)) { V.cur.check = check || null; if (V.cur.args) V.cur.args = { ...V.cur.args, check: check || null }; if (!V.cur.renaming) redraw(); } }
542
+ /** The item may be shown in any Viewer, not only the one used last: each one that shows it changes. */
543
+ const each = (id, fn) => ALL.filter((x) => x.cur && x.cur.id === String(id)).forEach((x) => on(x, fn));
544
+ export function setChip(id, chip) { each(id, () => setChip0(id, chip)); }
545
+ export function setPresses(id, list) { each(id, () => setPresses0(id, list)); }
546
+ export function setCheck(id, check) { each(id, () => setCheck0(id, check)); }
547
+ export function retitle(id, title) { each(id, () => retitle0(id, title)); }
498
548
  /** The caller's own rename landed elsewhere (Undo, or a reload): the header shows the name. */
499
- export function retitle(id, title) { if (V.cur && V.cur.id === String(id) && title) { V.cur.title = title; if (V.cur.args) V.cur.args = { ...V.cur.args, title }; if (!V.cur.renaming) redraw(); emit(); } }
549
+ function retitle0(id, title) { if (V.cur && V.cur.id === String(id) && title) { V.cur.title = title; if (V.cur.args) V.cur.args = { ...V.cur.args, title }; if (!V.cur.renaming) redraw(); emit(); } }
500
550
 
501
551
  /** Show one item in the Viewer, in place of the one shown. Returns the body element the content is in. */
502
552
  export function open(it) {
503
553
  const o = it || {};
554
+ use(o._inst || pick(o));
504
555
  // an item with unsaved changes asks first; the open goes on when it says so (and keeps a drill-in asked for before it)
505
556
  if (!o._asked && V.cur && typeof V.cur.guard === 'function') {
506
557
  const dr = V.drill; let now = true, ran = false;
507
- guarded(() => { ran = true; if (!now) { V.drill = dr; open({ ...o, _asked: true }); } });
558
+ const x = V; guarded(() => { ran = true; if (!now) { x.drill = dr; open({ ...o, _asked: true, _inst: x }); } });
508
559
  now = false;
509
560
  if (!ran) return null;
510
561
  }
@@ -513,6 +564,7 @@ export function open(it) {
513
564
  const was = isOpen(), pos = V.stack.length, how = stepOf(o);
514
565
  if (how === 'nav') { V.stack = o._trail.stack; V.fwd = o._trail.fwd; }
515
566
  else if (how === 'drill') { V.stack.push(V.cur.args); V.fwd = []; hq({ push: 1, s: H.s, i: V.stack.length }); }
567
+ else if (how === 'new' && V.i) { V.stack = []; V.fwd = []; } // a second Viewer keeps its trail without the browser history
516
568
  else if (how === 'new') {
517
569
  // a press starts a trail on its own entry; an open no press led to (the page drew it, or Back from another page restored it) takes the
518
570
  // page's entry, so Back from it leaves the page as before. A new trail from a press takes the place of a pressed one.
@@ -533,8 +585,8 @@ export function open(it) {
533
585
  body.className = 'cz-vw-body'; body.onclick = null; body.oninput = null; body.onchange = null; body.onkeydown = null; // what one item's render added to the body does not reach the next
534
586
  const wasHidden = el.hidden;
535
587
  el.hidden = false;
536
- const hold = V.hold > Date.now() && !wasHidden && (V.wide || V.rail); V.hold = 0;
537
- if (!hold && !(sameKind && !wasHidden && (V.wide || V.rail))) { const k = widthOf(o.kind); V.wide = false; apply(k || room().def); redraw(); }
588
+ const hold = G.hold > Date.now() && !wasHidden && (V.wide || G.rail); G.hold = 0;
589
+ if (!hold && !(sameKind && !wasHidden && (V.wide || G.rail))) { const k = widthOf(o.kind); V.wide = false; apply(k || room().def); redraw(); }
538
590
  if (typeof o.render === 'function') o.render(body); else if (o.html) body.innerHTML = o.html;
539
591
  emit();
540
592
  if (isPhone()) el.focus();
@@ -555,26 +607,31 @@ export function trail() {
555
607
  * already left the trail (its Back at the first item), so the history is not moved again. */
556
608
  export function close(o = {}) {
557
609
  if (!V.el || V.el.hidden) return;
558
- const pos = V.stack.length;
610
+ const pos = V.stack.length, x = V;
559
611
  leave();
560
612
  // the trail's entries come off, so Back never lands on a closed item; a trail on the page's own entry gives that entry back
561
- if (!o.quiet && H.s) { if (H.auto) { if (pos) hq({ go: -pos }); hq({ clear: 1 }); } else hq({ go: -(pos + 1) }); }
562
- H.s = ''; H.auto = false;
613
+ if (!V.i) {
614
+ if (!o.quiet && H.s) { if (H.auto) { if (pos) hq({ go: -pos }); hq({ clear: 1 }); } else hq({ go: -(pos + 1) }); }
615
+ H.s = ''; H.auto = false;
616
+ }
563
617
  V.via = o.quiet ? 'history' : '';
564
618
  V.stack = []; V.fwd = []; V.wide = false; V.drill = false;
565
619
  if (V.over) { V.over = false; document.body.classList.remove('cz-vw-over'); }
566
620
  V.el.hidden = true;
567
621
  V.el.querySelector('.cz-vw-body').innerHTML = '';
568
622
  V.el.querySelectorAll('.cz-vw-menu,.cz-vw-trail').forEach((m) => m.remove());
569
- setRail(false);
570
- emit();
571
- const b = V.back; V.back = null;
572
- if (b && b.isConnected) { try { b.focus(); } catch { /* gone */ } }
623
+ const nx = mru(); // another Viewer is still open: it is the one in use now, and the list stays as it is
624
+ if (nx) V = nx; else setRail(false);
625
+ emit(x);
626
+ let b = x.back; x.back = null;
627
+ // the page drew its rows again meanwhile (a page panel back to its wide form): the same row, by its key, takes the focus
628
+ if (b && !b.isConnected && b.dataset && b.dataset.key) b = document.querySelector(`[data-key="${CSS.escape(b.dataset.key)}"]`);
629
+ if (b && b.isConnected && !nx) { try { b.focus(); } catch { /* gone */ } }
573
630
  }
574
631
  export const isOpen = () => !!(V.el && !V.el.hidden && V.cur);
575
632
  export const current = () => (V.cur ? { id: V.cur.id, kind: V.cur.kind, title: V.cur.title, url: V.cur.url } : null);
576
633
  export const body = () => (isOpen() ? V.el.querySelector('.cz-vw-body') : null);
577
- export function onChange(fn) { if (typeof fn === 'function') V.subs.push(fn); }
634
+ export function onChange(fn) { if (typeof fn === 'function') G.subs.push(fn); }
578
635
  /** Open the Viewer on a feature the design does not draw yet. */
579
636
  export function placeholder(featureName, o = {}) {
580
637
  return open({ id: 'placeholder:' + featureName, kind: o.kind || featureName, title: featureName, icon: o.icon || 'info', render: (el) => czPlaceholder(el, featureName) });
@@ -590,12 +647,12 @@ function stepOf(o) {
590
647
  const p = H.press && Date.now() - H.press.t < 10000 ? H.press : null; // the press that led here: an open often waits for a module or a read
591
648
  if (o.keep && V.cur) return 'keep';
592
649
  if (V.cur && V.cur.args && !o.fresh && (o.back || V.drill)) return 'drill'; // asked for: a view of the same item drills in too (Stage, Documents)
593
- if (V.cur && o.id != null && V.cur.id === String(o.id) && !(p && !p.inside) && !o.fresh) return 'keep';
594
- if (V.cur && V.cur.args && !o.fresh && p && p.inside) return 'drill';
650
+ if (V.cur && o.id != null && V.cur.id === String(o.id) && !(p && p.inst !== V) && !o.fresh) return 'keep';
651
+ if (V.cur && V.cur.args && !o.fresh && p && p.inst === V) return 'drill';
595
652
  return 'new';
596
653
  }
597
654
  /** The history follows the trail. A go() waits for its popstate before the next push or replace, so the order holds. */
598
- function hq(op) { if (!canHist()) return; H.q.push(op); hRun(); }
655
+ function hq(op) { if (!canHist() || V.i) return; H.q.push(op); hRun(); }
599
656
  function hRun() {
600
657
  while (H.q.length && !H.wait) {
601
658
  const op = H.q.shift();
@@ -619,11 +676,12 @@ function step(n, o = {}) {
619
676
  if (at >= seq.length) return null;
620
677
  const to = seq[at];
621
678
  if (!o.quiet) hq({ go: n });
622
- return open({ ...to, back: false, keep: false, _asked: true, _nav: true, _trail: { stack: seq.slice(0, at), fwd: seq.slice(at + 1).reverse() } });
679
+ return open({ ...to, back: false, keep: false, _asked: true, _nav: true, _inst: V, _trail: { stack: seq.slice(0, at), fwd: seq.slice(at + 1).reverse() } });
623
680
  }
624
681
  /** The browser moved (Back, Forward, a swipe, a long press on its own ←). An item with unsaved changes asks first: the browser goes back to
625
682
  * where it was, and the move runs on Save or Discard. */
626
- function popped(e) {
683
+ function popped(e) { use(ALL[0]); popped0(e); }
684
+ function popped0(e) {
627
685
  if (H.wait) { H.wait = 0; hRun(); return; } // the history moving after ← → or a close: the Viewer is already there
628
686
  const st = e && e.state && e.state.czvw;
629
687
  if (!st) { if (isOpen()) follow(-(V.stack.length + 1)); return; } // before the trail: the page as it was
@@ -638,20 +696,20 @@ function follow(n) {
638
696
  if (!ran) hq({ go: -n });
639
697
  }
640
698
  /* where a press was: inside the Viewer it drills in, outside it starts a new trail */
641
- function pressAt(e) { const t = e.target; H.press = { t: Date.now(), inside: !!(V.el && t && t.nodeType === 1 && V.el.contains(t) && !t.closest('.cz-vw-trail')) }; }
699
+ function pressAt(e) { const t = e.target; const inst = t && t.nodeType === 1 && !t.closest('.cz-vw-trail') ? ALL.find((x) => x.el && x.el.contains(t)) || null : null; H.press = { t: Date.now(), inst }; }
642
700
  /* the trail list: hover ← or → for a moment (a mouse), or hold it (a touch). It names every step, newest first, and the page it started on. */
643
701
  let HOLD = { t: 0, fired: 0 };
644
- function holdable(el) {
645
- el.addEventListener('pointerover', (e) => { const b = e.target.closest('[data-cz-vw="back"],[data-cz-vw="fwd"]'); if (!b || e.pointerType === 'touch' || !V.stack.length && !V.fwd.length) return; clearTimeout(HOLD.t); HOLD.t = setTimeout(() => trailMenu(b), 500); });
702
+ function holdable(el, x) {
703
+ el.addEventListener('pointerover', (e) => { const b = e.target.closest('[data-cz-vw="back"],[data-cz-vw="fwd"]'); if (!b || e.pointerType === 'touch' || !x.stack.length && !x.fwd.length) return; clearTimeout(HOLD.t); HOLD.t = setTimeout(() => on(x, () => trailMenu(b, x)), 500); });
646
704
  el.addEventListener('pointerout', (e) => { if (e.target.closest('[data-cz-vw="back"],[data-cz-vw="fwd"]')) clearTimeout(HOLD.t); });
647
- el.addEventListener('pointerdown', (e) => { const b = e.target.closest('[data-cz-vw="back"],[data-cz-vw="fwd"]'); if (!b) return; HOLD.fired = 0; if (e.pointerType === 'mouse' || !V.stack.length && !V.fwd.length) return; clearTimeout(HOLD.t); HOLD.t = setTimeout(() => { HOLD.fired = Date.now(); trailMenu(b); }, 500); });
705
+ el.addEventListener('pointerdown', (e) => { const b = e.target.closest('[data-cz-vw="back"],[data-cz-vw="fwd"]'); if (!b) return; HOLD.fired = 0; if (e.pointerType === 'mouse' || !x.stack.length && !x.fwd.length) return; clearTimeout(HOLD.t); HOLD.t = setTimeout(() => { HOLD.fired = Date.now(); on(x, () => trailMenu(b, x)); }, 500); });
648
706
  ['pointerup', 'pointercancel'].forEach((k) => el.addEventListener(k, () => clearTimeout(HOLD.t)));
649
707
  el.addEventListener('contextmenu', (e) => { if (e.target.closest('[data-cz-vw="back"],[data-cz-vw="fwd"]')) e.preventDefault(); });
650
708
  }
651
709
  /** A hold that opened the trail list is not also a press. */
652
710
  function held() { if (HOLD.fired && Date.now() - HOLD.fired < 800) { HOLD.fired = 0; return true; } return false; }
653
711
  const PAGES = { '/premium.html': 'Home', '/premium-board.html': 'Board', '/premium-intelligence.html': 'Intelligence', '/premium-insights.html': 'Intelligence' };
654
- function trailMenu(b) {
712
+ function trailMenu(b, x) {
655
713
  if (!V.cur || !V.el) return;
656
714
  const old = V.el.querySelector('.cz-vw-trail'); if (old) old.remove();
657
715
  const seq = [...V.stack, V.cur.args, ...V.fwd.slice().reverse()], here = V.stack.length;
@@ -663,7 +721,7 @@ function trailMenu(b) {
663
721
  + `<button type="button" role="menuitem" class="pg" data-cz-vw-go="${-(here + 1)}"><span class="t">${svg(P.home, 15)}</span><span>${esc(PAGES[location.pathname] || document.title || 'The page')}</span></button>`;
664
722
  const off = () => { m.remove(); document.removeEventListener('pointerdown', away, true); };
665
723
  const away = (e) => { if (!m.contains(e.target)) off(); };
666
- m.addEventListener('click', (e) => { const x = e.target.closest('[data-cz-vw-go]'); if (!x) return; const n = +x.dataset.czVwGo; off(); if (n) guarded(() => step(n), b); });
724
+ m.addEventListener('click', (e) => { const g = e.target.closest('[data-cz-vw-go]'); if (!g) return; const n = +g.dataset.czVwGo; off(); if (x) use(x); if (n) guarded(() => step(n), b); });
667
725
  m.addEventListener('keydown', (e) => {
668
726
  const bs = [...m.querySelectorAll('button')], at = bs.indexOf(document.activeElement);
669
727
  if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); off(); b.focus(); }
@@ -681,13 +739,33 @@ if (typeof window !== 'undefined' && typeof window.addEventListener === 'functio
681
739
  // Escape closes the Viewer first, unless a layer over it (a menu, a confirm) is open: that layer closes first. The listener is on
682
740
  // window in the capture phase and is added before premium-shell.js adds its own, so the old dialog does not also close on the same key.
683
741
  window.addEventListener('keydown', (e) => {
684
- if (e.key !== 'Escape' || !isOpen() || e.defaultPrevented) return;
742
+ const x = mru();
743
+ if (e.key !== 'Escape' || !x || e.defaultPrevented) return;
685
744
  if (document.querySelector('[data-esc-layer]')) return;
686
- e.preventDefault(); e.stopImmediatePropagation(); guarded(close);
745
+ use(x); e.preventDefault(); e.stopImmediatePropagation(); guarded(close);
687
746
  }, true);
688
747
  window.addEventListener('click', pressAt, true);
689
748
  window.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') pressAt(e); }, true);
690
749
  window.addEventListener('popstate', popped);
691
750
  try { H.adopt = !!(history.state && history.state.czvw); } catch { H.adopt = false; } // back here from another page, or a reload: the first open takes this entry
692
751
  }
752
+ /* ── for cozy-panels.js (batch 18 item 15): the instances behind one object. A panel id is 'v' + the instance's number (v0 is #czViewer). ── */
753
+ const byP = (id) => ALL.find((x) => 'v' + x.i === id) || null;
754
+ export const panels = {
755
+ list: () => ALL.map((x) => ({ id: 'v' + x.i, open: shown(x), used: x.used, el: x.el, item: x.cur ? { id: x.cur.id, kind: x.cur.kind, title: x.cur.title } : null })),
756
+ /** limit: how many Viewers may be open at once · place(id, button): ⧉ was pressed · managed(id) → true: the panels engine sizes it */
757
+ config(c = {}) { if (c.limit) G.limit = c.limit; if ('place' in c) G.place = c.place; if ('managed' in c) G.managed = c.managed; ALL.filter(shown).forEach((x) => on(x, redraw)); },
758
+ /** The next open() goes into a Viewer of its own (a drop beside, TbT5DragRow). */
759
+ beside() { G.beside = { t: Date.now() }; }, unbeside() { G.beside = null; },
760
+ close(id) { const x = byP(id); if (shown(x)) { use(x); guarded(close); } },
761
+ use(id) { const x = byP(id); if (x) use(x); },
762
+ /** The width of a Viewer beside the chat (the first divider drives it): px; keep: remembered for its kind. */
763
+ size(id, px, keep) { const x = byP(id); if (shown(x)) on(x, () => { V.wide = false; setWidth(px, keep); redraw(); }); },
764
+ reset(id) { const x = byP(id); if (shown(x)) on(x, resetW); },
765
+ /** Lay each open Viewer out again (the engine changed what it manages). */
766
+ relayout() { ALL.filter(shown).forEach((x) => on(x, () => { apply(V.wide ? room().wideMax : V.w || room().def); redraw(); })); },
767
+ /** Back beside the chat after the engine laid it out: the width its kind keeps, else the default. */
768
+ rest() { ALL.filter(shown).forEach((x) => on(x, () => { const k = widthOf(V.cur.kind); V.wide = false; apply(k || room().def); redraw(); })); },
769
+ rail(v) { setRail(!!v); }, railOn: () => G.rail,
770
+ };
693
771
  if (typeof window !== 'undefined') window.czViewer = { open, close, back, forward, trail, replaceUrl, drill, setPresses, setChip, setCheck, isOpen, current, body, onChange, placeholder, retitle, czSummary, czSections, widthOf, setWidth, wide, railOn, railCard, railSync, keepWide, ICONS };
@@ -156,6 +156,8 @@ function repRow(r) {
156
156
  + `<div class="db-acts">${ib('hold', 'Skip this one', I.x, { k: rid(r) + '|skip' })}${ib('hold', 'Send it now with a note', I.send, { k: rid(r) + '|send-note' })}${ib('hold', 'Wait until it reads again', I.clock, { solid: true, k: rid(r) + '|wait' })}</div></div>`;
157
157
  const open = r.path ? ` data-db="report" data-k="${esc(rid(r))}"` : '';
158
158
  const head = `<${r.path ? 'button type="button"' : 'div'} class="db-rep"${open}><span class="db-dic">${SV(iconOf(r), 16)}</span><span class="db-rt"><b>${esc(r.name)}</b>${r.sub ? `<small>${esc(r.sub)}</small>` : ''}</span>${r.path ? SV(I.next, 16) : ''}</${r.path ? 'button' : 'div'}>`;
159
+ // a calm week goes by itself 10 minutes after its time (batch 17 item 6): skip it, keep each week for your own press, or send it now
160
+ if (r.calm) return `<div class="db-late">${head}<div class="db-acts">${ib('hold', 'Skip this week', I.x, { k: rid(r) + '|skip' })}${ib('calm-off', 'Wait for me to send it, every week', I.clock, { k: rid(r) })}${ib('send', 'Send it now', I.send, { solid: true, k: rid(r) })}</div></div>`;
159
161
  if (r.state === 'late') return `<div class="db-late">${head}<div class="db-acts">${ib('hold', 'Skip this week', I.x, { k: rid(r) + '|skip' })}${ib('send', 'Send it now', I.send, { solid: true, k: rid(r) })}</div></div>`;
160
162
  return head;
161
163
  }
@@ -175,7 +177,7 @@ function reportsHtml(d, o) {
175
177
  const more = rest.length ? `<button type="button" class="db-fold" data-db="fold" data-k="reports" aria-expanded="${open}"><span class="db-rt"><b>${rest.length} more</b><small>${esc(rest.map((r) => [r.name, r.sub].filter(Boolean).join(' · ')).join(' · '))}</small></span>${SV(I.down, 16)}</button>${open ? rest.map(repRow).join('') : ''}` : '';
176
178
  return hu + sec(d.level === 'product' ? 'This week' : 'Reports', `<div class="db-card db-reps">${lead.map(repRow).join('')}${more}</div>`);
177
179
  }
178
- /** Send by itself (PbG6): offered after 4 issues sent unchanged; calm weeks only. Off by default. */
180
+ /** Send by itself (PbG6): calm weeks go by themselves by default (Wawan 2026-10-28); the card shows only where the PM had turned it off. */
179
181
  function trustHtml(d) {
180
182
  const t = d.trust; if (!t) return '';
181
183
  return `<div class="db-card db-trust"><div class="db-top"><span class="db-rt"><b>Send by itself</b><small>Only weeks where everything is on its line</small></span></div>`
@@ -219,7 +221,8 @@ export function wireDash(body, h) {
219
221
  if (a === 'hold') { const [id, act] = k.split('|'), r = row(id) || {}; return done(await post('/api/ready-reports/hold', { ...base, kind: r.kind, act }), act === 'wait' ? 'It waits. It goes by itself once the source reads, if nothing changed.' : act === 'send-note' ? 'Sent, with the date of the last reading written on it.' : 'Skipped. The next issue covers both weeks.'); }
220
222
  // ➤ is the report's Issue press (POST /api/report/issue): PMOS never sends outward; issuing freezes the bytes the PM sends from their mail
221
223
  if (a === 'send') { const r = row(k) || {}; if (!r.cadence || !r.slot || !r.sha) { b.disabled = false; if (h.openReport && (r.path || r.desk)) h.openReport(r, d); return; } return done(await post('/api/report/issue', { ws: h.ws || undefined, cadence: r.cadence, slot: r.slot, sha: r.sha }), 'Issued. It is frozen as sent.'); }
222
- if (a === 'trust') { const r = (d.reports || []).find((x) => x.id === (d.trust && d.trust.reportId)) || (d.reports || [])[0] || {}; return done(await post('/api/ready-reports/trust', { ...base, kind: r.kind || 'weekly', on: k === 'on' }), k === 'on' ? 'Calm weeks get ready by themselves. You still issue each one, and a miss or a decision waits for you.' : 'Not now. Each week waits for you to approve it.'); }
224
+ if (a === 'calm-off') { const r = row(k) || {}; return done(await post('/api/ready-reports/trust', { ...base, kind: r.kind || 'weekly', on: false }), 'It waits for your press, this week and every week after.'); }
225
+ if (a === 'trust') { const r = (d.reports || []).find((x) => x.id === (d.trust && d.trust.reportId)) || (d.reports || [])[0] || {}; return done(await post('/api/ready-reports/trust', { ...base, kind: r.kind || 'weekly', on: k === 'on' }), k === 'on' ? 'Calm weeks go by themselves, 10 minutes after their time. A miss or a decision waits for you.' : 'Not now. Each week waits for your press.'); }
223
226
  if (a === 'reread') return done(await post('/api/sources/refresh', { ws: h.ws || undefined, source: k || 'jira' }), 'Reading it again. The dashboard shows it when the read lands.');
224
227
  // Connect again: Sources in the Viewer (pm/cozy-sources.js), where a source that is off or failing is connected; ← comes back
225
228
  if (a === 'reconnect') { b.disabled = false; if (h.reconnect) { h.reconnect(k); return; } const V = await import('./cozy-viewer.js'); V.drill(); (await import('./cozy-sources.js')).openSources(); return; }
@@ -6,6 +6,7 @@
6
6
  * keptSay(rows) the "Kept" toast: "Kept. I read it every Monday 07:00." with the goal's own rhythm (never "every morning")
7
7
  * tableHtml(rows, o) GcJ1aTable: the drafts table. Proposed metric · How it is counted · Now (read hh:mm) · Target · From, how often · ✕ ✓
8
8
  * checkHtml(r, st) GcJ1Drafts: the check panel of one drafted metric; GcS3Differs once the PM typed a number that differs
9
+ * needOf(x) "it needs a full week": why a weekly (or monthly) goal is not read more often, said after How often
9
10
  * firstOf(g) { n, first, next } while a goal has fewer than 3 readings (GcJ2FirstMonday): no pace, no trend yet
10
11
  * firstMeta(g) the row's second line then: "39.4k · Looker, Mon 2 Nov 07:02 · pace known after 3 readings"
11
12
  * firstChart(g) the dashed box where the chart will be: "The line starts with the 2nd reading, Mon 9 Nov"
@@ -52,6 +53,12 @@ export function rhythmOf(x) {
52
53
  if (c === 'monthly') return { short: 'Every month', long: 'every month, the 1st' + (at ? ' ' + at : '') };
53
54
  return { short: String(c), long: String(c) };
54
55
  }
56
+ /** Why a goal is read no more often than this (GcJ1Drafts): a weekly count needs the whole week in it, a monthly one the whole month. */
57
+ export function needOf(x) {
58
+ const R = (x && x.rhythm) || (x && x.raw && x.raw.rhythm), rc = (x && x.recipe) || (x && x.raw && x.raw.recipe) || null;
59
+ const c = (R && typeof R === 'object' && R.cadence) || (rc && rc.cadence) || '';
60
+ return c === 'weekly' ? 'it needs a full week' : c === 'monthly' ? 'it needs a full month' : '';
61
+ }
55
62
  /** The "Kept" toast (AdM3Intel, now with the goal's own rhythm). rows: the drafts kept by this press. One rhythm for all: it says it; several:
56
63
  * "each on its own rhythm". A server's said line (r.said) wins. */
57
64
  export function keptSay(rows, said) {
@@ -147,8 +154,8 @@ export function checkHtml(r, st = {}) {
147
154
  + `<div class="gc-sec"><b class="gc-k">My checks</b><ul class="gc-checks">${list.map(checkRow).join('')}</ul></div>`
148
155
  + `<form class="gc-cmp" data-gc-cmp><input name="v" inputmode="decimal" maxlength="24" autocomplete="off" placeholder="${esc('Your number for ' + (L && L.period ? L.period.replace(/^week of .*/, 'last week') : 'last week') + (value ? ', e.g. ' + value : ''))}" aria-label="Your number, to compare with mine" value="${esc(st.compare || '')}">`
149
156
  + `<button type="submit" class="cz-ib sm solid" aria-label="Compare with my number" title="Compare"${st.busy ? ' disabled' : ''}>${icon(I.chk, 18)}</button></form>`
150
- + (R ? `<p class="gc-line"><b>How often</b> ${esc(R.long)}</p>` : '')
151
- + queryHtml(rc, false)
157
+ + (R ? `<p class="gc-line"><b>How often</b> ${esc([R.long, needOf(r)].filter(Boolean).join(' · '))}</p>` : '')
158
+ + queryHtml(rc, true)
152
159
  + `<div class="gc-foot">${rc && rc.url ? `<a class="cz-ib sm" href="${esc(rc.url)}" target="_blank" rel="noopener noreferrer" aria-label="Open in ${esc(rc.connector || 'the source')}" title="Open in ${esc(rc.connector || 'the source')}">${icon(I.open)}</a>` : ''}`
153
160
  + ib({ act: 'edit', row: r.id, icon: I.pen, label: 'Edit how it is counted, the target or the source', title: 'Edit', busy: st.busy })
154
161
  + ib({ act: 'test', row: r.id, icon: I.redo, label: 'Read it now', title: 'Read now', busy: st.busy })