@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
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @import { Nabu } from "../nabu.svelte.js";
2
+ * The heading block (levels 1 to 6): the `# ` shortcuts, the `heading:1` to `heading:6` actions and the "Heading" slash entries.
3
3
  */
4
- export const HeadingExtension: import("../..").Extension;
4
+ export const HeadingExtension: import("../../extend.js").Extension;
5
5
  import HeadingComponent from "./Heading.svelte";
6
6
  import { Heading } from "./heading.svelte.js";
7
7
  export { HeadingComponent, Heading };
@@ -9,9 +9,20 @@ import { onBeforeInput } from "./hooks/onBeforeInput.hook";
9
9
  * @import { Nabu } from "../nabu.svelte.js";
10
10
  */
11
11
 
12
+ /** Total length of the text inserted by a Loro delta. @param {import('loro-crdt').Delta<string>[]} [delta] */
13
+ const deltaLength = (delta) => (delta || []).reduce((n, op) => n + (typeof op.insert === 'string' ? op.insert.length : 0), 0);
14
+
15
+ /**
16
+ * The heading block (levels 1 to 6): the `# ` shortcuts, the `heading:1` to `heading:6` actions and the "Heading" slash entries.
17
+ */
12
18
  const HeadingExtension = extension("heading", {
13
19
  block: Heading,
14
20
  component: HeadingComponent,
21
+ slashCommands: [
22
+ { title: 'Heading 1', icon: 'H1', aliases: ['h1', 'title', 'heading'], group: 'text', order: 10, run: (e) => e.exec('heading:1') },
23
+ { title: 'Heading 2', icon: 'H2', aliases: ['h2', 'subtitle'], group: 'text', order: 20, run: (e) => e.exec('heading:2') },
24
+ { title: 'Heading 3', icon: 'H3', aliases: ['h3'], group: 'text', order: 30, run: (e) => e.exec('heading:3') },
25
+ ],
15
26
  actions: {
16
27
  'heading:1': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 1 } }),
17
28
  'heading:2': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 2 } }),
@@ -21,18 +32,32 @@ const HeadingExtension = extension("heading", {
21
32
  'heading:6': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 6 } }),
22
33
  },
