@aionbuilders/nabu 0.1.0-alpha.9 → 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 (319) hide show
  1. package/CHANGELOG.md +523 -0
  2. package/LICENSE +21 -0
  3. package/README.md +82 -144
  4. package/dist/behaviors/text/RichText.svelte +25 -2
  5. package/dist/behaviors/text/index.d.ts +2 -0
  6. package/dist/behaviors/text/index.js +2 -0
  7. package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +5 -0
  8. package/dist/behaviors/text/markdown-shortcuts.extension.js +79 -0
  9. package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
  10. package/dist/behaviors/text/markdown-syntax.js +81 -0
  11. package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
  12. package/dist/behaviors/text/rich-text.extension.js +135 -53
  13. package/dist/behaviors/text/text.behavior.svelte.d.ts +217 -42
  14. package/dist/behaviors/text/text.behavior.svelte.js +657 -55
  15. package/dist/behaviors/text/typography.extension.d.ts +7 -0
  16. package/dist/behaviors/text/typography.extension.js +25 -0
  17. package/dist/blocks/Block.svelte +5 -2
  18. package/dist/blocks/BlockList.svelte +48 -0
  19. package/dist/blocks/BlockList.svelte.d.ts +17 -0
  20. package/dist/blocks/Nabu.svelte +180 -14
  21. package/dist/blocks/Nabu.svelte.d.ts +13 -0
  22. package/dist/blocks/block.extension.d.ts +3 -0
  23. package/dist/blocks/block.extension.js +8 -9
  24. package/dist/blocks/block.svelte.d.ts +356 -68
  25. package/dist/blocks/block.svelte.js +388 -42
  26. package/dist/blocks/blockquote/Blockquote.svelte +39 -0
  27. package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
  28. package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -0
  29. package/dist/blocks/blockquote/blockquote.extension.js +80 -0
  30. package/dist/blocks/blockquote/blockquote.svelte.d.ts +63 -0
  31. package/dist/blocks/blockquote/blockquote.svelte.js +136 -0
  32. package/dist/blocks/blockquote/index.d.ts +3 -0
  33. package/dist/blocks/blockquote/index.js +3 -0
  34. package/dist/blocks/callout/Callout.svelte +67 -0
  35. package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
  36. package/dist/blocks/callout/callout.extension.d.ts +4 -0
  37. package/dist/blocks/callout/callout.extension.js +84 -0
  38. package/dist/blocks/callout/callout.svelte.d.ts +80 -0
  39. package/dist/blocks/callout/callout.svelte.js +189 -0
  40. package/dist/blocks/callout/index.d.ts +3 -0
  41. package/dist/blocks/callout/index.js +3 -0
  42. package/dist/blocks/chunks.d.ts +49 -0
  43. package/dist/blocks/chunks.js +90 -0
  44. package/dist/blocks/code/Code.svelte +84 -0
  45. package/dist/blocks/code/Code.svelte.d.ts +11 -0
  46. package/dist/blocks/code/code.extension.d.ts +4 -0
  47. package/dist/blocks/code/code.extension.js +88 -0
  48. package/dist/blocks/code/code.svelte.d.ts +68 -0
  49. package/dist/blocks/code/code.svelte.js +245 -0
  50. package/dist/blocks/code/index.d.ts +3 -0
  51. package/dist/blocks/code/index.js +3 -0
  52. package/dist/blocks/container.utils.d.ts +85 -13
  53. package/dist/blocks/container.utils.js +338 -178
  54. package/dist/blocks/dialogue/Dialogue.svelte +8 -2
  55. package/dist/blocks/dialogue/dialogue.svelte.d.ts +36 -23
  56. package/dist/blocks/dialogue/dialogue.svelte.js +51 -45
  57. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
  58. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
  59. package/dist/blocks/dialogue/index.d.ts +12 -1
  60. package/dist/blocks/dialogue/index.js +51 -35
  61. package/dist/blocks/divider/Divider.svelte +28 -0
  62. package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
  63. package/dist/blocks/divider/divider.extension.d.ts +23 -0
  64. package/dist/blocks/divider/divider.extension.js +153 -0
  65. package/dist/blocks/divider/divider.svelte.d.ts +54 -0
  66. package/dist/blocks/divider/divider.svelte.js +89 -0
  67. package/dist/blocks/divider/index.d.ts +3 -0
  68. package/dist/blocks/divider/index.js +3 -0
  69. package/dist/blocks/file/File.svelte +56 -0
  70. package/dist/blocks/file/File.svelte.d.ts +11 -0
  71. package/dist/blocks/file/file.extension.d.ts +4 -0
  72. package/dist/blocks/file/file.extension.js +27 -0
  73. package/dist/blocks/file/file.svelte.d.ts +29 -0
  74. package/dist/blocks/file/file.svelte.js +77 -0
  75. package/dist/blocks/file/index.d.ts +3 -0
  76. package/dist/blocks/file/index.js +3 -0
  77. package/dist/blocks/heading/Heading.svelte +2 -1
  78. package/dist/blocks/heading/heading.svelte.d.ts +27 -34
  79. package/dist/blocks/heading/heading.svelte.js +72 -60
  80. package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
  81. package/dist/blocks/heading/index.d.ts +2 -2
  82. package/dist/blocks/heading/index.js +33 -8
  83. package/dist/blocks/image/Image.svelte +41 -0
  84. package/dist/blocks/image/Image.svelte.d.ts +11 -0
  85. package/dist/blocks/image/image.extension.d.ts +5 -0
  86. package/dist/blocks/image/image.extension.js +34 -0
  87. package/dist/blocks/image/image.svelte.d.ts +61 -0
  88. package/dist/blocks/image/image.svelte.js +114 -0
  89. package/dist/blocks/image/index.d.ts +3 -0
  90. package/dist/blocks/image/index.js +3 -0
  91. package/dist/blocks/index.d.ts +11 -1
  92. package/dist/blocks/index.js +11 -1
  93. package/dist/blocks/list/List.svelte +9 -2
  94. package/dist/blocks/list/ListItem.svelte +44 -7
  95. package/dist/blocks/list/convert.d.ts +20 -0
  96. package/dist/blocks/list/convert.js +92 -0
  97. package/dist/blocks/list/hooks/onBeforeInput.hook.js +60 -26
  98. package/dist/blocks/list/html-flat.d.ts +78 -0
  99. package/dist/blocks/list/html-flat.js +244 -0
  100. package/dist/blocks/list/indent.d.ts +86 -0
  101. package/dist/blocks/list/indent.js +205 -0
  102. package/dist/blocks/list/index.d.ts +7 -3
  103. package/dist/blocks/list/index.js +43 -31
  104. package/dist/blocks/list/list-item.svelte.d.ts +43 -17
  105. package/dist/blocks/list/list-item.svelte.js +143 -93
  106. package/dist/blocks/list/list.behavior.svelte.d.ts +7 -4
  107. package/dist/blocks/list/list.behavior.svelte.js +10 -5
  108. package/dist/blocks/list/list.svelte.d.ts +101 -23
  109. package/dist/blocks/list/list.svelte.js +136 -114
  110. package/dist/blocks/list/markdown.d.ts +149 -0
  111. package/dist/blocks/list/markdown.js +442 -0
  112. package/dist/blocks/list/normalize.d.ts +11 -0
  113. package/dist/blocks/list/normalize.js +396 -0
  114. package/dist/blocks/list/paste.d.ts +45 -0
  115. package/dist/blocks/list/paste.js +242 -0
  116. package/dist/blocks/list/step-back.d.ts +24 -0
  117. package/dist/blocks/list/step-back.js +87 -0
  118. package/dist/blocks/list/to-list.d.ts +7 -0
  119. package/dist/blocks/list/to-list.js +44 -0
  120. package/dist/blocks/list/todos-toggle.d.ts +20 -0
  121. package/dist/blocks/list/todos-toggle.js +48 -0
  122. package/dist/blocks/list/todos.svelte.d.ts +35 -0
  123. package/dist/blocks/list/todos.svelte.js +76 -0
  124. package/dist/blocks/media/index.d.ts +2 -0
  125. package/dist/blocks/media/index.js +2 -0
  126. package/dist/blocks/media/markdown.d.ts +12 -0
  127. package/dist/blocks/media/markdown.js +26 -0
  128. package/dist/blocks/media/media-block.svelte.d.ts +107 -0
  129. package/dist/blocks/media/media-block.svelte.js +181 -0
  130. package/dist/blocks/media/media.helpers.d.ts +24 -0
  131. package/dist/blocks/media/media.helpers.js +88 -0
  132. package/dist/blocks/megablock.svelte.d.ts +50 -19
  133. package/dist/blocks/megablock.svelte.js +115 -74
  134. package/dist/blocks/move.d.ts +23 -0
  135. package/dist/blocks/move.js +92 -0
  136. package/dist/blocks/nabu.svelte.d.ts +846 -75
  137. package/dist/blocks/nabu.svelte.js +1990 -182
  138. package/dist/blocks/paragraph/Paragraph.svelte +1 -0
  139. package/dist/blocks/paragraph/index.d.ts +2 -2
  140. package/dist/blocks/paragraph/index.js +35 -16
  141. package/dist/blocks/paragraph/paragraph.svelte.d.ts +49 -35
  142. package/dist/blocks/paragraph/paragraph.svelte.js +81 -69
  143. package/dist/blocks/paragraph/table.html.d.ts +9 -0
  144. package/dist/blocks/paragraph/table.html.js +111 -0
  145. package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
  146. package/dist/blocks/paragraph/table.markdown.js +90 -0
  147. package/dist/blocks/region/Region.svelte +264 -0
  148. package/dist/blocks/region/Region.svelte.d.ts +11 -0
  149. package/dist/blocks/region/actions.d.ts +135 -0
  150. package/dist/blocks/region/actions.js +402 -0
  151. package/dist/blocks/region/close.d.ts +35 -0
  152. package/dist/blocks/region/close.js +130 -0
  153. package/dist/blocks/region/commands.d.ts +6 -0
  154. package/dist/blocks/region/commands.js +277 -0
  155. package/dist/blocks/region/create.d.ts +72 -0
  156. package/dist/blocks/region/create.js +208 -0
  157. package/dist/blocks/region/end-marker.d.ts +35 -0
  158. package/dist/blocks/region/end-marker.js +51 -0
  159. package/dist/blocks/region/facts.d.ts +69 -0
  160. package/dist/blocks/region/facts.js +152 -0
  161. package/dist/blocks/region/format.d.ts +91 -0
  162. package/dist/blocks/region/format.js +260 -0
  163. package/dist/blocks/region/index.d.ts +14 -0
  164. package/dist/blocks/region/index.js +14 -0
  165. package/dist/blocks/region/insert.d.ts +59 -0
  166. package/dist/blocks/region/insert.js +102 -0
  167. package/dist/blocks/region/messages.d.ts +254 -0
  168. package/dist/blocks/region/messages.js +131 -0
  169. package/dist/blocks/region/normalize.d.ts +7 -0
  170. package/dist/blocks/region/normalize.js +170 -0
  171. package/dist/blocks/region/region.extension.d.ts +58 -0
  172. package/dist/blocks/region/region.extension.js +119 -0
  173. package/dist/blocks/region/region.svelte.d.ts +221 -0
  174. package/dist/blocks/region/region.svelte.js +582 -0
  175. package/dist/blocks/region/regions.svelte.d.ts +141 -0
  176. package/dist/blocks/region/regions.svelte.js +276 -0
  177. package/dist/blocks/region/serialize.d.ts +57 -0
  178. package/dist/blocks/region/serialize.js +112 -0
  179. package/dist/blocks/region/types.d.ts +255 -0
  180. package/dist/blocks/region/types.js +204 -0
  181. package/dist/blocks/selection.svelte.d.ts +106 -8
  182. package/dist/blocks/selection.svelte.js +632 -74
  183. package/dist/blocks/subthread.d.ts +80 -0
  184. package/dist/blocks/subthread.js +167 -0
  185. package/dist/blocks/text-block.svelte.d.ts +70 -0
  186. package/dist/blocks/text-block.svelte.js +108 -0
  187. package/dist/blocks/toggle/Toggle.svelte +73 -0
  188. package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
  189. package/dist/blocks/toggle/index.d.ts +3 -0
  190. package/dist/blocks/toggle/index.js +3 -0
  191. package/dist/blocks/toggle/markdown.d.ts +20 -0
  192. package/dist/blocks/toggle/markdown.js +112 -0
  193. package/dist/blocks/toggle/toggle.extension.d.ts +4 -0
  194. package/dist/blocks/toggle/toggle.extension.js +18 -0
  195. package/dist/blocks/toggle/toggle.svelte.d.ts +135 -0
  196. package/dist/blocks/toggle/toggle.svelte.js +352 -0
  197. package/dist/blocks/undo-selection.d.ts +175 -0
  198. package/dist/blocks/undo-selection.js +360 -0
  199. package/dist/blocks/video/Video.svelte +42 -0
  200. package/dist/blocks/video/Video.svelte.d.ts +11 -0
  201. package/dist/blocks/video/index.d.ts +3 -0
  202. package/dist/blocks/video/index.js +3 -0
  203. package/dist/blocks/video/video.extension.d.ts +4 -0
  204. package/dist/blocks/video/video.extension.js +27 -0
  205. package/dist/blocks/video/video.svelte.d.ts +29 -0
  206. package/dist/blocks/video/video.svelte.js +80 -0
  207. package/dist/extend.d.ts +55 -0
  208. package/dist/extend.js +88 -0
  209. package/dist/files/assets.clipboard.d.ts +77 -0
  210. package/dist/files/assets.clipboard.js +152 -0
  211. package/dist/files/files.svelte.d.ts +363 -0
  212. package/dist/files/files.svelte.js +897 -0
  213. package/dist/files/index.d.ts +3 -0
  214. package/dist/files/index.js +3 -0
  215. package/dist/files/outbox.d.ts +69 -0
  216. package/dist/files/outbox.js +48 -0
  217. package/dist/files/status.d.ts +65 -0
  218. package/dist/files/status.js +87 -0
  219. package/dist/files/store.d.ts +97 -0
  220. package/dist/files/store.js +65 -0
  221. package/dist/files/uploads.svelte.d.ts +174 -0
  222. package/dist/files/uploads.svelte.js +504 -0
  223. package/dist/index.d.ts +68 -6
  224. package/dist/index.js +117 -7
  225. package/dist/nabu-theme.css +112 -0
  226. package/dist/paste/html.paste.d.ts +74 -3
  227. package/dist/paste/html.paste.js +555 -83
  228. package/dist/paste/markdown-inline.d.ts +86 -0
  229. package/dist/paste/markdown-inline.js +528 -0
  230. package/dist/paste/markdown.paste.d.ts +2 -8
  231. package/dist/paste/markdown.paste.js +78 -94
  232. package/dist/paste/nabu.paste.d.ts +3 -0
  233. package/dist/paste/nabu.paste.js +29 -3
  234. package/dist/paste/plain-text.paste.d.ts +2 -2
  235. package/dist/paste/plain-text.paste.js +3 -3
  236. package/dist/persistence/asset-store.d.ts +51 -0
  237. package/dist/persistence/asset-store.js +103 -0
  238. package/dist/persistence/autosave.d.ts +53 -0
  239. package/dist/persistence/autosave.js +62 -0
  240. package/dist/persistence/compact.d.ts +162 -0
  241. package/dist/persistence/compact.js +141 -0
  242. package/dist/persistence/history.d.ts +77 -0
  243. package/dist/persistence/history.js +176 -0
  244. package/dist/persistence/indexeddb.d.ts +190 -4
  245. package/dist/persistence/indexeddb.js +333 -29
  246. package/dist/persistence/merge.d.ts +38 -0
  247. package/dist/persistence/merge.js +36 -0
  248. package/dist/persistence/outbox.d.ts +25 -0
  249. package/dist/persistence/outbox.js +40 -0
  250. package/dist/persistence/persistence.d.ts +70 -9
  251. package/dist/persistence/persistence.js +507 -35
  252. package/dist/persistence/recovery.d.ts +79 -0
  253. package/dist/persistence/recovery.js +79 -0
  254. package/dist/persistence/release.d.ts +34 -0
  255. package/dist/persistence/release.js +64 -0
  256. package/dist/persistence/state.svelte.d.ts +53 -0
  257. package/dist/persistence/state.svelte.js +48 -0
  258. package/dist/persistence/sync.d.ts +39 -0
  259. package/dist/persistence/sync.js +138 -0
  260. package/dist/persistence/tail.d.ts +42 -0
  261. package/dist/persistence/tail.js +103 -0
  262. package/dist/presets.d.ts +29 -24
  263. package/dist/presets.js +51 -14
  264. package/dist/themes/atelier.css +318 -0
  265. package/dist/ui/CommandChooser.svelte +153 -0
  266. package/dist/ui/CommandChooser.svelte.d.ts +13 -0
  267. package/dist/ui/CommandInvite.svelte +99 -0
  268. package/dist/ui/CommandInvite.svelte.d.ts +12 -0
  269. package/dist/ui/DragHandle.svelte +217 -0
  270. package/dist/ui/DragHandle.svelte.d.ts +11 -0
  271. package/dist/ui/FloatingToolbar.svelte +165 -0
  272. package/dist/ui/FloatingToolbar.svelte.d.ts +27 -0
  273. package/dist/ui/SlashMenu.svelte +215 -0
  274. package/dist/ui/SlashMenu.svelte.d.ts +33 -0
  275. package/dist/ui/anchor.d.ts +112 -0
  276. package/dist/ui/anchor.js +136 -0
  277. package/dist/ui/index.d.ts +10 -0
  278. package/dist/ui/index.js +15 -0
  279. package/dist/ui/slash-menu.svelte.d.ts +112 -0
  280. package/dist/ui/slash-menu.svelte.js +150 -0
  281. package/dist/utils/command-confirm.svelte.d.ts +349 -0
  282. package/dist/utils/command-confirm.svelte.js +673 -0
  283. package/dist/utils/commands.d.ts +328 -0
  284. package/dist/utils/commands.js +416 -0
  285. package/dist/utils/dom-scope.d.ts +14 -0
  286. package/dist/utils/dom-scope.js +20 -0
  287. package/dist/utils/drop.d.ts +160 -0
  288. package/dist/utils/drop.js +305 -0
  289. package/dist/utils/extensions.d.ts +488 -40
  290. package/dist/utils/extensions.js +300 -19
  291. package/dist/utils/html.d.ts +44 -0
  292. package/dist/utils/html.js +183 -0
  293. package/dist/utils/index.d.ts +4 -0
  294. package/dist/utils/index.js +4 -0
  295. package/dist/utils/keys.d.ts +120 -0
  296. package/dist/utils/keys.js +248 -0
  297. package/dist/utils/links.d.ts +22 -0
  298. package/dist/utils/links.js +34 -0
  299. package/dist/utils/placeholders.d.ts +88 -0
  300. package/dist/utils/placeholders.js +91 -0
  301. package/dist/utils/selection.svelte.d.ts +47 -19
  302. package/dist/utils/selection.svelte.js +60 -10
  303. package/dist/utils/spellcheck.d.ts +9 -0
  304. package/dist/utils/spellcheck.js +17 -0
  305. package/dist/utils/tab.d.ts +31 -0
  306. package/dist/utils/tab.js +117 -0
  307. package/dist/utils/words.d.ts +7 -0
  308. package/dist/utils/words.js +62 -0
  309. package/dist/vite.d.ts +22 -0
  310. package/dist/vite.js +34 -0
  311. package/package.json +61 -22
  312. package/dist/blocks/zone/Zone.svelte +0 -258
  313. package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
  314. package/dist/blocks/zone/index.d.ts +0 -2
  315. package/dist/blocks/zone/index.js +0 -2
  316. package/dist/blocks/zone/zone.extension.d.ts +0 -2
  317. package/dist/blocks/zone/zone.extension.js +0 -221
  318. package/dist/blocks/zone/zone.svelte.d.ts +0 -112
  319. package/dist/blocks/zone/zone.svelte.js +0 -321
