create-pmos 0.397.0 → 0.399.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/briefing-premium-adddoc-test.js +105 -52
  8. package/workspace/briefing-premium-board-test.js +284 -128
  9. package/workspace/briefing-premium-calendar-2-test.js +135 -198
  10. package/workspace/briefing-premium-calendar-3-test.js +143 -418
  11. package/workspace/briefing-premium-calendar-test.js +85 -196
  12. package/workspace/briefing-premium-doc-edit-test.js +99 -83
  13. package/workspace/briefing-premium-initiative-test.js +175 -290
  14. package/workspace/briefing-premium-insights-test.js +414 -219
  15. package/workspace/briefing-premium-metrics-test.js +55 -97
  16. package/workspace/briefing-premium-products-test.js +44 -28
  17. package/workspace/briefing-premium-sources-test.js +70 -49
  18. package/workspace/briefing-premium-test.js +155 -648
  19. package/workspace/briefing-premium-work-test.js +88 -283
  20. package/workspace/changelog.json +24 -0
  21. package/workspace/ev-everywhere-test.js +210 -0
  22. package/workspace/fixtures/board-premium-trail.js +32 -0
  23. package/workspace/fixtures/premium-viewer-fixtures.js +187 -0
  24. package/workspace/guide/briefing-premium.md +3 -1
  25. package/workspace/guide/home.md +68 -0
  26. package/workspace/guide/index.md +1 -0
  27. package/workspace/lib/agent-roles.js +71 -0
  28. package/workspace/lib/board-grill.js +63 -0
  29. package/workspace/lib/board-premium.js +121 -24
  30. package/workspace/lib/board-trail.js +223 -0
  31. package/workspace/lib/home-work-item.js +58 -0
  32. package/workspace/lib/initiative-layout.js +77 -0
  33. package/workspace/lib/insights-goals.js +196 -0
  34. package/workspace/lib/insights-premium.js +64 -15
  35. package/workspace/lib/insights-records.js +115 -0
  36. package/workspace/lib/jira-tickets.js +1 -1
  37. package/workspace/lib/meeting-points.js +52 -0
  38. package/workspace/lib/news-for-you.js +88 -0
  39. package/workspace/lib/notes-series.js +29 -6
  40. package/workspace/lib/report-confirm.js +48 -0
  41. package/workspace/lib/route-modules.js +12 -0
  42. package/workspace/lib/routes-board-docs.js +46 -0
  43. package/workspace/lib/routes-board-grill.js +90 -0
  44. package/workspace/lib/routes-board-trail.js +33 -0
  45. package/workspace/lib/routes-home-desk.js +176 -0
  46. package/workspace/lib/routes-home-review.js +108 -0
  47. package/workspace/lib/routes-initiative-layout.js +57 -0
  48. package/workspace/lib/routes-insights-premium.js +16 -4
  49. package/workspace/lib/routes-insights-records.js +133 -0
  50. package/workspace/lib/routes-meeting-points.js +37 -0
  51. package/workspace/lib/routes-news.js +57 -0
  52. package/workspace/lib/routes-notes.js +3 -1
  53. package/workspace/lib/routes-report-confirm.js +31 -0
  54. package/workspace/lib/routes-search.js +38 -0
  55. package/workspace/lib/routes-viewer.js +108 -0
  56. package/workspace/lib/search-index.js +176 -0
  57. package/workspace/lib/transcript-steps.js +123 -0
  58. package/workspace/lib/viewer-meeting.js +205 -0
  59. package/workspace/lib/viewer-report.js +89 -0
  60. package/workspace/package-lock.json +2 -2
  61. package/workspace/package.json +1 -1
  62. package/workspace/premium-board-actions-test.js +128 -82
  63. package/workspace/premium-briefing-depth-test.js +104 -90
  64. package/workspace/premium-chat-attach-test.js +54 -63
  65. package/workspace/premium-chat-chart-tab-test.js +37 -37
  66. package/workspace/premium-chat-context-test.js +19 -18
  67. package/workspace/premium-chat-goal-view-test.js +23 -23
  68. package/workspace/premium-chat-notes-test.js +26 -31
  69. package/workspace/premium-chat-report-tab-test.js +46 -28
  70. package/workspace/premium-chat-term-test.js +16 -16
  71. package/workspace/premium-chat-viewer-test.js +60 -59
  72. package/workspace/premium-core-doc-issue-test.js +52 -43
  73. package/workspace/premium-html-viewer-test.js +14 -17
  74. package/workspace/premium-phone-card-test.js +10 -3
  75. package/workspace/premium-phone-room-test.js +41 -35
  76. package/workspace/premium-report-read-test.js +152 -197
  77. package/workspace/premium-viewer-download-test.js +19 -22
  78. package/workspace/premium-viewer-flicker-test.js +11 -16
  79. package/workspace/premium-viewer-share-test.js +6 -9
  80. package/workspace/premium-viewer-test.js +41 -60
  81. package/workspace/premium-vw-backlog-test.js +53 -33
  82. package/workspace/premium-vw-cal-test.js +97 -128
  83. package/workspace/premium-vw-copy-test.js +17 -33
  84. package/workspace/premium-vw-doc-test.js +17 -10
  85. package/workspace/premium-vw-item-test.js +50 -49
  86. package/workspace/premium-vw-jira-test.js +53 -27
  87. package/workspace/premium-vw-meet-test.js +115 -187
  88. package/workspace/premium-vw-notes-test.js +88 -109
  89. package/workspace/premium-vw-rec-test.js +71 -194
  90. package/workspace/premium-vw-slides-test.js +46 -50
  91. package/workspace/premium-welcome-test.js +3 -2
  92. package/workspace/premium-work-depth-test.js +61 -53
  93. package/workspace/public/pm/bd-acts.js +383 -0
  94. package/workspace/public/pm/bd-asks.js +261 -0
  95. package/workspace/public/pm/bd-pop.js +59 -0
  96. package/workspace/public/pm/bd-span.js +222 -82
  97. package/workspace/public/pm/bd-stages.js +25 -11
  98. package/workspace/public/pm/bd-views.js +169 -0
  99. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  100. package/workspace/public/pm/c3-md.js +3 -395
  101. package/workspace/public/pm/c3-phone-detail.js +1 -1
  102. package/workspace/public/pm/c3-phone-model.js +3 -68
  103. package/workspace/public/pm/chat-term.js +3 -3
  104. package/workspace/public/pm/cozy-board.css +798 -230
  105. package/workspace/public/pm/cozy-ev.css +228 -0
  106. package/workspace/public/pm/cozy-evmodel.js +106 -0
  107. package/workspace/public/pm/cozy-evui.js +47 -0
  108. package/workspace/public/pm/cozy-home.css +570 -142
  109. package/workspace/public/pm/cozy-home.js +5 -3
  110. package/workspace/public/pm/cozy-insights.css +437 -170
  111. package/workspace/public/pm/cozy-md.js +396 -0
  112. package/workspace/public/pm/cozy-nav.js +104 -29
  113. package/workspace/public/pm/cozy-news.js +140 -0
  114. package/workspace/public/pm/cozy-placeholder.js +26 -0
  115. package/workspace/public/pm/cozy-search.js +203 -0
  116. package/workspace/public/pm/cozy-settings.js +198 -0
  117. package/workspace/public/pm/cozy-sources.js +89 -0
  118. package/workspace/public/pm/cozy-today.css +217 -0
  119. package/workspace/public/pm/cozy-viewer.css +3 -3
  120. package/workspace/public/pm/cozy-viewer.js +145 -0
  121. package/workspace/public/pm/cozy-vw-mtg.css +350 -0
  122. package/workspace/public/pm/cozy-vw-rp.css +152 -0
  123. package/workspace/public/pm/cozy-vw.css +485 -0
  124. package/workspace/public/pm/cozy.css +83 -1
  125. package/workspace/public/pm/home-adddoc.js +48 -0
  126. package/workspace/public/pm/home-app.js +1179 -0
  127. package/workspace/public/pm/home-around.js +413 -0
  128. package/workspace/public/pm/home-chat.js +512 -0
  129. package/workspace/public/pm/home-data.js +312 -0
  130. package/workspace/public/pm/home-dictate.js +54 -0
  131. package/workspace/public/pm/home-draft.js +68 -0
  132. package/workspace/public/pm/home-ini-model.js +190 -0
  133. package/workspace/public/pm/home-ini.css +171 -0
  134. package/workspace/public/pm/home-ini.js +456 -0
  135. package/workspace/public/pm/home-list.js +276 -0
  136. package/workspace/public/pm/home-more.js +132 -0
  137. package/workspace/public/pm/home-phone-card.js +109 -0
  138. package/workspace/public/pm/home-review.js +104 -0
  139. package/workspace/public/pm/home-task.js +67 -0
  140. package/workspace/public/pm/home-today.js +144 -0
  141. package/workspace/public/pm/home-work.js +547 -0
  142. package/workspace/public/pm/phone-moment.js +69 -0
  143. package/workspace/public/pm/pm-work-view.js +1 -1
  144. package/workspace/public/pm/premium-attach.js +4 -0
  145. package/workspace/public/pm/premium-board.js +548 -395
  146. package/workspace/public/pm/premium-chart-tab.js +109 -62
  147. package/workspace/public/pm/premium-deck.js +3 -3
  148. package/workspace/public/pm/premium-first.js +23 -21
  149. package/workspace/public/pm/premium-insights.js +1102 -581
  150. package/workspace/public/pm/premium-meeting.js +61 -549
  151. package/workspace/public/pm/premium-mtg-present.js +138 -0
  152. package/workspace/public/pm/premium-mtg-replay.js +142 -0
  153. package/workspace/public/pm/premium-notes.js +1 -1
  154. package/workspace/public/pm/premium-report-frame.css +20 -0
  155. package/workspace/public/pm/premium-report-read.js +669 -476
  156. package/workspace/public/pm/premium-report-tab.js +116 -67
  157. package/workspace/public/pm/premium-shell.js +76 -123
  158. package/workspace/public/pm/premium-viewer.js +22 -1
  159. package/workspace/public/pm/premium-vw-cal.js +277 -48
  160. package/workspace/public/pm/premium-vw-doc.css +6 -0
  161. package/workspace/public/pm/premium-vw-doc.js +40 -2
  162. package/workspace/public/pm/premium-vw-file.js +2 -2
  163. package/workspace/public/pm/premium-vw-meet.js +6 -83
  164. package/workspace/public/pm/premium-vw-mtg.js +958 -0
  165. package/workspace/public/pm/premium-vw-notes.js +116 -68
  166. package/workspace/public/pm/premium-vw-open.js +35 -0
  167. package/workspace/public/pm/premium-vw-page.js +16 -0
  168. package/workspace/public/pm/premium-vw-rec.js +11 -218
  169. package/workspace/public/pm/premium-vw-slides.css +5 -0
  170. package/workspace/public/pm/premium-vw-slides.js +44 -8
  171. package/workspace/public/pm/rp-parts.js +269 -0
  172. package/workspace/public/pm/term-view.js +22 -0
  173. package/workspace/public/premium-board.html +29 -70
  174. package/workspace/public/premium-initiative.html +8 -48
  175. package/workspace/public/premium-insights.html +26 -64
  176. package/workspace/public/premium-viewer.html +20 -0
  177. package/workspace/public/premium.html +18 -107
  178. package/workspace/r/m1.png +0 -0
  179. package/workspace/r/m2.png +0 -0
  180. package/workspace/r/m3.png +0 -0
  181. package/workspace/r/nl.png +0 -0
  182. package/workspace/server.js +18 -3
  183. package/workspace/test-files.json +1 -0
  184. package/workspace/test-lists/home-libs.json +9 -0
  185. package/workspace/test-lists/initiative-layout.json +9 -0
  186. package/workspace/test-lists/premium-report-read.json +1 -1
  187. package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
  188. package/workspace/test-lists/premium-uncovered-reports.json +9 -0
  189. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  190. package/workspace/test-lists/premium-vw-notes.json +1 -1
  191. package/workspace/test-lists/uf-everywhere.json +15 -0
  192. package/workspace/test-lists/uf-home.json +9 -0
  193. package/workspace/test-lists/uncovered-board.json +9 -0
  194. package/workspace/public/pm/premium-work.js +0 -729
  195. package/workspace/public/pm/premium.js +0 -1146
