create-pmos 0.399.0 → 0.401.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 (425) hide show
  1. package/package.json +30 -25
  2. package/payload/KIT-VERSION +1 -1
  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/workspace/briefing-premium-adddoc-test.js +2 -2
  7. package/workspace/briefing-premium-board-test.js +3 -3
  8. package/workspace/briefing-premium-doc-edit-test.js +2 -8
  9. package/workspace/briefing-premium-sources-test.js +2 -0
  10. package/workspace/briefing-premium-test.js +6 -2
  11. package/workspace/briefing-premium-work-test.js +9 -4
  12. package/workspace/c3-capture-test.js +0 -17
  13. package/workspace/changelog.json +29 -0
  14. package/workspace/guide/briefing-premium.md +2 -2
  15. package/workspace/guide/home.md +24 -3
  16. package/workspace/guide/layout.md +2 -2
  17. package/workspace/guide/notes.md +2 -2
  18. package/workspace/guide/phone-companion.md +1 -1
  19. package/workspace/lib/core-docs.js +2 -2
  20. package/workspace/lib/route-modules.js +1 -9
  21. package/workspace/lib/routes-phone-day.js +18 -9
  22. package/workspace/lib/routes-slash.js +95 -0
  23. package/workspace/package-lock.json +2 -2
  24. package/workspace/package.json +1 -2
  25. package/workspace/premium-chat-goal-view-test.js +1 -1
  26. package/workspace/premium-chat-term-test.js +0 -10
  27. package/workspace/premium-menu-rows-test.js +1 -1
  28. package/workspace/premium-phone-card-test.js +8 -3
  29. package/workspace/premium-vw-cal-test.js +4 -1
  30. package/workspace/premium-vw-doc-test.js +1 -8
  31. package/workspace/premium-work-depth-test.js +2 -3
  32. package/workspace/public/capture.html +23 -0
  33. package/workspace/public/pm/c3-base.js +47 -0
  34. package/workspace/public/pm/c3-capture.js +1 -1
  35. package/workspace/public/pm/c3-ini-ui.js +1 -1
  36. package/workspace/public/pm/c3-sheet.js +1 -1
  37. package/workspace/public/pm/c3-toast.js +1 -1
  38. package/workspace/public/pm/console3.css +3 -0
  39. package/workspace/public/pm/cozy-home.css +21 -6
  40. package/workspace/public/pm/cozy-today.css +4 -3
  41. package/workspace/public/pm/cozy-viewer.js +4 -2
  42. package/workspace/public/pm/cozy.css +9 -0
  43. package/workspace/public/pm/goal-chat.js +5 -1
  44. package/workspace/public/pm/home-app.js +65 -33
  45. package/workspace/public/pm/home-chat.js +34 -29
  46. package/workspace/public/pm/home-data.js +10 -2
  47. package/workspace/public/pm/home-dictate.js +7 -4
  48. package/workspace/public/pm/home-ini.js +13 -3
  49. package/workspace/public/pm/home-list.js +18 -10
  50. package/workspace/public/pm/home-more.js +2 -2
  51. package/workspace/public/pm/home-phone-card.js +9 -4
  52. package/workspace/public/pm/home-review.js +2 -3
  53. package/workspace/public/pm/home-today.js +11 -8
  54. package/workspace/public/pm/home-work.js +13 -8
  55. package/workspace/public/pm/note-dock.js +1 -2
  56. package/workspace/public/pm/notes-links.js +1 -2
  57. package/workspace/public/pm/notes-task.js +3 -4
  58. package/workspace/public/pm/premium-board.js +1 -1
  59. package/workspace/public/pm/premium-initiative-head.js +3 -3
  60. package/workspace/public/pm/premium-vw-doc.css +20 -2
  61. package/workspace/public/pm/premium-vw-doc.js +22 -7
  62. package/workspace/public/pm/premium-vw-item.css +6 -0
  63. package/workspace/public/pm/view-notes.js +2 -2
  64. package/workspace/replaced-tests.json +435 -0
  65. package/workspace/run-tests.js +323 -28
  66. package/workspace/server.js +15 -10
  67. package/workspace/test-files.json +4 -140
  68. package/workspace/test-lists/base.json +1 -2
  69. package/workspace/test-lists/c3-desktop-light-load.json +1 -2
  70. package/workspace/test-lists/c3-initiative-boards.json +1 -2
  71. package/workspace/test-lists/c3-meeting-focus.json +2 -12
  72. package/workspace/test-lists/c3-work-agent.json +1 -2
  73. package/workspace/test-lists/calendar-tidy-up.json +1 -2
  74. package/workspace/test-lists/console3-reports.json +1 -2
  75. package/workspace/test-lists/docs-three-way-sync.json +1 -2
  76. package/workspace/test-lists/extension-capture.json +5 -0
  77. package/workspace/test-lists/jira-wbs.json +1 -2
  78. package/workspace/test-lists/legacy-cleanup-a.json +9 -0
  79. package/workspace/test-lists/meeting-material.json +1 -2
  80. package/workspace/test-lists/meeting-notes.json +2 -36
  81. package/workspace/test-lists/meeting-replay.json +1 -2
  82. package/workspace/test-lists/mm-capture.json +2 -12
  83. package/workspace/test-lists/my-work.json +2 -10
  84. package/workspace/test-lists/onboarding-firstrun.json +2 -12
  85. package/workspace/test-lists/people-directory.json +1 -2
  86. package/workspace/test-lists/run2-a.json +1 -2
  87. package/workspace/test-lists/run2-d.json +2 -19
  88. package/workspace/test-lists/run3-b.json +1 -2
  89. package/workspace/test-lists/run3-c.json +2 -12
  90. package/workspace/test-lists/run4-b.json +1 -2
  91. package/workspace/test-lists/run4-d.json +1 -5
  92. package/workspace/test-lists/run5-c.json +1 -11
  93. package/workspace/test-lists/run6.json +1 -5
  94. package/workspace/test-lists/workspace-launch-flags.json +2 -12
  95. package/workspace/test-lists/workspace-profile-detection.json +2 -10
  96. package/workspace/test-timings.json +242 -123
  97. package/workspace/c3-briefing-test.js +0 -136
  98. package/workspace/c3-core-docs-test.js +0 -170
  99. package/workspace/c3-driver-fixture.js +0 -64
  100. package/workspace/c3-driver-test.js +0 -169
  101. package/workspace/c3-foundation-test.js +0 -163
  102. package/workspace/c3-ib-items-test.js +0 -114
  103. package/workspace/c3-ib-more-test.js +0 -146
  104. package/workspace/c3-ib-triage-backlog-test.js +0 -128
  105. package/workspace/c3-ini-harness.js +0 -66
  106. package/workspace/c3-ini-life-test.js +0 -167
  107. package/workspace/c3-initiatives-test.js +0 -186
  108. package/workspace/c3-light-load-test.js +0 -112
  109. package/workspace/c3-one-home-test.js +0 -149
  110. package/workspace/c3-phone-test.js +0 -289
  111. package/workspace/c3-quiet-test.js +0 -157
  112. package/workspace/c3-report-design-real-test.js +0 -264
  113. package/workspace/c3-report-design-test.js +0 -442
  114. package/workspace/c3-report-setup-test.js +0 -192
  115. package/workspace/c3-report-structure-real-test.js +0 -248
  116. package/workspace/c3-report-structure-test.js +0 -397
  117. package/workspace/c3-reports-test.js +0 -288
  118. package/workspace/c3-scan-test.js +0 -517
  119. package/workspace/c3-sessions-panel-test.js +0 -365
  120. package/workspace/c3-settings-test.js +0 -204
  121. package/workspace/c3-updates-test.js +0 -131
  122. package/workspace/c3-work-test.js +0 -260
  123. package/workspace/cut-stub.js +0 -40
  124. package/workspace/first-paint-audit.js +0 -160
  125. package/workspace/lib/c3-full-console.js +0 -15
  126. package/workspace/lib/engine/derived/trust.js +0 -3
  127. package/workspace/lib/engine/plan-forecast.js +0 -342
  128. package/workspace/lib/engine/report-families.js +0 -175
  129. package/workspace/lib/engine/truth-table.js +0 -57
  130. package/workspace/lib/routes-c3-init.js +0 -54
  131. package/workspace/lib/routes-c3-life.js +0 -120
  132. package/workspace/lib/routes-c3-timeline.js +0 -192
  133. package/workspace/lib/routes-forecast.js +0 -86
  134. package/workspace/lib/routes-releases.js +0 -130
  135. package/workspace/lib/routes-report-facts.js +0 -85
  136. package/workspace/lib/routes-report-families.js +0 -33
  137. package/workspace/lib/routes-signals.js +0 -51
  138. package/workspace/lib/routes-timeline.js +0 -197
  139. package/workspace/public/c3.html +0 -35
  140. package/workspace/public/index.html +0 -156
  141. package/workspace/public/pm/app.js +0 -831
  142. package/workspace/public/pm/bd-board.js +0 -159
  143. package/workspace/public/pm/bd-drag.js +0 -59
  144. package/workspace/public/pm/bd-model.js +0 -152
  145. package/workspace/public/pm/bd-timeline.js +0 -233
  146. package/workspace/public/pm/bd-tree.js +0 -244
  147. package/workspace/public/pm/board-copy.js +0 -59
  148. package/workspace/public/pm/board-read.js +0 -38
  149. package/workspace/public/pm/branches-sheet.js +0 -56
  150. package/workspace/public/pm/breakdown-api.js +0 -58
  151. package/workspace/public/pm/breakdown-copy.js +0 -138
  152. package/workspace/public/pm/briefing-deck.js +0 -441
  153. package/workspace/public/pm/briefing-model.js +0 -251
  154. package/workspace/public/pm/c3-ambient.js +0 -100
  155. package/workspace/public/pm/c3-audience-link.js +0 -21
  156. package/workspace/public/pm/c3-audience.js +0 -46
  157. package/workspace/public/pm/c3-boot.js +0 -13
  158. package/workspace/public/pm/c3-breakdown.js +0 -240
  159. package/workspace/public/pm/c3-brief-data.js +0 -11
  160. package/workspace/public/pm/c3-brief-mentions.js +0 -137
  161. package/workspace/public/pm/c3-brief-needs.js +0 -288
  162. package/workspace/public/pm/c3-brief-pulse.js +0 -112
  163. package/workspace/public/pm/c3-brief-summary.js +0 -139
  164. package/workspace/public/pm/c3-brief-today.js +0 -79
  165. package/workspace/public/pm/c3-brief.js +0 -279
  166. package/workspace/public/pm/c3-cal-strategy.js +0 -529
  167. package/workspace/public/pm/c3-calendar.js +0 -965
  168. package/workspace/public/pm/c3-calpop.js +0 -111
  169. package/workspace/public/pm/c3-case.js +0 -196
  170. package/workspace/public/pm/c3-core-docs.css +0 -18
  171. package/workspace/public/pm/c3-core-docs.js +0 -236
  172. package/workspace/public/pm/c3-daypart.js +0 -176
  173. package/workspace/public/pm/c3-demo-boards.js +0 -764
  174. package/workspace/public/pm/c3-demo-brief-ix.js +0 -350
  175. package/workspace/public/pm/c3-demo-brief-page.js +0 -70
  176. package/workspace/public/pm/c3-demo-cal-ix.js +0 -74
  177. package/workspace/public/pm/c3-demo-cal2.js +0 -66
  178. package/workspace/public/pm/c3-demo-cal3.js +0 -173
  179. package/workspace/public/pm/c3-demo-cal4.js +0 -169
  180. package/workspace/public/pm/c3-demo-cal5.js +0 -52
  181. package/workspace/public/pm/c3-demo-coredocs.js +0 -221
  182. package/workspace/public/pm/c3-demo-data.js +0 -552
  183. package/workspace/public/pm/c3-demo-focus.js +0 -181
  184. package/workspace/public/pm/c3-demo-init.js +0 -430
  185. package/workspace/public/pm/c3-demo-life.js +0 -77
  186. package/workspace/public/pm/c3-demo-material.js +0 -58
  187. package/workspace/public/pm/c3-demo-misc2.js +0 -34
  188. package/workspace/public/pm/c3-demo-phone.js +0 -48
  189. package/workspace/public/pm/c3-demo-plan2.js +0 -30
  190. package/workspace/public/pm/c3-demo-rd.js +0 -432
  191. package/workspace/public/pm/c3-demo-rep-ix.js +0 -126
  192. package/workspace/public/pm/c3-demo-rep2.js +0 -130
  193. package/workspace/public/pm/c3-demo-rep3.js +0 -138
  194. package/workspace/public/pm/c3-demo-rs.js +0 -287
  195. package/workspace/public/pm/c3-demo-term.js +0 -153
  196. package/workspace/public/pm/c3-demo-time.js +0 -49
  197. package/workspace/public/pm/c3-demo-work-ix.js +0 -32
  198. package/workspace/public/pm/c3-demo.js +0 -131
  199. package/workspace/public/pm/c3-design-studio.js +0 -369
  200. package/workspace/public/pm/c3-doc-formats.js +0 -153
  201. package/workspace/public/pm/c3-doc-sheet.js +0 -1230
  202. package/workspace/public/pm/c3-dock.js +0 -206
  203. package/workspace/public/pm/c3-docs.js +0 -291
  204. package/workspace/public/pm/c3-driver-work.js +0 -110
  205. package/workspace/public/pm/c3-driver.css +0 -18
  206. package/workspace/public/pm/c3-driver.js +0 -298
  207. package/workspace/public/pm/c3-focus.css +0 -304
  208. package/workspace/public/pm/c3-focus.js +0 -983
  209. package/workspace/public/pm/c3-ib-docs.js +0 -92
  210. package/workspace/public/pm/c3-ib-initiatives.js +0 -201
  211. package/workspace/public/pm/c3-ib-items.js +0 -210
  212. package/workspace/public/pm/c3-ib-releases.js +0 -48
  213. package/workspace/public/pm/c3-ib-sprints.js +0 -201
  214. package/workspace/public/pm/c3-ib-triage.js +0 -177
  215. package/workspace/public/pm/c3-ii-tabs.js +0 -252
  216. package/workspace/public/pm/c3-ini-life.css +0 -34
  217. package/workspace/public/pm/c3-ini-life.js +0 -379
  218. package/workspace/public/pm/c3-ini-records.js +0 -197
  219. package/workspace/public/pm/c3-ini-timeline.js +0 -278
  220. package/workspace/public/pm/c3-ini-work.js +0 -139
  221. package/workspace/public/pm/c3-init-extras.js +0 -170
  222. package/workspace/public/pm/c3-initiatives.js +0 -852
  223. package/workspace/public/pm/c3-lifecycle-panels.js +0 -479
  224. package/workspace/public/pm/c3-look.js +0 -27
  225. package/workspace/public/pm/c3-material.css +0 -22
  226. package/workspace/public/pm/c3-material.js +0 -321
  227. package/workspace/public/pm/c3-md.js +0 -3
  228. package/workspace/public/pm/c3-misc-panels.js +0 -89
  229. package/workspace/public/pm/c3-new-session.js +0 -110
  230. package/workspace/public/pm/c3-notes.js +0 -751
  231. package/workspace/public/pm/c3-phone-boot.js +0 -47
  232. package/workspace/public/pm/c3-phone-detail.js +0 -97
  233. package/workspace/public/pm/c3-phone-model.js +0 -3
  234. package/workspace/public/pm/c3-phone.css +0 -66
  235. package/workspace/public/pm/c3-phone.js +0 -444
  236. package/workspace/public/pm/c3-plan-panels.js +0 -163
  237. package/workspace/public/pm/c3-plan.js +0 -193
  238. package/workspace/public/pm/c3-quiet.css +0 -113
  239. package/workspace/public/pm/c3-quiet.js +0 -177
  240. package/workspace/public/pm/c3-replay.css +0 -133
  241. package/workspace/public/pm/c3-replay.js +0 -429
  242. package/workspace/public/pm/c3-report-deck.css +0 -163
  243. package/workspace/public/pm/c3-report-deck.js +0 -598
  244. package/workspace/public/pm/c3-report-frame.css +0 -20
  245. package/workspace/public/pm/c3-report-print.css +0 -20
  246. package/workspace/public/pm/c3-report-setup.css +0 -67
  247. package/workspace/public/pm/c3-report-setup.js +0 -298
  248. package/workspace/public/pm/c3-report-store.js +0 -244
  249. package/workspace/public/pm/c3-report-structure.css +0 -44
  250. package/workspace/public/pm/c3-report-structure.js +0 -473
  251. package/workspace/public/pm/c3-reports.css +0 -68
  252. package/workspace/public/pm/c3-reports.js +0 -377
  253. package/workspace/public/pm/c3-roadmap.js +0 -249
  254. package/workspace/public/pm/c3-scan-api.js +0 -167
  255. package/workspace/public/pm/c3-scan-next.js +0 -248
  256. package/workspace/public/pm/c3-scan-setup.js +0 -313
  257. package/workspace/public/pm/c3-scan-words.js +0 -41
  258. package/workspace/public/pm/c3-scan.css +0 -74
  259. package/workspace/public/pm/c3-scan.js +0 -93
  260. package/workspace/public/pm/c3-session-chat.js +0 -103
  261. package/workspace/public/pm/c3-session-conv.js +0 -165
  262. package/workspace/public/pm/c3-session-term.js +0 -216
  263. package/workspace/public/pm/c3-settings.css +0 -85
  264. package/workspace/public/pm/c3-settings.js +0 -1045
  265. package/workspace/public/pm/c3-shell.js +0 -628
  266. package/workspace/public/pm/c3-signals.js +0 -196
  267. package/workspace/public/pm/c3-strategy-panels.js +0 -45
  268. package/workspace/public/pm/c3-swipe.js +0 -230
  269. package/workspace/public/pm/c3-terminal-data.js +0 -48
  270. package/workspace/public/pm/c3-terminal-edge.js +0 -91
  271. package/workspace/public/pm/c3-terminal-icons.js +0 -40
  272. package/workspace/public/pm/c3-terminal-results.js +0 -141
  273. package/workspace/public/pm/c3-terminal.js +0 -52
  274. package/workspace/public/pm/c3-tickets.js +0 -163
  275. package/workspace/public/pm/c3-timeline.js +0 -201
  276. package/workspace/public/pm/calendar-views.js +0 -1049
  277. package/workspace/public/pm/console3-lift.md +0 -220
  278. package/workspace/public/pm/cozy-home.js +0 -172
  279. package/workspace/public/pm/cozy-initiative.css +0 -138
  280. package/workspace/public/pm/cycle-review.js +0 -125
  281. package/workspace/public/pm/data.js +0 -1577
  282. package/workspace/public/pm/dest-board.js +0 -444
  283. package/workspace/public/pm/dest-docs.js +0 -530
  284. package/workspace/public/pm/dest-initiatives.js +0 -162
  285. package/workspace/public/pm/dest-mywork.js +0 -307
  286. package/workspace/public/pm/dest-notes.js +0 -537
  287. package/workspace/public/pm/dest-people.js +0 -449
  288. package/workspace/public/pm/dest-reports.js +0 -383
  289. package/workspace/public/pm/dest-settings.js +0 -601
  290. package/workspace/public/pm/dest-today.js +0 -267
  291. package/workspace/public/pm/display-word.js +0 -56
  292. package/workspace/public/pm/doc-editor.js +0 -473
  293. package/workspace/public/pm/doc-graph.js +0 -272
  294. package/workspace/public/pm/doc-health-panel.js +0 -110
  295. package/workspace/public/pm/doc-rail.js +0 -167
  296. package/workspace/public/pm/doc-remote.js +0 -180
  297. package/workspace/public/pm/dock-sessions.js +0 -472
  298. package/workspace/public/pm/dock.js +0 -216
  299. package/workspace/public/pm/fixture.js +0 -821
  300. package/workspace/public/pm/flag-picker.js +0 -104
  301. package/workspace/public/pm/frame-copy.js +0 -278
  302. package/workspace/public/pm/freshness-line.js +0 -149
  303. package/workspace/public/pm/handoff-box.js +0 -82
  304. package/workspace/public/pm/initiative-list.js +0 -235
  305. package/workspace/public/pm/initiative-sheet.js +0 -331
  306. package/workspace/public/pm/initiatives-api.js +0 -95
  307. package/workspace/public/pm/initiatives-copy.js +0 -287
  308. package/workspace/public/pm/initiatives-timeline-copy.js +0 -59
  309. package/workspace/public/pm/initiatives-timeline.js +0 -410
  310. package/workspace/public/pm/initiatives-ui.js +0 -291
  311. package/workspace/public/pm/item-sheet.js +0 -268
  312. package/workspace/public/pm/keep-card.js +0 -204
  313. package/workspace/public/pm/lifecycle-lens-model.js +0 -246
  314. package/workspace/public/pm/lifecycle-lens.js +0 -276
  315. package/workspace/public/pm/lifecycle.js +0 -111
  316. package/workspace/public/pm/mobile.css +0 -366
  317. package/workspace/public/pm/mobile.js +0 -581
  318. package/workspace/public/pm/modes-live.js +0 -453
  319. package/workspace/public/pm/modes.js +0 -147
  320. package/workspace/public/pm/my-work-card.js +0 -51
  321. package/workspace/public/pm/my-work-data.js +0 -36
  322. package/workspace/public/pm/new-initiative-sheet.js +0 -169
  323. package/workspace/public/pm/next-step-ui.js +0 -190
  324. package/workspace/public/pm/outbox-panel.js +0 -125
  325. package/workspace/public/pm/palette-copy.js +0 -55
  326. package/workspace/public/pm/palette.js +0 -343
  327. package/workspace/public/pm/panel-breakdown.js +0 -702
  328. package/workspace/public/pm/panel-cockpit.js +0 -425
  329. package/workspace/public/pm/panel-detail.js +0 -1513
  330. package/workspace/public/pm/panel-initiatives.js +0 -929
  331. package/workspace/public/pm/panel-newsess.js +0 -709
  332. package/workspace/public/pm/panel-repos.js +0 -741
  333. package/workspace/public/pm/panel-tabs.js +0 -1506
  334. package/workspace/public/pm/panel-trees.js +0 -204
  335. package/workspace/public/pm/people-link.js +0 -106
  336. package/workspace/public/pm/phone-deck.js +0 -167
  337. package/workspace/public/pm/pm-work-view.js +0 -1533
  338. package/workspace/public/pm/portfolio-report.js +0 -61
  339. package/workspace/public/pm/premium-acts.js +0 -280
  340. package/workspace/public/pm/premium-brief.js +0 -111
  341. package/workspace/public/pm/premium-chat.js +0 -22
  342. package/workspace/public/pm/premium-doc-sheet.js +0 -312
  343. package/workspace/public/pm/premium-initiative.js +0 -324
  344. package/workspace/public/pm/premium-insights.css +0 -228
  345. package/workspace/public/pm/premium-metric-tiles.js +0 -68
  346. package/workspace/public/pm/premium-report-brief.js +0 -132
  347. package/workspace/public/pm/premium-vw-rec.js +0 -67
  348. package/workspace/public/pm/premium-wide.css +0 -30
  349. package/workspace/public/pm/print.css +0 -44
  350. package/workspace/public/pm/provider-cards.js +0 -136
  351. package/workspace/public/pm/registry.js +0 -203
  352. package/workspace/public/pm/release-card.js +0 -110
  353. package/workspace/public/pm/releases-view.js +0 -248
  354. package/workspace/public/pm/report-families-view.js +0 -505
  355. package/workspace/public/pm/report-slides.js +0 -438
  356. package/workspace/public/pm/report-tab.js +0 -33
  357. package/workspace/public/pm/report-view.js +0 -337
  358. package/workspace/public/pm/reports-copy.js +0 -134
  359. package/workspace/public/pm/roadmap.js +0 -294
  360. package/workspace/public/pm/run-card.js +0 -260
  361. package/workspace/public/pm/sessions-panel.js +0 -219
  362. package/workspace/public/pm/sheet-jira.js +0 -353
  363. package/workspace/public/pm/shell-bell.js +0 -163
  364. package/workspace/public/pm/shell-model.js +0 -83
  365. package/workspace/public/pm/shell-phone.js +0 -124
  366. package/workspace/public/pm/shell-readaloud.js +0 -53
  367. package/workspace/public/pm/shell-recording.js +0 -274
  368. package/workspace/public/pm/shell-ticker.js +0 -90
  369. package/workspace/public/pm/sig-watch.js +0 -41
  370. package/workspace/public/pm/slide-confirm.js +0 -163
  371. package/workspace/public/pm/slides-copy.js +0 -52
  372. package/workspace/public/pm/status-banner.js +0 -95
  373. package/workspace/public/pm/tab-doc.js +0 -859
  374. package/workspace/public/pm/tab-gone.js +0 -21
  375. package/workspace/public/pm/tab-term.js +0 -1210
  376. package/workspace/public/pm/tab-web.js +0 -90
  377. package/workspace/public/pm/timeline-copy.js +0 -48
  378. package/workspace/public/pm/timeline-forecast-view.js +0 -164
  379. package/workspace/public/pm/today-agenda.js +0 -331
  380. package/workspace/public/pm/today-cards.js +0 -244
  381. package/workspace/public/pm/today-copy.js +0 -506
  382. package/workspace/public/pm/today-day.js +0 -1371
  383. package/workspace/public/pm/today-goals.js +0 -297
  384. package/workspace/public/pm/today-jobs.js +0 -84
  385. package/workspace/public/pm/today-mentions.js +0 -50
  386. package/workspace/public/pm/topbar.js +0 -202
  387. package/workspace/public/pm/triage-card.js +0 -60
  388. package/workspace/public/pm/undo-hold.js +0 -103
  389. package/workspace/public/pm/view-addrepo.js +0 -208
  390. package/workspace/public/pm/view-files.js +0 -197
  391. package/workspace/public/pm/view-livenotes.js +0 -399
  392. package/workspace/public/pm/view-today.js +0 -13
  393. package/workspace/public/pm/view-validate.js +0 -171
  394. package/workspace/public/pm/welcome.js +0 -391
  395. package/workspace/public/pm/work-place.js +0 -68
  396. package/workspace/public/pm/xlsx-read.js +0 -117
  397. package/workspace/public/welcome.html +0 -22
  398. package/workspace/test-lists/browser-suites-green.json +0 -5
  399. package/workspace/test-lists/c3-core-docs.json +0 -9
  400. package/workspace/test-lists/c3-doc-sheet-rich.json +0 -6
  401. package/workspace/test-lists/c3-doc-sheet-size.json +0 -6
  402. package/workspace/test-lists/c3-doc-sheet-v2.json +0 -6
  403. package/workspace/test-lists/c3-ib-items.json +0 -9
  404. package/workspace/test-lists/c3-ib-more.json +0 -9
  405. package/workspace/test-lists/c3-ib-triage-backlog.json +0 -9
  406. package/workspace/test-lists/c3-ini-life.json +0 -9
  407. package/workspace/test-lists/c3-meeting-board.json +0 -5
  408. package/workspace/test-lists/c3-meeting-card.json +0 -5
  409. package/workspace/test-lists/c3-notes-place.json +0 -5
  410. package/workspace/test-lists/c3-notes-series.json +0 -5
  411. package/workspace/test-lists/calendar-time-page.json +0 -5
  412. package/workspace/test-lists/calpop.json +0 -4
  413. package/workspace/test-lists/console3-briefing.json +0 -9
  414. package/workspace/test-lists/console3-foundation.json +0 -9
  415. package/workspace/test-lists/console3-work-page.json +0 -9
  416. package/workspace/test-lists/premium-brief-parity.json +0 -9
  417. package/workspace/test-lists/report-design-studio-ui.json +0 -5
  418. package/workspace/test-lists/report-structure-ui.json +0 -11
  419. package/workspace/test-lists/report-workspace-ui.json +0 -5
  420. package/workspace/test-lists/run3-a.json +0 -5
  421. package/workspace/test-lists/run3-d.json +0 -6
  422. package/workspace/test-lists/run4-c.json +0 -13
  423. package/workspace/test-lists/today-goals-jobs-ui.json +0 -5
  424. package/workspace/test-lists/today-mentions-cards.json +0 -5
  425. package/workspace/test-lists/workspace-tabs-declutter.json +0 -13
