create-pmos 0.397.0 → 0.398.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 +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 +101 -52
- package/workspace/briefing-premium-board-test.js +252 -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 +86 -196
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +159 -296
- package/workspace/briefing-premium-insights-test.js +337 -219
- package/workspace/briefing-premium-metrics-test.js +53 -97
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +66 -48
- package/workspace/briefing-premium-test.js +150 -647
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +12 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +47 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +85 -19
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +62 -14
- package/workspace/lib/insights-records.js +101 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-insights-premium.js +12 -3
- package/workspace/lib/routes-insights-records.js +129 -0
- package/workspace/lib/routes-notes.js +1 -0
- package/workspace/lib/routes-viewer.js +108 -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 +85 -75
- package/workspace/premium-briefing-depth-test.js +66 -53
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +35 -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 +32 -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 +50 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +7 -2
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +115 -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 +82 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +11 -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 +118 -187
- package/workspace/premium-vw-notes-test.js +85 -108
- package/workspace/premium-vw-rec-test.js +72 -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 +305 -0
- package/workspace/public/pm/bd-span.js +186 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- 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 +497 -230
- 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 +296 -167
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +17 -6
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +144 -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 +905 -0
- package/workspace/public/pm/home-around.js +515 -0
- package/workspace/public/pm/home-chat.js +459 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-more.js +249 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-work.js +519 -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 +423 -394
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-insights.js +792 -568
- package/workspace/public/pm/premium-meeting.js +61 -549
- 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 +509 -480
- package/workspace/public/pm/premium-report-tab.js +87 -63
- package/workspace/public/pm/premium-shell.js +72 -119
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +187 -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 +731 -0
- package/workspace/public/pm/premium-vw-notes.js +56 -69
- 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/term-view.js +22 -0
- package/workspace/public/premium-board.html +28 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +22 -60
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +16 -107
- 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/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/* pm/home-work.js — My work in the Home Viewer (initiative premium-agreed-design; the depth of initiative premium-work-depth).
|
|
2
|
+
* The Agreed design does not draw My work yet, so this is a plain minimal card marked "Waiting for design". It reads GET /api/my-work-premium
|
|
3
|
+
* (lib/my-work-premium.js builds the model) and keeps every feature of the old My work page usable:
|
|
4
|
+
* four tabs: Your list (the Work queue but Kept and Done, with the Focus chip and one add box), Waiting on others, Weekly review, Untouched
|
|
5
|
+
* a row opens the item in the same card, with Back: Done, Edit ▾ (When, Waiting on, Who does it, Priority · Due), Keep it, Drop it, the agent
|
|
6
|
+
* on the item (draft, stop, try again, edit, post after a confirm, send back), and the draft or the source under it
|
|
7
|
+
* the Focus chip opens Focus and jobs in the same card: accept or dismiss a suggestion, clear one, add a job
|
|
8
|
+
* keys and swipe on the rows of Your list: J and K move, the arrows (or a drag past 90 px) do what the row names; most presses offer Undo
|
|
9
|
+
* Every press is the PM's and goes to the Work page's own route under /api/pm-items, /api/pm-jobs or /api/my-work (pmPost carries the launch
|
|
10
|
+
* nonce); this file adds no writer. A refused press shows the route's reason and changes nothing. Text from the list goes through esc(). */
|
|
11
|
+
import { pmGet, pmPost } from './http.js';
|
|
12
|
+
import { open as vwOpen } from './cozy-viewer.js';
|
|
13
|
+
import { mdRender } from './markdown.js';
|
|
14
|
+
|
|
15
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
16
|
+
const WAIT = '<p class="hx-wait"><i aria-hidden="true"></i>Waiting for design</p>';
|
|
17
|
+
const wsQ = () => { const w = new URLSearchParams(location.search).get('ws'); return w ? '?ws=' + encodeURIComponent(w) : ''; };
|
|
18
|
+
const WS = () => new URLSearchParams(location.search).get('ws') || '';
|
|
19
|
+
const RM = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
20
|
+
const SV = (p) => `<svg class="i" viewBox="0 0 24 24" aria-hidden="true">${p}</svg>`;
|
|
21
|
+
const CHECK = SV('<path d="M5 12l5 5 9-10"/>');
|
|
22
|
+
const ICON = { sun: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2"/>', moon: '<path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/>', eye: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>' };
|
|
23
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
24
|
+
const dayLabel = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso || ''); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
|
|
25
|
+
const addIso = (iso, n) => new Date(Date.parse(iso + 'T00:00:00Z') + n * 86400000).toISOString().slice(0, 10);
|
|
26
|
+
const nextMonday = (iso) => addIso(iso, ((1 - new Date(iso + 'T00:00:00Z').getUTCDay() + 7) % 7) || 7);
|
|
27
|
+
const hhmm = (iso) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? '' : String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
|
|
28
|
+
const mdHtml = (t) => { try { const d = document.createElement('div'); d.append(...mdRender(String(t)).blocks.map((b) => b.node || b)); return d.innerHTML; } catch { return '<p>' + esc(t) + '</p>'; } }; // mdRender builds nodes, never a string, so nothing in a draft runs
|
|
29
|
+
const post = (path, body) => pmPost(path, body).catch(() => null);
|
|
30
|
+
|
|
31
|
+
function toast(t) { const el = document.getElementById('toast'); if (!el) return; el.classList.remove('act'); el.textContent = t; el.classList.add('on'); clearTimeout(toast.t); toast.t = setTimeout(() => el.classList.remove('on'), 4200); }
|
|
32
|
+
function toastUndo(msg, undo, after) {
|
|
33
|
+
const t = document.getElementById('toast'); if (!t) return;
|
|
34
|
+
t.innerHTML = `${esc(msg)} <button class="undo" type="button">Undo</button>`; t.classList.add('on', 'act');
|
|
35
|
+
t.querySelector('.undo').onclick = async () => { t.classList.remove('on', 'act'); const r = await undo(); if (!r || r.ok !== true) toast((r && r.error) || 'It could not be undone.'); if (after) await after(); };
|
|
36
|
+
clearTimeout(toast.t); toast.t = setTimeout(() => t.classList.remove('on', 'act'), 8000);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const TABS = [['yours', 'Your list'], ['waiting', 'Waiting on others'], ['review', 'Weekly review'], ['stale', 'Untouched']];
|
|
40
|
+
const AG_CHIP = { ready: 'Draft ready', queued: 'Agent working', working: 'Agent working', sending: 'Agent working', failed: 'Agent stopped' };
|
|
41
|
+
const NOTYET = [['later-today', 'Later today'], ['tomorrow', 'Tomorrow'], ['next-week', 'Next week']];
|
|
42
|
+
const WHO = [['you', 'You'], ['agent-drafts', 'Agent drafts'], ['agent-does', 'Agent does']];
|
|
43
|
+
const PRIS = ['P1', 'P2', 'P3', ''];
|
|
44
|
+
const PLACE = { today: ['Today', ''], inbox: ['Inbox', 'not placed yet'], tray: ['Not placed yet', 'you added it'], upcoming: ['Upcoming', ''], waiting: ['Waiting', ''], someday: ['Someday', ''] };
|
|
45
|
+
const KIND = { ask: 'You asked', draft: 'Agent drafted', edit: 'You edited it', note: 'You sent it back', sent: 'Posted', post: 'Posted' };
|
|
46
|
+
const SAID = { done: 'Marked done.', notyet: 'Put off. It comes back by itself.', flag: 'Moved to Today.', waiting: 'Now waiting.', remove: 'Dropped.', keep: 'Kept.' };
|
|
47
|
+
const freshUi = () => ({ xp: null, ed: null, dd: '', sn: '', ask: null, body: null, editing: false, confirm: false, back: false, note: '', wo: '', pick: null, round: null, dpick: null, sheet: false, all: false, job: '' });
|
|
48
|
+
|
|
49
|
+
/** Open My work in the Viewer on one tab (yours | waiting | review | stale). */
|
|
50
|
+
export function openMyWork(tab = 'yours') {
|
|
51
|
+
const W = { r: null, M: null, tab: TABS.some((t) => t[0] === tab) ? tab : 'yours', msg: '', view: null, key: null, ui: freshUi(), refocus: null };
|
|
52
|
+
let body = null;
|
|
53
|
+
const rowOf = (key) => ((W.M && W.M.rows) || []).find((r) => r.key === key) || null;
|
|
54
|
+
const openR = () => (W.view === 'item' ? rowOf(W.key) : null);
|
|
55
|
+
const focusIds = () => new Set(((W.M && W.M.focus && W.M.focus.suggestions[0]) || {}).item_ids || []);
|
|
56
|
+
const setTitle = (t) => { const el = document.getElementById('czVwTitle'); if (el) el.textContent = t; };
|
|
57
|
+
|
|
58
|
+
/* ── the list ── */
|
|
59
|
+
function sideOf(r) {
|
|
60
|
+
if (!r || r.list === 'waiting') return null;
|
|
61
|
+
if (r.list === 'today') return {
|
|
62
|
+
r: r.agent === 'ready' ? { label: 'Review', ic: ICON.eye, fn: () => openItem(r.key) } : { label: 'Done', ic: null, fn: () => doneP(r, { list: true }) },
|
|
63
|
+
l: { label: 'Tomorrow', ic: ICON.moon, fn: () => deferP(r, addIso(W.M.today, 1), { list: true }) },
|
|
64
|
+
};
|
|
65
|
+
return { r: { label: 'In Today', ic: ICON.sun, fn: () => todayP(r, { list: true }) }, l: r.list === 'someday' ? null : { label: 'Someday', ic: ICON.moon, fn: () => somedayP(r, { list: true }) } };
|
|
66
|
+
}
|
|
67
|
+
function rowHtml(r, sm) {
|
|
68
|
+
const sd = sm ? null : sideOf(r);
|
|
69
|
+
const desc = sd ? ` aria-description="${esc((sd.r ? 'Right arrow: ' + sd.r.label + '. ' : '') + (sd.l ? 'Left arrow: ' + sd.l.label + '. ' : '') + 'J and K move between rows.')}"` : '';
|
|
70
|
+
const tags = (r.focus ? '<em class="xfc">Focus</em>' : '') + (!sm && !r.focus && focusIds().has(r.id) ? '<em class="xfc sug">Suggested focus</em>' : '');
|
|
71
|
+
const sub = [AG_CHIP[r.agent] || '', r.sub, r.chip || ''].filter(Boolean).join(' · ');
|
|
72
|
+
return `<div class="wrw"><div class="hx-row wrow${sm ? ' sm' : ''}" data-key="${esc(r.key)}"><button type="button" class="hx-t wrh"${desc}><b>${esc(r.title)}${tags}</b>${sub ? `<em>${esc(sub)}</em>` : ''}</button>`
|
|
73
|
+
+ (sm ? '' : `<button type="button" class="hx-b" data-done="${esc(r.id)}">Done</button>`) + '</div></div>';
|
|
74
|
+
}
|
|
75
|
+
function focusChip() {
|
|
76
|
+
const F = W.M.focus, nx = F.suggestions[0], acc = F.accepted;
|
|
77
|
+
const say = nx ? `Suggested · ${nx.title} · ${nx.why}` : acc.length ? 'Your focus today · ' + acc.map((a) => a.title).join(' · ') : 'Nothing to suggest · Nothing more to suggest today';
|
|
78
|
+
const n = nx ? F.suggestions.length + ' suggested' : acc.length ? acc.length + ' in focus' : '';
|
|
79
|
+
return `<span id="xFocus"><button type="button" class="hx-b xfq${nx ? ' on' : ''}" data-xf="more" title="${esc(say)}" aria-label="Focus and jobs. ${esc(say)}">Focus${n ? ` <em>${esc(n)}</em>` : ''}</button></span>`;
|
|
80
|
+
}
|
|
81
|
+
function listHtml() {
|
|
82
|
+
const m = W.M;
|
|
83
|
+
if (W.tab === 'yours') {
|
|
84
|
+
const tabs = m.queue.tabs.filter((t) => t.key !== 'kept' && t.key !== 'done'); // Kept and Done are not on your list
|
|
85
|
+
const groups = tabs.filter((t) => t.n).map((t) => `<h4 class="mw-g">${esc(t.label)}</h4>` + t.groups.flatMap((g) => g.rows || []).map((r) => rowHtml(r)).join('')).join('');
|
|
86
|
+
return `<div class="mw-list"><div class="mw-head">${focusChip()}</div>${groups || '<p class="hx-n">Nothing on your list.</p>'}`
|
|
87
|
+
+ '<div class="hx-add"><input id="hxLine" placeholder="Add to your list, e.g. Call Ana tomorrow" aria-label="Add to your list"><button type="button" class="hx-b pri" data-x="add">Add</button></div></div>';
|
|
88
|
+
}
|
|
89
|
+
if (W.tab === 'waiting') return `<div class="mw-wait">${m.waiting.rows.length ? m.waiting.rows.map((r) => rowHtml(r, true)).join('') : '<p class="hx-n">Nobody owes you anything.</p>'}</div>`;
|
|
90
|
+
if (W.tab === 'review') {
|
|
91
|
+
const F = m.friday;
|
|
92
|
+
return F ? `<p class="hx-n">${esc(F.cap)}</p>` + F.steps.map((s) => `<div class="hx-row"><span class="hx-t"><b>${esc(s.label)}</b><em>${s.n} to look at</em></span>${s.first && rowOf(s.first) ? `<button type="button" class="hx-b" data-open="${esc(s.first)}">Open</button>` : ''}</div>`).join('') : '<p class="hx-n">No review is due.</p>';
|
|
93
|
+
}
|
|
94
|
+
const ids = new Set((m.review && m.review.ids) || []), seen = new Set();
|
|
95
|
+
const rows = (m.rows || []).filter((r) => ids.has(r.id) && !seen.has(r.id) && seen.add(r.id));
|
|
96
|
+
const n = (m.review && m.review.n) || 0;
|
|
97
|
+
return n ? `<p class="hx-n">${n === 1 ? '1 item has' : n + ' items have'} sat untouched for ${m.review.days} days.</p>` + rows.map((r) => `<div class="hx-row"><button type="button" class="hx-t" data-open="${esc(r.key)}"><b>${esc(r.title)}</b><em>${esc(r.sub)}</em></button><button type="button" class="hx-b" data-done="${esc(r.id)}">Done</button></div>`).join('') : '<p class="hx-n">Nothing has sat untouched.</p>';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* ── the item ── */
|
|
101
|
+
const whenOf = (r) => {
|
|
102
|
+
const d = r.dialog, nb = d.defer && d.defer > W.M.today ? d.defer : null;
|
|
103
|
+
if (nb) return ['Not before ' + dayLabel(nb), 'off your lists until then'];
|
|
104
|
+
const p = PLACE[r.list] || ['On your list', ''];
|
|
105
|
+
return r.list === 'upcoming' && d.edit.due ? [p[0], 'due ' + dayLabel(d.edit.due)] : p;
|
|
106
|
+
};
|
|
107
|
+
const fieldHtml = (k, label, val, sub, open) => `<button type="button" class="hx-b ffd" data-p="xt" data-k="${k}" aria-expanded="${open}"><small>${esc(label)}</small><b>${esc(val)}${sub ? ` <em>· ${esc(sub)}</em>` : ''}</b></button>`;
|
|
108
|
+
function choicesHtml(r, a) {
|
|
109
|
+
const ui = W.ui, nm = nextMonday(W.M.today), pick = ui.pick || 'agent';
|
|
110
|
+
const opts = [['agent', 'Suggested', 'Let the agent draft this', a.mine ? 'Drafts it here in PMOS. Nothing leaves PMOS.' : `Drafts it here in PMOS. Nothing goes to ${a.where || 'anyone'}.`]];
|
|
111
|
+
if (r.list !== 'today') opts.push(['today', '', 'Do it today', 'Moves to Today']);
|
|
112
|
+
opts.push(['nb', '', 'Not before ' + dayLabel(nm), 'Out of Today until then']);
|
|
113
|
+
const go = pick === 'agent' ? ['ag-brief', 'Let the agent draft this'] : pick === 'today' ? ['ag-today', 'Do it today'] : ['ag-nb', 'Not before ' + dayLabel(nm)];
|
|
114
|
+
return `<div class="xch" role="radiogroup" aria-label="What to do with this">${opts.map((o) => `<button type="button" class="hx-b xco" role="radio" data-p="pick" data-v="${o[0]}" aria-checked="${pick === o[0]}">${o[1] ? `<em>${o[1]}</em>` : ''}<b>${esc(o[2])}</b><span>${esc(o[3])}</span></button>`).join('')}</div>`
|
|
115
|
+
+ `<div class="hx-top"><button type="button" class="hx-b pri" data-p="${go[0]}">${esc(go[1])}</button></div>`;
|
|
116
|
+
}
|
|
117
|
+
const DECIDE = (a, step, w) => [
|
|
118
|
+
...(!a.mine || step ? [['post', step ? 'Do the step' : 'Post it to ' + w, 'Suggested', [['lock', step ? 'Outward: exactly this step' : 'Outward: exactly this text'], ['out', step ? 'A session with Chrome does it' : 'Goes to ' + w + ' as you']]]] : []),
|
|
119
|
+
['edit', 'Edit the draft', '', [[null, step ? 'The step then uses your version' : a.mine ? 'Your version replaces the draft here' : 'Post then sends your version']]],
|
|
120
|
+
['keep', 'Keep it as a draft', a.mine ? 'Suggested' : '', [[null, 'Nothing leaves PMOS']]],
|
|
121
|
+
['done', 'Mark it done', '', [[null, 'Closes the item. Nothing is posted']]],
|
|
122
|
+
];
|
|
123
|
+
function decideHtml(a, step, w) {
|
|
124
|
+
const ui = W.ui, opts = DECIDE(a, step, w), pick = opts.some((o) => o[0] === ui.dpick) ? ui.dpick : opts[0][0], cur = opts.find((o) => o[0] === pick);
|
|
125
|
+
const go = { post: ['ag-post', cur[1]], edit: ['ag-save', 'Save my version'], keep: ['ag-keep', 'Keep it as a draft'], done: ['ag-done', 'Mark it done'] }[pick];
|
|
126
|
+
let h = `<p class="hx-n">Or decide</p><div class="xch" role="radiogroup" aria-label="What to do with the draft">${opts.map((o) => `<button type="button" class="hx-b xco" role="radio" data-p="dpick" data-v="${o[0]}" aria-checked="${pick === o[0]}">${o[2] ? `<em>${o[2]}</em>` : ''}<b>${esc(o[1])}</b>${o[3].map((f) => `<span>${esc(f[1])}</span>`).join('')}</button>`).join('')}</div>`;
|
|
127
|
+
if (ui.editing) h += `<label class="hx-n" for="agBody">Your text for the draft</label><textarea class="mw-ta" id="agBody" rows="8">${esc(ui.body == null ? (a.draft && a.draft.body) || '' : ui.body)}</textarea>`;
|
|
128
|
+
if (ui.confirm) {
|
|
129
|
+
const txt = ui.editing && ui.body != null ? ui.body : (a.draft && a.draft.body) || (a.draft && a.draft.summary) || '';
|
|
130
|
+
h += `<div class="xcon" role="group" aria-label="Confirm"><p><b>${step ? 'Do this step?' : `Post this to ${esc(w)} as you?`}</b></p>`
|
|
131
|
+
+ (step ? `<p>A new session with Chrome does exactly this step and nothing else:</p><p class="xq">${esc(step)}</p>` : `<p>Exactly this text goes:</p><p class="xq">${esc(txt).replace(/\n/g, '<br>')}</p>`)
|
|
132
|
+
+ `<div class="hx-top"><button type="button" class="hx-b pri" data-p="ag-go">${step ? 'Do the step now' : `Post it to ${esc(w)} now`}</button><button type="button" class="hx-b" data-p="ag-no">Not yet</button></div></div>`;
|
|
133
|
+
} else {
|
|
134
|
+
h += `<div class="hx-top"><button type="button" class="hx-b pri" data-p="${go[0]}">${esc(go[1])}</button>${ui.editing ? '<button type="button" class="hx-b" data-p="ag-edit">Use the agent’s text</button>' : ''}<button type="button" class="hx-b" data-p="ag-back" aria-expanded="${ui.back}">Send it back with a note</button></div>`;
|
|
135
|
+
if (ui.back) h += `<label class="hx-n" for="agNote">Tell the agent what to change</label><textarea class="mw-ta" id="agNote" rows="3" maxlength="500">${esc(ui.note)}</textarea><div class="hx-top"><button type="button" class="hx-b pri" data-p="ag-sendback"${ui.note.trim() ? '' : ' disabled'}>Send it back</button></div><p class="hx-n">The agent drafts it again. ${a.mine ? 'Nothing leaves PMOS.' : `Nothing goes to ${esc(w)} or to anyone.`}</p>`;
|
|
136
|
+
}
|
|
137
|
+
return h;
|
|
138
|
+
}
|
|
139
|
+
const turnsHtml = (a) => (a.turns && a.turns.length ? `<h4>Conversation with the agent</h4><ol class="mw-turns">${a.turns.map((t, i) => `<li><b>${esc(t.who === 'agent' ? 'Agent' : 'You')}</b> ${esc(KIND[t.kind] || t.kind || 'said')}${t.at ? ' · ' + esc(String(t.at).slice(0, 10)) : ''}${t.text ? ` <span>${esc(t.text)}</span>` : ''}${t.body ? ` <button type="button" class="hx-b" data-p="round" data-i="${i}" aria-expanded="${W.ui.round === i}">${t.who === 'agent' ? 'View round' : 'View your edit'}</button>${W.ui.round === i ? `<div class="mw-md">${mdHtml(t.body)}</div>` : ''}` : ''}</li>`).join('')}</ol>` : '');
|
|
140
|
+
function agentInner(r) {
|
|
141
|
+
const a = r.dialog.agent; if (!a) return '';
|
|
142
|
+
const ui = W.ui, w = a.where || 'anyone', dr = a.draft;
|
|
143
|
+
const draftBox = (dr && (dr.body || dr.summary) ? '<p class="hx-n">The draft is below.</p>' : '') + turnsHtml(a);
|
|
144
|
+
if (a.state === 'suggest') {
|
|
145
|
+
return `<p class="hx-n nodef">${a.mine ? 'The agent can draft a first version of this for you. You read it here. Nothing leaves PMOS.' : `The agent can draft this for you. You read it here first. Nothing goes to ${esc(w)} until you post it.`}</p>`
|
|
146
|
+
+ `<label class="hx-n" for="agAsk">What the agent will do</label><input id="agAsk" class="mw-in" maxlength="500" autocomplete="off" value="${esc(ui.ask == null ? a.ask : ui.ask)}">` + choicesHtml(r, a);
|
|
147
|
+
}
|
|
148
|
+
if (a.state === 'queued' || a.state === 'working' || a.state === 'sending') {
|
|
149
|
+
const line = a.state === 'queued' ? 'Queued. The agent starts as soon as a session is free. You can close this page.'
|
|
150
|
+
: a.state === 'sending' ? `Posting to ${esc(w)}. A session does exactly the step you approved and nothing else.`
|
|
151
|
+
: 'The agent is working on it. You can close this page: the item keeps its state.' + (a.started_at ? ' Started at ' + esc(hhmm(a.started_at)) + '.' : '');
|
|
152
|
+
return `<p class="hx-n nodef" role="status">${line}</p>${draftBox}${a.state === 'sending' ? '' : '<div class="hx-top"><button type="button" class="hx-b" data-p="ag-stop">Stop</button></div>'}`;
|
|
153
|
+
}
|
|
154
|
+
if (a.state === 'ready') {
|
|
155
|
+
const step = dr && dr.step;
|
|
156
|
+
return `<p class="hx-n nodef">${step ? 'Draft ready. The step has not run.' : `Draft ready. Nothing went to ${esc(a.mine ? 'anyone' : w)}.`}</p>` + draftBox + decideHtml(a, step, w);
|
|
157
|
+
}
|
|
158
|
+
if (a.state === 'failed') {
|
|
159
|
+
return `<p class="hx-n nodef" role="status">${a.asks && a.error ? esc(a.error.charAt(0).toUpperCase() + a.error.slice(1)) + ' Nothing was sent.' : `The agent stopped${a.error ? ': ' + esc(a.error) : '.'} Nothing was sent.`}</p>${draftBox}`
|
|
160
|
+
+ '<div class="hx-top"><button type="button" class="hx-b pri" data-p="ag-retry">Try again</button><button type="button" class="hx-b" data-p="ag-stop">Stop</button></div>';
|
|
161
|
+
}
|
|
162
|
+
if (a.state === 'sent') return `<p class="hx-n nodef" role="status">${a.mine ? 'The draft is kept on this item.' : `You posted it to ${esc(w)}${a.sent_at ? ' at ' + esc(hhmm(a.sent_at)) : ''}.`}${a.link ? ` <a href="${esc(a.link)}" target="_blank" rel="noopener">Open what was posted</a>` : ''}</p>${draftBox}`;
|
|
163
|
+
return '';
|
|
164
|
+
}
|
|
165
|
+
function panelHtml(r, x) {
|
|
166
|
+
const ui = W.ui, d = r.dialog, a = d.write.actions, S = d.steps || [];
|
|
167
|
+
if (x === 'agent') return `<div class="xpan agblk" data-state="${esc(d.agent.state)}">${agentInner(r)}</div>`;
|
|
168
|
+
if (x === 'when') {
|
|
169
|
+
const o = (attrs, l, sub) => `<button type="button" class="hx-b fopt" ${attrs}><span>${l}</span>${sub ? ` <small>${sub}</small>` : ''}</button>`;
|
|
170
|
+
return `<div class="xpan" role="group" aria-label="When">${a.includes('flag') ? o('data-p="flag"', 'Today') : ''}${NOTYET.map(([k, t]) => o(`data-p="notyet" data-when="${k}"`, t, 'comes back by itself')).join('')}`
|
|
171
|
+
+ o('data-p="xt" data-k="defer"', 'Not before a date…', 'leaves your lists') + o(`data-p="xt" data-k="someday" aria-pressed="${d.someday}"`, d.someday ? 'Bring back from Someday' : 'Someday') + '</div>';
|
|
172
|
+
}
|
|
173
|
+
if (x === 'wait') return `<div class="xpan"><div class="hx-add"><input id="wOn" class="mw-in" maxlength="80" placeholder="A name" aria-label="Waiting on" autocomplete="off" value="${esc(ui.wo)}"><button type="button" class="hx-b" data-p="waiting" id="wBtn"${ui.wo.trim() ? '' : ' disabled'}>Wait for them</button></div></div>`;
|
|
174
|
+
if (x === 'edit') {
|
|
175
|
+
const e = ui.ed || (ui.ed = { title: d.edit.title, due: d.edit.due, priority: d.edit.priority, wo: d.edit.waiting_on, job: d.edit.job }), ro = !!d.edit.title_ro;
|
|
176
|
+
return `<div class="xpan"><label class="mw-f"><span>Title</span><input id="xeT" class="mw-in" maxlength="250" value="${esc(e.title)}"${ro ? ' disabled' : ''}></label>${ro ? `<p class="hx-n note">${esc(d.edit.title_ro)}</p>` : ''}`
|
|
177
|
+
+ `<label class="mw-f"><span>Due</span><input type="date" id="xeD" class="mw-in" value="${esc(e.due)}"></label>`
|
|
178
|
+
+ `<div class="mw-f"><span>Priority</span><span class="hx-top" role="group" aria-label="Priority">${PRIS.map((p) => `<button type="button" class="hx-b" data-p="xpri" data-v="${p}" aria-pressed="${e.priority === p}">${p || 'None'}</button>`).join('')}</span></div>`
|
|
179
|
+
+ `<label class="mw-f"><span>Waiting on</span><input id="xeW" class="mw-in" maxlength="80" value="${esc(e.wo)}" placeholder="A name moves it to Waiting"></label>`
|
|
180
|
+
+ `<label class="mw-f"><span>Job</span><select id="xeJ" class="mw-in"><option value="">No job</option>${(W.M.jobs || []).map((j) => `<option value="${esc(j.id)}"${e.job === j.id ? ' selected' : ''}>${esc(j.name)}</option>`).join('')}</select></label>`
|
|
181
|
+
+ '<div class="hx-top"><button type="button" class="hx-b pri" data-p="xsave">Save</button><button type="button" class="hx-b" data-p="xt" data-k="edit">Cancel</button></div></div>';
|
|
182
|
+
}
|
|
183
|
+
if (x === 'steps') {
|
|
184
|
+
return `<div class="xpan"><ul class="xsteps">${S.map((s) => `<li><span class="xst">${esc(s.text)}</span><span class="hx-top" role="group" aria-label="Who does: ${esc(s.text)}">${WHO.map(([k, l]) => `<button type="button" class="hx-b" data-p="xwho" data-sid="${esc(s.id)}" data-v="${k}" aria-pressed="${s.who === k}">${l}</button>`).join('')}</span></li>`).join('') || '<li class="hx-n">No steps yet.</li>'}</ul>`
|
|
185
|
+
+ '<p class="hx-n note">A step that sends something to a person is only ever drafted by the agent. You release it.</p>'
|
|
186
|
+
+ `<div class="hx-add"><input id="xsIn" class="mw-in" maxlength="200" placeholder="Add a step" aria-label="A new step" value="${esc(ui.sn)}"><button type="button" class="hx-b" data-p="xsadd">Add</button></div></div>`;
|
|
187
|
+
}
|
|
188
|
+
if (x === 'defer') {
|
|
189
|
+
const dd = ui.dd || '', T = W.M.today;
|
|
190
|
+
return `<div class="xpan"><p class="hx-n">It leaves your lists until that day.</p><span class="hx-top" role="group" aria-label="Quick dates"><button type="button" class="hx-b" data-p="xdq" data-v="${addIso(T, 1)}">Tomorrow</button><button type="button" class="hx-b" data-p="xdq" data-v="${nextMonday(T)}">Monday</button><button type="button" class="hx-b" data-p="xdq" data-v="${addIso(T, 7)}">In a week</button></span>`
|
|
191
|
+
+ `<label class="mw-f"><span>Or a date</span><input type="date" id="xdD" class="mw-in" min="${addIso(T, 1)}" value="${esc(dd)}"></label>`
|
|
192
|
+
+ `<div class="hx-top"><button type="button" class="hx-b pri" data-p="xdgo"${dd ? '' : ' disabled'}>Not before ${dd ? esc(dayLabel(dd)) : 'that day'}</button>${d.defer ? '<button type="button" class="hx-b" data-p="xdclr">Clear the date</button>' : ''}</div></div>`;
|
|
193
|
+
}
|
|
194
|
+
return '';
|
|
195
|
+
}
|
|
196
|
+
function cardInner(r) {
|
|
197
|
+
const ui = W.ui, d = r.dialog, a = d.write.actions, x = ui.xp || '', S = d.steps || [], e = d.edit, ag = d.agent;
|
|
198
|
+
const steps = S.length ? S.length + (S.length === 1 ? ' step' : ' steps') : 'no steps yet';
|
|
199
|
+
const whos = [...new Set(S.map((s) => (WHO.find((w) => w[0] === s.who) || [0, 'You'])[1]))];
|
|
200
|
+
const fld = (k, label, val, sub, open = x === k) => fieldHtml(k, label, val, sub, open) + (open ? panelHtml(r, k) : '');
|
|
201
|
+
const when = whenOf(r), sum = [when[0], e.waiting_on ? 'waiting on ' + e.waiting_on : '', e.priority || '', e.due ? 'due ' + dayLabel(e.due) : ''].filter(Boolean).join(' · ');
|
|
202
|
+
let f = '';
|
|
203
|
+
if (ag && ag.state === 'suggest') f += fld('agent', 'The agent', 'Can draft this for you', ag.mine ? 'nothing leaves PMOS' : 'you read it first');
|
|
204
|
+
f += fieldHtml('when', 'When', when[0], when[1], x === 'when' || x === 'defer') + (x === 'when' || x === 'defer' ? panelHtml(r, x) : '')
|
|
205
|
+
+ (a.includes('waiting') || e.waiting_on ? fld('wait', 'Waiting on', e.waiting_on || 'Nobody', '') : '')
|
|
206
|
+
+ fld('steps', 'Who does it', whos.length ? whos.join(', ') : 'You', steps)
|
|
207
|
+
+ fld('edit', 'Priority · Due', e.priority || 'None', e.due ? 'due ' + dayLabel(e.due) : 'no date');
|
|
208
|
+
f += `<div class="hx-top">${a.includes('keep') ? '<button type="button" class="hx-b" data-p="keep">Keep it</button>' : ''}<button type="button" class="hx-b" data-p="remove">Drop it</button></div>`;
|
|
209
|
+
return `<div class="hx-top"><button type="button" class="hx-b" id="iTog" data-p="sheet" aria-expanded="${!!ui.sheet}" aria-controls="iSheet" title="Edit when, who and priority">Edit <em class="isum">${esc(sum)}</em></button>`
|
|
210
|
+
+ '<button type="button" class="hx-b pri" data-p="done">Done</button></div>'
|
|
211
|
+
+ `<div class="mw-sheet" id="iSheet" role="group" aria-label="Item fields"${ui.sheet ? '' : ' hidden'}>${f}</div>`
|
|
212
|
+
+ '<p class="hx-n mw-err" id="cardErr" role="alert" hidden></p>';
|
|
213
|
+
}
|
|
214
|
+
const agCardInner = (r) => (r.dialog.agent && r.dialog.agent.state !== 'suggest' ? `<div class="agblk" data-state="${esc(r.dialog.agent.state)}"><h4>The agent</h4>${agentInner(r)}</div>` : '');
|
|
215
|
+
function srcHtml(sc) {
|
|
216
|
+
const by = [sc.who, sc.where ? 'in ' + sc.where : ''].filter(Boolean).join(' ');
|
|
217
|
+
let g = `<p class="agtag"><b>${esc(sc.name || 'Source')}</b>${by ? ' ' + esc(by) : ''}</p>`;
|
|
218
|
+
if (sc.thread && sc.thread.length) g += sc.thread.map((m) => `<p class="hx-n"><b>${esc(m.who || 'Someone')}</b>${m.at ? ' ' + esc(m.at) : ''}<br>${esc(m.text)}</p>`).join('');
|
|
219
|
+
else if (sc.quote) g += `<blockquote>${esc(sc.quote)}</blockquote>`;
|
|
220
|
+
if (sc.ask && !(sc.thread && sc.thread.length) && !sc.quote) g += `<p><b>Asked:</b> ${esc(sc.ask)}</p>`;
|
|
221
|
+
if (sc.about) g += `<p>${esc(sc.about)}</p>`;
|
|
222
|
+
for (const rf of sc.refs || []) g += `<p><b>${rf.link ? `<a href="${esc(rf.link)}" target="_blank" rel="noopener">${esc(rf.label)}</a>` : esc(rf.label)}</b></p>${rf.lines.length ? `<ul>${rf.lines.map((l) => `<li>${esc(l)}</li>`).join('')}</ul>` : ''}`;
|
|
223
|
+
if (sc.evidence) g += `<p class="hx-n">Evidence: ${esc(sc.evidence)}</p>`;
|
|
224
|
+
if (sc.link) g += `<p><a class="hx-b mw-a" href="${esc(sc.link)}" target="_blank" rel="noopener">Open in ${esc(sc.name || 'its source')}</a></p>`;
|
|
225
|
+
return `<section class="mw-src">${g}</section>`;
|
|
226
|
+
}
|
|
227
|
+
function paneHtml(r) {
|
|
228
|
+
const p = r.dialog.pane, ag = r.dialog.agent, dr = ag && ag.draft && (ag.draft.body || ag.draft.summary) ? ag.draft : null;
|
|
229
|
+
let h = '';
|
|
230
|
+
if (dr) {
|
|
231
|
+
const long = String(dr.body || '').length > 900 || String(dr.body || '').split('\n').length > 16, clip = long && !W.ui.all;
|
|
232
|
+
h += `<section class="agpane"><p class="agtag"><b>${ag.state === 'sent' ? 'Posted' : 'Draft'}</b> ${ag.mine ? 'Draft for you' : 'Draft for ' + esc(ag.ref || ag.where || 'the item')} · ${ag.round ? 'Round ' + ag.round : 'Agent draft'}${ag.round_at ? ' · ' + esc(hhmm(ag.round_at)) : ''}</p>`
|
|
233
|
+
+ '<div class="hx-top"><button type="button" class="hx-b" data-pp="open">Open</button><button type="button" class="hx-b" data-pp="copy">Copy</button></div><p class="hx-n">Agent draft · not checked</p>'
|
|
234
|
+
+ (dr.step ? `<p class="hx-n">Step when you approve: ${esc(dr.step)}</p>` : '')
|
|
235
|
+
+ `<div class="mw-md${clip ? ' clipd' : ''}">${mdHtml(dr.body || dr.summary)}</div>${long ? `<button type="button" class="hx-b" data-pp="all" aria-expanded="${!clip}">${clip ? 'Show all' : 'Show less'}</button>` : ''}</section>`;
|
|
236
|
+
}
|
|
237
|
+
const kv = p.rows && p.rows.length ? `<dl class="hv-facts">${p.rows.map(([a, b]) => `<div><dt>${esc(a)}</dt><dd>${esc(b)}</dd></div>`).join('')}</dl>` : '';
|
|
238
|
+
if (r.dialog.source) return h + srcHtml(r.dialog.source) + `<details class="mw-det"><summary>Details</summary>${kv}<p class="hx-n">${esc(p.file)}</p></details>`;
|
|
239
|
+
return h + `<section class="mw-rec">${kv}<p class="hx-n">The item as your list holds it · ${esc(p.file)}</p></section>`;
|
|
240
|
+
}
|
|
241
|
+
function itemHtml(r) {
|
|
242
|
+
return `<div class="mw-sub mw-it" data-esc-layer>${WAIT}<div class="hx-top"><button type="button" class="hx-b" data-mw="back">Back to My work</button></div>`
|
|
243
|
+
+ `<h3 class="mw-t">${esc(r.title)}</h3>${r.sub ? `<p class="hx-n">${esc(r.sub)}</p>` : ''}${r.dialog.say ? `<p class="mw-say">${esc(r.dialog.say)}</p>` : ''}`
|
|
244
|
+
+ `<div id="card">${cardInner(r)}</div><div id="agCard">${agCardInner(r)}</div><div class="mw-pane">${paneHtml(r)}</div></div>`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/* ── Focus and jobs ── */
|
|
248
|
+
const fBody = (f) => ({ key: f.key, title: f.title, why: f.why, item_ids: f.item_ids, job: f.job || null });
|
|
249
|
+
const titleOfKey = (k) => {
|
|
250
|
+
const m = /^(job|item):(.+)$/.exec(k || ''); if (!m) return 'A suggestion';
|
|
251
|
+
if (m[1] === 'job') { const j = (W.M.jobs || []).find((x) => x.id === m[2]); return j ? j.name : 'A job'; }
|
|
252
|
+
const r = rowOf('work:' + m[2]); return r ? r.title : 'An item';
|
|
253
|
+
};
|
|
254
|
+
function focusHtml() {
|
|
255
|
+
const F = W.M.focus, titles = (ids) => ids.map((i) => { const r = rowOf('work:' + i); return r ? r.title : null; }).filter(Boolean);
|
|
256
|
+
const card = (f, state) => `<div class="mw-fc"><b>${esc(f.title)}</b>${f.why ? `<p class="hx-n">${esc(f.why)}</p>` : ''}${f.item_ids && f.item_ids.length ? `<p class="hx-n">${esc(titles(f.item_ids).join(' · '))}</p>` : ''}<div class="hx-top">`
|
|
257
|
+
+ (state === 'acc' ? `<span class="hx-n">In focus today.</span><button type="button" class="hx-b" data-fx="clr" data-k="${esc(f.key)}">Clear</button>`
|
|
258
|
+
: state === 'no' ? `<span class="hx-n">Not today.</span><button type="button" class="hx-b" data-fx="clr" data-k="${esc(f.key)}">Clear</button>`
|
|
259
|
+
: `<button type="button" class="hx-b" data-fx="acc" data-k="${esc(f.key)}">Accept</button><button type="button" class="hx-b" data-fx="no" data-k="${esc(f.key)}">Not today</button>`) + '</div></div>';
|
|
260
|
+
const rows = F.accepted.map((f) => card(f, 'acc')).concat(F.suggestions.map((f) => card(f, 'sug')), F.dismissed.map((k) => card({ key: k, title: titleOfKey(k), why: '', item_ids: [] }, 'no')));
|
|
261
|
+
const jobs = (W.M.jobs || []).map((j) => `<div class="mw-fc"><b>${esc(j.name)}</b><p class="hx-n">When ${esc(j.when)}, I want ${esc(j.want)}, so ${esc(j.so)}.</p><p class="hx-n">${j.open} open ${j.open === 1 ? 'item' : 'items'}</p></div>`).join('');
|
|
262
|
+
const okLine = /when .+,\s*i want .+,\s*so .+/i.test(W.ui.job || '');
|
|
263
|
+
return `<div class="mw-sub mw-fj" data-esc-layer>${WAIT}<div class="hx-top"><button type="button" class="hx-b" data-mw="back">Back to My work</button></div>`
|
|
264
|
+
+ '<p class="hx-n">PMOS suggests at most three, from your Today list: overdue first, then due today. Rules only, no model call.</p>'
|
|
265
|
+
+ (rows.join('') || '<p class="hx-n">Nothing is in Today, so there is nothing to suggest.</p>')
|
|
266
|
+
+ `<h4>Your jobs</h4>${jobs || '<p class="hx-n">You have no jobs yet. A job is something that matters to you, which items can serve.</p>'}`
|
|
267
|
+
+ `<div class="mw-fc"><b>Add a job</b><div class="hx-add"><input id="xjIn" class="mw-in" maxlength="300" placeholder="When …, I want …, so …" aria-label="A new job: when, I want, so" value="${esc(W.ui.job || '')}"><button type="button" class="hx-b pri" data-fx="jadd"${okLine ? '' : ' disabled'}>Add the job</button></div></div>`
|
|
268
|
+
+ '<p class="hx-n">Focus starts empty each day. Give an item a job from its Edit panel.</p></div>';
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* ── drawing ── */
|
|
272
|
+
function draw(sel) {
|
|
273
|
+
if (!body || !body.isConnected) return;
|
|
274
|
+
const keep = body.scrollTop;
|
|
275
|
+
if (!W.r) body.innerHTML = WAIT + '<p class="hx-n">Reading your list.</p>';
|
|
276
|
+
else if (!W.M) body.innerHTML = WAIT + `<p class="hx-n">Your list could not be read${W.r.error ? ': ' + esc(W.r.error) : ''}.</p>`;
|
|
277
|
+
else if (W.view === 'item' && openR()) { body.innerHTML = itemHtml(openR()); setTitle(openR().title); }
|
|
278
|
+
else if (W.view === 'fjobs') { body.innerHTML = focusHtml(); setTitle('Focus and jobs'); }
|
|
279
|
+
else {
|
|
280
|
+
W.view = null; setTitle('Your list');
|
|
281
|
+
body.innerHTML = WAIT + `<div class="hx-tabs" role="tablist">${TABS.map(([k, l]) => `<button type="button" role="tab" aria-selected="${k === W.tab}" data-tab="${k}">${esc(l)}</button>`).join('')}</div>` + listHtml() + `<p class="hx-n" role="status">${esc(W.msg)}</p>`;
|
|
282
|
+
}
|
|
283
|
+
body.scrollTop = keep;
|
|
284
|
+
if (sel) { const f = body.querySelector(sel); if (f) f.focus(); }
|
|
285
|
+
if (W.refocus && !W.view) {
|
|
286
|
+
const f = W.refocus; W.refocus = null;
|
|
287
|
+
const L = [...body.querySelectorAll('.mw-list .wrow:not(.sm) .wrh')], el = body.querySelector(`.mw-list .wrow[data-key="${CSS.escape(f.key)}"] .wrh`) || L[Math.min(f.i, L.length - 1)];
|
|
288
|
+
if (el) el.focus();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function showErr(msg) { const e = body && body.querySelector('#cardErr'); if (!e) { toast(msg); return; } e.textContent = msg; e.hidden = false; }
|
|
292
|
+
async function load() {
|
|
293
|
+
const r = await pmGet('/api/my-work-premium' + wsQ());
|
|
294
|
+
W.r = r || { ok: false };
|
|
295
|
+
W.M = r && r.ok && r.model ? r.model : null;
|
|
296
|
+
if (r && r.state === 'reading') setTimeout(load, 3000);
|
|
297
|
+
if (W.view === 'item' && !openR()) W.view = null; // the item left the list
|
|
298
|
+
draw();
|
|
299
|
+
}
|
|
300
|
+
function openItem(key) { if (!rowOf(key)) return; W.view = 'item'; W.key = key; W.ui = freshUi(); draw('[data-mw="back"]'); }
|
|
301
|
+
function back() { const k = W.key; W.view = null; W.ui = freshUi(); W.refocus = k ? { key: k, i: 0 } : null; draw(); }
|
|
302
|
+
|
|
303
|
+
/* ── presses ── */
|
|
304
|
+
async function commit(o) {
|
|
305
|
+
if (!o.list && body) body.querySelectorAll('#card button, #agCard button').forEach((b) => { b.disabled = true; });
|
|
306
|
+
const res = await o.send();
|
|
307
|
+
if (!res || res.ok !== true) {
|
|
308
|
+
const msg = (res && res.error) || 'The press was not recorded.';
|
|
309
|
+
if (o.list) toast(msg); else { draw(); showErr(msg); }
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
const said = typeof o.say === 'function' ? o.say(res) : o.say;
|
|
313
|
+
if (o.keep) { await load(); draw(o.focus); if (said) toast(said); }
|
|
314
|
+
else {
|
|
315
|
+
if (!o.list) { W.view = null; W.ui = freshUi(); }
|
|
316
|
+
if (o.undo) toastUndo(said, o.undo, load); else toast(said);
|
|
317
|
+
await load();
|
|
318
|
+
}
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
const reopen = (id) => () => post('/api/pm-items/reopen', { id });
|
|
322
|
+
const doneP = (r, o = {}) => commit({ ...o, send: () => post('/api/pm-items/done', { id: r.id, ...(o.how ? { how: o.how } : {}) }), say: o.say || SAID.done, undo: reopen(r.id) });
|
|
323
|
+
const deferP = (r, until, o = {}) => commit({ ...o, send: () => post('/api/pm-items/defer', { id: r.id, until }),
|
|
324
|
+
say: until ? `Not before ${dayLabel(until)}. It leaves your lists until then.` : 'Date cleared.', undo: () => post('/api/pm-items/defer', { id: r.id, until: r.dialog.defer || null }) });
|
|
325
|
+
const somedayP = (r, o = {}) => commit({ ...o, send: () => post(r.dialog.someday ? '/api/pm-items/unpark' : '/api/pm-items/someday', { id: r.id }),
|
|
326
|
+
say: r.dialog.someday ? 'Brought back.' : 'Moved to Someday.', undo: () => post(r.dialog.someday ? '/api/pm-items/someday' : '/api/pm-items/unpark', { id: r.id }) });
|
|
327
|
+
const todayP = (r, o = {}) => commit({ ...o, send: () => post('/api/pm-items/flag', { id: r.id, flagged: true }), say: SAID.flag, undo: () => post('/api/pm-items/flag', { id: r.id, flagged: false }) });
|
|
328
|
+
function saveEdit(r) {
|
|
329
|
+
const o = r.dialog.edit, e = W.ui.ed, id = r.id, fields = {}, old = {};
|
|
330
|
+
const t = e.title.trim();
|
|
331
|
+
if (!o.title_ro && t && t !== o.title) { fields.title = t; old.title = o.title; }
|
|
332
|
+
if (e.due !== o.due) { fields.due = e.due || null; old.due = o.due || null; }
|
|
333
|
+
if (e.priority !== o.priority) { fields.priority = e.priority || null; old.priority = o.priority || null; }
|
|
334
|
+
if (e.job !== o.job) { fields.job = e.job || null; old.job = o.job || null; }
|
|
335
|
+
const wo = e.wo.trim(), woChanged = wo !== o.waiting_on;
|
|
336
|
+
if (!Object.keys(fields).length && !woChanged) { showErr('Nothing changed.'); return null; }
|
|
337
|
+
return commit({
|
|
338
|
+
send: async () => { let res = { ok: true }; if (Object.keys(fields).length) res = await post('/api/pm-items/edit', { id, fields }); if (res && res.ok === true && woChanged) res = await post('/api/pm-items/waiting', { id, on: wo || null }); return res; },
|
|
339
|
+
say: woChanged && wo ? `Saved. It now waits on ${wo}.` : 'Saved.',
|
|
340
|
+
undo: async () => { let res = { ok: true }; if (Object.keys(old).length) res = await post('/api/pm-items/edit', { id, fields: old }); if (res && res.ok === true && woChanged) res = await post('/api/pm-items/waiting', { id, on: o.waiting_on || null }); return res; },
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function itemPress(b, r) {
|
|
344
|
+
const ui = W.ui, id = r.id, k = b.dataset.p, d = r.dialog, a = d.agent || {};
|
|
345
|
+
switch (k) {
|
|
346
|
+
case 'notyet': return commit({ send: () => post('/api/pm-items/notyet', { id, when: b.dataset.when }), say: SAID.notyet });
|
|
347
|
+
case 'waiting': return commit({ send: () => post('/api/pm-items/waiting', { id, on: ui.wo.trim() }), say: SAID.waiting });
|
|
348
|
+
case 'done': return doneP(r);
|
|
349
|
+
case 'sheet': ui.sheet = !ui.sheet; if (!ui.sheet) ui.xp = null; return draw(ui.sheet ? '#iSheet .ffd' : '#iTog');
|
|
350
|
+
case 'remove': return commit({ send: () => post('/api/pm-items/remove', { id }), say: SAID.remove, undo: () => post('/api/pm-items/undo', { id }) });
|
|
351
|
+
case 'flag': case 'ag-today': return todayP(r);
|
|
352
|
+
case 'keep': return commit({ send: () => post('/api/pm-items/keep', { id }), say: SAID.keep });
|
|
353
|
+
case 'pick': ui.pick = b.dataset.v; return draw(`[data-p="pick"][data-v="${b.dataset.v}"]`);
|
|
354
|
+
case 'ag-nb': return deferP(r, nextMonday(W.M.today));
|
|
355
|
+
case 'round': ui.round = ui.round === +b.dataset.i ? null : +b.dataset.i; return draw(`[data-p="round"][data-i="${b.dataset.i}"]`);
|
|
356
|
+
case 'xt': {
|
|
357
|
+
const t = b.dataset.k;
|
|
358
|
+
if (t === 'someday') return somedayP(r);
|
|
359
|
+
ui.xp = ui.xp === t ? null : t; if (t === 'edit') ui.ed = null;
|
|
360
|
+
return draw(ui.xp ? '.xpan input:not([disabled]),.xpan button' : `[data-k="${t}"]`);
|
|
361
|
+
}
|
|
362
|
+
case 'xpri': ui.ed.priority = b.dataset.v; return draw(`[data-p="xpri"][data-v="${b.dataset.v}"]`);
|
|
363
|
+
case 'xsave': return saveEdit(r);
|
|
364
|
+
case 'xwho': return commit({ keep: true, focus: `[data-p="xwho"][data-sid="${b.dataset.sid}"][data-v="${b.dataset.v}"]`, send: () => post('/api/pm-items/steps/who', { step_id: b.dataset.sid, who: b.dataset.v }),
|
|
365
|
+
say: (res) => (res.forced ? 'Set to Agent drafts: it sends something to a person.' : 'Step set to ' + (WHO.find((x) => x[0] === (res.who || b.dataset.v)) || [0, b.dataset.v])[1] + '.') });
|
|
366
|
+
case 'xsadd': {
|
|
367
|
+
const text = ui.sn.trim(); if (!text) { const f = body.querySelector('#xsIn'); if (f) f.focus(); return null; }
|
|
368
|
+
return commit({ keep: true, focus: '#xsIn', send: async () => { const res = await post('/api/pm-items/steps/add', { id, text }); if (res && res.ok === true) { ui.sn = ''; ui.addedForced = !!res.forced; } return res; },
|
|
369
|
+
say: () => (ui.addedForced ? 'Step added as Agent drafts: it sends something to a person.' : 'Step added.') });
|
|
370
|
+
}
|
|
371
|
+
case 'xdq': return deferP(r, b.dataset.v);
|
|
372
|
+
case 'xdgo': return ui.dd ? deferP(r, ui.dd) : null;
|
|
373
|
+
case 'xdclr': return deferP(r, null);
|
|
374
|
+
case 'ag-brief': {
|
|
375
|
+
const own = ((body.querySelector('#agAsk') || {}).value || '').trim();
|
|
376
|
+
return commit({ keep: true, send: () => post('/api/my-work/act', { action: 'brief', item: id, instruction: own || a.ask, ws: WS() }),
|
|
377
|
+
say: a.mine ? 'Handed to the agent. Its draft stays here in PMOS.' : `Handed to the agent. Nothing goes to ${a.where} until you post it.` });
|
|
378
|
+
}
|
|
379
|
+
case 'ag-stop': return commit({ keep: true, send: () => post('/api/my-work/stop', { item: id }), say: 'Stopped. Nothing was kept.' });
|
|
380
|
+
case 'ag-retry': return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'retry' }), say: 'The agent tries again.' });
|
|
381
|
+
case 'ag-edit': ui.editing = false; ui.body = null; ui.confirm = false; ui.dpick = 'post'; return draw('[data-p="dpick"][data-v="post"]');
|
|
382
|
+
case 'ag-save': return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'edit', body: ui.body }), say: a.mine ? 'Saved. The draft stays here.' : `Saved. Post sends your text to ${a.where}.` });
|
|
383
|
+
case 'ag-post': ui.confirm = true; return draw('[data-p="ag-go"]');
|
|
384
|
+
case 'dpick': ui.dpick = b.dataset.v; ui.confirm = false; if (ui.dpick === 'edit' && !ui.editing) { ui.editing = true; if (ui.body == null) ui.body = (a.draft && a.draft.body) || ''; } return draw(`[data-p="dpick"][data-v="${b.dataset.v}"]`);
|
|
385
|
+
case 'ag-keep': back(); toast(a.mine ? 'Kept. The draft stays on this item.' : 'Kept as a draft. Nothing was posted.'); return null;
|
|
386
|
+
case 'ag-no': ui.confirm = false; return draw('[data-p="ag-post"]');
|
|
387
|
+
case 'ag-go': {
|
|
388
|
+
const pb = { item: id, action: 'approve' };
|
|
389
|
+
if (ui.editing && ui.body != null && ui.body !== ((a.draft && a.draft.body) || '')) pb.body = ui.body;
|
|
390
|
+
return commit({ keep: true, send: () => post('/api/my-work/decide', pb), say: a.draft && a.draft.step ? 'Approved. A session with Chrome does exactly this step.' : 'Approved. A session posts exactly this text.' }).then((done) => { if (done) { ui.confirm = false; draw(); } return done; });
|
|
391
|
+
}
|
|
392
|
+
case 'ag-back': ui.back = !ui.back; return draw(ui.back ? '#agNote' : '[data-p="ag-back"]');
|
|
393
|
+
case 'ag-sendback': {
|
|
394
|
+
const note = ui.note.trim(); if (!note) { showErr('Say what to change first: type a note, then send it back.'); return null; }
|
|
395
|
+
return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'revise', note }), say: 'Sent back with your note. The agent drafts it again.' }).then((done) => { if (done) { ui.back = false; ui.note = ''; draw(); } return done; });
|
|
396
|
+
}
|
|
397
|
+
case 'ag-done': return doneP(r, { how: 'agent', say: 'Done. Nothing was posted.' });
|
|
398
|
+
default: return null;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async function focusPress(kind, key) {
|
|
402
|
+
const F = W.M.focus, f = F.suggestions.concat(F.accepted).find((x) => x.key === key);
|
|
403
|
+
const call = async (path, b) => { const res = await post(path, b); if (res && res.ok === true) await load(); else toast((res && res.error) || 'The press was not recorded.'); return res; };
|
|
404
|
+
if (kind === 'acc' && f) { const res = await call('/api/pm-items/focus/accept', fBody(f)); if (res && res.ok === true) toastUndo('In focus today.', () => post('/api/pm-items/focus/clear', { key }), load); return; }
|
|
405
|
+
if (kind === 'no') { const res = await call('/api/pm-items/focus/dismiss', { key }); if (res && res.ok === true) toastUndo('Not suggested again today.', () => post('/api/pm-items/focus/clear', { key }), load); return; }
|
|
406
|
+
if (kind === 'clr') { const was = F.accepted.find((x) => x.key === key); const res = await call('/api/pm-items/focus/clear', { key }); if (res && res.ok === true) { if (was) toastUndo('Cleared.', () => post('/api/pm-items/focus/accept', fBody(was)), load); else toast('Cleared.'); } }
|
|
407
|
+
}
|
|
408
|
+
async function onClick(e) {
|
|
409
|
+
if (Date.now() - sw.up < 120) return; // the click that ends a drag does nothing
|
|
410
|
+
const t = e.target.closest('button, a'); if (!t || t.disabled) return;
|
|
411
|
+
if (t.dataset.mw === 'back') { back(); return; }
|
|
412
|
+
if (t.dataset.tab) { W.tab = t.dataset.tab; W.msg = ''; draw(); return; }
|
|
413
|
+
if (t.dataset.xf) { W.view = 'fjobs'; W.ui = freshUi(); draw('[data-mw="back"]'); return; }
|
|
414
|
+
if (t.dataset.fx) {
|
|
415
|
+
if (t.dataset.fx !== 'jadd') { focusPress(t.dataset.fx, t.dataset.k); return; }
|
|
416
|
+
const line = (W.ui.job || '').trim(); t.disabled = true;
|
|
417
|
+
const res = await post('/api/pm-jobs/add', { line });
|
|
418
|
+
if (!res || res.ok !== true) { t.disabled = false; toast((res && res.error) || 'The job was not added.'); return; }
|
|
419
|
+
W.ui.job = ''; await load();
|
|
420
|
+
toastUndo('Job added.', () => post('/api/pm-jobs/delete', { id: res.job && res.job.id }), load);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (t.dataset.pp) {
|
|
424
|
+
const r = openR(), ag = r && r.dialog.agent, txt = (ag && ag.draft && (ag.draft.body || ag.draft.summary)) || '';
|
|
425
|
+
if (t.dataset.pp === 'all') { W.ui.all = !W.ui.all; draw(); return; }
|
|
426
|
+
if (t.dataset.pp === 'copy') { try { await navigator.clipboard.writeText(txt); toast('Draft copied.'); } catch { toast('Copy did not work here. Select the text and copy it.'); } return; }
|
|
427
|
+
const u = URL.createObjectURL(new Blob([txt], { type: 'text/plain;charset=utf-8' })); window.open(u, '_blank', 'noopener'); setTimeout(() => URL.revokeObjectURL(u), 60000); return;
|
|
428
|
+
}
|
|
429
|
+
if (t.dataset.p && openR()) { itemPress(t, openR()); return; }
|
|
430
|
+
if (t.dataset.open) { openItem(t.dataset.open); return; }
|
|
431
|
+
if (t.dataset.done) {
|
|
432
|
+
const res = await post('/api/pm-items/done', { id: t.dataset.done });
|
|
433
|
+
W.msg = res && res.ok ? 'Done.' : (res && res.error) || 'Not marked done.';
|
|
434
|
+
if (res && res.ok) toastUndo(SAID.done, reopen(t.dataset.done), load);
|
|
435
|
+
await load(); return;
|
|
436
|
+
}
|
|
437
|
+
if (t.dataset.x === 'add') {
|
|
438
|
+
const line = (body.querySelector('#hxLine').value || '').trim(); if (!line) return;
|
|
439
|
+
const res = await post('/api/pm-items/add', { line });
|
|
440
|
+
W.msg = res && res.ok ? 'Added.' : (res && res.error) || 'Not added.';
|
|
441
|
+
await load(); return;
|
|
442
|
+
}
|
|
443
|
+
const row = t.closest('.wrow'); if (row && t.classList.contains('wrh')) openItem(row.dataset.key);
|
|
444
|
+
}
|
|
445
|
+
const FIELD = { xeT: 'title', xeD: 'due', xeW: 'wo', xeJ: 'job' };
|
|
446
|
+
function onInput(e) {
|
|
447
|
+
const t = e.target, id = t.id, ui = W.ui;
|
|
448
|
+
if (id === 'wOn') { ui.wo = t.value; const b = body.querySelector('#wBtn'); if (b) b.disabled = !t.value.trim(); }
|
|
449
|
+
else if (ui.ed && FIELD[id]) ui.ed[FIELD[id]] = t.value;
|
|
450
|
+
else if (id === 'xsIn') ui.sn = t.value;
|
|
451
|
+
else if (id === 'xdD') { ui.dd = t.value; const g = body.querySelector('[data-p="xdgo"]'); if (g) { g.disabled = !t.value; g.textContent = 'Not before ' + (t.value ? dayLabel(t.value) : 'that day'); } }
|
|
452
|
+
else if (id === 'agAsk') ui.ask = t.value;
|
|
453
|
+
else if (id === 'agBody') ui.body = t.value;
|
|
454
|
+
else if (id === 'agNote') { ui.note = t.value; const g = body.querySelector('[data-p="ag-sendback"]'); if (g) g.disabled = !t.value.trim(); }
|
|
455
|
+
else if (id === 'xjIn') { ui.job = t.value; const g = body.querySelector('[data-fx="jadd"]'); if (g) g.disabled = !/when .+,\s*i want .+,\s*so .+/i.test(ui.job); }
|
|
456
|
+
}
|
|
457
|
+
/* keys on the rows of Your list: J and K move, the arrows do what the row names */
|
|
458
|
+
function onKey(e) {
|
|
459
|
+
const h = e.target.closest && e.target.closest('.mw-list .wrow:not(.sm) .wrh');
|
|
460
|
+
if (!h || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
|
|
461
|
+
const L = [...body.querySelectorAll('.mw-list .wrow:not(.sm) .wrh')], i = L.indexOf(h);
|
|
462
|
+
if (i < 0) return;
|
|
463
|
+
if (e.key === 'j' || e.key === 'k') { e.preventDefault(); const n = L[i + (e.key === 'j' ? 1 : -1)]; if (n) n.focus(); return; }
|
|
464
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') { e.preventDefault(); rowAct(rowOf(h.closest('.wrow').dataset.key), e.key === 'ArrowRight' ? 'r' : 'l', i); }
|
|
465
|
+
}
|
|
466
|
+
function rowAct(r, side, i) { const s = sideOf(r), a = s && s[side]; if (!a) return; W.refocus = { key: r.key, i }; a.fn(); }
|
|
467
|
+
/* the drag: locks to sideways after 8 px, hands a vertical move of more than 12 px back to the page, acts past 90 px */
|
|
468
|
+
const sw = { s: null, up: 0 }, TH = 90;
|
|
469
|
+
function onDown(e) {
|
|
470
|
+
const rw = e.target.closest('.mw-list .wrow:not(.sm)');
|
|
471
|
+
if (!rw || e.button > 0 || e.target.closest('[data-done]')) return;
|
|
472
|
+
const row = rowOf(rw.dataset.key); if (!row || !sideOf(row)) return;
|
|
473
|
+
sw.s = { r: rw, row, x: e.clientX, y: e.clientY, on: false, dx: 0, id: e.pointerId };
|
|
474
|
+
}
|
|
475
|
+
function onMove(e) {
|
|
476
|
+
const s = sw.s; if (!s || e.pointerId !== s.id) return;
|
|
477
|
+
const dx = e.clientX - s.x, dy = e.clientY - s.y, rm = RM();
|
|
478
|
+
if (!s.on) {
|
|
479
|
+
if (Math.abs(dy) > 12 && Math.abs(dy) > Math.abs(dx)) { sw.s = null; return; }
|
|
480
|
+
if (Math.abs(dx) < 8 || Math.abs(dy) > Math.abs(dx)) return;
|
|
481
|
+
s.on = true; try { s.r.setPointerCapture(e.pointerId); } catch { /* none */ }
|
|
482
|
+
s.w = s.r.closest('.wrw'); s.w.classList.add('xsw'); s.w.insertAdjacentHTML('afterbegin', '<div class="xrv" aria-hidden="true"></div>'); s.rv = s.w.querySelector('.xrv');
|
|
483
|
+
if (!rm) s.r.classList.add('xdr');
|
|
484
|
+
}
|
|
485
|
+
s.dx = dx;
|
|
486
|
+
const side = dx > 0 ? 'r' : 'l', a = sideOf(s.row)[side];
|
|
487
|
+
s.rv.className = 'xrv ' + side;
|
|
488
|
+
s.rv.innerHTML = a ? (a.ic ? SV(a.ic) : CHECK) + '<span>' + esc(a.label) + '</span>' : '';
|
|
489
|
+
s.rv.style.setProperty('--wl-d', rm ? (Math.abs(dx) >= TH && a ? 1 : 0) : a ? Math.min(1, Math.abs(dx) / TH) : 0);
|
|
490
|
+
if (!rm) s.r.style.setProperty('--wl-dx', dx * 0.55 + 'px');
|
|
491
|
+
}
|
|
492
|
+
function onEnd(e) {
|
|
493
|
+
const s = sw.s; if (!s) return; sw.s = null;
|
|
494
|
+
if (!s.on) return;
|
|
495
|
+
sw.up = Date.now();
|
|
496
|
+
s.r.classList.remove('xdr'); s.r.style.removeProperty('--wl-dx'); if (s.rv) s.rv.remove(); if (s.w) s.w.classList.remove('xsw');
|
|
497
|
+
if (e.type !== 'pointercancel' && Math.abs(s.dx) > TH) rowAct(s.row, s.dx > 0 ? 'r' : 'l', [...body.querySelectorAll('.mw-list .wrow:not(.sm)')].indexOf(s.r));
|
|
498
|
+
}
|
|
499
|
+
/* Escape closes the fields sheet first, then the item or Focus view (back to the list); the Viewer closes on the next Escape */
|
|
500
|
+
function onEsc(e) {
|
|
501
|
+
if (e.key !== 'Escape' || !body || !body.isConnected || !W.view) return;
|
|
502
|
+
e.preventDefault(); e.stopImmediatePropagation();
|
|
503
|
+
if (W.view === 'item' && W.ui.sheet) { W.ui.sheet = false; W.ui.xp = null; draw('#iTog'); return; }
|
|
504
|
+
back();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
body = vwOpen({ id: 'more:work', kind: 'My work', title: 'Your list', icon: 'list', render: (b) => { b.classList.add('hx'); }, onClose: () => { removeEventListener('keydown', onEsc, true); clearInterval(timer); } });
|
|
508
|
+
// delegated, as the other Home cards do: every control in the card is a real <button>; the drag repeats what the arrow keys do
|
|
509
|
+
body.onclick = onClick;
|
|
510
|
+
body.oninput = onInput;
|
|
511
|
+
body.onchange = (e) => { if (W.ui.ed && e.target.id === 'xeJ') W.ui.ed.job = e.target.value; };
|
|
512
|
+
body.onkeydown = onKey;
|
|
513
|
+
body.onpointerdown = onDown; body.onpointermove = onMove; body.onpointerup = onEnd; body.onpointercancel = onEnd;
|
|
514
|
+
addEventListener('keydown', onEsc, true);
|
|
515
|
+
const timer = setInterval(() => { if (!body.isConnected) { clearInterval(timer); return; } if (W.M && W.M.agents && W.M.agents.counts.running > 0 && !document.hidden) load(); }, 15000); // an agent's state changes without a press
|
|
516
|
+
draw();
|
|
517
|
+
load();
|
|
518
|
+
return body;
|
|
519
|
+
}
|