@sixb/app 0.2.3 → 0.2.5

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 (329) hide show
  1. package/assets/connector-icons/README.md +1 -0
  2. package/assets/connector-icons/ctm.png +0 -0
  3. package/dist/agent/activity-label.d.ts.map +1 -1
  4. package/dist/agent/agent-chat.d.ts +3 -1
  5. package/dist/agent/agent-chat.d.ts.map +1 -1
  6. package/dist/agent/agent-panel.d.ts.map +1 -1
  7. package/dist/agent/artifact-panel.d.ts +3 -1
  8. package/dist/agent/artifact-panel.d.ts.map +1 -1
  9. package/dist/agent/background/background-tool-row.d.ts.map +1 -1
  10. package/dist/agent/background/interpret.d.ts +1 -1
  11. package/dist/agent/background/interpret.d.ts.map +1 -1
  12. package/dist/agent/components/composer-settings.d.ts +1 -1
  13. package/dist/agent/components/composer-settings.d.ts.map +1 -1
  14. package/dist/agent/components/composer.d.ts +22 -5
  15. package/dist/agent/components/composer.d.ts.map +1 -1
  16. package/dist/agent/components/context-meter.d.ts +1 -1
  17. package/dist/agent/components/context-meter.d.ts.map +1 -1
  18. package/dist/agent/components/conversation-panel.d.ts +8 -2
  19. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  20. package/dist/agent/components/message-parts.d.ts +2 -1
  21. package/dist/agent/components/message-parts.d.ts.map +1 -1
  22. package/dist/agent/components/message-view.d.ts.map +1 -1
  23. package/dist/agent/components/pending-messages.d.ts +20 -0
  24. package/dist/agent/components/pending-messages.d.ts.map +1 -0
  25. package/dist/agent/components/sandbox-recovery.d.ts +11 -2
  26. package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
  27. package/dist/agent/components/threads-button.d.ts +1 -1
  28. package/dist/agent/components/threads-button.d.ts.map +1 -1
  29. package/dist/agent/components/transcript.d.ts +5 -0
  30. package/dist/agent/components/transcript.d.ts.map +1 -1
  31. package/dist/agent/conversation.d.ts +3 -6
  32. package/dist/agent/conversation.d.ts.map +1 -1
  33. package/dist/agent/delegation/agent-exchange.d.ts +16 -0
  34. package/dist/agent/delegation/agent-exchange.d.ts.map +1 -0
  35. package/dist/agent/delegation/child-card.d.ts +3 -3
  36. package/dist/agent/delegation/child-card.d.ts.map +1 -1
  37. package/dist/agent/delegation/child-parts.d.ts +1 -10
  38. package/dist/agent/delegation/child-parts.d.ts.map +1 -1
  39. package/dist/agent/delegation/child-work.d.ts.map +1 -1
  40. package/dist/agent/delegation/interpret.d.ts +9 -10
  41. package/dist/agent/delegation/interpret.d.ts.map +1 -1
  42. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  43. package/dist/agent/file-edits/file-edit-tool-view.d.ts +10 -0
  44. package/dist/agent/file-edits/file-edit-tool-view.d.ts.map +1 -0
  45. package/dist/agent/file-edits/interpret.d.ts +25 -0
  46. package/dist/agent/file-edits/interpret.d.ts.map +1 -0
  47. package/dist/agent/hooks/use-agent-conversation.d.ts +16 -4
  48. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  49. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  50. package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
  51. package/dist/agent/i18n/en.d.ts +114 -5
  52. package/dist/agent/i18n/en.d.ts.map +1 -1
  53. package/dist/agent/i18n/fr.d.ts.map +1 -1
  54. package/dist/agent/i18n/index.d.ts +190 -8
  55. package/dist/agent/i18n/index.d.ts.map +1 -1
  56. package/dist/agent/inbox-handoff.d.ts +10 -0
  57. package/dist/agent/inbox-handoff.d.ts.map +1 -0
  58. package/dist/agent/live-run.d.ts +8 -1
  59. package/dist/agent/live-run.d.ts.map +1 -1
  60. package/dist/agent/message-agent/interpret.d.ts +2 -2
  61. package/dist/agent/message-agent/interpret.d.ts.map +1 -1
  62. package/dist/agent/publish-artifact/interpret.d.ts +1 -1
  63. package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
  64. package/dist/agent/questions/interpret.d.ts +31 -0
  65. package/dist/agent/questions/interpret.d.ts.map +1 -0
  66. package/dist/agent/questions/question-card.d.ts +16 -0
  67. package/dist/agent/questions/question-card.d.ts.map +1 -0
  68. package/dist/agent/questions/question-composer.d.ts +15 -0
  69. package/dist/agent/questions/question-composer.d.ts.map +1 -0
  70. package/dist/agent/read/interpret.d.ts +8 -1
  71. package/dist/agent/read/interpret.d.ts.map +1 -1
  72. package/dist/agent/read/read-tool-view.d.ts.map +1 -1
  73. package/dist/agent/search/interpret.d.ts +101 -0
  74. package/dist/agent/search/interpret.d.ts.map +1 -0
  75. package/dist/agent/search/search-tool-view.d.ts +10 -0
  76. package/dist/agent/search/search-tool-view.d.ts.map +1 -0
  77. package/dist/agent/thread-state.d.ts +26 -0
  78. package/dist/agent/thread-state.d.ts.map +1 -0
  79. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  80. package/dist/agent/tool-views/registry.d.ts +5 -6
  81. package/dist/agent/tool-views/registry.d.ts.map +1 -1
  82. package/dist/agent/types.d.ts +5 -1
  83. package/dist/agent/types.d.ts.map +1 -1
  84. package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
  85. package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
  86. package/dist/agent/waits.d.ts +14 -0
  87. package/dist/agent/waits.d.ts.map +1 -0
  88. package/dist/artifacts/card-preview.d.ts.map +1 -1
  89. package/dist/artifacts/edit-session.d.ts +11 -1
  90. package/dist/artifacts/edit-session.d.ts.map +1 -1
  91. package/dist/artifacts/editor/block-handle.d.ts +20 -0
  92. package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
  93. package/dist/artifacts/editor/blocks.d.ts +34 -0
  94. package/dist/artifacts/editor/blocks.d.ts.map +1 -0
  95. package/dist/artifacts/editor/callout-view.d.ts +7 -0
  96. package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
  97. package/dist/artifacts/editor/document-editor.d.ts +30 -0
  98. package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
  99. package/dist/artifacts/editor/figure-view.d.ts +12 -0
  100. package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
  101. package/dist/artifacts/editor/find-blocks.d.ts +6 -0
  102. package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
  103. package/dist/artifacts/editor/markdown-document.d.ts +12 -0
  104. package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
  105. package/dist/artifacts/editor/messages.d.ts +4 -0
  106. package/dist/artifacts/editor/messages.d.ts.map +1 -0
  107. package/dist/artifacts/editor/schema.d.ts +21 -0
  108. package/dist/artifacts/editor/schema.d.ts.map +1 -0
  109. package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
  110. package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
  111. package/dist/artifacts/editor/slash-menu.d.ts +43 -0
  112. package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
  113. package/dist/artifacts/editor/upload.d.ts +12 -0
  114. package/dist/artifacts/editor/upload.d.ts.map +1 -0
  115. package/dist/artifacts/file-source.d.ts +5 -0
  116. package/dist/artifacts/file-source.d.ts.map +1 -1
  117. package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
  118. package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
  119. package/dist/artifacts/frame-editor/commands.d.ts +93 -0
  120. package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
  121. package/dist/artifacts/frame-editor/entry.d.ts +2 -0
  122. package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
  123. package/dist/artifacts/frame-editor/frame.d.ts +5 -0
  124. package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
  125. package/dist/artifacts/frame-editor/keys.d.ts +8 -0
  126. package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
  127. package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
  128. package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
  129. package/dist/artifacts/frame-editor/schema.d.ts +34 -0
  130. package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
  131. package/dist/artifacts/frame-editor/style.d.ts +2 -0
  132. package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
  133. package/dist/artifacts/frame.d.ts +2 -2
  134. package/dist/artifacts/frame.d.ts.map +1 -1
  135. package/dist/artifacts/live/boards.d.ts +2 -0
  136. package/dist/artifacts/live/boards.d.ts.map +1 -1
  137. package/dist/artifacts/live/document.d.ts +32 -0
  138. package/dist/artifacts/live/document.d.ts.map +1 -0
  139. package/dist/artifacts/live/header.d.ts +4 -4
  140. package/dist/artifacts/live/header.d.ts.map +1 -1
  141. package/dist/artifacts/live/presence.d.ts.map +1 -1
  142. package/dist/artifacts/live/session.d.ts +2 -0
  143. package/dist/artifacts/live/session.d.ts.map +1 -1
  144. package/dist/artifacts/live/view.d.ts +4 -3
  145. package/dist/artifacts/live/view.d.ts.map +1 -1
  146. package/dist/artifacts/messages.d.ts +278 -2
  147. package/dist/artifacts/messages.d.ts.map +1 -1
  148. package/dist/artifacts/pdf.d.ts +8 -0
  149. package/dist/artifacts/pdf.d.ts.map +1 -0
  150. package/dist/artifacts/queries.d.ts +80 -0
  151. package/dist/artifacts/queries.d.ts.map +1 -1
  152. package/dist/artifacts/references/references.d.ts +3 -3
  153. package/dist/artifacts/references/references.d.ts.map +1 -1
  154. package/dist/artifacts/renderers/canvas/board-editor.d.ts +11 -4
  155. package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
  156. package/dist/artifacts/renderers/canvas/board.d.ts +14 -2
  157. package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
  158. package/dist/artifacts/renderers/canvas/canvas.d.ts +4 -3
  159. package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -1
  160. package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
  161. package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
  162. package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
  163. package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
  164. package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
  165. package/dist/artifacts/renderers/canvas/controls.d.ts +15 -4
  166. package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -1
  167. package/dist/artifacts/renderers/canvas/focus.d.ts +19 -5
  168. package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
  169. package/dist/artifacts/renderers/canvas/gestures.d.ts +46 -0
  170. package/dist/artifacts/renderers/canvas/gestures.d.ts.map +1 -0
  171. package/dist/artifacts/renderers/canvas/page-resize.d.ts +21 -0
  172. package/dist/artifacts/renderers/canvas/page-resize.d.ts.map +1 -0
  173. package/dist/artifacts/renderers/canvas/page-size-controls.d.ts +21 -0
  174. package/dist/artifacts/renderers/canvas/page-size-controls.d.ts.map +1 -0
  175. package/dist/artifacts/renderers/canvas/page-size.d.ts +93 -0
  176. package/dist/artifacts/renderers/canvas/page-size.d.ts.map +1 -0
  177. package/dist/artifacts/renderers/canvas/page-zoom.d.ts +64 -0
  178. package/dist/artifacts/renderers/canvas/page-zoom.d.ts.map +1 -0
  179. package/dist/artifacts/renderers/canvas/shown-size.d.ts +26 -0
  180. package/dist/artifacts/renderers/canvas/shown-size.d.ts.map +1 -0
  181. package/dist/artifacts/renderers/designed-document.d.ts +28 -0
  182. package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
  183. package/dist/artifacts/renderers/document-tree.d.ts +2 -0
  184. package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
  185. package/dist/artifacts/renderers/document.d.ts +9 -1
  186. package/dist/artifacts/renderers/document.d.ts.map +1 -1
  187. package/dist/artifacts/renderers/live-frame.d.ts +145 -0
  188. package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
  189. package/dist/artifacts/renderers/page-editor.d.ts +16 -0
  190. package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
  191. package/dist/artifacts/renderers/page.d.ts +10 -1
  192. package/dist/artifacts/renderers/page.d.ts.map +1 -1
  193. package/dist/artifacts/viewer.d.ts.map +1 -1
  194. package/dist/{chunk-001c4gnk.js → chunk-4fex83k2.js} +19965 -13027
  195. package/dist/chunk-4fex83k2.js.map +239 -0
  196. package/dist/{chunk-5crvhjp2.js → chunk-4wm09prf.js} +1633 -1999
  197. package/dist/chunk-4wm09prf.js.map +27 -0
  198. package/dist/{chunk-fwb9mxwm.js → chunk-5sgac68y.js} +1 -1
  199. package/dist/{chunk-kes4ygmz.js → chunk-69qgh20f.js} +1 -1
  200. package/dist/chunk-y51c4tsz.js +11 -0
  201. package/dist/chunk-y51c4tsz.js.map +10 -0
  202. package/dist/index.d.ts +4 -1
  203. package/dist/index.d.ts.map +1 -1
  204. package/dist/index.js +13 -6
  205. package/dist/index.js.map +5 -5
  206. package/dist/pages/console/data/messages.d.ts +6 -0
  207. package/dist/pages/console/data/messages.d.ts.map +1 -1
  208. package/dist/pages/console/data/shared.d.ts.map +1 -1
  209. package/dist/pages.js +12 -5
  210. package/dist/pages.js.map +6 -6
  211. package/dist/shell/search-command.d.ts.map +1 -1
  212. package/package.json +22 -5
  213. package/src/agent/activity-label.ts +9 -1
  214. package/src/agent/agent-chat.tsx +57 -37
  215. package/src/agent/agent-execution-trace.tsx +2 -2
  216. package/src/agent/agent-panel.tsx +6 -4
  217. package/src/agent/agent.css +254 -0
  218. package/src/agent/artifact-panel.tsx +77 -22
  219. package/src/agent/background/background-tool-row.tsx +24 -10
  220. package/src/agent/background/interpret.ts +60 -51
  221. package/src/agent/components/composer-settings.tsx +20 -10
  222. package/src/agent/components/composer.tsx +342 -104
  223. package/src/agent/components/context-meter.tsx +7 -3
  224. package/src/agent/components/conversation-panel.tsx +96 -37
  225. package/src/agent/components/message-parts.tsx +390 -64
  226. package/src/agent/components/message-view.tsx +12 -2
  227. package/src/agent/components/pending-messages.tsx +338 -0
  228. package/src/agent/components/sandbox-recovery.tsx +36 -17
  229. package/src/agent/components/threads-button.tsx +3 -2
  230. package/src/agent/components/transcript.tsx +92 -45
  231. package/src/agent/conversation.ts +203 -54
  232. package/src/agent/delegation/agent-exchange.tsx +53 -0
  233. package/src/agent/delegation/child-card.tsx +6 -40
  234. package/src/agent/delegation/child-parts.tsx +1 -84
  235. package/src/agent/delegation/child-work.tsx +19 -5
  236. package/src/agent/delegation/interpret.ts +64 -61
  237. package/src/agent/delegation/model.ts +1 -1
  238. package/src/agent/file-edits/file-edit-tool-view.tsx +126 -0
  239. package/src/agent/file-edits/interpret.ts +120 -0
  240. package/src/agent/hooks/use-agent-conversation.ts +360 -92
  241. package/src/agent/hooks/use-thread-stream.ts +10 -0
  242. package/src/agent/i18n/en.ts +134 -16
  243. package/src/agent/i18n/fr.ts +122 -16
  244. package/src/agent/inbox-handoff.ts +47 -0
  245. package/src/agent/live-run.ts +23 -2
  246. package/src/agent/message-agent/interpret.ts +4 -3
  247. package/src/agent/publish-artifact/interpret.ts +14 -5
  248. package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +2 -2
  249. package/src/agent/questions/interpret.ts +90 -0
  250. package/src/agent/questions/question-card.tsx +57 -0
  251. package/src/agent/questions/question-composer.tsx +257 -0
  252. package/src/agent/react-router.tsx +2 -2
  253. package/src/agent/read/interpret.ts +34 -1
  254. package/src/agent/read/read-tool-view.tsx +20 -4
  255. package/src/agent/search/interpret.ts +367 -0
  256. package/src/agent/search/search-tool-view.tsx +235 -0
  257. package/src/agent/thread-state.ts +114 -0
  258. package/src/agent/tool-views/built-in.tsx +33 -6
  259. package/src/agent/tool-views/registry.tsx +28 -2
  260. package/src/agent/types.ts +7 -0
  261. package/src/agent/view-file/view-file-tool-view.tsx +33 -19
  262. package/src/agent/waits.ts +50 -0
  263. package/src/artifacts/artifacts.css +434 -0
  264. package/src/artifacts/card-preview.tsx +6 -1
  265. package/src/artifacts/edit-session.tsx +15 -1
  266. package/src/artifacts/editor/block-handle.tsx +278 -0
  267. package/src/artifacts/editor/blocks.ts +216 -0
  268. package/src/artifacts/editor/callout-view.tsx +31 -0
  269. package/src/artifacts/editor/document-editor.tsx +484 -0
  270. package/src/artifacts/editor/figure-view.tsx +66 -0
  271. package/src/artifacts/editor/find-blocks.ts +19 -0
  272. package/src/artifacts/editor/markdown-document.tsx +72 -0
  273. package/src/artifacts/editor/messages.ts +4 -0
  274. package/src/artifacts/editor/schema.ts +159 -0
  275. package/src/artifacts/editor/selection-toolbar.tsx +364 -0
  276. package/src/artifacts/editor/slash-menu.tsx +251 -0
  277. package/src/artifacts/editor/upload.ts +40 -0
  278. package/src/artifacts/file-source.ts +11 -0
  279. package/src/artifacts/frame-editor/bundle.ts +8 -0
  280. package/src/artifacts/frame-editor/commands.ts +565 -0
  281. package/src/artifacts/frame-editor/entry.ts +6 -0
  282. package/src/artifacts/frame-editor/frame.ts +847 -0
  283. package/src/artifacts/frame-editor/generated/editor.txt +149 -0
  284. package/src/artifacts/frame-editor/generated.d.ts +5 -0
  285. package/src/artifacts/frame-editor/keys.ts +323 -0
  286. package/src/artifacts/frame-editor/protocol.ts +151 -0
  287. package/src/artifacts/frame-editor/schema.ts +293 -0
  288. package/src/artifacts/frame-editor/style.ts +58 -0
  289. package/src/artifacts/frame.tsx +14 -5
  290. package/src/artifacts/live/boards.ts +46 -3
  291. package/src/artifacts/live/document.ts +89 -0
  292. package/src/artifacts/live/header.tsx +9 -14
  293. package/src/artifacts/live/presence.ts +5 -1
  294. package/src/artifacts/live/session.ts +4 -2
  295. package/src/artifacts/live/view.ts +14 -8
  296. package/src/artifacts/messages.ts +192 -2
  297. package/src/artifacts/pdf.ts +50 -0
  298. package/src/artifacts/references/references.tsx +46 -11
  299. package/src/artifacts/renderers/canvas/board-editor.tsx +44 -155
  300. package/src/artifacts/renderers/canvas/board.tsx +70 -8
  301. package/src/artifacts/renderers/canvas/canvas.tsx +66 -15
  302. package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
  303. package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
  304. package/src/artifacts/renderers/canvas/comments.ts +8 -4
  305. package/src/artifacts/renderers/canvas/controls.tsx +64 -30
  306. package/src/artifacts/renderers/canvas/focus.tsx +200 -56
  307. package/src/artifacts/renderers/canvas/gestures.ts +265 -0
  308. package/src/artifacts/renderers/canvas/page-resize.tsx +542 -0
  309. package/src/artifacts/renderers/canvas/page-size-controls.tsx +193 -0
  310. package/src/artifacts/renderers/canvas/page-size.ts +218 -0
  311. package/src/artifacts/renderers/canvas/page-zoom.ts +280 -0
  312. package/src/artifacts/renderers/canvas/shown-size.ts +105 -0
  313. package/src/artifacts/renderers/designed-document.tsx +277 -0
  314. package/src/artifacts/renderers/document-tree.ts +9 -0
  315. package/src/artifacts/renderers/document.tsx +13 -102
  316. package/src/artifacts/renderers/live-frame.ts +163 -0
  317. package/src/artifacts/renderers/page-editor.tsx +613 -0
  318. package/src/artifacts/renderers/page.tsx +21 -4
  319. package/src/artifacts/viewer.tsx +101 -41
  320. package/src/index.ts +8 -0
  321. package/src/pages/console/data/messages.ts +6 -0
  322. package/src/pages/console/data/projections.tsx +4 -0
  323. package/src/pages/console/data/shared.tsx +1 -0
  324. package/src/pages/console/ontology/lineage/trail.tsx +3 -0
  325. package/src/shell/search-command.tsx +2 -0
  326. package/dist/chunk-001c4gnk.js.map +0 -204
  327. package/dist/chunk-5crvhjp2.js.map +0 -28
  328. /package/dist/{chunk-fwb9mxwm.js.map → chunk-5sgac68y.js.map} +0 -0
  329. /package/dist/{chunk-kes4ygmz.js.map → chunk-69qgh20f.js.map} +0 -0