@@ -1,61 +1,90 @@
1
- /* pm/premium-report-read.js — a report document read on the premium Insights page (initiative premium-report-read; planning/prd/premium-report-read-prd.md).
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; the
2
+ * uncovered parts drawn by premium-uncovered-features, workstream reports: canvas RpBrief, RpStates, RpDoc, RpLive, RpPhone).
6
3
  *
7
- * openReport(row, hand) row = a Reports card document { cadence, slot, date, path, state, archived }; hand = { ws, name (the set-up report's name, or
8
- * null), cycles (every row of the same report, for the cycle chip), onIssue, onChange }
9
- * wordsOf(md, fallback) the document as { title, sections: [{ h, lines }] } (pure)
10
- * slideHtml(lines) a section's lines as html: paragraphs and lists, as written (pure)
4
+ * One report cycle, drawn as the design's report panel inside the czViewer card (cozy-viewer.js): no conversation, nothing in #dlg.
5
+ * Header kind "Report · <audience>" (the template's audience), the report's name.
6
+ * Tabs Report | Brief, Brief with the count of what waits for the PM's confirm (RpBrief).
7
+ * Chips the cycle chip (Draft · Oct 21, Issued · Oct 21; orange "Editing the Oct 21 draft" while editing) and its menu in groups:
8
+ * Draft, Issued, Archived with Bring back, and Archive <cycle> (RpStates); the schedule chip and its popover (Every week, Every
9
+ * 2 weeks, Every month on the 1st, Something else: say it in the chat; Mon to Fri; the time; Cancel and Schedule it).
10
+ * Toolbar Slides | Document | Live page, Edit, Present, Share (its popover: Link | Send a file, Ends in, Password, Create link, the open
11
+ * links and Turn off), Download (PDF or Word), the blue Issue button and More (PPTX DOCX PDF XLSX CSV MD, Print, Versions
12
+ * "N cycles", Discard this draft… or Archive).
13
+ * 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.
14
+ * Issued the lock line "Issued, so it stays as sent. Changes go into the next cycle." with Start the next cycle (RpStates).
15
+ * Discard a card at the foot of the panel: "Discard the Oct 12 draft?", the cycle that stays, "This cannot be undone." (RpStates).
16
+ * Slides the current slide, "Slides", the counter (1 of 5) with previous and next, and a thumbnail of each slide.
17
+ * Document the words as paper pages: the eyebrow, the title, "In one minute", numbered sections, tables, the sources as footnotes,
18
+ * "Page n of N" and Download as PDF or Word (RpDoc; rp-parts.js paperModel). A designed cycle shows its designed page.
19
+ * Live page the numbers Insights reads (GET /api/insights-premium): the goal tiles, Goals on track, Shipped and At risk, the picked goal's
20
+ * line with its range and its points, the shipped rows that open for detail (RpLive; rp-parts.js liveModel). An issued cycle
21
+ * reads only the readings up to its day, so its page never changes later.
22
+ * Brief At a glance (For, Read by, Goes out, Built from), Please confirm (Confirm or Correct, Use it or Read again), Why it looks like
23
+ * this, Earlier looks with Go back to it (RpBrief; rp-parts.js briefModel).
24
+ * Present the slide over the whole page, "Slide n of N", the numbered strip, ← → and B to blank the screen, Stop presenting.
25
+ * Phone Report | Brief, Slides | Page, the slide, "Slide 1 of 6 · swipe for the next", the lock line and Present (RpPhone).
26
+ * The page editor that Edit mounts on Document (premium-vw-doc.js) and the slide editor's own tools have no artboard: they keep the "Waiting
27
+ * for design" marker.
28
+ * 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
29
+ * 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
30
  *
12
- * READS: GET /api/doc (the words), GET /api/report-design/cycle and cycle-html (a cycle drawn to the saved design), GET /api/report-design and
13
- * version (the design and its versions), GET /api/report-export (the files). PDF is the browser's print. Every render is HTML the server sanitized,
14
- * shown in a frame with an empty sandbox: nothing in it runs.
15
- * WRITES: only the report-design describe, sample, unsample, turn, accept and revert routes, each a press on the page (pmPost, behind the launch nonce). An
16
- * issued cycle is frozen: no design row and no turn. Issue (POST /api/report/issue, after a confirm) freezes a draft cycle; the copies in other tools stay in the console.
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';
31
+ * openReport(row, hand) row = a Reports card document { cadence, slot, date, path, state, archived }; hand = { ws, name, cycles, onIssue, onChange }
32
+ * openReportView(ref, o) ref = a report path reports/<cadence>/<date>.md or a row; the window.czViews entry (premium-vw-open.js)
33
+ * wordsOf(md, fallback) the document as { title, sections: [{ h, lines }] } (pure)
34
+ * slideHtml(lines) a section's lines as html (pure) · splitRender(html) · slideCard(s, mini) · fit(root) · schedLabel(setup) (pure)
35
+ *
36
+ * READS: GET /api/doc, /api/report-design/cycle and cycle-html (a cycle drawn to its saved design), /api/report-setups (schedule and audience),
37
+ * /api/viewer-report/checks, /api/report-structure and /api/report-design (the Brief), /api/report-confirm, /api/insights-premium (Live page),
38
+ * /api/shares, /api/shares/password, /api/report-export (the files). Every render is HTML the server sanitized, shown in a frame with an empty
39
+ * sandbox: nothing in it runs.
40
+ * WRITES (each a press, pmPost behind the launch nonce): /api/report/issue, /api/report-setups/edit or /setup (Schedule it),
41
+ * /api/report-documents/discard and /archive, /api/shares and /api/shares/off, /api/report-confirm (Confirm, Use it), /api/report/draft
42
+ * (Read again: a redraft that keeps the notes; Start the next cycle without a template), /api/report-setups/draft (Start the next cycle),
43
+ * /api/report-design/revert (Go back to it). */
26
44
  import { pmGet, pmPost } from './http.js';
27
- import { vwStyle } from './premium-viewer.js';
28
- import { openDocPage } from './premium-vw-doc.js';
29
- import { schedWords, schedChoices } from './premium-report-tab.js';
45
+ import { open as vOpen, current as vCur } from './cozy-viewer.js';
46
+ import { placeholderHtml } from './cozy-placeholder.js';
47
+ import './premium-vw-open.js'; // registers window.czViews
48
+ import { cycleGroups, cycleName, briefModel, briefHtml, paperModel, paperHtml, liveModel, liveHtml, presentHtml, dayMon } from './rp-parts.js';
30
49
 
31
- const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
32
- const PREV = ICO('<path d="m15 6-6 6 6 6"/>'), NEXT = ICO('<path d="m9 6 6 6-6 6"/>'), CHV = ICO('<path d="M6 9l6 6 6-6"/>'), XI = ICO('<path d="M6 6l12 12M18 6 6 18"/>');
33
- const DLI = ICO('<path d="M12 4v11M7 10l5 5 5-5M5 20h14"/>'), PRI = ICO('<path d="M7 9V4h10v5M7 17H5v-6h14v6h-2M8 14h8v6H8z"/>'), PLAY = ICO('<path d="M8 5v14l11-7z"/>');
34
- const CHK = ICO('<path d="M5 12.5l4.5 4.5L19 7.5"/>'), PLUS = ICO('<path d="M12 5v14M5 12h14"/>'), SEND = ICO('<path d="M5 12h14M13 6l6 6-6 6"/>');
35
- const PEN = ICO('<path d="M4 20h4L19 9l-4-4L4 16z"/>');
36
- const SHI = ICO('<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"/>');
37
- const BIN = ICO('<path d="M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13"/>'), BOX = ICO('<path d="M4 5h16v4H4zM5 9v10h14V9M10 13h4"/>');
50
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
51
+ const svg = (p, n = 18) => `<svg viewBox="0 0 24 24" width="${n}" height="${n}" aria-hidden="true">${p}</svg>`;
52
+ const P = {
53
+ 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"/>',
54
+ 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"/>',
55
+ 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"/>',
56
+ 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"/>',
57
+ 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"/>',
58
+ 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"/>',
59
+ 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"/>',
60
+ 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"/>',
61
+ plus: '<path d="M12 5v14M5 12h14"/>', dl: '<path d="M12 4v11M7 10l5 5 5-5M5 20h14"/>', live: '<path d="M3 17l5-5 4 4 8-8M16 8h4v4"/>', layout: '<rect x="4" y="4" width="16" height="16" rx="2"/><path d="M4 10h16M10 10v10"/>',
62
+ 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"/>',
63
+ };
64
+ const ic = (k, n) => svg(P[k], n);
65
+ const MONS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
38
66
  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
67
  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
68
  const q = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
52
69
  const inline = (s) => esc(s).replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>').replace(/`([^`]+)`/g, '<code>$1</code>');
70
+ const WAIT = (f) => `<span class="vz-wait" data-cz-placeholder="${esc(f)}">Waiting for design</span>`; // only the page editor keeps it
71
+ /** The reader's own sheet (cozy-vw-rp.css), added to the page once. */
72
+ function rpStyle() {
73
+ if (typeof document === 'undefined' || document.querySelector('link[data-rp-css]')) return;
74
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = '/pm/cozy-vw-rp.css'; l.setAttribute('data-rp-css', ''); document.head.appendChild(l);
75
+ }
76
+ /** "Oct 21", from a cycle's YYYY-MM-DD slot. */
77
+ 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 || ''); };
78
+
79
+ let R = null; // the open report
53
80
 
81
+ /* ── the words (pure) ── */
54
82
  /** 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
83
  export function wordsOf(md, fallback) {
56
84
  const lines = String(md || '').replace(/\r/g, '').split('\n');
57
- let i = 0, title = '';
58
- 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); if (m) title = m[1].replace(/^["'](.*)["']$/, '$1').trim(); } i = e + 1; } }
85
+ let i = 0, title = '', sub = '';
86
+ const val = (m) => m[1].replace(/^["'](.*)["']$/, '$1').trim();
87
+ 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
88
  const sections = [], lead = [];
60
89
  let cur = null;
61
90
  for (; i < lines.length; i++) {
@@ -66,7 +95,7 @@ export function wordsOf(md, fallback) {
66
95
  (cur ? cur.lines : lead).push(l);
67
96
  }
68
97
  if (lead.some((l) => l.trim())) sections.unshift({ h: 'Summary', lines: lead });
69
- return { title: title || fallback || 'Report', sections };
98
+ return { title: title || fallback || 'Report', sub, sections };
70
99
  }
71
100
 
72
101
  /** 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 +115,28 @@ export function slideHtml(lines) {
86
115
  return out.join('') || '<p>This section is empty.</p>';
87
116
  }
88
117
 
118
+ /** 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". */
119
+ export function schedLabel(setup) {
120
+ const s = setup && setup.status !== 'paused' ? setup.schedule : null;
121
+ if (!s || !s.cadence || s.cadence === 'off') return 'Not scheduled';
122
+ const t = s.time || '09:00';
123
+ if (s.cadence === 'daily') return 'Every day ' + t;
124
+ if (s.cadence === 'monthly') { const d = s.dayOfMonth || 1; return 'Every month · ' + d + (d === 1 ? 'st' : d === 2 ? 'nd' : d === 3 ? 'rd' : 'th') + ' ' + t; }
125
+ return (s.cadence === 'bi-weekly' ? 'Every 2 weeks · ' : 'Every ') + (s.day || 'Mon') + ' ' + t;
126
+ }
127
+ /** The popover's starting pick, from the template's schedule. */
128
+ export function schedPick(setup) {
129
+ const s = setup && setup.status !== 'paused' ? setup.schedule : null;
130
+ const cad = s && ['weekly', 'bi-weekly', 'monthly'].includes(s.cadence) ? s.cadence : 'weekly';
131
+ return { cad, day: (s && s.day && DAYS.includes(s.day)) ? s.day : 'Mon', time: (s && s.time) || '09:00' };
132
+ }
133
+ /** The schedule a pick saves, or null for "Something else". */
134
+ export function schedOf(pick) {
135
+ if (!pick || pick.cad === 'else') return null;
136
+ if (pick.cad === 'monthly') return { cadence: 'monthly', dayOfMonth: 1, time: pick.time || '09:00' };
137
+ return { cadence: pick.cad, day: pick.day || 'Mon', time: pick.time || '09:00' };
138
+ }
139
+
89
140
  /* ── a sanitized render: its style, its slides and its body (DOMParser; nothing of it runs) ── */
90
141
  export function splitRender(html) {
91
142
  const d = new DOMParser().parseFromString(String(html || ''), 'text/html');
@@ -98,520 +149,662 @@ export function splitRender(html) {
98
149
  }
99
150
  const href = (f) => new URL('./' + f, import.meta.url).href;
100
151
  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('c3-report-frame.css')) + '">'
152
+ 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
153
  + '<style>' + String(style || '').replace(/<\/style/gi, '<\\/style') + '</style></head><body class="pmos-frame ' + cls + '">' + String(inner || '') + '</body></html>';
103
154
  }
104
- const frame = (style, inner, cls, title) => `<iframe class="rdif" sandbox="" tabindex="-1" title="${esc(title)}" srcdoc="${esc(frameDoc(style, inner, cls))}"></iframe>`;
155
+ const frame = (style, inner, cls, title) => `<iframe sandbox="" tabindex="-1" title="${esc(title)}" srcdoc="${esc(frameDoc(style, inner, cls))}"></iframe>`;
105
156
 
