create-pmos 0.396.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 +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/scripts/nine-stages.js +49 -20
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +103 -74
- package/workspace/briefing-premium-board-test.js +316 -154
- package/workspace/briefing-premium-calendar-2-test.js +135 -195
- package/workspace/briefing-premium-calendar-3-test.js +143 -413
- package/workspace/briefing-premium-calendar-test.js +86 -185
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +166 -294
- package/workspace/briefing-premium-insights-test.js +351 -214
- package/workspace/briefing-premium-metrics-test.js +53 -118
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +91 -52
- package/workspace/briefing-premium-test.js +150 -633
- package/workspace/briefing-premium-work-test.js +88 -269
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-premium-facts.js +2 -1
- package/workspace/fixtures/board-premium-jira.js +28 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/initiative-premium-facts.js +2 -1
- package/workspace/fixtures/initiatives-api/list.json +30 -42
- package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
- package/workspace/fixtures/initiatives-api/sheet.json +10 -14
- package/workspace/fixtures/insights-premium-facts.js +11 -2
- 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 +2 -0
- package/workspace/guide/lifecycle.md +51 -0
- package/workspace/home-shot.js +38 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +160 -3
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/engine/boards.js +15 -14
- package/workspace/lib/engine/nine-stages.js +49 -20
- package/workspace/lib/engine/signals/detectors.js +13 -11
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +126 -1
- 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-premium.js +3 -2
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-initiatives.js +1 -1
- package/workspace/lib/routes-insights-premium.js +19 -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/vendor/scripts/nine-stages.js +49 -20
- 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-agreed-viewer-shots.js +76 -0
- package/workspace/premium-board-actions-test.js +85 -73
- 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 -36
- package/workspace/premium-chat-context-test.js +22 -19
- package/workspace/premium-chat-goal-view-test.js +28 -26
- package/workspace/premium-chat-notes-test.js +29 -33
- package/workspace/premium-chat-report-tab-test.js +35 -25
- package/workspace/premium-chat-term-test.js +16 -14
- package/workspace/premium-chat-viewer-test.js +60 -53
- package/workspace/premium-core-doc-issue-test.js +50 -41
- package/workspace/premium-html-viewer-test.js +17 -18
- package/workspace/premium-phone-card-test.js +8 -2
- package/workspace/premium-phone-room-test.js +42 -31
- 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 -31
- package/workspace/premium-vw-cal-test.js +82 -123
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +12 -11
- package/workspace/premium-vw-item-test.js +50 -48
- package/workspace/premium-vw-jira-test.js +55 -26
- package/workspace/premium-vw-meet-test.js +118 -187
- package/workspace/premium-vw-notes-test.js +85 -107
- package/workspace/premium-vw-rec-test.js +72 -193
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +63 -51
- package/workspace/public/pm/bd-acts.js +305 -0
- package/workspace/public/pm/bd-span.js +224 -0
- package/workspace/public/pm/bd-stages.js +47 -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 +640 -0
- package/workspace/public/pm/cozy-home.css +580 -0
- package/workspace/public/pm/cozy-home.js +172 -0
- package/workspace/public/pm/cozy-initiative.css +138 -0
- package/workspace/public/pm/cozy-insights.css +421 -0
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +65 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +143 -0
- package/workspace/public/pm/cozy-viewer.js +144 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +254 -0
- 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/lifecycle-lens-model.js +45 -27
- package/workspace/public/pm/lifecycle-lens.js +22 -11
- 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 +544 -253
- package/workspace/public/pm/premium-brief.js +1 -1
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-chat.js +17 -10
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-initiative-head.js +138 -0
- package/workspace/public/pm/premium-initiative.js +28 -4
- package/workspace/public/pm/premium-insights.js +950 -440
- 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 +107 -124
- package/workspace/public/pm/premium-viewer.js +27 -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-jira-model.js +22 -5
- package/workspace/public/pm/premium-vw-jira.css +11 -0
- package/workspace/public/pm/premium-vw-jira.js +11 -4
- 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 -215
- 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 +57 -64
- package/workspace/public/premium-chat.html +7 -33
- package/workspace/public/premium-initiative.html +8 -41
- package/workspace/public/premium-insights.html +63 -62
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium-work.html +6 -72
- package/workspace/public/premium.html +21 -66
- package/workspace/public/vendor/nunito-var.woff2 +0 -0
- package/workspace/server.js +25 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/premium-agreed-viewer.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/third-party/README.md +1 -0
- package/workspace/public/pm/premium-work.js +0 -719
- package/workspace/public/pm/premium.js +0 -1133
|
@@ -1,61 +1,69 @@
|
|
|
1
|
-
/* pm/premium-report-read.js — a report
|
|
2
|
-
* One report, one bar (PM 2026-10-22, mockup /mnt/project-files/premium-reports-from-chat/one-report-editor/report-mockup.html): icon buttons for
|
|
3
|
-
* Slides | Page, the Brief, Edit, Present, Share, Issue and ⋯, the state and the schedule on the same row, and the report's cycles under its name.
|
|
4
|
-
* A new look waits on one line (Use it or Keep current); its samples are chips above the chat box, added with the clip. It opens in the page's
|
|
5
|
-
* dialog; the conversation on the left shapes the look.
|
|
1
|
+
/* pm/premium-report-read.js — a report cycle in the Viewer card (initiative premium-agreed-design, area viewer; ReportPanel.dc.html).
|
|
6
2
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
3
|
+
* One report cycle, drawn as the design's report panel inside the czViewer card (cozy-viewer.js): no conversation, no tabs, nothing in #dlg.
|
|
4
|
+
* Header kind "Report · <audience>" (the template's audience), the report's name.
|
|
5
|
+
* Chips the cycle chip (Draft · Oct 21, Issued · Oct 21; orange "Editing the Oct 21 draft" while editing), the schedule chip and its
|
|
6
|
+
* popover (Every week, Every 2 weeks, Every month on the 1st, Something else: say it in the chat; Mon to Fri; the time; Cancel and
|
|
7
|
+
* Schedule it), and Brief.
|
|
8
|
+
* Toolbar Slides | Page, Edit, Present, Share (its popover: Link | Send a file, Ends in, Password, Create link, the open links and Turn off),
|
|
9
|
+
* the blue Issue button and More (PPTX DOCX PDF XLSX CSV MD, Print, Versions "N cycles", Discard this draft… or Archive).
|
|
10
|
+
* Issue a confirm with the three checks of GET /api/viewer-report/checks, Issue it and Not yet. POST /api/report/issue freezes the cycle.
|
|
11
|
+
* Slides the current slide, "Slides", the counter (1 of 5) with previous and next, and a thumbnail of each slide.
|
|
12
|
+
* Phone Slides | Page as icons, Issue and More; More also holds Edit, Present, Share and Brief.
|
|
13
|
+
* Parts the design does not draw yet carry the "Waiting for design" marker: the Brief, the cycle menu (Versions), Discard and Archive confirms,
|
|
14
|
+
* the issued and archived states, Present, the page editor that Edit mounts on Page (premium-vw-doc.js), and the slide editor's tools the design
|
|
15
|
+
* does not draw (the slide tools, the selected item's tools, the speaker notes).
|
|
16
|
+
* Edit (Slides) the design's edit mode: the tip, the slide with a dashed outline and the selected item boxed, then "Slides ‹ n of N ›" and the
|
|
17
|
+
* thumbnails; Undo and Redo dim when there is nothing to take back or do again. premium-vw-slides.js draws it in the card.
|
|
11
18
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
19
|
+
* openReport(row, hand) row = a Reports card document { cadence, slot, date, path, state, archived }; hand = { ws, name, cycles, onIssue, onChange }
|
|
20
|
+
* openReportView(ref, o) ref = a report path reports/<cadence>/<date>.md or a row; the window.czViews entry (premium-vw-open.js)
|
|
21
|
+
* wordsOf(md, fallback) the document as { title, sections: [{ h, lines }] } (pure)
|
|
22
|
+
* slideHtml(lines) a section's lines as html (pure) · splitRender(html) · slideCard(s, mini) · fit(root) · schedLabel(setup) (pure)
|
|
23
|
+
*
|
|
24
|
+
* READS: GET /api/doc, /api/report-design/cycle and cycle-html (a cycle drawn to its saved design), /api/report-setups (schedule and audience),
|
|
25
|
+
* /api/viewer-report/checks, /api/shares, /api/shares/password, /api/report-export (the files). Every render is HTML the server sanitized,
|
|
14
26
|
* shown in a frame with an empty sandbox: nothing in it runs.
|
|
15
|
-
* WRITES
|
|
16
|
-
*
|
|
17
|
-
* Edit edits in place (PM 2026-10-22): on Slides it draws the slide editor (premium-vw-slides.js), on Page the page editor (premium-vw-doc.js) inside
|
|
18
|
-
* the dialog, with no viewer tab. Both save through the /api/doc-sheet routes; Save or Cancel brings the report back.
|
|
19
|
-
* The report's lifecycle (initiative premium-reports-from-chat, PM 2026-10-22: the dialog had no Discard, Archive, schedule or Share):
|
|
20
|
-
* Schedule chip the template's schedule (GET /api/report-setups), changed through POST /api/report-setups/edit; Off pauses it. A report with no
|
|
21
|
-
* template has no schedule: the chip says so and opens a chat to set one up.
|
|
22
|
-
* Discard a draft only, after a confirm (POST /api/report-documents/discard); the dialog closes. Issued reports are never deleted.
|
|
23
|
-
* Archive an issued report only, after a confirm (POST /api/report-documents/archive); Bring back undoes it.
|
|
24
|
-
* Share the viewer's share popover (premium-vw-share.js): a password link to a copy of the file as it is now. */
|
|
25
|
-
import { $, esc, openDlg, popKey, toast, turnA, turnU, ptx, setFull, closeDlg } from './premium-shell.js';
|
|
27
|
+
* WRITES (each a press, pmPost behind the launch nonce): /api/report/issue, /api/report-setups/edit or /setup (Schedule it),
|
|
28
|
+
* /api/report-documents/discard and /archive, /api/shares and /api/shares/off. */
|
|
26
29
|
import { pmGet, pmPost } from './http.js';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import
|
|
30
|
+
import { open as vOpen, current as vCur } from './cozy-viewer.js';
|
|
31
|
+
import { placeholderHtml } from './cozy-placeholder.js';
|
|
32
|
+
import './premium-vw-open.js'; // registers window.czViews
|
|
30
33
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
35
|
+
const svg = (p, n = 18) => `<svg viewBox="0 0 24 24" width="${n}" height="${n}" aria-hidden="true">${p}</svg>`;
|
|
36
|
+
const P = {
|
|
37
|
+
prev: '<path d="m15 6-6 6 6 6"/>', next: '<path d="m9 6 6 6-6 6"/>', chev: '<path d="M6 9l6 6 6-6"/>', x: '<path d="M6 6l12 12M18 6 6 18"/>',
|
|
38
|
+
check: '<path d="M5 12.5l4.5 4.5L19 7.5"/>', pen: '<path d="M4 20h4L19 9l-4-4L4 16z"/>', play: '<path d="M8 5v14l11-7z"/>',
|
|
39
|
+
share: '<circle cx="18" cy="5" r="2.5"/><circle cx="6" cy="12" r="2.5"/><circle cx="18" cy="19" r="2.5"/><path d="m8.2 10.8 7.6-4.4M8.2 13.2l7.6 4.4"/>',
|
|
40
|
+
more: '<circle cx="5" cy="12" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="19" cy="12" r="1.6"/>', clock: '<circle cx="12" cy="12" r="8"/><path d="M12 8v4l3 2"/>',
|
|
41
|
+
brief: '<path d="M6 3h9l4 4v14H6zM14 3v5h5M9 12h7M9 16h5"/>', slides: '<rect x="3" y="5" width="18" height="12" rx="1.5"/><path d="M8 21h8M12 17v4"/>',
|
|
42
|
+
page: '<path d="M6 3h9l4 4v14H6zM14 3v5h5"/>', print: '<path d="M7 9V4h10v5M7 17H5v-6h14v6h-2M8 14h8v6H8z"/>', hist: '<path d="M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5M12 7v5l3 2"/>',
|
|
43
|
+
bin: '<path d="M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13"/>', box: '<path d="M4 5h16v4H4zM5 9v10h14V9M10 13h4"/>', lock: '<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/>',
|
|
44
|
+
redo2: '<path d="M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7"/>', undo: '<path d="M9 14 4 9l5-5M4 9h11a5 5 0 0 1 0 10h-3"/>', redo: '<path d="m15 14 5-5-5-5M20 9H9a5 5 0 0 0 0 10h3"/>',
|
|
45
|
+
plus: '<path d="M12 5v14M5 12h14"/>', layout: '<rect x="4" y="4" width="16" height="16" rx="2"/><path d="M4 10h16M10 10v10"/>',
|
|
46
|
+
theme: '<path d="M12 3a9 9 0 1 0 0 18c1 0 1.5-.8 1.5-1.6 0-1-.8-1.4-.8-2.4 0-1 .8-1.6 1.8-1.6H17a4 4 0 0 0 4-4c0-4.6-4-8.4-9-8.4z"/><circle cx="7.5" cy="11" r="1"/><circle cx="10.5" cy="7.5" r="1"/><circle cx="15" cy="7.5" r="1"/>',
|
|
47
|
+
};
|
|
48
|
+
const ic = (k, n) => svg(P[k], n);
|
|
49
|
+
const MONS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
38
50
|
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
|
|
39
|
-
const MORE = ICO('<circle cx="5" cy="12" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="19" cy="12" r="1.6"/>');
|
|
40
|
-
const CLK = ICO('<circle cx="12" cy="12" r="8"/><path d="M12 8v4l3 2"/>'), CLIP = ICO('<path d="M20 11.5l-8 8a5 5 0 0 1-7-7l8.5-8.5a3.5 3.5 0 0 1 5 5L10 17.5a2 2 0 0 1-3-3l7.5-7.5"/>');
|
|
41
|
-
const SLI = ICO('<rect x="3" y="5" width="18" height="12" rx="1.5"/><path d="M8 21h8M12 17v4"/>'), PGI = ICO('<path d="M6 3h9l4 4v14H6zM14 3v5h5M9 12h7M9 16h7"/>');
|
|
42
|
-
const BRF = ICO('<path d="M5 4h14v16H5zM9 8h6M9 12h6M9 16h3"/>');
|
|
43
51
|
const W = 1280;
|
|
44
|
-
const POLL_MS = 800, POLL_MAX = 240000;
|
|
45
|
-
const DL = [['pptx', 'PowerPoint (.pptx)', 'A title slide, then one slide for each section.'], ['docx', 'Word (.docx)', 'Headings, paragraphs and lists.'],
|
|
46
|
-
['xlsx', 'Excel (.xlsx)', 'The tables and lists of the document, one sheet each.'], ['csv', 'CSV (.csv)', 'The rows of the document as plain text.']];
|
|
47
|
-
const KINDS = { pdf: 'pdf', pptx: 'pptx', docx: 'docx', png: 'image', jpg: 'image', jpeg: 'image' };
|
|
48
|
-
|
|
49
|
-
let R = null; // the open reader
|
|
50
|
-
|
|
51
52
|
const q = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
52
53
|
const inline = (s) => esc(s).replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>').replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
54
|
+
const WAIT = (f) => `<span class="vz-wait" data-cz-placeholder="${esc(f)}">Waiting for design</span>`;
|
|
55
|
+
/** "Oct 21", from a cycle's YYYY-MM-DD slot. */
|
|
56
|
+
export const shortSlot = (s) => { const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(s || '')); return m ? MONS[+m[2] - 1] + ' ' + +m[3] : String(s || ''); };
|
|
53
57
|
|
|
58
|
+
let R = null; // the open report
|
|
59
|
+
|
|
60
|
+
/* ── the words (pure) ── */
|
|
54
61
|
/** The document as a title and its sections, as written. A `## ` heading starts a section; the text before the first one is the lead. */
|
|
55
62
|
export function wordsOf(md, fallback) {
|
|
56
63
|
const lines = String(md || '').replace(/\r/g, '').split('\n');
|
|
57
|
-
let i = 0, title = '';
|
|
58
|
-
|
|
64
|
+
let i = 0, title = '', sub = '';
|
|
65
|
+
const val = (m) => m[1].replace(/^["'](.*)["']$/, '$1').trim();
|
|
66
|
+
if (lines[0] === '---') { const e = lines.indexOf('---', 1); if (e > 0) { for (const l of lines.slice(1, e)) { const m = /^title:\s*(.*)$/.exec(l), d = /^(?:subtitle|description):\s*(.*)$/.exec(l); if (m) title = val(m); if (d && !sub) sub = val(d); } i = e + 1; } }
|
|
59
67
|
const sections = [], lead = [];
|
|
60
68
|
let cur = null;
|
|
61
69
|
for (; i < lines.length; i++) {
|
|
@@ -66,7 +74,7 @@ export function wordsOf(md, fallback) {
|
|
|
66
74
|
(cur ? cur.lines : lead).push(l);
|
|
67
75
|
}
|
|
68
76
|
if (lead.some((l) => l.trim())) sections.unshift({ h: 'Summary', lines: lead });
|
|
69
|
-
return { title: title || fallback || 'Report', sections };
|
|
77
|
+
return { title: title || fallback || 'Report', sub, sections };
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
/** A section's lines as html: a list for each run of bullets, a sub-heading in bold, every other line a paragraph. */
|
|
@@ -86,6 +94,28 @@ export function slideHtml(lines) {
|
|
|
86
94
|
return out.join('') || '<p>This section is empty.</p>';
|
|
87
95
|
}
|
|
88
96
|
|
|
97
|
+
/** The schedule chip's words: "Not scheduled", "Every Mon 09:00", "Every 2 weeks · Mon 09:00", "Every month · 1st 09:00", "Every day 09:00". */
|
|
98
|
+
export function schedLabel(setup) {
|
|
99
|
+
const s = setup && setup.status !== 'paused' ? setup.schedule : null;
|
|
100
|
+
if (!s || !s.cadence || s.cadence === 'off') return 'Not scheduled';
|
|
101
|
+
const t = s.time || '09:00';
|
|
102
|
+
if (s.cadence === 'daily') return 'Every day ' + t;
|
|
103
|
+
if (s.cadence === 'monthly') { const d = s.dayOfMonth || 1; return 'Every month · ' + d + (d === 1 ? 'st' : d === 2 ? 'nd' : d === 3 ? 'rd' : 'th') + ' ' + t; }
|
|
104
|
+
return (s.cadence === 'bi-weekly' ? 'Every 2 weeks · ' : 'Every ') + (s.day || 'Mon') + ' ' + t;
|
|
105
|
+
}
|
|
106
|
+
/** The popover's starting pick, from the template's schedule. */
|
|
107
|
+
export function schedPick(setup) {
|
|
108
|
+
const s = setup && setup.status !== 'paused' ? setup.schedule : null;
|
|
109
|
+
const cad = s && ['weekly', 'bi-weekly', 'monthly'].includes(s.cadence) ? s.cadence : 'weekly';
|
|
110
|
+
return { cad, day: (s && s.day && DAYS.includes(s.day)) ? s.day : 'Mon', time: (s && s.time) || '09:00' };
|
|
111
|
+
}
|
|
112
|
+
/** The schedule a pick saves, or null for "Something else". */
|
|
113
|
+
export function schedOf(pick) {
|
|
114
|
+
if (!pick || pick.cad === 'else') return null;
|
|
115
|
+
if (pick.cad === 'monthly') return { cadence: 'monthly', dayOfMonth: 1, time: pick.time || '09:00' };
|
|
116
|
+
return { cadence: pick.cad, day: pick.day || 'Mon', time: pick.time || '09:00' };
|
|
117
|
+
}
|
|
118
|
+
|
|
89
119
|
/* ── a sanitized render: its style, its slides and its body (DOMParser; nothing of it runs) ── */
|
|
90
120
|
export function splitRender(html) {
|
|
91
121
|
const d = new DOMParser().parseFromString(String(html || ''), 'text/html');
|
|
@@ -98,520 +128,519 @@ export function splitRender(html) {
|
|
|
98
128
|
}
|
|
99
129
|
const href = (f) => new URL('./' + f, import.meta.url).href;
|
|
100
130
|
function frameDoc(style, inner, cls) {
|
|
101
|
-
return '<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="stylesheet" href="' + esc(href('tokens.css')) + '"><link rel="stylesheet" href="' + esc(href('
|
|
131
|
+
return '<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="stylesheet" href="' + esc(href('tokens.css')) + '"><link rel="stylesheet" href="' + esc(href('premium-report-frame.css')) + '">'
|
|
102
132
|
+ '<style>' + String(style || '').replace(/<\/style/gi, '<\\/style') + '</style></head><body class="pmos-frame ' + cls + '">' + String(inner || '') + '</body></html>';
|
|
103
133
|
}
|
|
104
|
-
const frame = (style, inner, cls, title) => `<iframe
|
|
134
|
+
const frame = (style, inner, cls, title) => `<iframe sandbox="" tabindex="-1" title="${esc(title)}" srcdoc="${esc(frameDoc(style, inner, cls))}"></iframe>`;
|
|
105
135
|
|
|
106
|
-
/* ── what is shown
|
|
107
|
-
function source() {
|
|
108
|
-
if (R.show !== 'cycle') return { kind: 'ver', n: R.show, X: R.ver.get(R.show) || null };
|
|
109
|
-
return R.cyc ? { kind: 'cycle', X: R.cyc } : { kind: 'words' };
|
|
110
|
-
}
|
|
136
|
+
/* ── what is shown ── */
|
|
111
137
|
function slides() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
138
|
+
if (R.cyc && R.cyc.slides.length) return R.cyc.slides.map((x) => ({ k: 'frame', h: x.h, html: x.html, css: R.cyc.style }));
|
|
139
|
+
const w = R.W || { title: R.name, sections: [] };
|
|
140
|
+
return [titleSlide(w)]
|
|
141
|
+
.concat(w.sections.map((x) => ({ k: 'text', h: x.h, html: slideHtml(x.lines) })));
|
|
142
|
+
}
|
|
143
|
+
/** "21 Oct 2026", from a YYYY-MM-DD slot. */
|
|
144
|
+
export const longSlot = (s) => { const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(s || '')); return m ? +m[3] + ' ' + MONS[+m[2] - 1] + ' ' + m[1] : String(s || ''); };
|
|
145
|
+
/** The title slide (ReportPanel.dc.html): the audience tag, the title with the audience as its accent line, a subtitle (the file's
|
|
146
|
+
* subtitle or description, else its first sections) and the as-of line. Nothing is made up: a part with no source is left out. */
|
|
147
|
+
function titleSlide(w) {
|
|
148
|
+
const heads = (w.sections || []).map((x) => x.h).filter((h) => !/^summary$/i.test(h)).slice(0, 3);
|
|
149
|
+
const list = heads.length > 1 ? heads.slice(0, -1).join(', ') + ' and ' + heads[heads.length - 1].toLowerCase() : heads.join('');
|
|
150
|
+
const f = headFigure(w), t = [R.row.slot ? 'As of ' + longSlot(R.row.slot) : '', f && f.data ? 'Data: ' + f.data : ''].filter(Boolean).join(' · ');
|
|
151
|
+
return { k: 'title', h: 'Title', title: w.title, eye: R.audience || 'Report', acc: R.audience ? R.audience.toLowerCase() : '', sub: w.sub || list, t,
|
|
152
|
+
fig: f ? { v: f.v, cap: f.cap } : null };
|
|
153
|
+
}
|
|
154
|
+
/** The title slide's headline figure (ReportPanel.dc.html: "81%" over "597 of 733 web logins"): the first bold number of the first
|
|
155
|
+
* section, the words in brackets after it as its caption, and an "as of <day month>" in that line as the data date. None → null. */
|
|
156
|
+
export function headFigure(w) {
|
|
157
|
+
const first = ((w && w.sections) || [])[0];
|
|
158
|
+
for (const l of (first && first.lines) || []) {
|
|
159
|
+
const m = /\*\*([^*]*\d[^*]*)\*\*\s*(?:\(([^)]+)\))?/.exec(l);
|
|
160
|
+
if (!m || m[1].length > 12) continue;
|
|
161
|
+
const d = /\bas of (\d{1,2} [A-Z][a-z]{2})/i.exec(l);
|
|
162
|
+
return { v: m[1].trim(), cap: (m[2] || '').trim(), data: d ? d[1] : '' };
|
|
116
163
|
}
|
|
117
|
-
return
|
|
164
|
+
return null;
|
|
118
165
|
}
|
|
119
|
-
|
|
166
|
+
/** One slide: a designed frame, the title slide or a section's words. */
|
|
120
167
|
export function slideCard(s, mini) {
|
|
121
|
-
if (s.k === 'frame') return `<
|
|
122
|
-
if (s.k === 'title') return `<
|
|
123
|
-
return `<
|
|
168
|
+
if (s.k === 'frame') return `<span class="vz-fr">${frame(s.css, s.html, 'pmos-one', s.h)}</span>`;
|
|
169
|
+
if (s.k === 'title') return `<span class="vz-words vz-title"><span class="vz-eye">${esc(s.eye || (R && R.audience) || 'Report')}</span><h4 data-ed="title">${esc(s.title || s.h)}${s.acc ? ` <em class="vz-acc">${esc(s.acc)}</em>` : ''}</h4>${mini ? '' : `${s.sub ? `<b class="vz-tsub">${esc(s.sub)}</b>` : ''}<p>${esc(s.t || '')}</p>`}</span>${!mini && s.fig ? `<span class="vz-tfig"><i class="vz-tdot" aria-hidden="true"></i><span><b>${esc(s.fig.v)}</b>${s.fig.cap ? `<small>${esc(s.fig.cap)}</small>` : ''}</span></span>` : ''}`;
|
|
170
|
+
return `<span class="vz-words"><h4>${esc(s.h)}</h4>${mini ? '' : s.html}</span>`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* ── drawing ── */
|
|
174
|
+
const chip = (k, inner, a, o = {}) => `<button type="button" class="vz-c vz-hv${o.cls || ''}" data-r="${a}"${k ? ` data-k="${k}"` : ''}${o.exp != null ? ` aria-haspopup="${o.pop || 'menu'}" aria-expanded="${o.exp}"` : ''}${o.label ? ` aria-label="${esc(o.label)}"` : ''}>${inner}</button>`;
|
|
175
|
+
const ib = (a, icon, name, o = {}) => `<button type="button" class="vz-ib vz-hv${o.cls || ''}" data-r="${a}" aria-label="${esc(name)}" title="${esc(name)}"${o.exp != null ? ` aria-haspopup="${o.pop || 'menu'}" aria-expanded="${o.exp}"` : ''}${o.off ? ' disabled' : ''}>${icon}</button>`;
|
|
176
|
+
function chipsHtml() {
|
|
177
|
+
const when = shortSlot(R.row.slot || R.row.date);
|
|
178
|
+
if (R.edit) return `<div class="vz-rpc">${chip('edit', `<i aria-hidden="true"></i>Editing the ${esc(when)} draft${ic('chev', 14)}`, 'cycm', { exp: R.pop === 'cyc' })}${R.pop === 'cyc' ? cycPop() : ''}</div>`;
|
|
179
|
+
const st = R.issued ? (R.archived ? 'Archived' : 'Issued') : 'Draft';
|
|
180
|
+
const sched = R.setup === undefined ? '' : chip(R.pop === 'sched' ? 'open' : '', `${ic('clock', 14)}${esc(schedLabel(R.setup))}${ic('chev', 14)}`, 'sched', { exp: R.pop === 'sched', pop: 'dialog', label: 'Schedule: ' + schedLabel(R.setup) + '. Change it' });
|
|
181
|
+
return `<div class="vz-rpc">${chip(R.issued ? 'issued' : '', `<i aria-hidden="true"></i>${st} · ${esc(when)}${ic('chev', 14)}`, 'cycm', { exp: R.pop === 'cyc', label: st + ', ' + when + '. Other cycles' })}`
|
|
182
|
+
+ `${R.issued ? WAIT(R.archived ? 'Archived state' : 'Issued state') : ''}${sched}${chip('line', `${ic('brief', 14)}Brief`, 'brief', { cls: ' vz-dko', exp: R.pop === 'brief', pop: 'dialog' })}`
|
|
183
|
+
+ `${R.pop === 'sched' ? schedPop() : R.pop === 'cyc' ? cycPop() : ''}</div>`;
|
|
184
|
+
}
|
|
185
|
+
function toolHtml() {
|
|
186
|
+
const seg = `<div class="vz-sg" role="group" aria-label="${R.edit ? 'Edit as' : 'Read as'}"><button type="button" data-r="view|deck" aria-pressed="${R.view === 'deck'}" aria-label="Slides" title="Slides">${ic('slides', 16)}<span class="vz-dko">Slides</span></button><button type="button" data-r="view|doc" aria-pressed="${R.view === 'doc'}" aria-label="Page" title="Page">${ic('page', 16)}<span class="vz-dko">Page</span></button></div>`;
|
|
187
|
+
if (R.edit) {
|
|
188
|
+
const deck = R.view === 'deck';
|
|
189
|
+
const SS = slideState(); // Undo and Redo are dimmed while there is nothing to take back or to do again (ReportPanel.dc.html: Redo at .4)
|
|
190
|
+
return `<div class="vz-tb">${deck ? ib('ed|undo', ic('undo'), 'Undo', { cls: !SS || !SS.hist.length ? ' vz-dim' : '' }) + ib('ed|redo', ic('redo'), 'Redo', { cls: !SS || !SS.fut.length ? ' vz-dim' : '' }) + '<span class="vz-sep"></span>'
|
|
191
|
+
+ `<button type="button" class="vz-sec2 vz-hv vz-flat" data-r="ins" aria-haspopup="menu" aria-expanded="${R.pop === 'ins'}">${ic('plus', 16)} Insert${ic('chev', 14)}</button>`
|
|
192
|
+
+ ib('ed|layout', ic('layout'), 'Layout') + ib('ed|theme', ic('theme'), 'Theme') : seg}<span class="vz-sp"></span>`
|
|
193
|
+
+ `<button type="button" class="vz-sec2 vz-hv" data-r="edcancel">Cancel</button>${deck ? `<button type="button" class="vz-issue vz-hv" data-r="edsave"${R.busy ? ' disabled' : ''}>Save</button>` : ''}${R.pop === 'ins' ? insPop() : ''}</div>`;
|
|
194
|
+
}
|
|
195
|
+
const issue = R.issued ? '' : `<button type="button" class="vz-issue vz-hv" data-r="issue" aria-expanded="${!!R.conf}">${ic('check', 16)}Issue</button>`;
|
|
196
|
+
return `<div class="vz-tb">${seg}<span class="vz-sp"></span>`
|
|
197
|
+
+ (R.issued ? '' : ib('edit', ic('pen'), R.view === 'deck' ? 'Edit the slides' : 'Edit the words', { cls: ' vz-dko' }))
|
|
198
|
+
+ ib('present', ic('play'), 'Present', { cls: ' vz-dko' }) + ib('share', ic('share'), 'Share a link to a copy', { cls: ' vz-dko', exp: R.pop === 'share', pop: 'dialog' })
|
|
199
|
+
+ (issue ? '<span class="vz-sep vz-dko"></span>' + issue : '') + ib('more', ic('more'), 'More', { exp: R.pop === 'more' })
|
|
200
|
+
+ (R.pop === 'more' ? morePop() : R.pop === 'share' ? sharePop() : '') + '</div>';
|
|
201
|
+
}
|
|
202
|
+
function schedPop() {
|
|
203
|
+
const k = R.sch, opts = [['weekly', 'Every week'], ['bi-weekly', 'Every 2 weeks'], ['monthly', 'Every month, on the 1st'], ['else', 'Something else: say it in the chat']];
|
|
204
|
+
const weekly = k.cad === 'weekly' || k.cad === 'bi-weekly';
|
|
205
|
+
return `<div class="vz-pop vz-pop-sched" data-esc-layer="1" role="dialog" aria-label="Schedule">`
|
|
206
|
+
+ `<b class="vz-pophd">Draft this report on a schedule</b><p class="vz-note">${R.setup ? 'Each cycle is drafted by a background run. Nothing is sent until you issue it.' : 'Picking one saves its sections and look as a template. A background run drafts each cycle. Nothing is sent until you issue it.'}</p>`
|
|
207
|
+
+ `<div class="vz-stack2" role="radiogroup" aria-label="How often">${opts.map(([c, l]) => `<button type="button" class="vz-mi vz-hv" role="radio" aria-checked="${k.cad === c}" data-r="scad|${c}"><span class="vz-ring"></span>${esc(l)}</button>`).join('')}</div>`
|
|
208
|
+
+ (k.cad === 'else' ? '<p class="vz-note">Say how often it should be drafted in the chat on Home, for example “Draft this every other Thursday at 8”.</p>' : '')
|
|
209
|
+
+ `<div class="vz-r1 vz-mt6">${weekly ? DAYS.map((d) => `<button type="button" class="vz-dbtn vz-hv" data-r="sday|${d}" aria-pressed="${k.day === d}">${d}</button>`).join('') : ''}<span class="vz-sp"></span><select class="vz-c vz-tchip" data-r="stime" aria-label="Time" title="The time it is drafted">${times(k.time).map((t) => `<option${t === k.time ? ' selected' : ''}>${t}</option>`).join('')}</select></div>`
|
|
210
|
+
+ (R.setup && R.setup.status !== 'paused' ? `<button type="button" class="vz-mi vz-hv vz-mi32" data-r="soff" data-k="bad">Stop drafting it on a schedule</button>` : '')
|
|
211
|
+
+ (R.schErr ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(R.schErr)}</p>` : '')
|
|
212
|
+
+ `<div class="vz-r1 vz-end4"><button type="button" class="vz-sec2 vz-hv" data-r="pop|">Cancel</button><button type="button" class="vz-issue vz-hv" data-r="sgo"${k.cad === 'else' || R.busy ? ' disabled' : ''}>Schedule it</button></div></div>`;
|
|
213
|
+
}
|
|
214
|
+
/** The times the schedule's chip offers, 24-hour, every half hour from 06:00 to 20:00, with the saved one kept. */
|
|
215
|
+
export const times = (cur) => { const L = []; for (let h = 6; h <= 20; h++) for (const m of ['00', '30']) L.push(String(h).padStart(2, '0') + ':' + m); if (cur && !L.includes(cur)) L.push(cur); return L.sort(); };
|
|
216
|
+
function cycPop() {
|
|
217
|
+
const C = R.cycles.length ? R.cycles : [R.row];
|
|
218
|
+
const st = (x) => (x.state === 'issued' ? (x.archived ? 'Archived' : 'Issued') : 'Draft');
|
|
219
|
+
return `<div class="vz-pop vz-pop-cyc" data-esc-layer="1" role="menu" aria-label="Cycles"><p class="vz-lab">Cycles ${WAIT('Cycle menu')}</p>`
|
|
220
|
+
+ C.map((x) => `<button type="button" class="vz-mi vz-hv" role="menuitemradio" aria-checked="${x.path === R.row.path}" data-r="cyc|${esc(x.path)}"><span class="vz-grow">${esc(shortSlot(x.slot || x.date))}</span><small class="vz-note">${st(x)}</small></button>`).join('') + '</div>';
|
|
221
|
+
}
|
|
222
|
+
function morePop() {
|
|
223
|
+
const fmt = (k, l) => (k === 'pdf' || k === 'md' ? `<button type="button" class="vz-fmt" data-r="${k}">${l}</button>` : `<a class="vz-fmt" data-r="dl|${k}" href="/api/report-export?${esc(q({ ws: R.ws, path: R.row.path, fmt: k }))}" download>${l}</a>`);
|
|
224
|
+
const n = R.cycles.length || 1;
|
|
225
|
+
return `<div class="vz-pop vz-pop-more" data-esc-layer="1" role="menu" aria-label="More">`
|
|
226
|
+
+ `<span class="vz-pho">${R.issued ? '' : mi('edit', 'pen', 'Edit')}${mi('present', 'play', 'Present')}${mi('share', 'share', 'Share')}${mi('brief', 'brief', 'Brief')}<hr></span>`
|
|
227
|
+
+ `<p class="vz-lab">Download</p><div class="vz-fmts">${fmt('pptx', 'PPTX')}${fmt('docx', 'DOCX')}${fmt('pdf', 'PDF')}${fmt('xlsx', 'XLSX')}${fmt('csv', 'CSV')}${fmt('md', 'MD')}</div>`
|
|
228
|
+
+ `<p class="vz-note vz-padmi">Slides as PowerPoint, words as Word or Markdown, tables as Excel or CSV. PDF keeps the look.</p>`
|
|
229
|
+
+ mi('print', 'print', 'Print') + `<button type="button" class="vz-mi vz-hv" role="menuitem" data-r="cycm">${ic('hist')}<span class="vz-grow">Versions</span><small class="vz-note">${n} ${n === 1 ? 'cycle' : 'cycles'}</small></button><hr>`
|
|
230
|
+
+ (R.issued ? mi(R.archived ? 'unarchive' : 'archive', 'box', R.archived ? 'Bring back' : 'Archive…') : `<button type="button" class="vz-mi vz-hv" role="menuitem" data-r="discard" data-k="bad">${ic('bin')}Discard this draft…</button>`) + '</div>';
|
|
231
|
+
}
|
|
232
|
+
const mi = (a, i, l) => `<button type="button" class="vz-mi vz-hv" role="menuitem" data-r="${a}">${ic(i)}${esc(l)}</button>`;
|
|
233
|
+
function insPop() {
|
|
234
|
+
return `<div class="vz-pop vz-pop-ins" data-esc-layer="1" role="menu" aria-label="Insert">${[['text', 'Text'], ['img', 'Image'], ['chart', 'Chart'], ['table', 'Table'], ['shape', 'Shape']].map(([k, l]) => `<button type="button" class="vz-mi vz-hv" role="menuitem" data-r="ed|${k}">${esc(l)}</button>`).join('')}</div>`;
|
|
235
|
+
}
|
|
236
|
+
const dayOf = (iso) => { const t = new Date(iso); return Number.isFinite(t.getTime()) ? MONS[t.getMonth()] + ' ' + t.getDate() : ''; };
|
|
237
|
+
function sharePop() {
|
|
238
|
+
const S = R.shr;
|
|
239
|
+
const base = String(R.row.path).split('/').pop(), mine = (S.list || []).filter((x) => x.name === base || x.name === R.row.path);
|
|
240
|
+
const foot = mine.length ? `<div class="vz-shf">${ic('lock', 14)}<span>${mine.length} ${mine.length === 1 ? 'link' : 'links'} open · ends ${esc(dayOf(mine[0].ends))} · ${mine[0].views ? mine[0].views + (mine[0].views === 1 ? ' view' : ' views') : 'not opened yet'}</span><button type="button" class="vz-link vz-hv" data-r="shoff|${esc(mine[0].id)}">${S.off === mine[0].id ? 'Sure? Turn off' : 'Turn off'}</button></div>` : '';
|
|
241
|
+
const seg = `<div class="vz-sg" role="tablist" aria-label="Share"><button type="button" role="tab" data-r="shtab|link" aria-pressed="${S.tab === 'link'}" aria-selected="${S.tab === 'link'}">Link</button><button type="button" role="tab" data-r="shtab|send" aria-pressed="${S.tab === 'send'}" aria-selected="${S.tab === 'send'}">Send a file</button></div>`;
|
|
242
|
+
let body;
|
|
243
|
+
if (S.tab === 'send') {
|
|
244
|
+
body = canSend() ? `<p class="vz-note">Sends a copy of this cycle's file through this device's share sheet. No link is made.</p><button type="button" class="vz-issue vz-hv vz-center" data-r="shsend">Send a copy</button>`
|
|
245
|
+
: '<p class="vz-note">This device has no share sheet. Download a file from More, then send it yourself.</p>';
|
|
246
|
+
} else if (S.made) {
|
|
247
|
+
body = `<p class="vz-note">Link ready. It ends ${esc(dayOf(S.made.ends))}.${S.made.pass ? ' Send the password in a different message.' : ''}</p><div class="vz-shr"><span>Link</span><code class="vz-pw" data-r="shurl">${esc(S.made.url)}</code></div>`
|
|
248
|
+
+ (S.made.pass ? `<div class="vz-shr"><span>Password</span><code class="vz-pw">${esc(S.made.pass)}</code></div>` : '')
|
|
249
|
+
+ `<button type="button" class="vz-issue vz-hv vz-center" data-r="shcopy">${S.copied ? esc(S.copied) : S.made.pass ? 'Copy link and password' : 'Copy link'}</button>`;
|
|
250
|
+
} else {
|
|
251
|
+
body = `<p class="vz-note">A read-only copy of this cycle as it is now. Later edits are not shared.</p>`
|
|
252
|
+
+ `<div class="vz-shr"><span>Ends in</span><div class="vz-sg vz-ends" role="group" aria-label="Ends in">${[1, 7, 30].map((d) => `<button type="button" data-r="shdays|${d}" aria-pressed="${S.days === d}">${d === 1 ? '1 day' : d + ' days'}</button>`).join('')}</div></div>`
|
|
253
|
+
+ `<div class="vz-shr"><span>Password</span>${S.pw ? `<input class="vz-pw vz-bare" data-r="shpass" aria-label="Password" spellcheck="false" autocomplete="off" value="${esc(S.pass)}">${ib('shnew', ic('redo2', 16), 'Make a new password', { cls: ' vz-small' })}${ib('shnopw', ic('x', 16), 'No password', { cls: ' vz-small' })}` : `<span class="vz-note vz-grow">None: anyone with the link can read it.</span><button type="button" class="vz-link vz-hv" data-r="shpw">Add one</button>`}</div>`
|
|
254
|
+
+ (S.err ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(S.err)}</p>` : '')
|
|
255
|
+
+ `<button type="button" class="vz-issue vz-hv vz-center" data-r="shmake"${S.busy ? ' disabled' : ''}>${S.busy ? 'Making the link…' : 'Create link'}</button>`;
|
|
256
|
+
}
|
|
257
|
+
return `<div class="vz-pop vz-pop-share" data-esc-layer="1" role="dialog" aria-label="Share">${seg}${body}${foot}</div>`;
|
|
258
|
+
}
|
|
259
|
+
function canSend() {
|
|
260
|
+
try { return typeof navigator !== 'undefined' && !!navigator.share && !!navigator.canShare && navigator.canShare({ files: [new File([R.text || ''], fileName(), { type: 'text/markdown' })] }); } catch { return false; }
|
|
261
|
+
}
|
|
262
|
+
const fileName = () => String(R.row.path).split('/').slice(-2).join('-') || 'report.md';
|
|
263
|
+
function confHtml() {
|
|
264
|
+
if (R.conf) {
|
|
265
|
+
const C = R.checks;
|
|
266
|
+
const list = !C ? '<li><span>…</span><span>Checking the sources, the sections and the figures.</span></li>'
|
|
267
|
+
: !C.ok ? `<li data-ok="false"><span>!</span><span>The checks could not run: ${esc(C.error || 'no answer')}</span></li>`
|
|
268
|
+
: C.checks.map((c) => `<li data-ok="${!!c.ok}"><span>${c.ok ? '<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>' : '!'}</span><span>${esc(c.text)}</span></li>`).join('');
|
|
269
|
+
return `<div class="vz-conf" role="group" aria-label="Issue this cycle"><b class="vz-w600">Issue the ${esc(shortSlot(R.row.slot || R.row.date))} cycle?</b><ul>${list}</ul><p class="vz-note">Issuing freezes the words and the look. Nothing is sent: you share it yourself.</p>`
|
|
270
|
+
+ (R.issueErr ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(R.issueErr)}</p>` : '')
|
|
271
|
+
+ `<div><button type="button" class="vz-issue vz-hv vz-h36" data-r="issueok"${R.busy ? ' disabled' : ''}>${ic('check', 16)}Issue it</button><button type="button" class="vz-sec2 vz-hv vz-h36" data-r="issueno"${R.busy ? ' disabled' : ''}>Not yet</button></div></div>`;
|
|
272
|
+
}
|
|
273
|
+
if (R.ask) {
|
|
274
|
+
const T = { discard: ['Discard this draft? The file is deleted. Issued reports are not touched.', 'Discard', 'Keep it', 'Discard confirm'],
|
|
275
|
+
archive: ['Archive this report? It is kept for good and moved to the end of the Reports list.', 'Archive', 'Cancel', 'Archive confirm'] }[R.ask];
|
|
276
|
+
return `<div class="vz-ask2" role="group" aria-label="${esc(T[1])}"><span>${esc(T[0])} ${WAIT(T[3])}</span>${R.askErr ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(R.askErr)}</p>` : ''}<div><button type="button" class="vz-issue vz-hv vz-h36" data-r="askok"${R.ask === 'discard' ? ' data-k="bad"' : ''}${R.busy ? ' disabled' : ''}>${esc(T[1])}</button><button type="button" class="vz-sec2 vz-hv vz-h36" data-r="askno">${esc(T[2])}</button></div></div>`;
|
|
277
|
+
}
|
|
278
|
+
return '';
|
|
124
279
|
}
|
|
125
280
|
function deckHtml() {
|
|
126
281
|
const L = slides();
|
|
127
|
-
if (!L.length) return '<p class="
|
|
282
|
+
if (!L.length) return '<p class="vz-empty">This cycle has no slides. Read it as a page.</p>';
|
|
128
283
|
const i = R.i = Math.max(0, Math.min(R.i, L.length - 1));
|
|
129
|
-
return `<div class="
|
|
130
|
-
+ `<div class="
|
|
131
|
-
+ `<div class="
|
|
284
|
+
return `<div class="vz-slide" tabindex="0" role="group" aria-roledescription="slide" aria-label="Slide ${i + 1} of ${L.length}: ${esc(L[i].h)}. Use the arrow keys to change slide." data-r="slide">${slideCard(L[i])}</div>`
|
|
285
|
+
+ `<div class="vz-snav"><b>Slides</b><span class="vz-sp"></span>${ib('prev', ic('prev', 16), 'Previous slide', { cls: ' vz-small', off: i === 0 })}<span aria-live="polite">${i + 1} of ${L.length}</span>${ib('next', ic('next', 16), 'Next slide', { cls: ' vz-small', off: i === L.length - 1 })}</div>`
|
|
286
|
+
+ `<div class="vz-thumbs" role="group" aria-label="Slides">${L.map((x, j) => `<button type="button" class="vz-th vz-hv" data-r="go|${j}"${j === i ? ' aria-current="true"' : ''} aria-label="Slide ${j + 1}: ${esc(x.h)}"><span>${j === i || x.k === 'frame' ? slideCard(x, true) : ''}</span><span>${j + 1} · ${esc(x.h)}</span></button>`).join('')}</div>`;
|
|
132
287
|
}
|
|
133
288
|
function pageHtml() {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
289
|
+
if (R.cyc) return `<div class="vz-pagefr">${frame(R.cyc.style, R.cyc.body, '', 'The report as a page')}</div>`;
|
|
290
|
+
const w = R.W || { title: R.name, sections: [] };
|
|
291
|
+
return `<article class="vz-page"><h2>${esc(w.title)}</h2>${w.sections.map((x) => `<h4>${esc(x.h)}</h4>${slideHtml(x.lines)}`).join('')}</article>`;
|
|
292
|
+
}
|
|
293
|
+
function bodyHtml() {
|
|
294
|
+
if (R.edit) {
|
|
295
|
+
const SS = slideState(), n = SS ? SS.deck.slides.length : slides().length, at = SS ? SS.i : R.i;
|
|
296
|
+
return `<div class="vz-rpb">${R.msg ? `<p class="vz-msg" role="status" data-tone="${R.msg.tone || ''}">${esc(R.msg.text)}</p>` : ''}`
|
|
297
|
+
+ (R.view === 'deck' && !R.noTip ? `<p class="vz-tip"><span>${tipText(at, n)}</span>${ib('notip', ic('x', 14), 'Hide this tip', { cls: ' vz-small' })}</p>` : '')
|
|
298
|
+
+ (R.view === 'deck' ? '' : `<div class="vz-r1">${WAIT('Page editor')}</div>`) + '<div class="vz-ed" data-vz-ed></div></div>';
|
|
138
299
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function
|
|
146
|
-
if (R.
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
function statusHtml() {
|
|
161
|
-
return `<span class="chp rdst ${R.issued ? 'ok' : 'warn'}"><i></i>${R.issued ? (R.archived ? 'Archived' : 'Issued') : 'Draft'}${R.edit ? ' · editing' : ''}</span>${R.edit ? '' : schedHtml()}`;
|
|
162
|
-
}
|
|
163
|
-
/** The schedule chip: the template's schedule in a few words, and its choices in a menu. Off is the template paused: nothing drafts it. */
|
|
164
|
-
const curSched = () => R.setup ? (R.setup.status === 'paused' ? 'off' : R.setup.schedule) : null;
|
|
165
|
-
function schedShort(s) {
|
|
166
|
-
if (!s || s === 'off') return 'Off';
|
|
167
|
-
const t = s.time || '09:00';
|
|
168
|
-
return s.cadence === 'daily' ? 'Daily ' + t : s.cadence === 'monthly' ? 'Day ' + (s.dayOfMonth || 1) + ' ' + t : (s.cadence === 'bi-weekly' ? '2 wk ' : '') + (s.day || 'Mon') + ' ' + t;
|
|
169
|
-
}
|
|
170
|
-
function schedHtml() {
|
|
171
|
-
if (R.setup === undefined) return '';
|
|
172
|
-
const cur = curSched(), words = R.setup ? schedWords(cur) : 'none';
|
|
173
|
-
const chip = `<button type="button" class="chp rdsch" data-rr="sched" aria-haspopup="menu" aria-expanded="${!!R.sOpen}" aria-label="Schedule: ${esc(words)}. Change it" title="Schedule: ${esc(words)}"${R.busy ? ' disabled' : ''}>${CLK}<b>${esc(R.setup ? schedShort(cur) : 'None')}</b></button>`;
|
|
174
|
-
if (!R.sOpen) return `<span class="dsvw">${chip}</span>`;
|
|
175
|
-
let menu;
|
|
176
|
-
if (R.setup) {
|
|
177
|
-
const days = cur && cur !== 'off' && (cur.cadence === 'weekly' || cur.cadence === 'bi-weekly')
|
|
178
|
-
? `<div class="rdsd" role="group" aria-label="Day">${DAYS.map((d) => `<button type="button" data-rr="sday|${d}" aria-pressed="${cur.day === d}">${d}</button>`).join('')}</div>` : '';
|
|
179
|
-
const now = R.setup.source === 'work' && cur !== 'off' ? `<hr><button type="button" role="menuitem" data-rr="draftnow">${SEND}<span>Draft the next cycle now<small>A background run writes it from the saved structure.</small></span></button>` : '';
|
|
180
|
-
menu = schedChoices(cur).map((c, i) => `<button type="button" role="menuitemradio" aria-checked="${schedWords(c) === schedWords(cur)}" data-rr="spick|${i}">${esc(schedWords(c))}${schedWords(c) === schedWords(cur) ? CHK : ''}</button>`).join('')
|
|
181
|
-
+ days + '<p class="note rpmn">Off pauses it: nothing drafts it until you pick a schedule again.</p>' + now;
|
|
182
|
-
} else {
|
|
183
|
-
const say = 'Make "' + R.name + '" a report that is drafted every week';
|
|
184
|
-
menu = `<p class="note rpmn">This report has no template, so nothing drafts it on a schedule. Say in a chat how often it should be drafted, then press Set it up.</p><a role="menuitem" data-rr-chat href="/premium-chat.html?say=${esc(encodeURIComponent(say))}">${SEND}<span>Set up a schedule in a chat</span></a>`;
|
|
300
|
+
return `<div class="vz-rpb">${confHtml()}${R.msg ? `<p class="vz-msg" role="status" data-tone="${R.msg.tone || ''}">${esc(R.msg.text)}</p>` : ''}`
|
|
301
|
+
+ (R.pop === 'brief' ? `<div class="vz-ask2"><div><b>Brief</b><span class="vz-sp"></span>${ib('pop|', ic('x', 14), 'Close the brief', { cls: ' vz-small' })}</div>${placeholderHtml('Report brief', 'How this report is made: its sources, sections and look.')}</div>` : '')
|
|
302
|
+
+ (R.err ? `<p class="vz-msg" data-tone="bad" role="alert">The document could not be read: ${esc(R.err)}</p>` : !R.W ? '<p class="vz-empty" role="status">Reading the report.</p>' : R.view === 'deck' ? deckHtml() : pageHtml()) + '</div>';
|
|
303
|
+
}
|
|
304
|
+
const tipText = (i, n) => `Slide ${i + 1} of ${n}. Click an item to change it; double-click text to type.`;
|
|
305
|
+
/** The editor's slide and its undo history changed: the tip and the dimmed Undo and Redo follow it. */
|
|
306
|
+
function edState(S) {
|
|
307
|
+
const b = bodyEl(); if (!b || !R || !R.edit) return;
|
|
308
|
+
const t = b.querySelector('.vz-tip > span'); if (t) t.textContent = tipText(S.i, S.deck.slides.length);
|
|
309
|
+
const u = b.querySelector('[data-r="ed|undo"]'), r = b.querySelector('[data-r="ed|redo"]');
|
|
310
|
+
if (u) u.classList.toggle('vz-dim', !S.hist.length); if (r) r.classList.toggle('vz-dim', !S.fut.length);
|
|
311
|
+
}
|
|
312
|
+
/** The whole panel as html. */
|
|
313
|
+
export function panelHtml() { return `<div class="vz vz-rp0" data-view="${R.view}"${R.edit ? ' data-edit' : ''}><div class="vz-rph">${chipsHtml()}${toolHtml()}</div>${bodyHtml()}</div>`; }
|
|
314
|
+
|
|
315
|
+
const bodyEl = () => (R && vCur() && vCur().id === R.vid ? document.querySelector('#czViewer .cz-vw-body') : null);
|
|
316
|
+
function draw() {
|
|
317
|
+
const b = bodyEl(); if (!b) return;
|
|
318
|
+
if (R.edit) { // the editor keeps its own DOM: only the head and the message are drawn again
|
|
319
|
+
const ed = b.querySelector('[data-vz-ed]');
|
|
320
|
+
if (ed && ed.dataset.mounted) { const h = b.querySelector('.vz-rph'); if (h) h.innerHTML = chipsHtml() + toolHtml(); const m = b.querySelector('.vz-rpb > .vz-msg'); if (m) m.remove(); if (R.msg) b.querySelector('.vz-rpb').insertAdjacentHTML('afterbegin', `<p class="vz-msg" role="status" data-tone="${R.msg.tone || ''}">${esc(R.msg.text)}</p>`); return; }
|
|
185
321
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
function
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
322
|
+
const ae = document.activeElement, keep = ae && b.contains(ae) ? ae.getAttribute('data-r') : null;
|
|
323
|
+
b.innerHTML = panelHtml();
|
|
324
|
+
wire(b);
|
|
325
|
+
fit(b);
|
|
326
|
+
if (keep) { const k = b.querySelector(`[data-r="${CSS.escape(keep)}"]`); if (k) k.focus(); }
|
|
327
|
+
if (R.edit) mountEditor();
|
|
328
|
+
}
|
|
329
|
+
function wire(b) {
|
|
330
|
+
b.onclick = (e) => {
|
|
331
|
+
const t = e.target.closest('[data-r]');
|
|
332
|
+
if (!t) { if (R.pop && R.pop !== 'brief' && !e.target.closest('.vz-pop')) { R.pop = null; draw(); } return; }
|
|
333
|
+
if (t.disabled || t.tagName === 'INPUT' || t.tagName === 'SELECT') return;
|
|
334
|
+
if (t.tagName === 'A' && t.dataset.r.startsWith('dl|')) { R.pop = null; setTimeout(draw, 0); return; }
|
|
335
|
+
e.preventDefault(); act(t.dataset.r.split('|'), t);
|
|
336
|
+
};
|
|
337
|
+
b.onchange = (e) => { if (e.target.dataset.r === 'stime') R.sch.time = e.target.value || '09:00'; };
|
|
338
|
+
b.oninput = (e) => { if (e.target.dataset.r === 'shpass') R.shr.pass = e.target.value; };
|
|
339
|
+
b.onkeydown = (e) => {
|
|
340
|
+
if (e.key === 'Escape' && R.pop) { e.preventDefault(); e.stopPropagation(); R.pop = null; draw(); return; }
|
|
341
|
+
if (!R.edit && R.view === 'deck' && /^Arrow(Left|Right)$/.test(e.key) && !e.target.closest('input')) { const L = slides().length, j = R.i + (e.key === 'ArrowRight' ? 1 : -1); if (j >= 0 && j < L) { e.preventDefault(); R.i = j; draw(); const s = bodyEl().querySelector('.vz-slide'); if (s) s.focus(); } }
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/* a 1280 x 720 frame scales to its slide's width */
|
|
345
|
+
const RO = typeof ResizeObserver === 'function' ? new ResizeObserver((es) => { for (const e of es) scaleOf(e.target, e.contentRect.width); }) : null;
|
|
346
|
+
function scaleOf(el, w) { if (w) el.style.setProperty('--rp-scale', String(Math.round((w / W) * 10000) / 10000)); }
|
|
347
|
+
export function fit(root) { root.querySelectorAll('.vz-fr').forEach((c) => { if (RO) RO.observe(c); scaleOf(c, c.getBoundingClientRect().width); }); }
|
|
348
|
+
|
|
349
|
+
/* ── the presses ── */
|
|
350
|
+
const say = (text, tone) => { R.msg = { text, tone }; draw(); };
|
|
351
|
+
async function act([k, v], t) {
|
|
352
|
+
if (k === 'pop') { R.pop = v || null; return draw(); }
|
|
353
|
+
if (k === 'view') { if (R.view === v) return; R.view = v; R.pop = null; const ed = R.edit && bodyEl() && bodyEl().querySelector('[data-vz-ed]'); if (ed) delete ed.dataset.mounted; return draw(); }
|
|
354
|
+
if (k === 'cycm') { R.pop = R.pop === 'cyc' ? null : 'cyc'; return draw(); }
|
|
355
|
+
if (k === 'cyc') { const row = R.cycles.find((x) => x.path === v); R.pop = null; if (row && row.path !== R.row.path) return openReport(row, R.hand); return draw(); }
|
|
356
|
+
if (k === 'sched') { if (R.pop !== 'sched') { R.sch = schedPick(R.setup); R.schErr = ''; } R.pop = R.pop === 'sched' ? null : 'sched'; return draw(); }
|
|
357
|
+
if (k === 'scad') { R.sch.cad = v; return draw(); }
|
|
358
|
+
if (k === 'sday') { R.sch.day = v; return draw(); }
|
|
359
|
+
if (k === 'sgo') return schedIt(schedOf(R.sch));
|
|
360
|
+
if (k === 'soff') return schedIt('off');
|
|
361
|
+
if (k === 'brief') { R.pop = R.pop === 'brief' ? null : 'brief'; return draw(); }
|
|
362
|
+
if (k === 'more') { R.pop = R.pop === 'more' ? null : 'more'; return draw(); }
|
|
363
|
+
if (k === 'share') { if (R.pop !== 'share') openShare(); else { R.pop = null; draw(); } return; }
|
|
364
|
+
if (k === 'prev' || k === 'next') { R.i += k === 'next' ? 1 : -1; return draw(); }
|
|
365
|
+
if (k === 'go') { R.i = +v; return draw(); }
|
|
366
|
+
if (k === 'md') { R.pop = null; saveMd(); return draw(); }
|
|
367
|
+
if (k === 'pdf' || k === 'print') { R.pop = null; draw(); return printIt(); }
|
|
368
|
+
if (k === 'present') { R.pop = null; draw(); return present(true); }
|
|
369
|
+
if (k === 'issue') { R.conf = !R.conf; R.ask = ''; R.issueErr = ''; R.pop = null; draw(); if (R.conf) readChecks(); return; }
|
|
370
|
+
if (k === 'issueno') { R.conf = false; R.issueErr = ''; return draw(); }
|
|
371
|
+
if (k === 'issueok') return issueIt();
|
|
372
|
+
if (k === 'discard' || k === 'archive') { R.ask = k; R.askErr = ''; R.conf = false; R.pop = null; return draw(); }
|
|
373
|
+
if (k === 'askno') { R.ask = ''; return draw(); }
|
|
374
|
+
if (k === 'askok') return lifeIt(R.ask);
|
|
375
|
+
if (k === 'unarchive') { R.pop = null; return lifeIt('unarchive'); }
|
|
376
|
+
if (k === 'edit') { if (R.issued) return; R.edit = true; R.pop = null; R.conf = false; R.ask = ''; R.msg = null; return draw(); }
|
|
377
|
+
if (k === 'notip') { R.noTip = true; const p = t.closest('.vz-tip'); if (p) p.remove(); return; }
|
|
378
|
+
if (k === 'ins') { R.pop = R.pop === 'ins' ? null : 'ins'; return draw(); }
|
|
379
|
+
if (k === 'ed') { R.pop = null; draw(); const b = bodyEl() && bodyEl().querySelector(`[data-vz-ed] [data-c="${v}"]`); if (b) b.click(); return; }
|
|
380
|
+
if (k === 'edcancel') return editCancel();
|
|
381
|
+
if (k === 'edsave') return editSave();
|
|
382
|
+
if (k.startsWith('sh')) return shareAct(k, v);
|
|
232
383
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
R.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
toast('The draft is discarded.'); if (R.onChange) R.onChange();
|
|
244
|
-
const rest = R.cycles.filter((x) => x.path !== R.row.path);
|
|
245
|
-
if (rest.length) openReport(rest[0], { ...R.hand, cycles: rest }); else closeDlg();
|
|
246
|
-
return;
|
|
384
|
+
|
|
385
|
+
/* ── schedule ── */
|
|
386
|
+
async function schedIt(s) {
|
|
387
|
+
if (!s || R.busy) return;
|
|
388
|
+
const me = R; R.busy = true; R.schErr = ''; draw();
|
|
389
|
+
let r;
|
|
390
|
+
if (R.setup) r = await pmPost('/api/report-setups/edit', { ws: R.ws, id: R.setup.id, schedule: s === 'off' ? { cadence: 'off' } : s }).catch(() => null);
|
|
391
|
+
else {
|
|
392
|
+
const w = R.W || { sections: [] };
|
|
393
|
+
r = await pmPost('/api/report-setups/setup', { ws: R.ws, proposal: { name: String(R.name).slice(0, 80), purpose: ('Drafted on a schedule from ' + R.row.path).slice(0, 400), audience: R.audience || 'Me', output: 'pdf', schedule: s, sections: w.sections.map((x) => x.h.slice(0, 60)).slice(0, 12) } }).catch(() => null);
|
|
247
394
|
}
|
|
248
|
-
R.archived = archived; R.row = { ...R.row, archived };
|
|
249
|
-
R.cycles = R.cycles.map((x) => x.path === R.row.path ? { ...x, archived } : x);
|
|
250
|
-
toast(archived ? 'Archived. It is kept, at the end of the Reports list.' : 'It is back in the Reports list.');
|
|
251
|
-
draw();
|
|
252
|
-
if (R.onChange) R.onChange();
|
|
253
|
-
}
|
|
254
|
-
async function setSched(s) {
|
|
255
|
-
if (!R.setup || R.busy) return;
|
|
256
|
-
const me = R;
|
|
257
|
-
R.busy = true; R.sOpen = false; draw();
|
|
258
|
-
const r = await pmPost('/api/report-setups/edit', { ws: R.ws, id: R.setup.id, schedule: s === 'off' ? { cadence: 'off' } : s }).catch(() => null);
|
|
259
395
|
if (R !== me) return;
|
|
260
396
|
R.busy = false;
|
|
261
|
-
if (!r || r.ok !== true) {
|
|
262
|
-
R.setup = r.setup;
|
|
263
|
-
|
|
264
|
-
draw();
|
|
397
|
+
if (!r || r.ok !== true) { R.schErr = 'The schedule did not change: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'; return draw(); }
|
|
398
|
+
R.setup = r.setup || R.setup; R.pop = null;
|
|
399
|
+
say(s === 'off' ? 'It is no longer drafted on a schedule.' : 'Scheduled: ' + schedLabel(R.setup) + '. Nothing is sent until you issue a cycle.');
|
|
265
400
|
if (R.onChange) R.onChange();
|
|
266
401
|
}
|
|
267
402
|
async function readSetup() {
|
|
268
403
|
const me = R;
|
|
269
404
|
const j = await Promise.resolve(pmGet('/api/report-setups?' + q({ ws: R.ws }))).catch(() => null);
|
|
270
405
|
if (R !== me) return;
|
|
271
|
-
R.setup = j && Array.isArray(j.setups) ? j.setups.find((x) => x.id === R.
|
|
406
|
+
R.setup = j && Array.isArray(j.setups) ? j.setups.find((x) => x.id === R.id) || null : null;
|
|
407
|
+
if (R.setup && R.setup.audience) R.audience = R.setup.audience;
|
|
408
|
+
if (R.setup && R.setup.name && !R.hand.name) R.name = R.setup.name;
|
|
272
409
|
}
|
|
273
|
-
|
|
410
|
+
|
|
411
|
+
/* ── issue ── */
|
|
412
|
+
export const cycleOf = (row) => {
|
|
274
413
|
const m = /reports\/([a-z][a-z0-9-]{0,39})\/(\d{4}-\d{2}-\d{2})\.md$/.exec(String(row.path || ''));
|
|
275
414
|
return { cadence: row.cadence || (m && m[1]) || '', slot: row.slot || (m && m[2]) || '' };
|
|
276
415
|
};
|
|
416
|
+
async function readChecks() {
|
|
417
|
+
const me = R; R.checks = null;
|
|
418
|
+
const c = await Promise.resolve(pmGet('/api/viewer-report/checks?' + q({ ws: R.ws, path: R.row.path, slot: R.row.slot }))).catch(() => null);
|
|
419
|
+
if (R !== me) return;
|
|
420
|
+
R.checks = c && c.ok ? c : { ok: false, error: (c && c.error) || 'no answer' }; draw();
|
|
421
|
+
}
|
|
277
422
|
async function issueIt() {
|
|
423
|
+
if (R.busy) return;
|
|
278
424
|
const me = R, c = cycleOf(R.row);
|
|
279
|
-
if (!c.cadence || !c.slot) { R.issueErr = 'This document is not a report cycle, so it cannot be issued.'; draw();
|
|
425
|
+
if (!c.cadence || !c.slot) { R.issueErr = 'This document is not a report cycle, so it cannot be issued.'; return draw(); }
|
|
280
426
|
R.busy = true; R.issueErr = ''; draw();
|
|
281
427
|
const cur = await Promise.resolve(pmGet('/api/report/draft?' + q({ ws: R.ws, cadence: c.cadence, slot: c.slot }))).catch(() => null);
|
|
282
428
|
if (R !== me) return;
|
|
283
|
-
if (!cur || !cur.ok || !cur.exists || !cur.sha) { R.busy = false; R.issueErr = (cur && cur.error) || 'The report was not issued: the file could not be read.'; draw();
|
|
284
|
-
if (cur.markdown != null && R.text && cur.markdown !== R.text) {
|
|
285
|
-
|
|
286
|
-
}
|
|
429
|
+
if (!cur || !cur.ok || !cur.exists || !cur.sha) { R.busy = false; R.issueErr = (cur && cur.error) || 'The report was not issued: the file could not be read.'; return draw(); }
|
|
430
|
+
if (cur.markdown != null && R.text && cur.markdown !== R.text) { R.text = cur.markdown; R.W = wordsOf(R.text, R.name); R.busy = false; R.issueErr = 'The file changed since you opened it. It is shown again now; read it, then press Issue it.'; return draw(); }
|
|
431
|
+
if (!R.ws && cur.ws) R.ws = cur.ws; // the draft read names the workspace when the page was opened without one
|
|
287
432
|
const r = await pmPost('/api/report/issue', { ws: R.ws, cadence: c.cadence, slot: c.slot, sha: cur.sha }).catch(() => null);
|
|
288
433
|
if (R !== me) return;
|
|
289
434
|
R.busy = false;
|
|
290
|
-
if (!r || r.ok !== true) { R.issueErr = (r && r.status === 409) || (r && /changed/i.test(r.error || '')) ? 'The file changed since you opened it. Close and open it again, then issue it.' : (r && r.error) || 'The report was not issued.'; draw();
|
|
435
|
+
if (!r || r.ok !== true) { R.issueErr = (r && r.status === 409) || (r && /changed/i.test(r.error || '')) ? 'The file changed since you opened it. Close and open it again, then issue it.' : (r && r.error) || 'The report was not issued.'; return draw(); }
|
|
291
436
|
R.issued = true; R.conf = false; R.row = { ...R.row, state: 'issued' };
|
|
292
|
-
R.cycles = R.cycles.map((x) => x.path === R.row.path ? { ...x, state: 'issued' } : x);
|
|
293
|
-
|
|
294
|
-
toast('Issued and frozen. Nothing was sent to anyone.');
|
|
295
|
-
sayA('Issued. This cycle is frozen as you read it. PMOS sends nothing; share it yourself.');
|
|
296
|
-
draw();
|
|
437
|
+
R.cycles = R.cycles.map((x) => (x.path === R.row.path ? { ...x, state: 'issued' } : x));
|
|
438
|
+
say('Issued and frozen. Nothing was sent to anyone; share it yourself.');
|
|
297
439
|
if (R.onIssue) R.onIssue(R.row);
|
|
298
440
|
}
|
|
299
|
-
function
|
|
300
|
-
if (
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
441
|
+
async function lifeIt(k) {
|
|
442
|
+
if (R.busy) return;
|
|
443
|
+
const me = R; R.busy = true; R.askErr = ''; draw();
|
|
444
|
+
const archived = k === 'archive';
|
|
445
|
+
const r = await pmPost('/api/report-documents/' + (k === 'discard' ? 'discard' : 'archive'), k === 'discard' ? { ws: R.ws, path: R.row.path } : { ws: R.ws, path: R.row.path, archived }).catch(() => null);
|
|
446
|
+
if (R !== me) return;
|
|
447
|
+
R.busy = false;
|
|
448
|
+
if (!r || r.ok !== true) { R.askErr = (k === 'discard' ? 'The draft was not discarded: ' : 'Nothing changed: ') + ((r && r.error) || 'the page could not reach PMOS') + '.'; if (!R.ask) R.msg = { text: R.askErr, tone: 'bad' }; return draw(); }
|
|
449
|
+
R.ask = '';
|
|
450
|
+
if (k === 'discard') {
|
|
451
|
+
if (R.onChange) R.onChange();
|
|
452
|
+
const rest = R.cycles.filter((x) => x.path !== R.row.path);
|
|
453
|
+
if (rest.length) return openReport(rest[0], { ...R.hand, cycles: rest });
|
|
454
|
+
const b = bodyEl(); if (b) b.innerHTML = '<div class="vz"><p class="vz-empty" role="status">The draft is discarded.</p></div>';
|
|
308
455
|
return;
|
|
309
456
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (
|
|
457
|
+
R.archived = archived; R.row = { ...R.row, archived };
|
|
458
|
+
R.cycles = R.cycles.map((x) => (x.path === R.row.path ? { ...x, archived } : x));
|
|
459
|
+
say(archived ? 'Archived. It is kept, at the end of the Reports list.' : 'It is back in the Reports list.');
|
|
460
|
+
if (R.onChange) R.onChange();
|
|
314
461
|
}
|
|
315
|
-
/* a 1280 x 720 frame scales to its card's width */
|
|
316
|
-
const RO = typeof ResizeObserver === 'function' ? new ResizeObserver((es) => { for (const e of es) scaleOf(e.target, e.contentRect.width); }) : null;
|
|
317
|
-
function scaleOf(card, w) { if (w) card.style.setProperty('--rp-scale', String(Math.round((w / W) * 10000) / 10000)); }
|
|
318
|
-
export function fit(root) { root.querySelectorAll('.rdfc').forEach((c) => { if (RO) RO.observe(c); scaleOf(c, c.getBoundingClientRect().width); }); }
|
|
319
462
|
|
|
320
|
-
/* ── the
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (R.issued) { sayA('This cycle is issued, so its look is frozen. Nothing changed.'); return; }
|
|
331
|
-
if (R.busy || (R.design && R.design.running)) { sayA('PMOS is still working on the last change. Wait for its answer, then try again.'); return; }
|
|
332
|
-
const line = sayA('PMOS is working on it.');
|
|
333
|
-
R.busy = true; draw();
|
|
334
|
-
if (R.design && !R.design.description) { const d = await pmPost('/api/report-design/describe', { ws: R.ws, id: R.id, text: t }).catch((x) => ({ ok: false, error: String(x && x.message || x) })); if (!d || d.ok !== true) return answer(line, (d && d.error) || 'The description could not be saved.'); }
|
|
335
|
-
const r = await pmPost('/api/report-design/turn', { ws: R.ws, id: R.id, text: t }).catch((x) => ({ ok: false, error: String(x && x.message || x) }));
|
|
336
|
-
if (!r || r.ok !== true) return answer(line, 'Nothing changed: ' + ((r && r.error) || 'the change could not start.'));
|
|
337
|
-
const before = (R.design && R.design.log || []).length;
|
|
338
|
-
const d = await settle();
|
|
339
|
-
if (!d) return answer(line, 'PMOS did not answer in time. The design is read again when you open the report.');
|
|
340
|
-
const L = (d.log || []).slice(before).filter((x) => x.kind === 'version' || x.kind === 'error');
|
|
341
|
-
const last = L[L.length - 1];
|
|
342
|
-
if (last && last.kind === 'version' && last.version) { R.noLook = null; await showVersion(last.version); return answer(line, last.text + ' It is shown in the report. Press Use it to keep it, or Keep current.'); }
|
|
343
|
-
return answer(line, last ? 'The change did not work: ' + last.text : 'PMOS ended without a new version.');
|
|
344
|
-
}
|
|
345
|
-
function answer(line, t) { R.busy = false; if (line) line.textContent = t; else sayA(t); draw(); refreshBrief(); }
|
|
346
|
-
/* read the design again until no job runs */
|
|
347
|
-
async function settle() {
|
|
348
|
-
const t0 = Date.now();
|
|
349
|
-
for (;;) {
|
|
350
|
-
const d = await readDesign();
|
|
351
|
-
if (!R) return null;
|
|
352
|
-
if (d && !d.running) return d;
|
|
353
|
-
if (Date.now() - t0 > POLL_MAX) return null;
|
|
354
|
-
await new Promise((ok) => setTimeout(ok, POLL_MS));
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
async function readDesign() {
|
|
358
|
-
const j = await Promise.resolve(pmGet('/api/report-design?' + q({ ws: R.ws, id: R.id }))).catch(() => null);
|
|
359
|
-
if (!R) return null;
|
|
360
|
-
if (j && j.ok) { R.design = j.design; R.dErr = ''; } else { R.design = null; R.dErr = (j && j.error) || 'The design of this report could not be read.'; }
|
|
361
|
-
return R.design;
|
|
362
|
-
}
|
|
363
|
-
async function textOf(url) {
|
|
364
|
-
const r = await fetch(url, { credentials: 'same-origin' });
|
|
365
|
-
if (!r.ok) throw new Error((await r.text().catch(() => '')) || 'the workspace did not answer');
|
|
366
|
-
return r.text();
|
|
367
|
-
}
|
|
368
|
-
async function showVersion(n) {
|
|
369
|
-
R.show = n;
|
|
370
|
-
if (!R.ver.has(n)) { try { R.ver.set(n, splitRender(await textOf('/api/report-design/version?' + q({ ws: R.ws, id: R.id, n })))); } catch (x) { toast('D' + n + ' could not be read.'); R.show = 'cycle'; } }
|
|
371
|
-
if (R.view === 'deck' && !slides().length) R.view = 'doc';
|
|
372
|
-
R.i = 0; draw();
|
|
463
|
+
/* ── share (Link | Send a file): POST /api/shares makes a copy of the file as it is now ── */
|
|
464
|
+
async function openShare() {
|
|
465
|
+
const me = R;
|
|
466
|
+
R.pop = 'share'; R.shr = { tab: 'link', pw: true, pass: R.shr && R.shr.pass ? R.shr.pass : '', days: 7, made: null, err: '', busy: false, list: (R.shr && R.shr.list) || [], off: null, copied: '' };
|
|
467
|
+
draw();
|
|
468
|
+
const [l, p] = await Promise.all([pmGet('/api/shares'), R.shr.pass ? null : pmGet('/api/shares/password')]);
|
|
469
|
+
if (R !== me || R.pop !== 'share') return;
|
|
470
|
+
if (l && l.ok) R.shr.list = l.shares || [];
|
|
471
|
+
if (p && p.ok && !R.shr.pass) R.shr.pass = p.password;
|
|
472
|
+
draw();
|
|
373
473
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
474
|
+
async function shareAct(k, v) {
|
|
475
|
+
const S = R.shr, me = R;
|
|
476
|
+
if (k === 'shtab') { S.tab = v; return draw(); }
|
|
477
|
+
if (k === 'shdays') { S.days = +v; return draw(); }
|
|
478
|
+
if (k === 'shnopw') { S.pw = false; return draw(); }
|
|
479
|
+
if (k === 'shpw') { S.pw = true; return draw(); }
|
|
480
|
+
if (k === 'shnew') { const p = await pmGet('/api/shares/password'); if (R !== me) return; if (p && p.ok) S.pass = p.password; return draw(); }
|
|
481
|
+
if (k === 'shoff') {
|
|
482
|
+
if (S.off !== v) { S.off = v; return draw(); }
|
|
483
|
+
const r = await pmPost('/api/shares/off', { id: v }); if (R !== me) return;
|
|
484
|
+
S.off = null; if (r && r.ok) S.list = S.list.filter((x) => x.id !== v); else S.err = (r && r.error) || 'The link could not be turned off.';
|
|
485
|
+
return draw();
|
|
486
|
+
}
|
|
487
|
+
if (k === 'shsend') { try { await navigator.share({ files: [new File([R.text || ''], fileName(), { type: 'text/markdown' })], title: R.name }); R.pop = null; draw(); } catch { /* the PM closed the share sheet */ } return; }
|
|
488
|
+
if (k === 'shmake') {
|
|
489
|
+
if (S.pw && String(S.pass || '').trim().length < 8) { S.err = 'The password needs at least 8 characters.'; return draw(); }
|
|
490
|
+
S.busy = true; S.err = ''; draw();
|
|
491
|
+
const r = await pmPost('/api/shares', { ws: R.ws, path: R.row.path, days: S.days, password: S.pw ? String(S.pass).trim() : null });
|
|
389
492
|
if (R !== me) return;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
493
|
+
S.busy = false;
|
|
494
|
+
if (!r || !r.ok) { S.err = (r && r.error) || 'The link could not be made.'; return draw(); }
|
|
495
|
+
S.made = { url: r.url, ends: r.ends, pass: S.pw ? String(S.pass).trim() : '' };
|
|
496
|
+
const l = await pmGet('/api/shares'); if (R !== me) return; if (l && l.ok) S.list = l.shares || [];
|
|
497
|
+
return draw();
|
|
498
|
+
}
|
|
499
|
+
if (k === 'shcopy') {
|
|
500
|
+
const txt = S.made.url + (S.made.pass ? '\nPassword: ' + S.made.pass : '');
|
|
501
|
+
try { await navigator.clipboard.writeText(txt); S.copied = 'Copied'; } catch { S.copied = 'Select the link and copy it'; }
|
|
502
|
+
return draw();
|
|
393
503
|
}
|
|
394
|
-
if (R !== me) return;
|
|
395
|
-
const last = st && (st.log || []).filter((x) => x.who === 'pmos').pop();
|
|
396
|
-
line.textContent = !st || st.running ? 'PMOS did not answer in time. The brief is read again when you open it.' : (last ? last.text : 'Done.') + (st.current !== st.saved ? ' The Brief shows the new version; press Use it there to keep it.' : '');
|
|
397
|
-
refreshBrief();
|
|
398
504
|
}
|
|
399
505
|
|
|
400
|
-
/* ── the
|
|
401
|
-
async function
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
import('./premium-vw-share.js').then((M) => M.shareMenu(b, { name: R.name + ' · ' + (R.row.date || R.row.slot), ws: R.ws, rel: R.row.path, text: R.text || '' }));
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
if (k === 'issueno') { R.conf = false; R.issueErr = ''; draw(); return; }
|
|
434
|
-
if (k === 'issueok') { if (!R.busy) await issueIt(); return; }
|
|
435
|
-
if (k === 'unsample') { if (!R.busy) await removeSample(v); }
|
|
436
|
-
}
|
|
437
|
-
/** Use it saves the new look as the design (report-design accept); Keep current goes back to the saved look (revert), or, with none saved yet,
|
|
438
|
-
* puts the line away until the next change. */
|
|
439
|
-
async function lookIt(use) {
|
|
440
|
-
const n = newLook(); if (n == null || R.busy) return;
|
|
441
|
-
const me = R;
|
|
442
|
-
if (!use && !(R.design.saved)) { R.noLook = n; R.show = 'cycle'; R.i = 0; draw(); sayA('Kept the current look. The new one stays in the Brief, under Why it looks like this.'); return; }
|
|
506
|
+
/* ── edit: the slide editor or the page editor, mounted in the panel (Waiting for design) ── */
|
|
507
|
+
async function mountEditor() {
|
|
508
|
+
const me = R, b = bodyEl(), host = b && b.querySelector('[data-vz-ed]');
|
|
509
|
+
if (!host || host.dataset.mounted) return;
|
|
510
|
+
host.dataset.mounted = '1';
|
|
511
|
+
const done = async () => { if (R !== me) return; R.edit = false; await reread(); if (R === me) draw(); };
|
|
512
|
+
try {
|
|
513
|
+
if (R.view === 'deck') {
|
|
514
|
+
const m = await import('./premium-vw-slides.js');
|
|
515
|
+
if (R !== me || !host.isConnected) return;
|
|
516
|
+
await m.openSlides({ ws: me.ws, path: me.row.path, title: me.name, readOnly: me.issued, host, onClose: done, onState: (S) => { if (R === me) edState(S); }, onSaved: (text) => { if (R !== me) return; R.text = text; R.W = wordsOf(text, R.name); } });
|
|
517
|
+
} else {
|
|
518
|
+
const m = await import('./premium-vw-doc.js');
|
|
519
|
+
if (R !== me || !host.isConnected) return;
|
|
520
|
+
m.openDocPage({ path: me.row.path, title: me.name + (me.row.slot ? ' · ' + me.row.slot : '') }, { host, ws: () => me.ws, onClose: done });
|
|
521
|
+
}
|
|
522
|
+
} catch (x) { host.innerHTML = placeholderHtml(R.view === 'deck' ? 'Slide editor' : 'Page editor', 'The editor could not start here: ' + String((x && x.message) || x)); }
|
|
523
|
+
}
|
|
524
|
+
const slideState = () => (window.__premiumSlides && R ? window.__premiumSlides.state(R.row.path) : null);
|
|
525
|
+
async function editCancel() {
|
|
526
|
+
const S = slideState();
|
|
527
|
+
if (S && S.dirty && !R.leave) { R.leave = true; return say('The slides have changes that are not saved. Press Cancel again to leave without saving.', 'bad'); }
|
|
528
|
+
R.leave = false; R.msg = null;
|
|
529
|
+
const b = bodyEl(), c = b && b.querySelector('[data-vz-ed] [data-c="close"]');
|
|
530
|
+
if (S && c) { S.dirty = false; c.click(); return; }
|
|
531
|
+
R.edit = false; await reread(); draw();
|
|
532
|
+
}
|
|
533
|
+
async function editSave() {
|
|
534
|
+
const S = slideState(); if (!S || R.busy) return;
|
|
535
|
+
if (!S.dirty) return say('Nothing has changed since the slides were opened.');
|
|
443
536
|
R.busy = true; draw();
|
|
444
|
-
const r = await
|
|
445
|
-
if (R !== me) return;
|
|
537
|
+
const r = await window.__premiumSlides.save(S, 'Edited the slides in the report');
|
|
446
538
|
R.busy = false;
|
|
447
|
-
if (!r || r.ok
|
|
448
|
-
R.
|
|
449
|
-
sayA(use ? 'This look is now the design. ' + (r.redraw && r.redraw.started ? 'PMOS is drawing this cycle to match it.' : 'Each new cycle is drawn to match it.') + ' Earlier looks are listed in the Brief. Nothing is sent.' : 'Kept the current look. The new one stays in the Brief, under Why it looks like this.');
|
|
450
|
-
draw(); refreshBrief();
|
|
451
|
-
if (use && r.redraw && r.redraw.started) { await settle(); if (R !== me) return; await readCycle(); draw(); }
|
|
452
|
-
}
|
|
453
|
-
async function draftNow() {
|
|
454
|
-
const me = R;
|
|
455
|
-
R.busy = true; draw();
|
|
456
|
-
const r = await pmPost('/api/report-setups/draft', { ws: R.ws, id: R.setup.id }).catch(() => null);
|
|
457
|
-
if (R !== me) return;
|
|
458
|
-
R.busy = false; draw();
|
|
459
|
-
if (!r || r.ok !== true) { toast('The next cycle was not drafted: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'); return; }
|
|
460
|
-
toast(r.drafting ? 'Drafting started. The new cycle shows in this report’s cycles when it is written.' : 'Drafted: ' + ((r.drafted && r.drafted.path) || 'the next cycle') + '.');
|
|
461
|
-
if (R.onChange) R.onChange();
|
|
462
|
-
}
|
|
463
|
-
/* ── the Brief: how this report is made, in a viewer tab (premium-report-brief.js) ── */
|
|
464
|
-
function briefCtx() { return { ws: R.ws, id: R.id, name: R.name, issued: R.issued, setup: R.setup, design: R.design, schedWords: schedWords(curSched()), format: R.design && R.design.format,
|
|
465
|
-
correct: (title) => { const inp = $('#rdIn') || $('#askIn'); if (!inp) return; inp.value = 'Correct "' + title + '": '; inp.focus(); },
|
|
466
|
-
goBack: async (n) => { if (!R || R.issued) return; const r = await pmPost('/api/report-design/revert', { ws: R.ws, id: R.id, n }).catch(() => null); if (!r || r.ok !== true) { toast((r && r.error) || 'That look could not be picked.'); return; } R.design = r.design; R.noLook = null; await syncShow(); sayA('That earlier look is shown in the report. Press Use it to keep it, or Keep current.'); refreshBrief(); } }; }
|
|
467
|
-
async function openBrief() { const M = await import('./premium-report-brief.js'); if (R) M.openBrief(briefCtx()); }
|
|
468
|
-
async function refreshBrief() { const M = await import('./premium-report-brief.js'); if (R) M.refreshBrief(briefCtx()); }
|
|
469
|
-
/** Edit in place (PM 2026-10-22): Slides opens the slide editor, Page opens the words, both inside #rdEd. Save or Cancel closes the editor and
|
|
470
|
-
* reads the file again. No viewer tab is opened, so there is one Edit, one Save and one Present for a report. */
|
|
471
|
-
async function mountEditor() {
|
|
472
|
-
const me = R, host = $('#rdEd'); if (!host) return;
|
|
473
|
-
const done = async () => { if (R !== me) return; R.edit = false; await reread(); if (R === me) { $('#oMain').innerHTML = ''; draw(); } };
|
|
474
|
-
if (R.view === 'deck') {
|
|
475
|
-
const m = await import('./premium-vw-slides.js');
|
|
476
|
-
if (R !== me || !host.isConnected) return;
|
|
477
|
-
m.openSlides({ ws: me.ws, path: me.row.path, title: me.name, readOnly: me.issued, host, onClose: done, onSaved: (text) => { if (R !== me) return; R.text = text; R.W = wordsOf(text, R.name); } });
|
|
478
|
-
} else openDocPage({ path: me.row.path, title: me.name + (me.row.slot ? ' · ' + me.row.slot : '') }, { host, ws: () => me.ws, onClose: done });
|
|
539
|
+
if (!r || !r.ok) return say((r && r.error) || 'The slides could not be saved.', 'bad');
|
|
540
|
+
R.edit = false; R.msg = { text: 'Saved. The reason is in the Edit log.' }; await reread(); draw();
|
|
479
541
|
}
|
|
480
542
|
async function reread() {
|
|
481
543
|
const me = R;
|
|
482
|
-
try { const t = await textOf('/api/doc?' + q({ ws: R.ws, path: R.row.path })); if (R === me) { R.text = t; R.W = wordsOf(t, R.name); } } catch { /* the
|
|
544
|
+
try { const t = await textOf('/api/doc?' + q({ ws: R.ws, path: R.row.path })); if (R === me) { R.text = t; R.W = wordsOf(t, R.name); } } catch { /* the panel keeps what it had */ }
|
|
483
545
|
if (R === me) await readCycle();
|
|
484
546
|
}
|
|
547
|
+
|
|
548
|
+
/* ── files ── */
|
|
549
|
+
async function textOf(url) {
|
|
550
|
+
const r = await fetch(url, { credentials: 'same-origin' });
|
|
551
|
+
if (!r.ok) throw new Error((await r.text().catch(() => '')) || 'the workspace did not answer');
|
|
552
|
+
return r.text();
|
|
553
|
+
}
|
|
485
554
|
function saveMd() {
|
|
486
|
-
const name = (
|
|
555
|
+
const name = fileName();
|
|
487
556
|
const u = URL.createObjectURL(new Blob([R.text || ''], { type: 'text/markdown' })), a = document.createElement('a');
|
|
488
557
|
a.href = u; a.download = name; a.setAttribute('data-rr-md', name); document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(u), 3000);
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
async function addSample(file) {
|
|
492
|
-
const ext = (/\.([a-z0-9]+)$/i.exec(file.name) || [])[1], kind = KINDS[String(ext || '').toLowerCase()];
|
|
493
|
-
if (!kind) { toast('A sample is a PDF, PowerPoint, Word, PNG or JPG file.'); return; }
|
|
494
|
-
const data = await new Promise((ok) => { const r = new FileReader(); r.onload = () => ok(String(r.result || '')); r.onerror = () => ok(''); r.readAsDataURL(file); });
|
|
495
|
-
if (!data) { toast('The file could not be read.'); return; }
|
|
496
|
-
const r = await pmPost('/api/report-design/sample', { ws: R.ws, id: R.id, name: file.name, kind, data }).catch((x) => ({ ok: false, error: String(x && x.message || x) }));
|
|
497
|
-
if (!r || r.ok !== true) { sayA('The sample was not added: ' + ((r && r.error) || 'the press did not go through.')); return; }
|
|
498
|
-
await readDesign(); draw(); refreshBrief();
|
|
499
|
-
sayA('Added "' + file.name + '". Tell me what to take from it, and I make the next version follow it.');
|
|
558
|
+
R.msg = { text: 'Saved ' + name + '.' };
|
|
500
559
|
}
|
|
501
|
-
|
|
502
|
-
/** Remove a sample: the next version, the brief and each cycle stop following it. Add the file again to follow it again. */
|
|
503
|
-
async function removeSample(id) {
|
|
504
|
-
const s = ((R.design && R.design.samples) || []).find((x) => x.id === id);
|
|
505
|
-
if (!s) return;
|
|
506
|
-
R.busy = true; draw();
|
|
507
|
-
const r = await pmPost('/api/report-design/unsample', { ws: R.ws, id: R.id, sample: id }).catch((x) => ({ ok: false, error: String(x && x.message || x) }));
|
|
508
|
-
R.busy = false;
|
|
509
|
-
if (!r || r.ok !== true) { draw(); toast('The sample was not removed: ' + ((r && r.error) || 'the press did not go through.')); return; }
|
|
510
|
-
R.design = r.design; draw(); refreshBrief();
|
|
511
|
-
const b = $('#rdClip'); if (b) b.focus();
|
|
512
|
-
sayA('Removed "' + s.name + '". The next version and each new cycle no longer follow it.');
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/* ── Present: the current slide on the whole screen ── */
|
|
516
|
-
function presHtml() {
|
|
517
|
-
const L = slides(), i = R.i;
|
|
518
|
-
return `<div class="rdpbox">${L.length ? slideCard(L[i]) : ''}</div><div class="rdpn"><button data-rp="prev" aria-label="Previous slide"${i === 0 ? ' disabled' : ''}>${PREV}</button><span>${i + 1} / ${L.length}</span><button data-rp="next" aria-label="Next slide"${i >= L.length - 1 ? ' disabled' : ''}>${NEXT}</button><button data-rp="end" aria-label="Stop presenting">${XI}</button></div>`;
|
|
519
|
-
}
|
|
520
|
-
function present(on) {
|
|
521
|
-
let p = $('#rdPres');
|
|
522
|
-
if (!on) { if (p) p.remove(); if (document.fullscreenElement) document.exitFullscreen().catch(() => {}); setFull(!R.unfull); R.unfull = false; draw(); const b = $('#oMain [data-rr="present"]'); if (b) b.focus(); return; }
|
|
523
|
-
if (R.view !== 'deck' || !slides().length) { R.view = 'deck'; if (!slides().length) { toast('This version has no slides to present.'); return; } }
|
|
524
|
-
if (!$('#dlg').classList.contains('full')) { R.unfull = true; setFull(true); }
|
|
525
|
-
if (!p) { p = document.createElement('div'); p.id = 'rdPres'; p.className = 'rdpres'; p.setAttribute('role', 'dialog'); p.setAttribute('aria-modal', 'true'); p.setAttribute('aria-label', 'Presenting ' + R.name); p.tabIndex = -1; document.body.appendChild(p); }
|
|
526
|
-
p.innerHTML = presHtml(); fit(p);
|
|
527
|
-
if (p.requestFullscreen && !document.fullscreenElement) p.requestFullscreen().catch(() => {});
|
|
528
|
-
p.focus();
|
|
529
|
-
}
|
|
530
|
-
document.addEventListener('click', (e) => {
|
|
531
|
-
const b = e.target.closest && e.target.closest('#rdPres [data-rp]');
|
|
532
|
-
if (!b || b.disabled || !R) return;
|
|
533
|
-
const k = b.dataset.rp;
|
|
534
|
-
if (k === 'end') { present(false); return; }
|
|
535
|
-
R.i += k === 'next' ? 1 : -1; present(true);
|
|
536
|
-
});
|
|
537
|
-
document.addEventListener('fullscreenchange', () => { if (!document.fullscreenElement && $('#rdPres')) present(false); });
|
|
538
|
-
|
|
539
|
-
/* ── Print: one slide to a page, or the page ── */
|
|
540
560
|
function printHtml() {
|
|
541
|
-
const
|
|
542
|
-
if (
|
|
561
|
+
const t = esc(R.name + ' ' + (R.row.slot || ''));
|
|
562
|
+
if (R.cyc) return frameDoc(R.cyc.style, R.view === 'deck' && R.cyc.slides.length ? R.cyc.slides.map((x) => x.html).join('') : R.cyc.body, R.view === 'deck' && R.cyc.slides.length ? 'pmos-print pmos-print-deck' : 'pmos-print pmos-print-doc').replace('<head>', '<head><title>' + t + '</title>');
|
|
543
563
|
const css = '<link rel="stylesheet" href="' + esc(href('premium-report-print.css')) + '">';
|
|
544
564
|
const w = R.W || { title: R.name, sections: [] };
|
|
545
565
|
const inner = R.view === 'deck'
|
|
546
|
-
? slides().map((x) => `<section class="pmos-slide"><h2 class="rp-slide__h">${esc(x.h)}</h2><div class="rp-slide__t">${x.k === 'title' ? `<p>${esc(x.t)}</p>` : x.html}</div></section>`).join('')
|
|
566
|
+
? slides().map((x) => `<section class="pmos-slide"><h2 class="rp-slide__h">${esc(x.k === 'title' ? x.title : x.h)}</h2><div class="rp-slide__t">${x.k === 'title' ? `<p>${esc(x.t)}</p>` : x.html}</div></section>`).join('')
|
|
547
567
|
: `<h1>${esc(w.title)}</h1>` + w.sections.map((x) => `<h2>${esc(x.h)}</h2>${slideHtml(x.lines)}`).join('');
|
|
548
568
|
return frameDoc('', inner, R.view === 'deck' ? 'pmos-print pmos-print-deck' : 'pmos-print pmos-print-doc').replace('<head>', '<head><title>' + t + '</title>').replace('</head>', css + '</head>');
|
|
549
569
|
}
|
|
550
570
|
function printIt() {
|
|
551
571
|
const w = window.open('', '_blank');
|
|
552
|
-
if (!w)
|
|
572
|
+
if (!w) return say('The browser blocked the print window. Allow pop-ups for this page, then press Print again.', 'bad');
|
|
553
573
|
w.document.open(); w.document.write(printHtml()); w.document.close();
|
|
554
574
|
w.focus(); setTimeout(() => { try { w.print(); } catch { /* the PM prints from the window */ } }, 300);
|
|
555
575
|
}
|
|
556
576
|
|
|
557
|
-
/* ──
|
|
577
|
+
/* ── Present: the current slide on the whole screen (Waiting for design) ── */
|
|
578
|
+
function present(on) {
|
|
579
|
+
let p = document.getElementById('vzPres');
|
|
580
|
+
if (!on) { if (!p) return; p.remove(); if (document.fullscreenElement) document.exitFullscreen().catch(() => {}); if (R) draw(); const b = bodyEl() && bodyEl().querySelector('[data-r="present"]'); if (b) b.focus(); return; }
|
|
581
|
+
const L = slides(); if (!L.length) return say('This cycle has no slides to present.');
|
|
582
|
+
if (!p) {
|
|
583
|
+
p = document.createElement('div'); p.id = 'vzPres'; p.className = 'vz vz-pres'; p.setAttribute('role', 'dialog'); p.setAttribute('aria-modal', 'true'); p.setAttribute('aria-label', 'Presenting ' + R.name); p.tabIndex = -1; p.dataset.escLayer = '1';
|
|
584
|
+
p.onclick = (e) => { const t = e.target.closest('[data-r]'); if (!t || t.disabled) return; const k = t.dataset.r; if (k === 'end') return present(false); R.i += k === 'next' ? 1 : -1; present(true); };
|
|
585
|
+
p.onkeydown = (e) => {
|
|
586
|
+
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); return present(false); }
|
|
587
|
+
if (/^Arrow(Left|Right)$/.test(e.key)) { e.preventDefault(); const j = R.i + (e.key === 'ArrowRight' ? 1 : -1); if (j >= 0 && j < slides().length) { R.i = j; present(true); } }
|
|
588
|
+
};
|
|
589
|
+
document.body.appendChild(p);
|
|
590
|
+
if (p.requestFullscreen && !document.fullscreenElement) p.requestFullscreen().catch(() => {});
|
|
591
|
+
}
|
|
592
|
+
const i = R.i = Math.max(0, Math.min(R.i, L.length - 1));
|
|
593
|
+
p.innerHTML = `<div class="vz-slide">${slideCard(L[i])}</div><div class="vz-snav">${ib('prev', ic('prev', 16), 'Previous slide', { off: i === 0 })}<span>${i + 1} of ${L.length}</span>${ib('next', ic('next', 16), 'Next slide', { off: i === L.length - 1 })}${ib('end', ic('x', 16), 'Stop presenting')}${WAIT('Present')}</div>`;
|
|
594
|
+
fit(p); p.focus();
|
|
595
|
+
}
|
|
596
|
+
if (typeof document !== 'undefined') document.addEventListener('fullscreenchange', () => { if (!document.fullscreenElement && document.getElementById('vzPres')) present(false); });
|
|
597
|
+
|
|
558
598
|
/* ── reading the cycle ── */
|
|
559
599
|
async function readCycle() {
|
|
600
|
+
const me = R;
|
|
560
601
|
const c = await Promise.resolve(pmGet('/api/report-design/cycle?' + q({ ws: R.ws, path: R.row.path }))).catch(() => null);
|
|
561
|
-
if (
|
|
562
|
-
R.cycle = c && c.ok ? c : null;
|
|
602
|
+
if (R !== me) return;
|
|
563
603
|
R.cyc = null;
|
|
564
|
-
if (
|
|
604
|
+
if (c && c.ok && c.designed) { try { const x = splitRender(await textOf('/api/report-design/cycle-html?' + q({ ws: R.ws, path: R.row.path }))); if (R === me) R.cyc = x; } catch { /* the words are shown */ } }
|
|
565
605
|
}
|
|
606
|
+
const viewUrl = (row, ws) => '/premium-viewer.html?' + q({ open: 'report', path: row.path, ws });
|
|
566
607
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
:
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (
|
|
580
|
-
if (!R.
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
if (
|
|
588
|
-
await Promise.all([readCycle(), R.issued ? null : readDesign(), readSetup()]);
|
|
589
|
-
if (R !== me) return;
|
|
608
|
+
/** Open a report cycle in the Viewer. row = { cadence, slot, date, path, state, archived }; hand = { ws, name, cycles, onIssue, onChange } */
|
|
609
|
+
export async function openReport(row, hand = {}) {
|
|
610
|
+
if (!row || !row.path) return null;
|
|
611
|
+
const c = cycleOf(row);
|
|
612
|
+
row = { ...row, cadence: c.cadence, slot: c.slot };
|
|
613
|
+
if (R) present(false);
|
|
614
|
+
const me = R = { row, ws: hand.ws || '', id: c.cadence, name: hand.name || row.name || c.cadence || 'Report', audience: hand.audience || '', issued: row.state === 'issued', archived: !!row.archived,
|
|
615
|
+
text: '', err: '', W: null, view: 'deck', i: 0, cyc: null, setup: undefined, pop: null, conf: false, checks: null, issueErr: '', busy: false, ask: '', askErr: '', edit: false, msg: null,
|
|
616
|
+
sch: schedPick(null), schErr: '', shr: null, hand, cycles: (hand.cycles || []).slice(), onIssue: hand.onIssue || null, onChange: hand.onChange || null, vid: 'report:' + row.path };
|
|
617
|
+
const head = () => ({ id: me.vid, kind: 'Report' + (me.audience ? ' · ' + me.audience : ''), title: me.name, icon: 'report', full: true, url: viewUrl(row, me.ws), render: (b) => { b.innerHTML = panelHtml(); wire(b); }, onClose: () => { if (R === me && !me.reopen) { present(false); R = null; } } });
|
|
618
|
+
vOpen(head());
|
|
619
|
+
try { R.text = await textOf('/api/doc?' + q({ ws: R.ws, path: row.path })); R.W = wordsOf(R.text, R.name); if (!hand.name && R.W.title) R.name = R.W.title; } catch (x) { R.err = String((x && x.message) || x); R.W = { title: R.name, sections: [] }; }
|
|
620
|
+
if (R !== me) return me;
|
|
621
|
+
if (!R.ws && c.cadence && c.slot) { // opened without a workspace (a /premium-viewer.html link): the report route names the one that holds it
|
|
622
|
+
const d = await Promise.resolve(pmGet('/api/report/draft?' + q({ cadence: c.cadence, slot: c.slot }))).catch(() => null);
|
|
623
|
+
if (R !== me) return me;
|
|
624
|
+
if (d && d.ws) R.ws = d.ws;
|
|
625
|
+
}
|
|
626
|
+
await Promise.all([readCycle(), readSetup()]);
|
|
627
|
+
if (R !== me) return me;
|
|
628
|
+
if (vCur() && vCur().id === me.vid && (vCur().title !== me.name || me.audience)) { me.reopen = true; vOpen(head()); me.reopen = false; } // the name and audience are known now
|
|
590
629
|
draw();
|
|
591
|
-
|
|
630
|
+
return me;
|
|
592
631
|
}
|
|
593
632
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
if (!
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
if (
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
if (e.key === 'Escape') { e.preventDefault(); e.stopImmediatePropagation(); present(false); return; }
|
|
606
|
-
if (/^Arrow(Left|Right)$/.test(e.key)) { e.preventDefault(); const L = slides().length; const j = R.i + (e.key === 'ArrowRight' ? 1 : -1); if (j >= 0 && j < L) { R.i = j; present(true); } }
|
|
607
|
-
return;
|
|
633
|
+
/** The window.czViews entry: a report path (reports/<cadence>/<date>.md) or a Reports row. o = { ws, name, cycles, onIssue, onChange } */
|
|
634
|
+
export async function openReportView(ref, o = {}) {
|
|
635
|
+
const row = typeof ref === 'string' ? { path: ref, state: o.state || '' } : ref;
|
|
636
|
+
if (!row || !row.path) return null;
|
|
637
|
+
const c = cycleOf(row), ws = o.ws || '';
|
|
638
|
+
let cycles = o.cycles || null, state = row.state;
|
|
639
|
+
if (!cycles || !state) { // the cycles of this report and this cycle's state, from GET /api/report-documents
|
|
640
|
+
const j = await Promise.resolve(pmGet('/api/report-documents?' + q({ ws }))).catch(() => null);
|
|
641
|
+
const docs = j && Array.isArray(j.docs) ? j.docs.filter((d) => cycleOf(d).cadence === c.cadence) : [];
|
|
642
|
+
if (!cycles) cycles = docs.map((d) => ({ path: d.path, slot: d.slot, state: d.state, archived: !!d.archived, cadence: c.cadence })).sort((a, b) => String(b.slot).localeCompare(String(a.slot)));
|
|
643
|
+
if (!state) { const me = docs.find((d) => d.path === row.path); state = me ? me.state : 'draft'; if (me && me.archived) row.archived = true; }
|
|
608
644
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
if (j < 0 || j >= L) return;
|
|
612
|
-
e.preventDefault(); R.i = j; draw(); const s = $('#rdSlide'); if (s) s.focus();
|
|
613
|
-
}, true);
|
|
614
|
-
/* Another dialog of the page opens without the reader's class; closing the dialog closes the reader. */
|
|
615
|
-
/* While presenting, the page's Escape takes the dialog out of full screen first (premium-shell.js): that is the reader's sign to stop presenting. */
|
|
616
|
-
new MutationObserver(() => { const d = $('#dlg'); if (R && $('#rdPres') && d.classList.contains('on') && !d.classList.contains('full')) present(false); }).observe($('#dlg'), { attributes: true, attributeFilter: ['class'] });
|
|
617
|
-
new MutationObserver(() => { const d = $('#dlg'); if (d && !d.classList.contains('on') && d.classList.contains('rdrd')) { d.classList.remove('rdrd'); const p = $('#rdPres'); if (p) p.remove(); R = null; } }).observe($('#dlg'), { attributes: true, attributeFilter: ['class'] });
|
|
645
|
+
return openReport({ ...row, state }, { ...o, ws, cycles });
|
|
646
|
+
}
|