create-pmos 0.712.0 → 0.714.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 (123) hide show
  1. package/package.json +99 -51
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/design-system/ui/README.md +1 -1
  4. package/payload/design-system/ui/components/State/README.md +21 -0
  5. package/payload/design-system/ui/components/State/preview.html +8 -0
  6. package/payload/design-system/ui/components/bundle.css +12 -0
  7. package/payload/design-system/ui/interactions.md +10 -0
  8. package/payload/planning/evals/eval-calibration.md +1 -1
  9. package/payload/planning/okrs/health-budgets.md +1 -1
  10. package/payload/state/discoveries.md +1 -1
  11. package/workspace/bin/back-place-health.js +70 -0
  12. package/workspace/changelog.json +98 -0
  13. package/workspace/design-system/ui/README.md +1 -1
  14. package/workspace/design-system/ui/components/State/README.md +21 -0
  15. package/workspace/design-system/ui/components/State/preview.html +8 -0
  16. package/workspace/design-system/ui/components/bundle.css +12 -0
  17. package/workspace/design-system/ui/interactions.md +10 -0
  18. package/workspace/guide/breakdown.md +20 -1
  19. package/workspace/guide/claude-proposes.md +5 -1
  20. package/workspace/guide/cli.md +10 -1
  21. package/workspace/guide/home.md +1 -0
  22. package/workspace/guide/initiatives-and-next-steps.md +13 -0
  23. package/workspace/guide/layout.md +27 -1
  24. package/workspace/guide/routine.md +10 -2
  25. package/workspace/guide/settings-and-switches.md +4 -0
  26. package/workspace/lib/briefing-premium-products.js +16 -2
  27. package/workspace/lib/changed-mark.js +34 -0
  28. package/workspace/lib/launch-cli.js +43 -5
  29. package/workspace/lib/launch-tiers.js +143 -0
  30. package/workspace/lib/moments.js +41 -3
  31. package/workspace/lib/needs-providers.js +1 -0
  32. package/workspace/lib/parked-cli.js +105 -0
  33. package/workspace/lib/parked-reasons.js +245 -0
  34. package/workspace/lib/pmos-verbs.js +4 -1
  35. package/workspace/lib/prefs-sync.js +138 -0
  36. package/workspace/lib/product-dots.js +60 -0
  37. package/workspace/lib/route-modules.js +2 -0
  38. package/workspace/lib/routes-briefing-premium.js +11 -1
  39. package/workspace/lib/routes-moments.js +1 -1
  40. package/workspace/lib/routes-prefs.js +56 -0
  41. package/workspace/lib/routes-strategy-card.js +53 -0
  42. package/workspace/lib/routes-use-log.js +24 -3
  43. package/workspace/lib/routine-sentence.js +250 -0
  44. package/workspace/lib/strategy-card.js +133 -0
  45. package/workspace/lib/unused-controls.js +178 -0
  46. package/workspace/lib/use-log.js +27 -3
  47. package/workspace/package-lock.json +2 -2
  48. package/workspace/package.json +1 -1
  49. package/workspace/premium-vw-doc-test.js +2 -0
  50. package/workspace/public/pm/action-keys.js +187 -0
  51. package/workspace/public/pm/back-place.js +87 -0
  52. package/workspace/public/pm/bd-pop-ds.css +10 -0
  53. package/workspace/public/pm/bd-pop-ds.js +27 -3
  54. package/workspace/public/pm/bd-strategy.js +85 -0
  55. package/workspace/public/pm/bd-views.js +2 -1
  56. package/workspace/public/pm/changed-mark.css +7 -0
  57. package/workspace/public/pm/changed-mark.js +117 -0
  58. package/workspace/public/pm/cozy-ev.css +7 -0
  59. package/workspace/public/pm/cozy-nav.js +2 -0
  60. package/workspace/public/pm/cozy-pick.css +12 -0
  61. package/workspace/public/pm/cozy-pop-work.css +10 -1
  62. package/workspace/public/pm/cozy-pop-work.js +201 -17
  63. package/workspace/public/pm/cozy-routine-job.js +50 -7
  64. package/workspace/public/pm/cozy-routine.css +2 -0
  65. package/workspace/public/pm/cozy-settings.js +21 -3
  66. package/workspace/public/pm/cozy-today-page.css +1 -0
  67. package/workspace/public/pm/cozy-viewer.css +1 -1
  68. package/workspace/public/pm/cozy-viewer.js +14 -2
  69. package/workspace/public/pm/cozy-vw-mtg.css +0 -2
  70. package/workspace/public/pm/cozy-vw.css +0 -1
  71. package/workspace/public/pm/home-app.js +21 -1
  72. package/workspace/public/pm/home-today.js +2 -0
  73. package/workspace/public/pm/ini-tasks.js +4 -1
  74. package/workspace/public/pm/komorebi.css +11 -0
  75. package/workspace/public/pm/page-chat.js +16 -0
  76. package/workspace/public/pm/prefs-sync.js +111 -0
  77. package/workspace/public/pm/premium-board.js +20 -2
  78. package/workspace/public/pm/premium-chart-tab.js +2 -1
  79. package/workspace/public/pm/premium-insights.js +2 -2
  80. package/workspace/public/pm/premium-mtg-replay.js +4 -3
  81. package/workspace/public/pm/premium-report-read.js +5 -4
  82. package/workspace/public/pm/premium-report-tab.js +4 -3
  83. package/workspace/public/pm/premium-vw-backlog.css +2 -1
  84. package/workspace/public/pm/premium-vw-backlog.js +4 -3
  85. package/workspace/public/pm/premium-vw-cal.css +1 -2
  86. package/workspace/public/pm/premium-vw-cal.js +14 -13
  87. package/workspace/public/pm/premium-vw-copies.js +3 -2
  88. package/workspace/public/pm/premium-vw-copy.css +0 -3
  89. package/workspace/public/pm/premium-vw-mtg.js +12 -11
  90. package/workspace/public/pm/product-switcher.js +41 -0
  91. package/workspace/public/pm/quiet-place.js +15 -2
  92. package/workspace/public/pm/report-orders-ui.js +2 -1
  93. package/workspace/public/pm/rp-parts.js +3 -2
  94. package/workspace/public/pm/state-blocks.js +67 -0
  95. package/workspace/public/pm/use-log.js +127 -1
  96. package/workspace/public/pm/work-select.js +92 -2
  97. package/workspace/public/pm/work-tree.js +70 -0
  98. package/workspace/public/premium-aud.html +1 -0
  99. package/workspace/public/premium-board.html +5 -0
  100. package/workspace/public/premium-buddy.html +1 -0
  101. package/workspace/public/premium-events.html +1 -0
  102. package/workspace/public/premium-goals.html +1 -0
  103. package/workspace/public/premium-intelligence.html +1 -0
  104. package/workspace/public/premium-library.html +1 -0
  105. package/workspace/public/premium-present.html +1 -0
  106. package/workspace/public/premium-rec.html +1 -0
  107. package/workspace/public/premium-routine.html +1 -0
  108. package/workspace/public/premium-viewer.html +1 -0
  109. package/workspace/public/premium-workflows.html +1 -0
  110. package/workspace/public/today.html +1 -0
  111. package/workspace/server.js +20 -0
  112. package/workspace/test-lists/action-keys.json +9 -0
  113. package/workspace/test-lists/back-place.json +9 -0
  114. package/workspace/test-lists/changed-mark.json +9 -0
  115. package/workspace/test-lists/launch-tiers.json +9 -0
  116. package/workspace/test-lists/parked-reasons.json +9 -0
  117. package/workspace/test-lists/prefs-follow-person.json +9 -0
  118. package/workspace/test-lists/product-switcher-dots.json +9 -0
  119. package/workspace/test-lists/routine-sentence.json +9 -0
  120. package/workspace/test-lists/shared-empty-states.json +9 -0
  121. package/workspace/test-lists/strategy-card.json +9 -0
  122. package/workspace/test-lists/unused-controls.json +9 -0
  123. package/workspace/test-lists/work-subtasks-followups.json +9 -0
@@ -53,14 +53,14 @@ const store = {
53
53
  };
54
54
  // 'pw-cols2': a column choice saved before round 3 (Status and Date hidden by an older tune menu) no longer hides them (round 3 point 5)
55
55
  const COLS = 'pw-cols2', SPAN = 'pw-span', BIG = 'pw-big', TLW = 'pw-tlw';
56
- const cols = () => ({ status: true, date: true, tl: true, kind: true, when: true, ...store.get(COLS, {}) });
56
+ const cols = () => ({ status: true, date: true, tl: true, jira: true, kind: true, when: true, ...store.get(COLS, {}) });
57
57
  const ST = new Map(); // initiative id → { open, shut, moreOpen, farOpen, details, top, subOpen, subShut, sel, anchor, tickAsk }
58
58
  let RSEL = new Set(); // the rows picked in the initiative drawn last (WorkBulkDS)
59
59
  const LOOSE = 'pw-loose'; // the initiatives whose Not in a stage row the PM opened (round 3 point 21), remembered on this computer
60
60
  const stOf = (id) => {
61
61
  if (!ST.has(id)) ST.set(id, { open: new Set((store.get(LOOSE, []) || []).includes(id) ? [''] : []), shut: new Set(), moreOpen: new Set(), farOpen: false, details: null, top: 0, msAdd: false, focus: '',
62
62
  // subtasks and the bulk move (initiative work-subtasks): the parents the PM opened or folded, the picked rows, the parent ticked
63
- subOpen: new Set(), subShut: new Set(), sel: new Set(), anchor: '', tickAsk: '' });
63
+ subOpen: new Set(), subShut: new Set(), sel: new Set(), anchor: '', tickAsk: '', src: 'all' });
64
64
  return ST.get(id);
65
65
  };