106
- /* ── what is shown: the cycle (its words, or its designed render) or a design version ── */
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
- }
157
+ /* ── what is shown ── */
111
158
  function slides() {
112
- const s = source();
113
- if (s.kind === 'words') {
114
- const w = R.W || { title: R.name, sections: [] };
115
- return [{ k: 'title', h: w.title, t: [R.name, R.row.date || R.row.slot, R.issued ? 'Issued' : 'Draft'].filter(Boolean).join(' · ') }].concat(w.sections.map((x) => ({ k: 'text', h: x.h, html: slideHtml(x.lines) })));
159
+ 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 }));
160
+ const w = R.W || { title: R.name, sections: [] };
161
+ return [titleSlide(w)]
162
+ .concat(w.sections.map((x) => ({ k: 'text', h: x.h, html: slideHtml(x.lines) })));
163
+ }
164
+ /** "21 Oct 2026", from a YYYY-MM-DD slot. */
165
+ 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 || ''); };
166
+ /** The title slide (ReportPanel.dc.html): the audience tag, the title with the audience as its accent line, a subtitle (the file's
167
+ * subtitle or description, else its first sections) and the as-of line. Nothing is made up: a part with no source is left out. */
168
+ function titleSlide(w) {
169
+ const heads = (w.sections || []).map((x) => x.h).filter((h) => !/^summary$/i.test(h)).slice(0, 3);
170
+ const list = heads.length > 1 ? heads.slice(0, -1).join(', ') + ' and ' + heads[heads.length - 1].toLowerCase() : heads.join('');
171
+ const f = headFigure(w), t = [R.row.slot ? 'As of ' + longSlot(R.row.slot) : '', f && f.data ? 'Data: ' + f.data : ''].filter(Boolean).join(' · ');
172
+ return { k: 'title', h: 'Title', title: w.title, eye: R.audience || 'Report', acc: R.audience ? R.audience.toLowerCase() : '', sub: w.sub || list, t,
173
+ fig: f ? { v: f.v, cap: f.cap } : null };
174
+ }
175
+ /** The title slide's headline figure (ReportPanel.dc.html: "81%" over "597 of 733 web logins"): the first bold number of the first
176
+ * 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. */
177
+ export function headFigure(w) {
178
+ const first = ((w && w.sections) || [])[0];
179
+ for (const l of (first && first.lines) || []) {
180
+ const m = /\*\*([^*]*\d[^*]*)\*\*\s*(?:\(([^)]+)\))?/.exec(l);
181
+ if (!m || m[1].length > 12) continue;
182
+ const d = /\bas of (\d{1,2} [A-Z][a-z]{2})/i.exec(l);
183
+ return { v: m[1].trim(), cap: (m[2] || '').trim(), data: d ? d[1] : '' };
116
184
  }
117
- return s.X ? s.X.slides.map((x) => ({ k: 'frame', h: x.h, html: x.html, css: s.X.style })) : [];
185
+ return null;
118
186
  }
