@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,6 +1,8 @@
1
1
  // @ts-ignore
2
2
  import { MediaBlock } from "../media/media-block.svelte.js";
3
+ import { markdownMediaLink } from "../media/markdown.js";
3
4
  import FileComponent from "./File.svelte";
5
+ import { escapeHtml, escapeAttr, sanitizeUrl } from "../../utils/html.js";
4
6
 
5
7
  /**
6
8
  * @import { Nabu, NabuNode } from "../nabu.svelte.js";
@@ -16,15 +18,15 @@ export class FileBlock extends MediaBlock {
16
18
  constructor(nabu, node) {
17
19
  super(nabu, node);
18
20
 
19
- this.serializers.set('markdown', () => '[' + (this.name || 'file') + '](' + this.ref + ')');
21
+ this.serializers.set('markdown', () => FileBlock.toMarkdown({ type: 'file', partial: false, props: this.exportProps }));
20
22
  this.serializers.set('json', () => ({
21
23
  id: this.id,
22
24
  type: 'file',
23
- props: { ref: this.ref, name: this.name },
25
+ props: this.exportProps,
24
26
  }));
25
27
  this.serializers.set('application/x-nabu+json', () => ({
26
28
  type: 'file',
27
- props: { ref: this.ref, name: this.name },
29
+ props: { ref: this.ref, name: this.name, ...this.clipboardState },
28
30
  partial: false,
29
31
  }));
30
32
  }
@@ -35,12 +37,17 @@ export class FileBlock extends MediaBlock {
35
37
 
36
38
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
37
39
  static toMarkdown(pb) {
38
- return '[' + (pb.props?.name || 'file') + '](' + (pb.props?.ref || '') + ')';
40
+ if (!pb.props?.ref) return pb.props?.name || 'file'; // no source: the file name only
41
+ return markdownMediaLink(pb.props?.name || 'file', pb.props.ref);
39
42
  }
40
43
 
41
44
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
42
45
  static toHtml(pb) {
43
- return '<a href="' + (pb.props?.ref || '') + '" download="' + (pb.props?.name || '') + '">' + (pb.props?.name || 'file') + '</a>';
46
+ const ref = pb.props?.ref || '';
47
+ const href = sanitizeUrl(ref, { kind: 'media' }); // null for an empty ref too
48
+ const name = pb.props?.name || '';
49
+ if (href === null) return '<p>' + escapeHtml(name || 'file') + '</p>';
50
+ return '<a href="' + escapeAttr(href) + '" download="' + escapeAttr(name) + '">' + escapeHtml(name || 'file') + '</a>';
44
51
  }
45
52
 
46
53
  static htmlRules = [
@@ -52,17 +59,16 @@ export class FileBlock extends MediaBlock {
52
59
  * @returns {import('../../utils/extensions.js').PasteBlock}
53
60
  */
54
61
  static fromHTML(el) {
55
- return {
56
- type: 'file',
57
- props: {
58
- ref: el.getAttribute('href') || '',
59
- name: el.getAttribute('download') || el.textContent || '',
60
- },
61
- partial: false,
62
- };
62
+ const href = el.getAttribute('href') || '';
63
+ const name = el.getAttribute('download') || el.textContent || '';
64
+ // An unsafe href never becomes a file block: keep the label as plain text.
65
+ if (href && sanitizeUrl(href, { kind: 'media' }) === null) {
66
+ return { type: 'paragraph', delta: name ? [{ insert: name }] : [], partial: false };
67
+ }
68
+ return { type: 'file', props: { ref: href, name }, partial: false };
63
69
  }
64
70
 
65
- /** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
71
+ /** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
66
72
  static create(nabu, type, props = {}, parentId = null, index = null) {
67
73
  const node = MediaBlock.createNode(nabu, 'file', props, parentId, index);
68
74
  const block = new FileBlock(nabu, /** @type {any} */ (node));
@@ -1,6 +1,5 @@
1
1
  <script>
2
2
  import RichText from '../../behaviors/text/RichText.svelte';
3
- import { getPlaceholder } from '../../utils/placeholders.js';
4
3
  /** @type {{block: import('./heading.svelte.js').Heading}}*/
5
4
  let {block} = $props();