@@ -1,859 +0,0 @@
1
- /* pm/tab-doc.js — the document tab body: view · raw · edit · diff, with save, revert and a dirty flag.
2
- *
3
- * A port of the prototype's doc pane (template lines 869–927, derivation 2020–2045). The four modes
4
- * are the whole design: `view` renders the document, `raw` shows the file tinted by line kind,
5
- * `edit` is the buffer, and `diff` is a real LCS line diff of the buffer against what is on disk.
6
- *
7
- * `view` renders the markdown — EXCEPT for an HTML file, which is a page, not prose. Handing one to
8
- * the markdown parser prints its own markup back at the PM: the document read as its source code.
9
- * So an `.html` document renders, in `view`, as the page it is; `raw` is the one click that still
10
- * shows the code. See `htmlFrame` for why rendering it is not a new privilege — and for the one
11
- * privilege that IS grantable, per document and only by the PM: `run scripts` lets a page execute
12
- * its own inline code in a frame with no origin and no network, which is what an interactive
13
- * explainer companion needs and all it needs.
14
- * The diff is COMPUTED, never narrated — a "2 sections differ" that nothing read is the watermelon
15
- * this repo has a word for, and the same rule that governs artifact sync governs this pane.
16
- *
17
- * ── Where the text comes from ───────────────────────────────────────────────────────────────
18
- * 1. `savedDocs[path]` — saved in this window, so it is what the pane must show;
19
- * 2. fixture mode → the prototype's seed documents (`fixture.js`, `rawFor`);
20
- * 3. real mode → the file on disk, read once through the local server (`/api/doc`) and cached
21
- * by path. Nothing is fetched from anywhere but this machine.
22
- * A file that cannot be read says so, in the pane, with the reason — never a blank page.
23
- *
24
- * ── Why the textarea outlives the render ────────────────────────────────────────────────────
25
- * Every keystroke is a state change, and a state change repaints the panel. A textarea rebuilt on
26
- * each keystroke loses the caret, so the element is created once per tab and kept; its text is
27
- * written back only when it actually differs from what the box already holds.
28
- *
29
- * ── …and why the SCROLLING ELEMENT does too ─────────────────────────────────────────────────
30
- * A scroll offset is the same class of state as a caret, and it was not getting the same treatment:
31
- * `view`, `raw` and `diff` each built a fresh scrolling div on every paint, so any repaint — the
32
- * 4-second session poll included — took a half-read document back to the top. `scrollPane` keeps one
33
- * element per tab and mode; see the block comment above it.
34
- *
35
- * ── In live mode, a markdown file the PM can edit is edited in place (workspace-tabs-declutter) ─────────────
36
- * The four modes are the prototype's, and the fixture keeps them. In live mode a markdown file the PM can write is
37
- * drawn by doc-editor.js: read and edited in one surface, block by block, in the layout it is read in. `edit` stays as
38
- * the whole file as markdown (the Markdown toggle) and `diff` as the Changes toggle; `raw` is the Source toggle of a
39
- * file that cannot be edited. Beside the document, doc-rail.js holds its outline and its Connections.
40
- *
41
- * ── What `view` renders it through ──────────────────────────────────────────────────────────
42
- * `markdown.js`, not `fixture.js`'s `mdParse`. The latter is a transcription of the design
43
- * prototype's four-branch stand-in (`# `/`## `/`- `/paragraph) pinned byte-for-byte by
44
- * `fixture-parity.test.mjs`; it stays exactly as it is, and it is not a markdown renderer.
45
- */
46
-
47
- import { el, setChildren } from './dom.js';
48
- import { state, setState, FIXTURE } from './state.js';
49
- import * as FX from './fixture.js';
50
- import { mdRender } from './markdown.js';
51
- import { openDoc } from './panel-initiatives.js';
52
- import { button, iconButton, menu } from './primitives.js';
53
- import { editorNode, disposeEditor, headsOf, goToBlock, isEditing } from './doc-editor.js';
54
- import { railNode, disposeRail, refreshGraph } from './doc-rail.js';
55
- import { copyChip, refreshCopies } from './doc-remote.js';
56
-
57
- /** `{{ expr }}` — one interpolated value in its own span, as the prototype's runtime emits it. */
58
- const iv = (v) => el('span', null, v === null || v === undefined ? '' : String(v));
59
-
60
- /* ── reading ───────────────────────────────────────────────────────────────────────────────── */
61
-
62
- const disk = new Map(); // path -> text read from this machine
63
- const pending = new Set(); // paths whose read is in flight
64
- const saveErr = new Map(); // path -> why the last save was refused
65
- const unread = new Set(); // paths whose read FAILED — what `disk` holds for them is a stub
66
-
67
- let dataMod = null;
68
- import('./data.js').then((m) => { dataMod = m; }).catch(() => { dataMod = null; });
69
-
70
- /** The workspace id the doc endpoints key on. The data layer names it; these are its aliases. */
71
- const wsId = () => state.wsId || state.ws || state.product || '';
72
- /* overhaul-r1 R1.3 — a doc tab opened from a search hit on a linked worktree carries that tree's
73
- * `ws`, and is read from and saved to THAT tree. Two trees can hold the same path with different
74
- * content, so every per-document cache keys on tree + path; a main-tree tab keys on path alone,
75
- * exactly as before. */
76
- const docKey = (tab) => (tab && tab.guide ? 'guide\u241f' : '') + (tab && tab.ws ? tab.ws + '\u241f' : '') + (tab && tab.ref ? tab.ref + '\u241f' : '') + (tab ? tab.path : '');
77
- const wsOf = (tab) => (tab && tab.ws) || wsId();
78
-
79
- /* A REFERENCE is not a file. Panel 3's links section files `jira://ATL-501`, `confluence://PM/x`,
80
- * `gdoc://x-brief` — URIs naming a record in someone else's system, deliberately kept out of the
81
- * repo (AC5). Opening one used to be read as a path and sent to `/api/doc`, which answered 404 on
82
- * every one of them: a request that cannot succeed, made on every click, logged as a page error and
83
- * shown to the PM as "this file could not be read". PMOS holds no credential for any of those
84
- * systems, so the honest pane says what the reference IS and that nothing was read from it.
85
- * Anything with a scheme is a reference; a repo path never has one. */
86
- const REFERENCE_URI = /^[a-z][a-z0-9+.-]*:\/\//i;
87
- const isReference = (p) => REFERENCE_URI.test(String(p || ''));
88
-
89
- /** The name of the system a reference scheme belongs to; the scheme itself when it is not one we file. */
90
- const SYSTEM_OF = { jira: 'Jira', confluence: 'Confluence', gdoc: 'Google Docs', google: 'Google Docs' };
91
-
92
- const referenceStub = (tab) => {
93
- const scheme = String(tab.path).split('://')[0].toLowerCase();
94
- const system = SYSTEM_OF[scheme] || scheme;
95
- return '---\npath: ' + tab.path + '\nrole: ' + tab.role + '\ninitiative: ' + (tab.slug || '—')
96
- + '\n---\n\n# ' + String(tab.path).split('://').pop()
97
- + '\n\nThis is a REFERENCE, not a file in this repository: it names a record in ' + system + '.'
98
- + '\n\nNothing was read and nothing was contacted — PMOS holds no credential for ' + system + '. '
99
- + 'The reference is recorded so this initiative says where the work is; open it in ' + system
100
- + ' to read it.\n';
101
- };
102
-
103
- const stub = (tab, body) =>
104
- '---\npath: ' + tab.path + '\nrole: ' + tab.role + '\ninitiative: ' + (tab.slug || '—')
105
- + '\n---\n\n# ' + String(tab.path).split('/').pop() + '\n\n' + body;
106
-
107
- /** Read a document from the local server, once, then repaint. */
108
- function requestDoc(tab) {
109
- const path = docKey(tab);
110
- if (pending.has(path)) return;
111
- pending.add(path);
112
- const done = (text) => { pending.delete(path); disk.set(path, text); setState({}); };
113
- // A guide page ships with the app and is read from it, not from the repository (status-clarity R6).
114
- const load = tab.guide
115
- ? fetch('/api/guide?page=' + encodeURIComponent(tab.path)).then((r) => (r.ok ? r.text() : Promise.reject(new Error('no such guide page'))))
116
- : (dataMod && typeof dataMod.readDoc === 'function')
117
- ? dataMod.readDoc(tab.path, tab.ws, tab.ref)
118
- : fetch('/api/doc?ws=' + encodeURIComponent(wsOf(tab)) + '&path=' + encodeURIComponent(tab.path) + (tab.ref ? '&ref=' + encodeURIComponent(tab.ref) : ''))
119
- .then((r) => (r.ok ? r.text() : Promise.reject(new Error('HTTP ' + r.status))));
120
- Promise.resolve(load).then(
121
- (text) => { unread.delete(path); done(typeof text === 'string' ? text : String(text == null ? '' : text)); },
122
- (e) => {
123
- unread.add(path);
124
- done(stub(tab, 'This file could not be read: ' + (e && e.message ? e.message : e)
125
- + '\n\nNothing was rendered from it. That is the failure being stated rather than an empty page shown.'));
126
- },
127
- );
128
- }
129
-
130
- /**
131
- * The text on disk for this tab — the baseline every diff and the dirty flag are measured against.
132
- * Exported because panel 4's `copy` button carries the same text.
133
- */
134
- export function docText(tab) {
135
- if (!tab || !tab.path) return '';
136
- const saved = state.savedDocs[docKey(tab)];
137
- if (saved != null) return saved;
138
- if (FIXTURE) return FX.rawFor(tab, state.savedDocs);
139
- if (isReference(tab.path)) return referenceStub(tab);
140
- if (disk.has(docKey(tab))) return disk.get(docKey(tab));
141
- requestDoc(tab);
142
- return stub(tab, 'reading ' + tab.path + ' …');
143
- }
144
-
145
- /* ── writing ───────────────────────────────────────────────────────────────────────────────── */
146
-
147
- /**
148
- * Save (line 2039). In fixture mode the buffer simply becomes the saved text — there is no disk to
149
- * write to and pretending otherwise would be a fiction. In real mode the write goes to the local
150
- * server with the base it was opened from, so a file that changed underneath is REFUSED rather
151
- * than silently overwritten; the refusal is shown where the PM is looking and the buffer is kept.
152
- */
153
- function save(tab, text) {
154
- const path = docKey(tab);
155
- // R11 — the server may stamp `generated:` with the PM as author, so what is on disk is not exactly what was sent.
156
- // The saved text it returns becomes the new base; keeping the old one would make the NEXT save a 409.
157
- const commit = (final) => setState((s) => {
158
- const de = { ...s.docEdits }; delete de[path];
159
- return { savedDocs: { ...s.savedDocs, [path]: typeof final === 'string' ? final : text }, docEdits: de };
160
- });
161
- saveErr.delete(path);
162
- if (FIXTURE) { commit(); return; }
163
-
164
- const base = disk.has(path) ? disk.get(path) : (state.savedDocs[path] ?? '');
165
- const write = (dataMod && typeof dataMod.saveDoc === 'function')
166
- ? dataMod.saveDoc({ ws: wsOf(tab), path: tab.path, base, text })
167
- : fetch('/api/doc/save', {
168
- method: 'POST', headers: { 'Content-Type': 'application/json' },
169
- body: JSON.stringify({ ws: wsOf(tab), path: tab.path, base, text }),
170
- }).then((r) => r.json());
171
- Promise.resolve(write).then(
172
- (out) => {
173
- if (out && out.ok === false) { saveErr.set(path, out.error || 'refused'); setState({}); return; }
174
- const final = out && typeof out.text === 'string' ? out.text : text;
175
- disk.set(path, final);
176
- claims.delete(wsOf(tab)); // the consistency record may move with the file; read it again
177
- refreshCopies(wsOf(tab)); // …and so may the copy's state, and the file's ties
178
- refreshGraph(wsOf(tab), tab.path);
179
- commit(final);
180
- },
181
- (e) => { saveErr.set(path, (e && e.message) || 'could not reach the workspace server'); setState({}); },
182
- );
183
- }
184
-
185
- /** Revert (line 2043): drop the buffer, keep the file. */
186
- function revert(tab) {
187
- saveErr.delete(docKey(tab));
188
- setState((s) => { const de = { ...s.docEdits }; delete de[docKey(tab)]; return { docEdits: de }; });
189
- }
190
-
191
- /* ── the four bodies ───────────────────────────────────────────────────────────────────────── */
192
-
193
- const FM_K = 'font-size:10.5px;color:var(--muted-foreground);padding-top:2px;font-family:var(--mono)';
194
- const FM_V = 'overflow-wrap:anywhere;font-family:var(--mono);font-size:11.5px';
195
-
196
- const VIEW_ST = 'flex:1;min-height:0;overflow-y:auto;background:var(--background);color:var(--foreground);padding:20px 24px 60px;font-size:14px;line-height:1.65';
197
- const RAW_ST = 'flex:1;min-height:0;overflow-y:auto;background:var(--background);padding:14px 16px;font-family:var(--mono);font-size:12px;line-height:1.7';
198
- const DIFF_ST = 'flex:1;min-height:0;overflow-y:auto;background:var(--background);padding:14px 0;font-family:var(--mono);font-size:12px;line-height:1.7';
199
-
200
- /* ── THE SCROLL POSITION IS STATE, AND IT LIVES ON A NODE ──────────────────────────────────────
201
- *
202
- * Every `setState` anywhere in the app repaints all four panels, and panel 4 calls `mountDoc` on
203
- * every paint. Each body used to be built from scratch, and `setChildren` reconciles by node
204
- * IDENTITY — so the div `scrollTop` lives on was removed and a fresh one inserted, and a half-read
205
- * document went back to line 1. With a live agent session beside it that fires on the session poll,
206
- * at four-second intervals the PM neither caused nor can predict.
207
- *
208
- * This is the same problem the edit textarea has, and it gets the same answer: the element is
209
- * created once per tab and per mode and KEPT. A repaint whose text has not changed hands back the
210
- * identical node, which is what `setChildren` needs in order to leave it alone; when the text really
211
- * does change the children are rebuilt INSIDE that element and the offset is restored, because the
212
- * document being read is still the document being read.
213
- *
214
- * Keyed on the rendered text, not on the tab alone — that is what makes "changed nothing" decidable
215
- * without diffing DOM.
216
- */
217
- const scrollers = new Map(); // tab id -> { view|raw|diff: { key, node } }
218
-
219
- function scrollPane(tab, mode, key, style, build) {
220
- let per = scrollers.get(tab.id);
221
- if (!per) { per = {}; scrollers.set(tab.id, per); }
222
- const cur = per[mode];
223
- if (cur && cur.key === key) return cur.node; // nothing changed — the very same element
224
- const node = (cur && cur.node) || el('div', { style });
225
- const top = node.scrollTop;
226
- setChildren(node, build());
227
- if (top) node.scrollTop = top;
228
- per[mode] = { key, node };
229
- return node;
230
- }
231
-
232
- /** What links and images in this document resolve against. `onDoc` opens a .md link as a doc tab. */
233
- const linkCtx = (tab) => ({
234
- dir: String(tab.path || '').split('/').slice(0, -1),
235
- ws: wsOf(tab),
236
- onDoc: (p) => openDoc(tab.slug, p, 'FILE'),
237
- // overhaul-r5 (D69) — ⧉ beside a remote link opens it as a web tab, on the PM's click only
238
- onWeb: FIXTURE ? undefined : (u) => import('./tab-web.js').then((m) => m.openWeb(u)),
239
- });
240
-
241
- /* overhaul-r1 R5 — the reading measure is the PM's choice per tab: full width, or 72ch. With no
242
- * choice made it is full on a desktop and 72ch on a phone (≤760px), where 72ch IS the screen. */
243
- const narrowOf = (tab) => {
244
- const v = (state.docNarrow || {})[tab.id];
245
- if (typeof v === 'boolean') return v;
246
- if (FIXTURE) return true; // the prototype's recorded rendering, which the comparator reads
247
- return typeof window !== 'undefined' && window.matchMedia ? window.matchMedia('(max-width: 760px)').matches : false;
248
- };
249
-
250
- function viewBody(tab, text) {
251
- const narrow = narrowOf(tab);
252
- return scrollPane(tab, 'view', (narrow ? 'n\u0000' : 'f\u0000') + text, VIEW_ST, () => {
253
- const doc = mdRender(text, linkCtx(tab));
254
- const fm = [];
255
- doc.fm.forEach((fp) => { fm.push(el('span', { style: FM_K }, iv(fp.k)), el('span', { style: FM_V }, iv(fp.v))); });
256
- return [el('div', { style: narrow ? 'max-width:72ch' : 'max-width:none', 'data-measure': narrow ? '72ch' : 'full' },
257
- el('div', {
258
- style: 'border:1px solid var(--border);background:var(--card);padding:10px 12px;margin-bottom:18px;display:grid;grid-template-columns:auto 1fr;gap:4px 14px;font-size:12.5px',
259
- }, fm),
260
- el('h1', {
261
- style: 'font-size:21px;font-weight:600;line-height:1.3;margin:4px 0 12px;text-wrap:balance;font-family:var(--sans)',
262
- }, doc.title || iv('')),
263
- doc.blocks.map((bk) => el('div', null, bk)),
264
- )];
265
- });
266
- }
267
-
268
- function rawBody(tab, text) {
269
- return scrollPane(tab, 'raw', text, RAW_ST, () => text.split('\n').map((l) => {
270
- const ln = FX.rawLine(l);
271
- return el('div', {
272
- style: 'color:' + ln.c + ';font-weight:' + ln.w + ';white-space:pre-wrap;overflow-wrap:anywhere;min-height:1.2em',
273
- }, iv(ln.t));
274
- }));
275
- }
276
-
277
- /* ── the HTML page body ────────────────────────────────────────────────────────────────────────
278
- *
279
- * `previewKind` is the single classifier both sides of this app already trust (server.js requires
280
- * it; index.html loads it as a classic script), so "what counts as HTML" is decided in exactly one
281
- * place and cannot drift from the read endpoints. If it somehow did not load, `isHtmlDoc` answers
282
- * false and the pane behaves exactly as it did before — a missing classifier degrades to the old
283
- * view, never to an unclassified render.
284
- */
285
- const isHtmlDoc = (p) => {
286
- const PK = typeof window !== 'undefined' ? window.PreviewKind : null;
287
- if (!PK || typeof PK.previewKind !== 'function') return false;
288
- return PK.previewKind(String(p || '')) === 'html';
289
- };
290
-
291
- /* A STUB IS NOT THE DOCUMENT, AND MUST NOT BE RENDERED AS ONE. When a read is in flight or has
292
- * failed, `docText` hands back this pane's own prose — "reading …", or the failure with its reason.
293
- * Rendering that inside a frame would bury the one sentence the PM needs behind an iframe boundary,
294
- * and an .html file that could not be read would look like an empty page: the exact "never a blank
295
- * page" rule this pane already keeps for every other kind. So a page is drawn only from text that
296
- * genuinely came from disk (or from an edit saved in this window). A reference URI never renders —
297
- * nothing was read from it to render. */
298
- function rendersAsPage(tab) {
299
- const p = tab.path;
300
- const k = docKey(tab);
301
- if (!isHtmlDoc(p) || isReference(p)) return false;
302
- if (state.savedDocs[k] != null) return true;
303
- if (FIXTURE) return true;
304
- return disk.has(k) && !unread.has(k);
305
- }
306
-
307
- /* Rendering an HTML document adds no privilege over showing it. The frame is fully sandboxed —
308
- * `sandbox=""` grants nothing, so scripts and same-origin access are both denied — and the injected
309
- * CSP is `default-src 'none'`, which blocks every network fetch the page could attempt. A poisoned
310
- * explainer therefore can neither execute nor beacon out, which is the same no-remote-fetch-on-view
311
- * invariant the markdown image rule holds (R4). Only inline styles, data: images and data: fonts
312
- * resolve — enough for a page to look like itself, not enough to reach anything.
313
- *
314
- * ── …and why one privilege is nevertheless grantable, per document ──────────────────────────────
315
- * That default left the surface short of what it is for: PMOS's own build explainers ship as
316
- * INTERACTIVE HTML companions, so the one document class that most needs this reader was the class
317
- * it could not run. `run scripts` grants exactly one thing and grants it per open document, on an
318
- * act the PM performed: `allow-scripts` on the sandbox, `script-src 'unsafe-inline'` added to the
319
- * same CSP. Read what is NOT in that list — `allow-same-origin` is absent, so the frame keeps an
320
- * opaque origin and can never reach this app's document, storage or cookies; `default-src 'none'`
321
- * is untouched, so `connect-src` is still `none` and fetch/XHR/WebSocket are refused; `script-src`
322
- * names no host, so a remote `<script src>` is refused too; and forms, popups, top-level navigation
323
- * and modals were never granted at all. The whole delta is: the page may run its own inline code,
324
- * in a box with no origin and no network. Everything else the empty sandbox withheld stays withheld,
325
- * and a page that needs a CDN does not work here by design. */
326
- const CSP_BASE = "default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:";
327
- const htmlCsp = (live) => '<meta http-equiv="Content-Security-Policy" content="'
328
- + CSP_BASE + (live ? "; script-src 'unsafe-inline'" : '') + '">';
329
-
330
- const running = new Set(); // tab ids the PM has granted script execution to, this window only
331
- const frames = new Map(); // tab id -> { text, live, node } — the frame currently showing that
332
-
333
- /* THE FRAME IS NEVER RE-POINTED, IT IS REPLACED. Writing a new `srcdoc` onto a frame that is
334
- * already in the document does navigate it — but the replacement document does NOT get the meta
335
- * CSP applied to its subresource loads, so the remote <link>s in the new page are fetched. That
336
- * is not a theory: the panel-4 suite opens `web/index.html`, whose remote font stylesheet went out
337
- * exactly this way, and the containment assertion caught it. Setting `srcdoc` BEFORE the frame is
338
- * inserted is enforced correctly, so a text change builds a new frame and the old one is dropped.
339
- *
340
- * The cache is therefore keyed on the TEXT, not just the tab: a repaint that changed nothing hands
341
- * back the identical node — which is what `setChildren` needs to leave a live frame alone — while a
342
- * changed document gets a frame built from scratch. The cost is that saving an open HTML file
343
- * returns it to the top; the alternative is a page that renders contained only until it is edited.
344
- *
345
- * The grant is keyed the same way and for the same reason. `sandbox` and the CSP are read when the
346
- * frame loads its document, so re-writing them on a frame already showing a page changes an
347
- * attribute and nothing else — the running document keeps whatever it was born with. Granting or
348
- * revoking therefore builds a NEW frame too, which is also the honest behaviour: `stop` really
349
- * stops, because the executing document is discarded rather than asked to behave. */
350
- function htmlFrame(tab, text, live) {
351
- const cur = frames.get(tab.id);
352
- if (cur && cur.text === text && cur.live === live) return cur.node;
353
- const node = el('iframe', {
354
- style: 'flex:1;min-height:0;width:100%;border:0;background:var(--background)',
355
- sandbox: live ? 'allow-scripts' : '', // never allow-same-origin — that pair dissolves the box
356
- referrerpolicy: 'no-referrer',
357
- title: String(tab.path || 'document'),
358
- srcdoc: htmlCsp(live) + text, // set HERE, on a node not yet in the document — see above
359
- });
360
- frames.set(tab.id, { text, live, node });
361
- return node;
362
- }
363
-
364
- /* Two texts joined into one key. The separator is a character no document can contain — the same
365
- * reasoning `sessionProjection` uses in data.js — so a change that only moves the boundary between
366
- * them cannot fold into an identical key and suppress a rebuild that was real. */
367
- const SEP = '\u0000';
368
-
369
- function diffBody(tab, raw, text, dirty) {
370
- return scrollPane(tab, 'diff', dirty ? raw + SEP + text : '', DIFF_ST, () => {
371
- const rows = dirty ? FX.diffLines(raw, text) : [FX.NO_DIFF_ROW];
372
- return rows.map((dr) => el('div', {
373
- style: 'color:' + dr.c + ';background:' + dr.bg + ';padding:0 16px;white-space:pre-wrap;overflow-wrap:anywhere;min-height:1.2em',
374
- }, iv(dr.t)));
375
- });
376
- }
377
-
378
- /* ── per-tab state that is DOM, not data ───────────────────────────────────────────────────── */
379
-
380
- const boxes = new Map(); // tab id -> the persistent textarea for that tab
381
- const normNote = new Map(); // tab id -> what the last `normalize` click did, in words
382
-
383
- function editBox(tab) {
384
- let ta = boxes.get(tab.id);
385
- if (ta) return ta;
386
- ta = el('textarea', {
387
- style: 'flex:1;min-height:0;background:var(--background);color:var(--foreground);padding:14px 16px;font-family:var(--mono);font-size:12px;line-height:1.7',
388
- onInput: (e) => {
389
- const v = e.target.value;
390
- saveErr.delete(docKey(tab));
391
- setState((s) => ({ docEdits: { ...s.docEdits, [docKey(tab)]: v } }));
392
- },
393
- });
394
- ta.spellcheck = false; // a property, not an attribute — the prototype renders no attribute
395
- boxes.set(tab.id, ta);
396
- return ta;
397
- }
398
-
399
- /** Release what a closed doc tab held. Called by panel-tabs.js when the tab goes away. */
400
- export function disposeDoc(id) {
401
- boxes.delete(id);
402
- docBars.delete(id);
403
- normNote.delete(id);
404
- frames.delete(id);
405
- scrollers.delete(id);
406
- running.delete(id); // the grant belonged to this open document, and it is closed
407
- disposeEditor(id);
408
- disposeRail(id);
409
- places.delete(id);
410
- railHidden.delete(id);
411
- }
412
-
413
-
414
- /* ── the findings beside a document (was the Alignment drawer) ─────────────────────────────────────────────────────
415
- *
416
- * The Alignment drawer (workspace-cockpit-nav Run 3) listed the documents with a concrete tie to this one, from the
417
- * consistency record the Validate view reads (`/api/claims`). The Connections rail (doc-rail.js) now draws every stated
418
- * tie, so what the record adds is its FINDINGS: the ones in this file, and the ones in another file that name this
419
- * file as their source. A tie is still never drawn from wording, and a file the last check did not read is not shown as
420
- * clean: it has no findings to show, and the rail says only what was read. */
421
- const claims = new Map(); // ws -> { state: 'loading' | 'ok' | 'error', data?, error? }
422
-
423
- function readClaims(ws) {
424
- let c = claims.get(ws);
425
- if (c) return c;
426
- c = { state: 'loading' };
427
- claims.set(ws, c);
428
- fetch('/api/claims?ws=' + encodeURIComponent(ws))
429
- .then((r) => r.json())
430
- .then((d) => { claims.set(ws, d && d.ok !== false ? { state: 'ok', data: d } : { state: 'error', error: (d && d.error) || 'refused' }); setState({}); },
431
- (e) => { claims.set(ws, { state: 'error', error: (e && e.message) || 'could not reach the workspace server' }); setState({}); });
432
- return c;
433
- }
434
-
435
- /** The findings that concern `rel`: its own, then each other file's finding whose source is `rel` (with that file). */
436
- function findingsFor(ws, rel) {
437
- const c = readClaims(ws);
438
- if (c.state !== 'ok') return [];
439
- const docs = Array.isArray(c.data && c.data.docs) ? c.data.docs : [];
440
- const out = [];
441
- const self = docs.find((x) => x.rel === rel);
442
- if (self) for (const f of self.findings || []) out.push({ status: f.status, sentence: f.sentence });
443
- for (const x of docs) {
444
- if (x.rel === rel) continue;
445
- for (const f of x.findings || []) if (f && f.source === rel) out.push({ status: f.status, sentence: f.sentence, rel: x.rel });
446
- }
447
- return out;
448
- }
449
-
450
- /** Whether a tab can have the rail at all: a file in the checked-out tree, in real mode. */
451
- const canRail = (tab) => !FIXTURE && !tab.guide && !tab.ref && !isReference(tab.path);
452
- const railHidden = new Set(); // tab ids whose outline and connections the PM put away
453
-
454
- /* ── mount ─────────────────────────────────────────────────────────────────────────────────── */
455
-
456
- /**
457
- * Render the doc pane for `tab` into `host` — the pane element panel 4 keeps for this tab.
458
- * Everything but the edit box is rebuilt on each paint; the box is kept so typing survives it.
459
- */
460
- /* overhaul-r2 D1 — a PDF is never read as text. It is embedded from /api/asset (the workspace's own
461
- * guarded route) in the browser's built-in viewer, with a plain link as the fallback for a browser
462
- * that will not render it inline. Nothing leaves the machine. */
463
- const extOfPath = (p) => { const b = String(p || '').split('/').pop().toLowerCase(); const i = b.lastIndexOf('.'); return i > 0 ? b.slice(i + 1) : ''; };
464
- function pdfBody(tab) {
465
- const src = '/api/asset?ws=' + encodeURIComponent(wsOf(tab)) + '&path=' + encodeURIComponent(tab.path);
466
- return el('div', { style: 'flex:1;display:flex;flex-direction:column;min-height:0', 'data-r2': 'pdf' },
467
- el('div', { style: 'flex:none;padding:6px 10px;border-bottom:1px solid var(--border);font-family:var(--mono);font-size:10.5px;color:var(--muted-foreground)' },
468
- iv('PDF · read-only · '),
469
- el('a', { href: src, target: '_blank', rel: 'noopener', 'data-r2': 'pdf-open' }, 'open in a browser tab')),
470
- el('embed', { src, type: 'application/pdf', style: 'flex:1;width:100%;min-height:0;border:0;background:var(--card)' }),
471
- );
472
- }
473
-
474
- /* overhaul-r2 D2 — a CSV/TSV reads as a grid: every cell is text (escaped by construction, never
475
- * markup), the first row is the header, and a cap is STATED rather than silently applied. */
476
- const GRID_CAP = 2000;
477
- function parseDelimited(text, sep) {
478
- const rows = [];
479
- let row = [], cell = '', q = false;
480
- for (let i = 0; i < text.length; i++) {
481
- const ch = text[i];
482
- if (q) {
483
- if (ch === '"' && text[i + 1] === '"') { cell += '"'; i++; }
484
- else if (ch === '"') q = false;
485
- else cell += ch;
486
- } else if (ch === '"' && cell === '') q = true;
487
- else if (ch === sep) { row.push(cell); cell = ''; }
488
- else if (ch === '\n' || ch === '\r') {
489
- if (ch === '\r' && text[i + 1] === '\n') i++;
490
- row.push(cell); rows.push(row); row = []; cell = '';
491
- if (rows.length > GRID_CAP + 1) break; // header + cap + one more, to KNOW there is more
492
- } else cell += ch;
493
- }
494
- if (cell !== '' || row.length) { row.push(cell); rows.push(row); }
495
- return rows;
496
- }
497
- function gridBody(tab, text) {
498
- // Until the file has really been read, `text` is the reader's placeholder stub — never parse that
499
- // as data (it rendered as an 8-row, 1-column "CSV" while the read was in flight).
500
- const k = docKey(tab);
501
- const loaded = state.savedDocs[k] != null || (disk.has(k) && !unread.has(k));
502
- if (!loaded) return el('div', { style: VIEW_ST }, iv(unread.has(k) ? 'this file could not be read' : 'reading ' + tab.path + ' …'));
503
- return scrollPane(tab, 'grid', text, VIEW_ST, () => {
504
- const rows = parseDelimited(text, extOfPath(tab.path) === 'tsv' ? '\t' : ',');
505
- const head = rows[0] || [];
506
- const body = rows.slice(1, GRID_CAP + 1);
507
- const capped = rows.length > GRID_CAP + 1;
508
- const cellSt = 'border:1px solid var(--border);padding:3px 7px;font-family:var(--mono);font-size:11.5px;text-align:left;white-space:nowrap';
509
- return [
510
- el('div', { 'data-r2': 'grid-meta', style: 'font-family:var(--mono);font-size:10.5px;color:var(--muted-foreground);margin-bottom:8px' },
511
- iv(body.length + ' row' + (body.length === 1 ? '' : 's') + ' · ' + head.length + ' column' + (head.length === 1 ? '' : 's')
512
- + (capped ? ' · showing the first ' + GRID_CAP + ' rows — the rest are in raw' : ''))),
513
- el('div', { style: 'overflow:auto' },
514
- el('table', { 'data-r2': 'grid', style: 'border-collapse:collapse' },
515
- el('thead', null, el('tr', null, head.map((h) => el('th', { style: cellSt + ';background:var(--secondary)' }, iv(h))))),
516
- el('tbody', null, body.map((r) => el('tr', null, r.map((c) => el('td', { style: cellSt }, iv(c)))))))),
517
- ];
518
- });
519
- }
520
-
521
- /* overhaul-r3 P10 — a workbook, read in the browser by xlsx-read.js (no dependency, no network).
522
- * Loaded once per document and cached; a sheet bar switches sheets; every cell is text. */
523
- const books = new Map(); // docKey -> { state: 'loading' | 'ok' | 'error', book?, error? }
524
- const bookSheet = new Map(); // tab.id -> sheet index
525
- function sheetBody(tab) {
526
- const k = docKey(tab);
527
- let b = books.get(k);
528
- if (!b) {
529
- b = { state: 'loading' };
530
- books.set(k, b);
531
- const src = '/api/asset?ws=' + encodeURIComponent(wsOf(tab)) + '&path=' + encodeURIComponent(tab.path);
532
- Promise.all([fetch(src).then((r) => (r.ok ? r.arrayBuffer() : Promise.reject(new Error('HTTP ' + r.status)))), import('./xlsx-read.js')])
533
- .then(([buf, mod]) => mod.readXlsx(buf, GRID_CAP))
534
- .then((book) => { books.set(k, { state: 'ok', book }); setState({}); },
535
- (e) => { books.set(k, { state: 'error', error: (e && e.message) || String(e) }); setState({}); });
536
- }
537
- const wrap = (kids) => el('div', { style: VIEW_ST, 'data-r3': 'sheet' }, kids);
538
- if (b.state === 'loading') return wrap([iv('reading ' + tab.path + ' …')]);
539
- if (b.state === 'error') return wrap([el('div', { style: 'color:var(--destructive)' }, iv('this workbook could not be read — ' + b.error))]);
540
- const sheets = b.book.sheets;
541
- const cur = Math.min(bookSheet.get(tab.id) || 0, Math.max(0, sheets.length - 1));
542
- const sh = sheets[cur] || { name: '—', rows: [] };
543
- const head = sh.rows[0] || [];
544
- const width = sh.rows.reduce((n, r) => Math.max(n, r.length), 0);
545
- const cellSt = 'border:1px solid var(--border);padding:3px 7px;font-family:var(--mono);font-size:11.5px;text-align:left;white-space:nowrap';
546
- const pad = (r) => Array.from({ length: width }, (_, i) => r[i] ?? '');
547
- return wrap([
548
- el('div', { 'data-r3': 'sheet-bar', style: 'display:flex;gap:4px;flex-wrap:wrap;margin-bottom:8px' },
549
- sheets.map((x, i) => el('button', {
550
- onClick: () => { bookSheet.set(tab.id, i); setState({}); },
551
- style: 'font-family:var(--mono);font-size:10.5px;padding:3px 9px;border:1px solid var(--border);background:' + (i === cur ? 'var(--accent)' : 'transparent'),
552
- }, iv(x.name)))),
553
- el('div', { 'data-r2': 'grid-meta', style: 'font-family:var(--mono);font-size:10.5px;color:var(--muted-foreground);margin-bottom:8px' },
554
- iv(Math.max(0, sh.rows.length - 1) + ' rows · ' + width + ' columns · values only (formulas show their cached value; dates are serial numbers)'
555
- + (sh.truncated ? ' · showing the first ' + GRID_CAP + ' rows' : '') + (sh.error ? ' · ' + sh.error : ''))),
556
- el('div', { style: 'overflow:auto' },
557
- el('table', { 'data-r2': 'grid', style: 'border-collapse:collapse' },
558
- el('thead', null, el('tr', null, pad(head).map((h) => el('th', { style: cellSt + ';background:var(--secondary)' }, iv(h))))),
559
- el('tbody', null, sh.rows.slice(1).map((r) => el('tr', null, pad(r).map((c) => el('td', { style: cellSt }, iv(c)))))))),
560
- ]);
561
- }
562
-
563
- /* ── file-viewer-any-text — a document that is not markdown, a page or a grid is SOURCE ──────────────────
564
- * `previewKind` decides what counts as markdown or HTML, in the one place the server also trusts. Anything else
565
- * the reader serves is shown as numbered monospace lines, never through the markdown renderer: JSON pretty-printed,
566
- * JSONL as one record per line. These tabs are read-only, because /api/doc/save refuses everything but markdown and
567
- * an edit or save button that cannot work is worse than none. If the classifier did not load, nothing here applies
568
- * and the pane behaves as before. */
569
- function isSourcePath(p) {
570
- if (isReference(p)) return false; // an external reference has no file to show
571
- const PK = typeof window !== 'undefined' ? window.PreviewKind : null;
572
- if (!PK || typeof PK.previewKind !== 'function') return false;
573
- const kind = PK.previewKind(String(p || ''));
574
- if (kind === 'markdown' || kind === 'html') return false;
575
- const e = extOfPath(p);
576
- return !(e === 'csv' || e === 'tsv' || e === 'pdf' || e === 'xlsx');
577
- }
578
- const SRC_CAP = 5000; // lines drawn; the cap is STATED when it applies
579
- const JSONL_EXT = new Set(['jsonl', 'ndjson', 'jsonlines', 'ldjson']);
580
- function sourceBody(tab, text) {
581
- const ext = extOfPath(tab.path);
582
- return scrollPane(tab, 'view', 'src\u0000' + text, RAW_ST, () => {
583
- const head = (t, bad) => el('div', {
584
- 'data-r21': 'source-note',
585
- style: 'padding:2px 0 8px;font-family:var(--mono);font-size:10.5px;color:' + (bad ? 'var(--destructive)' : 'var(--muted-foreground)'),
586
- }, iv(t));
587
- const row = (n, t, bad) => el('div', { style: 'display:flex;gap:10px;min-height:1.2em' },
588
- el('span', { style: 'flex:none;min-width:4ch;text-align:right;color:var(--muted-foreground);user-select:none' }, iv(String(n))),
589
- el('div', { style: 'flex:1;min-width:0;white-space:pre-wrap;overflow-wrap:anywhere' + (bad ? ';color:var(--destructive)' : '') }, iv(t)));
590
- const lines = (arr) => arr.slice(0, SRC_CAP).map((t, i) => row(i + 1, t, false));
591
- const capNote = (n) => (n > SRC_CAP ? [head('Showing the first ' + SRC_CAP + ' of ' + n + ' lines. The rest is not drawn. Use raw to read it all.', false)] : []);
592
- const all = text.split('\n');
593
- if (ext === 'json') {
594
- let v; let err = null;
595
- try { v = JSON.parse(text); } catch (e) { err = (e && e.message) || 'parse error'; }
596
- if (err) return [head('JSON · read-only · NOT valid JSON: ' + err + ' · shown as written', true), ...lines(all), ...capNote(all.length)];
597
- const pretty = JSON.stringify(v, null, 2).split('\n');
598
- return [head('JSON · read-only · pretty-printed · ' + pretty.length + ' lines', false), ...lines(pretty), ...capNote(pretty.length)];
599
- }
600
- if (JSONL_EXT.has(ext)) {
601
- const recs = []; let bad = 0; let n = 0;
602
- all.forEach((t, i) => {
603
- if (!t.trim()) return;
604
- n++;
605
- if (recs.length >= SRC_CAP) return;
606
- try { recs.push(row(i + 1, JSON.stringify(JSON.parse(t), null, 2), false)); }
607
- catch (e) { bad++; recs.push(row(i + 1, t + '\n⚠ line ' + (i + 1) + ' is not valid JSON: ' + ((e && e.message) || 'parse error'), true)); }
608
- });
609
- return [head('JSONL · read-only · ' + n + ' record' + (n === 1 ? '' : 's') + (bad ? ' · ' + bad + ' not valid JSON (marked)' : '') + (n > SRC_CAP ? ' · first ' + SRC_CAP + ' shown' : ''), bad > 0), ...recs];
610
- }
611
- return [head((ext || 'text') + ' · read-only · source', false), ...lines(all), ...capNote(all.length)];
612
- });
613
- }
614
-
615
- export function mountDoc(host, tab) {
616
- if (!FIXTURE && extOfPath(tab.path) === 'pdf') { setChildren(host, [pdfBody(tab)]); return; }
617
- if (!FIXTURE && extOfPath(tab.path) === 'xlsx') { setChildren(host, [sheetBody(tab)]); return; }
618
- const raw = docText(tab);
619
- const text = state.docEdits[docKey(tab)] ?? raw;
620
- const nonMd = !FIXTURE && isSourcePath(tab.path); // file-viewer-any-text: read-only, shown as source
621
- const writable = canWrite(tab, nonMd);
622
- let dm = ((tab.readonly || nonMd) && (state.docModes[tab.id] === 'edit' || state.docModes[tab.id] === 'diff')) ? 'view' : (state.docModes[tab.id] ?? 'view');
623
- if (writable && dm === 'raw') dm = 'view'; // in place, the file you can write IS its source: no read-only copy of it
624
- if (!FIXTURE && !writable && (dm === 'edit' || dm === 'diff')) dm = 'view'; // only a markdown file can be saved
625
- const dirty = text !== raw;
626
- const err = saveErr.get(docKey(tab));
627
-
628
- // A file opened from the initiative's git files is evidence of what changed: it is read, never edited or saved here.
629
- const readonly = !!tab.readonly || nonMd;
630
- const modeBtns = ['view', 'raw', 'edit', 'diff'].filter((mm) => !(readonly && (mm === 'edit' || mm === 'diff'))).map((mm) => el('button', {
631
- onClick: () => setState((s) => ({ docModes: { ...s.docModes, [tab.id]: mm } })),
632
- style: 'font-family:var(--mono);font-size:10.5px;padding:4px 10px;min-height:26px;background:'
633
- + (dm === mm ? 'var(--secondary)' : 'transparent')
634
- + ';color:' + (dm === mm ? 'var(--foreground)' : 'var(--muted-foreground)')
635
- + ';border:1px solid ' + (dm === mm ? 'var(--input)' : 'transparent'),
636
- hover: 'border-color:var(--ring)',
637
- }, iv(mm)));
638
-
639
- const saveBtn = dirty ? button({ label: 'save', variant: 'primary', size: 'sm', onClick: () => save(tab, text) }) : null;
640
-
641
- /* The one control that grants a privilege, and the only place the PM learns the page CAN run.
642
- * Offered only where it means something — a document actually being rendered as a page, in the
643
- * mode that renders it — so it never appears on markdown, on raw/edit/diff, or on a stub. Its two
644
- * states differ in WORD, not only in colour: a page that is executing says so in as many words. */
645
- const asPage = rendersAsPage(tab);
646
- const live = running.has(tab.id);
647
- const runBtn = (asPage && dm === 'view') ? el('button', {
648
- onClick: () => {
649
- if (live) running.delete(tab.id); else running.add(tab.id);
650
- setState({});
651
- },
652
- title: live
653
- ? 'This document is running its own scripts, in a frame with no origin and no network. Stop discards it.'
654
- : "Run this document's own scripts. It stays sandboxed: no origin, no network, nothing loaded from anywhere.",
655
- style: 'margin-left:8px;font-family:var(--mono);font-size:10.5px;padding:4px 10px;min-height:26px;background:'
656
- + (live ? 'var(--secondary)' : 'transparent')
657
- + ';color:' + (live ? 'var(--warning)' : 'var(--muted-foreground)')
658
- + ';border:1px solid ' + (live ? 'var(--warning)' : 'var(--border)'),
659
- hover: 'border-color:var(--ring)',
660
- }, iv(live ? '● scripts running — stop' : 'run scripts')) : null;
661
-
662
- const revertBtn = dirty ? el('button', {
663
- onClick: () => revert(tab),
664
- style: 'font-family:var(--mono);font-size:10.5px;padding:4px 10px;min-height:26px;background:var(--secondary);border:1px solid var(--border);color:var(--muted-foreground)',
665
- hover: 'border-color:var(--ring)',
666
- }, 'revert') : null;
667
-
668
- /* ── normalize ────────────────────────────────────────────────────────────────────────────────
669
- * The one-click half of markdown-newlines. It writes the normalized text into the BUFFER, never
670
- * to disk: the pane goes dirty, `diff` shows exactly which lines were joined, and `save` is the
671
- * existing write path with its existing refusal on a changed base. So a repair the PM did not
672
- * want is one `revert` away, and no new way to write a file was added to get it.
673
- *
674
- * A document that is already normalized reports that and leaves the buffer alone — marking a
675
- * clean file dirty for nothing is how a tool teaches you to ignore its dirty flag. */
676
- const norm = typeof window !== 'undefined' ? window.MdNormalize : null;
677
- const canNormalize = !!(norm && typeof norm.normalize === 'function')
678
- && !isHtmlDoc(tab.path) && !isReference(tab.path) && !unread.has(docKey(tab)) && !nonMd;
679
- const normBtn = canNormalize ? el('button', {
680
- onClick: () => normalizeBuffer(tab, norm),
681
- style: 'margin-left:8px;font-family:var(--mono);font-size:10.5px;padding:4px 10px;min-height:26px;background:var(--secondary);border:1px solid var(--border);color:var(--muted-foreground)',
682
- hover: 'border-color:var(--ring)',
683
- title: 'Join hard-wrapped paragraphs into one line each — what a Jira issue, a Google Doc or any'
684
- + ' plain-text destination needs. Writes the buffer, not the file: read it in diff, then save.',
685
- }, 'normalize') : null;
686
-
687
- // The one place a real-mode refusal is reported: the same line that carries the dirty flag, so
688
- // a save that did not happen cannot read as one that did. The normalize note shares the line for
689
- // the same reason — a repair that changed nothing must say so where the PM is already looking.
690
- const note = normNote.get(tab.id);
691
- const dirtyLabel = err ? 'not saved — ' + err
692
- : (dirty ? '● modified — unsaved' : (note || 'saved on disk'));
693
- const dirtyColor = err ? 'var(--destructive)' : (dirty ? 'var(--warning)' : 'var(--muted-foreground)');
694
-
695
- const modeBar = el('div', {
696
- style: 'flex:none;display:flex;gap:2px;align-items:center;padding:6px 10px;border-bottom:1px solid var(--border);background:var(--background)',
697
- },
698
- modeBtns, normBtn, saveBtn, revertBtn, runBtn,
699
- FIXTURE || dm !== 'view' ? null : el('button', {
700
- onClick: () => setState((s) => ({ docNarrow: { ...(s.docNarrow || {}), [tab.id]: !narrowOf(tab) } })),
701
- style: 'margin-left:8px;font-family:var(--mono);font-size:10.5px;padding:4px 10px;min-height:26px;background:var(--secondary);border:1px solid var(--border);color:var(--muted-foreground)',
702
- hover: 'color:var(--foreground)', 'data-r1': 'measure',
703
- title: narrowOf(tab) ? 'use the full width of the tab' : 'limit lines to a 72-character reading measure',
704
- }, iv(narrowOf(tab) ? '↔ full width' : '⇥ 72ch')),
705
- el('span', { style: 'margin-left:auto;font-family:var(--mono);font-size:10px;color:' + dirtyColor }, iv(dirtyLabel)),
706
- );
707
-
708
- /* Live mode draws the bar from the design system (workspace-tabs-declutter): the four modes as one segmented control,
709
- * the save state beside them, save and revert, and one ⋯ menu for what is used now and then (the reading width,
710
- * normalize, alignment). Run scripts stays on the bar while a page can run: it grants a privilege, so its state is
711
- * never one click away. The fixture keeps the prototype's bar above, which the parity suites pin. */
712
- const bar = FIXTURE ? modeBar : docBar(tab, {
713
- dm, readonly, writable, dirty, err, text, asPage, live, canNormalize, norm,
714
- statusText: dirtyLabel,
715
- tone: err ? 'error' : (dirty ? 'dirty' : 'clean'),
716
- });
717
-
718
- let body;
719
- if (dm === 'raw') body = rawBody(tab, text);
720
- else if (dm === 'diff') body = diffBody(tab, raw, text, dirty);
721
- else if (dm === 'edit') {
722
- body = editBox(tab);
723
- /* `defaultValue` IS the textarea's child text node, and the prototype's runtime keeps it in
724
- * step with the buffer — so the rendered document is in the DOM, not only in a property. On a
725
- * box the PM has typed into, writing it moves nothing; `value` is then written only when it
726
- * genuinely differs, which is what keeps the caret still mid-sentence. */
727
- if (body.defaultValue !== text) body.defaultValue = text;
728
- if (body.value !== text) body.value = text;
729
- } else if (!FIXTURE && (extOfPath(tab.path) === 'csv' || extOfPath(tab.path) === 'tsv')) body = gridBody(tab, text);
730
- else if (writable) body = inPlace(tab, text, raw);
731
- else body = asPage ? htmlFrame(tab, text, live) : (nonMd && !unread.has(docKey(tab)) ? sourceBody(tab, text) : viewBody(tab, text));
732
-
733
- setChildren(host, [bar, body]);
734
- return host;
735
- }
736
-
737
- /* A markdown file the PM can write, in live mode: edited in place. A guide page ships with the app, a file from git is
738
- * evidence, a reference names someone else's record, and a file that could not be read is a stub: none of those. */
739
- function canWrite(tab, nonMd) {
740
- if (FIXTURE || tab.readonly || tab.guide || tab.ref || nonMd || isReference(tab.path) || isHtmlDoc(tab.path)) return false;
741
- const PK = typeof window !== 'undefined' ? window.PreviewKind : null;
742
- if (!PK || typeof PK.previewKind !== 'function' || PK.previewKind(String(tab.path || '')) !== 'markdown') return false;
743
- const k = docKey(tab);
744
- return state.savedDocs[k] != null || (disk.has(k) && !unread.has(k));
745
- }
746
-
747
- /* The in-place surface: the editor and, beside it, the rail. One scrolling node per tab, kept like the scrollers above,
748
- * so neither a repaint nor a keystroke moves the page. */
749
- const places = new Map(); // tab id -> { node, grid }
750
- function inPlace(tab, text, raw) {
751
- let pl = places.get(tab.id);
752
- if (!pl) {
753
- const grid = el('div', { class: 'fr-ed__grid' });
754
- pl = { node: el('div', { class: 'fr-ed', 'data-ed': 'scroll' }, grid), grid };
755
- places.set(tab.id, pl);
756
- }
757
- const ws = wsOf(tab);
758
- const main = editorNode(tab, {
759
- text, ctx: linkCtx(tab),
760
- onChange: (t) => { saveErr.delete(docKey(tab)); setState((s) => { const de = { ...s.docEdits }; if (t === raw) delete de[docKey(tab)]; else de[docKey(tab)] = t; return { docEdits: de }; }); },
761
- onSave: () => { const cur = state.docEdits[docKey(tab)]; if (cur != null && cur !== raw) save(tab, cur); },
762
- });
763
- const showRail = canRail(tab) && !railHidden.has(tab.id);
764
- const rail = showRail ? railNode(tab, {
765
- ws, rel: String(tab.path || ''), heads: headsOf(tab.id), findings: findingsFor(ws, String(tab.path || '')),
766
- onGoto: (i) => goToBlock(tab.id, i),
767
- onOpen: (rel) => openDoc(tab.slug, rel, 'FILE', tab.ws ? { ws: tab.ws, branch: tab.branch || null, linked: true } : undefined),
768
- }) : null;
769
- pl.grid.setAttribute('data-measure', narrowOf(tab) ? '72ch' : 'full');
770
- pl.grid.toggleAttribute('data-rail', !!rail);
771
- setChildren(pl.grid, [main, rail]);
772
- if (isEditing(tab.id)) pl.node.setAttribute('data-editing', ''); else pl.node.removeAttribute('data-editing');
773
- return pl.node;
774
- }
775
-
776
- /** normalize: the buffer's paragraphs joined into one line each. The buffer, never the file; a clean document says so. */
777
- function normalizeBuffer(tab, norm) {
778
- const raw = docText(tab);
779
- const text = state.docEdits[docKey(tab)] ?? raw;
780
- const r = norm.normalize(text);
781
- normNote.set(tab.id, r.changed
782
- ? r.joins + ' line(s) joined' + (r.blanks ? ', ' + r.blanks + ' blank inserted' : '')
783
- : 'already normalized — every paragraph is one line');
784
- if (!r.changed) { setState({}); return; }
785
- setState((s) => ({ docEdits: { ...s.docEdits, [docKey(tab)]: r.text } }));
786
- }
787
-
788
- /* ── the document bar in live mode ──────────────────────────────────────────────────────────────────────────────────
789
- * One bar per tab, kept so the ⋯ control keeps its focus across a repaint; its children are rebuilt. The bar says whether
790
- * the file is saved and what its copy holds, and carries what changes the view: Changes while there is something to
791
- * compare, the whole file as markdown (or, for a file that cannot be edited, its source), and one ⋯ menu for what is used
792
- * now and then. Run scripts stays on the bar while a page can run: it grants a privilege, so its state is never one
793
- * click away. Every action is the prototype's: the same state keys, the same buffer, the same save path. */
794
- const docBars = new Map(); // tab id -> { node, more }
795
-
796
- function docBar(tab, o) {
797
- let kept = docBars.get(tab.id);
798
- if (!kept) {
799
- const more = iconButton({ icon: 'ellipsis', ariaLabel: 'Document options', size: 'sm', attrs: { 'data-doc': 'more', class: 'fr-doc-bar__more' },
800
- onClick: (e) => menu({ anchor: e.currentTarget, ariaLabel: 'Document options', items: docMenu(tab) }) });
801
- kept = { node: el('div', { class: 'fr-doc-bar', 'data-doc': 'bar' }), more };
802
- docBars.set(tab.id, kept);
803
- }
804
- const setMode = (m) => setState((s) => ({ docModes: { ...s.docModes, [tab.id]: m } }));
805
- const status = el('span', { class: 'fr-doc-bar__status', 'data-doc': 'status', 'data-tone': o.tone }, o.statusText);
806
- const copy = canRail(tab) && !o.readonly ? copyChip(wsOf(tab), String(tab.path || '')) : null;
807
- const inDiff = o.dm === 'diff';
808
- const changes = o.writable && (o.dirty || inDiff) ? button({
809
- label: 'changes', variant: inDiff ? 'outline' : 'ghost', size: 'sm', icon: 'git-compare',
810
- attrs: { 'data-doc': 'changes', 'aria-pressed': inDiff ? 'true' : 'false', title: 'What saving would change on disk, line by line' },
811
- onClick: () => setMode(inDiff ? 'view' : 'diff'),
812
- }) : null;
813
- const srcMode = o.writable ? 'edit' : 'raw';
814
- const inSrc = o.dm === srcMode;
815
- const source = button({
816
- label: o.writable ? 'markdown' : 'source', variant: inSrc ? 'outline' : 'ghost', size: 'sm', icon: 'file-code',
817
- attrs: { 'data-doc': 'source', 'aria-pressed': inSrc ? 'true' : 'false',
818
- title: o.writable ? 'Edit the whole file as markdown' : 'Show the file as it is written' },
819
- onClick: () => setMode(inSrc ? 'view' : srcMode),
820
- });
821
- const saveB = o.dirty ? button({ label: 'save', variant: 'primary', size: 'sm', attrs: { 'data-doc': 'save', title: 'Save (Ctrl or ⌘ S)' }, onClick: () => save(tab, o.text) }) : null;
822
- const revertB = o.dirty ? button({ label: 'revert', variant: 'ghost', size: 'sm', attrs: { 'data-doc': 'revert' }, onClick: () => revert(tab) }) : null;
823
- const run = o.asPage && o.dm === 'view' ? button({
824
- label: o.live ? 'scripts running — stop' : 'run scripts', variant: o.live ? 'danger' : 'outline', size: 'sm',
825
- onClick: () => { if (o.live) running.delete(tab.id); else running.add(tab.id); setState({}); },
826
- attrs: { 'data-doc': 'run', 'aria-pressed': o.live ? 'true' : 'false',
827
- title: o.live
828
- ? 'This document is running its own scripts, in a frame with no origin and no network. Stop discards it.'
829
- : "Run this document's own scripts. It stays sandboxed: no origin, no network, nothing loaded from anywhere." },
830
- }) : null;
831
- const hasMenu = docMenu(tab).length > 0;
832
- setChildren(kept.node, [status, copy, el('span', { class: 'fr-doc-bar__end' }, run, changes, revertB, saveB, source, hasMenu ? kept.more : null)]);
833
- return kept.node;
834
- }
835
-
836
- /** The ⋯ menu's items, read afresh when it opens, so each one says what choosing it will do now. */
837
- function docMenu(tab) {
838
- const items = [];
839
- const dm = state.docModes[tab.id] ?? 'view';
840
- if (dm === 'view' || dm === 'raw') {
841
- const narrow = narrowOf(tab);
842
- items.push({ label: narrow ? 'Use the full width' : 'Limit lines to 72 characters', icon: 'arrow-left-right', attrs: { 'data-r1': 'measure' },
843
- onSelect: () => setState((s) => ({ docNarrow: { ...(s.docNarrow || {}), [tab.id]: !narrowOf(tab) } })) });
844
- }
845
- const norm = typeof window !== 'undefined' ? window.MdNormalize : null;
846
- const nonMd = isSourcePath(tab.path);
847
- if (norm && typeof norm.normalize === 'function' && !tab.readonly && !isHtmlDoc(tab.path) && !isReference(tab.path) && !unread.has(docKey(tab)) && !nonMd) {
848
- items.push({ label: 'Normalize line breaks', icon: 'refresh-cw', attrs: { 'data-doc': 'normalize', title: 'Join hard-wrapped paragraphs into one line each. Writes the buffer, not the file: read it in Changes, then save.' },
849
- onSelect: () => normalizeBuffer(tab, norm) });
850
- }
851
- if (canRail(tab) && canWrite(tab, nonMd)) {
852
- const hidden = railHidden.has(tab.id);
853
- items.push({ label: hidden ? 'Show the outline and connections' : 'Hide the outline and connections', icon: 'share-2', attrs: { 'data-doc': 'rail' },
854
- onSelect: () => { if (hidden) railHidden.delete(tab.id); else railHidden.add(tab.id); setState({}); } });
855
- }
856
- return items;
857
- }
858
-
859
- export default mountDoc;