66
66
  const looseKeep = (id, on) => { const L = (store.get(LOOSE, []) || []).filter((x) => x !== id); if (on) L.push(id); store.set(LOOSE, L.slice(-200)); };
@@ -179,11 +179,13 @@ function headCells(C, W, mode, kind) {
179
179
  const tl = C.tl ? `<div class="pw-tl pw-tlh" aria-hidden="true">`
180
180
  + mk.months.filter((m) => m.x > 3 && m.x < 90 && !(td != null && Math.abs(m.x - td) < 7)).map((m) => `<span class="pw-mk" style="left:${m.x.toFixed(2)}%">${esc(m.label)}</span>`).join('')
181
181
  + (td != null ? `<span class="pw-tday" style="left:clamp(24px, ${td.toFixed(2)}%, calc(100% - 24px))">Today</span>` : '') + '</div>' : '';
182
- return `<div class="pw-tr pw-th" role="row"><span role="columnheader">${kind || 'Item'}</span>${C.status ? '<span role="columnheader">Status</span>' : ''}${C.date ? '<span role="columnheader">Date</span>' : ''}${tl}</div>`;
182
+ return `<div class="pw-tr pw-th" role="row"><span role="columnheader">${kind || 'Item'}</span>${W.jc ? '<span class="pw-jc" role="columnheader">Jira</span>' : ''}${C.status ? '<span role="columnheader">Status</span>' : ''}${C.date ? '<span role="columnheader">Date</span>' : ''}${tl}</div>`;
183
183
  }
184
184
  /* the grip between the item columns and the timeline (round 3 point 1): drag it left or right; the item columns keep about 220 px (the name)
185
185
  * and the timeline about 240 px. Double press or Home: back to the default. The width is remembered on this computer. */
186
- const tlStyle = () => { const w = +store.get(TLW, 0); return w > 0 ? ` style="--pw-tlw:${Math.round(w)}px"` : ''; };
186
+ const tlStyle = (gc = '') => { const w = +store.get(TLW, 0), s = (w > 0 ? `--pw-tlw:${Math.round(w)}px;` : '') + (gc ? `--pw-gc:${gc};` : ''); return s ? ` style="${s}"` : ''; };
187
+ /* the Gantt's Jira column (WorkJiraDS, work-subtasks-followups): the grid's columns when it shows, Item · Jira · Status · Date · Timeline */
188
+ const gridOf = (C) => [C.tl ? 'minmax(220px, 1fr)' : 'minmax(0, 1fr)', 'minmax(0, 132px)', C.status ? (C.tl ? 'minmax(0, 112px)' : '110px') : '', C.date ? (C.tl ? 'minmax(0, 168px)' : '160px') : '', C.tl ? 'var(--pw-tl)' : ''].filter(Boolean).join(' ');
187
189
  const gripHtml = () => `<div class="pw-tlgrip" role="separator" aria-orientation="vertical" tabindex="0" data-pw-grip aria-label="Drag to make the timeline wider or narrower. Double press to reset." title="Drag to make the timeline wider or narrower. Double press to reset."><i></i></div>`;