119
- /* ── drawing ── */
187
+ /** One slide: a designed frame, the title slide or a section's words. */
120
188
  export function slideCard(s, mini) {
121
- if (s.k === 'frame') return `<div class="rdfc${mini ? ' mini' : ''}">${frame(s.css, s.html, 'pmos-one', s.h)}</div>`;
122
- if (s.k === 'title') return `<div class="rds title${mini ? ' mini' : ''}"><h3>${esc(s.h)}</h3>${mini ? '' : `<p>${esc(s.t)}</p>`}</div>`;
123
- return `<div class="rds${mini ? ' mini' : ''}"><h3>${esc(s.h)}</h3>${mini ? '' : s.html}</div>`;
189
+ if (s.k === 'frame') return `<span class="vz-fr">${frame(s.css, s.html, 'pmos-one', s.h)}</span>`;
190
+ 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>` : ''}`;
191
+ return `<span class="vz-words"><h4>${esc(s.h)}</h4>${mini ? '' : s.html}</span>`;
192
+ }
193
+
194
+ /* ── drawing ── */
195
+ 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>`;
196
+ 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>`;
197
+ function chipsHtml() {
198
+ const when = shortSlot(R.row.slot || R.row.date);
199
+ 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>`;
200
+ const st = R.issued ? (R.archived ? 'Archived' : 'Issued') : 'Draft';
201
+ 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' });
202
+ 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' })}`
203
+ + `${sched}${R.pop === 'sched' ? schedPop() : R.pop === 'cyc' ? cycPop() : ''}</div>`;
204
+ }
205
+ /** Report | Brief (RpBrief). Brief carries the count of what waits for the PM's confirm. */
206
+ function tabsHtml() {
207
+ const n = R.BF ? R.BF.count : 0;
208
+ return `<div class="cz-tabs rp-tabs" role="tablist" aria-label="Report or its brief"><button type="button" role="tab" class="cz-tab" data-r="tab|report" aria-selected="${R.tab === 'report'}">Report</button>`
209
+ + `<button type="button" role="tab" class="cz-tab" data-r="tab|brief" aria-selected="${R.tab === 'brief'}">Brief${n ? ` <span class="cz-pill late rp-n" aria-label="${n} to confirm">${n}</span>` : ''}</button></div>`;
210
+ }
211
+ function toolHtml() {
212
+ const sb = (k, icon, l, cls) => `<button type="button" data-r="view|${k}" aria-pressed="${R.view === k}" aria-label="${l}" title="${l}"${cls ? ` class="${cls}"` : ''}>${ic(icon, 16)}<span class="vz-dko">${l}</span></button>`;
213
+ const seg = `<div class="vz-sg" role="group" aria-label="${R.edit ? 'Edit as' : 'Read as'}">${sb('deck', 'slides', 'Slides')}${sb('doc', 'page', R.edit ? 'Page' : 'Document')}${R.edit ? '' : sb('live', 'live', 'Live page', 'vz-dko')}</div>`;
214
+ if (R.edit) {
215
+ const deck = R.view === 'deck';
216
+ 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)
217
+ 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>'
218
+ + `<button type="button" class="vz-sec2 vz-hv vz-flat" data-r="ins" aria-haspopup="menu" aria-expanded="${R.pop === 'ins'}">${ic('plus', 16)}&nbsp;Insert${ic('chev', 14)}</button>`
219
+ + ib('ed|layout', ic('layout'), 'Layout') + ib('ed|theme', ic('theme'), 'Theme') : seg}<span class="vz-sp"></span>`
220
+ + `<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>`;
221
+ }
222
+ const issue = R.issued ? '' : `<button type="button" class="vz-issue vz-hv" data-r="issue" aria-expanded="${!!R.conf}">${ic('check', 16)}Issue</button>`;
223
+ return `<div class="vz-tb">${seg}<span class="vz-sp"></span>`
224
+ + (R.issued ? '' : ib('edit', ic('pen'), R.view === 'deck' ? 'Edit the slides' : 'Edit the words', { cls: ' vz-dko' }))
225
+ + 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' })
226
+ + ib('dlm', ic('dl'), 'Download', { cls: ' vz-dko', exp: R.pop === 'dl' })
227
+ + (issue ? '<span class="vz-sep vz-dko"></span>' + issue : '') + ib('more', ic('more'), 'More', { exp: R.pop === 'more' })
228
+ + (R.pop === 'more' ? morePop() : R.pop === 'share' ? sharePop() : R.pop === 'dl' ? dlPop() : '') + '</div>';
229
+ }
230
+ /** Download (RpDoc): the paper as PDF (the browser prints it) or Word. The other files stay in More. */
231
+ function dlPop() {
232
+ return `<div class="vz-pop vz-pop-dl" data-esc-layer="1" role="menu" aria-label="Download"><button type="button" class="vz-mi vz-hv" role="menuitem" data-r="pdf">${ic('print')}<span class="vz-grow">PDF</span><small class="vz-note">keeps the look</small></button>`
233
+ + `<a class="vz-mi vz-hv" role="menuitem" data-r="dl|docx" href="/api/report-export?${esc(q({ ws: R.ws, path: R.row.path, fmt: 'docx' }))}" download>${ic('page')}<span class="vz-grow">Word</span><small class="vz-note">to change the words</small></a>`
234
+ + `<p class="vz-note vz-padmi">Slides, tables and Markdown are in More.</p></div>`;
235
+ }
236
+ function schedPop() {
237
+ 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']];
238
+ const weekly = k.cad === 'weekly' || k.cad === 'bi-weekly';
239
+ return `<div class="vz-pop vz-pop-sched" data-esc-layer="1" role="dialog" aria-label="Schedule">`
240
+ + `<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>`
241
+ + `<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>`
242
+ + (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>' : '')
243
+ + `<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>`
244
+ + (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>` : '')
245
+ + (R.schErr ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(R.schErr)}</p>` : '')
246
+ + `<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>`;
247
+ }
248
+ /** The times the schedule's chip offers, 24-hour, every half hour from 06:00 to 20:00, with the saved one kept. */
249
+ 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(); };
250
+ /** The cycle menu (RpStates): Draft, Issued and Archived, an archived cycle with Bring back, and Archive for the open issued cycle. */
251
+ function cycPop() {
252
+ const G = cycleGroups(R.cycles.length ? R.cycles : [R.row], R.row.path, R.id);
253
+ const row = (x, g) => g === 'archived'
254
+ ? `<div class="vz-mi rp-arch"><span class="vz-grow">${esc(x.name)}</span><button type="button" class="rp-btn soft" data-r="unarch|${esc(x.path)}"${R.busy ? ' disabled' : ''}>Bring back</button></div>`
255
+ : `<button type="button" class="vz-mi vz-hv" role="menuitemradio" aria-checked="${x.cur}" data-r="cyc|${esc(x.path)}"><span class="vz-grow">${esc(x.name)}</span><small class="vz-note">${esc(x.when)}</small></button>`;
256
+ return `<div class="vz-pop vz-pop-cyc" data-esc-layer="1" role="menu" aria-label="Cycles">`
257
+ + G.map((g) => `<p class="vz-lab">${g.t}</p>` + g.rows.map((x) => row(x, g.k)).join('')).join('')
258
+ + (R.issued && !R.archived && !R.edit ? `<hr><button type="button" class="vz-mi vz-hv" role="menuitem" data-r="archive">${ic('box')}Archive ${esc(cycleName(R.row, R.id))}</button>` : '') + '</div>';
259
+ }
260
+ function morePop() {
261
+ 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>`);
262
+ const n = R.cycles.length || 1;
263
+ return `<div class="vz-pop vz-pop-more" data-esc-layer="1" role="menu" aria-label="More">`
264
+ + `<span class="vz-pho">${R.issued ? '' : mi('edit', 'pen', 'Edit')}${mi('present', 'play', 'Present')}${mi('share', 'share', 'Share')}<hr></span>`
265
+ + `<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>`
266
+ + `<p class="vz-note vz-padmi">Slides as PowerPoint, words as Word or Markdown, tables as Excel or CSV. PDF keeps the look.</p>`
267
+ + 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>`
268
+ + (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>';
269
+ }
270
+ const mi = (a, i, l) => `<button type="button" class="vz-mi vz-hv" role="menuitem" data-r="${a}">${ic(i)}${esc(l)}</button>`;
271
+ function insPop() {
272
+ 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>`;
273
+ }
274
+ const dayOf = (iso) => { const t = new Date(iso); return Number.isFinite(t.getTime()) ? MONS[t.getMonth()] + ' ' + t.getDate() : ''; };
275
+ function sharePop() {
276
+ const S = R.shr;
277
+ const base = String(R.row.path).split('/').pop(), mine = (S.list || []).filter((x) => x.name === base || x.name === R.row.path);
278
+ 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>` : '';
279
+ 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>`;
280
+ let body;
281
+ if (S.tab === 'send') {
282
+ 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>`
283
+ : '<p class="vz-note">This device has no share sheet. Download a file from More, then send it yourself.</p>';
284
+ } else if (S.made) {
285
+ 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>`
286
+ + (S.made.pass ? `<div class="vz-shr"><span>Password</span><code class="vz-pw">${esc(S.made.pass)}</code></div>` : '')
287
+ + `<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>`;
288
+ } else {
289
+ body = `<p class="vz-note">A read-only copy of this cycle as it is now. Later edits are not shared.</p>`
290
+ + `<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>`
291
+ + `<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>`
292
+ + (S.err ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(S.err)}</p>` : '')
293
+ + `<button type="button" class="vz-issue vz-hv vz-center" data-r="shmake"${S.busy ? ' disabled' : ''}>${S.busy ? 'Making the link…' : 'Create link'}</button>`;
294
+ }
295
+ return `<div class="vz-pop vz-pop-share" data-esc-layer="1" role="dialog" aria-label="Share">${seg}${body}${foot}</div>`;
296
+ }
297
+ function canSend() {
298
+ try { return typeof navigator !== 'undefined' && !!navigator.share && !!navigator.canShare && navigator.canShare({ files: [new File([R.text || ''], fileName(), { type: 'text/markdown' })] }); } catch { return false; }
299
+ }
300
+ const fileName = () => String(R.row.path).split('/').slice(-2).join('-') || 'report.md';
301
+ function confHtml() {
302
+ if (R.conf) {
303
+ const C = R.checks;
304
+ const list = !C ? '<li><span>…</span><span>Checking the sources, the sections and the figures.</span></li>'
305
+ : !C.ok ? `<li data-ok="false"><span>!</span><span>The checks could not run: ${esc(C.error || 'no answer')}</span></li>`
306
+ : 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('');
307
+ 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>`
308
+ + (R.issueErr ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(R.issueErr)}</p>` : '')
309
+ + `<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>`;
310
+ }
311
+ return '';
312
+ }
313
+ /** Discard or Archive asks in a card at the foot of the panel (RpStates: "Discard draft 2? Draft 1 stays. This cannot be undone."). */
314
+ function askHtml() {
315
+ if (!R.ask) return '';
316
+ const name = cycleName(R.row, R.id), other = R.cycles.filter((x) => x.path !== R.row.path && !x.archived)[0];
317
+ const T = R.ask === 'discard'
318
+ ? [`Discard the ${name} draft?`, (other ? cycleName(other, R.id) + ' stays. ' : '') + 'This cannot be undone.', 'Discard']
319
+ : [`Archive ${name}?`, 'It stays as sent, at the end of the Reports list. Bring it back from the cycle menu.', 'Archive'];
320
+ return `<div class="rp-ask" role="alertdialog" aria-label="${esc(T[0])}"><p><b>${esc(T[0])}</b> <span class="rp-mut">${esc(T[1])}</span></p>`
321
+ + (R.askErr ? `<p class="vz-msg" data-tone="bad" role="alert">${esc(R.askErr)}</p>` : '')
322
+ + `<div><button type="button" class="rp-btn${R.ask === 'discard' ? ' bad' : ' dark'}" data-r="askok"${R.busy ? ' disabled' : ''}>${esc(T[2])}</button><button type="button" class="rp-btn" data-r="askno">Keep it</button></div></div>`;
323
+ }
324
+ /** The lock line of an issued or archived cycle (RpStates, RpPhone). */
325
+ function lockHtml() {
326
+ if (!R.issued || R.edit) return '';
327
+ return `<div class="rp-lock">${ic('lock', 14)}<span>${R.archived ? 'Archived, so it stays as sent. Bring it back from the cycle menu.' : 'Issued, so it stays as sent. Changes go into the next cycle.'}</span>`
328
+ + (R.archived ? `<button type="button" class="rp-btn" data-r="unarch|${esc(R.row.path)}"${R.busy ? ' disabled' : ''}>Bring back</button>` : `<button type="button" class="rp-btn" data-r="nextcyc"${R.busy ? ' disabled' : ''}>Start the next cycle</button>`) + '</div>';
124
329
  }
125
330
  function deckHtml() {
126
331
  const L = slides();
127
- if (!L.length) return '<p class="note">This version has no slides. Read it as a page.</p>';
332
+ if (!L.length) return '<p class="vz-empty">This cycle has no slides. Read it as a document.</p>';
128
333
  const i = R.i = Math.max(0, Math.min(R.i, L.length - 1));
129
- return `<div class="rdk"><div class="rdbig" id="rdSlide" 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.">${slideCard(L[i])}</div>`
130
- + `<div class="rdnv"><button data-rr="prev" aria-label="Previous slide"${i === 0 ? ' disabled' : ''}>${PREV}</button><span id="rdN">${i + 1} / ${L.length}</span><button data-rr="next" aria-label="Next slide"${i === L.length - 1 ? ' disabled' : ''}>${NEXT}</button></div>`
131
- + `<div class="rdt" role="group" aria-label="Slides">${L.map((x, j) => `<button data-rr="go|${j}"${j === i ? ' aria-current="true"' : ''} aria-label="Slide ${j + 1}: ${esc(x.h)}"><span>${esc(x.h)}</span><i>${j + 1}</i></button>`).join('')}</div></div>`;
334
+ 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>`
335
+ + `<div class="vz-snav rp-dkn"><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>`
336
+ + `<p class="rp-swipe rp-pho">Slide ${i + 1} of ${L.length} · swipe for the next</p>`
337
+ + `<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
338
  }
133
339
  function pageHtml() {
134
- const s = source();
135
- if (s.kind === 'words') {
136
- const w = R.W || { title: R.name, sections: [] };
137
- return `<article class="paper doc rdpg"><h2>${esc(w.title)}</h2>${w.sections.map((x) => `<h3 class="d2">${esc(x.h)}</h3>${slideHtml(x.lines)}`).join('')}</article>`;
340
+ if (R.cyc) return `<div class="vz-pagefr">${frame(R.cyc.style, R.cyc.body, '', 'The report as a page')}</div>`;
341
+ const w = R.W || { title: R.name, sections: [] };
342
+ return paperHtml(paperModel(w, { audience: R.audience, name: R.name, slot: R.row.slot }), { state: R.archived ? 'archived' : R.issued ? 'issued' : 'draft', issuedOn: dayMon(R.row.slot) });
343
+ }
344
+ function liveView() {
345
+ const L = R.LV && R.LV.m ? liveModel(R.LV.m, { upTo: R.issued ? R.row.slot : null, range: R.LV.range, pick: R.LV.pick, open: R.LV.open }) : R.LV && R.LV.err ? { none: R.LV.err } : null;
346
+ return liveHtml(L, { name: R.name, audience: R.audience, period: R.issued ? 'As issued · ' + dayMon(R.row.slot) : 'Now', issued: R.issued, readAgo: R.LV && agoOf(R.LV.at), hover: R.LV ? R.LV.hover : null, prodOpen: R.pop === 'prod', products: R.LV && R.LV.m && R.LV.m.board ? R.LV.m.board.switcher : [] });
347
+ }
348
+ const agoOf = (t) => { if (!t) return ''; const m = Math.round((Date.now() - t) / 60000); return m < 1 ? 'just now' : m === 1 ? '1 min ago' : m < 60 ? m + ' min ago' : Math.round(m / 60) + ' h ago'; };
349
+ function bodyHtml() {
350
+ if (R.edit) {
351
+ const SS = slideState(), n = SS ? SS.deck.slides.length : slides().length, at = SS ? SS.i : R.i;
352
+ return `<div class="vz-rpb">${R.msg ? `<p class="vz-msg" role="status" data-tone="${R.msg.tone || ''}">${esc(R.msg.text)}</p>` : ''}`
353
+ + (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>` : '')
354
+ + (R.view === 'deck' ? '' : `<div class="vz-r1">${WAIT('Page editor')}</div>`) + '<div class="vz-ed" data-vz-ed></div></div>';
138
355
  }
139
- if (!s.X) return '<p class="note">Reading the render.</p>';
140
- return `<div class="rdpf">${frame(s.X.style, s.X.body, '', 'The report as a page')}</div>`;
141
- }
142
- /** A new look waits (PM 2026-10-22: the This cycle, D1, D2 row was confusing): one line, Use it or Keep current. A new look is a design version
143
- * that is not the saved one; it is shown below the line while the line is up. */
144
- const newLook = () => { const d = R.design; return !R.issued && d && d.current != null && (!d.saved || d.saved.version !== d.current) && R.noLook !== d.current ? d.current : null; };
145
- function lookHtml() {
146
- if (R.issued) return '';
147
- if (!R.design) return R.dErr ? `<p class="note rdsrc" role="alert">${esc(R.dErr)}</p>` : '';
148
- const n = newLook(); if (n == null) return '';
149
- const v = (R.design.versions || []).find((x) => x.n === n), from = v && v.turn ? '“' + v.turn + '”' : 'your last change';
150
- return `<div class="dsiss rdlook" role="status"><span><b>New look ready</b> from ${esc(from)}. It is shown below. Use it for this and the next cycles, or keep the current look.</span><span class="dsa"><button type="button" class="dmcta dark" data-rr="lookuse"${R.busy ? ' disabled' : ''}>Use it</button><button type="button" class="dmcta alt" data-rr="lookno"${R.busy ? ' disabled' : ''}>Keep current</button></span></div>`;
151
- }
152
- /** The samples the look follows, as chips above the chat box, each with its own remove; the paperclip in the box adds one. */
153
- function samplesHtml() {
154
- const L = (R.design && R.design.samples) || [];
155
- if (!L.length) return '';
156
- return `<span class="label">Follows</span>` + L.map((x) => `<span class="rdsm"><em title="${esc(x.name)}">${esc(x.name)}</em><button type="button" class="rdsx" data-rr="unsample|${esc(x.id)}" aria-label="Remove the sample ${esc(x.name)}" title="Remove this sample"${R.busy ? ' disabled' : ''}>${XI}</button></span>`).join('');
157
- }
158
- function drawSamples() { const el = $('#rdSmp'); if (el) { el.innerHTML = samplesHtml(); el.hidden = !el.innerHTML; } }
159
- const stLabel = (r) => r.state === 'issued' ? (r.archived ? 'Archived' : 'Issued') : 'Draft';
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>`;
356
+ if (R.tab === 'brief') return `<div class="vz-rpb">${briefHtml(R.BF, { issued: R.issued, busy: R.busy, msg: R.bfMsg })}</div>`;
357
+ const view = 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>'
358
+ : R.view === 'deck' ? deckHtml() : R.view === 'live' ? liveView() : pageHtml();
359
+ return `<div class="vz-rpb">${confHtml()}${R.msg ? `<p class="vz-msg" role="status" data-tone="${R.msg.tone || ''}">${esc(R.msg.text)}</p>` : ''}${lockHtml()}${view}`
360
+ + (R.view === 'deck' && R.W && !R.err ? `<button type="button" class="rp-btn rp-present rp-pho" data-r="present">${ic('play', 16)}Present</button>` : '') + askHtml() + '</div>';
361
+ }
362
+ const tipText = (i, n) => `Slide ${i + 1} of ${n}. Click an item to change it; double-click text to type.`;
363
+ /** The editor's slide and its undo history changed: the tip and the dimmed Undo and Redo follow it. */
364
+ function edState(S) {
365
+ const b = bodyEl(); if (!b || !R || !R.edit) return;
366
+ const t = b.querySelector('.vz-tip > span'); if (t) t.textContent = tipText(S.i, S.deck.slides.length);
367
+ const u = b.querySelector('[data-r="ed|undo"]'), r = b.querySelector('[data-r="ed|redo"]');
368
+ if (u) u.classList.toggle('vz-dim', !S.hist.length); if (r) r.classList.toggle('vz-dim', !S.fut.length);
369
+ }
370
+ /** The whole panel as html. */
371
+ export function panelHtml() { return `<div class="vz vz-rp0" data-view="${R.view}" data-tab="${R.tab}"${R.edit ? ' data-edit' : ''}><div class="vz-rph">${R.edit ? '' : tabsHtml()}${R.tab === 'brief' && !R.edit ? '' : chipsHtml() + toolHtml()}</div>${bodyHtml()}</div>`; }
372
+
373
+ const bodyEl = () => (R && vCur() && vCur().id === R.vid ? document.querySelector('#czViewer .cz-vw-body') : null);
374
+ function draw() {
375
+ const b = bodyEl(); if (!b) return;
376
+ if (R.edit) { // the editor keeps its own DOM: only the head and the message are drawn again
377
+ const ed = b.querySelector('[data-vz-ed]');
378
+ 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
379
  }
186
- return `<span class="dsvw">${chip}<div class="dsmn rdsm" role="menu" aria-label="Schedule">${menu}</div></span>`;
187
- }
188
- /** An icon button: its name is its aria-label and its tooltip (PM 2026-10-22: "buttons use icons, no label"). */
189
- const ib = (k, icon, name, o = {}) => `<button type="button" class="rdib${o.pri ? ' pri' : ''}" data-rr="${k}" aria-label="${esc(name)}" title="${esc(name)}"${o.pressed != null ? ` aria-pressed="${o.pressed}"` : ''}${o.exp != null ? ` aria-haspopup="${o.pop || 'menu'}" aria-expanded="${o.exp}"` : ''}${o.attr || ''}${o.off ? ' disabled' : ''}>${icon}</button>`;
190
- /** One bar for the report, one row (PM 2026-10-22: "So many different Edit report functions … Fix it", then "too much rows"): Slides | Page, the
191
- * Brief, the state and the schedule, then Edit, Present, Share, Issue and ⋯. ⋯ names the file and holds Download, Print, and Discard (a draft)
192
- * or Archive (an issued report). An issued report has no Edit and no Issue. While editing, the bar keeps Slides | Page, which switches the editor. */
193
- function barHtml() {
194
- const views = `<span class="rdvw" role="group" aria-label="${R.edit ? 'Edit as' : 'Read as'}">${ib('view|deck', SLI, 'Slides', { pressed: R.view === 'deck', off: R.edit && R.busy })}${ib('view|doc', PGI, 'Page', { pressed: R.view === 'doc', off: R.edit && R.busy })}</span>`;
195
- if (R.edit) return `<div class="rdbar">${views}${statusHtml()}<span class="note rdedn">Save or Cancel brings you back.</span></div>`;
196
- const file = String(R.row.path).split('/').pop();
197
- const more = R.mo ? `<div class="dsmn rpm rdmo" role="menu" aria-label="More"><p class="note rdfile" title="${esc(R.row.path)}">${esc(file)}</p><p class="label">Download a file</p>${DL.map(([k, l, s2]) => `<a role="menuitem" data-rr="dl|${k}" href="/api/report-export?${esc(q({ ws: R.ws, path: R.row.path, fmt: k }))}" download>${DLI}<span>${esc(l)}<small>${esc(s2)}</small></span></a>`).join('')}`
198
- + `<button type="button" role="menuitem" data-rr="md">${DLI}<span>Markdown (.md)<small>The file, as written.</small></span></button>`
199
- + `<button type="button" role="menuitem" data-rr="print">${PRI}<span>Print or save as PDF<small>Keeps the look. The files above carry the words only.</small></span></button><hr>`
200
- + (R.issued ? `<button type="button" role="menuitem" data-rr="${R.archived ? 'unarchive' : 'archive'}">${BOX}<span>${R.archived ? 'Bring back' : 'Archive'}<small>${R.archived ? 'It goes back with the issued cycles.' : 'Kept for good, listed under Archived in this report’s cycles.'}</small></span></button>`
201
- : `<button type="button" role="menuitem" class="rdbad" data-rr="discard">${BIN}<span>Discard this draft<small>Asks once. Issued reports are never deleted.</small></span></button>`) + '</div>' : '';
202
- return `<div class="rdbar">${views}${ib('brief', BRF, 'Brief: how this report is made (opens a tab)')}${statusHtml()}<span class="rdsp"></span>`
203
- + (R.issued ? '' : ib('edit', PEN, R.view === 'deck' ? 'Edit the slides' : 'Edit the words'))
204
- + ib('present', PLAY, 'Present')
205
- + `<span class="dsvw">${ib('share', SHI, 'Share a link to a copy', { exp: false, pop: 'dialog', attr: ' data-fsh' })}</span>`
206
- + (R.issued ? '' : ib('issue', CHK, 'Issue: freeze this cycle', { pri: 1, exp: !!R.conf, pop: 'true' }))
207
- + `<span class="dsvw">${ib('mo', MORE, R.issued ? 'More: file, download, print, archive' : 'More: file, download, print, discard', { exp: !!R.mo })}${more}</span></div>`;
208
- }
209
- /** The cycle chip under the report's name (PM 2026-10-22: "Each report should have a list of issued/archived/draft report"): this cycle's date,
210
- * how many cycles the report has, and a menu of them grouped Draft, Issued and Archived. Picking one reads that cycle here. */
211
- function cycHtml() {
212
- const C = R.cycles || [], when = R.row.date || R.row.slot;
213
- if (C.length < 2) return esc(when || '');
214
- const g = (st, h) => { const L = C.filter((x) => stLabel(x) === st); return L.length ? `<p class="label">${h}</p>` + L.map((x) => `<button type="button" role="menuitemradio" aria-checked="${x.path === R.row.path}" data-rr="cyc|${esc(x.path)}">${esc(x.date || x.slot)}<small>${esc(String(x.path).split('/').pop())}</small>${x.path === R.row.path ? CHK : ''}</button>`).join('') : ''; };
215
- const menu = R.cOpen ? `<div class="dsmn rdcm" role="menu" aria-label="Cycles">${g('Draft', 'Draft')}${g('Issued', 'Issued')}${g('Archived', 'Archived')}</div>` : '';
216
- return `<span class="dsvw rdcw"><button type="button" class="chp rdcyc" data-rr="cycm" aria-haspopup="menu" aria-expanded="${!!R.cOpen}" aria-label="Cycle: ${esc(when)}. Pick another cycle">${esc(when)} · ${C.length} cycles${CHV}</button>${menu}</span>`;
217
- }
218
- function drawCyc() { const s = $('#dSub'); if (!s || !R) return; s.innerHTML = cycHtml(); s.hidden = !s.innerHTML; }
219
- /** Issue it (the console's report Issue, POST /api/report/issue): the press says what it does first, then freezes the bytes the PM read. */
220
- function issueHtml() {
221
- if (R.issued || !R.conf) return '';
222
- return `<div class="dsiss" data-issue-bar="confirm" role="group" aria-label="Issue this cycle"><span>Issue freezes this cycle as it is now. The words and the look stop changing. Nothing is sent to anyone; you share it yourself.</span><span class="dsa"><button type="button" class="dmcta dark" data-rr="issueok"${R.busy ? ' disabled' : ''}>${R.busy ? '<span class="spin"></span>' : CHK}Issue it</button><button type="button" class="dmcta alt" data-rr="issueno"${R.busy ? ' disabled' : ''}>Cancel</button></span></div>`
223
- + (R.issueErr ? `<p class="nodef err" role="alert">${esc(R.issueErr)}</p>` : '');
224
- }
225
- /** Discard and Archive ask once, in the same bar as Issue. */
226
- function askHtml() {
227
- if (!R.ask) return '';
228
- const T = { discard: ['Discard this draft? The file is deleted. Issued reports are not touched.', 'Discard', 'Keep it'],
229
- archive: ['Archive this report? It is kept for good, marked Archived and moved to the end of the Reports list.', 'Archive', 'Cancel'] }[R.ask];
230
- return `<div class="dsiss" data-ask-bar="${R.ask}" role="group" aria-label="${esc(T[1])}"><span>${esc(T[0])}</span><span class="dsa"><button type="button" class="dmcta dark" data-rr="askok"${R.busy ? ' disabled' : ''}>${R.busy ? '<span class="spin"></span>' : ''}${esc(T[1])}</button><button type="button" class="dmcta alt" data-rr="askno"${R.busy ? ' disabled' : ''}>${esc(T[2])}</button></span></div>`
231
- + (R.askErr ? `<p class="nodef err" role="alert">${esc(R.askErr)}</p>` : '');
380
+ const ae = document.activeElement, keep = ae && b.contains(ae) ? ae.getAttribute('data-r') : null;
381
+ b.innerHTML = panelHtml();
382
+ wire(b);
383
+ fit(b);
384
+ if (keep) { const k = b.querySelector(`[data-r="${CSS.escape(keep)}"]`); if (k) k.focus(); }
385
+ if (R.edit) mountEditor();
386
+ }
387
+ function wire(b) {
388
+ b.onclick = (e) => {
389
+ const t = e.target.closest('[data-r]');
390
+ if (!t) { if (R.pop && R.pop !== 'brief' && !e.target.closest('.vz-pop')) { R.pop = null; draw(); } return; }
391
+ if (t.disabled || t.tagName === 'INPUT' || t.tagName === 'SELECT') return;
392
+ if (t.tagName === 'A') { if (t.dataset.r.startsWith('dl|')) { R.pop = null; setTimeout(draw, 0); } return; } // a download or a link to another page
393
+ e.preventDefault(); act(t.dataset.r.split('|'), t);
394
+ };
395
+ b.onchange = (e) => { if (e.target.dataset.r === 'stime') R.sch.time = e.target.value || '09:00'; };
396
+ b.oninput = (e) => { if (e.target.dataset.r === 'shpass') R.shr.pass = e.target.value; };
397
+ b.onkeydown = (e) => {
398
+ if (e.key === 'Escape' && R.pop) { e.preventDefault(); e.stopPropagation(); R.pop = null; draw(); return; }
399
+ 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(); } }
400
+ };
401
+ /* a phone swipes the slide (RpPhone "swipe for the next") */
402
+ let x0 = null;
403
+ b.ontouchstart = (e) => { x0 = !R.edit && R.view === 'deck' && e.target.closest('.vz-slide') && e.touches.length === 1 ? e.touches[0].clientX : null; };
404
+ b.ontouchend = (e) => {
405
+ if (x0 == null) return; const dx = e.changedTouches[0].clientX - x0; x0 = null;
406
+ if (Math.abs(dx) < 40) return; const j = R.i + (dx < 0 ? 1 : -1); if (j >= 0 && j < slides().length) { R.i = j; draw(); }
407
+ };
408
+ b.onmousemove = (e) => { if (R.view !== 'live' || !R.LV) return; const pt = e.target.closest('.rp-pt'); if (pt) { const h = +pt.dataset.r.split('|')[2]; if (R.LV.hover !== h) { R.LV.hover = h; draw(); } } };
409
+ }
410
+ /* a 1280 x 720 frame scales to its slide's width */
411
+ const RO = typeof ResizeObserver === 'function' ? new ResizeObserver((es) => { for (const e of es) scaleOf(e.target, e.contentRect.width); }) : null;
412
+ function scaleOf(el, w) { if (w) el.style.setProperty('--rp-scale', String(Math.round((w / W) * 10000) / 10000)); }
413
+ export function fit(root) { root.querySelectorAll('.vz-fr').forEach((c) => { if (RO) RO.observe(c); scaleOf(c, c.getBoundingClientRect().width); }); }
414
+
415
+ /* ── the presses ── */
416
+ const say = (text, tone) => { R.msg = { text, tone }; draw(); };
417
+ async function act([k, v], t) {
418
+ if (k === 'pop') { R.pop = v || null; return draw(); }
419
+ if (k === 'tab') { if (R.tab === v) return; R.tab = v; R.pop = null; R.conf = false; R.ask = ''; if (v === 'brief' && !R.BF) readBrief(); return draw(); }
420
+ if (k === 'bf') return briefAct(v, t.dataset.r.split('|').slice(2).join('|'));
421
+ if (k === 'lv') return liveAct(v, t.dataset.r.split('|').slice(2).join('|'));
422
+ if (k === 'dlm') { R.pop = R.pop === 'dl' ? null : 'dl'; return draw(); }
423
+ if (k === 'nextcyc') return nextCycle();
424
+ if (k === 'unarch') { R.pop = null; return lifeIt('unarchive', v); }
425
+ if (k === 'view') { if (R.view === v) return; R.view = v; R.pop = null; if (v === 'live' && !R.LV) readLive(); const ed = R.edit && bodyEl() && bodyEl().querySelector('[data-vz-ed]'); if (ed) delete ed.dataset.mounted; return draw(); }
426
+ if (k === 'cycm') { R.pop = R.pop === 'cyc' ? null : 'cyc'; return draw(); }
427
+ 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(); }
428
+ if (k === 'sched') { if (R.pop !== 'sched') { R.sch = schedPick(R.setup); R.schErr = ''; } R.pop = R.pop === 'sched' ? null : 'sched'; return draw(); }
429
+ if (k === 'scad') { R.sch.cad = v; return draw(); }
430
+ if (k === 'sday') { R.sch.day = v; return draw(); }
431
+ if (k === 'sgo') return schedIt(schedOf(R.sch));
432
+ if (k === 'soff') return schedIt('off');
433
+ if (k === 'more') { R.pop = R.pop === 'more' ? null : 'more'; return draw(); }
434
+ if (k === 'share') { if (R.pop !== 'share') openShare(); else { R.pop = null; draw(); } return; }
435
+ if (k === 'prev' || k === 'next') { R.i += k === 'next' ? 1 : -1; return draw(); }
436
+ if (k === 'go') { R.i = +v; return draw(); }
437
+ if (k === 'md') { R.pop = null; saveMd(); return draw(); }
438
+ if (k === 'pdf' || k === 'print') { R.pop = null; draw(); return printIt(); }
439
+ if (k === 'present') { R.pop = null; draw(); return present(true); }
440
+ if (k === 'issue') { R.conf = !R.conf; R.ask = ''; R.issueErr = ''; R.pop = null; draw(); if (R.conf) readChecks(); return; }
441
+ if (k === 'issueno') { R.conf = false; R.issueErr = ''; return draw(); }
442
+ if (k === 'issueok') return issueIt();
443
+ if (k === 'discard' || k === 'archive') { R.ask = k; R.askErr = ''; R.conf = false; R.pop = null; return draw(); }
444
+ if (k === 'askno') { R.ask = ''; return draw(); }
445
+ if (k === 'askok') return lifeIt(R.ask);
446
+ if (k === 'unarchive') { R.pop = null; return lifeIt('unarchive'); }
447
+ if (k === 'edit') { if (R.issued) return; R.edit = true; R.pop = null; R.conf = false; R.ask = ''; R.msg = null; return draw(); }
448
+ if (k === 'notip') { R.noTip = true; const p = t.closest('.vz-tip'); if (p) p.remove(); return; }
449
+ if (k === 'ins') { R.pop = R.pop === 'ins' ? null : 'ins'; return draw(); }
450
+ if (k === 'ed') { R.pop = null; draw(); const b = bodyEl() && bodyEl().querySelector(`[data-vz-ed] [data-c="${v}"]`); if (b) b.click(); return; }
451
+ if (k === 'edcancel') return editCancel();
452
+ if (k === 'edsave') return editSave();
453
+ if (k.startsWith('sh')) return shareAct(k, v);
232
454
  }
233
- async function lifeIt(k) {
234
- const me = R;
235
- R.busy = true; R.askErr = ''; draw();
236
- const archived = k === 'archive';
237
- 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);
238
- if (R !== me) return;
239
- R.busy = false;
240
- 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') + '.'; draw(); return; }
241
- R.ask = '';
242
- if (k === 'discard') {
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;
455
+
456
+ /* ── schedule ── */
457
+ async function schedIt(s) {
458
+ if (!s || R.busy) return;
459
+ const me = R; R.busy = true; R.schErr = ''; draw();
460
+ let r;
461
+ 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);
462
+ else {
463
+ const w = R.W || { sections: [] };
464
+ 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
465
  }
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
466
  if (R !== me) return;
260
467
  R.busy = false;
261
- if (!r || r.ok !== true) { toast('The schedule did not change: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'); draw(); return; }
262
- R.setup = r.setup;
263
- toast('Schedule: ' + schedWords(curSched()) + '.');
264
- draw();
468
+ if (!r || r.ok !== true) { R.schErr = 'The schedule did not change: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'; return draw(); }
469
+ R.setup = r.setup || R.setup; R.pop = null;
470
+ say(s === 'off' ? 'It is no longer drafted on a schedule.' : 'Scheduled: ' + schedLabel(R.setup) + '. Nothing is sent until you issue a cycle.');
265
471
  if (R.onChange) R.onChange();
266
472
  }
267
473
  async function readSetup() {
268
474
  const me = R;
269
475
  const j = await Promise.resolve(pmGet('/api/report-setups?' + q({ ws: R.ws }))).catch(() => null);
270
476
  if (R !== me) return;
271
- R.setup = j && Array.isArray(j.setups) ? j.setups.find((x) => x.id === R.row.cadence) || null : null;
477
+ R.setup = j && Array.isArray(j.setups) ? j.setups.find((x) => x.id === R.id) || null : null;
478
+ if (R.setup && R.setup.audience) R.audience = R.setup.audience;
479
+ if (R.setup && R.setup.name && !R.hand.name) R.name = R.setup.name;
272
480
  }
273
- const cycleOf = (row) => {
481
+
482
+ /* ── issue ── */
483
+ export const cycleOf = (row) => {
274
484
  const m = /reports\/([a-z][a-z0-9-]{0,39})\/(\d{4}-\d{2}-\d{2})\.md$/.exec(String(row.path || ''));
275
485
  return { cadence: row.cadence || (m && m[1]) || '', slot: row.slot || (m && m[2]) || '' };
276
486
  };
487
+ async function readChecks() {
488
+ const me = R; R.checks = null;
489
+ const c = await Promise.resolve(pmGet('/api/viewer-report/checks?' + q({ ws: R.ws, path: R.row.path, slot: R.row.slot }))).catch(() => null);
490
+ if (R !== me) return;
491
+ R.checks = c && c.ok ? c : { ok: false, error: (c && c.error) || 'no answer' }; draw();
492
+ }
277
493
  async function issueIt() {
494
+ if (R.busy) return;
278
495
  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(); return; }
496
+ if (!c.cadence || !c.slot) { R.issueErr = 'This document is not a report cycle, so it cannot be issued.'; return draw(); }
280
497
  R.busy = true; R.issueErr = ''; draw();
281
498
  const cur = await Promise.resolve(pmGet('/api/report/draft?' + q({ ws: R.ws, cadence: c.cadence, slot: c.slot }))).catch(() => null);
282
499
  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(); return; }
284
- if (cur.markdown != null && R.text && cur.markdown !== R.text) {
285
- 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.'; draw(); return;
286
- }
500
+ 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(); }
501
+ 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(); }
502
+ if (!R.ws && cur.ws) R.ws = cur.ws; // the draft read names the workspace when the page was opened without one
287
503
  const r = await pmPost('/api/report/issue', { ws: R.ws, cadence: c.cadence, slot: c.slot, sha: cur.sha }).catch(() => null);