@@ -2,6 +2,7 @@ import { tick } from "svelte";
2
2
  import { TextBehavior } from "../../../behaviors/text";
3
3
  import { List } from "../list.svelte.js";
4
4
  import { ListItem } from "../list-item.svelte.js";
5
+ import { stepBack } from "../step-back.js";
5
6
 
6
7
  /**
7
8
  * @import { Nabu, Block } from "../..";
@@ -18,6 +19,16 @@ import { ListItem } from "../list-item.svelte.js";
18
19
  export const onBeforeInput = (nabu, event, block) => {
19
20
  const { BREAK, CONTINUE } = nabu;
20
21
 
22
+ // Backspace at offset 0 of a list item (collapsed caret): step back one level instead of merging into
23
+ // the previous block. A nested item is unindented, a top-level one becomes a paragraph (the next
24
+ // Backspace then merges it like any paragraph). See step-back.js.
25
+ if (event.inputType === "deleteContentBackward" && block instanceof ListItem) {
26
+ const sel = block.behavior.selection;
27
+ if (!sel || !sel.isCollapsed || sel.from !== 0) return CONTINUE;
28
+ stepBack(nabu, /** @type {import('../../nabu.svelte.js').NabuNode} */ (block.node));
29
+ return BREAK;
30
+ }
31
+
21
32
  if (event.data !== " ") return CONTINUE;
