@aionbuilders/nabu 0.1.0-beta.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/CHANGELOG.md +523 -0
  2. package/LICENSE +21 -0
  3. package/README.md +72 -341
  4. package/dist/behaviors/text/RichText.svelte +24 -4
  5. package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +3 -0
  6. package/dist/behaviors/text/markdown-shortcuts.extension.js +35 -10
  7. package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
  8. package/dist/behaviors/text/markdown-syntax.js +81 -0
  9. package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
  10. package/dist/behaviors/text/rich-text.extension.js +95 -38
  11. package/dist/behaviors/text/text.behavior.svelte.d.ts +199 -48
  12. package/dist/behaviors/text/text.behavior.svelte.js +549 -83
  13. package/dist/behaviors/text/typography.extension.d.ts +2 -1
  14. package/dist/behaviors/text/typography.extension.js +3 -2
  15. package/dist/blocks/BlockList.svelte +48 -0
  16. package/dist/blocks/BlockList.svelte.d.ts +17 -0
  17. package/dist/blocks/Nabu.svelte +169 -25
  18. package/dist/blocks/Nabu.svelte.d.ts +13 -0
  19. package/dist/blocks/block.extension.d.ts +3 -0
  20. package/dist/blocks/block.extension.js +4 -7
  21. package/dist/blocks/block.svelte.d.ts +350 -86
  22. package/dist/blocks/block.svelte.js +370 -59
  23. package/dist/blocks/blockquote/Blockquote.svelte +1 -2
  24. package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -1
  25. package/dist/blocks/blockquote/blockquote.extension.js +14 -5
  26. package/dist/blocks/blockquote/blockquote.svelte.d.ts +19 -11
  27. package/dist/blocks/blockquote/blockquote.svelte.js +58 -13
  28. package/dist/blocks/callout/Callout.svelte +6 -8
  29. package/dist/blocks/callout/callout.extension.d.ts +4 -1
  30. package/dist/blocks/callout/callout.extension.js +19 -3
  31. package/dist/blocks/callout/callout.svelte.d.ts +5 -3
  32. package/dist/blocks/callout/callout.svelte.js +11 -6
  33. package/dist/blocks/chunks.d.ts +49 -0
  34. package/dist/blocks/chunks.js +90 -0
  35. package/dist/blocks/code/Code.svelte +7 -8
  36. package/dist/blocks/code/code.extension.d.ts +4 -1
  37. package/dist/blocks/code/code.extension.js +22 -2
  38. package/dist/blocks/code/code.svelte.d.ts +9 -2
  39. package/dist/blocks/code/code.svelte.js +49 -25
  40. package/dist/blocks/container.utils.d.ts +85 -13
  41. package/dist/blocks/container.utils.js +338 -178
  42. package/dist/blocks/dialogue/Dialogue.svelte +8 -4
  43. package/dist/blocks/dialogue/dialogue.svelte.d.ts +33 -2
  44. package/dist/blocks/dialogue/dialogue.svelte.js +58 -4
  45. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
  46. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
  47. package/dist/blocks/dialogue/index.d.ts +12 -1
  48. package/dist/blocks/dialogue/index.js +51 -35
  49. package/dist/blocks/divider/divider.extension.d.ts +23 -1
  50. package/dist/blocks/divider/divider.extension.js +85 -19
  51. package/dist/blocks/divider/divider.svelte.d.ts +7 -2
  52. package/dist/blocks/divider/divider.svelte.js +9 -4
  53. package/dist/blocks/file/File.svelte +13 -6
  54. package/dist/blocks/file/file.extension.d.ts +4 -1
  55. package/dist/blocks/file/file.extension.js +9 -1
  56. package/dist/blocks/file/file.svelte.d.ts +3 -3
  57. package/dist/blocks/file/file.svelte.js +20 -14
  58. package/dist/blocks/heading/Heading.svelte +1 -2
  59. package/dist/blocks/heading/heading.svelte.d.ts +23 -11
  60. package/dist/blocks/heading/heading.svelte.js +68 -13
  61. package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
  62. package/dist/blocks/heading/index.d.ts +2 -2
  63. package/dist/blocks/heading/index.js +33 -8
  64. package/dist/blocks/image/Image.svelte +5 -2
  65. package/dist/blocks/image/image.extension.d.ts +4 -1
  66. package/dist/blocks/image/image.extension.js +9 -1
  67. package/dist/blocks/image/image.svelte.d.ts +17 -6
  68. package/dist/blocks/image/image.svelte.js +33 -11
  69. package/dist/blocks/index.d.ts +1 -1
  70. package/dist/blocks/index.js +1 -1
  71. package/dist/blocks/list/List.svelte +1 -0
  72. package/dist/blocks/list/ListItem.svelte +1 -0
  73. package/dist/blocks/list/convert.d.ts +20 -0
  74. package/dist/blocks/list/convert.js +92 -0
  75. package/dist/blocks/list/hooks/onBeforeInput.hook.js +49 -28
  76. package/dist/blocks/list/html-flat.d.ts +78 -0
  77. package/dist/blocks/list/html-flat.js +244 -0
  78. package/dist/blocks/list/indent.d.ts +86 -0
  79. package/dist/blocks/list/indent.js +205 -0
  80. package/dist/blocks/list/index.d.ts +6 -3
  81. package/dist/blocks/list/index.js +42 -31
  82. package/dist/blocks/list/list-item.svelte.d.ts +31 -17
  83. package/dist/blocks/list/list-item.svelte.js +99 -100
  84. package/dist/blocks/list/list.behavior.svelte.d.ts +4 -1
  85. package/dist/blocks/list/list.behavior.svelte.js +6 -1
  86. package/dist/blocks/list/list.svelte.d.ts +89 -18
  87. package/dist/blocks/list/list.svelte.js +129 -125
  88. package/dist/blocks/list/markdown.d.ts +149 -0
  89. package/dist/blocks/list/markdown.js +442 -0
  90. package/dist/blocks/list/normalize.d.ts +11 -0
  91. package/dist/blocks/list/normalize.js +396 -0
  92. package/dist/blocks/list/paste.d.ts +45 -0
  93. package/dist/blocks/list/paste.js +242 -0
  94. package/dist/blocks/list/step-back.d.ts +24 -0
  95. package/dist/blocks/list/step-back.js +87 -0
  96. package/dist/blocks/list/to-list.d.ts +7 -0
  97. package/dist/blocks/list/to-list.js +44 -0
  98. package/dist/blocks/list/todos-toggle.d.ts +20 -0
  99. package/dist/blocks/list/todos-toggle.js +48 -0
  100. package/dist/blocks/media/markdown.d.ts +12 -0
  101. package/dist/blocks/media/markdown.js +26 -0
  102. package/dist/blocks/media/media-block.svelte.d.ts +77 -2
  103. package/dist/blocks/media/media-block.svelte.js +124 -12
  104. package/dist/blocks/media/media.helpers.d.ts +6 -1
  105. package/dist/blocks/media/media.helpers.js +43 -6
  106. package/dist/blocks/megablock.svelte.d.ts +50 -19
  107. package/dist/blocks/megablock.svelte.js +114 -74
  108. package/dist/blocks/move.d.ts +23 -0
  109. package/dist/blocks/move.js +92 -0
  110. package/dist/blocks/nabu.svelte.d.ts +764 -71
  111. package/dist/blocks/nabu.svelte.js +1746 -189
  112. package/dist/blocks/paragraph/Paragraph.svelte +1 -2
  113. package/dist/blocks/paragraph/index.d.ts +2 -2
  114. package/dist/blocks/paragraph/index.js +35 -13
  115. package/dist/blocks/paragraph/paragraph.svelte.d.ts +46 -14
  116. package/dist/blocks/paragraph/paragraph.svelte.js +77 -16
  117. package/dist/blocks/paragraph/table.html.d.ts +9 -0
  118. package/dist/blocks/paragraph/table.html.js +111 -0
  119. package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
  120. package/dist/blocks/paragraph/table.markdown.js +90 -0
  121. package/dist/blocks/region/Region.svelte +264 -0
  122. package/dist/blocks/region/Region.svelte.d.ts +11 -0
  123. package/dist/blocks/region/actions.d.ts +135 -0
  124. package/dist/blocks/region/actions.js +402 -0
  125. package/dist/blocks/region/close.d.ts +35 -0
  126. package/dist/blocks/region/close.js +130 -0
  127. package/dist/blocks/region/commands.d.ts +6 -0
  128. package/dist/blocks/region/commands.js +277 -0
  129. package/dist/blocks/region/create.d.ts +72 -0
  130. package/dist/blocks/region/create.js +208 -0
  131. package/dist/blocks/region/end-marker.d.ts +35 -0
  132. package/dist/blocks/region/end-marker.js +51 -0
  133. package/dist/blocks/region/facts.d.ts +69 -0
  134. package/dist/blocks/region/facts.js +152 -0
  135. package/dist/blocks/region/format.d.ts +91 -0
  136. package/dist/blocks/region/format.js +260 -0
  137. package/dist/blocks/region/index.d.ts +14 -0
  138. package/dist/blocks/region/index.js +14 -0
  139. package/dist/blocks/region/insert.d.ts +59 -0
  140. package/dist/blocks/region/insert.js +102 -0
  141. package/dist/blocks/region/messages.d.ts +254 -0
  142. package/dist/blocks/region/messages.js +131 -0
  143. package/dist/blocks/region/normalize.d.ts +7 -0
  144. package/dist/blocks/region/normalize.js +170 -0
  145. package/dist/blocks/region/region.extension.d.ts +58 -0
  146. package/dist/blocks/region/region.extension.js +119 -0
  147. package/dist/blocks/region/region.svelte.d.ts +221 -0
  148. package/dist/blocks/region/region.svelte.js +582 -0
  149. package/dist/blocks/region/regions.svelte.d.ts +141 -0
  150. package/dist/blocks/region/regions.svelte.js +276 -0
  151. package/dist/blocks/region/serialize.d.ts +57 -0
  152. package/dist/blocks/region/serialize.js +112 -0
  153. package/dist/blocks/region/types.d.ts +255 -0
  154. package/dist/blocks/region/types.js +204 -0
  155. package/dist/blocks/selection.svelte.d.ts +106 -8
  156. package/dist/blocks/selection.svelte.js +622 -74
  157. package/dist/blocks/subthread.d.ts +80 -0
  158. package/dist/blocks/subthread.js +167 -0
  159. package/dist/blocks/text-block.svelte.d.ts +34 -13
  160. package/dist/blocks/text-block.svelte.js +42 -8
  161. package/dist/blocks/toggle/Toggle.svelte +4 -15
  162. package/dist/blocks/toggle/markdown.d.ts +20 -0
  163. package/dist/blocks/toggle/markdown.js +112 -0
  164. package/dist/blocks/toggle/toggle.extension.d.ts +4 -1
  165. package/dist/blocks/toggle/toggle.extension.js +6 -0
  166. package/dist/blocks/toggle/toggle.svelte.d.ts +54 -7
  167. package/dist/blocks/toggle/toggle.svelte.js +134 -34
  168. package/dist/blocks/undo-selection.d.ts +175 -0
  169. package/dist/blocks/undo-selection.js +360 -0
  170. package/dist/blocks/video/Video.svelte +5 -2
  171. package/dist/blocks/video/video.extension.d.ts +4 -1
  172. package/dist/blocks/video/video.extension.js +9 -1
  173. package/dist/blocks/video/video.svelte.d.ts +6 -5
  174. package/dist/blocks/video/video.svelte.js +18 -9
  175. package/dist/extend.d.ts +55 -0
  176. package/dist/extend.js +88 -0
  177. package/dist/files/assets.clipboard.d.ts +77 -0
  178. package/dist/files/assets.clipboard.js +152 -0
  179. package/dist/files/files.svelte.d.ts +321 -19
  180. package/dist/files/files.svelte.js +847 -43
  181. package/dist/files/index.d.ts +3 -1
  182. package/dist/files/index.js +3 -1
  183. package/dist/files/outbox.d.ts +69 -0
  184. package/dist/files/outbox.js +48 -0
  185. package/dist/files/status.d.ts +65 -0
  186. package/dist/files/status.js +87 -0
  187. package/dist/files/store.d.ts +97 -0
  188. package/dist/files/store.js +65 -0
  189. package/dist/files/uploads.svelte.d.ts +174 -0
  190. package/dist/files/uploads.svelte.js +504 -0
  191. package/dist/index.d.ts +68 -9
  192. package/dist/index.js +117 -10
  193. package/dist/nabu-theme.css +21 -1
  194. package/dist/paste/html.paste.d.ts +74 -3
  195. package/dist/paste/html.paste.js +550 -86
  196. package/dist/paste/markdown-inline.d.ts +86 -0
  197. package/dist/paste/markdown-inline.js +528 -0
  198. package/dist/paste/markdown.paste.d.ts +2 -8
  199. package/dist/paste/markdown.paste.js +78 -94
  200. package/dist/paste/nabu.paste.d.ts +3 -0
  201. package/dist/paste/nabu.paste.js +29 -3
  202. package/dist/paste/plain-text.paste.d.ts +2 -2
  203. package/dist/paste/plain-text.paste.js +3 -3
  204. package/dist/persistence/asset-store.d.ts +51 -0
  205. package/dist/persistence/asset-store.js +103 -0
  206. package/dist/persistence/autosave.d.ts +53 -0
  207. package/dist/persistence/autosave.js +62 -0
  208. package/dist/persistence/compact.d.ts +162 -0
  209. package/dist/persistence/compact.js +141 -0
  210. package/dist/persistence/history.d.ts +77 -0
  211. package/dist/persistence/history.js +176 -0
  212. package/dist/persistence/indexeddb.d.ts +190 -4
  213. package/dist/persistence/indexeddb.js +333 -29
  214. package/dist/persistence/merge.d.ts +38 -0
  215. package/dist/persistence/merge.js +36 -0
  216. package/dist/persistence/outbox.d.ts +25 -0
  217. package/dist/persistence/outbox.js +40 -0
  218. package/dist/persistence/persistence.d.ts +70 -9
  219. package/dist/persistence/persistence.js +507 -35
  220. package/dist/persistence/recovery.d.ts +79 -0
  221. package/dist/persistence/recovery.js +79 -0
  222. package/dist/persistence/release.d.ts +34 -0
  223. package/dist/persistence/release.js +64 -0
  224. package/dist/persistence/state.svelte.d.ts +53 -0
  225. package/dist/persistence/state.svelte.js +48 -0
  226. package/dist/persistence/sync.d.ts +39 -0
  227. package/dist/persistence/sync.js +138 -0
  228. package/dist/persistence/tail.d.ts +42 -0
  229. package/dist/persistence/tail.js +103 -0
  230. package/dist/presets.d.ts +29 -26
  231. package/dist/presets.js +35 -13
  232. package/dist/themes/atelier.css +318 -0
  233. package/dist/ui/CommandChooser.svelte +153 -0
  234. package/dist/ui/CommandChooser.svelte.d.ts +13 -0
  235. package/dist/ui/CommandInvite.svelte +99 -0
  236. package/dist/ui/CommandInvite.svelte.d.ts +12 -0
  237. package/dist/ui/DragHandle.svelte +97 -21
  238. package/dist/ui/FloatingToolbar.svelte +75 -27
  239. package/dist/ui/FloatingToolbar.svelte.d.ts +10 -0
  240. package/dist/ui/SlashMenu.svelte +147 -15
  241. package/dist/ui/SlashMenu.svelte.d.ts +20 -0
  242. package/dist/ui/anchor.d.ts +112 -0
  243. package/dist/ui/anchor.js +136 -0
  244. package/dist/ui/index.d.ts +7 -1
  245. package/dist/ui/index.js +12 -1
  246. package/dist/ui/slash-menu.svelte.d.ts +79 -7
  247. package/dist/ui/slash-menu.svelte.js +85 -51
  248. package/dist/utils/command-confirm.svelte.d.ts +349 -0
  249. package/dist/utils/command-confirm.svelte.js +673 -0
  250. package/dist/utils/commands.d.ts +328 -0
  251. package/dist/utils/commands.js +416 -0
  252. package/dist/utils/dom-scope.d.ts +14 -0
  253. package/dist/utils/dom-scope.js +20 -0
  254. package/dist/utils/drop.d.ts +160 -0
  255. package/dist/utils/drop.js +305 -0
  256. package/dist/utils/extensions.d.ts +439 -45
  257. package/dist/utils/extensions.js +271 -29
  258. package/dist/utils/html.d.ts +44 -0
  259. package/dist/utils/html.js +183 -0
  260. package/dist/utils/index.d.ts +3 -0
  261. package/dist/utils/index.js +3 -0
  262. package/dist/utils/keys.d.ts +120 -0
  263. package/dist/utils/keys.js +248 -0
  264. package/dist/utils/links.d.ts +22 -0
  265. package/dist/utils/links.js +34 -0
  266. package/dist/utils/placeholders.d.ts +81 -3
  267. package/dist/utils/placeholders.js +73 -3
  268. package/dist/utils/selection.svelte.d.ts +47 -19
  269. package/dist/utils/selection.svelte.js +60 -10
  270. package/dist/utils/spellcheck.d.ts +9 -0
  271. package/dist/utils/spellcheck.js +17 -0
  272. package/dist/utils/tab.d.ts +31 -0
  273. package/dist/utils/tab.js +117 -0
  274. package/dist/utils/words.d.ts +7 -0
  275. package/dist/utils/words.js +62 -0
  276. package/dist/vite.d.ts +9 -3
  277. package/dist/vite.js +19 -8
  278. package/package.json +54 -20
  279. package/dist/blocks/variable.svelte.d.ts +0 -47
  280. package/dist/blocks/variable.svelte.js +0 -51
  281. package/dist/blocks/zone/TemplateEditor.svelte +0 -308
  282. package/dist/blocks/zone/TemplateEditor.svelte.d.ts +0 -11
  283. package/dist/blocks/zone/Zone.svelte +0 -272
  284. package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
  285. package/dist/blocks/zone/ZoneEditor.svelte +0 -289
  286. package/dist/blocks/zone/ZoneEditor.svelte.d.ts +0 -11
  287. package/dist/blocks/zone/ZoneTemplatesList.svelte +0 -188
  288. package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +0 -11
  289. package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +0 -3
  290. package/dist/blocks/zone/hooks/onBeforeInput.hook.js +0 -30
  291. package/dist/blocks/zone/index.d.ts +0 -2
  292. package/dist/blocks/zone/index.js +0 -2
  293. package/dist/blocks/zone/zone.extension.d.ts +0 -2
  294. package/dist/blocks/zone/zone.extension.js +0 -237
  295. package/dist/blocks/zone/zone.svelte.d.ts +0 -221
  296. package/dist/blocks/zone/zone.svelte.js +0 -608
  297. package/dist/overlays/context/Context.svelte +0 -182
  298. package/dist/overlays/context/Context.svelte.d.ts +0 -17
  299. package/dist/overlays/context/collect.d.ts +0 -17
  300. package/dist/overlays/context/collect.js +0 -33
  301. package/dist/overlays/context/context.extension.d.ts +0 -2
  302. package/dist/overlays/context/context.extension.js +0 -8
  303. package/dist/overlays/context/context.svelte.d.ts +0 -82
  304. package/dist/overlays/context/context.svelte.js +0 -159
  305. package/dist/overlays/context/index.d.ts +0 -3
  306. package/dist/overlays/context/index.js +0 -3