288
504
  if (R !== me) return;
289
505
  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(); return; }
506
+ 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
507
  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
- const eye = $('#dEye'); if (eye) eye.textContent = 'Report · issued';
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();
508
+ R.cycles = R.cycles.map((x) => (x.path === R.row.path ? { ...x, state: 'issued' } : x));
509
+ say('Issued and frozen. Nothing was sent to anyone; share it yourself.');
297
510
  if (R.onIssue) R.onIssue(R.row);
298
511
  }
299
- function draw() {
300
- if (!R) return;
301
- const m = $('#oMain');
302
- drawCyc(); drawSamples();
303
- if (R.edit) { // the editor is drawn in #rdEd by its own module: only the head is drawn again, so what is typed stays
304
- const h = $('#rdHead', m);
305
- if (h && $('#rdEd', m)) { h.innerHTML = barHtml(); return; }
306
- m.innerHTML = `<div class="rdr" id="rdR"><div id="rdHead">${barHtml()}</div><div class="rded" id="rdEd"></div></div>`;
307
- mountEditor();
512
+ async function lifeIt(k, at) {
513
+ if (R.busy) return;
514
+ const me = R, rel = at || R.row.path; R.busy = true; R.askErr = ''; draw();
515
+ const archived = k === 'archive';
516
+ const r = await pmPost('/api/report-documents/' + (k === 'discard' ? 'discard' : 'archive'), k === 'discard' ? { ws: R.ws, path: rel } : { ws: R.ws, path: rel, archived }).catch(() => null);
517
+ if (R !== me) return;
518
+ R.busy = false;
519
+ 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(); }
520
+ R.ask = '';
521
+ if (k === 'discard') {
522
+ if (R.onChange) R.onChange();
523
+ const rest = R.cycles.filter((x) => x.path !== R.row.path);
524
+ if (rest.length) return openReport(rest[0], { ...R.hand, cycles: rest });
525
+ const b = bodyEl(); if (b) b.innerHTML = '<div class="vz"><p class="vz-empty" role="status">The draft is discarded.</p></div>';
308
526
  return;
309
527
  }
310
- const keep = document.activeElement && document.activeElement.closest && document.activeElement.closest('#oMain') ? document.activeElement.getAttribute('data-rr') : null;
311
- m.innerHTML = `<div class="rdr" id="rdR"><div id="rdHead">${barHtml()}</div>${issueHtml()}${askHtml()}${R.err ? `<p class="note rdsrc" role="alert">The document could not be read: ${esc(R.err)}</p>` : ''}${lookHtml()}${R.view === 'deck' ? deckHtml() : pageHtml()}</div>`;
312
- fit(m);
313
- if (keep) { const b = m.querySelector(`[data-rr="${keep}"]`); if (b) b.focus(); }
314
- }
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
-
320
- /* ── the conversation ── */
321
- const stream = () => $('#dBody .stream');
322
- function sayA(t) { const s = stream(); if (!s) return null; s.insertAdjacentHTML('beforeend', turnA(ptx(t))); s.scrollTop = s.scrollHeight; const a = s.querySelectorAll('.turn.a .tt'); return a[a.length - 1]; }
323
- function sayU(t) { const s = stream(); if (s) s.insertAdjacentHTML('beforeend', turnU(t)); }
324
- async function onSay(e) {
325
- e.preventDefault();
326
- const inp = $('#rdIn'), t = inp.value.trim();
327
- if (!t || !R) return;
328
- inp.value = ''; sayU(t);
329
- if (/^Correct "/.test(t)) { await correctBrief(t); return; }
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();
528
+ R.cycles = R.cycles.map((x) => (x.path === rel ? { ...x, archived } : x));
529
+ if (rel === R.row.path) { R.archived = archived; R.row = { ...R.row, archived }; }
530
+ say(archived ? 'Archived. It is kept, at the end of the Reports list.' : (rel === R.row.path ? 'It is back in the Reports list.' : cycleName(R.cycles.find((x) => x.path === rel) || {}, R.id) + ' is back in the Reports list.'));
531
+ if (R.onChange) R.onChange();
367
532
  }
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();
533
+ /** Start the next cycle (RpStates): the template drafts its next cycle; a report with no template drafts one now. The new draft opens. */
534
+ async function nextCycle() {
535
+ if (R.busy) return;
536
+ const me = R, c = cycleOf(R.row); R.busy = true; draw();
537
+ const r = R.setup ? await pmPost('/api/report-setups/draft', { ws: R.ws, id: R.setup.id }).catch(() => null) : await pmPost('/api/report/draft', { ws: R.ws, cadence: c.cadence }).catch(() => null);
538
+ if (R !== me) return;
539
+ R.busy = false;
540
+ if (!r || r.ok !== true) return say('The next cycle was not started: ' + ((r && r.error) || 'the page could not reach PMOS') + '.', 'bad');
541
+ if (R.onChange) R.onChange();
542
+ const at = (r.drafted && r.drafted.path) || r.path;
543
+ if (!at) return say('PMOS is drafting the next cycle. It shows in the cycle menu when it is ready.');
544
+ const slot = (r.drafted && r.drafted.slot) || r.slot || '';
545
+ const row = { path: at, slot, state: 'draft', cadence: c.cadence };
546
+ return openReport(row, { ...R.hand, name: R.name, cycles: [row].concat(R.cycles.filter((x) => x.path !== at)) });
373
547
  }
374
548
 
375
- /** Show the new look when one waits, else this cycle. */
376
- async function syncShow() { const n = newLook(); if (n != null) await showVersion(n); else if (R.show !== 'cycle') { R.show = 'cycle'; R.i = 0; draw(); } }
377
- /** A correction of the Brief (its Correct press fills the box with Correct "<section>": …) is a structure turn: a new structure version, shown in
378
- * the Brief with Use it. The look does not change. */
379
- async function correctBrief(t) {
380
- if (!R.setup) { sayA('This report has no template yet, so it has no brief to correct. Say in a chat how often it is drafted, and PMOS sets one up.'); return; }
381
- const me = R, line = sayA('PMOS is working on the brief.');
382
- const r = await pmPost('/api/report-structure/turn', { ws: R.ws, id: R.id, text: t }).catch(() => null);
549
+ /* ── the Brief (RpBrief): the template, its structure and look, the checks and what the PM confirmed ── */
550
+ async function readBrief() {
551
+ const me = R;
552
+ const [st, de, ch, cf] = await Promise.all([
553
+ R.setup ? pmGet('/api/report-structure?' + q({ ws: R.ws, id: R.id })) : null, R.setup ? pmGet('/api/report-design?' + q({ ws: R.ws, id: R.id })) : null,
554
+ R.issued ? null : pmGet('/api/viewer-report/checks?' + q({ ws: R.ws, path: R.row.path, slot: R.row.slot })), pmGet('/api/report-confirm?' + q({ path: R.row.path })),
555
+ ].map((x) => Promise.resolve(x).catch(() => null)));
383
556
  if (R !== me) return;
384
- if (!r || r.ok !== true) { line.textContent = 'Nothing changed: ' + ((r && r.error) || 'the correction could not start') + '.'; return; }
385
- const t0 = Date.now();
386
- let st = null;
387
- for (;;) {
388
- await new Promise((ok) => setTimeout(ok, POLL_MS));
557
+ R.bfRaw = { structure: st && st.ok ? st.structure : null, design: de && de.ok ? de.design : null, checks: ch, confirms: cf && cf.ok ? cf.keys : [] };
558
+ buildBrief(); draw();
559
+ }
560
+ function buildBrief() {
561
+ const x = R.bfRaw; if (!x) return;
562
+ const goes = R.issued ? 'Issued ' + dayMon(R.row.slot) : R.setup && R.setup.status !== 'paused' ? schedLabel(R.setup) + (R.setup.next_draft ? ' · next ' + dayMon(String(R.setup.next_draft).slice(0, 10)) : '') : '';
563
+ R.BF = briefModel({ ...x, setup: R.setup, W: R.W, issued: R.issued, goesOut: goes, hasTemplate: !!R.setup });
564
+ }
565
+ async function briefAct(a, v) {
566
+ const me = R;
567
+ if (a === 'fix') {
568
+ const it = R.BF && R.BF.confirm.find((c) => c.key === v); if (!it) return;
569
+ const text = (it.where === 'Brief' ? 'Answer' : 'Correct') + ' "' + R.name + '", ' + it.where.toLowerCase() + ': ' + it.text + ' → ';
570
+ const ta = document.getElementById('hmIn'); // Home's chat box, when the Viewer sits beside it
571
+ if (ta) { ta.value = text; ta.dispatchEvent(new Event('input', { bubbles: true })); ta.focus(); R.bfMsg = 'Say the correction in the chat. The report changes on its next draft.'; }
572
+ else R.bfMsg = 'Say the correction in the chat on Home: ' + it.where + ': ' + it.text;
573
+ return draw();
574
+ }
575
+ if (a === 'ok' || a === 'use') {
576
+ R.busy = true; draw();
577
+ const r = await pmPost('/api/report-confirm', { path: R.row.path, key: v, act: a === 'use' ? 'use' : 'confirm' }).catch(() => null);
389
578
  if (R !== me) return;
390
- const j = await Promise.resolve(pmGet('/api/report-structure?' + q({ ws: R.ws, id: R.id }))).catch(() => null);
391
- st = j && j.ok ? j.structure : null;
392
- if ((st && !st.running) || Date.now() - t0 > POLL_MAX) break;
579
+ R.busy = false;
580
+ if (!r || !r.ok) { R.bfMsg = 'That was not kept: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'; return draw(); }
581
+ R.bfRaw.confirms = (R.bfRaw.confirms || []).concat(v); buildBrief(); R.bfMsg = a === 'use' ? 'Kept: it goes out with that figure.' : 'Confirmed.'; return draw();
582
+ }
583
+ if (a === 'again') {
584
+ const c = cycleOf(R.row); R.busy = true; R.bfMsg = 'Reading the sources again.'; draw();
585
+ const r = await pmPost('/api/report/draft', { ws: R.ws, cadence: c.cadence, slot: c.slot, redraft: true }).catch(() => null);
586
+ if (R !== me) return;
587
+ R.busy = false;
588
+ if (!r || !r.ok) { R.bfMsg = 'It was not read again: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'; return draw(); }
589
+ await reread(); if (R !== me) return; R.bfMsg = 'Read again. Your notes are kept.'; return readBrief();
590
+ }
591
+ if (a === 'back') {
592
+ R.busy = true; draw();
593
+ const r = await pmPost('/api/report-design/revert', { ws: R.ws, id: R.id, n: +v }).catch(() => null);
594
+ if (R !== me) return;
595
+ R.busy = false;
596
+ if (!r || !r.ok) { R.bfMsg = 'The look did not change: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'; return draw(); }
597
+ R.bfMsg = 'Back to D' + v + '. Press Use it in the report\'s design to keep it for the next cycle.'; return readBrief();
393
598
  }
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
599
  }
399
600
 
400
- /* ── the presses ── */
401
- async function act(a) {
402
- const [k, v] = a;
403
- if (k === 'view') { if (R.view === v) return; R.view = v; R.mo = false; if (R.edit) $('#oMain').innerHTML = ''; draw(); return; }
404
- if (k === 'mo') { R.mo = !R.mo; R.sOpen = false; R.cOpen = false; draw(); return; }
405
- if (k === 'cycm') { R.cOpen = !R.cOpen; R.mo = false; R.sOpen = false; draw(); return; }
406
- if (k === 'cyc') { const row = (R.cycles || []).find((x) => x.path === v); if (row && row.path !== R.row.path) openReport(row, R.hand); else { R.cOpen = false; draw(); } return; }
407
- if (k === 'brief') { openBrief(); return; }
408
- if (k === 'draftnow') { R.sOpen = false; await draftNow(); return; }
409
- if (k === 'lookno') { await lookIt(false); return; }
410
- if (k === 'lookuse') { await lookIt(true); return; }
411
- if (k === 'edit') { if (R.issued) return; R.edit = true; R.mo = false; R.sOpen = false; R.conf = false; R.ask = ''; $('#oMain').innerHTML = ''; draw(); return; }
412
- if (k === 'prev' || k === 'next') { R.i += k === 'next' ? 1 : -1; draw(); return; }
413
- if (k === 'go') { R.i = +v; draw(); return; }
414
- if (k === 'dl') { R.mo = false; setTimeout(draw, 0); return; }
415
- if (k === 'md') { R.mo = false; saveMd(); draw(); return; }
416
- if (k === 'print') { R.mo = false; draw(); printIt(); return; }
417
- if (k === 'present') { R.mo = false; draw(); present(true); return; }
418
- if (k === 'issue') { R.conf = !R.conf; R.ask = ''; R.issueErr = ''; R.mo = false; R.sOpen = false; draw(); return; }
419
- if (k === 'discard' || k === 'archive') { R.ask = R.ask === k ? '' : k; R.askErr = ''; R.conf = false; R.mo = false; R.sOpen = false; draw(); return; }
420
- if (k === 'askno') { R.ask = ''; R.askErr = ''; draw(); return; }
421
- if (k === 'askok') { if (!R.busy && R.ask) await lifeIt(R.ask); return; }
422
- if (k === 'unarchive') { R.mo = false; if (!R.busy) await lifeIt('unarchive'); return; }
423
- if (k === 'sched') { R.sOpen = !R.sOpen; R.mo = false; R.cOpen = false; draw(); return; }
424
- if (k === 'spick') { await setSched(schedChoices(curSched())[+v]); return; }
425
- if (k === 'sday') { const c = curSched(); if (c && c !== 'off') await setSched(Object.assign({}, c, { day: v })); return; }
426
- if (k === 'share') {
427
- if (R.mo || R.sOpen) { R.mo = false; R.sOpen = false; draw(); }
428
- const b = $('#oMain [data-rr="share"]'); if (!b) return;
429
- vwStyle('doc');
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;
601
+ /* ── the live page (RpLive): GET /api/insights-premium, the numbers Insights reads ── */
602
+ async function readLive(board) {
441
603
  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; }
443
- R.busy = true; draw();
444
- const r = await pmPost('/api/report-design/' + (use ? 'accept' : 'revert'), { ws: R.ws, id: R.id, n: use ? n : R.design.saved.version }).catch(() => null);
604
+ R.LV = Object.assign(R.LV || { range: '8w', pick: null, open: null, hover: null }, { m: null, err: '' });
605
+ const qq = board ? q({ ws: board.ws, board: board.id }) : q({ ws: R.ws });
606
+ let j = null;
607
+ try { const res = await fetch('/api/insights-premium' + (qq ? '?' + qq : ''), { credentials: 'same-origin' }); j = await res.json(); } catch { j = null; }
445
608
  if (R !== me) return;
446
- R.busy = false;
447
- if (!r || r.ok !== true) { draw(); toast((r && r.error) || 'The look did not change.'); return; }
448
- R.design = r.design; R.show = 'cycle'; R.i = 0;
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(); }
609
+ if (!j || !j.ok || !j.model) R.LV.err = 'The numbers could not be read' + (j && j.error ? ': ' + j.error : '') + '.';
610
+ else { R.LV.m = j.model; R.LV.at = j.as_of ? Date.parse(j.as_of) || Date.now() : Date.now(); }
611
+ draw();
452
612
  }
453
- async function draftNow() {
613
+ function liveAct(a, v) {
614
+ const L = R.LV; if (!L) return;
615
+ if (a === 'goal') { L.pick = v; L.hover = null; return draw(); }
616
+ if (a === 'range') { L.range = v; L.hover = null; return draw(); }
617
+ if (a === 'pt') { L.hover = +v; return draw(); }
618
+ if (a === 'row') { L.open = L.open === v ? null : v; return draw(); }
619
+ if (a === 'prod') { R.pop = R.pop === 'prod' ? null : 'prod'; return draw(); }
620
+ if (a === 'board') { const [ws, id] = v.split('~'); R.pop = null; return readLive({ ws, id }); }
621
+ }
622
+
623
+ /* ── share (Link | Send a file): POST /api/shares makes a copy of the file as it is now ── */
624
+ async function openShare() {
454
625
  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();
626
+ 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: '' };
627
+ draw();
628
+ const [l, p] = await Promise.all([pmGet('/api/shares'), R.shr.pass ? null : pmGet('/api/shares/password')]);
629
+ if (R !== me || R.pop !== 'share') return;
630
+ if (l && l.ok) R.shr.list = l.shares || [];
631
+ if (p && p.ok && !R.shr.pass) R.shr.pass = p.password;
632
+ draw();
462
633
  }
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. */
634
+ async function shareAct(k, v) {
635
+ const S = R.shr, me = R;
636
+ if (k === 'shtab') { S.tab = v; return draw(); }
637
+ if (k === 'shdays') { S.days = +v; return draw(); }
638
+ if (k === 'shnopw') { S.pw = false; return draw(); }
639
+ if (k === 'shpw') { S.pw = true; return draw(); }
640
+ if (k === 'shnew') { const p = await pmGet('/api/shares/password'); if (R !== me) return; if (p && p.ok) S.pass = p.password; return draw(); }
641
+ if (k === 'shoff') {
642
+ if (S.off !== v) { S.off = v; return draw(); }
643
+ const r = await pmPost('/api/shares/off', { id: v }); if (R !== me) return;
644
+ 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.';
645
+ return draw();
646
+ }
647
+ 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; }
648
+ if (k === 'shmake') {
649
+ if (S.pw && String(S.pass || '').trim().length < 8) { S.err = 'The password needs at least 8 characters.'; return draw(); }
650
+ S.busy = true; S.err = ''; draw();
651
+ const r = await pmPost('/api/shares', { ws: R.ws, path: R.row.path, days: S.days, password: S.pw ? String(S.pass).trim() : null });
652
+ if (R !== me) return;
653
+ S.busy = false;
654
+ if (!r || !r.ok) { S.err = (r && r.error) || 'The link could not be made.'; return draw(); }
655
+ S.made = { url: r.url, ends: r.ends, pass: S.pw ? String(S.pass).trim() : '' };
656
+ const l = await pmGet('/api/shares'); if (R !== me) return; if (l && l.ok) S.list = l.shares || [];
657
+ return draw();
658
+ }
659
+ if (k === 'shcopy') {
660
+ const txt = S.made.url + (S.made.pass ? '\nPassword: ' + S.made.pass : '');
661
+ try { await navigator.clipboard.writeText(txt); S.copied = 'Copied'; } catch { S.copied = 'Select the link and copy it'; }
662
+ return draw();
663
+ }
664
+ }
665
+
666
+ /* ── edit: the slide editor or the page editor, mounted in the panel (Waiting for design) ── */
471
667
  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 });
668
+ const me = R, b = bodyEl(), host = b && b.querySelector('[data-vz-ed]');
669
+ if (!host || host.dataset.mounted) return;
670
+ host.dataset.mounted = '1';
671
+ const done = async () => { if (R !== me) return; R.edit = false; await reread(); if (R === me) draw(); };
672
+ try {
673
+ if (R.view === 'deck') {
674
+ const m = await import('./premium-vw-slides.js');
675
+ if (R !== me || !host.isConnected) return;
676
+ 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); } });
677
+ } else {
678
+ const m = await import('./premium-vw-doc.js');
679
+ if (R !== me || !host.isConnected) return;
680
+ m.openDocPage({ path: me.row.path, title: me.name + (me.row.slot ? ' · ' + me.row.slot : '') }, { host, ws: () => me.ws, onClose: done });
681
+ }
682
+ } catch (x) { host.innerHTML = placeholderHtml(R.view === 'deck' ? 'Slide editor' : 'Page editor', 'The editor could not start here: ' + String((x && x.message) || x)); }
683
+ }
684
+ const slideState = () => (window.__premiumSlides && R ? window.__premiumSlides.state(R.row.path) : null);
685
+ async function editCancel() {
686
+ const S = slideState();
687
+ 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'); }
688
+ R.leave = false; R.msg = null;
689
+ const b = bodyEl(), c = b && b.querySelector('[data-vz-ed] [data-c="close"]');
690
+ if (S && c) { S.dirty = false; c.click(); return; }
691
+ R.edit = false; await reread(); draw();
692
+ }
693
+ async function editSave() {
694
+ const S = slideState(); if (!S || R.busy) return;
695
+ if (!S.dirty) return say('Nothing has changed since the slides were opened.');
696
+ R.busy = true; draw();
697
+ const r = await window.__premiumSlides.save(S, 'Edited the slides in the report');
698
+ R.busy = false;
699
+ if (!r || !r.ok) return say((r && r.error) || 'The slides could not be saved.', 'bad');
700
+ R.edit = false; R.msg = { text: 'Saved. The reason is in the Edit log.' }; await reread(); draw();
479
701
  }