6
5
  </script>
@@ -10,7 +9,7 @@
10
9
  bind:this={block.element}
11
10
  data-block-id={block.id}
12
11
  data-block-type="heading"
13
- data-placeholder={block.text ? '' : getPlaceholder('heading', block.level)}
12
+ data-placeholder={block.placeholder}
14
13
  class="nabu-heading"
15
14
  class:debug={block.nabu.debugging}
16
15
  class:selected={block.selected}
@@ -1,27 +1,39 @@
1
- /**
2
- * @import { Nabu, NabuNode } from "../nabu.svelte.js";
3
- */
4
- /**
5
- * @typedef {NabuNode<{type: "heading", text: LoroText, level: number}>} HeadingNode
6
- */
7
1
  export class Heading extends TextBlock {
2
+ /** @param {Heading} block */
3
+ static placeholder: (block: Heading) => string;
8
4
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
9
5
  static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
10
6
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
11
7
  static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
12
- static markdownRules: {
8
+ /**
9
+ * Two rules: the ATX heading (`## Title`, up to 3 spaces of indent) and the setext heading (`Title` then `===` for a
10
+ * level 1, `---` for a level 2). The setext rule sits just ABOVE the paragraph catch-all and BELOW every block rule: a
11
+ * line that starts a list, a quote, a fence, a divider… never becomes a heading text, and a `---` after a blank line
12
+ * (nothing to underline) stays a divider. In a paste a heading text is ONE line (one line = one block); on import
13
+ * (`joinLines`) it is the whole paragraph above the underline (CommonMark).
14
+ */
15
+ static markdownRules: ({
13
16
  priority: number;
17
+ interruptsParagraph: boolean;
14
18
  detect: RegExp;
15
19
  consume: () => number;
16
- }[];
20
+ setext?: undefined;
21
+ } | {
22
+ priority: number;
23
+ setext: boolean;
24
+ detect(line: string, lines: string[], i: number, helpers: any): boolean;
25
+ consume(lines: string[], i: number, helpers: any): number;
26
+ interruptsParagraph?: undefined;
27
+ })[];
17
28
  /**
18
29
  * @param {string[]} lines
19
30
  * @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
31
+ * @param {import('../../utils/extensions.js').MarkdownRule} [rule]
20
32
  * @returns {import('../../utils/extensions.js').PasteBlock | null}
21
33
  */
22
34
  static fromMarkdown(lines: string[], { parseInline }: {
23
35
  parseInline: (text: string) => import("loro-crdt").Delta<string>[];
24
- }): import("../../utils/extensions.js").PasteBlock | null;
36
+ }, rule?: import("../../utils/extensions.js").MarkdownRule): import("../../utils/extensions.js").PasteBlock | null;
25
37
  static htmlRules: {
26
38
  selector: string;
27
39
  props: {
@@ -41,8 +53,8 @@ export class Heading extends TextBlock {
41
53
  level?: number;
42
54
  };
43
55
  }): import("../../utils/extensions.js").PasteBlock | null;
44
- /** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
45
- static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): Heading;
56
+ /** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
57
+ static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): Heading;
46
58
  /** @param {Nabu} nabu @param {HeadingNode} node */
47
59
  constructor(nabu: Nabu, node: HeadingNode);
48
60
  /** @type {number} */
@@ -11,6 +11,26 @@ import { LoroText } from "loro-crdt";
11
11
  * @typedef {NabuNode<{type: "heading", text: LoroText, level: number}>} HeadingNode
12
12
  */
13
13
 
