create-pmos 0.737.0 → 0.739.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,280 @@
1
+ /* pm/live-edit.js — an edit shows at once, everywhere it is drawn (Wawan, 2026-11-23: "When I change date or status here, it didn't change
2
+ * immediately on the UI ... Also applies to any other changes ... show issue when it is failed to update eventually").
3
+ *
4
+ * Before: a task's status or day was drawn again only after the save answered AND the page read the whole board again (Home reads eleven
5
+ * routes; the Board can answer "stale, ask again"). A drilled-in page, such as the big Work breakdown, was not drawn again at all until the
6
+ * popup was opened again.
7
+ *
8
+ * Now, one path for every page. install() (run once when this module first loads in a page) watches the page's own fetch, so every task
9
+ * write is seen whatever helper sends it (pm/http.js pmPost, pressFetch, data.js postJson):
10
+ * begin(path, body) a task write (POST /api/boards/tasks/state | edit | rename) is put on every copy of the task that a page holds
11
+ * (source()), and every page and open view is drawn again at once. Returns { ok(), fail() } or null.
12
+ * ok() the save landed: the change stays on until a read that started after the save replaces it (loaded()).
13
+ * fail() the save did not land: every copy gets its old value back and is drawn again. The caller says why in its toast.
14
+ * loaded({ since, stale }) a page read its data again: the changes still saving (and the saved ones a stale read cannot hold yet) are
15
+ * put back on the new copies, then the open views are drawn again, so a drilled-in page follows the read too.
16
+ * source({ model, redraw }) a page's data (a root, or a list of roots) and the draw that shows it; returns the call that removes it.
17
+ * view(el, redraw) an open view drawn from those sources (the popup body, the big Work breakdown); dropped once el leaves the page.
18
+ *
19
+ * Pure apart from the redraw calls and install(): no DOM reads, no requests of its own, so live-edit.test.js runs it in Node.
20
+ */
21
+
22
+ /** The write's field → the names a page's copy of a task uses for it (the Board's rows say status and end; Home's and the Backlog's say
23
+ * state and due). Only these fields are drawn at once; any other field waits for the read, as before. */
24
+ export const FIELDS = {
25
+ state: ['status', 'state'],
26
+ start: ['start'],
27
+ due: ['end', 'due'],
28
+ milestone: ['milestone', 'ms'],
29
+ owner: ['owner'],
30
+ priority: ['priority'],
31
+ sprint: ['sprint'],
32
+ title: ['title'],
33
+ notes: ['notes'],
34
+ section: ['section'],
35
+ parent: ['parent'],
36
+ };
37
+ const TASK_WRITE = /^\/api\/boards\/tasks\/(state|edit|rename|add|delete|bulk)(?:\?|$)/;
38
+ const JIRA_KEY = /^[A-Z][A-Z0-9]+-\d+$/i;
39
+ const isJira = (id) => JIRA_KEY.test(id) && !/^task-/i.test(id); // a PMOS task id is task-<hex>, which can be all digits
40
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
41
+
42
+ const SOURCES = new Set();
43
+ const VIEWS = new Map(); // el (or a token) → redraw
44
+ const PENDING = new Map(); // a write's token → { op, saved: 0 | the time it landed }
45
+ let seq = 0;
46
+
47
+ /** The fields of one task write that can be drawn at once: { state: 'Done' }, { due: '2026-11-30' }, … null when none. */
48
+ function pick(body, rename) {
49
+ const out = {};
50
+ for (const k of Object.keys(FIELDS)) if (body[k] !== undefined && body[k] !== null) out[k] = body[k];
51
+ if (!rename) delete out.title;
52
+ if ('state' in out) out.state = String(out.state);
53
+ return Object.keys(out).length ? out : null;
54
+ }
55
+
56
+ /** What a write does to the pages' copies of its tasks, as a list of ops; null when it is not a task write.
57
+ * { kind: 'patch', id, fields } status, days, owner, priority, sprint, name, stage (section), parent; fields.shift: move both days by N
58
+ * { kind: 'remove', id } tasks/delete
59
+ * { kind: 'add', ini, row } tasks/add: a row drawn under its initiative until the read brings the real one */
60
+ export function opsOf(path, body) {
61
+ const m = TASK_WRITE.exec(String(path || ''));
62
+ if (!m || !body || typeof body !== 'object') return null;
63
+ const w = m[1];
64
+ if (w === 'add') {
65
+ if (typeof body.initiative !== 'string' || !body.initiative || typeof body.title !== 'string' || !body.title.trim()) return null;
66
+ const row = { uid: 'adding:' + (++seq), title: body.title.trim(), status: 'To do', owner: body.owner || '', start: body.start || '', end: body.due || '', adding: true,
67
+ ...(typeof body.section === 'string' ? { section: body.section } : {}), ...(body.parent ? { parent: body.parent } : {}), ...(body.milestone ? { milestone: true } : {}) };
68
+ return [{ kind: 'add', ini: body.initiative, row }];
69
+ }
70
+ if (w === 'bulk') {
71
+ const ids = Array.isArray(body.tasks) ? body.tasks.filter((x) => typeof x === 'string' && x) : [];
72
+ const v = body.value, f = body.op === 'done' ? { state: 'Done' } : body.op === 'shift' ? (Number.isInteger(Number(v)) && Number(v) ? { shift: Number(v) } : null)
73
+ : ['section', 'owner', 'parent'].includes(body.op) && typeof v === 'string' ? { [body.op]: v } : null;
74
+ // Jira keeps a ticket's status, stage and assignee, so the server skips those: they are not drawn either
75
+ const keep = body.op === 'shift' || body.op === 'parent' ? ids : ids.filter((id) => !isJira(id));
76
+ return f && keep.length ? keep.map((id) => ({ kind: 'patch', id, fields: f })) : null;
77
+ }
78
+ if (typeof body.task !== 'string' || !body.task) return null;
79
+ if (w === 'delete') return [{ kind: 'remove', id: body.task }];
80
+ const fields = pick(body, w === 'rename');
81
+ return fields ? [{ kind: 'patch', id: body.task, fields }] : null;
82
+ }
83
+
84
+ /** The fields of a single task write (kept for callers that only patch). */
85
+ export function fieldsOf(path, body) {
86
+ const ops = opsOf(path, body);
87
+ return ops && ops.length === 1 && ops[0].kind === 'patch' && path.indexOf('/bulk') < 0 ? ops[0].fields : null;
88
+ }
89
+
90
+ /** Is o a copy of task id? A PMOS task carries uid; a Backlog row carries id; a Jira ticket carries its key. */
91
+ export function isTask(o, id) {
92
+ if (!o || typeof o !== 'object' || Array.isArray(o)) return false;
93
+ if (o.uid === id) return true;
94
+ if (o.id === id && typeof o.title === 'string' && ('state' in o || 'status' in o)) return true;
95
+ return isJira(id) && typeof o.key === 'string' && o.key.toUpperCase() === id.toUpperCase() && ('status' in o || 'state' in o);
96
+ }
97
+
98
+ /** Every place under root that holds something test() accepts: { o, parent, key } (objects, arrays, Map values), each place once. Stops
99
+ * at DOM nodes and at depth 12. */
100
+ function walk(root, test, out, seen, depth) {
101
+ if (!root || typeof root !== 'object' || depth > 12 || seen.has(root)) return out;
102
+ if (typeof root.nodeType === 'number' || typeof root.then === 'function') return out;
103
+ seen.add(root);
104
+ const visit = (v, key) => {
105
+ if (!v || typeof v !== 'object') return;
106
+ if (test(v)) out.push({ o: v, parent: root, key });
107
+ walk(v, test, out, seen, depth + 1);
108
+ };
109
+ if (Array.isArray(root)) root.forEach((v, i) => visit(v, i));
110
+ else if (root instanceof Map) for (const [k, v] of root) visit(v, k);
111
+ else if (!(root instanceof Set)) for (const k of Object.keys(root)) visit(root[k], k);
112
+ return out;
113
+ }
114
+ export function findAll(root, id, out = [], seen = new WeakSet()) { return walk(root, (v) => isTask(v, id), out, seen, 0); }
115
+
116
+ /** A day N days later (or earlier): '2026-11-23' + 2 → '2026-11-25'. Anything that is not a day is left as it is. */
117
+ export function shiftDay(d, n) {
118
+ if (typeof d !== 'string' || !DAY.test(d)) return d;
119
+ const t = new Date(d + 'T00:00:00Z'); t.setUTCDate(t.getUTCDate() + n);
120
+ return t.toISOString().slice(0, 10);
121
+ }
122
+
123
+ /** The copy with the fields put on it (a new object: whoever holds the old one, such as a press's Undo, still reads the old value). A field
124
+ * the copy does not have is added under its first name only on a PMOS task copy (it has uid), so a ticket never grows a field its page
125
+ * does not read. fields.shift moves every day the copy has by that many days. */
126
+ export function patched(o, fields) {
127
+ const n = { ...o };
128
+ for (const [k, v] of Object.entries(fields)) {
129
+ if (k === 'shift') { for (const name of ['start', 'end', 'due']) if (name in o) n[name] = shiftDay(o[name], v); continue; }
130
+ const names = FIELDS[k] || [k], val = k === 'milestone' ? !!v : v;
131
+ let hit = false;
132
+ for (const name of names) if (name in o) { n[name] = val; hit = true; }
133
+ if (!hit && 'uid' in o) n[names[0]] = val;
134
+ }
135
+ return n;
136
+ }
137
+
138
+ const get = (parent, key) => (parent instanceof Map ? parent.get(key) : parent[key]);
139
+ const put = (parent, key, v) => { if (parent instanceof Map) parent.set(key, v); else parent[key] = v; };
140
+
141
+ function rootsOf(s) { try { const m = s.model(); return Array.isArray(m) ? m : [m]; } catch { return []; } }
142
+ function places(test) {
143
+ const at = [], seen = new WeakSet();
144
+ for (const s of SOURCES) for (const r of rootsOf(s)) walk(r, test, at, seen, 0);
145
+ return at;
146
+ }
147
+
148
+ /** Do one op on every copy the pages hold; returns the undo steps, for fail(). */
149
+ function apply(op) {
150
+ const steps = [];
151
+ if (op.kind === 'patch') {
152
+ const made = new Map();
153
+ for (const { o, parent, key } of places((v) => isTask(v, op.id))) {
154
+ // a copy that already says it (the read caught up) is left alone, so a read never draws twice for nothing
155
+ if (!made.has(o)) { const n = patched(o, op.fields); made.set(o, Object.keys(n).some((k) => n[k] !== o[k]) ? n : o); }
156
+ if (made.get(o) === o) continue;
157
+ const n = made.get(o);
158
+ put(parent, key, n);
159
+ steps.push(() => { if (get(parent, key) === n) { put(parent, key, o); return 1; } return 0; });
160
+ }
161
+ } else if (op.kind === 'remove') {
162
+ // from the end of each list first, so the places of the others hold
163
+ const at = places((v) => isTask(v, op.id)).sort((a, b) => (typeof b.key === 'number' ? b.key : 0) - (typeof a.key === 'number' ? a.key : 0));
164
+ for (const { o, parent, key } of at) {
165
+ if (Array.isArray(parent)) { const i = parent.indexOf(o); if (i < 0) continue; parent.splice(i, 1); steps.push(() => { if (parent.includes(o)) return 0; parent.splice(Math.min(i, parent.length), 0, o); return 1; }); }
166
+ else if (parent instanceof Map) { parent.delete(key); steps.push(() => { if (parent.has(key)) return 0; parent.set(key, o); return 1; }); }
167
+ }
168
+ } else if (op.kind === 'add') {
169
+ // under each copy of its initiative that lists tasks (the Board's and Home's rows); a copy that has the task already is left alone
170
+ for (const { o } of places((v) => !Array.isArray(v) && v.id === op.ini && Array.isArray(v.tasks))) {
171
+ if (o.tasks.some((t) => t && t.uid === op.row.uid)) continue;
172
+ const row = { ...op.row }, arr = o.tasks;
173
+ arr.push(row);
174
+ steps.push(() => { const i = arr.indexOf(row); if (i < 0) return 0; arr.splice(i, 1); return 1; });
175
+ }
176
+ }
177
+ return steps;
178
+ }
179
+
180
+ /** Draw every page and open view again. One failing draw never stops the others. */
181
+ /** A task card's picker (status, dates) is open: it hangs from a row a redraw would replace, and closes when that row goes. */
182
+ const pickerOpen = () => typeof document !== 'undefined' && !!document.querySelector('.tkc.ivq');
183
+ let HELD = null;
184
+ export function paint(views = true) {
185
+ // hold the redraw while a picker is open (the picker itself already shows the new value), and draw once it closes
186
+ if (pickerOpen()) {
187
+ HELD = HELD === null ? views : HELD || views;
188
+ if (HELD !== null && !paint.wait) paint.wait = setInterval(() => { if (pickerOpen()) return; clearInterval(paint.wait); paint.wait = 0; const v = HELD; HELD = null; paint(v); }, 120);
189
+ return;
190
+ }
191
+ for (const s of SOURCES) if (s.redraw) { try { s.redraw(); } catch { /* the next read draws it */ } }
192
+ if (!views) return;
193
+ for (const [el, fn] of [...VIEWS]) {
194
+ if (el && typeof el === 'object' && 'isConnected' in el && !el.isConnected) { VIEWS.delete(el); continue; }
195
+ try { fn(); } catch { /* the next read draws it */ }
196
+ }
197
+ }
198
+
199
+ /** A write is about to be sent. null when it is not a task write. */
200
+ export function begin(path, body) {
201
+ const ops = opsOf(path, body);
202
+ if (!ops) return null;
203
+ const entries = ops.map((op) => { const e = { op, saved: 0 }; PENDING.set(++seq, e); return [seq, e]; });
204
+ const steps = ops.flatMap((op) => apply(op));
205
+ if (steps.length) paint();
206
+ return {
207
+ ok(at) { const t = at || Date.now(); for (const [, e] of entries) e.saved = t; },
208
+ fail() {
209
+ for (const [k] of entries) PENDING.delete(k);
210
+ // only a copy still showing this change goes back: a newer read or a newer change is left as it is
211
+ let back = 0;
212
+ for (const undo of steps.reverse()) back += undo();
213
+ if (back) paint();
214
+ },
215
+ };
216
+ }
217
+
218
+ /** A page read its data again (since: when that read started; stale: the server said a press is still being folded in). */
219
+ export function loaded({ since = 0, stale = false } = {}) {
220
+ let n = 0;
221
+ for (const [k, e] of [...PENDING]) {
222
+ // a read that started after the save landed, and is not stale, holds the saved value itself
223
+ if (e.saved && !stale && since >= e.saved) { PENDING.delete(k); continue; }
224
+ // a saved new task may already be in the read under its real id: its stand-in is not drawn twice
225
+ if (e.op.kind === 'add' && e.saved) continue;
226
+ n += apply(e.op).length;
227
+ }
228
+ // the page drew the read already; it draws again only when a change still saving was put back on it
229
+ if (n) { paint(); return; }
230
+ for (const [el, fn] of [...VIEWS]) {
231
+ if (el && typeof el === 'object' && 'isConnected' in el && !el.isConnected) { VIEWS.delete(el); continue; }
232
+ try { fn(); } catch { /* the next read draws it */ }
233
+ }
234
+ }
235
+
236
+ /** The one line a page shows when a save did not land: the change is already back as it was. Plain words; the server's reason when it
237
+ * gave one. */
238
+ export function notSaved(res) {
239
+ const why = res && typeof res.error === 'string' && res.error.trim() ? res.error.trim().replace(/[.\s]+$/, '') : 'the workspace did not answer';
240
+ return 'Not saved, so it is back as it was: ' + why + '.';
241
+ }
242
+
243
+ /** Watch the page's fetch: a POST of a task write begins before it is sent, and ok() or fail() follows the answer (a refused answer, a
244
+ * body with ok:false, or no answer at all). The answer itself is handed back untouched; its body is read from a clone. */
245
+ export function install(g = globalThis) {
246
+ if (!g || typeof g.fetch !== 'function' || g.fetch.__liveEdit) return false;
247
+ const real = g.fetch;
248
+ const watched = async function (input, init) {
249
+ let le = null;
250
+ try {
251
+ const url = typeof input === 'string' ? input : input && input.url;
252
+ const method = String((init && init.method) || (input && typeof input === 'object' && input.method) || 'GET').toUpperCase();
253
+ if (method === 'POST' && url && init && typeof init.body === 'string') {
254
+ const p = new URL(url, 'http://x').pathname;
255
+ if (TASK_WRITE.test(p)) le = begin(p, JSON.parse(init.body));
256
+ }
257
+ } catch { le = null; }
258
+ if (!le) return real.call(this, input, init);
259
+ let res;
260
+ try { res = await real.call(this, input, init); } catch (e) { le.fail(); throw e; }
261
+ // a 403 (a stale nonce) is put back at once: pressFetch sends the press again, and that send begins on its own
262
+ if (res.status === 403) { le.fail(); return res; }
263
+ // landed now: the caller reads again as soon as it has the answer, and that read must count as after the save
264
+ const at = Date.now();
265
+ let body = null; try { body = await res.clone().json(); } catch { body = null; }
266
+ if (!res.ok || !body || body.ok === false) le.fail(); else le.ok(at);
267
+ return res;
268
+ };
269
+ watched.__liveEdit = true;
270
+ g.fetch = watched;
271
+ return true;
272
+ }
273
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') install(window);
274
+
275
+ export function source(s) { SOURCES.add(s); return () => SOURCES.delete(s); }
276
+ export function view(el, redraw) { VIEWS.set(el, redraw); return () => { if (VIEWS.get(el) === redraw) VIEWS.delete(el); }; }
277
+ /** The task ids with a change still on the pages (tests). */
278
+ export const pending = () => new Map([...PENDING.values()].map((e) => [e.op.id || e.op.ini, e]));
279
+ /** Tests only: forget every source, view and pending write. */
280
+ export function reset() { SOURCES.clear(); VIEWS.clear(); PENDING.clear(); HELD = null; if (paint.wait) { clearInterval(paint.wait); paint.wait = 0; } }
@@ -20,6 +20,7 @@
20
20
  import './fetch-share.js'; // first: identical GETs in flight are asked once (page-open-speed)
