create-pmos 0.656.0 → 0.658.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,207 @@
1
+ /* pm/goals-ds.js — the blocks Goals is built from (initiative goals-ds-page; Exploring 3 page "pages", board GoalsDS; brief
2
+ * design-system/pages-rebuild/brief.md). Built only from PMOS Komorebi parts (workspace/design-system/ui). PURE: no DOM, no fetch, no clock of its
3
+ * own; `today` ('YYYY-MM-DD') comes in. The page (pm/premium-goals.js) passes one product's model and wires the presses by their data- attributes.
4
+ *
5
+ * standsOf(model, today) → [html] Where it stands: the cause, the risk and the next decision point, never counts alone
6
+ * sugOf(model, ns, dismissed) → { kind, key, title, why, will, changes, basis, say } | null the one Suggestion under it
7
+ * numbersOf(model, ns) → [{ role, name, value, at, spark, line, ns? }] North Star, input, guardrail (Number blocks)
8
+ * guessKr(title, F) → { key, token, title, words } | null the key result PMOS thinks an unlinked initiative moves, and why
9
+ * linkSay(ini, guess) → the words Link puts in the Conversation box
10
+ * paceOf(row) → [label, badge tone]
11
+ * tableHtml(p, o) → the Key results Table (pm-table in a pm-block, group rows, tabs, Choose columns)
12
+ * COLS the columns: Key result always, then Now, Pace, Moved by, Check (shown) and Left, Levers (Choose columns)
13
+ *
14
+ * NOTHING HERE MAKES A NUMBER UP (the proven-only rule of pm/goals-model.js). A sentence is made from a field of the model; a key result with
15
+ * no reading says so and what it waits on; a sparkline needs two readings. Zero is silence: nothing to say, no block. */
16
+ import * as GM from './goals-model.js';
17
+ import { sugHtml } from './bd-stands.js';
18
+
19
+ export { sugHtml };
20
+ export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
21
+ export const SV = (d, n = 16, cls = '') => `<svg class="pm-ic${cls ? ' ' + cls : ''}" width="${n}" height="${n}" viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
22
+ export const I = {
23
+ star: 'M12 3l1.8 5.4L19 10.2l-5.2 1.8L12 17.4l-1.8-5.4L5 10.2l5.2-1.8z', link: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1',
24
+ cols: 'M4 7h10M18 7h2M4 17h4M12 17h8M14 5v4M8 15v4', chat: 'M4 5h16v11H9l-5 4z', chev: 'M10 8l4 4-4 4',
25
+ };
26
+ const noun = (n, one, many) => n + ' ' + (n === 1 ? one : many);
27
+ const kr = (ws, k, text) => `<a href="#" data-gl-ws="${esc(ws)}" data-gl-kr="${esc(k.key)}">${esc(text || k.title)}</a>`;
28
+ const ini = (ws, i) => `<a href="#" data-gl-ws="${esc(ws)}" data-gl-ini="${esc(i.id)}"${i.verdict ? ' data-gl-verdict' : ''}>${esc(i.title)}</a>`;
29
+
30
+ /** Every key result row of the file (filter all), with its objective. */
31
+ const rowsOf = (model, today) => GM.tableOf(model, today, 'all').objectives.flatMap((o) => o.krs.map((k) => ({ o, k })));
32
+ /** The initiative records the OKR file names, by id (each carries endAt and status). */
33
+ function recs(model) {
34
+ const by = new Map(), F = model && model.okrFile;
35
+ if (F) for (const o of F.objectives || []) for (const k of o.krs || []) for (const r of k.moves || []) by.set(r.id, r);
36
+ return by;
37
+ }
38
+ /** The work that moves a key result most soon: the open initiative with the nearest end still ahead, else the one most over. */
39
+ function leadWork(model, k, today) {
40
+ const by = recs(model);
41
+ const open = k.moves.map((id) => by.get(id)).filter((r) => r && r.status !== 'done' && r.status !== 'cancelled');
42
+ const ahead = open.filter((r) => r.endAt && GM.daysTo(today, r.endAt) >= 0).sort((a, b) => String(a.endAt).localeCompare(String(b.endAt)));
43
+ if (ahead.length) return { r: ahead[0], ahead: true };
44
+ const over = open.filter((r) => r.endAt).sort((a, b) => String(a.endAt).localeCompare(String(b.endAt)));
45
+ return over.length ? { r: over[0], ahead: false } : null;
46
+ }
47
+
48
+ /* ── Where it stands ──────────────────────────────────────────────────────────────────────────────────────────── */
49
+ export function standsOf(model, today) {
50
+ const F = model && model.okrFile; if (!F) return [];
51
+ const ws = (model.board && model.board.ws) || '';
52
+ const all = rowsOf(model, today), out = [];
53
+ if (!all.length) return [];
54
+ const read = all.filter((x) => x.k.read), pace = read.filter((x) => x.k.dot === 'ok');
55
+ const behind = read.filter((x) => x.k.dot === 'rk' || x.k.dot === 'rd');
56
+ // 1. how many are on pace, said only when something was read (a count of nothing read would say nothing true)
57
+ if (read.length) out.push(`${pace.length} of ${noun(all.length, 'key result', 'key results')} ${pace.length === 1 ? 'is' : 'are'} on pace.`);
58
+ // 2. the behind ones: value, target, time left, and the work that moves it with its date (the cause and the risk)
59
+ for (const { k } of behind.slice(0, 2)) {
60
+ const w = leadWork(model, k, today);
61
+ const work = !w ? '' : w.ahead ? `, and the work that moves it, ${ini(ws, { id: w.r.id, title: w.r.title })}, ships ${esc(GM.mdy(w.r.endAt))}`
62
+ : `, and the work that moves it, ${ini(ws, { id: w.r.id, title: w.r.title })}, is ${esc(noun(-GM.daysTo(today, w.r.endAt), 'day', 'days'))} past its end`;
63
+ const left = k.left ? (k.left === 'today' ? ' with the check today' : /over$/.test(k.left) ? ', ' + esc(k.left) : ' with ' + esc(k.left) + ' left') : '';
64
+ out.push(`${kr(ws, k)} is behind: ${esc(k.act)}${k.target ? ' of ' + esc(k.target) : ''}${left}${work}.`);
65
+ }
66
+ // 3. no reading: the one read before and silent since, else how many wait and on what
67
+ const unread = all.filter((x) => !x.k.read);
68
+ const stale = unread.filter((x) => x.k.lastAt).sort((a, b) => String(a.k.lastAt).localeCompare(String(b.k.lastAt)))[0];
69
+ if (stale) out.push(`${kr(ws, stale.k)} has had no reading since ${esc(GM.mdy(stale.k.lastAt))}, so nobody knows how it is going.`);
70
+ else if (unread.length) {
71
+ const by = new Map(); for (const { k } of unread) if (k.need) by.set(k.need, (by.get(k.need) || 0) + 1);
72
+ const top = [...by.entries()].sort((a, b) => b[1] - a[1])[0];
73
+ const who = unread.length === 1 ? kr(ws, unread[0].k) + ' has' : (unread.length === all.length ? 'No key result has' : noun(unread.length, 'key result has', 'key results have'));
74
+ const wait = !top ? '' : unread.length === 1 ? `: it waits on ${esc(top[0])}` : top[1] === unread.length ? `: they all wait on ${esc(top[0])}` : `: ${top[1]} wait on ${esc(top[0])}`;
75
+ out.push(`${who} ${unread.length === all.length && unread.length > 1 ? 'a reading yet' : 'no reading yet'}${wait}.`);
76
+ }
77
+ // 4. a health budget over its cap
78
+ for (const b of ((model.budgets || []).filter((b) => b && b.reading && b.reading.over)).slice(0, 1)) {
79
+ out.push(`The ${esc(b.id)} health budget is over its cap${typeof b.reading.share === 'number' && typeof b.cap === 'number' ? `: ${Math.round(b.reading.share * 100)}% of the work against ${Math.round(b.cap * 100)}%` : ''}.`);
80
+ }
81
+ // 5. the next decision point: the nearest check still ahead
82
+ const next = all.filter((x) => x.k.due && GM.daysTo(today, x.k.due) >= 0).sort((a, b) => String(a.k.due).localeCompare(String(b.k.due)))[0];
83
+ if (next) {
84
+ const n = GM.daysTo(today, next.k.due), when = n === 0 ? ', today' : n === 1 ? ', tomorrow' : `, in ${noun(n, 'day', 'days')}`;
85
+ const end = F.period && F.period.toAt && next.k.due === F.period.toAt && !all.some((x) => x.k.due && x.k.due !== F.period.toAt);
86
+ out.push(end ? `Every key result is checked when ${esc(F.period.label || 'the period')} ends on ${esc(GM.mdy(next.k.due))}${when}.`
87
+ : `The next check is ${kr(ws, next.k, next.k.token + ' ' + next.k.title)} on ${esc(GM.mdy(next.k.due))}${when}.`);
88
+ }
89
+ return out;
90
+ }
91
+
92
+ /* ── the one Suggestion ───────────────────────────────────────────────────────────────────────────────────────── */
93
+ /** The North Star draft first, else a source to connect (the one that frees the most key results), else drafting a North Star. A kind the PM
94
+ * said No to on this device (dismissed: Set of keys) is passed over. */
95
+ export function sugOf(model, ns, dismissed = new Set()) {
96
+ const F = model && model.okrFile; if (!F) return null;
97
+ const out = [];
98
+ if (ns && ns.state === 'draft') out.push({ kind: 'ns', key: 'ns:' + ns.row, title: 'Set the North Star: ' + ns.title, why: ns.sub,
99
+ will: ['Keep the draft as this product’s North Star measure'], changes: 'Goals shows it as the North Star, and the key results hang from it.', basis: 'PMOS’s draft from your key results' });
100
+ const su = GM.setupOf(model, ns);
101
+ for (const s of (su && su.sources) || []) {
102
+ const toks = s.frees.replace(/^Frees /, ''), n = (toks.match(/,| to /g) || []).length + 1;
103
+ out.push({ kind: 'src', key: 'src:' + s.need, title: 'Connect ' + s.need, why: `${toks} ${n === 1 ? 'has' : 'have'} no reading. Your OKR file names ${s.need} as the source.`,
104
+ will: ['Connect ' + s.need + ' as a source', 'Test one read before it keeps it', 'Read ' + toks + ' from it'], changes: `${toks} get readings, so their pace shows here.`, basis: 'Your OKR file',
105
+ say: `Connect ${s.need} and read ${toks} from it. Test one read before you keep it.` });
106
+ }
107
+ if (ns && ns.state === 'none') out.push({ kind: 'draft', key: 'draft', title: 'Draft a North Star', why: ns.sub,
108
+ will: ['Draft a North Star from your key results', 'Show it here for your tick before it counts'], changes: 'The key results hang from one measure.', basis: 'Your OKR file',
109
+ say: 'Draft a North Star for this product from its key results. I approve it with a tick.' });
110
+ return out.find((s) => !dismissed.has(s.key)) || null;
111
+ }
112
+
113
+ /* ── North Star, input, guardrail ─────────────────────────────────────────────────────────────────────────────── */
114
+ /** A sparkline's points in a 120 × 32 box, from two readings or more; '' with fewer. */
115
+ export function sparkOf(series) {
116
+ const s = (series || []).filter((x) => x && typeof x.v === 'number');
117
+ if (s.length < 2) return '';
118
+ const vs = s.map((x) => x.v), lo = Math.min(...vs), hi = Math.max(...vs), span = hi - lo || 1;
119
+ return s.map((x, i) => `${Math.round((i / (s.length - 1)) * 120)},${Math.round(30 - ((x.v - lo) / span) * 28)}`).join(' ');
120
+ }
121
+ const lineOf = (g) => [g.title + '.', g.targetTxt ? `Target ${g.targetTxt}${g.by ? ' by ' + g.by : ''}.` : '', g.pace && g.pace.sub && g.pace.head !== '—' ? g.pace.sub.replace(/^./, (c) => c.toUpperCase()) + '.' : ''].filter(Boolean).join(' ');
122
+ export function numbersOf(model, ns) {
123
+ const G = ((model && model.goals) || []);
124
+ const one = (role, name) => { const g = G.find((x) => x && x.role === role); return g ? { role, name, value: g.nowTxt || '—', at: (g.reading && g.reading.at) || null, spark: sparkOf(g.series), line: lineOf(g), goal: g.id } : null; };
125
+ const out = [];
126
+ const n = one('north-star', 'North Star');
127
+ if (n) out.push(n); else if (model && model.okrFile && ns) out.push({ role: 'north-star', name: 'North Star', ns });
128
+ for (const [r, name] of [['input', 'Input'], ['guardrail', 'Guardrail']]) { const x = one(r, name); if (x) out.push(x); }
129
+ return out;
130
+ }
131
+
132
+ /* ── an unlinked initiative: the key result PMOS thinks it moves ──────────────────────────────────────────────── */
133
+ const STOP = new Set(['the', 'and', 'for', 'with', 'from', 'into', 'over', 'under', 'that', 'this', 'than', 'more', 'less', 'make', 'new', 'old', 'all', 'one', 'per',
134
+ 'its', 'our', 'your', 'are', 'not', 'off', 'out', 'up', 'down', 'v1', 'v2', 'phase', 'work', 'held', 'least', 'good', 'before', 'after', 'week', 'month']);
135
+ const words = (s) => [...new Set(String(s || '').toLowerCase().replace(/[^a-z0-9 ]+/g, ' ').split(/\s+/).filter((w) => w.length >= 4 && !STOP.has(w)))];
136
+ /** The key result whose words the initiative's title shares most; two words, or one of six letters or more. null when none fits. */
137
+ export function guessKr(title, F) {
138
+ const mine = words(title); if (!mine.length) return null;
139
+ let best = null;
140
+ for (const o of (F && F.objectives) || []) for (const k of o.krs || []) {
141
+ const kw = words(k.title + ' ' + (o.title || '')), hit = mine.filter((w) => kw.includes(w));
142
+ const score = hit.length * 10 + hit.reduce((a, w) => a + w.length, 0);
143
+ if ((hit.length >= 2 || hit.some((w) => w.length >= 6)) && (!best || score > best.score)) best = { key: k.key, token: k.token, title: k.title, words: hit, score };
144
+ }
145
+ return best ? { key: best.key, token: best.token, title: best.title, words: best.words } : null;
146
+ }
147
+ export const linkSay = (i, g) => (g ? `Link ${i.title} to ${g.token} ${g.title}.` : `Which key result does ${i.title} move? Link it, or say a new one.`);
148
+
149
+ /* ── the Key results Table ────────────────────────────────────────────────────────────────────────────────────── */
150
+ export const COLS = Object.freeze([['now', 'Now', true], ['pace', 'Pace', true], ['moved', 'Moved by', true], ['check', 'Check', true], ['left', 'Left', false], ['levers', 'Levers', false]]);
151
+ const PACE = { on: ['On pace', 'blue'], close: ['Behind', 'alert'], behind: ['Behind', 'alert'], broken: ['Off track', 'alert'] };
152
+ export const paceOf = (k) => (k.read ? PACE[k.pace] || ['Read', ''] : ['No reading', '']);
153
+ const badge = ([t, tone]) => `<span class="pm-badge${tone ? ' ' + tone : ''}">${esc(t)}</span>`;
154
+ // the bar is an SVG (its length an attribute, never an inline style: conformance R28-1)
155
+ const bar = (f) => `<svg class="gl-meter" aria-hidden="true" width="90" height="6" viewBox="0 0 90 6"><rect width="90" height="6" rx="3" fill="var(--well)"/><rect width="${Math.round(Math.max(0, Math.min(1, f)) * 90)}" height="6" rx="3" fill="var(--leaf)"/></svg>`;
156
+
157
+ /** p: { ws, name, model, T (tableOf with the tab), counts: { all, slip, unread, pace } }; o: { today, filter, cols: Set, many }. */
158
+ export function tableHtml(p, o) {
159
+ const { model, T, ws } = p, F = model.okrFile, cols = COLS.filter(([k]) => o.cols.has(k)), n = cols.length + 1;
160
+ const by = recs(model);
161
+ const moved = (ids) => ids.map((id) => GM.iniItem(by.get(id) || { id, title: id }, model, o.today))
162
+ .map((i) => `<span class="gl-mv${i.tone ? ' gl-al' : ''}" title="${esc(i.line)}">${ini(ws, i)}</span>`).join(', ');
163
+ const cell = {
164
+ now: (k) => `<td class="gl-now">${k.act ? `<b>${esc(k.act)}</b>` : '<b>—</b>'}${k.target ? ` <span class="pm-meta">of ${esc(k.target)}</span>` : ''}`
165
+ + (k.done !== null && k.done !== undefined ? bar(k.done) : !k.read ? ` <span class="pm-meta">${esc(k.lastAt ? 'last read ' + GM.mdy(k.lastAt) : k.sub)}</span>` : '') + '</td>',
166
+ pace: (k) => `<td>${badge(paceOf(k))}</td>`,
167
+ moved: (k) => `<td class="gl-mvs">${moved(k.moves)}</td>`,
168
+ check: (k) => `<td class="code pm-meta">${esc(k.due ? GM.mdy(k.due) : '')}</td>`,
169
+ left: (k) => `<td class="pm-meta">${esc(k.left)}</td>`,
170
+ levers: (k, ob, i) => `<td class="gl-lvs">${i === 0 ? ob.levers.map((l) => `<span><b>${esc(l.title)}</b> <span class="pm-meta${l.tone ? ' gl-al' : ''}">${esc(l.txt)}</span></span>`).join('') : ''}</td>`,
171
+ };
172
+ const group = (label, sub, extra = '') => `<tr class="gl-g"><td colspan="${n}"><div class="pm-group"><b>${esc(label)}</b><span>${esc(sub)}</span>${extra}</div></td></tr>`;
173
+ let body = '';
174
+ for (const ob of T.objectives) {
175
+ body += group(ob.label + (ob.title ? ' · ' + ob.title : ''), noun(ob.krs.length, 'key result', 'key results'));
176
+ body += ob.krs.map((k, i) => `<tr><td class="gl-kr"><a href="#" class="gl-k" data-gl-ws="${esc(ws)}" data-gl-kr="${esc(k.key)}" title="${esc(k.sub)}">${esc(k.token)} · ${esc(k.title)}</a></td>`
177
+ + cols.map(([c]) => cell[c](k, ob, i)).join('') + '</tr>').join('');
178
+ }
179
+ if (T.budgets.length) {
180
+ body += group('Health budgets', 'work that keeps things running');
181
+ body += T.budgets.map((b) => {
182
+ const c = { now: `<td class="gl-now">${b.share ? `<b>${esc(b.share.replace(/ of .*/, ''))}</b> <span class="pm-meta">of ${esc(b.share.replace(/^.* of /, ''))} at most</span>` : '<span class="pm-meta">no share yet</span>'}</td>`,
183
+ pace: `<td>${b.share ? badge(b.over ? ['Over', 'alert'] : ['Within', 'blue']) : ''}</td>`, moved: `<td class="gl-mvs">${b.items.map((i) => `<span class="gl-mv${i.tone ? ' gl-al' : ''}" title="${esc(i.line)}">${ini(ws, i)}</span>`).join(', ')}</td>`,
184
+ check: '<td></td>', left: '<td></td>', levers: `<td class="pm-meta">${esc(b.covers)}</td>` };
185
+ return `<tr><td class="gl-kr"><b>${esc(b.label)}</b></td>${cols.map(([k]) => c[k]).join('')}</tr>`;
186
+ }).join('');
187
+ }
188
+ if (T.unlinked.length) {
189
+ body += group('Not linked to a key result', noun(T.unlinked.length, 'initiative', 'initiatives'));
190
+ body += T.unlinked.map((i) => {
191
+ const g = guessKr(i.title, F);
192
+ const say = g ? `PMOS thinks it moves ${g.token} (both say ${g.words.join(', ')})` : 'no key result fits yet';
193
+ return `<tr><td class="gl-kr">${ini(ws, i)}</td><td colspan="${Math.max(1, n - 2)}" class="pm-meta">${esc(say)}</td>`
194
+ + `<td class="gl-end"><button type="button" class="pm-btn" data-gl-link="${esc(i.id)}" data-gl-ws="${esc(ws)}" data-gl-say="${esc(linkSay(i, g))}" aria-label="Link to a key result" title="Link to a key result">${SV(I.link)}</button></td></tr>`;
195
+ }).join('');
196
+ }
197
+ const tabs = GM.FILTERS.map(([k, label]) => `<button type="button" class="pm-tab" role="tab" aria-selected="${o.filter === k}" data-gl-f="${k}">${esc(label)}${p.counts[k] ? ` <span class="gl-tn">${p.counts[k]}</span>` : ''}</button>`).join('');
198
+ const head = `<div class="head"><h2 class="pm-h">Key results</h2>${o.many ? `<span class="pm-meta">${esc(p.name)}</span>` : ''}<span class="sp"></span>`
199
+ + `<div class="pm-tabs" role="tablist" aria-label="Show">${tabs}</div>`
200
+ + `<span class="gl-mw"><button type="button" class="pm-btn" data-gl-cols="${esc(ws)}" aria-haspopup="menu" aria-expanded="false" aria-label="Choose columns" title="Choose columns">${SV(I.cols)}</button></span></div>`;
201
+ const none = !T.objectives.length && !T.budgets.length && !T.unlinked.length;
202
+ const label = (GM.FILTERS.find((f) => f[0] === o.filter) || [])[1] || '';
203
+ return `<section class="pm-block gl-krs" aria-label="Key results">${head}`
204
+ + (none ? `<p class="pm-meta gl-m0">No key result is ${esc(label.toLowerCase())} in ${esc(p.name)}.</p>`
205
+ : `<div class="gl-tw"><table class="pm-table" aria-label="Key results of ${esc(p.name)}"><thead><tr><th scope="col">Key result</th>${cols.map(([, h]) => `<th scope="col">${esc(h)}</th>`).join('')}</tr></thead><tbody>${body}</tbody></table></div>`)
206
+ + '</section>';
207
+ }
@@ -25,7 +25,9 @@ export const mdy = (d) => { const t = ms(d); if (t === null) return ''; const x
25
25
  export const daysTo = (a, b) => { const x = ms(a), y = ms(b); return x === null || y === null ? null : Math.round((y - x) / DAY); };
26
26
  const noun = (n, one, many) => n + ' ' + (n === 1 ? one : many);
27
27
 
28
- export const FILTERS = Object.freeze([['all', 'All'], ['slip', 'Slipping'], ['unread', 'Not read'], ['read', 'Read']]);
28
+ /* the Key results tabs (GoalsDS): All, Behind, No reading, On pace. 'read' (every read key result) was the old fourth choice and still filters, so a
29
+ * choice stored on a device before the tabs keeps working. */
30
+ export const FILTERS = Object.freeze([['all', 'All'], ['slip', 'Behind'], ['unread', 'No reading'], ['pace', 'On pace']]);
29
31
 
30
32
  /** "O-A" → "Objective A", "O1" → "Objective 1", "Objective 2" stays. */
31
33
  export function objLabel(token) {
@@ -81,9 +83,14 @@ function krRow(model, o, k, today) {
81
83
  act: read ? g.nowTxt : '', target: g && g.targetTxt ? g.targetTxt : '', tone: dot === 'rk' ? 'risk' : dot === 'rd' ? 'late' : '',
82
84
  left: d === null ? '' : d > 0 ? noun(d, 'day', 'days') : d === 0 ? 'today' : noun(-d, 'day', 'days') + ' over', due,
83
85
  moves: (k.moves || []).map((r) => r.id),
86
+ // GoalsDS: the pace a reading gives (on, close, behind, broken; none with no reading), the share of the way to the target when the record
87
+ // has a start, a target and a reading (lib/insights-premium.js done), and the last reading's day even when it is no longer counted as read
88
+ pace: read ? ((g.reading || {}).dot || 'none') : 'none', done: read && typeof g.done === 'number' ? g.done : null,
89
+ lastAt: (g && g.reading && g.reading.at) || (g && g.lastRead && g.lastRead.day) || null,
84
90
  };
85
91
  }
86
- const passes = (row, filter) => filter === 'slip' ? row.dot === 'rk' || row.dot === 'rd' : filter === 'unread' ? !row.read : filter === 'read' ? row.read : true;
92
+ const passes = (row, filter) => filter === 'slip' ? row.dot === 'rk' || row.dot === 'rd' : filter === 'unread' ? !row.read : filter === 'read' ? row.read
93
+ : filter === 'pace' ? row.read && row.dot === 'ok' : true;
87
94
 
88
95
  /** The outcome promise of an initiative (model.outcomes), by id. */
89
96
  const outcomeOf = (model, id) => ((model && model.outcomes) || []).find((r) => r && r.id === id) || null;
@@ -1,4 +1,19 @@
1
- /* pm/premium-goals.js — Goals, the place (initiative goals-place, slice 9 of the six-place navigation; boards 8, 13, 31, 32, 33 on Exploring 2,
1
+ /* pm/premium-goals.js — Goals, the place. REBUILT FROM DESIGN SYSTEM BLOCKS (initiative goals-ds-page; board GoalsDS on Exploring 3, page "pages";
2
+ * brief design-system/pages-rebuild/brief.md). One column of blocks (pm/goals-ds.js writes them):
3
+ * · the top line: the path Goals › the product chip, the period chip, then Search, New key result (+: the words go in the Conversation box) and More
4
+ * (Set up, Charts and dashboards, Export CSV). The old Filter button is the Key results tabs now.
5
+ * · Where it stands (a Summary block): behind key results with the work that moves them and its date, a key result with no reading and since when,
6
+ * the next check. One Suggestion in the expanded form follows: the North Star draft (Yes keeps it, No drops it, both with Undo), else a source to
7
+ * connect, else drafting a North Star. Yes on an ask sends its words to PMOS in the Conversation; No hides it on this device ('pmos.goals.no');
8
+ * the pencil puts the words in the box to change first.
9
+ * · North Star, input and guardrail as Number blocks; a North Star not set keeps its draft (✓ ✕) or the ask (✦) in its block.
10
+ * · Key results: one Table grouped by objective, then health budgets, then the work no key result names (PMOS's guess of the key result, Link).
11
+ * Tabs All, Behind, No reading, On pace ('pmos.goals.filt'); Choose columns adds Left and Levers ('pmos.goals.cols').
12
+ * · the Conversation block: the one chat (pm/page-chat.js) about Goals of the product. The popup borrows the same element (cozy-popup.js
13
+ * useChat) and gives it back, so the page never holds two chats.
14
+ * Everything below this line is as goals-place built it, unless it says otherwise.
15
+ *
16
+ * First built as Goals (initiative goals-place, slice 9 of the six-place navigation; boards 8, 13, 31, 32, 33 on Exploring 2,
2
17
  * page "Navigation: Today, Work, Goals, Events, Library, Routine"; handover /mnt/project-files/goals-handover/).
3
18
  *
4
19
  * "Am I on track? What do I do?" as one hierarchy. Top: the product choice Work and Goals share (cozy-pick.js, full names) and the OKR period. Then
@@ -24,16 +39,20 @@ import * as POP from './cozy-popup.js'; // the one popup: window.czOpenChat fo
24
39
  import * as GM from './goals-model.js';
25
40
  import * as GO from './goals-open.js';
26
41
  import { undoToast } from './hi-pop.js';
27
- import { productName, whenNames } from './scope-chip.js'; // names, not ids: the product's display name (IDPF), not its folder name
42
+ import { productName, whenNames } from './scope-chip.js';
43
+ import * as DS from './goals-ds.js'; // names, not ids: the product's display name (IDPF), not its folder name
28
44
 
29
45
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
30
46
  const SVG = (d, w = 16) => `<svg class="pm-ic" aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24"><path d="${d}"/></svg>`;
