@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
@@ -3,8 +3,6 @@
3
3
  * @import { Nabu } from './nabu.svelte.js';
4
4
  */
5
5
 
6
- import { MegaBlock } from './megablock.svelte.js';
7
-
8
6
  /**
9
7
  * Walks up from `block` toward `container` and returns the direct child of
10
8
  * `container` that is (or contains) `block`.
@@ -101,217 +99,379 @@ export function wrapOrphan(nabu, block) {
101
99
  return wrapper;
102
100
  }
103
101
 
102
+
103
+ // ── Deleting a range across blocks ──────────────────────────────────────────
104
+
104
105
  /**
105
- * Shared beforeinput logic for block containers (Nabu root and MegaBlock).
106
- *
107
- * Uses a "spine" approach: for each selection boundary, we walk up the parent
108
- * chain until we hit the container, collecting intermediate blocks to clean up
109
- * along the way. This correctly handles arbitrarily nested structures.
106
+ * A selected range of the document, as model positions.
107
+ * @typedef {object} DeletionRange
108
+ * @property {Block} startBlock Block holding the start of the range (earlier in document order).
109
+ * @property {number} startOffset Text offset of the start inside `startBlock`.
110
+ * @property {Block} endBlock Block holding the end of the range.
111
+ * @property {number} endOffset Text offset of the end inside `endBlock`.
112
+ */
113
+
114
+ /** @param {Block | null | undefined} block @returns {Block[]} */
115
+ const kidsOf = (block) => /** @type {Block[]} */ (/** @type {any} */ (block)?.children ?? []);
116
+
117
+ /** Children of `parent`, or the root blocks when `parent` is null. @param {Nabu} nabu @param {Block | null} parent */
118
+ const childrenOf = (nabu, parent) => (parent ? kidsOf(parent) : /** @type {Block[]} */ (nabu.children));
119
+
120
+ /** @param {Block} block @returns {import('../behaviors/text/text.behavior.svelte.js').TextBehavior | null} */
121
+ const textOf = (block) => /** @type {any} */ (block.behaviors?.get('text')) ?? null;
122
+
123
+ /**
124
+ * `block` and its ancestors, up to (and excluding) `stop`: `[block, parent, …, child of stop]`.
125
+ * @param {Block} block
126
+ * @param {Block | null} stop
127
+ * @returns {Block[]}
128
+ */
129
+ function pathUp(block, stop) {
130
+ /** @type {Block[]} */
131
+ const path = [];
132
+ for (let cur = /** @type {Block | null} */ (block); cur && cur !== stop; cur = cur.parent ?? null) path.push(cur);
133
+ return path;
134
+ }
135
+
136
+ /**
137
+ * Re-homes `blocks`, in order, right after `anchor` (a block of the tree), wrapping the ones whose type
138
+ * demands a specific parent (`requiredParent`) in a fresh wrapper. No commit.
139
+ * @param {Nabu} nabu
140
+ * @param {Block} anchor
141
+ * @param {Block[]} blocks
142
+ */
143
+ function rehomeAfter(nabu, anchor, blocks) {
144
+ let after = anchor.node;
145
+ for (const block of blocks) {
146
+ block.node.moveAfter(after);
147
+ const wrapper = wrapOrphan(nabu, block);
148
+ after = (wrapper ?? block).node;
149
+ }
150
+ }
151
+
152
+ /**
153
+ * The deletion of a range whose text positions are all plain (no isolated block inside: see {@link deleteRange}).
154
+ * Mutates the Loro tree and texts, never commits.
110
155
  *
111
- * Spine termination differs between the two callers:
112
- * - MegaBlock: the container IS pushed into the spine (loop exits on === container),
113
- * so the direct child of container is at spine.at(-2).
114
- * - Nabu: root blocks have parent = null, so the loop breaks before Nabu is ever
115
- * pushed, and the direct child of container is at spine.at(-1).
116
- * Both cases are unified by the directChild() helper below.
156
+ * Model: document order is pre-order, a block's own text coming before its children. The range runs from
157
+ * (`startBlock`, `startOffset`) to (`endBlock`, `endOffset`):
158
+ * - the head of the start block and the tail of the end block are merged at the junction (the end block's
159
+ * children follow it: adopted by the start block when it can hold children, else promoted after it);
160
+ * - everything strictly inside the range is destroyed: blocks between the two spines, the later children of
161
+ * every block on the start spine, the earlier children of every block on the end spine, and the blocks of
162
+ * the end spine themselves (their own text lies inside the range);
163
+ * - what follows the end point inside the partially-selected blocks of the end spine SURVIVES, in document
164
+ * order, re-homed right after the start block (`wrapOrphan` honours `requiredParent`), so it keeps its
165
+ * position relative to everything outside the range; blocks that follow the end spine at the level of the
166
+ * common ancestor are untouched;
167
+ * - when the start block is an ANCESTOR of the end block (it starts in a hybrid's text and ends in its
168
+ * body), the remaining body stays where it is: structure-only blocks of the end spine are kept in place
169
+ * and only the blocks whose own text was inside the range are removed.
170
+ * Survivors are always moved out BEFORE their former ancestors are destroyed (deleting a Loro node deletes
171
+ * its whole subtree). The result may violate type-specific invariants; the normalizers fix them on commit.
117
172
  *
118
- * @param {{ children: Block[], commit: () => void }} container
119
173
  * @param {Nabu} nabu
120
- * @param {InputEvent} event
174
+ * @param {DeletionRange} range
175
+ * @returns {{ block: Block, offset: number } | null} the junction (where the caret belongs), or null if the range is unusable
121
176
  */
