@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,363 @@
1
+ export { FileRejectedError };
2
+ /** Origin of the commits that finish a paste in the background (ref swap): not undoable. See Nabu's UndoManager. */
3
+ export const SILENT_ORIGIN: "nabu:silent:files";
4
+ /** Largest asset (bytes) turned into a `data:` URL in the `text/html` of a copy. */
5
+ export const HTML_INLINE_LIMIT: number;
6
+ /**
7
+ * An asset as carried by `application/x-nabu+json` (`assets: { [id]: EmbeddedAsset }`), `id` being the part of the ref
8
+ * after `nabu-asset:` (`sha256-<hex>`, or a beta `<uuid>`). An entry with `omitted: true` and no `data` says "this file
9
+ * exists but its bytes are NOT in this copy" (too large, or not loaded yet): the receiver shows the block as `missing`
10
+ * with the reason `not-embedded` (unless its own store already has the file).
11
+ * @typedef {Object} EmbeddedAsset
12
+ * @property {string} mime
13
+ * @property {string} name
14
+ * @property {number} size byte length
15
+ * @property {string} [data] base64 (absent when `omitted`)
16
+ * @property {boolean} [omitted]
17
+ */
18
+ /**
19
+ * @typedef {Object} FilesConfig
20
+ * @property {AssetStore} [store] Where the BYTES of the files live (ADR 014). Default: a `MemoryAssetStore`
21
+ * (`createPersistedEditor`: an `IndexedDBAssetStore` shared by all the documents of the origin). The document itself only
22
+ * holds `nabu-asset:sha256-<hex>` references and a metadata index (`assetIndex`).
23
+ * @property {(file: File, ctx: { signal?: AbortSignal, onProgress?: (p: number) => void }) => Promise<{ ref: string } | void>} [onBeforePersist]
24
+ * Host storage (ADR 014 §3.4). The file is always written to the local store first and the block keeps its
25
+ * `nabu-asset:sha256-…` ref FOREVER; the upload then runs in the background (the block is `pending`, `block.progress` follows
26
+ * `onProgress(0..1)`). Return `{ ref }` (where the host keeps the file): it is recorded as `assetIndex[hash].url` and the
27
+ * block becomes `ready`. Throw to fail (`error`, the local copy is kept, `block.retry()` runs it again). `signal` fires when
28
+ * the upload is cancelled (`block.cancel()`) or when the last block that shows the file is deleted — honour it. The upload
29
+ * is retried from the local copy after a reload (it may therefore run more than once for one file: make it idempotent).
30
+ * @property {false | import('./uploads.svelte.js').AutoRetryConfig} [autoRetry] Retry on open (P-97), only meaningful with a host and a persisted editor:
31
+ * the uploads the outbox lists when the document is opened (interrupted, or failed earlier) are sent again by themselves, in the
32
+ * background, with a growing delay (`initialDelay` 2 s, doubling, `maxDelay` 60 s, `maxAttempts` 8 per session; the browser's `online`
33
+ * event grants a fresh series). A cancelled upload is never retried; failures of the current session are left to `block.retry()`.
34
+ * `false` turns it off.
35
+ * @property {number} [maxFileSize] Largest file (bytes) accepted; default none. A bigger file is REFUSED: the block that would
36
+ * have shown it is created with `status: 'rejected'`, no ref, and a readable `reason` (`too-large`).
37
+ * @property {Outbox} [outbox] Where the uploads still to do are listed (ADR 014 §3.4), scoped to this document. Default: in
38
+ * memory (`createPersistedEditor`: an `IndexedDBOutbox`, next to the asset store).
39
+ * @property {(ref: string) => void | Promise<void>} [onAssetReleased] Host mode, called with the host `url` (the `ref` your
40
+ * `onBeforePersist` returned) of a file that THIS document no longer references in any version it keeps: after a compaction
41
+ * (`history: { mode: 'compact' }` / `nabu.compact()`) released it, or when `clearPersistence()` deleted the document. Nabu NEVER
42
+ * deletes anything at the host: you decide (another document may still use the same host file). Awaited; an error is swallowed
43
+ * and reported with `nabu.warn`. Never called in the default `history: 'full'` mode (nothing is released).
44
+ * @property {number} [releaseGraceMs] Default 10 minutes. A release (compaction, `clearPersistence()`) never deletes from the shared store
45
+ * a file whose record is newer than this, nor one whose age is unknown: another tab may have just added it without having saved
46
+ * its references yet. Such a file is skipped and reconsidered at the next compaction / clear. `0` disables the grace period.
47
+ * @property {(ref: string) => string} [resolve] Turn a stored ref into a display URL.
48
+ * @property {number} [maxInlineSize] Byte threshold for embedding files in a COPY / export (`application/x-nabu+json`,
49
+ * `serialize('json')`): above it (total, or for one file) the bytes are not embedded. Default 2MB.
50
+ * @property {boolean} [importRemote] Opt-in, default `false`. When `true`, a remote image / media (an `http(s)` URL) pasted
51
+ * from the HTML of a web page is fetched and stored in the local store (and sent to `onBeforePersist`, if any) instead of
52
+ * being hot-linked: the block shows the original URL meanwhile (`pending`) and gets its `nabu-asset:` ref when done. A fetch
53
+ * that fails (network, CORS, HTTP error) or a file over `maxFileSize` keeps the original URL.
54
+ */
55
+ /**
56
+ * @typedef {Object} EmbeddedBytes
57
+ * @property {Uint8Array} bytes @property {string} type @property {string} name
58
+ */
59
+ /**
60
+ * Document-level file/asset manager (ADR 014). The bytes of a file live in an {@link AssetStore}, the document only holds
61
+ * `nabu-asset:sha256-<hex>` references and a small `assetIndex` Loro map (`hash → { mime, name, size, url? }`).
62
+ * Lazy: Files.get(nabu).
63
+ */
64
+ export class Files {
65
+ /** @param {import('../blocks/nabu.svelte.js').Nabu} nabu @returns {Files} */
66
+ static get(nabu: import("../blocks/nabu.svelte.js").Nabu): Files;
67
+ /** @param {import('../blocks/nabu.svelte.js').Nabu} nabu */
68
+ constructor(nabu: import("../blocks/nabu.svelte.js").Nabu);
69
+ /** Milliseconds an unused objectURL is kept before being revoked (a block that moves unmounts and remounts at once). */
70
+ revokeGraceMs: number;
71
+ /** The local store of the bytes. @type {AssetStore} */
72
+ store: AssetStore;
73
+ /** Beta format: bytes inside the document. Read-only legacy, emptied by the migration. */
74
+ assets: import("loro-crdt").LoroMap<Record<string, unknown>>;
75
+ /** ADR 014 §3.2: `hash → { mime, name, size, url? }`, metadata only (never bytes). */
76
+ index: import("loro-crdt").LoroMap<Record<string, unknown>>;
77
+ /** @returns {FilesConfig} */
78
+ get config(): FilesConfig;
79
+ get maxInlineSize(): number;
80
+ /** `files.maxFileSize`, or `null` (no limit). @returns {number | null} */
81
+ get maxFileSize(): number | null;
82
+ /** Whether a host is configured (`files.onBeforePersist`): files are then uploaded in the background. @returns {boolean} */
83
+ get hosted(): boolean;
84
+ /**
85
+ * Check a file size against `files.maxFileSize`.
86
+ * @param {number} size bytes @returns {FileReason | null} the reason it is refused, `null` when accepted
87
+ */
88
+ checkSize(size: number): FileReason | null;
89
+ /**
90
+ * Resolves when the background storage work started by a paste / import / migration is done (bytes verified and written
91
+ * to the store, index completed, missing files flagged). Uploads to a host (`onBeforePersist`) are NOT waited for.
92
+ * @returns {Promise<void>}
93
+ */
94
+ whenIdle(): Promise<void>;
95
+ /** Ids (`sha256-<hex>`) of every file the document knows (its `assetIndex`): what a persisted document references. @returns {string[]} */
96
+ indexedHashes(): string[];
97
+ /**
98
+ * The host location (`assetIndex[hash].url`) of each of `hashes` that has one (lot 3: what `onAssetReleased` receives).
99
+ * @param {Iterable<string>} hashes @returns {Map<string, string>}
100
+ */
101
+ hostUrls(hashes: Iterable<string>): Map<string, string>;
102
+ /**
103
+ * How many uploads are still to do or running (the outbox of the document, plus any running job). A compaction refuses to run
104
+ * while this is not 0 (ADR 014 §3.6): the local copy is the only copy of such a file. Waits for the resume pass first.
105
+ * @returns {Promise<number>}
106
+ */
107
+ pendingUploads(): Promise<number>;
108
+ /**
109
+ * Remove the index entries of files a compaction released (silent commit, not an undo step). The entries stay readable in the
110
+ * history that was archived / retained; only the live index forgets them.
111
+ * @param {Iterable<string>} hashes @returns {Promise<void>}
112
+ */
113
+ releaseIndex(hashes: Iterable<string>): Promise<void>;
114
+ /**
115
+ * Hash a File and write it to the local store (deduplicated: the same bytes give the same id and one entry), then
116
+ * make sure the document's `assetIndex` knows it. This is step 1 of the lifecycle (ADR 014 §3.4).
117
+ * Throws {@link FileRejectedError} for a file over `files.maxFileSize`.
118
+ * @param {File} file
119
+ * @returns {Promise<{ id: string, ref: string, meta: AssetMeta }>}
120
+ */
121
+ ingest(file: File): Promise<{
122
+ id: string;
123
+ ref: string;
124
+ meta: AssetMeta;
125
+ }>;
126
+ /**
127
+ * Store a File and hand it to the host: {@link Files#ingest}, then (with `onBeforePersist`) the upload starts in the
128
+ * background. Resolves with the `nabu-asset:sha256-…` ref as soon as the local copy is written — it never changes, the
129
+ * host location ends up in `assetIndex[hash].url`. Blocks do not call this: they use `ingest` and become `pending`, the
130
+ * upload queue does the rest. For programmatic use.
131
+ * @param {File} file
132
+ * @returns {Promise<string>}
133
+ */
134
+ persist(file: File): Promise<string>;
135
+ /**
136
+ * Progress (0–1) of the running upload of the file `ref` designates; `null` when none runs. Reactive.
137
+ * @param {string} ref @returns {number | null}
138
+ */
139
+ progress(ref: string): number | null;
140
+ /** Whether the upload of the file `ref` designates is running. Reactive. @param {string} ref @returns {boolean} */
141
+ isUploading(ref: string): boolean;
142
+ /**
143
+ * Run the upload of the file `ref` designates again, from its local copy. Resolves `true` when the file ended up at the host.
144
+ * @param {string} ref @returns {Promise<boolean>}
145
+ */
146
+ retry(ref: string): Promise<boolean>;
147
+ /**
148
+ * Abort the running upload of the file `ref` designates (the host's `signal` fires). The blocks showing it become `error` with
149
+ * the reason `cancelled`; the local copy stays. Uploads are per file: every block with the same ref is affected.
150
+ * @param {string} ref @returns {boolean} whether an upload was running
151
+ */
152
+ cancel(ref: string): boolean;
153
+ /**
154
+ * The status a block showing the file `id` should start with: `pending` when a host still has to get it, else `ready`.
155
+ * @param {string} id @returns {'pending' | 'ready'}
156
+ */
157
+ initialStatus(id: string): "pending" | "ready";
158
+ /** Stop the automatic upload retries (timers, `online` listener): the persistence of the editor was disposed. */
159
+ dispose(): void;
160
+ /** Resolves when the first pass over the document (resuming the uploads of a reopened document) is done. @returns {Promise<void>} */
161
+ whenResumed(): Promise<void>;
162
+ /** Run an upload pass now (tests, or after changing the host config at runtime). @returns {Promise<void>} */
163
+ reconcileUploads(): Promise<void>;
164
+ /**
165
+ * Resolve a ref to a displayable URL. `nabu-asset:` refs → objectURL made from the local store (loaded in the
166
+ * background: `''` until it is there, reactive), else the `url` of the document index (through `config.resolve`);
167
+ * external URLs → config.resolve or identity.
168
+ * @param {string} ref @returns {string}
169
+ */
170
+ resolve(ref: string): string;
171
+ /**
172
+ * What displaying `ref` would give right now: `loading` (being read from the store), `missing` (neither the local store
173
+ * nor the document index has it) or `ready`. Reactive. Refs that are not `nabu-asset:` are always `ready`.
174
+ * @param {string} ref @returns {'ready' | 'loading' | 'missing'}
175
+ */
176
+ state(ref: string): "ready" | "loading" | "missing";
177
+ /**
178
+ * A block displaying `ref` is mounted: its objectURL stays alive until the returned function is called (the media
179
+ * components call this from an effect). An objectURL no mounted block uses any more is revoked after a short grace period.
180
+ * @param {string} ref @returns {() => void}
181
+ */
182
+ hold(ref: string): () => void;
183
+ /**
184
+ * Read the bytes of a stored file into the embed cache, so that a later copy / export (synchronous) can carry them.
185
+ * Cheap no-op for big files, which are never embedded.
186
+ * @param {string} ref
187
+ */
188
+ warm(ref: string): void;
189
+ /**
190
+ * The bytes behind a `nabu-asset:` ref (or bare id), when they are at hand SYNCHRONOUSLY (a copy / export cannot wait):
191
+ * the files of at most `maxInlineSize` that were added or displayed in this session. `null` otherwise.
192
+ * @param {string} ref @returns {{ id: string, data: Uint8Array, type: string, name: string } | null}
193
+ */
194
+ getAsset(ref: string): {
195
+ id: string;
196
+ data: Uint8Array;
197
+ type: string;
198
+ name: string;
199
+ } | null;
200
+ /**
201
+ * COPY: the bytes of every `nabu-asset:` media of `blocks`, for the `assets` map of the fragment (keyed by hash id, ADR 014
202
+ * §3.8). A file whose bytes cannot go along (total over `maxInlineSize`, or not in the in-memory cache — evicted, or not
203
+ * read yet) is NOT silently dropped: it gets an entry `{ mime, name, size, omitted: true }` so the receiver shows the block
204
+ * as `missing` with the reason `not-embedded` (unless its own store has the file), and `nabu.warn` says so. The blocks keep
205
+ * their ref either way.
206
+ * @param {any[]} blocks PasteBlocks about to be copied
207
+ * @returns {Record<string, EmbeddedAsset> | undefined} `undefined` when there is nothing to carry
208
+ */
209
+ embedAssets(blocks: any[]): Record<string, EmbeddedAsset> | undefined;
210
+ /**
211
+ * COPY, `text/html` and `text/plain`: a copy of `blocks` where no `nabu-asset:` ref is left (it means nothing outside
212
+ * Nabu). With `inline` (HTML), a media of at most {@link HTML_INLINE_LIMIT} bytes whose type `sanitizeUrl(kind:'media')`
213
+ * accepts (image / video) becomes a `data:` URL; any other asset gets an empty ref, which the block serializers render
214
+ * as a label (alt / file name) rather than a broken `src`.
215
+ * @param {any[]} blocks @param {{ inline?: boolean }} [options]
216
+ * @returns {any[]}
217
+ */
218
+ externalize(blocks: any[], { inline }?: {
219
+ inline?: boolean;
220
+ }): any[];
221
+ /**
222
+ * PASTE / import: make every `nabu-asset:` media of `blocks` valid in THIS document (ADR 014 §3.4, §3.8). Synchronous:
223
+ * the refs are content hashes, so a block keeps its ref and the storage happens in the background (see {@link Files#whenIdle}).
224
+ * - a hash ref whose bytes the fragment carries: they are verified (the hash must match, else the file is treated as
225
+ * missing — reason `corrupt` — and `nabu.warn` says so) and written to the store, unless it already has them; over
226
+ * `files.maxFileSize` the block becomes `rejected` (no ref, a readable reason) instead;
227
+ * - a hash ref the document already indexes: reused as is;
228
+ * - a hash ref with no bytes and no index entry: kept, then flagged `status: 'missing'` unless the local store has the file
229
+ * (reason `not-embedded` when the copy said it left the bytes out, else `unavailable`);
230
+ * - a beta `nabu-asset:<uuid>` ref (older exports / clipboards) with its bytes: re-created through {@link Files#ingest}
231
+ * and given its hash ref when done (the block is `pending` with a local preview meanwhile); without bytes: `missing`;
232
+ * - with a host hook, a file the host does not have yet makes the block `pending`: the upload starts in the background (the
233
+ * block keeps its hash ref; the host location lands in `assetIndex[hash].url`).
234
+ * No commit; the caller commits. Never throws.
235
+ * @param {any[]} blocks PasteBlocks (already sanitized)
236
+ * @param {Record<string, EmbeddedAsset> | null | undefined} embedded the `assets` map of the fragment
237
+ * @returns {any[]}
238
+ */
239
+ adoptAssets(blocks: any[], embedded: Record<string, EmbeddedAsset> | null | undefined): any[];
240
+ /**
241
+ * PASTE FILES: read a pasted File and prepare it for {@link Files#adoptAssets}. The file is hashed and written to the local
242
+ * store right here (no base64 round trip), whatever the mode: the fragment only carries its hash ref, as one undo step with
243
+ * the blocks. `props` is a patch for the block: `status: 'pending'` when a host still has to get the file (the upload starts
244
+ * once the block is in the document), or `status: 'rejected'` + `reason` (and an empty ref) when it is over `files.maxFileSize`.
245
+ * @param {File} file
246
+ * @returns {Promise<{ id: string, ref: string, asset: EmbeddedAsset | null, props?: Record<string, any> }>}
247
+ */
248
+ stage(file: File): Promise<{
249
+ id: string;
250
+ ref: string;
251
+ asset: EmbeddedAsset | null;
252
+ props?: Record<string, any>;
253
+ }>;
254
+ /**
255
+ * PASTE (HTML from outside): with `config.importRemote`, every block of `blocks` whose `ref` is a remote `http(s)` URL is
256
+ * fetched and stored in the local store ({@link Files#ingest}). The block shows the original URL at once, as `pending`, and gets its
257
+ * `nabu-asset:` ref in the background (a silent commit, not an undo step; still `pending` while a host uploads it); when the
258
+ * fetch or the storage fails (or the file is over `maxFileSize`) it keeps the original URL. Without the option, `blocks` come back untouched. No commit; never throws.
259
+ * @param {any[]} blocks PasteBlocks (already sanitized)
260
+ * @returns {any[]}
261
+ */
262
+ importRemote(blocks: any[]): any[];
263
+ #private;
264
+ }
265
+ /**
266
+ * An asset as carried by `application/x-nabu+json` (`assets: { [id]: EmbeddedAsset }`), `id` being the part of the ref
267
+ * after `nabu-asset:` (`sha256-<hex>`, or a beta `<uuid>`). An entry with `omitted: true` and no `data` says "this file
268
+ * exists but its bytes are NOT in this copy" (too large, or not loaded yet): the receiver shows the block as `missing`
269
+ * with the reason `not-embedded` (unless its own store already has the file).
270
+ */
271
+ export type EmbeddedAsset = {
272
+ mime: string;
273
+ name: string;
274
+ /**
275
+ * byte length
276
+ */
277
+ size: number;
278
+ /**
279
+ * base64 (absent when `omitted`)
280
+ */
281
+ data?: string | undefined;
282
+ omitted?: boolean | undefined;
283
+ };
284
+ export type FilesConfig = {
285
+ /**
286
+ * Where the BYTES of the files live (ADR 014). Default: a `MemoryAssetStore`
287
+ * (`createPersistedEditor`: an `IndexedDBAssetStore` shared by all the documents of the origin). The document itself only
288
+ * holds `nabu-asset:sha256-<hex>` references and a metadata index (`assetIndex`).
289
+ */
290
+ store?: AssetStore | undefined;
291
+ /**
292
+ * Host storage (ADR 014 §3.4). The file is always written to the local store first and the block keeps its
293
+ * `nabu-asset:sha256-…` ref FOREVER; the upload then runs in the background (the block is `pending`, `block.progress` follows
294
+ * `onProgress(0..1)`). Return `{ ref }` (where the host keeps the file): it is recorded as `assetIndex[hash].url` and the
295
+ * block becomes `ready`. Throw to fail (`error`, the local copy is kept, `block.retry()` runs it again). `signal` fires when
296
+ * the upload is cancelled (`block.cancel()`) or when the last block that shows the file is deleted — honour it. The upload
297
+ * is retried from the local copy after a reload (it may therefore run more than once for one file: make it idempotent).
298
+ */
299
+ onBeforePersist?: ((file: File, ctx: {
300
+ signal?: AbortSignal;
301
+ onProgress?: (p: number) => void;
302
+ }) => Promise<{
303
+ ref: string;
304
+ } | void>) | undefined;
305
+ /**
306
+ * Retry on open (P-97), only meaningful with a host and a persisted editor:
307
+ * the uploads the outbox lists when the document is opened (interrupted, or failed earlier) are sent again by themselves, in the
308
+ * background, with a growing delay (`initialDelay` 2 s, doubling, `maxDelay` 60 s, `maxAttempts` 8 per session; the browser's `online`
309
+ * event grants a fresh series). A cancelled upload is never retried; failures of the current session are left to `block.retry()`.
310
+ * `false` turns it off.
311
+ */
312
+ autoRetry?: false | import("./uploads.svelte.js").AutoRetryConfig | undefined;
313
+ /**
314
+ * Largest file (bytes) accepted; default none. A bigger file is REFUSED: the block that would
315
+ * have shown it is created with `status: 'rejected'`, no ref, and a readable `reason` (`too-large`).
316
+ */
317
+ maxFileSize?: number | undefined;
318
+ /**
319
+ * Where the uploads still to do are listed (ADR 014 §3.4), scoped to this document. Default: in
320
+ * memory (`createPersistedEditor`: an `IndexedDBOutbox`, next to the asset store).
321
+ */
322
+ outbox?: Outbox | undefined;
323
+ /**
324
+ * Host mode, called with the host `url` (the `ref` your
325
+ * `onBeforePersist` returned) of a file that THIS document no longer references in any version it keeps: after a compaction
326
+ * (`history: { mode: 'compact' }` / `nabu.compact()`) released it, or when `clearPersistence()` deleted the document. Nabu NEVER
327
+ * deletes anything at the host: you decide (another document may still use the same host file). Awaited; an error is swallowed
328
+ * and reported with `nabu.warn`. Never called in the default `history: 'full'` mode (nothing is released).
329
+ */
330
+ onAssetReleased?: ((ref: string) => void | Promise<void>) | undefined;
331
+ /**
332
+ * Default 10 minutes. A release (compaction, `clearPersistence()`) never deletes from the shared store
333
+ * a file whose record is newer than this, nor one whose age is unknown: another tab may have just added it without having saved
334
+ * its references yet. Such a file is skipped and reconsidered at the next compaction / clear. `0` disables the grace period.
335
+ */
336
+ releaseGraceMs?: number | undefined;
337
+ /**
338
+ * Turn a stored ref into a display URL.
339
+ */
340
+ resolve?: ((ref: string) => string) | undefined;
341
+ /**
342
+ * Byte threshold for embedding files in a COPY / export (`application/x-nabu+json`,
343
+ * `serialize('json')`): above it (total, or for one file) the bytes are not embedded. Default 2MB.
344
+ */
345
+ maxInlineSize?: number | undefined;
346
+ /**
347
+ * Opt-in, default `false`. When `true`, a remote image / media (an `http(s)` URL) pasted
348
+ * from the HTML of a web page is fetched and stored in the local store (and sent to `onBeforePersist`, if any) instead of
349
+ * being hot-linked: the block shows the original URL meanwhile (`pending`) and gets its `nabu-asset:` ref when done. A fetch
350
+ * that fails (network, CORS, HTTP error) or a file over `maxFileSize` keeps the original URL.
351
+ */
352
+ importRemote?: boolean | undefined;
353
+ };
354
+ export type EmbeddedBytes = {
355
+ bytes: Uint8Array;
356
+ type: string;
357
+ name: string;
358
+ };
359
+ import { FileRejectedError } from './status.js';
360
+ import type { AssetStore } from './store.js';
361
+ import type { FileReason } from './status.js';
362
+ import type { AssetMeta } from './store.js';
363
+ import type { Outbox } from './outbox.js';