@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,504 @@
1
+ import { SvelteMap } from 'svelte/reactivity';
2
+ import { ASSET_PREFIX, isHashId } from './assets.clipboard.js';
3
+ import { MemoryOutbox } from './outbox.js';
4
+ import { reasonOf } from './status.js';
5
+
6
+ /** @import { Outbox, OutboxEntry } from './outbox.js' */
7
+ /** @import { FileReason } from './status.js' */
8
+
9
+ /**
10
+ * @typedef {Object} AutoRetryConfig How a persisted editor retries, by itself, the uploads it finds waiting when it is opened (P-97).
11
+ * @property {number} [initialDelay] ms before the second attempt (default 2000); each next one waits twice as long
12
+ * @property {number} [maxDelay] longest wait between two attempts (default 60000)
13
+ * @property {number} [maxAttempts] attempts per file and per session, the one at open included (default 8); the `online` event grants a new series
14
+ */
15
+ export const DEFAULT_AUTO_RETRY = Object.freeze({ initialDelay: 2000, maxDelay: 60000, maxAttempts: 8 });
16
+
17
+ /**
18
+ * The resolved `files.autoRetry` option: `false` disables the automatic retries, an object tunes them, anything else is the default.
19
+ * @param {unknown} option @returns {Required<AutoRetryConfig> | null}
20
+ */
21
+ export function resolveAutoRetry(option) {
22
+ if (option === false) return null;
23
+ const o = option && typeof option === 'object' ? /** @type {AutoRetryConfig} */ (option) : {};
24
+ const positive = (/** @type {unknown} */ v, /** @type {number} */ fallback) => (typeof v === 'number' && v >= 0 && Number.isFinite(v) ? v : fallback);
25
+ return {
26
+ initialDelay: positive(o.initialDelay, DEFAULT_AUTO_RETRY.initialDelay),
27
+ maxDelay: positive(o.maxDelay, DEFAULT_AUTO_RETRY.maxDelay),
28
+ maxAttempts: Math.max(1, Math.floor(positive(o.maxAttempts, DEFAULT_AUTO_RETRY.maxAttempts))),
29
+ };
30
+ }
31
+
32
+ /**
33
+ * What the upload queue needs from {@link import('./files.svelte.js').Files} (kept as an interface so this module does not
34
+ * reach into it).
35
+ * @typedef {Object} UploadHost
36
+ * @property {import('../blocks/nabu.svelte.js').Nabu} nabu
37
+ * @property {import('./store.js').AssetStore} store
38
+ * @property {import('loro-crdt').LoroMap} index the document's `assetIndex`
39
+ * @property {() => import('./files.svelte.js').FilesConfig} config
40
+ * @property {(write: () => void) => Promise<void>} silent run Loro writes as a silent commit (not an undo step)
41
+ * @property {(hash: string) => Promise<void>} settled resolves when the bytes of `hash` arriving with a paste are stored
42
+ * @property {() => void} forgetMissing forget the "no source has it" verdicts (the index changed)
43
+ * @property {<T>(promise: Promise<T>) => Promise<T>} track register a background job (see `Files#whenIdle`)
44
+ */
45
+
46
+ /**
47
+ * @typedef {Object} Job
48
+ * @property {string} hash
49
+ * @property {AbortController} controller
50
+ * @property {'cancel' | 'released' | null} cause why the controller was aborted
51
+ * @property {boolean} referenced a live block has referenced this file since the job started (a job nobody references
52
+ * yet, e.g. started by `Files#persist`, is not aborted by the "last block deleted" rule)
53
+ * @property {Promise<boolean>} promise resolves `true` when the upload succeeded
54
+ */
55
+
56
+ /**
57
+ * The upload side of {@link import('./files.svelte.js').Files} (ADR 014 lot 2): with a host (`files.onBeforePersist`) a file is
58
+ * stored locally first, then sent in the background. The queue is DRIVEN BY THE DOCUMENT, not by calls:
59
+ *
60
+ * - a block whose status is `pending`, with a `nabu-asset:sha256-…` ref, local bytes, no host `url` and no running upload
61
+ * → the upload starts (this is also how an upload RESUMES when a document is opened again, and how an undo that brings a
62
+ * deleted block back restarts it);
63
+ * - an upload whose file no live block references any more is aborted (`AbortController` → the `signal` given to the host);
64
+ * - success: `assetIndex[hash].url = <ref returned by the host>` and the blocks become `ready`, in a silent commit; the
65
+ * block's ref NEVER changes. Failure: the blocks become `error` (local copy kept). {@link Uploads#retry} / {@link Uploads#cancel}
66
+ * are the explicit controls.
67
+ *
68
+ * The outbox ({@link Outbox}) remembers what is waiting (and how many attempts were made) next to the local store, so it
69
+ * survives a closed tab; it is a record, the document statuses plus the local bytes are what the queue acts on.
70
+ *
71
+ * Retry on open (P-97): the files the outbox lists when the document is opened (an upload interrupted, or one that had failed) are
72
+ * sent again BY THEMSELVES, in the background: a failed `error` file at once, then, whenever an attempt fails, after 2 s, 4 s, 8 s…
73
+ * (at most 60 s), `maxAttempts` times per session; the browser's `online` event starts a fresh series. A cancelled upload (the user's
74
+ * choice) is not retried, nor are the failures of the current session (the block's `retry()` is for those). See {@link AutoRetryConfig}.
75
+ */
76
+ export class Uploads {
77
+ /** @type {UploadHost} */
78
+ #host;
79
+ /** @type {Outbox} */
80
+ outbox;
81
+ /** @type {Map<string, Job>} */
82
+ #jobs = new Map();
83
+ /** hash → progress (0–1) of the running upload. @type {SvelteMap<string, number>} */
84
+ #progress = new SvelteMap();
85
+ /** @type {Map<string, OutboxEntry>} */
86
+ #entries = new Map();
87
+ #scheduled = false;
88
+ /** @type {Promise<void> | null} */
89
+ #running = null;
90
+ #again = false;
91
+ #booted = false;
92
+ /** @type {Promise<void>} */
93
+ #boot;
94
+ /** `files.autoRetry`, resolved (`null`: off). */
95
+ #auto;
96
+ /** Files the outbox listed at open: the ones retried by themselves. @type {Set<string>} */
97
+ #autoSet = new Set();
98
+ /** Attempts started this session, per file of {@link Uploads#autoSet}. @type {Map<string, number>} */
99
+ #attempts = new Map();
100
+ /** @type {Map<string, ReturnType<typeof setTimeout>>} */
101
+ #timers = new Map();
102
+ /** Files that used their attempts or waited for the network: the next `online` event retries them. @type {Set<string>} */
103
+ #parked = new Set();
104
+ #disposed = false;
105
+ /** @type {(() => void) | null} */
106
+ #onOnline = null;
107
+
108
+ /** @param {UploadHost} host */
109
+ constructor(host) {
110
+ this.#host = host;
111
+ this.outbox = /** @type {Outbox} */ (host.config().outbox ?? new MemoryOutbox());
112
+ this.#auto = resolveAutoRetry(/** @type {any} */ (host.config()).autoRetry);
113
+ this.#boot = host.track(this.#start0());
114
+ }
115
+
116
+ /** Stop the automatic retries (timers, `online` listener). The queue itself keeps working. */
117
+ dispose() {
118
+ this.#disposed = true;
119
+ for (const timer of this.#timers.values()) clearTimeout(timer);
120
+ this.#timers.clear();
121
+ this.#parked.clear();
122
+ if (this.#onOnline) globalThis.removeEventListener?.('online', this.#onOnline);
123
+ this.#onOnline = null;
124
+ }
125
+
126
+ /** Resolves once the outbox was read and the first pass (resume) ran. @returns {Promise<void>} */
127
+ ready() { return this.#boot; }
128
+
129
+ /** @returns {((file: File, ctx: { signal?: AbortSignal, onProgress?: (p: number) => void }) => Promise<{ ref: string } | void>) | undefined} */
130
+ get #hook() { return this.#host.config().onBeforePersist; }
131
+
132
+ // ── Reactive state ───────────────────────────────────────────────────────────────────────────
133
+
134
+ /** Progress (0–1) of the running upload of `hash`, `null` when none runs. Reactive. @param {string} hash @returns {number | null} */
135
+ progress(hash) { return this.#progress.get(hash) ?? null; }
136
+
137
+ /** Whether any upload is running (not reactive). @returns {boolean} */
138
+ busy() { return this.#jobs.size > 0; }
139
+
140
+ /** Whether an upload of `hash` is running. Reactive. @param {string} hash @returns {boolean} */
141
+ isUploading(hash) { return this.#progress.has(hash); }
142
+
143
+ /** @param {string} hash @returns {string | null} the host location recorded in the index */
144
+ hostedUrl(hash) {
145
+ const url = /** @type {any} */ (this.#host.index.get(hash))?.url;
146
+ return typeof url === 'string' && url ? url : null;
147
+ }
148
+
149
+ /** Whether a file with this hash still has to be sent to the host. @param {string} hash @returns {boolean} */
150
+ needsUpload(hash) { return Boolean(this.#hook) && !this.hostedUrl(hash); }
151
+
152
+ // ── Document watching ────────────────────────────────────────────────────────────────────────
153
+
154
+ /**
155
+ * Called for every committed change of the document. Only what can concern an upload triggers a pass: a media ref /
156
+ * status written, or (while an upload runs) a node deleted. Typing never does.
157
+ * @param {any} event a Loro event batch
158
+ */
159
+ onDocEvent(event) {
160
+ let relevant = false;
161
+ for (const e of event?.events ?? []) {
162
+ const diff = e.diff;
163
+ if (e.path?.[0] === 'assetIndex') this.#host.forgetMissing();
164
+ // Changes IMPORTED from another tab (multi-tab sync) are that tab's uploads: they never start one here (two tabs would send
165
+ // the same file twice). They arrive with their final status; if that tab goes away first, the next open resumes the upload.
166
+ if (event?.by === 'import') continue;
167
+ if (diff?.type === 'map') {
168
+ const updated = diff.updated;
169
+ if (updated && ('ref' in updated || 'status' in updated)) relevant = true;
170
+ } else if (diff?.type === 'tree' && this.#jobs.size > 0) {
171
+ relevant = true;
172
+ }
173
+ }
174
+ if (relevant) this.schedule();
175
+ }
176
+
177
+ /** Run a pass soon (coalesced). */
178
+ schedule() {
179
+ if (this.#scheduled) return;
180
+ this.#scheduled = true;
181
+ queueMicrotask(() => {
182
+ this.#scheduled = false;
183
+ this.#host.track(this.reconcile());
184
+ });
185
+ }
186
+
187
+ /**
188
+ * Look at the document and act: abort the uploads nobody references, start those that are due. Passes never overlap.
189
+ * @returns {Promise<void>}
190
+ */
191
+ reconcile() {
192
+ if (!this.#booted) { this.#again = true; return this.#boot; } // the first pass (resume) runs first
193
+ if (this.#running) { this.#again = true; return this.#running; }
194
+ const run = (async () => {
195
+ try {
196
+ do {
197
+ this.#again = false;
198
+ try { await this.#pass(false); } catch (error) { this.#host.nabu.warn(`files: upload pass failed: ${error}`); }
199
+ } while (this.#again);
200
+ } finally {
201
+ this.#running = null;
202
+ }
203
+ })();
204
+ this.#running = run;
205
+ return run;
206
+ }
207
+
208
+ async #start0() {
209
+ try {
210
+ for (const entry of await this.outbox.list()) this.#entries.set(entry.hash, entry);
211
+ } catch (error) {
212
+ this.#host.nabu.warn(`files: could not read the upload outbox: ${error}`);
213
+ }
214
+ try {
215
+ await this.#pass(true);
216
+ } catch (error) {
217
+ this.#host.nabu.warn(`files: could not resume the uploads: ${error}`);
218
+ }
219
+ this.#booted = true;
220
+ if (this.#again) await this.reconcile();
221
+ this.#startAutoRetry();
222
+ }
223
+
224
+ // ── Retry on open (P-97) ─────────────────────────────────────────────────────────────────────
225
+
226
+ /** After the first pass: the files still waiting in the outbox are the ones to retry by themselves. */
227
+ #startAutoRetry() {
228
+ if (!this.#auto || !this.#hook || this.#disposed) return;
229
+ for (const [hash, entry] of this.#entries) {
230
+ this.#autoSet.add(hash);
231
+ if (entry.state === 'error' && !this.#jobs.has(hash)) this.#arm(hash);
232
+ }
233
+ if (this.#autoSet.size === 0 || this.#onOnline || typeof globalThis.addEventListener !== 'function') return;
234
+ this.#onOnline = () => this.#networkBack();
235
+ globalThis.addEventListener('online', this.#onOnline);
236
+ }
237
+
238
+ /** The network is back: every file that gave up or waited gets a fresh series, at once. */
239
+ #networkBack() {
240
+ if (this.#disposed) return;
241
+ for (const hash of [...this.#autoSet]) {
242
+ if (!this.#parked.has(hash) && !this.#timers.has(hash)) continue;
243
+ clearTimeout(this.#timers.get(hash));
244
+ this.#timers.delete(hash);
245
+ this.#parked.delete(hash);
246
+ this.#attempts.set(hash, 0);
247
+ this.#arm(hash);
248
+ }
249
+ }
250
+
251
+ /** Whether some live block of `hash` failed for a reason a retry can cure (not a cancellation, which is the user's choice). @param {string} hash */
252
+ #retriable(hash) {
253
+ return this.#nodesOf(hash).some((n) => n.data.get('status') === 'error' && n.data.get('reason')?.code !== 'cancelled');
254
+ }
255
+
256
+ /** Schedule the next automatic attempt of `hash` (backoff), unless it is not one to retry, or used its attempts. @param {string} hash */
257
+ #arm(hash) {
258
+ const auto = this.#auto;
259
+ if (!auto || this.#disposed || !this.#autoSet.has(hash) || this.#timers.has(hash) || this.#jobs.has(hash) || !this.#hook) return;
260
+ if (this.hostedUrl(hash) || !this.#retriable(hash)) return;
261
+ const done = this.#attempts.get(hash) ?? 0;
262
+ if (done >= auto.maxAttempts) { this.#parked.add(hash); return; }
263
+ const delay = done === 0 ? 0 : Math.min(auto.maxDelay, auto.initialDelay * 2 ** (done - 1));
264
+ this.#timers.set(hash, setTimeout(() => { this.#timers.delete(hash); void this.#attempt(hash); }, delay));
265
+ }
266
+
267
+ /** @param {string} hash */
268
+ async #attempt(hash) {
269
+ if (this.#disposed || this.#jobs.has(hash)) return;
270
+ if (globalThis.navigator?.onLine === false) { this.#parked.add(hash); return; } // offline: wait for the `online` event, no attempt used
271
+ if (this.hostedUrl(hash) || !this.#retriable(hash)) return;
272
+ const ok = await this.retry(hash);
273
+ if (!ok) this.#arm(hash); // (a failed job armed it already; this covers a retry that could not start)
274
+ }
275
+
276
+ /**
277
+ * Every live media block that references a stored file by hash: hash → its tree nodes (`nodes`) and the ones that are `pending`.
278
+ * @returns {Map<string, { nodes: any[], pending: any[] }>}
279
+ */
280
+ #scan() {
281
+ /** @type {Map<string, { nodes: any[], pending: any[] }>} */
282
+ const groups = new Map();
283
+ for (const node of /** @type {any[]} */ (this.#host.nabu.tree.getNodes())) {
284
+ if (node.isDeleted?.()) continue;
285
+ const ref = node.data.get('ref');
286
+ if (typeof ref !== 'string' || !ref.startsWith(ASSET_PREFIX)) continue;
287
+ const hash = ref.slice(ASSET_PREFIX.length);
288
+ if (!isHashId(hash)) continue;
289
+ let group = groups.get(hash);
290
+ if (!group) groups.set(hash, group = { nodes: [], pending: [] });
291
+ group.nodes.push(node);
292
+ if (node.data.get('status') === 'pending') group.pending.push(node);
293
+ }
294
+ return groups;
295
+ }
296
+
297
+ /** @param {boolean} boot the first pass after the document was opened */
298
+ async #pass(boot) {
299
+ let groups = this.#scan();
300
+ if (boot && (await this.#adoptOutbox(groups))) groups = this.#scan();
301
+
302
+ // The last block that shows a file in flight is gone (deleted): stop sending it. An undo brings it back and restarts it.
303
+ for (const [hash, job] of this.#jobs) {
304
+ if (groups.has(hash)) job.referenced = true;
305
+ else if (job.referenced && !job.cause) { job.cause = 'released'; job.controller.abort(); }
306
+ }
307
+
308
+ for (const [hash, group] of groups) {
309
+ if (!group.pending.length || this.#jobs.has(hash)) continue;
310
+ await this.#host.settled(hash); // bytes arriving with a paste are being stored: do not conclude too early
311
+ if (this.#jobs.has(hash)) continue;
312
+ if (this.hostedUrl(hash)) { await this.#mark(hash, 'ready', null, ['pending']); continue; } // already at the host
313
+ if (!(await this.#host.store.has(hash).catch(() => false))) continue; // nothing to send, nothing to show: see MediaBlock#isMissing
314
+ if (this.#hook) this.#startJob(hash, true);
315
+ else await this.#mark(hash, 'ready', null, ['pending']); // no host configured: the local copy is the file
316
+ }
317
+ }
318
+
319
+ /**
320
+ * First pass after opening: reconcile the outbox with the document. An entry whose file is not referenced by the document any
321
+ * more, already hosted, or whose local copy is gone, is stale and dropped; a still-pending entry referenced by a block
322
+ * that is not `pending` (the status was not saved before the tab closed) puts it back to `pending` so it resumes.
323
+ * @param {Map<string, { nodes: any[], pending: any[] }>} groups
324
+ * @returns {Promise<boolean>} whether the document was changed
325
+ */
326
+ async #adoptOutbox(groups) {
327
+ let changed = false;
328
+ for (const [hash, entry] of [...this.#entries]) {
329
+ const group = groups.get(hash);
330
+ if (!group || this.hostedUrl(hash) || !(await this.#host.store.has(hash).catch(() => false))) {
331
+ await this.#forget(hash);
332
+ continue;
333
+ }
334
+ if (entry.state === 'pending' && this.#hook && group.nodes.some((n) => n.data.get('status') === 'ready')) {
335
+ changed = (await this.#mark(hash, 'pending', null, ['ready'])) || changed;
336
+ }
337
+ }
338
+ return changed;
339
+ }
340
+
341
+ // ── Document writes ──────────────────────────────────────────────────────────────────────────
342
+
343
+ /** @param {string} hash @returns {any[]} live tree nodes whose ref is `hash` */
344
+ #nodesOf(hash) {
345
+ const ref = ASSET_PREFIX + hash;
346
+ return /** @type {any[]} */ (this.#host.nabu.tree.getNodes()).filter((n) => !n.isDeleted?.() && n.data.get('ref') === ref);
347
+ }
348
+
349
+ /**
350
+ * Set the status (and reason) of the live blocks of a file, silently. `from` restricts it to blocks currently in one of those statuses.
351
+ * @param {string} hash @param {string} status @param {FileReason | null} reason @param {string[]} [from]
352
+ * @param {(() => void)} [extra] more writes for the same commit
353
+ * @returns {Promise<boolean>} whether a block was changed
354
+ */
355
+ async #mark(hash, status, reason, from, extra) {
356
+ const targets = this.#nodesOf(hash).filter((n) => !from || from.includes(n.data.get('status')));
357
+ if (!targets.length && !extra) return false;
358
+ await this.#host.silent(() => {
359
+ extra?.();
360
+ for (const node of targets) {
361
+ node.data.set('status', status);
362
+ if (reason) node.data.set('reason', reason);
363
+ else if (node.data.get('reason') !== undefined) node.data.delete('reason');
364
+ }
365
+ });
366
+ return targets.length > 0;
367
+ }
368
+
369
+ /** @param {string} hash @param {'pending' | 'error'} state @param {number} attempts */
370
+ async #remember(hash, state, attempts) {
371
+ const entry = { hash, attempts, state, updatedAt: Date.now() };
372
+ this.#entries.set(hash, entry);
373
+ try { await this.outbox.put(entry); } catch (error) { this.#host.nabu.warn(`files: outbox write failed: ${error}`); }
374
+ }
375
+
376
+ /** @param {string} hash */
377
+ async #forget(hash) {
378
+ this.#entries.delete(hash);
379
+ try { await this.outbox.delete(hash); } catch (error) { this.#host.nabu.warn(`files: outbox write failed: ${error}`); }
380
+ }
381
+
382
+ // ── Jobs ─────────────────────────────────────────────────────────────────────────────────────
383
+
384
+ /**
385
+ * Start (or join) the upload of a file already in the local store. Returns at once; the job promise resolves `true` on success.
386
+ * @param {string} hash @param {boolean} referenced whether a live block references the file
387
+ * @returns {Job}
388
+ */
389
+ #startJob(hash, referenced) {
390
+ const existing = this.#jobs.get(hash);
391
+ if (existing) return existing;
392
+ /** @type {Job} */
393
+ const job = { hash, controller: new AbortController(), cause: null, referenced, promise: /** @type {any} */ (null) };
394
+ this.#jobs.set(hash, job);
395
+ this.#progress.set(hash, 0);
396
+ job.promise = this.#run(job);
397
+ return job;
398
+ }
399
+
400
+ /**
401
+ * Send a file that is already in the local store to the host, now (`Files#persist`). No-op without a host or when it is
402
+ * already hosted. @param {string} hash @returns {Promise<boolean>}
403
+ */
404
+ upload(hash) {
405
+ if (!this.#hook || this.hostedUrl(hash)) return Promise.resolve(Boolean(this.hostedUrl(hash)));
406
+ return this.#startJob(hash, false).promise;
407
+ }
408
+
409
+ /** @param {Job} job @returns {Promise<boolean>} */
410
+ async #run(job) {
411
+ const { hash, controller } = job;
412
+ const { signal } = controller;
413
+ const attempts = (this.#entries.get(hash)?.attempts ?? 0) + 1;
414
+ let rearm = false;
415
+ if (this.#autoSet.has(hash)) this.#attempts.set(hash, (this.#attempts.get(hash) ?? 0) + 1);
416
+ try {
417
+ await this.#remember(hash, 'pending', attempts);
418
+ const blob = await this.#host.store.get(hash);
419
+ if (!blob) throw new Error('the local copy of the file is gone');
420
+ const meta = /** @type {any} */ (this.#host.index.get(hash)) ?? (await this.#host.store.stat?.(hash)) ?? {};
421
+ const file = new File([blob], meta.name || '', { type: meta.mime || blob.type || 'application/octet-stream' });
422
+ /** @type {{ ref: string } | void} */
423
+ let result = undefined;
424
+ const hook = this.#hook;
425
+ if (!hook) throw new Error('no host configured');
426
+ if (!signal.aborted) {
427
+ result = await hook(file, {
428
+ signal,
429
+ onProgress: (p) => {
430
+ if (this.#jobs.get(hash) !== job || typeof p !== 'number' || !Number.isFinite(p)) return;
431
+ this.#progress.set(hash, Math.min(1, Math.max(0, p)));
432
+ },
433
+ });
434
+ }
435
+ // 'released': the block is gone but the host has the file: keep that knowledge (an undo shows it ready at once)
436
+ if (signal.aborted && job.cause !== 'released') throw new DOMException('aborted', 'AbortError');
437
+ if (signal.aborted && !result) throw new DOMException('aborted', 'AbortError');
438
+ const ref = result && typeof result.ref === 'string' && result.ref ? result.ref : null;
439
+ await this.#host.silent(() => {
440
+ if (ref) this.#host.index.set(hash, { ...meta, mime: meta.mime ?? file.type, name: meta.name ?? '', size: meta.size ?? blob.size, url: ref });
441
+ for (const node of this.#nodesOf(hash)) {
442
+ if (node.data.get('status') !== 'pending' && node.data.get('status') !== 'error') continue;
443
+ node.data.set('status', 'ready');
444
+ if (node.data.get('reason') !== undefined) node.data.delete('reason');
445
+ }
446
+ });
447
+ this.#host.forgetMissing();
448
+ await this.#forget(hash);
449
+ this.#autoSet.delete(hash);
450
+ this.#attempts.delete(hash);
451
+ this.#parked.delete(hash);
452
+ return true;
453
+ } catch (error) {
454
+ if (signal.aborted) {
455
+ if (job.cause === 'cancel') {
456
+ await this.#mark(hash, 'error', reasonOf('cancelled'), ['pending']);
457
+ await this.#remember(hash, 'error', attempts);
458
+ }
459
+ // 'released': nothing changes; the outbox keeps the entry, an undo restarts the upload
460
+ return false;
461
+ }
462
+ const detail = error instanceof Error && error.message ? error.message : String(error);
463
+ this.#host.nabu.warn(`files: upload of ${hash} failed: ${detail}`);
464
+ await this.#mark(hash, 'error', reasonOf('upload-failed', `The upload failed: ${detail}`.slice(0, 300)), ['pending']);
465
+ await this.#remember(hash, 'error', attempts);
466
+ rearm = true;
467
+ return false;
468
+ } finally {
469
+ if (this.#jobs.get(hash) === job) this.#jobs.delete(hash);
470
+ this.#progress.delete(hash);
471
+ this.schedule();
472
+ if (rearm) this.#arm(hash); // (after the job left the table: a failed upload of a file retried on open is tried again, later)
473
+ }
474
+ }
475
+
476
+ // ── Controls ─────────────────────────────────────────────────────────────────────────────────
477
+
478
+ /**
479
+ * Run the upload of a file again from its local copy (the blocks that were `error` become `pending`).
480
+ * @param {string} hash @returns {Promise<boolean>} `true` when the file ended up at the host
481
+ */
482
+ async retry(hash) {
483
+ const running = this.#jobs.get(hash);
484
+ if (running) return running.promise;
485
+ if (!this.#hook) return false;
486
+ if (this.hostedUrl(hash)) { await this.#mark(hash, 'ready', null, ['pending', 'error']); return true; }
487
+ if (!(await this.#host.store.has(hash).catch(() => false))) return false;
488
+ await this.#mark(hash, 'pending', null, ['error']);
489
+ return this.#startJob(hash, this.#nodesOf(hash).length > 0).promise;
490
+ }
491
+
492
+ /**
493
+ * Abort the running upload of a file (its `signal` fires). The blocks become `error` with the reason `cancelled`; the
494
+ * local copy stays, {@link Uploads#retry} sends it again.
495
+ * @param {string} hash @returns {boolean} whether an upload was running
496
+ */
497
+ cancel(hash) {
498
+ const job = this.#jobs.get(hash);
499
+ if (!job || job.controller.signal.aborted) return false;
500
+ job.cause = 'cancel';
501
+ job.controller.abort();
502
+ return true;
503
+ }
504
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,68 @@
1
- export * from "./blocks";
2
- export * from "./utils";
3
- export * from "./behaviors";
4
- export * from "./presets";
5
- export * from "./paste";
6
- export * from "./overlays/context";
7
- export * from "./ui";
8
- export * from "./files";
9
- export { RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, RichText } from "./behaviors/text";
1
+ export { Nabu } from "./blocks/nabu.svelte.js";
2
+ export { default as NabuEditor } from "./blocks/Nabu.svelte";
3
+ export { BlockExtension } from "./blocks/block.extension.js";
4
+ export { ParagraphExtension } from "./blocks/paragraph/index.js";
5
+ export { HeadingExtension } from "./blocks/heading/index.js";
6
+ export { BlockquoteExtension } from "./blocks/blockquote/index.js";
7
+ export { DividerExtension } from "./blocks/divider/index.js";
8
+ export { CodeExtension } from "./blocks/code/index.js";
9
+ export { CalloutExtension } from "./blocks/callout/index.js";
10
+ export { ToggleExtension } from "./blocks/toggle/index.js";
11
+ export { VideoExtension } from "./blocks/video/index.js";
12
+ export { FileExtension } from "./blocks/file/index.js";
13
+ export { insertMediaFromFile } from "./blocks/media/index.js";
14
+ export { sanitizeUrl } from "./utils/html.js";
15
+ export { formatChord } from "./utils/keys.js";
16
+ /**
17
+ * The options of an editor: `new Nabu(init)`, the factories and `createPersistedEditor`.
18
+ */
19
+ export type NabuInit = import("./blocks/nabu.svelte.js").NabuInit;
20
+ /**
21
+ * The options of the editor factories (`createEditor` and the preset factories): every `NabuInit` option plus the `preset` to start from.
22
+ */
23
+ export type EditorOptions = import("./presets.js").EditorOptions;
24
+ /**
25
+ * The `files` option: uploads, limits, embedding.
26
+ */
27
+ export type FilesConfig = import("./files/files.svelte.js").FilesConfig;
28
+ export type EmbeddedAsset = import("./files/files.svelte.js").EmbeddedAsset;
29
+ export type PlaceholdersOption = import("./utils/placeholders.js").PlaceholdersOption;
30
+ export type PlaceholdersConfig = import("./utils/placeholders.js").PlaceholdersConfig;
31
+ export type PlaceholderText = import("./utils/placeholders.js").PlaceholderText;
32
+ /**
33
+ * A command declared by an extension (`commands`).
34
+ */
35
+ export type CommandDef = import("./utils/commands.js").CommandDef;
36
+ export type CommandContext = import("./utils/commands.js").CommandContext;
37
+ export type CommandConfirm = import("./utils/commands.js").CommandConfirm;
38
+ export type CommandInfo = import("./utils/commands.js").CommandInfo;
39
+ export type CommandConfirmOptions = import("./utils/command-confirm.svelte.js").CommandConfirmOptions;
40
+ export type ConfirmMessages = import("./utils/command-confirm.svelte.js").ConfirmMessages;
41
+ /**
42
+ * Declaration of a region type.
43
+ */
44
+ export type RegionTypeInit = import("./blocks/region/types.js").RegionTypeInit;
45
+ export type RegionTypeDef = import("./blocks/region/types.js").RegionTypeDef;
46
+ export type RegionsConfig = import("./blocks/region/types.js").RegionsConfig;
47
+ export type FieldKind = import("./blocks/region/types.js").FieldKind;
48
+ export type FieldSpec = import("./blocks/region/types.js").FieldSpec;
49
+ export type Numbering = import("./blocks/region/types.js").Numbering;
50
+ export type RegionMessages = import("./blocks/region/messages.js").RegionMessages;
51
+ export type RegionMessageParams = import("./blocks/region/messages.js").RegionMessageParams;
52
+ export type RegionNameParams = import("./blocks/region/messages.js").RegionNameParams;
53
+ export type RegionTypeParams = import("./blocks/region/messages.js").RegionTypeParams;
54
+ export type HistoryConfig = import("./persistence/history.js").HistoryConfig;
55
+ export type CompactOptions = import("./persistence/history.js").CompactOptions;
56
+ export type CompactResult = import("./persistence/compact.js").CompactResult;
57
+ export type Recovery = import("./persistence/recovery.js").Recovery;
58
+ export type Chord = import("./utils/keys.js").Chord;
59
+ export type Platform = import("./utils/keys.js").Platform;
60
+ export { createEditor, createMinimalEditor, createTextEditor, createDocumentEditor, createFullEditor, createPersistedEditor, MinimalPreset, TextPreset, DocumentPreset, FullPreset } from "./presets.js";
61
+ export { ListExtension, ListItemExtension, Todos } from "./blocks/list/index.js";
62
+ export { ImageExtension, insertImageFromFile } from "./blocks/image/index.js";
63
+ export { DialogueExtension, createDialogueExtension } from "./blocks/dialogue/index.js";
64
+ export { RegionsExtension, createRegionsExtension, DEFAULT_REGION_TYPES, DEFAULT_REGION_MESSAGES, Regions, Region } from "./blocks/region/index.js";
65
+ export { RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, deltaToMarkdown, deltaToHtml } from "./behaviors/text/index.js";
66
+ export { PlainTextPasteExtension, NabuPasteExtension, HtmlPasteExtension, MarkdownPasteExtension } from "./paste/index.js";
67
+ export { Files, FileRejectedError, MemoryOutbox, REASON_CODES } from "./files/index.js";
68
+ export { JSON_FORMAT_VERSION, CLIPBOARD_FORMAT_VERSION, isSupportedJsonVersion } from "./utils/extensions.js";