188
190
  function wireGrip(root) {
189
191
  if (root.__pwGrip) return; root.__pwGrip = true;
@@ -222,6 +224,7 @@ function barHtml(x, W) {
222
224
  return CB.taskBar(x, X, W.today);
223
225
  }
224
226
  function rowHtml(x, W, C, sugRows) {
227
+ const jc = W.jc ? (x.kind === 'task' ? `<span class="pw-jc">${PD.keyChip(x)}${PD.epicDot(x, W.epics || [])}</span>` : '<span class="pw-jc"></span>') : '';
225
228
  if (RO) { x = { ...x, jira: true }; sugRows = new Map(); } // a copy: a task's status, date and name are text, as a Jira task's are; no ✦
226
229
  const tl = C.tl ? `<div class="pw-tl">${(x.kind === 'stage' || x.kind === 'task') ? barHtml(x, W) : ''}${W.tx != null ? `<i class="pw-now" style="left:${W.tx.toFixed(2)}%"></i>` : ''}</div>` : '';
227
230
  const stc = C.status ? `<span class="pw-st">${x.kind === 'task' && !x.jira ? `<button type="button" class="pw-cell" data-pw-status="${esc(x.uid)}" aria-haspopup="menu" aria-label="${esc('Status: ' + x.status + '. Change it')}">${esc(x.status)}</button>` : esc(x.status || '')}</span>` : '';
@@ -229,17 +232,17 @@ function rowHtml(x, W, C, sugRows) {
229
232
  if (x.kind === 'stage') {
230
233
  const lead = `<button type="button" class="pw-stg" data-pw-fold="${esc(x.key)}" aria-expanded="${x.open}"${x.can ? '' : ' disabled'}><span class="pw-n">${esc(x.n)}</span><b>${esc(x.name)}</b>${x.can ? SVG(x.open ? P.down : P.right, 14) : ''}<small>${esc(x.count)}</small></button>`;
231
234
  const ls = x.loose ? sugRows.get('stage:') : null; // the one ✦ of the Not in a stage row (round 3 point 21)
232
- return `<div class="pw-tr pw-sr${x.now ? ' now' : ''}${x.loose ? ' loose' : ''}" role="row"><span class="pw-it">${lead}</span>${stc}${dtc}${x.loose ? (C.tl ? '<div class="pw-tl"></div>' : '') : tl}</div>`
235
+ return `<div class="pw-tr pw-sr${x.now ? ' now' : ''}${x.loose ? ' loose' : ''}" role="row"><span class="pw-it">${lead}</span>${jc}${stc}${dtc}${x.loose ? (C.tl ? '<div class="pw-tl"></div>' : '') : tl}</div>`
233
236
  + (ls ? `<div class="pw-tr pw-sugrow" role="row"><span class="pw-it">${sugLine(ls, true)}</span></div>` : '');
234
237
  }
235
- if (x.kind === 'far') return `<div class="pw-tr pw-sr" role="row"><span class="pw-it"><button type="button" class="pw-stg" data-pw-far aria-expanded="false"><span class="pw-n">${esc(x.n)}</span><b>${esc(x.name)}</b>${SVG(P.right, 14)}<small>${esc(x.count)}</small></button></span>${stc}${C.date ? '<span></span>' : ''}${tl}</div>`;
236
- if (x.kind === 'more') return `<div class="pw-tr pw-dr" role="row"><span class="pw-it"><button type="button" class="pw-dn" data-pw-more="${esc(x.key)}" aria-expanded="false">${esc(x.label)}${SVG(P.right, 14)}</button></span>${C.status ? '<span></span>' : ''}${C.date ? '<span></span>' : ''}${C.tl ? '<div class="pw-tl"></div>' : ''}</div>`;
238
+ if (x.kind === 'far') return `<div class="pw-tr pw-sr" role="row"><span class="pw-it"><button type="button" class="pw-stg" data-pw-far aria-expanded="false"><span class="pw-n">${esc(x.n)}</span><b>${esc(x.name)}</b>${SVG(P.right, 14)}<small>${esc(x.count)}</small></button></span>${jc}${stc}${C.date ? '<span></span>' : ''}${tl}</div>`;
239
+ if (x.kind === 'more') return `<div class="pw-tr pw-dr" role="row"><span class="pw-it"><button type="button" class="pw-dn" data-pw-more="${esc(x.key)}" aria-expanded="false">${esc(x.label)}${SVG(P.right, 14)}</button></span>${jc}${C.status ? '<span></span>' : ''}${C.date ? '<span></span>' : ''}${C.tl ? '<div class="pw-tl"></div>' : ''}</div>`;
237
240
  const s = sugRows.get(x.uid);
238
241
  const title = x.jira ? `<span class="pw-tt">${esc(x.title)}</span>` : `<button type="button" class="pw-tt" data-pw-name="${esc(x.uid)}" aria-label="${esc('Rename ' + x.title)}">${esc(x.title)}</button>`;
239
242
  // subtasks (WorkSubtasksDS): indent one step per level, a parent's fold and count; a Jira row's key chip and the epic check's dot (WorkJiraDS)
240
243
  const chev = x.kids ? `<button type="button" class="pw-chev" data-pw-sub="${esc(x.uid)}" aria-expanded="${!!x.open}" aria-label="${esc((x.open ? 'Fold ' : 'Open ') + x.title)}">${SVG(x.open ? P.down : P.right, 13)}</button>` : '';
241
- const more2 = (x.kids ? `<small class="pw-cnt">${esc(x.count)}</small>` : '') + PD.keyChip(x) + PD.epicDot(x, W.epics || []);
242
- return `<div class="pw-tr pw-kr${x.done ? ' done' : ''}${x.lit ? ' lit' : ''}${x.kids ? ' par' : ''}${RSEL.has(String(x.uid)) ? ' sel' : ''}" role="row" data-pw-row="${esc(x.uid)}" data-pw-sec="${esc(x.sec)}"${x.depth ? ` style="--pw-d:${x.depth}"` : ''}><span class="pw-it">${chev}<i class="pw-bul${x.ms ? ' ms' : ''}" aria-hidden="true"></i>${title}${more2}${RO ? '' : ib(`data-pw-open="${esc(x.uid)}"`, 'Open the task', P.open, 'xs hov') + ib(`data-pw-row-more="${esc(x.uid)}" aria-haspopup="menu"`, 'More for ' + x.title, P.more, 'xs hov')}</span>${stc}${dtc}${tl}</div>`
244
+ const more2 = (x.kids ? `<small class="pw-cnt">${esc(x.count)}</small>` : '') + (W.jc ? '' : PD.keyChip(x) + PD.epicDot(x, W.epics || []));
245
+ return `<div class="pw-tr pw-kr${x.done ? ' done' : ''}${x.lit ? ' lit' : ''}${x.kids ? ' par' : ''}${RSEL.has(String(x.uid)) ? ' sel' : ''}" role="row" data-pw-row="${esc(x.uid)}" data-pw-sec="${esc(x.sec)}"${x.depth ? ` style="--pw-d:${x.depth}"` : ''}><span class="pw-it">${chev}<i class="pw-bul${x.ms ? ' ms' : ''}" aria-hidden="true"></i>${title}${more2}${RO ? '' : ib(`data-pw-open="${esc(x.uid)}"`, 'Open the task', P.open, 'xs hov') + ib(`data-pw-row-more="${esc(x.uid)}" aria-haspopup="menu"`, 'More for ' + x.title, P.more, 'xs hov')}</span>${jc}${stc}${dtc}${tl}</div>`
243
246
  + (s ? `<div class="pw-tr pw-sugrow" role="row"><span class="pw-it">${sugLine(s, true)}</span></div>` : '');
244
247
  }
245
248
  function breakdownHtml(W, C, mode, full, S) {
@@ -261,7 +264,7 @@ function breakdownHtml(W, C, mode, full, S) {
261
264
  // the tasks in no stage are not in the breakdown (Wawan, 2026-11-19): they live in Work › Backlog; one quiet line says so and goes there
262
265
  const loose = W.looseN && !RO ? `<p class="pw-loose"><button type="button" class="pw-lk" data-pw-backlog>${esc(W.looseN === 1 ? '1 task with no stage is in the Backlog' : W.looseN + ' tasks with no stage are in the Backlog')}${SVG(P.right, 13)}</button></p>` : '';
263
266
  return `<section class="pw-sec" aria-label="Work breakdown">${full ? `<div class="pw-sech">${tools}</div>` : `<div class="pw-sech"><h3>Work breakdown</h3>${show}${tools}</div>`}`
264
- + `<div class="pw-card pw-wbs${C.tl ? '' : ' notl'}${C.status ? '' : ' nost'}${C.date ? '' : ' nodt'}" role="table" aria-label="Work breakdown"${tlStyle()}>${C.tl ? gripHtml() : ''}${headCells(C, W, mode)}${out || '<div class="pw-tr pw-empty" role="row"><span>No task yet.</span></div>'}</div>`
267
+ + `<div class="pw-card pw-wbs${C.tl ? '' : ' notl'}${C.status ? '' : ' nost'}${C.date ? '' : ' nodt'}${W.jc ? ' jc' : ''}" role="table" aria-label="Work breakdown"${tlStyle(W.jc ? gridOf(C) : '')}>${C.tl ? gripHtml() : ''}${headCells(C, W, mode)}${out || '<div class="pw-tr pw-empty" role="row"><span>No task yet.</span></div>'}</div>`
265
268
  + (C.tl ? '<p class="pw-key"><span><i class="k-tb pr"></i>In progress</span><span><i class="k-tb"></i>To do</span><span><i class="k-tb dn"></i>Done</span><span><i class="k-md"></i>Milestone</span><span><i class="k-late"></i>Late</span><span><i class="k-gap"></i>No activity</span></p>' : '') + loose + '</section>';
266
269
  }
267
270
  /* the Artefacts (round 3 point 16): one row per Kind, in lifecycle order. Kind | Artefact (the current one) | Version | Updated. Versions and the
@@ -305,6 +308,10 @@ function model(r, v, o) {
305
308
  const W = M.workOf(r, v, { ...o, goal: M.idShaped(g) ? '' : g, product: productName(o.product, o.ws), art: artOf(id, o.ws), open: S.open, shut: S.shut, moreOpen: S.moreOpen, farOpen: S.farOpen, focus: S.focus, subOpen: S.subOpen, subShut: S.subShut, mode: store.get(SPAN, 'full'), items: it || [], dropped: dropped() });
306
309
  const mk = M.marksOf(W.span, W.today); W.tx = mk.today;
307
310
  W.epics = (r.epics || []).filter(Boolean); RSEL = S.sel; // the epic check and the picked rows, for the Gantt rows (initiative work-subtasks)
311
+ // the Gantt's Jira column (work-subtasks-followups): on unless Choose columns hides it, and only when the work has a Jira row
312
+ W.jc = !!cols().jira && W.rows.some((x) => x.kind === 'task' && WT.keyOf(x));
313
+ // the Source filter (WorkJiraDS): the Gantt keeps the matching rows and the parents above them
314
+ if (S.src && S.src !== 'all') W.rows = WT.sourceKeep(W.rows, S.src, W.epics);
308
315
  return { W, S, id };
309
316
  }
310
317
  export function html(r, v, o = {}) {
@@ -331,16 +338,25 @@ function dsHtml(r, v, o, W, S, C, mode) {
331
338
  const st = stagesOf(r, v, { ...o, today: W.today, focus: S.focus, subOpen: S.subOpen, subShut: S.subShut }, S);
332
339
  // the epic check (WorkJiraDS): the initiative's epics, the ✦ fix unless the PM said no to it; ticking a parent asks once
333
340
  const epics = (r.epics || []).filter(Boolean), fix = dropped().has('epic:' + id) ? null : WT.epicFix(st, epics);
341
+ // the follow-ups (work-subtasks-followups): the Source filter and its counts, the ✦ grouping of a long stage, "Set epic…" in the bar
342
+ const cnt = WT.sourceCounts(st, epics), src = cnt.all && S.src ? S.src : 'all', stF = WT.sourceKeep(st, src, epics);
343
+ const group = src === 'all' ? WT.groupPlan(st, { dropped: groupDropped(id) })[0] || null : null;
344
+ const epicSel = S.sel.size > 0 && WT.allJira(stagesOf(r, v, { ...o, today: W.today, subAll: true }), S.sel);
345
+ const srcB = PD.sourceHtml(cnt, src);
334
346
  const askRow = S.tickAsk ? st.find((x) => x.uid === S.tickAsk) : null, ask = askRow ? { x: askRow, n: openUnder(stagesOf(r, v, { ...o, today: W.today, subAll: true }), askRow.uid).length } : null;
335
- const head = (vw) => PD.wbsHead(vw, epics[0] || '', epics[0] ? jiraUrlOf(st, epics[0]) : '');
347
+ const head = (vw) => PD.wbsHead(vw, epics[0] || '', epics[0] ? jiraUrlOf(st, epics[0]) : '').replace('<div class="pm-tabs"', srcB + '<div class="pm-tabs"');
336
348
  const wbs = view === 'gantt'
337
- ? breakdownHtml(W, C, mode, false, S).replace('<h3>Work breakdown</h3>', head('gantt') + (S.sel.size ? SEL.barHtml(S.sel.size) : '')).replace('class="pw-sec"', 'class="pw-sec pm-block pwd-blk pwd-wbs"')
338
- : `<section class="pm-block pwd-blk pwd-wbs" aria-label="Work breakdown">${S.sel.size ? '' : head('list')}${PD.listHtml(st, W, { looseN: W.looseN, epics, fix, ask, sel: S.sel, nested: st.some((x) => x.kids) })}</section>`;
349
+ ? breakdownHtml(W, C, mode, false, S).replace('<h3>Work breakdown</h3>', head('gantt') + (S.sel.size ? SEL.barHtml(S.sel.size, { epic: epicSel }) : '')).replace('class="pw-sec"', 'class="pw-sec pm-block pwd-blk pwd-wbs"')
350
+ : `<section class="pm-block pwd-blk pwd-wbs" aria-label="Work breakdown">${S.sel.size ? '' : head('list')}${PD.listHtml(stF, W, { looseN: W.looseN, epics, fix, ask, sel: S.sel, nested: st.some((x) => x.kids), drag: canDrag(), group, epicSel })}</section>`;
339
351
  const mg = mergeOf(W.artefacts), merge = mg ? `<div class="pw-sugs pw-amg" role="list" aria-label="PMOS suggests">${sugLine({ id: mg.id, say: mg.say, merge: mg })}</div>` : '';
340
352
  return `<div class="pw pwd">${'<div class="pwd-main">'}${PD.standsHtml(W, r)}${PD.stagesHtml(st, W)}${wbs}</div>`
341
353
  + `<aside class="pwd-side">${PD.caseHtml(W, { oid: id, dropped: dropped() })}${PD.artsHtml(W.artefacts, { merge })}</aside></div>`;
342
354
  }
343
355
 
356
+ /** The grouping ✦ the PM said no to, for this initiative: 'group:<stage>'. */
357
+ const groupDropped = (id) => { const pre = 'group:' + id + ':'; return new Set([...dropped()].filter((k) => k.startsWith(pre)).map((k) => 'group:' + k.slice(pre.length))); };
358
+ /** Drag with a mouse (work-subtasks-followups); a touch screen selects by press and hold instead. */
359
+ const canDrag = () => !RO && typeof matchMedia === 'function' && matchMedia('(hover: hover) and (pointer: fine)').matches;
344
360
  /** The open rows under a parent, at any depth (a parent ticked asks to tick them too). */
345
361
  /** A tick on a parent with open subtasks: ask once (true), else write the tick (false). */
346
362
  function askKids(c, x, W, S, uid) {
@@ -405,7 +421,7 @@ function phTask(x) {
405
421
  const meta = [x.ms ? `${SVG(P.dia, 12)}<span>Milestone</span>` : `${SVG(P.box, 12)}`, x.who ? esc(x.who) : '', x.date ? (x.late ? `<em>${esc(x.date)}</em>` : esc(x.date)) : '', x.done ? 'done' : '']
406
422
  .filter(Boolean).join('<i aria-hidden="true">·</i>').replace(/^(<svg[^]*?<\/svg>)<i aria-hidden="true">·<\/i>/, '$1');
407
423
  const chip = x.ckey ? `<span class="pm-chip pw-pkey">${esc(x.ckey)}</span>` : '';
408
- return `<li class="pw-ptk2${x.done ? ' done' : ''}"${x.depth ? ` style="--pw-d:${Math.min(x.depth, 3)}"` : ''}>${mark}<div class="pw-ptx"><button type="button" class="pw-tt" data-pw-open="${esc(x.uid)}">${esc(x.title)}</button><small class="pw-pm">${meta}${chip}</small></div></li>`;
424
+ return `<li class="pw-ptk2${x.done ? ' done' : ''}${RSEL.has(String(x.uid)) ? ' sel' : ''}" data-pw-row="${esc(x.uid)}"${x.depth ? ` style="--pw-d:${Math.min(x.depth, 3)}"` : ''}>${mark}<div class="pw-ptx"><button type="button" class="pw-tt" data-pw-open="${esc(x.uid)}">${esc(x.title)}</button><small class="pw-pm">${meta}${chip}</small></div></li>`;
409
425
  }
410
426
  function phoneHtml(W, S, oid, v) {
411
427
  const st = (v && v.stage) || {}, dr = dropped(), PT = phoneParts(W);
@@ -439,7 +455,9 @@ function phoneHtml(W, S, oid, v) {
439
455
  }
440
456
  const others = PT.others.length ? `<button type="button" class="pw-pfold" data-pw-phall aria-expanded="${all}"><b>${esc(PT.others.map((x) => x.name).join(', '))}</b><span>${esc(all ? 'tap to fold' : 'tap to open')}</span>${SVG(all ? P.down : P.right, 13)}</button>${all ? `<ul class="pw-pwbs2">${rest}</ul>` : ''}` : '';
441
457
  const loose = W.looseN ? `<p class="pw-loose"><button type="button" class="pw-lk" data-pw-backlog>${esc(W.looseN === 1 ? '1 task with no stage is in the Backlog' : W.looseN + ' tasks with no stage are in the Backlog')}${SVG(P.right, 13)}</button></p>` : '';
442
- const wbs = `<section class="pw-psec" aria-label="Work breakdown"><h4>Work breakdown${PT.now ? ' · ' + esc(PT.now.name) : ''}</h4>${nowList}${others}${loose}</section>`;
458
+ // press and hold a row to select it, then tap more (WorkBulkDS); the bar takes the heading's place while rows are picked
459
+ const pbar = S.sel.size ? SEL.barHtml(S.sel.size, { epic: WT.allJira(W.rows, S.sel) }) : '';
460
+ const wbs = `<section class="pw-psec" aria-label="Work breakdown">${pbar || `<h4>Work breakdown${PT.now ? ' · ' + esc(PT.now.name) : ''}</h4>`}${nowList}${others}${loose}</section>`;
443
461
  // the case: the lines that are written (Problem, Solution, Expected, Check …), each changeable where the popup lets it be
444
462
  const lines = ov.lines.filter((L) => L.text);
445
463
  const kase = lines.length ? `<section class="pw-psec" aria-label="The case"><h4>The case</h4><dl class="pw-pcase">${lines.map((L) => `<dt>${esc(L.k)}</dt><dd>${L.edit ? `<span class="pw-otx" data-pw-line="${esc(L.id)}" tabindex="0" role="button" aria-label="${esc('Change the ' + L.k.toLowerCase())}">${esc(L.text)}</span>` : esc(L.text)}${L.serves ? ' ' + esc(L.serves) : ''}</dd>`).join('')}</dl></section>` : '';
@@ -448,7 +466,6 @@ function phoneHtml(W, S, oid, v) {
448
466
  const artH = arts.length || mg ? `<section class="pw-psec" aria-label="Artefacts"><h4>Artefacts · ${esc(arts.length)}</h4>${mg ? `<div class="pw-psugs" role="list">${phSug(mg.id, mg.say, `data-pw-keep="${esc(mg.id)}"`, `data-pw-drop="${esc(mg.id)}"`, `data-pw-sug="${esc(mg.id)}"`)}</div>` : ''}`
449
467
  + `<ul class="pw-parts2">${W.artefacts.map((a, i) => (a.missing ? '' : `<li><button type="button" class="pw-an2" data-pw-art="${i}">${SVG(artIc(a), 16)}<span><b>${esc(a.title)}</b><small>${esc([a.kindName || a.kind || '', a.when || ''].filter(Boolean).join(' · '))}</small></span></button></li>`)).join('')}</ul></section>` : '';
450
468
  const ask = `<form class="pw-pask" data-pw-pask><input type="text" maxlength="500" placeholder="Ask PMOS about this work" aria-label="Ask PMOS about this work" autocomplete="off"><button type="submit" aria-label="Send" title="Send">${SVG('M12 19V5M6 11l6-6 6 6', 16, 2)}</button></form>`;
451
- void S;
452
469
  return `<div class="pw pw-ph">${gate}${stands}${strip}${wbs}${kase}${artH}${ask}</div>`;
453
470
  }
454
471
 
@@ -579,8 +596,11 @@ export function wire(body, h0, x0) {
579
596
  });
580
597
  const live = (e) => !!body.__pwx && !!e.target.closest('.pw') && !e.target.closest('.pw-sp, [data-pw-level]');
581
598
  body.addEventListener('scroll', () => { if (!body.querySelector(':scope > .pw, .pw:not(.pw-sp)')) return; const c = cur(); if (c) c.S.top = body.scrollTop; }, { passive: true });
599
+ wireMoves(body, cur, redraw); // drag to nest, press and hold, Gantt bars (work-subtasks-followups)
582
600
  body.addEventListener('click', async (e) => {
583
601
  if (!live(e)) return;
602
+ // the click that ends a press and hold or a bar drag is not a press of its own
603
+ if (body.__pwQuiet && Date.now() - body.__pwQuiet < 700) { e.preventDefault(); e.stopPropagation(); body.__pwQuiet = 0; return; }
584
604
  // select several rows (WorkBulkDS): Cmd or Ctrl-click adds one, Shift-click a range; with rows picked, a click adds or takes out one
585
605
  { const rw = e.target.closest('[data-pw-row]'), c0 = rw && !e.target.closest('a, input, textarea, [data-pw-tick], [data-pw-sub], [data-pw-row-more], .acts') ? cur() : null;
586
606
  if (rw && c0 && !RO && (e.shiftKey || e.metaKey || e.ctrlKey || c0.S.sel.size)) {
@@ -634,6 +654,10 @@ export function wire(body, h0, x0) {
634
654
  if ('pwEpicFix' in d) { b.disabled = true; await epicFix(c, h, x); return; }
635
655
  if ('pwEpicDrop' in d) { const dd = dropped(); dd.add('epic:' + c.id); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
636
656
  if (d.wsOp) { await bulkPress(b, d.wsOp, c, h, x); return; }
657
+ // the follow-ups (work-subtasks-followups): the Source filter, the ✦ grouping (✓ makes the parents, ✕ hides it)
658
+ if ('pwSrcMenu' in d) { srcMenu(b, c, x, h); return; }
659
+ if (d.pwGroup) { b.disabled = true; await applyGroup(b, c, h, x); return; }
660
+ if (d.pwGroupDrop) { const dd = dropped(); dd.add('group:' + c.id + ':' + d.pwGroupDrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
637
661
  if (d.pwWho) { whoMenu(b, d.pwWho, c, h, x); return; }
638
662
  if (d.pwStage) { stageMenu(b, d.pwStage, c, h, x); return; }
639
663
  if ('pwAddty' in d) { S.msAdd = !S.msAdd; const f = b.closest('.pw-add'), k = f && f.querySelector('[data-pw-add]') && f.querySelector('[data-pw-add]').dataset.pwAdd; redraw(); if (k != null) setTimeout(() => { const i = body.querySelector(`[data-pw-add="${window.CSS.escape(k)}"]`); if (i) i.focus(); }, 0); return; }
@@ -928,7 +952,167 @@ async function bulkPress(btn, op, c, h, x) {
928
952
  if (n == null) return;
929
953
  closePop(); await runBulk(ids, 'shift', n, c, h, x);
930
954
  }, { label: 'Move dates' });
955
+ return;
956
+ }
957
+ // "Set epic…" (WorkJiraDS): only in the bar when every picked row is a Jira ticket
958
+ if (op === 'epic') epicMenu(btn, ids, c, h, x);
959
+ }
960
+ async function setEpic(ids, epic, c, h, x) {
961
+ const o = (x && x.o && x.o()) || {}, at = atOf(h, x);
962
+ const st = stagesOf(c.r, c.v, { ...o, today: c.W.today, subAll: true });
963
+ const tickets = ids.map((u) => st.find((q) => String(q.uid) === String(u))).filter((r) => r && WT.keyOf(r) && !r.jsub).map((r) => ({ key: WT.keyOf(r), from: r.jepic || '', who: r.jassignee || '' }));
964
+ const say = (m, u) => (u ? undoToast(m, u) : h.toast ? h.toast(m) : undoToast(m));
965
+ if (!tickets.length) { say('Only a Jira ticket has an epic.'); return; }
966
+ c.S.sel.clear(); c.S.anchor = '';
967
+ moveLog('set-epic', tickets.length);
968
+ const r = await pmPost('/api/jira-epics/fix', { ws: at.ws, ini: at.ini, epic, tickets }).catch(() => null);
969
+ if (!r || r.ok === false) { say((r && r.error) || 'The epic was not asked.'); if (h.redraw) h.redraw(); return; }
970
+ const words = [r.direct.length ? (r.direct.length === 1 ? r.direct[0] + ' moves' : r.direct.length + ' tickets move') + ' under ' + epic + ' in Jira now.' : '',
971
+ r.draft.length ? (r.draft.length === 1 ? r.draft[0].key + ' is' : r.draft.length + ' tickets are') + ' in today\'s Jira draft for ' + [...new Set(r.draft.map((q) => q.who || 'their owner'))].join(', ') + '.' : ''].filter(Boolean).join(' ');
972
+ say(words, async () => { const u = await pmPost('/api/jira-epics/undo', { ws: at.ws, ids: r.ids }).catch(() => null); say(u && u.kept && u.kept.length ? 'Put back, except ' + u.kept.join(', ') + ': Jira already has it.' : 'Put back.'); if (h.redraw) h.redraw(); });
973
+ if (h.redraw) h.redraw();
974
+ }
975
+ /* ── the follow-ups (initiative work-subtasks-followups; WorkSubtasksDS, WorkBulkDS, WorkJiraDS) ── */
976
+ /** One line in the browser's log per move (the record's health_log): which way it came and how many tasks. No title, no name. */
977
+ const moveLog = (how, n) => { try { console.info('[work-move]', how, n); } catch { /* no console */ } };
978
+ /** Source: All · In Jira · Only in PMOS · Epic to fix, each with its count. The choice holds for this initiative while the page is open. */
979
+ function srcMenu(btn, c, x, h) {
980
+ const st = stagesOf(c.r, c.v, { ...((x && x.o && x.o()) || {}), today: c.W.today, subAll: true }), L = PD.sourceItems(WT.sourceCounts(st, (c.r.epics || []).filter(Boolean)), c.S.src || 'all');
981
+ openPop(btn, 'pw-src', L.map((s, i) => `<button type="button" class="hi-mi" role="menuitemradio" aria-checked="${s.on}" data-i="${i}">${esc(s.label)}${s.k === 'all' ? '' : ` <span class="hi-small">${esc(s.n)}</span>`}</button>`).join(''), (b) => {
982
+ const s = L[+b.dataset.i]; closePop(); if (!s) return; c.S.src = s.k; c.S.sel.clear(); if (h.redraw) h.redraw();
983
+ }, { menu: true, label: 'Source', focus: '[aria-checked="true"]' });
984
+ }
985
+ /** "Set epic…" (WorkJiraDS): every picked row is a Jira ticket. The initiative's epics, or a key typed in. Tickets assigned to the PM change in
986
+ * Jira at once, the rest go to the day's Jira draft for their owners (POST /api/jira-epics/fix, the same path as the ✦ epic fix); Undo
987
+ * withdraws what Jira has not done yet (POST /api/jira-epics/undo). */
988
+ function epicMenu(btn, ids, c, h, x) {
989
+ const epics = (c.r.epics || []).filter(Boolean);
990
+ openPop(btn, 'pw-bepic', `<p class="hi-small">${esc('Put ' + (ids.length === 1 ? 'it' : ids.length + ' tickets') + ' under')}</p>`
991
+ + epics.map((k, i) => `<button type="button" class="hi-mi" role="menuitem" data-i="${i}">${esc(k)}${i === 0 ? ' <span class="hi-small">this initiative\'s epic</span>' : ''}</button>`).join('')
992
+ + `<label class="hi-small" for="pw-bepic-in">Or another epic's key</label><input id="pw-bepic-in" class="pm-input" data-bepic maxlength="40" autocomplete="off" placeholder="IDPF-2600"><div class="pm-row"><button type="button" class="pm-btn primary" data-go aria-label="Set the epic" title="Set the epic">${SVG(P.check, 14)}</button></div>`, async (b) => {
993
+ let k = b.dataset.i != null ? epics[+b.dataset.i] : null;
994
+ if ('go' in b.dataset) { const i = document.querySelector('[data-bepic]'); k = i ? i.value.trim().toUpperCase() : ''; if (!/^[A-Z][A-Z0-9_]{0,30}-\d{1,9}$/.test(k)) return; }
995
+ if (!k) return;
996
+ closePop(); await setEpic(ids, k, c, h, x);
997
+ }, { label: 'Set epic', focus: '[data-i="0"], [data-bepic]' });
998
+ }
999
+ /** The ✦ grouping, on the PM's yes only: make each batch's parent in the stage, then move its tasks under it. One Undo moves them back
1000
+ * and takes the parents out again (POST /api/boards/tasks/bulk-undo, then /api/boards/tasks/undo-add). */
1001
+ async function applyGroup(btn, c, h, x) {
1002
+ const stage = btn.dataset.pwGroup, o = (x && x.o && x.o()) || {}, at = atOf(h, x);
1003
+ const st = stagesOf(c.r, c.v, { ...o, today: c.W.today, subAll: true }), g = WT.groupPlan(st, { dropped: groupDropped(c.id) }).find((q) => q.stage === stage);
1004
+ const say = (m, u) => (u ? undoToast(m, u) : h.toast ? h.toast(m) : undoToast(m));
1005
+ if (!g) { if (h.redraw) h.redraw(); return; }
1006
+ const made = [], runs = [];
1007
+ for (const b of g.groups) {
1008
+ const r = await pmPost('/api/boards/tasks/add', { ws: at.ws, board: at.board, initiative: at.ini, title: b.name, section: stage }).catch(() => null);
1009
+ if (!r || r.ok === false || !r.item) continue;
1010
+ made.push(r.item.uid);
1011
+ const m = await SEL.bulk(pmPost, { ws: at.ws, board: at.board }, b.uids, 'parent', r.item.uid, {}, b.name).catch(() => null);
1012
+ if (m && m.runs) runs.push(...m.runs);
1013
+ c.S.subOpen.delete(r.item.uid);
931
1014
  }
1015
+ const n = runs.reduce((k, d) => k + d.undo.length, 0);
1016
+ moveLog('group', n);
1017
+ if (!made.length) { say('The batches were not made.'); if (h.reload) await h.reload(); return; }
1018
+ say(`${n === 1 ? '1 task' : n + ' tasks'} grouped into ${made.length === 1 ? '1 batch' : made.length + ' batches'}.`, async () => {
1019
+ for (const d of runs.slice().reverse()) await pmPost('/api/boards/tasks/bulk-undo', { ws: d.ws, board: d.board, undo: d.undo }).catch(() => null);
1020
+ for (const u of made) await pmPost('/api/boards/tasks/undo-add', { ws: at.ws, board: at.board, task: u }).catch(() => null);
1021
+ say('Put back.'); if (h.reload) await h.reload();
1022
+ });
1023
+ if (h.reload) await h.reload();
1024
+ }
1025
+ /* Drag to nest (WorkSubtasksDS: "Drag a task onto another to nest it; drag it left to take it out"), dragging every picked row (WorkBulkDS),
1026
+ * press and hold on a touch screen, and the Gantt's bars dragged by whole days ("dragging one bar shifts every selected bar by the same days").
1027
+ * Every write goes through the bulk move and its one Undo. */
1028
+ function wireMoves(body, cur, redraw) {
1029
+ if (RO || body.__pwMoves) return; body.__pwMoves = true;
1030
+ const say = (h) => (m, u) => (u ? undoToast(m, u) : h.toast ? h.toast(m) : undoToast(m));
1031
+ const allOf = (c) => stagesOf(c.r, c.v, { ...((body.__pwx && body.__pwx.o()) || {}), today: c.W.today, subAll: true });
1032
+ const reload = (h) => async () => { if (h.reload) await h.reload(); else if (h.redraw) h.redraw(); };
1033
+ // the List: HTML drag and drop (a mouse); onto a row nests, its top or bottom edge is between rows, a stage head is the stage, left is out
1034
+ let DR = null;
1035
+ const marks = () => body.querySelectorAll('.drop-on, .drop-before, .drop-after, .drop-left, .dragging').forEach((el) => el.classList.remove('drop-on', 'drop-before', 'drop-after', 'drop-left', 'dragging'));
1036
+ const zoneOf = (e) => {
1037
+ // a stage head (its fold press carries the stage key, its name is the bold text)
1038
+ const sh = e.target.closest && e.target.closest('.pwd-gh[data-pw-fold]');
1039
+ if (sh) return { el: sh, cls: 'drop-on', to: { zone: 'stage', key: sh.dataset.pwFold, name: (sh.querySelector('b') || {}).textContent || '' } };
1040
+ const rw = e.target.closest && e.target.closest('.pwd-li[data-pw-row]'); if (!rw) return null;
1041
+ const u = rw.dataset.pwRow;
1042
+ if (DR.ids.includes(u)) return e.clientX - DR.x0 < -32 ? { el: rw, cls: 'drop-left', to: { zone: 'left' } } : null;
1043
+ const r = rw.getBoundingClientRect(), y = (e.clientY - r.top) / Math.max(1, r.height);
1044
+ return y < 0.25 ? { el: rw, cls: 'drop-before', to: { zone: 'between', uid: u } } : y > 0.75 ? { el: rw, cls: 'drop-after', to: { zone: 'between', uid: u } } : { el: rw, cls: 'drop-on', to: { zone: 'on', uid: u } };
1045
+ };
1046
+ body.addEventListener('dragstart', (e) => {
1047
+ const rw = e.target.closest && e.target.closest('.pwd-li[draggable="true"]'); if (!rw) return;
1048
+ const c = cur(); if (!c) return;
1049
+ DR = { ids: SEL.dragIds(c.S.sel, rw.dataset.pwRow), x0: e.clientX };
1050
+ try { e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', DR.ids.join(',')); } catch { /* an old browser */ }
1051
+ for (const u of DR.ids) { const el = body.querySelector(`.pwd-li[data-pw-row="${window.CSS.escape(u)}"]`); if (el) el.classList.add('dragging'); }
1052
+ });
1053
+ body.addEventListener('dragover', (e) => {
1054
+ if (!DR) return; const z = zoneOf(e);
1055
+ body.querySelectorAll('.drop-on, .drop-before, .drop-after, .drop-left').forEach((el) => el.classList.remove('drop-on', 'drop-before', 'drop-after', 'drop-left'));
1056
+ if (!z) return; e.preventDefault(); z.el.classList.add(z.cls);
1057
+ });
1058
+ body.addEventListener('dragend', () => { DR = null; marks(); });
1059
+ body.addEventListener('drop', async (e) => {
1060
+ if (!DR) return; const z = zoneOf(e), ids = DR.ids; DR = null; marks();
1061
+ if (!z) return; e.preventDefault();
1062
+ const c = cur(), h = body.__pwh; if (!c || !h) return;
1063
+ const plan = SEL.dropPlan(allOf(c), ids, z.to); if (!plan) return;
1064
+ const at = atOf(h, body.__pwx);
1065
+ if (z.to.zone === 'on') { c.S.subOpen.add(z.to.uid); c.S.subShut.delete(z.to.uid); }
1066
+ c.S.sel.clear(); c.S.anchor = '';
1067
+ moveLog('drag-' + z.to.zone, ids.length);
1068
+ await SEL.bulkSteps(pmPost, { ws: at.ws, board: at.board }, plan.steps, { say: say(h), reload: reload(h) }, plan.label);
1069
+ });
1070
+ // press and hold (a touch screen): the row is picked; after that a tap adds or takes out one row (the click handler's pick)
1071
+ let HOLD = null;
1072
+ const stopHold = () => { if (HOLD) { clearTimeout(HOLD.t); HOLD = null; } };
1073
+ const held = (rw, m) => {
1074
+ HOLD = null; const c = cur(); if (!c) return;
1075
+ const order = [...body.querySelectorAll('[data-pw-row]')].map((el) => el.dataset.pwRow);
1076
+ const pk = SEL.pick(c.S.sel, order, rw.dataset.pwRow, { ...m, anchor: c.S.anchor });
1077
+ if (!pk) return;
1078
+ c.S.sel = pk.sel; c.S.anchor = pk.anchor; body.__pwQuiet = Date.now();
1079
+ if (navigator.vibrate) { try { navigator.vibrate(10); } catch { /* not allowed */ } }
1080
+ redraw();
1081
+ };
1082
+ body.addEventListener('pointerdown', (e) => {
1083
+ if (e.pointerType !== 'touch' && e.pointerType !== 'pen') return;
1084
+ const rw = e.target.closest && e.target.closest('[data-pw-row]'); if (!rw || e.target.closest('input, textarea, .acts, [data-pw-row-more]')) return;
1085
+ stopHold(); HOLD = { x: e.clientX, y: e.clientY, t: setTimeout(() => held(rw, { touch: true }), 500) };
1086
+ }, { passive: true });
1087
+ body.addEventListener('pointermove', (e) => { if (HOLD && Math.hypot(e.clientX - HOLD.x, e.clientY - HOLD.y) > 10) stopHold(); }, { passive: true });
1088
+ body.addEventListener('pointerup', stopHold, { passive: true });
1089
+ body.addEventListener('pointercancel', stopHold, { passive: true });
1090
+ body.addEventListener('contextmenu', (e) => { if (body.__pwQuiet && Date.now() - body.__pwQuiet < 700 && e.target.closest && e.target.closest('[data-pw-row]')) e.preventDefault(); });
1091
+ // the Gantt: a task's bar (or a parent's) dragged by a mouse moves by whole days; a picked row's bar moves every picked row
1092
+ body.addEventListener('pointerdown', (e) => {
1093
+ if (e.pointerType !== 'mouse' || e.button !== 0) return;
1094
+ const bar = e.target.closest && e.target.closest('.pw-kr .pw-tl .iva-tb, .pw-kr .pw-tl .pw-pbar'); if (!bar) return;
1095
+ const rw = bar.closest('[data-pw-row]'), tl = bar.closest('.pw-tl'), c = cur(); if (!rw || !tl || !c) return;
1096
+ const all = allOf(c), ids = SEL.shiftIds(c.S.sel, rw.dataset.pwRow, all);
1097
+ const span = (Date.parse(c.W.span.b) - Date.parse(c.W.span.a)) / 864e5, w = tl.getBoundingClientRect().width, x0 = e.clientX;
1098
+ const els = [...new Set(ids.concat(String(rw.dataset.pwRow)))].map((u) => body.querySelector(`.pw-kr[data-pw-row="${window.CSS.escape(u)}"] .pw-tl`)).filter(Boolean)
1099
+ .flatMap((t2) => [...t2.querySelectorAll('.iva-tb, .pw-pbar, .iva-md')]);
1100
+ let dx = 0;
1101
+ e.preventDefault(); try { bar.setPointerCapture(e.pointerId); } catch { /* fine */ }
1102
+ document.body.classList.add('pw-drag');
1103
+ const mv = (ev) => { dx = ev.clientX - x0; const n = SEL.daysOf(dx, w, span), px = (n / Math.max(1, span)) * w; for (const el of els) el.style.transform = `translateX(${px.toFixed(1)}px)`; };
1104
+ const up = async () => {
1105
+ bar.removeEventListener('pointermove', mv); bar.removeEventListener('pointerup', up); bar.removeEventListener('pointercancel', up);
1106
+ document.body.classList.remove('pw-drag');
1107
+ const n = SEL.daysOf(dx, w, span);
1108
+ if (Math.abs(dx) > 3) body.__pwQuiet = Date.now();
1109
+ if (!n) { for (const el of els) el.style.transform = ''; return; }
1110
+ const h = body.__pwh; if (!h) return;
1111
+ moveLog('bar-shift', ids.length);
1112
+ await runBulk(ids, 'shift', n, c, h, body.__pwx); // a Jira ticket with no dates in PMOS is skipped, with the reason
1113
+ };
1114
+ bar.addEventListener('pointermove', mv); bar.addEventListener('pointerup', up); bar.addEventListener('pointercancel', up);
1115
+ });
932
1116
  }
933
1117
  /** The epic check's ✦ fix (WorkJiraDS): every flagged ticket goes under the initiative's epic; Undo withdraws what Jira has not done yet. */
934
1118
  async function epicFix(c, h, x) {
@@ -1023,7 +1207,7 @@ function spanMenu(btn, redraw) {
1023
1207
  }
1024
1208
  function tuneMenu(btn, which, redraw) {
1025
1209
  const C = cols();
1026
- const L = which === 'art' ? [['when', 'Updated']] : [['status', 'Status'], ['date', 'Date'], ['tl', 'Timeline, on the right']];
1210
+ const L = which === 'art' ? [['when', 'Updated']] : [['jira', 'Jira'], ['status', 'Status'], ['date', 'Date'], ['tl', 'Timeline, on the right']];
1027
1211
  openPop(btn, 'pw-tune', `<p class="hi-h3">${which === 'art' ? 'Kind and Artefact always show' : 'Item always shows'}</p>` + L.map(([k, l]) => `<button type="button" class="hi-mi pw-sw" role="menuitemcheckbox" aria-checked="${!!C[k]}" data-col="${k}"><span>${esc(l)}</span><i aria-hidden="true"></i></button>`).join('')
1028
1212
  + '<button type="button" class="hi-mi" data-reset>Reset</button>', (b) => {
1029
1213
  if (b.dataset.col) { const n = { ...cols(), [b.dataset.col]: !cols()[b.dataset.col] }; store.set(COLS, n); b.setAttribute('aria-checked', String(!!n[b.dataset.col])); redraw(); return; }
@@ -80,20 +80,63 @@ export function jobHtml(J, now = Date.now()) {
80
80
  return `<div class="rp-w"><div class="rp-main">${main}${msg}</div>${box}</div>`;
81
81
  }
82
82
 
83
- /** + a new routine (round 3 item 4): an empty setup on the left; PMOS asks "What should repeat?" on the right and fills it from the answer. Pure. */
84
- export function newHtml() {
85
- const rows = [kv('On', sw(false, 'Off until PMOS has filled it in', true)), kv('Repeats', em('From your answer')), kv('Tells', em('From your answer')), kv('After the run', em('From your answer'))];
86
- const main = `<section class="rj-sec" aria-label="Instruction"><h6>Instruction</h6><p class="rj-txt">Tell PMOS on the right what should repeat, how often, and who it tells. PMOS fills in the setup and the instruction, and asks you once before it starts.</p>`
87
- + `<p class="rj-hint">For example: “Every Friday at 16:00, sum up the week for me.”</p></section>`;
88
- return `<div class="rp-w"><div class="rp-main">${main}</div><aside class="rp-box" aria-label="Setup"><h6>Setup</h6>${rows.join('')}</aside></div>`;
83
+ /** + a new routine (round 3 item 4; bet A144 routine-from-sentence): the PM says it in one sentence on the left, and the Setup box fills from it as
84
+ * it is typed (POST /api/routine-sentence, which only reads). One press (rtSaySet) sets it up; the chat on the right stays for the rest. Pure.
85
+ * N = { text, got: { ok, read: { words, notes }, next } | { ok: false, ask }, busy, msg } */
86
+ export function newHtml(N = {}) {
87
+ const got = N.got || null, sure = !!(got && got.ok && got.read), w = sure ? got.read.words : null;
88
+ const rows = sure
89
+ ? [kv('Repeats', em(w.when, w.when)), kv('First run', em(when(got.next) || w.when)), kv('Does', em(w.does, w.does)), kv('Tells', em(w.tells))]
90
+ : [kv('On', sw(false, 'Off until PMOS has filled it in', true)), kv('Repeats', em('From your sentence')), kv('Does', em('From your sentence')), kv('Tells', em('Nobody. PMOS drafts it; you send it.'))];
91
+ const notes = sure && got.read.notes && got.read.notes.length ? `<p>${esc(got.read.notes.join(' '))}</p>` : '';
92
+ const said = got && !got.ok && got.ask && String(N.text || '').trim() ? `<p class="rj-hint" role="status">${esc(got.ask)}</p>` : '';
93
+ const main = `<section class="rj-sec" aria-label="Instruction"><h6>Say it in one sentence</h6>`
94
+ + `<label class="vh" for="rjSay">What should repeat, and when</label><textarea id="rjSay" class="rj-ins" data-rj="say" rows="3" maxlength="600" placeholder="Every Monday at 9am, sum up the top 3 risks for the team">${esc(N.text || '')}</textarea>`
95
+ + `<div class="rj-act"><button type="button" id="rtSaySet" class="rp-y" data-rj="set" aria-label="Set it up" title="Set it up"${sure && !N.busy ? '' : ' disabled'}>${svg(ICON.check, 14)}</button>`
96
+ + `<span class="rj-hint">${esc(sure ? 'Check the setup on the right, then set it up.' : 'PMOS reads when it repeats and what to do. Or tell PMOS on the right.')}</span></div>${said}`
97
+ + `<p class="rp-msg" role="status">${esc(N.msg || '')}</p></section>`;
98
+ return `<div class="rp-w"><div class="rp-main">${main}</div><aside class="rp-box" aria-label="Setup"><h6>Setup</h6>${rows.join('')}${notes}</aside></div>`;
89
99
  }
90
100
  /** Open + in the popup, with Ask PMOS open on "What should repeat?" (the one popup that opens with the chat shown). */
91
101
  export function openNew(h, target) {
92
102
  // the same chip ("In: New routine") and empty line as every popup (design check item 2); the box asks the question
93
103
  const t = { ...target, placeholder: 'What should repeat?', context: 'Routine · a new routine: ask what should repeat, how often and who it tells' };
104
+ const N = { text: '', got: null, busy: false, msg: '' };
105
+ let body = null, timer = null, seq = 0;
106
+ const http = h.http || {}, ws = () => h.ws || undefined;
107
+ const draw = () => {
108
+ if (!body || !body.isConnected) return;
109
+ const ta = body.querySelector('#rjSay'), had = ta && document.activeElement === ta, pos = ta ? ta.selectionStart : 0;
110
+ body.innerHTML = newHtml(N);
111
+ if (had) { const x = body.querySelector('#rjSay'); if (x) { x.focus(); x.setSelectionRange(pos, pos); } }
112
+ };
113
+ const readNow = async () => {
114
+ const mine = ++seq, text = N.text;
115
+ if (!String(text).trim()) { N.got = null; draw(); return; }
116
+ const r = await Promise.resolve(http.pmPost ? http.pmPost('/api/routine-sentence', { ws: ws(), text }) : null).catch(() => null);
117
+ if (mine !== seq) return; // a newer keystroke has its own read
118
+ N.got = r || { ok: false, ask: 'PMOS could not read it just now. Try again.' }; N.readFor = text; draw();
119
+ };
120
+ const set = async () => {
121
+ if (N.busy || !(N.got && N.got.ok)) return;
122
+ if (N.readFor !== N.text) { clearTimeout(timer); readNow(); return; } // the setup shown must be the one for these words
123
+ N.busy = true; N.msg = ''; draw();
124
+ const r = await Promise.resolve(http.pmPost('/api/routine-sentence', { ws: ws(), text: N.text, set: true })).catch(() => null);
125
+ N.busy = false;
126
+ if (!r || !r.ok) { N.msg = 'Nothing changed: ' + ((r && (r.ask || r.error)) || 'the server did not answer') + '.'; draw(); return; }
127
+ if (h.VW.closePop) h.VW.closePop();
128
+ if (h.reload) await h.reload();
129
+ if (h.toast) h.toast('Set up. ' + (r.read && r.read.words ? r.read.words.when : '') + (r.schedule && r.schedule.nextRun ? '. First run ' + when(r.schedule.nextRun) + '.' : '.'));
130
+ };
94
131
  h.VW.open({ id: 'routine:new', kind: 'New routine', from: 'Routine', kindChip: 'New routine', title: 'New routine', icon: 'gear',
95
132
  pop: { id: 'routine-new', kind: 'routine', title: 'New routine', target: t, chat: 'open' },
96
- render: (b) => { b.innerHTML = newHtml(); } });
133
+ render: (b) => {
134
+ body = b; draw();
135
+ if (b.__rjn) return; b.__rjn = true;
136
+ b.addEventListener('input', (e) => { if (e.target.dataset && e.target.dataset.rj === 'say') { N.text = e.target.value; N.msg = ''; N.got = N.got && N.got.ok ? N.got : null; clearTimeout(timer); timer = setTimeout(readNow, 350); } });
137
+ b.addEventListener('keydown', (e) => { if (e.target.dataset && e.target.dataset.rj === 'say' && e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); clearTimeout(timer); if (N.got && N.got.ok && N.readFor === N.text) set(); else readNow(); } });
138
+ b.addEventListener('click', (e) => { const x = e.target.closest('[data-rj="set"]'); if (x && !x.disabled) set(); });
139
+ } });
97
140
  }
98
141
 
99
142
  /* ── the popup ── */
@@ -164,3 +164,5 @@
164
164
  .rp-hold ol { margin: 0; padding-left: 20px; font-size: var(--fs-body); line-height: 1.5; }
165
165
  .rp-hold li { margin: 0 0 var(--space-4); color: var(--cz-ink2); }
166
166
  .rp-hold li b { font-weight: var(--fw-strong); color: var(--cz-ink); }
167
+ /* New routine from one sentence (bet A144): the question PMOS asks back when it cannot read the sentence */
168
+ .rj-sec > .rj-hint[role="status"] { margin-top: 6px; color: var(--cz-ink2); }
@@ -125,17 +125,33 @@ function general() {
125
125
  /* General › Extras › Use log (bet A466): what lib/use-log.js keeps for the last 30 days (GET /api/use-log), and Clear (POST /api/use-log/clear) */
126
126
  const UL_PAGE = { today: 'Today', premium: 'Home', 'premium-board': 'Work', 'premium-goals': 'Goals', 'premium-intelligence': 'Intelligence', 'premium-library': 'Library', 'premium-events': 'Events', 'premium-routine': 'Routine', 'premium-viewer': 'Viewer' };
127
127
  const ulPage = (p) => UL_PAGE[p] || p;
128
- async function loadUseLog() { const r = await pmGet('/api/use-log'); T.ul = r && r.ok ? r : { error: (r && r.error) || 'PMOS could not read the use log.' }; draw(); }
128
+ async function loadUseLog() {
129
+ const [r, h] = await Promise.all([pmGet('/api/use-log'), pmGet('/api/use-log/hidden')]);
130
+ T.ul = r && r.ok ? r : { error: (r && r.error) || 'PMOS could not read the use log.' };
131
+ T.uh = h && h.ok && Array.isArray(h.hidden) ? h.hidden : [];
132
+ draw();
133
+ }
134
+ /* Hidden buttons (idea A454): what PMOS hid after a Yes on its ✦ (lib/unused-controls.js). Each one comes back with Show, or all with Show all,
135
+ * so a hidden button is never lost. A button is named by its id, never its text. */
136
+ function hiddenSec() {
137
+ const H = T.uh || [];
138
+ if (!H.length) return '';
139
+ return '<h4 class="pm-h-sm">Hidden buttons</h4>'
140
+ + '<p class="ev-mut">PMOS hid these after you said yes, because you had not pressed them in 14 days. Show puts one back on its page.</p>'
141
+ + trow('All hidden buttons', `${H.length} hidden`, '<button type="button" class="ev-btn sm" data-ev-ucall>Show all</button>')
142
+ + `<ul class="ev-ul-list">${H.map((x) => `<li>${esc(x.control)} <span class="ev-mut">on ${esc(ulPage(x.page))}</span> <button type="button" class="ev-btn sm" data-ev-ucshow="${esc(x.page)} ${esc(x.control)}">Show</button></li>`).join('')}</ul>`;
143
+ }
129
144
  function useLogSec() {
130
145
  const U = T.ul, about = '<p class="ev-mut">PMOS notes which pages you open and which buttons you press, so it can see what is easy to use and what nobody uses. It keeps 30 days, it stays on this computer, and it is never sent anywhere. It keeps no text you type and no names.</p>';
131
146
  if (!U) return about + '<p class="ev-mut">Reading…</p>';
132
147
  if (U.error) return about + `<p class="ev-mut">${esc(U.error)}</p>`;
133
- if (!U.opens && !U.uses) return about + '<p class="ev-mut">Nothing yet.</p>';
148
+ if (!U.opens && !U.uses) return about + '<p class="ev-mut">Nothing yet.</p>' + hiddenSec();
134
149
  const list = (rows) => `<ul class="ev-ul-list">${rows.join('')}</ul>`;
135
150
  return about
136
151
  + trow('Last 30 days', `${U.days} ${U.days === 1 ? 'day' : 'days'} · ${U.opens} page ${U.opens === 1 ? 'open' : 'opens'} · ${U.uses} ${U.uses === 1 ? 'press' : 'presses'}`, '<button type="button" class="ev-btn sm" data-ev-ulclear>Clear</button>')
137
152
  + (U.pages.length ? '<h4 class="pm-h-sm">Pages you open most</h4>' + list(U.pages.map((x) => `<li>${esc(ulPage(x.page))} <span class="ev-mut">${x.n}</span></li>`)) : '')
138
- + (U.controls.length ? '<h4 class="pm-h-sm">Buttons you press most</h4>' + list(U.controls.map((x) => `<li>${esc(x.control)} <span class="ev-mut">on ${esc(ulPage(x.page))} · ${x.n}</span></li>`)) : '');
153
+ + (U.controls.length ? '<h4 class="pm-h-sm">Buttons you press most</h4>' + list(U.controls.map((x) => `<li>${esc(x.control)} <span class="ev-mut">on ${esc(ulPage(x.page))} · ${x.n}</span></li>`)) : '')
154
+ + hiddenSec();
139
155
  }
140
156
  /* Your role (initiative kind-scopes-lifecycle-stages): work.role, the kind a new initiative starts as when its name gives no cue */
141
157
  const roleVal = () => { const r = T.set && Array.isArray(T.set.settings) ? T.set.settings.find((x) => x.key === 'work.role') : null; return r && r.value ? r.value : 'product'; };
@@ -636,6 +652,8 @@ async function press(e) {
636
652
  if (await extClick(e, XT, draw, toast)) return;
637
653
  if (t.dataset.evWk) { const k = t.dataset.evWk; if (T.wkOpen.has(k)) T.wkOpen.delete(k); else T.wkOpen.add(k); draw(); return; }
638
654
  if ('evArc' in t.dataset) { T.arc = !T.arc; draw(); return; }
655
+ if ('evUcall' in t.dataset) { const r = await pmPost('/api/use-log/show', { all: true }); if (r && r.ok) { toast(r.shown === 1 ? '1 button is back on its page.' : `${r.shown} buttons are back on their pages.`); loadUseLog(); } else toast((r && r.error) || 'PMOS could not show the hidden buttons.'); return; }
656
+ if ('evUcshow' in t.dataset) { const [page, control] = t.dataset.evUcshow.split(' '); const r = await pmPost('/api/use-log/show', { page, controls: [control] }); if (r && r.ok) { toast(`Back on ${ulPage(page)}.`); loadUseLog(); } else toast((r && r.error) || 'PMOS could not show that button.'); return; }
639
657
  if ('evUlclear' in t.dataset) { const r = await pmPost('/api/use-log/clear', {}); if (r && r.ok) { T.ul = null; toast('Use log cleared.'); loadUseLog(); } else toast((r && r.error) || 'PMOS could not clear the use log.'); return; }
640
658
  if ('evInfo' in t.dataset) { T.info = !T.info; draw(); return; }
641
659
  if ('evFold' in t.dataset) { T.fold = !T.fold; draw(); return; }
@@ -156,6 +156,7 @@ button.td-ev:focus-visible { outline: none; box-shadow: var(--glow); }
156
156
  .tdp-f svg { right: var(--space-8); }
157
157
  .tdp-f select { color: var(--ink); min-height: 32px; padding: 0 22px 0 var(--space-8); text-align: left; }
158
158
  .tdp-none { padding: var(--space-16) 0; font-size: var(--fs-body); color: var(--muted); line-height: var(--lh-body); }
159
+ body.cz-vw-on .tdp-cap { display: none; } /* the Viewer covers Today on a phone: its box goes too, so it never sits under the Viewer's own controls */
159
160
  .tdp-cap { position: fixed; left: var(--space-12); right: var(--space-12); bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-12)); z-index: 30; display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4) var(--space-4) var(--space-4) var(--space-16); border-radius: var(--radius-pill); background: var(--well); box-shadow: var(--raise); }
160
161
  .tdp-in { flex: 1; min-width: 0; border: 0; background: none; font: inherit; font-size: var(--fs-field); color: var(--ink); padding: var(--space-8) 0; outline: none; }
161
162
  .tdp-in::placeholder { color: var(--muted); }
@@ -125,7 +125,7 @@
125
125
  .cz .vc .vc-seg button, .cz .sl-seg button, .cz .rt-seg .btn, .cz .vm .vm-mn button { border-radius: var(--radius-pill); }
126
126
  .cz .vm .vm-bx, .cz .vm .vm-none, .cz .vm .vm-part > summary.vm-sh, .cz .vn-q, .cz .vn-l, .cz .rvh, .cz .rvb, .cz .rvta, .cz .vc .vc-w, .cz .vc .vc-db, .cz .vc .vc-md, .cz .vc .vc-dn,
127
127
  .cz .rt-msg, .cz .rt-secs, .cz .rt-frame, .cz .rt-cyc li, .cz .sl-ctx, .cz .sl-b, .cz .sl-msg, .cz .sl-stage, .cz .sl-pbox, .cz .vwi .vwi-r, .cz .vbl .bl-s, .cz .vbl .bl-st,
128
- .cz .vwfnone, .cz .vwag, .cz .vwbefore, .cz .cf, .cz .pnl, .cz .dt, .cz .chk, .cz .xp, .cz .cb, .cz .vwmd, .cz .vwframe, .cz .vwshp, .cz .cpv-bar, .cz .cpv-empty, .cz .cpv-page { border-radius: 14px; }
128
+ .cz .vwfnone, .cz .vwag, .cz .vwbefore, .cz .cf, .cz .pnl, .cz .dt, .cz .chk, .cz .xp, .cz .cb, .cz .vwmd, .cz .vwframe, .cz .vwshp, .cz .cpv-bar, .cz .cpv-page { border-radius: 14px; }
129
129
  .cz .ntmenu, .cz .recm, .cz .rt-menu, .cz .sl-pop, .cz .vwpop { border-radius: var(--radius-card); background: var(--card-solid); border: 1px solid var(--hair); box-shadow: 0 24px 60px -24px rgba(42,46,53,.45); }
130
130
  .cz .ntmenu button, .cz .recm [role="menuitem"], .cz .rt-menu > button, .cz .sl-pop [role="menuitem"], .cz .vwpop button { border-radius: var(--radius-md); }
131
131
  .cz .vm .vm-agl i, .cz .vn-k, .cz .vbl .bl-p { border-radius: var(--radius-pill); }
@@ -126,8 +126,9 @@ const kindKey = (k) => String(k || 'item').trim().toLowerCase().replace(/^file
126
126
  * 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,
127
127
  * the listeners, the rail's card. Only the first instance (#czViewer) writes the browser history; another keeps its own ← → trail.
128
128
  * Without cozy-panels.js (Board, Intelligence) the limit stays 1 and there is one Viewer, as before. */
129
+ import { capture as capturePlace, restore as restorePlace } from './back-place.js'; // Back restores your place (A430)
129
130
  const G = { chat: null, subs: [], railKey: null, rail: false, lw: 0, tick: 0, limit: 1, beside: null, place: null, managed: null, popH: null, popNext: null };
130
- 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: '', pop: false });
131
+ const mk = (i) => ({ i, el: null, cur: null, back: null, stack: [], fwd: [], unplace: null, wide: false, w: 0, drill: false, over: false, used: 0, ph: false, via: '', pop: false });
131
132
  let V = mk(0);
132
133
  const ALL = [V];
133
134
  const shown = (x) => !!(x && x.el && !x.el.hidden && x.cur);
@@ -641,7 +642,7 @@ export function open(it) {
641
642
  if (!V.cur) { const ae = document.activeElement; V.back = ae && ae !== document.body && !el.contains(ae) ? ae : null; }
642
643
  const was = isOpen(), pos = V.stack.length, how = stepOf(o);
643
644
  if (how === 'nav') { V.stack = o._trail.stack; V.fwd = o._trail.fwd; }
644
- else if (how === 'drill') { V.stack.push(V.cur.args); V.fwd = []; hq({ push: 1, s: H.s, i: V.stack.length }); }
645
+ else if (how === 'drill') { keepPlace(); V.stack.push(V.cur.args); V.fwd = []; hq({ push: 1, s: H.s, i: V.stack.length }); }
645
646
  else if (how === 'new' && V.i) { V.stack = []; V.fwd = []; } // a second Viewer keeps its trail without the browser history
646
647
  else if (how === 'new') {
647
648
  // 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
@@ -659,12 +660,15 @@ export function open(it) {
659
660
  redraw();
660
661
  el.querySelectorAll('.cz-vw-menu,.cz-vw-trail').forEach((m) => m.remove());
661
662
  const body = el.querySelector('.cz-vw-body');
663
+ if (V.unplace) { V.unplace(); V.unplace = null; }
662
664
  body.innerHTML = ''; body.scrollTop = 0;
663
665
  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
664
666
  const wasHidden = el.hidden;
665
667
  el.hidden = false;
666
668
  if (!(sameKind && !wasHidden && (V.wide || G.rail))) { const k = widthOf(o.kind); V.wide = false; apply(k || room().def); redraw(); }
667
669
  if (typeof o.render === 'function') o.render(body); else if (o.html) body.innerHTML = o.html;
670
+ // a step back or forward comes back to the item's place (its scroll, its open sections), now and while its content arrives
671
+ if (how === 'nav' && o._place) V.unplace = restorePlace(body, o._place);
668
672
  emit();
669
673
  if (isPhone()) el.focus();
670
674
  return body;
@@ -694,6 +698,7 @@ export function close(o = {}) {
694
698
  V.via = o.quiet ? 'history' : '';
695
699
  V.stack = []; V.fwd = []; V.wide = false; V.drill = false;
696
700
  if (V.over) { V.over = false; document.body.classList.remove('cz-vw-over'); }
701
+ if (V.unplace) { V.unplace(); V.unplace = null; }
697
702
  V.el.hidden = true;
698
703
  V.el.querySelector('.cz-vw-body').innerHTML = '';
699
704
  V.el.querySelectorAll('.cz-vw-menu,.cz-vw-trail').forEach((m) => m.remove());
@@ -751,6 +756,7 @@ export function replaceUrl(url) { if (canHist()) hq({ url: String(url) }); }
751
756
  /** n steps along the trail (← is -1, → is 1, the trail list jumps). Past its start the Viewer closes. o.quiet: the browser already moved. */
752
757
  function step(n, o = {}) {
753
758
  if (!V.cur || !n) return null;
759
+ keepPlace();
754
760
  const seq = [...V.stack, V.cur.args, ...V.fwd.slice().reverse()], at = V.stack.length + n;
755
761
  if (at < 0) { close(o); return null; }
756
762
  if (at >= seq.length) return null;
@@ -758,6 +764,12 @@ function step(n, o = {}) {
758
764
  if (!o.quiet) hq({ go: n });
759
765
  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() } });
760
766
  }
767
+ /** The item shown now keeps its place (scroll, open sections) in its trail entry, so a step back to it restores it (back-place.js). */
768
+ function keepPlace() {
769
+ if (!V.cur || !V.cur.args || !V.el) return;
770
+ const p = capturePlace(V.el.querySelector('.cz-vw-body'));
771
+ if (p) V.cur.args = { ...V.cur.args, _place: p };
772
+ }
761
773
  /** 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
762
774
  * where it was, and the move runs on Save or Discard. */
763
775
  function popped(e) { use(ALL[0]); popped0(e); }