21
21
  import * as WK from './work-kind.js'; // the kind of work before each title (batch 29 item 11, KdBd)
22
22
  import { pmPost } from './http.js';
23
+ import * as LE from './live-edit.js'; // a task's status or days show at once (the save answers later; a failed save is put back)
23
24
  import { followDoc } from './doc-follow.js';
24
25
  import { $, $$, esc, store, chatAbout, setPageGaps } from './premium-shell.js';
25
26
  import * as PK from './cozy-pick.js';
@@ -221,8 +222,8 @@ function closePanel() {
221
222
  /* ── the toast: the Agreed design's dark pill ─────────────────────────────────────────────────────────────────────────────── */
222
223
  let toastT = null;
223
224
  /** The toast; with `undo`, an Undo button that runs it once (the write's opposite, through the same route). */
224
- function say(msg, undo) {
225
- const t = $('#bdToast'); t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="bd-undo">Undo</button>' : ''}`; t.hidden = false;
225
+ function say(msg, undo, label = 'Undo') {
226
+ const t = $('#bdToast'); t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="bd-undo">' + esc(label) + '</button>' : ''}`; t.hidden = false;
226
227
  const u = t.querySelector('.bd-undo'); if (u) u.onclick = () => { u.disabled = true; t.hidden = true; undo(); };
227
228
  clearTimeout(toastT); toastT = setTimeout(() => { t.hidden = true; }, undo ? 10000 : 5000);
228
229
  }
@@ -1428,7 +1429,10 @@ async function readAll(q) {
1428
1429
  if (lost.length) { model.header.missing = [...model.header.missing, ...lost]; model.header.text += (/not read: /.test(model.header.text) ? ', ' : ' · not read: ') + lost.join(', '); }
1429
1430
  return { r: { ok: true, model, stale: got.some((g) => g.r && g.r.stale) || h.r.stale }, status: 200 };
1430
1431
  }
1432
+ /* the Board's copy of every task, drawn again the moment a task write is sent (pm/live-edit.js), before the board is read again */
1433
+ LE.source({ model: () => M, redraw: () => { if (!M) return; drawInit(); if (peek && peek.kind === 'ini') BI.refresh(true); } });
1431
1434
  async function load() {
1435
+ const since = Date.now();
1432
1436
  // while the board is read (the pick's default board, then the picked ones) the page says so and shows no row instead of a guess
1433
1437
  const reading = () => {
1434
1438
  const t0 = Date.now(), tick = () => { const s = 'Reading the board · ' + Math.round((Date.now() - t0) / 1000) + ' s so far'; $('#snap').textContent = s; if (!M && !$('#ibBody .ls-bd')) { $('#ibBody').innerHTML = SKEL; LS.slowLine($('#ibBody'), () => M); } };
@@ -1449,6 +1453,7 @@ async function load() {
1449
1453
  }
1450
1454
  M = r.model; readTries = 0; jiraReading = false; holdNames(); draw();
1451
1455
  readChanges();
1456
+ LE.loaded({ since, stale: !!r.stale }); // a change still saving stays on the new read; open views (the big Work breakdown) follow it
1452
1457
  STRAT.refresh($('#cStrat'), { ws: M.board.ws || null, board: M.board.id || null, single: !ALL, say });
1453
1458
  PRIN.refresh($('#cPrin'), { ws: M.board.ws || null, single: !ALL, say });
1454
1459
  focusOnce(); programOnce(); newOnce(); loadOthers(); loadWorkflows();
@@ -1475,7 +1480,8 @@ async function loadWorkflows() {
1475
1480
  async function setTask(r, uid, state, w) {
1476
1481
  const k = (r.tasks || []).find((x) => x.uid === uid), body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, task: uid }, happened = (w && w.happened) || null;
1477
1482
  const res = await pmPost('/api/boards/tasks/state', { ...body, state, ...(happened ? { happened } : {}) }).catch(() => null);
1478
- if (!res || res.ok === false) { say((res && res.error) || 'Nothing was changed.'); return; }
1483
+ // the new status showed at once (pm/live-edit.js); a save that did not land is back as it was, and the toast says so with Try again
1484
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => setTask(r, uid, state, w), 'Try again'); return; }
1479
1485
  // a breakdown item closed as Won't do is withdrawn, which the ledger cannot undo; every other change can go back (batch 9 item 5b)
1480
1486
  const undo = k && k.status !== state && !(k.item && state === "Won't do");
1481
1487
  // the day it really happened is said too (round 3 point 18): "Done on 14 Nov, noted today: <title>."
@@ -1487,7 +1493,7 @@ async function setTask(r, uid, state, w) {
1487
1493
  async function setDates(r, uid, patch) {
1488
1494
  const k = (r.tasks || []).find((x) => x.uid === uid), body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, task: uid };
1489
1495
  const res = await pmPost('/api/boards/tasks/edit', { ...body, ...patch }).catch(() => null);
1490
- if (!res || res.ok === false) { say((res && res.error) || 'Nothing was changed.'); return; }
1496
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => setDates(r, uid, patch), 'Try again'); return; }
1491
1497
  const ms = 'milestone' in patch;
1492
1498
  const back = {}; for (const f of Object.keys(patch)) back[f] = f === 'milestone' ? (res.from && 'milestone' in res.from ? !!res.from.milestone : !patch.milestone) : k ? (f === 'due' ? k.end : k[f]) || '' : res.from && f in res.from ? res.from[f] || '' : ''; // a Jira ticket's days come back in from (batch 11 item 23)
1493
1499
  const words = ms ? (patch.milestone ? 'Milestone' : 'Not a milestone') : 'Dates saved';
@@ -1499,7 +1505,7 @@ async function setDates(r, uid, patch) {
1499
1505
  async function removeTask(r, uid) {
1500
1506
  const k = (r.tasks || []).find((x) => x.uid === uid), body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, task: uid };
1501
1507
  const res = await pmPost('/api/boards/tasks/delete', body).catch(() => null);
1502
- if (!res || res.ok === false) { say((res && res.error) || 'The task was not deleted.'); return; }
1508
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => removeTask(r, uid), 'Try again'); return; } // the row went at once and is back
1503
1509
  say('Deleted · ' + (k ? k.title : uid) + '.', async () => { const u = await pmPost('/api/boards/tasks/restore', body).catch(() => null); if (!u || u.ok === false) say((u && u.error) || 'The undo did not land.'); load(); });
1504
1510
  load();
1505
1511
  }
