create-pmos 0.398.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 +13 -13
- package/payload/KIT-VERSION +1 -1
- 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/workspace/briefing-premium-adddoc-test.js +18 -14
- package/workspace/briefing-premium-board-test.js +80 -48
- package/workspace/briefing-premium-calendar-2-test.js +36 -36
- package/workspace/briefing-premium-calendar-3-test.js +39 -39
- package/workspace/briefing-premium-calendar-test.js +23 -24
- package/workspace/briefing-premium-doc-edit-test.js +6 -2
- package/workspace/briefing-premium-initiative-test.js +38 -16
- package/workspace/briefing-premium-insights-test.js +114 -37
- package/workspace/briefing-premium-metrics-test.js +6 -4
- package/workspace/briefing-premium-products-test.js +10 -7
- package/workspace/briefing-premium-sources-test.js +25 -22
- package/workspace/briefing-premium-test.js +46 -42
- package/workspace/briefing-premium-work-test.js +9 -9
- package/workspace/changelog.json +12 -0
- package/workspace/ev-everywhere-test.js +210 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +11 -6
- package/workspace/guide/home.md +39 -18
- package/workspace/guide/index.md +1 -1
- package/workspace/lib/board-grill.js +63 -0
- package/workspace/lib/board-premium.js +36 -5
- package/workspace/lib/initiative-layout.js +77 -0
- package/workspace/lib/insights-premium.js +3 -2
- package/workspace/lib/insights-records.js +21 -7
- 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 +8 -0
- package/workspace/lib/routes-board-docs.js +46 -0
- package/workspace/lib/routes-board-grill.js +90 -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 +4 -1
- package/workspace/lib/routes-insights-records.js +8 -4
- package/workspace/lib/routes-meeting-points.js +37 -0
- package/workspace/lib/routes-news.js +57 -0
- package/workspace/lib/routes-notes.js +2 -1
- package/workspace/lib/routes-report-confirm.js +31 -0
- package/workspace/lib/routes-search.js +38 -0
- package/workspace/lib/search-index.js +176 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +86 -50
- package/workspace/premium-briefing-depth-test.js +55 -54
- package/workspace/premium-chat-chart-tab-test.js +4 -2
- package/workspace/premium-chat-report-tab-test.js +16 -2
- package/workspace/premium-core-doc-issue-test.js +15 -13
- package/workspace/premium-phone-card-test.js +5 -3
- package/workspace/premium-report-read-test.js +55 -18
- package/workspace/premium-vw-backlog-test.js +2 -2
- package/workspace/premium-vw-cal-test.js +50 -35
- package/workspace/premium-vw-doc-test.js +9 -3
- package/workspace/premium-vw-item-test.js +1 -1
- package/workspace/premium-vw-jira-test.js +2 -2
- package/workspace/premium-vw-meet-test.js +37 -40
- package/workspace/premium-vw-notes-test.js +21 -19
- package/workspace/premium-vw-rec-test.js +11 -12
- package/workspace/premium-welcome-test.js +3 -3
- package/workspace/premium-work-depth-test.js +3 -3
- package/workspace/public/pm/bd-acts.js +303 -225
- 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 +49 -13
- package/workspace/public/pm/bd-views.js +169 -0
- package/workspace/public/pm/cozy-board.css +301 -0
- 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-insights.css +148 -10
- package/workspace/public/pm/cozy-nav.js +103 -39
- package/workspace/public/pm/cozy-news.js +140 -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.js +1 -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/home-adddoc.js +5 -5
- package/workspace/public/pm/home-app.js +329 -55
- package/workspace/public/pm/home-around.js +24 -126
- package/workspace/public/pm/home-chat.js +67 -14
- package/workspace/public/pm/home-data.js +6 -6
- package/workspace/public/pm/home-dictate.js +54 -0
- package/workspace/public/pm/home-draft.js +6 -6
- 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 +17 -134
- package/workspace/public/pm/home-phone-card.js +4 -4
- 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 +54 -26
- package/workspace/public/pm/premium-board.js +163 -39
- package/workspace/public/pm/premium-chart-tab.js +4 -5
- package/workspace/public/pm/premium-first.js +5 -7
- package/workspace/public/pm/premium-insights.js +499 -202
- 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-report-read.js +216 -52
- package/workspace/public/pm/premium-report-tab.js +44 -19
- package/workspace/public/pm/premium-shell.js +7 -7
- package/workspace/public/pm/premium-vw-cal.js +150 -60
- package/workspace/public/pm/premium-vw-mtg.js +488 -261
- package/workspace/public/pm/premium-vw-notes.js +61 -0
- package/workspace/public/pm/rp-parts.js +269 -0
- package/workspace/public/premium-board.html +4 -3
- package/workspace/public/premium-insights.html +10 -10
- package/workspace/public/premium.html +3 -1
- 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/test-lists/initiative-layout.json +9 -0
- package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
- package/workspace/test-lists/premium-uncovered-reports.json +9 -0
- 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
|
@@ -1,65 +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
|
*/
|
|
8
|
-
import {
|
|
15
|
+
import { esc, svg, ICON, wsQ } from './cozy-evui.js';
|
|
16
|
+
import { fabLabel, staleOf } from './cozy-evmodel.js';
|
|
9
17
|
|
|
10
18
|
export const PLACES = [
|
|
11
|
-
{ key: 'home', label: 'Home', href: '/premium.html', d:
|
|
12
|
-
{ key: 'board', label: 'Board', href: '/premium-board.html', d:
|
|
13
|
-
{ 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 },
|
|
14
22
|
];
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
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' };
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 } }));
|
|
25
40
|
}
|
|
26
41
|
|
|
27
|
-
/** The menu's markup
|
|
28
|
-
export function menuHtml(here) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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>`;
|
|
32
55
|
}
|
|
33
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
|
+
|
|
34
63
|
/** Mount the menu once. `here` is home | board | insights. Returns the wrapper. */
|
|
35
64
|
export function mountNav(here, doc = document, opts = {}) {
|
|
36
65
|
const old = doc.getElementById('czNav'); if (old) return old;
|
|
66
|
+
N.here = here;
|
|
37
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 */ }
|
|
38
72
|
const w = doc.createElement('div'); w.className = 'cz-fabw'; w.id = 'czNav';
|
|
39
|
-
w.innerHTML =
|
|
40
|
-
+ `<
|
|
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>';
|
|
41
77
|
doc.body.appendChild(w);
|
|
42
|
-
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
|
+
};
|
|
43
85
|
const set = (open) => {
|
|
44
|
-
menu.hidden = !open; fab.setAttribute('aria-expanded', String(open));
|
|
45
|
-
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(); }
|
|
46
90
|
};
|
|
91
|
+
draw();
|
|
47
92
|
fab.addEventListener('click', () => set(menu.hidden));
|
|
48
|
-
|
|
93
|
+
scrim.addEventListener('click', () => set(false));
|
|
94
|
+
doc.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !menu.hidden) { e.stopPropagation(); set(false); fab.focus(); } }, true);
|
|
49
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
|
|
50
96
|
doc.addEventListener('click', (e) => { if (!menu.hidden && e.target.isConnected && !w.contains(e.target)) set(false); });
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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; }
|
|
54
100
|
set(false);
|
|
55
|
-
if (
|
|
56
|
-
import('./
|
|
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);
|
|
57
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(); } });
|
|
58
128
|
return w;
|
|
59
129
|
}
|
|
60
|
-
/** The features with no design yet, as one list in the Viewer, on a page that has no menu of its own for them. */
|
|
61
|
-
function moreList(M, doc) {
|
|
62
|
-
const go = { work: M.openMyWork, around: M.openAround, inbox: () => M.openInbox(), eod: M.openEndOfDay, rec: M.openRecorder, search: () => M.openSearch(), products: M.openProducts, sources: M.openSources, settings: M.openSettings,
|
|
63
|
-
cal: () => (doc.defaultView.czViews && doc.defaultView.czViews.openCalendar ? doc.defaultView.czViews.openCalendar({ view: 'day' }) : placeholder('Calendar', { icon: 'cal' })) };
|
|
64
|
-
return M.listCard(M.moreItems.map(([k, l]) => [l, go[k]]));
|
|
65
|
-
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* pm/cozy-news.js — New for you, in the Viewer (initiative premium-uncovered-features, E2; canvas EvInbox, HmAround). It replaces the Inbox
|
|
2
|
+
* (the bell) and Around you.
|
|
3
|
+
*
|
|
4
|
+
* For your information only: Mentions, Given to you, Finished while you were away (GET /api/news-for-you), and today's digests from the
|
|
5
|
+
* morning brief (GET /api/briefing-premium). An item leaves once it is seen: the items shown are marked seen when the card closes, and
|
|
6
|
+
* Mark all seen marks them at once (POST /api/news-for-you/seen). Open on a row shows the item: a mention with Make it a task, Mark read and
|
|
7
|
+
* Open in its source; a task with its source; finished work opens where it waits. What Around you also showed has one home each, named
|
|
8
|
+
* under "Where the rest went", and each line opens it (home-around.js keeps those views). The prep line Around you held (the meetings left
|
|
9
|
+
* today and how many are prepped, GET /api/brief-page) sits under the head when a meeting is still ahead.
|
|
10
|
+
* openNews({ go? }) → the body element */
|
|
11
|
+
import { pmGet, pmPost } from './http.js';
|
|
12
|
+
import { open as vwOpen, current as vwCurrent } from './cozy-viewer.js';
|
|
13
|
+
import { esc, svg, ICON, toast, wsParam, wsQ, skelRows, cantRead, allClear } from './cozy-evui.js';
|
|
14
|
+
import { initials, ago } from './cozy-evmodel.js';
|
|
15
|
+
|
|
16
|
+
const SRC = { slack: 'Slack', jira: 'Jira', confluence: 'Confluence', mail: 'Mail' };
|
|
17
|
+
const N = { r: null, dig: null, prep: '', view: '', body: null, shown: new Set(), madd: new Set(), mread: new Set(), busy: false };
|
|
18
|
+
const homeUrl = (params) => { const q = new URLSearchParams(params); if (wsParam()) q.set('ws', wsParam()); return '/premium.html?' + q.toString(); };
|
|
19
|
+
const https = (u) => (/^https:\/\/\S+$/i.test(String(u || '')) ? u : '');
|
|
20
|
+
/** The deep link of a finished item, as the bell's was: a My work item opens its dialog; anything else opens on Home. */
|
|
21
|
+
const finHref = (it) => (/^item:/.test(it.open) ? homeUrl({ item: it.open.slice(5) }) : homeUrl(it.pws ? { open: it.open, pws: it.pws } : { open: it.open }));
|
|
22
|
+
const taskLine = (m) => (m.asks ? 'Reply to ' + String(m.who || 'the sender').split(/\s+/)[0] + ' (' + (SRC[m.source] || m.source || 'source') + ') by today' : 'Read ' + String(m.who || 'the sender').split(/\s+/)[0] + '\'s note (' + (SRC[m.source] || m.source || 'source') + ')');
|
|
23
|
+
|
|
24
|
+
function items() { return N.r && N.r.ok ? N.r.groups.flatMap((g) => g.items) : []; }
|
|
25
|
+
function rowHtml(it) {
|
|
26
|
+
const who = it.kind === 'mention' ? it.who : it.kind === 'task' ? (it.from || 'Someone') : (it.product || 'Agent');
|
|
27
|
+
const av = `<span class="ev-av${it.kind === 'finished' ? ' b' : ''}" aria-hidden="true">${esc(initials(who))}</span>`;
|
|
28
|
+
const sub = it.kind === 'mention' ? ['“' + it.text + '”', [SRC[it.source] || it.source, it.where].filter(Boolean).join(' '), ago(it.at ? new Date(it.at).toISOString() : '')].filter(Boolean).join(' · ')
|
|
29
|
+
: it.kind === 'task' ? ['From ' + (it.from || 'a source') + (it.key ? ' ' + it.key : ''), it.due ? 'due ' + it.due : '', it.initiative ? 'filed under ' + it.initiative : ''].filter(Boolean).join(' · ')
|
|
30
|
+
: [it.what, it.product, it.target, it.at ? ago(new Date(it.at).toISOString()) : ''].filter(Boolean).join(' · ');
|
|
31
|
+
return `<div class="ev-trow" data-ev-id="${esc(it.id)}"><i class="ev-dot you" aria-hidden="true"></i>${av}<div class="ev-tx"><p><b>${esc(it.title)}</b></p><p class="ev-small ev-mut">${esc(sub)}</p></div>`
|
|
32
|
+
+ `<button type="button" class="ev-ib" data-ev-open="${esc(it.id)}" aria-label="Open: ${esc(it.title)}" title="Open">${svg(ICON.open, 16)}</button></div>`;
|
|
33
|
+
}
|
|
34
|
+
const REST = [
|
|
35
|
+
['pulse', 'Portfolio pulse', 'Insights · Goals. Home does not repeat it.'],
|
|
36
|
+
['rep', 'Found in your work', 'Insights · Library, at the top.'],
|
|
37
|
+
['prop', 'Proposals', 'the initiative’s next step, because they need an answer.'],
|
|
38
|
+
['scan', 'Scan now', 'Ask in chat: “scan for billing news”.'],
|
|
39
|
+
];
|
|
40
|
+
function digHtml() {
|
|
41
|
+
const d = N.dig; if (!d || !d.length) return '';
|
|
42
|
+
return `<section id="aroundDig" class="ev-dig"><p class="ev-lbl">Digests ${d.length}</p>${d.map((e) => { const x = e.dialog || {}, p = x.pane || {}, l = https(x.link);
|
|
43
|
+
return `<div class="ev-trow"><i class="ev-dot none" aria-hidden="true"></i><span class="ev-av" aria-hidden="true">${esc(initials(e.title))}</span><div class="ev-tx"><p><b>${esc(e.title)}</b></p><p class="ev-small ev-mut">${esc(e.sub || '')}</p>${(p.paras || []).map((t) => `<p class="ev-small">${esc(t)}</p>`).join('')}</div>${l ? `<a class="ev-ib srcLink" href="${esc(l)}" target="_blank" rel="noopener noreferrer" aria-label="Open ${esc(x.linkLabel || 'it')}" title="${esc(x.linkLabel || 'Open it')}">${svg(ICON.open, 16)}</a>` : ''}</div>`; }).join('')}</section>`;
|
|
44
|
+
}
|
|
45
|
+
function listHtml() {
|
|
46
|
+
const r = N.r;
|
|
47
|
+
const head = `<div class="ev-head"><h2 class="ev-h2">New since this morning</h2>${r && r.ok && r.count ? '<button type="button" class="ev-btn sm ghost" data-ev-all>Mark all seen</button>' : ''}</div>`;
|
|
48
|
+
const two = '<div class="ev-two"><div class="ev-box"><b>Initiatives</b> (left)<br><span class="ev-mut">Each shows its next step. It stays until you act.</span></div><div class="ev-box blue"><b>New for you</b> (here)<br><span class="ev-mut">For your information. It goes once you have seen it.</span></div></div>';
|
|
49
|
+
let body;
|
|
50
|
+
if (!r) body = skelRows(3) + '<p class="ev-small ev-mut">Reading what is new for you</p>';
|
|
51
|
+
else if (!r.ok) body = cantRead({ what: 'New for you', why: r.error || '' });
|
|
52
|
+
else if (!r.count) body = allClear('Nothing new since you last looked');
|
|
53
|
+
else body = r.groups.map((g) => `<p class="ev-lbl">${esc(g.label)}</p>` + g.items.map(rowHtml).join('')).join('');
|
|
54
|
+
const notRead = r && r.ok && r.read ? [['mentions', 'Mentions'], ['inbox', 'The agents\' results'], ['work', 'Your tasks']].filter(([k]) => r.read[k] === false).map(([, l]) => l) : [];
|
|
55
|
+
const rest = `<p class="ev-lbl">Where the rest went</p><div class="ev-box ev-rest">${REST.map(([k, t, w]) => `<button type="button" data-ev-rest="${k}"><b>${esc(t)}</b><span>${esc(w)}</span></button>`).join('')}</div>`;
|
|
56
|
+
const foot = '<div class="ev-foot"><div class="ev-box ev-small"><b>Not here, so nothing shows twice</b><br>A mention that asks you something, a passed review or a proposal becomes the next step of its initiative. A task given to you shows here once, then sits under its initiative. Goal trends live in Insights.</div></div>';
|
|
57
|
+
return head + (N.prep || '') + two + body + (notRead.length ? `<p class="ev-small ev-mut" role="status">Not read: ${esc(notRead.join(', '))}.</p>` : '') + digHtml() + rest + foot;
|
|
58
|
+
}
|
|
59
|
+
function detailHtml(it) {
|
|
60
|
+
const back = '<div class="ev-head"><button type="button" class="ev-btn sm ghost" data-ev-back>' + svg(ICON.back, 16) + 'New for you</button></div>';
|
|
61
|
+
if (it.kind === 'mention') {
|
|
62
|
+
const l = https(it.link), done = N.madd.has(it.id), read = N.mread.has(it.id);
|
|
63
|
+
return back + `<p class="ev-lbl">${esc([SRC[it.source] || it.source, it.where, ago(it.at ? new Date(it.at).toISOString() : '')].filter(Boolean).join(' · '))}${it.asks ? ' · asks you something' : ''}</p><h2 class="ev-h2">${esc(it.title)}</h2><p class="ev-q">${esc(it.text)}</p>`
|
|
64
|
+
+ (it.initiative ? `<p class="ev-small ev-mut">${esc(it.initiative)}</p>` : '')
|
|
65
|
+
+ `<div class="ev-acts">${done ? '<span class="ev-pill ok">In your tasks</span>' : '<button type="button" class="ev-btn sm pri" data-ev-act="task">Make it a task</button>'}${read ? '<span class="ev-pill">Marked read</span>' : '<button type="button" class="ev-btn sm" data-ev-act="read">Mark read</button>'}${l ? `<a class="ev-btn sm" href="${esc(l)}" target="_blank" rel="noopener noreferrer">Open in ${esc(SRC[it.source] || 'its source')}</a>` : ''}</div>`
|
|
66
|
+
+ (done ? '' : `<p class="ev-small ev-mut">Make it a task adds “${esc(taskLine(it))}” to your tasks. Mark read keeps it out of today's list. Nothing here replies or posts.</p>`);
|
|
67
|
+
}
|
|
68
|
+
const l = https(it.link);
|
|
69
|
+
return back + `<p class="ev-lbl">Given to you · ${esc(it.from || 'a source')}</p><h2 class="ev-h2">${esc(it.title.replace(/^New task: /, ''))}</h2>`
|
|
70
|
+
+ `<p class="ev-small ev-mut">${esc([it.key, it.due ? 'due ' + it.due : '', it.initiative ? 'filed under ' + it.initiative : ''].filter(Boolean).join(' · '))}</p>`
|
|
71
|
+
+ `<div class="ev-acts"><a class="ev-btn sm pri" href="${esc(homeUrl({ item: it.tid }))}">Open in Home</a>${l ? `<a class="ev-btn sm" href="${esc(l)}" target="_blank" rel="noopener noreferrer">Open in ${esc(it.from || 'its source')}</a>` : ''}</div>`;
|
|
72
|
+
}
|
|
73
|
+
function draw() {
|
|
74
|
+
const b = N.body; if (!b || !b.isConnected) return;
|
|
75
|
+
{ const c = vwCurrent(); if (!c || c.id !== 'news') return; } // the Viewer moved on to another item: a late read draws nothing
|
|
76
|
+
const it = N.view && items().find((x) => x.id === N.view);
|
|
77
|
+
b.innerHTML = it ? detailHtml(it) : listHtml();
|
|
78
|
+
if (!it) for (const x of items()) N.shown.add(x.id);
|
|
79
|
+
}
|
|
80
|
+
async function read() {
|
|
81
|
+
const [r, d, bp] = await Promise.all([pmGet('/api/news-for-you' + wsQ()), N.dig ? Promise.resolve(null) : pmGet('/api/briefing-premium' + wsQ()), pmGet('/api/brief-page' + wsQ())]);
|
|
82
|
+
N.prep = bp && bp.ok !== false ? await import('./home-around.js').then((M) => M.prepHtmlOf(bp)).catch(() => '') : '';
|
|
83
|
+
N.r = r && r.ok ? r : { ok: false, error: (r && r.error) || 'the server did not answer' };
|
|
84
|
+
if (d && d.ok && d.model) { const T = d.model.today || {}; N.dig = [].concat(T.earlier || [], T.ahead || []).filter((e) => e && e.kind === 'digest'); }
|
|
85
|
+
draw();
|
|
86
|
+
if (N.r.ok) document.dispatchEvent(new CustomEvent('cz:news', { detail: { count: N.r.count } }));
|
|
87
|
+
}
|
|
88
|
+
/** Mark ids seen; the count in the menu follows. */
|
|
89
|
+
async function seen(ids) {
|
|
90
|
+
const L = [...ids].filter(Boolean); if (!L.length) return true;
|
|
91
|
+
let ok = true;
|
|
92
|
+
for (let i = 0; i < L.length; i += 300) { const r = await pmPost('/api/news-for-you/seen', { ids: L.slice(i, i + 300) }); if (!r || !r.ok) ok = false; }
|
|
93
|
+
document.dispatchEvent(new CustomEvent('cz:news', {}));
|
|
94
|
+
return ok;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function openNews(o = {}) {
|
|
98
|
+
N.view = ''; N.shown = new Set();
|
|
99
|
+
N.body = vwOpen({ id: 'news', kind: 'For your information', title: 'New for you', icon: ICON.news, render: (b) => { b.classList.add('ev-card-b', 'ev-news'); N.body = b; draw(); wire(b, o); },
|
|
100
|
+
onClose: () => { const ids = [...N.shown]; N.shown = new Set(); seen(ids); } }); // an item leaves once seen: what the card showed is seen when it closes
|
|
101
|
+
read();
|
|
102
|
+
return N.body;
|
|
103
|
+
}
|
|
104
|
+
function wire(b, o) {
|
|
105
|
+
b.onclick = async (e) => {
|
|
106
|
+
const t = e.target.closest('button'); if (!t || N.busy) return;
|
|
107
|
+
if ('evRetry' in t.dataset) { N.r = null; draw(); read(); return; }
|
|
108
|
+
if ('evSources' in t.dataset) { import('./cozy-sources.js').then((M) => M.openSources()); return; }
|
|
109
|
+
if ('evBack' in t.dataset) { N.view = ''; draw(); const f = b.querySelector('[data-ev-open]'); if (f) f.focus(); return; }
|
|
110
|
+
if ('evAll' in t.dataset) {
|
|
111
|
+
N.busy = true; const ids = items().map((x) => x.id);
|
|
112
|
+
const ok = await seen(ids); N.busy = false;
|
|
113
|
+
if (!ok) { toast('It was not marked seen. The server did not answer.'); return; }
|
|
114
|
+
N.shown = new Set(); toast('Marked seen.'); N.r = null; draw(); read(); return;
|
|
115
|
+
}
|
|
116
|
+
if (t.dataset.evRest) {
|
|
117
|
+
const k = t.dataset.evRest;
|
|
118
|
+
// each opens its view, so every press the old Around you held (keep, dismiss, Scan now, set up) is still one press away
|
|
119
|
+
import('./home-around.js').then((M) => M.openAround(k)); return;
|
|
120
|
+
}
|
|
121
|
+
if (t.dataset.evOpen) {
|
|
122
|
+
const it = items().find((x) => x.id === t.dataset.evOpen); if (!it) return;
|
|
123
|
+
N.shown.add(it.id);
|
|
124
|
+
if (it.kind === 'finished') { await seen([it.id]); location.assign(finHref(it)); return; }
|
|
125
|
+
N.view = it.id; draw(); const f = b.querySelector('[data-ev-back]'); if (f) f.focus(); return;
|
|
126
|
+
}
|
|
127
|
+
if (t.dataset.evAct) {
|
|
128
|
+
const it = items().find((x) => x.id === N.view); if (!it) return;
|
|
129
|
+
N.busy = true; t.disabled = true;
|
|
130
|
+
const r = t.dataset.evAct === 'task' ? await pmPost('/api/pm-items/add', { line: taskLine(it) }) : await pmPost('/api/mentions/read', { id: it.mid, read: true });
|
|
131
|
+
N.busy = false;
|
|
132
|
+
if (!r || r.ok === false) { toast('That did not go through' + (r && r.error ? ': ' + r.error : '.')); t.disabled = false; return; }
|
|
133
|
+
if (t.dataset.evAct === 'task') { N.madd.add(it.id); toast('Added to your tasks: ' + taskLine(it).replace(/ by today$/, '')); } else { N.mread.add(it.id); toast('Marked read.'); }
|
|
134
|
+
draw();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
void o;
|
|
138
|
+
}
|
|
139
|
+
/** Still open on this item? For a page that redraws around the Viewer. */
|
|
140
|
+
export const isNewsOpen = () => { const c = vwCurrent(); return !!(c && c.id === 'news'); };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/* pm/cozy-search.js — Search (initiative premium-uncovered-features, E1; canvas EvSearch, and EvPhone on the right).
|
|
2
|
+
*
|
|
3
|
+
* One palette over the page: the query, the kind chips with their counts (All, Initiatives, Documents, Slides, Reports, Artifacts, Meetings)
|
|
4
|
+
* and the worktree picker ("main + 3 worktrees"); the results grouped (Initiatives · Documents, slides and reports · Artifacts and designs ·
|
|
5
|
+
* Meetings), and last "Ask Claude about …", which starts a chat in Home. ↑ ↓ move, ↵ opens, Esc closes. On a phone it is the whole screen.
|
|
6
|
+
* openSearch({ go?, q? }) go: the page's own opener ({ ini } | { ses } | { doc }), used before a page change
|
|
7
|
+
* closeSearch()
|
|
8
|
+
* It reads GET /api/find (the repository and every worktree: lib/search-index.js), GET /api/boards/backlog (the initiatives' stage) and
|
|
9
|
+
* GET /api/sessions. A result opens in the Viewer when it can: a document of main as its page (premium-vw-doc.js), a meeting as its card,
|
|
10
|
+
* any other file read-only from its worktree (GET /api/find/file). Nothing here writes. */
|
|
11
|
+
import { esc, svg, ICON, wsParam, wsQ, skelRows, cantRead, failedItem } from './cozy-evui.js';
|
|
12
|
+
const ARROW = { up: 'M12 19V5M6 11l6-6 6 6', down: 'M12 5v14M6 13l6 6 6-6', enter: 'M20 5v7a3 3 0 0 1-3 3H5M9 11l-4 4 4 4' }; // the footer's keys, drawn (R28-13: no glyph as a control)
|
|
13
|
+
import { SEARCH_KINDS, PHONE_KINDS, searchGroups, resultSub, resultTag, wtChip } from './cozy-evmodel.js';
|
|
14
|
+
import { open as vwOpen, current as vwCurrent } from './cozy-viewer.js';
|
|
15
|
+
|
|
16
|
+
const PHONE = 760;
|
|
17
|
+
const isPhone = () => innerWidth <= PHONE;
|
|
18
|
+
const S = { el: null, q: '', kind: 'all', at: 0, rows: [], res: null, busy: false, err: '', wt: null, wtOpen: false, back: null, go: null, seq: 0, boards: null, sessions: null, t: 0 };
|
|
19
|
+
const KIND_ICON = { initiative: ICON.flag, document: ICON.doc, slides: ICON.slides, report: ICON.report, artifact: ICON.design, file: ICON.file, meeting: ICON.meet, session: ICON.session };
|
|
20
|
+
async function getj(p) { try { const r = await fetch(p, { credentials: 'same-origin' }); const j = await r.json().catch(() => null); return j || { ok: false, error: 'the server did not answer' }; } catch { return { ok: false, error: 'the server did not answer' }; } }
|
|
21
|
+
const WT_KEY = 'pmos.search.wt';
|
|
22
|
+
const wtPick = () => { try { const v = JSON.parse(localStorage.getItem(WT_KEY) || 'null'); return Array.isArray(v) ? v : null; } catch { return null; } };
|
|
23
|
+
|
|
24
|
+
function mount() {
|
|
25
|
+
if (S.el && S.el.isConnected) return S.el;
|
|
26
|
+
const d = document.createElement('div');
|
|
27
|
+
d.innerHTML = '<div class="ev-sp-scrim" id="evSpScrim" hidden></div>'
|
|
28
|
+
+ '<div class="ev-sp" id="evSearch" role="dialog" aria-modal="true" aria-label="Search" hidden>'
|
|
29
|
+
+ `<div class="ev-sp-in">${svg(ICON.search, 20)}<label for="evQ" class="ev-vh">Search PMOS</label><input id="evQ" type="text" autocomplete="off" spellcheck="false" placeholder="Search initiatives, documents, slides, reports, artifacts and meetings" role="combobox" aria-expanded="true" aria-controls="evRes" aria-autocomplete="list"><span class="ev-kbd">Esc</span><button type="button" class="ev-ib x" data-ev="close" aria-label="Close search">${svg(ICON.close, 18)}</button></div>`
|
|
30
|
+
+ '<div class="ev-sp-chips" id="evChips" role="group" aria-label="Kind"></div>'
|
|
31
|
+
+ '<div class="ev-sp-list" id="evRes" role="listbox" aria-label="Results"></div>'
|
|
32
|
+
+ `<div class="ev-sp-ft"><span><span class="ev-kbd" role="img" aria-label="Arrow up">${svg(ARROW.up, 12)}</span> <span class="ev-kbd" role="img" aria-label="Arrow down">${svg(ARROW.down, 12)}</span> move</span><span><span class="ev-kbd" role="img" aria-label="Enter">${svg(ARROW.enter, 12)}</span> open</span><span class="ev-r">Searches the repo and every worktree. Opens in the Viewer when it can.</span></div>`
|
|
33
|
+
+ '</div>';
|
|
34
|
+
document.body.append(...d.childNodes);
|
|
35
|
+
S.el = document.getElementById('evSearch');
|
|
36
|
+
document.getElementById('evSpScrim').addEventListener('click', closeSearch);
|
|
37
|
+
const q = S.el.querySelector('#evQ');
|
|
38
|
+
q.addEventListener('input', () => { S.q = q.value; S.at = 0; schedule(); });
|
|
39
|
+
q.addEventListener('keydown', (e) => {
|
|
40
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); const n = S.rows.length; if (n) { S.at = (S.at + (e.key === 'ArrowDown' ? 1 : n - 1)) % n; drawList(); } }
|
|
41
|
+
else if (e.key === 'Enter') { e.preventDefault(); const r = S.rows[S.at]; if (r) go(r); }
|
|
42
|
+
});
|
|
43
|
+
S.el.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); if (S.wtOpen) { S.wtOpen = false; drawChips(); return; } closeSearch(); } });
|
|
44
|
+
S.el.addEventListener('click', (e) => {
|
|
45
|
+
const b = e.target.closest('button, input[type="checkbox"]'); if (!b) return;
|
|
46
|
+
if (b.dataset.ev === 'close') { closeSearch(); return; }
|
|
47
|
+
if (b.dataset.evKind) { S.kind = b.dataset.evKind; S.at = 0; draw(); q.focus(); return; }
|
|
48
|
+
if ('evWt' in b.dataset) { S.wtOpen = !S.wtOpen; drawChips(); return; }
|
|
49
|
+
if (b.dataset.evWtId) { const all = (S.res && S.res.worktrees || []).filter((w) => !w.main).map((w) => w.id); const cur = new Set(S.wt || all); if (b.checked) cur.add(b.dataset.evWtId); else cur.delete(b.dataset.evWtId); S.wt = [...cur]; try { localStorage.setItem(WT_KEY, JSON.stringify(S.wt)); } catch { /* no storage */ } run(); return; }
|
|
50
|
+
if (b.dataset.evI != null) { const r = S.rows[+b.dataset.evI]; if (r) go(r); }
|
|
51
|
+
});
|
|
52
|
+
return S.el;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function openSearch(o = {}) {
|
|
56
|
+
const el = mount();
|
|
57
|
+
S.go = typeof o.go === 'function' ? o.go : null;
|
|
58
|
+
if (!el.hidden) { el.querySelector('#evQ').focus(); return el; }
|
|
59
|
+
const ae = document.activeElement; S.back = ae && ae !== document.body ? ae : null;
|
|
60
|
+
S.wt = wtPick(); S.wtOpen = false; S.kind = 'all'; S.at = 0;
|
|
61
|
+
if (o.q != null) S.q = String(o.q);
|
|
62
|
+
el.hidden = false; document.getElementById('evSpScrim').hidden = false; el.setAttribute('data-esc-layer', '');
|
|
63
|
+
const q = el.querySelector('#evQ'); q.value = S.q; q.focus(); q.select();
|
|
64
|
+
if (!S.boards) getj('/api/boards/backlog?limit=200' + wsQ('&')).then((b) => { S.boards = b && b.ok && Array.isArray(b.rows) ? b : { rows: [] }; draw(); });
|
|
65
|
+
if (!S.sessions) getj('/api/sessions').then((s) => { S.sessions = s && Array.isArray(s.sessions) ? s.sessions.filter((x) => !x.automatic && x.shown !== 'exited') : []; draw(); });
|
|
66
|
+
run();
|
|
67
|
+
return el;
|
|
68
|
+
}
|
|
69
|
+
export function closeSearch() {
|
|
70
|
+
if (!S.el || S.el.hidden) return;
|
|
71
|
+
S.el.hidden = true; document.getElementById('evSpScrim').hidden = true; S.el.removeAttribute('data-esc-layer');
|
|
72
|
+
const b = S.back; S.back = null; if (b && b.isConnected) { try { b.focus(); } catch { /* gone */ } }
|
|
73
|
+
}
|
|
74
|
+
export const isSearchOpen = () => !!(S.el && !S.el.hidden);
|
|
75
|
+
|
|
76
|
+
function schedule() { clearTimeout(S.t); S.t = setTimeout(run, 160); draw(); }
|
|
77
|
+
async function run() {
|
|
78
|
+
const q = S.q.trim(), my = ++S.seq;
|
|
79
|
+
if (q.length < 2) { S.res = S.res && { ...S.res, results: [], counts: {} }; S.busy = false; S.err = ''; draw(); if (!S.res) { const r = await getj('/api/find?q=' + wsQ('&')); if (my === S.seq && r.ok) { S.res = r; drawChips(); } } return; }
|
|
80
|
+
S.busy = true; S.err = ''; draw();
|
|
81
|
+
const wt = S.wt ? '&wt=' + encodeURIComponent(S.wt.join(',') || '-') : '';
|
|
82
|
+
const r = await getj('/api/find?q=' + encodeURIComponent(q) + wsQ('&') + wt);
|
|
83
|
+
if (my !== S.seq) return;
|
|
84
|
+
S.busy = false;
|
|
85
|
+
if (!r.ok) { S.err = r.error || 'the server did not answer'; draw(); return; }
|
|
86
|
+
S.res = r; draw();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Every row the palette shows for the query: the search's results, the board's initiatives and the sessions that match, each once. */
|
|
90
|
+
function allRows() {
|
|
91
|
+
const q = S.q.trim().toLowerCase();
|
|
92
|
+
if (q.length < 2 || !S.res) return [];
|
|
93
|
+
const res = (S.res.results || []).slice();
|
|
94
|
+
const B = (S.boards && S.boards.rows) || [];
|
|
95
|
+
const seen = new Set(res.filter((r) => r.kind === 'initiative').map((r) => r.id));
|
|
96
|
+
for (const r of res) if (r.kind === 'initiative') { const b = B.find((x) => x.id === r.id); if (b) Object.assign(r, { stage: b.stage, lane: r.lane || b.lane, days: b.days_in_stage || b.days || null, title: b.title || r.title, board: S.boards.board, bws: S.boards.ws }); }
|
|
97
|
+
for (const b of B) if (!seen.has(b.id) && (String(b.title || '') + ' ' + b.id).toLowerCase().includes(q)) res.unshift({ kind: 'initiative', group: 'initiative', id: b.id, title: b.title || b.id, lane: b.lane, stage: b.stage, days: b.days_in_stage || null, board: S.boards.board, bws: S.boards.ws, why: 'name' });
|
|
98
|
+
for (const s of S.sessions || []) if ((String(s.name || '') + ' ' + String((s.hx && s.hx.title) || '')).toLowerCase().includes(q)) res.push({ kind: 'session', group: 'meeting', id: s.id, title: (s.hx && s.hx.title) || s.name || s.id, where: s.cwd && s.cwd !== '.' ? s.cwd : '', state: s.state || '', why: 'name' });
|
|
99
|
+
return res;
|
|
100
|
+
}
|
|
101
|
+
const countsOf = (rows) => { const c = { all: rows.length }; for (const r of rows) { const k = r.group === 'session' ? 'meeting' : r.group || r.kind; c[k] = (c[k] || 0) + 1; } return c; };
|
|
102
|
+
|
|
103
|
+
function drawChips() {
|
|
104
|
+
const box = S.el && S.el.querySelector('#evChips'); if (!box) return;
|
|
105
|
+
const rows = allRows(), c = countsOf(rows), K = isPhone() ? PHONE_KINDS : SEARCH_KINDS, wts = (S.res && S.res.worktrees) || [];
|
|
106
|
+
const on = (w) => !S.wt || S.wt.includes(w.id);
|
|
107
|
+
const shown = wts.map((w) => ({ ...w, on: w.main || on(w) }));
|
|
108
|
+
box.innerHTML = K.map(([k, l]) => `<button type="button" class="ev-chip${S.kind === k ? ' on' : ''}" data-ev-kind="${k}" aria-pressed="${S.kind === k}">${esc(l)}${!isPhone() && S.q.trim().length >= 2 ? ' ' + (c[k] || 0) : ''}</button>`).join('')
|
|
109
|
+
+ `<button type="button" class="ev-chip gh ev-wt" data-ev-wt aria-expanded="${S.wtOpen}" aria-haspopup="true" title="Which worktrees Search reads">${svg(ICON.branch, 14)}${esc(wtChip(shown))}</button>`
|
|
110
|
+
+ `<div class="ev-wtm" role="group" aria-label="Worktrees"${S.wtOpen ? '' : ' hidden'}>${shown.map((w) => `<label><input type="checkbox" ${w.main ? 'checked disabled' : `data-ev-wt-id="${esc(w.id)}"${w.on ? ' checked' : ''}`}><span>${esc(w.main ? 'main' : w.name)}</span><small>${w.main ? 'always' : w.error ? esc(w.error) : esc(w.id)}</small></label>`).join('')}</div>`;
|
|
111
|
+
}
|
|
112
|
+
function rowHtml(r, i) {
|
|
113
|
+
const tag = resultTag(r), sub = resultSub(r);
|
|
114
|
+
const right = r.kind === 'document' && r.draft ? '<span class="ev-pill y">Draft</span>' : esc(tag);
|
|
115
|
+
const title = r.kind === 'initiative' ? `<b>${esc(r.title)}</b>` : esc(r.title);
|
|
116
|
+
const subHtml = r.draft ? esc(sub).replace(/^worktree (\S+)/, 'worktree <b>$1</b>') : esc(sub);
|
|
117
|
+
const two = isPhone() ? `<span class="ev-t">${title}${sub ? `<br><span class="ev-small ev-mut">${subHtml}</span>` : ''}</span>` : `<span class="ev-t">${title}${sub ? ` <span class="ev-mut">· ${subHtml}</span>` : ''}</span>`;
|
|
118
|
+
return `<button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}">${svg(KIND_ICON[r.kind] || ICON.doc, 18)}${two}${right ? `<span class="ev-k">${right}</span>` : ''}</button>`;
|
|
119
|
+
}
|
|
120
|
+
function drawList() {
|
|
121
|
+
const box = S.el && S.el.querySelector('#evRes'); if (!box) return;
|
|
122
|
+
const q = S.q.trim();
|
|
123
|
+
let rows = allRows();
|
|
124
|
+
if (S.kind !== 'all') rows = rows.filter((r) => (S.kind === 'artifact' ? ['artifact', 'file'].includes(r.kind) : S.kind === 'meeting' ? ['meeting', 'session'].includes(r.kind) : r.kind === S.kind));
|
|
125
|
+
const groups = searchGroups(rows, { phone: isPhone() });
|
|
126
|
+
S.rows = groups.flatMap((g) => g.rows);
|
|
127
|
+
const ask = q.length >= 2 ? { kind: 'ask', title: q } : null;
|
|
128
|
+
if (ask) S.rows.push(ask);
|
|
129
|
+
S.at = Math.min(S.at, Math.max(0, S.rows.length - 1));
|
|
130
|
+
let h = '', i = 0;
|
|
131
|
+
if (q.length < 2) h = '<p class="ev-sp-empty">Type two letters or more. Search reads the initiatives, the documents, slides and reports, the artifacts and designs, and the meetings, in the repository and every worktree.</p>';
|
|
132
|
+
else if (S.err) h = cantRead({ what: 'Search', why: S.err, sources: false });
|
|
133
|
+
else if (S.busy && !groups.length) h = skelRows(3);
|
|
134
|
+
else if (!groups.length) h = `<p class="ev-sp-empty" role="status">Nothing matches “${esc(q)}”${S.kind !== 'all' ? ' in this kind' : ''}.</p>`;
|
|
135
|
+
groups.forEach((g, gi) => {
|
|
136
|
+
h += `<p class="ev-mlbl">${esc(g.label)}</p>` + g.rows.map((r) => rowHtml(r, i++)).join('');
|
|
137
|
+
if (gi === 0 && isPhone() && g.key === 'initiative') h += '<div class="ev-sp-chips ev-phchips" aria-hidden="true"></div>';
|
|
138
|
+
});
|
|
139
|
+
if (S.res && S.res.more && q.length >= 2) h += `<p class="ev-sp-empty">${S.res.more} more match. Pick a kind to see them.</p>`;
|
|
140
|
+
if (ask) h += `<div class="ev-hr" role="separator"></div><button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}">${svg(ICON.chat, 18)}<span class="ev-t">Ask Claude about <b>“${esc(q)}”</b></span><span class="ev-k">Starts a chat in Home</span></button>`;
|
|
141
|
+
const chips = S.el.querySelector('#evChips');
|
|
142
|
+
if (chips && chips.parentNode !== S.el) S.el.insertBefore(chips, box); // home first, so the redraw below never drops it
|
|
143
|
+
box.innerHTML = h;
|
|
144
|
+
// the phone draws the kind chips after the Initiatives group (EvPhone)
|
|
145
|
+
const ph = box.querySelector('.ev-phchips');
|
|
146
|
+
if (ph && chips) ph.replaceWith(chips);
|
|
147
|
+
const r = box.querySelector('[data-ev-retry]'); if (r) r.onclick = () => run();
|
|
148
|
+
const a = box.querySelector('#evo' + S.at); if (a) { S.el.querySelector('#evQ').setAttribute('aria-activedescendant', a.id); a.scrollIntoView({ block: 'nearest' }); }
|
|
149
|
+
}
|
|
150
|
+
function draw() { if (!S.el || S.el.hidden) return; drawChips(); drawList(); }
|
|
151
|
+
addEventListener('resize', () => draw());
|
|
152
|
+
|
|
153
|
+
/* ── open a result ── */
|
|
154
|
+
const onHome = () => /^\/(?:premium(?:\.html)?|index\.html)?$/.test(location.pathname);
|
|
155
|
+
function homeUrl(params) { const q = new URLSearchParams(params); if (wsParam()) q.set('ws', wsParam()); return '/premium.html?' + q.toString(); }
|
|
156
|
+
function go(r) {
|
|
157
|
+
closeSearch();
|
|
158
|
+
if (r.kind === 'ask') { askClaude(r.title); return; }
|
|
159
|
+
if (r.kind === 'initiative') { if (S.go) { S.go({ ini: r.id }); return; } location.assign(homeUrl(r.board ? { ini: r.id, board: r.board } : { ini: r.id })); return; }
|
|
160
|
+
if (r.kind === 'session') { if (S.go) { S.go({ ses: r.id }); return; } location.assign(homeUrl({ session: r.id })); return; }
|
|
161
|
+
if (r.kind === 'meeting') { import('./premium-vw-open.js').then(() => window.czViews.openMeeting({ note: r.id }, { ws: wsParam() })).catch(() => openFileCard(r)); return; }
|
|
162
|
+
if (r.main && /\.md$/i.test(r.path)) {
|
|
163
|
+
import('./premium-vw-doc.js').then((M) => { if (!M.openDocPage({ path: r.path, title: r.title }, { ws: () => wsParam() })) openFileCard(r); }).catch(() => openFileCard(r));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
openFileCard(r);
|
|
167
|
+
}
|
|
168
|
+
/** "Ask Claude about …" starts a chat in Home: the question is put in Home's box, not sent. */
|
|
169
|
+
function askClaude(q) {
|
|
170
|
+
const text = 'Tell me about “' + q + '” in this product.';
|
|
171
|
+
const box = onHome() && document.getElementById('hmIn');
|
|
172
|
+
if (box) { box.value = text; box.dispatchEvent(new Event('input', { bubbles: true })); box.focus(); return; }
|
|
173
|
+
location.assign(homeUrl({ say: text }));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A file read-only from its worktree, in the Viewer: Markdown as text, HTML as a still picture (no scripts), anything else as text. */
|
|
177
|
+
export function openFileCard(r) {
|
|
178
|
+
const kind = { document: 'Document', slides: 'Slides', report: 'Report', artifact: 'Artifact', file: 'File' }[r.kind] || 'File';
|
|
179
|
+
const where = r.main ? 'main' : 'worktree ' + (r.branch || r.wt);
|
|
180
|
+
const vid = 'search:' + (r.wt || 'main') + ':' + r.path;
|
|
181
|
+
const body = vwOpen({ id: vid, kind: kind + ' · ' + where, title: r.title || r.path, icon: r.kind === 'slides' ? 'slides' : r.kind === 'report' ? 'report' : 'doc', render: (b) => { b.classList.add('ev-card-b'); b.innerHTML = skelRows(3); } });
|
|
182
|
+
const load = async () => {
|
|
183
|
+
const f = await getj('/api/find/file?wt=' + encodeURIComponent(r.wt || 'main') + '&path=' + encodeURIComponent(r.path) + wsQ('&'));
|
|
184
|
+
if (!body.isConnected || !vwCurrent() || vwCurrent().id !== vid) return; // the Viewer moved on: a late read draws nothing
|
|
185
|
+
if (!f.ok) {
|
|
186
|
+
body.innerHTML = `<h2 class="ev-h2">${esc(r.title || r.path)}</h2>` + failedItem({ what: 'This ' + kind.toLowerCase(), why: f.error, find: (r.path || '').split('/').pop().replace(/\.[^.]+$/, '') });
|
|
187
|
+
body.querySelector('[data-ev-retry]').onclick = () => { body.innerHTML = skelRows(3); load(); };
|
|
188
|
+
const fi = body.querySelector('[data-ev-find]'); if (fi) fi.onclick = () => openSearch({ q: fi.dataset.evFind });
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const head = `<p class="ev-lbl">${esc(f.path)} · ${esc(f.main ? 'main' : 'worktree ' + (f.branch || f.wt))}${f.main ? '' : ' · not merged'}</p>`;
|
|
192
|
+
if (/\.html?$/i.test(f.path)) {
|
|
193
|
+
body.innerHTML = head + '<iframe class="ev-frame" sandbox="" referrerpolicy="no-referrer" title="' + esc(r.title || f.path) + '"></iframe><p class="ev-small ev-mut">A still picture of the page: its scripts do not run here.</p>';
|
|
194
|
+
body.querySelector('iframe').srcdoc = f.text;
|
|
195
|
+
} else if (/\.(md|mdx|txt)$/i.test(f.path)) {
|
|
196
|
+
body.innerHTML = head + '<div class="ev-md"></div>';
|
|
197
|
+
try { const M = await import('./cozy-md.js'); const box = body.querySelector('.ev-md'); box.append(...M.toDom(M.parseMd(f.text.replace(/^---\n[\s\S]*?\n---\n/, '')), document)); }
|
|
198
|
+
catch { body.querySelector('.ev-md').outerHTML = `<pre class="ev-pre">${esc(f.text)}</pre>`; }
|
|
199
|
+
} else body.innerHTML = head + `<pre class="ev-pre">${esc(f.text)}</pre>`;
|
|
200
|
+
};
|
|
201
|
+
load();
|
|
202
|
+
return body;
|
|
203
|
+
}
|