31
- const I = { check: 'M5 12.5l4.5 4.5L19 7.5', x: 'M6 6l12 12M18 6L6 18', cal: 'M4 5.5h16v14H4zM4 10h16M9 3.5v4M15 3.5v4', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z' };
47
+ const I = { check: 'M5 12.5l4.5 4.5L19 7.5', x: 'M6 6l12 12M18 6L6 18', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z' };
32
48
  const STAR = (w = 16) => `<svg class="pm-ic pm-star" aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24"><path d="${I.spark}"/></svg>`;
33
49
  const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* a private window */ } } };
34
50
  const todayIso = () => { const d = new Date(); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
35
- const FILT = GM.FILTERS.map((f) => f[0]);
36
- const S = { P: null, list: [], at: 0, filter: FILT.includes(store.get('pmos.goals.filt')) ? store.get('pmos.goals.filt') : 'all', error: '' };
51
+ const FILT = GM.FILTERS.map((f) => f[0]).concat('read'); // 'read' was the old fourth choice: a device that stored it keeps its view
52
+ const COLS0 = (() => { try { const v = JSON.parse(store.get('pmos.goals.cols') || 'null'); return Array.isArray(v) ? v : null; } catch { return null; } })();
53
+ const NO0 = (() => { try { const v = JSON.parse(store.get('pmos.goals.no') || '[]'); return Array.isArray(v) ? v : []; } catch { return []; } })();
54
+ const S = { P: null, list: [], at: 0, filter: FILT.includes(store.get('pmos.goals.filt')) ? store.get('pmos.goals.filt') : 'all', error: '',
55
+ cols: new Set(COLS0 || DS.COLS.filter((c) => c[2]).map((c) => c[0])), no: new Set(NO0), sug: null };
37
56
  const DEEP = new URLSearchParams(location.search).get('ws');
38
57
 
39
58
  mountNav('insights', document, { scope: () => ({ name: 'Goals', hits: (q) => hits(q) }) });
@@ -62,69 +81,92 @@ function drawPer() {
62
81
  const x = S.list.find((p) => p.model && p.model.okrFile && p.model.okrFile.period);
63
82
  const per = x ? GM.periodOf(x.model.okrFile) : null, el = $('glPer');
64
83
  el.hidden = !per;
65
- if (per) el.innerHTML = `${SVG(I.cal, 16)}<b>${esc(per.label)}</b>${per.sub ? `<span class="gl-pers">${esc(per.sub)}</span>` : ''}`;
84
+ if (per) { el.innerHTML = `<b>${esc(per.label)}</b>`; el.title = per.sub || ''; }
66
85
  }
67
86
 
68
- /* ── the North Star: a Number block once it is set, else PMOS's Suggestion (its draft with ✓ ✕, or ✦ to draft one) ── */
69
- function nsHtml(p) {
87
+ /* ── the blocks (pm/goals-ds.js writes the words; here they are laid out) ── */
88
+ /** A North Star not set: its block holds PMOS's draft (✓ ✕) or the ask to draft one (✦). */
89
+ function nsAsk(p) {
70
90
  const ns = p.ns;
71
- if (ns.state === 'set') return `<section class="pm-block gl-ns" aria-label="North Star"><div class="head"><h3 class="pm-h-sm">North Star</h3></div><div class="heading">${esc(ns.title)}</div><p class="pm-meta gl-m0">${esc(ns.sub)}</p></section>`;
72
- const head = `<div class="head"><h3 class="pm-h-sm pm-row">${STAR()}North Star</h3><span class="sp"></span><span class="pm-meta">not set in your OKR file</span></div>`;
73
- if (ns.state === 'draft') return `<section class="pm-block gl-ns" aria-label="North Star">${head}<div class="pm-sug" role="group" aria-label="PMOS suggests"><span class="say"><b>${esc(ns.title)}</b><br>${esc(ns.sub)}</span>`
74
- + `<button type="button" class="pm-btn primary" data-gl-nskeep="${esc(p.ws)}" aria-label="Approve this North Star" title="Approve this North Star">${SVG(I.check)}</button><button type="button" class="pm-btn outline" data-gl-nsdrop="${esc(p.ws)}" aria-label="No, drop this North Star" title="No">${SVG(I.x)}</button></div></section>`;
75
- return `<section class="pm-block gl-ns" aria-label="North Star">${head}<div class="pm-sug" role="group" aria-label="PMOS suggests"><span class="say"><b>${esc(ns.title)}</b><br>${esc(ns.sub)}</span>`
76
- + `<button type="button" class="pm-btn primary" data-gl-setup="${esc(p.ws)}" aria-label="Ask PMOS to draft the North Star" title="Ask PMOS to draft the North Star">${SVG(I.spark)}</button></div></section>`;
91
+ if (S.sug && S.sug.ws === p.ws && (S.sug.kind === 'ns' || S.sug.kind === 'draft')) return `<p class="pm-meta gl-m0">${ns.state === 'draft' ? 'PMOS drafted one: it waits for your answer in Where it stands.' : 'PMOS can draft one: see Where it stands.'}</p>`; // say it once
92
+ if (ns.state === 'draft') return `<div class="pm-sug" role="group" aria-label="PMOS suggests"><span class="say"><b>${esc(ns.title)}</b><br>${esc(ns.sub)}</span>`
93
+ + `<button type="button" class="pm-btn primary" data-gl-nskeep="${esc(p.ws)}" aria-label="Approve this North Star" title="Approve this North Star">${SVG(I.check)}</button><button type="button" class="pm-btn outline" data-gl-nsdrop="${esc(p.ws)}" aria-label="No, drop this North Star" title="No">${SVG(I.x)}</button></div>`;
94
+ return `<div class="pm-sug" role="group" aria-label="PMOS suggests"><span class="say">${esc(ns.sub)}</span>`
95
+ + `<button type="button" class="pm-btn primary" data-gl-setup="${esc(p.ws)}" aria-label="Ask PMOS to draft the North Star" title="Ask PMOS to draft the North Star">${SVG(I.spark)}</button></div>`;
77
96
  }
78
-
79
- /* ── the hierarchy: one Table (rowspans hold an objective's name, its levers and its initiatives beside its key results) ── */
80
- const dm = (k) => (k ? `<i class="gl-dm${k === 'rd' ? ' rd' : ''}" aria-hidden="true"></i>` : '');
81
- const iniHtml = (p, i) => `<button type="button" class="gl-hit" data-gl-ws="${esc(p.ws)}" data-gl-ini="${esc(i.id)}"${i.verdict ? ' data-gl-verdict' : ''}><b>${esc(i.title)}</b>${i.line ? `<span class="pm-meta${i.tone ? ' gl-al' : ''}">${dm(i.dm)}${esc(i.line)}</span>` : ''}</button>`;
82
- const inis = (p, items) => `<div class="gl-inis">${items.map((i) => iniHtml(p, i)).join('')}</div>`;
83
- const rs = (n) => (n > 1 ? ` rowspan="${n}"` : '');
84
- function krCells(p, k) {
85
- const act = k.act ? `<b class="${k.tone ? 'gl-al' : ''}">${esc(k.act)}</b>` : '<span class="pm-meta">—</span>';
86
- return `<td class="gl-kr"><button type="button" class="gl-hit" data-gl-ws="${esc(p.ws)}" data-gl-kr="${esc(k.key)}" aria-label="${esc(k.token + ' ' + k.title + '. ' + (k.act ? 'Now ' + k.act : 'No reading') + '. ' + k.sub)}">`
87
- + `<span><span class="pm-meta gl-tok">${esc(k.token)}</span>${esc(k.title)}</span><span class="pm-meta gl-sub">${esc(k.sub)}</span></button></td>`
88
- + `<td class="gl-act">${act}${k.target ? `<span class="pm-meta"> / ${esc(k.target)}</span>` : ''}</td><td class="gl-left pm-meta">${esc(k.left)}</td>`;
89
- }
90
- function objRows(p, o) {
91
- const n = o.krs.length;
92
- return o.krs.map((k, i) => {
93
- let h = '';
94
- if (i === 0) h += `<th scope="rowgroup" class="gl-obj"${rs(n)}><b>${esc(o.label)}</b>${o.title ? `<span class="pm-meta">${esc(o.title)}</span>` : ''}${o.slip ? `<span class="pm-badge alert">${esc(o.slip)}</span>` : ''}</th>`;
95
- h += krCells(p, k);
96
- if (i === 0) h += `<td class="gl-lv"${rs(n)}>${o.levers.map((l) => `<div><b>${esc(l.title)}</b><span class="pm-meta${l.tone ? ' gl-al' : ''}">${esc(l.txt)}</span></div>`).join('')}</td>`;
97
- const c = o.inis.find((x) => x.from === i + 1);
98
- if (c) h += `<td class="gl-in"${rs(c.span)}>${inis(p, c.items)}</td>`;
99
- else if (!o.inis.some((x) => i + 1 > x.from && i + 1 < x.from + x.span)) h += '<td class="gl-in"></td>';
100
- return `<tr${i === 0 ? ' class="gl-first"' : ''}>${h}</tr>`;
101
- }).join('');
102
- }
103
- const wideRow = (head, tone, line, say, items, p) => `<tbody><tr class="gl-first"><th scope="row" class="gl-obj"><b>${esc(head)}</b>${line ? `<span class="pm-meta${tone ? ' gl-al' : ''}">${esc(line)}</span>` : ''}</th>`
104
- + `<td class="gl-wide" colspan="4">${say}</td><td class="gl-in">${inis(p, items)}</td></tr></tbody>`;
105
- function tableHtml(p) {
106
- const T = p.T;
107
- if (!p.model.okrFile) return `<p class="pm-meta gl-none">No OKR file was found for ${esc(nm(p))}, so there is no key result to show. Goals reads the OKR file in planning/okrs/.</p>`;
108
- if (!T.objectives.length && S.filter !== 'all') return `<p class="pm-meta gl-none">No key result is ${esc((GM.FILTERS.find((f) => f[0] === S.filter) || [])[1] || '').toLowerCase()} in ${esc(nm(p))}.</p>`;
109
- const hd = '<thead><tr><th scope="col">Objective</th><th scope="col">Key result</th><th scope="col" class="gl-act">Actual / target</th><th scope="col" class="gl-left">Left</th><th scope="col" class="gl-lv">Levers</th><th scope="col">Initiative</th></tr></thead>';
110
- const bud = T.budgets.map((b) => wideRow('Budget', b.over, b.label + (b.share ? ' · ' + b.share : ''), `<b>No key result: a budget that is always on</b>${b.covers ? `<span class="pm-meta">${esc(b.covers)}</span>` : ''}`, b.items, p)).join('');
111
- const un = T.unlinked.length ? wideRow('Unlinked', false, '', `<span class="pm-meta">${T.unlinked.length === 1 ? 'An initiative with no key result named' : T.unlinked.length + ' initiatives with no key result named'}</span>`, T.unlinked, p) : '';
112
- return `<div class="pm-block list gl-tb"><table class="pm-table" aria-label="Goals of ${esc(nm(p))}">${hd}${T.objectives.map((o) => `<tbody>${objRows(p, o)}</tbody>`).join('')}${bud}${un}</table></div>`;
97
+ function numbersHtml(p) {
98
+ const N = DS.numbersOf(p.model, p.ns);
99
+ if (!N.length) return '';
100
+ return `<div class="gl-nums">${N.map((n) => `<section class="pm-block" aria-label="${esc(n.name)}"><div class="head"><h3 class="pm-h-sm">${esc(n.name)}</h3><span class="sp"></span>`
101
+ + (n.ns ? `<span class="pm-meta">not set</span></div>${nsAsk(p)}` : `${n.at ? `<span class="pm-meta">read ${esc(GM.mdy(n.at))}</span>` : ''}</div>`
102
+ + `<div class="pm-row gl-numr"><span class="pm-num">${esc(n.value)}</span>${n.spark ? `<svg aria-hidden="true" width="120" height="32" viewBox="0 0 120 32"><polyline points="${n.spark}" fill="none" stroke="var(--blue)" stroke-width="2"/></svg>` : ''}</div>`
103
+ + `<p class="pm-meta gl-m0">${esc(n.line)}</p>`) + '</section>').join('')}</div>`;
104
+ }
105
+ /** Where it stands and its one Suggestion, for the first product that has something to say. */
106
+ function standsHtml(p, sug) {
107
+ const say = DS.standsOf(p.model, todayIso());
108
+ if (!say.length && !sug) return '';
109
+ return `<section class="pm-block gl-stands" aria-label="Where it stands"><h2 class="pm-h-sm pm-row">${STAR()}Where it stands</h2>`
110
+ + (say.length ? `<p class="gl-m0">${say.join(' ')}</p>` : '') + (sug ? DS.sugHtml(sug, `data-gl-sk="${esc(sug.key)}" data-gl-sws="${esc(p.ws)}"`, 'data-gl-sug') : '') + '</section>';
113
111
  }
114
112
  function draw() {
115
- if (!S.list.length) { body.innerHTML = `<p class="pm-meta gl-none">${esc(S.error ? 'Goals could not be read: ' + S.error + '.' : 'No product is ticked. Tick one in the product choice.')}</p>`; $('glNote').hidden = true; return; }
113
+ if (!S.list.length) { body.innerHTML = `<p class="pm-meta gl-none">${esc(S.error ? 'Goals could not be read: ' + S.error + '.' : 'No product is ticked. Tick one in the product choice.')}</p>`; $('glNote').hidden = true; $('glTalk').hidden = true; return; }
116
114
  const today = todayIso(), many = S.list.length > 1;
117
115
  let h = '';
116
+ S.sug = null;
118
117
  for (const p of S.list) {
119
118
  if (!p.model) { h += `<section class="gl-p">${many ? `<h2 class="pm-h">${esc(nm(p))}</h2>` : ''}<p class="pm-meta gl-none">${esc(nm(p))} could not be read: ${esc(p.error || 'the server did not answer')}.</p></section>`; continue; }
120
119
  p.T = GM.tableOf(p.model, today, S.filter);
121
120
  p.ns = GM.northStarOf(p.model, p.drafts);
122
- h += `<section class="gl-p" aria-label="${esc(nm(p))}">${many ? `<h2 class="pm-h">${esc(nm(p))}</h2>` : ''}${p.model.okrFile ? nsHtml(p) : ''}${tableHtml(p)}</section>`;
121
+ p.counts = Object.fromEntries(GM.FILTERS.map(([k]) => [k, GM.tableOf(p.model, today, k).shown]));
122
+ const sug = S.sug ? null : DS.sugOf(p.model, p.ns, S.no); // one Suggestion on the page
123
+ if (sug) S.sug = { ...sug, ws: p.ws };
124
+ if (!p.model.okrFile) { h += `<section class="gl-p" aria-label="${esc(nm(p))}">${many ? `<h2 class="pm-h">${esc(nm(p))}</h2>` : ''}<p class="pm-meta gl-none">No OKR file was found for ${esc(nm(p))}, so there is no key result to show. Goals reads the OKR file in planning/okrs/.</p></section>`; continue; }
125
+ h += `<section class="gl-p" aria-label="${esc(nm(p))}">${many ? `<h2 class="pm-h">${esc(nm(p))}</h2>` : ''}${standsHtml(p, sug)}${numbersHtml(p)}`
126
+ + `${DS.tableHtml({ ...p, name: nm(p) }, { today, filter: S.filter === 'read' ? 'pace' : S.filter, cols: S.cols, many })}</section>`;
123
127
  }
124
128
  body.innerHTML = h;
125
129
  $('glNote').hidden = false;
126
- $('glFdot').hidden = S.filter === 'all';
127
130
  drawPer();
131
+ talk();
132
+ }
133
+
134
+ /* ── the Conversation block: the one chat, about Goals of the product ── */
135
+ const T = { box: null, target: null, phone: matchMedia('(max-width: 760px)') };
136
+ function goalsTarget(PC) {
137
+ const p = S.list.find((x) => x.model) || null, ws = p ? p.ws : '', name = p && S.list.length === 1 ? nm(p) : '';
138
+ const base = PC.popTarget({ kind: 'goal', id: 'goals-' + (ws || 'all'), title: name ? 'Goals of ' + name : 'Goals' }, ws || undefined);
139
+ return { ...base, placeholder: 'Ask about a key result, or say a new one', empty: 'Ask why a key result is behind, or say a new one. PMOS reads your goals and says where each answer came from.' };
140
+ }
141
+ async function talk() {
142
+ const host = $('glChat'), sec = $('glTalk');
143
+ if (!S.list.some((x) => x.model) || (window.PMOS_READONLY)) { sec.hidden = true; return; } // a read-only copy has no chat
144
+ sec.hidden = false;
145
+ const PC = await import('./page-chat.js');
146
+ if (!T.box) {
147
+ T.box = await PC.box();
148
+ host.appendChild(T.box.el);
149
+ // the popup borrows this chat and gives it back (cozy-popup.js useChat): never a second chat on the page
150
+ POP.useChat({ el: T.box.el, open: (t) => T.box.chat.open(t), current: () => (T.box.chat.current ? T.box.chat.current() : null), focus: () => T.box.chat.focus(), stop: () => T.box.chat.stop && T.box.chat.stop() });
151
+ new MutationObserver(() => {
152
+ const home = T.box.el.parentNode === host;
153
+ host.classList.toggle('away', !home);
154
+ if (home && T.target) T.box.chat.open(T.target); // back from the popup: the chat about Goals again
155
+ }).observe(host, { childList: true });
156
+ }
157
+ const t = goalsTarget(PC);
158
+ if (!T.target || T.target.key !== t.key) { T.target = t; if (T.box.el.parentNode === host) T.box.chat.open(t); }
159
+ }
160
+ /** Words for PMOS: sent at once (Yes), or put in the box to change first (the pencil, Link, +). */
161
+ async function say(text, send) {
162
+ await talk();
163
+ if (!T.box) return;
164
+ const host = $('glChat');
165
+ if (T.box.el.parentNode !== host) { POP.close(); }
166
+ $('glTalk').scrollIntoView({ block: 'nearest', behavior: 'smooth' });
167
+ if (send) { await T.box.chat.send(text); return; }
168
+ const ta = T.box.el.querySelector('textarea');
169
+ if (ta) { ta.value = text; ta.dispatchEvent(new Event('input', { bubbles: true })); ta.focus(); ta.setSelectionRange(text.length, text.length); }
128
170
  }
129
171
 
130
172
  /* ── load ── */
@@ -164,21 +206,64 @@ async function dropNs(p, row) {
164
206
  undoToast('Dropped.', async () => { await pmPost('/api/metric-drafts/undo', base).catch(() => null); await load(); });
165
207
  await load();
166
208
  }
209
+ const saveNo = () => store.set('pmos.goals.no', JSON.stringify([...S.no].slice(-40)));
210
+ async function onSug(t) {
211
+ const sg = S.sug; if (!sg || t.dataset.glSk !== sg.key) return;
212
+ const p = S.list.find((x) => x.ws === sg.ws) || S.list[0], act = t.dataset.glSug;
213
+ if (sg.kind === 'ns') { // the North Star draft: the metric-drafts keep and drop, with Undo, as before
214
+ if (act === 'yes') { t.disabled = true; keepNs(p, p.ns.row); } else if (act === 'no') { t.disabled = true; dropNs(p, p.ns.row); }
215
+ else say('Change the North Star draft "' + p.ns.title + '": ', false);
216
+ return;
217
+ }
218
+ if (act === 'yes') { say(sg.say, true); return; }
219
+ if (act === 'edit') { say(sg.say, false); return; }
220
+ // No: this Suggestion stays away on this device, with Undo
221
+ S.no.add(sg.key); saveNo(); draw();
222
+ undoToast('PMOS will not suggest this again here.', () => { S.no.delete(sg.key); saveNo(); draw(); });
223
+ }
167
224
  body.onclick = (e) => {
168
- const t = e.target.closest('button'); if (!t) return;
225
+ const t = e.target.closest('button,a'); if (!t || !body.contains(t)) return;
169
226
  const d = t.dataset;
227
+ if (t.tagName === 'A' && (d.glKr || d.glIni)) e.preventDefault();
170
228
  if (d.glKr) { GO.openKr(ctxOf(d.glWs), d.glKr); return; }
171
229
  if (d.glIni) { const c = ctxOf(d.glWs); if ('glVerdict' in d) GO.openVerdict(c, d.glIni); else GO.openIni(c, d.glIni); return; }
230
+ if (d.glSug) { onSug(t); return; }
231
+ if (d.glF) { S.filter = d.glF; store.set('pmos.goals.filt', S.filter); draw(); const b = body.querySelector(`[data-gl-f="${S.filter}"]`); if (b) b.focus(); return; }
232
+ if (d.glCols !== undefined) { openCols(t); return; }
233
+ if (d.glLink) { say(d.glSay, false); return; }
172
234
  if (d.glNskeep) { const p = S.list.find((x) => x.ws === d.glNskeep); if (p && p.ns.row) { t.disabled = true; keepNs(p, p.ns.row); } return; }
173
235
  if (d.glNsdrop) { const p = S.list.find((x) => x.ws === d.glNsdrop); if (p && p.ns.row) { t.disabled = true; dropNs(p, p.ns.row); } return; }
174
236
  if (d.glSetup) { GO.openSetup(ctxOf(d.glSetup)); setTimeout(() => GO.toChat('Draft a North Star for this product from its key results. I approve it with a tick.'), 150); }
175
237
  };
238
+ /* the tabs move with the arrow keys (the system's Tabs part) */
239
+ body.addEventListener('keydown', (e) => {
240
+ const t = e.target.closest && e.target.closest('[data-gl-f]'); if (!t || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft')) return;
241
+ const all = [...t.parentNode.querySelectorAll('[data-gl-f]')], i = all.indexOf(t), n = all[(i + (e.key === 'ArrowRight' ? 1 : all.length - 1)) % all.length];
242
+ e.preventDefault(); n.click();
243
+ });
244
+ $('glNew').onclick = () => say('New key result: ', false);
176
245
 
177
- /* ── the menus: Filter and ⋯ ── */
178
- const MENUS = [['glFilt', 'glFiltMenu'], ['glMore', 'glMoreMenu']];
246
+ /* ── Choose columns: a Menu of the columns, each a tick; remembered on this device ── */
247
+ function openCols(btn) {
248
+ closeMenus();
249
+ const old = document.getElementById('glColsMenu'); if (old) { old.remove(); btn.setAttribute('aria-expanded', 'false'); return; }
250
+ const m = document.createElement('div');
251
+ m.className = 'pm-menu gl-menu'; m.id = 'glColsMenu'; m.setAttribute('role', 'menu'); m.setAttribute('aria-label', 'Choose columns');
252
+ m.innerHTML = DS.COLS.map(([k, label]) => `<button type="button" role="menuitemcheckbox" aria-checked="${S.cols.has(k)}" data-gl-c="${k}">${esc(label)}</button>`).join('');
253
+ btn.parentNode.appendChild(m); btn.setAttribute('aria-expanded', 'true');
254
+ m.onclick = (e) => {
255
+ const b = e.target.closest('[data-gl-c]'); if (!b) return;
256
+ const k = b.dataset.glC; if (S.cols.has(k)) S.cols.delete(k); else S.cols.add(k);
257
+ store.set('pmos.goals.cols', JSON.stringify([...S.cols])); draw();
258
+ };
259
+ m.querySelector('button').focus();
260
+ }
261
+ document.addEventListener('click', (e) => { const m = document.getElementById('glColsMenu'); if (m && !e.target.closest('#glColsMenu') && !e.target.closest('[data-gl-cols]')) m.remove(); });
262
+
263
+ /* ── the ⋯ menu ── */
264
+ const MENUS = [['glMore', 'glMoreMenu']];
179
265
  function closeMenus(except) { for (const [b, m] of MENUS) if (m !== except && !$(m).hidden) { $(m).hidden = true; $(b).setAttribute('aria-expanded', 'false'); } }
180
266
  function drawMenus() {
181
- $('glFiltMenu').innerHTML = GM.FILTERS.map(([k, label]) => `<button type="button" role="menuitemradio" aria-checked="${S.filter === k}" data-gl-f="${k}">${esc(label)}</button>`).join('');
182
267
  $('glMoreMenu').innerHTML = '<button type="button" role="menuitem" data-gl-m="setup">Set up</button><button type="button" role="menuitem" data-gl-m="charts">Charts and dashboards</button><button type="button" role="menuitem" data-gl-m="csv">Export CSV</button>';
183
268
  }
184
269
  for (const [b, m] of MENUS) {
@@ -189,11 +274,11 @@ for (const [b, m] of MENUS) {
189
274
  };
190
275
  }
191
276
  document.addEventListener('click', (e) => { for (const [b, m] of MENUS) if (!$(m).hidden && !e.target.closest('#' + m) && !e.target.closest('#' + b)) { $(m).hidden = true; $(b).setAttribute('aria-expanded', 'false'); } });
192
- document.addEventListener('keydown', (e) => { if (e.key !== 'Escape') return; for (const [b, m] of MENUS) if (!$(m).hidden) { $(m).hidden = true; $(b).setAttribute('aria-expanded', 'false'); $(b).focus(); } });
193
- $('glFiltMenu').onclick = (e) => {
194
- const t = e.target.closest('[data-gl-f]'); if (!t) return;
195
- S.filter = t.dataset.glF; store.set('pmos.goals.filt', S.filter); closeMenus(); draw();
196
- };
277
+ document.addEventListener('keydown', (e) => {
278
+ if (e.key !== 'Escape') return;
279
+ const c = document.getElementById('glColsMenu'); if (c) { c.remove(); const b = body.querySelector('[data-gl-cols]'); if (b) b.focus(); }
280
+ for (const [b, m] of MENUS) if (!$(m).hidden) { $(m).hidden = true; $(b).setAttribute('aria-expanded', 'false'); $(b).focus(); }
281
+ });
197
282
  $('glMoreMenu').onclick = (e) => {
198
283
  const t = e.target.closest('[data-gl-m]'); if (!t) return;
199
284
  closeMenus();