122
- export function handleContainerBeforeInput(container, nabu, event) {
123
- const startBlock = /** @type {Block} */ (nabu.selection.startBlock);
124
- const endBlock = /** @type {Block} */ (nabu.selection.endBlock);
125
- if (!startBlock || !endBlock) return false;
126
-
127
- const focusData = startBlock.focus(undefined, true);
128
- const inputType = event.inputType;
129
-
130
- const toDestroy = new Set();
177
+ function deleteRangeRaw(nabu, range) {
178
+ const { startBlock: start, startOffset, endBlock: end, endOffset } = range;
179
+ const startText = textOf(start);
180
+ const endText = textOf(end);
181
+
182
+ // ── One block: a plain text deletion ──
183
+ if (start === end) {
184
+ if (startText && endOffset > startOffset) startText.delete({ from: startOffset, to: endOffset });
185
+ return { block: start, offset: startOffset };
186
+ }
131
187
 
132
- // Build start spine: walk from startBlock up to (but not past) container,
133
- // pruning next-siblings of each intermediate node along the way.
134
- const startSpine = [startBlock];
135
- while (startSpine.at(-1) && startSpine.at(-1) !== container) {
136
- const current = startSpine.at(-1);
137
- const parent = current?.parent;
138
- if (!current || !parent) break;
139
- startSpine.push(parent);
140
- if (parent !== container) {
141
- const nextSiblings = parent.children.slice(current.index + 1);
142
- if (nextSiblings.length) nextSiblings.forEach(block => toDestroy.add(block));
188
+ const lca = findLCA(start, end);
189
+ if (lca === end) return null; // end encloses start: the range is reversed
190
+ const nested = lca === start; // the start block holds the end block in its subtree
191
+ const startPath = nested ? [] : pathUp(start, lca);
192
+ const endPath = pathUp(end, lca);
193
+ if (!endPath.length) return null;
194
+
195
+ /** Blocks destroyed at the end (with their subtree). @type {Set<Block>} */
196
+ const doomed = new Set();
197
+ /** Blocks that outlive the cut, in document order, to re-home after `anchor`. @type {Block[]} */
198
+ const survivors = [];
199
+ let anchor = start;
200
+ /** Nested case: the outermost block of the end spine (below `start`) that has own text. @type {Block | null} */
201
+ let hybrid = null;
202
+
203
+ if (!nested) {
204
+ const siblings = childrenOf(nabu, lca);
205
+ const first = /** @type {Block} */ (startPath.at(-1));
206
+ const last = /** @type {Block} */ (endPath.at(-1));
207
+ const firstIndex = siblings.indexOf(first);
208
+ const lastIndex = siblings.indexOf(last);
209
+ if (firstIndex < 0 || lastIndex <= firstIndex) return null;
210
+
211
+ // Between the two spines.
212
+ siblings.slice(firstIndex + 1, lastIndex).forEach(block => doomed.add(block));
213
+ // After the start, inside the start spine (the start block's own children come right after its text).
214
+ for (const node of startPath) {
215
+ if (node === first) break;
216
+ const brothers = kidsOf(node.parent);
217
+ brothers.slice(brothers.indexOf(node) + 1).forEach(block => doomed.add(block));
143
218
  }
219
+ kidsOf(start).forEach(block => doomed.add(block));
220
+ // Before the end, inside the end spine; what follows the end point survives.
221
+ endPath.forEach((node, i) => {
222
+ if (node !== last) {
223
+ const brothers = kidsOf(node.parent);
224
+ const at = brothers.indexOf(node);
225
+ brothers.slice(0, at).forEach(block => doomed.add(block));
226
+ survivors.push(...brothers.slice(at + 1));
227
+ }
228
+ if (i > 0) doomed.add(node);
229
+ });
230
+ } else {
231
+ for (let i = endPath.length - 1; i >= 1; i--) {
232
+ if (textOf(endPath[i])) { hybrid = endPath[i]; break; }
233
+ }
234
+ const hybridIndex = hybrid ? endPath.indexOf(hybrid) : -1;
235
+ endPath.forEach((node, i) => {
236
+ const brothers = kidsOf(node.parent);
237
+ const at = brothers.indexOf(node);
238
+ brothers.slice(0, at).forEach(block => doomed.add(block));
239
+ // Only what sits under a block that is removed has to move; the rest stays in place.
240
+ if (hybrid && i < hybridIndex) survivors.push(...brothers.slice(at + 1));
241
+ });
242
+ if (hybrid) { doomed.add(hybrid); anchor = hybrid; }
144
243
  }
145
244
 
146
- // Build end spine: walk from endBlock up to (but not past) container,
147
- // pruning prev-siblings of each intermediate node along the way.
148
- const endSpine = [endBlock];
149
- while (endSpine.at(-1) && endSpine.at(-1) !== container) {
150
- const current = endSpine.at(-1);
151
- const parent = current?.parent;
152
- if (!current || !parent) break;
153
- endSpine.push(parent);
154
- if (parent !== container) {
155
- const previousSiblings = parent.children.slice(0, current.index);
156
- if (previousSiblings.length) previousSiblings.forEach(block => toDestroy.add(block));
245
+ // ── Text: head of the start block + tail of the end block ──
246
+ if (startText) {
247
+ const length = startText.container.length;
248
+ if (length > startOffset) startText.delete({ from: startOffset, to: length });
249
+ }
250
+ if (endText && endOffset > 0) endText.delete({ from: 0, to: endOffset });
251
+
252
+ const absorbed = !!(startText && endText && start.absorbs(end));
253
+ const endChildren = [...kidsOf(end)];
254
+ if (absorbed || !endText) doomed.add(end);
255
+ else if (!nested) survivors.unshift(end); // could not be merged: it stays, right after the start
256
+
257
+ // The end block's children: adopted by the start block when it holds children, else promoted.
258
+ /** @type {any} */
259
+ const host = start;
260
+ const adopts = typeof host.adoptChildren === 'function';
261
+ let adoptAfterMoves = false;
262
+ if (endChildren.length && (absorbed || !endText)) {
263
+ if (nested && !hybrid) {
264
+ host.adoptChildren(endChildren, kidsOf(start).indexOf(/** @type {Block} */ (endPath.at(-1))));
265
+ } else if (!nested && !hybrid && adopts) {
266
+ adoptAfterMoves = true;
267
+ } else {
268
+ survivors.unshift(...endChildren);
157
269
  }
158
270
  }
159
271
 
160
- // Resolve the direct children of container from each spine.
161
- const directChild = (spine) => spine.at(-1) === container ? spine.at(-2) : spine.at(-1);
162
- const startOfStartSpine = directChild(startSpine);
163
- const startOfEndSpine = directChild(endSpine);
164
- if (!startOfStartSpine || !startOfEndSpine) return false;
272
+ rehomeAfter(nabu, anchor, survivors);
273
+ if (adoptAfterMoves) host.adoptChildren(endChildren);
165
274
 
166
- // Delete intermediate direct children of container between the two spines.
167
- const intermediates = container.children.slice(startOfStartSpine.index + 1, startOfEndSpine.index);
168
- intermediates.forEach(block => toDestroy.add(block));
169
-
170
- // Single-block selection: delegate directly to that block.
171
- if (startBlock === endBlock) {
172
- return startBlock.beforeinput(event);
275
+ // ── Destroy, outermost blocks only (a Loro delete takes the subtree along) ──
276
+ for (const block of doomed) {
277
+ let covered = false;
278
+ for (let p = block.parent ?? null; p; p = p.parent ?? null) if (doomed.has(p)) { covered = true; break; }
279
+ if (!covered && !block.node.isDeleted?.()) block.destroy();
173
280
  }
174
281
 
175
- // Delete the selected portions of both boundary blocks.
176
- startBlock.delete();
177
- endBlock.delete();
282
+ return { block: start, offset: startOffset };
283
+ }
178
284
 
179
- let focusBlock = startBlock;
285
+ // ── Isolated text fields (`Block#isolatesSelection`) ─────────────────────────
180
286
 
181
- if (inputType === 'deleteContentBackward' || inputType === 'deleteContentForward') {
182
- // Text deletion already handled above.
183
- } else if (inputType === 'insertParagraph') {
184
- const { block: newBlock } = startBlock.split({ offset: focusData.options.startOffset }) || {};
185
- if (newBlock) focusBlock = newBlock;
186
- } else if (inputType === 'insertText' || inputType === 'insertLineBreak') {
187
- const text = event.data || (inputType === 'insertLineBreak' ? '\n' : '');
188
- startBlock.insert(focusData.options.startOffset, text);
189
- } else {
190
- nabu.warn('Unhandled input type in container:', inputType);
191
- return false;
192
- }
287
+ /** Whether `block` holds text. @param {Block} block */
288
+ const hasTextBehavior = (block) => !!block.behaviors?.has('text');
193
289
 
194
- // Merge the end block into focusBlock and relocate orphaned siblings.
195
- focusBlock.consume(endBlock);
196
-
197
- endSpine.forEach(block => {
198
- if (block === container) return;
199
- const brotherhood = block.parent?.children || [];
200
- const index = brotherhood.indexOf(block);
201
- if (index !== -1) {
202
- const nextSiblings = brotherhood.slice(index + 1);
203
- if (nextSiblings.length) {
204
- // Reverse to preserve original order: moveAfter(focus) inserts right
205
- // after focus each time, so forward iteration would reverse the result.
206
- // wrapOrphan ensures structural integrity (e.g. ListItem → needs List parent).
207
- [...nextSiblings].reverse().forEach(sibling => {
208
- sibling.node.moveAfter(focusBlock.node);
209
- wrapOrphan(nabu, sibling);
210
- });
211
- }
212
- }
213
- });
214
-
215
- if (startOfEndSpine === startOfStartSpine) {
216
- if (startOfStartSpine instanceof MegaBlock) {
217
- startOfStartSpine.children.filter(c => c.selected).forEach(c => toDestroy.add(c));
218
- }
219
- }
220
-
221
- if (startOfEndSpine !== startOfStartSpine) {
222
- startOfEndSpine?.destroy();
223
- if (startOfStartSpine !== startBlock && startBlock instanceof MegaBlock) {
224
- startBlock.children.forEach(child => child.destroy());
290
+ /**
291
+ * The text blocks of the document in document order (a block's own text before its children). With `visible`, the children of
292
+ * a block that hides them are skipped (they are not rendered: no caret, no DOM point).
293
+ * @param {Nabu} nabu
294
+ * @param {{ visible?: boolean }} [options]
295
+ * @returns {Block[]}
296
+ */
297
+ export function textBlocksInOrder(nabu, { visible = false } = {}) {
298
+ /** @type {Block[]} */
299
+ const out = [];
300
+ /** @param {Block[]} blocks */
301
+ const walk = (blocks) => {
302
+ for (const block of blocks) {
303
+ if (hasTextBehavior(block)) out.push(block);
304
+ const kids = kidsOf(block);
305
+ if (kids.length && !(visible && block.hidesChildren)) walk(kids);
225
306
  }
226
- }
307
+ };
308
+ walk(/** @type {Block[]} */ (nabu.children));
309
+ return out;
310
+ }
227
311
 
228
- toDestroy.forEach(block => block.destroy());
312
+ /**
313
+ * The ISOLATION OWNER of a block: its nearest ancestor that isolates its text (`Block#isolatesSelection`), or null. Two text
314
+ * blocks with different owners (the body of a chapter and the body of a scene inside it) never merge by a range deletion.
315
+ * @param {Block} block
316
+ * @returns {Block | null}
317
+ */
318
+ export function isolationOwnerOf(block) {
319
+ for (let cur = block.parent ?? null; cur; cur = cur.parent ?? null) if (cur.isolatesSelection) return cur;
320
+ return null;
321
+ }
229
322
 
230
- container.commit();
231
- startBlock.focus({
232
- offset: focusData.options.startOffset + (inputType === 'insertText' ? (event.data?.length || 0) : 0)
323
+ /**
324
+ * Splits a range into the RUNS that a deletion may act on (ADR 018 §3.9): maximal sequences of consecutive text blocks, in
325
+ * document order, that do not contain an isolated block and share one isolation owner. The text of an isolated block is
326
+ * outside every run (a range starting or ending in it starts after it / ends before it), and a run boundary is never merged
327
+ * across. A document without isolated blocks gives a single run, the range itself.
328
+ * @param {Nabu} nabu
329
+ * @param {DeletionRange} range
330
+ * @returns {DeletionRange[] | null} the runs in document order (possibly empty), or null when the range cannot be placed in the document
331
+ */
332
+ export function isolatedRuns(nabu, range) {
333
+ const { startBlock, endBlock } = range;
334
+ const order = textBlocksInOrder(nabu);
335
+ const first = order.indexOf(startBlock);
336
+ const last = order.indexOf(endBlock);
337
+ if (first < 0 || last < first) return null;
338
+
339
+ /** @type {Block[][]} */
340
+ const groups = [];
341
+ /** @type {Block[] | null} */
342
+ let current = null;
343
+ let owner = /** @type {Block | null} */ (null);
344
+ for (const block of order.slice(first, last + 1)) {
345
+ if (block.isolatesSelection) { current = null; continue; }
346
+ const blockOwner = isolationOwnerOf(block);
347
+ if (!current || blockOwner !== owner) { current = []; owner = blockOwner; groups.push(current); }
348
+ current.push(block);
349
+ }
350
+ return groups.map((blocks) => {
351
+ const head = /** @type {Block} */ (blocks[0]);
352
+ const tail = /** @type {Block} */ (blocks.at(-1));
353
+ return {
354
+ startBlock: head,
355
+ startOffset: head === startBlock ? range.startOffset : 0,
356
+ endBlock: tail,
357
+ endOffset: tail === endBlock ? range.endOffset : (textOf(tail)?.container.length ?? 0),
358
+ };
233
359
  });
234
- return true;
235
360
  }
236
361
 
237
362
  /**
238
- * Deletes the current selection content without committing.
239
- * Handles both single-block and multi-block selections.
240
- * Returns the resulting insertion position {block, offset}, or null on failure.
363
+ * THE one implementation of "delete the selected range across blocks" (cut, Backspace / Delete, typing over a
364
+ * selection, paste over a selection, move by drag). Mutates the Loro tree and texts, never commits.
241
365
  *
242
- * @param {{ children: import('./block.svelte.js').Block[] }} container
243
- * @param {import('./nabu.svelte.js').Nabu} nabu
244
- * @returns {{ block: import('./block.svelte.js').Block, offset: number } | null}
366
+ * A range that crosses ISOLATED text (`Block#isolatesSelection`, e.g. the title of a region) acts on its {@link isolatedRuns}
367
+ * only: the text of an isolated block is never touched, an isolated block and its container are never deleted, and the runs
368
+ * are never merged with one another (each one is deleted like a range of its own, the LAST run first so that the earlier
369
+ * ones are not disturbed). What is left is the first block of every run, emptied: that is where a caret still has a home.
370
+ * Without isolated block in the range it is exactly {@link deleteRangeRaw}.
371
+ *
372
+ * @param {Nabu} nabu
373
+ * @param {DeletionRange} range
374
+ * @returns {{ block: Block, offset: number } | null} the junction (where the caret belongs: the start of the first run), or null if the range is unusable or holds no deletable text
245
375
  */
246
- export function deleteSelectionContent(container, nabu) {
247
- const startBlock = /** @type {import('./block.svelte.js').Block} */ (nabu.selection.startBlock);
248
- const endBlock = /** @type {import('./block.svelte.js').Block} */ (nabu.selection.endBlock);
376
+ export function deleteRange(nabu, range) {
377
+ if (range.startBlock === range.endBlock) return deleteRangeRaw(nabu, range);
378
+ const runs = isolatedRuns(nabu, range);
379
+ if (!runs) return deleteRangeRaw(nabu, range);
380
+ if (runs.length === 1 && runs[0].startBlock === range.startBlock && runs[0].endBlock === range.endBlock) return deleteRangeRaw(nabu, range);
381
+ if (!runs.length) return null;
382
+ for (let i = runs.length - 1; i >= 0; i--) {
383
+ const run = /** @type {DeletionRange} */ (runs[i]);
384
+ const empty = run.startBlock === run.endBlock && run.endOffset <= run.startOffset;
385
+ if (!empty) deleteRangeRaw(nabu, run);
386
+ }
387
+ const head = /** @type {DeletionRange} */ (runs[0]);
388
+ return { block: head.startBlock, offset: head.startOffset };
389
+ }
390
+
391
+ /**
392
+ * The current selection as a {@link DeletionRange}, or null when there is none.
393
+ * A selection inside one block has `startBlock === endBlock`.
394
+ * @param {Nabu} nabu
395
+ * @returns {DeletionRange | null}
396
+ */
397
+ export function selectionRange(nabu) {
398
+ const startBlock = /** @type {Block | null} */ (nabu.selection.startBlock);
399
+ const endBlock = /** @type {Block | null} */ (nabu.selection.endBlock);
249
400
  if (!startBlock || !endBlock) return null;
401
+ const startSel = /** @type {any} */ (startBlock.selection);
402
+ const startOffset = startSel?.from ?? 0;
403
+ if (startBlock === endBlock) return { startBlock, startOffset, endBlock, endOffset: startSel?.to ?? startOffset };
404
+ const endSel = /** @type {any} */ (endBlock.selection);
405
+ return { startBlock, startOffset, endBlock, endOffset: endSel?.to ?? 0 };
406
+ }
250
407
 
251
- // Single-block selection: delete the range only
252
- if (startBlock === endBlock) {
253
- const sel = startBlock.selection;
254
- if (!sel || sel.from === sel.to) return { block: startBlock, offset: sel?.from ?? 0 };
255
- const tb = startBlock.behaviors?.get('text');
256
- if (tb) tb.delete({ from: sel.from, to: sel.to });
257
- return { block: startBlock, offset: sel.from };
258
- }
408
+ /**
409
+ * Shared beforeinput logic for block containers (Nabu root and MegaBlock) when the selection spans SEVERAL
410
+ * blocks (a selection inside one block is that block's business). Backspace / Delete / word deletions delete the
411
+ * range; typing replaces it; Enter replaces it and splits at the junction. All of it is {@link deleteRange}
412
+ * followed by the plain single-block edit at the junction, then ONE commit (one undo step).
413
+ *
414
+ * The `container` (the lowest common ancestor the event was routed to) is not needed any more: the range is
415
+ * resolved from the selection alone, which also makes the same code correct for every depth.
416
+ *
417
+ * @param {{ children: Block[], commit: () => void }} container
418
+ * @param {Nabu} nabu
419
+ * @param {InputEvent} event
420
+ */
421
+ export function handleContainerBeforeInput(container, nabu, event) {
422
+ const range = selectionRange(nabu);
423
+ if (!range) return false;
259
424
 
260
- // Multi-block selection: same spine logic as handleContainerBeforeInput (no commit)
261
- const startOffset = startBlock.focus(undefined, true).options.startOffset;
425
+ // Single-block selection: delegate directly to that block.
426
+ if (range.startBlock === range.endBlock) return range.startBlock.beforeinput(event);
262
427
 
263
- const startSpine = [startBlock];
264
- while (startSpine.at(-1) && startSpine.at(-1) !== container) {
265
- const current = startSpine.at(-1);
266
- const parent = current?.parent;
267
- if (!current || !parent) break;
268
- startSpine.push(parent);
269
- if (parent !== container) {
270
- const nextSiblings = parent.children.slice(current.index + 1);
271
- if (nextSiblings.length) nextSiblings.forEach(block => block.destroy());
272
- }
428
+ const inputType = event.inputType;
429
+ const typed = inputType === 'insertText' ? (event.data || '')
430
+ : (inputType === 'insertReplacementText' || inputType === 'insertFromYank') ? (event.data || event.dataTransfer?.getData?.('text/plain') || '')
431
+ : (inputType === 'insertLineBreak' || inputType === 'insertSoftLineBreak') ? '\n'
432
+ : null;
433
+ const isDeletion = inputType.startsWith('delete');
434
+ const isParagraph = inputType === 'insertParagraph';
435
+ if (!isDeletion && !isParagraph && typed === null) {
436
+ if (inputType.startsWith('history')) return true; // undo / redo go through the keydown handler
437
+ if (inputType.startsWith('format') || inputType === 'insertTranspose') return true; // formatting: extension hooks; transpose: meaningless across blocks
438
+ nabu.warn('Unhandled input type in container:', inputType);
439
+ return false;
273
440
  }
274
441
 
275
- const endSpine = [endBlock];
276
- while (endSpine.at(-1) && endSpine.at(-1) !== container) {
277
- const current = endSpine.at(-1);
278
- const parent = current?.parent;
279
- if (!current || !parent) break;
280
- endSpine.push(parent);
281
- if (parent !== container) {
282
- const previousSiblings = parent.children.slice(0, current.index);
283
- if (previousSiblings.length) previousSiblings.forEach(block => block.destroy());
442
+ const junction = deleteRange(nabu, range);
443
+ if (!junction) return false;
444
+ const { block } = junction;
445
+ let { offset } = junction;
446
+
447
+ if (typed !== null) {
448
+ block.insert(offset, typed);
449
+ offset += typed.length;
450
+ } else if (isParagraph) {
451
+ const text = textOf(block);
452
+ const split = block.split({ offset, to: text ? text.container.length : offset });
453
+ if (split?.block) {
454
+ // The split commits the whole operation (deletion included) and puts the caret in the new block.
455
+ nabu.commit();
456
+ return true;
284
457
  }
285
458
  }
286
459
 
287
- const directChild = (spine) => spine.at(-1) === container ? spine.at(-2) : spine.at(-1);
288
- const startOfStartSpine = directChild(startSpine);
289
- const startOfEndSpine = directChild(endSpine);
290
- if (!startOfStartSpine || !startOfEndSpine) return null;
291
-
292
- const intermediates = container.children.slice(startOfStartSpine.index + 1, startOfEndSpine.index);
293
- intermediates.forEach(block => block.destroy());
294
-
295
- startBlock.delete();
296
- endBlock.delete();
297
- startBlock.consume(endBlock);
298
-
299
- endSpine.forEach(block => {
300
- if (block === container) return;
301
- const brotherhood = block.parent?.children || [];
302
- const index = brotherhood.indexOf(block);
303
- if (index !== -1) {
304
- const nextSiblings = brotherhood.slice(index + 1);
305
- if (nextSiblings.length) {
306
- [...nextSiblings].reverse().forEach(sibling => {
307
- sibling.node.moveAfter(startBlock.node);
308
- wrapOrphan(nabu, sibling);
309
- });
310
- }
311
- }
312
- });
313
-
314
- startOfEndSpine?.destroy();
460
+ nabu.commit().then(() => nabu.selection.setCursor(nabu.blocks.get(block.id) ?? block, offset));
461
+ return true;
462
+ }
315
463
 
316
- return { block: startBlock, offset: startOffset };
464
+ /**
465
+ * Deletes the current selection content without committing (cut, paste over a selection).
466
+ * Handles both single-block and multi-block selections — see {@link deleteRange}.
467
+ * Returns the resulting insertion position {block, offset}, or null on failure.
468
+ *
469
+ * @param {{ children: import('./block.svelte.js').Block[] }} container (unused: the range comes from the selection)
470
+ * @param {import('./nabu.svelte.js').Nabu} nabu
471
+ * @returns {{ block: import('./block.svelte.js').Block, offset: number } | null}
472
+ */
473
+ export function deleteSelectionContent(container, nabu) {
474
+ const range = selectionRange(nabu);
475
+ if (!range) return null;
476
+ return deleteRange(nabu, range);
317
477
  }
@@ -2,13 +2,18 @@
2
2
  import RichText from '../../behaviors/text/RichText.svelte';
3
3
  /** @type {{block: import('./dialogue.svelte.js').Dialogue}}*/
4
4
  let {block} = $props();
5
+
6
+ /** The configured dash as a CSS string (`"–"`): fed to the `::before` below. */
7
+ const dashCss = $derived(JSON.stringify(String(block.dash).replace(/[\n\r]/g, ' ')));
5
8
  </script>
6
9
 
7
10
  <div
8
11
  bind:this={block.element}
9
12
  data-block-id={block.id}
10
13
  data-block-type="dialogue"
14
+ data-placeholder={block.placeholder}
11
15
  class="nabu-dialogue"
16
+ style:--nb-dialogue-dash-configured={dashCss}
12
17
  class:debug={block.nabu.debugging}
13
18
  class:selected={block.selected}
14
19
  class:first={block.isSelectionStart}
@@ -24,8 +29,9 @@
24
29
  }
25
30
 
26
31
  .nabu-dialogue::before {
27
- /* content: "—"; */
28
- content: "–";
32
+ /* `--nb-dialogue-dash` is the host override (any ancestor / rule); the configured dash
33
+ (createDialogueExtension({ dash })) is the fallback. */
34
+ content: var(--nb-dialogue-dash, var(--nb-dialogue-dash-configured, "–"));
29
35
  position: absolute;
30
36
  left: 0;
31
37
  user-select: none;