@@ -1555,7 +1561,7 @@ async function addTask(r, title, section, dates, name) {
1555
1561
  // dates: a gap's + (batch 11 item 13) fills the task's start and due with the gap's days ahead; section: the stage it goes under (the
1556
1562
  // add route places it, batch 18 item 16); the add field's chips also send milestone and owner in it (batch 25 item 5)
1557
1563
  const res = await pmPost('/api/boards/tasks/add', { ...body, initiative: r.id, title, ...(dates && dates.start ? { start: dates.start } : {}), ...(dates && dates.due ? { due: dates.due } : {}), ...(dates && dates.milestone ? { milestone: true } : {}), ...(dates && dates.owner ? { owner: dates.owner } : {}), ...(section ? { section } : {}) }).catch(() => null);
1558
- if (!res || res.ok === false) { say((res && res.error) || 'The task was not added.'); return false; }
1564
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => addTask(r, title, section, dates, name), 'Try again'); return false; } // the row showed at once (pm/live-edit.js) and is gone again
1559
1565
  const uid = res.item && res.item.uid;
1560
1566
  // the + on a stage (batch 18 item 16, StA5Add): "Added to Build" with Undo
1561
1567
  if (name && uid) say('Added to ' + name + '.', async () => { const u = await pmPost('/api/boards/tasks/delete', { ...body, task: uid, why: 'undo of add' }).catch(() => null); if (!u || u.ok === false) say((u && u.error) || 'The undo did not land.'); load(); });
