create-pmos 0.833.0 → 0.834.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.
@@ -0,0 +1,172 @@
1
+ 'use strict';
2
+ /* story-map.js — a story map with the first release line for a new bet (initiative story-map, idea A419; board BatchPlanDS panel 5).
3
+ *
4
+ * The steps of the user's journey run left to right, the tasks of each step top to bottom, and a dashed line marks Release 1: the thinnest
5
+ * release that works end to end (Jeff Patton's story mapping). PMOS drafts it through the existing read-only ✦ draft job (lib/star-draft.js,
6
+ * the words are askOf below); nothing is kept until the PM's ✓. The PM moves a task across the line; Keep makes every task a task of the
7
+ * initiative's breakdown, Release 1 first, by the boards' own Add a task, and Unkeep deletes them again.
8
+ *
9
+ * PURE
10
+ * parseDraft(text) → { steps: [{ name, tasks: [{ id, title, rel }] }] } | { error } one line per step: `Step: a; b / c; d`;
11
+ * the tasks before the `/` are Release 1 (rel 1), the rest later (rel 2). At least 2 steps and 1 Release 1 task.
12
+ * releaseOf(map) → [{ id, title, step }] the Release 1 tasks, step by step
13
+ * move(map, task, 'above' | 'below') → map | null the task on the other side of the line (null: no such task)
14
+ * newBet(taskCount) → true when the initiative has fewer than NEW_BET tasks (the ✦ line shows only then)
15
+ * askOf({ id, title }) → the ✦ draft words for the initiative
16
+ * textOf(map) → the map as lines (`pmos story-map show`, and the draft form again)
17
+ * STORE (the product's state folder: story-maps.json, { <initiative>: map })
18
+ * read(dir, ini) · save(dir, ini, map | null) · set(dir, ini, text, { by, now }) → { ok, map, prev } | { ok: false, error }
19
+ * moveTo(dir, ini, task, side) → { ok, map, from } | { ok: false, error }
20
+ * keep(ctx, w, ini, dir, g) → { ok, map, added } | { ok: false, status, error } refused when the map is kept already (no second copy)
21
+ * unkeep(ctx, w, ini, dir, g) → { ok, map, removed }
22
+ * count(dir, { days, now }) → maps kept in the window
23
+ * CLI: lib/story-map-cli.js — `pmos story-map show|set|move|keep|unkeep|drop|count`
24
+ *
25
+ * WHAT IT NEVER DOES. It calls no model of its own, writes no Jira and sends nothing. Every write logs one [story-map] line. */
26
+ const fs = require('fs');
27
+ const path = require('path');
28
+
29
+ const TAG = '[story-map]';
30
+ const FILE = 'story-maps.json';
31
+ const NEW_BET = 3;
32
+ const MAX_STEPS = 8, MAX_TASKS = 10, MAX_TITLE = 120;
33
+
34
+ const clip = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
35
+
36
+ /** PURE. */
37
+ function parseDraft(text) {
38
+ const lines = String(text == null ? '' : text).replace(/\r\n?/g, '\n').replace(/```[a-z]*\n?/gi, '').split('\n');
39
+ const steps = [];
40
+ let n = 0;
41
+ for (const raw of lines) {
42
+ const l = raw.replace(/^\s*(?:[-*•]|\d+[.)])\s*/, '').replace(/\*\*/g, '').trim();
43
+ const m = /^([^:]{1,60}):\s*(.+)$/.exec(l);
44
+ if (!m) continue;
45
+ const name = clip(m[1], 40);
46
+ const cut = /\s+\/\s+|\s*\|\s*|^\/\s*|\s*\/$/.exec(m[2]); // the Release 1 line: " / " (or "|")
47
+ const now = cut ? m[2].slice(0, cut.index) : m[2], later = cut ? m[2].slice(cut.index + cut[0].length) : '';
48
+ const tasks = [];
49
+ for (const [part, rel] of [[now, 1], [later, 2]]) {
50
+ for (const t of part.split(/\s*;\s*/)) { const title = clip(t.replace(/[.]+$/, ''), MAX_TITLE); if (title && tasks.length < MAX_TASKS) tasks.push({ id: 't' + (++n), title, rel }); }
51
+ }
52
+ if (!name || !tasks.length) continue;
53
+ steps.push({ name, tasks });
54
+ if (steps.length >= MAX_STEPS) break;
55
+ }
56
+ if (steps.length < 2) return { error: 'a story map needs at least 2 steps of the user\'s journey, one line each: "Step: task; task / later task"' };
57
+ if (!steps.some((s) => s.tasks.some((t) => t.rel === 1))) return { error: 'a story map needs at least one Release 1 task (before the /)' };
58
+ return { steps };
59
+ }
60
+
61
+ /** PURE. */
62
+ function releaseOf(map) {
63
+ const out = [];
64
+ for (const s of (map && map.steps) || []) for (const t of s.tasks || []) if (t.rel === 1) out.push({ id: t.id, title: t.title, step: s.name });
65
+ return out;
66
+ }
67
+
68
+ /** PURE: a new map with the task on the given side of the line; a task keeps its place among its step's tasks. */
69
+ function move(map, task, side) {
70
+ if (!map || !Array.isArray(map.steps) || (side !== 'above' && side !== 'below')) return null;
71
+ let hit = false;
72
+ const steps = map.steps.map((s) => ({ ...s, tasks: s.tasks.map((t) => { if (t.id !== task) return t; hit = true; return { ...t, rel: side === 'above' ? 1 : Math.max(2, t.rel === 1 ? 2 : t.rel) }; }) }));
73
+ return hit ? { ...map, steps } : null;
74
+ }
75
+
76
+ const newBet = (taskCount) => (Number(taskCount) || 0) < NEW_BET;
77
+
78
+ function askOf({ id, title } = {}) {
79
+ return `Draft a story map for the initiative "${clip(title || id, 120)}" (id ${clip(id, 80)}). Read its record, its goal and its sources (PRD, research, notes) first, and use the user's own words from them.`
80
+ + ' Answer 3 to 6 lines, one per step of the user\'s journey, left to right in the order the user goes, each in this form:'
81
+ + '\nStep name: task; task / later task; later task'
82
+ + '\nThe tasks before the / are the thinnest first release that still works from the first step to the last: at least one per step, as few as possible. The tasks after the / come later. Keep each task to a few words.';
83
+ }
84
+
85
+ /** PURE. */
86
+ function textOf(map) {
87
+ return ((map && map.steps) || []).map((s) => {
88
+ const a = s.tasks.filter((t) => t.rel === 1).map((t) => t.title), b = s.tasks.filter((t) => t.rel !== 1).map((t) => t.title);
89
+ return `${s.name}: ${[a.join('; '), b.length ? '/ ' + b.join('; ') : ''].filter(Boolean).join(' ')}`;
90
+ }).join('\n');
91
+ }
92
+
93
+ /* ── the store ── */
94
+ const fileOf = (dir) => path.join(dir, FILE);
95
+ function readAll(dir) { try { const o = JSON.parse(fs.readFileSync(fileOf(dir), 'utf8')); return o && typeof o === 'object' && !Array.isArray(o) ? o : {}; } catch { return {}; } }
96
+ function read(dir, ini) { const m = dir ? readAll(dir)[ini] : null; return m && Array.isArray(m.steps) ? m : null; }
97
+ function save(dir, ini, map) {
98
+ const all = readAll(dir);
99
+ if (map) all[ini] = map; else delete all[ini];
100
+ fs.mkdirSync(dir, { recursive: true });
101
+ const tmp = fileOf(dir) + '.' + process.pid + '.tmp';
102
+ fs.writeFileSync(tmp, JSON.stringify(all, null, 1) + '\n');
103
+ fs.renameSync(tmp, fileOf(dir));
104
+ }
105
+ const okId = (ini) => /^[a-z0-9][a-z0-9._-]{0,80}$/.test(String(ini || ''));
106
+
107
+ function set(dir, ini, text, { by = 'pmos', now = Date.now() } = {}) {
108
+ if (!okId(ini)) return { ok: false, error: 'the initiative id is missing or not a lowercase slug' };
109
+ const prev = read(dir, ini);
110
+ if (prev && prev.kept) return { ok: false, error: 'this map is kept as the task breakdown already; unkeep it first' };
111
+ const p = parseDraft(text);
112
+ if (p.error) return { ok: false, error: p.error };
113
+ const map = { ini, by: by === 'pm' ? 'pm' : 'pmos', at: new Date(now).toISOString(), steps: p.steps, kept: null };
114
+ save(dir, ini, map);
115
+ console.info(`${TAG} set ini=${ini} steps=${map.steps.length} release1=${releaseOf(map).length} by=${map.by}`);
116
+ return { ok: true, map, prev };
117
+ }
118
+
119
+ function moveTo(dir, ini, task, side) {
120
+ const m = read(dir, ini);
121
+ if (!m) return { ok: false, error: `no story map for ${ini}` };
122
+ const t = m.steps.flatMap((s) => s.tasks).find((x) => x.id === task);
123
+ const n = move(m, task, side);
124
+ if (!n || !t) return { ok: false, error: `no task ${task} on the story map of ${ini}, or the side is not above or below` };
125
+ save(dir, ini, n);
126
+ console.info(`${TAG} move ini=${ini} task=${task} ${side} release1=${releaseOf(n).length}`);
127
+ return { ok: true, map: n, from: t.rel === 1 ? 'above' : 'below' };
128
+ }
129
+
130
+ function keep(ctx, w, ini, dir, g) {
131
+ const m = read(dir, ini);
132
+ if (!m) return { ok: false, status: 404, error: `no story map for ${ini}` };
133
+ if (m.kept) return { ok: false, status: 409, error: 'this map is kept as the task breakdown already' };
134
+ const RB = require('./routes-boards.js');
135
+ let wf = RB.initiativeWorkflow(ctx, w, ini);
136
+ // outside the server (pmos story-map keep) the rows may still be read: derive them now, as pmos task add does
137
+ if (wf.pending) { try { require('./initiative-rows.js').deriveNow(w.root); } catch { /* answered below */ } wf = RB.initiativeWorkflow(ctx, w, ini); }
138
+ if (!wf.ok || !wf.board) return { ok: false, status: (wf && wf.status) || 404, error: (wf && wf.error) || 'the initiative is on no board' };
139
+ const order = [], added = [];
140
+ for (const rel of [1, 2]) for (const s of m.steps) for (const t of s.tasks) if ((t.rel === 1) === (rel === 1)) order.push({ s, t });
141
+ for (const { s, t } of order) {
142
+ const r = RB.taskAdd(ctx, { ws: w.id, board: wf.board.id, initiative: ini, title: t.title, notes: `Story map: ${s.name} · ${t.rel === 1 ? 'Release 1' : 'Later'}` }, g);
143
+ if (!r.body || r.body.ok !== true) {
144
+ for (const a of added) RB.taskDelete(ctx, { ws: w.id, board: wf.board.id, task: a.uid, why: 'story map keep did not finish' }, g);
145
+ return { ok: false, status: r.status || 500, error: (r.body && r.body.error) || 'a task could not be added' };
146
+ }
147
+ added.push({ id: t.id, uid: r.body.item.uid || r.body.item.id });
148
+ }
149
+ const n = { ...m, kept: { at: new Date().toISOString(), board: wf.board.id, tasks: added } };
150
+ save(dir, ini, n);
151
+ console.info(`${TAG} keep ini=${ini} tasks=${added.length} release1=${releaseOf(m).length}`);
152
+ return { ok: true, map: n, added };
153
+ }
154
+
155
+ function unkeep(ctx, w, ini, dir, g) {
156
+ const m = read(dir, ini);
157
+ if (!m || !m.kept) return { ok: false, status: 404, error: `no kept story map for ${ini}` };
158
+ const RB = require('./routes-boards.js');
159
+ let removed = 0;
160
+ for (const a of m.kept.tasks || []) { const r = RB.taskDelete(ctx, { ws: w.id, board: m.kept.board, task: a.uid, why: 'story map unkept' }, g); if (r.body && r.body.ok) removed++; }
161
+ const n = { ...m, kept: null };
162
+ save(dir, ini, n);
163
+ console.info(`${TAG} unkeep ini=${ini} removed=${removed}`);
164
+ return { ok: true, map: n, removed };
165
+ }
166
+
167
+ function count(dir, { days = 14, now = Date.now() } = {}) {
168
+ const from = now - days * 864e5;
169
+ return Object.values(readAll(dir)).filter((m) => m && m.kept && Date.parse(m.kept.at) >= from).length;
170
+ }
171
+
172
+ module.exports = { TAG, FILE, NEW_BET, parseDraft, releaseOf, move, newBet, askOf, textOf, read, save, set, moveTo, keep, unkeep, count };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.833.0",
3
+ "version": "0.834.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.833.0",
9
+ "version": "0.834.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.833.0",
3
+ "version": "0.834.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -18,6 +18,7 @@
18
18
  * the page already reads stand in. The UI says PMOS, never Claude; icon-only buttons carry aria-label. */
19
19
  import { wireSwipe } from './cozy-phone-swipe.js';
20
20
  import * as M from './pop-work-model.js';
21
+ import * as WD from './work-drag.js'; // drag a bar to change its dates (initiative timeline-bar-drag)
21
22
  import * as CB from './cozy-bar.js';
22
23
  import { openPop, closePop, undoToast } from './hi-pop.js';
23
24
  import { pmGet, pmPost } from './http.js';
@@ -37,6 +38,7 @@ import * as IF from './inline-fields.js'; // a task's sprint and priority, set
37
38
  import * as SD from './star-draft.js'; // a ✦ draft runs as a PMOS background job and lands on its line (star-buttons-act-directly A7)
38
39
  import * as CAP from './pop-cap.js'; // five actions at most: Ask PMOS and the toolbar's four, the rest under ⋯ (popup-cap, idea A498)
39
40
  import { noteUse } from './use-log.js';
41
+ import * as STMAP from './story-map.js'; // a new bet's story map with the Release 1 line (initiative story-map, A419)
40
42
  import * as TLY from './three-layouts.js'; // three layouts for a new screen, pick one (initiative three-layouts, A317)
41
43
  import * as PR from './print-pdf.js'; // Print or PDF under ⋯ (job #1911, A379)
42
44
  import * as SMAP from './stakeholder-map.js'; // the People block: who decides, must agree, needs to know (stakeholder-map, A371)
@@ -497,7 +499,9 @@ function dsHtml(r, v, o, W, S, C, mode) {
497
499
  const lay = TLY.html(TLY.seen(id));
498
500
  // the People block under the Overview (stakeholder-map, BatchPeopleDS panel 9): drawn from memory, read once per initiative; no name, no block
499
501
  const ppl = SMAP.blockFor(id, o.ws, () => { if (artRedraw) artRedraw(); });
500
- return `<div class="pw pwd">${PD.overviewHtml(W, r, { oid: id, dropped: dropped(), open: ovOpen() })}${ppl}<div class="pwd-main">${PD.stagesHtml(st, W)}${lay}${crit}${wbs}</div></div>`;
502
+ // the story map (A419): a new bet's journey and its Release 1 line, above the breakdown; nothing when there is no map and the bet has tasks
503
+ const smap = STMAP.blockHtml({ id, ws: o.ws || '', title: W.title || '', tasks: stagesOf(r, v, { ...o, today: W.today, subAll: true }).filter((x) => x.kind === 'task').length });
504
+ return `<div class="pw pwd">${PD.overviewHtml(W, r, { oid: id, dropped: dropped(), open: ovOpen() })}${ppl}<div class="pwd-main">${PD.stagesHtml(st, W)}${lay}${smap}${crit}${wbs}</div></div>`;
501
505
  }
502
506
 
503
507
  /** The grouping ✦ the PM said no to, for this initiative: 'group:<stage>'. */
@@ -919,6 +923,7 @@ export function wire(body, h0, x0) {
919
923
  goalsRedraw = artRedraw = wsnRedraw = capRedraw = () => { if (body.isConnected && body.querySelector('.pw')) redraw(); };
920
924
  body.__pwcur = cur; body.__pwredraw = redraw; // ⋯ acts on the popup drawn now (capItems)
921
925
  wireGrip(body);
926
+ STMAP.wire(body, { redraw: () => { if (body.querySelector('.pw')) redraw(); } }); // the story map's presses and drag (A419)
922
927
  // the People block's presses (stakeholder-map), before the popup's own handler below
923
928
  body.addEventListener('click', (e) => { SMAP.press(e, body, { say: (t) => { const hh = body.__pwh; if (hh && hh.toast) hh.toast(t); } }); });
924
929
  // a phone: a proposal swiped right says yes, left says no (its own hidden Yes and No presses, so the popup's writes and Undo stay theirs)
@@ -1561,31 +1566,8 @@ function wireMoves(body, cur, redraw) {
1561
1566
  body.addEventListener('pointerup', stopHold, { passive: true });
1562
1567
  body.addEventListener('pointercancel', stopHold, { passive: true });
1563
1568
  body.addEventListener('contextmenu', (e) => { if (body.__pwQuiet && Date.now() - body.__pwQuiet < 700 && e.target.closest && e.target.closest('[data-pw-row]')) e.preventDefault(); });
1564
- // 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
1565
- body.addEventListener('pointerdown', (e) => {
1566
- if (e.pointerType !== 'mouse' || e.button !== 0) return;
1567
- const bar = e.target.closest && e.target.closest('.pw-kr .pw-tl .iva-tb, .pw-kr .pw-tl .pw-pbar'); if (!bar) return;
1568
- const rw = bar.closest('[data-pw-row]'), tl = bar.closest('.pw-tlin') || bar.closest('.pw-tl'), c = cur(); if (!rw || !tl || !c) return;
1569
- const all = allOf(c), ids = SEL.shiftIds(c.S.sel, rw.dataset.pwRow, all);
1570
- const span = (Date.parse(c.W.span.b) - Date.parse(c.W.span.a)) / 864e5, w = tl.getBoundingClientRect().width, x0 = e.clientX;
1571
- 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)
1572
- .flatMap((t2) => [...t2.querySelectorAll('.iva-tb, .pw-pbar, .iva-md')]);
1573
- let dx = 0;
1574
- e.preventDefault(); try { bar.setPointerCapture(e.pointerId); } catch { /* fine */ }
1575
- document.body.classList.add('pw-drag');
1576
- 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)`; };
1577
- const up = async () => {
1578
- bar.removeEventListener('pointermove', mv); bar.removeEventListener('pointerup', up); bar.removeEventListener('pointercancel', up);
1579
- document.body.classList.remove('pw-drag');
1580
- const n = SEL.daysOf(dx, w, span);
1581
- if (Math.abs(dx) > 3) body.__pwQuiet = Date.now();
1582
- if (!n) { for (const el of els) el.style.transform = ''; return; }
1583
- const h = body.__pwh; if (!h) return;
1584
- moveLog('bar-shift', ids.length);
1585
- await runBulk(ids, 'shift', n, c, h, body.__pwx); // a Jira ticket with no dates in PMOS is skipped, with the reason
1586
- };
1587
- bar.addEventListener('pointermove', mv); bar.addEventListener('pointerup', up); bar.addEventListener('pointercancel', up);
1588
- });
1569
+ // the Gantt: a bar dragged to change its dates, by the middle, an end, a pen, a finger or the keys (pm/work-drag.js, timeline-bar-drag)
1570
+ WD.wireBarDrag(body, { cur, allOf, runBulk, moveLog, ro: () => RO });
1589
1571
  }
1590
1572
  /** The epic check's ✦ fix (WorkJiraDS): every flagged ticket goes under the initiative's epic; Undo withdraws what Jira has not done yet. */
1591
1573
  async function epicFix(c, h, x) {
@@ -0,0 +1,22 @@
1
+ /* pm/story-map.css — the story map block on the initiative popup (initiative story-map, idea A419; board BatchPlanDS panel 5). It only
2
+ * places the parts; the tokens are the design system's. */
3
+ .stm-head { gap: 8px; align-items: baseline; }
4
+ .stm-head .pm-h-sm { margin: 0; flex: 1; }
5
+ .stm-acts { display: inline-flex; gap: 6px; }
6
+ .stm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
7
+ .stm-step { background: var(--ink); color: var(--card); border-radius: var(--radius-sm); padding: 5px 8px; font-size: var(--fs-label); font-weight: var(--fw-strong); }
8
+ .stm-cell { display: flex; flex-direction: column; gap: 6px; min-height: 30px; border-radius: var(--radius-sm); }
9
+ .stm-cell.on { box-shadow: var(--glow); }
10
+ .stm-card { all: unset; box-sizing: border-box; display: block; background: var(--card); border-radius: var(--radius-sm); box-shadow: var(--raise); padding: 6px 8px; font-size: var(--fs-meta); line-height: 16px; color: var(--ink); }
11
+ button.stm-card { cursor: grab; }
12
+ button.stm-card:focus-visible { box-shadow: var(--glow); }
13
+ .stm-card.later { background: var(--well); }
14
+ .stm-line { grid-column: 1 / -1; border-top: 2px dashed var(--blue); font-size: var(--fs-badge); color: var(--blue); padding-top: 2px; }
15
+ .stm-draft { margin-top: 4px; }
16
+ .stm-grid.stm-n2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
17
+ .stm-grid.stm-n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
18
+ .stm-grid.stm-n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
19
+ .stm-grid.stm-n5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
20
+ .stm-grid.stm-n6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
21
+ .stm-grid.stm-n7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
22
+ .stm-grid.stm-n8 { grid-template-columns: repeat(8, minmax(0, 1fr)); }
@@ -0,0 +1,180 @@
1
+ /* pm/story-map.js — a new bet's story map with the Release 1 line, on the initiative popup on a computer (initiative story-map, idea A419;
2
+ * board BatchPlanDS panel 5). pm/cozy-pop-work.js draws blockHtml() in the popup's main column and calls wire() once per body.
3
+ *
4
+ * PURE
5
+ * showsSuggest(st, taskCount) → true when the ✦ line shows: the map was read, there is none, and the initiative has fewer than 3 tasks
6
+ * parseDraft(text) → the same parse as lib/story-map.js (a preview of PMOS's draft before ✓)
7
+ * releaseOf(map) → the Release 1 tasks
8
+ * mapHtml(map, { live }) → the grid: the steps as dark heads left to right, Release 1's tasks, the dashed line, the later tasks
9
+ * blockHtml({ id, ws, title, tasks }) → the block (pm-block), '' when there is nothing to show (zero is silence); reads the map once
10
+ * READS GET /api/story-map once per initiative (again after a chat turn).
11
+ * WRITES, each on a press: ✦ starts PMOS's read-only draft (pm/star-draft.js run); ✓ on the draft POST /api/story-map/set (Undo /put);
12
+ * a task pressed or dragged across the line POST /move (Undo moves it back); ✓ Keep POST /keep (Undo /unkeep); ✕ POST /put null (Undo /put).
13
+ * The words say PMOS, never Claude; every button is an icon with an aria-label. Nothing is sent and Jira is not written. */
14
+ import * as SD from './star-draft.js';
15
+ import { pmGet, pmPost } from './http.js';
16
+ import { undoToast } from './hi-pop.js';
17
+
18
+ const CSS = new URL('./story-map.css', import.meta.url).href;
19
+ if (typeof document !== 'undefined' && document.head && !document.querySelector(`link[href="${CSS}"]`)) {
20
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = CSS; document.head.appendChild(l);
21
+ }
22
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
23
+ const SVG = (d) => `<svg class="pm-ic" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
24
+ const I = { ok: 'M5 12.5l4.5 4.5L19 7.5', x: 'M6 6l12 12M18 6L6 18', star: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z', again: 'M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5' };
25
+ const btn = (attr, icon, label, cls = '') => `<button type="button" class="pm-btn${cls ? ' ' + cls : ''}" ${attr} aria-label="${esc(label)}" title="${esc(label)}">${SVG(icon)}</button>`;
26
+ export const NEW_BET = 3;
27
+
28
+ /* state per initiative: undefined not read · null reading · { map, ask, draft } read. draft: { phase: 'pending' | 'ready' | 'failed', text, why } */
29
+ const ST = new Map();
30
+ let redrawAll = null;
31
+ if (typeof document !== 'undefined' && document.addEventListener) document.addEventListener('cz:chat-turn', () => { for (const [k, v] of ST) if (v && !v.draft) ST.delete(k); if (redrawAll) redrawAll(); });
32
+
33
+ /** PURE: the same parse as lib/story-map.js parseDraft (kept in step by story-map.test.js S1). */
34
+ export function parseDraft(text) {
35
+ const lines = String(text == null ? '' : text).replace(/\r\n?/g, '\n').replace(/```[a-z]*\n?/gi, '').split('\n');
36
+ const steps = []; let n = 0;
37
+ for (const raw of lines) {
38
+ const l = raw.replace(/^\s*(?:[-*•]|\d+[.)])\s*/, '').replace(/\*\*/g, '').trim();
39
+ const m = /^([^:]{1,60}):\s*(.+)$/.exec(l);
40
+ if (!m) continue;
41
+ const name = m[1].replace(/\s+/g, ' ').trim().slice(0, 40);
42
+ const cut = /\s+\/\s+|\s*\|\s*|^\/\s*|\s*\/$/.exec(m[2]);
43
+ const now = cut ? m[2].slice(0, cut.index) : m[2], later = cut ? m[2].slice(cut.index + cut[0].length) : '';
44
+ const tasks = [];
45
+ for (const [part, rel] of [[now, 1], [later, 2]]) for (const t of part.split(/\s*;\s*/)) { const title = t.replace(/[.]+$/, '').replace(/\s+/g, ' ').trim().slice(0, 120); if (title && tasks.length < 10) tasks.push({ id: 't' + (++n), title, rel }); }
46
+ if (!name || !tasks.length) continue;
47
+ steps.push({ name, tasks });
48
+ if (steps.length >= 8) break;
49
+ }
50
+ if (steps.length < 2 || !steps.some((s) => s.tasks.some((t) => t.rel === 1))) return null;
51
+ return { steps };
52
+ }
53
+ export const releaseOf = (map) => ((map && map.steps) || []).flatMap((s) => s.tasks.filter((t) => t.rel === 1).map((t) => ({ ...t, step: s.name })));
54
+ export const showsSuggest = (st, taskCount) => !!st && !st.map && (Number(taskCount) || 0) < NEW_BET;
55
+
56
+ /** PURE: the grid. live: the cards move (a press or a drag); a kept map or a draft preview does not. */
57
+ export function mapHtml(map, { live = false } = {}) {
58
+ const steps = (map && map.steps) || [];
59
+ if (!steps.length) return '';
60
+ const card = (t) => live
61
+ ? `<button type="button" class="stm-card${t.rel === 1 ? '' : ' later'}" draggable="true" data-stm-task="${esc(t.id)}" aria-label="${esc(t.title + (t.rel === 1 ? ': move below the line' : ': move into Release 1'))}">${esc(t.title)}</button>`
62
+ : `<span class="stm-card${t.rel === 1 ? '' : ' later'}">${esc(t.title)}</span>`;
63
+ const cell = (s, side) => `<div class="stm-cell" data-stm-side="${side}" role="group" aria-label="${esc(s.name + (side === 'above' ? ', Release 1' : ', later'))}">${s.tasks.filter((t) => (t.rel === 1) === (side === 'above')).map(card).join('')}</div>`;
64
+ const n = releaseOf(map).length;
65
+ return `<div class="stm-grid stm-n${steps.length}">${steps.map((s) => `<div class="stm-step">${esc(s.name)}</div>`).join('')}`
66
+ + steps.map((s) => cell(s, 'above')).join('')
67
+ + `<div class="stm-line" role="separator">Release 1 · thinnest end to end · ${n} ${n === 1 ? 'task' : 'tasks'}</div>`
68
+ + steps.map((s) => cell(s, 'below')).join('') + '</div>';
69
+ }
70
+
71
+ function read(id, ws, title, tasks) {
72
+ if (!id || ST.has(id)) return;
73
+ ST.set(id, null);
74
+ pmGet('/api/story-map?ini=' + encodeURIComponent(id) + (ws ? '&ws=' + encodeURIComponent(ws) : '') + (title ? '&title=' + encodeURIComponent(title) : ''))
75
+ .then((x) => { const st = x && x.ok ? { map: x.map || null, ask: x.ask || '', ws: x.ws || ws } : false; ST.set(id, st);
76
+ // Draw again only when the block now shows: a redraw for nothing would rebuild the popup under an open menu.
77
+ if (redrawAll && st && (st.map || showsSuggest(st, tasks))) redrawAll(); })
78
+ .catch(() => ST.set(id, false));
79
+ }
80
+
81
+ /** The block, '' when nothing shows (zero is silence): an initiative with a map, or a new bet with none. */
82
+ export function blockHtml({ id, ws, title, tasks } = {}) {
83
+ read(id, ws, title, tasks);
84
+ const st = ST.get(id);
85
+ if (!st) return '';
86
+ const head = (extra = '') => `<div class="pm-row stm-head"><h2 class="pm-h-sm">Story map</h2>${extra}</div>`;
87
+ const wrap = (inner) => `<section class="pm-block pwd-blk stm-blk" aria-label="Story map" data-stm-block="${esc(id)}">${inner}</section>`;
88
+ if (st.map) {
89
+ const m = st.map, k = m.kept;
90
+ const meta = `<span class="pm-meta">${k ? 'Kept as ' + k.tasks.length + ' tasks' : m.by === 'pm' ? '' : '✦ drafted by PMOS'}</span>`;
91
+ const acts = k ? '' : `<span class="stm-acts">${btn('data-stm-keep', I.ok, 'Keep the map: its tasks become the task breakdown, Release 1 first', 'primary')}${btn('data-stm-drop', I.x, 'Delete this story map')}</span>`;
92
+ return wrap(head(meta + acts) + mapHtml(m, { live: !k }));
93
+ }
94
+ const d = st.draft;
95
+ if (d && d.phase === 'pending') return wrap(head() + SD.pendingHtml('the story map'));
96
+ if (d && d.phase === 'failed') return wrap(head() + `<p class="pm-state error" role="alert"><span>${esc(d.why)}</span>${btn('data-stm-again', I.again, 'Try again')}</p>`);
97
+ if (d && d.phase === 'ready') {
98
+ const prev = parseDraft(d.text);
99
+ return wrap(head() + `<div class="pm-sug stm-draft" role="group" aria-label="Draft of the story map"><span class="pm-star" aria-hidden="true">✦</span><span class="say">PMOS drafted this map from the goal and sources.</span>`
100
+ + `<span class="ans">${btn('data-stm-take', I.ok, 'Keep this draft', 'primary')}${btn('data-stm-skip', I.x, 'Not this one')}</span></div>` + mapHtml(prev));
101
+ }
102
+ if (!showsSuggest(st, tasks)) return '';
103
+ return wrap(head() + `<div class="pm-sug stm-sug" role="group" aria-label="PMOS suggests"><span class="pm-star" aria-hidden="true">✦</span>`
104
+ + `<span class="say">Map the user's journey for this bet, with the thinnest first release</span><span class="ans">${btn('data-stm-draft', I.star, 'Let PMOS draft the story map', 'primary')}</span></div>`);
105
+ }
106
+
107
+ async function post(p, body) { const r = await pmPost(p, body).catch(() => null); return r && r.ok !== false ? r : { ok: false, error: (r && r.error) || 'PMOS could not save it.' }; }
108
+
109
+ /** Once per popup body: the presses and the drag of the story map block. redraw() draws the popup again. */
110
+ export function wire(body, { redraw } = {}) {
111
+ if (!body || body.__sm) return;
112
+ body.__sm = true;
113
+ redrawAll = () => { if (body.isConnected && redraw) redraw(); };
114
+ const at = (el) => { const b = el && el.closest && el.closest('[data-stm-block]'); const id = b ? b.dataset.stmBlock : ''; return id ? { id, st: ST.get(id) } : null; };
115
+ const apply = (id, map) => { const st = ST.get(id) || {}; ST.set(id, { ...st, map, draft: null }); redrawAll(); };
116
+ const moveIt = async (id, st, task, side) => {
117
+ if (!st || !st.map || st.map.kept) return;
118
+ const r = await post('/api/story-map/move', { ws: st.ws, ini: id, task, side });
119
+ if (!r.ok) { undoToast(r.error, () => {}, 4000, 'OK'); return; }
120
+ apply(id, r.map);
121
+ undoToast(side === 'above' ? 'Moved into Release 1.' : 'Moved below the line.', async () => { const u = await post('/api/story-map/move', { ws: st.ws, ini: id, task, side: r.from }); if (u.ok) apply(id, u.map); });
122
+ };
123
+ const draft = async (id, st, again) => {
124
+ ST.set(id, { ...st, draft: { phase: 'pending' } }); redrawAll();
125
+ const r = await SD.run(st.ask, { ws: st.ws, pmPost, pmGet, again });
126
+ const ok = r.ok && parseDraft(r.text);
127
+ ST.set(id, { ...(ST.get(id) || st), draft: ok ? { phase: 'ready', text: r.text } : { phase: 'failed', why: r.ok ? 'The draft did not read as steps and tasks.' : r.why } });
128
+ redrawAll();
129
+ };
130
+ // one press handler on the document for the presses inside this body (the design system's rule: no click listener on an element)
131
+ const onPress = async (e) => {
132
+ if (!body.isConnected) { document.removeEventListener('click', onPress); return; }
133
+ if (!body.contains(e.target)) return;
134
+ const b = e.target.closest && e.target.closest('[data-stm-draft],[data-stm-again],[data-stm-take],[data-stm-skip],[data-stm-keep],[data-stm-drop],[data-stm-task]');
135
+ const c = b && at(b);
136
+ if (!c || !c.st) return;
137
+ e.preventDefault(); e.stopPropagation();
138
+ const { id, st } = c, d = b.dataset;
139
+ if ('stmDraft' in d || 'stmAgain' in d) { draft(id, st, 'stmAgain' in d); return; }
140
+ if ('stmSkip' in d) { ST.set(id, { ...st, draft: null }); redrawAll(); return; }
141
+ if ('stmTake' in d) {
142
+ const r = await post('/api/story-map/set', { ws: st.ws, ini: id, text: st.draft && st.draft.text, by: 'pmos' });
143
+ if (!r.ok) { undoToast(r.error, () => {}, 4000, 'OK'); return; }
144
+ apply(id, r.map);
145
+ undoToast('Story map kept as a draft.', async () => { const u = await post('/api/story-map/put', { ws: st.ws, ini: id, map: r.prev || null }); if (u.ok) apply(id, u.map); });
146
+ return;
147
+ }
148
+ if ('stmKeep' in d) {
149
+ const r = await post('/api/story-map/keep', { ws: st.ws, ini: id });
150
+ if (!r.ok) { undoToast(r.error, () => {}, 4000, 'OK'); return; }
151
+ apply(id, r.map);
152
+ document.dispatchEvent(new CustomEvent('cz:chat-turn')); // the breakdown reads its tasks again
153
+ undoToast(r.added.length + ' tasks added to the breakdown, Release 1 first.', async () => { const u = await post('/api/story-map/unkeep', { ws: st.ws, ini: id }); if (u.ok) { apply(id, u.map); document.dispatchEvent(new CustomEvent('cz:chat-turn')); } });
154
+ return;
155
+ }
156
+ if ('stmDrop' in d) {
157
+ const was = st.map;
158
+ const r = await post('/api/story-map/put', { ws: st.ws, ini: id, map: null });
159
+ if (!r.ok) { undoToast(r.error, () => {}, 4000, 'OK'); return; }
160
+ apply(id, null);
161
+ undoToast('Story map deleted.', async () => { const u = await post('/api/story-map/put', { ws: st.ws, ini: id, map: was }); if (u.ok) apply(id, u.map); });
162
+ return;
163
+ }
164
+ if ('stmTask' in d) { const side = b.closest('[data-stm-side]'); moveIt(id, st, d.stmTask, side && side.dataset.stmSide === 'above' ? 'below' : 'above'); }
165
+ };
166
+ document.addEventListener('click', onPress);
167
+ // drag a task above or below the line (a mouse); the press does the same on a touch screen and with a keyboard
168
+ body.addEventListener('dragstart', (e) => { const t = e.target.closest && e.target.closest('[data-stm-task]'); if (t && e.dataTransfer) { e.dataTransfer.setData('text/x-stm-task', t.dataset.stmTask); e.dataTransfer.effectAllowed = 'move'; } });
169
+ body.addEventListener('dragover', (e) => { const z = e.target.closest && e.target.closest('[data-stm-side]'); if (z && e.dataTransfer && [...(e.dataTransfer.types || [])].includes('text/x-stm-task')) { e.preventDefault(); z.classList.add('on'); } });
170
+ body.addEventListener('dragleave', (e) => { const z = e.target.closest && e.target.closest('[data-stm-side]'); if (z) z.classList.remove('on'); });
171
+ body.addEventListener('drop', (e) => {
172
+ const z = e.target.closest && e.target.closest('[data-stm-side]'), task = e.dataTransfer && e.dataTransfer.getData('text/x-stm-task');
173
+ if (!z || !task) return;
174
+ e.preventDefault(); z.classList.remove('on');
175
+ const c = at(z); if (!c || !c.st || !c.st.map) return;
176
+ const now = c.st.map.steps.flatMap((s) => s.tasks).find((t) => t.id === task);
177
+ const side = z.dataset.stmSide;
178
+ if (now && (now.rel === 1) !== (side === 'above')) moveIt(c.id, c.st, task, side);
179
+ });
180
+ }
@@ -0,0 +1,14 @@
1
+ /* pm/work-drag.css — the grips and the tip of a bar you drag to change its dates (pm/work-drag.js, initiative timeline-bar-drag) */
2
+ .wd-on { cursor: grab; touch-action: pan-y; }
3
+ .wd-on:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
4
+ .wd-on.wd-live { cursor: grabbing; z-index: 2; }
5
+ .wd-g { position: absolute; top: 0; bottom: 0; width: var(--space-8); cursor: col-resize; opacity: 0; }
6
+ .wd-g::after { content: ''; position: absolute; top: 25%; bottom: 25%; left: 50%; width: 2px; margin-left: -1px; border-radius: var(--radius-pill); background: var(--cz-ink2); }
7
+ .wd-g.s { left: 0; }
8
+ .wd-g.e { right: 0; }
9
+ .wd-on:focus-visible .wd-g, .wd-on.wd-live .wd-g { opacity: 1; }
10
+ @media (hover: hover) { .wd-on:hover .wd-g { opacity: 1; } }
11
+ @media (hover: none) { .wd-g { opacity: 1; } }
12
+ .wd-mv { transform: translateX(var(--tl-dx, 0)); }
13
+ .wd-rs { left: var(--tl-l) !important; width: var(--tl-w) !important; }
14
+ .wd-tip { position: fixed; left: var(--tl-tipx, 0); top: var(--tl-tipy, 0); z-index: 1000; transform: translateX(-50%); padding: var(--space-4) var(--space-8); border-radius: var(--radius-sm); background: var(--cz-ink); color: var(--cz-card); font-size: var(--fs-meta); font-weight: var(--fw-strong); pointer-events: none; white-space: nowrap; }
@@ -0,0 +1,133 @@
1
+ /* pm/work-drag.js — drag a bar on the Gantt to change its dates (initiative timeline-bar-drag, board TbInitTimeline on Exploring 3, page
2
+ * balanced; job #2014). The Work popup's Gantt (pm/cozy-pop-work.js) calls wireBarDrag(body, deps) once.
3
+ *
4
+ * What it does, on every task bar PMOS may change (pm/work-tree.js canDrag):
5
+ * - marks it: "Drag to change dates" in its label and title, a grip at each end, a place in the Tab order (zero is silence: a bar PMOS
6
+ * may not change, a stage, and a read-only copy get nothing);
7
+ * - the middle moves the whole task by whole days, with every picked row, through the old shift (one Undo);
8
+ * - an end changes that date only, and a milestone's ◇ moves its one date, through the host's dates() writer: the same as the date
9
+ * picker, whose toast says "Dates saved" with Undo;
10
+ * - a tip shows the new dates while dragging; a mouse starts after 3 px, a pen or a finger after 6 px sideways (a smaller move stays a tap);
11
+ * - on a focused bar, ← → move the task a day, Shift moves the due day, Alt the start.
12
+ * Nothing is sent to anyone and nothing is written to Jira: a Jira ticket's dates are PMOS only, as the date picker says.
13
+ *
14
+ * wireBarDrag(body, { cur, allOf, runBulk, moveLog, ro }) cur() → the popup's current { W, S }; allOf(c) → its rows in order;
15
+ * runBulk(ids, 'shift', days, c, h, x); moveLog(how, n); ro() → read-only
16
+ * decorate(root, rowOf, ro) marks the bars under root (exported for the test) */
17
+ import * as WT from './work-tree.js';
18
+ import * as SEL from './work-select.js';
19
+ import { noteUse } from './use-log.js';
20
+
21
+ const BAR = '.pw-kr .pw-tl .iva-tb, .pw-kr .pw-tl .iva-md, .pw-kr .pw-tl .pw-pbar';
22
+ const HINT = 'Drag to change dates';
23
+
24
+ if (typeof document !== 'undefined' && document.head && !document.querySelector('link[data-wd-css]')) {
25
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = new URL('./work-drag.css', import.meta.url).href; l.dataset.wdCss = '1';
26
+ document.head.appendChild(l);
27
+ }
28
+
29
+ const uidOf = (bar) => { const rw = bar && bar.closest && bar.closest('[data-pw-row]'); return rw ? String(rw.dataset.pwRow) : ''; };
30
+
31
+ /** Mark every bar under root that PMOS may change. rowOf(uid) → the row; ro: a read-only copy. Returns how many bars it marked. */
32
+ export function decorate(root, rowOf, ro = false) {
33
+ if (!root || !root.querySelectorAll) return 0;
34
+ let n = 0;
35
+ for (const bar of root.querySelectorAll(BAR)) {
36
+ if (bar.dataset.wd) continue;
37
+ const row = rowOf(uidOf(bar));
38
+ if (bar.classList.contains('pw-pbar')) { bar.dataset.wd = 'par'; continue; } // a parent keeps its whole-bar move, with no grips
39
+ if (!WT.canDrag(row, ro)) { bar.dataset.wd = 'no'; continue; }
40
+ bar.dataset.wd = row.ms ? 'ms' : 'on';
41
+ bar.classList.add('wd-on');
42
+ const words = (row.title ? row.title + ': ' : '') + WT.dragTip(row, 'move', 0) + '. ' + HINT;
43
+ bar.setAttribute('aria-label', words);
44
+ bar.setAttribute('title', HINT);
45
+ if (bar.tagName !== 'BUTTON') { bar.setAttribute('tabindex', '0'); bar.setAttribute('role', 'button'); }
46
+ if (!row.ms) bar.insertAdjacentHTML('beforeend', '<b class="wd-g s" aria-hidden="true"></b><b class="wd-g e" aria-hidden="true"></b>');
47
+ n++;
48
+ }
49
+ return n;
50
+ }
51
+
52
+ function tipAt(text, x, y) {
53
+ let t = document.querySelector('.wd-tip');
54
+ if (!t) { t = document.createElement('div'); t.className = 'wd-tip'; t.setAttribute('role', 'status'); document.body.appendChild(t); }
55
+ t.textContent = text; t.style.setProperty('--tl-tipx', Math.round(x) + 'px'); t.style.setProperty('--tl-tipy', Math.round(y - 36) + 'px');
56
+ }
57
+ const tipOff = () => { const t = document.querySelector('.wd-tip'); if (t) t.remove(); };
58
+ /* after a drag the press is not a click: the ◇'s card and the row's open stay shut */
59
+ const eatClick = () => { const f = (e) => { e.stopPropagation(); e.preventDefault(); }; window.addEventListener('click', f, { capture: true, once: true }); setTimeout(() => window.removeEventListener('click', f, { capture: true }), 400); };
60
+
61
+ export function wireBarDrag(body, d) {
62
+ if (!body || body.__wdWired) return; body.__wdWired = true;
63
+ const ro = () => !!(d.ro && d.ro());
64
+ const rowOf = (uid) => { const c = d.cur(); return c && c.W ? c.W.rows.find((r) => String(r.uid) === String(uid)) : null; };
65
+ const mark = () => decorate(body, rowOf, ro());
66
+ mark();
67
+ if (typeof MutationObserver !== 'undefined') new MutationObserver(mark).observe(body, { childList: true, subtree: true });
68
+
69
+ const save = async (kind, n, uid, ids, c) => {
70
+ const h = body.__pwh; if (!h || !n) return;
71
+ const row = rowOf(uid); if (!row && kind !== 'par') return;
72
+ try { noteUse('barDrag'); } catch { /* the use log is a convenience */ }
73
+ try { console.info('[bar-drag]', kind, n, uid); } catch { /* no console */ }
74
+ if (kind === 'move' && !(row && row.ms) || kind === 'par') { d.moveLog('bar-shift', ids.length); await d.runBulk(ids, 'shift', n, c, h, body.__pwx); return; }
75
+ const patch = WT.dragPatch(row, kind, n); if (!patch) return;
76
+ d.moveLog('bar-' + (row.ms ? 'ms' : kind), 1);
77
+ if (h.dates) await h.dates(uid, patch);
78
+ };
79
+
80
+ // the listeners sit on the document (a drag can leave the popup), and answer only for a bar inside this popup
81
+ document.addEventListener('pointerdown', (e) => {
82
+ if (e.button !== 0 || ro() || !body.isConnected || !body.contains(e.target)) return;
83
+ const bar = e.target.closest && e.target.closest(BAR); if (!bar || !bar.dataset.wd || bar.dataset.wd === 'no') return;
84
+ const uid = uidOf(bar), tl = bar.closest('.pw-tlin') || bar.closest('.pw-tl'), c = d.cur(); if (!uid || !tl || !c) return;
85
+ const row = rowOf(uid), par = bar.dataset.wd === 'par';
86
+ const r0 = bar.getBoundingClientRect(), pr = tl.getBoundingClientRect(), w = Math.max(1, pr.width);
87
+ const kind = par ? 'par' : row && row.ms ? 'move' : WT.dragKind(e.clientX, r0.left, r0.width);
88
+ const span = (Date.parse(c.W.span.b) - Date.parse(c.W.span.a)) / 864e5, dayPx = w / Math.max(1, span);
89
+ // the middle moves every picked row with it (shift-click picks); an end or a ◇ changes this one row
90
+ const ids = kind === 'move' || par ? [...new Set(SEL.shiftIds(c.S.sel, uid, d.allOf(c)).concat(uid))] : [uid];
91
+ const els = kind === 'move' || par ? ids.map((u) => body.querySelector(`.pw-kr[data-pw-row="${window.CSS.escape(u)}"] .pw-tl`)).filter(Boolean).flatMap((t2) => [...t2.querySelectorAll('.iva-tb, .pw-pbar, .iva-md')]) : [bar];
92
+ const x0 = e.clientX, y0 = e.clientY, pointer = e.pointerType || 'mouse';
93
+ let on = false, dx = 0;
94
+ const begin = () => { on = true; try { bar.setPointerCapture(e.pointerId); } catch { /* fine */ } document.body.classList.add('pw-drag'); bar.classList.add('wd-live'); };
95
+ if (pointer === 'mouse') { e.preventDefault(); begin(); }
96
+ const draw = (n) => {
97
+ const px = n * dayPx;
98
+ if (kind === 'move' || par) { for (const el of els) { el.classList.add('wd-mv'); el.style.setProperty('--tl-dx', px.toFixed(1) + 'px'); } return; }
99
+ const L = r0.left - pr.left, W0 = r0.width;
100
+ const l = kind === 'start' ? Math.min(L + px, L + W0 - dayPx) : L, wd = kind === 'start' ? W0 - (l - L) : Math.max(dayPx, W0 + px);
101
+ bar.classList.add('wd-rs'); bar.style.setProperty('--tl-l', l.toFixed(1) + 'px'); bar.style.setProperty('--tl-w', wd.toFixed(1) + 'px');
102
+ };
103
+ const mv = (ev) => {
104
+ dx = ev.clientX - x0;
105
+ if (!on) { if (!WT.dragStarts(dx, ev.clientY - y0, pointer)) return; begin(); }
106
+ ev.preventDefault();
107
+ const n = SEL.daysOf(dx, w, span);
108
+ draw(n);
109
+ if (row) tipAt(WT.dragTip(row, kind === 'par' ? 'move' : kind, n), ev.clientX, r0.top);
110
+ };
111
+ const up = async () => {
112
+ document.removeEventListener('pointermove', mv); document.removeEventListener('pointerup', up); document.removeEventListener('pointercancel', up);
113
+ tipOff();
114
+ if (!on) return; // a tap: the ◇'s card, the row's pick and the hold to pick work as before
115
+ document.body.classList.remove('pw-drag'); bar.classList.remove('wd-live');
116
+ const n = SEL.daysOf(dx, w, span);
117
+ if (Math.abs(dx) > 3) { body.__pwQuiet = Date.now(); eatClick(); }
118
+ if (!n) { for (const el of els) { el.classList.remove('wd-mv'); el.style.removeProperty('--tl-dx'); } bar.classList.remove('wd-rs'); return; }
119
+ await save(kind, n, uid, ids, c);
120
+ };
121
+ document.addEventListener('pointermove', mv); document.addEventListener('pointerup', up); document.addEventListener('pointercancel', up);
122
+ });
123
+
124
+ // the keys, on a focused bar: ← → a day; Shift the due day, Alt the start
125
+ body.addEventListener('keydown', (e) => {
126
+ const bar = e.target.closest && e.target.closest(BAR); if (!bar || ro() || (bar.dataset.wd !== 'on' && bar.dataset.wd !== 'ms')) return;
127
+ const st = WT.keyStep(e.key, e); if (!st) return;
128
+ e.preventDefault();
129
+ const uid = uidOf(bar), c = d.cur(); if (!uid || !c) return;
130
+ const row = rowOf(uid);
131
+ save(row && row.ms ? 'move' : st.kind, st.days, uid, [uid], c);
132
+ });
133
+ }