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.
@@ -21,6 +21,7 @@ import * as M from './pop-work-model.js';
21
21
  import * as CB from './cozy-bar.js';
22
22
  import { openPop, closePop, undoToast } from './hi-pop.js';
23
23
  import { pmGet, pmPost } from './http.js';
24
+ import * as LE from './live-edit.js'; // an edit shows at once: this popup is drawn again the moment a task write is sent, and after each read
24
25
  import * as VW from './cozy-viewer.js';
25
26
  import * as ED from './ini-edit.js';
26
27
  import * as SW from './cozy-status-when.js'; // When did this happen? after a status pick (round 3 point 18)
@@ -123,7 +124,7 @@ function critSugHtml(cr) {
123
124
  return `<div class="pm-sug x" role="group" aria-label="PMOS suggests"><div class="ttl">${SVG(P.spark || P.dia, 14)}<b class="say">${esc(say)}</b></div>`
124
125
  + `<dl><dt>Why</dt><dd>${esc('The people who build these tickets do not see the done test. Each check goes on the ticket it fits, as Given / When / Then.')}</dd>`
125
126
  + `<dt>PMOS will</dt><dd><ul>${will.map((w) => `<li>${esc(w)}</li>`).join('')}</ul></dd><dt>Tickets</dt><dd><ul>${L.map(row).join('')}</ul></dd></dl>`
126
- + `<div class="ans"><button type="button" class="pm-btn primary" data-pw-crit-ok aria-label="Yes, do it" title="Yes, do it">${SVG(P.check, 14)}</button>`
127
+ + `<div class="ans"><button type="button" class="pm-btn primary" data-pw-crit-ok aria-label="Yes, do it" title="Yes, do it">${SVG(PD.I.ok, 14)}</button>`
127
128
  + `<button type="button" class="pm-btn outline" data-pw-crit-drop aria-label="No" title="No">${SVG(P.x, 14)}</button></div></div>`;
128
129
  }
129
130
  /* the goal's name, not its id (board 25: "De-risk Okta dependency", not KR-C4): GET /api/boards/anchors once per product */
@@ -149,7 +150,7 @@ function artOf(id, ws) {
149
150
  if (!ART.has(id)) {
150
151
  ART.set(id, null);
151
152
  pmGet('/api/artefacts?scope=' + encodeURIComponent('experiment:' + id) + (ws ? '&ws=' + encodeURIComponent(ws) : ''))
152
- .then((x) => { ART.set(id, x && x.ok && Array.isArray(x.artefacts) ? x.artefacts : []); if (artRedraw) artRedraw(); }).catch(() => ART.set(id, []));
153
+ .then((x) => { ART.set(id, x && x.ok && Array.isArray(x.artefacts) ? x.artefacts : []); const p = PEND.get(id); if (p && !p.saving) p.lines = {}; if (artRedraw) artRedraw(); }).catch(() => ART.set(id, []));
153
154
  }
154
155
  return ART.get(id);
155
156
  }
@@ -336,10 +337,17 @@ const mergeOf = (rows) => AK.group(rows, { dropped: dropped() }).merge;
336
337
 
337
338
  /* ── the initiative ── */
338
339
  const keyOf = (v, o) => String((o && o.id) || (v && (v.id || v.key)) || '');
339
- function model(r, v, o) {
340
- const id = keyOf(v, o), S = stOf(id), it = ITEMS.get(id);
340
+ /* a case line or the summary shows the moment it is saved (Wawan, 2026-11-23: every edit shows at once): id → { lines: { lineId: text },
341
+ * desc }. A line stays until the artefacts are read again; the summary until the host reads the initiative again. A save that fails takes
342
+ * it out and says so with Try again. */
343
+ const PEND = new Map();
344
+ const pendOf = (id) => { if (!PEND.has(id)) PEND.set(id, { lines: {}, desc: null }); return PEND.get(id); };
345
+ function model(r, v0, o) {
346
+ const id0 = keyOf(v0, o), pd = PEND.get(id0), v = pd && pd.desc != null ? { ...v0, desc: pd.desc } : v0;
347
+ const id = id0, S = stOf(id), it = ITEMS.get(id);
341
348
  const g = o.goal || goalOf(o.ws, o.board, r.anchor || v.anchor);
342
349
  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() });
