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
@@ -0,0 +1,169 @@
1
+ /* pm/bd-views.js — the Board's List and By stage views, the phone list and the Documents tab (initiative premium-uncovered-features, Board:
2
+ * BdList, BdByStage, BdPhone, BdDocs). Markup from the page's model; the presses go back to the page (premium-board.js) through data- attributes.
3
+ * · List (BdList): one table, sorted by need (your turn, blocked, late, at risk, then by stage); a column title sorts by that column.
4
+ * Monitor and Evaluate sit folded at the foot until "Show them". Each row has ⋯ for its actions (BdActions).
5
+ * · By stage (BdByStage): one column per stage, a card per initiative; Monitor and Evaluate fold into strips when nothing in them needs
6
+ * you, and a strip opens its column. A card is dragged to another column to move its stage (POST /api/boards/move, with Undo).
7
+ * · the phone list (BdPhone): Your turn, At risk or late, On track.
8
+ * · Documents (BdDocs): the board's core documents and the documents its initiatives link (PRD, rubric, evaluation, release notes), with
9
+ * kind chips, health, when it changed and who changed it (GET /api/board-docs), and a row opens the document's panel.
10
+ * Nothing here invents a value: what no record holds is shown as "—" or not drawn. */
11
+ import { esc } from './premium-shell.js';
12
+
13
+ let A = null; // the page: { M(), statusOf(r), usual(t), trail(r), docMeta(path), sel() }
14
+ export function init(api) { A = api; }
15
+ const M = () => A.M();
16
+ const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
17
+ const MORE = 'M5 12h.01M12 12h.01M19 12h.01';
18
+ const cap = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : '');
19
+ const plural = (n, a, b) => (n === 1 ? a : b);
20
+ /** Two letters for an avatar: "Mei" stays "Mei", "Rizky" becomes "Ri", "you" becomes "W"-style initials of the name. */
21
+ export const initials = (name) => { const s = String(name || '').trim(); if (!s) return ''; const p = s.split(/\s+/); return p.length > 1 ? (p[0][0] + p[1][0]).toUpperCase() : s.length <= 3 ? s : s.slice(0, 2); };
22
+ export const avatar = (name, cls = '') => (name ? `<span class="bd-av${cls ? ' ' + cls : ''}" title="${esc(name)}" aria-label="${esc(name)}">${esc(initials(name))}</span>` : '<span class="bd-amut">—</span>');
23
+
24
+ /* ── the step a row is in, and what a row needs ─────────────────────────────────────────────────────────────── */
25
+ const kOf = (r) => (r.track && r.track.k >= 0 ? r.track.k : 99);
26
+ const isME = (r) => r.track && r.track.k >= 6;
27
+ /** The order of need: your turn, blocked, late, at risk, idle, then the rest. */
28
+ export const needOf = (r) => { const t = r.track || {}; return t.you ? 0 : t.blocked ? 1 : r.late ? 2 : r.status === 'at risk' ? 3 : t.idle != null ? 4 : 5; };
29
+ /** The status line of a row in the list, the cards and the phone: the page's status, with "N blocked in Jira" where a ticket is blocked. */
30
+ export function statusLine(r) {
31
+ const s = A.statusOf(r), t = r.track || {};
32
+ if (t.blocked && !t.you && !(r.acts && r.acts.life === 'hold')) return { tone: 'red', mo: 'm-crit', text: t.blocked + ' blocked in Jira' };
33
+ return s;
34
+ }
35
+ /** The output toward the step as a fraction: points or tickets for Build and Deliver, the parts for the others, the record's percent. */
36
+ export function outOf(r) {
37
+ const t = r.track || {};
38
+ if (t.prog && t.prog.unit !== '%' && t.prog.total) return { pct: Math.round((t.prog.done / t.prog.total) * 100), count: t.prog.unit === 'tickets', label: t.count };
39
+ if (t.pct != null) return { pct: t.pct, count: false, label: t.pct + '%' };
40
+ const segs = t.segs || [], n = segs.filter((s) => !s.tk).length;
41
+ if (n && segs.some((s) => s.cls === 'dn')) return { pct: Math.round((segs.filter((s) => s.cls === 'dn').length / n) * 100), count: true, label: t.count };
42
+ return null;
43
+ }
44
+ /** A progress bar; a count (tickets, parts) is striped so it never reads as points (BdPanel). */
45
+ export const barHtml = (o, cls = '') => (o ? `<span class="bd-bar${cls ? ' ' + cls : ''}" role="img" aria-label="${esc(o.label || o.pct + '%')}${o.count ? ' (by count)' : ''}"><i class="${o.count ? 'cnt' : ''}" style="width:${Math.max(0, Math.min(100, o.pct))}%"></i></span>` : '<span class="bd-bar" aria-hidden="true"><i style="width:0"></i></span>');
46
+ const stepText = (r, days) => { const t = r.track || {}; return (t.label || r.stage || 'No stage') + (days && t.days != null ? ' · ' + t.days + 'd' : ''); };
47
+ /** What the row waits on next: the trail's next part, else the first line under its Output bar. */
48
+ const nextOf = (r) => { const t = r.track || {}; if (typeof t.next === 'string' && t.next) return t.next; if (t.next && t.next.text) return t.next.text; const l = (t.line || [])[0]; return l ? l.text : ''; };
49
+
50
+ /* ── List (BdList) ───────────────────────────────────────────────────────────────────────────────────────────── */
51
+ let sortBy = 'need', meOpen = false;
52
+ const COLS = [['title', 'Initiative'], ['kind', 'Kind'], ['stage', 'Stage'], ['need', 'Status'], ['owner', 'Owner'], ['', 'Next'], ['finish', 'Finish'], ['', 'Output'], ['', '']];
53
+ const SORTS = {
54
+ need: (a, b) => needOf(a) - needOf(b) || kOf(a) - kOf(b),
55
+ title: (a, b) => String(a.title).localeCompare(String(b.title)),
56
+ kind: (a, b) => String(a.lane || '').localeCompare(String(b.lane || '')) || needOf(a) - needOf(b),
57
+ stage: (a, b) => kOf(a) - kOf(b) || needOf(a) - needOf(b),
58
+ owner: (a, b) => String(a.owner || '~').localeCompare(String(b.owner || '~')),
59
+ finish: (a, b) => String(a.end || '9999').localeCompare(String(b.end || '9999')),
60
+ };
61
+ export function setSort(k) { if (SORTS[k]) sortBy = k; }
62
+ export function toggleME() { meOpen = !meOpen; }
63
+ function listRow(r) {
64
+ const s = statusLine(r), sel = A.sel && A.sel() === r.key, finish = r.end ? r.finish : '—';
65
+ return `<div class="bd-lt${sel ? ' sel' : ''}${r.acts && r.acts.life === 'hold' ? ' held' : ''}" role="row" data-row="${esc(r.key)}">`
66
+ + `<button type="button" class="bd-ltn ini2" data-key="${esc(r.key)}" role="rowheader" aria-haspopup="dialog"><b>${esc(r.title)}</b></button>`
67
+ + `<span role="cell" class="bd-amut">${esc(cap(r.lane) || '—')}</span><span role="cell">${(r.track || {}).ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(stepText(r, true))}</span>`
68
+ + `<span role="cell" class="cs s-${s.tone}"><i class="cz-dot ${s.tone} ${s.mo || ''}"></i>${esc(s.text)}</span>`
69
+ + `<span role="cell">${avatar(r.owner)}</span><span role="cell" class="bd-amut bd-ell">${esc(nextOf(r) || '—')}</span>`
70
+ + `<span role="cell"${r.over ? ' class="bd-late"' : ''}>${esc(finish)}</span><span role="cell">${barHtml(outOf(r))}</span>`
71
+ + `<button type="button" class="bd-ib sm" data-rowmenu="${esc(r.key)}" aria-haspopup="menu" aria-expanded="false" aria-label="More for ${esc(r.title)}" title="Actions">${SV(MORE)}</button></div>`;
72
+ }
73
+ export function listHtml(L, filtered) {
74
+ const S = M().steps || [];
75
+ const all = L.slice().sort(SORTS[sortBy] || SORTS.need);
76
+ const top = all.filter((r) => !isME(r)), me = all.filter(isME);
77
+ const meTotal = Math.max(me.length, (S[6] ? S[6].count : 0) + (S[7] ? S[7].count : 0));
78
+ const head = `<div class="bd-lt h" role="row">${COLS.map(([k, n], i) => (k ? `<button type="button" role="columnheader" class="bd-lth${sortBy === k ? ' on' : ''}" data-sort="${k}" aria-sort="${sortBy === k ? 'ascending' : 'none'}">${i === 0 ? esc(n) + (sortBy === 'need' ? ' · sorted by need' : '') : esc(n)}</button>` : `<span role="columnheader">${esc(n)}</span>`)).join('')}</div>`;
79
+ if (!L.length) return `<div class="bd-ltw" role="table" aria-label="Initiatives">${head}<p class="bt-empty">${filtered ? 'No initiative matches the chips or the filter. <button type="button" class="dlink" id="fClear">Clear them</button>' : 'No initiatives are on this board\'s now view.'}</p></div>`;
80
+ const fold = meTotal ? (meOpen
81
+ ? me.map(listRow).join('') + `<div class="bd-lt foot" role="row"><span class="bd-amut">Monitor and Evaluate · ${meTotal}${meTotal > me.length ? ' · ' + (meTotal - me.length) + ' more are not loaded' : ''}</span><button type="button" class="bd-btn sm" data-me aria-expanded="true">Fold them</button></div>`
82
+ : `<div class="bd-lt foot" role="row"><span class="bd-amut">${meTotal} more in Monitor and Evaluate · sorted below</span><button type="button" class="bd-btn sm" data-me aria-expanded="false">Show them</button></div>`) : '';
83
+ return `<div class="bd-ltw" role="table" aria-label="Initiatives">${head}${top.map(listRow).join('')}${fold}</div><p class="bd-foot">Press a column title to sort. Press a row to open its panel, the same panel as the stage track.</p>`;
84
+ }
85
+
86
+ /* ── By stage (BdByStage) ─────────────────────────────────────────────────────────────────────────────────────── */
87
+ const opened = new Set(); // the Monitor and Evaluate strips the PM opened
88
+ export function toggleStrip(k) { if (opened.has(k)) opened.delete(k); else opened.add(k); }
89
+ const EMPTY = ['Nothing in Triage.', 'Nothing in Discover.', 'Nothing in Plan.', 'Nothing waits to be ranked.', 'Nothing in Build.', 'Nothing waits to ship.', 'Nothing in Monitor.', 'Nothing waits for a verdict.'];
90
+ function card(r, drag) {
91
+ const t = r.track || {}, s = statusLine(r), u = A.usual(t);
92
+ const left = r.owner ? avatar(r.owner) : `<span>${esc(t.count && t.count !== 'Not counted yet' ? (t.output || '').split(/[ ,+]/)[0] + ' ' + t.count : '')}</span>`;
93
+ const right = t.key === 'deliver' && r.release ? r.release.name + ' · ' + r.release.at : (t.key === 'build' || t.key === 'deliver') && t.prog && t.prog.unit !== '%' ? t.count : t.days != null ? t.days + 'd' + (u ? ' · usually ' + u.days : '') : '';
94
+ return `<button type="button" class="bd-bc ini2${t.ms ? ' ms' : ''}${t.you ? ' you' : ''}${A.sel && A.sel() === r.key ? ' sel' : ''}" data-key="${esc(r.key)}"${drag ? ' draggable="true"' : ''} aria-haspopup="dialog"><b class="t">${esc(r.title)}</b><span class="s cs s-${s.tone}"><i class="cz-dot ${s.tone} ${s.mo || ''}"></i>${esc(s.text)}</span><span class="f">${left}<span>${esc(right)}</span></span></button>`;
95
+ }
96
+ export function stagesHtml(L, o = {}) {
97
+ const S = M().steps || [], drag = !M().board.self && !o.phone;
98
+ const cols = S.map((s, j) => {
99
+ const rs = L.filter((r) => r.track && r.track.k === j).sort((a, b) => needOf(a) - needOf(b));
100
+ const fold = j >= 6 && !o.phone && !opened.has(s.key) && !rs.some((r) => r.track.you);
101
+ if (fold) return `<button type="button" class="bd-strip" data-strip="${s.key}" aria-label="Show ${esc(s.label)}, ${s.count} ${plural(s.count, 'initiative', 'initiatives')}"><span>${s.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(s.label)} · ${s.count}</span></button>`;
102
+ const shut = j >= 6 && !o.phone && opened.has(s.key) ? `<button type="button" class="bd-ib sm" data-strip="${s.key}" aria-label="Fold ${esc(s.label)}" title="Fold">${SV('M7 14l5-5 5 5')}</button>` : '';
103
+ return `<section class="bd-scol" aria-label="${esc(s.label)}" data-step="${j}"><h3>${s.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(s.label)}<span>${s.count}</span>${shut}</h3>${rs.map((r) => card(r, drag)).join('') || `<p class="bd-amut bd-cempty">${esc(EMPTY[j] || 'Nothing here.')}</p>`}</section>`;
104
+ }).join('');
105
+ const foot = o.phone ? '' : `<div class="bd-foot bd-sfoot"><span>Monitor and Evaluate fold when nothing in them needs you. Press a strip to open it.</span>${drag ? '<span>Drag a card to move its stage</span>' : ''}</div>`;
106
+ return `<div class="bd-scols${o.phone ? ' ph' : ''}">${cols}</div>${foot}`;
107
+ }
108
+
109
+ /* ── the phone list (BdPhone) ─────────────────────────────────────────────────────────────────────────────────── */
110
+ export function phoneListHtml(L) {
111
+ const you = L.filter((r) => r.track && r.track.you), bad = L.filter((r) => !you.includes(r) && needOf(r) <= 3), rest = L.filter((r) => !you.includes(r) && !bad.includes(r));
112
+ const row = (r) => {
113
+ const s = statusLine(r), t = r.track || {};
114
+ const sub = [t.label || r.stage, t.you ? t.you.replace(/^Your /, 'your ') : s.tone !== 'ok' && s.tone !== 'q' ? s.text.toLowerCase() : '', r.owner].filter(Boolean).join(' · ');
115
+ return `<button type="button" class="bd-lrow ini2${A.sel && A.sel() === r.key ? ' sel' : ''}" data-key="${esc(r.key)}" aria-haspopup="dialog"><i class="cz-dot ${s.tone} ${s.mo || ''}"></i><span class="tx"><span class="t">${esc(r.title)}</span><span class="s${t.you ? '' : ' q'}">${esc(sub)}</span></span>${t.you && t.days != null ? `<span class="r">${t.days}d</span>` : ''}</button>`;
116
+ };
117
+ const grp = (name, rs) => (rs.length ? `<div class="bd-ghd">${esc(name)}<span class="n">${rs.length}</span></div>${rs.map(row).join('')}` : '');
118
+ if (!L.length) return '<p class="bt-empty">No initiative matches the chips or the filter.</p>';
119
+ return `<div class="bd-plist">${grp('Your turn', you)}${grp('At risk or late', bad)}${grp('On track', rest)}</div>`;
120
+ }
121
+
122
+ /* ── Documents (BdDocs) ───────────────────────────────────────────────────────────────────────────────────────── */
123
+ let docKind = 'all';
124
+ export function setDocKind(k) { docKind = k || 'all'; }
125
+ const DOC_IC = { PRD: 'M7 3h7l5 5v13H7zM14 3v5h5', BRD: 'M7 3h7l5 5v13H7zM14 3v5h5', Rubric: 'M5 12l5 5 9-10', Evaluation: 'M5 20V11M12 20V5M19 20v-6', 'Release notes': 'M4 5h16v14H4zM8 9h8M8 13h5', Board: 'M4 4h16v16H4zM4 9h16M9 9v11' };
126
+ const ST_TONE = { ok: 'ok', draft: 'y', stale: 'w', due: 'w', missing: '', linked: '' };
127
+ /** Every document the tab lists: the initiatives' own (from the trail's links) and the board's core documents. */
128
+ export function docRows() {
129
+ const out = [], seen = new Set(), m = M();
130
+ for (const r of m.initiatives.list.rows) {
131
+ const T = A.trail(r), L = (T && T.links) || {};
132
+ const add = (kind, label, path, extra = {}) => { if (!path || seen.has(path)) return; seen.add(path); out.push({ src: 'ini', kind, title: label, path, ini: r, ...extra }); };
133
+ const drift = (T && T.drift) || [];
134
+ const parts = r.track && r.track.key === 'discover' && T && Array.isArray(T.parts) ? T.parts : null;
135
+ add('PRD', L.prdVersion ? 'PRD v' + String(L.prdVersion).replace(/^v/i, '') : 'PRD', L.prd, { drift, parts });
136
+ add('Rubric', 'Rubric', L.rubric); add('Evaluation', 'Evaluation', L.evaluation); add('Release notes', 'Release notes' + (r.release ? ' ' + r.release.name : ''), L.notes, { you: !!(r.track && r.track.you && r.track.key === 'deliver') });
137
+ }
138
+ for (const d of (m.docs && m.docs.rows) || []) out.push({ src: 'core', kind: 'Board', title: d.title, path: d.path || null, d });
139
+ return out;
140
+ }
141
+ /** A row's id: a core document by its key (its path appears only once drafted), an initiative's by its path. */
142
+ export const docId = (x) => (x.src === 'core' ? 'core:' + x.d.key : x.path);
143
+ export function healthOf(x) {
144
+ if (x.src === 'core') return { tone: ST_TONE[x.d.st] || '', text: x.d.state || '—' };
145
+ if (x.drift && x.drift.length) return { tone: 'w', text: 'Changed after the push' };
146
+ if (x.parts) { const d = x.parts.filter((p) => p.done).length; return { tone: d === x.parts.length ? 'ok' : '', text: d === x.parts.length ? 'Complete' : d + ' of ' + x.parts.length + ' parts' }; }
147
+ if (x.you) return { tone: 'y', text: 'Waits on your sign-off' };
148
+ return { tone: '', text: 'Linked' };
149
+ }
150
+ export function docsHtml() {
151
+ const m = M(), D = m.docs || { rows: [] }, rows = docRows();
152
+ const kinds = [...new Set(rows.map((x) => x.kind))];
153
+ if (docKind !== 'all' && !kinds.includes(docKind)) docKind = 'all';
154
+ const chips = `<div class="bd-dchips" role="group" aria-label="Kind">${[['all', 'All', rows.length]].concat(kinds.map((k) => [k, k, rows.filter((x) => x.kind === k).length])).map(([k, n, c]) => `<button type="button" class="bd-chip${docKind === k ? ' on' : ''}" data-dkind="${esc(k)}" aria-pressed="${docKind === k}">${esc(n)} ${c}</button>`).join('')}<span class="bd-sp"></span>${D.scope ? '<button type="button" class="bd-btn" id="addDoc" data-act="adddoc">Add a document</button>' : ''}</div>`;
155
+ const shown = rows.filter((x) => docKind === 'all' || x.kind === docKind);
156
+ if (!rows.length) return chips + `<p class="bd-amut">${D.missing ? 'The core documents could not be read, so none is shown.' : 'No document is on this board yet.'}</p>`;
157
+ const sel = A.docSel ? A.docSel() : null;
158
+ const row = (x) => {
159
+ const h = healthOf(x), meta = x.path ? A.docMeta(x.path) : null, d = x.d || {};
160
+ const changed = x.src === 'core' ? d.when || d.added || '—' : meta && meta.changed ? meta.changed + (x.drift && x.drift.length ? ' · after the push' : '') : '—';
161
+ const by = x.src === 'core' ? `<span class="bd-amut">${esc(d.by || '—')}</span>` : meta && meta.by ? avatar(meta.by, 'b') : '<span class="bd-amut">—</span>';
162
+ const act = x.src === 'core' && d.act && d.act.kind === 'draft' ? `<button type="button" class="bd-btn sm" data-act="draft" data-key="${esc(d.key)}"${d.running ? ' disabled' : ''}>${d.running ? 'Drafting' : esc(d.act.label || 'Draft it')}</button>` : '';
163
+ const id = docId(x);
164
+ return `<div class="bd-dt${sel === id ? ' sel' : ''}" role="row" data-docrow="${esc(id)}"><span class="bd-dic" aria-hidden="true">${SV(DOC_IC[x.kind] || DOC_IC.PRD)}</span>`
165
+ + `<button type="button" class="bd-dlink" role="rowheader" data-opendoc="${esc(id)}">${esc(x.title)}</button><span role="cell">${esc(x.src === 'core' ? m.board.name || 'Board' : x.ini.title)}</span>`
166
+ + `<span role="cell"><span class="bd-pill${h.tone ? ' ' + h.tone : ''}">${esc(h.text)}</span></span><span role="cell" class="bd-amut">${esc(changed)}</span><span role="cell" class="bd-dby">${by}${act}</span></div>`;
167
+ };
168
+ return chips + `<div class="bd-dtw" role="table" aria-label="Documents"><div class="bd-dt h" role="row"><span></span><span role="columnheader">Document</span><span role="columnheader">Initiative</span><span role="columnheader">Health</span><span role="columnheader">Changed</span><span role="columnheader">By</span></div>${shown.map(row).join('')}</div>`;
169
+ }
@@ -46,7 +46,7 @@ import { say } from './c3-init-extras.js';
46
46
  import { c3btn } from './page-agent.js';
