kaizen-agent 1.86.0 → 1.87.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (541) hide show
  1. package/README.md +1 -1
  2. package/cli/annotate-proxy.ts +6 -3
  3. package/cli/build-web.ts +46 -16
  4. package/cli/dev.ts +67 -0
  5. package/cli/docs.ts +1 -1
  6. package/cli/notes.ts +9 -3
  7. package/cli/ports.ts +121 -0
  8. package/cli/settings.ts +16 -17
  9. package/cli/state.ts +15 -29
  10. package/cli/task-service.ts +79 -17
  11. package/cli/tasks.ts +2 -2
  12. package/cli/term-image.ts +18 -0
  13. package/cli/ui-audit.allow.json +0 -1
  14. package/cli/ui-audit.ts +12 -12
  15. package/cli/web.ts +188 -58
  16. package/package.json +21 -4
  17. package/skills/kaizen/spec.md +10 -3
  18. package/tsconfig.json +16 -0
  19. package/web/README.md +105 -0
  20. package/web/{annotate.js → annotate/annotate.ts} +51 -50
  21. package/web/boot/boot.ts +7 -0
  22. package/web/components/annotate/annotate-bar.tsx +78 -0
  23. package/web/components/annotate/annotate-panel.tsx +20 -0
  24. package/web/components/annotate/annotate-settings.tsx +60 -0
  25. package/web/components/annotate/index.ts +1 -0
  26. package/web/components/annotate/notes-list.tsx +75 -0
  27. package/web/components/board/board-card.tsx +177 -0
  28. package/web/components/board/board-column.tsx +212 -0
  29. package/web/components/board/board-mode-switch.tsx +21 -0
  30. package/web/components/board/board-popups.tsx +45 -0
  31. package/web/components/board/card-footer.tsx +58 -0
  32. package/web/components/board/card-form.tsx +168 -0
  33. package/web/components/board/card-kids.tsx +53 -0
  34. package/web/components/board/clear-menu.tsx +36 -0
  35. package/web/components/board/filter-box.tsx +42 -0
  36. package/web/components/board/index.ts +6 -0
  37. package/web/components/board/run-form.tsx +129 -0
  38. package/web/components/board/severity-menu.tsx +44 -0
  39. package/web/components/board/status-strip.tsx +75 -0
  40. package/web/components/board/task-form.tsx +140 -0
  41. package/web/components/board/ws-card.tsx +38 -0
  42. package/web/components/context/context-panel.tsx +244 -0
  43. package/web/components/context/index.ts +1 -0
  44. package/web/components/decision/decision-bar.tsx +422 -0
  45. package/web/components/decision/index.ts +1 -0
  46. package/web/components/decision/inline-form.tsx +47 -0
  47. package/web/components/decision/plan-answers-form.tsx +78 -0
  48. package/web/components/decision/revise-form.tsx +65 -0
  49. package/web/components/decision/task-reply-form.tsx +48 -0
  50. package/web/components/footer/foot-bar.tsx +67 -0
  51. package/web/components/footer/index.ts +1 -0
  52. package/web/components/git/git-ask.tsx +88 -0
  53. package/web/components/git/git-commits.tsx +53 -0
  54. package/web/components/git/git-confirm.tsx +78 -0
  55. package/web/components/git/git-counts.tsx +10 -0
  56. package/web/components/git/git-files.tsx +113 -0
  57. package/web/components/git/git-head.tsx +70 -0
  58. package/web/components/git/git-icon.tsx +25 -0
  59. package/web/components/git/git-message.tsx +44 -0
  60. package/web/components/git/git-split.tsx +64 -0
  61. package/web/components/git/git-tab.tsx +55 -0
  62. package/web/components/git/index.ts +1 -0
  63. package/web/components/home/chat-list.tsx +57 -0
  64. package/web/components/home/home-composer.tsx +169 -0
  65. package/web/components/home/home-message.tsx +120 -0
  66. package/web/components/home/home-window.tsx +253 -0
  67. package/web/components/home/home-ws-add.tsx +47 -0
  68. package/web/components/home/index.ts +6 -0
  69. package/web/components/home/onboarding-dialog.tsx +371 -0
  70. package/web/components/icebox/board-chip.tsx +27 -0
  71. package/web/components/icebox/board-menu.tsx +41 -0
  72. package/web/components/icebox/bulk-bar.tsx +41 -0
  73. package/web/components/icebox/capture-box.tsx +155 -0
  74. package/web/components/icebox/choice-menu.tsx +39 -0
  75. package/web/components/icebox/collection-dialog.tsx +60 -0
  76. package/web/components/icebox/favicon.tsx +39 -0
  77. package/web/components/icebox/index.ts +10 -0
  78. package/web/components/icebox/kind-label.tsx +22 -0
  79. package/web/components/icebox/kind-menu.tsx +20 -0
  80. package/web/components/icebox/promote-form.tsx +93 -0
  81. package/web/components/icebox/reply-box.tsx +88 -0
  82. package/web/components/icebox/request-actions.tsx +141 -0
  83. package/web/components/icebox/request-badges.tsx +13 -0
  84. package/web/components/icebox/request-card.tsx +99 -0
  85. package/web/components/icebox/request-detail.tsx +43 -0
  86. package/web/components/icebox/request-images.tsx +33 -0
  87. package/web/components/icebox/request-phone-row.tsx +181 -0
  88. package/web/components/icebox/request-row.tsx +120 -0
  89. package/web/components/icebox/service-chip.tsx +58 -0
  90. package/web/components/icebox/snooze-menu.tsx +83 -0
  91. package/web/components/icebox/source-card.tsx +225 -0
  92. package/web/components/icebox/source-drawer.tsx +112 -0
  93. package/web/components/icebox/source-form.tsx +147 -0
  94. package/web/components/icebox/swipe-deck.tsx +242 -0
  95. package/web/components/layout/index.ts +1 -0
  96. package/web/components/layout/page-frame.tsx +44 -0
  97. package/web/components/markdown/index.ts +1 -0
  98. package/web/components/markdown/markdown.tsx +156 -0
  99. package/web/components/notebook/editor-pane.tsx +23 -0
  100. package/web/components/notebook/index.ts +5 -0
  101. package/web/components/notebook/note-body.tsx +172 -0
  102. package/web/components/notebook/note-tree.tsx +99 -0
  103. package/web/components/notebook/notes-head.tsx +37 -0
  104. package/web/components/notebook/notes-side.tsx +46 -0
  105. package/web/components/notes/index.ts +1 -0
  106. package/web/components/notes/note-composer.tsx +90 -0
  107. package/web/components/notes/notes-chat.tsx +58 -0
  108. package/web/components/panes/browser-pane.tsx +281 -0
  109. package/web/components/panes/index.ts +3 -0
  110. package/web/components/panes/preview-pane.tsx +91 -0
  111. package/web/components/panes/terminal-pane.tsx +52 -0
  112. package/web/components/phone/haptic.tsx +29 -0
  113. package/web/components/phone/index.ts +6 -0
  114. package/web/components/phone/phone-card.tsx +118 -0
  115. package/web/components/phone/phone-home.tsx +304 -0
  116. package/web/components/phone/phone-sheets.tsx +103 -0
  117. package/web/components/phone/qr-code.tsx +6 -0
  118. package/web/components/phone/usage-chips.tsx +85 -0
  119. package/web/components/phone/whatsapp-card.tsx +85 -0
  120. package/web/components/project/add-project-dialog.tsx +435 -0
  121. package/web/components/project/index.ts +3 -0
  122. package/web/components/project/project-bar.tsx +101 -0
  123. package/web/components/project/ws-menu.tsx +21 -0
  124. package/web/components/rail/agent-chips.tsx +110 -0
  125. package/web/components/rail/index.ts +4 -0
  126. package/web/components/rail/rail-filter.tsx +118 -0
  127. package/web/components/rail/rail-list.tsx +259 -0
  128. package/web/components/rail/source-marks.tsx +21 -0
  129. package/web/components/resources/index.ts +1 -0
  130. package/web/components/resources/resources-popup.tsx +490 -0
  131. package/web/components/run/doc-body.tsx +123 -0
  132. package/web/components/run/file-viewer.tsx +53 -0
  133. package/web/components/run/fix-form.tsx +88 -0
  134. package/web/components/run/index.ts +16 -0
  135. package/web/components/run/inline-md.tsx +30 -0
  136. package/web/components/run/key-hint.tsx +29 -0
  137. package/web/components/run/pane-gutter.tsx +52 -0
  138. package/web/components/run/pane-header.tsx +35 -0
  139. package/web/components/run/pane.tsx +140 -0
  140. package/web/components/run/panel-grip.tsx +49 -0
  141. package/web/components/run/panel-head.tsx +56 -0
  142. package/web/components/run/panel-tabs.tsx +35 -0
  143. package/web/components/run/phase-steps.tsx +37 -0
  144. package/web/components/run/project-notes.tsx +49 -0
  145. package/web/components/run/run-add-menu.tsx +80 -0
  146. package/web/components/run/run-bar.tsx +40 -0
  147. package/web/components/run/run-empty.tsx +10 -0
  148. package/web/components/run/run-footer.tsx +53 -0
  149. package/web/components/run/run-history.tsx +24 -0
  150. package/web/components/run/run-panes.tsx +78 -0
  151. package/web/components/run/run-picker.tsx +51 -0
  152. package/web/components/run/run-progress.tsx +30 -0
  153. package/web/components/run/run-tabs.tsx +147 -0
  154. package/web/components/run/run-wait.tsx +18 -0
  155. package/web/components/search/index.ts +1 -0
  156. package/web/components/search/search-palette.tsx +159 -0
  157. package/web/components/settings/account-rows.tsx +128 -0
  158. package/web/components/settings/agent-rows.tsx +249 -0
  159. package/web/components/settings/automation-rows.tsx +211 -0
  160. package/web/components/settings/browser-row.tsx +111 -0
  161. package/web/components/settings/cleanup-row.tsx +32 -0
  162. package/web/components/settings/commit-input.tsx +39 -0
  163. package/web/components/settings/index.ts +4 -0
  164. package/web/components/settings/integration-row.tsx +158 -0
  165. package/web/components/settings/mic-row.tsx +48 -0
  166. package/web/components/settings/orchestration-flow.tsx +87 -0
  167. package/web/components/settings/setting-row.tsx +131 -0
  168. package/web/components/settings/settings-item.tsx +78 -0
  169. package/web/components/settings/settings-loading.tsx +41 -0
  170. package/web/components/settings/settings-nav.tsx +119 -0
  171. package/web/components/settings/settings-scope.tsx +66 -0
  172. package/web/components/settings/settings-section.tsx +33 -0
  173. package/web/components/settings/skill-card.tsx +131 -0
  174. package/web/components/settings/stepper.tsx +74 -0
  175. package/web/components/settings/update-bar.tsx +167 -0
  176. package/web/components/shared/action-menu.tsx +76 -0
  177. package/web/components/shared/ask-host.tsx +18 -0
  178. package/web/components/shared/attach-button.tsx +23 -0
  179. package/web/components/shared/chip.tsx +19 -0
  180. package/web/components/shared/client-mark.tsx +15 -0
  181. package/web/components/shared/confirm-dialog.tsx +35 -0
  182. package/web/components/shared/empty-state.tsx +29 -0
  183. package/web/components/shared/field.tsx +77 -0
  184. package/web/components/shared/filter-popover.tsx +29 -0
  185. package/web/components/shared/form-frame.tsx +19 -0
  186. package/web/components/shared/icon-button.tsx +50 -0
  187. package/web/components/shared/index.ts +18 -0
  188. package/web/components/shared/mic-button.tsx +75 -0
  189. package/web/components/shared/pager.tsx +49 -0
  190. package/web/components/shared/picker.tsx +108 -0
  191. package/web/components/shared/project-mark.tsx +38 -0
  192. package/web/components/shared/segmented.tsx +43 -0
  193. package/web/components/shared/state-dot.tsx +4 -0
  194. package/web/components/shared/status-mark.tsx +26 -0
  195. package/web/components/shell/index.ts +3 -0
  196. package/web/components/shell/rail.tsx +259 -0
  197. package/web/components/shell/sprite.tsx +124 -0
  198. package/web/components/shell/wordmark.tsx +13 -0
  199. package/web/components/task/artifact-view.tsx +148 -0
  200. package/web/components/task/chat-bubble.tsx +43 -0
  201. package/web/components/task/filter-menu.tsx +38 -0
  202. package/web/components/task/index.ts +7 -0
  203. package/web/components/task/result-checks.tsx +34 -0
  204. package/web/components/task/result-view.tsx +113 -0
  205. package/web/components/task/status-badge.tsx +24 -0
  206. package/web/components/task/task-row.tsx +34 -0
  207. package/web/components/task/typing-dots.tsx +16 -0
  208. package/web/components/terminal/index.ts +3 -0
  209. package/web/components/terminal/terminal-bar.tsx +91 -0
  210. package/web/components/terminal/terminal-grid.tsx +149 -0
  211. package/web/components/terminal/terminal-modes.tsx +23 -0
  212. package/web/components/terminal/terminal-tile.tsx +139 -0
  213. package/web/dist/annotate.js +24 -0
  214. package/web/dist/board.css +718 -0
  215. package/web/dist/board.js +115 -0
  216. package/web/dist/boot.js +2 -0
  217. package/web/dist/notebook.css +319 -0
  218. package/web/dist/notebook.js +89 -0
  219. package/web/dist/popup.css +41 -0
  220. package/web/dist/popup.js +13 -0
  221. package/web/{term.js → dist/term.js} +48 -48
  222. package/web/dist/ui.css +3 -0
  223. package/web/dist/video.js +108 -0
  224. package/web/html/board.html +17 -0
  225. package/web/html/notes.html +14 -0
  226. package/web/html/popup.html +13 -0
  227. package/web/{video.html → html/video.html} +14 -15
  228. package/web/lib/annotate/index.ts +2 -0
  229. package/web/lib/annotate/notes.ts +105 -0
  230. package/web/lib/annotate/page.ts +121 -0
  231. package/web/lib/annotate/rules.ts +37 -0
  232. package/web/lib/annotate/session.ts +336 -0
  233. package/web/lib/board/board-actions.ts +119 -0
  234. package/web/lib/board/board-open.ts +12 -0
  235. package/web/lib/board/board-store.ts +159 -0
  236. package/web/lib/board/filter-box.ts +7 -0
  237. package/web/lib/board/index.ts +10 -0
  238. package/web/lib/board/nav.ts +29 -0
  239. package/web/lib/board/on-state.ts +90 -0
  240. package/web/lib/board/popups.ts +22 -0
  241. package/web/lib/board/snapshot.ts +105 -0
  242. package/web/lib/board/strip.ts +43 -0
  243. package/web/{board → lib/board}/ws-board.ts +1 -1
  244. package/web/lib/context/context-rules.ts +27 -0
  245. package/web/lib/context/context-store.ts +95 -0
  246. package/web/lib/context/feed.ts +28 -0
  247. package/web/lib/context/index.ts +3 -0
  248. package/web/lib/core/api.ts +86 -0
  249. package/web/lib/core/ask.ts +24 -0
  250. package/web/lib/core/board.ts +290 -0
  251. package/web/lib/core/brief.ts +31 -0
  252. package/web/lib/core/format.ts +8 -0
  253. package/web/lib/core/host.ts +107 -0
  254. package/web/lib/core/index.ts +16 -0
  255. package/web/{board → lib/core}/labels.ts +6 -5
  256. package/web/lib/core/layers.ts +7 -0
  257. package/web/lib/core/leave.ts +7 -0
  258. package/web/lib/core/motion.ts +10 -0
  259. package/web/{board/toast.ts → lib/core/notices.ts} +2 -20
  260. package/web/lib/core/notifier.ts +15 -0
  261. package/web/lib/core/store.ts +39 -0
  262. package/web/lib/core/term-handle.ts +8 -0
  263. package/web/lib/core/toast.ts +29 -0
  264. package/web/lib/core/utils.ts +15 -0
  265. package/web/lib/decision/index.ts +1 -0
  266. package/web/lib/decision/plan-questions.ts +39 -0
  267. package/web/lib/dictation/chunks.ts +93 -0
  268. package/web/lib/dictation/dictation-store.ts +22 -0
  269. package/web/lib/dictation/engine.ts +265 -0
  270. package/web/lib/dictation/index.ts +5 -0
  271. package/web/lib/dictation/mic.ts +42 -0
  272. package/web/lib/dictation/terminal-dictation.ts +50 -0
  273. package/web/lib/footer/footer-rules.ts +13 -0
  274. package/web/lib/footer/footer-store.ts +42 -0
  275. package/web/lib/footer/index.ts +2 -0
  276. package/web/lib/git/git-actions.ts +110 -0
  277. package/web/lib/git/git-panel.ts +43 -0
  278. package/web/lib/git/git-store.ts +47 -0
  279. package/web/lib/git/git.ts +170 -0
  280. package/web/lib/git/index.ts +4 -0
  281. package/web/lib/home/home-engine.ts +16 -0
  282. package/web/lib/home/home-events.ts +9 -0
  283. package/web/lib/home/home-store.ts +247 -0
  284. package/web/lib/home/home-window.ts +193 -0
  285. package/web/lib/home/home.ts +85 -0
  286. package/web/lib/home/index.ts +7 -0
  287. package/web/lib/home/onboarding.ts +199 -0
  288. package/web/lib/home/use-float-drag.ts +62 -0
  289. package/web/lib/icebox/icebox-actions.ts +518 -0
  290. package/web/lib/icebox/icebox-store.ts +112 -0
  291. package/web/lib/icebox/icebox-view.ts +48 -0
  292. package/web/lib/icebox/icebox.ts +273 -0
  293. package/web/lib/icebox/index.ts +8 -0
  294. package/web/lib/icebox/use-card-drag.ts +82 -0
  295. package/web/lib/icebox/use-ice-keys.ts +75 -0
  296. package/web/lib/icebox/use-icebox.ts +41 -0
  297. package/web/lib/icebox/use-row-swipe.ts +107 -0
  298. package/web/lib/markdown/index.ts +1 -0
  299. package/web/lib/markdown/markdown.ts +136 -0
  300. package/web/lib/notebook/autosave.ts +131 -0
  301. package/web/lib/notebook/deal.ts +58 -0
  302. package/web/lib/notebook/engine-complete.ts +128 -0
  303. package/web/lib/notebook/engine-preview.ts +287 -0
  304. package/web/lib/notebook/engine-types.ts +26 -0
  305. package/web/lib/notebook/engine-widgets.ts +218 -0
  306. package/web/lib/notebook/engine.ts +74 -0
  307. package/web/lib/notebook/index.ts +9 -0
  308. package/web/lib/notebook/kit-loader.ts +16 -0
  309. package/web/lib/notebook/kit.ts +12 -0
  310. package/web/{notes-lib.ts → lib/notebook/text.ts} +11 -10
  311. package/web/lib/notebook/vault-actions.ts +239 -0
  312. package/web/lib/notebook/vault-rules.ts +74 -0
  313. package/web/lib/notebook/vault-session.ts +73 -0
  314. package/web/lib/notebook/vault-store.ts +63 -0
  315. package/web/lib/notes/index.ts +4 -0
  316. package/web/lib/notes/md-html.ts +115 -0
  317. package/web/lib/notes/notes-actions.ts +32 -0
  318. package/web/lib/notes/notes-store.ts +22 -0
  319. package/web/lib/notes/notes.ts +58 -0
  320. package/web/{board → lib/notes}/rich.ts +1 -2
  321. package/web/lib/phone/index.ts +7 -0
  322. package/web/lib/phone/phone-actions.ts +77 -0
  323. package/web/lib/phone/phone-home.ts +102 -0
  324. package/web/lib/phone/phone-setup.ts +59 -0
  325. package/web/lib/phone/phone-sheet.ts +25 -0
  326. package/web/lib/phone/phone-store.ts +32 -0
  327. package/web/lib/phone/sheet-swipe.ts +55 -0
  328. package/web/lib/phone/use-phone-setup.ts +89 -0
  329. package/web/lib/project/add-project.ts +37 -0
  330. package/web/lib/project/branch.ts +14 -0
  331. package/web/lib/project/index.ts +5 -0
  332. package/web/lib/project/project-bar.ts +76 -0
  333. package/web/lib/project/project-pick.ts +36 -0
  334. package/web/lib/project/ws-menu.ts +8 -0
  335. package/web/lib/rail/agents.ts +63 -0
  336. package/web/lib/rail/card-links.ts +20 -0
  337. package/web/lib/rail/index.ts +7 -0
  338. package/web/lib/rail/rail-actions.ts +74 -0
  339. package/web/lib/rail/rail-boot.ts +99 -0
  340. package/web/lib/rail/rail-store.ts +85 -0
  341. package/web/lib/rail/rules.ts +241 -0
  342. package/web/lib/rail/source-marks.ts +17 -0
  343. package/web/lib/rail/use-rank-drag.ts +108 -0
  344. package/web/lib/resources/index.ts +3 -0
  345. package/web/lib/resources/resources-actions.ts +59 -0
  346. package/web/lib/resources/resources-store.ts +48 -0
  347. package/web/lib/resources/rules.ts +56 -0
  348. package/web/lib/router/index.ts +3 -0
  349. package/web/lib/router/route-rules.ts +96 -0
  350. package/web/lib/router/route-store.ts +115 -0
  351. package/web/lib/router/use-route-classes.ts +15 -0
  352. package/web/lib/run/browser.ts +53 -0
  353. package/web/lib/run/card-terminal.ts +32 -0
  354. package/web/lib/run/doc.ts +42 -0
  355. package/web/lib/run/grip.ts +8 -0
  356. package/web/lib/run/index.ts +19 -0
  357. package/web/lib/run/kept.ts +58 -0
  358. package/web/lib/run/layout-store.ts +156 -0
  359. package/web/lib/run/layout.ts +195 -0
  360. package/web/lib/run/panel-actions.ts +104 -0
  361. package/web/lib/run/panel-derive.ts +148 -0
  362. package/web/lib/run/panel-store.ts +125 -0
  363. package/web/lib/run/preview.ts +105 -0
  364. package/web/lib/run/run-actions.ts +118 -0
  365. package/web/lib/run/run-view-store.ts +134 -0
  366. package/web/lib/run/term-loader.ts +19 -0
  367. package/web/lib/run/use-panel-run.ts +125 -0
  368. package/web/lib/run/use-run-lifecycle.ts +70 -0
  369. package/web/lib/run/viewer.ts +12 -0
  370. package/web/lib/run/workspace.ts +281 -0
  371. package/web/lib/run/ws-actions.ts +293 -0
  372. package/web/lib/run/ws-derive.ts +50 -0
  373. package/web/lib/run/ws-draw.ts +102 -0
  374. package/web/lib/run/ws-store.ts +21 -0
  375. package/web/lib/run/ws-tabs.ts +125 -0
  376. package/web/lib/search/index.ts +3 -0
  377. package/web/lib/search/search-match.ts +48 -0
  378. package/web/lib/search/search-rows.ts +228 -0
  379. package/web/lib/search/search.ts +30 -0
  380. package/web/lib/search/use-search-rows.ts +22 -0
  381. package/web/lib/server/attention.ts +29 -0
  382. package/web/lib/server/index.ts +6 -0
  383. package/web/lib/server/poll-rules.ts +57 -0
  384. package/web/lib/server/poller.ts +210 -0
  385. package/web/lib/server/server-store.ts +39 -0
  386. package/web/lib/server/types.ts +31 -0
  387. package/web/lib/server/use-server.ts +19 -0
  388. package/web/lib/settings/agent-favicons.ts +14 -0
  389. package/web/lib/settings/index.ts +7 -0
  390. package/web/lib/settings/panel-settings.ts +29 -0
  391. package/web/lib/settings/settings-actions.ts +357 -0
  392. package/web/lib/settings/settings-store.ts +114 -0
  393. package/web/lib/settings/settings.ts +413 -0
  394. package/web/lib/settings/skill-icons.ts +24 -0
  395. package/web/lib/settings/update.ts +70 -0
  396. package/web/lib/shared/data-urls.ts +32 -0
  397. package/web/lib/shared/index.ts +4 -0
  398. package/web/lib/shared/use-draft.ts +38 -0
  399. package/web/lib/shared/use-narrow.ts +11 -0
  400. package/web/lib/shared/use-pager.ts +24 -0
  401. package/web/lib/shell/appearance.ts +97 -0
  402. package/web/lib/shell/help-store.ts +4 -0
  403. package/web/lib/shell/index.ts +4 -0
  404. package/web/lib/shell/shell-store.ts +23 -0
  405. package/web/lib/shell/stored-look.ts +47 -0
  406. package/web/lib/task/index.ts +7 -0
  407. package/web/lib/task/task-results.ts +92 -0
  408. package/web/lib/task/tasks.ts +134 -0
  409. package/web/lib/task/use-live-frame.ts +85 -0
  410. package/web/lib/task/use-saved-text.ts +25 -0
  411. package/web/lib/task/use-task.ts +161 -0
  412. package/web/lib/task/use-tasks.ts +50 -0
  413. package/web/{board → lib/task}/zoom.ts +25 -12
  414. package/web/lib/terminal/hidden-badge.ts +15 -0
  415. package/web/lib/terminal/index.ts +8 -0
  416. package/web/lib/terminal/layout.ts +138 -0
  417. package/web/{term-font.ts → lib/terminal/term-font.ts} +3 -2
  418. package/web/lib/terminal/terminal-store.ts +65 -0
  419. package/web/lib/terminal/terms-feed.ts +37 -0
  420. package/web/lib/terminal/use-arranged.ts +15 -0
  421. package/web/lib/terminal/use-terminal-keys.ts +37 -0
  422. package/web/lib/url/index.ts +1 -0
  423. package/web/lib/url/safe-url.ts +9 -0
  424. package/web/notebook/notebook.ts +27 -0
  425. package/web/notebook/notes-lib.ts +3 -0
  426. package/web/pages/board/App.tsx +76 -0
  427. package/web/pages/board/header.tsx +83 -0
  428. package/web/pages/board/help.tsx +59 -0
  429. package/web/pages/board/host-bridge.ts +94 -0
  430. package/web/pages/board/host.tsx +19 -0
  431. package/web/pages/board/keys.ts +112 -0
  432. package/web/pages/board/live.ts +39 -0
  433. package/web/pages/board/main.ts +32 -0
  434. package/web/pages/board/pages.tsx +86 -0
  435. package/web/pages/board/panel.tsx +157 -0
  436. package/web/pages/board/portal.tsx +39 -0
  437. package/web/pages/board/use-boot.ts +13 -0
  438. package/web/pages/board/views.ts +63 -0
  439. package/web/pages/board-page.tsx +62 -0
  440. package/web/pages/home-page.tsx +127 -0
  441. package/web/pages/icebox-page.tsx +440 -0
  442. package/web/pages/notebook/App.tsx +35 -0
  443. package/web/pages/notebook-page.tsx +50 -0
  444. package/web/pages/popup/App.tsx +207 -0
  445. package/web/pages/settings-page.tsx +111 -0
  446. package/web/pages/task-page.tsx +397 -0
  447. package/web/pages/tasks-page.tsx +151 -0
  448. package/web/pages/terminal-page.tsx +15 -0
  449. package/web/popup/popup.ts +7 -0
  450. package/web/{term.ts → term/term.ts} +48 -20
  451. package/web/ui/alert-dialog.tsx +39 -0
  452. package/web/ui/badge.tsx +20 -0
  453. package/web/ui/button.tsx +37 -0
  454. package/web/ui/checkbox.tsx +20 -0
  455. package/web/ui/command.tsx +41 -0
  456. package/web/ui/dialog.tsx +28 -0
  457. package/web/ui/dropdown-menu.tsx +54 -0
  458. package/web/ui/icon.tsx +17 -0
  459. package/web/ui/index.ts +21 -0
  460. package/web/ui/input.tsx +9 -0
  461. package/web/ui/label.tsx +7 -0
  462. package/web/ui/legacy/board.css +715 -0
  463. package/web/{notes.html → ui/legacy/notes.css} +23 -157
  464. package/web/ui/legacy/popup.css +40 -0
  465. package/web/ui/popover.tsx +28 -0
  466. package/web/ui/select.tsx +61 -0
  467. package/web/ui/sheet.tsx +43 -0
  468. package/web/ui/skeleton.tsx +6 -0
  469. package/web/ui/sonner.tsx +25 -0
  470. package/web/ui/spinner.tsx +12 -0
  471. package/web/ui/switch.tsx +18 -0
  472. package/web/ui/tabs.tsx +18 -0
  473. package/web/ui/textarea.tsx +14 -0
  474. package/web/ui/theme.css +125 -0
  475. package/web/ui/toggle.tsx +8 -0
  476. package/web/ui/tooltip.tsx +26 -0
  477. package/web/{video.ts → video/video.ts} +5 -5
  478. package/web/board/add-project.ts +0 -147
  479. package/web/board/agent-favicons.ts +0 -9
  480. package/web/board/agent-term.ts +0 -51
  481. package/web/board/annotate-lib.ts +0 -19
  482. package/web/board/annotate.ts +0 -221
  483. package/web/board/api.ts +0 -180
  484. package/web/board/approvals.ts +0 -109
  485. package/web/board/badge.ts +0 -115
  486. package/web/board/cards.ts +0 -1080
  487. package/web/board/chat.ts +0 -128
  488. package/web/board/context.ts +0 -248
  489. package/web/board/dictation.ts +0 -343
  490. package/web/board/dom.ts +0 -132
  491. package/web/board/drafts.ts +0 -21
  492. package/web/board/fixes.ts +0 -89
  493. package/web/board/git.ts +0 -416
  494. package/web/board/home-ws.ts +0 -266
  495. package/web/board/home.ts +0 -421
  496. package/web/board/icebox.ts +0 -1788
  497. package/web/board/keys.ts +0 -121
  498. package/web/board/live.ts +0 -87
  499. package/web/board/main.ts +0 -94
  500. package/web/board/markdown.ts +0 -210
  501. package/web/board/onboarding.ts +0 -227
  502. package/web/board/panel.ts +0 -437
  503. package/web/board/phone-setup.ts +0 -79
  504. package/web/board/phone.ts +0 -219
  505. package/web/board/projects.ts +0 -277
  506. package/web/board/resources.ts +0 -170
  507. package/web/board/run-pick.ts +0 -41
  508. package/web/board/run-view.ts +0 -1316
  509. package/web/board/search-match.ts +0 -20
  510. package/web/board/search.ts +0 -330
  511. package/web/board/settings-accounts.ts +0 -76
  512. package/web/board/settings-agents.ts +0 -102
  513. package/web/board/settings-automations.ts +0 -71
  514. package/web/board/settings-cleanup.ts +0 -42
  515. package/web/board/settings-orchestration.ts +0 -32
  516. package/web/board/settings-pages.ts +0 -62
  517. package/web/board/settings-skills.ts +0 -103
  518. package/web/board/settings-voice.ts +0 -28
  519. package/web/board/settings.ts +0 -490
  520. package/web/board/store.ts +0 -47
  521. package/web/board/task-page.ts +0 -628
  522. package/web/board/task-results.ts +0 -234
  523. package/web/board/tasks.ts +0 -242
  524. package/web/board/terms.ts +0 -390
  525. package/web/board/update.ts +0 -171
  526. package/web/board/viewer.ts +0 -47
  527. package/web/board/views.ts +0 -164
  528. package/web/board/whatsapp-setup.ts +0 -149
  529. package/web/board/workspace.ts +0 -650
  530. package/web/board/ws-board-ui.ts +0 -95
  531. package/web/board/ws-tabs.ts +0 -227
  532. package/web/board.html +0 -1563
  533. package/web/board.js +0 -505
  534. package/web/notebook.js +0 -519
  535. package/web/notebook.ts +0 -1254
  536. package/web/popup.html +0 -141
  537. package/web/video.js +0 -575
  538. /package/web/{term.css → dist/term.css} +0 -0
  539. /package/web/{board/term-sessions.ts → lib/terminal/sessions.ts} +0 -0
  540. /package/web/{board/terminal-viewport.ts → lib/terminal/viewport.ts} +0 -0
  541. /package/web/{term-paste.ts → term/term-paste.ts} +0 -0