@@ -224,6 +224,19 @@ async function pure() {
224
224
  ok('D4 the second tap sets the due day and closes the picker', await until(() => last(A, '/api/boards/tasks/edit').body.due === '2026-11-01') && await until(() => p.evaluate((c) => !document.querySelector(c + ' .tkc-dp'), C)));
225
225
  await p.click(C + ' [data-tkc="dates"]');
226
226
  await until(() => p.evaluate((c) => !!document.querySelector(c + ' .tkc-dp'), C));
227
+ // the keys: one day of the grid takes the focus (the start), the arrows move it, Enter picks it
228
+ await p.focus(C + ' .tkc-dp .rp-g [tabindex="0"]');
229
+ const kf = await p.evaluate(() => (document.activeElement || {}).dataset && document.activeElement.dataset.rpDay);
230
+ await p.keyboard.press('ArrowLeft'); await p.keyboard.press('ArrowUp');
231
+ const km = await p.evaluate(() => (document.activeElement || {}).dataset && document.activeElement.dataset.rpDay);
232
+ await p.keyboard.press('Enter');
233
+ ok('D4 the keys: the start day has the focus, the arrows move it a day and a week, Enter sets the start and the due day is next', kf === '2026-10-31' && km === '2026-10-23'
234
+ && await until(() => last(A, '/api/boards/tasks/edit').body.start === '2026-10-23') && await until(() => p.evaluate((c) => { const e = document.querySelector(c + ' .tkc-dp [data-rp-end="due"]'); return !!e && e.classList.contains('on'); }, C)), JSON.stringify({ kf, km, last: last(A, '/api/boards/tasks/edit') }));
235
+ // typing: a day written in an end's field, then Enter, sets that end
236
+ await p.fill(C + ' .tkc-dp [data-rp-end="due"] .rp-in', '5 Nov'); await p.keyboard.press('Enter');
237
+ ok('D4 a day typed in Due ("5 Nov") and Enter sets the due day and closes the picker', await until(() => last(A, '/api/boards/tasks/edit').body.due === '2026-11-05') && await until(() => p.evaluate((c) => !document.querySelector(c + ' .tkc-dp'), C)), JSON.stringify(last(A, '/api/boards/tasks/edit')));
238
+ await p.click(C + ' [data-tkc="dates"]');
239
+ await until(() => p.evaluate((c) => !!document.querySelector(c + ' .tkc-dp'), C));
227
240
  await p.mouse.click(5, 5);
228
241
  ok('D4 a press outside closes the picker', await until(() => p.evaluate((c) => !document.querySelector(c + ' .tkc-dp'), C)));
229
242
  // owner
@@ -339,6 +352,9 @@ async function pure() {
339
352
  await p.click(C + ' [data-tkc="dates"]');
340
353
  const dp = await until(() => p.evaluate((c) => { const pop = document.querySelector(c + ' .tkc-dp'); if (!pop) return null; const r = pop.getBoundingClientRect(); return r.right <= innerWidth + 1 && r.left >= -1; }, C));
341
354
  ok('D12 the picker stays on the screen', dp === true);
355
+ // on a phone the days are thumb-sized: each day's mark at least 42 px, the grid with no sideways scroll
356
+ const ph = await p.evaluate((c) => { const d = [...document.querySelectorAll(c + ' .tkc-dp .rp-g .rp-d span')]; const r = d.map((x) => x.getBoundingClientRect()); return { n: d.length, w: Math.min(...r.map((x) => x.width)), h: Math.min(...r.map((x) => x.height)), over: document.documentElement.scrollWidth > innerWidth + 1 }; }, C);
357
+ ok('D12 the phone: every day is at least 42 px, and nothing scrolls sideways', ph.n >= 28 && ph.w >= 42 && ph.h >= 42 && !ph.over, JSON.stringify(ph));
342
358
  await shot(p, 'task-phone-390-dark');
343
359
  ok('D12 the page raised no error', A.errors.length === 0, A.errors.join(' | '));
344
360
  await A.ctx.close();
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Every edit shows at once on the workspace, and a failed save says so (initiative edits-show-at-once, done test C1-C8): the pure module public/pm/live-edit.js and a read of the page code. No server, browser or network.",
3
+ "modules": [
4
+ "live-edit.test.js"
5
+ ],
6
+ "seconds": {
7
+ "live-edit.test.js": 1
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Initiative search-answers-questions: a question typed in Search gets a short answer written from passages of the user's files, with its sources. The passages, the route and the silence run in node with a made-up session; the row in pm/cozy-search.js has no browser test (TESTS rule: no new browser tests).",
3
+ "modules": [
4
+ "search-ask.test.js"
5
+ ],
6
+ "seconds": {
7
+ "search-ask.test.js": 2
8
+ }
9
+ }