23
34
  hooks: {
24
- /** @param {Nabu} nabu @param {Heading} block @param {Event} event @param {{offset: number, delta: import('loro-crdt').Delta<string>}} data */
35
+ /** @param {Nabu} nabu @param {Heading} block @param {Event | null} event @param {import('../../utils/extensions.js').SplitData} data */
25
36
  onSplit: (nabu, block, event, data) => {
26
37
  const { offset, delta } = data;
27
-
28
- block.delete({from: offset, to: -1});
29
-
30
- const currentIndex = block.node.index();
38
+ const length = block.text.length;
39
+
40
+ const currentIndex = block.node.index() ?? 0;
31
41
  const parent = block.node.parent();
32
42
  const parentId = parent?.id.toString() || null;
33
-
34
- // On split souvent un titre pour créer un paragraphe après
35
- const newBlock = nabu.insert("paragraph", { delta }, parentId, currentIndex + 1);
43
+
44
+ // START of a non-empty heading → an empty PARAGRAPH is inserted above; the heading keeps its text,
45
+ // its level and the caret (at the start of its text). Only when the tail is the WHOLE text (a
46
+ // collapsed caret): with a range selection the generic split below applies, nothing is dropped.
47
+ if (offset === 0 && length > 0 && deltaLength(delta) === length) {
48
+ nabu.insert("paragraph", {}, parentId, currentIndex);
49
+ block.commit().then(() => nabu.selection.setCursor(block, 0));
50
+ return { block };
51
+ }
52
+
53
+ block.delete({from: offset, to: -1});
54
+
55
+ // END of the heading (or an EMPTY one) → a paragraph below. MIDDLE → both halves are headings of the
56
+ // same level.
57
+ const atEnd = offset >= length;
58
+ const newBlock = atEnd
59
+ ? nabu.insert("paragraph", /** @type {any} */ ({ delta }), parentId, currentIndex + 1)
60
+ : nabu.insert("heading", /** @type {any} */ ({ delta, level: block.level }), parentId, currentIndex + 1);
36
61
 
37
62
  block.commit().then(() => nabu.selection.setCursor(newBlock, 0));
38
63
 
@@ -0,0 +1,41 @@
1
+ <script>
2
+ /** @type {{ block: import('./image.svelte.js').ImageBlock }} */
3
+ let { block } = $props();
4
+ $effect(() => block.holdSource());
5
+ const src = $derived(block.displaySrc);
6
+ </script>
7
+
8
+ <figure
9
+ bind:this={block.element}
10
+ data-block-id={block.id}
11
+ data-block-type="image"
12
+ data-nabu-inert
13
+ contenteditable="false"
14
+ class="nabu-image"
15
+ class:selected={block.selected}
16
+ class:pending={block.status === 'pending'}
17
+ class:error={block.status === 'error'}
18
+ class:missing={block.isMissing}
19
+ >
20
+ {#if block.status === 'error'}
21
+ <div class="nabu-image-error">⚠️ Upload failed</div>
22
+ {:else if block.isMissing}
23
+ <div class="nabu-image-error nabu-image-missing" data-nabu-missing>Missing file{block.alt ? ' — ' + block.alt : ''}</div>
24
+ {:else if src}
25
+ <img src={src} alt={block.alt} draggable="false" />{#if block.status === 'pending'}<div class="nabu-image-spinner">Uploading…</div>{/if}
26
+ {:else}
27
+ <div class="nabu-image-empty">No image</div>
28
+ {/if}
29
+ </figure>
30
+
31
+ <style>
32
+ .nabu-image { margin: 0.5em 0; user-select: none; position: relative; display: block; max-width: 100%; }
33
+ .nabu-image img { max-width: 100%; height: auto; border-radius: 6px; display: block; }
34
+ .nabu-image.selected img { outline: 2px solid var(--nb-accent, #4d9fff); }
35
+ .nabu-image.pending img { opacity: 0.6; }
36
+ .nabu-image-spinner, .nabu-image-error, .nabu-image-empty {
37
+ position: absolute; inset: auto 0 0 0; padding: 4px 8px; font-size: 12px;
38
+ background: var(--nb-bg-surface, rgba(0,0,0,0.6)); color: var(--nb-text-primary, #fff); border-radius: 0 0 6px 6px;
39
+ }
40
+ .nabu-image-empty, .nabu-image-error { position: static; padding: 1.5em; text-align: center; border: 1px dashed var(--nb-border, rgba(255,255,255,0.2)); border-radius: 6px; color: var(--nb-text-muted, rgba(255,255,255,0.4)); }
41
+ </style>
@@ -0,0 +1,11 @@
1
+ export default Image;
2
+ type Image = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const Image: import("svelte").Component<{
7
+ block: import("./image.svelte.js").ImageBlock;
8
+ }, {}, "">;
9
+ type $$ComponentProps = {
10
+ block: import("./image.svelte.js").ImageBlock;
11
+ };
@@ -0,0 +1,5 @@
1
+ export function insertImageFromFile(nabu: import("../nabu.svelte.js").Nabu, file: File): Promise<void>;
2
+ /**
3
+ * The image block: stored through the `files` option, with the `image:insert` and `image:pick` actions, image file paste and the "Image" slash entry.
4
+ */
5
+ export const ImageExtension: import("../../extend.js").Extension;
@@ -0,0 +1,34 @@
1
+ import { extension } from "../../utils/extensions";
2
+ import { ImageBlock } from "./image.svelte.js";
3
+ import ImageComponent from "./Image.svelte";
4
+ import { insertMediaFromFile, pickMedia, insertMediaUrl, mediaFileHandler } from "../media/media.helpers.js";
5
+
6
+ /**
7
+ * Insert an image block from a local File: optimistic preview → persist → ref.
8
+ * Re-exported for back-compat.
9
+ * @param {import('../nabu.svelte.js').Nabu} nabu @param {File} file
10
+ */
11
+ export const insertImageFromFile = (nabu, file) => insertMediaFromFile(nabu, 'image', file);
12
+
13
+ /**
14
+ * The image block: stored through the `files` option, with the `image:insert` and `image:pick` actions, image file paste and the "Image" slash entry.
15
+ */
16
+ export const ImageExtension = extension("image", {
17
+ // @ts-ignore — static-side variance on create()
18
+ block: ImageBlock,
19
+ component: ImageComponent,
20
+ // A file pasted from the clipboard becomes this block.
21
+ pasteFileHandlers: [mediaFileHandler('image', (file) => /^image\//i.test(file.type), 20)],
22
+ slashCommands: [
23
+ { title: 'Image', icon: '▢', aliases: ['image', 'img', 'photo', 'picture'], group: 'media', order: 0, run: (e) => e.exec('image:pick') },
24
+ ],
25
+ actions: {
26
+ 'image:pick': (nabu) => pickMedia(nabu, 'image', 'image/*'),
27
+ /**
28
+ * Insert from a URL (external ref). data: { ref, alt? }
29
+ * @param {import('../nabu.svelte.js').Nabu} nabu
30
+ * @param {{ ref: string, alt?: string }} data
31
+ */
32
+ 'image:insert': (nabu, data) => insertMediaUrl(nabu, 'image', data),
33
+ },
34
+ });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @import { Nabu, NabuNode } from "../nabu.svelte.js";
3
+ */
4
+ /**
5
+ * @typedef {NabuNode<{type: "image", ref: string, alt: string, status: string}>} ImageNode
6
+ */
7
+ /**
8
+ * Void image block. Extends MediaBlock for shared void/metadata behavior.
9
+ * No editable text — renders an inert <figure> with a single cursor position.
10
+ */
11
+ export class ImageBlock extends MediaBlock {
12
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
13
+ static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): any;
14
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
15
+ static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
16
+ static htmlRules: {
17
+ selector: string;
18
+ embed: boolean;
19
+ }[];
20
+ /**
21
+ * @param {Element} el
22
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
23
+ */
24
+ static fromHTML(el: Element): import("../../utils/extensions.js").PasteBlock | null;
25
+ static markdownRules: {
26
+ priority: number;
27
+ detect: RegExp;
28
+ consume: () => number;
29
+ }[];
30
+ /**
31
+ * A line that is only an image (`![alt](url "title")`, `![alt][ref]`) becomes an image block; anything else
32
+ * (text around it, unsafe URL) returns null and falls to the paragraph rule.
33
+ * @param {string[]} lines
34
+ * @param {{ parseInlineSegments?: (text: string) => Array<{ image?: { alt: string, ref: string } }> }} [helpers]
35
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
36
+ */
37
+ static fromMarkdown(lines: string[], helpers?: {
38
+ parseInlineSegments?: (text: string) => Array<{
39
+ image?: {
40
+ alt: string;
41
+ ref: string;
42
+ };
43
+ }>;
44
+ }): import("../../utils/extensions.js").PasteBlock | null;
45
+ /** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
46
+ static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): ImageBlock;
47
+ /** @param {Nabu} nabu @param {ImageNode} node */
48
+ constructor(nabu: Nabu, node: ImageNode);
49
+ component: import("svelte").Component<any, any, string> | import("svelte").Component<{
50
+ block: import("./image.svelte.js").ImageBlock;
51
+ }, {}, "">;
52
+ }
53
+ export type ImageNode = NabuNode<{
54
+ type: "image";
55
+ ref: string;
56
+ alt: string;
57
+ status: string;
58
+ }>;
59
+ import { MediaBlock } from "../media/media-block.svelte.js";
60
+ import type { Nabu } from "../nabu.svelte.js";
61
+ import type { NabuNode } from "../nabu.svelte.js";
@@ -0,0 +1,114 @@
1
+ import { MediaBlock } from "../media/media-block.svelte.js";
2
+ import { markdownImage } from "../media/markdown.js";
3
+ import ImageComponent from "./Image.svelte";
4
+ import { escapeHtml, escapeAttr, sanitizeUrl } from "../../utils/html.js";
5
+
6
+ /**
7
+ * @import { Nabu, NabuNode } from "../nabu.svelte.js";
8
+ */
9
+
10
+ /**
11
+ * @typedef {NabuNode<{type: "image", ref: string, alt: string, status: string}>} ImageNode
12
+ */
13
+
14
+ /**
15
+ * Void image block. Extends MediaBlock for shared void/metadata behavior.
16
+ * No editable text — renders an inert <figure> with a single cursor position.
17
+ */
18
+ // @ts-ignore — static-side variance on create()
19
+ export class ImageBlock extends MediaBlock {
20
+ /** @param {Nabu} nabu @param {ImageNode} node */
21
+ constructor(nabu, node) {
22
+ super(nabu, node);
23
+
24
+ this.serializers.set('markdown', () => ImageBlock.toMarkdown({ type: 'image', partial: false, props: this.exportProps }));
25
+ this.serializers.set('json', () => ({
26
+ id: this.id,
27
+ type: 'image',
28
+ props: this.exportProps,
29
+ }));
30
+ this.serializers.set('application/x-nabu+json', () => ({
31
+ type: 'image',
32
+ props: { ref: this.ref, alt: this.alt, ...this.clipboardState },
33
+ partial: false,
34
+ }));
35
+ }
36
+
37
+ component = $derived(this.nabu.components.get("image") || ImageComponent);
38
+
39
+ // ── Statics ──────────────────────────────────────────────────────────────
40
+
41
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
42
+ static toMarkdown(pb) {
43
+ if (!pb.props?.ref) return pb.props?.alt || ''; // no source (an embedded asset outside Nabu): the alt text only
44
+ return markdownImage(pb.props?.alt || '', pb.props.ref);
45
+ }
46
+
47
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
48
+ static toHtml(pb) {
49
+ const ref = pb.props?.ref || '';
50
+ const src = sanitizeUrl(ref, { kind: 'media' }); // null for an empty ref too
51
+ const alt = pb.props?.alt || '';
52
+ if (src === null) return alt ? '<p>' + escapeHtml(alt) + '</p>' : ''; // unsafe / empty source: no live <img>
53
+ return '<img src="' + escapeAttr(src) + '" alt="' + escapeAttr(alt) + '">';
54
+ }
55
+
56
+ static htmlRules = [
57
+ // `embed`: an <img> inside a paragraph is lifted out as an image block, the text around it stays (paste/html.paste.js).
58
+ { selector: 'img', embed: true },
59
+ ];
60
+
61
+ /**
62
+ * @param {Element} el
63
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
64
+ */
65
+ static fromHTML(el) {
66
+ const src = (el.getAttribute('src') || '').trim();
67
+ // No source (a lazy-loaded placeholder) or an unsafe one (javascript:, data:text/html…) never becomes an image block.
68
+ if (!src || sanitizeUrl(src, { kind: 'media' }) === null) return null;
69
+ return {
70
+ type: 'image',
71
+ props: {
72
+ ref: src,
73
+ alt: el.getAttribute('alt') || '',
74
+ },
75
+ partial: false,
76
+ };
77
+ }
78
+
79
+ static markdownRules = [
80
+ {
81
+ priority: 25,
82
+ // A line that starts with an image. `fromMarkdown` only accepts a line that IS an image; an image inside
83
+ // text is split out of the paragraph by the paragraph rule.
84
+ detect: /^!\[/,
85
+ consume: () => 1,
86
+ }
87
+ ];
88
+
89
+ /**
90
+ * A line that is only an image (`![alt](url "title")`, `![alt][ref]`) becomes an image block; anything else
91
+ * (text around it, unsafe URL) returns null and falls to the paragraph rule.
92
+ * @param {string[]} lines
93
+ * @param {{ parseInlineSegments?: (text: string) => Array<{ image?: { alt: string, ref: string } }> }} [helpers]
94
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
95
+ */
96
+ static fromMarkdown(lines, helpers) {
97
+ if (helpers?.parseInlineSegments) {
98
+ const segments = helpers.parseInlineSegments(lines[0].trim());
99
+ const image = segments.length === 1 ? segments[0].image : undefined;
100
+ return image ? { type: 'image', props: { alt: image.alt, ref: image.ref }, partial: false } : null;
101
+ }
102
+ const m = lines[0].match(/^!\[([^\]]*)\]\(([^)]+)\)/);
103
+ if (!m) return null;
104
+ if (sanitizeUrl(m[2].trim(), { kind: 'media' }) === null) return null; // falls back to a plain paragraph
105
+ return { type: 'image', props: { alt: m[1], ref: m[2] }, partial: false };
106
+ }
107
+
108
+ /** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
109
+ static create(nabu, type, props = {}, parentId = null, index = null) {
110
+ const node = MediaBlock.createNode(nabu, 'image', props, parentId, index);
111
+ const block = new ImageBlock(nabu, /** @type {ImageNode} */ (/** @type {unknown} */ (node)));
112
+ return block;
113
+ }
114
+ }
@@ -0,0 +1,3 @@
1
+ export { ImageBlock } from "./image.svelte.js";
2
+ export { default as ImageComponent } from "./Image.svelte";
3
+ export { ImageExtension, insertImageFromFile } from "./image.extension.js";
@@ -0,0 +1,3 @@
1
+ export { ImageBlock } from './image.svelte.js';
2
+ export { ImageExtension, insertImageFromFile } from './image.extension.js';
3
+ export { default as ImageComponent } from './Image.svelte';
@@ -1,4 +1,5 @@
1
1
  export * from "./block.svelte.js";
2
+ export * from "./text-block.svelte.js";
2
3
  export * from "./block.extension.js";
3
4
  export * from "./nabu.svelte.js";
4
5
  export * from "./megablock.svelte.js";
@@ -7,7 +8,16 @@ export * from "./paragraph";
7
8
  export * from "./heading";
8
9
  export * from "./list";
9
10
  export * from "./dialogue";
10
- export * from "./zone";
11
+ export * from "./blockquote";
12
+ export * from "./divider";
13
+ export * from "./code";
14
+ export * from "./callout";
15
+ export * from "./toggle";
16
+ export * from "./image";
17
+ export * from "./media";
18
+ export * from "./video";
19
+ export * from "./file";
20
+ export * from "./region";
11
21
  export * from "./selection.svelte.js";
12
22
  export { default as NabuEditor } from "./Nabu.svelte";
13
23
  export { default as BlockComponent } from "./Block.svelte";
@@ -1,4 +1,5 @@
1
1
  export * from "./block.svelte.js";
2
+ export * from "./text-block.svelte.js";
2
3
  export * from "./block.extension.js";
3
4
  export * from "./nabu.svelte.js";
4
5
  export * from "./megablock.svelte.js";
@@ -10,6 +11,15 @@ export * from "./paragraph";
10
11
  export * from "./heading";
11
12
  export * from "./list";
12
13
  export * from "./dialogue";
13
- export * from "./zone";
14
+ export * from "./blockquote";
15
+ export * from "./divider";
16
+ export * from "./code";
17
+ export * from "./callout";
18
+ export * from "./toggle";
19
+ export * from "./image";
20
+ export * from "./media";
21
+ export * from "./video";
22
+ export * from "./file";
23
+ export * from "./region";
14
24
 
15
25
  export * from "./selection.svelte.js";
@@ -5,11 +5,13 @@
5
5
  let {block} = $props();
6
6
  </script>
7
7
 
8
- <svelte:element
9
- this={block.listType === 'ordered' ? 'ol' : 'ul'}
8
+ <svelte:element
9
+ this={block.listType === 'ordered' ? 'ol' : 'ul'}
10
+ start={block.listType === 'ordered' ? (block.start ?? undefined) : undefined}
10
11
  data-block-id={block.id}
11
12
  data-block-type="list"
12
13
  class="nabu-list"
14
+ class:todo={block.listType === 'todo'}
13
15
  >
14
16
  {#each block.children as child (child.id)}
15
17
  <Block block={child} />
@@ -22,4 +24,9 @@
22
24
  margin-bottom: 0.5rem;
23
25
  padding-left: 1.5rem;
24
26
  }
27
+
28
+ .nabu-list.todo {
29
+ list-style: none;
30
+ padding-left: 0;
31
+ }
25
32
  </style>
@@ -6,7 +6,7 @@
6
6
  let {block} = $props();
7
7
  </script>
8
8
 
9
- <li
9
+ <li
10
10
  data-block-id={block.id}
11
11
  data-block-type="list-item"
12
12
  class="nabu-list-item"
@@ -14,8 +14,16 @@
14
14
  class:selected={block.selected}
15
15
  class:first={block.isSelectionStart}
16
16
  class:last={block.isSelectionEnd}
17
- >
18
- <div bind:this={block.element} class="item-content"><RichText delta={block.delta} /></div><!--
17
+ class:todo={block.isTodo}
18
+ >{#if block.isTodo}<button
19
+ class="nabu-todo-check"
20
+ data-nabu-ui
21
+ contenteditable="false"
22
+ type="button"
23
+ aria-pressed={block.checked}
24
+ aria-disabled={block.nabu.readonly ? 'true' : undefined}
25
+ onmousedown={(e) => { e.preventDefault(); block.toggleChecked(); }}
26
+ >{block.checked ? '☑' : '☐'}</button>{/if}<div bind:this={block.element} class="item-content" class:checked={block.checked}><RichText delta={block.delta} /></div><!--
19
27
  -->{#if block.children && block.children.length > 0}
20
28
  <div class="item-children">
21
29
  {#each block.children as child (child.id)}
@@ -28,22 +36,51 @@
28
36
  <style>
29
37
  .nabu-list-item {
30
38
  margin: 0.25rem 0;
31
-
39
+
32
40
  &.debug{
33
41
  &.selected > .item-content {
34
42
  background-color: rgba(59, 130, 246, 0.25);
35
43
  }
36
44
  }
37
-
45
+
46
+ &.todo {
47
+ display: flex;
48
+ flex-wrap: wrap;
49
+ align-items: flex-start;
50
+ gap: 0.2em 0.4em;
51
+ }
52
+ /* Checkbox + content share line 1; a nested sublist wraps to its own
53
+ full-width line below (without flex-wrap it would sit to the right). */
54
+ &.todo > .item-content { flex: 1; min-width: 0; }
55
+ &.todo > .item-children { flex-basis: 100%; }
38
56
  }
39
-
57
+
40
58
  .item-content {
41
59
  outline: none;
42
60
  white-space: pre-wrap;
43
61
  min-height: 1.5em; /* Permet de cliquer dans un item vide */
62
+
63
+ &.checked {
64
+ text-decoration: line-through;
65
+ opacity: 0.55;
66
+ }
44
67
  }
45
-
68
+
46
69
  .item-children {
47
70
  /* Pas de margin-left ici, c'est le <ul> imbriqué qui gèrera l'indentation */
48
71
  }
72
+
73
+ .nabu-todo-check {
74
+ flex-shrink: 0;
75
+ background: none;
76
+ border: none;
77
+ padding: 0;
78
+ margin: 0;
79
+ cursor: pointer;
80
+ user-select: none;
81
+ font-size: 1em;
82
+ line-height: 1.5;
83
+ outline: none;
84
+ vertical-align: top;
85
+ }
49
86
  </style>
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Turns an item into a block that is not a list item (see the file header). Moves only; no commit.
3
+ * @param {Nabu} nabu
4
+ * @param {NabuNode} item a list-item node
5
+ * @param {string} type
6
+ * @param {Record<string, any>} [props]
7
+ * @param {boolean} [numbered=true] see `liftItemTo`
8
+ * @returns {boolean} whether the item was retyped
9
+ */
10
+ export function retypeItem(nabu: Nabu, item: NabuNode, type: string, props?: Record<string, any>, numbered?: boolean): boolean;
11
+ /**
12
+ * Moves an item to a list of another type (see the file header). Moves only; no commit.
13
+ * @param {Nabu} nabu
14
+ * @param {NabuNode} item a list-item node
15
+ * @param {"bullet" | "ordered" | "todo"} listType
16
+ * @returns {boolean} whether something changed (false: already of that type, or not in a list)
17
+ */
18
+ export function convertItemToListType(nabu: Nabu, item: NabuNode, listType: "bullet" | "ordered" | "todo"): boolean;
19
+ import type { Nabu } from "../nabu.svelte.js";
20
+ import type { NabuNode } from "../nabu.svelte.js";
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Changing the TYPE of ONE list item, in place: the rest of the list is not touched.
3
+ *
4
+ * - to another LIST type (bullet / ordered / todo): the item (with its sublists) goes into a new list of the
5
+ * target type, placed between the part of the list before it and the part after it (both keep their
6
+ * type; an ORDERED tail keeps counting through `start`). Adjacent lists of the same type are merged by the
7
+ * normalizer afterwards. The same type is a no-op. Entering a todo list sets `checked: false`, leaving
8
+ * one drops `checked`.
9
+ * This works at ANY nesting level (P-28): inside a sublist the three parts are sublists of the same
10
+ * parent item, in place, side by side (`a > [ul[s1], ol[s2], ul[s3]]`); nothing is promoted. A sole child
11
+ * converted to another list type just changes the type of its list (which the normalizer then merges with
12
+ * an adjacent sublist of the new type).
13
+ * - to any other block (paragraph, heading, quote, code…): the item leaves its list exactly like the
14
+ * top-level Backspace (see step-back.js `liftItemTo`). A NESTED item cannot become a non-list block where it
15
+ * is (a list only holds items), so it is first unindented up to the top level (exactly what repeated
16
+ * Shift+Tab / Backspace do: the following siblings, level after level, become its children, so the
17
+ * document order and every item survive) and then lifted as a top-level item.
18
+ *
19
+ * Moves on tree NODES only, no commit (the caller owns the transaction, hence the undo step).
20
+ *
21
+ * @import { Nabu, NabuNode } from "../nabu.svelte.js";
22
+ */
23
+
24
+ import { List, listStart } from "./list.svelte.js";
25
+ import { typeOf, kids, listTypeOf, dropIfEmpty, unindentNode } from "./indent.js";
26
+ import { liftItemTo } from "./step-back.js";
27
+
28
+ /** Whether the item sits in a sublist of another item. @param {NabuNode} item */
29
+ const isNested = (item) => typeOf(item.parent()?.parent()) === "list-item";
30
+
31
+ /**
32
+ * Unindents a nested item until it is top-level. Moves only.
33
+ * @param {Nabu} nabu
34
+ * @param {NabuNode} item
35
+ */
36
+ function hoistToTopLevel(nabu, item) {
37
+ while (isNested(item)) if (!unindentNode(nabu, item)) break;
38
+ }
39
+
40
+ /**
41
+ * Turns an item into a block that is not a list item (see the file header). Moves only; no commit.
42
+ * @param {Nabu} nabu
43
+ * @param {NabuNode} item a list-item node
44
+ * @param {string} type
45
+ * @param {Record<string, any>} [props]
46
+ * @param {boolean} [numbered=true] see `liftItemTo`
47
+ * @returns {boolean} whether the item was retyped
48
+ */
49
+ export function retypeItem(nabu, item, type, props = {}, numbered = true) {
50
+ if (type === "list-item") return false;
51
+ hoistToTopLevel(nabu, item);
52
+ return liftItemTo(nabu, item, type, props, numbered);
53
+ }
54
+
55
+ /**
56
+ * Moves an item to a list of another type (see the file header). Moves only; no commit.
57
+ * @param {Nabu} nabu
58
+ * @param {NabuNode} item a list-item node
59
+ * @param {"bullet" | "ordered" | "todo"} listType
60
+ * @returns {boolean} whether something changed (false: already of that type, or not in a list)
61
+ */
62
+ export function convertItemToListType(nabu, item, listType) {
63
+ const list = item.parent();
64
+ if (!list || typeOf(list) !== "list" || listTypeOf(list) === listType) return false;
65
+ const current = listTypeOf(list);
66
+ const data = /** @type {any} */ (item.data);
67
+ if (kids(list).length === 1) {
68
+ // The only item: the list itself changes type.
69
+ /** @type {any} */ (list.data).set("listType", listType);
70
+ if (listType !== "ordered" && /** @type {any} */ (list.data).get("start") !== undefined) /** @type {any} */ (list.data).delete("start");
71
+ } else {
72
+ const index = item.index() ?? 0;
73
+ const followers = kids(list).slice(index + 1);
74
+ const parentId = list.parent()?.id.toString() ?? null;
75
+ // The number the first follower had: the list's own start + the items before it (item included).
76
+ const tailStart = (listStart(current, /** @type {any} */ (list.data).get("start")) ?? 1) + index + 1;
77
+ // List.create, not nabu.insert(): that commits, and the empty list would be normalized away.
78
+ const middle = List.create(nabu, "list", { listType }, parentId).node;
79
+ middle.moveAfter(list);
80
+ item.move(middle, 0);
81
+ if (followers.length) {
82
+ const tail = List.create(nabu, "list", { listType: current, start: tailStart }, parentId).node;
83
+ tail.moveAfter(middle);
84
+ for (const follower of followers) follower.move(tail, kids(tail).length);
85
+ }
86
+ dropIfEmpty(nabu, list);
87
+ }
88
+
89
+ if (listType === "todo") data.set("checked", false);
90
+ else if (data.get("checked") !== undefined) data.delete("checked");
91
+ return true;
92
+ }