47
47
  import { button } from './primitives.js';
48
48
  import { mountSlide } from './slide-confirm.js';
49
- import { parseMd, toMd, canonMd, diffMd, toDom, fromDom, wordCounts, safeHref } from './c3-md.js';
49
+ import { parseMd, toMd, canonMd, diffMd, toDom, fromDom, wordCounts, safeHref } from './cozy-md.js';
50
50
  import { ensureReportCss, formatOf, formatView, outlineLabels, downloadsOf, printPdf, copyKindFor } from './c3-doc-formats.js';
51
51
 
52
52
  /* the sheet's width (initiative c3-doc-sheet-size): Normal (780px), Half, 3/4 or Whole window, as the session, meeting and studio sheets */
@@ -1,395 +1,3 @@
1
- /* pm/c3-md.js — markdown for the console3 document sheet (initiative c3-doc-sheet-rich): read it as rich text, edit it as rich
2
- * text, and show a change as a rendered diff.
3
- *
4
- * parseMd(md) → blocks the subset PMOS documents use: headings, paragraphs, quotes, bulleted, numbered and
5
- * checklist lists, tables, dividers and fenced code; inline bold, italic, code and links
6
- * toMd(blocks) → md the canonical markdown of blocks; toMd(parseMd(toMd(b))) === toMd(b)
7
- * canonMd(md) → md toMd(parseMd(md)): two texts that read the same compare equal
8
- * diffMd(before, after) → md `after`, with the words removed and added since `before` wrapped in markers that
9
- * toDom draws as <del> and <ins>; a line or sentence rewritten in most of its words is
10
- * shown whole, removed then added
11
- * toDom(blocks, doc?) → Node[] the blocks as elements (no innerHTML: every text is a text node); links are http(s),
12
- * mailto or relative only
13
- * fromDom(root) → blocks what the rich-text editor holds, read back as blocks
14
- *
15
- * parseMd, toMd, canonMd and diffMd are pure (Node-testable: c3-md.test.js); toDom and fromDom need a document.
16
- */
17
-
18
- export const INS = '\uE000';
19
- export const INS_END = '\uE001';
20
- export const DEL = '\uE002';
21
- export const DEL_END = '\uE003';
22
- const MARK = /[\uE000-\uE003]/g;
23
-
24
- /* ── inline ── */
25
-
26
- /** Inline markdown → [{ t:'text', s } | { t:'b'|'i', c:[…] } | { t:'code', s } | { t:'a', href, c:[…] }]. */
27
- export function parseInline(src) {
28
- const s = String(src == null ? '' : src);
29
- const out = [];
30
- let buf = '';
31
- const flush = () => { if (buf) { out.push({ t: 'text', s: buf }); buf = ''; } };
32
- let i = 0;
33
- while (i < s.length) {
34
- const c = s[i];
35
- if (c === '\\' && i + 1 < s.length && /[\\`*_[\]()#|>-]/.test(s[i + 1])) { buf += s[i + 1]; i += 2; continue; }
36
- if (c === '`') {
37
- const j = s.indexOf('`', i + 1);
38
- if (j > i) { flush(); out.push({ t: 'code', s: s.slice(i + 1, j) }); i = j + 1; continue; }
39
- }
40
- if (c === '[') {
41
- const m = /^\[((?:[^\]\\]|\\.)+)\]\(([^)\s]+)\)/.exec(s.slice(i));
42
- if (m) { flush(); out.push({ t: 'a', href: m[2], c: parseInline(m[1]) }); i += m[0].length; continue; }
43
- }
44
- if ((c === '*' || c === '_') && s[i + 1] === c) {
45
- const j = s.indexOf(c + c, i + 2);
46
- if (j > i + 2) { flush(); out.push({ t: 'b', c: parseInline(s.slice(i + 2, j)) }); i = j + 2; continue; }
47
- }
48
- if ((c === '*' || c === '_') && s[i + 1] !== c && s[i + 1] !== ' ' && (c === '*' || !/\w/.test(s[i - 1] || ''))) {
49
- let j = i + 1;
50
- while (j < s.length && !(s[j] === c && s[j + 1] !== c && s[j - 1] !== ' ' && s[j - 1] !== c)) j++;
51
- if (j < s.length && j > i + 1 && (c === '*' || !/\w/.test(s[j + 1] || ''))) { flush(); out.push({ t: 'i', c: parseInline(s.slice(i + 1, j)) }); i = j + 1; continue; }
52
- }
53
- buf += c; i++;
54
- }
55
- flush();
56
- return out;
57
- }
58
-
59
- // Text is escaped only where markdown would read it as syntax: a backslash before punctuation, `, *, [ and ], and an _ that
60
- // is not inside a word (snake_case stays as written).
61
- const escText = (s) => String(s).replace(/\\(?=[\\`*_[\]()#|>-])/g, '\\\\').replace(/[`*[\]]/g, '\\$&').replace(/(^|\W)_|_(?=\W|$)/g, (m) => m.replace('_', '\\_'));
62
- /** Inline nodes → markdown. `raw`: text as it is, unescaped (for a plain-text label). */
63
- export function inlineMd(nodes, raw) {
64
- return (nodes || []).map((n) => {
65
- if (n.t === 'text') return raw ? n.s : escText(n.s);
66
- if (n.t === 'code') return raw ? n.s : '`' + n.s + '`';
67
- const inner = inlineMd(n.c, raw);
68
- if (raw || !inner.trim()) return inner;
69
- const lead = inner.match(/^\s*/)[0]; const tail = inner.match(/\s*$/)[0]; const core = inner.trim();
70
- if (n.t === 'b') return lead + '**' + core + '**' + tail;
71
- if (n.t === 'i') return lead + '*' + core + '*' + tail;
72
- if (n.t === 'a') return lead + '[' + core + '](' + n.href + ')' + tail;
73
- return inner;
74
- }).join('');
75
- }
76
- // a paragraph or list item whose text would start a heading, quote, list or rule is escaped at its start
77
- const lineSafe = (s) => s.replace(/^(#{1,6}\s|>|[-+]\s|\d+[.)]\s|-{3,}\s*$)/, '\\$1');
78
-
79
- /* ── blocks ── */
80
-
81
- const LIST = /^(\s*)([-*+]|\d+[.)])\s+/;
82
- const TASK = /^\[( |x|X)\]\s+/;
83
- const cells = (r) => {
84
- const t = r.trim().replace(/^\|/, '').replace(/\|\s*$/, '');
85
- const out = []; let cur = ''; for (let i = 0; i < t.length; i++) { if (t[i] === '\\' && t[i + 1] === '|') { cur += '|'; i++; } else if (t[i] === '|') { out.push(cur.trim()); cur = ''; } else cur += t[i]; }
86
- out.push(cur.trim()); return out;
87
- };
88
- const isRule = (l) => /^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(l);
89
- const startsBlock = (l) => /^(#{1,6}\s|>|```|~~~|\s*(-{3,}|\*{3,}|_{3,})\s*$)/.test(l) || LIST.test(l) || /^\s*\|/.test(l);
90
-
91
- /** Markdown → blocks: { t:'h', level, c } · { t:'p', c } · { t:'quote', blocks } · { t:'list', ordered, items:[{ task, c }] } ·
92
- * { t:'table', head:[c], rows:[[c]] } · { t:'hr' } · { t:'code', lang, s }. Marker characters (diffMd) pass through as text. */
93
- export function parseMd(md) {
94
- const L = String(md == null ? '' : md).replace(/\r\n?/g, '\n').split('\n');
95
- const out = []; let i = 0;
96
- const bare = (l) => l.replace(MARK, '');
97
- while (i < L.length) {
98
- const l = L[i]; const b = bare(l); let m;
99
- if (!b.trim()) { i++; continue; }
100
- if ((m = /^(```|~~~)\s*([\w-]*)/.exec(b))) {
101
- const fence = m[1]; const body = []; i++;
102
- while (i < L.length && !bare(L[i]).startsWith(fence)) body.push(L[i++]);
103
- i++; out.push({ t: 'code', lang: m[2] || '', s: body.join('\n') }); continue;
104
- }
105
- if ((m = /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(l))) { out.push({ t: 'h', level: m[1].length, c: parseInline(m[2]) }); i++; continue; }
106
- if (/^\s*(-{3,}|\*{3,}|_{3,})\s*$/.test(b)) { out.push({ t: 'hr' }); i++; continue; }
107
- if (/^\s*>/.test(b)) {
108
- const body = [];
109
- while (i < L.length && /^\s*>/.test(bare(L[i]))) body.push(L[i++].replace(/^(\s*[\uE000-\uE003]*)\s*>\s?/, '$1'));
110
- out.push({ t: 'quote', blocks: parseMd(body.join('\n')) }); continue;
111
- }
112
- if (/^\s*\|/.test(b) && i + 1 < L.length && isRule(bare(L[i + 1]))) {
113
- const head = cells(l); i += 2; const rows = [];
114
- while (i < L.length && /^\s*\|/.test(bare(L[i]))) rows.push(cells(L[i++]));
115
- out.push({ t: 'table', head: head.map(parseInline), rows: rows.map((r) => head.map((_, k) => parseInline(r[k] || ''))) }); continue;
116
- }
117
- if (LIST.test(b)) {
118
- const ordered = /^\s*\d/.test(b); const items = [];
119
- while (i < L.length && LIST.test(bare(L[i])) && /^\s*\d/.test(bare(L[i])) === ordered) {
120
- const lead = (/^[\uE000-\uE003]*/.exec(L[i]) || [''])[0];
121
- let t = lead + L[i].slice(lead.length).replace(LIST, ''); i++;
122
- while (i < L.length && /^\s{2,}\S/.test(L[i]) && !LIST.test(bare(L[i]))) t += ' ' + L[i++].trim();
123
- const tk = TASK.exec(t.replace(MARK, ''));
124
- if (tk) { const k = t.indexOf('['); t = t.slice(0, k) + t.slice(k).replace(TASK, ''); }
125
- items.push({ task: tk ? tk[1] !== ' ' : null, c: parseInline(t) });
126
- }
127
- out.push({ t: 'list', ordered, items }); continue;
128
- }
129
- const body = [];
130
- while (i < L.length && bare(L[i]).trim() && (!body.length || !startsBlock(bare(L[i])))) body.push(L[i++].trim());
131
- out.push({ t: 'p', c: parseInline(body.join(' ')) });
132
- }
133
- return out;
134
- }
135
-
136
- /** Blocks → markdown, one blank line between blocks. */
137
- export function toMd(blocks) {
138
- return (blocks || []).map((b) => {
139
- if (b.t === 'h') return '#'.repeat(b.level || 2) + ' ' + inlineMd(b.c).trim();
140
- if (b.t === 'p') return lineSafe(inlineMd(b.c).trim());
141
- if (b.t === 'hr') return '---';
142
- if (b.t === 'code') return '```' + (b.lang || '') + '\n' + b.s + '\n```';
143
- if (b.t === 'quote') return toMd(b.blocks).split('\n').map((x) => (x ? '> ' + x : '>')).join('\n');
144
- if (b.t === 'list') return b.items.map((it, k) => (b.ordered ? (k + 1) + '. ' : '- ') + (it.task == null ? '' : it.task ? '[x] ' : '[ ] ') + inlineMd(it.c).trim()).join('\n');
145
- if (b.t === 'table') {
146
- const cell = (c) => inlineMd(c).trim().replace(/\|/g, '\\|');
147
- const w = Math.max(b.head.length, ...b.rows.map((r) => r.length));
148
- const line = (r) => '| ' + Array.from({ length: w }, (_, k) => (r[k] ? cell(r[k]) : '')).join(' | ') + ' |';
149
- return [line(b.head), '|' + Array.from({ length: w }, () => '---').join('|') + '|', ...b.rows.map(line)].join('\n');
150
- }
151
- return '';
152
- }).filter((x) => x !== '').join('\n\n');
153
- }
154
-
155
- export const canonMd = (md) => toMd(parseMd(md));
156
-
157
- /* ── the rendered diff ── */
158
-
159
- function lcs(a, b) {
160
- const n = a.length, m = b.length;
161
- if (n * m > 400000) return [...a.map((x) => ['-', x]), ...b.map((x) => ['+', x])];
162
- const T = Array.from({ length: n + 1 }, () => new Int32Array(m + 1));
163
- for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) T[i][j] = a[i] === b[j] ? T[i + 1][j + 1] + 1 : Math.max(T[i + 1][j], T[i][j + 1]);
164
- const ops = []; let i = 0, j = 0;
165
- while (i < n && j < m) { if (a[i] === b[j]) { ops.push(['=', a[i]]); i++; j++; } else if (T[i + 1][j] >= T[i][j + 1]) ops.push(['-', a[i++]]); else ops.push(['+', b[j++]]); }
166
- while (i < n) ops.push(['-', a[i++]]); while (j < m) ops.push(['+', b[j++]]);
167
- return ops;
168
- }
169
- /** Runs of ops: [{ eq:true, items } | { eq:false, del:[…], add:[…] }]. */
170
- function runs(ops) {
171
- const out = [];
172
- for (const [op, x] of ops) {
173
- const last = out[out.length - 1];
174
- if (op === '=') { if (last && last.eq) last.items.push(x); else out.push({ eq: true, items: [x] }); }
175
- else { if (!last || last.eq) out.push({ eq: false, del: [], add: [] }); out[out.length - 1][op === '-' ? 'del' : 'add'].push(x); }
176
- }
177
- return out;
178
- }
179
- const wrap = (s, a, z) => (s && s.trim() ? a + s + z : s);
180
- function words(a, b) {
181
- const tok = (x) => x.match(/\s+|[^\s]+/g) || [];
182
- const A = tok(a), B = tok(b); const ops = lcs(A, B);
183
- const real = (x) => /\S/.test(x);
184
- const same = ops.filter(([o, x]) => o === '=' && real(x)).length;
185
- const tot = Math.max(A.filter(real).length, B.filter(real).length);
186
- if (tot > 4 && same / tot < 0.6) return wrap(a, DEL, DEL_END) + ' ' + wrap(b, INS, INS_END);
187
- return runs(ops).map((r) => (r.eq ? r.items.join('') : wrap(r.del.join(''), DEL, DEL_END) + (r.del.length && r.add.length ? ' ' : '') + wrap(r.add.join(''), INS, INS_END))).join('');
188
- }
189
- function sentences(a, b) {
190
- const cut = (x) => x.split(/(?<=[.;!?])\s+/);
191
- const A = cut(a), B = cut(b);
192
- if (A.length < 2 && B.length < 2) return words(a, b);
193
- return runs(lcs(A, B)).map((r) => {
194
- if (r.eq) return r.items.join(' ');
195
- const n = Math.min(r.del.length, r.add.length); const parts = [];
196
- for (let k = 0; k < n; k++) parts.push(words(r.del[k], r.add[k]));
197
- r.del.slice(n).forEach((x) => parts.push(wrap(x, DEL, DEL_END)));
198
- r.add.slice(n).forEach((x) => parts.push(wrap(x, INS, INS_END)));
199
- return parts.join(' ');
200
- }).join(' ');
201
- }
202
- const PREFIX = /^(\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?|\s*>\s?|#{1,6}\s+)/;
203
- function wrapLine(l, a, z) {
204
- if (!l.trim() || isRule(l)) return l;
205
- if (/^\s*\|/.test(l)) return '| ' + cells(l).map((c) => wrap(c, a, z)).join(' | ') + ' |';
206
- if (/^(```|~~~)/.test(l) || /^\s*(-{3,}|\*{3,})\s*$/.test(l)) return l;
207
- const p = (PREFIX.exec(l) || [''])[0];
208
- return p + wrap(l.slice(p.length), a, z);
209
- }
210
- function lineDiff(a, b) {
211
- const pa = (PREFIX.exec(a) || [''])[0], pb = (PREFIX.exec(b) || [''])[0];
212
- if (/^\s*\|/.test(a) && /^\s*\|/.test(b) && !isRule(a) && !isRule(b)) {
213
- const ca = cells(a), cb = cells(b);
214
- return '| ' + cb.map((c, k) => (ca[k] === c ? c : sentences(ca[k] || '', c))).join(' | ') + ' |';
215
- }
216
- if (pa === pb) return pb + sentences(a.slice(pa.length), b.slice(pb.length));
217
- return null;
218
- }
219
-
220
- /** `after` with the change since `before` marked. `before` null: the whole of `after` is new. */
221
- export function diffMd(before, after) {
222
- const B = String(after == null ? '' : after).split('\n');
223
- if (before == null) return B.map((l) => wrapLine(l, INS, INS_END)).join('\n');
224
- const A = String(before).split('\n');
225
- const out = [];
226
- for (const r of runs(lcs(A, B))) {
227
- if (r.eq) { out.push(...r.items); continue; }
228
- const n = Math.min(r.del.length, r.add.length);
229
- const removed = []; const added = [];
230
- for (let k = 0; k < n; k++) {
231
- const d = lineDiff(r.del[k], r.add[k]);
232
- if (d == null) { removed.push(wrapLine(r.del[k], DEL, DEL_END)); added.push(wrapLine(r.add[k], INS, INS_END)); } else added.push(d);
233
- }
234
- r.del.slice(n).forEach((l) => removed.push(wrapLine(l, DEL, DEL_END)));
235
- r.add.slice(n).forEach((l) => added.push(wrapLine(l, INS, INS_END)));
236
- // a removed table row or list item stays in its table or list: put it with the rows after it
237
- out.push(...removed.filter((l) => l.trim()), ...added);
238
- }
239
- return out.join('\n');
240
- }
241
-
242
- /** Words added and removed between two texts: [added, removed]. */
243
- export function wordCounts(before, after) {
244
- const A = String(before || '').match(/\S+/g) || [], B = String(after || '').match(/\S+/g) || [];
245
- let add = 0, del = 0;
246
- for (const [o] of lcs(A, B)) { if (o === '+') add++; else if (o === '-') del++; }
247
- return [add, del];
248
- }
249
-
250
- /* ── DOM ── */
251
-
252
- /** A safe href: http(s), mailto, a fragment or a relative path; anything else (javascript:, data:) is dropped. */
253
- export function safeHref(h) {
254
- const s = String(h || '').trim();
255
- if (/^(https?:|mailto:)/i.test(s)) return s;
256
- if (/^[a-z][\w+.-]*:/i.test(s)) return null;
257
- return s;
258
- }
259
-
260
- /** Text with diff markers → nodes: the marked runs inside <ins> and <del>. `st` carries an open marker across inline nodes. */
261
- function textNodes(doc, s, st) {
262
- const out = []; let buf = '';
263
- const push = () => {
264
- if (!buf) return;
265
- const t = doc.createTextNode(buf); buf = '';
266
- if (st.mode) { const w = doc.createElement(st.mode); w.appendChild(t); out.push(w); } else out.push(t);
267
- };
268
- for (const ch of String(s)) {
269
- if (ch === INS || ch === DEL) { push(); st.mode = ch === INS ? 'ins' : 'del'; }
270
- else if (ch === INS_END || ch === DEL_END) { push(); st.mode = null; }
271
- else buf += ch;
272
- }
273
- push();
274
- return out;
275
- }
276
- function inlineDom(doc, nodes, st) {
277
- const out = [];
278
- for (const n of nodes || []) {
279
- if (n.t === 'text') { out.push(...textNodes(doc, n.s, st)); continue; }
280
- if (n.t === 'code') { const c = doc.createElement('code'); c.append(...textNodes(doc, n.s, st)); out.push(c); continue; }
281
- const tag = n.t === 'b' ? 'strong' : n.t === 'i' ? 'em' : 'a';
282
- const e = doc.createElement(tag);
283
- if (n.t === 'a') {
284
- const h = safeHref(n.href);
285
- if (h != null) { e.setAttribute('href', h); if (/^https?:/i.test(h)) { e.setAttribute('target', '_blank'); e.setAttribute('rel', 'noopener'); } }
286
- }
287
- e.append(...inlineDom(doc, n.c, st));
288
- out.push(e);
289
- }
290
- return out;
291
- }
292
-
293
- /** Blocks → elements. `opts.editable` draws checklist boxes that can be ticked (the editor). */
294
- export function toDom(blocks, doc, opts = {}) {
295
- const d = doc || document;
296
- const mk = (tag, cls) => { const e = d.createElement(tag); if (cls) e.className = cls; return e; };
297
- return (blocks || []).map((b) => {
298
- const st = { mode: null };
299
- if (b.t === 'h') { const e = mk('h' + Math.min(6, Math.max(1, b.level || 2))); e.append(...inlineDom(d, b.c, st)); return e; }
300
- if (b.t === 'p') { const e = mk('p'); e.append(...inlineDom(d, b.c, st)); return e; }
301
- if (b.t === 'hr') return mk('hr');
302
- if (b.t === 'code') { const p = mk('pre'); if (b.lang) p.setAttribute('data-lang', b.lang); const c = mk('code'); c.append(...textNodes(d, b.s, st)); p.appendChild(c); return p; }
303
- if (b.t === 'quote') { const q = mk('blockquote'); q.append(...toDom(b.blocks, d, opts)); return q; }
304
- if (b.t === 'list') {
305
- const l = mk(b.ordered ? 'ol' : 'ul', b.items.some((it) => it.task != null) ? 'tasks' : '');
306
- for (const it of b.items) {
307
- const li = mk('li');
308
- if (it.task != null) {
309
- li.className = 'task' + (it.task ? ' done' : '');
310
- const box = mk('input'); box.type = 'checkbox'; box.checked = !!it.task; box.setAttribute('aria-label', 'Done');
311
- if (opts.editable) box.setAttribute('contenteditable', 'false'); else box.disabled = true;
312
- const sp = mk('span'); sp.append(...inlineDom(d, it.c, st));
313
- li.append(box, sp);
314
- } else li.append(...inlineDom(d, it.c, st));
315
- l.appendChild(li);
316
- }
317
- return l;
318
- }
319
- if (b.t === 'table') {
320
- const w = mk('div', 'tw'); const t = mk('table'); const th = mk('thead'); const tr = mk('tr');
321
- for (const c of b.head) { const x = mk('th'); x.append(...inlineDom(d, c, st)); tr.appendChild(x); }
322
- th.appendChild(tr); const tb = mk('tbody');
323
- for (const r of b.rows) { const row = mk('tr'); for (const c of r) { const x = mk('td'); x.append(...inlineDom(d, c, st)); row.appendChild(x); } tb.appendChild(row); }
324
- t.append(th, tb); w.appendChild(t); return w;
325
- }
326
- return d.createTextNode('');
327
- });
328
- }
329
-
330
- /* reading the editor back */
331
- function inlineOf(n) {
332
- const out = [];
333
- const text = (s) => { if (!s) return; const last = out[out.length - 1]; if (last && last.t === 'text') last.s += s; else out.push({ t: 'text', s }); };
334
- for (const c of Array.from(n.childNodes || [])) {
335
- if (c.nodeType === 3) { text(c.textContent.replace(/\u00a0/g, ' ').replace(/\u200b/g, '').replace(/\s+/g, ' ')); continue; }
336
- if (c.nodeType !== 1) continue;
337
- const t = c.tagName;
338
- if (t === 'BR') { text(' '); continue; }
339
- if (t === 'INPUT' || t === 'UL' || t === 'OL') continue;
340
- if (t === 'CODE') { out.push({ t: 'code', s: c.textContent.replace(/\u200b/g, '') }); continue; }
341
- if (t === 'STRONG' || t === 'B') { out.push({ t: 'b', c: inlineOf(c) }); continue; }
342
- if (t === 'EM' || t === 'I') { out.push({ t: 'i', c: inlineOf(c) }); continue; }
343
- if (t === 'A') { out.push({ t: 'a', href: c.getAttribute('href') || '', c: inlineOf(c) }); continue; }
344
- if (t === 'SPAN' && /font-weight:\s*(bold|[6-9]00)/.test(c.getAttribute('style') || '')) { out.push({ t: 'b', c: inlineOf(c) }); continue; }
345
- if (t === 'SPAN' && /font-style:\s*italic/.test(c.getAttribute('style') || '')) { out.push({ t: 'i', c: inlineOf(c) }); continue; }
346
- for (const x of inlineOf(c)) { if (x.t === 'text') text(x.s); else out.push(x); }
347
- }
348
- return out;
349
- }
350
- const trimInline = (c) => {
351
- const a = c.slice();
352
- while (a.length && a[0].t === 'text' && !a[0].s.trim()) a.shift();
353
- while (a.length && a[a.length - 1].t === 'text' && !a[a.length - 1].s.trim()) a.pop();
354
- if (a.length && a[0].t === 'text') a[0] = { ...a[0], s: a[0].s.replace(/^\s+/, '') };
355
- if (a.length && a[a.length - 1].t === 'text') a[a.length - 1] = { ...a[a.length - 1], s: a[a.length - 1].s.replace(/\s+$/, '') };
356
- return a;
357
- };
358
- const BLOCK = /^(P|DIV|H[1-6]|BLOCKQUOTE|UL|OL|TABLE|PRE|HR|SECTION)$/;
359
- /** The editor's children → blocks. Loose text and inline nodes between blocks become a paragraph. */
360
- export function fromDom(root) {
361
- const out = []; let loose = null;
362
- const endLoose = () => { if (loose) { const c = trimInline(inlineOf(loose)); if (c.length) out.push({ t: 'p', c }); loose = null; } };
363
- for (const n of Array.from(root.childNodes || [])) {
364
- if (n.nodeType === 1 && BLOCK.test(n.tagName)) { endLoose(); out.push(...blockOf(n)); continue; }
365
- if (n.nodeType === 3 && !n.textContent.trim() && !loose) continue;
366
- if (!loose) loose = (root.ownerDocument || document).createElement('p');
367
- loose.appendChild(n.cloneNode(true));
368
- }
369
- endLoose();
370
- return out;
371
- }
372
- function blockOf(n) {
373
- const t = n.tagName;
374
- if (/^H[1-6]$/.test(t)) return [{ t: 'h', level: +t[1], c: trimInline(inlineOf(n)) }];
375
- if (t === 'HR') return [{ t: 'hr' }];
376
- if (t === 'PRE') return [{ t: 'code', lang: n.getAttribute('data-lang') || '', s: n.textContent.replace(/\n$/, '') }];
377
- if (t === 'BLOCKQUOTE') { const b = fromDom(n); return b.length ? [{ t: 'quote', blocks: b }] : []; }
378
- if (t === 'UL' || t === 'OL') {
379
- const items = Array.from(n.children).filter((li) => li.tagName === 'LI').map((li) => {
380
- const box = li.querySelector(':scope > input[type=checkbox]');
381
- return { task: box ? !!box.checked : null, c: trimInline(inlineOf(li)) };
382
- });
383
- const nested = Array.from(n.querySelectorAll(':scope > li > ul, :scope > li > ol')).flatMap(blockOf);
384
- return [{ t: 'list', ordered: t === 'OL', items }, ...nested];
385
- }
386
- if (t === 'TABLE' || (t === 'DIV' && n.querySelector(':scope > table'))) {
387
- const tb = t === 'TABLE' ? n : n.querySelector(':scope > table');
388
- const rows = Array.from(tb.querySelectorAll('tr')).map((r) => Array.from(r.children).map((c) => trimInline(inlineOf(c))));
389
- if (!rows.length) return [];
390
- return [{ t: 'table', head: rows[0], rows: rows.slice(1) }];
391
- }
392
- if ((t === 'DIV' || t === 'SECTION') && Array.from(n.children).some((c) => BLOCK.test(c.tagName))) return fromDom(n);
393
- const c = trimInline(inlineOf(n));
394
- return c.length ? [{ t: 'p', c }] : [];
395
- }
1
+ /* pm/c3-md.js — moved to pm/cozy-md.js (premium-agreed-design: no c3-* module loads on a premium page). The console keeps importing
2
+ * this name, so it re-exports the one copy. */
3
+ export * from './cozy-md.js';
@@ -15,7 +15,7 @@ import { button, row } from './primitives.js';
15
15
  import { pmGet } from './http.js';
16
16
  import { c3ic } from './pm-work-view.js';
17
17
  import { openSheet, closeSheet } from './c3-sheet.js';
18
- import { parseMd, toDom } from './c3-md.js';
18
+ import { parseMd, toDom } from './cozy-md.js';
19
19
 
20
20
  const p2 = (n) => String(n).padStart(2, '0');
21
21
  const hm = (iso) => { const d = new Date(iso); return p2(d.getHours()) + ':' + p2(d.getMinutes()); };