@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { decodeImportBlobMeta } from 'loro-crdt';
|
|
2
|
+
|
|
3
|
+
/** @import { LoroDoc } from 'loro-crdt' */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} MergeResult
|
|
7
|
+
* @property {boolean} imported the stored record held changes the document did not have, and they were imported
|
|
8
|
+
* @property {boolean} covers the stored record now contains EVERYTHING the document has (writing the document again would add nothing)
|
|
9
|
+
* @property {boolean} merged `false`: the record holds something the document still lacks after the import (a shallow snapshot that
|
|
10
|
+
* does not follow from the document): it cannot be merged and must not be overwritten without a copy being kept
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Merge a stored snapshot into the live document (ADR 010, multi-tab, P-94): whatever another tab saved that this document does not
|
|
15
|
+
* have is IMPORTED, so the save that follows (a full export of the document) cannot overwrite it. The version vector of the record
|
|
16
|
+
* is read from its header (no decoding of the whole record) and compared with the document's; the import only happens when the
|
|
17
|
+
* record is ahead of, or concurrent with, the document. Synchronous (it runs inside an IndexedDB request callback, see
|
|
18
|
+
* `saveMerged`). Throws when the bytes are unreadable.
|
|
19
|
+
*
|
|
20
|
+
* @param {LoroDoc} doc
|
|
21
|
+
* @param {Uint8Array} bytes the stored snapshot
|
|
22
|
+
* @param {(bytes: Uint8Array) => unknown} [importBytes] how to import (default `doc.import`; the editor passes `nabu.importRemote`, which
|
|
23
|
+
* keeps the caret and is never an undo step)
|
|
24
|
+
* @returns {MergeResult}
|
|
25
|
+
*/
|
|
26
|
+
export function mergeStored(doc, bytes, importBytes = (b) => doc.import(b)) {
|
|
27
|
+
const theirs = decodeImportBlobMeta(bytes, false).partialEndVersionVector;
|
|
28
|
+
const before = doc.version().compare(theirs); // 0 equal, 1 the document is ahead, -1 the record is ahead, undefined concurrent
|
|
29
|
+
let imported = false;
|
|
30
|
+
if (before === -1 || before === undefined) {
|
|
31
|
+
importBytes(bytes);
|
|
32
|
+
imported = true;
|
|
33
|
+
}
|
|
34
|
+
const after = doc.version().compare(theirs);
|
|
35
|
+
return { imported, covers: after === 0, merged: after === 0 || after === 1 };
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../files/outbox.js').Outbox} Outbox
|
|
3
|
+
* @typedef {import('../files/outbox.js').OutboxEntry} OutboxEntry
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The {@link Outbox} of a persisted editor (ADR 014 lot 2): database `nabu`, object store `outbox`
|
|
7
|
+
* (`{ docId, hash, attempts, state, updatedAt }`, key `[docId, hash]`), next to the asset store and outside the Loro document.
|
|
8
|
+
* One instance per document.
|
|
9
|
+
* @implements {Outbox}
|
|
10
|
+
*/
|
|
11
|
+
export class IndexedDBOutbox implements Outbox {
|
|
12
|
+
/** @param {string} docId */
|
|
13
|
+
constructor(docId: string);
|
|
14
|
+
docId: string;
|
|
15
|
+
/** @returns {Promise<OutboxEntry[]>} */
|
|
16
|
+
list(): Promise<OutboxEntry[]>;
|
|
17
|
+
/** @param {OutboxEntry} entry @returns {Promise<void>} */
|
|
18
|
+
put(entry: OutboxEntry): Promise<void>;
|
|
19
|
+
/** @param {string} hash @returns {Promise<void>} */
|
|
20
|
+
delete(hash: string): Promise<void>;
|
|
21
|
+
/** Forget every entry of this document. @returns {Promise<void>} */
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export type Outbox = import("../files/outbox.js").Outbox;
|
|
25
|
+
export type OutboxEntry = import("../files/outbox.js").OutboxEntry;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { OUTBOX_STORE, withStore } from './indexeddb.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('../files/outbox.js').Outbox} Outbox
|
|
5
|
+
* @typedef {import('../files/outbox.js').OutboxEntry} OutboxEntry
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The {@link Outbox} of a persisted editor (ADR 014 lot 2): database `nabu`, object store `outbox`
|
|
10
|
+
* (`{ docId, hash, attempts, state, updatedAt }`, key `[docId, hash]`), next to the asset store and outside the Loro document.
|
|
11
|
+
* One instance per document.
|
|
12
|
+
* @implements {Outbox}
|
|
13
|
+
*/
|
|
14
|
+
export class IndexedDBOutbox {
|
|
15
|
+
/** @param {string} docId */
|
|
16
|
+
constructor(docId) {
|
|
17
|
+
this.docId = docId;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @returns {Promise<OutboxEntry[]>} */
|
|
21
|
+
async list() {
|
|
22
|
+
const records = /** @type {any[]} */ (await withStore(OUTBOX_STORE, 'readonly', (s) => s.index('docId').getAll(this.docId)));
|
|
23
|
+
return records.map(({ hash, attempts, state, updatedAt }) => ({ hash, attempts, state, updatedAt }));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @param {OutboxEntry} entry @returns {Promise<void>} */
|
|
27
|
+
async put(entry) {
|
|
28
|
+
await withStore(OUTBOX_STORE, 'readwrite', (s) => s.put({ docId: this.docId, hash: entry.hash, attempts: entry.attempts, state: entry.state, updatedAt: entry.updatedAt }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @param {string} hash @returns {Promise<void>} */
|
|
32
|
+
async delete(hash) {
|
|
33
|
+
await withStore(OUTBOX_STORE, 'readwrite', (s) => s.delete([this.docId, hash]));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Forget every entry of this document. @returns {Promise<void>} */
|
|
37
|
+
async clear() {
|
|
38
|
+
for (const { hash } of await this.list()) await this.delete(hash);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @import { Extension } from '../utils/extensions.js';
|
|
3
|
-
*/
|
|
4
1
|
/**
|
|
5
2
|
* Create a Nabu editor instance with automatic IndexedDB persistence.
|
|
6
3
|
*
|
|
@@ -10,16 +7,58 @@
|
|
|
10
7
|
* On first call, the document is empty (only the default paragraph from ParagraphExtension).
|
|
11
8
|
* On subsequent calls, the document state is restored from the last saved snapshot.
|
|
12
9
|
*
|
|
13
|
-
* The
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
10
|
+
* The bytes of the files (images, videos…) are NOT saved in the snapshot (ADR 014): they go to an `IndexedDBAssetStore`
|
|
11
|
+
* (base `nabu`, object store `assets`, shared by every document of the origin), unless `files.store` provides another one.
|
|
12
|
+
* The document only keeps references and a small metadata index; the store also records which files each document references.
|
|
13
|
+
* With a host (`files.onBeforePersist`) the uploads still to do are listed in an `IndexedDBOutbox` (object store `outbox`, unless
|
|
14
|
+
* `files.outbox` provides another one): an upload interrupted by a closed tab RESUMES when the document is opened again.
|
|
15
|
+
*
|
|
16
|
+
* History (ADR 014 §3.6): the default `history: 'full'` NEVER compacts or trims anything (the whole evolution of the document
|
|
17
|
+
* is kept and saved, whatever the number of sessions). `history: { mode: 'compact', retain, onBeforeCompact }` opts in to a
|
|
18
|
+
* compaction when the document is OPENED (after loading, migration and upload reconciliation; never mid-session): history older
|
|
19
|
+
* than `retain` is dropped and the files only that history referenced are released. See {@link CompactOptions} and `nabu.compact()`.
|
|
20
|
+
*
|
|
21
|
+
* Timestamps of the changes are recorded (`doc.setRecordTimestamp(true)`) so a retention window can be honoured.
|
|
22
|
+
*
|
|
23
|
+
* Robustness (ADR 010, theme 8): the autosave also happens at most every `maxWait` ms during a continuous burst, and immediately when
|
|
24
|
+
* the page is hidden (`visibilitychange` → `hidden`, `pagehide`). Every save keeps the snapshot it replaces as a BACKUP. A stored
|
|
25
|
+
* snapshot that cannot be read is moved aside (never deleted: the `quarantine` object store), the backup is tried, else the editor
|
|
26
|
+
* starts empty — it always boots, and `nabu.persistence.recovery` / `onRecover` tell the host what happened. When IndexedDB is not
|
|
27
|
+
* usable the editor boots IN MEMORY (`nabu.persistence.available === false`, status `'unavailable'`): `createPersistedEditor` does not reject.
|
|
28
|
+
*
|
|
29
|
+
* Several tabs (ADR 010, P-94): two tabs on the same `docId` never overwrite each other. EVERY save first merges what is stored (read and
|
|
30
|
+
* written in one IndexedDB transaction: the changes another tab saved are imported into the live document, not as undo steps, the caret
|
|
31
|
+
* stays on its character), and, with `sync` (default), the tabs also exchange their changes LIVE through a `BroadcastChannel`
|
|
32
|
+
* (`nabu:<docId>`): an edit made in one tab appears in the others at once.
|
|
33
|
+
*
|
|
34
|
+
* The instance gains extra members:
|
|
35
|
+
* - `nabu.persistence` — reactive state: `status` (`'saved' | 'pending' | 'saving' | 'error' | 'unavailable'`), `lastSavedAt`,
|
|
36
|
+
* `lastError`, `available`, `recovery`, `sync`, and `dispose()` (stop autosave, remove the page listeners, close the sync channel and
|
|
37
|
+
* the connection)
|
|
38
|
+
* - `nabu.saveNow()` — force an immediate save (returns a Promise; rejects if the save fails)
|
|
39
|
+
* - `nabu.compact({ retain, onBeforeCompact })` — explicit compaction (returns a `CompactResult`, never throws for a refusal)
|
|
40
|
+
* - `nabu.clearPersistence()` — delete the stored snapshot and release the document's files (returns a Promise)
|
|
41
|
+
* - `nabu.isNew` — `true` if no previous snapshot was found (fresh document, or nothing readable was left: `persistence.recovery.kind === 'empty'`)
|
|
17
42
|
*
|
|
18
43
|
* @param {object} options
|
|
19
44
|
* @param {string} options.docId - Unique identifier for this document in IndexedDB
|
|
20
45
|
* @param {Extension[]} [options.preset] - Extension preset (default: FullPreset)
|
|
21
46
|
* @param {Extension[]} [options.extensions] - Additional extensions to append
|
|
22
47
|
* @param {number} [options.debounce] - Auto-save debounce delay in ms (default: 2000)
|
|
48
|
+
* @param {number} [options.maxWait] - Longest time (ms) a continuous burst of edits goes without a save (default: 3000, never shorter than
|
|
49
|
+
* `debounce`; `0` / `Infinity`: no maximum, the autosave only happens after a pause)
|
|
50
|
+
* @param {(error: unknown) => void} [options.onSaveError] - Called when an AUTOMATIC save fails (quota…); `nabu.persistence.status` is `'error'` and the
|
|
51
|
+
* next change retries. `saveNow()` rejects for its awaiter instead (the hook is not called for it)
|
|
52
|
+
* @param {(recovery: Recovery) => void} [options.onRecover] - Called at boot when the stored document could not be read (see `nabu.persistence.recovery`)
|
|
53
|
+
* @param {boolean} [options.sync] - Live sync between the tabs that edit the same `docId` through a `BroadcastChannel` (default `true`; `false`
|
|
54
|
+
* disables it; a browser without `BroadcastChannel` skips it silently). The merge on save does not depend on it. `nabu.persistence.sync` tells whether it runs.
|
|
55
|
+
* @param {import('../files/files.svelte.js').FilesConfig} [options.files] - File handling; `files.store` replaces the default IndexedDB asset store
|
|
56
|
+
* @param {'full' | { mode: 'full' } | { mode: 'compact', retain: number | string, onBeforeCompact?: CompactOptions['onBeforeCompact'] }} [options.history] - `'full'` (default): nothing is ever compacted.
|
|
57
|
+
* `{ mode: 'compact', retain, onBeforeCompact }`: compact at open (`retain`: ms, `'30d'`, `'12h'`, or `0` = keep no past history).
|
|
58
|
+
* @param {import('../utils/placeholders.js').PlaceholdersOption} [options.placeholders] - Forwarded to Nabu
|
|
59
|
+
* (any other Nabu init option, e.g. `files`, is forwarded too; `files.store` replaces the default IndexedDB asset store)
|
|
60
|
+
* @param {boolean} [options.spellcheck] - Forwarded to Nabu (default `true`)
|
|
61
|
+
* @param {string} [options.lang] - Forwarded to Nabu (BCP 47 tag of the content)
|
|
23
62
|
* @returns {Promise<Nabu>}
|
|
24
63
|
*
|
|
25
64
|
* @example
|
|
@@ -34,15 +73,37 @@
|
|
|
34
73
|
* extensions: [MyCustomExtension],
|
|
35
74
|
* });
|
|
36
75
|
*/
|
|
37
|
-
export function createPersistedEditor({ docId, preset, extensions, debounce }?: {
|
|
76
|
+
export function createPersistedEditor({ docId, preset, extensions, debounce, maxWait, sync, onSaveError, onRecover, history, ...init }?: {
|
|
38
77
|
docId: string;
|
|
39
78
|
preset?: Extension[] | undefined;
|
|
40
79
|
extensions?: Extension[] | undefined;
|
|
41
80
|
debounce?: number | undefined;
|
|
81
|
+
maxWait?: number | undefined;
|
|
82
|
+
onSaveError?: ((error: unknown) => void) | undefined;
|
|
83
|
+
onRecover?: ((recovery: Recovery) => void) | undefined;
|
|
84
|
+
sync?: boolean | undefined;
|
|
85
|
+
files?: import("../files/files.svelte.js").FilesConfig | undefined;
|
|
86
|
+
history?: "full" | {
|
|
87
|
+
mode: "full";
|
|
88
|
+
} | {
|
|
89
|
+
mode: "compact";
|
|
90
|
+
retain: number | string;
|
|
91
|
+
onBeforeCompact?: CompactOptions["onBeforeCompact"];
|
|
92
|
+
} | undefined;
|
|
93
|
+
placeholders?: import("../utils/placeholders.js").PlaceholdersOption | undefined;
|
|
94
|
+
spellcheck?: boolean | undefined;
|
|
95
|
+
lang?: string | undefined;
|
|
42
96
|
}): Promise<Nabu>;
|
|
43
97
|
import type { Extension } from '../utils/extensions.js';
|
|
98
|
+
import type { Recovery } from './recovery.js';
|
|
99
|
+
import type { CompactOptions } from './history.js';
|
|
44
100
|
import { Nabu } from '../blocks/nabu.svelte.js';
|
|
45
101
|
import { loadSnapshot } from './indexeddb.js';
|
|
46
102
|
import { saveSnapshot } from './indexeddb.js';
|
|
47
103
|
import { deleteSnapshot } from './indexeddb.js';
|
|
48
|
-
|
|
104
|
+
import { loadRecords } from './indexeddb.js';
|
|
105
|
+
import { listQuarantined } from './indexeddb.js';
|
|
106
|
+
import { IndexedDBAssetStore } from './asset-store.js';
|
|
107
|
+
import { IndexedDBOutbox } from './outbox.js';
|
|
108
|
+
import { PersistenceState } from './state.svelte.js';
|
|
109
|
+
export { loadSnapshot, saveSnapshot, deleteSnapshot, loadRecords, listQuarantined, IndexedDBAssetStore, IndexedDBOutbox, PersistenceState };
|