14
+ const SETEXT_UNDERLINE = /^ {0,3}(?:=+|-+)[ \t]*$/;
15
+
16
+ /**
17
+ * Index of the setext underline (`===` / `---`) that turns the text starting at line `i` into a heading, or -1. A paste
18
+ * heading text is the single line `i`; on import (`joinLines`) it is every line up to the underline, as long as none of
19
+ * them starts a block of its own.
20
+ * @param {string[]} lines
21
+ * @param {number} i
22
+ * @param {{ joinLines?: boolean, interrupts?: (lines: string[], k: number) => boolean }} [helpers]
23
+ * @returns {number}
24
+ */
25
+ function setextEnd(lines, i, helpers) {
26
+ const last = helpers?.joinLines ? lines.length - 1 : Math.min(i + 1, lines.length - 1);
27
+ for (let j = i + 1; j <= last; j++) {
28
+ if (SETEXT_UNDERLINE.test(lines[j])) return j;
29
+ if (!lines[j].trim() || helpers?.interrupts?.(lines, j)) return -1;
30
+ }
31
+ return -1;
32
+ }
33
+
14
34
  export class Heading extends TextBlock {
15
35
  /** @param {Nabu} nabu @param {HeadingNode} node */
16
36
  constructor(nabu, node) {
@@ -19,7 +39,7 @@ export class Heading extends TextBlock {
19
39
 
20
40
  this.level = data.get("level") || 1;
21
41
 
22
- this.serializers.set('markdown', () => `${'#'.repeat(this.level)} ${this.behavior.toMarkdown()}`);
42
+ this.serializers.set('markdown', () => { const md = this.behavior.toMarkdown(); return md ? `${'#'.repeat(this.level)} ${md}` : ''; }); // an empty heading has no markdown (`## ` would read back as text)
23
43
  this.serializers.set('json', () => ({
24
44
  id: this.id,
25
45
  type: 'heading',
@@ -37,39 +57,74 @@ export class Heading extends TextBlock {
37
57
  /** @type {number} */
38
58
  level = $state(1);
39
59
 
60
+ /** @param {Heading} block */
61
+ static placeholder = (block) => `Heading ${block.level}`;
62
+
40
63
  component = $derived(this.nabu.components.get("heading") || HeadingComponent);
41
64
 
42
65
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
43
66
  static toMarkdown(pb) {
44
- const level = pb.props?.level ?? 1;
45
- return `${'#'.repeat(level)} ${deltaToMarkdown(pb.delta || [])}`;
67
+ const n = Math.trunc(Number(pb.props?.level));
68
+ const level = n >= 1 && n <= 6 ? n : 1; // never interpolate an arbitrary value into a tag name
69
+ const md = deltaToMarkdown(pb.delta || []);
70
+ return md ? `${'#'.repeat(level)} ${md}` : ''; // an empty heading has no markdown (`## ` would read back as text)
46
71
  }
47
72
 
48
73
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
49
74
  static toHtml(pb) {
50
- const level = pb.props?.level ?? 1;
75
+ const n = Math.trunc(Number(pb.props?.level));
76
+ const level = n >= 1 && n <= 6 ? n : 1; // never interpolate an arbitrary value into a tag name
51
77
  return `<h${level}>${deltaToHtml(pb.delta || [])}</h${level}>`;
52
78
  }
53
79
 
80
+ /**
81
+ * Two rules: the ATX heading (`## Title`, up to 3 spaces of indent) and the setext heading (`Title` then `===` for a
82
+ * level 1, `---` for a level 2). The setext rule sits just ABOVE the paragraph catch-all and BELOW every block rule: a
83
+ * line that starts a list, a quote, a fence, a divider… never becomes a heading text, and a `---` after a blank line
84
+ * (nothing to underline) stays a divider. In a paste a heading text is ONE line (one line = one block); on import
85
+ * (`joinLines`) it is the whole paragraph above the underline (CommonMark).
86
+ */
54
87
  static markdownRules = [
55
88
  {
56
89
  priority: 10,
57
- detect: /^#{1,6} /,
90
+ interruptsParagraph: true,
91
+ detect: /^ {0,3}#{1,6}[ \t]/,
58
92
  consume: () => 1,
93
+ },
94
+ {
95
+ priority: 5,
96
+ setext: true,
97
+ detect(/** @type {string} */ line, /** @type {string[]} */ lines, /** @type {number} */ i, /** @type {any} */ helpers) {
98
+ return setextEnd(lines, i, helpers) > i;
99
+ },
100
+ consume(/** @type {string[]} */ lines, /** @type {number} */ i, /** @type {any} */ helpers) {
101
+ return setextEnd(lines, i, helpers) - i + 1;
102
+ },
59
103
  }
60
104
  ];
61
105
 
62
106
  /**
63
107
  * @param {string[]} lines
64
108
  * @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
109
+ * @param {import('../../utils/extensions.js').MarkdownRule} [rule]
65
110
  * @returns {import('../../utils/extensions.js').PasteBlock | null}
66
111
  */
67
- static fromMarkdown(lines, { parseInline }) {
68
- const m = lines[0].match(/^(#{1,6})\s+(.*)/);
69
- if (!m) return null;
70
- const delta = parseInline(m[2]);
112
+ static fromMarkdown(lines, { parseInline }, rule) {
113
+ let level;
114
+ let text;
115
+ if (rule?.setext) {
116
+ const underline = lines[lines.length - 1].trim();
117
+ level = underline[0] === '=' ? 1 : 2;
118
+ text = lines.slice(0, -1).map((line) => line.trim().replace(/\\$/, '')).join(' ');
119
+ } else {
120
+ const m = lines[0].match(/^ {0,3}(#{1,6})[ \t]+(.*)/);
121
+ if (!m) return null;
122
+ level = m[1].length;
123
+ text = m[2];
124
+ }
125
+ const delta = parseInline(text);
71
126
  if (!delta.length) return null;
72
- return { type: 'heading', props: { level: m[1].length }, delta, partial: false };
127
+ return { type: 'heading', props: { level }, delta, partial: false };
73
128
  }
74
129
 
75
130
  static htmlRules = [
@@ -93,15 +148,15 @@ export class Heading extends TextBlock {
93
148
  return { type: 'heading', props: { level: rule?.props?.level ?? 1 }, delta, partial: false };
94
149
  }
95
150
 
96
- /** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
151
+ /** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
97
152
  static create(nabu, type, props = {}, parentId = null, index = null) {
98
- const node = nabu.tree.createNode(parentId || undefined, index || undefined);
153
+ const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
99
154
  node.data.set("type", "heading");
100
155
  node.data.set("level", props.level || 1);
101
156
  const container = node.data.setContainer("text", new LoroText());
102
157
  if (props.text) container.insert(0, props.text);
103
158
  if (props.delta) container.applyDelta([...props.delta]);
104
- const block = new Heading(nabu, node);
159
+ const block = new Heading(nabu, /** @type {HeadingNode} */ (node));
105
160
  return block;
106
161
  }
107
162
  }
@@ -40,13 +40,15 @@ export const onBeforeInput = (nabu, event, block) => {
40
40
 
41
41
  const level = match[1].length;
42
42
 
43
- if (block.type === "heading" && block.level === level) return CONTINUE;
44
-
45
- behavior.delete({index: 0, length: level});
43
+ if (block.type === "heading" && /** @type {Heading} */ (block).level === level) return CONTINUE;
46
44
 
47
45
  const blockId = block.node.id.toString();
48
-
49
- block.transformTo("heading", { level });
46
+
47
+ // Undo gives back "# " (trigger space included): see Nabu.shortcut()
48
+ nabu.shortcut(block, " ", (b) => {
49
+ b.delete({index: 0, length: level + 1}); // the hashes + the trigger space
50
+ block.transformTo("heading", { level });
51
+ });
50
52
 
51
53
  tick().then(() => {
52
54
  const block = nabu.blocks.get(blockId);
@@ -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
 
@@ -1,6 +1,7 @@
1
1
  <script>
2
2
  /** @type {{ block: import('./image.svelte.js').ImageBlock }} */
3
3
  let { block } = $props();
4
+ $effect(() => block.holdSource());
4
5
  const src = $derived(block.displaySrc);
5
6
  </script>
6
7
 
@@ -14,12 +15,14 @@
14
15
  class:selected={block.selected}
15
16
  class:pending={block.status === 'pending'}
16
17
  class:error={block.status === 'error'}
18
+ class:missing={block.isMissing}
17
19
  >
18
20
  {#if block.status === 'error'}
19
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>
20
24
  {:else if src}
21
- <img src={src} alt={block.alt} draggable="false" />
22
- {#if block.status === 'pending'}<div class="nabu-image-spinner">Uploading…</div>{/if}
25
+ <img src={src} alt={block.alt} draggable="false" />{#if block.status === 'pending'}<div class="nabu-image-spinner">Uploading…</div>{/if}
23
26
  {:else}
24
27
  <div class="nabu-image-empty">No image</div>
25
28
  {/if}
@@ -1,2 +1,5 @@
1
1
  export function insertImageFromFile(nabu: import("../nabu.svelte.js").Nabu, file: File): Promise<void>;
2
- export const ImageExtension: import("../..").Extension;
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;
@@ -1,7 +1,7 @@
1
1
  import { extension } from "../../utils/extensions";
2
2
  import { ImageBlock } from "./image.svelte.js";
3
3
  import ImageComponent from "./Image.svelte";
4
- import { insertMediaFromFile, pickMedia, insertMediaUrl } from "../media/media.helpers.js";
4
+ import { insertMediaFromFile, pickMedia, insertMediaUrl, mediaFileHandler } from "../media/media.helpers.js";
5
5
 
6
6
  /**
7
7
  * Insert an image block from a local File: optimistic preview → persist → ref.
@@ -10,10 +10,18 @@ import { insertMediaFromFile, pickMedia, insertMediaUrl } from "../media/media.h
10
10
  */
11
11
  export const insertImageFromFile = (nabu, file) => insertMediaFromFile(nabu, 'image', file);
12
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
+ */
13
16
  export const ImageExtension = extension("image", {
14
17
  // @ts-ignore — static-side variance on create()
15
18
  block: ImageBlock,
16
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
+ ],
17
25
  actions: {
18
26
  'image:pick': (nabu) => pickMedia(nabu, 'image', 'image/*'),
19
27
  /**
@@ -10,29 +10,40 @@
10
10
  */
11
11
  export class ImageBlock extends MediaBlock {
12
12
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
13
- static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
13
+ static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): any;
14
14
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
15
15
  static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
16
16
  static htmlRules: {
17
17
  selector: string;
18
+ embed: boolean;
18
19
  }[];
19
20
  /**
20
21
  * @param {Element} el
21
- * @returns {import('../../utils/extensions.js').PasteBlock}
22
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
22
23
  */
23
- static fromHTML(el: Element): import("../../utils/extensions.js").PasteBlock;
24
+ static fromHTML(el: Element): import("../../utils/extensions.js").PasteBlock | null;
24
25
  static markdownRules: {
25
26
  priority: number;
26
27
  detect: RegExp;
27
28
  consume: () => number;
28
29
  }[];
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.
30
33
  * @param {string[]} lines
34
+ * @param {{ parseInlineSegments?: (text: string) => Array<{ image?: { alt: string, ref: string } }> }} [helpers]
31
35
  * @returns {import('../../utils/extensions.js').PasteBlock | null}
32
36
  */
33
- static fromMarkdown(lines: string[]): import("../../utils/extensions.js").PasteBlock | null;
34
- /** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
35
- static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): ImageBlock;
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;
36
47
  /** @param {Nabu} nabu @param {ImageNode} node */
37
48
  constructor(nabu: Nabu, node: ImageNode);
38
49
  component: import("svelte").Component<any, any, string> | import("svelte").Component<{
@@ -1,5 +1,7 @@
1
1
  import { MediaBlock } from "../media/media-block.svelte.js";
2
+ import { markdownImage } from "../media/markdown.js";
2
3
  import ImageComponent from "./Image.svelte";
4
+ import { escapeHtml, escapeAttr, sanitizeUrl } from "../../utils/html.js";
3
5
 
4
6
  /**
5
7
  * @import { Nabu, NabuNode } from "../nabu.svelte.js";
@@ -19,15 +21,15 @@ export class ImageBlock extends MediaBlock {
19
21
  constructor(nabu, node) {
20
22
  super(nabu, node);
21
23
 
22
- this.serializers.set('markdown', () => '![' + this.alt + '](' + this.ref + ')');
24
+ this.serializers.set('markdown', () => ImageBlock.toMarkdown({ type: 'image', partial: false, props: this.exportProps }));
23
25
  this.serializers.set('json', () => ({
24
26
  id: this.id,
25
27
  type: 'image',
26
- props: { ref: this.ref, alt: this.alt },
28
+ props: this.exportProps,
27
29
  }));
28
30
  this.serializers.set('application/x-nabu+json', () => ({
29
31
  type: 'image',
30
- props: { ref: this.ref, alt: this.alt },
32
+ props: { ref: this.ref, alt: this.alt, ...this.clipboardState },
31
33
  partial: false,
32
34
  }));
33
35
  }
@@ -38,27 +40,36 @@ export class ImageBlock extends MediaBlock {
38
40
 
39
41
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
40
42
  static toMarkdown(pb) {
41
- return '![' + (pb.props?.alt || '') + '](' + (pb.props?.ref || '') + ')';
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);
42
45
  }
43
46
 
44
47
  /** @param {import('../../utils/extensions.js').PasteBlock} pb */
45
48
  static toHtml(pb) {
46
- return '<img src="' + (pb.props?.ref || '') + '" alt="' + (pb.props?.alt || '') + '">';
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) + '">';
47
54
  }
48
55
 
49
56
  static htmlRules = [
50
- { selector: 'img' },
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 },
51
59
  ];
52
60
 
53
61
  /**
54
62
  * @param {Element} el
55
- * @returns {import('../../utils/extensions.js').PasteBlock}
63
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
56
64
  */
57
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;
58
69
  return {
59
70
  type: 'image',
60
71
  props: {
61
- ref: el.getAttribute('src') || '',
72
+ ref: src,
62
73
  alt: el.getAttribute('alt') || '',
63
74
  },
64
75
  partial: false,
@@ -68,22 +79,33 @@ export class ImageBlock extends MediaBlock {
68
79
  static markdownRules = [
69
80
  {
70
81
  priority: 25,
71
- detect: /^!\[[^\]]*\]\([^)]+\)/,
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: /^!\[/,
72
85
  consume: () => 1,
73
86
  }
74
87
  ];
75
88
 
76
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.
77
92
  * @param {string[]} lines
93
+ * @param {{ parseInlineSegments?: (text: string) => Array<{ image?: { alt: string, ref: string } }> }} [helpers]
78
94
  * @returns {import('../../utils/extensions.js').PasteBlock | null}
79
95
  */
80
- static fromMarkdown(lines) {
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
+ }
81
102
  const m = lines[0].match(/^!\[([^\]]*)\]\(([^)]+)\)/);
82
103
  if (!m) return null;
104
+ if (sanitizeUrl(m[2].trim(), { kind: 'media' }) === null) return null; // falls back to a plain paragraph
83
105
  return { type: 'image', props: { alt: m[1], ref: m[2] }, partial: false };
84
106
  }
85
107
 
86
- /** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
108
+ /** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
87
109
  static create(nabu, type, props = {}, parentId = null, index = null) {
88
110
  const node = MediaBlock.createNode(nabu, 'image', props, parentId, index);
89
111
  const block = new ImageBlock(nabu, /** @type {ImageNode} */ (/** @type {unknown} */ (node)));
@@ -8,7 +8,6 @@ export * from "./paragraph";
8
8
  export * from "./heading";
9
9
  export * from "./list";
10
10
  export * from "./dialogue";
11
- export * from "./zone";
12
11
  export * from "./blockquote";
13
12
  export * from "./divider";
14
13
  export * from "./code";
@@ -18,6 +17,7 @@ export * from "./image";
18
17
  export * from "./media";
19
18
  export * from "./video";
20
19
  export * from "./file";
20
+ export * from "./region";
21
21
  export * from "./selection.svelte.js";
22
22
  export { default as NabuEditor } from "./Nabu.svelte";
23
23
  export { default as BlockComponent } from "./Block.svelte";
@@ -11,7 +11,6 @@ export * from "./paragraph";
11
11
  export * from "./heading";
12
12
  export * from "./list";
13
13
  export * from "./dialogue";
14
- export * from "./zone";
15
14
  export * from "./blockquote";
16
15
  export * from "./divider";
17
16
  export * from "./code";
@@ -21,5 +20,6 @@ export * from "./image";
21
20
  export * from "./media";
22
21
  export * from "./video";
23
22
  export * from "./file";
23
+ export * from "./region";
24
24
 
25
25
  export * from "./selection.svelte.js";
@@ -7,6 +7,7 @@
7
7
 
8
8
  <svelte:element
9
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"