22
33
  if (block.type !== "paragraph") return CONTINUE;
23
34
 
@@ -29,9 +40,13 @@ export const onBeforeInput = (nabu, event, block) => {
29
40
 
30
41
  const textBeforeCursor = behavior.text.slice(0, sel.from);
31
42
 
32
- /** @type {"bullet" | "ordered" | null} */
43
+ /** @type {"bullet" | "ordered" | "todo" | null} */
33
44
  let listType = null;
34
45
  let prefixLength = 0;
46
+ /** @type {boolean | undefined} */
47
+ let checked = undefined;
48
+ /** @type {number | undefined} */
49
+ let start = undefined;
35
50
 
36
51
  if (textBeforeCursor.match(/^-$/)) {
37
52
  listType = "bullet";
@@ -39,37 +54,56 @@ export const onBeforeInput = (nabu, event, block) => {
39
54
  } else if (textBeforeCursor.match(/^\d+\.$/)) {
40
55
  listType = "ordered";
41
56
  prefixLength = textBeforeCursor.length;
57
+ start = parseInt(textBeforeCursor, 10); // "3. " starts the list at 3 (List drops it when it is 1)
58
+ } else if (textBeforeCursor.match(/^\[\s?\]$/)) {
59
+ listType = "todo";
60
+ checked = false;
61
+ prefixLength = textBeforeCursor.length;
62
+ } else if (textBeforeCursor.match(/^\[[xX]\]$/)) {
63
+ listType = "todo";
64
+ checked = true;
65
+ prefixLength = textBeforeCursor.length;
42
66
  }
43
67
 
44
68
  if (!listType) return CONTINUE;
45
-
46
- // Delete the prefix ("- " trigger: delete the "-"; "1. " trigger: delete the "1.")
47
- behavior.delete({ index: 0, length: prefixLength });
48
-
49
- // Capture remaining text delta (everything after the prefix)
50
- const delta = behavior.container.toDelta();
51
-
52
- // Get current tree position from live Loro state (pre-commit)
53
- const parentNode = block.node.parent();
54
- const parentId = parentNode?.id.toString() ?? null;
55
- const index = block.node.index();
56
-
57
- // Create the List at the same position as the paragraph
58
- const list = List.create(nabu, "list", { listType }, parentId, index);
59
-
60
- // Create the ListItem inside the list with the captured content
61
- const listItem = ListItem.create(nabu, "list-item", { delta }, list.node.id.toString());
62
-
63
- // Destroy the original paragraph (no commit)
64
- block.destroy();
65
-
66
- // Commit the whole operation as a single transaction
67
- nabu.commit();
69
+ const type = listType;
70
+
71
+ /** @type {string | null} */
72
+ let listItemId = null;
73
+
74
+ // Undo gives back the typed trigger ("- ", "1. "…, space included): see Nabu.shortcut()
75
+ nabu.shortcut(block, " ", (b) => {
76
+ // Delete the prefix and the trigger space ("- " -> "", "1. " -> "")
77
+ b.delete({ index: 0, length: prefixLength + 1 });
78
+
79
+ // Capture remaining text delta (everything after the prefix)
80
+ const delta = b.container.toDelta();
81
+
82
+ // Get current tree position from live Loro state (pre-commit)
83
+ const parentNode = block.node.parent();
84
+ const parentId = parentNode?.id.toString() ?? null;
85
+ const index = block.node.index();
86
+
87
+ // Create the List at the same position as the paragraph
88
+ /** @type {Record<string, any>} */
89
+ const listProps = { listType: type };
90
+ if (start !== undefined) listProps.start = start;
91
+ const list = List.create(nabu, "list", listProps, parentId, index);
92
+
93
+ // Create the ListItem inside the list with the captured content
94
+ /** @type {Record<string, any>} */
95
+ const itemProps = { delta };
96
+ if (checked !== undefined) itemProps.checked = checked;
97
+ const listItem = ListItem.create(nabu, "list-item", itemProps, list.node.id.toString());
98
+ listItemId = listItem.node.id.toString();
99
+
100
+ // Destroy the original paragraph; shortcut() commits the whole operation as one transaction
101
+ block.destroy();
102
+ });
68
103
 
69
104
  // Restore focus to the new list-item
70
- const listItemId = listItem.node.id.toString();
71
105
  tick().then(() => {
72
- const updatedListItem = nabu.blocks.get(listItemId);
106
+ const updatedListItem = listItemId ? nabu.blocks.get(listItemId) : null;
73
107
  if (updatedListItem) updatedListItem.focus({ start: 0, end: 0 });
74
108
  });
75
109
 
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Whether a list element expresses its nesting by level (Docs) rather than by `<li>` containing sublists: an `<li
3
+ * aria-level>`, or a list nested straight in a list.
4
+ * @param {Element} listEl @returns {boolean}
5
+ */
6
+ export function hasLeveledItems(listEl: Element): boolean;
7
+ /**
8
+ * The items of a Docs list element, in document order, with their level and kind.
9
+ * @param {Element} listEl
10
+ * @param {number} [depth] level of the items that carry no `aria-level` (their nesting depth)
11
+ * @param {RawEntry[]} [out]
12
+ * @returns {RawEntry[]}
13
+ */
14
+ export function docsEntries(listEl: Element, depth?: number, out?: RawEntry[]): RawEntry[];
15
+ /**
16
+ * The `<ul>` / `<ol>` siblings that continue a Docs list: Docs sometimes writes each nesting level as its own list element.
17
+ * A following list element belongs to the same list when it goes DEEPER than where the list started, or when it comes back
18
+ * to that level after going deeper (same tag, no `start` of its own).
19
+ * @param {Element} el
20
+ * @returns {Element[]}
21
+ */
22
+ export function docsSiblings(el: Element): Element[];
23
+ /**
24
+ * Bullet or numbered, and the number when the marker is one (`3.`).
25
+ * @param {string | null} marker
26
+ * @returns {{ listType: ListKind, start: number | null }}
27
+ */
28
+ export function classifyWordMarker(marker: string | null): {
29
+ listType: ListKind;
30
+ start: number | null;
31
+ };
32
+ /**
33
+ * The Word list paragraphs that continue the list of `p` (same list and override id), straight after it.
34
+ * @param {Element} p
35
+ * @returns {Element[]}
36
+ */
37
+ export function wordSiblings(p: Element): Element[];
38
+ /**
39
+ * @param {Element[]} paragraphs the list paragraphs of ONE Word list, in order
40
+ * @returns {RawEntry[]}
41
+ */
42
+ export function wordEntries(paragraphs: Element[]): RawEntry[];
43
+ /**
44
+ * Build the nested list of flat, leveled items. Depth is the level relative to the first item; an item can go at most ONE
45
+ * level deeper than the previous one (a jump is clamped), and an item shallower than the first one sits at the top.
46
+ * Each depth keeps the kind of its first item (a bullet sublist under a numbered item, and so on); a change of kind at the
47
+ * same depth inside a sublist starts a sibling sublist. A list holding a checked / unchecked item is a to-do list.
48
+ * @param {Array<{ level: number, listType: ListKind, start: number | null, item: PasteBlock }>} entries
49
+ * @param {(listType: string, start: number | null) => Record<string, any>} propsOf list props for a kind and a first number
50
+ * @returns {PasteBlock | null}
51
+ */
52
+ export function nestEntries(entries: Array<{
53
+ level: number;
54
+ listType: ListKind;
55
+ start: number | null;
56
+ item: PasteBlock;
57
+ }>, propsOf: (listType: string, start: number | null) => Record<string, any>): PasteBlock | null;
58
+ export function isWordListParagraph(el: Element): boolean;
59
+ export type ListKind = "bullet" | "ordered" | "todo";
60
+ /**
61
+ * an item of a flat list, before its content is parsed
62
+ */
63
+ export type RawEntry = {
64
+ /**
65
+ * the `<li>` (Docs) or `<p>` (Word)
66
+ */
67
+ el: Element;
68
+ /**
69
+ * 1-based, as written by the source
70
+ */
71
+ level: number;
72
+ listType: ListKind;
73
+ /**
74
+ * first number of an ordered list, when this item opens a list element that says so
75
+ */
76
+ start: number | null;
77
+ };
78
+ import type { PasteBlock } from "../../utils/extensions.js";
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Lists in the HTML of Google Docs and Microsoft Word: nesting is not expressed by `<ul>` inside `<li>` but by a LEVEL
3
+ * attached to flat items. This module reads those levels and rebuilds real nested lists (PasteBlocks).
4
+ *
5
+ * - Google Docs: `<li aria-level="N" style="list-style-type:…">` (the level), items of one list in a single `<ul>`, or a
6
+ * `<ul>` nested straight inside the `<ul>` (invalid HTML the parser keeps), or one `<ul>` per level as siblings;
7
+ * `<ol start>` is kept; `aria-checked` items are to-do items.
8
+ * - Word: consecutive `<p class=MsoListParagraph… style="mso-list:l0 level2 lfo1">`: the list is `l0 lfo1`, the level is
9
+ * `level2`, and the kind (bullet / numbered) comes from the marker Word writes in a `mso-list:Ignore` span (`·`, `o`, `§`
10
+ * for bullets; `1.`, `a)`, `i.` for numbers).
11
+ *
12
+ * Pure DOM / PasteBlock functions, no editor access. Used by `List.fromHTML` / `List.htmlSiblings`.
13
+ *
14
+ * @import { PasteBlock } from "../../utils/extensions.js";
15
+ */
16
+
17
+ /**
18
+ * @typedef {'bullet' | 'ordered' | 'todo'} ListKind
19
+ * @typedef {Object} RawEntry an item of a flat list, before its content is parsed
20
+ * @property {Element} el the `<li>` (Docs) or `<p>` (Word)
21
+ * @property {number} level 1-based, as written by the source
22
+ * @property {ListKind} listType
23
+ * @property {number | null} start first number of an ordered list, when this item opens a list element that says so
24
+ */
25
+
26
+ /** The value of one CSS property of the `style` attribute (lower-cased, `!important` dropped), or ''. @param {Element} el @param {string} prop */
27
+ function styleValue(el, prop) {
28
+ const style = el.getAttribute('style');
29
+ if (!style) return '';
30
+ let value = '';
31
+ for (const decl of style.split(';')) {
32
+ const i = decl.indexOf(':');
33
+ if (i > 0 && decl.slice(0, i).trim().toLowerCase() === prop) value = decl.slice(i + 1).replace(/!\s*important/i, '').trim().toLowerCase();
34
+ }
35
+ return value;
36
+ }
37
+
38
+ const ORDERED_STYLE = /^(decimal|lower-|upper-|armenian|georgian|hebrew|cjk-|hiragana|katakana|arabic-indic|persian|devanagari|bengali|gujarati|gurmukhi|kannada|khmer|lao|malayalam|myanmar|oriya|tamil|telugu|thai|tibetan)/;
39
+
40
+ /**
41
+ * The kind of list an item belongs to, from its `list-style-type` (`disc` / `circle` / `square` → bullet, `decimal` /
42
+ * `lower-alpha` / `upper-roman`… → ordered); no (or `none`) style: the kind of the list tag.
43
+ * @param {string} styleType @param {ListKind} fallback @returns {ListKind}
44
+ */
45
+ function kindFromStyle(styleType, fallback) {
46
+ if (!styleType || styleType === 'none') return fallback;
47
+ return ORDERED_STYLE.test(styleType) ? 'ordered' : 'bullet';
48
+ }
49
+
50
+ /** @param {unknown} start @returns {number | null} */
51
+ const startNumber = (start) => {
52
+ if (start === null || start === undefined || start === '') return null;
53
+ const n = Number(start);
54
+ return Number.isInteger(n) && n >= 0 ? n : null;
55
+ };
56
+
57
+ /** The ul / ol elements are the list tags. @param {Element | null | undefined} el */
58
+ const isListTag = (el) => !!el && (el.localName === 'ul' || el.localName === 'ol');
59
+
60
+ /** The next sibling ELEMENT, over blank text and comments only; `null` when something else (text, an element) is met first. @param {Element} el */
61
+ function nextSiblingElement(el) {
62
+ for (let n = el.nextSibling; n; n = n.nextSibling) {
63
+ if (n.nodeType === 1) return /** @type {Element} */ (n);
64
+ if (n.nodeType === 8 || (n.nodeType === 3 && !/\S/.test(n.textContent ?? ''))) continue;
65
+ return null;
66
+ }
67
+ return null;
68
+ }
69
+
70
+ // ── Google Docs ──────────────────────────────────────────────────────────────
71
+
72
+ /**
73
+ * Whether a list element expresses its nesting by level (Docs) rather than by `<li>` containing sublists: an `<li
74
+ * aria-level>`, or a list nested straight in a list.
75
+ * @param {Element} listEl @returns {boolean}
76
+ */
77
+ export function hasLeveledItems(listEl) {
78
+ return [...listEl.children].some((c) => (c.localName === 'li' && c.hasAttribute('aria-level')) || isListTag(c));
79
+ }
80
+
81
+ /**
82
+ * The items of a Docs list element, in document order, with their level and kind.
83
+ * @param {Element} listEl
84
+ * @param {number} [depth] level of the items that carry no `aria-level` (their nesting depth)
85
+ * @param {RawEntry[]} [out]
86
+ * @returns {RawEntry[]}
87
+ */
88
+ export function docsEntries(listEl, depth = 1, out = []) {
89
+ const tagKind = /** @type {ListKind} */ (listEl.localName === 'ol' ? 'ordered' : 'bullet');
90
+ const start = listEl.localName === 'ol' ? startNumber(listEl.getAttribute('start')) : null;
91
+ let first = true;
92
+ for (const child of listEl.children) {
93
+ if (child.localName === 'li') {
94
+ const aria = parseInt(child.getAttribute('aria-level') ?? '', 10);
95
+ out.push({ el: child, level: aria > 0 ? aria : depth, listType: kindFromStyle(styleValue(child, 'list-style-type'), tagKind), start: first ? start : null });
96
+ first = false;
97
+ } else if (isListTag(child)) {
98
+ docsEntries(child, depth + 1, out);
99
+ }
100
+ }
101
+ return out;
102
+ }
103
+
104
+ /**
105
+ * The `<ul>` / `<ol>` siblings that continue a Docs list: Docs sometimes writes each nesting level as its own list element.
106
+ * A following list element belongs to the same list when it goes DEEPER than where the list started, or when it comes back
107
+ * to that level after going deeper (same tag, no `start` of its own).
108
+ * @param {Element} el
109
+ * @returns {Element[]}
110
+ */
111
+ export function docsSiblings(el) {
112
+ if (!isListTag(el) || !hasLeveledItems(el)) return [];
113
+ const own = docsEntries(el);
114
+ if (!own.length) return [];
115
+ const base = own[0].level;
116
+ let last = own[own.length - 1].level;
117
+ /** @type {Element[]} */
118
+ const out = [];
119
+ for (let n = nextSiblingElement(el); isListTag(n) && hasLeveledItems(/** @type {Element} */ (n)); n = nextSiblingElement(/** @type {Element} */ (n))) {
120
+ const list = /** @type {Element} */ (n);
121
+ const entries = docsEntries(list);
122
+ if (!entries.length) break;
123
+ const deeper = entries[0].level > base;
124
+ const back = entries[0].level === base && last > base && list.localName === el.localName && !list.hasAttribute('start');
125
+ if (!deeper && !back) break;
126
+ out.push(list);
127
+ last = entries[entries.length - 1].level;
128
+ }
129
+ return out;
130
+ }
131
+
132
+ // ── Microsoft Word ───────────────────────────────────────────────────────────
133
+
134
+ const WORD_LIST = /mso-list\s*:\s*(l\d+)\s+level(\d+)(?:\s+(lfo\d+))?/i;
135
+
136
+ /** @param {Element} el @returns {{ key: string, level: number } | null} */
137
+ function wordInfo(el) {
138
+ const m = WORD_LIST.exec(el.getAttribute('style') ?? '');
139
+ return m ? { key: m[1].toLowerCase() + (m[3] ? ' ' + m[3].toLowerCase() : ''), level: Number(m[2]) } : null;
140
+ }
141
+
142
+ /** Whether an element is a Word list paragraph (`mso-list:l0 level1 lfo1`). @param {Element} el @returns {boolean} */
143
+ export const isWordListParagraph = (el) => wordInfo(el) !== null;
144
+
145
+ /**
146
+ * The marker Word writes before the text of a list paragraph (the content of its `mso-list:Ignore` span), or `null`.
147
+ * @param {Element} p @returns {string | null}
148
+ */
149
+ function wordMarker(p) {
150
+ for (const span of p.querySelectorAll('[style]')) {
151
+ if (/mso-list\s*:\s*ignore/i.test(span.getAttribute('style') ?? '')) return (span.textContent ?? '').replace(/[\s ]+/g, ' ').trim();
152
+ }
153
+ return null;
154
+ }
155
+
156
+ /**
157
+ * Bullet or numbered, and the number when the marker is one (`3.`).
158
+ * @param {string | null} marker
159
+ * @returns {{ listType: ListKind, start: number | null }}
160
+ */
161
+ export function classifyWordMarker(marker) {
162
+ if (!marker) return { listType: 'bullet', start: null };
163
+ const number = /^\(?(\d+)[.)]?$/.exec(marker);
164
+ if (number) return { listType: 'ordered', start: startNumber(number[1]) };
165
+ if (/^\(?[A-Za-z]+[.)]$/.test(marker)) return { listType: 'ordered', start: null }; // a. A) i. IV.
166
+ if (marker.length === 1 && /[A-Za-z]/.test(marker) && marker !== 'o' && marker !== 'O') return { listType: 'ordered', start: null };
167
+ return { listType: 'bullet', start: null }; // · • o § - ▪ and the private-use glyphs of the Symbol / Wingdings fonts
168
+ }
169
+
170
+ /**
171
+ * The Word list paragraphs that continue the list of `p` (same list and override id), straight after it.
172
+ * @param {Element} p
173
+ * @returns {Element[]}
174
+ */
175
+ export function wordSiblings(p) {
176
+ const info = wordInfo(p);
177
+ if (!info) return [];
178
+ /** @type {Element[]} */
179
+ const out = [];
180
+ for (let n = nextSiblingElement(p); n && n.localName === 'p' && wordInfo(n)?.key === info.key; n = nextSiblingElement(n)) out.push(n);
181
+ return out;
182
+ }
183
+
184
+ /**
185
+ * @param {Element[]} paragraphs the list paragraphs of ONE Word list, in order
186
+ * @returns {RawEntry[]}
187
+ */
188
+ export function wordEntries(paragraphs) {
189
+ /** @type {RawEntry[]} */
190
+ const out = [];
191
+ paragraphs.forEach((el, i) => {
192
+ const info = wordInfo(el);
193
+ if (!info) return;
194
+ const { listType, start } = classifyWordMarker(wordMarker(el));
195
+ out.push({ el, level: info.level, listType, start: i === 0 ? start : null });
196
+ });
197
+ return out;
198
+ }
199
+
200
+ // ── Levels → nested lists ────────────────────────────────────────────────────
201
+
202
+ /**
203
+ * Build the nested list of flat, leveled items. Depth is the level relative to the first item; an item can go at most ONE
204
+ * level deeper than the previous one (a jump is clamped), and an item shallower than the first one sits at the top.
205
+ * Each depth keeps the kind of its first item (a bullet sublist under a numbered item, and so on); a change of kind at the
206
+ * same depth inside a sublist starts a sibling sublist. A list holding a checked / unchecked item is a to-do list.
207
+ * @param {Array<{ level: number, listType: ListKind, start: number | null, item: PasteBlock }>} entries
208
+ * @param {(listType: string, start: number | null) => Record<string, any>} propsOf list props for a kind and a first number
209
+ * @returns {PasteBlock | null}
210
+ */
211
+ export function nestEntries(entries, propsOf) {
212
+ if (!entries.length) return null;
213
+ const base = entries[0].level;
214
+ /** @param {{ listType: ListKind, start: number | null }} e @returns {PasteBlock} */
215
+ const makeList = (e) => ({ type: 'list', props: propsOf(e.listType, e.listType === 'ordered' ? e.start : null), children: [], partial: false });
216
+ const root = makeList(entries[0]);
217
+ /** @type {PasteBlock[]} */
218
+ const lists = [root];
219
+ /** @type {PasteBlock[]} */
220
+ const lastItem = [];
221
+ let previous = -1;
222
+ for (const e of entries) {
223
+ const depth = Math.max(0, Math.min(e.level - base, previous + 1));
224
+ lastItem.length = Math.min(lastItem.length, depth);
225
+ if (depth > 0 && (!lists[depth] || lists[depth].props?.listType !== e.listType)) {
226
+ const list = makeList(e);
227
+ const parent = lastItem[depth - 1];
228
+ (parent.children ??= []).push(list);
229
+ lists[depth] = list;
230
+ }
231
+ lists.length = depth + 1;
232
+ /** @type {PasteBlock[]} */ (lists[depth].children).push(e.item);
233
+ lastItem[depth] = e.item;
234
+ previous = depth;
235
+ }
236
+ /** @param {PasteBlock} list */
237
+ const promote = (list) => {
238
+ const items = list.children ?? [];
239
+ if (items.some((item) => item.props?.checked !== undefined)) list.props = { ...list.props, listType: 'todo' };
240
+ for (const item of items) for (const sub of item.children ?? []) promote(sub);
241
+ };
242
+ promote(root);
243
+ return root;
244
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Deletes a list this batch just emptied. The normalizer would do it too, but it spares a list created by
3
+ * the same transaction (it may still be "under construction"), and a batch of moves creates then empties
4
+ * such lists (an item unindented, then its adopted follower unindented in turn).
5
+ * @param {Nabu} nabu
6
+ * @param {NabuNode | null | undefined} list
7
+ */
8
+ export function dropIfEmpty(nabu: Nabu, list: NabuNode | null | undefined): void;
9
+ /**
10
+ * Indent one item: it goes under its previous sibling, at the end of that sibling's LAST sublist when that
11
+ * sublist has the same type as the item's current list, otherwise in a new sublist of that type appended
12
+ * after the sibling's sublists. Its whole subtree moves along (its own sublists stay attached to it). Moves
13
+ * only; no commit.
14
+ * @param {Nabu} nabu
15
+ * @param {NabuNode} item
16
+ * @returns {boolean} whether the item moved
17
+ */
18
+ export function indentNode(nabu: Nabu, item: NabuNode): boolean;
19
+ /**
20
+ * Unindent one item: it goes right after its parent item, and the siblings that followed it become its
21
+ * children, in a sublist of THEIR list type appended after the sublists it already has (its own subtree
22
+ * stays attached). To keep the document order, the sublists of the parent item that came after the item's
23
+ * list follow them. Moves only; no commit.
24
+ * @param {Nabu} nabu
25
+ * @param {NabuNode} item
26
+ * @returns {boolean} whether the item moved
27
+ */
28
+ export function unindentNode(nabu: Nabu, item: NabuNode): boolean;
29
+ /**
30
+ * @typedef {{ block: Block, offset: number }} CaretPoint
31
+ * @typedef {{ anchor: CaretPoint, focus: CaretPoint }} SelectionSnapshot
32
+ */
33
+ /**
34
+ * Model position (block + text offset) of the live selection's anchor and focus, or null when one of
35
+ * them is not in a text block.
36
+ * @param {Nabu} nabu
37
+ * @returns {SelectionSnapshot | null}
38
+ */
39
+ export function captureSelection(nabu: Nabu): SelectionSnapshot | null;
40
+ /**
41
+ * Put the selection back after a re-render: same blocks (looked up again by id), same offsets, so a
42
+ * collapsed caret stays collapsed and a range stays a range.
43
+ * @param {Nabu} nabu
44
+ * @param {SelectionSnapshot | null} snapshot
45
+ * @returns {Promise<void>}
46
+ */
47
+ export function restoreSelection(nabu: Nabu, snapshot: SelectionSnapshot | null): Promise<void>;
48
+ /**
49
+ * Indent (`unindent = false`) or unindent every given list item, in document order, as ONE transaction.
50
+ * Items that cannot move (e.g. the first item of a list on indent) stay. The selection is restored.
51
+ * @param {Nabu} nabu
52
+ * @param {NabuNode[]} items list-item nodes, in document order
53
+ * @param {boolean} unindent
54
+ * @returns {Promise<boolean>} whether at least one item moved
55
+ */
56
+ export function moveItems(nabu: Nabu, items: NabuNode[], unindent: boolean): Promise<boolean>;
57
+ /**
58
+ * The list items a selection touches, in document order: the anchor block alone when the selection is
59
+ * inside one block, otherwise every list item between the start and the end block.
60
+ * @param {Nabu} nabu
61
+ * @returns {NabuNode[]}
62
+ */
63
+ export function selectedItems(nabu: Nabu): NabuNode[];
64
+ /**
65
+ * Tab / Shift+Tab on the current selection. Returns true (= the key is handled, the default prevented)
66
+ * whenever the selection touches list items, even when none of them could move: focus never leaves the editor.
67
+ * @param {Nabu} nabu
68
+ * @param {KeyboardEvent} event
69
+ * @returns {boolean}
70
+ */
71
+ export function handleTab(nabu: Nabu, event: KeyboardEvent): boolean;
72
+ export function typeOf(node: NabuNode | null | undefined): any;
73
+ export function kids(node: NabuNode): NabuNode[];
74
+ export function listTypeOf(list: NabuNode | null | undefined): any;
75
+ export function sublistsOf(item: NabuNode): NabuNode[];
76
+ export type CaretPoint = {
77
+ block: Block;
78
+ offset: number;
79
+ };
80
+ export type SelectionSnapshot = {
81
+ anchor: CaretPoint;
82
+ focus: CaretPoint;
83
+ };
84
+ import type { Nabu } from "../nabu.svelte.js";
85
+ import type { NabuNode } from "../nabu.svelte.js";
86
+ import type { Block } from "../block.svelte.js";