@aionbuilders/nabu 0.1.0-beta.0 → 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.
- package/CHANGELOG.md +523 -0
- package/LICENSE +21 -0
- package/README.md +72 -341
- package/dist/behaviors/text/RichText.svelte +24 -4
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +3 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +35 -10
- package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
- package/dist/behaviors/text/markdown-syntax.js +81 -0
- package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
- package/dist/behaviors/text/rich-text.extension.js +95 -38
- package/dist/behaviors/text/text.behavior.svelte.d.ts +199 -48
- package/dist/behaviors/text/text.behavior.svelte.js +549 -83
- package/dist/behaviors/text/typography.extension.d.ts +2 -1
- package/dist/behaviors/text/typography.extension.js +3 -2
- package/dist/blocks/BlockList.svelte +48 -0
- package/dist/blocks/BlockList.svelte.d.ts +17 -0
- package/dist/blocks/Nabu.svelte +169 -25
- package/dist/blocks/Nabu.svelte.d.ts +13 -0
- package/dist/blocks/block.extension.d.ts +3 -0
- package/dist/blocks/block.extension.js +4 -7
- package/dist/blocks/block.svelte.d.ts +350 -86
- package/dist/blocks/block.svelte.js +370 -59
- package/dist/blocks/blockquote/Blockquote.svelte +1 -2
- package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -1
- package/dist/blocks/blockquote/blockquote.extension.js +14 -5
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +19 -11
- package/dist/blocks/blockquote/blockquote.svelte.js +58 -13
- package/dist/blocks/callout/Callout.svelte +6 -8
- package/dist/blocks/callout/callout.extension.d.ts +4 -1
- package/dist/blocks/callout/callout.extension.js +19 -3
- package/dist/blocks/callout/callout.svelte.d.ts +5 -3
- package/dist/blocks/callout/callout.svelte.js +11 -6
- package/dist/blocks/chunks.d.ts +49 -0
- package/dist/blocks/chunks.js +90 -0
- package/dist/blocks/code/Code.svelte +7 -8
- package/dist/blocks/code/code.extension.d.ts +4 -1
- package/dist/blocks/code/code.extension.js +22 -2
- package/dist/blocks/code/code.svelte.d.ts +9 -2
- package/dist/blocks/code/code.svelte.js +49 -25
- package/dist/blocks/container.utils.d.ts +85 -13
- package/dist/blocks/container.utils.js +338 -178
- package/dist/blocks/dialogue/Dialogue.svelte +8 -4
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +33 -2
- package/dist/blocks/dialogue/dialogue.svelte.js +58 -4
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
- package/dist/blocks/dialogue/index.d.ts +12 -1
- package/dist/blocks/dialogue/index.js +51 -35
- package/dist/blocks/divider/divider.extension.d.ts +23 -1
- package/dist/blocks/divider/divider.extension.js +85 -19
- package/dist/blocks/divider/divider.svelte.d.ts +7 -2
- package/dist/blocks/divider/divider.svelte.js +9 -4
- package/dist/blocks/file/File.svelte +13 -6
- package/dist/blocks/file/file.extension.d.ts +4 -1
- package/dist/blocks/file/file.extension.js +9 -1
- package/dist/blocks/file/file.svelte.d.ts +3 -3
- package/dist/blocks/file/file.svelte.js +20 -14
- package/dist/blocks/heading/Heading.svelte +1 -2
- package/dist/blocks/heading/heading.svelte.d.ts +23 -11
- package/dist/blocks/heading/heading.svelte.js +68 -13
- package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
- package/dist/blocks/heading/index.d.ts +2 -2
- package/dist/blocks/heading/index.js +33 -8
- package/dist/blocks/image/Image.svelte +5 -2
- package/dist/blocks/image/image.extension.d.ts +4 -1
- package/dist/blocks/image/image.extension.js +9 -1
- package/dist/blocks/image/image.svelte.d.ts +17 -6
- package/dist/blocks/image/image.svelte.js +33 -11
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +1 -1
- package/dist/blocks/list/List.svelte +1 -0
- package/dist/blocks/list/ListItem.svelte +1 -0
- package/dist/blocks/list/convert.d.ts +20 -0
- package/dist/blocks/list/convert.js +92 -0
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +49 -28
- package/dist/blocks/list/html-flat.d.ts +78 -0
- package/dist/blocks/list/html-flat.js +244 -0
- package/dist/blocks/list/indent.d.ts +86 -0
- package/dist/blocks/list/indent.js +205 -0
- package/dist/blocks/list/index.d.ts +6 -3
- package/dist/blocks/list/index.js +42 -31
- package/dist/blocks/list/list-item.svelte.d.ts +31 -17
- package/dist/blocks/list/list-item.svelte.js +99 -100
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -1
- package/dist/blocks/list/list.behavior.svelte.js +6 -1
- package/dist/blocks/list/list.svelte.d.ts +89 -18
- package/dist/blocks/list/list.svelte.js +129 -125
- package/dist/blocks/list/markdown.d.ts +149 -0
- package/dist/blocks/list/markdown.js +442 -0
- package/dist/blocks/list/normalize.d.ts +11 -0
- package/dist/blocks/list/normalize.js +396 -0
- package/dist/blocks/list/paste.d.ts +45 -0
- package/dist/blocks/list/paste.js +242 -0
- package/dist/blocks/list/step-back.d.ts +24 -0
- package/dist/blocks/list/step-back.js +87 -0
- package/dist/blocks/list/to-list.d.ts +7 -0
- package/dist/blocks/list/to-list.js +44 -0
- package/dist/blocks/list/todos-toggle.d.ts +20 -0
- package/dist/blocks/list/todos-toggle.js +48 -0
- package/dist/blocks/media/markdown.d.ts +12 -0
- package/dist/blocks/media/markdown.js +26 -0
- package/dist/blocks/media/media-block.svelte.d.ts +77 -2
- package/dist/blocks/media/media-block.svelte.js +124 -12
- package/dist/blocks/media/media.helpers.d.ts +6 -1
- package/dist/blocks/media/media.helpers.js +43 -6
- package/dist/blocks/megablock.svelte.d.ts +50 -19
- package/dist/blocks/megablock.svelte.js +114 -74
- package/dist/blocks/move.d.ts +23 -0
- package/dist/blocks/move.js +92 -0
- package/dist/blocks/nabu.svelte.d.ts +764 -71
- package/dist/blocks/nabu.svelte.js +1746 -189
- package/dist/blocks/paragraph/Paragraph.svelte +1 -2
- package/dist/blocks/paragraph/index.d.ts +2 -2
- package/dist/blocks/paragraph/index.js +35 -13
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +46 -14
- package/dist/blocks/paragraph/paragraph.svelte.js +77 -16
- package/dist/blocks/paragraph/table.html.d.ts +9 -0
- package/dist/blocks/paragraph/table.html.js +111 -0
- package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
- package/dist/blocks/paragraph/table.markdown.js +90 -0
- package/dist/blocks/region/Region.svelte +264 -0
- package/dist/blocks/region/Region.svelte.d.ts +11 -0
- package/dist/blocks/region/actions.d.ts +135 -0
- package/dist/blocks/region/actions.js +402 -0
- package/dist/blocks/region/close.d.ts +35 -0
- package/dist/blocks/region/close.js +130 -0
- package/dist/blocks/region/commands.d.ts +6 -0
- package/dist/blocks/region/commands.js +277 -0
- package/dist/blocks/region/create.d.ts +72 -0
- package/dist/blocks/region/create.js +208 -0
- package/dist/blocks/region/end-marker.d.ts +35 -0
- package/dist/blocks/region/end-marker.js +51 -0
- package/dist/blocks/region/facts.d.ts +69 -0
- package/dist/blocks/region/facts.js +152 -0
- package/dist/blocks/region/format.d.ts +91 -0
- package/dist/blocks/region/format.js +260 -0
- package/dist/blocks/region/index.d.ts +14 -0
- package/dist/blocks/region/index.js +14 -0
- package/dist/blocks/region/insert.d.ts +59 -0
- package/dist/blocks/region/insert.js +102 -0
- package/dist/blocks/region/messages.d.ts +254 -0
- package/dist/blocks/region/messages.js +131 -0
- package/dist/blocks/region/normalize.d.ts +7 -0
- package/dist/blocks/region/normalize.js +170 -0
- package/dist/blocks/region/region.extension.d.ts +58 -0
- package/dist/blocks/region/region.extension.js +119 -0
- package/dist/blocks/region/region.svelte.d.ts +221 -0
- package/dist/blocks/region/region.svelte.js +582 -0
- package/dist/blocks/region/regions.svelte.d.ts +141 -0
- package/dist/blocks/region/regions.svelte.js +276 -0
- package/dist/blocks/region/serialize.d.ts +57 -0
- package/dist/blocks/region/serialize.js +112 -0
- package/dist/blocks/region/types.d.ts +255 -0
- package/dist/blocks/region/types.js +204 -0
- package/dist/blocks/selection.svelte.d.ts +106 -8
- package/dist/blocks/selection.svelte.js +622 -74
- package/dist/blocks/subthread.d.ts +80 -0
- package/dist/blocks/subthread.js +167 -0
- package/dist/blocks/text-block.svelte.d.ts +34 -13
- package/dist/blocks/text-block.svelte.js +42 -8
- package/dist/blocks/toggle/Toggle.svelte +4 -15
- package/dist/blocks/toggle/markdown.d.ts +20 -0
- package/dist/blocks/toggle/markdown.js +112 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +4 -1
- package/dist/blocks/toggle/toggle.extension.js +6 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +54 -7
- package/dist/blocks/toggle/toggle.svelte.js +134 -34
- package/dist/blocks/undo-selection.d.ts +175 -0
- package/dist/blocks/undo-selection.js +360 -0
- package/dist/blocks/video/Video.svelte +5 -2
- package/dist/blocks/video/video.extension.d.ts +4 -1
- package/dist/blocks/video/video.extension.js +9 -1
- package/dist/blocks/video/video.svelte.d.ts +6 -5
- package/dist/blocks/video/video.svelte.js +18 -9
- package/dist/extend.d.ts +55 -0
- package/dist/extend.js +88 -0
- package/dist/files/assets.clipboard.d.ts +77 -0
- package/dist/files/assets.clipboard.js +152 -0
- package/dist/files/files.svelte.d.ts +321 -19
- package/dist/files/files.svelte.js +847 -43
- package/dist/files/index.d.ts +3 -1
- package/dist/files/index.js +3 -1
- package/dist/files/outbox.d.ts +69 -0
- package/dist/files/outbox.js +48 -0
- package/dist/files/status.d.ts +65 -0
- package/dist/files/status.js +87 -0
- package/dist/files/store.d.ts +97 -0
- package/dist/files/store.js +65 -0
- package/dist/files/uploads.svelte.d.ts +174 -0
- package/dist/files/uploads.svelte.js +504 -0
- package/dist/index.d.ts +68 -9
- package/dist/index.js +117 -10
- package/dist/nabu-theme.css +21 -1
- package/dist/paste/html.paste.d.ts +74 -3
- package/dist/paste/html.paste.js +550 -86
- package/dist/paste/markdown-inline.d.ts +86 -0
- package/dist/paste/markdown-inline.js +528 -0
- package/dist/paste/markdown.paste.d.ts +2 -8
- package/dist/paste/markdown.paste.js +78 -94
- package/dist/paste/nabu.paste.d.ts +3 -0
- package/dist/paste/nabu.paste.js +29 -3
- package/dist/paste/plain-text.paste.d.ts +2 -2
- package/dist/paste/plain-text.paste.js +3 -3
- package/dist/persistence/asset-store.d.ts +51 -0
- package/dist/persistence/asset-store.js +103 -0
- package/dist/persistence/autosave.d.ts +53 -0
- package/dist/persistence/autosave.js +62 -0
- package/dist/persistence/compact.d.ts +162 -0
- package/dist/persistence/compact.js +141 -0
- package/dist/persistence/history.d.ts +77 -0
- package/dist/persistence/history.js +176 -0
- package/dist/persistence/indexeddb.d.ts +190 -4
- package/dist/persistence/indexeddb.js +333 -29
- package/dist/persistence/merge.d.ts +38 -0
- package/dist/persistence/merge.js +36 -0
- package/dist/persistence/outbox.d.ts +25 -0
- package/dist/persistence/outbox.js +40 -0
- package/dist/persistence/persistence.d.ts +70 -9
- package/dist/persistence/persistence.js +507 -35
- package/dist/persistence/recovery.d.ts +79 -0
- package/dist/persistence/recovery.js +79 -0
- package/dist/persistence/release.d.ts +34 -0
- package/dist/persistence/release.js +64 -0
- package/dist/persistence/state.svelte.d.ts +53 -0
- package/dist/persistence/state.svelte.js +48 -0
- package/dist/persistence/sync.d.ts +39 -0
- package/dist/persistence/sync.js +138 -0
- package/dist/persistence/tail.d.ts +42 -0
- package/dist/persistence/tail.js +103 -0
- package/dist/presets.d.ts +29 -26
- package/dist/presets.js +35 -13
- package/dist/themes/atelier.css +318 -0
- package/dist/ui/CommandChooser.svelte +153 -0
- package/dist/ui/CommandChooser.svelte.d.ts +13 -0
- package/dist/ui/CommandInvite.svelte +99 -0
- package/dist/ui/CommandInvite.svelte.d.ts +12 -0
- package/dist/ui/DragHandle.svelte +97 -21
- package/dist/ui/FloatingToolbar.svelte +75 -27
- package/dist/ui/FloatingToolbar.svelte.d.ts +10 -0
- package/dist/ui/SlashMenu.svelte +147 -15
- package/dist/ui/SlashMenu.svelte.d.ts +20 -0
- package/dist/ui/anchor.d.ts +112 -0
- package/dist/ui/anchor.js +136 -0
- package/dist/ui/index.d.ts +7 -1
- package/dist/ui/index.js +12 -1
- package/dist/ui/slash-menu.svelte.d.ts +79 -7
- package/dist/ui/slash-menu.svelte.js +85 -51
- package/dist/utils/command-confirm.svelte.d.ts +349 -0
- package/dist/utils/command-confirm.svelte.js +673 -0
- package/dist/utils/commands.d.ts +328 -0
- package/dist/utils/commands.js +416 -0
- package/dist/utils/dom-scope.d.ts +14 -0
- package/dist/utils/dom-scope.js +20 -0
- package/dist/utils/drop.d.ts +160 -0
- package/dist/utils/drop.js +305 -0
- package/dist/utils/extensions.d.ts +439 -45
- package/dist/utils/extensions.js +271 -29
- package/dist/utils/html.d.ts +44 -0
- package/dist/utils/html.js +183 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/keys.d.ts +120 -0
- package/dist/utils/keys.js +248 -0
- package/dist/utils/links.d.ts +22 -0
- package/dist/utils/links.js +34 -0
- package/dist/utils/placeholders.d.ts +81 -3
- package/dist/utils/placeholders.js +73 -3
- package/dist/utils/selection.svelte.d.ts +47 -19
- package/dist/utils/selection.svelte.js +60 -10
- package/dist/utils/spellcheck.d.ts +9 -0
- package/dist/utils/spellcheck.js +17 -0
- package/dist/utils/tab.d.ts +31 -0
- package/dist/utils/tab.js +117 -0
- package/dist/utils/words.d.ts +7 -0
- package/dist/utils/words.js +62 -0
- package/dist/vite.d.ts +9 -3
- package/dist/vite.js +19 -8
- package/package.json +54 -20
- package/dist/blocks/variable.svelte.d.ts +0 -47
- package/dist/blocks/variable.svelte.js +0 -51
- package/dist/blocks/zone/TemplateEditor.svelte +0 -308
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +0 -11
- package/dist/blocks/zone/Zone.svelte +0 -272
- package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
- package/dist/blocks/zone/ZoneEditor.svelte +0 -289
- package/dist/blocks/zone/ZoneEditor.svelte.d.ts +0 -11
- package/dist/blocks/zone/ZoneTemplatesList.svelte +0 -188
- package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +0 -11
- package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +0 -3
- package/dist/blocks/zone/hooks/onBeforeInput.hook.js +0 -30
- package/dist/blocks/zone/index.d.ts +0 -2
- package/dist/blocks/zone/index.js +0 -2
- package/dist/blocks/zone/zone.extension.d.ts +0 -2
- package/dist/blocks/zone/zone.extension.js +0 -237
- package/dist/blocks/zone/zone.svelte.d.ts +0 -221
- package/dist/blocks/zone/zone.svelte.js +0 -608
- package/dist/overlays/context/Context.svelte +0 -182
- package/dist/overlays/context/Context.svelte.d.ts +0 -17
- package/dist/overlays/context/collect.d.ts +0 -17
- package/dist/overlays/context/collect.js +0 -33
- package/dist/overlays/context/context.extension.d.ts +0 -2
- package/dist/overlays/context/context.extension.js +0 -8
- package/dist/overlays/context/context.svelte.d.ts +0 -82
- package/dist/overlays/context/context.svelte.js +0 -159
- package/dist/overlays/context/index.d.ts +0 -3
- package/dist/overlays/context/index.js +0 -3
|
@@ -1,47 +1,300 @@
|
|
|
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
|
+
*/
|
|
1
18
|
/**
|
|
2
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`).
|
|
3
23
|
* @property {(file: File, ctx: { signal?: AbortSignal, onProgress?: (p: number) => void }) => Promise<{ ref: string } | void>} [onBeforePersist]
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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.
|
|
6
47
|
* @property {(ref: string) => string} [resolve] Turn a stored ref into a display URL.
|
|
7
|
-
* @property {number} [maxInlineSize] Byte threshold
|
|
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.
|
|
8
54
|
*/
|
|
9
55
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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).
|
|
12
63
|
*/
|
|
13
64
|
export class Files {
|
|
14
65
|
/** @param {import('../blocks/nabu.svelte.js').Nabu} nabu @returns {Files} */
|
|
15
66
|
static get(nabu: import("../blocks/nabu.svelte.js").Nabu): Files;
|
|
16
67
|
/** @param {import('../blocks/nabu.svelte.js').Nabu} nabu */
|
|
17
68
|
constructor(nabu: import("../blocks/nabu.svelte.js").Nabu);
|
|
18
|
-
|
|
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>>;
|
|
19
77
|
/** @returns {FilesConfig} */
|
|
20
78
|
get config(): FilesConfig;
|
|
21
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
|
+
}>;
|
|
22
126
|
/**
|
|
23
|
-
*
|
|
24
|
-
* the
|
|
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.
|
|
25
131
|
* @param {File} file
|
|
26
|
-
* @param {{ signal?: AbortSignal, onProgress?: (p:number)=>void }} [ctx]
|
|
27
132
|
* @returns {Promise<string>}
|
|
28
133
|
*/
|
|
29
|
-
persist(file: File
|
|
30
|
-
signal?: AbortSignal;
|
|
31
|
-
onProgress?: (p: number) => void;
|
|
32
|
-
}): Promise<string>;
|
|
134
|
+
persist(file: File): Promise<string>;
|
|
33
135
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
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.
|
|
36
168
|
* @param {string} ref @returns {string}
|
|
37
169
|
*/
|
|
38
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[];
|
|
39
263
|
#private;
|
|
40
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
|
+
};
|
|
41
284
|
export type FilesConfig = {
|
|
42
285
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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).
|
|
45
298
|
*/
|
|
46
299
|
onBeforePersist?: ((file: File, ctx: {
|
|
47
300
|
signal?: AbortSignal;
|
|
@@ -49,13 +302,62 @@ export type FilesConfig = {
|
|
|
49
302
|
}) => Promise<{
|
|
50
303
|
ref: string;
|
|
51
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;
|
|
52
337
|
/**
|
|
53
338
|
* Turn a stored ref into a display URL.
|
|
54
339
|
*/
|
|
55
340
|
resolve?: ((ref: string) => string) | undefined;
|
|
56
341
|
/**
|
|
57
|
-
* Byte threshold
|
|
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.
|
|
58
344
|
*/
|
|
59
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;
|
|
60
358
|
};
|
|
61
|
-
import {
|
|
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';
|