create-pmos 0.397.0 → 0.399.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -25
- package/payload/KIT-VERSION +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +105 -52
- package/workspace/briefing-premium-board-test.js +284 -128
- package/workspace/briefing-premium-calendar-2-test.js +135 -198
- package/workspace/briefing-premium-calendar-3-test.js +143 -418
- package/workspace/briefing-premium-calendar-test.js +85 -196
- package/workspace/briefing-premium-doc-edit-test.js +99 -83
- package/workspace/briefing-premium-initiative-test.js +175 -290
- package/workspace/briefing-premium-insights-test.js +414 -219
- package/workspace/briefing-premium-metrics-test.js +55 -97
- package/workspace/briefing-premium-products-test.js +44 -28
- package/workspace/briefing-premium-sources-test.js +70 -49
- package/workspace/briefing-premium-test.js +155 -648
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +24 -0
- package/workspace/ev-everywhere-test.js +210 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +187 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +68 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-grill.js +63 -0
- package/workspace/lib/board-premium.js +121 -24
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/initiative-layout.js +77 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +64 -15
- package/workspace/lib/insights-records.js +115 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/meeting-points.js +52 -0
- package/workspace/lib/news-for-you.js +88 -0
- package/workspace/lib/notes-series.js +29 -6
- package/workspace/lib/report-confirm.js +48 -0
- package/workspace/lib/route-modules.js +12 -0
- package/workspace/lib/routes-board-docs.js +46 -0
- package/workspace/lib/routes-board-grill.js +90 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-home-review.js +108 -0
- package/workspace/lib/routes-initiative-layout.js +57 -0
- package/workspace/lib/routes-insights-premium.js +16 -4
- package/workspace/lib/routes-insights-records.js +133 -0
- package/workspace/lib/routes-meeting-points.js +37 -0
- package/workspace/lib/routes-news.js +57 -0
- package/workspace/lib/routes-notes.js +3 -1
- package/workspace/lib/routes-report-confirm.js +31 -0
- package/workspace/lib/routes-search.js +38 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/search-index.js +176 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/viewer-meeting.js +205 -0
- package/workspace/lib/viewer-report.js +89 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +128 -82
- package/workspace/premium-briefing-depth-test.js +104 -90
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +37 -37
- package/workspace/premium-chat-context-test.js +19 -18
- package/workspace/premium-chat-goal-view-test.js +23 -23
- package/workspace/premium-chat-notes-test.js +26 -31
- package/workspace/premium-chat-report-tab-test.js +46 -28
- package/workspace/premium-chat-term-test.js +16 -16
- package/workspace/premium-chat-viewer-test.js +60 -59
- package/workspace/premium-core-doc-issue-test.js +52 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +10 -3
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +152 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -33
- package/workspace/premium-vw-cal-test.js +97 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +17 -10
- package/workspace/premium-vw-item-test.js +50 -49
- package/workspace/premium-vw-jira-test.js +53 -27
- package/workspace/premium-vw-meet-test.js +115 -187
- package/workspace/premium-vw-notes-test.js +88 -109
- package/workspace/premium-vw-rec-test.js +71 -194
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +61 -53
- package/workspace/public/pm/bd-acts.js +383 -0
- package/workspace/public/pm/bd-asks.js +261 -0
- package/workspace/public/pm/bd-pop.js +59 -0
- package/workspace/public/pm/bd-span.js +222 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- package/workspace/public/pm/bd-views.js +169 -0
- package/workspace/public/pm/c3-doc-sheet.js +1 -1
- package/workspace/public/pm/c3-md.js +3 -395
- package/workspace/public/pm/c3-phone-detail.js +1 -1
- package/workspace/public/pm/c3-phone-model.js +3 -68
- package/workspace/public/pm/chat-term.js +3 -3
- package/workspace/public/pm/cozy-board.css +798 -230
- package/workspace/public/pm/cozy-ev.css +228 -0
- package/workspace/public/pm/cozy-evmodel.js +106 -0
- package/workspace/public/pm/cozy-evui.js +47 -0
- package/workspace/public/pm/cozy-home.css +570 -142
- package/workspace/public/pm/cozy-home.js +5 -3
- package/workspace/public/pm/cozy-insights.css +437 -170
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +104 -29
- package/workspace/public/pm/cozy-news.js +140 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-search.js +203 -0
- package/workspace/public/pm/cozy-settings.js +198 -0
- package/workspace/public/pm/cozy-sources.js +89 -0
- package/workspace/public/pm/cozy-today.css +217 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +145 -0
- package/workspace/public/pm/cozy-vw-mtg.css +350 -0
- package/workspace/public/pm/cozy-vw-rp.css +152 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +83 -1
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +1179 -0
- package/workspace/public/pm/home-around.js +413 -0
- package/workspace/public/pm/home-chat.js +512 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-dictate.js +54 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-ini-model.js +190 -0
- package/workspace/public/pm/home-ini.css +171 -0
- package/workspace/public/pm/home-ini.js +456 -0
- package/workspace/public/pm/home-list.js +276 -0
- package/workspace/public/pm/home-more.js +132 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-review.js +104 -0
- package/workspace/public/pm/home-task.js +67 -0
- package/workspace/public/pm/home-today.js +144 -0
- package/workspace/public/pm/home-work.js +547 -0
- package/workspace/public/pm/phone-moment.js +69 -0
- package/workspace/public/pm/pm-work-view.js +1 -1
- package/workspace/public/pm/premium-attach.js +4 -0
- package/workspace/public/pm/premium-board.js +548 -395
- package/workspace/public/pm/premium-chart-tab.js +109 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +23 -21
- package/workspace/public/pm/premium-insights.js +1102 -581
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-mtg-present.js +138 -0
- package/workspace/public/pm/premium-mtg-replay.js +142 -0
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +669 -476
- package/workspace/public/pm/premium-report-tab.js +116 -67
- package/workspace/public/pm/premium-shell.js +76 -123
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +277 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +958 -0
- package/workspace/public/pm/premium-vw-notes.js +116 -68
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -218
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/rp-parts.js +269 -0
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +29 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +26 -64
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +18 -107
- package/workspace/r/m1.png +0 -0
- package/workspace/r/m2.png +0 -0
- package/workspace/r/m3.png +0 -0
- package/workspace/r/nl.png +0 -0
- package/workspace/server.js +18 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/initiative-layout.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
- package/workspace/test-lists/premium-uncovered-reports.json +9 -0
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/test-lists/uf-everywhere.json +15 -0
- package/workspace/test-lists/uf-home.json +9 -0
- package/workspace/test-lists/uncovered-board.json +9 -0
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/* pm/bd-asks.js — new asks, New initiative and its first questions (initiative premium-uncovered-features, Board: BdAsks, BdNew, BdGrill, BdPhone).
|
|
2
|
+
* New asks (BdAsks) a popover (a bottom sheet on a phone) under the chip: each ask with who sent it and where, the product it is for and why,
|
|
3
|
+
* the kind PMOS suggests, its anchor, the initiative it is close to and an earlier rejection. Accept to Triage
|
|
4
|
+
* POST /api/boards/asks/accept (Undo archives what it made); Add to <initiative> and Decline POST /api/boards/asks/decline
|
|
5
|
+
* with the reason. An ask the record gives two products for sits under "Not sure which product".
|
|
6
|
+
* New initiative (BdNew) the side panel: name, why, material (links and files), no lane field (PMOS leans on the intake draft and names the
|
|
7
|
+
* kind in Triage), what it counts toward, the product. A name close to an earlier rejection or to an open initiative
|
|
8
|
+
* says so. Create: POST /api/boards/asks/add then /asks/accept (it starts in the first stage), then POST /api/board-grill/start
|
|
9
|
+
* and /file for the material.
|
|
10
|
+
* First questions (BdGrill) the same panel, right after: what PMOS took from the Why and the material, then only the open questions, one at a
|
|
11
|
+
* time (POST /api/board-grill/answer). Later (POST /api/board-grill/later) keeps them as the initiative's next step.
|
|
12
|
+
* Nothing is sent to anyone: a decline keeps its reason in the board ledger. */
|
|
13
|
+
import { pmPost } from './http.js';
|
|
14
|
+
import { $, $$, esc } from './premium-shell.js';
|
|
15
|
+
import * as Pop from './bd-pop.js';
|
|
16
|
+
import { avatar } from './bd-views.js';
|
|
17
|
+
|
|
18
|
+
let A = null; // the page: { M(), load(), say(msg, undo?), panel(html, from, cls), close(), rowOf(key), openIni(r), openDoc(path), anchors() }
|
|
19
|
+
export function init(api) { A = api; }
|
|
20
|
+
const M = () => A.M();
|
|
21
|
+
const post = (p, body) => pmPost(p, { ws: M().board.ws, ...body });
|
|
22
|
+
const errOf = (r) => (r && r.error) || 'Nothing was recorded. The server did not say why.';
|
|
23
|
+
const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
|
|
24
|
+
const I = { x: 'M6 6l12 12M18 6L6 18', link: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1', file: 'M7 3h7l5 5v13H7zM14 3v5h5', up: 'M12 16V4M7 9l5-5 5 5M5 20h14', info: 'M12 8v5M12 16h.01M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18', chev: 'M7 10l5 5 5-5', next: 'M9 6l6 6-6 6' };
|
|
25
|
+
const cap = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : '');
|
|
26
|
+
const krShort = (a) => { const s = String(a || ''); if (!s) return ''; if (/^health:/.test(s)) return 'Health budget'; const m = /:o(\d+):kr(\d+)/i.exec(s); return m ? 'KR ' + m[1] + '.' + m[2] : s; };
|
|
27
|
+
const WHY_NOT = ['Out of scope', 'Already planned', 'Not now', 'Other'];
|
|
28
|
+
|
|
29
|
+
/* ── New asks (BdAsks, BdPhone) ─────────────────────────────────────────────────────────────────────────────────── */
|
|
30
|
+
let declining = null, expanded = null, picked = {};
|
|
31
|
+
const asksOf = () => ((M().asks && M().asks.rows) || []);
|
|
32
|
+
function askCard(a, i, phone) {
|
|
33
|
+
if (phone && i > 0 && expanded !== a.id) return `<button type="button" class="bd-acard row" data-askopen="${esc(a.id)}">${avatar(a.by || a.source)}<span class="tx"><b>${esc(a.by || a.source || 'Someone')}</b> · “${esc(a.line)}”</span>${SV(I.next)}</button>`;
|
|
34
|
+
const who = `<div class="bd-awho">${avatar(a.by || a.source)}<b>${esc(a.by || a.source || 'Someone')}</b><span class="bd-amut">${esc([a.by ? a.source : '', a.at].filter(Boolean).map((x) => '· ' + x).join(' '))}</span></div>`;
|
|
35
|
+
const prod = picked[a.id] || a.product;
|
|
36
|
+
const product = prod && prod.name ? `<div class="bd-aprod"><span class="bd-chip sm"><b>${esc(prod.name)}</b></span><span class="bd-amut">Why: ${esc(prod.why || '')}</span></div>` : '';
|
|
37
|
+
const pills = [a.draft.lane ? `<span class="bd-pill">Suggest: ${esc(cap(a.draft.lane))}</span>` : '', a.draft.anchor ? `<span class="bd-pill">${esc(krShort(a.draft.anchor))}</span>` : '', a.close ? `<span class="bd-pill w">Close to: ${esc(a.close.title)}</span>` : ''].join('');
|
|
38
|
+
const prior = (a.prior || []).length ? `<p class="bd-warn sm">Close to something you declined: “${esc(a.prior[0].title)}”.</p>` : '';
|
|
39
|
+
if (declining === a.id) {
|
|
40
|
+
return `<div class="bd-acard" data-ask="${esc(a.id)}">${who}<p class="bd-aq">“${esc(a.line)}”</p>${product}<p class="bd-lbl">Why not</p><div class="bd-chips" role="radiogroup" aria-label="Why not">${WHY_NOT.map((w, j) => `<button type="button" class="bd-chip${j === 0 ? ' on' : ''}" role="radio" aria-checked="${j === 0}" data-whynot="${esc(w)}">${esc(w)}</button>`).join('')}</div>`
|
|
41
|
+
+ `<input class="bd-inp sm" name="why" maxlength="400" placeholder="Say a little more, optional" aria-label="Why not, in your words"><p class="bd-amsg" role="status"></p>`
|
|
42
|
+
+ `<div class="bd-arow"><button type="button" class="bd-btn sm solid" data-askact="decline-go" data-id="${esc(a.id)}">Decline</button><button type="button" class="bd-btn sm ghost" data-askact="back">Back</button><span class="bd-amut bd-push">The reason is kept with the ask</span></div></div>`;
|
|
43
|
+
}
|
|
44
|
+
const btns = phone
|
|
45
|
+
? `<button type="button" class="bd-btn solid wide" data-askact="accept" data-id="${esc(a.id)}">Accept to ${esc(firstStage())}</button><div class="bd-arow two">${a.close ? `<button type="button" class="bd-btn" data-askact="add" data-id="${esc(a.id)}">Add to existing</button>` : ''}<button type="button" class="bd-btn ghost" data-askact="decline" data-id="${esc(a.id)}">Decline</button></div>`
|
|
46
|
+
: `<div class="bd-arow"><button type="button" class="bd-btn sm solid" data-askact="accept" data-id="${esc(a.id)}">Accept to ${esc(firstStage())}</button>${a.close ? `<button type="button" class="bd-btn sm" data-askact="add" data-id="${esc(a.id)}">Add to ${esc(a.close.title)}</button>` : ''}<button type="button" class="bd-btn sm ghost" data-askact="decline" data-id="${esc(a.id)}">Decline</button></div>`;
|
|
47
|
+
return `<div class="bd-acard" data-ask="${esc(a.id)}">${who}<p class="bd-aq">“${esc(a.line)}”</p>${product}${pills ? `<div class="bd-pills">${pills}</div>` : ''}${prior}${btns}<p class="bd-amsg" role="status"></p></div>`;
|
|
48
|
+
}
|
|
49
|
+
const firstStage = () => (M().board.stages || [])[0] || 'Triage';
|
|
50
|
+
function unsureHtml(L) {
|
|
51
|
+
if (!L.length) return '';
|
|
52
|
+
return `<div class="bd-unsure"><p class="bd-lbl">Not sure which product · ${L.length}</p>${L.map((a) => `<div class="bd-un1"><p class="sm">${esc(a.by || 'Someone')}${a.source ? ' by ' + esc(a.source.toLowerCase()) : ''}: “${esc(a.line)}”</p><p class="bd-amut">Could be ${a.products.map((p) => esc(p.name) + (p.why ? ' (' + esc(p.why) + ')' : '')).join(' or ')}.</p><div class="bd-chips">${a.products.map((p) => `<button type="button" class="bd-chip" data-pickprod="${esc(a.id)}" data-prod="${esc(p.id)}">${esc(p.name)}</button>`).join('')}</div></div>`).join('')}<p class="bd-amut bd-hr">PMOS picks the product from where the ask came from and what it talks about. When both point the same way, it shows the product with its reason. When they disagree, it asks you.</p></div>`;
|
|
53
|
+
}
|
|
54
|
+
function asksHtml() {
|
|
55
|
+
const L = asksOf(), phone = matchMedia('(max-width: 720px)').matches;
|
|
56
|
+
if (M().board.self) return '<p class="bd-h3">New asks</p><p class="bd-amut">PMOS-self has no ask source. New work starts at the pmos-router skill.</p>';
|
|
57
|
+
if (M().asks == null || M().asks.missing) return '<p class="bd-h3">New asks</p><p class="bd-amut">The new asks could not be read, so none is shown.</p>';
|
|
58
|
+
const sure = L.filter((a) => !(a.products || []).length || picked[a.id]), unsure = L.filter((a) => (a.products || []).length && !picked[a.id]);
|
|
59
|
+
const src = [...new Set(L.map((a) => a.source).filter(Boolean))];
|
|
60
|
+
const head = `<div class="bd-phead"><p class="bd-h3" id="hAsks">${L.length} new ${L.length === 1 ? 'ask' : 'asks'}</p>${src.length ? `<span class="bd-amut">For ${esc(M().board.name || 'this board')} · from ${esc(src.slice(0, 3).join(', ').toLowerCase())}</span>` : ''}</div>`;
|
|
61
|
+
if (!L.length) return head + '<p class="bd-amut">No new ask waits for triage.</p>';
|
|
62
|
+
return head + `<div class="bd-acards">${sure.map((a, i) => askCard(a, i, phone)).join('')}</div>` + unsureHtml(unsure);
|
|
63
|
+
}
|
|
64
|
+
export function openAsks(btn) {
|
|
65
|
+
declining = null; expanded = null;
|
|
66
|
+
Pop.open(asksHtml(), btn, { label: 'New asks', width: 520, cls: 'bd-asks' });
|
|
67
|
+
}
|
|
68
|
+
const redrawAsks = () => Pop.redraw(asksHtml());
|
|
69
|
+
async function acceptAsk(a, btn) {
|
|
70
|
+
const d = a.draft || {};
|
|
71
|
+
if (!d.anchor) { Pop.close(false); openNew(null, a); return; } // no anchor yet: the New initiative panel asks for one
|
|
72
|
+
btn.disabled = true;
|
|
73
|
+
const r = await post('/api/boards/asks/accept', { board: M().board.id, ask: a.id, title: d.title, lane: d.lane || 'feature', anchor: d.anchor, intent: a.line.slice(0, 400) }).catch(() => null);
|
|
74
|
+
if (!r || !r.ok) { btn.disabled = false; const m = btn.closest('.bd-acard').querySelector('.bd-amsg'); if (m) m.textContent = errOf(r); return; }
|
|
75
|
+
Pop.close(false);
|
|
76
|
+
const id = r.initiative && r.initiative.id;
|
|
77
|
+
A.say('Accepted to ' + (r.stage || firstStage()) + ' · ' + d.title, id ? async () => { const u = await post('/api/boards/archive', { board: M().board.id, id, archived: true, reason: 'Accepted by mistake: undone' }).catch(() => null); A.say(u && u.ok ? d.title + ' is undone. It is archived, and nothing else changed.' : errOf(u)); await A.load(); } : null);
|
|
78
|
+
await A.load();
|
|
79
|
+
}
|
|
80
|
+
document.addEventListener('click', async (e) => {
|
|
81
|
+
if (!A || !Pop.isOpen() || !Pop.el().contains(e.target)) return;
|
|
82
|
+
const op = e.target.closest('[data-askopen]'); if (op) { expanded = op.dataset.askopen; redrawAsks(); return; }
|
|
83
|
+
const wn = e.target.closest('[data-whynot]'); if (wn) { $$('[data-whynot]', Pop.el()).forEach((b) => { const on = b === wn; b.classList.toggle('on', on); b.setAttribute('aria-checked', String(on)); }); return; }
|
|
84
|
+
const pp = e.target.closest('[data-pickprod]');
|
|
85
|
+
if (pp) {
|
|
86
|
+
const a = asksOf().find((x) => x.id === pp.dataset.pickprod), p = a && a.products.find((x) => x.id === pp.dataset.prod); if (!p) return;
|
|
87
|
+
if (p.name === M().board.name || p.id === M().board.id) { picked[a.id] = { name: p.name, why: 'you chose it' }; redrawAsks(); }
|
|
88
|
+
else A.say('Open the ' + p.name + ' Board to accept it there. This Board holds only ' + (M().board.name || 'its own') + ' work.');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const b = e.target.closest('[data-askact]'); if (!b) return;
|
|
92
|
+
const k = b.dataset.askact, a = asksOf().find((x) => x.id === b.dataset.id);
|
|
93
|
+
if (k === 'back') { declining = null; redrawAsks(); return; }
|
|
94
|
+
if (!a) return;
|
|
95
|
+
if (k === 'decline') { declining = a.id; redrawAsks(); const f = Pop.el().querySelector('[data-whynot].on'); if (f) f.focus(); return; }
|
|
96
|
+
if (k === 'accept') { acceptAsk(a, b); return; }
|
|
97
|
+
const card = b.closest('.bd-acard'), m = card && card.querySelector('.bd-amsg');
|
|
98
|
+
let why;
|
|
99
|
+
if (k === 'add') why = 'Added to ' + a.close.title + ' (' + a.close.id + ')';
|
|
100
|
+
else { const c = Pop.el().querySelector('[data-whynot].on'), t = (card.querySelector('input[name="why"]') || {}).value || ''; why = ((c && c.dataset.whynot) || 'Other') + (t.trim() ? ': ' + t.trim().replace(/\s+/g, ' ') : ''); }
|
|
101
|
+
b.disabled = true;
|
|
102
|
+
const r = await post('/api/boards/asks/decline', { board: M().board.id, ask: a.id, why }).catch(() => null);
|
|
103
|
+
if (!r || !r.ok) { b.disabled = false; if (m) m.textContent = errOf(r); return; }
|
|
104
|
+
declining = null; Pop.close(false);
|
|
105
|
+
A.say(k === 'add' ? 'Added to ' + a.close.title + '. The ask is kept with the reason.' : 'Ask declined. The reason is kept in the board ledger.');
|
|
106
|
+
await A.load();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
/* ── New initiative (BdNew) ────────────────────────────────────────────────────────────────────────────────────── */
|
|
110
|
+
let N = null; // the form: { ask, links: [{url,label}], files: [File], lean, prior, ack }
|
|
111
|
+
function materialChips() {
|
|
112
|
+
return N.links.map((k, i) => `<span class="bd-chip sm">${SV(I.link)}${esc(k.label)}<button type="button" class="bd-x0" data-rmlink="${i}" aria-label="Remove ${esc(k.label)}">${SV(I.x)}</button></span>`).join('')
|
|
113
|
+
+ N.files.map((f, i) => `<span class="bd-chip sm">${SV(I.file)}${esc(f.name)}<button type="button" class="bd-x0" data-rmfile="${i}" aria-label="Remove ${esc(f.name)}">${SV(I.x)}</button></span>`).join('');
|
|
114
|
+
}
|
|
115
|
+
function kindBox() {
|
|
116
|
+
const lean = N.lean ? cap(N.lean) : null;
|
|
117
|
+
return `<b>Kind of work · PMOS works it out</b><span>No need to choose now. It starts in ${esc(firstStage())}, and PMOS names the kind (feature, discovery, chore and so on) once the BRD or the first research makes it clear. It tells you in New for you, and you can change it.</span><span class="bd-amut">Now: ${lean ? 'not sure yet · leaning ' + esc(lean) + ', from the words of the name' : 'not sure yet'}</span>`;
|
|
118
|
+
}
|
|
119
|
+
function hintsHtml() {
|
|
120
|
+
const p = N.prior && N.prior[0] && !N.ack ? `<div class="bd-warn"><b>Close to something you declined</b><span>“${esc(N.prior[0].title)}” was set aside in ${esc(N.prior[0].file)}.</span><div class="bd-arow"><button type="button" class="bd-btn sm" data-newact="seewhy">See why</button><button type="button" class="bd-btn sm ghost" data-newact="ack">It is different</button></div></div>` : '';
|
|
121
|
+
const c = N.close ? `<div class="bd-need">${SV(I.info)}<span>Also close to <button type="button" class="bd-dlink" data-newact="close">${esc(N.close.title)}</button> in ${esc(N.close.stage || 'its stage')}. Add to it instead?</span></div>` : '';
|
|
122
|
+
return p + c;
|
|
123
|
+
}
|
|
124
|
+
/** The open initiative a new name is close to (the model's rule for asks, run on the page as the PM types). */
|
|
125
|
+
function closeOf(text) {
|
|
126
|
+
const STOP = new Set(['the', 'and', 'for', 'with', 'from', 'that', 'this', 'who', 'what', 'when', 'can', 'are', 'was', 'not', 'our', 'your', 'their', 'they', 'into', 'each', 'all', 'any', 'has', 'have', 'its']);
|
|
127
|
+
const sig = (s) => new Set(String(s || '').toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length >= 3 && !STOP.has(w)));
|
|
128
|
+
const want = sig(text); let best = null;
|
|
129
|
+
for (const r of M().initiatives.list.rows) { const have = sig(r.title), n = [...have].filter((w) => want.has(w)).length; if (have.size && (n >= 2 || (n >= 1 && n / have.size >= 0.5)) && (!best || n > best.n)) best = { n, r }; }
|
|
130
|
+
return best ? { key: best.r.key, title: best.r.title, stage: (best.r.track && best.r.track.label) || best.r.stage } : null;
|
|
131
|
+
}
|
|
132
|
+
export async function openNew(from, ask) {
|
|
133
|
+
const d = ask ? ask.draft || {} : {};
|
|
134
|
+
N = { ask: ask || null, links: [], files: [], lean: d.lane || null, prior: ask ? ask.prior || [] : [], ack: false, close: null };
|
|
135
|
+
const body = `<form class="bd-form bd-new" data-form="new2"${ask ? ` data-ask="${esc(ask.id)}"` : ''} novalidate>`
|
|
136
|
+
+ (ask ? `<p class="bd-quote">“${esc(ask.line)}”</p>` : '')
|
|
137
|
+
+ `<label class="bd-field">Name<input class="bd-inp" name="title" maxlength="120" value="${esc(d.title || '')}" placeholder="For example: Partner SSO audit trail" autocomplete="off"></label>`
|
|
138
|
+
+ `<label class="bd-field">Why<textarea class="bd-inp ta" name="why" rows="3" maxlength="400" placeholder="Who asks for it, and what it changes for them">${esc(ask ? ask.line : '')}</textarea></label>`
|
|
139
|
+
+ `<div class="bd-field"><span class="bd-flbl">Material · links or files</span><div class="bd-drop" id="nwDrop"><span class="bd-mchips" id="nwMat"></span><span class="bd-sp"></span><button type="button" class="bd-ib sm" data-newact="link" aria-label="Paste a link" title="Paste a link">${SV(I.link)}</button><button type="button" class="bd-ib sm" data-newact="file" aria-label="Upload a file" title="Upload a file">${SV(I.up)}</button><input type="file" id="nwFile" multiple hidden></div>`
|
|
140
|
+
+ `<div class="bd-linkin" id="nwLink" hidden><input class="bd-inp sm" name="link" maxlength="600" placeholder="https://" aria-label="A link"><button type="button" class="bd-btn sm" data-newact="addlink">Add</button></div><p class="bd-amut">Drop files here. PMOS reads them before it asks you anything.</p></div>`
|
|
141
|
+
+ `<div class="bd-box sm" id="nwKind">${kindBox()}</div>`
|
|
142
|
+
+ `<label class="bd-field">Counts toward<span id="anW"><select class="bd-inp" name="anchor" disabled><option>Reading the goals</option></select></span><span class="bd-amut">A goal, or a health budget for upkeep work.</span></label>`
|
|
143
|
+
+ `<div class="bd-field"><span class="bd-flbl">Product</span><span class="bd-inp ro">${esc(M().board.name || 'This board')}</span></div>`
|
|
144
|
+
+ `<div id="nwHints">${hintsHtml()}</div><p class="bd-amsg" id="formM" role="status"></p>`
|
|
145
|
+
+ `<div class="bd-arow bd-pfoot"><button type="submit" class="bd-btn solid">${ask ? 'Accept and start ' : 'Create and start '}${esc(firstStage())}</button><span class="bd-amut">PMOS asks a few questions next</span></div></form>`;
|
|
146
|
+
A.panel(`<div class="pk-h"><div class="pk-ht"><h2 id="pkTitle">${ask ? 'Accept ask' : 'New initiative'}</h2></div><div class="pk-tools"><button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(I.x)}</button></div></div><div class="pk-b bd-pl">${body}</div>`, from, 'pk-new');
|
|
147
|
+
const L = await A.anchors(), w = $('#anW'); if (!w) return;
|
|
148
|
+
w.innerHTML = L && L.length ? `<select class="bd-inp" name="anchor"><option value="">Choose a goal or a health budget</option>${L.map((x) => `<option value="${esc(x.value)}"${x.value === d.anchor ? ' selected' : ''}>${esc(x.label || x.value)}</option>`).join('')}</select>`
|
|
149
|
+
: `<input class="bd-inp" name="anchor" maxlength="120" value="${esc(d.anchor || '')}" placeholder="A KR id or health:<budget>">`;
|
|
150
|
+
if (d.title) lean(d.title);
|
|
151
|
+
}
|
|
152
|
+
let leanT = null;
|
|
153
|
+
/** The intake draft of the name (POST /api/intake/draft): the kind it leans to and an earlier rejection it is close to. Drafts only. */
|
|
154
|
+
function lean(text) {
|
|
155
|
+
clearTimeout(leanT);
|
|
156
|
+
leanT = setTimeout(async () => {
|
|
157
|
+
if (!N) return;
|
|
158
|
+
N.close = text.trim().length > 3 ? closeOf(text) : null;
|
|
159
|
+
const r = text.trim().length > 3 ? await pmPost('/api/intake/draft', { line: text.trim() }).catch(() => null) : null;
|
|
160
|
+
if (!N) return;
|
|
161
|
+
if (r && r.ok && r.draft) { N.lean = r.draft.lane || N.lean; if (!N.ask) N.prior = r.draft.prior_rejections || []; }
|
|
162
|
+
const k = $('#nwKind'), h = $('#nwHints'); if (k) k.innerHTML = kindBox(); if (h) h.innerHTML = hintsHtml();
|
|
163
|
+
}, 350);
|
|
164
|
+
}
|
|
165
|
+
const drawMat = () => { const m = $('#nwMat'); if (m) m.innerHTML = materialChips(); };
|
|
166
|
+
function addFiles(list) { for (const f of list || []) if (N && N.files.length < 10 && !N.files.some((x) => x.name === f.name)) N.files.push(f); drawMat(); }
|
|
167
|
+
document.addEventListener('input', (e) => { if (N && e.target.matches('form[data-form="new2"] input[name="title"]')) lean(e.target.value); });
|
|
168
|
+
document.addEventListener('change', (e) => { if (N && e.target.id === 'nwFile') { addFiles(e.target.files); e.target.value = ''; } });
|
|
169
|
+
document.addEventListener('dragover', (e) => { const d = e.target.closest && e.target.closest('#nwDrop'); if (d) { e.preventDefault(); d.classList.add('on'); } });
|
|
170
|
+
document.addEventListener('dragleave', (e) => { const d = e.target.closest && e.target.closest('#nwDrop'); if (d) d.classList.remove('on'); });
|
|
171
|
+
document.addEventListener('drop', (e) => { const d = e.target.closest && e.target.closest('#nwDrop'); if (!d || !N) return; e.preventDefault(); d.classList.remove('on'); addFiles(e.dataTransfer && e.dataTransfer.files); });
|
|
172
|
+
document.addEventListener('click', (e) => {
|
|
173
|
+
if (!N) return;
|
|
174
|
+
const rl = e.target.closest('[data-rmlink]'); if (rl) { N.links.splice(+rl.dataset.rmlink, 1); drawMat(); return; }
|
|
175
|
+
const rf = e.target.closest('[data-rmfile]'); if (rf) { N.files.splice(+rf.dataset.rmfile, 1); drawMat(); return; }
|
|
176
|
+
const b = e.target.closest('[data-newact]'); if (!b) return;
|
|
177
|
+
const k = b.dataset.newact;
|
|
178
|
+
if (k === 'file') $('#nwFile').click();
|
|
179
|
+
else if (k === 'link') { const l = $('#nwLink'); l.hidden = !l.hidden; if (!l.hidden) l.querySelector('input').focus(); }
|
|
180
|
+
else if (k === 'addlink') {
|
|
181
|
+
const i = $('#nwLink input'), u = i.value.trim();
|
|
182
|
+
if (!/^https?:\/\/\S{3,}$/i.test(u)) { $('#formM').textContent = 'A link must start with http or https.'; return; }
|
|
183
|
+
let label = u; try { const x = new URL(u); label = x.hostname.replace(/^www\./, '') + (x.pathname.length > 1 ? x.pathname.replace(/\/$/, '').split('/').slice(-1)[0].slice(0, 30).replace(/^/, ' · ') : ''); } catch { /* keep it */ }
|
|
184
|
+
N.links.push({ url: u, label }); i.value = ''; $('#nwLink').hidden = true; $('#formM').textContent = ''; drawMat();
|
|
185
|
+
} else if (k === 'ack') { N.ack = true; $('#nwHints').innerHTML = hintsHtml(); }
|
|
186
|
+
else if (k === 'seewhy' && N.prior[0]) A.openDoc(N.prior[0].file);
|
|
187
|
+
else if (k === 'close' && N.close) { const r = A.rowOf(N.close.key); if (r) A.openIni(r); }
|
|
188
|
+
});
|
|
189
|
+
document.addEventListener('keydown', (e) => { if (N && e.key === 'Enter' && e.target.matches('#nwLink input')) { e.preventDefault(); const b = document.querySelector('[data-newact="addlink"]'); if (b) b.click(); } });
|
|
190
|
+
const b64 = (file) => new Promise((res) => { const fr = new FileReader(); fr.onload = () => res(String(fr.result).split(',')[1] || ''); fr.onerror = () => res(''); fr.readAsDataURL(file); });
|
|
191
|
+
document.addEventListener('submit', async (e) => {
|
|
192
|
+
const f = e.target.closest('form[data-form="new2"]'); if (!f || !A || !N) return;
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
const m = $('#formM'), go = f.querySelector('[type="submit"]'), val = (n) => (f.elements[n] ? String(f.elements[n].value || '').trim() : '');
|
|
195
|
+
const title = val('title'), why = val('why').replace(/\s+/g, ' ').slice(0, 400), anchor = val('anchor'), askId = f.dataset.ask || null;
|
|
196
|
+
if (!title) { m.textContent = 'Give it a name.'; f.title.focus(); return; }
|
|
197
|
+
if (!anchor) { m.textContent = 'Choose what it counts toward. Unanchored work is rejected.'; return; }
|
|
198
|
+
go.disabled = true; m.textContent = '';
|
|
199
|
+
let ask = askId;
|
|
200
|
+
if (!ask) { const r0 = await post('/api/boards/asks/add', { board: M().board.id, line: title, source: 'New initiative, typed by you' }).catch(() => null); if (!r0 || r0.ok !== true) { go.disabled = false; m.textContent = errOf(r0); return; } ask = r0.ask && r0.ask.id; }
|
|
201
|
+
const res = await post('/api/boards/asks/accept', { board: M().board.id, ask, title, lane: N.lean || 'feature', anchor, ...(why ? { intent: why } : {}) }).catch(() => null);
|
|
202
|
+
if (!res || res.ok !== true) { go.disabled = false; m.textContent = errOf(res); return; }
|
|
203
|
+
const id = res.initiative && res.initiative.id, stage = res.stage || firstStage();
|
|
204
|
+
if (id) {
|
|
205
|
+
await post('/api/board-grill/start', { id, why, links: N.links }).catch(() => null);
|
|
206
|
+
for (const file of N.files) { if (file.size > 4 * 1024 * 1024) continue; await post('/api/board-grill/file', { id, name: file.name, type: file.type, data: await b64(file) }).catch(() => null); }
|
|
207
|
+
}
|
|
208
|
+
N = null;
|
|
209
|
+
A.say('“' + title + '” is ' + (askId ? 'accepted' : 'created') + ' in ' + stage + ', anchored to ' + anchor + '.');
|
|
210
|
+
A.load();
|
|
211
|
+
if (id) openGrill(id, title, stage, true); else A.close();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
/* ── the first questions (BdGrill) ─────────────────────────────────────────────────────────────────────────────── */
|
|
215
|
+
let Q = null; // { id, title, stage, fresh, data, at }
|
|
216
|
+
const gget = async (id) => { try { const r = await (await fetch('/api/board-grill?ws=' + encodeURIComponent(M().board.ws || '') + '&id=' + encodeURIComponent(id), { credentials: 'same-origin' })).json(); return r && r.ok ? r : null; } catch { return null; } };
|
|
217
|
+
function grillHtml() {
|
|
218
|
+
const g = Q.data, qs = g ? g.questions : [], cur = qs[Q.at] || null, open = qs.filter((x) => !x.answer).length;
|
|
219
|
+
const took = g && g.summary.took.length ? g.summary.took : ['Nothing yet: no Why and no material were given.'];
|
|
220
|
+
const names = g ? g.material.links.map((k) => k.label).concat(g.material.files.map((f) => f.name)) : [];
|
|
221
|
+
const card = (x, i) => (i === Q.at
|
|
222
|
+
? `<div class="bd-qc on" data-q="${esc(x.key)}"><span class="src">${x.n} of ${x.of} · ${esc(x.topic)}</span><b>${esc(x.q)}</b><span class="bd-amut">${esc(x.why)}</span>${x.chips.length ? `<div class="bd-chips" role="radiogroup" aria-label="${esc(x.topic)}">${x.chips.map((c) => `<button type="button" class="bd-chip${x.answer === c ? ' on' : ''}" role="radio" aria-checked="${x.answer === c}" data-qchip="${esc(c)}">${esc(c)}</button>`).join('')}</div>` : ''}<input class="bd-inp sm" name="qa" maxlength="500" value="${esc(x.answer && !x.chips.includes(x.answer) ? x.answer : '')}" placeholder="Or answer in your words…" aria-label="Your answer"></div>`
|
|
223
|
+
: `<button type="button" class="bd-qc off" data-qgo="${i}"><span class="src">${x.n} of ${x.of} · ${esc(x.topic)}${x.answer ? ' · answered' : ''}</span><span class="sm">${esc(x.answer ? x.q + ' ' + x.answer : x.q)}</span></button>`);
|
|
224
|
+
const last = Q.at >= qs.length - 1;
|
|
225
|
+
return `<div class="pk-h"><div class="pk-ht"><p class="pk-eye">${esc(Q.stage)} · ${Q.fresh ? 'just created' : 'open questions'}</p><h2 id="pkTitle">${esc(Q.title)}</h2></div><div class="pk-tools"><button type="button" class="bd-ib" data-grill="later" aria-label="Close. The questions stay as this initiative’s next step" title="Close">${SV(I.x)}</button></div></div>`
|
|
226
|
+
+ `<div class="pk-b bd-pl"><div class="bd-box sm"><b>What PMOS took from your material</b>${took.map((t) => `<span>${esc(t)}</span>`).join('')}${names.length ? `<span class="bd-amut">From ${esc(names.join(' and '))}</span>` : ''}</div>`
|
|
227
|
+
+ (qs.length ? `<div class="bd-qhd"><b>${qs.length} ${qs.length === 1 ? 'question' : 'questions'} before the BRD</b><span class="bd-amut">Only what the material does not answer</span></div>${qs.map(card).join('')}` : '<p class="bd-amut">Nothing is left to ask: the BRD can start from what you gave.</p>')
|
|
228
|
+
+ `<p class="bd-amsg" id="grM" role="status"></p><div class="bd-arow bd-pfoot">${qs.length ? `<button type="button" class="bd-btn solid" data-grill="next">${last ? 'Done' : 'Next question'}</button>` : ''}<button type="button" class="bd-btn ghost" data-grill="later">Later</button><span class="bd-amut bd-push">${open ? 'Later keeps them as the next step' : 'Every question is answered'}</span></div></div>`;
|
|
229
|
+
}
|
|
230
|
+
export async function openGrill(id, title, stage, fresh, from) {
|
|
231
|
+
Q = { id, title, stage, fresh: !!fresh, data: null, at: 0 };
|
|
232
|
+
A.panel(grillHtml(), from || null, 'pk-new');
|
|
233
|
+
const g = await gget(id); if (!Q || Q.id !== id) return;
|
|
234
|
+
Q.data = g; Q.at = Math.max(0, g ? g.questions.findIndex((x) => !x.answer) : 0);
|
|
235
|
+
A.panel(grillHtml(), null, 'pk-new');
|
|
236
|
+
}
|
|
237
|
+
async function saveCur() {
|
|
238
|
+
const cur = Q.data && Q.data.questions[Q.at]; if (!cur) return true;
|
|
239
|
+
const box = document.querySelector('#peek .bd-qc.on'); if (!box) return true;
|
|
240
|
+
const typed = (box.querySelector('input[name="qa"]') || {}).value || '', chip = box.querySelector('[data-qchip].on');
|
|
241
|
+
const answer = typed.trim() || (chip ? chip.dataset.qchip : '');
|
|
242
|
+
if (answer === (cur.answer || '')) return true;
|
|
243
|
+
const r = await post('/api/board-grill/answer', { id: Q.id, q: cur.key, answer }).catch(() => null);
|
|
244
|
+
if (!r || !r.ok) { $('#grM').textContent = errOf(r); return false; }
|
|
245
|
+
Q.data = r; return true;
|
|
246
|
+
}
|
|
247
|
+
document.addEventListener('click', async (e) => {
|
|
248
|
+
if (!Q || !e.target.closest('#peek')) return;
|
|
249
|
+
const c = e.target.closest('[data-qchip]'); if (c) { $$('#peek [data-qchip]').forEach((x) => { const on = x === c && !x.classList.contains('on'); x.classList.toggle('on', on); x.setAttribute('aria-checked', String(on)); }); return; }
|
|
250
|
+
const go = e.target.closest('[data-qgo]'); if (go) { if (await saveCur()) { Q.at = +go.dataset.qgo; A.panel(grillHtml(), null, 'pk-new'); } return; }
|
|
251
|
+
const b = e.target.closest('[data-grill]'); if (!b) return;
|
|
252
|
+
if (!(await saveCur())) return;
|
|
253
|
+
const open = Q.data ? Q.data.questions.filter((x) => !x.answer).length : 0, title = Q.title;
|
|
254
|
+
if (b.dataset.grill === 'next' && Q.at < ((Q.data && Q.data.questions.length) || 0) - 1) { Q.at++; A.panel(grillHtml(), null, 'pk-new'); const i = $('#peek .bd-qc.on input'); if (i) i.focus(); return; }
|
|
255
|
+
if (b.dataset.grill === 'later' && open) await post('/api/board-grill/later', { id: Q.id }).catch(() => null);
|
|
256
|
+
Q = null; A.close();
|
|
257
|
+
A.say(open ? 'Kept as the next step of ' + title + ': ' + open + ' open ' + (open === 1 ? 'question' : 'questions') + '.' : 'The answers are kept on ' + title + ' for its BRD.');
|
|
258
|
+
A.load();
|
|
259
|
+
});
|
|
260
|
+
export const grillOpen = () => !!Q;
|
|
261
|
+
export function dropGrill() { Q = null; N = null; }
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* pm/bd-pop.js — the Board's popovers (initiative premium-uncovered-features, Board): one floating card under the button that opened it
|
|
2
|
+
* (BdActions' row menu, BdFilter's Filter and Find, BdSprint's sprints and releases, BdAsks' new asks, BdPanel's metric trend), and on a
|
|
3
|
+
* phone the same card as a bottom sheet over a scrim (BdPhone). One popover is open at a time; a press outside it, Escape or a second press
|
|
4
|
+
* on its button closes it, and the focus goes back to that button. */
|
|
5
|
+
import { $ } from './premium-shell.js';
|
|
6
|
+
|
|
7
|
+
let host = null, scrim = null, from = null, onClose = null;
|
|
8
|
+
const PHONE = matchMedia('(max-width: 720px)');
|
|
9
|
+
function ensure() {
|
|
10
|
+
if (host) return;
|
|
11
|
+
host = document.createElement('div'); host.className = 'bd-pp'; host.id = 'bdPop'; host.hidden = true; host.setAttribute('role', 'dialog');
|
|
12
|
+
scrim = document.createElement('div'); scrim.className = 'bd-scrim'; scrim.hidden = true;
|
|
13
|
+
const main = $('#stage') || document.body;
|
|
14
|
+
main.appendChild(scrim); main.appendChild(host);
|
|
15
|
+
scrim.addEventListener('click', () => close(true));
|
|
16
|
+
document.addEventListener('pointerdown', (e) => { if (!host.hidden && !host.contains(e.target) && !(from && from.contains(e.target)) && !e.target.closest('.bd-scrim')) close(false); }, true);
|
|
17
|
+
window.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !host.hidden) { e.stopPropagation(); close(true); } }, true);
|
|
18
|
+
window.addEventListener('resize', () => { if (!host.hidden) place(); });
|
|
19
|
+
}
|
|
20
|
+
/** Where the card goes: under its button, kept inside the window; a phone puts it at the bottom as a sheet. */
|
|
21
|
+
function place() {
|
|
22
|
+
const sheet = PHONE.matches;
|
|
23
|
+
host.classList.toggle('sheet', sheet); scrim.hidden = !sheet;
|
|
24
|
+
if (sheet || !from) { host.style.left = host.style.top = ''; return; }
|
|
25
|
+
const b = from.getBoundingClientRect(), w = host.offsetWidth, h = host.offsetHeight;
|
|
26
|
+
let left = host.dataset.align === 'right' ? b.right - w : b.left;
|
|
27
|
+
left = Math.max(12, Math.min(left, innerWidth - w - 12));
|
|
28
|
+
let top = b.bottom + 8;
|
|
29
|
+
if (top + h > innerHeight - 12) top = Math.max(12, b.top - h - 8);
|
|
30
|
+
host.style.left = left + 'px'; host.style.top = top + 'px';
|
|
31
|
+
}
|
|
32
|
+
/** Opens `html` under `btn`. o: { label, cls, width, align: 'left'|'right', onClose, focus: selector } → the card. A second press on the same button closes it. */
|
|
33
|
+
export function open(html, btn, o = {}) {
|
|
34
|
+
ensure();
|
|
35
|
+
if (!host.hidden && btn && from === btn) { close(true); return null; }
|
|
36
|
+
if (!host.hidden) close(false);
|
|
37
|
+
host.className = 'bd-pp' + (o.cls ? ' ' + o.cls : '');
|
|
38
|
+
host.style.width = o.width ? o.width + 'px' : '';
|
|
39
|
+
host.dataset.align = o.align || 'left';
|
|
40
|
+
host.setAttribute('aria-label', o.label || 'Board');
|
|
41
|
+
host.setAttribute('role', o.role || 'dialog');
|
|
42
|
+
host.innerHTML = (PHONE.matches ? '<div class="bd-grab" aria-hidden="true"></div>' : '') + html;
|
|
43
|
+
host.hidden = false; from = btn || null; onClose = o.onClose || null;
|
|
44
|
+
if (from) from.setAttribute('aria-expanded', 'true');
|
|
45
|
+
place();
|
|
46
|
+
const f = (o.focus && host.querySelector(o.focus)) || host.querySelector('input, button, [tabindex="0"]');
|
|
47
|
+
if (f) f.focus({ preventScroll: true });
|
|
48
|
+
return host;
|
|
49
|
+
}
|
|
50
|
+
/** Draws the open card again with new markup, in place (a filter chip pressed, a decline opened). */
|
|
51
|
+
export function redraw(html) { if (!host || host.hidden) return; host.innerHTML = (PHONE.matches ? '<div class="bd-grab" aria-hidden="true"></div>' : '') + html; place(); }
|
|
52
|
+
export function close(back) {
|
|
53
|
+
if (!host || host.hidden) return;
|
|
54
|
+
host.hidden = true; scrim.hidden = true;
|
|
55
|
+
if (from) { from.setAttribute('aria-expanded', 'false'); if (back && document.contains(from)) from.focus({ preventScroll: true }); }
|
|
56
|
+
const cb = onClose; from = null; onClose = null; if (cb) cb();
|
|
57
|
+
}
|
|
58
|
+
export const isOpen = () => !!host && !host.hidden;
|
|
59
|
+
export const el = () => host;
|