350
+ if (pd && W.overview) for (const L of W.overview.lines || []) if (pd.lines[L.id] != null) { L.text = pd.lines[L.id]; delete L.ask; delete L.miss; }
343
351
  const mk = M.marksOf(W.span, W.today); W.tx = mk.today;
344
352
  W.epics = (r.epics || []).filter(Boolean); RSEL = S.sel; // the epic check and the picked rows, for the Gantt rows (initiative work-subtasks)
345
353
  // the Gantt's Jira column (work-subtasks-followups): on unless Choose columns hides it, and only when the work has a Jira row
@@ -600,15 +608,18 @@ async function dropSug(s, x, h) {
600
608
  if (h.reload) await h.reload();
601
609
  }
602
610
  async function saveDesc(text, x, h) {
603
- const w = h.where ? h.where() : {}, id = x.o().id;
611
+ const w = h.where ? h.where() : {}, id = x.o().id, kid = keyOf(x.v(), x.o());
612
+ // shown at once; the host's read after the save replaces it
613
+ const pd = pendOf(kid); pd.desc = text; if (h.redraw) h.redraw();
604
614
  const res = await pmPost('/api/initiative/describe', { ws: w.ws, id, text }).catch(() => null);
605
- if (!res || res.ok === false) { if (h.toast) h.toast((res && res.error) || 'It was not saved.'); return false; }
615
+ if (!res || res.ok === false) { pd.desc = null; if (h.redraw) h.redraw(); undoToast(LE.notSaved(res), () => saveDesc(text, x, h), 12000, 'Try again'); return false; }
616
+ const settle = async () => { if (h.reload) await h.reload(); if (pd.desc === text) { pd.desc = null; if (h.redraw) h.redraw(); } };
606
617
  if (!res.same) undoToast('Saved.', async () => {
607
618
  const u = await pmPost('/api/initiative/describe-undo', { ws: w.ws, id, from: res.from || '', to: res.text }).catch(() => null);
608
619
  if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
609
620
  if (h.reload) await h.reload();
610
621
  });
611
- if (h.reload) await h.reload();
622
+ await settle();
612
623
  return true;
613
624
  }
614
625
  const findSug = (W, id) => W.suggests.find((s) => s.id === id) || [...W.rowSuggests.values()].find((s) => s.id === id) || null;