480
702
  async function reread() {
481
703
  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 reader keeps what it had */ }
704
+ 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
705
  if (R === me) await readCycle();
484
706
  }
707
+
708
+ /* ── files ── */
709
+ async function textOf(url) {
710
+ const r = await fetch(url, { credentials: 'same-origin' });
711
+ if (!r.ok) throw new Error((await r.text().catch(() => '')) || 'the workspace did not answer');
712
+ return r.text();
713
+ }
485
714
  function saveMd() {
486
- const name = (R.row.path.split('/').slice(-2).join('-') || 'report.md');
715
+ const name = fileName();
487
716
  const u = URL.createObjectURL(new Blob([R.text || ''], { type: 'text/markdown' })), a = document.createElement('a');
488
717
  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
- toast('Saved ' + name + '.');
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.');
500
- }
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>`;
718
+ R.msg = { text: 'Saved ' + name + '.' };
519
719
  }
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
720
  function printHtml() {
541
- const s = source(), t = esc(R.name + ' ' + (R.row.slot || ''));
542
- if (s.kind !== 'words' && s.X) return frameDoc(s.X.style, R.view === 'deck' && s.X.slides.length ? s.X.slides.map((x) => x.html).join('') : s.X.body, R.view === 'deck' && s.X.slides.length ? 'pmos-print pmos-print-deck' : 'pmos-print pmos-print-doc').replace('<head>', '<head><title>' + t + '</title>');
721
+ const t = esc(R.name + ' ' + (R.row.slot || ''));
722
+ 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
723
  const css = '<link rel="stylesheet" href="' + esc(href('premium-report-print.css')) + '">';
544
724
  const w = R.W || { title: R.name, sections: [] };
545
725
  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('')
726
+ ? 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
727
  : `<h1>${esc(w.title)}</h1>` + w.sections.map((x) => `<h2>${esc(x.h)}</h2>${slideHtml(x.lines)}`).join('');
548
728
  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
729
  }
550
730
  function printIt() {
551
731
  const w = window.open('', '_blank');
552
- if (!w) { toast('The browser blocked the print window. Allow pop-ups for this page, then press Print again.'); return; }
732
+ if (!w) return say('The browser blocked the print window. Allow pop-ups for this page, then press Print again.', 'bad');
553
733
  w.document.open(); w.document.write(printHtml()); w.document.close();
554
734
  w.focus(); setTimeout(() => { try { w.print(); } catch { /* the PM prints from the window */ } }, 300);
555
735
  }
556
736
 
557
- /* ── the slide editor (premium-viewer R-SL1): the same file, in a Slides tab of the viewer; a save reads the words again ── */
737
+ /* ── Present: the current slide on the whole screen (RpPhone Present; the strip and the hint of MtPresent) ── */
738
+ function present(on) {
739
+ let p = document.getElementById('vzPres');
740
+ 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; }
741
+ const L = slides(); if (!L.length) return say('This cycle has no slides to present.');
742
+ if (!p) {
743
+ p = document.createElement('div'); p.id = 'vzPres'; p.className = 'vz vz-pres rp-pres'; p.setAttribute('role', 'dialog'); p.setAttribute('aria-modal', 'true'); p.setAttribute('aria-label', 'Presenting ' + R.name); p.tabIndex = -1; p.dataset.escLayer = '1';
744
+ R.blank = false;
745
+ p.onclick = (e) => { const t = e.target.closest('[data-r]'); if (!t || t.disabled) return; const [k, v] = t.dataset.r.split('|'); if (k === 'end') return present(false); if (k === 'go') R.i = +v; else R.i += k === 'next' ? 1 : -1; R.blank = false; present(true); };
746
+ p.onkeydown = (e) => {
747
+ if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); return present(false); }
748
+ if (e.key === 'b' || e.key === 'B') { e.preventDefault(); R.blank = !R.blank; return present(true); }
749
+ 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; R.blank = false; present(true); } }
750
+ };
751
+ document.body.appendChild(p);
752
+ if (p.requestFullscreen && !document.fullscreenElement) p.requestFullscreen().catch(() => {});
753
+ }
754
+ const i = R.i = Math.max(0, Math.min(R.i, L.length - 1));
755
+ p.innerHTML = presentHtml({ name: R.name, i, n: L.length, slide: slideCard(L[i]), blank: R.blank });
756
+ fit(p); p.focus();
757
+ }
758
+ if (typeof document !== 'undefined') document.addEventListener('fullscreenchange', () => { if (!document.fullscreenElement && document.getElementById('vzPres')) present(false); });
759
+
558
760
  /* ── reading the cycle ── */
559
761
  async function readCycle() {
762
+ const me = R;
560
763
  const c = await Promise.resolve(pmGet('/api/report-design/cycle?' + q({ ws: R.ws, path: R.row.path }))).catch(() => null);
561
- if (!R) return;
562
- R.cycle = c && c.ok ? c : null;
764
+ if (R !== me) return;
563
765
  R.cyc = null;
564
- if (R.cycle && R.cycle.designed) { try { R.cyc = splitRender(await textOf('/api/report-design/cycle-html?' + q({ ws: R.ws, path: R.row.path }))); } catch { R.cyc = null; } }
766
+ 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
767
  }
768
+ const viewUrl = (row, ws) => '/premium-viewer.html?' + q({ open: 'report', path: row.path, ws });
566
769
 
567
- export async function openReport(row, hand) {
568
- if (!row || !row.path) return;
569
- R = { row, ws: hand.ws, id: row.cadence, name: hand.name || row.cadence, issued: row.state === 'issued', text: '', err: '', W: null, view: 'deck', i: 0, cycle: null, cyc: null, show: 'cycle', ver: new Map(), design: null, dErr: '', busy: false, conf: false, issueErr: '',
570
- onIssue: hand.onIssue || null, onChange: hand.onChange || null, setup: undefined, sOpen: false, ask: '', askErr: '', archived: !!row.archived, edit: false, mo: false,
571
- hand, cycles: (hand.cycles || []).slice(), cOpen: false, noLook: null };
572
- const when = row.date || row.slot;
573
- const say = R.issued
574
- ? 'This is the ' + when + ' cycle of "' + R.name + '". It is issued, so it is frozen. Read it as a deck or a page, present it, download it or print it. Nothing is sent from here.'
575
- : 'This is the ' + when + ' cycle of "' + R.name + '". The Brief (its icon opens a tab) explains how it is made. Tell me how it should look, or attach a sample with the clip. Nothing is sent from here.';
576
- openDlg({ eye: 'Report · ' + (R.issued ? 'issued' : 'draft'), title: R.name, sub: when, stream: turnA(ptx(say)), noteKey: R.issued ? popKey('report-cycle', R.id, when) : null, pane: '<p class="note">Reading the document.</p>', label: 'Report' });
577
- $('#dlg').classList.add('rdrd');
578
- $('#dlg').classList.toggle('rdiss', R.issued); // premium-popup-context P1: an issued cycle has the chat; a draft keeps its own "Say how it should look" box
579
- if (!R.issued) { $('#askF').hidden = true; const an = $('#askNote'); if (an) an.hidden = true; }
580
- if (!R.issued) $('#dBody').insertAdjacentHTML('beforeend', `<div class="rdsmp" id="rdSmp" hidden></div><form class="askbar" id="rdF"><button type="button" class="rdclip" id="rdClip" aria-label="Attach a sample" title="Attach a sample">${CLIP}</button><input type="file" id="rdFile" hidden accept=".pdf,.pptx,.docx,.png,.jpg,.jpeg"><input id="rdIn" placeholder="Say how it should look" maxlength="4000" autocomplete="off" aria-label="Say how the report should look"><button type="submit" aria-label="Send" title="Send">${SEND}</button></form><p class="fine2">A change starts a design run that writes only a new version of the look. The document's words do not change.</p>`);
581
- const f = $('#rdF'); if (f) f.onsubmit = onSay;
582
- const fi = $('#rdFile'), cl = $('#rdClip');
583
- if (fi && cl) { cl.onclick = () => fi.click(); fi.onchange = () => { if (fi.files && fi.files[0] && R) { addSample(fi.files[0]); fi.value = ''; } }; }
584
- const sm = $('#rdSmp'); if (sm) sm.onclick = (e) => { const b = e.target.closest('[data-rr^="unsample|"]'); if (b && !b.disabled && R && !R.busy) removeSample(b.dataset.rr.split('|')[1]); };
585
- const me = R;
586
- try { R.text = await textOf('/api/doc?' + q({ ws: R.ws, path: row.path })); R.W = wordsOf(R.text, R.name); } catch (x) { R.err = String((x && x.message) || x); }
587
- if (R !== me) return;
588
- await Promise.all([readCycle(), R.issued ? null : readDesign(), readSetup()]);
589
- if (R !== me) return;
770
+ /** Open a report cycle in the Viewer. row = { cadence, slot, date, path, state, archived }; hand = { ws, name, cycles, onIssue, onChange } */
771
+ export async function openReport(row, hand = {}) {
772
+ if (!row || !row.path) return null;
773
+ const c = cycleOf(row);
774
+ row = { ...row, cadence: c.cadence, slot: c.slot };
775
+ rpStyle();
776
+ if (R) present(false);
777
+ 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,
778
+ text: '', err: '', W: null, view: 'deck', tab: 'report', BF: null, bfRaw: null, bfMsg: '', LV: null, blank: false, i: 0, cyc: null, setup: undefined, pop: null, conf: false, checks: null, issueErr: '', busy: false, ask: '', askErr: '', edit: false, msg: null,
779
+ sch: schedPick(null), schErr: '', shr: null, hand, cycles: (hand.cycles || []).slice(), onIssue: hand.onIssue || null, onChange: hand.onChange || null, vid: 'report:' + row.path };
780
+ 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; } } });
781
+ vOpen(head());
782
+ 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: [] }; }
783
+ if (R !== me) return me;
784
+ 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
785
+ const d = await Promise.resolve(pmGet('/api/report/draft?' + q({ cadence: c.cadence, slot: c.slot }))).catch(() => null);
786
+ if (R !== me) return me;
787
+ if (d && d.ws) R.ws = d.ws;
788
+ }
789
+ await Promise.all([readCycle(), readSetup()]);
790
+ if (R !== me) return me;
791
+ readBrief(); // the Brief tab's count shows at once
792
+ 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
793
  draw();