@@ -1,38 +1,69 @@
1
1
  /**
2
2
  * @import { Nabu, NabuNode } from "./nabu.svelte.js";
3
3
  */
4
+ /**
5
+ * A block that holds child blocks (a container): list, list item, toggle, region. It keeps its `children` in sync with the tree and delegates positions, word count and event handling to them.
6
+ */
4
7
  export class MegaBlock extends Block {
5
- /** @type {Block[]} */
6
- children: Block[];
7
- updateChildren(): void;
8
- /** @param {Block[]} children @param {number | null} [index] */
9
- adoptChildren(children: Block[], index?: number | null): void;
8
+ /**
9
+ * @type {Block[]}
10
+ * @public
11
+ */
12
+ public children: Block[];
13
+ /**
14
+ * @param {Set<string>} [retyped] ids whose `type` just changed; without it, the type of every child is checked
15
+ * @public
16
+ */
17
+ public updateChildren(retyped?: Set<string>): void;
18
+ /**
19
+ * @param {Block[]} children
20
+ * @param {number | null} [index]
21
+ * @public
22
+ */
23
+ public adoptChildren(children: Block[], index?: number | null): void;
10
24
  /**
11
25
  * Props to include in the clipboard representation of this container block.
12
- * Override in subclasses that carry structural props (e.g. List → { listType }).
26
+ * Override in subclasses that carry structural props (e.g. List -> { listType }, ListItem -> { checked },
27
+ * Toggle -> { collapsed }).
28
+ * @returns {Record<string, any>}
29
+ * @public
30
+ */
31
+ public get clipboardProps(): Record<string, any>;
32
+ /**
33
+ * Clipboard props when the copied slice starts at `firstChildIndex` (the children before it are NOT copied).
34
+ * Containers whose props depend on their first copied child (an ordered list's `start`) override this.
35
+ * @param {number} firstChildIndex
13
36
  * @returns {Record<string, any>}
37
+ * @public
14
38
  */
15
- get clipboardProps(): Record<string, any>;
39
+ public clipboardPropsFrom(firstChildIndex: number): Record<string, any>;
16
40
  /**
17
- * Serializes the portion of this MegaBlock that falls within the given
18
- * selection boundaries, recursively.
41
+ * Serializes the portion of this MegaBlock that falls within the given selection boundaries, recursively.
19
42
  *
20
- * For hybrid blocks (MegaBlock + text behavior, like ListItem):
21
- * if startBlock or endBlock IS this block, serialize text directly.
22
- * if neither boundary is set, this block is fully selected — serialize all text.
43
+ * The context carries the selection boundary blocks that belong to THIS subtree (`startBlock` / `endBlock`, null =
44
+ * the selection extends past this block on that side, i.e. it is fully selected on that side). Document order of a
45
+ * block is: own text (hybrid blocks only), then its children. So:
46
+ * - own text is copied unless the selection starts inside a child; it is clipped to `startFrom` when this block IS
47
+ * the start boundary, and to `endTo` when it IS the end boundary;
48
+ * - children are copied unless the selection ends in the own text; only those between the child holding the start
49
+ * boundary and the child holding the end boundary (inclusive) are kept, each one recursively clipped.
50
+ * A pure container (no text) simply has no own-text part. Nothing here depends on a concrete block type.
23
51
  *
24
- * For pure containers (like List):
25
- * find direct children that contain/are the boundaries, slice children in range,
26
- * recurse into each with propagated context.
52
+ * With `textOnly` (the context of a TEXT selection: copy, cut, drag), a block that ISOLATES its text (`isolatesSelection`) is
53
+ * transparent to a selection that is not entirely inside it: its own text is not copied and its container is not created, its
54
+ * selected children are returned directly (an ARRAY, to be spliced in the list of its siblings). Without it (the structure of
55
+ * a whole block), the container is serialized as it is.
27
56
  *
28
- * @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null }} [ctx]
29
- * @returns {import('../utils/extensions.js').PasteBlock | null}
57
+ * @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null, textOnly?: boolean }} [ctx]
58
+ * @returns {import('../utils/extensions.js').PasteBlock | import('../utils/extensions.js').PasteBlock[] | null}
59
+ * @public
30
60
  */
31
- serializeForClipboard({ startBlock, startFrom, endBlock, endTo }?: {
61
+ public serializeForClipboard({ startBlock, startFrom, endBlock, endTo, textOnly }?: {
32
62
  startBlock?: Block | null;
33
63
  startFrom?: number;
34
64
  endBlock?: Block | null;
35
65
  endTo?: number | null;
36
- }): import("../utils/extensions.js").PasteBlock | null;
66
+ textOnly?: boolean;
67
+ }): import("../utils/extensions.js").PasteBlock | import("../utils/extensions.js").PasteBlock[] | null;
37
68
  }
