@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
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Validates the declaration and returns the resolved configuration. Throws on an invalid declaration (a
3
+ * configuration error is the integrator's, and is reported when the extension is created).
4
+ * @param {{ types?: Record<string, RegionTypeInit> }} [options]
5
+ * @returns {RegionsConfig}
6
+ */
7
+ export function resolveConfig(options?: {
8
+ types?: Record<string, RegionTypeInit>;
9
+ }): RegionsConfig;
10
+ /**
11
+ * The spec of a field of a region type: the base `title`, a declared field, or `undefined` (an unknown field,
12
+ * kept as-is).
13
+ * @param {RegionTypeDef | undefined} def @param {string} name
14
+ * @returns {FieldSpec | undefined}
15
+ */
16
+ export function fieldSpec(def: RegionTypeDef | undefined, name: string): FieldSpec | undefined;
17
+ /**
18
+ * Whether `value` is a valid date string: ISO 8601 `YYYY-MM-DD`, optionally with a time (`YYYY-MM-DDTHH:mm[:ss[.sss]][Z|±HH:MM]`).
19
+ * @param {unknown} value
20
+ * @returns {value is string}
21
+ */
22
+ export function isDateString(value: unknown): value is string;
23
+ /**
24
+ * Validates (and normalises) a value against a field spec.
25
+ * - `null` / `undefined` always validate: they CLEAR the field (`{ ok: true, value: undefined }`);
26
+ * - `text` a string; `number` a finite number; `boolean` a boolean; `enum` one of the declared values;
27
+ * - `date` a valid ISO date string, or a `Date` (stored as its ISO string);
28
+ * - `richtext` a string, or a Loro delta array (`[{ insert, attributes? }]`): normalised to a delta.
29
+ * Never throws and never coerces across kinds (`'3'` is not a number).
30
+ * @param {FieldSpec} spec @param {unknown} value
31
+ * @returns {{ ok: true, value: any } | { ok: false }}
32
+ */
33
+ export function validateField(spec: FieldSpec, value: unknown): {
34
+ ok: true;
35
+ value: any;
36
+ } | {
37
+ ok: false;
38
+ };
39
+ /**
40
+ * Applies a label template. `{index}` (the number, empty when the type is not numbered), `{path}` ("2.3"), `{title}`,
41
+ * `{type}`, `{level}`; any other `{token}` is left as written. The result is trimmed and its whitespace collapsed,
42
+ * so an empty `{title}` leaves no dangling space ("1.1 " → "1.1").
43
+ * @param {string} template
44
+ * @param {{ index: number | null, path: string, title: string, type: string, level: number }} values
45
+ * @returns {string}
46
+ */
47
+ export function formatLabel(template: string, values: {
48
+ index: number | null;
49
+ path: string;
50
+ title: string;
51
+ type: string;
52
+ level: number;
53
+ }): string;
54
+ /**
55
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
56
+ * runes, no engine: everything here is testable on its own.
57
+ *
58
+ * A region TYPE is declared by the integrator:
59
+ *
60
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
61
+ *
62
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
63
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
64
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
65
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
66
+ * over the whole document, for that type) or `'none'` (no index).
67
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
68
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
69
+ *
70
+ * @typedef {'text' | 'richtext' | 'number' | 'boolean' | 'enum' | 'date'} FieldKind
71
+ *
72
+ * @typedef {Object} FieldSpec
73
+ * @property {string} name
74
+ * @property {FieldKind} kind
75
+ * @property {string[]} [values] the allowed values of an `enum`
76
+ *
77
+ * @typedef {'parent' | 'document' | 'none'} Numbering
78
+ *
79
+ * @typedef {Object} RegionTypeInit
80
+ * @property {number} level
81
+ * @property {string} [name]
82
+ * @property {string} [label]
83
+ * @property {Numbering} [numbering]
84
+ * @property {Record<string, FieldKind | { type: FieldKind, values?: string[] }>} [fields]
85
+ *
86
+ * @typedef {Object} RegionTypeDef
87
+ * @property {string} id
88
+ * @property {number} level
89
+ * @property {string} name readable name; the id when none is declared
90
+ * @property {string} label
91
+ * @property {Numbering} numbering
92
+ * @property {Map<string, FieldSpec>} fields the DECLARED fields (the base `title` is not in it)
93
+ *
94
+ * @typedef {Object} RegionsConfig
95
+ * @property {Map<string, RegionTypeDef>} types in declaration order
96
+ * @property {string} defaultType the type `insertRegion` uses when none is given: the declared type of the lowest level
97
+ * @property {number} maxLevel the deepest declared level (the level given to a marker whose type is not declared)
98
+ */
99
+ export const FIELD_KINDS: readonly ["text", "richtext", "number", "boolean", "enum", "date"];
100
+ export const NUMBERINGS: readonly ["parent", "document", "none"];
101
+ export namespace TITLE_SPEC {
102
+ let name: string;
103
+ let kind: FieldKind;
104
+ let values: string[] | undefined;
105
+ }
106
+ /**
107
+ * Default types: ONE generic `section` division over three levels, as three types (the level IS the type: changing
108
+ * the level of a region = changing its type, ADR 016 §3.4). Labels "1.", "1.1", "1.1.1".
109
+ * @type {Record<string, RegionTypeInit>}
110
+ */
111
+ export const DEFAULT_TYPES: Record<string, RegionTypeInit>;
112
+ /**
113
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
114
+ * runes, no engine: everything here is testable on its own.
115
+ *
116
+ * A region TYPE is declared by the integrator:
117
+ *
118
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
119
+ *
120
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
121
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
122
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
123
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
124
+ * over the whole document, for that type) or `'none'` (no index).
125
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
126
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
127
+ */
128
+ export type FieldKind = "text" | "richtext" | "number" | "boolean" | "enum" | "date";
129
+ /**
130
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
131
+ * runes, no engine: everything here is testable on its own.
132
+ *
133
+ * A region TYPE is declared by the integrator:
134
+ *
135
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
136
+ *
137
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
138
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
139
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
140
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
141
+ * over the whole document, for that type) or `'none'` (no index).
142
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
143
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
144
+ */
145
+ export type FieldSpec = {
146
+ name: string;
147
+ kind: FieldKind;
148
+ /**
149
+ * the allowed values of an `enum`
150
+ */
151
+ values?: string[] | undefined;
152
+ };
153
+ /**
154
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
155
+ * runes, no engine: everything here is testable on its own.
156
+ *
157
+ * A region TYPE is declared by the integrator:
158
+ *
159
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
160
+ *
161
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
162
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
163
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
164
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
165
+ * over the whole document, for that type) or `'none'` (no index).
166
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
167
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
168
+ */
169
+ export type Numbering = "parent" | "document" | "none";
170
+ /**
171
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
172
+ * runes, no engine: everything here is testable on its own.
173
+ *
174
+ * A region TYPE is declared by the integrator:
175
+ *
176
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
177
+ *
178
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
179
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
180
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
181
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
182
+ * over the whole document, for that type) or `'none'` (no index).
183
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
184
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
185
+ */
186
+ export type RegionTypeInit = {
187
+ level: number;
188
+ name?: string | undefined;
189
+ label?: string | undefined;
190
+ numbering?: Numbering | undefined;
191
+ fields?: Record<string, FieldKind | {
192
+ type: FieldKind;
193
+ values?: string[];
194
+ }> | undefined;
195
+ };
196
+ /**
197
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
198
+ * runes, no engine: everything here is testable on its own.
199
+ *
200
+ * A region TYPE is declared by the integrator:
201
+ *
202
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
203
+ *
204
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
205
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
206
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
207
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
208
+ * over the whole document, for that type) or `'none'` (no index).
209
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
210
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
211
+ */
212
+ export type RegionTypeDef = {
213
+ id: string;
214
+ level: number;
215
+ /**
216
+ * readable name; the id when none is declared
217
+ */
218
+ name: string;
219
+ label: string;
220
+ numbering: Numbering;
221
+ /**
222
+ * the DECLARED fields (the base `title` is not in it)
223
+ */
224
+ fields: Map<string, FieldSpec>;
225
+ };
226
+ /**
227
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
228
+ * runes, no engine: everything here is testable on its own.
229
+ *
230
+ * A region TYPE is declared by the integrator:
231
+ *
232
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
233
+ *
234
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
235
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
236
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
237
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
238
+ * over the whole document, for that type) or `'none'` (no index).
239
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
240
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
241
+ */
242
+ export type RegionsConfig = {
243
+ /**
244
+ * in declaration order
245
+ */
246
+ types: Map<string, RegionTypeDef>;
247
+ /**
248
+ * the type `insertRegion` uses when none is given: the declared type of the lowest level
249
+ */
250
+ defaultType: string;
251
+ /**
252
+ * the deepest declared level (the level given to a marker whose type is not declared)
253
+ */
254
+ maxLevel: number;
255
+ };
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Region types: declaration, normalisation and field validation (ADR 016 §3.2). Pure functions, no
3
+ * runes, no engine: everything here is testable on its own.
4
+ *
5
+ * A region TYPE is declared by the integrator:
6
+ *
7
+ * { chapter: { level: 2, label: 'Chapter {index}', numbering: 'document', fields: { pov: 'text' } } }
8
+ *
9
+ * - `level` depth of the division (1 = the highest). The extent of a region is deduced from the levels.
10
+ * - `name` readable name of the type ("Chapter"), shown by the region chooser and the slash menu; defaults to the type id.
11
+ * - `label` display template: `{index}`, `{path}` ("2.3"), `{title}`, `{type}`, `{level}`.
12
+ * - `numbering` `'parent'` (restarts at 1 in each parent region; the default), `'document'` (continues
13
+ * over the whole document, for that type) or `'none'` (no index).
14
+ * - `fields` typed fields: `text`, `richtext` (LoroText), `number`, `boolean`, `enum`, `date`.
15
+ * A field is declared by its kind (`'text'`) or by an object (`{ type: 'enum', values: [...] }`).
16
+ *
17
+ * @typedef {'text' | 'richtext' | 'number' | 'boolean' | 'enum' | 'date'} FieldKind
18
+ *
19
+ * @typedef {Object} FieldSpec
20
+ * @property {string} name
21
+ * @property {FieldKind} kind
22
+ * @property {string[]} [values] the allowed values of an `enum`
23
+ *
24
+ * @typedef {'parent' | 'document' | 'none'} Numbering
25
+ *
26
+ * @typedef {Object} RegionTypeInit
27
+ * @property {number} level
28
+ * @property {string} [name]
29
+ * @property {string} [label]
30
+ * @property {Numbering} [numbering]
31
+ * @property {Record<string, FieldKind | { type: FieldKind, values?: string[] }>} [fields]
32
+ *
33
+ * @typedef {Object} RegionTypeDef
34
+ * @property {string} id
35
+ * @property {number} level
36
+ * @property {string} name readable name; the id when none is declared
37
+ * @property {string} label
38
+ * @property {Numbering} numbering
39
+ * @property {Map<string, FieldSpec>} fields the DECLARED fields (the base `title` is not in it)
40
+ *
41
+ * @typedef {Object} RegionsConfig
42
+ * @property {Map<string, RegionTypeDef>} types in declaration order
43
+ * @property {string} defaultType the type `insertRegion` uses when none is given: the declared type of the lowest level
44
+ * @property {number} maxLevel the deepest declared level (the level given to a marker whose type is not declared)
45
+ */
46
+
47
+ export const FIELD_KINDS = /** @type {const} */ (['text', 'richtext', 'number', 'boolean', 'enum', 'date']);
48
+ export const NUMBERINGS = /** @type {const} */ (['parent', 'document', 'none']);
49
+
50
+ /** The base field every region has. */
51
+ export const TITLE_SPEC = /** @type {FieldSpec} */ ({ name: 'title', kind: 'text' });
52
+
53
+ /**
54
+ * Default types: ONE generic `section` division over three levels, as three types (the level IS the type: changing
55
+ * the level of a region = changing its type, ADR 016 §3.4). Labels "1.", "1.1", "1.1.1".
56
+ * @type {Record<string, RegionTypeInit>}
57
+ */
58
+ export const DEFAULT_TYPES = {
59
+ 'section-1': { level: 1, name: 'Section', label: '{path}. {title}' },
60
+ 'section-2': { level: 2, name: 'Subsection', label: '{path} {title}' },
61
+ 'section-3': { level: 3, name: 'Sub-subsection', label: '{path} {title}' },
62
+ };
63
+
64
+ /**
65
+ * @param {string} id @param {string} name @param {unknown} raw
66
+ * @returns {FieldSpec}
67
+ */
68
+ function normalizeField(id, name, raw) {
69
+ const spec = typeof raw === 'string' ? { type: raw } : /** @type {any} */ (raw);
70
+ const kind = spec?.type;
71
+ if (!FIELD_KINDS.includes(kind)) {
72
+ throw new Error(`Region type "${id}": field "${name}" has an unknown kind ${JSON.stringify(kind)} (expected one of ${FIELD_KINDS.join(', ')}).`);
73
+ }
74
+ /** @type {FieldSpec} */
75
+ const out = { name, kind };
76
+ if (kind === 'enum') {
77
+ if (!Array.isArray(spec.values) || !spec.values.length || spec.values.some((/** @type {unknown} */ v) => typeof v !== 'string')) {
78
+ throw new Error(`Region type "${id}": enum field "${name}" needs a non-empty \`values\` array of strings.`);
79
+ }
80
+ out.values = [...spec.values];
81
+ }
82
+ return out;
83
+ }
84
+
85
+ /**
86
+ * Validates the declaration and returns the resolved configuration. Throws on an invalid declaration (a
87
+ * configuration error is the integrator's, and is reported when the extension is created).
88
+ * @param {{ types?: Record<string, RegionTypeInit> }} [options]
89
+ * @returns {RegionsConfig}
90
+ */
91
+ export function resolveConfig(options = {}) {
92
+ const declared = options.types && Object.keys(options.types).length ? options.types : DEFAULT_TYPES;
93
+ /** @type {Map<string, RegionTypeDef>} */
94
+ const types = new Map();
95
+ for (const [id, init] of Object.entries(declared)) {
96
+ if (!init || !Number.isInteger(init.level) || init.level < 1) {
97
+ throw new Error(`Region type "${id}": \`level\` must be an integer >= 1.`);
98
+ }
99
+ const numbering = init.numbering ?? 'parent';
100
+ if (!NUMBERINGS.includes(numbering)) {
101
+ throw new Error(`Region type "${id}": \`numbering\` must be one of ${NUMBERINGS.join(', ')}.`);
102
+ }
103
+ /** @type {Map<string, FieldSpec>} */
104
+ const fields = new Map();
105
+ for (const [name, raw] of Object.entries(init.fields ?? {})) {
106
+ if (name === TITLE_SPEC.name) continue; // `title` is a base field of every region
107
+ fields.set(name, normalizeField(id, name, raw));
108
+ }
109
+ types.set(id, {
110
+ id,
111
+ level: init.level,
112
+ name: typeof init.name === 'string' && init.name.trim() ? init.name.trim() : id,
113
+ label: typeof init.label === 'string' ? init.label : (numbering === 'none' ? '{title}' : '{path} {title}'),
114
+ numbering,
115
+ fields,
116
+ });
117
+ }
118
+ let defaultType = '';
119
+ let maxLevel = 1;
120
+ for (const def of types.values()) {
121
+ if (!defaultType || def.level < /** @type {RegionTypeDef} */ (types.get(defaultType)).level) defaultType = def.id;
122
+ if (def.level > maxLevel) maxLevel = def.level;
123
+ }
124
+ return { types, defaultType, maxLevel };
125
+ }
126
+
127
+ /**
128
+ * The spec of a field of a region type: the base `title`, a declared field, or `undefined` (an unknown field,
129
+ * kept as-is).
130
+ * @param {RegionTypeDef | undefined} def @param {string} name
131
+ * @returns {FieldSpec | undefined}
132
+ */
133
+ export function fieldSpec(def, name) {
134
+ return name === TITLE_SPEC.name ? TITLE_SPEC : def?.fields.get(name);
135
+ }
136
+
137
+ const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
138
+
139
+ /**
140
+ * Whether `value` is a valid date string: ISO 8601 `YYYY-MM-DD`, optionally with a time (`YYYY-MM-DDTHH:mm[:ss[.sss]][Z|±HH:MM]`).
141
+ * @param {unknown} value
142
+ * @returns {value is string}
143
+ */
144
+ export function isDateString(value) {
145
+ if (typeof value !== 'string') return false;
146
+ const m = DATE_RE.exec(value);
147
+ if (!m) return false;
148
+ const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
149
+ const probe = new Date(Date.UTC(y, mo - 1, d));
150
+ if (probe.getUTCFullYear() !== y || probe.getUTCMonth() !== mo - 1 || probe.getUTCDate() !== d) return false; // 2024-02-31
151
+ return !Number.isNaN(Date.parse(value.replace(' ', 'T')));
152
+ }
153
+
154
+ /** @param {unknown} v @returns {v is Array<{ insert: string, attributes?: Record<string, any> }>} */
155
+ const isDelta = (v) => Array.isArray(v) && v.every((op) => op && typeof op === 'object' && typeof (/** @type {any} */ (op)).insert === 'string');
156
+
157
+ /**
158
+ * Validates (and normalises) a value against a field spec.
159
+ * - `null` / `undefined` always validate: they CLEAR the field (`{ ok: true, value: undefined }`);
160
+ * - `text` a string; `number` a finite number; `boolean` a boolean; `enum` one of the declared values;
161
+ * - `date` a valid ISO date string, or a `Date` (stored as its ISO string);
162
+ * - `richtext` a string, or a Loro delta array (`[{ insert, attributes? }]`): normalised to a delta.
163
+ * Never throws and never coerces across kinds (`'3'` is not a number).
164
+ * @param {FieldSpec} spec @param {unknown} value
165
+ * @returns {{ ok: true, value: any } | { ok: false }}
166
+ */
167
+ export function validateField(spec, value) {
168
+ if (value === undefined || value === null) return { ok: true, value: undefined };
169
+ switch (spec.kind) {
170
+ case 'text': return typeof value === 'string' ? { ok: true, value } : { ok: false };
171
+ case 'number': return typeof value === 'number' && Number.isFinite(value) ? { ok: true, value } : { ok: false };
172
+ case 'boolean': return typeof value === 'boolean' ? { ok: true, value } : { ok: false };
173
+ case 'enum': return typeof value === 'string' && spec.values?.includes(value) ? { ok: true, value } : { ok: false };
174
+ case 'date':
175
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? { ok: false } : { ok: true, value: value.toISOString() };
176
+ return isDateString(value) ? { ok: true, value } : { ok: false };
177
+ case 'richtext':
178
+ if (typeof value === 'string') return { ok: true, value: value ? [{ insert: value }] : [] };
179
+ return isDelta(value) ? { ok: true, value } : { ok: false };
180
+ default: return { ok: false };
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Applies a label template. `{index}` (the number, empty when the type is not numbered), `{path}` ("2.3"), `{title}`,
186
+ * `{type}`, `{level}`; any other `{token}` is left as written. The result is trimmed and its whitespace collapsed,
187
+ * so an empty `{title}` leaves no dangling space ("1.1 " → "1.1").
188
+ * @param {string} template
189
+ * @param {{ index: number | null, path: string, title: string, type: string, level: number }} values
190
+ * @returns {string}
191
+ */
192
+ export function formatLabel(template, values) {
193
+ const map = /** @type {Record<string, string>} */ ({
194
+ index: values.index == null ? '' : String(values.index),
195
+ path: values.path,
196
+ title: values.title,
197
+ type: values.type,
198
+ level: String(values.level),
199
+ });
200
+ return template
201
+ .replace(/\{(index|path|title|type|level)\}/g, (_, token) => map[token])
202
+ .replace(/\s+/g, ' ')
203
+ .trim();
204
+ }
@@ -6,20 +6,102 @@
6
6
  export class NabuSelection extends SvelteSelection {
7
7
  /** @param {Nabu} nabu */
8
8
  constructor(nabu: Nabu);
9
+ /** How many times the editor itself placed the selection: lets a deferred fix-up tell that someone else already did. */
10
+ placements: number;
11
+ /**
12
+ * The root element of this engine (set by `Nabu.svelte` through {@link NabuSelection#attachRoot}); null while no editor is
13
+ * mounted. Not part of the stable contract.
14
+ * @type {HTMLElement | null}
15
+ */
16
+ root: HTMLElement | null;
17
+ /**
18
+ * Declare the element that renders this engine (the `[data-nabu-root]` div). Returns the function that detaches it (only
19
+ * clears the reference when it is still this element: a remount may already have set the next one).
20
+ * @param {HTMLElement} el
21
+ * @returns {() => void}
22
+ */
23
+ attachRoot(el: HTMLElement): () => void;
24
+ /**
25
+ * How `node` stands relative to this engine's root (see above). A node of a detached tree is 'none'.
26
+ * @param {Node | null | undefined} node
27
+ * @returns {'mine' | 'foreign' | 'none'}
28
+ */
29
+ kindOf(node: Node | null | undefined): "mine" | "foreign" | "none";
30
+ /** Whether `node` is inside this engine's own root (and not inside a nested editor). @param {Node | null | undefined} node */
31
+ owns(node: Node | null | undefined): boolean;
32
+ /**
33
+ * The nearest ancestor-or-self of `node` matching `selector` that lies inside MY root: a `[data-nabu-ui]` island or an inert
34
+ * block AROUND my root (this editor nested in a block of another one) is not a marker of my content.
35
+ * @param {Node | null | undefined} node @param {string} selector
36
+ * @returns {Element | null}
37
+ */
38
+ closestOwn(node: Node | null | undefined, selector: string): Element | null;
39
+ /**
40
+ * The scope of the live DOM selection for this engine (see above).
41
+ * @param {Selection | null} [live] defaults to `window.getSelection()`
42
+ * @returns {'mine' | 'outside' | 'foreign'}
43
+ */
44
+ scope(live?: Selection | null): "mine" | "outside" | "foreign";
9
45
  nabu: Nabu;
10
46
  /** @type {Set<Block>} */
11
47
  previous: Set<Block>;
12
- anchorBlock: Block | null | undefined;
13
- focusBlock: Block | null | undefined;
14
- startBlock: Block | null | undefined;
15
- endBlock: Block | null | undefined;
16
- start: {
48
+ /**
49
+ * Move a caret / focus that sits on a NON-TEXT position to the nearest valid text position, in the
50
+ * direction of travel (arrow keys; a heuristic otherwise): inert blocks (dividers, images…), element
51
+ * carets (container padding, between blocks, the editor root) and stray text nodes outside any text
52
+ * block (whitespace around a toggle's arrow…) are all "dead" positions where typing would be swallowed.
53
+ * Hidden content is never a target (it is not rendered). Works for collapsed carets and for ranges
54
+ * (shift+arrow): invalid anchor → collapse to the corrected anchor; only the focus invalid → keep the
55
+ * anchor, correct the focus.
56
+ *
57
+ * Synchronous and idempotent (reads the live DOM selection): call it right after `sync()`.
58
+ * When ArrowDown / ArrowRight leaves the document with no text position after the caret, the nabu
59
+ * "opens" a trailing caret (see `Nabu.openTrailingCaret`).
60
+ * @returns {boolean} True if the selection was moved
61
+ */
62
+ normalize(): boolean;
63
+ /**
64
+ * Blocks were removed from the document (a programmatic change, a collaborator, an import, an undo): once the dust has
65
+ * settled, a DOM selection left on a DEAD position (the editor root or a container, where the removed block was) is brought
66
+ * onto the nearest text, so that the next click, key or paste starts from a real model position (P-108): the browser fires
67
+ * no `selectionchange` when a click re-selects the very position the selection already has. Deferred to a task of its own, so
68
+ * that whoever removed the block, and the editor's own handlers (which place their caret right after the render), win.
69
+ * Debounced: one check per burst. A selection that is not dead (or not in an editor) is left alone.
70
+ */
71
+ scheduleRepair(): void;
72
+ /** @returns {boolean} Whether the selection was moved */
73
+ repairAfterRemoval(): boolean;
74
+ /**
75
+ * Selects exactly the text of `block` (Select All inside an isolated field).
76
+ * @param {Block} block
77
+ * @returns {boolean} False when the block has no DOM point to select
78
+ * @public
79
+ */
80
+ public selectBlockText(block: Block): boolean;
81
+ /**
82
+ * Selects the text of the document between two blocks (first block start -> last block end).
83
+ * @param {Block} first @param {Block} last
84
+ * @returns {boolean}
85
+ * @public
86
+ */
87
+ public selectBetween(first: Block, last: Block): boolean;
88
+ /** @public */
89
+ public anchorBlock: Block | null | undefined;
90
+ /** @public */
91
+ public focusBlock: Block | null | undefined;
92
+ /** @public */
93
+ public startBlock: Block | null | undefined;
94
+ /** @public */
95
+ public endBlock: Block | null | undefined;
96
+ /** @public */
97
+ public start: {
17
98
  from: number;
18
99
  to: number;
19
100
  direction: "forward" | "backward" | "none";
20
101
  block: Block;
21
102
  } | null | undefined;
22
- end: {
103
+ /** @public */
104
+ public end: {
23
105
  from: number;
24
106
  to: number;
25
107
  direction: "forward" | "backward" | "none";
@@ -29,9 +111,25 @@ export class NabuSelection extends SvelteSelection {
29
111
  * Définit le curseur à un endroit précis du document (Modèle -> DOM)
30
112
  * @param {Block} block
31
113
  * @param {number} offset
114
+ * @public
115
+ */
116
+ public setCursor(block: Block, offset: number): void;
117
+ /**
118
+ * The blocks the selection covers (flagged `selected`: highlighted, marked, …). A selection that does not lie entirely in
119
+ * one block leaves out the blocks that isolate their text (`Block#isolatesSelection`): a title is not part of a range.
120
+ * Nor does it hold the HIDDEN content of a block that hides its children (the body of a collapsed toggle, `hidesChildren`):
121
+ * a mark or a highlight never reaches text nobody sees (P-112). Deleting a range still removes such a body with its owner:
122
+ * the deletion walks the tree itself (`container.utils.js`), it does not read this set.
123
+ * @type {Set<Block>}
124
+ * @public
125
+ */
126
+ public blocks: Set<Block>;
127
+ /**
128
+ * True while the selection is a non-collapsed range across several blocks. The editor mirrors it as `data-nabu-range` on its
129
+ * root, which the stylesheet uses to not highlight isolated blocks (the model leaves them out of the range, see `blocks`).
130
+ * @public
32
131
  */
33
- setCursor(block: Block, offset: number): void;
34
- blocks: Set<Block>;
132
+ public isRange: boolean;
35
133
  #private;
36
134
  }
37
135
  import { SvelteSelection } from "../utils/selection.svelte.js";