create-pmos 0.397.0 → 0.399.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.
- package/package.json +25 -25
- package/payload/KIT-VERSION +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +105 -52
- package/workspace/briefing-premium-board-test.js +284 -128
- package/workspace/briefing-premium-calendar-2-test.js +135 -198
- package/workspace/briefing-premium-calendar-3-test.js +143 -418
- package/workspace/briefing-premium-calendar-test.js +85 -196
- package/workspace/briefing-premium-doc-edit-test.js +99 -83
- package/workspace/briefing-premium-initiative-test.js +175 -290
- package/workspace/briefing-premium-insights-test.js +414 -219
- package/workspace/briefing-premium-metrics-test.js +55 -97
- package/workspace/briefing-premium-products-test.js +44 -28
- package/workspace/briefing-premium-sources-test.js +70 -49
- package/workspace/briefing-premium-test.js +155 -648
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +24 -0
- package/workspace/ev-everywhere-test.js +210 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +187 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +68 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-grill.js +63 -0
- package/workspace/lib/board-premium.js +121 -24
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/initiative-layout.js +77 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +64 -15
- package/workspace/lib/insights-records.js +115 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/meeting-points.js +52 -0
- package/workspace/lib/news-for-you.js +88 -0
- package/workspace/lib/notes-series.js +29 -6
- package/workspace/lib/report-confirm.js +48 -0
- package/workspace/lib/route-modules.js +12 -0
- package/workspace/lib/routes-board-docs.js +46 -0
- package/workspace/lib/routes-board-grill.js +90 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-home-review.js +108 -0
- package/workspace/lib/routes-initiative-layout.js +57 -0
- package/workspace/lib/routes-insights-premium.js +16 -4
- package/workspace/lib/routes-insights-records.js +133 -0
- package/workspace/lib/routes-meeting-points.js +37 -0
- package/workspace/lib/routes-news.js +57 -0
- package/workspace/lib/routes-notes.js +3 -1
- package/workspace/lib/routes-report-confirm.js +31 -0
- package/workspace/lib/routes-search.js +38 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/search-index.js +176 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/viewer-meeting.js +205 -0
- package/workspace/lib/viewer-report.js +89 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +128 -82
- package/workspace/premium-briefing-depth-test.js +104 -90
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +37 -37
- package/workspace/premium-chat-context-test.js +19 -18
- package/workspace/premium-chat-goal-view-test.js +23 -23
- package/workspace/premium-chat-notes-test.js +26 -31
- package/workspace/premium-chat-report-tab-test.js +46 -28
- package/workspace/premium-chat-term-test.js +16 -16
- package/workspace/premium-chat-viewer-test.js +60 -59
- package/workspace/premium-core-doc-issue-test.js +52 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +10 -3
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +152 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -33
- package/workspace/premium-vw-cal-test.js +97 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +17 -10
- package/workspace/premium-vw-item-test.js +50 -49
- package/workspace/premium-vw-jira-test.js +53 -27
- package/workspace/premium-vw-meet-test.js +115 -187
- package/workspace/premium-vw-notes-test.js +88 -109
- package/workspace/premium-vw-rec-test.js +71 -194
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +61 -53
- package/workspace/public/pm/bd-acts.js +383 -0
- package/workspace/public/pm/bd-asks.js +261 -0
- package/workspace/public/pm/bd-pop.js +59 -0
- package/workspace/public/pm/bd-span.js +222 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- package/workspace/public/pm/bd-views.js +169 -0
- package/workspace/public/pm/c3-doc-sheet.js +1 -1
- package/workspace/public/pm/c3-md.js +3 -395
- package/workspace/public/pm/c3-phone-detail.js +1 -1
- package/workspace/public/pm/c3-phone-model.js +3 -68
- package/workspace/public/pm/chat-term.js +3 -3
- package/workspace/public/pm/cozy-board.css +798 -230
- package/workspace/public/pm/cozy-ev.css +228 -0
- package/workspace/public/pm/cozy-evmodel.js +106 -0
- package/workspace/public/pm/cozy-evui.js +47 -0
- package/workspace/public/pm/cozy-home.css +570 -142
- package/workspace/public/pm/cozy-home.js +5 -3
- package/workspace/public/pm/cozy-insights.css +437 -170
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +104 -29
- package/workspace/public/pm/cozy-news.js +140 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-search.js +203 -0
- package/workspace/public/pm/cozy-settings.js +198 -0
- package/workspace/public/pm/cozy-sources.js +89 -0
- package/workspace/public/pm/cozy-today.css +217 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +145 -0
- package/workspace/public/pm/cozy-vw-mtg.css +350 -0
- package/workspace/public/pm/cozy-vw-rp.css +152 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +83 -1
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +1179 -0
- package/workspace/public/pm/home-around.js +413 -0
- package/workspace/public/pm/home-chat.js +512 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-dictate.js +54 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-ini-model.js +190 -0
- package/workspace/public/pm/home-ini.css +171 -0
- package/workspace/public/pm/home-ini.js +456 -0
- package/workspace/public/pm/home-list.js +276 -0
- package/workspace/public/pm/home-more.js +132 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-review.js +104 -0
- package/workspace/public/pm/home-task.js +67 -0
- package/workspace/public/pm/home-today.js +144 -0
- package/workspace/public/pm/home-work.js +547 -0
- package/workspace/public/pm/phone-moment.js +69 -0
- package/workspace/public/pm/pm-work-view.js +1 -1
- package/workspace/public/pm/premium-attach.js +4 -0
- package/workspace/public/pm/premium-board.js +548 -395
- package/workspace/public/pm/premium-chart-tab.js +109 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +23 -21
- package/workspace/public/pm/premium-insights.js +1102 -581
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-mtg-present.js +138 -0
- package/workspace/public/pm/premium-mtg-replay.js +142 -0
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +669 -476
- package/workspace/public/pm/premium-report-tab.js +116 -67
- package/workspace/public/pm/premium-shell.js +76 -123
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +277 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +958 -0
- package/workspace/public/pm/premium-vw-notes.js +116 -68
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -218
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/rp-parts.js +269 -0
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +29 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +26 -64
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +18 -107
- package/workspace/r/m1.png +0 -0
- package/workspace/r/m2.png +0 -0
- package/workspace/r/m3.png +0 -0
- package/workspace/r/nl.png +0 -0
- package/workspace/server.js +18 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/initiative-layout.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
- package/workspace/test-lists/premium-uncovered-reports.json +9 -0
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/test-lists/uf-everywhere.json +15 -0
- package/workspace/test-lists/uf-home.json +9 -0
- package/workspace/test-lists/uncovered-board.json +9 -0
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/* pm/cozy-md.js — markdown for the console3 document sheet (initiative c3-doc-sheet-rich): read it as rich text, edit it as rich
|
|
2
|
+
* text, and show a change as a rendered diff.
|
|
3
|
+
* Moved here from pm/c3-md.js (premium-agreed-design), so premium pages load no c3-* module; c3-md.js re-exports it.
|
|
4
|
+
*
|
|
5
|
+
* parseMd(md) → blocks the subset PMOS documents use: headings, paragraphs, quotes, bulleted, numbered and
|
|
6
|
+
* checklist lists, tables, dividers and fenced code; inline bold, italic, code and links
|
|
7
|
+
* toMd(blocks) → md the canonical markdown of blocks; toMd(parseMd(toMd(b))) === toMd(b)
|
|
8
|
+
* canonMd(md) → md toMd(parseMd(md)): two texts that read the same compare equal
|
|
9
|
+
* diffMd(before, after) → md `after`, with the words removed and added since `before` wrapped in markers that
|
|
10
|
+
* toDom draws as <del> and <ins>; a line or sentence rewritten in most of its words is
|
|
11
|
+
* shown whole, removed then added
|
|
12
|
+
* toDom(blocks, doc?) → Node[] the blocks as elements (no innerHTML: every text is a text node); links are http(s),
|
|
13
|
+
* mailto or relative only
|
|
14
|
+
* fromDom(root) → blocks what the rich-text editor holds, read back as blocks
|
|
15
|
+
*
|
|
16
|
+
* parseMd, toMd, canonMd and diffMd are pure (Node-testable: c3-md.test.js); toDom and fromDom need a document.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export const INS = '\uE000';
|
|
20
|
+
export const INS_END = '\uE001';
|
|
21
|
+
export const DEL = '\uE002';
|
|
22
|
+
export const DEL_END = '\uE003';
|
|
23
|
+
const MARK = /[\uE000-\uE003]/g;
|
|
24
|
+
|
|
25
|
+
/* ── inline ── */
|
|
26
|
+
|
|
27
|
+
/** Inline markdown → [{ t:'text', s } | { t:'b'|'i', c:[…] } | { t:'code', s } | { t:'a', href, c:[…] }]. */
|
|
28
|
+
export function parseInline(src) {
|
|
29
|
+
const s = String(src == null ? '' : src);
|
|
30
|
+
const out = [];
|
|
31
|
+
let buf = '';
|
|
32
|
+
const flush = () => { if (buf) { out.push({ t: 'text', s: buf }); buf = ''; } };
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < s.length) {
|
|
35
|
+
const c = s[i];
|
|
36
|
+
if (c === '\\' && i + 1 < s.length && /[\\`*_[\]()#|>-]/.test(s[i + 1])) { buf += s[i + 1]; i += 2; continue; }
|
|
37
|
+
if (c === '`') {
|
|
38
|
+
const j = s.indexOf('`', i + 1);
|
|
39
|
+
if (j > i) { flush(); out.push({ t: 'code', s: s.slice(i + 1, j) }); i = j + 1; continue; }
|
|
40
|
+
}
|
|
41
|
+
if (c === '[') {
|
|
42
|
+
const m = /^\[((?:[^\]\\]|\\.)+)\]\(([^)\s]+)\)/.exec(s.slice(i));
|
|
43
|
+
if (m) { flush(); out.push({ t: 'a', href: m[2], c: parseInline(m[1]) }); i += m[0].length; continue; }
|
|
44
|
+
}
|
|
45
|
+
if ((c === '*' || c === '_') && s[i + 1] === c) {
|
|
46
|
+
const j = s.indexOf(c + c, i + 2);
|
|
47
|
+
if (j > i + 2) { flush(); out.push({ t: 'b', c: parseInline(s.slice(i + 2, j)) }); i = j + 2; continue; }
|
|
48
|
+
}
|
|
49
|
+
if ((c === '*' || c === '_') && s[i + 1] !== c && s[i + 1] !== ' ' && (c === '*' || !/\w/.test(s[i - 1] || ''))) {
|
|
50
|
+
let j = i + 1;
|
|
51
|
+
while (j < s.length && !(s[j] === c && s[j + 1] !== c && s[j - 1] !== ' ' && s[j - 1] !== c)) j++;
|
|
52
|
+
if (j < s.length && j > i + 1 && (c === '*' || !/\w/.test(s[j + 1] || ''))) { flush(); out.push({ t: 'i', c: parseInline(s.slice(i + 1, j)) }); i = j + 1; continue; }
|
|
53
|
+
}
|
|
54
|
+
buf += c; i++;
|
|
55
|
+
}
|
|
56
|
+
flush();
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Text is escaped only where markdown would read it as syntax: a backslash before punctuation, `, *, [ and ], and an _ that
|
|
61
|
+
// is not inside a word (snake_case stays as written).
|
|
62
|
+
const escText = (s) => String(s).replace(/\\(?=[\\`*_[\]()#|>-])/g, '\\\\').replace(/[`*[\]]/g, '\\$&').replace(/(^|\W)_|_(?=\W|$)/g, (m) => m.replace('_', '\\_'));
|
|
63
|
+
/** Inline nodes → markdown. `raw`: text as it is, unescaped (for a plain-text label). */
|
|
64
|
+
export function inlineMd(nodes, raw) {
|
|
65
|
+
return (nodes || []).map((n) => {
|
|
66
|
+
if (n.t === 'text') return raw ? n.s : escText(n.s);
|
|
67
|
+
if (n.t === 'code') return raw ? n.s : '`' + n.s + '`';
|
|
68
|
+
const inner = inlineMd(n.c, raw);
|
|
69
|
+
if (raw || !inner.trim()) return inner;
|
|
70
|
+
const lead = inner.match(/^\s*/)[0]; const tail = inner.match(/\s*$/)[0]; const core = inner.trim();
|
|
71
|
+
if (n.t === 'b') return lead + '**' + core + '**' + tail;
|
|
72
|
+
if (n.t === 'i') return lead + '*' + core + '*' + tail;
|
|
73
|
+
if (n.t === 'a') return lead + '[' + core + '](' + n.href + ')' + tail;
|
|
74
|
+
return inner;
|
|
75
|
+
}).join('');
|
|
76
|
+
}
|
|
77
|
+
// a paragraph or list item whose text would start a heading, quote, list or rule is escaped at its start
|
|
78
|
+
const lineSafe = (s) => s.replace(/^(#{1,6}\s|>|[-+]\s|\d+[.)]\s|-{3,}\s*$)/, '\\$1');
|
|
79
|
+
|
|
80
|
+
/* ── blocks ── */
|
|
81
|
+
|
|
82
|
+
const LIST = /^(\s*)([-*+]|\d+[.)])\s+/;
|
|
83
|
+
const TASK = /^\[( |x|X)\]\s+/;
|
|
84
|
+
const cells = (r) => {
|
|
85
|
+
const t = r.trim().replace(/^\|/, '').replace(/\|\s*$/, '');
|
|
86
|
+
const out = []; let cur = ''; for (let i = 0; i < t.length; i++) { if (t[i] === '\\' && t[i + 1] === '|') { cur += '|'; i++; } else if (t[i] === '|') { out.push(cur.trim()); cur = ''; } else cur += t[i]; }
|
|
87
|
+
out.push(cur.trim()); return out;
|
|
88
|
+
};
|
|
89
|
+
const isRule = (l) => /^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(l);
|
|
90
|
+
const startsBlock = (l) => /^(#{1,6}\s|>|```|~~~|\s*(-{3,}|\*{3,}|_{3,})\s*$)/.test(l) || LIST.test(l) || /^\s*\|/.test(l);
|
|
91
|
+
|
|
92
|
+
/** Markdown → blocks: { t:'h', level, c } · { t:'p', c } · { t:'quote', blocks } · { t:'list', ordered, items:[{ task, c }] } ·
|
|
93
|
+
* { t:'table', head:[c], rows:[[c]] } · { t:'hr' } · { t:'code', lang, s }. Marker characters (diffMd) pass through as text. */
|
|
94
|
+
export function parseMd(md) {
|
|
95
|
+
const L = String(md == null ? '' : md).replace(/\r\n?/g, '\n').split('\n');
|
|
96
|
+
const out = []; let i = 0;
|
|
97
|
+
const bare = (l) => l.replace(MARK, '');
|
|
98
|
+
while (i < L.length) {
|
|
99
|
+
const l = L[i]; const b = bare(l); let m;
|
|
100
|
+
if (!b.trim()) { i++; continue; }
|
|
101
|
+
if ((m = /^(```|~~~)\s*([\w-]*)/.exec(b))) {
|
|
102
|
+
const fence = m[1]; const body = []; i++;
|
|
103
|
+
while (i < L.length && !bare(L[i]).startsWith(fence)) body.push(L[i++]);
|
|
104
|
+
i++; out.push({ t: 'code', lang: m[2] || '', s: body.join('\n') }); continue;
|
|
105
|
+
}
|
|
106
|
+
if ((m = /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(l))) { out.push({ t: 'h', level: m[1].length, c: parseInline(m[2]) }); i++; continue; }
|
|
107
|
+
if (/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(b)) { out.push({ t: 'hr' }); i++; continue; }
|
|
108
|
+
if (/^\s*>/.test(b)) {
|
|
109
|
+
const body = [];
|
|
110
|
+
while (i < L.length && /^\s*>/.test(bare(L[i]))) body.push(L[i++].replace(/^(\s*[\uE000-\uE003]*)\s*>\s?/, '$1'));
|
|
111
|
+
out.push({ t: 'quote', blocks: parseMd(body.join('\n')) }); continue;
|
|
112
|
+
}
|
|
113
|
+
if (/^\s*\|/.test(b) && i + 1 < L.length && isRule(bare(L[i + 1]))) {
|
|
114
|
+
const head = cells(l); i += 2; const rows = [];
|
|
115
|
+
while (i < L.length && /^\s*\|/.test(bare(L[i]))) rows.push(cells(L[i++]));
|
|
116
|
+
out.push({ t: 'table', head: head.map(parseInline), rows: rows.map((r) => head.map((_, k) => parseInline(r[k] || ''))) }); continue;
|
|
117
|
+
}
|
|
118
|
+
if (LIST.test(b)) {
|
|
119
|
+
const ordered = /^\s*\d/.test(b); const items = [];
|
|
120
|
+
while (i < L.length && LIST.test(bare(L[i])) && /^\s*\d/.test(bare(L[i])) === ordered) {
|
|
121
|
+
const lead = (/^[\uE000-\uE003]*/.exec(L[i]) || [''])[0];
|
|
122
|
+
let t = lead + L[i].slice(lead.length).replace(LIST, ''); i++;
|
|
123
|
+
while (i < L.length && /^\s{2,}\S/.test(L[i]) && !LIST.test(bare(L[i]))) t += ' ' + L[i++].trim();
|
|
124
|
+
const tk = TASK.exec(t.replace(MARK, ''));
|
|
125
|
+
if (tk) { const k = t.indexOf('['); t = t.slice(0, k) + t.slice(k).replace(TASK, ''); }
|
|
126
|
+
items.push({ task: tk ? tk[1] !== ' ' : null, c: parseInline(t) });
|
|
127
|
+
}
|
|
128
|
+
out.push({ t: 'list', ordered, items }); continue;
|
|
129
|
+
}
|
|
130
|
+
const body = [];
|
|
131
|
+
while (i < L.length && bare(L[i]).trim() && (!body.length || !startsBlock(bare(L[i])))) body.push(L[i++].trim());
|
|
132
|
+
out.push({ t: 'p', c: parseInline(body.join(' ')) });
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Blocks → markdown, one blank line between blocks. */
|
|
138
|
+
export function toMd(blocks) {
|
|
139
|
+
return (blocks || []).map((b) => {
|
|
140
|
+
if (b.t === 'h') return '#'.repeat(b.level || 2) + ' ' + inlineMd(b.c).trim();
|
|
141
|
+
if (b.t === 'p') return lineSafe(inlineMd(b.c).trim());
|
|
142
|
+
if (b.t === 'hr') return '---';
|
|
143
|
+
if (b.t === 'code') return '```' + (b.lang || '') + '\n' + b.s + '\n```';
|
|
144
|
+
if (b.t === 'quote') return toMd(b.blocks).split('\n').map((x) => (x ? '> ' + x : '>')).join('\n');
|
|
145
|
+
if (b.t === 'list') return b.items.map((it, k) => (b.ordered ? (k + 1) + '. ' : '- ') + (it.task == null ? '' : it.task ? '[x] ' : '[ ] ') + inlineMd(it.c).trim()).join('\n');
|
|
146
|
+
if (b.t === 'table') {
|
|
147
|
+
const cell = (c) => inlineMd(c).trim().replace(/\|/g, '\\|');
|
|
148
|
+
const w = Math.max(b.head.length, ...b.rows.map((r) => r.length));
|
|
149
|
+
const line = (r) => '| ' + Array.from({ length: w }, (_, k) => (r[k] ? cell(r[k]) : '')).join(' | ') + ' |';
|
|
150
|
+
return [line(b.head), '|' + Array.from({ length: w }, () => '---').join('|') + '|', ...b.rows.map(line)].join('\n');
|
|
151
|
+
}
|
|
152
|
+
return '';
|
|
153
|
+
}).filter((x) => x !== '').join('\n\n');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const canonMd = (md) => toMd(parseMd(md));
|
|
157
|
+
|
|
158
|
+
/* ── the rendered diff ── */
|
|
159
|
+
|
|
160
|
+
function lcs(a, b) {
|
|
161
|
+
const n = a.length, m = b.length;
|
|
162
|
+
if (n * m > 400000) return [...a.map((x) => ['-', x]), ...b.map((x) => ['+', x])];
|
|
163
|
+
const T = Array.from({ length: n + 1 }, () => new Int32Array(m + 1));
|
|
164
|
+
for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) T[i][j] = a[i] === b[j] ? T[i + 1][j + 1] + 1 : Math.max(T[i + 1][j], T[i][j + 1]);
|
|
165
|
+
const ops = []; let i = 0, j = 0;
|
|
166
|
+
while (i < n && j < m) { if (a[i] === b[j]) { ops.push(['=', a[i]]); i++; j++; } else if (T[i + 1][j] >= T[i][j + 1]) ops.push(['-', a[i++]]); else ops.push(['+', b[j++]]); }
|
|
167
|
+
while (i < n) ops.push(['-', a[i++]]); while (j < m) ops.push(['+', b[j++]]);
|
|
168
|
+
return ops;
|
|
169
|
+
}
|
|
170
|
+
/** Runs of ops: [{ eq:true, items } | { eq:false, del:[…], add:[…] }]. */
|
|
171
|
+
function runs(ops) {
|
|
172
|
+
const out = [];
|
|
173
|
+
for (const [op, x] of ops) {
|
|
174
|
+
const last = out[out.length - 1];
|
|
175
|
+
if (op === '=') { if (last && last.eq) last.items.push(x); else out.push({ eq: true, items: [x] }); }
|
|
176
|
+
else { if (!last || last.eq) out.push({ eq: false, del: [], add: [] }); out[out.length - 1][op === '-' ? 'del' : 'add'].push(x); }
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
const wrap = (s, a, z) => (s && s.trim() ? a + s + z : s);
|
|
181
|
+
function words(a, b) {
|
|
182
|
+
const tok = (x) => x.match(/\s+|[^\s]+/g) || [];
|
|
183
|
+
const A = tok(a), B = tok(b); const ops = lcs(A, B);
|
|
184
|
+
const real = (x) => /\S/.test(x);
|
|
185
|
+
const same = ops.filter(([o, x]) => o === '=' && real(x)).length;
|
|
186
|
+
const tot = Math.max(A.filter(real).length, B.filter(real).length);
|
|
187
|
+
if (tot > 4 && same / tot < 0.6) return wrap(a, DEL, DEL_END) + ' ' + wrap(b, INS, INS_END);
|
|
188
|
+
return runs(ops).map((r) => (r.eq ? r.items.join('') : wrap(r.del.join(''), DEL, DEL_END) + (r.del.length && r.add.length ? ' ' : '') + wrap(r.add.join(''), INS, INS_END))).join('');
|
|
189
|
+
}
|
|
190
|
+
function sentences(a, b) {
|
|
191
|
+
const cut = (x) => x.split(/(?<=[.;!?])\s+/);
|
|
192
|
+
const A = cut(a), B = cut(b);
|
|
193
|
+
if (A.length < 2 && B.length < 2) return words(a, b);
|
|
194
|
+
return runs(lcs(A, B)).map((r) => {
|
|
195
|
+
if (r.eq) return r.items.join(' ');
|
|
196
|
+
const n = Math.min(r.del.length, r.add.length); const parts = [];
|
|
197
|
+
for (let k = 0; k < n; k++) parts.push(words(r.del[k], r.add[k]));
|
|
198
|
+
r.del.slice(n).forEach((x) => parts.push(wrap(x, DEL, DEL_END)));
|
|
199
|
+
r.add.slice(n).forEach((x) => parts.push(wrap(x, INS, INS_END)));
|
|
200
|
+
return parts.join(' ');
|
|
201
|
+
}).join(' ');
|
|
202
|
+
}
|
|
203
|
+
const PREFIX = /^(\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?|\s*>\s?|#{1,6}\s+)/;
|
|
204
|
+
function wrapLine(l, a, z) {
|
|
205
|
+
if (!l.trim() || isRule(l)) return l;
|
|
206
|
+
if (/^\s*\|/.test(l)) return '| ' + cells(l).map((c) => wrap(c, a, z)).join(' | ') + ' |';
|
|
207
|
+
if (/^(```|~~~)/.test(l) || /^\s*(-{3,}|\*{3,})\s*$/.test(l)) return l;
|
|
208
|
+
const p = (PREFIX.exec(l) || [''])[0];
|
|
209
|
+
return p + wrap(l.slice(p.length), a, z);
|
|
210
|
+
}
|
|
211
|
+
function lineDiff(a, b) {
|
|
212
|
+
const pa = (PREFIX.exec(a) || [''])[0], pb = (PREFIX.exec(b) || [''])[0];
|
|
213
|
+
if (/^\s*\|/.test(a) && /^\s*\|/.test(b) && !isRule(a) && !isRule(b)) {
|
|
214
|
+
const ca = cells(a), cb = cells(b);
|
|
215
|
+
return '| ' + cb.map((c, k) => (ca[k] === c ? c : sentences(ca[k] || '', c))).join(' | ') + ' |';
|
|
216
|
+
}
|
|
217
|
+
if (pa === pb) return pb + sentences(a.slice(pa.length), b.slice(pb.length));
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** `after` with the change since `before` marked. `before` null: the whole of `after` is new. */
|
|
222
|
+
export function diffMd(before, after) {
|
|
223
|
+
const B = String(after == null ? '' : after).split('\n');
|
|
224
|
+
if (before == null) return B.map((l) => wrapLine(l, INS, INS_END)).join('\n');
|
|
225
|
+
const A = String(before).split('\n');
|
|
226
|
+
const out = [];
|
|
227
|
+
for (const r of runs(lcs(A, B))) {
|
|
228
|
+
if (r.eq) { out.push(...r.items); continue; }
|
|
229
|
+
const n = Math.min(r.del.length, r.add.length);
|
|
230
|
+
const removed = []; const added = [];
|
|
231
|
+
for (let k = 0; k < n; k++) {
|
|
232
|
+
const d = lineDiff(r.del[k], r.add[k]);
|
|
233
|
+
if (d == null) { removed.push(wrapLine(r.del[k], DEL, DEL_END)); added.push(wrapLine(r.add[k], INS, INS_END)); } else added.push(d);
|
|
234
|
+
}
|
|
235
|
+
r.del.slice(n).forEach((l) => removed.push(wrapLine(l, DEL, DEL_END)));
|
|
236
|
+
r.add.slice(n).forEach((l) => added.push(wrapLine(l, INS, INS_END)));
|
|
237
|
+
// a removed table row or list item stays in its table or list: put it with the rows after it
|
|
238
|
+
out.push(...removed.filter((l) => l.trim()), ...added);
|
|
239
|
+
}
|
|
240
|
+
return out.join('\n');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Words added and removed between two texts: [added, removed]. */
|
|
244
|
+
export function wordCounts(before, after) {
|
|
245
|
+
const A = String(before || '').match(/\S+/g) || [], B = String(after || '').match(/\S+/g) || [];
|
|
246
|
+
let add = 0, del = 0;
|
|
247
|
+
for (const [o] of lcs(A, B)) { if (o === '+') add++; else if (o === '-') del++; }
|
|
248
|
+
return [add, del];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/* ── DOM ── */
|
|
252
|
+
|
|
253
|
+
/** A safe href: http(s), mailto, a fragment or a relative path; anything else (javascript:, data:) is dropped. */
|
|
254
|
+
export function safeHref(h) {
|
|
255
|
+
const s = String(h || '').trim();
|
|
256
|
+
if (/^(https?:|mailto:)/i.test(s)) return s;
|
|
257
|
+
if (/^[a-z][\w+.-]*:/i.test(s)) return null;
|
|
258
|
+
return s;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Text with diff markers → nodes: the marked runs inside <ins> and <del>. `st` carries an open marker across inline nodes. */
|
|
262
|
+
function textNodes(doc, s, st) {
|
|
263
|
+
const out = []; let buf = '';
|
|
264
|
+
const push = () => {
|
|
265
|
+
if (!buf) return;
|
|
266
|
+
const t = doc.createTextNode(buf); buf = '';
|
|
267
|
+
if (st.mode) { const w = doc.createElement(st.mode); w.appendChild(t); out.push(w); } else out.push(t);
|
|
268
|
+
};
|
|
269
|
+
for (const ch of String(s)) {
|
|
270
|
+
if (ch === INS || ch === DEL) { push(); st.mode = ch === INS ? 'ins' : 'del'; }
|
|
271
|
+
else if (ch === INS_END || ch === DEL_END) { push(); st.mode = null; }
|
|
272
|
+
else buf += ch;
|
|
273
|
+
}
|
|
274
|
+
push();
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
function inlineDom(doc, nodes, st) {
|
|
278
|
+
const out = [];
|
|
279
|
+
for (const n of nodes || []) {
|
|
280
|
+
if (n.t === 'text') { out.push(...textNodes(doc, n.s, st)); continue; }
|
|
281
|
+
if (n.t === 'code') { const c = doc.createElement('code'); c.append(...textNodes(doc, n.s, st)); out.push(c); continue; }
|
|
282
|
+
const tag = n.t === 'b' ? 'strong' : n.t === 'i' ? 'em' : 'a';
|
|
283
|
+
const e = doc.createElement(tag);
|
|
284
|
+
if (n.t === 'a') {
|
|
285
|
+
const h = safeHref(n.href);
|
|
286
|
+
if (h != null) { e.setAttribute('href', h); if (/^https?:/i.test(h)) { e.setAttribute('target', '_blank'); e.setAttribute('rel', 'noopener'); } }
|
|
287
|
+
}
|
|
288
|
+
e.append(...inlineDom(doc, n.c, st));
|
|
289
|
+
out.push(e);
|
|
290
|
+
}
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Blocks → elements. `opts.editable` draws checklist boxes that can be ticked (the editor). */
|
|
295
|
+
export function toDom(blocks, doc, opts = {}) {
|
|
296
|
+
const d = doc || document;
|
|
297
|
+
const mk = (tag, cls) => { const e = d.createElement(tag); if (cls) e.className = cls; return e; };
|
|
298
|
+
return (blocks || []).map((b) => {
|
|
299
|
+
const st = { mode: null };
|
|
300
|
+
if (b.t === 'h') { const e = mk('h' + Math.min(6, Math.max(1, b.level || 2))); e.append(...inlineDom(d, b.c, st)); return e; }
|
|
301
|
+
if (b.t === 'p') { const e = mk('p'); e.append(...inlineDom(d, b.c, st)); return e; }
|
|
302
|
+
if (b.t === 'hr') return mk('hr');
|
|
303
|
+
if (b.t === 'code') { const p = mk('pre'); if (b.lang) p.setAttribute('data-lang', b.lang); const c = mk('code'); c.append(...textNodes(d, b.s, st)); p.appendChild(c); return p; }
|
|
304
|
+
if (b.t === 'quote') { const q = mk('blockquote'); q.append(...toDom(b.blocks, d, opts)); return q; }
|
|
305
|
+
if (b.t === 'list') {
|
|
306
|
+
const l = mk(b.ordered ? 'ol' : 'ul', b.items.some((it) => it.task != null) ? 'tasks' : '');
|
|
307
|
+
for (const it of b.items) {
|
|
308
|
+
const li = mk('li');
|
|
309
|
+
if (it.task != null) {
|
|
310
|
+
li.className = 'task' + (it.task ? ' done' : '');
|
|
311
|
+
const box = mk('input'); box.type = 'checkbox'; box.checked = !!it.task; box.setAttribute('aria-label', 'Done');
|
|
312
|
+
if (opts.editable) box.setAttribute('contenteditable', 'false'); else box.disabled = true;
|
|
313
|
+
const sp = mk('span'); sp.append(...inlineDom(d, it.c, st));
|
|
314
|
+
li.append(box, sp);
|
|
315
|
+
} else li.append(...inlineDom(d, it.c, st));
|
|
316
|
+
l.appendChild(li);
|
|
317
|
+
}
|
|
318
|
+
return l;
|
|
319
|
+
}
|
|
320
|
+
if (b.t === 'table') {
|
|
321
|
+
const w = mk('div', 'tw'); const t = mk('table'); const th = mk('thead'); const tr = mk('tr');
|
|
322
|
+
for (const c of b.head) { const x = mk('th'); x.append(...inlineDom(d, c, st)); tr.appendChild(x); }
|
|
323
|
+
th.appendChild(tr); const tb = mk('tbody');
|
|
324
|
+
for (const r of b.rows) { const row = mk('tr'); for (const c of r) { const x = mk('td'); x.append(...inlineDom(d, c, st)); row.appendChild(x); } tb.appendChild(row); }
|
|
325
|
+
t.append(th, tb); w.appendChild(t); return w;
|
|
326
|
+
}
|
|
327
|
+
return d.createTextNode('');
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/* reading the editor back */
|
|
332
|
+
function inlineOf(n) {
|
|
333
|
+
const out = [];
|
|
334
|
+
const text = (s) => { if (!s) return; const last = out[out.length - 1]; if (last && last.t === 'text') last.s += s; else out.push({ t: 'text', s }); };
|
|
335
|
+
for (const c of Array.from(n.childNodes || [])) {
|
|
336
|
+
if (c.nodeType === 3) { text(c.textContent.replace(/\u00a0/g, ' ').replace(/\u200b/g, '').replace(/\s+/g, ' ')); continue; }
|
|
337
|
+
if (c.nodeType !== 1) continue;
|
|
338
|
+
const t = c.tagName;
|
|
339
|
+
if (t === 'BR') { text(' '); continue; }
|
|
340
|
+
if (t === 'INPUT' || t === 'UL' || t === 'OL') continue;
|
|
341
|
+
if (t === 'CODE') { out.push({ t: 'code', s: c.textContent.replace(/\u200b/g, '') }); continue; }
|
|
342
|
+
if (t === 'STRONG' || t === 'B') { out.push({ t: 'b', c: inlineOf(c) }); continue; }
|
|
343
|
+
if (t === 'EM' || t === 'I') { out.push({ t: 'i', c: inlineOf(c) }); continue; }
|
|
344
|
+
if (t === 'A') { out.push({ t: 'a', href: c.getAttribute('href') || '', c: inlineOf(c) }); continue; }
|
|
345
|
+
if (t === 'SPAN' && /font-weight:\s*(bold|[6-9]00)/.test(c.getAttribute('style') || '')) { out.push({ t: 'b', c: inlineOf(c) }); continue; }
|
|
346
|
+
if (t === 'SPAN' && /font-style:\s*italic/.test(c.getAttribute('style') || '')) { out.push({ t: 'i', c: inlineOf(c) }); continue; }
|
|
347
|
+
for (const x of inlineOf(c)) { if (x.t === 'text') text(x.s); else out.push(x); }
|
|
348
|
+
}
|
|
349
|
+
return out;
|
|
350
|
+
}
|
|
351
|
+
const trimInline = (c) => {
|
|
352
|
+
const a = c.slice();
|
|
353
|
+
while (a.length && a[0].t === 'text' && !a[0].s.trim()) a.shift();
|
|
354
|
+
while (a.length && a[a.length - 1].t === 'text' && !a[a.length - 1].s.trim()) a.pop();
|
|
355
|
+
if (a.length && a[0].t === 'text') a[0] = { ...a[0], s: a[0].s.replace(/^\s+/, '') };
|
|
356
|
+
if (a.length && a[a.length - 1].t === 'text') a[a.length - 1] = { ...a[a.length - 1], s: a[a.length - 1].s.replace(/\s+$/, '') };
|
|
357
|
+
return a;
|
|
358
|
+
};
|
|
359
|
+
const BLOCK = /^(P|DIV|H[1-6]|BLOCKQUOTE|UL|OL|TABLE|PRE|HR|SECTION)$/;
|
|
360
|
+
/** The editor's children → blocks. Loose text and inline nodes between blocks become a paragraph. */
|
|
361
|
+
export function fromDom(root) {
|
|
362
|
+
const out = []; let loose = null;
|
|
363
|
+
const endLoose = () => { if (loose) { const c = trimInline(inlineOf(loose)); if (c.length) out.push({ t: 'p', c }); loose = null; } };
|
|
364
|
+
for (const n of Array.from(root.childNodes || [])) {
|
|
365
|
+
if (n.nodeType === 1 && BLOCK.test(n.tagName)) { endLoose(); out.push(...blockOf(n)); continue; }
|
|
366
|
+
if (n.nodeType === 3 && !n.textContent.trim() && !loose) continue;
|
|
367
|
+
if (!loose) loose = (root.ownerDocument || document).createElement('p');
|
|
368
|
+
loose.appendChild(n.cloneNode(true));
|
|
369
|
+
}
|
|
370
|
+
endLoose();
|
|
371
|
+
return out;
|
|
372
|
+
}
|
|
373
|
+
function blockOf(n) {
|
|
374
|
+
const t = n.tagName;
|
|
375
|
+
if (/^H[1-6]$/.test(t)) return [{ t: 'h', level: +t[1], c: trimInline(inlineOf(n)) }];
|
|
376
|
+
if (t === 'HR') return [{ t: 'hr' }];
|
|
377
|
+
if (t === 'PRE') return [{ t: 'code', lang: n.getAttribute('data-lang') || '', s: n.textContent.replace(/\n$/, '') }];
|
|
378
|
+
if (t === 'BLOCKQUOTE') { const b = fromDom(n); return b.length ? [{ t: 'quote', blocks: b }] : []; }
|
|
379
|
+
if (t === 'UL' || t === 'OL') {
|
|
380
|
+
const items = Array.from(n.children).filter((li) => li.tagName === 'LI').map((li) => {
|
|
381
|
+
const box = li.querySelector(':scope > input[type=checkbox]');
|
|
382
|
+
return { task: box ? !!box.checked : null, c: trimInline(inlineOf(li)) };
|
|
383
|
+
});
|
|
384
|
+
const nested = Array.from(n.querySelectorAll(':scope > li > ul, :scope > li > ol')).flatMap(blockOf);
|
|
385
|
+
return [{ t: 'list', ordered: t === 'OL', items }, ...nested];
|
|
386
|
+
}
|
|
387
|
+
if (t === 'TABLE' || (t === 'DIV' && n.querySelector(':scope > table'))) {
|
|
388
|
+
const tb = t === 'TABLE' ? n : n.querySelector(':scope > table');
|
|
389
|
+
const rows = Array.from(tb.querySelectorAll('tr')).map((r) => Array.from(r.children).map((c) => trimInline(inlineOf(c))));
|
|
390
|
+
if (!rows.length) return [];
|
|
391
|
+
return [{ t: 'table', head: rows[0], rows: rows.slice(1) }];
|
|
392
|
+
}
|
|
393
|
+
if ((t === 'DIV' || t === 'SECTION') && Array.from(n.children).some((c) => BLOCK.test(c.tagName))) return fromDom(n);
|
|
394
|
+
const c = trimInline(inlineOf(n));
|
|
395
|
+
return c.length ? [{ t: 'p', c }] : [];
|
|
396
|
+
}
|
|
@@ -1,54 +1,129 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* cozy-nav.js — the floating
|
|
2
|
+
* cozy-nav.js — the floating menu (initiative premium-agreed-design; redrawn by premium-uncovered-features E1, canvas EvMenu and EvPhone).
|
|
3
3
|
*
|
|
4
|
-
* One button, bottom left on desktop and bottom right on a phone, opens Home, Board, Insights
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* One button, bottom left on desktop and bottom right on a phone, opens the menu: Home, Board, Insights; then Search (⌘K), New for you
|
|
5
|
+
* (its count), Sources (the source furthest behind, with an amber dot), Settings and Theme (Light, Dark, Auto). It is the one way between
|
|
6
|
+
* places. Closed, the button shows two dots: blue when something is new for you, amber when a source is stale. Nothing moves.
|
|
7
|
+
* Search pm/cozy-search.js: across the repository and every worktree; Ctrl K (Cmd K) or "/" opens it from any page
|
|
8
|
+
* New for you pm/cozy-news.js: the FYI items (mentions, tasks given to you, finished work) in the Viewer
|
|
9
|
+
* Sources pm/cozy-sources.js: what PMOS reads and how old each reading is, in the Viewer
|
|
10
|
+
* Settings pm/cozy-settings.js: General, Connectors, Workspaces, Updates, What's new
|
|
11
|
+
* A page with features the design does not draw yet passes opts.more (Home): a quiet "More" row then follows Settings.
|
|
12
|
+
* The counts come from GET /api/news-for-you and GET /api/sources, read when the page opens and every two minutes while it is shown.
|
|
13
|
+
* Nothing here leads to the console, and nothing here writes but the theme (this device).
|
|
7
14
|
*/
|
|
15
|
+
import { esc, svg, ICON, wsQ } from './cozy-evui.js';
|
|
16
|
+
import { fabLabel, staleOf } from './cozy-evmodel.js';
|
|
8
17
|
|
|
9
18
|
export const PLACES = [
|
|
10
|
-
{ key: 'home', label: 'Home', href: '/premium.html', d:
|
|
11
|
-
{ key: 'board', label: 'Board', href: '/premium-board.html', d:
|
|
12
|
-
{ key: 'insights', label: 'Insights', href: '/premium-insights.html', d:
|
|
19
|
+
{ key: 'home', label: 'Home', href: '/premium.html', d: ICON.home },
|
|
20
|
+
{ key: 'board', label: 'Board', href: '/premium-board.html', d: ICON.board },
|
|
21
|
+
{ key: 'insights', label: 'Insights', href: '/premium-insights.html', d: ICON.insights },
|
|
13
22
|
];
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
23
|
+
export { fabLabel };
|
|
24
|
+
const THEME_KEY = 'pmos.c3.theme';
|
|
25
|
+
const THEMES = [['light', 'Light'], ['dark', 'Dark'], ['auto', 'Auto']];
|
|
26
|
+
const CSS = '/pm/cozy-ev.css';
|
|
27
|
+
const N = { news: 0, stale: null, here: 'home' };
|
|
18
28
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { if (v) localStorage.setItem(k, v); else localStorage.removeItem(k); } catch { /* a private window */ } } };
|
|
30
|
+
/** The theme the PM picked on this device: light, dark or auto. */
|
|
31
|
+
export const themePick = () => { const t = store.get(THEME_KEY); return t === 'light' || t === 'dark' ? t : 'auto'; };
|
|
32
|
+
/** Apply a pick: Auto follows the computer, and follows it when it changes. */
|
|
33
|
+
export function setTheme(pick, doc = document, { keep = true } = {}) {
|
|
34
|
+
const p = pick === 'light' || pick === 'dark' ? pick : 'auto';
|
|
35
|
+
if (keep) store.set(THEME_KEY, p === 'auto' ? '' : p);
|
|
36
|
+
const dark = p === 'dark' || (p === 'auto' && typeof matchMedia === 'function' && matchMedia('(prefers-color-scheme: dark)').matches);
|
|
37
|
+
doc.documentElement.dataset.theme = dark ? 'dark' : 'light';
|
|
38
|
+
doc.querySelectorAll('[data-ev-theme]').forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.evTheme === p)));
|
|
39
|
+
doc.dispatchEvent(new CustomEvent('cz:theme', { detail: { pick: p, dark } }));
|
|
23
40
|
}
|
|
24
41
|
|
|
25
|
-
/** The menu's markup
|
|
26
|
-
export function menuHtml(here) {
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
/** The menu's markup; pure, so a unit test can read it. here: home | board | insights. o: { news, stale: { text } | null, more, theme } */
|
|
43
|
+
export function menuHtml(here, o = {}) {
|
|
44
|
+
const news = o.news > 0 ? `<span class="ev-k"><span class="ev-pill y">${o.news > 99 ? '99+' : o.news}</span></span>` : '';
|
|
45
|
+
const stale = o.stale ? `<span class="ev-k"><i class="ev-dot risk" aria-hidden="true"></i>${esc(o.stale.text)}</span>` : '';
|
|
46
|
+
const th = o.theme || 'auto';
|
|
47
|
+
return PLACES.map((p) => `<a href="${p.href}"${p.key === here ? ' aria-current="page"' : ''}>${svg(p.d, 18)}${p.key === here ? `<b>${p.label}</b>` : `<span>${p.label}</span>`}</a>`).join('')
|
|
48
|
+
+ '<div class="ev-hr" role="separator"></div>'
|
|
49
|
+
+ `<button type="button" class="ev-mi" data-cz-search>${svg(ICON.search, 18)}<span>Search</span><span class="ev-k"><span class="ev-kbd">⌘K</span></span></button>`
|
|
50
|
+
+ `<button type="button" class="ev-mi" data-cz-news aria-label="New for you${o.news > 0 ? ', ' + o.news + ' new' : ''}">${svg(ICON.news, 18)}<span>New for you</span>${news}</button>`
|
|
51
|
+
+ `<button type="button" class="ev-mi" data-cz-sources aria-label="Sources${o.stale ? ', ' + esc(o.stale.text) : ''}">${svg(ICON.sources, 18)}<span>Sources</span>${stale}</button>`
|
|
52
|
+
+ `<button type="button" class="ev-mi" data-cz-settings>${svg(ICON.settings, 18)}<span>Settings</span></button>`
|
|
53
|
+
+ (o.more ? `<button type="button" class="ev-mi ev-mmore" data-cz-more>${svg(ICON.more, 18)}<span>More</span></button>` : '')
|
|
54
|
+
+ `<div class="ev-mi ev-theme">${svg(ICON.theme, 18)}<span>Theme</span><span class="ev-seg sm" role="group" aria-label="Theme">${THEMES.map(([k, w]) => `<button type="button" data-ev-theme="${k}" aria-pressed="${k === th}">${w}</button>`).join('')}</span></div>`;
|
|
29
55
|
}
|
|
30
56
|
|
|
57
|
+
function addCss(doc) {
|
|
58
|
+
if (doc.querySelector(`link[href="${CSS}"]`)) return;
|
|
59
|
+
const l = doc.createElement('link'); l.rel = 'stylesheet'; l.href = CSS; doc.head.append(l);
|
|
60
|
+
}
|
|
61
|
+
async function getj(p) { try { const r = await fetch(p, { credentials: 'same-origin' }); return r.ok ? await r.json() : null; } catch { return null; } }
|
|
62
|
+
|
|
31
63
|
/** Mount the menu once. `here` is home | board | insights. Returns the wrapper. */
|
|
32
|
-
export function mountNav(here, doc = document) {
|
|
64
|
+
export function mountNav(here, doc = document, opts = {}) {
|
|
33
65
|
const old = doc.getElementById('czNav'); if (old) return old;
|
|
66
|
+
N.here = here;
|
|
34
67
|
doc.body.classList.add('cz');
|
|
68
|
+
addCss(doc);
|
|
69
|
+
{ const u = new URLSearchParams(location.search).get('theme'); setTheme(u || themePick(), doc, { keep: false }); } // ?theme= shows that theme and is not kept
|
|
70
|
+
if (typeof matchMedia === 'function') { const mq = matchMedia('(prefers-color-scheme: dark)'); const f = () => { if (themePick() === 'auto') setTheme('auto', doc); }; if (mq.addEventListener) mq.addEventListener('change', f); }
|
|
71
|
+
try { if (localStorage.getItem('pmos.cz.viewer') === 'popup') doc.body.classList.add('ev-vw-popup'); } catch { /* no storage */ }
|
|
35
72
|
const w = doc.createElement('div'); w.className = 'cz-fabw'; w.id = 'czNav';
|
|
36
|
-
w.innerHTML =
|
|
37
|
-
+ `<
|
|
73
|
+
w.innerHTML = '<div class="ev-scrim" id="czScrim" hidden></div>'
|
|
74
|
+
+ `<nav class="cz-fabm ev-menu" id="czMenu" aria-label="Menu" hidden></nav>`
|
|
75
|
+
+ `<button type="button" class="cz-fab" id="czFab" aria-controls="czMenu" aria-expanded="false" aria-label="${fabLabel(here, false)}">${svg(ICON.menu, 22)}</button>`
|
|
76
|
+
+ '<i class="ev-fd you" id="czFdYou" hidden></i><i class="ev-fd risk" id="czFdRisk" hidden></i>';
|
|
38
77
|
doc.body.appendChild(w);
|
|
39
|
-
const fab = w.querySelector('#czFab'), menu = w.querySelector('#czMenu');
|
|
78
|
+
const fab = w.querySelector('#czFab'), menu = w.querySelector('#czMenu'), scrim = w.querySelector('#czScrim');
|
|
79
|
+
const draw = () => {
|
|
80
|
+
menu.innerHTML = menuHtml(here, { news: N.news, stale: N.stale, more: !!opts.more, theme: themePick() });
|
|
81
|
+
w.querySelector('#czFdYou').hidden = !(N.news > 0) || !menu.hidden;
|
|
82
|
+
w.querySelector('#czFdRisk').hidden = !N.stale || !menu.hidden;
|
|
83
|
+
if (menu.hidden) fab.setAttribute('aria-label', fabLabel(here, false, !!N.stale) + (N.news > 0 ? '. ' + N.news + ' new for you' : ''));
|
|
84
|
+
};
|
|
40
85
|
const set = (open) => {
|
|
41
|
-
menu.hidden = !open; fab.setAttribute('aria-expanded', String(open));
|
|
42
|
-
fab.setAttribute('aria-label', fabLabel(here, open)); fab.innerHTML = svg(open ?
|
|
86
|
+
menu.hidden = !open; scrim.hidden = !open; fab.setAttribute('aria-expanded', String(open));
|
|
87
|
+
fab.setAttribute('aria-label', fabLabel(here, open, !!N.stale)); fab.innerHTML = svg(open ? ICON.close : ICON.menu, 22);
|
|
88
|
+
draw();
|
|
89
|
+
if (open) { const f = menu.querySelector('a, button'); if (f) f.focus(); }
|
|
43
90
|
};
|
|
91
|
+
draw();
|
|
44
92
|
fab.addEventListener('click', () => set(menu.hidden));
|
|
45
|
-
|
|
93
|
+
scrim.addEventListener('click', () => set(false));
|
|
94
|
+
doc.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !menu.hidden) { e.stopPropagation(); set(false); fab.focus(); } }, true);
|
|
46
95
|
// set() redraws the button's icon, so the pressed icon may be gone from the page by now: only a press still on the page closes the menu
|
|
47
96
|
doc.addEventListener('click', (e) => { if (!menu.hidden && e.target.isConnected && !w.contains(e.target)) set(false); });
|
|
48
|
-
menu.
|
|
97
|
+
menu.addEventListener('click', (e) => {
|
|
98
|
+
const b = e.target.closest('button'); if (!b) return;
|
|
99
|
+
if (b.dataset.evTheme) { setTheme(b.dataset.evTheme, doc); return; }
|
|
49
100
|
set(false);
|
|
50
|
-
|
|
51
|
-
if (b)
|
|
101
|
+
if ('czSearch' in b.dataset) import('./cozy-search.js').then((M) => M.openSearch(opts.search ? { go: opts.search() } : {}));
|
|
102
|
+
else if ('czNews' in b.dataset) import('./cozy-news.js').then((M) => M.openNews(opts.news ? { go: opts.news() } : {}));
|
|
103
|
+
else if ('czSources' in b.dataset) import('./cozy-sources.js').then((M) => M.openSources());
|
|
104
|
+
else if ('czSettings' in b.dataset) import('./cozy-settings.js').then((M) => M.openSettings());
|
|
105
|
+
else if ('czMore' in b.dataset && opts.more) opts.more()(fab);
|
|
52
106
|
});
|
|
107
|
+
// Ctrl K (Cmd K) and "/" open Search from any page; a second press focuses it
|
|
108
|
+
doc.addEventListener('keydown', (e) => {
|
|
109
|
+
const t = e.target, typing = t && t.matches && t.matches('input, textarea, select, [contenteditable="true"], [contenteditable=""]');
|
|
110
|
+
const k = (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey && (e.key === 'k' || e.key === 'K');
|
|
111
|
+
if (!k && !(e.key === '/' && !e.ctrlKey && !e.metaKey && !e.altKey && !typing)) return;
|
|
112
|
+
if (t && t.closest && t.closest('.xterm')) return; // a terminal keeps its keys
|
|
113
|
+
e.preventDefault(); e.stopImmediatePropagation();
|
|
114
|
+
import('./cozy-search.js').then((M) => M.openSearch(opts.search ? { go: opts.search() } : {}));
|
|
115
|
+
}, true);
|
|
116
|
+
const read = async () => {
|
|
117
|
+
if (doc.hidden) return;
|
|
118
|
+
const [n, s] = await Promise.all([getj('/api/news-for-you' + wsQ()), getj('/api/sources' + wsQ())]);
|
|
119
|
+
if (n && n.ok) N.news = n.count || 0;
|
|
120
|
+
if (s && s.ok) N.stale = staleOf(s.sources);
|
|
121
|
+
if (menu.hidden || !menu.contains(doc.activeElement)) draw();
|
|
122
|
+
};
|
|
123
|
+
read();
|
|
124
|
+
setInterval(read, 120000);
|
|
125
|
+
doc.addEventListener('visibilitychange', () => { if (!doc.hidden) read(); });
|
|
126
|
+
doc.addEventListener('cz:news', (e) => { if (e.detail && Number.isFinite(e.detail.count)) { N.news = e.detail.count; draw(); } else read(); });
|
|
127
|
+
window.addEventListener('pm:sources', (e) => { const d = e.detail; if (d && d.ok) { N.stale = staleOf(d.sources); draw(); } });
|
|
53
128
|
return w;
|
|
54
129
|
}
|