@@ -0,0 +1,5 @@
1
+ // What `bundle.ts` imports as text. Bun's loader reads it; the type checker needs telling.
2
+ declare module "*/generated/editor.txt" {
3
+ const text: string
4
+ export default text
5
+ }
@@ -0,0 +1,323 @@
1
+ import { type Editor, Extension } from "@tiptap/core"
2
+ import type { Node as ProseMirrorNode } from "@tiptap/pm/model"
3
+ import { NodeSelection, Selection, TextSelection } from "@tiptap/pm/state"
4
+ import {
5
+ duplicate,
6
+ LIST_TAGS,
7
+ liftOut,
8
+ move,
9
+ SINGLE_BLOCK_TAGS,
10
+ tagOf,
11
+ withoutId,
12
+ words,
13
+ wordsAt,
14
+ } from "./commands"
15
+ import type { PageMark } from "./protocol"
16
+
17
+ // The keys of a page, Notion's where a page allows them. Enter starts a new paragraph, or a new
18
+ // item in a list; Backspace at the start of a heading makes it a paragraph, and of a list's first
19
+ // item takes it out of the list. What would merge two boxes of the design, a section into the one
20
+ // before it or a cell into its neighbour, does nothing: the design's structure is changed by the
21
+ // block handle, never by a stray key.
22
+
23
+ /** After a block of these, Enter makes a paragraph; after any other, a block like it. */
24
+ const ENDS_IN_PARAGRAPH: ReadonlySet<string> = new Set([
25
+ "h1",
26
+ "h2",
27
+ "h3",
28
+ "h4",
29
+ "h5",
30
+ "h6",
31
+ "blockquote",
32
+ "address",
33
+ ])
34
+
35
+ export interface PageKeysOptions {
36
+ readonly toggleMark: (editor: Editor, mark: PageMark) => void
37
+ readonly onLink: () => void
38
+ }
39
+
40
+ export const PageKeys = Extension.create<PageKeysOptions>({
41
+ name: "pageKeys",
42
+ addOptions: () => ({ toggleMark: () => {}, onLink: () => {} }),
43
+ addKeyboardShortcuts() {
44
+ const editor = this.editor
45
+ const mark = (name: PageMark) => () => {
46
+ this.options.toggleMark(editor, name)
47
+ return true
48
+ }
49
+ const current = () => {
50
+ const at = wordsAt(editor.state.selection)
51
+ if (at) return at
52
+ const { selection } = editor.state
53
+ return selection instanceof NodeSelection
54
+ ? { node: selection.node, pos: selection.from }
55
+ : null
56
+ }
57
+ return {
58
+ Enter: () => enter(editor),
59
+ "Shift-Enter": () => lineBreak(editor),
60
+ Backspace: () => backspace(editor),
61
+ Delete: () => forwardDelete(editor),
62
+ // The body is the editor, so the browser would scroll the whole page to its end as well.
63
+ Home: () => toLineEdge(editor, "backward", false),
64
+ End: () => toLineEdge(editor, "forward", false),
65
+ "Shift-Home": () => toLineEdge(editor, "backward", true),
66
+ "Shift-End": () => toLineEdge(editor, "forward", true),
67
+ Tab: () => nextCell(editor, 1),
68
+ "Shift-Tab": () => nextCell(editor, -1),
69
+ "Mod-b": mark("bold"),
70
+ "Mod-i": mark("italic"),
71
+ "Mod-u": mark("underline"),
72
+ "Mod-Shift-s": mark("strike"),
73
+ "Mod-e": mark("code"),
74
+ "Mod-k": () => {
75
+ if (editor.state.selection.empty) return false
76
+ this.options.onLink()
77
+ return true
78
+ },
79
+ "Mod-d": () => {
80
+ const at = current()
81
+ return at ? duplicate(editor, at.pos) : false
82
+ },
83
+ "Alt-Shift-ArrowUp": () => {
84
+ const at = current()
85
+ if (at) move(editor, at.pos, -1)
86
+ return true
87
+ },
88
+ "Alt-Shift-ArrowDown": () => {
89
+ const at = current()
90
+ if (at) move(editor, at.pos, 1)
91
+ return true
92
+ },
93
+ }
94
+ },
95
+ })
96
+
97
+ /** Moves the caret, or extends the selection, to the start or end of the line it is on. */
98
+ function toLineEdge(editor: Editor, direction: "forward" | "backward", extend: boolean): boolean {
99
+ const selection = editor.view.dom.ownerDocument.getSelection()
100
+ if (!selection || typeof selection.modify !== "function") return false
101
+ selection.modify(extend ? "extend" : "move", direction, "lineboundary")
102
+ return true
103
+ }
104
+
105
+ function lineBreak(editor: Editor): boolean {
106
+ const at = wordsAt(editor.state.selection)
107
+ if (!at) return false
108
+ if (tagOf(at.node) === "pre") return editor.commands.insertContent("\n")
109
+ return editor.commands.insertContent({ type: "hardBreak" })
110
+ }
111
+
112
+ /**
113
+ * Enter: a new block after the one the caret is in, which takes the words after the caret. In
114
+ * `<pre>`, a new line; in a cell or a caption, a line break. An empty list item ends its list.
115
+ */
116
+ function enter(editor: Editor): boolean {
117
+ if (!(editor.state.selection instanceof TextSelection)) return false
118
+ const first = wordsAt(editor.state.selection)
119
+ if (!first) return false
120
+ const tag = tagOf(first.node)
121
+ if (tag === "pre") return editor.commands.insertContent("\n")
122
+ if (SINGLE_BLOCK_TAGS.has(tag)) return lineBreak(editor)
123
+
124
+ const tr = editor.state.tr
125
+ if (!tr.selection.empty) tr.deleteSelection()
126
+ const at = wordsAt(tr.selection)
127
+ if (!at) return false
128
+ const { node, pos } = at
129
+ const $pos = tr.doc.resolve(pos)
130
+ const inList = tag === "li" && LIST_TAGS.has(tagOf($pos.parent))
131
+
132
+ if (node.content.size === 0) {
133
+ // An empty item ends its list, and an empty description its list of terms.
134
+ if (inList || ((tag === "dd" || tag === "dt") && tagOf($pos.parent) === "dl")) {
135
+ liftOut(tr, pos, words(editor.schema, "p"))
136
+ editor.view.dispatch(tr.scrollIntoView())
137
+ return true
138
+ }
139
+ // The last, empty, paragraph of an item that holds paragraphs: the next item, or, alone in
140
+ // its item, the end of the list.
141
+ const item = $pos.parent
142
+ const itemPos = $pos.depth > 0 ? $pos.before() : -1
143
+ const listOfItem = itemPos >= 0 ? tr.doc.resolve(itemPos).parent : null
144
+ if (
145
+ tagOf(item) === "li" &&
146
+ LIST_TAGS.has(tagOf(listOfItem)) &&
147
+ $pos.index() === item.childCount - 1
148
+ ) {
149
+ if (item.childCount === 1) {
150
+ liftOut(tr, itemPos, words(editor.schema, "p"))
151
+ } else {
152
+ tr.delete(pos, pos + node.nodeSize)
153
+ const after = tr.mapping.map(itemPos + item.nodeSize)
154
+ const open = typeof item.attrs.open === "string" ? withoutId(item.attrs.open, "li") : "<li>"
155
+ tr.insert(
156
+ after,
157
+ item.type.create({ ...item.attrs, open, before: null, end: null }, [
158
+ words(editor.schema, "p"),
159
+ ])
160
+ )
161
+ tr.setSelection(TextSelection.create(tr.doc, after + 2))
162
+ }
163
+ editor.view.dispatch(tr.scrollIntoView())
164
+ return true
165
+ }
166
+ }
167
+
168
+ const offset = tr.selection.$from.parentOffset
169
+ const open = typeof node.attrs.open === "string" ? withoutId(node.attrs.open, tag) : `<${tag}>`
170
+
171
+ // Within the last paragraph of an item that holds paragraphs, past its start: the next item
172
+ // takes the words after the caret, as in a list of words alone.
173
+ const item = $pos.depth > 0 ? $pos.parent : null
174
+ if (
175
+ item &&
176
+ offset > 0 &&
177
+ tagOf(item) === "li" &&
178
+ LIST_TAGS.has(tagOf(tr.doc.resolve($pos.before()).parent)) &&
179
+ $pos.index() === item.childCount - 1
180
+ ) {
181
+ const itemOpen = typeof item.attrs.open === "string" ? withoutId(item.attrs.open, "li") : "<li>"
182
+ tr.split(tr.selection.from, 2, [
183
+ { type: item.type, attrs: { ...item.attrs, open: itemOpen, before: null, end: null } },
184
+ { type: node.type, attrs: { ...node.attrs, open, before: null, inner: null } },
185
+ ])
186
+ editor.view.dispatch(tr.scrollIntoView())
187
+ return true
188
+ }
189
+ const next =
190
+ ENDS_IN_PARAGRAPH.has(tag) || (!inList && tag !== "dt" && tag !== "dd")
191
+ ? words(editor.schema, "p")
192
+ : words(editor.schema, tag, open)
193
+
194
+ if (offset === 0 && node.content.size > 0) {
195
+ // At the start of words: an empty block before them, which they keep their kind beside.
196
+ tr.insert(pos, ENDS_IN_PARAGRAPH.has(tag) ? words(editor.schema, "p") : copyOf(node, open))
197
+ } else if (offset === node.content.size) {
198
+ tr.insert(pos + node.nodeSize, next)
199
+ tr.setSelection(TextSelection.create(tr.doc, pos + node.nodeSize + 1))
200
+ } else {
201
+ // In the middle: the words after the caret go to a block like this one.
202
+ tr.split(tr.selection.from, 1, [
203
+ { type: node.type, attrs: { ...node.attrs, open, before: null, inner: null } },
204
+ ])
205
+ }
206
+ editor.view.dispatch(tr.scrollIntoView())
207
+ return true
208
+ }
209
+
210
+ /** An empty block of words like `node`, without its id. */
211
+ function copyOf(node: ProseMirrorNode, open: string): ProseMirrorNode {
212
+ return node.type.create({ ...node.attrs, open, before: null, inner: null })
213
+ }
214
+
215
+ /**
216
+ * Backspace at the start of a block of words: a heading or a quote becomes a paragraph, a list's
217
+ * first item leaves the list, and what would merge across boxes of the design does nothing. An
218
+ * empty block after a picture or another block goes, and the caret with it.
219
+ */
220
+ function backspace(editor: Editor): boolean {
221
+ const { selection } = editor.state
222
+ if (!(selection instanceof TextSelection) || !selection.empty) return false
223
+ const at = wordsAt(selection)
224
+ if (!at || selection.$from.parentOffset > 0) return false
225
+ const { node, pos } = at
226
+ const tag = tagOf(node)
227
+ const $pos = editor.state.doc.resolve(pos)
228
+ const index = $pos.index()
229
+ const tr = editor.state.tr
230
+
231
+ if (ENDS_IN_PARAGRAPH.has(tag) && node.content.size > 0) {
232
+ tr.setNodeMarkup(pos, undefined, { ...node.attrs, tag: "p", open: "<p>", close: "</p>" })
233
+ editor.view.dispatch(tr)
234
+ return true
235
+ }
236
+ if (tag === "li" && LIST_TAGS.has(tagOf($pos.parent))) {
237
+ if (index > 0) return false
238
+ liftOut(tr, pos, words(editor.schema, "p", undefined, node.content))
239
+ editor.view.dispatch(tr.scrollIntoView())
240
+ return true
241
+ }
242
+ if (SINGLE_BLOCK_TAGS.has(tag)) return true
243
+
244
+ const previous = index > 0 ? $pos.parent.child(index - 1) : null
245
+ if (!previous) {
246
+ // The first block in its box: leaving it would merge it into what comes before.
247
+ if (node.content.size > 0 || $pos.depth === 0 || $pos.parent.childCount === 1) return true
248
+ tr.delete(pos, pos + node.nodeSize)
249
+ tr.setSelection(Selection.near(tr.doc.resolve(pos), -1))
250
+ editor.view.dispatch(tr.scrollIntoView())
251
+ return true
252
+ }
253
+ if (previous.type.name === "textBlock") return false
254
+
255
+ const previousPos = pos - previous.nodeSize
256
+ if (node.content.size === 0) {
257
+ tr.delete(pos, pos + node.nodeSize)
258
+ tr.setSelection(
259
+ previous.isAtom
260
+ ? NodeSelection.create(tr.doc, previousPos)
261
+ : Selection.near(tr.doc.resolve(pos), -1)
262
+ )
263
+ } else if (previous.isAtom) {
264
+ tr.setSelection(NodeSelection.create(tr.doc, previousPos))
265
+ } else {
266
+ tr.setSelection(Selection.near(tr.doc.resolve(pos), -1))
267
+ }
268
+ editor.view.dispatch(tr.scrollIntoView())
269
+ return true
270
+ }
271
+
272
+ /** Delete at the end of a block of words, as Backspace at the start of the next. */
273
+ function forwardDelete(editor: Editor): boolean {
274
+ const { selection } = editor.state
275
+ if (!(selection instanceof TextSelection) || !selection.empty) return false
276
+ const at = wordsAt(selection)
277
+ if (!at || selection.$from.parentOffset < at.node.content.size) return false
278
+ if (SINGLE_BLOCK_TAGS.has(tagOf(at.node))) return true
279
+ const $pos = editor.state.doc.resolve(at.pos)
280
+ const next = $pos.parent.maybeChild($pos.index() + 1)
281
+ // The last block in its box, or before something that is not words: nothing merges.
282
+ if (!next) return true
283
+ if (next.type.name !== "textBlock") {
284
+ const after = at.pos + at.node.nodeSize
285
+ const tr = editor.state.tr
286
+ if (at.node.content.size === 0) tr.delete(at.pos, after)
287
+ else if (next.isAtom) tr.setSelection(NodeSelection.create(tr.doc, after))
288
+ editor.view.dispatch(tr.scrollIntoView())
289
+ return true
290
+ }
291
+ return false
292
+ }
293
+
294
+ /** Tab in a table moves to the next cell, Shift-Tab to the one before; elsewhere it stays put. */
295
+ function nextCell(editor: Editor, by: -1 | 1): boolean {
296
+ const at = wordsAt(editor.state.selection)
297
+ const tag = tagOf(at?.node)
298
+ // Out of a table, Tab leaves the frame, as it leaves any field.
299
+ if (!at || (tag !== "td" && tag !== "th")) return false
300
+ const cells: number[] = []
301
+ const $pos = editor.state.doc.resolve(at.pos)
302
+ let tableDepth = 0
303
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
304
+ if (tagOf($pos.node(depth)) === "table") tableDepth = depth
305
+ }
306
+ if (tableDepth === 0) return true
307
+ const table = $pos.node(tableDepth)
308
+ const start = $pos.start(tableDepth)
309
+ table.descendants((node, offset) => {
310
+ if (node.type.name === "textBlock" && (tagOf(node) === "td" || tagOf(node) === "th")) {
311
+ cells.push(start + offset)
312
+ }
313
+ return node.type.name !== "textBlock"
314
+ })
315
+ const target = cells[cells.indexOf(at.pos) + by]
316
+ if (target === undefined) return true
317
+ const cell = editor.state.doc.nodeAt(target) as ProseMirrorNode
318
+ const tr = editor.state.tr.setSelection(
319
+ TextSelection.create(editor.state.doc, target + 1, target + 1 + cell.content.size)
320
+ )
321
+ editor.view.dispatch(tr.scrollIntoView())
322
+ return true
323
+ }
@@ -0,0 +1,151 @@
1
+ // What the app and a designed document's editor in its frame say to each other, through the port
2
+ // the app hands the frame with the `editor` request, where the page's own scripts never post.
3
+ //
4
+ // app ── start ────▶ frame the live document's state, the page's path, the blocks it offers
5
+ // ── update ───▶ what changed in the live document, from others or the Agent
6
+ // ── awareness ▶ where everyone else's carets are
7
+ // ── run ──────▶ what the reader chose in the app's menus and toolbar
8
+ // ◀─ update ─── what the reader changed
9
+ // ◀─ cursor ─── where the reader's caret is, for everyone else
10
+ // ◀─ selection, slash, hover, drop what the app draws over the frame, in its coordinates
11
+ // ◀─ upload ─── pictures the reader pasted or dropped, for the app to store
12
+ //
13
+ // The frame keeps a copy of the live document and edits it with TipTap, as a Markdown document is
14
+ // edited, so the two stay in step by Yjs updates alone. Everything the reader sees around the
15
+ // page, menus and toolbars and the block handle, the app draws, in its own design.
16
+
17
+ /** The kinds of block the editor makes, as the `/` menu and "Turn into" offer them. */
18
+ export type PageBlockId =
19
+ | "paragraph"
20
+ | "heading1"
21
+ | "heading2"
22
+ | "heading3"
23
+ | "bulletList"
24
+ | "orderedList"
25
+ | "quote"
26
+ | "table"
27
+ | "image"
28
+ | "divider"
29
+ | "pageBreak"
30
+
31
+ /** A kind of block, as the frame finds it by what the reader types after `/`. */
32
+ export interface PageBlockChoice {
33
+ readonly id: PageBlockId
34
+ readonly label: string
35
+ readonly keywords: readonly string[]
36
+ }
37
+
38
+ /** A rectangle in the frame's viewport, which is where the app's overlay draws. */
39
+ export interface EditorRect {
40
+ readonly left: number
41
+ readonly top: number
42
+ readonly right: number
43
+ readonly bottom: number
44
+ }
45
+
46
+ /** The marks of selected words the toolbar shows. */
47
+ export type PageMark = "bold" | "italic" | "underline" | "strike" | "code"
48
+
49
+ export type EditorCommand =
50
+ | { readonly name: "mark"; readonly mark: PageMark }
51
+ | { readonly name: "link"; readonly href: string | null }
52
+ | { readonly name: "turnInto"; readonly block: PageBlockId; readonly pos?: number }
53
+ /** Chooses the `/` menu's item at `index`, as Enter does. */
54
+ | { readonly name: "choose"; readonly index: number }
55
+ /** Points the `/` menu at its item at `index`, as the arrows do. */
56
+ | { readonly name: "point"; readonly index: number }
57
+ | { readonly name: "closeMenu" }
58
+ /** Adds a paragraph below the block at `pos` and opens the `/` menu in it. */
59
+ | { readonly name: "addBelow"; readonly pos: number }
60
+ | { readonly name: "duplicate"; readonly pos: number }
61
+ | { readonly name: "remove"; readonly pos: number }
62
+ | { readonly name: "move"; readonly pos: number; readonly by: -1 | 1 }
63
+ /** Picks the block at `pos` whole, as its handle's menu acts on it. */
64
+ | { readonly name: "pick"; readonly pos: number }
65
+ /** A drag of the block at `pos` by its handle, the pointer at `x`, `y`. */
66
+ | { readonly name: "drag"; readonly pos: number; readonly x: number; readonly y: number }
67
+ | { readonly name: "drop"; readonly pos: number; readonly x: number; readonly y: number }
68
+ | { readonly name: "endDrag" }
69
+ /**
70
+ * A picture the app stored for the reader, at the path its source names; `preview` shows it
71
+ * until a version of the document holds it.
72
+ */
73
+ | {
74
+ readonly name: "image"
75
+ readonly src: string
76
+ readonly alt: string
77
+ readonly at?: number
78
+ readonly preview?: Blob
79
+ }
80
+ | { readonly name: "focus" }
81
+
82
+ export type AppToEditor =
83
+ | {
84
+ readonly type: "start"
85
+ /** The live document, as `Y.encodeStateAsUpdate` encodes it. */
86
+ readonly state: Uint8Array
87
+ readonly path: string
88
+ readonly editable: boolean
89
+ readonly blocks: readonly PageBlockChoice[]
90
+ /** Words the editor shows itself, in the reader's language. */
91
+ readonly words: EditorWords
92
+ }
93
+ | { readonly type: "update"; readonly update: Uint8Array }
94
+ | { readonly type: "awareness"; readonly update: Uint8Array }
95
+ | { readonly type: "editable"; readonly editable: boolean }
96
+ | { readonly type: "run"; readonly command: EditorCommand }
97
+
98
+ export interface EditorWords {
99
+ readonly placeholder: string
100
+ readonly listItem: string
101
+ /** An empty heading's placeholder, by level from 1. */
102
+ readonly headings: readonly string[]
103
+ readonly pageBreak: string
104
+ }
105
+
106
+ /** What the toolbar over selected words shows; null when no words are selected. */
107
+ export interface SelectionState {
108
+ readonly rect: EditorRect
109
+ readonly marks: Readonly<Record<PageMark, boolean>>
110
+ readonly link: string | null
111
+ readonly block: PageBlockId | null
112
+ /** Whether the words' block may be turned into another kind: not a cell or a caption. */
113
+ readonly turnable: boolean
114
+ }
115
+
116
+ /** The `/` menu: where the `/` is, the kinds of block that match what follows it, the one pointed at. */
117
+ export interface SlashState {
118
+ readonly rect: EditorRect
119
+ readonly items: readonly PageBlockId[]
120
+ readonly index: number
121
+ }
122
+
123
+ /** The block the pointer is over, which the handle sits beside. */
124
+ export interface HoverState {
125
+ readonly pos: number
126
+ readonly rect: EditorRect
127
+ /** Whether "Turn into" changes it: words that stand where any block may. */
128
+ readonly textual: boolean
129
+ }
130
+
131
+ export type EditorToApp =
132
+ | { readonly type: "ready" }
133
+ /** The page is no longer one the editor holds: the live document holds it as text now. */
134
+ | { readonly type: "gone" }
135
+ | { readonly type: "update"; readonly update: Uint8Array }
136
+ | { readonly type: "cursor"; readonly cursor: unknown }
137
+ | { readonly type: "focus"; readonly focused: boolean }
138
+ | { readonly type: "selection"; readonly selection: SelectionState | null }
139
+ | { readonly type: "slash"; readonly slash: SlashState | null }
140
+ | { readonly type: "hover"; readonly hover: HoverState | null }
141
+ /** Where a block dragged by its handle would land: a line across the page. */
142
+ | { readonly type: "drop"; readonly line: EditorRect | null }
143
+ /** ⌘K over selected words: the app opens the toolbar's link field. */
144
+ | { readonly type: "linkRequest" }
145
+ /** Pictures the reader pasted or dropped, to add at the block at `at`. */
146
+ | { readonly type: "upload"; readonly files: readonly File[]; readonly at: number | null }
147
+ /** The reader chose a picture from the `/` menu: the app asks them for the file. */
148
+ | { readonly type: "pickImage"; readonly at: number | null }
149
+
150
+ /** The global the editor's script sets as it runs, which the frame's runtime takes at once. */
151
+ export const FRAME_EDITOR_GLOBAL = "__sixbFrameEditor"