591
- if (!R.issued) await syncShow();
794
+ return me;
592
795
  }
593
796
 
594
- /* The reader's presses. The dialog is shared, so each listener first asks whether the reader is what it holds. */
595
- const inReader = (e) => R && $('#dlg').classList.contains('rdrd') && $('#dlg').classList.contains('on') && e.target.closest && e.target.closest('#oMain');
596
- document.addEventListener('click', (e) => {
597
- if (!R || !$('#dlg').classList.contains('rdrd') || !$('#dlg').classList.contains('on') || !e.target.closest) return;
598
- const inSub = e.target.closest('#dSub');
599
- if (inReader(e) || inSub) { const t = e.target.closest('[data-rr]'); if (t && !t.disabled) { act(t.dataset.rr.split('|')); return; } }
600
- if ((R.mo || R.sOpen || R.cOpen) && !e.target.closest('.dsvw')) { R.mo = false; R.sOpen = false; R.cOpen = false; draw(); }
601
- });
602
- document.addEventListener('keydown', (e) => {
603
- if (!R) return;
604
- if ($('#rdPres')) {
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;
797
+ /** The window.czViews entry: a report path (reports/<cadence>/<date>.md) or a Reports row. o = { ws, name, cycles, onIssue, onChange } */
798
+ export async function openReportView(ref, o = {}) {
799
+ const row = typeof ref === 'string' ? { path: ref, state: o.state || '' } : ref;
800
+ if (!row || !row.path) return null;
801
+ const c = cycleOf(row), ws = o.ws || '';
802
+ let cycles = o.cycles || null, state = row.state;
803
+ if (!cycles || !state) { // the cycles of this report and this cycle's state, from GET /api/report-documents
804
+ const j = await Promise.resolve(pmGet('/api/report-documents?' + q({ ws }))).catch(() => null);
805
+ const docs = j && Array.isArray(j.docs) ? j.docs.filter((d) => cycleOf(d).cadence === c.cadence) : [];
806
+ 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)));
807
+ if (!state) { const me = docs.find((d) => d.path === row.path); state = me ? me.state : 'draft'; if (me && me.archived) row.archived = true; }
608
808
  }
609
- if (!inReader(e) || !/^Arrow(Left|Right)$/.test(e.key) || !e.target.closest('.rdk')) return;
610
- const L = slides().length, j = R.i + (e.key === 'ArrowRight' ? 1 : -1);
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'] });
809
+ return openReport({ ...row, state }, { ...o, ws, cycles });
810
+ }