package/web/notebook.ts DELETED
@@ -1,1254 +0,0 @@
1
- // The notebook page. Bundled into web/notebook.js by `bun run build:web`; the page
2
- // never sees the filesystem, only /vault. See design.md, "Notebook", for the look.
3
- import { refreshBoardBadge } from "./board/badge.ts";
4
- import { initRail } from "./board/workspace.ts";
5
- // embed=1: a run workspace's note tab shows the note alone, without the side menu and header.
6
- if (new URLSearchParams(location.search).has("embed")) document.body.classList.add("embed");
7
- import {
8
- EditorView,
9
- Decoration,
10
- ViewPlugin,
11
- WidgetType,
12
- keymap,
13
- type DecorationSet,
14
- type ViewUpdate,
15
- } from "@codemirror/view";
16
- import { EditorState, StateEffect, StateField, type Range } from "@codemirror/state";
17
- import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
18
- import { syntaxTree, syntaxHighlighting, HighlightStyle } from "@codemirror/language";
19
- import { markdown, markdownLanguage, markdownKeymap } from "@codemirror/lang-markdown";
20
- import { tags as t } from "@lezer/highlight";
21
- import { autocompletion, startCompletion, type CompletionContext, type Completion } from "@codemirror/autocomplete";
22
- import {
23
- wikilinks,
24
- tags,
25
- resolve,
26
- safeUrl,
27
- tree,
28
- freshName,
29
- parseTable,
30
- boardLink,
31
- resolveRun,
32
- anchorWords,
33
- TABS,
34
- type Tree,
35
- type BoardLink,
36
- } from "./notes-lib.ts";
37
-
38
- type Note = { name: string; mtime: number; text: string };
39
-
40
- const $ = <T extends HTMLElement = HTMLElement>(id: string) => document.getElementById(id) as T;
41
- const esc = (s: string) =>
42
- String(s).replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]!);
43
- const ico = (n: string) => `<svg><use href="#i-${n}"/></svg>`;
44
- const last = (name: string) => name.split("/").pop()!;
45
- const folderOf = (name: string) => (name.includes("/") ? name.slice(0, name.lastIndexOf("/")) : "");
46
-
47
- type Board = {
48
- runs: {
49
- id: string;
50
- short: string;
51
- title: string;
52
- status: string;
53
- findings: { n: number; text: string; done: boolean }[];
54
- backlog: { n: number; status: string; text: string }[];
55
- }[];
56
- ideas: { text: string; status: string }[];
57
- };
58
- let board: Board = { runs: [], ideas: [] }; // what [[run:…]] and [[idea:…]] can name, from /links
59
- let dir = ""; // the state dir whose notes/ is shown
60
- let notes: Note[] = [];
61
- let open: string | null = null; // the note in the editor
62
- let base = 0; // the mtime it was loaded or last saved at
63
- let dirty = false,
64
- saving: Promise<void> | null = null,
65
- timer: ReturnType<typeof setTimeout> | undefined;
66
- let conflict: { text: string; mtime: number } | null = null;
67
- let confirmDelete = false;
68
- const shut = new Set<string>(); // folders folded in the tree, for this page load
69
-
70
- function toast(msg: string) {
71
- const el = $("toast");
72
- el.textContent = msg;
73
- el.classList.add("on");
74
- setTimeout(() => el.classList.remove("on"), 2600);
75
- }
76
- async function post(body: Record<string, unknown>) {
77
- try {
78
- const r = await fetch("/vault", {
79
- method: "POST",
80
- headers: { "content-type": "application/json" },
81
- body: JSON.stringify({ dir, ...body }),
82
- });
83
- return { status: r.status, ...(await r.json().catch(() => ({}))) };
84
- } catch {
85
- return { status: 0, error: "The board is not running" };
86
- }
87
- }
88
-
89
- // ---- live preview: markdown hidden and typeset on every line the cursor is not on
90
-
91
- class Check extends WidgetType {
92
- constructor(
93
- readonly on: boolean,
94
- readonly at: number,
95
- ) {
96
- super();
97
- }
98
- eq(o: Check) {
99
- return o.on === this.on && o.at === this.at;
100
- }
101
- toDOM(view: EditorView) {
102
- const b = document.createElement("input");
103
- b.type = "checkbox";
104
- b.checked = this.on;
105
- b.className = "cm-task";
106
- b.setAttribute("aria-label", this.on ? "done" : "to do");
107
- b.addEventListener("mousedown", (e) => {
108
- e.preventDefault();
109
- view.dispatch({ changes: { from: this.at, to: this.at + 3, insert: this.on ? "[ ]" : "[x]" } });
110
- });
111
- return b;
112
- }
113
- ignoreEvent() {
114
- return true;
115
- }
116
- }
117
- class Bullet extends WidgetType {
118
- eq() {
119
- return true;
120
- }
121
- toDOM() {
122
- const s = document.createElement("span");
123
- s.className = "cm-bullet";
124
- s.textContent = "•";
125
- return s;
126
- }
127
- }
128
- class Rule extends WidgetType {
129
- eq() {
130
- return true;
131
- }
132
- toDOM() {
133
- const s = document.createElement("span");
134
- s.className = "cm-rule";
135
- return s;
136
- }
137
- }
138
- class Img extends WidgetType {
139
- constructor(
140
- readonly src: string,
141
- readonly alt: string,
142
- ) {
143
- super();
144
- }
145
- eq(o: Img) {
146
- return o.src === this.src && o.alt === this.alt;
147
- }
148
- toDOM() {
149
- const i = document.createElement("img");
150
- i.src = this.src;
151
- i.alt = this.alt;
152
- i.className = "cm-img";
153
- return i;
154
- }
155
- }
156
-
157
- // A table the cursor is not in is drawn as one; clicking it puts the cursor in its
158
- // source. Cells are text nodes: nothing in a note becomes markup.
159
- class TableView extends WidgetType {
160
- constructor(
161
- readonly src: string,
162
- readonly at: number,
163
- ) {
164
- super();
165
- }
166
- eq(o: TableView) {
167
- return o.src === this.src && o.at === this.at;
168
- }
169
- toDOM(view: EditorView) {
170
- const t = parseTable(this.src),
171
- wrap = document.createElement("div"),
172
- table = document.createElement("table");
173
- wrap.className = "cm-table";
174
- const row = (cells: string[], tag: "th" | "td") => {
175
- const tr = document.createElement("tr");
176
- cells.forEach((c, i) => {
177
- const el = document.createElement(tag);
178
- el.textContent = c;
179
- if (t.align[i]) el.style.textAlign = t.align[i]!;
180
- tr.append(el);
181
- });
182
- return tr;
183
- };
184
- const head = document.createElement("thead"),
185
- body = document.createElement("tbody");
186
- head.append(row(t.head, "th"));
187
- t.rows.forEach((r) => body.append(row(r, "td")));
188
- table.append(head, body);
189
- wrap.append(table);
190
- wrap.addEventListener("mousedown", (e) => {
191
- e.preventDefault();
192
- view.dispatch({ selection: { anchor: this.at } });
193
- view.focus();
194
- });
195
- return wrap;
196
- }
197
- ignoreEvent() {
198
- return true;
199
- }
200
- }
201
- // Whether the editor has focus, as state: an unfocused editor shows every table drawn.
202
- const focusSet = StateEffect.define<boolean>();
203
- const focused = StateField.define<boolean>({
204
- create: () => false,
205
- update: (v, tr) => tr.effects.reduce((f, e) => (e.is(focusSet) ? e.value : f), v),
206
- });
207
- // Block widgets may span lines, which a view plugin may not do: tables live in a field.
208
- function tables(state: EditorState) {
209
- const out: Range<Decoration>[] = [],
210
- sel = state.selection.main,
211
- live = state.field(focused, false);
212
- syntaxTree(state).iterate({
213
- enter(n) {
214
- if (n.name !== "Table") return;
215
- const from = state.doc.lineAt(n.from).from,
216
- to = state.doc.lineAt(n.to).to;
217
- if (live && sel.to >= from && sel.from <= to) return false;
218
- out.push(
219
- Decoration.replace({ widget: new TableView(state.sliceDoc(from, to), from), block: true }).range(from, to),
220
- );
221
- return false;
222
- },
223
- });
224
- return Decoration.set(out);
225
- }
226
- const tableField = StateField.define<DecorationSet>({
227
- create: tables,
228
- update: (v, tr) =>
229
- tr.docChanged ||
230
- tr.selection ||
231
- tr.effects.some((e) => e.is(focusSet)) ||
232
- syntaxTree(tr.startState) !== syntaxTree(tr.state)
233
- ? tables(tr.state)
234
- : v,
235
- provide: (f) => EditorView.decorations.from(f),
236
- });
237
-
238
- // A link to the board: where it goes, what the chip says, and whether it is there.
239
- const ICON: Record<string, string> = {
240
- idea: "idea",
241
- starting: "idea",
242
- running: "run",
243
- stalled: "stall",
244
- waiting: "wait",
245
- done: "done",
246
- abandoned: "aband",
247
- };
248
- function boardTarget(l: BoardLink) {
249
- const q = (o: Record<string, string>) => "/?" + new URLSearchParams({ all: "1", dir, ...o }).toString();
250
- if (l.kind === "idea") {
251
- const t = l.text.toLowerCase();
252
- const task =
253
- board.ideas.find((i) => i.text.toLowerCase() === t) ??
254
- board.ideas.find((i) => i.text.toLowerCase().startsWith(t));
255
- return {
256
- name: task?.text ?? l.text,
257
- sub: "idea",
258
- status: task?.status ?? "",
259
- href: task ? q({ idea: task.text }) : null,
260
- };
261
- }
262
- const id = resolveRun(
263
- l.id,
264
- board.runs.map((r) => r.id),
265
- ),
266
- run = board.runs.find((r) => r.id === id);
267
- const item = l.item && run && (l.item.type === "finding" ? run.findings : run.backlog).some((x) => x.n === l.item!.n);
268
- const ok = !!run && (!l.item || item);
269
- return {
270
- name: run?.short ?? l.id,
271
- sub: anchorWords(l),
272
- status: run?.status ?? "",
273
- href: ok
274
- ? q({ run: run!.id, ...(l.tab ? { tab: l.tab } : {}), ...(l.item ? { item: `${l.item.type}-${l.item.n}` } : {}) })
275
- : null,
276
- };
277
- }
278
- // Leave for the board only once the note is on disk.
279
- async function go(href: string) {
280
- await flush();
281
- if (dirty) {
282
- toast("This note is not saved yet");
283
- return;
284
- }
285
- location.href = href;
286
- }
287
- class BoardChip extends WidgetType {
288
- constructor(
289
- readonly name: string,
290
- readonly sub: string,
291
- readonly status: string,
292
- readonly href: string | null,
293
- ) {
294
- super();
295
- }
296
- eq(o: BoardChip) {
297
- return o.name === this.name && o.sub === this.sub && o.status === this.status && o.href === this.href;
298
- }
299
- toDOM() {
300
- const c = document.createElement("span");
301
- c.className = "cm-board" + (this.href ? "" : " cm-board-missing");
302
- c.title = this.href ? "Open on the board" : "Not on the board";
303
- if (this.status) {
304
- const ic = document.createElement("span");
305
- ic.className = "st d-" + (ICON[this.status] ?? "idea");
306
- ic.innerHTML = `<svg><use href="#s-${ICON[this.status] ?? "idea"}"/></svg>`;
307
- c.append(ic);
308
- }
309
- c.append(this.name);
310
- if (this.sub) {
311
- const s = document.createElement("span");
312
- s.className = "sub";
313
- s.textContent = "› " + this.sub;
314
- c.append(s);
315
- }
316
- c.addEventListener("mousedown", (e) => {
317
- e.preventDefault();
318
- if (this.href) void go(this.href);
319
- else toast("That is not on the board");
320
- });
321
- return c;
322
- }
323
- ignoreEvent() {
324
- return true;
325
- }
326
- }
327
-
328
- const hide = Decoration.replace({});
329
- const refresh = StateEffect.define<null>(); // the list of notes changed: redraw missing links
330
-
331
- function build(view: EditorView): DecorationSet {
332
- const { state } = view,
333
- doc = state.doc,
334
- out: Range<Decoration>[] = [];
335
- const live = new Set<number>();
336
- // Only a focused editor has a cursor line: a note just opened reads fully typeset.
337
- if (view.hasFocus)
338
- for (const r of state.selection.ranges)
339
- for (let l = doc.lineAt(r.from).number; l <= doc.lineAt(r.to).number; l++) live.add(l);
340
- const on = (pos: number) => live.has(doc.lineAt(pos).number);
341
- // A plugin may not replace a line break: anything that would is left as written.
342
- const put = (d: Decoration, from: number, to: number) => {
343
- if (doc.lineAt(from).number === doc.lineAt(to).number) out.push(d.range(from, to));
344
- };
345
- const lines = (from: number, to: number, cls: string) => {
346
- for (let l = doc.lineAt(from).number; l <= doc.lineAt(to).number; l++)
347
- out.push(Decoration.line({ class: cls }).range(doc.line(l).from));
348
- };
349
- for (const { from, to } of view.visibleRanges) {
350
- syntaxTree(state).iterate({
351
- from,
352
- to,
353
- enter(n) {
354
- const name = n.name;
355
- const h = /^ATXHeading(\d)$/.exec(name);
356
- if (h) {
357
- lines(n.from, n.from, `cm-h cm-h${Math.min(+h[1]!, 4)}`);
358
- return;
359
- }
360
- if (name === "HeaderMark" && n.node.parent?.name.startsWith("ATX")) {
361
- if (!on(n.from))
362
- put(
363
- hide,
364
- n.from,
365
- Math.min(n.to + (doc.sliceString(n.to, n.to + 1) === " " ? 1 : 0), doc.lineAt(n.from).to),
366
- );
367
- return;
368
- }
369
- if (
370
- name === "EmphasisMark" ||
371
- name === "StrikethroughMark" ||
372
- (name === "CodeMark" && n.node.parent?.name === "InlineCode")
373
- ) {
374
- if (!on(n.from)) put(hide, n.from, n.to);
375
- return;
376
- }
377
- if (name === "Blockquote") {
378
- lines(n.from, n.to, "cm-quote");
379
- return;
380
- }
381
- if (name === "QuoteMark") {
382
- if (!on(n.from))
383
- put(
384
- hide,
385
- n.from,
386
- Math.min(n.to + (doc.sliceString(n.to, n.to + 1) === " " ? 1 : 0), doc.lineAt(n.from).to),
387
- );
388
- return;
389
- }
390
- if (name === "FencedCode") {
391
- lines(n.from, n.to, "cm-fence");
392
- out.push(
393
- Decoration.line({ class: "cm-fence-a" }).range(doc.lineAt(n.from).from),
394
- Decoration.line({ class: "cm-fence-z" }).range(doc.lineAt(n.to).from),
395
- );
396
- return false;
397
- }
398
- if (name === "HorizontalRule") {
399
- if (!on(n.from)) put(Decoration.replace({ widget: new Rule() }), n.from, n.to);
400
- return;
401
- }
402
- if (name === "ListMark" && n.node.parent?.parent?.name === "BulletList") {
403
- if (on(n.from)) return;
404
- const task = n.node.nextSibling?.name === "Task";
405
- put(
406
- task ? hide : Decoration.replace({ widget: new Bullet() }),
407
- n.from,
408
- task ? Math.min(n.to + 1, doc.lineAt(n.from).to) : n.to,
409
- );
410
- return;
411
- }
412
- if (name === "TaskMarker") {
413
- if (!on(n.from))
414
- put(
415
- Decoration.replace({ widget: new Check(/x/i.test(doc.sliceString(n.from, n.to)), n.from) }),
416
- n.from,
417
- n.to,
418
- );
419
- return;
420
- }
421
- if (name === "Image") {
422
- const url = n.node.getChild("URL"),
423
- marks = n.node.getChildren("LinkMark");
424
- if (on(n.from) || !url || marks.length < 2) return false;
425
- const src = safeUrl(doc.sliceString(url.from, url.to));
426
- if (src && /^https?:/i.test(src))
427
- put(
428
- Decoration.replace({ widget: new Img(src, doc.sliceString(marks[0]!.to, marks[1]!.from)) }),
429
- n.from,
430
- n.to,
431
- );
432
- return false;
433
- }
434
- if (name === "Link") {
435
- const url = n.node.getChild("URL"),
436
- marks = n.node.getChildren("LinkMark");
437
- // Only the inline form `[text](url)`; a reference link stays as written.
438
- if (!url || marks.length < 4) return;
439
- const href = safeUrl(doc.sliceString(url.from, url.to));
440
- const text = { from: marks[0]!.to, to: marks[1]!.from };
441
- // A link to somewhere safeUrl refuses stays as written, so what it points at is visible.
442
- if (on(n.from) || !href) {
443
- out.push(Decoration.mark({ class: "cm-link-src" }).range(n.from, n.to));
444
- return;
445
- }
446
- if (text.to > text.from)
447
- out.push(
448
- Decoration.mark({ class: "cm-link", attributes: { "data-href": href } }).range(text.from, text.to),
449
- );
450
- put(hide, marks[0]!.from, marks[0]!.to);
451
- put(hide, marks[1]!.from, n.to);
452
- return;
453
- }
454
- if (name === "URL" && n.node.parent?.name !== "Link" && n.node.parent?.name !== "Image") {
455
- const href = safeUrl(doc.sliceString(n.from, n.to));
456
- out.push(
457
- Decoration.mark({ class: "cm-link", attributes: href && !on(n.from) ? { "data-href": href } : {} }).range(
458
- n.from,
459
- n.to,
460
- ),
461
- );
462
- }
463
- },
464
- });
465
- }
466
- // Wikilinks and tags are not markdown: found by notes-lib over the text.
467
- // ponytail: the whole note is scanned on each redraw; limit to visible ranges if notes reach megabytes.
468
- const text = doc.toString(),
469
- names = notes.map((x) => x.name);
470
- for (const w of wikilinks(text)) {
471
- const bl = boardLink(w);
472
- if (bl) {
473
- if (on(w.from)) {
474
- out.push(Decoration.mark({ class: "cm-wiki" }).range(w.from, w.to));
475
- continue;
476
- }
477
- const t = boardTarget(bl);
478
- put(
479
- Decoration.replace({ widget: new BoardChip(w.label !== w.target ? w.label : t.name, t.sub, t.status, t.href) }),
480
- w.from,
481
- w.to,
482
- );
483
- continue;
484
- }
485
- const target = resolve(w.name, names);
486
- const cls = "cm-wiki" + (target ? "" : " cm-wiki-missing");
487
- if (on(w.from)) {
488
- out.push(Decoration.mark({ class: cls }).range(w.from, w.to));
489
- continue;
490
- }
491
- const labelAt = text.lastIndexOf(w.label, w.to - 2);
492
- const lf = labelAt > w.from ? labelAt : w.from + 2,
493
- lt = lf + w.label.length;
494
- put(hide, w.from, lf);
495
- out.push(Decoration.mark({ class: cls, attributes: { "data-note": target ?? w.name } }).range(lf, lt));
496
- put(hide, lt, w.to);
497
- }
498
- for (const g of tags(text))
499
- out.push(
500
- Decoration.mark({ class: "cm-tag", attributes: on(g.from) ? {} : { "data-tag": g.tag } }).range(g.from, g.to),
501
- );
502
- return Decoration.set(out, true);
503
- }
504
-
505
- const preview = ViewPlugin.fromClass(
506
- class {
507
- decorations: DecorationSet;
508
- constructor(view: EditorView) {
509
- this.decorations = build(view);
510
- }
511
- update(u: ViewUpdate) {
512
- if (
513
- u.docChanged ||
514
- u.viewportChanged ||
515
- u.selectionSet ||
516
- u.focusChanged ||
517
- syntaxTree(u.startState) !== syntaxTree(u.state) ||
518
- u.transactions.some((tr) => tr.effects.some((e) => e.is(refresh)))
519
- )
520
- this.decorations = build(u.view);
521
- }
522
- },
523
- { decorations: (v) => v.decorations },
524
- );
525
-
526
- const look = HighlightStyle.define([
527
- { tag: t.emphasis, fontStyle: "italic" },
528
- { tag: t.strong, fontWeight: "600" },
529
- { tag: t.strikethrough, textDecoration: "line-through" },
530
- {
531
- tag: t.monospace,
532
- fontFamily: "var(--mono)",
533
- fontSize: "0.86em",
534
- background: "var(--bg)",
535
- borderRadius: "var(--r-s)",
536
- padding: "1px 4px",
537
- },
538
- { tag: [t.processingInstruction, t.meta, t.url, t.labelName, t.contentSeparator], color: "var(--dim)" },
539
- { tag: t.link, color: "var(--accent)" },
540
- { tag: t.quote, color: "var(--dim)" },
541
- ]);
542
-
543
- // Clicks on what the preview drew: a link opens, a wikilink opens its note, a tag filters.
544
- const clicks = EditorView.domEventHandlers({
545
- mousedown(e) {
546
- const el = (e.target as HTMLElement).closest?.("[data-href],[data-note],[data-tag]") as HTMLElement | null;
547
- if (!el || e.button !== 0) return false;
548
- e.preventDefault();
549
- const href = el.dataset.href;
550
- // A relative link is a note (`[x](Other%20note.md)`), as in Obsidian; the rest open in a tab.
551
- if (href && !/^[a-z][a-z0-9+.-]*:/i.test(href)) {
552
- let name = href;
553
- try {
554
- name = decodeURIComponent(href);
555
- } catch {
556
- /* as written */
557
- }
558
- const hit = resolve(
559
- name.split("#")[0]!,
560
- notes.map((x) => x.name),
561
- );
562
- hit ? void openNote(hit) : toast(`No note named ${name}`);
563
- } else if (href) window.open(href, "_blank", "noopener");
564
- else if (el.dataset.note) openOrCreate(el.dataset.note);
565
- else if (el.dataset.tag) {
566
- $<HTMLInputElement>("q").value = "#" + el.dataset.tag;
567
- drawSide();
568
- }
569
- return true;
570
- },
571
- });
572
-
573
- // The `/` menu: at the start of a line, `/` offers the blocks, so nobody has to
574
- // remember markdown. Picking one replaces the `/word` with the block's source; `|`
575
- // in the text marks where the cursor lands.
576
- const BLOCKS: [string, string, string][] = [
577
- ["Checkbox", "- [ ] |", "to do"],
578
- ["Divider", "---\n|", "line across"],
579
- ["Heading 1", "# |", "big"],
580
- ["Heading 2", "## |", "medium"],
581
- ["Heading 3", "### |", "small"],
582
- ["Bullet list", "- |", "•"],
583
- ["Numbered list", "1. |", "1."],
584
- ["Quote", "> |", "aside"],
585
- ["Code block", "```\n|\n```", "monospace"],
586
- ["Table", "| Column | Column |\n| --- | --- |\n| | |", "rows"],
587
- ["Link to note", "[[|]]", "[[ ]]"],
588
- ["Link to run", "[[run:|]]", "board"],
589
- ["Tag", "#|", "#"],
590
- ];
591
- function slash(cx: CompletionContext) {
592
- const m = cx.matchBefore(/^[ \t]*\/[\w ]*$/);
593
- if (!m) return null;
594
- const at = m.from + m.text.indexOf("/");
595
- return {
596
- from: at,
597
- filter: true,
598
- validFor: /^\/[\w ]*$/,
599
- // Boosted in list order, so an unfiltered menu reads as written above.
600
- options: BLOCKS.map(([label, src, detail], i): Completion => ({
601
- label: "/" + label.toLowerCase(),
602
- displayLabel: label,
603
- detail,
604
- boost: 50 - i,
605
- apply: (view, _c, from, to) => {
606
- // Straight under a line of text, `---` would underline it into a heading and a
607
- // table would join its paragraph: both need a blank line above.
608
- const line = view.state.doc.lineAt(from);
609
- const gap =
610
- (label === "Divider" || label === "Table") &&
611
- line.number > 1 &&
612
- view.state.doc.line(line.number - 1).text.trim()
613
- ? "\n"
614
- : "";
615
- const text = gap + src.replace("|", ""),
616
- caret = from + gap.length + src.indexOf("|");
617
- view.dispatch({
618
- changes: { from, to, insert: text },
619
- selection: { anchor: caret },
620
- userEvent: "input.complete",
621
- });
622
- // A link is only begun: the next list offers what it can point at.
623
- if (label.startsWith("Link to")) setTimeout(() => startCompletion(view));
624
- },
625
- })),
626
- };
627
- }
628
-
629
- // `[[` offers notes, runs and tasks; `#` after a run offers its tabs, findings and
630
- // backlog items. Picking one closes the link unless it is a run, which leaves the
631
- // cursor before `]]` so a `#` can follow.
632
- function links(cx: CompletionContext) {
633
- const m = cx.matchBefore(/\[\[[^\]\n|]*$/);
634
- if (!m) return null;
635
- const q = m.text.slice(2),
636
- close = cx.state.sliceDoc(cx.pos, cx.pos + 2) === "]]";
637
- const put = (text: string, stay: boolean) => (view: EditorView, _c: Completion, from: number, to: number) => {
638
- view.dispatch({
639
- changes: { from, to, insert: text + (close ? "" : "]]") },
640
- selection: { anchor: from + text.length + (stay ? 0 : 2) },
641
- userEvent: "input.complete",
642
- });
643
- };
644
- const anchor = /^run:\s*([\w.-]+)#([\w-]*)$/i.exec(q);
645
- if (anchor) {
646
- const id = resolveRun(
647
- anchor[1]!,
648
- board.runs.map((r) => r.id),
649
- ),
650
- run = board.runs.find((r) => r.id === id);
651
- if (!run) return null;
652
- const cut = (t: string) => (t.length > 60 ? t.slice(0, 59) + "…" : t);
653
- return {
654
- from: cx.pos - anchor[2]!.length,
655
- validFor: /^[\w-]*$/,
656
- options: [
657
- ...TABS.map((t, i): Completion => ({ label: t, detail: "tab", boost: 20 - i, apply: put(t, false) })),
658
- ...run.findings.map((f): Completion => ({
659
- label: `finding-${f.n}`,
660
- detail: cut(f.text) + (f.done ? " (closed)" : ""),
661
- apply: put(`finding-${f.n}`, false),
662
- })),
663
- ...run.backlog.map((b): Completion => ({
664
- label: `backlog-${b.n}`,
665
- detail: `${b.status}: ${cut(b.text)}`,
666
- apply: put(`backlog-${b.n}`, false),
667
- })),
668
- ],
669
- };
670
- }
671
- return {
672
- from: m.from + 2,
673
- validFor: /^[^\]\n|#]*$/,
674
- options: [
675
- ...notes.map((n): Completion => ({ label: n.name, detail: "note", apply: put(n.name, false) })),
676
- // Newest first, by the name the board shows; the full id is what gets written.
677
- ...[...board.runs]
678
- .sort((a, b) => b.id.localeCompare(a.id))
679
- .map((r, i): Completion => ({
680
- label: "run:" + r.id,
681
- displayLabel: r.short,
682
- detail: r.id.slice(0, 10) + " · " + r.title,
683
- boost: Math.max(-99, 60 - i),
684
- apply: put("run:" + r.id, true),
685
- })),
686
- ...board.ideas.map((i): Completion => ({
687
- label: "idea:" + i.text,
688
- detail: "idea",
689
- apply: put("idea:" + i.text, false),
690
- })),
691
- ],
692
- };
693
- }
694
-
695
- const exts = (crlf: boolean) => [
696
- autocompletion({ override: [slash, links], icons: false }),
697
- history(),
698
- keymap.of([
699
- ...markdownKeymap,
700
- ...defaultKeymap,
701
- ...historyKeymap,
702
- indentWithTab,
703
- {
704
- key: "Mod-s",
705
- run: () => {
706
- void flush();
707
- return true;
708
- },
709
- },
710
- ]),
711
- markdown({ base: markdownLanguage }),
712
- syntaxHighlighting(look),
713
- EditorView.lineWrapping,
714
- EditorView.contentAttributes.of({ "aria-label": "Note", spellcheck: "true" }),
715
- focused,
716
- EditorView.focusChangeEffect.of((_s, on) => focusSet.of(on)),
717
- tableField,
718
- preview,
719
- clicks,
720
- EditorView.updateListener.of((u) => {
721
- if (u.docChanged && !loading) {
722
- dirty = true;
723
- conflict = null;
724
- drawMeta();
725
- clearTimeout(timer);
726
- timer = setTimeout(() => void flush(), 600);
727
- }
728
- }),
729
- crlf ? EditorState.lineSeparator.of("\r\n") : [],
730
- ];
731
-
732
- let loading = false;
733
- const view = new EditorView({ parent: $("editor"), state: EditorState.create({ doc: "", extensions: exts(false) }) });
734
- // Replace the text without it counting as the user's edit.
735
- function setText(text: string, fresh: boolean) {
736
- loading = true;
737
- if (fresh) view.setState(EditorState.create({ doc: text, extensions: exts(text.includes("\r\n")) }));
738
- else
739
- view.dispatch({
740
- changes: { from: 0, to: view.state.doc.length, insert: text },
741
- selection: { anchor: Math.min(view.state.selection.main.head, text.length) },
742
- });
743
- loading = false;
744
- }
745
-
746
- // ---- saving
747
-
748
- // Write the open note if it has unsaved text. Never called for a note only opened.
749
- async function flush(): Promise<void> {
750
- clearTimeout(timer);
751
- if (saving) await saving;
752
- if (!open || !dirty || conflict) return;
753
- const name = open,
754
- text = view.state.sliceDoc();
755
- let saved = false;
756
- saving = (async () => {
757
- drawMeta("Saving…");
758
- const r = await post({ op: "save", name, text, base });
759
- if (open !== name) return;
760
- if (r.ok) {
761
- saved = true;
762
- base = r.mtime;
763
- if (view.state.sliceDoc() === text) dirty = false;
764
- upsert({ name, mtime: r.mtime, text });
765
- } else if (r.status === 409) conflict = { text: r.text ?? "", mtime: r.mtime ?? 0 };
766
- else toast(r.error || "Not saved");
767
- })();
768
- await saving;
769
- saving = null;
770
- drawMeta();
771
- // Typed on while that save was out: save again. A failed save waits for the next keystroke.
772
- if (saved && dirty && !conflict && open === name) {
773
- clearTimeout(timer);
774
- timer = setTimeout(() => void flush(), 600);
775
- }
776
- }
777
- function upsert(n: Note) {
778
- notes = [n, ...notes.filter((x) => x.name !== n.name)];
779
- drawSide();
780
- drawLinks();
781
- }
782
-
783
- // ---- the vault
784
-
785
- async function load() {
786
- let r: { notes?: Note[]; error?: string };
787
- try {
788
- r = await (await fetch("/vault?dir=" + encodeURIComponent(dir))).json();
789
- } catch {
790
- toast("The board is not running");
791
- return;
792
- }
793
- if (!r.notes) {
794
- toast(r.error || "Could not read notes");
795
- return;
796
- }
797
- notes = r.notes;
798
- // The board's items, for chips and completion; a failure keeps the last ones.
799
- try {
800
- const b = await (await fetch("/links?dir=" + encodeURIComponent(dir))).json();
801
- if (Array.isArray(b.runs)) board = b;
802
- } catch {
803
- /* keep */
804
- }
805
- const mine = open && notes.find((n) => n.name === open);
806
- // Someone else changed the open note: take it only when nothing typed here is unsaved.
807
- if (mine && mine.mtime !== base && !dirty && !saving) {
808
- base = mine.mtime;
809
- setText(mine.text, false);
810
- }
811
- view.dispatch({ effects: refresh.of(null) });
812
- drawSide();
813
- drawLinks();
814
- drawPane();
815
- }
816
-
817
- // Laying down a page: the note being left is copied onto a sheet under the paper
818
- // side, and the next note slides a short way in over it from the right, fading up,
819
- // like a fresh sheet dealt onto a stack, while the one beneath eases left into its
820
- // shadow. The sidebar sits above both, so nothing moves across it. The copy
821
- // is pixels only: never focused, never read. Transform and opacity only, so it stays
822
- // smooth. Every open does it, the first one too. Nothing moves under reduced motion.
823
- const DEAL = { duration: 260, easing: "cubic-bezier(.22,.61,.36,1)" };
824
- function lift(): HTMLElement | null {
825
- const main = document.querySelector<HTMLElement>(".main")!;
826
- const m = document.documentElement.dataset.motion;
827
- if (m ? m === "reduce" : matchMedia("(prefers-reduced-motion: reduce)").matches) return null;
828
- const r = main.getBoundingClientRect(),
829
- top = main.scrollTop;
830
- const sheet = main.cloneNode(true) as HTMLElement;
831
- sheet.classList.add("sheet");
832
- sheet.setAttribute("aria-hidden", "true");
833
- sheet.inert = true;
834
- Object.assign(sheet.style, {
835
- left: r.left + "px",
836
- top: r.top + "px",
837
- width: r.width + "px",
838
- height: r.height + "px",
839
- });
840
- sheet.append(Object.assign(document.createElement("i"), { className: "shade" }));
841
- // After the real page in document order, so every id still finds the real one first.
842
- document.body.append(sheet);
843
- sheet.scrollTop = top;
844
- return sheet;
845
- }
846
- function turn(sheet: HTMLElement | null) {
847
- if (!sheet) return;
848
- const main = document.querySelector<HTMLElement>(".main")!;
849
- main.classList.add("dealt");
850
- const done = () => {
851
- main.classList.remove("dealt");
852
- sheet.remove();
853
- };
854
- main
855
- .animate(
856
- [
857
- { transform: "translateX(56px)", opacity: 0 },
858
- { transform: "none", opacity: 1 },
859
- ],
860
- DEAL,
861
- )
862
- .finished.then(done, done);
863
- // The old page is gone before the new one is fully up, so the two never read as one.
864
- sheet.animate(
865
- [
866
- { transform: "none", opacity: 1 },
867
- { transform: "translateX(-24px)", opacity: 0, offset: 0.6 },
868
- { transform: "translateX(-24px)", opacity: 0 },
869
- ],
870
- { ...DEAL, fill: "forwards" },
871
- );
872
- sheet.querySelector<HTMLElement>(".shade")!.animate([{ opacity: 0 }, { opacity: 1 }], { ...DEAL, fill: "forwards" });
873
- }
874
-
875
- // False when the open note still holds text that is not on disk: it stays open.
876
- async function openNote(name: string | null): Promise<boolean> {
877
- if (name === open) return true;
878
- await flush();
879
- if (dirty) {
880
- toast(conflict ? "Choose Keep mine or Load theirs first" : "This note is not saved yet");
881
- return false;
882
- }
883
- const sheet = lift();
884
- open = name;
885
- conflict = null;
886
- confirmDelete = false;
887
- dirty = false;
888
- const n = name ? notes.find((x) => x.name === name) : null;
889
- base = n?.mtime ?? 0;
890
- setText(n?.text ?? "", true);
891
- try {
892
- name ? sessionStorage.setItem("kz-note:" + dir, name) : sessionStorage.removeItem("kz-note:" + dir);
893
- } catch {
894
- /* private window */
895
- }
896
- document.body.classList.remove("side-open");
897
- drawSide();
898
- drawPane();
899
- drawLinks();
900
- turn(sheet);
901
- return true;
902
- }
903
-
904
- async function create(name: string) {
905
- const r = await post({ op: "save", name, text: "", base: 0 });
906
- if (!r.ok) {
907
- toast(r.status === 409 ? "A note with that name exists" : r.error || "Could not create the note");
908
- return false;
909
- }
910
- upsert({ name: r.name, mtime: r.mtime, text: "" });
911
- return openNote(r.name);
912
- }
913
- async function openOrCreate(name: string) {
914
- const hit = resolve(
915
- name,
916
- notes.map((n) => n.name),
917
- );
918
- if (hit) return void openNote(hit);
919
- if (await create(name)) view.focus();
920
- }
921
- async function newNote() {
922
- if (
923
- await create(
924
- freshName(
925
- notes.map((n) => n.name),
926
- open ? folderOf(open) : "",
927
- ),
928
- )
929
- ) {
930
- const t = $<HTMLInputElement>("title");
931
- t.focus();
932
- t.select();
933
- }
934
- }
935
-
936
- async function rename(to: string) {
937
- if (!open || !to.trim() || to.trim() === open) {
938
- drawPane();
939
- return;
940
- }
941
- const from = open;
942
- await flush();
943
- const r = await post({ op: "rename", name: from, to });
944
- if (!r.ok) {
945
- toast(r.error || "Could not rename");
946
- drawPane();
947
- return;
948
- }
949
- // Another note was opened meanwhile: the rename stands, the editor stays where it is.
950
- if (open !== from) {
951
- await load();
952
- return;
953
- }
954
- open = to
955
- .trim()
956
- .replace(/\.md$/i, "")
957
- .split("/")
958
- .map((p) => p.trim())
959
- .join("/");
960
- await load();
961
- base = notes.find((n) => n.name === open)?.mtime ?? base;
962
- toast(folderOf(from) === folderOf(open) ? "Renamed" : `Moved to ${folderOf(open) || "the top"}`);
963
- }
964
-
965
- async function remove() {
966
- if (!open) return;
967
- clearTimeout(timer);
968
- const r = await post({ op: "delete", name: open });
969
- if (!r.ok) {
970
- toast(r.error || "Could not delete");
971
- return;
972
- }
973
- toast("Moved to notes/.trash");
974
- dirty = false;
975
- notes = notes.filter((n) => n.name !== open);
976
- await openNote(null);
977
- }
978
-
979
- // ---- drawing
980
-
981
- function drawSide() {
982
- const q = $<HTMLInputElement>("q").value.trim().toLowerCase();
983
- // Tags, most used first.
984
- const count = new Map<string, number>();
985
- for (const n of notes) for (const g of new Set(tags(n.text).map((x) => x.tag))) count.set(g, (count.get(g) ?? 0) + 1);
986
- const tg = q.startsWith("#") ? q.slice(1) : null;
987
- $("tags").innerHTML = [...count]
988
- .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
989
- .map(
990
- ([g, c]) =>
991
- `<button class="chip${g === tg ? " on" : ""}" data-tag="${esc(g)}" aria-pressed="${g === tg}">#${esc(g)} <span>${c}</span></button>`,
992
- )
993
- .join("");
994
- $("tagsh").hidden = !count.size;
995
- const row = (n: string, withFolder = false) => {
996
- const note = notes.find((x) => x.name === n);
997
- return `<li><button class="nt${n === open ? " cur" : ""}" data-open="${esc(n)}"${n === open ? ' aria-current="true"' : ""}><span class="nm">${esc(last(n))}</span>${withFolder && folderOf(n) ? `<span class="fd">${esc(folderOf(n))}</span>` : ""}<span class="age">${note ? age(note.mtime) : ""}</span></button></li>`;
998
- };
999
- if (q) {
1000
- const hits = notes.filter((n) =>
1001
- tg !== null
1002
- ? tags(n.text).some((x) => x.tag === tg || x.tag.startsWith(tg + "/"))
1003
- : n.name.toLowerCase().includes(q) || n.text.toLowerCase().includes(q),
1004
- );
1005
- $("tree").innerHTML = hits.length
1006
- ? `<ul>${hits.map((n) => row(n.name, true)).join("")}</ul>`
1007
- : `<p class="none">No note matches.</p>`;
1008
- return;
1009
- }
1010
- const draw = (tr: Tree, path: string): string =>
1011
- `<ul>${[...tr.folders]
1012
- .map(([f, sub]) => {
1013
- const p = path + f;
1014
- return `<li><details data-folder="${esc(p)}"${shut.has(p) ? "" : " open"}><summary><i class="chev">${ico("chev")}</i>${ico("folder")}<span>${esc(f)}</span></summary>${draw(sub, p + "/")}</details></li>`;
1015
- })
1016
- .join("")}${tr.notes.map((n) => row(n)).join("")}</ul>`;
1017
- $("tree").innerHTML = notes.length ? draw(tree(notes.map((n) => n.name)), "") : "";
1018
- }
1019
-
1020
- // Full screen: the open note alone, no header or sidebar. Off until the icon turns it
1021
- // on; it then holds from note to note until the icon or Esc turns it off. With no note
1022
- // open the page is never full screen: picking one needs the sidebar.
1023
- let full = false;
1024
- function setFull(on: boolean) {
1025
- full = on;
1026
- drawPane();
1027
- }
1028
- // Width: the reading column (boxed, 68ch) or the whole paper side. Kept per browser.
1029
- let wide = false;
1030
- try {
1031
- wide = localStorage.getItem("kz-note-wide") === "1";
1032
- } catch {
1033
- /* no storage */
1034
- }
1035
- function setWide(on: boolean) {
1036
- wide = on;
1037
- try {
1038
- localStorage.setItem("kz-note-wide", on ? "1" : "0");
1039
- } catch {
1040
- /* no storage */
1041
- }
1042
- drawPane();
1043
- }
1044
-
1045
- function drawPane() {
1046
- const has = !!open;
1047
- document.body.classList.toggle("full", has && full);
1048
- document.body.classList.toggle("wide", wide);
1049
- $("pane").hidden = !has;
1050
- $("empty").hidden = has || notes.length > 0;
1051
- $("pick").hidden = has || !notes.length;
1052
- if (!has) return;
1053
- const t = $<HTMLInputElement>("title");
1054
- if (document.activeElement !== t) t.value = open!;
1055
- drawMeta();
1056
- }
1057
-
1058
- function drawMeta(state?: string) {
1059
- const m = $("meta");
1060
- if (!open) return;
1061
- if (conflict) {
1062
- m.innerHTML = `<span class="warnw">This note changed somewhere else since you opened it.</span><span class="acts"><button class="btn ghost" id="theirs">Load theirs</button><button class="btn pri" id="mine">Keep mine</button></span>`;
1063
- $("theirs").onclick = () => {
1064
- const c = conflict!;
1065
- conflict = null;
1066
- dirty = false;
1067
- base = c.mtime;
1068
- setText(c.text, false);
1069
- drawMeta();
1070
- };
1071
- $("mine").onclick = () => {
1072
- base = conflict!.mtime;
1073
- conflict = null;
1074
- void flush();
1075
- };
1076
- return;
1077
- }
1078
- if (confirmDelete) {
1079
- m.innerHTML = `<span>Move this note to <code>notes/.trash</code>?</span><span class="acts"><button class="btn ghost" id="cancel">Cancel</button><button class="btn danger" id="del">Delete</button></span>`;
1080
- $("cancel").onclick = () => {
1081
- confirmDelete = false;
1082
- drawMeta();
1083
- };
1084
- $("del").onclick = () => {
1085
- confirmDelete = false;
1086
- void remove();
1087
- };
1088
- return;
1089
- }
1090
- const where = folderOf(open);
1091
- m.innerHTML = `<span>${where ? esc(where) : "Notes"}</span><span>·</span><span id="saved">${state ?? (dirty ? "Not saved yet" : "Saved")}</span><span class="sp"></span><button class="ib" id="wide" title="${wide ? "Boxed width" : "Full width"}" aria-label="${wide ? "Boxed width" : "Full width"}" aria-pressed="${wide}">${ico(wide ? "box" : "wide")}</button><button class="ib" id="full" title="${full ? "Exit full screen (Esc)" : "Full screen"}" aria-label="${full ? "Exit full screen" : "Full screen"}">${ico(full ? "min" : "max")}</button><button class="ib" id="trash" title="Delete note" aria-label="Delete note">${ico("trash")}</button>`;
1092
- $("trash").onclick = () => {
1093
- confirmDelete = true;
1094
- drawMeta();
1095
- };
1096
- $("full").onclick = () => setFull(!full);
1097
- $("wide").onclick = () => setWide(!wide);
1098
- }
1099
-
1100
- function drawLinks() {
1101
- const box = $("links");
1102
- if (!open) {
1103
- box.hidden = true;
1104
- return;
1105
- }
1106
- const names = notes.map((n) => n.name);
1107
- const from = notes.filter((n) => n.name !== open && wikilinks(n.text).some((l) => resolve(l.name, names) === open));
1108
- box.hidden = !from.length;
1109
- box.innerHTML = `<h3>Linked from</h3><ul>${from.map((n) => `<li><button class="nt" data-open="${esc(n.name)}"><span class="nm">${esc(last(n.name))}</span>${folderOf(n.name) ? `<span class="fd">${esc(folderOf(n.name))}</span>` : ""}</button></li>`).join("")}</ul>`;
1110
- }
1111
-
1112
- function age(ms: number) {
1113
- const s = (Date.now() - ms) / 1000;
1114
- return s < 60
1115
- ? "now"
1116
- : s < 3600
1117
- ? `${Math.floor(s / 60)}m`
1118
- : s < 86400
1119
- ? `${Math.floor(s / 3600)}h`
1120
- : `${Math.floor(s / 86400)}d`;
1121
- }
1122
-
1123
- // ---- wiring
1124
-
1125
- document.addEventListener("click", (e) => {
1126
- // The narrow layout's drawer closes on any click outside it.
1127
- const tg = e.target as HTMLElement;
1128
- if (document.body.classList.contains("side-open") && !tg.closest?.(".side,#side"))
1129
- document.body.classList.remove("side-open");
1130
- const el = (e.target as HTMLElement).closest?.("[data-open],[data-tag]") as HTMLElement | null;
1131
- if (!el || el.closest(".cm-editor")) return;
1132
- if (el.dataset.open) void openNote(el.dataset.open);
1133
- else if (el.dataset.tag) {
1134
- const q = $<HTMLInputElement>("q");
1135
- q.value = q.value === "#" + el.dataset.tag ? "" : "#" + el.dataset.tag;
1136
- drawSide();
1137
- }
1138
- });
1139
- $("tree").addEventListener(
1140
- "toggle",
1141
- (e) => {
1142
- const d = e.target as HTMLDetailsElement;
1143
- if (d.dataset.folder) d.open ? shut.delete(d.dataset.folder) : shut.add(d.dataset.folder);
1144
- },
1145
- true,
1146
- );
1147
- $("q").addEventListener("input", drawSide);
1148
- $("new").onclick = () => void newNote();
1149
- $("new2").onclick = () => void newNote();
1150
- $("side").onclick = () => document.body.classList.toggle("side-open");
1151
- const title = $<HTMLInputElement>("title");
1152
- title.addEventListener("keydown", (e) => {
1153
- if (e.key === "Enter") {
1154
- e.preventDefault();
1155
- title.blur();
1156
- }
1157
- if (e.key === "Escape") {
1158
- title.value = open ?? "";
1159
- title.blur();
1160
- }
1161
- });
1162
- title.addEventListener("blur", () => void rename(title.value));
1163
- document.addEventListener("keydown", (e) => {
1164
- // Esc in the name or search field is theirs (it undoes a rename there).
1165
- if (e.key !== "Escape" || (e.target as HTMLElement).matches?.("input")) return;
1166
- document.body.classList.remove("side-open");
1167
- if (document.body.classList.contains("full")) setFull(false);
1168
- });
1169
- // Closing with text not on disk: the browser asks first.
1170
- addEventListener("beforeunload", (e) => {
1171
- if (dirty) e.preventDefault();
1172
- });
1173
- // Leaving with unsaved text: a keepalive request outlives the page.
1174
- addEventListener("pagehide", () => {
1175
- if (open && dirty && !conflict)
1176
- fetch("/vault", {
1177
- method: "POST",
1178
- keepalive: true,
1179
- headers: { "content-type": "application/json" },
1180
- body: JSON.stringify({ dir, op: "save", name: open, text: view.state.sliceDoc(), base }),
1181
- });
1182
- });
1183
-
1184
- // The project: ?dir= in the URL, else the one the board picked last, else where it started.
1185
- (async () => {
1186
- try {
1187
- const th = localStorage.getItem("kz-theme");
1188
- if (th) document.documentElement.dataset.theme = th;
1189
- if (localStorage.getItem("kz-color") === "blue") document.documentElement.dataset.color = "blue";
1190
- } catch {
1191
- /* no storage */
1192
- }
1193
- let S: { dir: string | null; projects: { dir: string; label: string }[] };
1194
- try {
1195
- S = await (await fetch("/state")).json();
1196
- } catch {
1197
- toast("The board is not running");
1198
- return;
1199
- }
1200
- let kept: string | null = null;
1201
- try {
1202
- kept = localStorage.getItem("kz-proj");
1203
- } catch {
1204
- /* no storage */
1205
- }
1206
- const want = new URLSearchParams(location.search).get("dir");
1207
- const known = (d: string | null) => !!d && S.projects.some((p) => p.dir === d);
1208
- dir = [want, kept, S.dir].find(known) ?? S.projects[0]?.dir ?? "";
1209
- const sel = $<HTMLSelectElement>("proj");
1210
- sel.innerHTML = S.projects
1211
- .map((p) => `<option value="${esc(p.dir)}" title="${esc(p.label)}"${p.dir === dir ? " selected" : ""}>${esc(p.label.split(/[\\/]/).filter(Boolean).pop() || p.label)}</option>`)
1212
- .join("");
1213
- // Folder names only, as on the board; the full path is the tooltip.
1214
- const full = () => (sel.title = S.projects.find((p) => p.dir === sel.value)?.label ?? "");
1215
- full();
1216
- sel.onchange = async () => {
1217
- if (!(await openNote(null))) {
1218
- sel.value = dir;
1219
- return;
1220
- }
1221
- dir = sel.value;
1222
- full();
1223
- // window.: `history` here is CodeMirror's undo extension.
1224
- const u = new URL(location.href);
1225
- u.searchParams.set("dir", dir);
1226
- window.history.replaceState(null, "", u);
1227
- await load();
1228
- };
1229
- await load();
1230
- let again: string | null = null;
1231
- try {
1232
- again = sessionStorage.getItem("kz-note:" + dir);
1233
- } catch {
1234
- /* no storage */
1235
- }
1236
- // ?note= is the board's "Linked from notes"; otherwise the note open last in this tab.
1237
- const asked = new URLSearchParams(location.search).get("note");
1238
- if (asked && notes.some((n) => n.name === asked)) again = asked;
1239
- if (again && notes.some((n) => n.name === again)) await openNote(again);
1240
- initRail();
1241
- void refreshBoardBadge();
1242
- // Every write under a state dir arrives as `changed`, this page's own saves included.
1243
- const listen = () => {
1244
- const es = new EventSource("/events");
1245
- es.onmessage = (ev) => {
1246
- if (ev.data === "changed") { void load(); void refreshBoardBadge(); }
1247
- };
1248
- es.onerror = () => {
1249
- es.close();
1250
- setTimeout(listen, 3000);
1251
- };
1252
- };
1253
- listen();
1254
- })();