@@ -626,6 +637,7 @@ export function wire(body, h0, x0) {
626
637
  body.__pw = true;
627
638
  function cur() { const x = body.__pwx, r = x && x.r(), v = x && x.v(); return r && v ? { r, v, ...model(r, v, x.o()) } : null; }
628
639
  function redraw() { if (body.__pwh && body.__pwh.redraw) body.__pwh.redraw(); }
640
+ LE.view(body, () => { if (body.querySelector('.pw')) redraw(); });
629
641
  goalsRedraw = artRedraw = wsnRedraw = () => { if (body.isConnected && body.querySelector('.pw')) redraw(); };
630
642
  wireGrip(body);
631
643
  // 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)
@@ -758,7 +770,13 @@ function big(c, x, h) {
758
770
  if (hide) hide.click();
759
771
  VW.drill();
760
772
  VW.open({ kind: 'Work breakdown', title: 'Work breakdown', icon: 'list', id: 'wbs:' + c.id, back: true,
761
- render: (b) => { b.dataset.pwBig = '1'; const o = x.o(); S.big = true; b.innerHTML = html(x.r(), x.v(), o); wire(b, { ...h, redraw: () => { const t = b.scrollTop; b.innerHTML = html(x.r(), x.v(), x.o()); b.scrollTop = t; } }, x); },
773
+ render: (b) => {
774
+ b.dataset.pwBig = '1'; const o = x.o(); S.big = true; b.innerHTML = html(x.r(), x.v(), o);
775
+ const again = () => { if (!S.big || !b.isConnected || !x.r() || !x.v()) return; const t = b.scrollTop; b.innerHTML = html(x.r(), x.v(), x.o()); b.scrollTop = t; };
776
+ // the host draws its own popup body after a write and a read, never this drill-in: wire() puts it in pm/live-edit.js, so it follows
777
+ // the same writes and reads (Wawan, 2026-11-23: a status or day changed here showed only after the popup was opened again)
778
+ wire(b, { ...h, redraw: again }, x);
779
+ },
762
780
  onClose: () => { S.big = false; if (hid) { const ask = document.querySelector('.cz-pop [data-pop="ask"]'); if (ask && !ask.closest('[hidden]')) ask.click(); } } });
763
781
  void title;
764
782
  }
@@ -820,9 +838,17 @@ function editLine(el, L, c, x, h) {
820
838
  }
821
839
  async function saveLine(L, text, x, h) {
822
840
  if (L.edit.to === 'desc') return saveDesc(text, x, h);
823
- const w = h.where ? h.where() : {}, o = x.o(), id = o.id, ws = w.ws || o.ws;
841
+ const w = h.where ? h.where() : {}, o = x.o(), id = o.id, ws = w.ws || o.ws, kid = keyOf(x.v(), o);
842
+ // shown at once (Wawan, 2026-11-23); the next read of the artefacts replaces it
843
+ const pd = pendOf(kid); pd.lines[L.id] = text; pd.saving = (pd.saving || 0) + 1; if (h.redraw) h.redraw();
824
844
  const res = await pmPost('/api/artefacts/set', { ws, scope: 'experiment:' + id, artefact: L.edit.artefact, field: L.edit.field, text }).catch(() => null);
825
- if (!res || res.ok === false || !res.line) { if (h.toast) h.toast((res && res.error) || 'It was not saved.'); return false; }
845
+ pd.saving--;
846
+ if (!res || res.ok === false || !res.line) {
847
+ if (pd.lines[L.id] === text) delete pd.lines[L.id];
848
+ if (h.redraw) h.redraw();
849
+ undoToast(LE.notSaved(res && res.ok !== false && !res.line ? { error: 'the line was not written' } : res), () => saveLine(L, text, x, h), 12000, 'Try again');
850
+ return false;
851
+ }
826
852
  const ref = res.line.id;
827
853
  ART.delete(id);
828
854
  undoToast(L.k + ' saved.', async () => {
@@ -8,6 +8,9 @@
8
8
  * Esc closes. On a phone it is the whole screen.
9
9
  * Above everything, when the words clearly point to one thing, one answer: a sentence copied from the user's own files, with its source
10
10
  * and the check date when it is an initiative (search-answers-first, lib/search-answer.js). ↵ on it opens the source. No answer: no row.
11
+ * A question with no such sentence (search-answers-questions): the first row says "Finding an answer in your work…" while
12
+ * GET /api/search-ask runs (one read-only PMOS session answers from passages of the user's files, lib/search-ask.js), then shows that
13
+ * answer and the files it came from. "Ask PMOS" stays the next row, to go deeper. No answer: the row goes away.
11
14
  * openSearch({ go?, q?, scope? }) go: the page's own opener ({ ini } | { ses } | { doc }), used before a page change
12
15
  * scope: the page Search opens from (UI grill U2: one search; the Board's and Intelligence's own find boxes are gone). { name, hits(q) }
13
16
  * where hits returns [{ label, rows: [{ id?, title, sub?, tag?, icon?, open() }] }]: the page's own groups, drawn first ("On this Board ·
@@ -25,8 +28,11 @@ import { adler } from './cozy-adler.js'; // session names A: the PM's name win
25
28
 
26
29
  const PHONE = 760;
27
30
  const isPhone = () => innerWidth <= PHONE;
28
- const S = { el: null, q: '', kind: 'all', scope: null, at: 0, rows: [], res: null, busy: false, err: '', wt: null, back: null, go: null, seq: 0, boards: null, sessions: null, t: 0 };
31
+ const S = { ask: null, el: null, q: '', kind: 'all', scope: null, at: 0, rows: [], res: null, busy: false, err: '', wt: null, back: null, go: null, seq: 0, boards: null, sessions: null, t: 0 };
29
32
  const KIND_ICON = { initiative: ICON.flag, document: ICON.doc, slides: ICON.slides, report: ICON.report, artifact: ICON.design, file: ICON.file, meeting: ICON.meet, session: ICON.session };
33
+ /** A question: it ends with "?" or starts with a question word, and has 3 words or more (the same rule as lib/search-ask.js isQuestion). */
34
+ const QW = /^\s*(why|how|what|whats|what's|who|whom|whose|when|where|which|is|are|was|were|do|does|did|can|could|should|would|will|has|have|had)\b/i;
35
+ const isQuestion = (q) => String(q || '').trim().split(/\s+/).filter(Boolean).length >= 3 && (/\?\s*$/.test(String(q).trim()) || QW.test(q));
30
36
  async function getj(p) { try { const r = await fetch(p, { credentials: 'same-origin' }); const j = await r.json().catch(() => null); return j || { ok: false, error: 'the server did not answer' }; } catch { return { ok: false, error: 'the server did not answer' }; } }
31
37
 
32
38
  function mount() {
@@ -92,6 +98,13 @@ async function run() {
92
98
  S.busy = false;
93
99
  if (!r.ok) { S.err = r.error || 'the server did not answer'; draw(); return; }
94
100
  S.res = r; draw();
101
+ // search-answers-questions: a question the copied sentence did not answer gets an answer written from the user's own files
102
+ if (!r.answer && isQuestion(q) && !(S.ask && S.ask.q === q)) {
103
+ S.ask = { q, busy: true, answer: null }; draw();
104
+ const a = await getj('/api/search-ask?q=' + encodeURIComponent(q) + wsQ('&'));
105
+ if (!S.ask || S.ask.q !== q) return;
106
+ S.ask = { q, busy: false, answer: a && a.ok && a.answer && a.answer.source ? a.answer : null }; draw();
107
+ }
95
108
  }
96
109
 
97
110
  /** Every row the palette shows for the query: the search's results, the board's initiatives and the sessions that match, each once. */
@@ -145,8 +158,11 @@ function drawList() {
145
158
  const groups = own.concat(searchGroups(rows, { phone: isPhone() }));
146
159
  const ask = q.length >= 2 ? { kind: 'ask', title: q } : null;
147
160
  // search-answers-first: the answer, with its source, is the first row; only for the words it answered and on All
148
- const A = S.res && S.res.answer && S.kind === 'all' && q.length >= 2 && String(S.res.q || '').trim() === q ? S.res.answer : null;
161
+ const A0 = S.res && S.res.answer && S.kind === 'all' && q.length >= 2 && String(S.res.q || '').trim() === q ? S.res.answer : null;
162
+ const made = !A0 && S.kind === 'all' && S.ask && S.ask.q === q ? S.ask : null; // search-answers-questions: the written answer, or its wait
163
+ const A = A0 || (made && made.answer);
149
164
  const ansRow = A && A.source ? { kind: 'answer', answer: A } : null;
165
+ const waiting = !ansRow && made && made.busy;
150
166
  // chief-of-staff C5: the one chat is the first row of Search; a page's own find (U2 scope) keeps its own hits first, then the chat
151
167
  const ownRows = own.flatMap((g) => g.rows);
152
168
  S.rows = (ansRow ? [ansRow] : []).concat(ownRows, ask ? [ask] : [], groups.slice(own.length).flatMap((g) => g.rows));
@@ -154,6 +170,7 @@ function drawList() {
154
170
  let h = '', i = 0;
155
171
  const askHtml = () => `<button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}">${svg(ICON.chat, 18)}<span class="ev-t">Ask PMOS: <b>“${esc(q)}”</b></span><span class="ev-k">${onHome() ? 'In the chat' : 'Opens the chat here'}</span></button>`;
156
172
  if (ansRow && !S.err) { h += answerHtml(ansRow.answer, i); i++; }
173
+ else if (waiting && !S.err) h += `<p class="ev-sp-empty" role="status">Finding an answer in your work…</p>`;
157
174
  // the page's own groups first (UI grill U2): what Search itself could not read is said after them
158
175
  own.forEach((g) => { h += `<p class="ev-mlbl">${esc(g.label)}</p>` + g.rows.map((r) => rowHtml(r, i++)).join(''); });
159
176
  if (ask) { h += askHtml(); i++; }
@@ -182,7 +199,9 @@ const dayOf = (iso) => { const d = new Date(String(iso) + 'T00:00:00'); return i
182
199
  function answerHtml(a, i) {
183
200
  const src = a.source, kind = { initiative: 'initiative', document: 'document', report: 'report', slides: 'slides' }[src.kind] || 'file';
184
201
  const facts = (a.facts || []).filter((f) => f.key === 'check' && dayOf(f.date)).map((f) => 'Check ' + dayOf(f.date));
185
- const from = 'From ' + (src.title || src.path) + ' (' + kind + (src.main === false ? ', draft in ' + (src.branch || src.wt) : '') + ')';
202
+ const from = a.made && Array.isArray(a.sources) && a.sources.length
203
+ ? 'From ' + a.sources.map((x) => x.title || x.path).join(', ') // written from these files (search-answers-questions)
204
+ : 'From ' + (src.title || src.path) + ' (' + kind + (src.main === false ? ', draft in ' + (src.branch || src.wt) : '') + ')';
186
205
  // the plain wrapper keeps the row as tall as its lines: the list is a flex column and would squeeze the button to its min-height
187
206
  return `<div role="none"><button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}" aria-label="${esc(a.text + ' ' + facts.concat(from).join(' · '))}">${svg(KIND_ICON[src.kind] || ICON.doc, 18)}<span><b>${esc(a.text)}</b><br><span class="ev-small ev-mut">${esc(facts.concat(from).join(' · '))}</span></span></button></div>`;
188
207
  }
@@ -116,7 +116,7 @@ button.td-ev:focus-visible { outline: none; box-shadow: var(--glow); }
116
116
  .tdp-rec i { width: 9px; height: 9px; border-radius: 50%; background: var(--cz-dot-red); }
117
117
  /* Today's log */
118
118
  .tdp-lh { display: flex; align-items: center; justify-content: space-between; gap: var(--space-12); padding: 18px 0 10px; border-bottom: 1px solid var(--cz-hair); }
119
- .tdp-lh h2 { font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: .08em; text-transform: uppercase; color: var(--cz-ink2); line-height: var(--lh-label); }
119
+ .tdp-lh h2, .tdp-gh { font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: .08em; text-transform: uppercase; color: var(--cz-ink2); line-height: var(--lh-label); }
120
120
  .tdp-f { position: relative; display: inline-flex; align-items: center; gap: 2px; color: var(--cz-ink3); }
121
121
  .tdp-f select { appearance: none; -webkit-appearance: none; border: 0; background: none; font: inherit; font-size: var(--fs-row); color: var(--cz-ink3); padding: 6px 18px 6px 6px; min-height: 36px; text-align: right; }
122
122
  .tdp-f svg { position: absolute; right: 0; pointer-events: none; }
@@ -176,8 +176,8 @@ button.td-ev:focus-visible { outline: none; box-shadow: var(--glow); }
176
176
  }
177
177
  /* open-questions-today (A420, board QuestionsA): the Decide tab's two groups; the line under a row says what PMOS does if nobody answers */
178
178
  .oq-r .oq-u { display: flex; align-items: flex-start; gap: var(--space-4); }
179
- .oq-r .oq-u .pm-ic { flex: none; margin-top: 2px; }
179
+ .oq-r .oq-u .pm-ic { flex: none; margin-top: calc(var(--space-4) / 2); }
180
180
  @media (max-width: 760px) {
181
- .tdp-gh { padding: 18px 0 10px; font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: .08em; text-transform: uppercase; color: var(--cz-ink2); line-height: var(--lh-label); }
181
+ .tdp-gh { padding: var(--space-16) 0 var(--space-8); }
182
182
  .tdp-m.oq-u.d { color: var(--cz-blueink); }
183
183
  }
@@ -50,11 +50,11 @@ export function openPop(anchor, kind, html, onClick, o = {}) {
50
50
  const f = el.querySelector((sheet && o.sheetFocus) || o.focus || 'input, textarea, button:not([disabled])'); if (f) setTimeout(() => f.focus(), 0);
51
51
  return el;
52
52
  }
53
- export function undoToast(text, undo, ms = 9000) {
53
+ export function undoToast(text, undo, ms = 9000, label = 'Undo') {
54
54
  ensureCss();
55
55
  let el = document.getElementById('hiToast');
56
56
  if (!el) { el = document.createElement('div'); el.id = 'hiToast'; el.className = 'hi-toast'; el.setAttribute('role', 'status'); el.setAttribute('aria-live', 'polite'); document.body.appendChild(el); }
57
- el.innerHTML = `<span>${esc(text)}</span><button type="button" data-hi-undo>Undo</button>`;
57
+ el.innerHTML = `<span>${esc(text)}</span><button type="button" data-hi-undo>${esc(label)}</button>`;
58
58
  el.hidden = false; el.classList.add('on');
59
59
  el.querySelector('[data-hi-undo]').onclick = () => { hide(); undo(); };
60
60
  const hide = () => { el.classList.remove('on'); el.hidden = true; };
@@ -30,6 +30,7 @@ import * as POP from './cozy-popup.js'; // the one popup: an initiative and As
30
30
  import { mountToday } from './cozy-today-app.js'; // Today on a desk (slice 5): today.html is this page with data-today
31
31
  import * as SV from './small-vw.js'; // the small Viewers: a stakeholder, its form, a routine (batch 18 item 2-C)
32
32
  import { pmGet, pmPost, pmHeaders } from './http.js';
33
+ 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)
33
34
  import * as ST from './story.js';
34
35
  import * as IT from './intent.js'; // board AwI: the Intent card under the story
35
36
  import * as H from './home-data.js';
@@ -205,8 +206,10 @@ async function getRetry(path, tries = 20) {
205
206
  }
206
207
  const LAST_KEY = (WS || '') + '|' + (BOARD || ''); // the last view Home drew, by its product and board (SpA)
207
208
  let pickGen = 0; // bumped by every saved pick, so a read that started before the save does not put the old pick back
209
+ /* Home's copy of every task, drawn again the moment a task write is sent (pm/live-edit.js), before Home reads its eleven routes again */
210
+ LE.source({ model: () => [S.D, S.IM], redraw: () => { if (S.ready) draw(); } });
208
211
  async function load() {
209
- const gen = pickGen;
212
+ const gen = pickGen, since = Date.now();
210
213
  const [brief, board, ses, desk, today, sch, work, day, rev, progs, , pick] = await Promise.all([
211
214
  getRetry('/api/briefing-premium' + wsQ()), getRetry('/api/board-premium' + wsQ() + boardQ(WS ? '&' : '?')), pmGet('/api/sessions'), pmGet('/api/home-desk' + wsQ()),
212
215
  pmGet('/api/brief-page' + wsQ()), pmGet('/api/schedules' + wsQ()), pmGet('/api/my-work-premium' + wsQ()), pmGet('/api/phone-day'), pmGet('/api/home-review' + wsQ()),
@@ -241,6 +244,7 @@ async function load() {
241
244
  S.ready = true;
242
245
  await loadIni();
243
246
  draw();
247
+ LE.loaded({ since }); // a change still saving stays on the new read; open views (the big Work breakdown) follow it
244
248
  NEED.refresh(); // an open ask: its agent finished, or it left Home while it was open
245
249
  loadImpact();
246
250
  loadDrift();
@@ -36,6 +36,7 @@ import { ensureCss as ensureStepsCss } from './cozy-steps.js'; // stage card D
36
36
  import * as DB from './dash-view.js'; // the ready-made Dashboard view (batch 17 item 1)
37
37
  import * as TL from './ini-tail.js';
38
38
  import * as ED from './ini-edit.js'; // round 3 item 11b: a Today task row opens its initiative with that task's row open in place
39
+ import * as LE from './live-edit.js'; // an edit shows at once: the open initiative view is drawn again the moment a task write is sent
39
40
  import * as PW from './cozy-pop-work.js'; // what the popup shows for work (slice 3 of the six-place navigation): in the popup, in place of the old page
40
41
  import * as PP from './ini-props.js'; // everything PMOS suggests, as a drill-in (the popup's ⋯) // under Linked, as the Board draws it (UI grill U1): drafted tickets, the PRD drift, Your impact
41
42
  import * as SWN from './cozy-status-when.js'; // the day a status move really happened, in the toast (round 3 point 18)
@@ -322,13 +323,14 @@ function wirePage(b, id) {
322
323
  // the stage card's ⏸ or calendar on a hold (batch 11 item 21): what the hold says, and its return date set or changed here
323
324
  hold: (i, btn) => holdPop(btn, id),
324
325
  // opt (batch 18 item 16): the + on a stage: the task goes under that stage, with the dates its field picked; the toast offers Undo
325
- addTask: async (title, inp, opt) => {
326
+ addTask: async function add(title, inp, opt) {
326
327
  const M = curM(); if (!M) return;
327
328
  inp.disabled = true;
328
329
  const D = opt ? opt : ADD_DATES || {};
329
330
  const r = await C.pmPost('/api/boards/tasks/add', { ...bw(M), initiative: id, title, ...(D.start ? { start: D.start } : {}), ...(D.due ? { due: D.due } : {}), ...(opt && opt.section != null ? { section: opt.section } : {}), ...(opt && opt.milestone ? { milestone: true } : {}), ...(opt && opt.owner ? { owner: opt.owner } : {}) });
330
331
  inp.disabled = false;
331
- if (!r || r.ok === false) { say((r && r.error) || 'The task was not added.'); return; }
332
+ // the row showed at once (pm/live-edit.js) and is gone again: say so, with Try again
333
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => add(title, inp, opt), 12000, 'Try again'); return; }
332
334
  const uid = r.item && r.item.uid;
333
335
  if (opt && uid) undoToast('Added to ' + (opt.name || 'the stage') + '.', async () => { const u = await C.pmPost('/api/boards/tasks/delete', { ...bw(M), task: uid, why: 'undo of add' }); if (!u || u.ok === false) C.toast((u && u.error) || 'The undo did not land.'); await C.load(); redrawView(); });
334
336
  else say('Task added.');
@@ -367,7 +369,8 @@ async function setState(id, uid, state, w) {
367
369
  const M = curM(); if (!M) return;
368
370
  const k = taskAt(id, uid), C = X.ctx, body = { ...bw(M), task: uid }, happened = (w && w.happened) || null;
369
371
  const r = await C.pmPost('/api/boards/tasks/state', { ...body, state, ...(happened ? { happened } : {}) });
370
- if (!r || r.ok === false) { C.toast((r && r.error) || 'Nothing was changed.'); return; }
372
+ // 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
373
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => setState(id, uid, state, w), 12000, 'Try again'); return; }
371
374
  await C.load(); redrawView();
372
375
  const was = k && k.status;
373
376
  // the day it really happened is said beside the title (round 3 point 18): "Done on 14 Nov, noted today."
@@ -379,7 +382,7 @@ async function removeTask(id, uid) {
379
382
  const M = curM(); if (!M) return;
380
383
  const k = taskAt(id, uid), C = X.ctx, body = { ...bw(M), task: uid }, title = (k && k.title) || uid;
381
384
  const r = await C.pmPost('/api/boards/tasks/delete', body);
382
- if (!r || r.ok === false) { C.toast((r && r.error) || 'The task was not deleted.'); return; }
385
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => removeTask(id, uid), 12000, 'Try again'); return; } // the row went at once and is back
383
386
  await C.load(); redrawView();
384
387
  undoToast('Deleted · ' + title + '.', async () => { const u = await C.pmPost('/api/boards/tasks/restore', body); if (!u || u.ok === false) C.toast((u && u.error) || 'The undo did not land.'); await C.load(); redrawView(); });
385
388
  }
@@ -388,7 +391,7 @@ async function setDates(id, uid, patch) {
388
391
  const M = curM(); if (!M) return;
389
392
  const k = taskAt(id, uid), C = X.ctx, body = { ...bw(M), task: uid };
390
393
  const r = await C.pmPost('/api/boards/tasks/edit', { ...body, ...patch });
391
- if (!r || r.ok === false) { C.toast((r && r.error) || 'Nothing was changed.'); return; }
394
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => setDates(id, uid, patch), 12000, 'Try again'); return; }
392
395
  await C.load(); redrawView();
393
396
  const back = {}; for (const f of Object.keys(patch)) back[f] = f === 'milestone' ? (r.from && 'milestone' in r.from ? !!r.from.milestone : !patch.milestone) : k ? (f === 'due' ? k.end : k[f]) || '' : r.from && f in r.from ? r.from[f] || '' : ''; // a Jira ticket's days come back in from (batch 11 item 23)
394
397
  if ('milestone' in patch) { undoToast((patch.milestone ? 'Milestone: ' : 'Not a milestone: ') + (k ? k.title : uid) + '.', async () => { const u = await C.pmPost('/api/boards/tasks/edit', { ...body, ...back }); if (!u || u.ok === false) C.toast((u && u.error) || 'The undo did not land.'); await C.load(); redrawView(); }); return; }
@@ -602,6 +605,7 @@ function draw(b) {
602
605
  // the phone keeps the Documents | Stage switch (PgTkList); in shell A on a desktop the other view sits under ⋯ (XvATasks)
603
606
  b.innerHTML = `<div class="hi-v" data-hi-v="${v}">${isPhone() || !X.ctx.VW.czSummary ? segHtml(v) : ''}${stageView(id, M, STAGE_ASK)}<p class="hi-small" role="status" id="ovMsg"></p></div>`;
604
607
  }
608
+ LE.view('home-ini', () => redrawView());
605
609
  function redrawView() {
606
610
  if (!BODY || !BODY.isConnected || !X.ctx) return;
607
611
  const cur = X.ctx.VW.current(); if (!cur) return;
@@ -139,8 +139,8 @@ export function sheetHtml(m, g, z = zoomOf()) {
139
139
  }
140
140
  function openSheet(anchor, H) {
141
141
  const g = () => (H.__g && H.__g.ok ? { by: H.__g.by(), label: H.__g.label() } : null);
142
- const draw = () => { if (POP && POP.anchor === anchor) POP.el.innerHTML = sheetHtml(viewMode(), g()); };
143
- const el = openPop(anchor, sheetHtml(viewMode(), g()), (b) => {
142
+ let el = null; const draw = () => { if (POP && POP.el === el) POP.el.innerHTML = sheetHtml(viewMode(), g()); };
143
+ el = openPop(anchor, sheetHtml(viewMode(), g()), (b) => {
144
144
  const d = b.dataset;
145
145
  if (d.ivsView) { setViewMode(d.ivsView); if (H.redraw) H.redraw(); draw(); return; }
146
146
  if (d.ivsCol) { const on = timelineCols(); setTimelineCols(on.includes(d.ivsCol) ? on.filter((k) => k !== d.ivsCol) : on.concat(d.ivsCol)); if (H.redraw) H.redraw(); draw(); return; }
@@ -577,7 +577,15 @@ export function kanbanHtml(v, o, isOpen) {
577
577
  /* ── the popovers: the task card's own status segment and date picker, opened right under the press ── */
578
578
  let POP = null;
579
579
  /** The press the picker hangs from moved (or left the page) since it opened. */
580
- const moved = (P) => { if (!P.anchor || !P.anchor.isConnected || !P.at) return true; const r = P.anchor.getBoundingClientRect(); return Math.abs(r.left - P.at[0]) > 1 || Math.abs(r.top - P.at[1]) > 1; };
580
+ const moved = (P) => { if (P.anchor && !P.anchor.isConnected) rehang(P); if (!P.anchor || !P.anchor.isConnected || !P.at) return true; const r = P.anchor.getBoundingClientRect(); return Math.abs(r.left - P.at[0]) > 1 || Math.abs(r.top - P.at[1]) > 1; };
581
+ /** A redraw put a new copy of the press in place (an edit shows at once, pm/live-edit.js): the picker hangs from that copy, found by
582
+ * the press's own data attributes, so it stays open. */
583
+ const selOf = (a) => { const at = [...a.attributes].filter((x) => x.name.startsWith('data-') && !/^data-(s|e|t)$/.test(x.name)); return at.length ? a.tagName.toLowerCase() + at.map((x) => `[${x.name}="${CSS.escape(x.value)}"]`).join('') : null; };
584
+ function rehang(P) {
585
+ let n = null; try { n = P.sel && document.querySelector(P.sel); } catch { n = null; }
586
+ if (!n || P.el.contains(n)) return;
587
+ P.anchor = n; n.setAttribute('aria-expanded', 'true'); const r = n.getBoundingClientRect(); P.at = [r.left, r.top];
588
+ }
581
589
  export function closePop() { if (!POP) return; const { el, anchor, scrim } = POP; POP = null; el.remove(); if (scrim) scrim.remove(); if (anchor && anchor.isConnected) anchor.setAttribute('aria-expanded', 'false'); }
582
590
  /** o.sheet: a bottom sheet over a scrim (a phone); o.right: the popover's right edge under the press's right edge. */
583
591
  export function openPop(anchor, html, onPress, o = {}) {
@@ -594,7 +602,7 @@ export function openPop(anchor, html, onPress, o = {}) {
594
602
  }
595
603
  anchor.setAttribute('aria-expanded', 'true');
596
604
  const ar = anchor.getBoundingClientRect();
597
- POP = { el, anchor, onPress, scrim, at: [ar.left, ar.top] };
605
+ POP = { el, anchor, onPress, scrim, at: [ar.left, ar.top], sel: selOf(anchor) };
598
606
  const f = el.querySelector('[aria-checked="true"], [aria-pressed="true"], button'); if (f) f.focus({ preventScroll: true });
599
607
  return el;
600
608
  }