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.
- package/package.json +30 -25
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +2 -2
- package/workspace/briefing-premium-board-test.js +3 -3
- package/workspace/briefing-premium-doc-edit-test.js +2 -8
- package/workspace/briefing-premium-sources-test.js +2 -0
- package/workspace/briefing-premium-test.js +6 -2
- package/workspace/briefing-premium-work-test.js +9 -4
- package/workspace/c3-capture-test.js +0 -17
- package/workspace/changelog.json +29 -0
- package/workspace/guide/briefing-premium.md +2 -2
- package/workspace/guide/home.md +24 -3
- package/workspace/guide/layout.md +2 -2
- package/workspace/guide/notes.md +2 -2
- package/workspace/guide/phone-companion.md +1 -1
- package/workspace/lib/core-docs.js +2 -2
- package/workspace/lib/route-modules.js +1 -9
- package/workspace/lib/routes-phone-day.js +18 -9
- package/workspace/lib/routes-slash.js +95 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -2
- package/workspace/premium-chat-goal-view-test.js +1 -1
- package/workspace/premium-chat-term-test.js +0 -10
- package/workspace/premium-menu-rows-test.js +1 -1
- package/workspace/premium-phone-card-test.js +8 -3
- package/workspace/premium-vw-cal-test.js +4 -1
- package/workspace/premium-vw-doc-test.js +1 -8
- package/workspace/premium-work-depth-test.js +2 -3
- package/workspace/public/capture.html +23 -0
- package/workspace/public/pm/c3-base.js +47 -0
- package/workspace/public/pm/c3-capture.js +1 -1
- package/workspace/public/pm/c3-ini-ui.js +1 -1
- package/workspace/public/pm/c3-sheet.js +1 -1
- package/workspace/public/pm/c3-toast.js +1 -1
- package/workspace/public/pm/console3.css +3 -0
- package/workspace/public/pm/cozy-home.css +21 -6
- package/workspace/public/pm/cozy-today.css +4 -3
- package/workspace/public/pm/cozy-viewer.js +4 -2
- package/workspace/public/pm/cozy.css +9 -0
- package/workspace/public/pm/goal-chat.js +5 -1
- package/workspace/public/pm/home-app.js +65 -33
- package/workspace/public/pm/home-chat.js +34 -29
- package/workspace/public/pm/home-data.js +10 -2
- package/workspace/public/pm/home-dictate.js +7 -4
- package/workspace/public/pm/home-ini.js +13 -3
- package/workspace/public/pm/home-list.js +18 -10
- package/workspace/public/pm/home-more.js +2 -2
- package/workspace/public/pm/home-phone-card.js +9 -4
- package/workspace/public/pm/home-review.js +2 -3
- package/workspace/public/pm/home-today.js +11 -8
- package/workspace/public/pm/home-work.js +13 -8
- package/workspace/public/pm/note-dock.js +1 -2
- package/workspace/public/pm/notes-links.js +1 -2
- package/workspace/public/pm/notes-task.js +3 -4
- package/workspace/public/pm/premium-board.js +1 -1
- package/workspace/public/pm/premium-initiative-head.js +3 -3
- package/workspace/public/pm/premium-vw-doc.css +20 -2
- package/workspace/public/pm/premium-vw-doc.js +22 -7
- package/workspace/public/pm/premium-vw-item.css +6 -0
- package/workspace/public/pm/view-notes.js +2 -2
- package/workspace/replaced-tests.json +435 -0
- package/workspace/run-tests.js +323 -28
- package/workspace/server.js +15 -10
- package/workspace/test-files.json +4 -140
- package/workspace/test-lists/base.json +1 -2
- package/workspace/test-lists/c3-desktop-light-load.json +1 -2
- package/workspace/test-lists/c3-initiative-boards.json +1 -2
- package/workspace/test-lists/c3-meeting-focus.json +2 -12
- package/workspace/test-lists/c3-work-agent.json +1 -2
- package/workspace/test-lists/calendar-tidy-up.json +1 -2
- package/workspace/test-lists/console3-reports.json +1 -2
- package/workspace/test-lists/docs-three-way-sync.json +1 -2
- package/workspace/test-lists/extension-capture.json +5 -0
- package/workspace/test-lists/jira-wbs.json +1 -2
- package/workspace/test-lists/legacy-cleanup-a.json +9 -0
- package/workspace/test-lists/meeting-material.json +1 -2
- package/workspace/test-lists/meeting-notes.json +2 -36
- package/workspace/test-lists/meeting-replay.json +1 -2
- package/workspace/test-lists/mm-capture.json +2 -12
- package/workspace/test-lists/my-work.json +2 -10
- package/workspace/test-lists/onboarding-firstrun.json +2 -12
- package/workspace/test-lists/people-directory.json +1 -2
- package/workspace/test-lists/run2-a.json +1 -2
- package/workspace/test-lists/run2-d.json +2 -19
- package/workspace/test-lists/run3-b.json +1 -2
- package/workspace/test-lists/run3-c.json +2 -12
- package/workspace/test-lists/run4-b.json +1 -2
- package/workspace/test-lists/run4-d.json +1 -5
- package/workspace/test-lists/run5-c.json +1 -11
- package/workspace/test-lists/run6.json +1 -5
- package/workspace/test-lists/workspace-launch-flags.json +2 -12
- package/workspace/test-lists/workspace-profile-detection.json +2 -10
- package/workspace/test-timings.json +242 -123
- package/workspace/c3-briefing-test.js +0 -136
- package/workspace/c3-core-docs-test.js +0 -170
- package/workspace/c3-driver-fixture.js +0 -64
- package/workspace/c3-driver-test.js +0 -169
- package/workspace/c3-foundation-test.js +0 -163
- package/workspace/c3-ib-items-test.js +0 -114
- package/workspace/c3-ib-more-test.js +0 -146
- package/workspace/c3-ib-triage-backlog-test.js +0 -128
- package/workspace/c3-ini-harness.js +0 -66
- package/workspace/c3-ini-life-test.js +0 -167
- package/workspace/c3-initiatives-test.js +0 -186
- package/workspace/c3-light-load-test.js +0 -112
- package/workspace/c3-one-home-test.js +0 -149
- package/workspace/c3-phone-test.js +0 -289
- package/workspace/c3-quiet-test.js +0 -157
- package/workspace/c3-report-design-real-test.js +0 -264
- package/workspace/c3-report-design-test.js +0 -442
- package/workspace/c3-report-setup-test.js +0 -192
- package/workspace/c3-report-structure-real-test.js +0 -248
- package/workspace/c3-report-structure-test.js +0 -397
- package/workspace/c3-reports-test.js +0 -288
- package/workspace/c3-scan-test.js +0 -517
- package/workspace/c3-sessions-panel-test.js +0 -365
- package/workspace/c3-settings-test.js +0 -204
- package/workspace/c3-updates-test.js +0 -131
- package/workspace/c3-work-test.js +0 -260
- package/workspace/cut-stub.js +0 -40
- package/workspace/first-paint-audit.js +0 -160
- package/workspace/lib/c3-full-console.js +0 -15
- package/workspace/lib/engine/derived/trust.js +0 -3
- package/workspace/lib/engine/plan-forecast.js +0 -342
- package/workspace/lib/engine/report-families.js +0 -175
- package/workspace/lib/engine/truth-table.js +0 -57
- package/workspace/lib/routes-c3-init.js +0 -54
- package/workspace/lib/routes-c3-life.js +0 -120
- package/workspace/lib/routes-c3-timeline.js +0 -192
- package/workspace/lib/routes-forecast.js +0 -86
- package/workspace/lib/routes-releases.js +0 -130
- package/workspace/lib/routes-report-facts.js +0 -85
- package/workspace/lib/routes-report-families.js +0 -33
- package/workspace/lib/routes-signals.js +0 -51
- package/workspace/lib/routes-timeline.js +0 -197
- package/workspace/public/c3.html +0 -35
- package/workspace/public/index.html +0 -156
- package/workspace/public/pm/app.js +0 -831
- package/workspace/public/pm/bd-board.js +0 -159
- package/workspace/public/pm/bd-drag.js +0 -59
- package/workspace/public/pm/bd-model.js +0 -152
- package/workspace/public/pm/bd-timeline.js +0 -233
- package/workspace/public/pm/bd-tree.js +0 -244
- package/workspace/public/pm/board-copy.js +0 -59
- package/workspace/public/pm/board-read.js +0 -38
- package/workspace/public/pm/branches-sheet.js +0 -56
- package/workspace/public/pm/breakdown-api.js +0 -58
- package/workspace/public/pm/breakdown-copy.js +0 -138
- package/workspace/public/pm/briefing-deck.js +0 -441
- package/workspace/public/pm/briefing-model.js +0 -251
- package/workspace/public/pm/c3-ambient.js +0 -100
- package/workspace/public/pm/c3-audience-link.js +0 -21
- package/workspace/public/pm/c3-audience.js +0 -46
- package/workspace/public/pm/c3-boot.js +0 -13
- package/workspace/public/pm/c3-breakdown.js +0 -240
- package/workspace/public/pm/c3-brief-data.js +0 -11
- package/workspace/public/pm/c3-brief-mentions.js +0 -137
- package/workspace/public/pm/c3-brief-needs.js +0 -288
- package/workspace/public/pm/c3-brief-pulse.js +0 -112
- package/workspace/public/pm/c3-brief-summary.js +0 -139
- package/workspace/public/pm/c3-brief-today.js +0 -79
- package/workspace/public/pm/c3-brief.js +0 -279
- package/workspace/public/pm/c3-cal-strategy.js +0 -529
- package/workspace/public/pm/c3-calendar.js +0 -965
- package/workspace/public/pm/c3-calpop.js +0 -111
- package/workspace/public/pm/c3-case.js +0 -196
- package/workspace/public/pm/c3-core-docs.css +0 -18
- package/workspace/public/pm/c3-core-docs.js +0 -236
- package/workspace/public/pm/c3-daypart.js +0 -176
- package/workspace/public/pm/c3-demo-boards.js +0 -764
- package/workspace/public/pm/c3-demo-brief-ix.js +0 -350
- package/workspace/public/pm/c3-demo-brief-page.js +0 -70
- package/workspace/public/pm/c3-demo-cal-ix.js +0 -74
- package/workspace/public/pm/c3-demo-cal2.js +0 -66
- package/workspace/public/pm/c3-demo-cal3.js +0 -173
- package/workspace/public/pm/c3-demo-cal4.js +0 -169
- package/workspace/public/pm/c3-demo-cal5.js +0 -52
- package/workspace/public/pm/c3-demo-coredocs.js +0 -221
- package/workspace/public/pm/c3-demo-data.js +0 -552
- package/workspace/public/pm/c3-demo-focus.js +0 -181
- package/workspace/public/pm/c3-demo-init.js +0 -430
- package/workspace/public/pm/c3-demo-life.js +0 -77
- package/workspace/public/pm/c3-demo-material.js +0 -58
- package/workspace/public/pm/c3-demo-misc2.js +0 -34
- package/workspace/public/pm/c3-demo-phone.js +0 -48
- package/workspace/public/pm/c3-demo-plan2.js +0 -30
- package/workspace/public/pm/c3-demo-rd.js +0 -432
- package/workspace/public/pm/c3-demo-rep-ix.js +0 -126
- package/workspace/public/pm/c3-demo-rep2.js +0 -130
- package/workspace/public/pm/c3-demo-rep3.js +0 -138
- package/workspace/public/pm/c3-demo-rs.js +0 -287
- package/workspace/public/pm/c3-demo-term.js +0 -153
- package/workspace/public/pm/c3-demo-time.js +0 -49
- package/workspace/public/pm/c3-demo-work-ix.js +0 -32
- package/workspace/public/pm/c3-demo.js +0 -131
- package/workspace/public/pm/c3-design-studio.js +0 -369
- package/workspace/public/pm/c3-doc-formats.js +0 -153
- package/workspace/public/pm/c3-doc-sheet.js +0 -1230
- package/workspace/public/pm/c3-dock.js +0 -206
- package/workspace/public/pm/c3-docs.js +0 -291
- package/workspace/public/pm/c3-driver-work.js +0 -110
- package/workspace/public/pm/c3-driver.css +0 -18
- package/workspace/public/pm/c3-driver.js +0 -298
- package/workspace/public/pm/c3-focus.css +0 -304
- package/workspace/public/pm/c3-focus.js +0 -983
- package/workspace/public/pm/c3-ib-docs.js +0 -92
- package/workspace/public/pm/c3-ib-initiatives.js +0 -201
- package/workspace/public/pm/c3-ib-items.js +0 -210
- package/workspace/public/pm/c3-ib-releases.js +0 -48
- package/workspace/public/pm/c3-ib-sprints.js +0 -201
- package/workspace/public/pm/c3-ib-triage.js +0 -177
- package/workspace/public/pm/c3-ii-tabs.js +0 -252
- package/workspace/public/pm/c3-ini-life.css +0 -34
- package/workspace/public/pm/c3-ini-life.js +0 -379
- package/workspace/public/pm/c3-ini-records.js +0 -197
- package/workspace/public/pm/c3-ini-timeline.js +0 -278
- package/workspace/public/pm/c3-ini-work.js +0 -139
- package/workspace/public/pm/c3-init-extras.js +0 -170
- package/workspace/public/pm/c3-initiatives.js +0 -852
- package/workspace/public/pm/c3-lifecycle-panels.js +0 -479
- package/workspace/public/pm/c3-look.js +0 -27
- package/workspace/public/pm/c3-material.css +0 -22
- package/workspace/public/pm/c3-material.js +0 -321
- package/workspace/public/pm/c3-md.js +0 -3
- package/workspace/public/pm/c3-misc-panels.js +0 -89
- package/workspace/public/pm/c3-new-session.js +0 -110
- package/workspace/public/pm/c3-notes.js +0 -751
- package/workspace/public/pm/c3-phone-boot.js +0 -47
- package/workspace/public/pm/c3-phone-detail.js +0 -97
- package/workspace/public/pm/c3-phone-model.js +0 -3
- package/workspace/public/pm/c3-phone.css +0 -66
- package/workspace/public/pm/c3-phone.js +0 -444
- package/workspace/public/pm/c3-plan-panels.js +0 -163
- package/workspace/public/pm/c3-plan.js +0 -193
- package/workspace/public/pm/c3-quiet.css +0 -113
- package/workspace/public/pm/c3-quiet.js +0 -177
- package/workspace/public/pm/c3-replay.css +0 -133
- package/workspace/public/pm/c3-replay.js +0 -429
- package/workspace/public/pm/c3-report-deck.css +0 -163
- package/workspace/public/pm/c3-report-deck.js +0 -598
- package/workspace/public/pm/c3-report-frame.css +0 -20
- package/workspace/public/pm/c3-report-print.css +0 -20
- package/workspace/public/pm/c3-report-setup.css +0 -67
- package/workspace/public/pm/c3-report-setup.js +0 -298
- package/workspace/public/pm/c3-report-store.js +0 -244
- package/workspace/public/pm/c3-report-structure.css +0 -44
- package/workspace/public/pm/c3-report-structure.js +0 -473
- package/workspace/public/pm/c3-reports.css +0 -68
- package/workspace/public/pm/c3-reports.js +0 -377
- package/workspace/public/pm/c3-roadmap.js +0 -249
- package/workspace/public/pm/c3-scan-api.js +0 -167
- package/workspace/public/pm/c3-scan-next.js +0 -248
- package/workspace/public/pm/c3-scan-setup.js +0 -313
- package/workspace/public/pm/c3-scan-words.js +0 -41
- package/workspace/public/pm/c3-scan.css +0 -74
- package/workspace/public/pm/c3-scan.js +0 -93
- package/workspace/public/pm/c3-session-chat.js +0 -103
- package/workspace/public/pm/c3-session-conv.js +0 -165
- package/workspace/public/pm/c3-session-term.js +0 -216
- package/workspace/public/pm/c3-settings.css +0 -85
- package/workspace/public/pm/c3-settings.js +0 -1045
- package/workspace/public/pm/c3-shell.js +0 -628
- package/workspace/public/pm/c3-signals.js +0 -196
- package/workspace/public/pm/c3-strategy-panels.js +0 -45
- package/workspace/public/pm/c3-swipe.js +0 -230
- package/workspace/public/pm/c3-terminal-data.js +0 -48
- package/workspace/public/pm/c3-terminal-edge.js +0 -91
- package/workspace/public/pm/c3-terminal-icons.js +0 -40
- package/workspace/public/pm/c3-terminal-results.js +0 -141
- package/workspace/public/pm/c3-terminal.js +0 -52
- package/workspace/public/pm/c3-tickets.js +0 -163
- package/workspace/public/pm/c3-timeline.js +0 -201
- package/workspace/public/pm/calendar-views.js +0 -1049
- package/workspace/public/pm/console3-lift.md +0 -220
- package/workspace/public/pm/cozy-home.js +0 -172
- package/workspace/public/pm/cozy-initiative.css +0 -138
- package/workspace/public/pm/cycle-review.js +0 -125
- package/workspace/public/pm/data.js +0 -1577
- package/workspace/public/pm/dest-board.js +0 -444
- package/workspace/public/pm/dest-docs.js +0 -530
- package/workspace/public/pm/dest-initiatives.js +0 -162
- package/workspace/public/pm/dest-mywork.js +0 -307
- package/workspace/public/pm/dest-notes.js +0 -537
- package/workspace/public/pm/dest-people.js +0 -449
- package/workspace/public/pm/dest-reports.js +0 -383
- package/workspace/public/pm/dest-settings.js +0 -601
- package/workspace/public/pm/dest-today.js +0 -267
- package/workspace/public/pm/display-word.js +0 -56
- package/workspace/public/pm/doc-editor.js +0 -473
- package/workspace/public/pm/doc-graph.js +0 -272
- package/workspace/public/pm/doc-health-panel.js +0 -110
- package/workspace/public/pm/doc-rail.js +0 -167
- package/workspace/public/pm/doc-remote.js +0 -180
- package/workspace/public/pm/dock-sessions.js +0 -472
- package/workspace/public/pm/dock.js +0 -216
- package/workspace/public/pm/fixture.js +0 -821
- package/workspace/public/pm/flag-picker.js +0 -104
- package/workspace/public/pm/frame-copy.js +0 -278
- package/workspace/public/pm/freshness-line.js +0 -149
- package/workspace/public/pm/handoff-box.js +0 -82
- package/workspace/public/pm/initiative-list.js +0 -235
- package/workspace/public/pm/initiative-sheet.js +0 -331
- package/workspace/public/pm/initiatives-api.js +0 -95
- package/workspace/public/pm/initiatives-copy.js +0 -287
- package/workspace/public/pm/initiatives-timeline-copy.js +0 -59
- package/workspace/public/pm/initiatives-timeline.js +0 -410
- package/workspace/public/pm/initiatives-ui.js +0 -291
- package/workspace/public/pm/item-sheet.js +0 -268
- package/workspace/public/pm/keep-card.js +0 -204
- package/workspace/public/pm/lifecycle-lens-model.js +0 -246
- package/workspace/public/pm/lifecycle-lens.js +0 -276
- package/workspace/public/pm/lifecycle.js +0 -111
- package/workspace/public/pm/mobile.css +0 -366
- package/workspace/public/pm/mobile.js +0 -581
- package/workspace/public/pm/modes-live.js +0 -453
- package/workspace/public/pm/modes.js +0 -147
- package/workspace/public/pm/my-work-card.js +0 -51
- package/workspace/public/pm/my-work-data.js +0 -36
- package/workspace/public/pm/new-initiative-sheet.js +0 -169
- package/workspace/public/pm/next-step-ui.js +0 -190
- package/workspace/public/pm/outbox-panel.js +0 -125
- package/workspace/public/pm/palette-copy.js +0 -55
- package/workspace/public/pm/palette.js +0 -343
- package/workspace/public/pm/panel-breakdown.js +0 -702
- package/workspace/public/pm/panel-cockpit.js +0 -425
- package/workspace/public/pm/panel-detail.js +0 -1513
- package/workspace/public/pm/panel-initiatives.js +0 -929
- package/workspace/public/pm/panel-newsess.js +0 -709
- package/workspace/public/pm/panel-repos.js +0 -741
- package/workspace/public/pm/panel-tabs.js +0 -1506
- package/workspace/public/pm/panel-trees.js +0 -204
- package/workspace/public/pm/people-link.js +0 -106
- package/workspace/public/pm/phone-deck.js +0 -167
- package/workspace/public/pm/pm-work-view.js +0 -1533
- package/workspace/public/pm/portfolio-report.js +0 -61
- package/workspace/public/pm/premium-acts.js +0 -280
- package/workspace/public/pm/premium-brief.js +0 -111
- package/workspace/public/pm/premium-chat.js +0 -22
- package/workspace/public/pm/premium-doc-sheet.js +0 -312
- package/workspace/public/pm/premium-initiative.js +0 -324
- package/workspace/public/pm/premium-insights.css +0 -228
- package/workspace/public/pm/premium-metric-tiles.js +0 -68
- package/workspace/public/pm/premium-report-brief.js +0 -132
- package/workspace/public/pm/premium-vw-rec.js +0 -67
- package/workspace/public/pm/premium-wide.css +0 -30
- package/workspace/public/pm/print.css +0 -44
- package/workspace/public/pm/provider-cards.js +0 -136
- package/workspace/public/pm/registry.js +0 -203
- package/workspace/public/pm/release-card.js +0 -110
- package/workspace/public/pm/releases-view.js +0 -248
- package/workspace/public/pm/report-families-view.js +0 -505
- package/workspace/public/pm/report-slides.js +0 -438
- package/workspace/public/pm/report-tab.js +0 -33
- package/workspace/public/pm/report-view.js +0 -337
- package/workspace/public/pm/reports-copy.js +0 -134
- package/workspace/public/pm/roadmap.js +0 -294
- package/workspace/public/pm/run-card.js +0 -260
- package/workspace/public/pm/sessions-panel.js +0 -219
- package/workspace/public/pm/sheet-jira.js +0 -353
- package/workspace/public/pm/shell-bell.js +0 -163
- package/workspace/public/pm/shell-model.js +0 -83
- package/workspace/public/pm/shell-phone.js +0 -124
- package/workspace/public/pm/shell-readaloud.js +0 -53
- package/workspace/public/pm/shell-recording.js +0 -274
- package/workspace/public/pm/shell-ticker.js +0 -90
- package/workspace/public/pm/sig-watch.js +0 -41
- package/workspace/public/pm/slide-confirm.js +0 -163
- package/workspace/public/pm/slides-copy.js +0 -52
- package/workspace/public/pm/status-banner.js +0 -95
- package/workspace/public/pm/tab-doc.js +0 -859
- package/workspace/public/pm/tab-gone.js +0 -21
- package/workspace/public/pm/tab-term.js +0 -1210
- package/workspace/public/pm/tab-web.js +0 -90
- package/workspace/public/pm/timeline-copy.js +0 -48
- package/workspace/public/pm/timeline-forecast-view.js +0 -164
- package/workspace/public/pm/today-agenda.js +0 -331
- package/workspace/public/pm/today-cards.js +0 -244
- package/workspace/public/pm/today-copy.js +0 -506
- package/workspace/public/pm/today-day.js +0 -1371
- package/workspace/public/pm/today-goals.js +0 -297
- package/workspace/public/pm/today-jobs.js +0 -84
- package/workspace/public/pm/today-mentions.js +0 -50
- package/workspace/public/pm/topbar.js +0 -202
- package/workspace/public/pm/triage-card.js +0 -60
- package/workspace/public/pm/undo-hold.js +0 -103
- package/workspace/public/pm/view-addrepo.js +0 -208
- package/workspace/public/pm/view-files.js +0 -197
- package/workspace/public/pm/view-livenotes.js +0 -399
- package/workspace/public/pm/view-today.js +0 -13
- package/workspace/public/pm/view-validate.js +0 -171
- package/workspace/public/pm/welcome.js +0 -391
- package/workspace/public/pm/work-place.js +0 -68
- package/workspace/public/pm/xlsx-read.js +0 -117
- package/workspace/public/welcome.html +0 -22
- package/workspace/test-lists/browser-suites-green.json +0 -5
- package/workspace/test-lists/c3-core-docs.json +0 -9
- package/workspace/test-lists/c3-doc-sheet-rich.json +0 -6
- package/workspace/test-lists/c3-doc-sheet-size.json +0 -6
- package/workspace/test-lists/c3-doc-sheet-v2.json +0 -6
- package/workspace/test-lists/c3-ib-items.json +0 -9
- package/workspace/test-lists/c3-ib-more.json +0 -9
- package/workspace/test-lists/c3-ib-triage-backlog.json +0 -9
- package/workspace/test-lists/c3-ini-life.json +0 -9
- package/workspace/test-lists/c3-meeting-board.json +0 -5
- package/workspace/test-lists/c3-meeting-card.json +0 -5
- package/workspace/test-lists/c3-notes-place.json +0 -5
- package/workspace/test-lists/c3-notes-series.json +0 -5
- package/workspace/test-lists/calendar-time-page.json +0 -5
- package/workspace/test-lists/calpop.json +0 -4
- package/workspace/test-lists/console3-briefing.json +0 -9
- package/workspace/test-lists/console3-foundation.json +0 -9
- package/workspace/test-lists/console3-work-page.json +0 -9
- package/workspace/test-lists/premium-brief-parity.json +0 -9
- package/workspace/test-lists/report-design-studio-ui.json +0 -5
- package/workspace/test-lists/report-structure-ui.json +0 -11
- package/workspace/test-lists/report-workspace-ui.json +0 -5
- package/workspace/test-lists/run3-a.json +0 -5
- package/workspace/test-lists/run3-d.json +0 -6
- package/workspace/test-lists/run4-c.json +0 -13
- package/workspace/test-lists/today-goals-jobs-ui.json +0 -5
- package/workspace/test-lists/today-mentions-cards.json +0 -5
- package/workspace/test-lists/workspace-tabs-declutter.json +0 -13
|
@@ -1,1230 +0,0 @@
|
|
|
1
|
-
/* pm/c3-doc-sheet.js — the DOCUMENT SHEET of /c3.html (Initiatives › Documents, an initiative's Docs, Reports). The right-hand sheet from
|
|
2
|
-
* c3-sheet.js, up to 780px, a bottom sheet on a phone. Initiative c3-doc-sheet-rich: the approved mockup (planning/prd/c3-doc-sheet-rich-prd.md).
|
|
3
|
-
*
|
|
4
|
-
* openDocSheet({ ws, doc, mode, prompt, relations(doc, openOther), onChanged, generated, secExtra, library(), openGraph(doc) }) doc = { path, name, ty, v, st, ini, iniName }
|
|
5
|
-
*
|
|
6
|
-
* Six modes (the segment under the header; the keys are kept for the callers):
|
|
7
|
-
* read Read the markdown rendered (pm/c3-md.js): the front matter as properties, each section with who changed it last (from the
|
|
8
|
-
* revisions), "Show who wrote what", the Markdown source with a copy button, the stale banner, and the open proposals
|
|
9
|
-
* pinned to the sections they change, with "Show change" for the diff in place. The OUTLINE (v2) beside it: the headings
|
|
10
|
-
* nested by level, the section in view marked as the page scrolls, groups that fold, a filter past 12 headings, a dot on
|
|
11
|
-
* stale and proposal sections; Hide is kept in this browser (localStorage); under 900px it is a button over the text.
|
|
12
|
-
* edit Edit a rich-text editor of the whole document (toolbar, Rich | Markdown over the same draft), the front matter as fields; a
|
|
13
|
-
* changed section is marked; saving needs a reason (POST /api/doc-sheet/edit). A section nobody touched is written back
|
|
14
|
-
* exactly as it was, so opening and saving without a change writes nothing.
|
|
15
|
-
* ask Proposals Ask the agent (POST /api/doc-sheet/ask: a background run that may only read; its answer becomes a proposal), the open
|
|
16
|
-
* proposals (GET /api/doc-sheet/proposals) with a tick per section, a rendered diff and the slide that accepts the ticked
|
|
17
|
-
* sections (POST /api/doc-sheet/accept with `sections`), Reject with a reason (POST /api/doc-sheet/reject), and the closed ones.
|
|
18
|
-
* hist Edit log every revision and event (GET /api/doc-sheet/log): who wrote the text, how it came in (this sheet, a proposal, outside
|
|
19
|
-
* PMOS with its commit), the reason, the sections, the words added and removed, Show the change, and a reason for an outside
|
|
20
|
-
* change that has none (POST /api/doc-sheet/why).
|
|
21
|
-
* health Health POST /api/doc-health/check: the checks, N of M; a failing Fresh check lists the sources that changed, and "Mark as still
|
|
22
|
-
* current" records a reason (POST /api/doc-sheet/mark-current).
|
|
23
|
-
* links Relations the graph around this document (v2): its sources on the left, its initiative and goals on top, the documents that
|
|
24
|
-
* use it and its copies on the right, a drift link dashed; a node opens that document. It reads `library()` from the
|
|
25
|
-
* caller, else GET /api/docs/library; the caller's `relations` list, when given, is kept below the graph.
|
|
26
|
-
* COPIES (v2): GET /api/docs gives the document's Confluence and Google Doc links with their signal (lib/doc-sync.js): a chip per copy in
|
|
27
|
-
* the header, and the "Copies in other tools" panel: Check now (POST /api/docs/check), Open in the tool, Bring their change in as a
|
|
28
|
-
* proposal (the ask run reads the copy; PMOS keeps hashes, not the copy's text, so the proposal is the difference), Update the copy to
|
|
29
|
-
* this version (five seconds to undo, then POST /api/docs/sync with use: pmos), and Link a copy (POST /api/docs/link).
|
|
30
|
-
* Nothing is invented: a part with no data says so. The demo (?demo=1) answers the routes from fixtures.
|
|
31
|
-
*
|
|
32
|
-
* Two options for a report, which is a document with no stored file yet (report-families-view.js):
|
|
33
|
-
* generated = { text, why, health } Read shows the generated text; Edit and Proposals say why they need a stored document; Health shows `health`.
|
|
34
|
-
* An agent's draft on a Work item (initiative c3-work-agent, amendment 16) is a generated document with three more hooks:
|
|
35
|
-
* generated.save(text, why) → { ok, error } Edit works: Save hands the text to the caller (the reason is optional) instead of the edit route.
|
|
36
|
-
* generated.ask(note) → { ok, error } Proposals is the note that sends the draft back to the agent.
|
|
37
|
-
* generated.log = [{ who, what, at, text }] Edit log lists these turns (the conversation with the agent).
|
|
38
|
-
* secExtra(name) a node under each section in Read: the report's claims and where they come from.
|
|
39
|
-
* Pure parts (Node-testable): splitDoc, joinDoc, changedSections, wordDiffTokens, byName, dayName, parseFront, setFront, composeSections,
|
|
40
|
-
* copyKindOf, citesIn, outlineOf, hoodOf. */
|
|
41
|
-
import { el } from './dom.js';
|
|
42
|
-
import { pmGet, pmPost } from './http.js';
|
|
43
|
-
import { c3ic } from './pm-work-view.js';
|
|
44
|
-
import { openSheet } from './c3-sheet.js';
|
|
45
|
-
import { say } from './c3-init-extras.js';
|
|
46
|
-
import { c3btn } from './page-agent.js';
|
|
47
|
-
import { button } from './primitives.js';
|
|
48
|
-
import { mountSlide } from './slide-confirm.js';
|
|
49
|
-
import { parseMd, toMd, canonMd, diffMd, toDom, fromDom, wordCounts, safeHref } from './cozy-md.js';
|
|
50
|
-
import { ensureReportCss, formatOf, formatView, outlineLabels, downloadsOf, printPdf, copyKindFor } from './c3-doc-formats.js';
|
|
51
|
-
|
|
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 */
|
|
53
|
-
const DOC_SIZE_KEY = 'pmos.workspace.c3.doc-size';
|
|
54
|
-
export const DOC_SIZES = [['normal', 'Normal', 'Normal'], ['half', 'Half', 'Half of the window'], ['three-quarters', '3/4', 'Three-quarters of the window'], ['whole', 'Whole', 'Whole window']];
|
|
55
|
-
export const docSizeOf = (v) => (DOC_SIZES.some((x) => x[0] === v) ? v : 'normal');
|
|
56
|
-
const docSizeStore = { get() { try { return localStorage.getItem(DOC_SIZE_KEY); } catch { return null; } }, set(v) { try { localStorage.setItem(DOC_SIZE_KEY, v); } catch { /* no storage */ } } };
|
|
57
|
-
|
|
58
|
-
/* ── pure: sections, round trip, word diff ── */
|
|
59
|
-
|
|
60
|
-
/** Split a markdown text into sections at its headings. Each section keeps the exact text it came from, so joinDoc(splitDoc(t)) === t. */
|
|
61
|
-
export function splitDoc(text) {
|
|
62
|
-
const t = String(text == null ? '' : text);
|
|
63
|
-
const heads = []; let off = 0; let fence = false;
|
|
64
|
-
for (const line of t.split('\n')) {
|
|
65
|
-
if (/^\s*(```|~~~)/.test(line)) fence = !fence;
|
|
66
|
-
if (!fence && /^#{1,6}\s+\S/.test(line)) heads.push({ at: off, line, end: off + line.length + 1 });
|
|
67
|
-
off += line.length + 1;
|
|
68
|
-
}
|
|
69
|
-
const raw = [];
|
|
70
|
-
const first = heads.length ? heads[0].at : t.length;
|
|
71
|
-
if (first > 0 || !heads.length) raw.push({ prefix: '', name: /^---\n/.test(t) ? 'Front matter' : 'Overview', body: t.slice(0, first) });
|
|
72
|
-
heads.forEach((h, i) => raw.push({ prefix: t.slice(h.at, Math.min(h.end, t.length)), name: h.line.replace(/^#+\s+/, '').replace(/\s+#+\s*$/, '').trim(), body: t.slice(Math.min(h.end, t.length), i + 1 < heads.length ? heads[i + 1].at : t.length) }));
|
|
73
|
-
return raw.map((s, i) => {
|
|
74
|
-
const lead = s.body.match(/^\s*/)[0]; const rest = s.body.slice(lead.length); const tail = rest.match(/\s*$/)[0];
|
|
75
|
-
return { i, prefix: s.prefix, name: s.name, lead, tail, text: rest.slice(0, rest.length - tail.length) };
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Put the sections back together. `edits` (optional) maps a section index to its new text; every other section is written as it was. */
|
|
80
|
-
export function joinDoc(secs, edits) {
|
|
81
|
-
return secs.map((s) => s.prefix + s.lead + (edits && Object.prototype.hasOwnProperty.call(edits, s.i) ? edits[s.i] : s.text) + s.tail).join('');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** The sections of `after` that differ from `before`, by name: [{ name, before, after, kind: 'changed'|'added'|'removed' }]. */
|
|
85
|
-
export function changedSections(before, after) {
|
|
86
|
-
const A = splitDoc(before); const B = splitDoc(after); const out = [];
|
|
87
|
-
B.forEach((s) => { const p = A.find((q) => q.name === s.name); if (!p) out.push({ name: s.name, before: '', after: s.text, kind: 'added' }); else if (p.text !== s.text || p.prefix !== s.prefix) out.push({ name: s.name, before: p.text, after: s.text, kind: 'changed' }); });
|
|
88
|
-
A.forEach((q) => { if (!B.some((s) => s.name === q.name)) out.push({ name: q.name, before: q.text, after: '', kind: 'removed' }); });
|
|
89
|
-
return out;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** The word diff: [{ op: 'same'|'add'|'del', text }], whitespace kept in the tokens. */
|
|
93
|
-
export function wordDiffTokens(a, b) {
|
|
94
|
-
const x = String(a || '').split(/(\s+)/).filter((s) => s !== ''); const y = String(b || '').split(/(\s+)/).filter((s) => s !== '');
|
|
95
|
-
const n = x.length; const m = y.length;
|
|
96
|
-
if (n * m > 600000) return [...(a ? [{ op: 'del', text: a }] : []), ...(b ? [{ op: 'add', text: b }] : [])];
|
|
97
|
-
const L = []; for (let i = 0; i <= n; i++) L.push(new Array(m + 1).fill(0));
|
|
98
|
-
for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) L[i][j] = x[i] === y[j] ? L[i + 1][j + 1] + 1 : Math.max(L[i + 1][j], L[i][j + 1]);
|
|
99
|
-
const out = []; const push = (op, text) => { const l = out[out.length - 1]; if (l && l.op === op) l.text += text; else out.push({ op, text }); };
|
|
100
|
-
let i = 0; let j = 0;
|
|
101
|
-
while (i < n && j < m) { if (x[i] === y[j]) { push('same', x[i]); i++; j++; } else if (L[i + 1][j] >= L[i][j + 1]) push('del', x[i++]); else push('add', y[j++]); }
|
|
102
|
-
while (i < n) push('del', x[i++]);
|
|
103
|
-
while (j < m) push('add', y[j++]);
|
|
104
|
-
return out;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** Who a ledger `by` is, as the page says it. */
|
|
108
|
-
export const byName = (by) => { const b = String(by || ''); return /^(agent|claude)/i.test(b) ? 'Agent' : /^(pm|human:wawan|human:pm|you)$/i.test(b) || b === '' ? 'You' : b.replace(/^human:/, ''); };
|
|
109
|
-
const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
110
|
-
/** '2026-10-05T09:00:00Z' to 'Mon 5 Oct'. Anything that is not a date comes back as it is. */
|
|
111
|
-
export function dayName(v) {
|
|
112
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); if (!m) return String(v || '');
|
|
113
|
-
const d = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));
|
|
114
|
-
return WD[d.getUTCDay()] + ' ' + (+m[3]) + ' ' + MON[+m[2] - 1];
|
|
115
|
-
}
|
|
116
|
-
const timeOf = (v) => { const m = /T(\d{2}):(\d{2})/.exec(String(v || '')); return m ? m[1] + ':' + m[2] : ''; };
|
|
117
|
-
const whenOf = (v) => dayName(v) + (timeOf(v) ? ', ' + timeOf(v) : '');
|
|
118
|
-
const nextV = (v) => { const m = /^v(\d+)$/.exec(v || ''); return m ? 'v' + (+m[1] + 1) : ''; };
|
|
119
|
-
|
|
120
|
-
/** The front matter of a text: { block, rest, fields: [{ key, value, line, editable, quote }] } or null. `block` is the `---` … `---` lines
|
|
121
|
-
* without the newline after them; `rest` is everything after. A field is editable when it is one line with a plain value. */
|
|
122
|
-
export function parseFront(text) {
|
|
123
|
-
const t = String(text == null ? '' : text);
|
|
124
|
-
const m = /^---\n([\s\S]*?)\n---(?=\n|$)/.exec(t);
|
|
125
|
-
if (!m) return null;
|
|
126
|
-
const fields = []; const lines = m[1].split('\n');
|
|
127
|
-
lines.forEach((l, line) => {
|
|
128
|
-
const f = /^([A-Za-z_][\w.-]*):[ \t]*(.*)$/.exec(l);
|
|
129
|
-
if (f) {
|
|
130
|
-
const raw = f[2]; const q = /^"(.*)"\s*$/.exec(raw) || /^'(.*)'\s*$/.exec(raw);
|
|
131
|
-
const multi = raw === '' || /^[|>]/.test(raw);
|
|
132
|
-
fields.push({ key: f[1], value: q ? (raw[0] === '"' ? q[1].replace(/\\"/g, '"').replace(/\\\\/g, '\\') : q[1].replace(/''/g, "'")) : raw, line, editable: !multi && !/^[[{]/.test(raw), quote: q ? raw[0] : '' });
|
|
133
|
-
} else if (fields.length && /^\s+(-\s+)?\S/.test(l)) {
|
|
134
|
-
const last = fields[fields.length - 1];
|
|
135
|
-
last.value = (last.value ? last.value + ', ' : '') + l.trim().replace(/^-\s+/, '');
|
|
136
|
-
last.editable = false;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return { block: m[0], rest: t.slice(m[0].length), fields };
|
|
140
|
-
}
|
|
141
|
-
/** The front matter block with `values` ({ key: value }) written into its editable fields; every other line stays as it was. */
|
|
142
|
-
export function setFront(block, values) {
|
|
143
|
-
const p = parseFront(block); if (!p) return block;
|
|
144
|
-
const inner = block.replace(/^---\n/, '').replace(/\n---$/, '').split('\n');
|
|
145
|
-
for (const f of p.fields) {
|
|
146
|
-
if (!f.editable || !Object.prototype.hasOwnProperty.call(values, f.key) || values[f.key] === f.value) continue;
|
|
147
|
-
const v = String(values[f.key]);
|
|
148
|
-
const needs = /^[\s"'#&*!|>%@`[{-]|:\s|\s#|\s$/.test(v) || v === '';
|
|
149
|
-
const out = f.quote === "'" ? "'" + v.replace(/'/g, "''") + "'" : f.quote === '"' || needs ? JSON.stringify(v) : v;
|
|
150
|
-
inner[f.line] = f.key + ': ' + out;
|
|
151
|
-
}
|
|
152
|
-
return '---\n' + inner.join('\n') + '\n---';
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** The new text of a document from the editor's sections. `base` is splitDoc of the text the editor was drawn from; each group is
|
|
156
|
-
* { sid, level, name, md } where sid is the index of the base section it was drawn from (or null for a new one) and md is the markdown
|
|
157
|
-
* the editor holds now. `intro` is the markdown before the first heading, `front` the front matter block (or null).
|
|
158
|
-
* A section whose heading and canonical text did not change is written back exactly as it was. */
|
|
159
|
-
export function composeSections(base, groups, intro, front) {
|
|
160
|
-
const levelOf = (s) => (/^(#+)/.exec(s.prefix || '') || ['', ''])[1].length;
|
|
161
|
-
const out = [];
|
|
162
|
-
const b0 = base.find((s) => s.prefix === '');
|
|
163
|
-
if (b0 || intro || front) {
|
|
164
|
-
const fm = b0 ? parseFront(b0.text) : null;
|
|
165
|
-
const restOrig = fm ? fm.rest : b0 ? b0.text : '';
|
|
166
|
-
const same = canonMd(restOrig) === canonMd(intro || '');
|
|
167
|
-
const body = same ? restOrig : (intro ? (front ? '\n\n' : '') + intro : '');
|
|
168
|
-
const text = (front || '') + body;
|
|
169
|
-
if (text || (b0 && (b0.lead || b0.tail))) out.push({ prefix: '', lead: b0 ? b0.lead : '', text, tail: b0 ? b0.tail : '\n\n' });
|
|
170
|
-
}
|
|
171
|
-
const used = new Set();
|
|
172
|
-
for (const g of groups) {
|
|
173
|
-
const B = g.sid != null && !used.has(g.sid) ? base[g.sid] : null;
|
|
174
|
-
if (B) used.add(g.sid);
|
|
175
|
-
const sameHead = B && B.name === g.name && levelOf(B) === g.level;
|
|
176
|
-
const sameText = B && canonMd(B.text) === canonMd(g.md);
|
|
177
|
-
out.push({ bi: B ? g.sid : null, prefix: sameHead ? B.prefix : '#'.repeat(g.level || 2) + ' ' + g.name + '\n', lead: B ? B.lead : (g.md ? '\n' : ''), text: sameText ? B.text : g.md, tail: B ? B.tail : '\n\n' });
|
|
178
|
-
}
|
|
179
|
-
if (out.length && out[0].prefix === '' && b0) out[0].bi = b0.i;
|
|
180
|
-
// where two parts were not next to each other before, the first ends in a blank line; a new last part ends in one newline
|
|
181
|
-
out.forEach((p, k) => {
|
|
182
|
-
const s = p.prefix + p.lead + p.text + p.tail;
|
|
183
|
-
if (k < out.length - 1) {
|
|
184
|
-
if (p.bi != null && out[k + 1].bi === p.bi + 1) return;
|
|
185
|
-
if (!/\n[ \t]*\n$/.test(s)) p.tail = p.tail.replace(/[ \t]*$/, '') + (/\n$/.test(s) ? '\n' : '\n\n');
|
|
186
|
-
} else if (p.bi !== base.length - 1 || p.bi == null) p.tail = p.tail.replace(/\s*$/, '') + '\n';
|
|
187
|
-
});
|
|
188
|
-
return out.map((p) => p.prefix + p.lead + p.text + p.tail).join('');
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/* ── the sheet ── */
|
|
192
|
-
|
|
193
|
-
const NAMES = { fresh: 'Fresh', decisions: 'Matches decisions', data: 'Matches the data', complete: 'Complete', traced: 'Traced to a goal and tickets', readers: 'Readers have this version' };
|
|
194
|
-
const STATE = { issued: ['Issued', 'ds-good', 'check'], current: ['Current', 'ds-good', 'check'], stale: ['Stale', 'ds-warn', 'alert'], draft: ['Draft', 'ds-pe', 'clock'], missing: ['Missing', 'ds-bad', 'plus'] };
|
|
195
|
-
const TABS = [['read', 'eye', 'Read'], ['edit', 'edit', 'Edit'], ['ask', 'spark', 'Proposals'], ['hist', 'clock', 'Edit log'], ['health', 'shield', 'Health'], ['links', 'init', 'Relations']];
|
|
196
|
-
const MODE = { proposals: 'ask', props: 'ask', log: 'hist', history: 'hist' };
|
|
197
|
-
const isDemo = () => !!window.__c3demo;
|
|
198
|
-
const q = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
199
|
-
const plural = (n, w) => n + ' ' + w + (n === 1 ? '' : 's');
|
|
200
|
-
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
201
|
-
const hcls = (h) => (!h || h.total === 0 ? '' : h.passed === h.total ? 'ds-good' : h.total - h.passed === 1 ? 'ds-warn' : 'ds-bad');
|
|
202
|
-
const isAgentRev = (r) => !!r && (r.text_by ? r.text_by === 'agent' : byName(r.by) === 'Agent');
|
|
203
|
-
const md = (text, extra) => el('div', { class: 'ds-md' + (extra ? ' ' + extra : '') }, toDom(parseMd(text), document));
|
|
204
|
-
const btn = (cls, attrs, kids, onClick) => c3btn(cls, attrs, kids, onClick);
|
|
205
|
-
/* a console3 primitive button (the Issue press and the menu: the mockup's UI.btn) */
|
|
206
|
-
const pb = (variant, attrs, kids, onClick) => { const b = button({ label: '', variant, size: 'sm', onClick, attrs: attrs || {} }); b.replaceChildren(...[].concat(kids).filter((k) => k != null && k !== false)); return b; };
|
|
207
|
-
const headLevel = (s) => (/^(#+)/.exec(s.prefix || '') || ['', ''])[1].length;
|
|
208
|
-
|
|
209
|
-
/* ── v2 (c3-doc-sheet-v2): the copies in other tools, the outline, the graph ── */
|
|
210
|
-
/* a copy's state (lib/doc-sync.js signal): [label, icon, class, sentence, chip word] */
|
|
211
|
-
const SIG = {
|
|
212
|
-
same: ['In step', 'check', 'ds-good', 'Both have the same text.', 'in step'],
|
|
213
|
-
ahead: ['PMOS is ahead', 'up', 'ds-acc', 'PMOS has changes the copy does not have.', 'PMOS ahead'],
|
|
214
|
-
behind: ['Behind', 'alert', 'ds-warn', 'The copy has changes PMOS does not have.', 'behind'],
|
|
215
|
-
diverged: ['Both changed', 'alert', 'ds-bad', 'Both changed since they last matched.', 'both changed'],
|
|
216
|
-
unchecked: ['Not checked', 'info', '', 'No check has read this copy yet.', 'not checked'],
|
|
217
|
-
unreadable: ['Cannot open', 'alert', 'ds-bad', 'The last check could not open the copy.', 'cannot open'],
|
|
218
|
-
none: ['Not created', 'info', '', 'No copy exists yet.', 'not created'],
|
|
219
|
-
'missing-remote': ['Not found', 'alert', 'ds-bad', 'The copy is not there any more.', 'not found'],
|
|
220
|
-
'missing-repo': ['Not in PMOS', 'alert', 'ds-bad', 'This file is not in the repository any more.', 'not in PMOS'] };
|
|
221
|
-
const SYNCING = ['Updating', 'clock', 'ds-acc', 'A session is updating this copy.', 'updating'];
|
|
222
|
-
const KLABEL = { google: 'Google Doc', 'google-slides': 'Google Slides', 'google-sheets': 'Google Sheets', confluence: 'Confluence' };
|
|
223
|
-
const sigOf = (l) => (l.syncing ? SYNCING : SIG[l.signal] || SIG.unchecked);
|
|
224
|
-
const labelOf = (l) => KLABEL[l.kind] || l.label || l.kind;
|
|
225
|
-
/** Which tool a pasted address names (the server checks it again): 'confluence', 'google' or null. */
|
|
226
|
-
export function copyKindOf(target) {
|
|
227
|
-
const t = String(target || '');
|
|
228
|
-
if (/atlassian|confluence|\/wiki\/|pageId=/i.test(t)) return 'confluence';
|
|
229
|
-
if (/docs\.google\.com\/presentation|slides\.google|\/presentation\/d\//i.test(t)) return 'google-slides';
|
|
230
|
-
if (/docs\.google\.com\/spreadsheets|sheets\.google|\/spreadsheets\/d\//i.test(t)) return 'google-sheets';
|
|
231
|
-
if (/google|docs\.|drive\./i.test(t)) return 'google';
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
/** The names of the sections that cite a path (or its file name). */
|
|
235
|
-
export function citesIn(secs, p) {
|
|
236
|
-
const b = String(p).split('/').pop();
|
|
237
|
-
return secs.filter((s) => s.name !== 'Front matter' && (s.text.includes(p) || (b && s.text.includes(b)))).map((s) => s.name);
|
|
238
|
-
}
|
|
239
|
-
/** The outline: the named sections, nested from the top level found (1 to 3). A single title heading on top is left out. */
|
|
240
|
-
export function outlineOf(secs) {
|
|
241
|
-
let named = secs.filter((s) => s.prefix && headLevel(s) > 0);
|
|
242
|
-
if (named.length && headLevel(named[0]) === 1 && named.filter((s) => headLevel(s) === 1).length === 1) named = named.slice(1);
|
|
243
|
-
if (!named.length) return [];
|
|
244
|
-
const base = Math.min(...named.map(headLevel));
|
|
245
|
-
return named.map((s) => ({ s, lv: Math.min(3, headLevel(s) - base + 1) }));
|
|
246
|
-
}
|
|
247
|
-
/** The neighbourhood of a document in a library response: { me, src, out } with each edge's state (the Docs page's rule when it has none). */
|
|
248
|
-
export function hoodOf(lib, path) {
|
|
249
|
-
if (!lib || !Array.isArray(lib.files)) return null;
|
|
250
|
-
const me = lib.files.findIndex((f) => f.path === path);
|
|
251
|
-
const kinds = lib.kinds || []; const src = []; const out = [];
|
|
252
|
-
const st = (a, b, k, s) => s || (['link', 'cites', 'anchor'].includes(kinds[k]) && a.date && b.date && a.date > b.date ? 'drift' : 'ok');
|
|
253
|
-
if (me >= 0) for (const [a, b, k, s] of lib.edges || []) {
|
|
254
|
-
if (b === me && a !== me && lib.files[a]) src.push({ f: lib.files[a], kind: kinds[k] || '', st: st(lib.files[a], lib.files[me], k, s) });
|
|
255
|
-
else if (a === me && b !== me && lib.files[b]) out.push({ f: lib.files[b], kind: kinds[k] || '', st: st(lib.files[me], lib.files[b], k, s) });
|
|
256
|
-
}
|
|
257
|
-
return { me: me >= 0 ? lib.files[me] : null, src, out };
|
|
258
|
-
}
|
|
259
|
-
const OL_KEY = 'pmos.c3.docOutline';
|
|
260
|
-
const olGet = () => { try { return localStorage.getItem(OL_KEY) !== 'off'; } catch { return true; } };
|
|
261
|
-
const olSet = (on) => { try { localStorage.setItem(OL_KEY, on ? 'on' : 'off'); } catch { /* no storage here */ } };
|
|
262
|
-
const ESTATE = { ok: 'in step', drift: 'out of step', conflict: 'conflict', missing: 'missing', ahead: 'PMOS ahead' };
|
|
263
|
-
|
|
264
|
-
/** Parts another module puts under the sheet's header and tabs, ahead of the text (the Horizon scan's "Proposed next steps"). Each is
|
|
265
|
-
* ({ ws, doc, text, key }) => Node|null, called on every draw with the text read so far; `key` is stable for one open sheet, so a part
|
|
266
|
-
* keeps its node (and its own state) in a WeakMap on it. A part that throws is left out. */
|
|
267
|
-
export const docAbove = [];
|
|
268
|
-
|
|
269
|
-
export function openDocSheet({ ws, doc, mode = 'read', prompt = '', relations, onChanged, generated, secExtra, library, openGraph, report }) {
|
|
270
|
-
const S = { mode: MODE[mode] || mode, prompt, text: null, err: '', revs: null, texts: {}, health: null, hAsk: false, busy: false, changed: false,
|
|
271
|
-
meta: null, metaFor: null, props: null, propsErr: '', log: null, logErr: '', asking: null, closed: false, who: false, src: false, preview: {},
|
|
272
|
-
pick: {}, rejFor: null, rejWhy: '', whyFor: null, whyText: '', staleWhy: null, logF: 'all', cmp: null, cmpNode: null, flashRev: null, ed: null, leave: null,
|
|
273
|
-
copies: null, copiesErr: '', syncOpen: false, menu: false, linking: false, linkUrl: '', pend: {}, checkRun: null, lib: undefined, ol: olGet(), olOpen: false, olq: '', olShut: {}, cur: null };
|
|
274
|
-
const demo = isDemo();
|
|
275
|
-
const base = { ws, path: doc.path };
|
|
276
|
-
/* a report cycle (initiative report-workspace): report = { output, state: 'draft'|'issued', name, cycle, foot, onIssue(doc), onNext(doc), onState(state) }.
|
|
277
|
-
* It is a document with an output format: Read draws it as slides, a grid, a page or A4 pages, an issued one is frozen, and the copy is
|
|
278
|
-
* created by the PM's press. Everything else in the sheet is the ordinary document sheet. */
|
|
279
|
-
const R = report || null;
|
|
280
|
-
if (R) ensureReportCss();
|
|
281
|
-
const frozen = () => !!R && R.state === 'issued';
|
|
282
|
-
const fmt = () => formatOf(R && R.output);
|
|
283
|
-
let ui = null;
|
|
284
|
-
|
|
285
|
-
/* ── data ── */
|
|
286
|
-
const loadText = async () => {
|
|
287
|
-
if (generated) { S.text = String(generated.text || ''); S.err = ''; return; }
|
|
288
|
-
try { const r = await fetch('/api/doc?' + q({ ws, path: doc.path })); if (!r.ok) throw new Error((await r.text()) || 'could not read the document'); S.text = await r.text(); S.err = ''; }
|
|
289
|
-
catch (e) { S.text = null; S.err = (e && e.message) || 'could not read the document'; }
|
|
290
|
-
};
|
|
291
|
-
const loadRevs = async () => {
|
|
292
|
-
if (generated) { S.revs = []; return; }
|
|
293
|
-
const j = await pmGet('/api/doc-sheet/revisions?' + q(base)).catch(() => null);
|
|
294
|
-
S.revs = j && j.ok ? j.revisions : [];
|
|
295
|
-
};
|
|
296
|
-
const textAt = async (rev) => {
|
|
297
|
-
if (S.texts[rev] != null) return S.texts[rev];
|
|
298
|
-
const j = await pmGet('/api/doc-sheet/at?' + q({ ...base, rev })).catch(() => null);
|
|
299
|
-
S.texts[rev] = j && j.ok ? j.text : null; return S.texts[rev];
|
|
300
|
-
};
|
|
301
|
-
const loadHealth = async () => {
|
|
302
|
-
S.hAsk = true;
|
|
303
|
-
if (generated) { S.health = generated.health || { passed: 0, total: 0, checks: [], err: generated.why }; drawBg(); return; }
|
|
304
|
-
const r = await pmPost('/api/doc-health/check', base).catch(() => null);
|
|
305
|
-
S.health = r && r.ok && r.health ? r.health : { passed: 0, total: 0, checks: [], err: (r && r.error) || 'The checks could not run.' }; drawBg();
|
|
306
|
-
};
|
|
307
|
-
const loadProps = async () => {
|
|
308
|
-
if (generated) { S.props = []; return; }
|
|
309
|
-
const j = await pmGet('/api/doc-sheet/proposals?' + q(base)).catch(() => null);
|
|
310
|
-
S.props = j && j.ok ? j.proposals || [] : []; S.propsErr = j && j.ok ? '' : (j && j.error) || 'The proposals could not be read.';
|
|
311
|
-
};
|
|
312
|
-
const loadLog = async () => {
|
|
313
|
-
if (generated) { S.log = { revisions: [], events: [] }; return; }
|
|
314
|
-
const j = await pmGet('/api/doc-sheet/log?' + q(base)).catch(() => null);
|
|
315
|
-
if (j && j.ok) { S.log = { revisions: j.revisions || [], events: j.events || [] }; S.logErr = ''; }
|
|
316
|
-
else { S.log = { revisions: S.revs || [], events: [] }; S.logErr = j && j.error ? j.error : ''; }
|
|
317
|
-
};
|
|
318
|
-
/* who changed each section last: the text of the last revisions (a few, fetched once) */
|
|
319
|
-
const loadMeta = async () => {
|
|
320
|
-
if (!S.revs || !S.revs.length || S.metaFor === S.revs.length) return;
|
|
321
|
-
S.metaFor = S.revs.length;
|
|
322
|
-
const rs = S.revs.slice(-12);
|
|
323
|
-
const texts = await Promise.all(rs.map((r) => textAt(r.rev)));
|
|
324
|
-
const meta = {};
|
|
325
|
-
rs.forEach((r, i) => { if (texts[i] == null) return; const cur = splitDoc(texts[i]); const prev = i ? splitDoc(texts[i - 1] || '') : []; cur.forEach((s) => { const p = prev.find((x) => x.name === s.name); if (!p || p.text !== s.text) meta[s.name] = r; }); });
|
|
326
|
-
S.meta = meta; drawBg();
|
|
327
|
-
};
|
|
328
|
-
const reloadAll = async () => {
|
|
329
|
-
S.revs = null; S.meta = null; S.metaFor = null; S.texts = {}; S.health = null; S.hAsk = false; S.log = null;
|
|
330
|
-
await loadText(); draw();
|
|
331
|
-
await Promise.all([loadRevs(), loadProps(), loadHealth(), loadCopies()]); loadMeta(); if (S.mode === 'hist') { await loadLog(); } draw();
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
/* ── drawing helpers ── */
|
|
335
|
-
const openProps = () => (S.props || []).filter((p) => p.state === 'proposed');
|
|
336
|
-
const failing = () => (S.health && !S.health.err ? S.health.checks.filter((c) => c.pass === false) : []);
|
|
337
|
-
const fresh = () => (S.health && !S.health.err ? S.health.checks.find((c) => c.id === 'fresh' && c.pass === false) : null);
|
|
338
|
-
const lastRev = () => (S.revs && S.revs.length ? S.revs[S.revs.length - 1] : null);
|
|
339
|
-
const whoOf = (r) => {
|
|
340
|
-
if (!r) return '';
|
|
341
|
-
if (isAgentRev(r)) return 'Agent' + (r.via === 'proposal' || r.by === 'pm' ? ' · accepted by you' : '');
|
|
342
|
-
if (r.git && r.git.author) return r.git.author;
|
|
343
|
-
if (r.via === 'first' || r.via === 'outside' || r.by === 'baseline') return r.via === 'first' ? 'Before the sheet' : 'Outside PMOS';
|
|
344
|
-
return byName(r.by);
|
|
345
|
-
};
|
|
346
|
-
const byChip = (r) => {
|
|
347
|
-
if (!r) return null;
|
|
348
|
-
const ag = isAgentRev(r); const label = whoOf(r);
|
|
349
|
-
return btn('ds-by', { 'data-doc-by': String(r.rev), title: 'Open revision ' + r.rev + ' in the edit log' },
|
|
350
|
-
[el('span', { class: 'ds-dot' + (ag ? ' a' : '') }, ag ? c3ic('spark') : (label[0] || '?').toUpperCase()), label + ' · ' + (r.v || 'rev ' + r.rev) + ' · ' + dayName(r.at)],
|
|
351
|
-
() => { S.flashRev = r.rev; S.logF = 'all'; go('hist'); });
|
|
352
|
-
};
|
|
353
|
-
const goEl = (sel) => { const n = ui && ui.body.querySelector(sel); if (n) { n.scrollIntoView({ block: 'start' }); n.classList.remove('flash'); void n.offsetWidth; n.classList.add('flash'); } };
|
|
354
|
-
|
|
355
|
-
function head() {
|
|
356
|
-
const st = STATE[R ? R.state : fresh() ? 'stale' : doc.st] || STATE.current; const h = S.health; const last = lastRev();
|
|
357
|
-
return el('div', { class: 'chips2 ds-meta', 'data-doc-meta': '' },
|
|
358
|
-
el('span', { class: 'chip2 ' + st[1] }, c3ic(st[2], 'sm'), st[0]), el('span', { class: 'chip2' }, doc.ty || 'Document'), doc.v ? el('span', { class: 'chip2 mono' }, doc.v) : null,
|
|
359
|
-
h && h.total ? btn('chip2 lk ' + hcls(h), { 'data-doc-hchip': '' }, [c3ic('shield', 'sm'), h.passed + ' of ' + h.total + ' checks'], () => go('health')) : null,
|
|
360
|
-
el('span', { class: 'chip2' }, c3ic('init', 'sm'), doc.iniName || doc.ini || 'Portfolio'), copyChips(),
|
|
361
|
-
R ? el('span', { class: 'chip2', 'data-doc-format': R.output }, c3ic(fmt().ic, 'sm'), fmt().l) : null,
|
|
362
|
-
last && !generated ? btn('chip2 lk', { 'data-doc-last': '' }, [c3ic(isAgentRev(last) ? 'spark' : 'user', 'sm'), 'Last change: ', el('b', null, whoOf(last) + ','), ' ' + dayName(last.at)], () => go('hist')) : null);
|
|
363
|
-
}
|
|
364
|
-
function seg() {
|
|
365
|
-
return el('div', { class: 'seg', role: 'group', 'aria-label': 'Document mode' }, TABS.map(([k, ic, l]) => {
|
|
366
|
-
const n = k === 'health' ? failing().length : k === 'ask' ? openProps().length : 0;
|
|
367
|
-
return btn('', { 'aria-pressed': String(S.mode === k), 'aria-label': l, title: l, 'data-dmode': k },
|
|
368
|
-
[c3ic(ic, 'sm'), el('span', { class: 'lbl' }, l), n ? el('span', { class: 'bdg ' + (k === 'ask' ? 'p' : 'w') }, String(n)) : null], () => go(k));
|
|
369
|
-
}));
|
|
370
|
-
}
|
|
371
|
-
function go(m) {
|
|
372
|
-
if (S.mode === 'edit' && m !== 'edit' && S.ed && dirty().length && S.leave !== m) { S.leave = m; draw(); return; }
|
|
373
|
-
if (m !== 'edit') S.ed = null;
|
|
374
|
-
S.leave = null; S.mode = m;
|
|
375
|
-
if (m === 'edit' && !S.ed) startEdit();
|
|
376
|
-
if (m === 'health' && !S.hAsk) loadHealth();
|
|
377
|
-
if (m === 'hist') { S.cmp = null; loadLog().then(() => { draw(); if (S.flashRev != null) { goEl('[data-log-rev="' + S.flashRev + '"]'); S.flashRev = null; } }); }
|
|
378
|
-
if (m === 'ask' && S.props === null) loadProps().then(draw);
|
|
379
|
-
if (m === 'read') loadMeta();
|
|
380
|
-
if (m === 'links') loadLib();
|
|
381
|
-
draw();
|
|
382
|
-
const sb = ui && ui.body.closest('.sb'); if (sb) sb.scrollTop = 0;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/* the stale banner: the Fresh check's sources, the sections that cite them, the open proposal */
|
|
386
|
-
function staleBanner() {
|
|
387
|
-
const f = fresh(); if (!f || generated) return null;
|
|
388
|
-
const secs = S.text ? splitDoc(S.text) : [];
|
|
389
|
-
const srcs = Array.isArray(f.sources) ? f.sources : [];
|
|
390
|
-
const cites = (p) => citesIn(secs, p);
|
|
391
|
-
const op = openProps();
|
|
392
|
-
if (S.staleWhy !== null) {
|
|
393
|
-
const inp = el('input', { type: 'text', id: 'dstalewhy', 'data-doc-stalewhy': '', placeholder: 'For example: the launch date is not agreed yet', 'aria-label': 'Why it is still current', value: S.staleWhy, onInput: (e) => { S.staleWhy = e.target.value; } });
|
|
394
|
-
return el('div', { class: 'ds-stale', role: 'note', 'data-doc-stale': '' }, el('div', { class: 't' }, c3ic('alert', 'sm'), 'Mark as still current'),
|
|
395
|
-
el('p', null, 'Say why the document is still right. The reason goes in the edit log, and the Fresh check counts it as a change.'),
|
|
396
|
-
el('div', { class: 'ds-whyadd' }, inp, btn('ds-btn pri', { 'data-doc-markok': '' }, 'Mark current', () => markCurrent()), btn('ds-btn', {}, 'Cancel', () => { S.staleWhy = null; draw(); })));
|
|
397
|
-
}
|
|
398
|
-
return el('div', { class: 'ds-stale', role: 'note', 'data-doc-stale': '' }, el('div', { class: 't' }, c3ic('alert', 'sm'), 'Stale'),
|
|
399
|
-
el('p', null, f.reason + '.' + (op.length ? ' ' + plural(op.length, 'open proposal') + ' may bring it up to date.' : ' Edit the sections they touch, or ask the agent for an update.')),
|
|
400
|
-
srcs.length ? el('ul', null, srcs.map((s) => { const c = cites(s.path); return el('li', { 'data-doc-stalesrc': s.path }, s.path + (s.changed ? ', changed ' + dayName(s.changed) : '') + (c.length ? ' (cited in ' + c.join(', ') + ')' : '')); })) : null,
|
|
401
|
-
el('div', { class: 'ds-acts' }, op.length ? btn('ds-btn ag', {}, [c3ic('spark', 'sm'), 'Review the proposals'], () => go('ask'))
|
|
402
|
-
: btn('ds-btn ag', {}, [c3ic('spark', 'sm'), 'Ask the agent'], () => { S.prompt = 'Bring this document up to date with ' + (srcs.map((s) => s.path).join(', ') || 'its sources'); go('ask'); }),
|
|
403
|
-
btn('ds-btn', { 'data-doc-mark': '' }, 'Mark as still current', () => { S.staleWhy = ''; draw(); const i = ui.body.querySelector('#dstalewhy'); if (i) i.focus(); })));
|
|
404
|
-
}
|
|
405
|
-
async function markCurrent() {
|
|
406
|
-
const w = String(S.staleWhy || '').trim();
|
|
407
|
-
if (!w) { say('Say why it is still current'); const i = ui.body.querySelector('#dstalewhy'); if (i) i.focus(); return; }
|
|
408
|
-
const r = await pmPost('/api/doc-sheet/mark-current', { ...base, why: w }).catch(() => null);
|
|
409
|
-
if (!r || !r.ok) { say((r && r.error) || 'It was not marked.'); return; }
|
|
410
|
-
S.staleWhy = null; S.changed = true; if (doc.st === 'stale') doc.st = 'current'; S.health = null; S.hAsk = false; S.log = null;
|
|
411
|
-
await loadHealth(); draw(); say('Marked as current. The reason is in the edit log.');
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/* ── v2: the copies in other tools (GET /api/docs: the links and their signals, lib/doc-sync.js) ── */
|
|
415
|
-
const loadCopies = async () => {
|
|
416
|
-
if (generated) { S.copies = []; return; }
|
|
417
|
-
const j = await pmGet('/api/docs?' + q({ ws })).catch(() => null);
|
|
418
|
-
if (!j || !j.ok) { S.copies = S.copies || []; S.copiesErr = (j && j.error) || 'The copies could not be read.'; return; }
|
|
419
|
-
const d = (j.docs || []).find((x) => x.path === doc.path);
|
|
420
|
-
S.copies = d ? d.links || [] : []; S.copiesErr = ''; S.checkRun = j.session || j.open || null;
|
|
421
|
-
};
|
|
422
|
-
/* a report with no copy yet still shows the copy it will make: the tool its output keeps its copy in, "not created" */
|
|
423
|
-
const copyList = () => { const L = S.copies || []; return R && !L.length && fmt().copy ? [{ kind: fmt().copy, signal: 'none', synthetic: true, title: doc.name }] : L; };
|
|
424
|
-
const copyChips = () => {
|
|
425
|
-
if (generated || S.copies == null) return null;
|
|
426
|
-
if (R && !fmt().copy) return btn('chip2 lk', { 'data-doc-copychip': 'pdf', 'aria-expanded': String(S.syncOpen) }, [c3ic('pdf', 'sm'), 'PDF: no live copy'], () => toggleCopies());
|
|
427
|
-
if (!copyList().length) return btn('chip2 lk', { 'data-doc-copychip': '', 'aria-expanded': String(S.syncOpen) }, [c3ic('link', 'sm'), 'Link a Confluence or Google Doc copy'], () => toggleCopies());
|
|
428
|
-
return copyList().map((l) => { const g = sigOf(l); return btn('chip2 lk ' + g[2], { 'data-doc-copychip': l.kind, 'aria-expanded': String(S.syncOpen), title: l.words || g[3] }, [c3ic(g[1], 'sm'), labelOf(l) + ': ' + g[4]], () => toggleCopies()); });
|
|
429
|
-
};
|
|
430
|
-
function toggleCopies() {
|
|
431
|
-
S.syncOpen = !S.syncOpen;
|
|
432
|
-
if (S.syncOpen && S.mode === 'edit') { go('read'); return; }
|
|
433
|
-
draw(); const sb = ui && ui.body.closest('.sb'); if (sb && S.syncOpen) sb.scrollTop = 0;
|
|
434
|
-
}
|
|
435
|
-
function copiesPanel() {
|
|
436
|
-
if (!S.syncOpen || generated) return null;
|
|
437
|
-
if (R && !fmt().copy) return el('section', { class: 'ds-sync', 'aria-label': 'Copies in other tools', 'data-doc-copies': '' }, el('div', { class: 'hd' }, el('b', null, 'Copies in other tools'),
|
|
438
|
-
btn('ds-btn', { 'aria-label': 'Close the copies', 'data-copy-close': '' }, c3ic('x', 'sm'), () => { S.syncOpen = false; draw(); })),
|
|
439
|
-
el('div', { class: 'fold' }, c3ic('info', 'sm'), 'A PDF has no live copy. Download it when you issue. Nothing goes to another tool.'));
|
|
440
|
-
const L = R ? copyList() : (S.copies || []);
|
|
441
|
-
const rows = L.map((l) => {
|
|
442
|
-
const g = sigOf(l); const name = labelOf(l); const pend = S.pend[l.kind];
|
|
443
|
-
const acts = [btn('ds-btn', { 'data-copy-check': l.kind, disabled: !!S.checkRun, 'aria-disabled': S.checkRun ? 'true' : null }, [c3ic(S.checkRun ? 'clock' : 'undo', 'sm'), S.checkRun ? 'Checking' : 'Check now'], () => checkNow()),
|
|
444
|
-
l.url ? el('a', { class: 'ds-btn', href: l.url, target: '_blank', rel: 'noopener', 'data-copy-open': l.kind }, c3ic('out', 'sm'), 'Open in ' + name) : null];
|
|
445
|
-
if (!l.syncing && (l.signal === 'behind' || l.signal === 'diverged')) acts.push(btn('ds-btn ag', { 'data-copy-take': l.kind }, [c3ic('spark', 'sm'), 'Bring their change in as a proposal'], () => takeCopy(l)));
|
|
446
|
-
if (!l.syncing && l.signal === 'ahead') acts.push(pend ? btn('ds-btn', { 'data-copy-undo': l.kind }, [c3ic('undo', 'sm'), 'Undo the update'], () => undoPush(l))
|
|
447
|
-
: btn('ds-btn pri', { 'data-copy-push': l.kind }, [c3ic('up', 'sm'), R ? 'Update the ' + name + ' copy to ' + (doc.v || 'this version') : 'Update the ' + name + ' to this version'], () => pushCopy(l)));
|
|
448
|
-
if (R && !l.syncing && l.signal === 'none') acts.push(pend ? btn('ds-btn', { 'data-copy-undo': l.kind }, [c3ic('undo', 'sm'), 'Undo'], () => undoPush(l))
|
|
449
|
-
: btn('ds-btn pri', { 'data-copy-create': l.kind }, [c3ic('out', 'sm'), 'Create the ' + name + ' copy'], () => createCopy(l)));
|
|
450
|
-
const changed = l.remote_modified_at ? 'changed ' + whenOf(l.remote_modified_at) + (l.remote_modified_by ? ' by ' + l.remote_modified_by : '') : '';
|
|
451
|
-
return el('li', { 'data-copy': l.kind },
|
|
452
|
-
el('div', { class: 'l1' }, c3ic('doc', 'sm'), el('b', null, l.title || name), el('span', { class: 'tag ' + g[2], 'data-copy-state': l.syncing ? 'syncing' : l.signal || 'unchecked' }, c3ic(g[1], 'sm'), g[0])),
|
|
453
|
-
el('div', { class: 'ds-mono' }, [name, l.target, changed].filter(Boolean).join(' · ')),
|
|
454
|
-
el('p', null, l.words || (R && l.signal === 'none' ? 'No copy exists yet. PMOS writes to ' + name + ' only when you press Create the ' + name + ' copy.' : g[3])),
|
|
455
|
-
el('div', { class: 'ds-note' }, l.checked_at ? 'Last checked ' + whenOf(l.checked_at) + (l.checked_by ? ' by ' + byName(l.checked_by) : '') + '.' : 'Not checked yet.'),
|
|
456
|
-
l.syncing ? el('div', { class: 'fold', role: 'status', 'data-copy-syncing': l.kind }, c3ic('clock', 'sm'), 'A session is updating ' + (l.syncing.use === 'copy' ? 'PMOS from the ' + name : 'the ' + name + ' to this version') + (l.syncing.started_at ? '. It started ' + whenOf(l.syncing.started_at) + '.' : '.')) : null,
|
|
457
|
-
l.sync_failed ? el('div', { class: 'fold w', role: 'alert', 'data-copy-failed': l.kind }, c3ic('alert', 'sm'), 'The last update did not finish' + (l.sync_failed.reason ? ': ' + l.sync_failed.reason : '.')) : null,
|
|
458
|
-
pend ? el('div', { class: 'fold', role: 'status', 'data-copy-pending': l.kind }, c3ic('clock', 'sm'), (R && l.signal === 'none' ? 'The copy is created in five seconds' : 'The update starts in five seconds') + '. Undo stops it.') : null,
|
|
459
|
-
el('div', { class: 'ds-acts' }, acts));
|
|
460
|
-
});
|
|
461
|
-
const linkRow = S.linking ? el('div', { class: 'ds-whyadd ds-linkadd' },
|
|
462
|
-
el('input', { type: 'text', id: 'dcopyurl', 'data-copy-url': '', placeholder: 'Paste a Confluence page or Google Doc link', 'aria-label': 'Address of the copy', value: S.linkUrl, onInput: (e) => { S.linkUrl = e.target.value; } }),
|
|
463
|
-
btn('ds-btn pri', { 'data-copy-linkok': '' }, 'Link', () => linkCopy()), btn('ds-btn', {}, 'Cancel', () => { S.linking = false; draw(); })) : null;
|
|
464
|
-
return el('section', { class: 'ds-sync', 'aria-label': 'Copies in other tools', 'data-doc-copies': '' },
|
|
465
|
-
el('div', { class: 'hd' }, el('b', null, 'Copies in other tools'), el('span', { class: 'ds-acts' },
|
|
466
|
-
R ? null : btn('ds-btn', { 'data-copy-link': '' }, [c3ic('link', 'sm'), L.length ? 'Link another copy' : 'Link a copy'], () => { S.linking = true; S.linkUrl = ''; draw(); const i = ui.body.querySelector('#dcopyurl'); if (i) i.focus(); }),
|
|
467
|
-
btn('ds-btn', { 'aria-label': 'Close the copies', 'data-copy-close': '' }, c3ic('x', 'sm'), () => { S.syncOpen = false; draw(); }))),
|
|
468
|
-
S.copiesErr ? el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), S.copiesErr) : null, linkRow,
|
|
469
|
-
L.length ? el('ul', null, rows) : el('p', { class: 'ds-note', 'data-copy-none': '' }, 'This document has no copy in Confluence or Google Docs yet. Link one to see whether it is in step.'),
|
|
470
|
-
el('p', { class: 'ds-note' }, R ? 'PMOS never writes to ' + fmt().app + ' on its own. Create and Update start one agent session through your own connector, and you can undo for 5 seconds. Nothing is sent to people.'
|
|
471
|
-
: 'PMOS never overwrites this document from a copy: a change in the copy comes in as a proposal you accept by section. Updating a copy starts one agent session, and you have five seconds to undo.'));
|
|
472
|
-
}
|
|
473
|
-
async function checkNow() {
|
|
474
|
-
const r = await pmPost('/api/docs/check', { ws }).catch(() => null);
|
|
475
|
-
if (!r || !r.ok) { say((r && r.error) || 'The check did not start.'); return; }
|
|
476
|
-
S.checkRun = { id: r.session }; draw();
|
|
477
|
-
say('Checking the copies. An agent session reads them with your connectors; the states change when it finishes.');
|
|
478
|
-
for (let i = 0; i < 120 && !S.closed && S.checkRun; i++) {
|
|
479
|
-
await new Promise((ok) => setTimeout(ok, 5000));
|
|
480
|
-
if (S.closed) return;
|
|
481
|
-
await loadCopies(); drawBg();
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
/* a change in the copy comes in as a proposal: the read-only ask run (#637) reads the copy and drafts it by section */
|
|
485
|
-
function takeCopy(l) {
|
|
486
|
-
S.prompt = 'Read the ' + labelOf(l) + ' copy of this document (' + l.target + ') and propose its changes here, section by section. Keep the PMOS text where only PMOS changed.';
|
|
487
|
-
S.syncOpen = false; go('ask');
|
|
488
|
-
if (demo) askDemo(); else askReal();
|
|
489
|
-
}
|
|
490
|
-
function pushCopy(l) {
|
|
491
|
-
const name = labelOf(l);
|
|
492
|
-
S.pend[l.kind] = setTimeout(async () => {
|
|
493
|
-
delete S.pend[l.kind];
|
|
494
|
-
const r = await pmPost('/api/docs/sync', { ws, path: doc.path, kind: l.kind, use: 'pmos' }).catch(() => null);
|
|
495
|
-
if (!r || !r.ok) say((r && r.error) || 'The update did not start.');
|
|
496
|
-
else say('Updating the ' + name + '. A session writes it with your connectors.');
|
|
497
|
-
await loadCopies(); drawBg();
|
|
498
|
-
}, 5000);
|
|
499
|
-
draw();
|
|
500
|
-
}
|
|
501
|
-
function createCopy(l) {
|
|
502
|
-
const name = labelOf(l);
|
|
503
|
-
S.pend[l.kind] = setTimeout(async () => {
|
|
504
|
-
delete S.pend[l.kind];
|
|
505
|
-
const r = await pmPost('/api/docs/create-copy', { ws, path: doc.path, kind: l.kind }).catch(() => null);
|
|
506
|
-
if (!r || !r.ok) say((r && r.error) || 'The copy did not start.');
|
|
507
|
-
else say('Creating the ' + name + ' copy. A session writes it with your connector. Nothing is sent to people.');
|
|
508
|
-
await loadCopies(); drawBg();
|
|
509
|
-
}, 5000);
|
|
510
|
-
draw();
|
|
511
|
-
say('Creating the ' + name + ' copy in five seconds. Nothing is sent to people.', () => undoPush(l));
|
|
512
|
-
}
|
|
513
|
-
function undoPush(l) { clearTimeout(S.pend[l.kind]); delete S.pend[l.kind]; draw(); say('Stopped. The ' + labelOf(l) + ' is not updated.'); }
|
|
514
|
-
async function linkCopy() {
|
|
515
|
-
const t = String(S.linkUrl || '').trim(); const kind = copyKindOf(t);
|
|
516
|
-
if (!kind) { say('Paste a Confluence page or Google Doc link.'); const i = ui.body.querySelector('#dcopyurl'); if (i) i.focus(); return; }
|
|
517
|
-
const r = await pmPost('/api/docs/link', { ws, path: doc.path, kind, target: t }).catch(() => null);
|
|
518
|
-
if (!r || !r.ok) { say((r && r.error) || 'The copy was not linked.'); return; }
|
|
519
|
-
S.linking = false; S.linkUrl = ''; await loadCopies(); draw(); say('Linked the ' + KLABEL[kind] + ' copy. Check now reads it.');
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/* ── v2: the outline (Read) ── */
|
|
523
|
-
const staleNames = () => {
|
|
524
|
-
const f = fresh(); if (!f || !S.text) return new Set();
|
|
525
|
-
const secs = splitDoc(S.text); const out = new Set();
|
|
526
|
-
(Array.isArray(f.sources) ? f.sources : []).forEach((x) => citesIn(secs, x.path).forEach((n) => out.add(n)));
|
|
527
|
-
return out;
|
|
528
|
-
};
|
|
529
|
-
function outlineNav(items) {
|
|
530
|
-
const qq = S.olq.trim().toLowerCase(); const stale = staleNames(); const prop = new Set(openProps().flatMap((p) => p.sections.map((c) => c.name)));
|
|
531
|
-
const rows = []; let hideUnder = null;
|
|
532
|
-
items.forEach((it, k) => {
|
|
533
|
-
const { s, lv } = it;
|
|
534
|
-
if (hideUnder !== null && lv > hideUnder) return;
|
|
535
|
-
hideUnder = null;
|
|
536
|
-
if (qq && !s.name.toLowerCase().includes(qq)) return;
|
|
537
|
-
let n = 0; for (let j = k + 1; j < items.length && items[j].lv > lv; j++) n++;
|
|
538
|
-
const shut = !qq && !!S.olShut[s.i]; if (shut) hideUnder = lv;
|
|
539
|
-
const on = S.cur === s.i;
|
|
540
|
-
rows.push(el('li', { class: 'l' + lv + (on ? ' on' : ''), 'data-ol-i': String(s.i) },
|
|
541
|
-
n && !qq ? btn('tw', { 'aria-label': (shut ? 'Show' : 'Hide') + ' the ' + plural(n, 'heading') + ' under ' + s.name, 'aria-expanded': String(!shut), 'data-ol-fold': String(s.i) }, c3ic('next', 'sm'), () => { S.olShut[s.i] = !shut; redrawOl(); }) : el('span', { class: 'tw' }),
|
|
542
|
-
btn('go', { 'data-ol-go': String(s.i), 'aria-current': on ? 'location' : null }, [el('span', null, it.label || s.name),
|
|
543
|
-
stale.has(s.name) ? el('i', { class: 'mdot w', title: 'A source changed after this section', 'data-ol-stale': '' }) : null,
|
|
544
|
-
prop.has(s.name) ? el('i', { class: 'mdot p', title: 'The agent proposes a change here', 'data-ol-prop': '' }) : null], () => jumpTo(s.i))));
|
|
545
|
-
});
|
|
546
|
-
return el('nav', { class: 'ds-ol', 'aria-label': 'Outline', 'data-doc-outline': '' },
|
|
547
|
-
el('div', { class: 'hd' }, el('b', null, 'Outline'), el('span', { class: 'ds-mono' }, plural(items.length, R ? fmt().word.replace(/s$/, '') : 'heading'))),
|
|
548
|
-
items.length > 12 ? el('input', { type: 'text', id: 'dolq', 'data-ol-find': '', placeholder: 'Find a heading', 'aria-label': 'Find a heading', value: S.olq, onInput: (e) => { S.olq = e.target.value; redrawOl(); } }) : null,
|
|
549
|
-
el('ul', null, rows.length ? rows : el('li', { class: 'none ds-note' }, 'No heading matches.')),
|
|
550
|
-
stale.size || prop.size ? el('div', { class: 'key ds-note' }, stale.size ? el('span', null, el('i', { class: 'mdot w' }), 'stale') : null, prop.size ? el('span', null, el('i', { class: 'mdot p' }), 'proposal') : null) : null);
|
|
551
|
-
}
|
|
552
|
-
function redrawOl() {
|
|
553
|
-
const n = ui && ui.body.querySelector('.ds-ol'); if (!n || S.text == null) return;
|
|
554
|
-
const f = document.activeElement && document.activeElement.id === 'dolq' ? document.activeElement.selectionStart : null;
|
|
555
|
-
n.replaceWith(outlineNav(outlineOf(splitDoc(S.text)))); placeOl();
|
|
556
|
-
if (f != null) { const i = ui.body.querySelector('#dolq'); if (i) { i.focus(); try { i.setSelectionRange(f, f); } catch { /* not a text field */ } } }
|
|
557
|
-
}
|
|
558
|
-
/* where the sticky header ends: a section scrolled to lands below it, and the outline sticks under it */
|
|
559
|
-
/* (a sticky element sticks inside the scroller's padding: its edge from the scroller's top adds the padding) */
|
|
560
|
-
const stickBottom = () => { const t = ui && ui.body.querySelector('.ds-top'); return t ? (parseFloat(getComputedStyle(t).top) || 0) + t.offsetHeight : 0; };
|
|
561
|
-
const topEdge = () => { const sb = ui && ui.body.closest('.sb'); return stickBottom() + (sb ? parseFloat(getComputedStyle(sb).paddingTop) || 0 : 0); };
|
|
562
|
-
function placeOl() {
|
|
563
|
-
const nav = ui && ui.body.querySelector('.ds-ol'); const sb = ui && ui.body.closest('.sb'); if (!nav || !sb) return;
|
|
564
|
-
const h = stickBottom() + 8;
|
|
565
|
-
nav.style.setProperty('--in-ds-oltop', h + 'px'); nav.style.setProperty('--in-ds-olmax', Math.max(160, sb.clientHeight - h - 16) + 'px');
|
|
566
|
-
}
|
|
567
|
-
function jumpTo(i) {
|
|
568
|
-
const sb = ui && ui.body.closest('.sb'); const n = ui && ui.body.querySelector('[data-dsec-i="' + i + '"]'); if (!sb || !n) return;
|
|
569
|
-
sb.scrollTop += n.getBoundingClientRect().top - sb.getBoundingClientRect().top - topEdge() - 8;
|
|
570
|
-
n.classList.remove('flash'); void n.offsetWidth; n.classList.add('flash');
|
|
571
|
-
S.cur = i; S.pinCur = i; S.olOpen = false; const lay = ui.body.querySelector('.ds-rlay'); if (lay) lay.classList.remove('olopen');
|
|
572
|
-
const b = ui.body.querySelector('[data-ol-btn]'); if (b) b.setAttribute('aria-expanded', 'false');
|
|
573
|
-
markCur();
|
|
574
|
-
}
|
|
575
|
-
function trackCur() {
|
|
576
|
-
if (S.mode !== 'read' || !ui) return;
|
|
577
|
-
const sb = ui.body.closest('.sb'); const nav = ui.body.querySelector('.ds-ol'); if (!sb || !nav) return;
|
|
578
|
-
const ids = new Set([...nav.querySelectorAll('[data-ol-i]')].map((x) => x.getAttribute('data-ol-i')));
|
|
579
|
-
const lim = sb.getBoundingClientRect().top + topEdge() + 24; let cur = null;
|
|
580
|
-
for (const s of ui.body.querySelectorAll('.ds-rmain [data-dsec-i]')) {
|
|
581
|
-
const k = s.getAttribute('data-dsec-i');
|
|
582
|
-
if (s.getBoundingClientRect().top <= lim) { if (ids.has(k)) cur = +k; } else break;
|
|
583
|
-
}
|
|
584
|
-
if (cur == null) { const f = nav.querySelector('[data-ol-i]'); cur = f ? +f.getAttribute('data-ol-i') : null; }
|
|
585
|
-
/* a section pressed near the end cannot scroll to the top: it stays the marked one while it is on screen */
|
|
586
|
-
if (S.pinCur != null) {
|
|
587
|
-
const p = ui.body.querySelector('[data-dsec-i="' + S.pinCur + '"]'); const r = p && p.getBoundingClientRect(); const b = sb.getBoundingClientRect();
|
|
588
|
-
if (r && r.top >= b.top + topEdge() - 8 && r.top < b.bottom - 40) cur = S.pinCur; else S.pinCur = null;
|
|
589
|
-
}
|
|
590
|
-
if (cur !== S.cur) { S.cur = cur; markCur(); }
|
|
591
|
-
}
|
|
592
|
-
function markCur() {
|
|
593
|
-
const nav = ui && ui.body.querySelector('.ds-ol'); if (!nav) return;
|
|
594
|
-
nav.querySelectorAll('[data-ol-i]').forEach((li) => { const on = +li.getAttribute('data-ol-i') === S.cur; li.classList.toggle('on', on); const g = li.querySelector('[data-ol-go]'); if (g) { if (on) g.setAttribute('aria-current', 'location'); else g.removeAttribute('aria-current'); } });
|
|
595
|
-
const secs = S.text ? splitDoc(S.text) : []; const c = secs.find((s) => s.i === S.cur);
|
|
596
|
-
const ob = ui.body.querySelector('[data-ol-btn] b'); if (ob) ob.textContent = c ? c.name : '';
|
|
597
|
-
const on = nav.querySelector('li.on');
|
|
598
|
-
if (on && nav.scrollHeight > nav.clientHeight) { const t = on.offsetTop - nav.offsetTop; if (t < nav.scrollTop || t > nav.scrollTop + nav.clientHeight - 30) nav.scrollTop = t - nav.clientHeight / 3; }
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/* ── v2: Relations, the graph around this document (from the caller's library, else GET /api/docs/library) ── */
|
|
602
|
-
const loadLib = async () => {
|
|
603
|
-
if (S.lib !== undefined) return;
|
|
604
|
-
S.lib = null;
|
|
605
|
-
const j = await (library ? Promise.resolve().then(library) : pmGet('/api/docs/library?' + q({ ws }))).catch(() => null);
|
|
606
|
-
S.lib = j && j.ok ? j : { err: (j && j.error) || 'The document graph could not be read.' };
|
|
607
|
-
drawBg();
|
|
608
|
-
};
|
|
609
|
-
const catName = (c) => { const k = ((S.lib && S.lib.categories) || []).find((x) => x.key === c); return k ? k.name : c || 'Document'; };
|
|
610
|
-
const fileDoc = (f) => ({ path: f.path, name: f.title || f.path, ty: f.ty || catName(f.category), v: f.v || '', st: STATE[f.st] ? f.st : 'current', ini: f.initiative || '',
|
|
611
|
-
iniName: (S.lib && S.lib.initiatives && S.lib.initiatives[f.initiative] && (S.lib.initiatives[f.initiative].short || S.lib.initiatives[f.initiative].title)) || f.initiative || '' });
|
|
612
|
-
function graphNodes() {
|
|
613
|
-
const H = hoodOf(S.lib && !S.lib.err ? S.lib : null, doc.path) || { src: [], out: [] };
|
|
614
|
-
const isGoal = (f) => f.category === 'goal' || f.node === 'Goal';
|
|
615
|
-
const nd = (e, side) => { const f = e.f; const file = !f.node && f.st !== 'node' && f.st !== 'missing';
|
|
616
|
-
return { side, name: f.title || f.path, sub: [...new Set([e.kind, f.node || (f.date ? dayName(f.date) : '')].filter(Boolean).map((x) => x.toLowerCase() === String(e.kind).toLowerCase() ? e.kind : x))].join(' · '), st: e.st, path: f.path, open: file ? fileDoc(f) : null }; };
|
|
617
|
-
const top = H.src.filter((e) => isGoal(e.f)).map((e) => nd(e, 'top'));
|
|
618
|
-
if (doc.ini || doc.iniName) top.unshift({ side: 'top', name: doc.iniName || doc.ini, sub: 'initiative', st: 'ok', init: true });
|
|
619
|
-
const left = H.src.filter((e) => !isGoal(e.f)).map((e) => nd(e, 'left'));
|
|
620
|
-
const right = H.out.map((e) => nd(e, 'right')).concat((S.copies || []).map((l) => ({ side: 'right', name: labelOf(l) + ' copy', sub: sigOf(l)[4], url: l.url, kind: l.kind,
|
|
621
|
-
st: l.signal === 'behind' || l.signal === 'diverged' ? 'drift' : l.signal === 'ahead' ? 'ahead' : l.signal === 'same' ? 'ok' : 'missing' })));
|
|
622
|
-
return { top, left, right };
|
|
623
|
-
}
|
|
624
|
-
function graphEl(G) {
|
|
625
|
-
const CAP = 6;
|
|
626
|
-
const node = (n) => {
|
|
627
|
-
const kids = [el('b', null, n.name), el('small', null, n.sub)];
|
|
628
|
-
const a = { 'data-gn': n.side, 'data-gn-st': n.st, 'data-gn-copy': n.kind || null };
|
|
629
|
-
if (n.url) return el('a', { class: 'ds-gn ' + n.st, href: n.url, target: '_blank', rel: 'noopener', ...a }, ...kids);
|
|
630
|
-
if (n.open) return btn('ds-gn ' + n.st, { 'data-gn-path': n.path, title: 'Open ' + n.name, ...a }, kids, () => S.open(n.open));
|
|
631
|
-
return el('div', { class: 'ds-gn x ' + n.st, ...a }, ...kids);
|
|
632
|
-
};
|
|
633
|
-
const col = (list) => [list.slice(0, CAP).map(node), list.length > CAP ? el('div', { class: 'ds-note ds-gmore' }, '+' + (list.length - CAP) + ' more, listed below') : null];
|
|
634
|
-
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('class', 'ds-gsvg'); svg.setAttribute('aria-hidden', 'true');
|
|
635
|
-
const wrap = el('div', { class: 'ds-graph', role: 'group', 'aria-label': 'This document, its sources on the left, its initiative above, the documents that use it and its copies on the right', 'data-doc-graph': '' }, svg,
|
|
636
|
-
G.top.length ? el('div', { class: 'ds-gtop' }, col(G.top)) : null,
|
|
637
|
-
el('div', { class: 'ds-gmid' }, el('div', { class: 'ds-gcol' }, G.left.length ? col(G.left) : el('div', { class: 'ds-note' }, 'No source recorded')),
|
|
638
|
-
el('div', { class: 'ds-gn me', 'data-gn': 'me' }, el('b', null, doc.name), el('small', null, 'this document' + (doc.v ? ' · ' + doc.v : ''))),
|
|
639
|
-
el('div', { class: 'ds-gcol' }, G.right.length ? col(G.right) : el('div', { class: 'ds-note' }, 'Nothing uses it yet'))),
|
|
640
|
-
el('div', { class: 'key ds-note' }, el('span', null, el('i', { class: 'ln ok' }), 'in step'), el('span', null, el('i', { class: 'ln drift' }), 'out of step'), el('span', null, el('i', { class: 'ln ahead' }), 'PMOS ahead of the copy'),
|
|
641
|
-
openGraph ? btn('chip2 lk', { 'data-doc-fullgraph': '' }, [c3ic('tree', 'sm'), 'Open the full graph in Docs'], () => { ui.close(); openGraph(doc); }) : null));
|
|
642
|
-
if (typeof ResizeObserver === 'function') new ResizeObserver(() => drawEdges(wrap)).observe(wrap);
|
|
643
|
-
return wrap;
|
|
644
|
-
}
|
|
645
|
-
function drawEdges(wrap) {
|
|
646
|
-
const svg = wrap.querySelector('.ds-gsvg'); const me = wrap.querySelector('[data-gn="me"]'); if (!svg || !me || !wrap.isConnected) return;
|
|
647
|
-
const W = wrap.getBoundingClientRect(); const M = me.getBoundingClientRect();
|
|
648
|
-
svg.setAttribute('viewBox', '0 0 ' + Math.round(W.width) + ' ' + Math.round(W.height)); svg.setAttribute('width', String(Math.round(W.width))); svg.setAttribute('height', String(Math.round(W.height)));
|
|
649
|
-
const paths = [...wrap.querySelectorAll('[data-gn]:not([data-gn="me"])')].map((n) => {
|
|
650
|
-
const R = n.getBoundingClientRect(); const side = n.getAttribute('data-gn');
|
|
651
|
-
const [fx, fy, tx, ty] = side === 'left' ? [R.right, R.top + R.height / 2, M.left, M.top + M.height / 2] : side === 'right' ? [M.right, M.top + M.height / 2, R.left, R.top + R.height / 2] : [R.left + R.width / 2, R.bottom, M.left + M.width / 2, M.top];
|
|
652
|
-
const x1 = fx - W.left; const y1 = fy - W.top; const x2 = tx - W.left; const y2 = ty - W.top;
|
|
653
|
-
const d = side === 'top' ? 'M' + x1 + ' ' + y1 + ' C ' + x1 + ' ' + (y1 + y2) / 2 + ', ' + x2 + ' ' + (y1 + y2) / 2 + ', ' + x2 + ' ' + y2 : 'M' + x1 + ' ' + y1 + ' C ' + (x1 + x2) / 2 + ' ' + y1 + ', ' + (x1 + x2) / 2 + ' ' + y2 + ', ' + x2 + ' ' + y2;
|
|
654
|
-
const p = document.createElementNS('http://www.w3.org/2000/svg', 'path'); p.setAttribute('d', d); p.setAttribute('class', 'e ' + (n.getAttribute('data-gn-st') || 'ok')); return p;
|
|
655
|
-
});
|
|
656
|
-
svg.replaceChildren(...paths);
|
|
657
|
-
}
|
|
658
|
-
function linksBody() {
|
|
659
|
-
if (S.lib === undefined) loadLib();
|
|
660
|
-
if (S.lib == null) return el('div', { class: 'fold', role: 'status' }, c3ic('clock', 'sm'), 'Reading the document graph.');
|
|
661
|
-
const G = graphNodes(); const any = G.left.length || G.right.length || G.top.some((n) => !n.init);
|
|
662
|
-
const rel = (h, list) => list.length ? [el('h3', { class: 'ds-h' }, h), el('ul', { class: 'ds-rel' }, list.map((n) => el('li', { 'data-rel': n.path || n.kind || n.name },
|
|
663
|
-
c3ic(n.url ? 'out' : n.init ? 'init' : 'doc', 'sm'),
|
|
664
|
-
n.open ? btn('ds-rlk', { 'data-rel-open': n.path }, [n.name, el('small', null, n.sub)], () => S.open(n.open)) : n.url ? el('a', { class: 'ds-rlk', href: n.url, target: '_blank', rel: 'noopener' }, n.name, el('small', null, n.sub)) : el('span', { class: 'ds-rlk' }, n.name, el('small', null, n.sub)),
|
|
665
|
-
n.st && n.st !== 'ok' ? el('span', { class: 'tag ' + (n.st === 'ahead' ? 'ds-acc' : n.st === 'drift' ? 'ds-warn' : 'ds-bad') }, ESTATE[n.st] || n.st) : el('span'))))] : null;
|
|
666
|
-
return el('div', { class: 'ds' },
|
|
667
|
-
S.lib.err ? el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), S.lib.err) : null,
|
|
668
|
-
any ? graphEl(G) : el('div', { class: 'fold', 'data-doc-norel': '' }, c3ic('info', 'sm'), 'No relation is recorded for this document.'),
|
|
669
|
-
relations ? relations(doc, (d) => { if (S.open) S.open(d); }) : [rel('Sources', G.left), rel('Goals and initiative', G.top.filter((n) => !n.init)), rel('Used by and copies', G.right)]);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/* ── Read ── */
|
|
673
|
-
function propsBlock(secs, editing) {
|
|
674
|
-
const s0 = secs.find((s) => s.prefix === ''); const fm = s0 && parseFront(s0.text);
|
|
675
|
-
if (!fm || !fm.fields.length) return null;
|
|
676
|
-
if (editing) {
|
|
677
|
-
return el('dl', { class: 'ds-props', 'data-doc-props': 'edit' }, fm.fields.map((f) => [el('dt', null, el('label', { for: 'dsp-' + f.key }, f.key)),
|
|
678
|
-
el('dd', null, f.editable ? el('input', { id: 'dsp-' + f.key, type: 'text', value: S.ed.front[f.key] != null ? S.ed.front[f.key] : f.value, 'data-doc-prop': f.key, onInput: (e) => { S.ed.front[f.key] = e.target.value; mark(); } }) : f.value)]));
|
|
679
|
-
}
|
|
680
|
-
const r = S.meta && S.meta['Front matter'];
|
|
681
|
-
return el('dl', { class: 'ds-props', 'data-doc-props': '' }, fm.fields.map((f) => [el('dt', null, f.key), el('dd', null, f.value)]),
|
|
682
|
-
el('div', { class: 'sub' }, c3ic('doc', 'sm'), 'Front matter', r ? [' · ', byChip(r)] : null));
|
|
683
|
-
}
|
|
684
|
-
/* a designed report cycle (initiative report-design-studio): c3-report-deck.js draws the deck or the interactive document in place of the
|
|
685
|
-
format view, and reaches back through this api (the Edit tab at a section, the Markdown source, the copies, the download, the edit log) */
|
|
686
|
-
const deckApi = { redraw: () => drawBg(), setSrc: (v) => { S.src = !!v; draw(); }, toggleCopies: () => toggleCopies(), download: (fmt) => download({ fmt }), editAt: (name) => editAt(name), logChanged: () => { S.log = null; }, go: (m) => go(m) };
|
|
687
|
-
function editAt(name) {
|
|
688
|
-
if (frozen()) { say('Issued reports are frozen. Start the next cycle to change the words.'); return; }
|
|
689
|
-
go('edit');
|
|
690
|
-
setTimeout(() => {
|
|
691
|
-
const k = S.ed ? S.ed.base.findIndex((x) => x.name === name) : -1;
|
|
692
|
-
const h = k >= 0 && ui ? ui.body.querySelector('[data-sid="' + k + '"]') : null;
|
|
693
|
-
if (!h) return;
|
|
694
|
-
h.scrollIntoView({ block: 'start' }); h.setAttribute('data-doc-editat', '');
|
|
695
|
-
try { const r = document.createRange(); r.selectNodeContents(h); r.collapse(false); const sel = getSelection(); sel.removeAllRanges(); sel.addRange(r); const ed = ui.body.querySelector('[data-doc-editor]'); if (ed) ed.focus({ preventScroll: true }); } catch { /* the caret stays where it is */ }
|
|
696
|
-
}, 30);
|
|
697
|
-
}
|
|
698
|
-
function readBody() {
|
|
699
|
-
if (S.text == null) return S.err ? el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), S.err) : el('div', { class: 'fold', role: 'status' }, c3ic('clock', 'sm'), 'Reading the document.');
|
|
700
|
-
const deck = R && R.deck && !S.src ? R.deck(deckApi) : null;
|
|
701
|
-
if (deck) return el('div', { class: 'ds' }, staleBanner(), deck);
|
|
702
|
-
const secs = splitDoc(S.text);
|
|
703
|
-
if (!S.text.trim()) return el('div', { class: 'fold' }, c3ic('moon', 'sm'), 'The document is empty.');
|
|
704
|
-
const items = R ? outlineLabels(secs, R.output) : outlineOf(secs); const olOn = items.length >= 2 && !S.src;
|
|
705
|
-
if (S.cur == null && items.length) S.cur = items[0].s.i;
|
|
706
|
-
const curName = (items.find((x) => x.s.i === S.cur) || items[0] || { s: { name: '' } }).s.name;
|
|
707
|
-
const olCtl = olOn ? el('span', { class: 'ds-acts' },
|
|
708
|
-
btn('ds-btn ds-olbtn', { 'aria-expanded': String(S.olOpen), 'data-ol-btn': '' }, [c3ic('ul', 'sm'), 'Outline · ', el('b', null, curName)], () => { S.olOpen = !S.olOpen; const lay = ui.body.querySelector('.ds-rlay'); if (lay) lay.classList.toggle('olopen', S.olOpen); const b = ui.body.querySelector('[data-ol-btn]'); if (b) b.setAttribute('aria-expanded', String(S.olOpen)); }),
|
|
709
|
-
btn('ds-btn ds-olhide', { 'aria-pressed': String(!S.ol), 'data-ol-hide': '' }, [c3ic('ul', 'sm'), S.ol ? 'Hide the outline' : 'Show the outline'], () => { S.ol = !S.ol; olSet(S.ol); draw(); })) : el('span');
|
|
710
|
-
const tg = (id, label, on, set) => el('label', { class: 'ds-tg' }, el('input', { type: 'checkbox', checked: on, 'data-doc-toggle': id, onChange: (e) => { set(e.target.checked); draw(); } }), label);
|
|
711
|
-
const bar = el('div', { class: 'ds-rbar' }, olCtl, el('span', { class: 'ds-acts' },
|
|
712
|
-
generated ? null : tg('who', 'Show who wrote what', S.who, (v) => { S.who = v; }), tg('src', 'Markdown source', S.src, (v) => { S.src = v; })));
|
|
713
|
-
const legend = S.who ? el('div', { class: 'ds-legend' }, el('span', null, el('i', { class: 'h' }), 'Written by a person'), el('span', null, el('i', { class: 'a' }), 'Written by the agent, accepted by a person')) : null;
|
|
714
|
-
if (S.src) {
|
|
715
|
-
const pre = el('pre', { 'data-doc-source': '' }, el('code', null, S.text));
|
|
716
|
-
const copy = async () => { try { await navigator.clipboard.writeText(S.text); say('Copied the markdown.'); } catch { const s = getSelection(); const rg = document.createRange(); rg.selectNodeContents(pre); s.removeAllRanges(); s.addRange(rg); say('Copying is blocked here. The text is selected.'); } };
|
|
717
|
-
return el('div', { class: 'ds' }, bar, el('div', { class: 'ds-acts' }, btn('ds-btn', { 'data-doc-copysrc': '' }, [c3ic('copy', 'sm'), 'Copy the markdown'], copy), el('span', { class: 'ds-mono' }, doc.path)), el('div', { class: 'ds-md' }, pre));
|
|
718
|
-
}
|
|
719
|
-
const meta = S.meta || {};
|
|
720
|
-
const pins = (name) => openProps().filter((p) => p.sections.some((c) => c.name === name && c.kind !== 'added'));
|
|
721
|
-
const flags = {}; failing().forEach((c) => { if (c.section && c.flag) flags[c.section] = c.flag; });
|
|
722
|
-
const secCell = (s, inner, label) => {
|
|
723
|
-
const fm = s.prefix === '' ? parseFront(s.text) : null;
|
|
724
|
-
const body = fm ? fm.rest.trim() : s.text;
|
|
725
|
-
if (!s.prefix && !body) return null;
|
|
726
|
-
const r = meta[s.name]; const P = pins(s.name);
|
|
727
|
-
const shown = P.find((p) => S.preview[p.id]);
|
|
728
|
-
const ch = shown && shown.sections.find((c) => c.name === s.name);
|
|
729
|
-
const content = ch ? md(diffMd(ch.stale ? s.text : ch.before, ch.after), 'ds-body') : inner ? inner : body ? md(body, 'ds-body') : headLevel(s) === 1 ? null : el('p', { class: 'ds-note' }, 'This section is empty.');
|
|
730
|
-
const lvl = Math.min(3, Math.max(2, headLevel(s)));
|
|
731
|
-
return el('div', { class: 'ds-sec ' + (r ? (isAgentRev(r) ? 'a' : 'h') : '') + (ch ? ' prev' : ''), 'data-dsec': s.name, 'data-dsec-i': String(s.i) },
|
|
732
|
-
s.prefix ? el('div', { class: 'ds-sec-h' }, label ? el('h3', null, label) : headLevel(s) === 1 ? el('div', { class: 'ds-md' }, el('h1', null, s.name)) : el('h' + lvl, null, s.name), generated ? null : byChip(r)) : null,
|
|
733
|
-
P.map((p) => { const c = p.sections.find((x) => x.name === s.name); return el('div', { class: 'ds-pin', 'data-doc-pin': p.id }, el('span', null, c3ic('spark', 'sm'), (c.stale ? 'A proposal was drafted against older text here' : 'The agent proposes a change here') + ': “' + short(p.prompt) + '”'),
|
|
734
|
-
el('span', { class: 'ds-acts' }, btn('ds-btn', { 'data-doc-preview': p.id }, S.preview[p.id] ? 'Show current' : 'Show change', () => { S.preview[p.id] = !S.preview[p.id]; draw(); }),
|
|
735
|
-
btn('ds-btn ag', {}, 'Review', () => { S.openProp = p.id; go('ask'); }))); }),
|
|
736
|
-
flags[s.name] ? el('div', { class: 'fold w', role: 'note' }, c3ic('alert', 'sm'), flags[s.name]) : null,
|
|
737
|
-
content, secExtra ? secExtra(s.name) : null);
|
|
738
|
-
};
|
|
739
|
-
const cells = R && !S.src ? [formatView({ output: R.output, name: R.name || doc.name, cycle: R.cycle, foot: R.foot, secs, md: (t) => md(t, 'ds-body'), wrap: (s, inner, label) => secCell(s, inner, label) })] : secs.map((s) => secCell(s));
|
|
740
|
-
const adds = openProps().flatMap((p) => p.sections.filter((c) => c.kind === 'added' && S.preview[p.id]).map((c) => el('div', { class: 'ds-sec a prev', 'data-dsec-new': c.name },
|
|
741
|
-
el('div', { class: 'ds-pin' }, el('span', null, c3ic('spark', 'sm'), 'The proposal adds a section: ' + c.name)), el('div', { class: 'ds-sec-h' }, el('h2', null, c.name)), md(diffMd(null, c.after), 'ds-body'))));
|
|
742
|
-
const copyNote = R && R.copyNotice ? el('div', { class: 'fold', 'data-rd-copynote': '' }, c3ic('info', 'sm'), ' The deck now lives in PMOS. The Google Slides copy of this report is optional. ', btn('chip2 lk', {}, 'Copies in other tools', () => toggleCopies())) : null;
|
|
743
|
-
// a draft on a Work item: the box that writes to the agent sits under the draft (amendment 16)
|
|
744
|
-
const main = [generated ? el('div', { class: 'fold', role: 'note', 'data-doc-generated': '' }, c3ic('info', 'sm'), generated.why) : null, copyNote, staleBanner(), propsBlock(secs, false), cells, adds,
|
|
745
|
-
generated && generated.ask ? askGenerated() : null];
|
|
746
|
-
return el('div', { class: 'ds' + (S.who ? ' who' : '') }, bar, legend,
|
|
747
|
-
olOn ? el('div', { class: 'ds-rlay' + (S.ol ? '' : ' nool') + (S.olOpen ? ' olopen' : '') }, outlineNav(items), el('div', { class: 'ds-rmain' }, main)) : el('div', { class: 'ds-rmain' }, main));
|
|
748
|
-
}
|
|
749
|
-
const short = (t) => { const s = String(t || '').replace(/\s+/g, ' ').trim(); return s.length > 90 ? s.slice(0, 88) + '…' : s; };
|
|
750
|
-
|
|
751
|
-
/* ── Edit ── */
|
|
752
|
-
function startEdit() {
|
|
753
|
-
if ((generated && !generated.save) || frozen() || S.text == null) { S.ed = null; return; }
|
|
754
|
-
S.ed = { text: S.text, base: splitDoc(S.text), front: {}, kind: 'rich', why: '', whyBad: false, node: null, ta: null, range: null, link: false };
|
|
755
|
-
}
|
|
756
|
-
function edNode() {
|
|
757
|
-
const E = S.ed; const kids = [];
|
|
758
|
-
E.base.forEach((s, i) => {
|
|
759
|
-
if (s.prefix === '') { const fm = parseFront(s.text); const rest = fm ? fm.rest.trim() : s.text; if (rest) kids.push(...toDom(parseMd(rest), document, { editable: true })); return; }
|
|
760
|
-
const h = el('h' + Math.min(6, Math.max(1, headLevel(s))), { 'data-sid': String(i) }, s.name);
|
|
761
|
-
kids.push(h, ...toDom(parseMd(s.text), document, { editable: true }));
|
|
762
|
-
});
|
|
763
|
-
const n = el('div', { class: 'ds-md ds-ed', id: 'ded', contenteditable: 'true', role: 'textbox', 'aria-multiline': 'true', 'aria-label': 'Document', spellcheck: 'true', 'data-doc-editor': '',
|
|
764
|
-
onInput: () => { clearTimeout(E.t); E.t = setTimeout(mark, 200); }, onChange: () => mark(),
|
|
765
|
-
onKeyDown: (e) => { if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); linkOpen(); } if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { e.preventDefault(); save(); } } }, kids);
|
|
766
|
-
n.querySelectorAll('input[type=checkbox]').forEach((c) => { c.disabled = false; });
|
|
767
|
-
return n;
|
|
768
|
-
}
|
|
769
|
-
/** The draft as text, from whichever editor is open. */
|
|
770
|
-
function draftText() {
|
|
771
|
-
const E = S.ed; if (!E) return S.text;
|
|
772
|
-
const s0 = E.base.find((s) => s.prefix === ''); const fm = s0 && parseFront(s0.text);
|
|
773
|
-
const front = fm ? setFront(fm.block, E.front) : null;
|
|
774
|
-
if (E.kind === 'md') {
|
|
775
|
-
let t = E.ta ? E.ta.value : E.text;
|
|
776
|
-
if (fm && front !== fm.block && t.startsWith(fm.block)) t = front + t.slice(fm.block.length);
|
|
777
|
-
return t;
|
|
778
|
-
}
|
|
779
|
-
if (!E.node) return E.text;
|
|
780
|
-
const groups = []; let intro = []; let cur = null;
|
|
781
|
-
for (const n of Array.from(E.node.childNodes)) {
|
|
782
|
-
if (n.nodeType === 1 && /^H[1-6]$/.test(n.tagName)) { cur = { sid: n.hasAttribute('data-sid') ? Number(n.getAttribute('data-sid')) : null, level: Number(n.tagName[1]), name: n.textContent.replace(/\s+/g, ' ').trim() || 'Untitled section', nodes: [] }; groups.push(cur); continue; }
|
|
783
|
-
(cur ? cur.nodes : intro).push(n);
|
|
784
|
-
}
|
|
785
|
-
const mdOf = (nodes) => { const d = document.createElement('div'); nodes.forEach((x) => d.appendChild(x.cloneNode(true))); return toMd(fromDom(d)); };
|
|
786
|
-
return composeSections(E.base, groups.map((g) => ({ sid: g.sid, level: g.level, name: g.name, md: mdOf(g.nodes) })), mdOf(intro), front);
|
|
787
|
-
}
|
|
788
|
-
const dirty = () => (S.ed ? changedSections(S.text, draftText()) : []);
|
|
789
|
-
const clashOf = (name) => openProps().find((p) => p.sections.some((c) => c.name === name));
|
|
790
|
-
function mark() {
|
|
791
|
-
const E = S.ed; if (!E) return;
|
|
792
|
-
const ch = dirty(); const names = new Set(ch.map((c) => c.name));
|
|
793
|
-
if (E.node) E.node.querySelectorAll(':scope > h1,:scope > h2,:scope > h3,:scope > h4,:scope > h5,:scope > h6').forEach((h) => {
|
|
794
|
-
const nm = h.textContent.replace(/\s+/g, ' ').trim(); const on = !h.hasAttribute('data-sid') || names.has(nm) || names.has(E.base[Number(h.getAttribute('data-sid'))]?.name);
|
|
795
|
-
h.classList.toggle('chg', on); h.classList.toggle('clash', !!(on && clashOf(nm)));
|
|
796
|
-
});
|
|
797
|
-
const s = ui.body.querySelector('[data-doc-savesum]'); if (s) s.replaceChildren(...saveSum(ch).filter(Boolean));
|
|
798
|
-
}
|
|
799
|
-
function saveSum(ch) {
|
|
800
|
-
if (!ch.length) return [c3ic('info', 'sm'), generated ? 'No changes yet.' : 'No changes yet. Health checks the document again after you save.'];
|
|
801
|
-
const cl = [...new Set(ch.map((c) => clashOf(c.name)).filter(Boolean))];
|
|
802
|
-
return [c3ic('edit', 'sm'), plural(ch.length, 'section') + ' changed: ' + ch.map((c) => c.name).join(', ') + '.',
|
|
803
|
-
cl.length ? el('span', { class: 'ds-warn' }, ' ' + plural(cl.length, 'open proposal') + ' also change' + (cl.length === 1 ? 's' : '') + ' them; accepting it after your save needs a new draft.') : null];
|
|
804
|
-
}
|
|
805
|
-
const keepRange = () => { const E = S.ed; const s = getSelection(); if (E && E.node && s.rangeCount && E.node.contains(s.anchorNode)) E.range = s.getRangeAt(0).cloneRange(); };
|
|
806
|
-
const restore = () => { const E = S.ed; if (E && E.range) { const s = getSelection(); s.removeAllRanges(); s.addRange(E.range); } };
|
|
807
|
-
function cmd(c, arg) {
|
|
808
|
-
const E = S.ed; if (!E || E.kind !== 'rich' || !E.node) { say('Switch to Rich to use the toolbar.'); return; }
|
|
809
|
-
E.node.focus(); restore();
|
|
810
|
-
const txt = getSelection().toString();
|
|
811
|
-
if (c === 'code') document.execCommand('insertHTML', false, '<code>' + esc(txt || 'code') + '</code>​');
|
|
812
|
-
else if (c === 'task') document.execCommand('insertHTML', false, '<ul class="tasks"><li class="task"><input type="checkbox" aria-label="Done"><span>' + esc(txt || 'New item') + '</span></li></ul>');
|
|
813
|
-
else if (c === 'table') document.execCommand('insertHTML', false, '<div class="tw"><table><thead><tr><th>Column</th><th>Column</th></tr></thead><tbody><tr><td> </td><td> </td></tr></tbody></table></div><p><br></p>');
|
|
814
|
-
else if (c === 'formatBlock') document.execCommand('formatBlock', false, arg);
|
|
815
|
-
else document.execCommand(c, false, arg);
|
|
816
|
-
keepRange(); mark();
|
|
817
|
-
}
|
|
818
|
-
function linkOpen() { keepRange(); S.ed.link = true; drawEdit(); const i = ui.body.querySelector('#dlink'); if (i) i.focus(); }
|
|
819
|
-
function linkDone(ok, url) {
|
|
820
|
-
const E = S.ed; E.link = false; const u = safeHref(String(url || '').trim());
|
|
821
|
-
drawEdit();
|
|
822
|
-
if (!ok || !u) { if (ok && url && !u) say('That link cannot be used. Use an http or https address, or a path.'); return; }
|
|
823
|
-
E.node.focus(); restore();
|
|
824
|
-
if (getSelection().toString()) document.execCommand('createLink', false, u); else document.execCommand('insertHTML', false, '<a href="' + esc(u) + '">' + esc(u) + '</a>');
|
|
825
|
-
mark();
|
|
826
|
-
}
|
|
827
|
-
function toolbar() {
|
|
828
|
-
const E = S.ed;
|
|
829
|
-
const tb = (c, ic, l, arg) => btn('', { 'aria-label': l, title: l, 'data-doc-cmd': c, onMouseDown: (e) => e.preventDefault() }, c3ic(ic, 'sm'), () => (c === 'link' ? linkOpen() : cmd(c, arg)));
|
|
830
|
-
const style = el('select', { 'aria-label': 'Paragraph style', 'data-doc-style': '', onChange: (e) => { cmd('formatBlock', e.target.value); e.target.value = ''; } },
|
|
831
|
-
el('option', { value: '' }, 'Style'), el('option', { value: 'p' }, 'Text'), el('option', { value: 'h2' }, 'Section heading'), el('option', { value: 'h3' }, 'Subheading'), el('option', { value: 'blockquote' }, 'Callout'));
|
|
832
|
-
const kind = el('div', { class: 'seg', role: 'group', 'aria-label': 'Editor' },
|
|
833
|
-
btn('', { 'aria-pressed': String(E.kind === 'rich'), 'data-doc-edkind': 'rich' }, [c3ic('eye', 'sm'), 'Rich'], () => switchKind('rich')),
|
|
834
|
-
btn('', { 'aria-pressed': String(E.kind === 'md'), 'data-doc-edkind': 'md' }, [c3ic('md', 'sm'), 'Markdown'], () => switchKind('md')));
|
|
835
|
-
const bar = el('div', { class: 'ds-tb', role: 'toolbar', 'aria-label': 'Formatting' }, style, el('span', { class: 'sep' }),
|
|
836
|
-
tb('bold', 'bold', 'Bold (Ctrl+B)'), tb('italic', 'italic', 'Italic (Ctrl+I)'), tb('code', 'code', 'Inline code'), tb('link', 'link', 'Link (Ctrl+K)'), el('span', { class: 'sep' }),
|
|
837
|
-
tb('insertUnorderedList', 'ul', 'Bulleted list'), tb('insertOrderedList', 'ol', 'Numbered list'), tb('task', 'task', 'Checklist'), tb('table', 'table', 'Table'), tb('insertHorizontalRule', 'hr', 'Divider'), el('span', { class: 'sep' }),
|
|
838
|
-
tb('undo', 'undo', 'Undo (Ctrl+Z)'), tb('redo', 'redo', 'Redo'), el('span', { class: 'sp' }), kind);
|
|
839
|
-
if (!E.link) return bar;
|
|
840
|
-
const inp = el('input', { id: 'dlink', type: 'url', placeholder: 'Paste a link, for example a Confluence page', 'aria-label': 'Link address', onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); linkDone(true, e.target.value); } if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); linkDone(false); } } });
|
|
841
|
-
return [bar, el('div', { class: 'ds-pop', 'data-doc-linkpop': '' }, c3ic('link', 'sm'), inp, btn('ds-btn pri', {}, 'Add link', () => linkDone(true, inp.value)), btn('ds-btn', {}, 'Cancel', () => linkDone(false)))];
|
|
842
|
-
}
|
|
843
|
-
function switchKind(k) {
|
|
844
|
-
const E = S.ed; if (E.kind === k) return;
|
|
845
|
-
E.text = draftText(); E.kind = k;
|
|
846
|
-
if (k === 'rich') { E.base = splitDoc(E.text); E.node = null; }
|
|
847
|
-
drawEdit();
|
|
848
|
-
}
|
|
849
|
-
function editBody() {
|
|
850
|
-
if (generated && !generated.save) return el('div', { class: 'fold w', role: 'note', 'data-doc-nostore': 'edit' }, c3ic('lock', 'sm'), generated.why);
|
|
851
|
-
if (frozen()) return el('div', { class: 'ds', 'data-doc-frozen': '' }, el('div', { class: 'fold w', role: 'status' }, c3ic('lock', 'sm'), 'Issued reports are frozen. Start the next cycle to change it.'),
|
|
852
|
-
el('div', { class: 'ds-acts' }, btn('ds-btn pri', { 'data-doc-next': '' }, [c3ic('plus', 'sm'), 'Start the next cycle'], () => nextCycle())));
|
|
853
|
-
if (S.text == null) return readBody();
|
|
854
|
-
if (!S.ed) startEdit();
|
|
855
|
-
const E = S.ed;
|
|
856
|
-
const secs = splitDoc(S.text);
|
|
857
|
-
let area;
|
|
858
|
-
if (E.kind === 'rich') { if (!E.node) E.node = edNode(); area = E.node; E.ta = null; }
|
|
859
|
-
else { E.ta = E.ta || el('textarea', { class: 'ds-src', id: 'dsrc', 'aria-label': 'Markdown source', spellcheck: 'false', 'data-doc-mdsrc': '', onInput: () => { clearTimeout(E.t); E.t = setTimeout(mark, 250); } }, E.text); area = E.ta; E.node = null; }
|
|
860
|
-
const why = el('input', { type: 'text', id: 'dwhy', class: E.whyBad ? 'bad' : '', placeholder: generated ? 'What did you change? Optional.' : 'Why are you changing it? Kept in the edit log.', 'aria-label': 'Why', 'data-doc-why': '', value: E.why,
|
|
861
|
-
onInput: (e) => { E.why = e.target.value; if (E.whyBad && E.why.trim()) { E.whyBad = false; e.target.classList.remove('bad'); const a = ui.body.querySelector('[data-doc-whybad]'); if (a) a.remove(); } } });
|
|
862
|
-
const save = el('div', { class: 'ds-save' }, el('div', { class: 'sum', 'data-doc-savesum': '' }, saveSum([])), why,
|
|
863
|
-
E.whyBad ? el('div', { class: 'fold w', role: 'alert', 'data-doc-whybad': '' }, c3ic('alert', 'sm'), 'Say why the document changes. The reason is kept in the edit log.') : null,
|
|
864
|
-
S.err ? el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), S.err) : null,
|
|
865
|
-
el('div', { class: 'row' }, el('span', { class: 'ds-mono' }, c3ic('user', 'sm'), generated ? ' Saved by you as the draft' : ' Saved by you' + (nextV(doc.v) ? ' as ' + nextV(doc.v) : '')),
|
|
866
|
-
el('span', { class: 'ds-acts' }, btn('ds-btn', { 'data-doc-cancel': '' }, 'Cancel', () => { S.ed = null; S.err = ''; go('read'); }),
|
|
867
|
-
btn('ds-btn pri', { 'data-doc-save': '' }, [c3ic('check', 'sm'), 'Save' + (nextV(doc.v) ? ' as ' + nextV(doc.v) : '')], () => saveDoc()))));
|
|
868
|
-
return el('div', { class: 'ds', 'data-doc-edit': '' }, staleBanner(), propsBlock(secs, true), area, save);
|
|
869
|
-
}
|
|
870
|
-
function drawEdit() { draw(); if (S.ed) setTimeout(mark, 0); }
|
|
871
|
-
async function saveDoc() {
|
|
872
|
-
const E = S.ed; if (!E || S.busy) return;
|
|
873
|
-
const after = draftText(); const ch = changedSections(S.text, after);
|
|
874
|
-
if (after === S.text || !ch.length) { say('Nothing changed.'); S.ed = null; S.err = ''; go('read'); return; }
|
|
875
|
-
if (generated) { await saveGenerated(after, E.why.trim()); return; }
|
|
876
|
-
if (!E.why.trim()) { E.whyBad = true; E.text = after; if (E.kind === 'rich') { E.base = splitDoc(after); E.node = null; } else if (E.ta) E.ta.value = after; drawEdit(); const w = ui.body.querySelector('#dwhy'); if (w) w.focus(); return; }
|
|
877
|
-
const before = S.text; S.busy = true;
|
|
878
|
-
const r = await pmPost('/api/doc-sheet/edit', { ...base, text: after, why: E.why.trim() }).catch(() => null);
|
|
879
|
-
S.busy = false;
|
|
880
|
-
if (!r || !r.ok) { S.err = (r && r.error) || 'The document was not saved.'; E.text = after; if (E.kind === 'rich') { E.base = splitDoc(after); E.node = null; } drawEdit(); return; }
|
|
881
|
-
const v = nextV(doc.v); if (v) doc.v = v; if (doc.st === 'stale') doc.st = 'current';
|
|
882
|
-
S.err = ''; S.ed = null; S.changed = true; S.mode = 'read';
|
|
883
|
-
await reloadAll();
|
|
884
|
-
say('Saved' + (v ? ' as ' + v : '') + '. ' + plural(ch.length, 'section') + ' changed; the reason is in the edit log.', async () => {
|
|
885
|
-
const u = await pmPost('/api/doc-sheet/edit', { ...base, text: before, why: 'Undone: restored the text from before the last edit.' }).catch(() => null);
|
|
886
|
-
if (u && u.ok) { await reloadAll(); } else say((u && u.error) || 'The edit could not be undone.');
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
async function saveGenerated(after, why) {
|
|
891
|
-
const E = S.ed; S.busy = true;
|
|
892
|
-
const r = await Promise.resolve(generated.save(after, why)).catch((e) => ({ ok: false, error: e && e.message }));
|
|
893
|
-
S.busy = false;
|
|
894
|
-
if (!r || !r.ok) { S.err = (r && r.error) || 'The draft was not saved.'; E.text = after; if (E.kind === 'rich') { E.base = splitDoc(after); E.node = null; } drawEdit(); return; }
|
|
895
|
-
S.text = after; generated.text = after; S.err = ''; S.ed = null; S.changed = true; go('read');
|
|
896
|
-
say(generated.saved || 'Saved as the draft.');
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
/* ── Proposals ── */
|
|
900
|
-
function askBox() {
|
|
901
|
-
if (frozen()) return el('div', { class: 'fold w', role: 'status', 'data-doc-frozen': '' }, c3ic('lock', 'sm'), 'Issued reports are frozen. Start the next cycle to ask for a change.');
|
|
902
|
-
const A = S.asking;
|
|
903
|
-
const ta = el('textarea', { id: 'dpr', placeholder: 'Tell the agent what to change, for example: add a one-paragraph summary at the top', 'aria-label': 'Request to the agent', 'data-doc-prompt': '', onInput: (e) => { S.prompt = e.target.value; } }, S.prompt);
|
|
904
|
-
const sug = [...new Set(failing().map((c) => c.fix).filter(Boolean))];
|
|
905
|
-
const copy = async () => { const t = 'Change ' + doc.path + ': ' + (S.prompt || '').trim(); try { await navigator.clipboard.writeText(t); say('The request is copied. Give it to your agent session.'); } catch { say('Copying is blocked here. Select the request and copy it.'); } };
|
|
906
|
-
const working = A && A.state === 'working';
|
|
907
|
-
return el('div', { class: 'ds-ask' }, el('label', { class: 'ds-h', for: 'dpr' }, c3ic('spark', 'sm'), 'Ask the agent'), ta,
|
|
908
|
-
el('div', { class: 'ds-acts' },
|
|
909
|
-
btn('ds-btn ag', { 'data-doc-ask': '', disabled: working, 'aria-disabled': working ? 'true' : null }, [c3ic(working ? 'clock' : 'spark', 'sm'), working ? 'The agent is drafting' : 'Ask the agent'], () => (demo ? askDemo() : askReal())),
|
|
910
|
-
demo ? null : btn('ds-btn', { 'data-doc-copy': '' }, [c3ic('copy', 'sm'), 'Copy the request'], copy),
|
|
911
|
-
sug.map((t, i) => btn('chip2 lk', { 'data-doc-chip': String(i) }, [c3ic('spark', 'sm'), t], () => { S.prompt = t; draw(); }))),
|
|
912
|
-
working ? el('div', { class: 'fold', role: 'status', 'data-doc-asking': '' }, c3ic('clock', 'sm'), 'The agent is reading the document and drafting the change. It runs in the background and can only read; you can close this sheet and come back. Its run is listed in Sessions.')
|
|
913
|
-
: A && A.state === 'failed' ? el('div', { class: 'fold w', role: 'alert', 'data-doc-ask-err': '' }, c3ic('alert', 'sm'), A.error || 'The agent did not answer.')
|
|
914
|
-
: el('p', { class: 'ds-note', 'data-doc-ask-why': '' }, 'The agent drafts a proposal and can only read. Nothing in the document changes until you accept it, and your request is kept in the edit log.'));
|
|
915
|
-
}
|
|
916
|
-
async function askDemo() {
|
|
917
|
-
const pr = (S.prompt || '').trim(); if (!pr) { say('Tell the agent what to change'); return; }
|
|
918
|
-
const before = S.text || ''; const after = before.replace(/\s*$/, '\n\n') + '## Agent note\n\nDrafted from your request: ' + pr.slice(0, 160) + '\n';
|
|
919
|
-
const r = await pmPost('/api/doc-sheet/propose', { ...base, prompt: pr, after }).catch(() => null);
|
|
920
|
-
if (!r || !r.ok) { say((r && r.error) || 'The agent did not answer.'); return; }
|
|
921
|
-
S.prompt = ''; S.openProp = r.id; await loadProps(); draw();
|
|
922
|
-
}
|
|
923
|
-
/* real mode: start the run from the page (page-starts-agent), then read its state until the proposal is there */
|
|
924
|
-
async function askReal() {
|
|
925
|
-
const pr = (S.prompt || '').trim(); if (!pr) { say('Tell the agent what to change'); const t = ui.body.querySelector('#dpr'); if (t) t.focus(); return; }
|
|
926
|
-
S.asking = { state: 'working' }; draw();
|
|
927
|
-
const r = await pmPost('/api/doc-sheet/ask', { ...base, prompt: pr }).catch(() => null);
|
|
928
|
-
if (!r || !r.ok) { S.asking = { state: 'failed', error: (r && r.error) || 'The agent could not start.' }; draw(); return; }
|
|
929
|
-
S.asking = { id: r.id, state: 'working' }; S.prompt = ''; S.log = null; draw();
|
|
930
|
-
pollAsk(r.id);
|
|
931
|
-
}
|
|
932
|
-
async function pollAsk(id) {
|
|
933
|
-
while (!S.closed && S.asking && S.asking.id === id) {
|
|
934
|
-
await new Promise((ok) => setTimeout(ok, 3000));
|
|
935
|
-
if (S.closed || !S.asking || S.asking.id !== id) return;
|
|
936
|
-
const r = await pmGet('/api/doc-sheet/ask?' + q({ id, ws })).catch(() => null);
|
|
937
|
-
if (!r || !r.ok || r.state === 'working') continue;
|
|
938
|
-
if (r.state === 'proposed' && r.proposal) { S.asking = null; S.openProp = r.proposal.id; await loadProps(); }
|
|
939
|
-
else S.asking = { id, state: 'failed', error: r.error };
|
|
940
|
-
S.log = null; drawBg();
|
|
941
|
-
say(r.state === 'proposed' ? 'The agent’s draft is ready in Proposals. Read it, then slide to accept.' : 'The agent did not draft the change.');
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
function propCard(p) {
|
|
946
|
-
const pick = S.pick[p.id] || (S.pick[p.id] = {});
|
|
947
|
-
p.sections.forEach((c) => { if (pick[c.name] == null || c.stale) pick[c.name] = !c.stale; });
|
|
948
|
-
const n = p.sections.filter((c) => pick[c.name]).length;
|
|
949
|
-
const anyStale = p.sections.some((c) => c.stale);
|
|
950
|
-
const hd = el('div', { class: 'hd' }, el('span', { class: 'ds-av ' + (p.by === 'pm' ? 'h' : 'a') }, p.by === 'pm' ? 'Y' : c3ic('spark', 'sm')),
|
|
951
|
-
el('span', null, el('div', { class: 'ti' }, short(p.prompt) || 'A proposal'), el('div', { class: 'sub' }, el('span', null, p.by === 'pm' ? 'Drafted by you' : 'Drafted by the agent'), el('span', null, whenOf(p.at)), p.hash ? el('span', null, 'hash ' + String(p.hash).slice(0, 8)) : null)),
|
|
952
|
-
el('span', { class: 'tag ds-ag' }, plural(p.sections.length, 'section')));
|
|
953
|
-
const why = el('p', { class: 'ds-why' }, c3ic('user', 'sm'), el('span', null, 'You asked: ', el('q', null, p.prompt)));
|
|
954
|
-
const chs = p.sections.map((c) => {
|
|
955
|
-
const [a, d] = wordCounts(c.stale ? c.current || '' : c.before, c.after);
|
|
956
|
-
const box = el('input', { type: 'checkbox', checked: !!pick[c.name], disabled: c.stale, 'data-doc-pick': p.id + ':' + c.name, onChange: (e) => { pick[c.name] = e.target.checked; draw(); } });
|
|
957
|
-
return el('div', { class: 'ds-chg' + (pick[c.name] ? '' : ' off'), 'data-doc-chg': c.name },
|
|
958
|
-
el('header', null, el('label', null, box, (c.kind === 'added' ? 'New section: ' : c.kind === 'removed' ? 'Removes: ' : '') + c.name),
|
|
959
|
-
c.stale ? el('span', { class: 'ds-warn', 'data-doc-chgstale': '' }, c3ic('alert', 'sm'), ' Changed since this draft. Ask again to re-draft it.') : el('span', { class: 'dim' }, '+' + a + ' −' + d + ' words')),
|
|
960
|
-
md(c.kind === 'added' ? diffMd(null, c.after) : diffMd(c.stale ? c.current || '' : c.before, c.after)));
|
|
961
|
-
});
|
|
962
|
-
const host = el('div', { class: 'ds-slide', 'data-doc-slide': p.id });
|
|
963
|
-
if (n && !frozen()) mountSlide(host, { label: 'Slide to accept ' + n + ' of ' + p.sections.length, hash: p.hash, onConfirm: (h) => acceptProp(p, h) });
|
|
964
|
-
else host.append(el('div', { class: 'slt-why', role: 'note' }, c3ic('lock', 'sm'), frozen() ? 'Issued reports are frozen. Start the next cycle to accept a change.' : anyStale && p.sections.every((c) => c.stale) ? 'Every section changed since this draft. Ask the agent again.' : 'Tick at least one section to accept.'));
|
|
965
|
-
const rej = S.rejFor === p.id
|
|
966
|
-
? el('div', { class: 'ds-whyadd' }, el('input', { type: 'text', id: 'drejwhy', 'data-doc-rejwhy': '', placeholder: 'Why are you rejecting it? Kept in the edit log.', 'aria-label': 'Why reject', value: S.rejWhy, onInput: (e) => { S.rejWhy = e.target.value; } }),
|
|
967
|
-
btn('ds-btn pri', { 'data-doc-rejok': p.id }, 'Reject', () => rejectProp(p)), btn('ds-btn', {}, 'Cancel', () => { S.rejFor = null; draw(); }))
|
|
968
|
-
: el('div', { class: 'ds-acts' }, btn('ds-btn', { 'data-doc-showin': p.id }, [c3ic('eye', 'sm'), 'Show it in the document'], () => { S.preview[p.id] = true; go('read'); const c = p.sections[0]; if (c) goEl(c.kind === 'added' ? '[data-dsec-new="' + c.name + '"]' : '[data-dsec="' + c.name + '"]'); }),
|
|
969
|
-
demo ? null : btn('ds-btn', { 'data-doc-refine': p.id }, [c3ic('reply', 'sm'), 'Change the request'], () => { S.prompt = p.prompt + ', and '; draw(); const t = ui.body.querySelector('#dpr'); if (t) { t.focus(); t.setSelectionRange(t.value.length, t.value.length); } }),
|
|
970
|
-
btn('ds-btn', { 'data-doc-rej': p.id }, [c3ic('x', 'sm'), 'Reject'], () => { S.rejFor = p.id; S.rejWhy = ''; draw(); const i = ui.body.querySelector('#drejwhy'); if (i) i.focus(); }));
|
|
971
|
-
return el('div', { class: 'ds-prop', id: 'dprop-' + p.id, 'data-doc-prop-card': p.id }, hd, el('div', { class: 'pb' }, why, chs, host,
|
|
972
|
-
el('p', { class: 'ds-note' }, 'Logged as text by the agent, accepted by you. Health checks the document again after.'), rej));
|
|
973
|
-
}
|
|
974
|
-
async function acceptProp(p, hash) {
|
|
975
|
-
const names = p.sections.filter((c) => (S.pick[p.id] || {})[c.name] && !c.stale).map((c) => c.name);
|
|
976
|
-
const r = await pmPost('/api/doc-sheet/accept', { ...base, id: p.id, hash, sections: names }).catch(() => null);
|
|
977
|
-
if (!r || !r.ok) { say('Not accepted: ' + ((r && (r.error || r.reason)) || 'the proposal changed.')); await loadProps(); draw(); return; }
|
|
978
|
-
const v = nextV(doc.v); if (v) doc.v = v; if (doc.st === 'stale') doc.st = 'current';
|
|
979
|
-
S.changed = true; S.preview[p.id] = false; delete S.pick[p.id];
|
|
980
|
-
await reloadAll();
|
|
981
|
-
say('Accepted ' + plural(names.length, 'section') + (v ? ' as ' + v : '') + '. The edit log names the agent and you.');
|
|
982
|
-
}
|
|
983
|
-
async function rejectProp(p) {
|
|
984
|
-
const w = String(S.rejWhy || '').trim();
|
|
985
|
-
if (!w) { say('Say why you are rejecting it'); const i = ui.body.querySelector('#drejwhy'); if (i) i.focus(); return; }
|
|
986
|
-
const r = await pmPost('/api/doc-sheet/reject', { ...base, id: p.id, why: w }).catch(() => null);
|
|
987
|
-
if (!r || !r.ok) { say((r && r.error) || 'It was not rejected.'); return; }
|
|
988
|
-
S.rejFor = null; S.rejWhy = ''; S.log = null; await loadProps(); draw(); say('Rejected. The reason is in the edit log.');
|
|
989
|
-
}
|
|
990
|
-
function propsBody() {
|
|
991
|
-
if (generated && generated.ask) return askGenerated();
|
|
992
|
-
if (generated) return el('div', { class: 'fold w', role: 'note', 'data-doc-nostore': 'ask' }, c3ic('lock', 'sm'), generated.why);
|
|
993
|
-
const op = openProps(); const closed = (S.props || []).filter((p) => p.state !== 'proposed');
|
|
994
|
-
const list = S.props === null ? el('div', { class: 'fold', role: 'status' }, c3ic('clock', 'sm'), 'Reading the proposals.')
|
|
995
|
-
: S.propsErr ? el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), S.propsErr)
|
|
996
|
-
: op.length ? op.map(propCard) : el('div', { class: 'fold', 'data-doc-noprops': '' }, c3ic('check', 'sm'), 'No open proposals.');
|
|
997
|
-
return el('div', { class: 'ds', 'data-doc-proposals': '' }, staleBanner(), askBox(), el('h3', { class: 'ds-h' }, 'Open proposals · ' + op.length), list,
|
|
998
|
-
closed.length ? [el('h3', { class: 'ds-h' }, 'Closed'), el('ul', { class: 'ds-closed hx' }, closed.map((p) => el('li', { 'data-doc-closed': p.id },
|
|
999
|
-
el('span', { class: 'chip2 ' + (p.state === 'accepted' ? 'ds-good' : 'dim') }, c3ic(p.state === 'accepted' ? 'check' : 'x', 'sm'), p.state === 'accepted' ? 'Accepted' : 'Rejected'),
|
|
1000
|
-
el('span', null, el('b', null, short(p.prompt)), el('small', null, p.state === 'accepted' ? (p.taken && p.of && p.taken.length < p.of ? p.taken.length + ' of ' + p.of + ' sections: ' : 'Sections: ') + (p.taken || []).join(', ') : 'Why: ' + (p.why || 'no reason'))),
|
|
1001
|
-
el('span', { class: 'w' }, dayName(p.closed_at || p.at)))))] : null);
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
/* ── Edit log ── */
|
|
1005
|
-
/* notes on the slide and the cycle's design decisions (report-design-studio): the server appends them to the document's log */
|
|
1006
|
-
const DESIGN_T = { keep: 'Kept a difference from the design for this cycle', adopt: 'Made a difference part of the design', match: 'Matched the design' };
|
|
1007
|
-
function pinTitle(e) {
|
|
1008
|
-
const on = e.slide ? ' (' + e.slide + ')' : '';
|
|
1009
|
-
if (e.op === 'add') return (e.by === 'agent' ? 'PMOS proposed a note on the slide' : 'Note pinned on the slide') + on;
|
|
1010
|
-
return ({ edit: 'Changed a note on the slide', remove: 'Removed a note on the slide', keep: 'Kept the note PMOS proposed', dismiss: 'Dismissed the note PMOS proposed' }[e.op] || 'Note on the slide') + on;
|
|
1011
|
-
}
|
|
1012
|
-
function logEntries() {
|
|
1013
|
-
const L = S.log || { revisions: [], events: [] };
|
|
1014
|
-
const out = [];
|
|
1015
|
-
for (const r of L.revisions) {
|
|
1016
|
-
const ag = isAgentRev(r); const outside = r.via === 'outside' || r.via === 'first' || (r.by === 'baseline' && !r.via);
|
|
1017
|
-
const title = r.via === 'proposal' ? 'Proposal accepted' : r.via === 'outside' || (r.by === 'baseline' && !r.via) ? 'Changed outside the sheet' : r.via === 'first' ? 'First seen by the sheet' : 'Edited in this sheet';
|
|
1018
|
-
out.push({ kind: 'rev', at: r.at, r, ag, outside, people: !ag, title: (r.v ? r.v + ' · ' : 'Revision ' + r.rev + ' · ') + title });
|
|
1019
|
-
}
|
|
1020
|
-
for (const e of L.events) {
|
|
1021
|
-
const t = e.kind === 'pin' ? pinTitle(e) : e.kind === 'design' ? DESIGN_T[e.choice] || 'A decision on the design'
|
|
1022
|
-
: { proposed: 'The agent drafted a proposal', revised: 'The agent revised a proposal', rejected: 'Proposal rejected', asked: 'You asked the agent', 'ask-failed': 'The agent did not draft the change', marked: 'Marked as still current' }[e.kind] || e.kind;
|
|
1023
|
-
out.push({ kind: e.kind, at: e.at, e, ag: e.by === 'agent' || e.kind === 'proposed' || e.kind === 'revised' || e.kind === 'ask-failed', outside: false, people: e.by === 'pm' || e.kind === 'rejected' || e.kind === 'asked' || e.kind === 'marked', title: t });
|
|
1024
|
-
}
|
|
1025
|
-
return out.sort((a, b) => String(b.at).localeCompare(String(a.at)));
|
|
1026
|
-
}
|
|
1027
|
-
function logRow(x) {
|
|
1028
|
-
const r = x.r; const e = x.e;
|
|
1029
|
-
const av = el('span', { class: 'ds-av ' + (x.kind === 'ask-failed' ? 'w' : x.ag ? 'a' : 'h') }, x.ag ? c3ic(x.kind === 'ask-failed' ? 'alert' : 'spark', 'sm') : (r ? (whoOf(r)[0] || '?') : 'Y').toUpperCase());
|
|
1030
|
-
const who = [];
|
|
1031
|
-
if (r) {
|
|
1032
|
-
if (r.via === 'proposal') who.push(el('span', { class: 'ds-ag' }, c3ic('spark', 'sm'), ' Text by the agent'), el('span', { class: 'ds-pe' }, c3ic('user', 'sm'), ' Accepted by you'), el('span', null, 'Proposal ' + String(r.proposal || '').replace(/^prop-/, '') + (r.sections && r.of ? ', ' + r.sections.length + ' of ' + r.of + ' sections' : '')));
|
|
1033
|
-
else if (x.outside) who.push(el('span', { class: x.ag ? 'ds-ag' : 'ds-pe' }, c3ic(x.ag ? 'spark' : 'user', 'sm'), ' ' + (r.git && r.git.author ? r.git.author : 'Unknown author')), el('span', { class: 'ds-warn' }, c3ic('git', 'sm'), ' ' + (r.git && r.git.commit ? 'commit ' + r.git.commit : 'not committed') + (r.via === 'first' ? ', before the edit log' : ', outside PMOS')));
|
|
1034
|
-
else who.push(el('span', { class: 'ds-pe' }, c3ic('user', 'sm'), ' ' + byName(r.by)), el('span', null, 'This sheet'));
|
|
1035
|
-
} else if (x.ag) who.push(el('span', { class: 'ds-ag' }, c3ic('spark', 'sm'), ' The agent' + (e.session ? ' · session ' + e.session : '')));
|
|
1036
|
-
else who.push(el('span', { class: 'ds-pe' }, c3ic('user', 'sm'), ' You'));
|
|
1037
|
-
let why = null;
|
|
1038
|
-
if (r) {
|
|
1039
|
-
const noReason = x.outside && !r.why_known && !r.why_added;
|
|
1040
|
-
if (r.why_added) why = el('p', { class: 'why' }, r.why_added, el('span', { class: 'dim' }, ' (reason added ' + dayName(r.why_added_at) + ')'));
|
|
1041
|
-
else if (noReason && S.whyFor === r.rev) why = el('div', { class: 'ds-whyadd' }, el('input', { type: 'text', id: 'daddwhy', 'data-doc-addwhy': '', placeholder: 'Why did this change?', 'aria-label': 'Reason', value: S.whyText, onInput: (ev) => { S.whyText = ev.target.value; } }),
|
|
1042
|
-
btn('ds-btn pri', { 'data-doc-whyok': String(r.rev) }, 'Add the reason', () => addWhy(r)), btn('ds-btn', {}, 'Cancel', () => { S.whyFor = null; draw(); }));
|
|
1043
|
-
else if (noReason) why = el('p', { class: 'why none' }, c3ic('alert', 'sm'), ' No reason recorded: this change was made outside PMOS. ', btn('chip2 lk ds-pe', { 'data-doc-whyadd': String(r.rev) }, 'Add a reason', () => { S.whyFor = r.rev; S.whyText = ''; draw(); const i = ui.body.querySelector('#daddwhy'); if (i) i.focus(); }));
|
|
1044
|
-
else if (r.why) why = el('p', { class: 'why' }, r.why);
|
|
1045
|
-
} else {
|
|
1046
|
-
const t = e.kind === 'pin' ? (e.text ? '“' + e.text + '” Note on the slide: the words on the slide did not change.' : 'Note on the slide.') : e.kind === 'design' ? (e.what || e.diff || '') : e.kind === 'asked' ? '“' + e.prompt + '”' : e.kind === 'proposed' || e.kind === 'revised' ? 'For: “' + (e.prompt || '') + '”' : e.why || '';
|
|
1047
|
-
if (t) why = el('p', { class: 'why' }, t);
|
|
1048
|
-
}
|
|
1049
|
-
const tags = [];
|
|
1050
|
-
if (r) {
|
|
1051
|
-
const prev = S.texts[r.rev - 1]; const cur = S.texts[r.rev];
|
|
1052
|
-
const secs = r.sections || (prev != null && cur != null ? changedSections(prev, cur).map((c) => c.name) : null);
|
|
1053
|
-
if (secs) secs.forEach((s) => tags.push(el('span', { class: 'tag' }, s)));
|
|
1054
|
-
if (prev != null && cur != null) { const [a, d] = wordCounts(prev, cur); tags.push(el('span', { class: 'tag add' }, '+' + a), el('span', { class: 'tag del' }, '−' + d)); }
|
|
1055
|
-
}
|
|
1056
|
-
const acts = [];
|
|
1057
|
-
if (r && r.rev > 1) acts.push(btn('chip2 lk', { 'data-doc-cmp': String(r.rev) }, [c3ic('eye', 'sm'), S.cmp === r.rev ? 'Hide the change' : 'Show the change'], () => cmpWith(r.rev)));
|
|
1058
|
-
if (e && (e.kind === 'proposed' || e.kind === 'revised') && openProps().some((p) => p.id === e.id)) acts.push(btn('chip2 lk ds-ag', {}, [c3ic('spark', 'sm'), 'Review it'], () => { S.openProp = e.id; go('ask'); }));
|
|
1059
|
-
const cmp = r && S.cmp === r.rev ? el('div', { class: 'ds-cmp', 'data-doc-cmpbox': '' }, S.cmpNode || el('div', { class: 'fold' }, c3ic('clock', 'sm'), 'Comparing.')) : null;
|
|
1060
|
-
return el('li', { 'data-log-kind': x.kind, ...(r ? { 'data-log-rev': String(r.rev) } : {}) }, av, el('div', { class: 'ds-le' },
|
|
1061
|
-
el('div', { class: 'l1' }, el('b', null, x.title), el('span', { class: 'when' }, whenOf(x.at))), el('div', { class: 'who' }, who), why,
|
|
1062
|
-
tags.length ? el('div', { class: 'tags' }, tags) : null, acts.length ? el('div', { class: 'ds-acts' }, acts) : null, cmp));
|
|
1063
|
-
}
|
|
1064
|
-
async function cmpWith(rev) {
|
|
1065
|
-
if (S.cmp === rev) { S.cmp = null; draw(); return; }
|
|
1066
|
-
S.cmp = rev; S.cmpNode = null; draw();
|
|
1067
|
-
const [a, b] = await Promise.all([textAt(rev - 1), textAt(rev)]);
|
|
1068
|
-
if (S.cmp !== rev) return;
|
|
1069
|
-
const D = a == null || b == null ? null : changedSections(a, b);
|
|
1070
|
-
S.cmpNode = !D ? el('div', { class: 'fold w' }, c3ic('alert', 'sm'), 'That revision could not be read.')
|
|
1071
|
-
: D.length ? D.map((d) => [el('h4', null, d.name), md(diffMd(d.kind === 'added' ? null : d.before, d.after))]) : el('div', { class: 'dim' }, 'No change in the text.');
|
|
1072
|
-
draw();
|
|
1073
|
-
}
|
|
1074
|
-
async function addWhy(r) {
|
|
1075
|
-
const w = String(S.whyText || '').trim(); if (!w) { const i = ui.body.querySelector('#daddwhy'); if (i) i.focus(); return; }
|
|
1076
|
-
const j = await pmPost('/api/doc-sheet/why', { ...base, rev: r.rev, why: w }).catch(() => null);
|
|
1077
|
-
if (!j || !j.ok) { say((j && j.error) || 'The reason was not added.'); return; }
|
|
1078
|
-
S.whyFor = null; await loadLog(); draw(); say('Reason added. The revision itself is unchanged.');
|
|
1079
|
-
}
|
|
1080
|
-
/* a draft on a Work item: the note sends it back to the agent, which drafts it again on the item */
|
|
1081
|
-
function askGenerated() {
|
|
1082
|
-
const ta = el('textarea', { id: 'dpr', placeholder: 'Tell the agent what to change', 'aria-label': 'Note to the agent', 'data-doc-prompt': '', onInput: (e) => { S.prompt = e.target.value; } }, S.prompt);
|
|
1083
|
-
const send = async () => {
|
|
1084
|
-
const v = String(S.prompt || '').trim(); if (!v) { say('Tell the agent what to change'); ta.focus(); return; }
|
|
1085
|
-
S.busy = true; draw();
|
|
1086
|
-
const r = await Promise.resolve(generated.ask(v)).catch((e) => ({ ok: false, error: e && e.message }));
|
|
1087
|
-
S.busy = false;
|
|
1088
|
-
if (!r || !r.ok) { S.err = (r && r.error) || 'The draft was not sent back.'; draw(); return; }
|
|
1089
|
-
S.prompt = ''; S.err = ''; ui.close();
|
|
1090
|
-
};
|
|
1091
|
-
ta.addEventListener('keydown', (e) => { if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { e.preventDefault(); send(); } });
|
|
1092
|
-
return el('div', { class: 'ds', 'data-doc-proposals': '' }, el('div', { class: 'ds-ask' }, el('label', { class: 'ds-h', for: 'dpr' }, c3ic('reply', 'sm'), 'Write to the agent'), ta,
|
|
1093
|
-
el('div', { class: 'ds-acts' }, btn('ds-btn ag', { 'data-doc-ask': '', disabled: S.busy, 'aria-disabled': S.busy ? 'true' : null }, [c3ic('reply', 'sm'), 'Send to the agent'], send)),
|
|
1094
|
-
S.err ? el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), S.err) : null,
|
|
1095
|
-
el('p', { class: 'ds-note', 'data-doc-ask-why': '' }, generated.askWhy || 'The agent drafts it again with your note. Nothing is sent anywhere.')));
|
|
1096
|
-
}
|
|
1097
|
-
function logBody() {
|
|
1098
|
-
if (generated && Array.isArray(generated.log)) {
|
|
1099
|
-
return el('div', { class: 'ds', 'data-doc-log': '' }, el('h3', { class: 'ds-h' }, 'Conversation with the agent · ' + generated.log.length),
|
|
1100
|
-
el('ul', { class: 'ds-closed hx', 'data-doc-genlog': '' }, generated.log.map((t, i) => el('li', { 'data-doc-genturn': String(i) },
|
|
1101
|
-
el('span', { class: 'chip2' + (t.who === 'agent' ? ' ds-ag' : '') }, c3ic(t.who === 'agent' ? 'spark' : 'user', 'sm'), t.who === 'agent' ? 'Agent' : 'You'),
|
|
1102
|
-
el('span', null, el('b', null, t.what), t.text ? el('small', null, short(t.text)) : null),
|
|
1103
|
-
el('span', { class: 'w' }, t.at ? whenOf(t.at) : '')))));
|
|
1104
|
-
}
|
|
1105
|
-
if (generated) return el('div', { class: 'fold', 'data-doc-nostore': 'hist' }, c3ic('info', 'sm'), generated.why);
|
|
1106
|
-
if (!S.log) return el('div', { class: 'fold', role: 'status' }, c3ic('clock', 'sm'), 'Reading the edit log.');
|
|
1107
|
-
const F = [['all', 'All'], ['people', 'People'], ['agent', 'Agent'], ['outside', 'Outside PMOS']];
|
|
1108
|
-
const all = logEntries();
|
|
1109
|
-
const rows = all.filter((x) => S.logF === 'all' || (S.logF === 'people' && x.people) || (S.logF === 'agent' && x.ag) || (S.logF === 'outside' && x.outside));
|
|
1110
|
-
return el('div', { class: 'ds', 'data-doc-log': '' }, el('div', { class: 'ds-rbar' }, el('div', { class: 'seg', role: 'group', 'aria-label': 'Filter' }, F.map(([k, l]) => btn('', { 'aria-pressed': String(S.logF === k), 'data-doc-logf': k }, l, () => { S.logF = k; draw(); }))),
|
|
1111
|
-
el('span', { class: 'ds-mono' }, plural(all.length, 'entry').replace('entrys', 'entries') + ' · append-only')),
|
|
1112
|
-
S.logErr ? el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), S.logErr) : null,
|
|
1113
|
-
rows.length ? el('ul', { class: 'ds-log' }, rows.map(logRow)) : el('div', { class: 'fold' }, c3ic('info', 'sm'), all.length ? 'Nothing in this filter.' : 'Nothing is recorded yet. The first save through this sheet starts the log.'));
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
/* ── Health ── */
|
|
1117
|
-
function healthBody() {
|
|
1118
|
-
const h = S.health;
|
|
1119
|
-
if (!h) return el('div', { class: 'fold', role: 'status' }, c3ic('clock', 'sm'), 'Checking this document.');
|
|
1120
|
-
if (h.err) return el('div', { class: 'fold w', role: 'alert' }, c3ic('alert', 'sm'), 'The checks could not run: ' + h.err + '. Nothing is shown.');
|
|
1121
|
-
const unanswered = h.checks.filter((c) => c.pass === null).length;
|
|
1122
|
-
return el('div', { class: 'ds' }, el('div', { class: 'chips2', 'data-doc-health': '' }, el('span', { class: 'ki ' + hcls(h) }, c3ic('shield')), el('b', null, h.passed + ' of ' + h.total + ' checks pass')),
|
|
1123
|
-
unanswered ? el('p', { class: 'ds-note' }, plural(unanswered, 'check') + ' not counted: not enough input.') : null,
|
|
1124
|
-
el('ul', { class: 'chgl' }, h.checks.map((c) => el('li', { class: c.pass === null ? '' : c.pass ? 'ok' : 'bad', 'data-check': c.id }, c3ic(c.pass === null ? 'info' : c.pass ? 'check' : 'alert', 'sm'),
|
|
1125
|
-
el('span', null, (c.name || NAMES[c.id] || c.id) + ': ' + c.reason + ' ',
|
|
1126
|
-
c.id === 'fresh' && c.pass === false && Array.isArray(c.sources) && c.sources.length ? el('small', { class: 'ds-mono' }, ' ' + c.sources.map((s) => s.path).join(', ') + ' ') : null,
|
|
1127
|
-
c.id === 'fresh' && c.pass === false && !generated ? btn('chip2 lk', { 'data-doc-hmark': '' }, 'Mark as still current', () => { S.staleWhy = ''; go('read'); const i = ui.body.querySelector('#dstalewhy'); if (i) i.focus(); }) : null,
|
|
1128
|
-
c.pass === false && !generated ? btn('chip2 lk ds-ag', { 'data-doc-fix': c.id }, [c3ic('spark', 'sm'), 'Fix with the agent'], () => { S.prompt = c.fix || 'Fix: ' + (NAMES[c.id] || c.id) + ' (' + c.reason + ')'; go('ask'); }) : null),
|
|
1129
|
-
el('span', { class: 'tag' }, c.pass === null ? 'no input' : c.pass ? 'pass' : 'fail')))),
|
|
1130
|
-
el('p', { class: 'ds-note' }, 'Health answers one question: can I trust this document without rereading it? The checks run again every time the text changes.'));
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
/* ── a report cycle: Issue, the menu (Download, Start the next cycle) ── */
|
|
1134
|
-
const toolsNode = R ? el('span', { class: 'rs-tools' }) : null;
|
|
1135
|
-
const slugOf = (t) => String(t || 'report').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
1136
|
-
function menuRow() {
|
|
1137
|
-
const items = downloadsOf(R.output);
|
|
1138
|
-
return el('div', { class: 'chips2 rs-menu', role: 'menu', 'aria-label': 'Document actions', 'data-doc-menu': '' }, el('span', { class: 'dim mono ds-mono' }, 'DOWNLOAD'),
|
|
1139
|
-
items.map((it) => pb('outline', { 'data-doc-download': it.fmt, role: 'menuitem' }, [c3ic('drop', 'sm'), it.label], () => download(it))),
|
|
1140
|
-
frozen() ? pb('ghost', { 'data-doc-next': '', role: 'menuitem' }, [c3ic('plus', 'sm'), 'Start the next cycle'], () => nextCycle()) : null);
|
|
1141
|
-
}
|
|
1142
|
-
async function download(it) {
|
|
1143
|
-
S.menu = false; draw();
|
|
1144
|
-
const title = R.name || doc.name; const secs = S.text != null ? splitDoc(S.text) : [];
|
|
1145
|
-
if (it.fmt === 'pdf') {
|
|
1146
|
-
if (!printPdf({ output: R.output, name: title, cycle: R.cycle, secs })) say('The browser blocked the print window. Allow pop-ups for this page, then press Download again.');
|
|
1147
|
-
else say('The print view is open. Choose Save as PDF. Nothing is uploaded.');
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
try {
|
|
1151
|
-
const r = await fetch('/api/report-export?' + q({ ws, path: doc.path, fmt: it.fmt }));
|
|
1152
|
-
if (!r.ok) { let m = ''; try { m = (await r.json()).error; } catch { /* not JSON */ } throw new Error(m || 'the workspace did not make the file'); }
|
|
1153
|
-
const blob = await r.blob();
|
|
1154
|
-
const cd = /filename="?([^";]+)"?/.exec(r.headers.get('content-disposition') || '');
|
|
1155
|
-
const name = cd ? cd[1] : slugOf(title + ' ' + (R.cycle || '')) + '.' + it.fmt;
|
|
1156
|
-
const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = name; document.body.appendChild(a); a.click(); a.remove();
|
|
1157
|
-
setTimeout(() => URL.revokeObjectURL(a.href), 4000);
|
|
1158
|
-
say('Downloaded ' + name + '. Nothing went to another tool.');
|
|
1159
|
-
} catch (e) { say('The file was not made: ' + ((e && e.message) || 'no answer') + '.'); }
|
|
1160
|
-
}
|
|
1161
|
-
async function issue() {
|
|
1162
|
-
/* Issue is the PM's act on the existing route (routes-reports.js, requirePmPress). It freezes the bytes the PM read:
|
|
1163
|
-
the sha comes from the file as served, and the page refuses when that text is not the text on screen. */
|
|
1164
|
-
const m = /reports\/([a-z][a-z0-9-]{0,39})\/(\d{4}-\d{2}-\d{2})\.md$/.exec(doc.path || '');
|
|
1165
|
-
if (!m) { say('This document is not a report cycle, so it cannot be issued.'); return; }
|
|
1166
|
-
const cur = await pmGet('/api/report/draft?' + q({ ws, cadence: m[1], slot: m[2] })).catch(() => null);
|
|
1167
|
-
if (!cur || !cur.ok || !cur.exists || !cur.sha) { say((cur && cur.error) || 'The report was not issued: the file could not be read.'); return; }
|
|
1168
|
-
if (S.text != null && cur.markdown != null && cur.markdown !== S.text) { await reloadAll(); say('The file changed since you opened it. Read it again, then press Issue.'); return; }
|
|
1169
|
-
const r = await pmPost('/api/report/issue', { ws, cadence: m[1], slot: m[2], sha: cur.sha }).catch(() => null);
|
|
1170
|
-
if (!r || !r.ok) { say((r && r.error) || 'The report was not issued.'); return; }
|
|
1171
|
-
R.state = 'issued'; doc.st = 'issued'; S.changed = true; S.menu = false; if (S.mode === 'edit') { S.ed = null; S.mode = 'read'; }
|
|
1172
|
-
if (R.onIssue) R.onIssue(doc);
|
|
1173
|
-
await reloadAll(); say('Issued and frozen. PMOS sends nothing; share it yourself.');
|
|
1174
|
-
}
|
|
1175
|
-
function nextCycle() { S.menu = false; if (R.onNext) R.onNext(doc, ui); else say('The next cycle starts on its schedule. PMOS drafts it then.'); }
|
|
1176
|
-
function drawTools() {
|
|
1177
|
-
if (!toolsNode) return;
|
|
1178
|
-
toolsNode.replaceChildren(...[...(R.tools ? R.tools() : []), R.state === 'draft' ? pb('outline', { 'data-doc-issue': '' }, [c3ic('check', 'sm'), 'Issue'], () => issue()) : null,
|
|
1179
|
-
btn('ib sm', { 'aria-label': 'Download and more', title: 'Download and more', 'aria-expanded': String(S.menu), 'data-doc-more': '' }, c3ic('more', 'sm'), () => { S.menu = !S.menu; draw(); })].filter(Boolean));
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
/* a load that finished in the background must not redraw under a hand that is typing */
|
|
1183
|
-
const drawBg = () => { const a = document.activeElement; if (ui && a && ui.body.contains(a) && a.closest('input,textarea,[contenteditable=true]')) { refreshTop(); return; } draw(); };
|
|
1184
|
-
const top = () => el('div', { class: 'ds-top' }, head(), seg(), R && S.menu ? menuRow() : null, S.mode === 'edit' && S.ed ? toolbar() : null,
|
|
1185
|
-
S.leave ? el('div', { class: 'fold w', role: 'alert', 'data-doc-leave': '' }, c3ic('alert', 'sm'), 'You have unsaved changes in ' + plural(dirty().length, 'section') + '. ',
|
|
1186
|
-
btn('ds-btn', {}, 'Keep editing', () => { S.leave = null; drawEdit(); }), btn('ds-btn', { 'data-doc-discard': '' }, 'Discard and leave', () => { const m = S.leave; S.ed = null; S.leave = null; go(m); })) : null);
|
|
1187
|
-
function refreshTop() { const t = ui && ui.body.querySelector('.ds-top'); if (t) t.replaceWith(top()); }
|
|
1188
|
-
function draw() {
|
|
1189
|
-
if (!ui) return;
|
|
1190
|
-
if (S.mode === 'edit' && S.ed && S.ed.kind === 'rich' && S.ed.node) keepRange();
|
|
1191
|
-
drawTools();
|
|
1192
|
-
const body = S.mode === 'read' ? readBody() : S.mode === 'edit' ? editBody() : S.mode === 'ask' ? propsBody() : S.mode === 'hist' ? logBody() : S.mode === 'health' ? healthBody() : linksBody();
|
|
1193
|
-
const keep = ui.body.querySelector('textarea:focus,input[type=text]:focus');
|
|
1194
|
-
const had = keep ? { id: keep.id, s: keep.selectionStart } : null;
|
|
1195
|
-
const above = docAbove.map((fn) => { try { return fn({ ws, doc, text: S.text, key: S }); } catch { return null; } });
|
|
1196
|
-
ui.body.replaceChildren(el('div', { class: 'dpn ds' }, top(), above, copiesPanel(), body));
|
|
1197
|
-
const sh = ui.body.closest('.sheet'); if (sh) sh.classList.toggle('dwx', S.mode === 'read' && ((S.ol && !!ui.body.querySelector('.ds-ol')) || !!ui.body.querySelector('[data-rd-deck]')));
|
|
1198
|
-
const sb = ui.body.closest('.sb');
|
|
1199
|
-
if (sb && !sb.__dsTrack) { sb.__dsTrack = true; sb.addEventListener('scroll', trackCur, { passive: true }); }
|
|
1200
|
-
if (S.mode === 'read') { placeOl(); trackCur(); }
|
|
1201
|
-
if (S.mode === 'links') { const g = ui.body.querySelector('.ds-graph'); if (g) requestAnimationFrame(() => drawEdges(g)); }
|
|
1202
|
-
if (had && had.id) { const n = ui.body.querySelector('#' + had.id); if (n) { n.focus(); try { n.setSelectionRange(had.s, had.s); } catch { /* not a text field */ } } }
|
|
1203
|
-
if (S.mode === 'ask' && S.openProp) { const id = S.openProp; S.openProp = null; goEl('[data-doc-prop-card="' + id + '"]'); }
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
document.addEventListener('selectionchange', keepRange);
|
|
1207
|
-
// the size control of the session and meeting sheets (Normal, Half, 3/4, Whole), remembered in this browser
|
|
1208
|
-
let size = docSizeOf(docSizeStore.get());
|
|
1209
|
-
const sizeBtns = DOC_SIZES.map(([k, label, tip]) => button({ label, variant: 'ghost', attrs: { 'aria-pressed': String(k === size), 'data-doc-size': k, title: tip, 'aria-label': tip },
|
|
1210
|
-
onClick: () => setSize(k) }));
|
|
1211
|
-
const sizeSeg = el('div', { class: 'seg ds-size', role: 'group', 'aria-label': 'Size', 'data-doc': 'size' }, ...sizeBtns);
|
|
1212
|
-
function setSize(k) {
|
|
1213
|
-
size = k; docSizeStore.set(k);
|
|
1214
|
-
DOC_SIZES.forEach(([x]) => ui.sheet.classList.toggle('tsz-' + x, x === k));
|
|
1215
|
-
sizeBtns.forEach((b) => b.setAttribute('aria-pressed', String(b.getAttribute('data-doc-size') === k)));
|
|
1216
|
-
}
|
|
1217
|
-
ui = openSheet({ title: doc.name, icon: 'doc', dw: true, cls: 'tsz-' + size, actions: [sizeSeg, toolsNode].filter(Boolean), body: el('div', { class: 'dpn' }), onClose: () => { S.closed = true; document.removeEventListener('selectionchange', keepRange); if (S.changed && onChanged) onChanged(); } });
|
|
1218
|
-
S.open = (d) => { ui.close(); if (S.openOther) S.openOther(d); else openDocSheet({ ws, doc: d, library, openGraph }); };
|
|
1219
|
-
ui.setOpener = (fn) => { S.openOther = fn; };
|
|
1220
|
-
draw();
|
|
1221
|
-
(async () => {
|
|
1222
|
-
await loadText();
|
|
1223
|
-
if (S.mode === 'edit') startEdit();
|
|
1224
|
-
drawBg();
|
|
1225
|
-
await Promise.all([loadRevs(), loadProps(), loadHealth(), loadCopies()]);
|
|
1226
|
-
if (S.mode === 'hist') await loadLog();
|
|
1227
|
-
drawBg(); loadMeta();
|
|
1228
|
-
})();
|
|
1229
|
-
return ui;
|
|
1230
|
-
}
|