38
69
  import { Block } from "./block.svelte.js";
@@ -5,6 +5,9 @@ import { handleContainerBeforeInput, findDirectChildOf } from "./container.utils
5
5
  * @import { Nabu, NabuNode } from "./nabu.svelte.js";
6
6
  */
7
7
 
8
+ /**
9
+ * A block that holds child blocks (a container): list, list item, toggle, region. It keeps its `children` in sync with the tree and delegates positions, word count and event handling to them.
10
+ */
8
11
  export class MegaBlock extends Block {
9
12
 
10
13
  /** @param {Nabu} nabu @param {NabuNode} node */
@@ -13,15 +16,21 @@ export class MegaBlock extends Block {
13
16
  this.updateChildren();
14
17
  }
15
18
 
16
- /** @type {Block[]} */
19
+ /**
20
+ * @type {Block[]}
21
+ * @public
22
+ */
17
23
  children = $state([]);
24
+ /** @public */
18
25
  positions = $derived(this.children.reduce((sum, child) => sum + (child.positions ?? 0), 0));
26
+ /** @public */
19
27
  wordCount = $derived(this.children.reduce((sum, c) => sum + (c.wordCount ?? 0), 0));
20
28
 
21
29
  /**
22
30
  * Pure container: no own text, delegate entirely to children.
23
31
  * @param {number} localOffset
24
32
  * @returns {{ block: Block, offset: number } | null}
33
+ * @public
25
34
  */
26
35
  resolveOffset(localOffset) {
27
36
  let remaining = localOffset;
@@ -35,20 +44,26 @@ export class MegaBlock extends Block {
35
44
  return last ? last.resolveOffset(Math.max(0, (last.positions ?? 1) - 1)) : null;
36
45
  }
37
46
 
38
- updateChildren() {
47
+ /**
48
+ * @param {Set<string>} [retyped] ids whose `type` just changed; without it, the type of every child is checked
49
+ * @public
50
+ */
51
+ updateChildren(retyped) {
39
52
  const childrenNodes = this.node.children();
40
53
  if (!childrenNodes) return;
41
54
  this.children = childrenNodes.map((childNode, i) => {
42
55
  const id = childNode.id.toString();
43
56
  let block = this.nabu.blocks.get(id);
44
- const currentType = childNode.data.get("type");
45
57
 
46
- if (!block || block.type !== currentType) {
47
- if (block) {
48
- this.nabu.blocks.delete(id);
49
- this.nabu.blocksByType.get(block.type)?.delete(block);
58
+ if (!block || !retyped || retyped.has(id)) {
59
+ const currentType = childNode.data.get("type");
60
+ if (!block || block.type !== currentType) {
61
+ if (block) {
62
+ this.nabu.blocks.delete(id);
63
+ this.nabu.blocksByType.get(block.type)?.delete(block);
64
+ }
65
+ block = Block.load(this.nabu, childNode);
50
66
  }
51
- block = Block.load(this.nabu, childNode);
52
67
  }
53
68
  block.parent = this;
54
69
  block.index = i;
@@ -57,7 +72,11 @@ export class MegaBlock extends Block {
57
72
  }
58
73
 
59
74
 
60
- /** @param {Block[]} children @param {number | null} [index] */
75
+ /**
76
+ * @param {Block[]} children
77
+ * @param {number | null} [index]
78
+ * @public
79
+ */
61
80
  adoptChildren(children, index = null) {
62
81
  // Reverse so that when index is specified, children are inserted in original
63
82
  // order (each insert at the same position pushes others down, so reverse of
@@ -70,92 +89,113 @@ export class MegaBlock extends Block {
70
89
  }
71
90
 
72
91
 
73
- /** @param {InputEvent} event */
92
+ /**
93
+ * @param {InputEvent} event
94
+ * @public
95
+ */
74
96
  beforeinput(event) {
75
97
  return handleContainerBeforeInput(this, this.nabu, event);
76
98
  }
77
99
 
78
100
  /**
79
101
  * Props to include in the clipboard representation of this container block.
80
- * Override in subclasses that carry structural props (e.g. List → { listType }).
102
+ * Override in subclasses that carry structural props (e.g. List -> { listType }, ListItem -> { checked },
103
+ * Toggle -> { collapsed }).
81
104
  * @returns {Record<string, any>}
105
+ * @public
82
106
  */
83
107
  get clipboardProps() { return {}; }
84
108
 
85
109
  /**
86
- * Serializes the portion of this MegaBlock that falls within the given
87
- * selection boundaries, recursively.
110
+ * Clipboard props when the copied slice starts at `firstChildIndex` (the children before it are NOT copied).
111
+ * Containers whose props depend on their first copied child (an ordered list's `start`) override this.
112
+ * @param {number} firstChildIndex
113
+ * @returns {Record<string, any>}
114
+ * @public
115
+ */
116
+ clipboardPropsFrom(firstChildIndex) { return this.clipboardProps; }
117
+
118
+ /**
119
+ * Serializes the portion of this MegaBlock that falls within the given selection boundaries, recursively.
88
120
  *
89
- * For hybrid blocks (MegaBlock + text behavior, like ListItem):
90
- * if startBlock or endBlock IS this block, serialize text directly.
91
- * if neither boundary is set, this block is fully selected — serialize all text.
121
+ * The context carries the selection boundary blocks that belong to THIS subtree (`startBlock` / `endBlock`, null =
122
+ * the selection extends past this block on that side, i.e. it is fully selected on that side). Document order of a
123
+ * block is: own text (hybrid blocks only), then its children. So:
124
+ * - own text is copied unless the selection starts inside a child; it is clipped to `startFrom` when this block IS
125
+ * the start boundary, and to `endTo` when it IS the end boundary;
126
+ * - children are copied unless the selection ends in the own text; only those between the child holding the start
127
+ * boundary and the child holding the end boundary (inclusive) are kept, each one recursively clipped.
128
+ * A pure container (no text) simply has no own-text part. Nothing here depends on a concrete block type.
92
129
  *
93
- * For pure containers (like List):
94
- * find direct children that contain/are the boundaries, slice children in range,
95
- * recurse into each with propagated context.
130
+ * With `textOnly` (the context of a TEXT selection: copy, cut, drag), a block that ISOLATES its text (`isolatesSelection`) is
131
+ * transparent to a selection that is not entirely inside it: its own text is not copied and its container is not created, its
132
+ * selected children are returned directly (an ARRAY, to be spliced in the list of its siblings). Without it (the structure of
133
+ * a whole block), the container is serialized as it is.
96
134
  *
97
- * @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null }} [ctx]
98
- * @returns {import('../utils/extensions.js').PasteBlock | null}
135
+ * @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null, textOnly?: boolean }} [ctx]
136
+ * @returns {import('../utils/extensions.js').PasteBlock | import('../utils/extensions.js').PasteBlock[] | null}
137
+ * @public
99
138
  */
100
- serializeForClipboard({ startBlock = null, startFrom = 0, endBlock = null, endTo = null } = {}) {
139
+ serializeForClipboard({ startBlock = null, startFrom = 0, endBlock = null, endTo = null, textOnly = false } = {}) {
101
140
  const tb = this.behaviors?.get('text');
102
141
  const imStart = startBlock === this;
103
142
  const imEnd = endBlock === this;
104
-
105
- // ── Hybrid block (has text): this block IS a selection boundary or fully selected ──
106
- if (tb && (imStart || imEnd || (!startBlock && !endBlock))) {
143
+ const childOfThis = (/** @type {Block|null} */ block) => {
144
+ for (let cur = block; cur; cur = cur.parent ?? null) if (cur.parent === this) return cur;
145
+ return null;
146
+ };
147
+ const startChild = startBlock && !imStart ? childOfThis(startBlock) : null;
148
+ const endChild = endBlock && !imEnd ? childOfThis(endBlock) : null;
149
+
150
+ const isolated = textOnly && this.isolatesSelection && !(imStart && imEnd);
151
+ const textIncluded = !!tb && !startChild && !isolated;
152
+ const childrenIncluded = !imEnd && !!this.children?.length;
153
+ if (!textIncluded && imEnd) return null;
154
+
155
+ // ── Own text ──
156
+ /** @type {import('../utils/extensions.js').PasteBlock | null} */
157
+ let result = null;
158
+ if (tb && textIncluded) {
159
+ const length = tb.container.length;
107
160
  const from = imStart ? startFrom : 0;
108
- const to = imEnd ? endTo : tb.container.length;
161
+ const to = imEnd ? (endTo ?? length) : length;
109
162
  const partial = imStart && imEnd ? 'both' : imStart ? 'start' : imEnd ? 'end' : false;
110
- const delta = tb.container.sliceDelta(from, to ?? tb.container.length);
111
- const result = /** @type {import('../utils/extensions.js').PasteBlock} */ (
112
- { type: this.type, props: this.clipboardProps, partial, delta }
163
+ result = /** @type {import('../utils/extensions.js').PasteBlock} */ (
164
+ { type: this.type, props: this.clipboardProps, partial, delta: tb.container.sliceDelta(from, to) }
113
165
  );
114
- // If fully selected and has children (e.g. ListItem with sublist), include them too
115
- if (!imStart && !imEnd && this.children?.length) {
116
- const childrenSerialized = this.children.map(child =>
117
- typeof child.serializeForClipboard === 'function'
118
- ? child.serializeForClipboard({})
119
- : child.serialize('application/x-nabu+json', { partial: false })
120
- ).filter(Boolean);
121
- if (childrenSerialized.length) result.children = childrenSerialized;
122
- }
123
- return result;
124
166
  }
125
167
 
126
- // ── Pure container: find relevant children by walking up from boundaries ──
127
- if (!this.children?.length) return null;
128
-
129
- const sc = (startBlock ? findDirectChildOf(startBlock, this) : null) ?? this.children[0];
130
- const ec = (endBlock ? findDirectChildOf(endBlock, this) : null) ?? this.children.at(-1);
131
- if (!sc || !ec) return null;
132
-
133
- const si = this.children.indexOf(sc);
134
- const ei = this.children.indexOf(ec);
135
- if (si === -1 || ei === -1) return null;
136
-
137
- const relevant = this.children.slice(si, ei + 1);
138
- const lastI = relevant.length - 1;
139
-
140
- const children = relevant.map((child, i) => {
141
- const isFirst = i === 0;
142
- const isLast = i === lastI;
143
- const childCtx = {
144
- startBlock: isFirst ? startBlock : null,
145
- startFrom: isFirst ? startFrom : 0,
146
- endBlock: isLast ? endBlock : null,
147
- endTo: isLast ? endTo : null,
148
- };
149
- if (typeof child.serializeForClipboard === 'function') {
150
- return child.serializeForClipboard(childCtx);
151
- }
152
- return child.serialize('application/x-nabu+json', {
153
- from: isFirst && startBlock ? startFrom : 0,
154
- to: isLast && endBlock ? endTo : null,
155
- partial: isFirst && isLast ? 'both' : isFirst ? 'start' : isLast ? 'end' : false,
156
- });
157
- }).filter(Boolean);
158
-
159
- return children.length ? { type: this.type, props: this.clipboardProps, children } : null;
168
+ // ── Children inside the selection ──
169
+ /** @type {any[]} */
170
+ let kids = [];
171
+ let firstIndex = 0;
172
+ if (childrenIncluded) {
173
+ const si = startChild ? this.children.indexOf(/** @type {Block} */ (startChild)) : 0;
174
+ const ei = endChild ? this.children.indexOf(/** @type {Block} */ (endChild)) : this.children.length - 1;
175
+ if (si === -1 || ei === -1 || si > ei) return result;
176
+ firstIndex = si;
177
+ const relevant = this.children.slice(si, ei + 1);
178
+ const lastI = relevant.length - 1;
179
+ kids = relevant.map((child, i) => {
180
+ const cs = i === 0 && startChild ? startBlock : null;
181
+ const ce = i === lastI && endChild ? endBlock : null;
182
+ const mb = /** @type {any} */ (child);
183
+ if (typeof mb.serializeForClipboard === 'function') {
184
+ return mb.serializeForClipboard({ startBlock: cs, startFrom: cs ? startFrom : 0, endBlock: ce, endTo: ce ? endTo : null, textOnly });
185
+ }
186
+ return child.serialize('application/x-nabu+json', {
187
+ from: cs ? startFrom : 0,
188
+ to: ce ? endTo : null,
189
+ partial: cs && ce ? 'both' : cs ? 'start' : ce ? 'end' : false,
190
+ });
191
+ }).flat().filter(Boolean);
192
+ }
193
+
194
+ if (result) {
195
+ if (kids.length) result.children = kids;
196
+ return result;
197
+ }
198
+ if (isolated) return /** @type {import('../utils/extensions.js').PasteBlock[]} */ (kids);
199
+ return kids.length ? { type: this.type, props: this.clipboardPropsFrom(firstIndex), children: kids } : null;
160
200
  }
161
- }
201
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The run of sibling blocks a selection covers: `{ siblings, from, to }` (indexes in `siblings`, `from <= to`).
3
+ * @param {Block} a one end of the selection
4
+ * @param {Block} b the other end (the same block for a caret)
5
+ * @param {Nabu} nabu
6
+ * @returns {{ siblings: Block[], from: number, to: number } | null}
7
+ */
8
+ export function siblingRun(a: Block, b: Block, nabu: Nabu): {
9
+ siblings: Block[];
10
+ from: number;
11
+ to: number;
12
+ } | null;
13
+ /**
14
+ * Move the selected blocks (or `data.block`) one step among their siblings.
15
+ * @param {Nabu} nabu
16
+ * @param {'up' | 'down'} direction
17
+ * @param {Block | string | null} [target] a block (or its id) to move instead of the selected ones
18
+ * @returns {Promise<boolean> | boolean} `false` = nothing to act on (no selection in the editor): the key is not handled;
19
+ * otherwise a promise of `true` (handled, also when the block already is at the edge and nothing moved)
20
+ */
21
+ export function moveBlocks(nabu: Nabu, direction: "up" | "down", target?: Block | string | null): Promise<boolean> | boolean;
22
+ import type { Block } from './block.svelte.js';
23
+ import type { Nabu } from './nabu.svelte.js';
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Keyboard block moves (`block:move-up` / `block:move-down`, P-80): the keyboard alternative to dragging (WCAG 2.5.7).
3
+ *
4
+ * Generic: it names no block type. The blocks that move are the SIBLINGS of one parent (the root, or a container's children):
5
+ * - the caret in a block moves that block; a list item moves among the items of its list, with its sub-lists;
6
+ * - a selection moves the whole contiguous run of its top-most blocks together: the blocks covered by the selection, taken at
7
+ * the level of the deepest container that holds both ends (a container selected from its own text to a descendant moves as
8
+ * one block);
9
+ * - one step at a time; at the edge of the parent nothing moves (leaving a container is a structural decision of its own:
10
+ * indent / outdent for lists, drag for the rest) and the key is still consumed;
11
+ * - one undo step; the selection stays on the same characters.
12
+ *
13
+ * @import { Nabu } from './nabu.svelte.js'
14
+ * @import { Block } from './block.svelte.js'
15
+ */
16
+
17
+ import { tick } from 'svelte';
18
+ import { livePoints, placePoints, revealFocus } from './undo-selection.js';
19
+
20
+ /**
21
+ * The run of sibling blocks a selection covers: `{ siblings, from, to }` (indexes in `siblings`, `from <= to`).
22
+ * @param {Block} a one end of the selection
23
+ * @param {Block} b the other end (the same block for a caret)
24
+ * @param {Nabu} nabu
25
+ * @returns {{ siblings: Block[], from: number, to: number } | null}
26
+ */
27
+ export function siblingRun(a, b, nabu) {
28
+ /** @param {Block} block @returns {Block[]} root first */
29
+ const chain = (block) => {
30
+ /** @type {Block[]} */
31
+ const out = [];
32
+ for (let x = /** @type {Block | null} */ (block); x; x = /** @type {Block | null} */ (x.parent)) out.unshift(x);
33
+ return out;
34
+ };
35
+ const ca = chain(a);
36
+ const cb = chain(b);
37
+ let k = 0;
38
+ while (k < ca.length && k < cb.length && ca[k] === cb[k]) k++;
39
+ // One end holds the other (or they are the same block): that block moves as a whole.
40
+ if (k > 0 && (k === ca.length || k === cb.length)) {
41
+ const whole = ca[k - 1];
42
+ const siblings = /** @type {Block[]} */ (whole.parent ? /** @type {any} */ (whole.parent).children : nabu.children);
43
+ const at = siblings.indexOf(whole);
44
+ return at < 0 ? null : { siblings, from: at, to: at };
45
+ }
46
+ const siblings = /** @type {Block[]} */ (k === 0 ? nabu.children : /** @type {any} */ (ca[k - 1]).children);
47
+ const i = siblings.indexOf(ca[k]);
48
+ const j = siblings.indexOf(cb[k]);
49
+ if (i < 0 || j < 0) return null;
50
+ return { siblings, from: Math.min(i, j), to: Math.max(i, j) };
51
+ }
52
+
53
+ /**
54
+ * Move the selected blocks (or `data.block`) one step among their siblings.
55
+ * @param {Nabu} nabu
56
+ * @param {'up' | 'down'} direction
57
+ * @param {Block | string | null} [target] a block (or its id) to move instead of the selected ones
58
+ * @returns {Promise<boolean> | boolean} `false` = nothing to act on (no selection in the editor): the key is not handled;
59
+ * otherwise a promise of `true` (handled, also when the block already is at the edge and nothing moved)
60
+ */
61
+ export function moveBlocks(nabu, direction, target = null) {
62
+ const given = typeof target === 'string' ? nabu.blocks.get(target) : target;
63
+ const a = given ?? nabu.selection.anchorBlock ?? nabu.selection.focusBlock ?? null;
64
+ const b = given ?? nabu.selection.focusBlock ?? a;
65
+ if (!a || !b) return false;
66
+ const run = siblingRun(a, b, nabu);
67
+ if (!run) return false;
68
+ const { siblings, from, to } = run;
69
+ const edge = direction === 'up' ? siblings[from - 1] : siblings[to + 1];
70
+ if (!edge) return Promise.resolve(true);
71
+ return perform(nabu, () => {
72
+ // Moving the ONE neighbour past the run is the same order as moving the run, in a single tree operation, and the
73
+ // selected blocks keep their elements.
74
+ if (direction === 'up') edge.node.moveAfter(siblings[to].node);
75
+ else edge.node.moveBefore(siblings[from].node);
76
+ });
77
+ }
78
+
79
+ /**
80
+ * @param {Nabu} nabu
81
+ * @param {() => void} mutate
82
+ * @returns {Promise<boolean>}
83
+ */
84
+ async function perform(nabu, mutate) {
85
+ const kept = livePoints(nabu);
86
+ await nabu.transact(mutate);
87
+ if (kept) {
88
+ await tick();
89
+ if (placePoints(nabu, kept)) revealFocus(kept.focus.block);
90
+ }
91
+ return true;
92
+ }