@aionbuilders/nabu 0.1.0-beta.0 → 0.1.1

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 (308) hide show
  1. package/CHANGELOG.md +531 -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 +195 -55
  12. package/dist/behaviors/text/text.behavior.svelte.js +531 -103
  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 +32 -18
  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 +1753 -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 +35 -14
  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 +55 -8
  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/composition.d.ts +28 -0
  253. package/dist/utils/composition.js +51 -0
  254. package/dist/utils/dom-scope.d.ts +14 -0
  255. package/dist/utils/dom-scope.js +20 -0
  256. package/dist/utils/drop.d.ts +160 -0
  257. package/dist/utils/drop.js +305 -0
  258. package/dist/utils/extensions.d.ts +439 -45
  259. package/dist/utils/extensions.js +271 -29
  260. package/dist/utils/html.d.ts +44 -0
  261. package/dist/utils/html.js +183 -0
  262. package/dist/utils/index.d.ts +3 -0
  263. package/dist/utils/index.js +3 -0
  264. package/dist/utils/keys.d.ts +120 -0
  265. package/dist/utils/keys.js +248 -0
  266. package/dist/utils/links.d.ts +22 -0
  267. package/dist/utils/links.js +34 -0
  268. package/dist/utils/placeholders.d.ts +81 -3
  269. package/dist/utils/placeholders.js +73 -3
  270. package/dist/utils/selection.svelte.d.ts +48 -20
  271. package/dist/utils/selection.svelte.js +60 -10
  272. package/dist/utils/spellcheck.d.ts +9 -0
  273. package/dist/utils/spellcheck.js +17 -0
  274. package/dist/utils/tab.d.ts +31 -0
  275. package/dist/utils/tab.js +117 -0
  276. package/dist/utils/words.d.ts +42 -0
  277. package/dist/utils/words.js +147 -0
  278. package/dist/vite.d.ts +9 -3
  279. package/dist/vite.js +19 -8
  280. package/package.json +56 -20
  281. package/dist/blocks/variable.svelte.d.ts +0 -47
  282. package/dist/blocks/variable.svelte.js +0 -51
  283. package/dist/blocks/zone/TemplateEditor.svelte +0 -308
  284. package/dist/blocks/zone/TemplateEditor.svelte.d.ts +0 -11
  285. package/dist/blocks/zone/Zone.svelte +0 -272
  286. package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
  287. package/dist/blocks/zone/ZoneEditor.svelte +0 -289
  288. package/dist/blocks/zone/ZoneEditor.svelte.d.ts +0 -11
  289. package/dist/blocks/zone/ZoneTemplatesList.svelte +0 -188
  290. package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +0 -11
  291. package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +0 -3
  292. package/dist/blocks/zone/hooks/onBeforeInput.hook.js +0 -30
  293. package/dist/blocks/zone/index.d.ts +0 -2
  294. package/dist/blocks/zone/index.js +0 -2
  295. package/dist/blocks/zone/zone.extension.d.ts +0 -2
  296. package/dist/blocks/zone/zone.extension.js +0 -237
  297. package/dist/blocks/zone/zone.svelte.d.ts +0 -221
  298. package/dist/blocks/zone/zone.svelte.js +0 -608
  299. package/dist/overlays/context/Context.svelte +0 -182
  300. package/dist/overlays/context/Context.svelte.d.ts +0 -17
  301. package/dist/overlays/context/collect.d.ts +0 -17
  302. package/dist/overlays/context/collect.js +0 -33
  303. package/dist/overlays/context/context.extension.d.ts +0 -2
  304. package/dist/overlays/context/context.extension.js +0 -8
  305. package/dist/overlays/context/context.svelte.d.ts +0 -82
  306. package/dist/overlays/context/context.svelte.js +0 -159
  307. package/dist/overlays/context/index.d.ts +0 -3
  308. package/dist/overlays/context/index.js +0 -3
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Regions extension factory (ADR 016, data model of ADR 018): structure a text in divisions. Installs the `region` container
3
+ * block (its header is its title, its body is its children), the placement / nesting normalizer, and the reactive registry
4
+ * (`nabu.regions`, also `Regions.get(nabu)`).
5
+ *
6
+ * It also declares the region commands (`region:split` on Mod-Enter, the protected merges on Backspace / Delete, and the keyless
7
+ * `region:insert` / `move` / `promote` / `demote` / `next` / `prev` / `parent`: see commands.js) and vetoes any silent text merge
8
+ * into, out of or across a title (`onBeforeMerge`).
9
+ *
10
+ * @param {{ types?: Record<string, RegionTypeInit>, messages?: RegionMessages }} [options]
11
+ * `types`: the region types of the integrator (see `types.js`: `level`, `label`, `numbering`, `fields`). Without it,
12
+ * a generic `section` division over three levels is declared, as the types `section-1`, `section-2`, `section-3`.
13
+ * Throws on an invalid declaration.
14
+ * `messages`: texts of the commands and of the hold prompt (see messages.js), English by default.
15
+ *
16
+ * @example
17
+ * RegionsExtension({
18
+ * types: {
19
+ * part: { level: 1, label: 'Part {index}' },
20
+ * chapter: { level: 2, label: 'Chapter {index}', numbering: 'document' },
21
+ * scene: { level: 3, fields: { pov: 'text' } },
22
+ * },
23
+ * })
24
+ */
25
+ export function RegionsExtension(options?: {
26
+ types?: Record<string, RegionTypeInit>;
27
+ messages?: RegionMessages;
28
+ }): import("../../extend.js").Extension;
29
+ /**
30
+ * Regions extension factory (ADR 016, data model of ADR 018): structure a text in divisions. Installs the `region` container
31
+ * block (its header is its title, its body is its children), the placement / nesting normalizer, and the reactive registry
32
+ * (`nabu.regions`, also `Regions.get(nabu)`).
33
+ *
34
+ * It also declares the region commands (`region:split` on Mod-Enter, the protected merges on Backspace / Delete, and the keyless
35
+ * `region:insert` / `move` / `promote` / `demote` / `next` / `prev` / `parent`: see commands.js) and vetoes any silent text merge
36
+ * into, out of or across a title (`onBeforeMerge`).
37
+ *
38
+ * @param {{ types?: Record<string, RegionTypeInit>, messages?: RegionMessages }} [options]
39
+ * `types`: the region types of the integrator (see `types.js`: `level`, `label`, `numbering`, `fields`). Without it,
40
+ * a generic `section` division over three levels is declared, as the types `section-1`, `section-2`, `section-3`.
41
+ * Throws on an invalid declaration.
42
+ * `messages`: texts of the commands and of the hold prompt (see messages.js), English by default.
43
+ *
44
+ * @example
45
+ * RegionsExtension({
46
+ * types: {
47
+ * part: { level: 1, label: 'Part {index}' },
48
+ * chapter: { level: 2, label: 'Chapter {index}', numbering: 'document' },
49
+ * scene: { level: 3, fields: { pov: 'text' } },
50
+ * },
51
+ * })
52
+ */
53
+ export function createRegionsExtension(options?: {
54
+ types?: Record<string, RegionTypeInit>;
55
+ messages?: RegionMessages;
56
+ }): import("../../extend.js").Extension;
57
+ import type { RegionTypeInit } from "./types.js";
58
+ import type { RegionMessages } from "./messages.js";
@@ -0,0 +1,119 @@
1
+ import { tick } from "svelte";
2
+ import { extension } from "../../utils/extensions";
3
+ import { RegionBlock } from "./region.svelte.js";
4
+ import RegionComponent from "./Region.svelte";
5
+ import { Regions } from "./regions.svelte.js";
6
+ import { normalizeRegions } from "./normalize.js";
7
+ import { createRegionCommands } from "./commands.js";
8
+ import { mergeCrossesRegion, regionFacts } from "./facts.js";
9
+ import { resolveConfig } from "./types.js";
10
+ import { createMessages } from "./messages.js";
11
+ import { placeOf, regionChoices } from "./create.js";
12
+ import { closeOnEnter } from "./close.js";
13
+
14
+ /**
15
+ * @import { Nabu } from "../nabu.svelte.js";
16
+ * @import { RegionTypeInit } from "./types.js";
17
+ * @import { RegionMessages } from "./messages.js";
18
+ */
19
+
20
+ /**
21
+ * @param {Nabu} nabu @param {InputEvent} event @param {import("../block.svelte.js").Block} block
22
+ */
23
+ function openCreateChooser(nabu, event, block) {
24
+ const { BREAK, CONTINUE } = nabu;
25
+ if (event.inputType !== "insertText" || event.data !== " ") return CONTINUE;
26
+ const behavior = /** @type {any} */ (block.behaviors.get("text"));
27
+ const sel = behavior?.selection;
28
+ if (!sel || !sel.isCollapsed || behavior.text !== ":::" || sel.from !== 3) return CONTINUE;
29
+ if (block.type !== nabu.defaultBlockType || /** @type {any} */ (block).children?.length || !placeOf(nabu, block)) return CONTINUE;
30
+ behavior.insert(3, " ");
31
+ nabu.commit().then(async () => {
32
+ nabu.selection.setCursor(block, 4);
33
+ await tick();
34
+ nabu.selection.sync?.(); // the command reads selection.anchorBlock: don't wait for the async `selectionchange`
35
+ nabu.commandConfirm.offer("region:create");
36
+ });
37
+ return BREAK;
38
+ }
39
+
40
+ /**
41
+ * Regions extension factory (ADR 016, data model of ADR 018): structure a text in divisions. Installs the `region` container
42
+ * block (its header is its title, its body is its children), the placement / nesting normalizer, and the reactive registry
43
+ * (`nabu.regions`, also `Regions.get(nabu)`).
44
+ *
45
+ * It also declares the region commands (`region:split` on Mod-Enter, the protected merges on Backspace / Delete, and the keyless
46
+ * `region:insert` / `move` / `promote` / `demote` / `next` / `prev` / `parent`: see commands.js) and vetoes any silent text merge
47
+ * into, out of or across a title (`onBeforeMerge`).
48
+ *
49
+ * @param {{ types?: Record<string, RegionTypeInit>, messages?: RegionMessages }} [options]
50
+ * `types`: the region types of the integrator (see `types.js`: `level`, `label`, `numbering`, `fields`). Without it,
51
+ * a generic `section` division over three levels is declared, as the types `section-1`, `section-2`, `section-3`.
52
+ * Throws on an invalid declaration.
53
+ * `messages`: texts of the commands and of the hold prompt (see messages.js), English by default.
54
+ *
55
+ * @example
56
+ * RegionsExtension({
57
+ * types: {
58
+ * part: { level: 1, label: 'Part {index}' },
59
+ * chapter: { level: 2, label: 'Chapter {index}', numbering: 'document' },
60
+ * scene: { level: 3, fields: { pov: 'text' } },
61
+ * },
62
+ * })
63
+ */
64
+ export function RegionsExtension(options = {}) {
65
+ const config = resolveConfig(options);
66
+ const text = createMessages(options.messages);
67
+ // The configuration is carried by the block class (as the dash of the dialogue extension).
68
+ const BlockClass = class extends RegionBlock { static config = config; static messages = options.messages; };
69
+ return extension("region", {
70
+ // @ts-ignore — static-side variance on create() (same pattern as Divider/Image)
71
+ block: BlockClass,
72
+ component: RegionComponent,
73
+ commands: createRegionCommands(options.messages),
74
+ commandContext: regionFacts,
75
+ // One slash entry per declared type, offered where the type fits INSIDE the caret's place (create.js).
76
+ slashCommands: [...config.types.values()].map((def) => ({
77
+ title: text('slash', { name: def.name, type: def.id }),
78
+ icon: '§',
79
+ group: 'structure',
80
+ aliases: [def.id, 'region'],
81
+ when: (/** @type {Nabu} */ nabu, /** @type {import("../block.svelte.js").Block} */ block) => {
82
+ const place = placeOf(nabu, block);
83
+ return !!place && regionChoices(nabu, place.parent).here.some((d) => d.id === def.id);
84
+ },
85
+ run: (/** @type {Nabu} */ nabu) => { nabu.exec('region:create', { type: def.id }); },
86
+ })),
87
+ hooks: {
88
+ /** @param {Nabu} nabu */
89
+ onInit: (nabu) => {
90
+ Regions.get(nabu);
91
+ // `nabu.regions`: installed here, so that the engine knows nothing about it (same exposure as other
92
+ // subsystems, `Todos.get(nabu)` / `Files.get(nabu)`, plus a getter for convenience).
93
+ if (!('regions' in nabu)) {
94
+ Object.defineProperty(nabu, 'regions', { get: () => Regions.get(nabu), configurable: true, enumerable: false });
95
+ }
96
+ },
97
+ // `:::` + Space in an empty default paragraph (at the root or in a region body) asks which region to create: the
98
+ // space is typed as usual (so Escape leaves `::: ` as text), then the `choose` confirmation of `region:create`
99
+ // opens at the caret. See create.js.
100
+ // `:::` + Enter in a paragraph of a region body closes a region (close.js); the Enter is not applied.
101
+ /** @param {Nabu} nabu @param {InputEvent} event @param {import("../block.svelte.js").Block} block */
102
+ onBeforeInput: (nabu, event, block) => {
103
+ const closed = closeOnEnter(nabu, event, block);
104
+ return closed === nabu.BREAK ? closed : openCreateChooser(nabu, event, block);
105
+ },
106
+ // Runs before doc.commit(): a region that ended up in a list / toggle is brought back next to it, and a region too
107
+ // shallow for its parent is moved out, in the same transaction (same undo step) as the operation that displaced it.
108
+ // See normalize.js.
109
+ onBeforeTransaction: normalizeRegions,
110
+ // Backspace / Delete never merge text into a title, out of it, or across a seam, whoever asks (ADR 016 §6.1,
111
+ // ADR 018 §3.9: structure is protected; the merge is the hold of `region:merge-previous` / `region:merge-next`).
112
+ /** @param {Nabu} nabu @param {import("../block.svelte.js").Block} survivor @param {import("../block.svelte.js").Block} victim */
113
+ onBeforeMerge: (nabu, survivor, victim) => (mergeCrossesRegion(nabu, survivor, victim) ? nabu.BREAK : undefined),
114
+ },
115
+ });
116
+ }
117
+
118
+ /** Alias following the `createXxxExtension` naming of the other factories. */
119
+ export const createRegionsExtension = RegionsExtension;
@@ -0,0 +1,221 @@
1
+ /**
2
+ * The `fields` map of a region node's data map, created on first use. It is a MERGEABLE child (`ensureMergeableMap`): two peers that
3
+ * each create it concurrently get the same container id, so their writes converge instead of one branch being hidden by the map's
4
+ * LWW. A document written before the mergeable API holds a REGULAR child there: it is returned as-is (`ensureMergeable*` would
5
+ * refuse a slot holding a non-mergeable value). Anything else in the slot (never written by Nabu) is replaced by a regular map.
6
+ * @param {any} data the node's data map @returns {LoroMap}
7
+ */
8
+ export function fieldsMap(data: any): LoroMap;
9
+ /**
10
+ * A region (ADR 018 §3.1): a CONTAINER block, like the toggle. Its HEADER is its TITLE (a LoroText under the data key `text`,
11
+ * inline marks allowed, edited in place in the seam); its BODY is its children: any blocks, and sub-regions. It also stores
12
+ * - `regionType` the id of a declared region type;
13
+ * - `fields` a LoroMap holding the fields the type declares.
14
+ * Its level, label, number and parent region are NOT stored: they are derived from the document by the `Regions` registry
15
+ * (`nabu.regions`).
16
+ *
17
+ * The title behaves as a LOCKED FIELD (ADR 018 §3.9) although it is stored as text: Enter never splits it (the caret goes to
18
+ * the body), Backspace at its start and Delete at its end do nothing (the protected merge is a command), a multi-block paste
19
+ * lands flat, and no text merge goes into or out of it (the `onBeforeMerge` veto of the extension).
20
+ *
21
+ * The configuration (declared types) is carried by the class (`static config`): `RegionsExtension(options)` builds a
22
+ * subclass bound to its options, as `createDialogueExtension` does for the dash.
23
+ */
24
+ export class RegionBlock extends MegaBlock {
25
+ /** @type {RegionsConfig} */
26
+ static config: RegionsConfig;
27
+ /** Texts of the integrator (`RegionsExtension({ messages })`), for the placeholder of the title. @type {import('./messages.js').RegionMessages | undefined} */
28
+ static messages: import("./messages.js").RegionMessages | undefined;
29
+ /** The placeholder of an empty title (the `untitled` message). @param {RegionBlock} block */
30
+ static placeholder: (block: RegionBlock) => string;
31
+ /**
32
+ * Clipboard `text/plain` (several blocks) and static export: the data comment, the title as a heading, the body, and the
33
+ * closing comment when what follows would be swallowed (serialize.js). `after` (the following siblings) and `tail` (what
34
+ * follows the parent) are the neighbour context the engine hands to every serializer.
35
+ * @param {import('../../utils/extensions.js').PasteBlock} pb
36
+ * @param {{ recurse?: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string, recurseAll?: (children: import('../../utils/extensions.js').PasteBlock[], ctx?: object) => string[], after?: import('../../utils/extensions.js').PasteBlock[], tail?: import('./serialize.js').Follow }} [helpers]
37
+ */
38
+ static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { recurse, recurseAll, after, tail }?: {
39
+ recurse?: (child: import("../../utils/extensions.js").PasteBlock, ctx?: object) => string;
40
+ recurseAll?: (children: import("../../utils/extensions.js").PasteBlock[], ctx?: object) => string[];
41
+ after?: import("../../utils/extensions.js").PasteBlock[];
42
+ tail?: import("./serialize.js").Follow;
43
+ }): string;
44
+ /**
45
+ * Clipboard `text/html`: a `<section>` carrying the data, the title as a heading, the body (serialize.js).
46
+ * @param {import('../../utils/extensions.js').PasteBlock} pb
47
+ * @param {{ recurse?: (child: import('../../utils/extensions.js').PasteBlock) => string }} [helpers]
48
+ */
49
+ static toHtml(pb: import("../../utils/extensions.js").PasteBlock, { recurse }?: {
50
+ recurse?: (child: import("../../utils/extensions.js").PasteBlock) => string;
51
+ }): string;
52
+ /**
53
+ * Markdown rules (paste AND `importMarkdown`): the opening data comment (exact form, see format.js). `detect` is cheap (one
54
+ * line); `consume` computes the extent of the region (`scanRegion`: explicit close, next opening of the same or a higher
55
+ * level, end of the lines), and `fromMarkdown` reads the title and parses the body as a document of its own, exactly like
56
+ * the toggle, so sub-regions nest by recursion. A stray `<!-- /region -->` (nothing to close) is not a rule: literal text.
57
+ */
58
+ static get markdownRules(): {
59
+ priority: number;
60
+ interruptsParagraph: boolean;
61
+ detect: (line: string) => boolean;
62
+ consume: (lines: string[], i: number) => number;
63
+ }[];
64
+ /**
65
+ * The region: type and fields from the comment, the title (inline markdown) from the heading right after it, the body
66
+ * (the lines up to the end of the region, closing comment excluded) parsed as a document of its own.
67
+ * @param {string[]} lines exactly the lines `consume` took
68
+ * @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[], parseBlocks?: (lines: string[]) => import('../../utils/extensions.js').PasteBlock[] }} helpers
69
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
70
+ */
71
+ static fromMarkdown(lines: string[], { parseInline, parseBlocks }: {
72
+ parseInline: (text: string) => import("loro-crdt").Delta<string>[];
73
+ parseBlocks?: (lines: string[]) => import("../../utils/extensions.js").PasteBlock[];
74
+ }): import("../../utils/extensions.js").PasteBlock | null;
75
+ /**
76
+ * HTML rules (paste): `<section data-nabu-region="type">` with a plausible type id. A `<section>` without it, or with an
77
+ * empty / absurd one, is not matched: it stays a transparent wrapper, as before.
78
+ */
79
+ static get htmlRules(): {
80
+ selector: string;
81
+ priority: number;
82
+ filter: (el: Element) => boolean;
83
+ }[];
84
+ /**
85
+ * The region of a `<section data-nabu-region>`: type and fields from the attributes (invalid fields = no fields, never
86
+ * markup), the title from the heading (`h1`-`h6`) that is its FIRST element child (inline), the body from the other
87
+ * children, read like the toggle's.
88
+ * @param {Element} el
89
+ * @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[], parseChildren?: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
90
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
91
+ */
92
+ static fromHTML(el: Element, { parseInline, parseChildren }: {
93
+ parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
94
+ parseChildren?: (el: Element) => import("../../utils/extensions.js").PasteBlock[];
95
+ }): import("../../utils/extensions.js").PasteBlock | null;
96
+ /**
97
+ * @param {Nabu} nabu @param {string} type
98
+ * @param {{ regionType?: string, title?: string, text?: string, delta?: import('loro-crdt').Delta<string>[], fields?: Record<string, any> }} [props={}]
99
+ * `regionType` defaults to the lowest-level declared type. The TITLE (the header text) comes from `delta`, else `text`,
100
+ * else `title`, else `fields.title`: it is never stored in the `fields` map. Invalid values for declared fields are
101
+ * dropped (warning); unknown fields are kept as-is.
102
+ * @param {string|null} [parentId=null] @param {number|null} [index=null]
103
+ * @returns {RegionBlock}
104
+ */
105
+ static create(nabu: Nabu, type: string, props?: {
106
+ regionType?: string;
107
+ title?: string;
108
+ text?: string;
109
+ delta?: import("loro-crdt").Delta<string>[];
110
+ fields?: Record<string, any>;
111
+ }, parentId?: string | null, index?: number | null): RegionBlock;
112
+ /** @param {Nabu} nabu @param {RegionNode} node */
113
+ constructor(nabu: Nabu, node: RegionNode);
114
+ container: LoroText;
115
+ /** @type {TextBehavior} */
116
+ behavior: TextBehavior;
117
+ /** @type {RegionsConfig} */
118
+ get config(): RegionsConfig;
119
+ component: import("svelte").Component<any, any, string> | import("svelte").Component<{
120
+ block: import("./region.svelte.js").RegionBlock;
121
+ }, {}, "">;
122
+ get text(): string;
123
+ get delta(): import("loro-crdt").Delta<string>[];
124
+ selection: {
125
+ from: number;
126
+ to: number;
127
+ isCollapsed: boolean;
128
+ direction: "backward" | "forward" | "none";
129
+ } | null;
130
+ /** @type {number} */
131
+ weight: number;
132
+ /** The id of the region type (`''` while unset). Reactive. @type {string} */
133
+ regionType: string;
134
+ /**
135
+ * The fields, typed by the declaration of the region type. Reactive.
136
+ * - `title` is always there: the plain text of the header (`''` when empty);
137
+ * - a declared field holds its value, or `null` when it is unset OR holds something of the wrong type
138
+ * (the stored value is kept untouched; `richtext` reads as its plain string, see `richtext(name)`);
139
+ * - a field the type does NOT declare is returned as-is.
140
+ * @type {Record<string, any>}
141
+ */
142
+ fields: Record<string, any>;
143
+ /** The title: the plain text of the header. Reactive. @type {string} */
144
+ get title(): string;
145
+ /** The fields as stored, richtext as Loro deltas: what a document / clipboard export writes. The title is the header, never a field. @returns {Record<string, any>} */
146
+ get exportFields(): Record<string, any>;
147
+ /** @returns {{ regionType: string, fields: Record<string, any> }} */
148
+ get exportProps(): {
149
+ regionType: string;
150
+ fields: Record<string, any>;
151
+ };
152
+ /** What the clipboard form of a (partially) selected region carries besides its title and children. */
153
+ get clipboardProps(): {
154
+ regionType: string;
155
+ fields: Record<string, any>;
156
+ };
157
+ /**
158
+ * The LoroText behind a `richtext` field (to read its delta / marks, or to bind an editor), or null.
159
+ * @param {string} name
160
+ * @returns {LoroText | null}
161
+ */
162
+ richtext(name: string): LoroText | null;
163
+ /**
164
+ * Sets (or, with `null` / `undefined`, clears) a field. The `title` is the header text: setting it replaces that text
165
+ * (marks are dropped). A declared field is validated (see `validateField`): an invalid value is refused (returns false,
166
+ * warns, nothing is written). A field the type does not declare is stored as-is. Own undo step like any commit.
167
+ * @param {string} name @param {unknown} value
168
+ * @param {{ commit?: boolean }} [options] `commit: false` leaves the transaction open (the caller commits)
169
+ * @returns {boolean} whether the value was written
170
+ */
171
+ setField(name: string, value: unknown, { commit }?: {
172
+ commit?: boolean;
173
+ }): boolean;
174
+ /**
175
+ * Changes the type of this region (its level follows). The fields are kept: those the new type does not declare
176
+ * remain stored as unknown fields. An unknown type id is refused.
177
+ * @param {string} regionType
178
+ * @param {{ commit?: boolean }} [options]
179
+ * @returns {boolean}
180
+ */
181
+ setRegionType(regionType: string, { commit }?: {
182
+ commit?: boolean;
183
+ }): boolean;
184
+ /** @param {import('../block.svelte.js').Block} block */
185
+ absorbs(block: import("../block.svelte.js").Block): boolean;
186
+ /** @param {import('loro-crdt').Delta<string>[]} data */
187
+ applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
188
+ /**
189
+ * Paste with the caret in the TITLE (text only, flat). Several blocks (or a container): the text of every pasted text
190
+ * block, depth first, joined by a single space, goes into the title at the caret, marks kept; nothing goes to the
191
+ * body. One pasted text block is the engine's inline paste (declined). Blocks without text (an image…) are dropped.
192
+ * @param {import('../../utils/extensions.js').PasteBlock[]} blocks
193
+ * @param {{ offset: number }} ctx
194
+ * @returns {{ block: RegionBlock, offset: number } | null}
195
+ */
196
+ acceptPaste(blocks: import("../../utils/extensions.js").PasteBlock[], ctx: {
197
+ offset: number;
198
+ }): {
199
+ block: RegionBlock;
200
+ offset: number;
201
+ } | null;
202
+ /**
203
+ * @param {InputEvent} event
204
+ * @returns {boolean}
205
+ */
206
+ beforeinput(event: InputEvent): boolean;
207
+ #private;
208
+ }
209
+ export type RegionNode = NabuNode<{
210
+ type: "region";
211
+ regionType: string;
212
+ fields: LoroMap;
213
+ text: LoroText;
214
+ }>;
215
+ import { LoroMap } from "loro-crdt";
216
+ import { MegaBlock } from "../megablock.svelte.js";
217
+ import { LoroText } from "loro-crdt";
218
+ import { TextBehavior } from "../../behaviors/text";
219
+ import type { RegionsConfig } from "./types.js";
220
+ import type { Nabu } from "../nabu.svelte.js";
221
+ import type { NabuNode } from "../nabu.svelte.js";