@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
|
@@ -5,13 +5,37 @@
|
|
|
5
5
|
* @typedef {NabuNode<{type: "toggle", text: LoroText, collapsed: boolean}>} ToggleNode
|
|
6
6
|
*/
|
|
7
7
|
export class ToggleBlock extends MegaBlock {
|
|
8
|
+
static placeholder: string;
|
|
8
9
|
/**
|
|
10
|
+
* `<details>` / `<details open>` + `<summary>` + the body as markdown + `</details>` (see markdown.js).
|
|
9
11
|
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
10
|
-
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string }} helpers
|
|
12
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string, recurseAll?: (children: import('../../utils/extensions.js').PasteBlock[], ctx?: object) => string[] }} helpers
|
|
11
13
|
*/
|
|
12
|
-
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
14
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { recurse, recurseAll }: {
|
|
13
15
|
recurse: (child: import("../../utils/extensions.js").PasteBlock, ctx?: object) => string;
|
|
16
|
+
recurseAll?: (children: import("../../utils/extensions.js").PasteBlock[], ctx?: object) => string[];
|
|
14
17
|
}): string;
|
|
18
|
+
/**
|
|
19
|
+
* Markdown (paste AND `importMarkdown`): the exact `<details>` construct Nabu emits, nothing else (see markdown.js).
|
|
20
|
+
* An opening line without a matching `</details>`, with attributes or without a `<summary>` is not a toggle: it stays text.
|
|
21
|
+
*/
|
|
22
|
+
static markdownRules: {
|
|
23
|
+
priority: number;
|
|
24
|
+
interruptsParagraph: boolean;
|
|
25
|
+
detect: (line: string, lines: string[], i: number) => boolean;
|
|
26
|
+
consume: (lines: string[], i: number) => number;
|
|
27
|
+
}[];
|
|
28
|
+
/**
|
|
29
|
+
* The toggle (header = the summary, parsed as inline markdown; body = the lines between the summary and `</details>`,
|
|
30
|
+
* parsed as a document of their own, nested toggles included).
|
|
31
|
+
* @param {string[]} lines
|
|
32
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[], parseBlocks?: (lines: string[]) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
33
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
34
|
+
*/
|
|
35
|
+
static fromMarkdown(lines: string[], { parseInline, parseBlocks }: {
|
|
36
|
+
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
37
|
+
parseBlocks?: (lines: string[]) => import("../../utils/extensions.js").PasteBlock[];
|
|
38
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
15
39
|
/**
|
|
16
40
|
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
17
41
|
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
@@ -34,18 +58,28 @@ export class ToggleBlock extends MegaBlock {
|
|
|
34
58
|
/**
|
|
35
59
|
* @param {Nabu} nabu
|
|
36
60
|
* @param {string} type
|
|
37
|
-
* @param {
|
|
61
|
+
* @param {Record<string, any>} [props={}]
|
|
38
62
|
* @param {string|null} [parentId=null]
|
|
39
63
|
* @param {number|null} [index=null]
|
|
40
64
|
*/
|
|
41
|
-
static create(nabu: Nabu, type: string, props?:
|
|
65
|
+
static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): ToggleBlock;
|
|
42
66
|
/** @param {Nabu} nabu @param {ToggleNode} node */
|
|
43
67
|
constructor(nabu: Nabu, node: ToggleNode);
|
|
44
68
|
container: LoroText;
|
|
45
69
|
/** @type {TextBehavior} */
|
|
46
70
|
behavior: TextBehavior;
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
set collapsed(v: boolean);
|
|
72
|
+
/**
|
|
73
|
+
* Whether the body is hidden. In a read-only editor a reader may open or close a toggle to read it: that is VIEW STATE
|
|
74
|
+
* (kept in memory, not in the document: no Loro write, no commit, no undo step, nothing synced or persisted, serializers
|
|
75
|
+
* keep reporting the document's own state), and it is ignored again as soon as the editor is not read-only.
|
|
76
|
+
* @type {boolean}
|
|
77
|
+
*/
|
|
78
|
+
get collapsed(): boolean;
|
|
79
|
+
/** A collapsed toggle stays collapsed on the clipboard. */
|
|
80
|
+
get clipboardProps(): {
|
|
81
|
+
collapsed: boolean;
|
|
82
|
+
};
|
|
49
83
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
50
84
|
block: import("./toggle.svelte.js").ToggleBlock;
|
|
51
85
|
}, {}, "">;
|
|
@@ -58,7 +92,7 @@ export class ToggleBlock extends MegaBlock {
|
|
|
58
92
|
direction: "forward" | "backward" | "none";
|
|
59
93
|
} | null;
|
|
60
94
|
/**
|
|
61
|
-
* Set the collapsed state and persist to Loro.
|
|
95
|
+
* Set the collapsed state and persist to Loro (in a read-only editor: only what the reader sees, see {@link ToggleBlock#collapsed}).
|
|
62
96
|
* @param {boolean} v
|
|
63
97
|
*/
|
|
64
98
|
setCollapsed(v: boolean): void;
|
|
@@ -70,11 +104,24 @@ export class ToggleBlock extends MegaBlock {
|
|
|
70
104
|
absorbs(block: import("../block.svelte.js").Block): boolean;
|
|
71
105
|
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
72
106
|
applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
|
|
107
|
+
/**
|
|
108
|
+
* Enter in a body child (called through `ascend("onSplit")`). Only the Enter that EXITS the sub-thread is
|
|
109
|
+
* taken here: on an EMPTY paragraph that is the LAST child, the paragraph moves right after the toggle and
|
|
110
|
+
* takes the caret. Anything else is declined (falsy) and goes through the regular split of the child's type.
|
|
111
|
+
* @param {Event | null} event
|
|
112
|
+
* @param {{ from: import('../block.svelte.js').Block }} data
|
|
113
|
+
*/
|
|
114
|
+
onSplit(event: Event | null, data: {
|
|
115
|
+
from: import("../block.svelte.js").Block;
|
|
116
|
+
}): false | {
|
|
117
|
+
block: import("../block.svelte.js").Block;
|
|
118
|
+
};
|
|
73
119
|
/**
|
|
74
120
|
* @param {InputEvent} event
|
|
75
121
|
* @returns {boolean}
|
|
76
122
|
*/
|
|
77
123
|
beforeinput(event: InputEvent): boolean;
|
|
124
|
+
#private;
|
|
78
125
|
}
|
|
79
126
|
export type ToggleNode = NabuNode<{
|
|
80
127
|
type: "toggle";
|
|
@@ -2,7 +2,8 @@ import { MegaBlock } from "../megablock.svelte.js";
|
|
|
2
2
|
import { TextBehavior, deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
3
3
|
import { LoroText } from "loro-crdt";
|
|
4
4
|
import ToggleComponent from "./Toggle.svelte";
|
|
5
|
-
import {
|
|
5
|
+
import { parseDetails, toggleMarkdown } from "./markdown.js";
|
|
6
|
+
import { isEmptyLastParagraph, exitSubThread, dissolveToParagraph, insertParagraphAfter, pasteIntoHeader } from "../subthread.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
@@ -27,26 +28,23 @@ export class ToggleBlock extends MegaBlock {
|
|
|
27
28
|
|
|
28
29
|
// Initialize collapsed from Loro metadata
|
|
29
30
|
this.collapsed = !!data.get('collapsed');
|
|
30
|
-
// Subscribe to data changes to keep collapsed in sync
|
|
31
|
+
// Subscribe to data changes to keep collapsed in sync (a change of the document wins over the read-only view state)
|
|
31
32
|
this.node.data.subscribe(() => {
|
|
33
|
+
this.#viewState = null;
|
|
32
34
|
this.collapsed = !!this.node.data.get('collapsed');
|
|
33
35
|
});
|
|
34
36
|
|
|
35
|
-
this.serializers.set('markdown', () => {
|
|
36
|
-
const head = this.behavior.toMarkdown();
|
|
37
|
-
const body = this.children.map(c => c.serialize('markdown')).filter(Boolean).join('\n\n');
|
|
38
|
-
return '<details><summary>' + head + '</summary>\n\n' + body + '\n\n</details>';
|
|
39
|
-
});
|
|
37
|
+
this.serializers.set('markdown', () => toggleMarkdown(this.#stored, this.behavior.toMarkdown(), /** @type {any} */ (this.children.map(c => c.serialize('markdown')))));
|
|
40
38
|
this.serializers.set('json', () => ({
|
|
41
39
|
id: this.id,
|
|
42
40
|
type: 'toggle',
|
|
43
|
-
props: { collapsed: this
|
|
41
|
+
props: { collapsed: this.#stored },
|
|
44
42
|
content: this.behavior.toJSON(),
|
|
45
43
|
children: this.children.map(c => c.serialize('json')).filter(Boolean)
|
|
46
44
|
}));
|
|
47
45
|
this.serializers.set('application/x-nabu+json', () => ({
|
|
48
46
|
type: 'toggle',
|
|
49
|
-
props: { collapsed: this
|
|
47
|
+
props: { collapsed: this.#stored },
|
|
50
48
|
delta: this.container.sliceDelta(0, this.container.length),
|
|
51
49
|
children: this.children.map(c => c.serialize('application/x-nabu+json')).filter(Boolean)
|
|
52
50
|
}));
|
|
@@ -58,8 +56,29 @@ export class ToggleBlock extends MegaBlock {
|
|
|
58
56
|
// marksEnabled stays true (default) — bold/italic work inside the header
|
|
59
57
|
// splitsOnEnter is not set (defaults true) but Enter is overridden in beforeinput
|
|
60
58
|
|
|
61
|
-
/**
|
|
62
|
-
|
|
59
|
+
/** The collapsed state of the DOCUMENT (the `collapsed` prop of the node). */
|
|
60
|
+
#stored = $state(false);
|
|
61
|
+
|
|
62
|
+
/** Read-only editors only: what the reader chose to see, never written to the document (`null`: nothing chosen). */
|
|
63
|
+
/** @type {boolean | null} */
|
|
64
|
+
#viewState = $state(null);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether the body is hidden. In a read-only editor a reader may open or close a toggle to read it: that is VIEW STATE
|
|
68
|
+
* (kept in memory, not in the document: no Loro write, no commit, no undo step, nothing synced or persisted, serializers
|
|
69
|
+
* keep reporting the document's own state), and it is ignored again as soon as the editor is not read-only.
|
|
70
|
+
* @type {boolean}
|
|
71
|
+
*/
|
|
72
|
+
get collapsed() { return this.nabu.readonly && this.#viewState !== null ? this.#viewState : this.#stored; }
|
|
73
|
+
set collapsed(v) { this.#stored = !!v; }
|
|
74
|
+
|
|
75
|
+
/** A collapsed toggle does not render its body: navigation must never put the caret in it. */
|
|
76
|
+
get hidesChildren() { return this.collapsed; }
|
|
77
|
+
|
|
78
|
+
/** A collapsed toggle stays collapsed on the clipboard. */
|
|
79
|
+
get clipboardProps() { return { collapsed: this.collapsed }; }
|
|
80
|
+
|
|
81
|
+
static placeholder = 'Toggle…';
|
|
63
82
|
|
|
64
83
|
component = $derived(this.nabu.components.get("toggle") || ToggleComponent);
|
|
65
84
|
|
|
@@ -69,6 +88,7 @@ export class ToggleBlock extends MegaBlock {
|
|
|
69
88
|
selection = $derived(this.behavior.selection);
|
|
70
89
|
|
|
71
90
|
// When collapsed, exclude children from positions so cursor cannot enter hidden body
|
|
91
|
+
// @ts-ignore — `super.positions`: Svelte compiles the parent's `$derived` field to a prototype accessor, which TS sees as a field
|
|
72
92
|
positions = $derived(this.behavior.positions + (this.collapsed ? 0 : super.positions));
|
|
73
93
|
|
|
74
94
|
// Count body words regardless of collapse state
|
|
@@ -97,10 +117,12 @@ export class ToggleBlock extends MegaBlock {
|
|
|
97
117
|
// ── Collapse control ────────────────────────────────────────────────────
|
|
98
118
|
|
|
99
119
|
/**
|
|
100
|
-
* Set the collapsed state and persist to Loro.
|
|
120
|
+
* Set the collapsed state and persist to Loro (in a read-only editor: only what the reader sees, see {@link ToggleBlock#collapsed}).
|
|
101
121
|
* @param {boolean} v
|
|
102
122
|
*/
|
|
103
123
|
setCollapsed(v) {
|
|
124
|
+
if (this.nabu.readonly) { this.#viewState = !!v; return; } // view state only: the document is not touched
|
|
125
|
+
this.#viewState = null;
|
|
104
126
|
this.collapsed = !!v;
|
|
105
127
|
/** @type {any} */ (this.node.data).set('collapsed', !!v);
|
|
106
128
|
this.commit();
|
|
@@ -133,7 +155,61 @@ export class ToggleBlock extends MegaBlock {
|
|
|
133
155
|
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
134
156
|
applyDelta(data = []) { return this.behavior.applyDelta(data); }
|
|
135
157
|
|
|
136
|
-
// ──
|
|
158
|
+
// ── Sub-thread rules (P-40) ─────────────────────────────────────────────
|
|
159
|
+
// Header = own text, body = children. The tree operations live in ../subthread.js, shared with any other
|
|
160
|
+
// container block (the container Callout will reuse them as is).
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Enter in a body child (called through `ascend("onSplit")`). Only the Enter that EXITS the sub-thread is
|
|
164
|
+
* taken here: on an EMPTY paragraph that is the LAST child, the paragraph moves right after the toggle and
|
|
165
|
+
* takes the caret. Anything else is declined (falsy) and goes through the regular split of the child's type.
|
|
166
|
+
* @param {Event | null} event
|
|
167
|
+
* @param {{ from: import('../block.svelte.js').Block }} data
|
|
168
|
+
*/
|
|
169
|
+
onSplit(event, data) {
|
|
170
|
+
const source = data.from;
|
|
171
|
+
if (!isEmptyLastParagraph(/** @type {any} */ (this), source)) return false;
|
|
172
|
+
const id = source.node.id.toString();
|
|
173
|
+
exitSubThread(source.node, this.node);
|
|
174
|
+
this.nabu.commit().then(() => {
|
|
175
|
+
const f = this.nabu.blocks.get(id);
|
|
176
|
+
if (f) this.nabu.selection.setCursor(f, 0);
|
|
177
|
+
});
|
|
178
|
+
return { block: source };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Children adopted by a merge (`Block#consume`) never vanish into a HIDDEN body: when collapsed they stay
|
|
183
|
+
* visible, in order, right after the toggle.
|
|
184
|
+
* @param {import('../block.svelte.js').Block[]} children
|
|
185
|
+
* @param {number | null} [index]
|
|
186
|
+
*/
|
|
187
|
+
adoptChildren(children, index = null) {
|
|
188
|
+
if (!this.collapsed) return super.adoptChildren(children, index);
|
|
189
|
+
[...children].reverse().forEach(child => { if (child.node) child.node.moveAfter(this.node); });
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The body is free-form: an empty paragraph of the body takes the type of a whole block pasted into it. */
|
|
193
|
+
get adoptsPastedTypes() { return true; }
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Paste with the caret in the HEADER (text only). One pasted text block is the engine's inline merge
|
|
197
|
+
* (declined). Several blocks: the first completes the header at the caret, the others go to the TOP of the
|
|
198
|
+
* body (like Enter, which creates the first body child), the header text after the caret follows the last
|
|
199
|
+
* one (merged into it when it is text, else in a new paragraph). A COLLAPSED toggle is EXPANDED first: the
|
|
200
|
+
* pasted content would otherwise land hidden. (A paste with the caret in a body child never reaches this
|
|
201
|
+
* hook: the child's own rules apply, inside the body.)
|
|
202
|
+
* @param {import('../../utils/extensions.js').PasteBlock[]} blocks
|
|
203
|
+
* @param {{ offset: number }} ctx
|
|
204
|
+
*/
|
|
205
|
+
acceptPaste(blocks, ctx) {
|
|
206
|
+
if (!blocks?.length || (blocks.length === 1 && !blocks[0].children?.length)) return null;
|
|
207
|
+
const landing = pasteIntoHeader(this.nabu, /** @type {any} */ (this), ctx.offset, blocks);
|
|
208
|
+
if (landing && this.collapsed) /** @type {any} */ (this.node.data).set('collapsed', false);
|
|
209
|
+
return landing;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ── Custom beforeinput (handles Enter and Backspace in the header) ──────
|
|
137
213
|
|
|
138
214
|
/**
|
|
139
215
|
* @param {InputEvent} event
|
|
@@ -142,10 +218,10 @@ export class ToggleBlock extends MegaBlock {
|
|
|
142
218
|
beforeinput(event) {
|
|
143
219
|
const sel = this.behavior.selection;
|
|
144
220
|
|
|
145
|
-
// Enter in the header → split
|
|
146
|
-
// into a new paragraph
|
|
147
|
-
//
|
|
148
|
-
//
|
|
221
|
+
// Enter in the header → split at the caret.
|
|
222
|
+
// - COLLAPSED: the tail goes into a new paragraph AFTER the toggle (caret in it); the toggle stays collapsed
|
|
223
|
+
// and its hidden body is not touched.
|
|
224
|
+
// - EXPANDED: the tail goes into a new paragraph as the FIRST body child (caret in it).
|
|
149
225
|
if (event.inputType === 'insertParagraph' && sel) {
|
|
150
226
|
const from = sel.from;
|
|
151
227
|
const to = sel.isCollapsed ? this.behavior.text.length : sel.to;
|
|
@@ -153,11 +229,9 @@ export class ToggleBlock extends MegaBlock {
|
|
|
153
229
|
if (this.behavior.text.length > from) {
|
|
154
230
|
this.behavior.delete({ index: from, length: this.behavior.text.length - from });
|
|
155
231
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.
|
|
159
|
-
}
|
|
160
|
-
const p = this.nabu.insert('paragraph', { delta }, this.node.id.toString(), 0);
|
|
232
|
+
const p = this.collapsed
|
|
233
|
+
? insertParagraphAfter(this.nabu, this.node, delta)
|
|
234
|
+
: this.nabu.insert('paragraph', { delta }, this.node.id.toString(), 0);
|
|
161
235
|
this.nabu.commit().then(() => {
|
|
162
236
|
const f = this.nabu.blocks.get(p.id);
|
|
163
237
|
if (f) this.nabu.selection.setCursor(f, 0);
|
|
@@ -165,12 +239,11 @@ export class ToggleBlock extends MegaBlock {
|
|
|
165
239
|
return true;
|
|
166
240
|
}
|
|
167
241
|
|
|
168
|
-
// Backspace at
|
|
169
|
-
|
|
170
|
-
|
|
242
|
+
// Backspace at offset 0 of the header (empty or not, with or without body) → the toggle becomes a
|
|
243
|
+
// paragraph with the header text; its body children follow it. One transaction = one undo step.
|
|
244
|
+
if (event.inputType === 'deleteContentBackward' && sel?.isCollapsed && sel.from === 0) {
|
|
171
245
|
const id = this.node.id.toString();
|
|
172
|
-
this.
|
|
173
|
-
tick().then(() => {
|
|
246
|
+
this.nabu.transact(() => dissolveToParagraph(this.node, ['collapsed'])).then(() => {
|
|
174
247
|
const f = this.nabu.blocks.get(id);
|
|
175
248
|
if (f) f.focus({ start: 0, end: 0 });
|
|
176
249
|
});
|
|
@@ -183,13 +256,40 @@ export class ToggleBlock extends MegaBlock {
|
|
|
183
256
|
// ── Statics ─────────────────────────────────────────────────────────────
|
|
184
257
|
|
|
185
258
|
/**
|
|
259
|
+
* `<details>` / `<details open>` + `<summary>` + the body as markdown + `</details>` (see markdown.js).
|
|
186
260
|
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
187
|
-
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string }} helpers
|
|
261
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string, recurseAll?: (children: import('../../utils/extensions.js').PasteBlock[], ctx?: object) => string[] }} helpers
|
|
262
|
+
*/
|
|
263
|
+
static toMarkdown(pb, { recurse, recurseAll }) {
|
|
264
|
+
const children = pb.children || [];
|
|
265
|
+
return toggleMarkdown(!!pb.props?.collapsed, deltaToMarkdown(pb.delta || []), recurseAll ? recurseAll(children) : children.map(c => recurse(c)));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Markdown (paste AND `importMarkdown`): the exact `<details>` construct Nabu emits, nothing else (see markdown.js).
|
|
270
|
+
* An opening line without a matching `</details>`, with attributes or without a `<summary>` is not a toggle: it stays text.
|
|
271
|
+
*/
|
|
272
|
+
static markdownRules = [
|
|
273
|
+
{
|
|
274
|
+
priority: 20,
|
|
275
|
+
interruptsParagraph: true,
|
|
276
|
+
detect: (/** @type {string} */ line, /** @type {string[]} */ lines, /** @type {number} */ i) => line.startsWith('<details') && !!parseDetails(lines, i),
|
|
277
|
+
consume: (/** @type {string[]} */ lines, /** @type {number} */ i) => (parseDetails(lines, i)?.end ?? i) - i + 1,
|
|
278
|
+
}
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The toggle (header = the summary, parsed as inline markdown; body = the lines between the summary and `</details>`,
|
|
283
|
+
* parsed as a document of their own, nested toggles included).
|
|
284
|
+
* @param {string[]} lines
|
|
285
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[], parseBlocks?: (lines: string[]) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
286
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
188
287
|
*/
|
|
189
|
-
static
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
288
|
+
static fromMarkdown(lines, { parseInline, parseBlocks }) {
|
|
289
|
+
const details = parseDetails(lines, 0);
|
|
290
|
+
if (!details || !parseBlocks) return null;
|
|
291
|
+
const children = parseBlocks(lines.slice(details.bodyStart, details.end));
|
|
292
|
+
return { type: 'toggle', props: { collapsed: !details.open }, delta: parseInline(details.summary), partial: false, ...(children.length ? { children } : {}) };
|
|
193
293
|
}
|
|
194
294
|
|
|
195
295
|
/**
|
|
@@ -236,12 +336,12 @@ export class ToggleBlock extends MegaBlock {
|
|
|
236
336
|
/**
|
|
237
337
|
* @param {Nabu} nabu
|
|
238
338
|
* @param {string} type
|
|
239
|
-
* @param {
|
|
339
|
+
* @param {Record<string, any>} [props={}]
|
|
240
340
|
* @param {string|null} [parentId=null]
|
|
241
341
|
* @param {number|null} [index=null]
|
|
242
342
|
*/
|
|
243
343
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
244
|
-
const node = nabu.tree.createNode(
|
|
344
|
+
const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
|
|
245
345
|
/** @type {any} */ (node.data).set('type', 'toggle');
|
|
246
346
|
/** @type {any} */ (node.data).set('collapsed', props.collapsed ?? false);
|
|
247
347
|
const container = /** @type {any} */ (node.data).setContainer('text', new LoroText());
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { LoroDoc } from 'loro-crdt';
|
|
3
|
+
* @import { Nabu } from './nabu.svelte.js';
|
|
4
|
+
* @import { Block } from './block.svelte.js';
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object} Endpoint One end of a stored selection.
|
|
8
|
+
* @property {string} blockId
|
|
9
|
+
* @property {number[]} path child index at each level, root first (see {@link blockPath})
|
|
10
|
+
* @property {number} offset model offset when captured: the fallback when no cursor can be used
|
|
11
|
+
* @property {number} [length] length of the block's text when captured (see {@link resolveOffset}: both cursors dead)
|
|
12
|
+
* @property {string | null} container id of the block's text container the cursors belong to
|
|
13
|
+
* @property {'start' | 'end'} role the first end of a range sticks to the character before it, every other end to the one after
|
|
14
|
+
* @property {Uint8Array | null} next encoded Loro cursor (the UndoManager serializes what it stores: a live Cursor would not survive)
|
|
15
|
+
* @property {Uint8Array | null} prev
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {Object} UndoSelection The selection stored with an undo / redo step.
|
|
19
|
+
* @property {Endpoint} anchor
|
|
20
|
+
* @property {Endpoint} focus Equal to `anchor` for a caret. The direction of a backward selection is kept by which end is which.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Tree path of a block: the child index at each level, root first. Read from the Block's own
|
|
24
|
+
* `parent` / `index` — still valid for a block destroyed in the very transaction being recorded,
|
|
25
|
+
* whose Loro node can no longer tell (a deleted node has no index).
|
|
26
|
+
* @param {Block} block
|
|
27
|
+
* @returns {number[]}
|
|
28
|
+
*/
|
|
29
|
+
export function blockPath(block: Block): number[];
|
|
30
|
+
/**
|
|
31
|
+
* @param {Block} block
|
|
32
|
+
* @param {number} offset
|
|
33
|
+
* @param {'start' | 'end'} role
|
|
34
|
+
* @param {boolean} [withCursors] false for a caret known only after the fact (no pre-change text to bind to)
|
|
35
|
+
* @returns {Endpoint}
|
|
36
|
+
*/
|
|
37
|
+
export function makeEndpoint(block: Block, offset: number, role: "start" | "end", withCursors?: boolean): Endpoint;
|
|
38
|
+
/**
|
|
39
|
+
* The live DOM selection as MODEL points (block + text offset), anchor and focus kept apart so the direction survives.
|
|
40
|
+
* The only reliable way to carry a selection across a change that rewrites the DOM of its blocks (a mark toggled, a text
|
|
41
|
+
* rewritten): DOM offsets are relative to a text node, and the text nodes change with the spans.
|
|
42
|
+
* @param {Nabu} nabu
|
|
43
|
+
* @returns {{ anchor: { block: Block, offset: number }, focus: { block: Block, offset: number } } | null}
|
|
44
|
+
*/
|
|
45
|
+
export function livePoints(nabu: Nabu): {
|
|
46
|
+
anchor: {
|
|
47
|
+
block: Block;
|
|
48
|
+
offset: number;
|
|
49
|
+
};
|
|
50
|
+
focus: {
|
|
51
|
+
block: Block;
|
|
52
|
+
offset: number;
|
|
53
|
+
};
|
|
54
|
+
} | null;
|
|
55
|
+
/**
|
|
56
|
+
* Put a selection given as model points (see {@link livePoints}) on the rendered DOM, direction included. Offsets are clamped to
|
|
57
|
+
* the text. Does nothing when a block has no DOM point (not rendered).
|
|
58
|
+
* @param {Nabu} nabu
|
|
59
|
+
* @param {{ anchor: { block: Block, offset: number }, focus: { block: Block, offset: number } }} points
|
|
60
|
+
* @returns {boolean} whether the selection was placed
|
|
61
|
+
*/
|
|
62
|
+
export function placePoints(nabu: Nabu, { anchor, focus }: {
|
|
63
|
+
anchor: {
|
|
64
|
+
block: Block;
|
|
65
|
+
offset: number;
|
|
66
|
+
};
|
|
67
|
+
focus: {
|
|
68
|
+
block: Block;
|
|
69
|
+
offset: number;
|
|
70
|
+
};
|
|
71
|
+
}): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Capture the live DOM selection as an {@link UndoSelection}. The cursors are created on the CURRENT text, so call it while the
|
|
74
|
+
* model and the DOM agree and before the change to be undone is applied (see `Nabu#captureUndoSelection`).
|
|
75
|
+
* @param {Nabu} nabu
|
|
76
|
+
* @returns {UndoSelection | null} null when the selection is not in this editor
|
|
77
|
+
*/
|
|
78
|
+
export function captureSelection(nabu: Nabu): UndoSelection | null;
|
|
79
|
+
/**
|
|
80
|
+
* A caret decided by a caller (a block shortcut puts it right after the typed trigger): plain block + offset, no cursors
|
|
81
|
+
* (the text it refers to is not the one the change is applied on).
|
|
82
|
+
* @param {Block} block
|
|
83
|
+
* @param {number} offset
|
|
84
|
+
* @returns {UndoSelection}
|
|
85
|
+
*/
|
|
86
|
+
export function explicitSelection(block: Block, offset: number): UndoSelection;
|
|
87
|
+
/**
|
|
88
|
+
* The caret the selection state reports, when the DOM selection could not be captured (no DOM selection: a blurred editor, a
|
|
89
|
+
* test environment). No cursors.
|
|
90
|
+
* @param {Nabu} nabu
|
|
91
|
+
* @returns {UndoSelection | null}
|
|
92
|
+
*/
|
|
93
|
+
export function legacySelection(nabu: Nabu): UndoSelection | null;
|
|
94
|
+
/**
|
|
95
|
+
* Offset an endpoint stands at NOW. A cursor whose character was deleted (`update` set) is the one to distrust; of the
|
|
96
|
+
* two cursors, the live one wins — for two live ones the role decides (a range start sticks to the character before it).
|
|
97
|
+
* Both dead: the position of the tombstones, unless the text has the very length it had when the endpoint was captured — the
|
|
98
|
+
* characters around it were then deleted and re-created by an undo / redo of the action (typing over a range: the caret between
|
|
99
|
+
* the typed character and the merged tail, and both are new characters after the redo), and the stored offset is the right one.
|
|
100
|
+
* @param {LoroDoc} doc
|
|
101
|
+
* @param {Endpoint} ep
|
|
102
|
+
* @param {number} length current length of the text
|
|
103
|
+
* @returns {number | null} null when no cursor resolves (use the stored offset)
|
|
104
|
+
*/
|
|
105
|
+
export function resolveOffset(doc: LoroDoc, ep: Endpoint, length: number): number | null;
|
|
106
|
+
/**
|
|
107
|
+
* Put the stored selection back, after the undo / redo has re-rendered, then scroll it into view. A block recreated by the undo
|
|
108
|
+
* may not be rendered yet: retried a few ticks.
|
|
109
|
+
* @param {Nabu} nabu
|
|
110
|
+
* @param {UndoSelection} snap
|
|
111
|
+
* @param {number} [attempt]
|
|
112
|
+
* @param {boolean} [reveal] scroll the focus end into view (default); `false` for a change the user did not make (a remote import)
|
|
113
|
+
*/
|
|
114
|
+
export function restoreSelection(nabu: Nabu, snap: UndoSelection, attempt?: number, reveal?: boolean): void;
|
|
115
|
+
/**
|
|
116
|
+
* Keep the live selection on the characters it was on: after a change the user did not make in a block holding one of its ends
|
|
117
|
+
* (a programmatic edit, a collaborator's), the DOM selection is put back where the stored endpoints (Loro cursors) now stand,
|
|
118
|
+
* if it is anywhere else. Svelte rewrites the text node of an edited block, which sends the end of a DOM range to offset 0 of it
|
|
119
|
+
* (P-109). Does nothing when there is no live selection in the editor, when a block of the snapshot is gone, or when the
|
|
120
|
+
* selection is already right. Never scrolls.
|
|
121
|
+
* @param {Nabu} nabu
|
|
122
|
+
* @param {UndoSelection} snap the selection BEFORE the change
|
|
123
|
+
* @returns {boolean} whether the selection was moved
|
|
124
|
+
*/
|
|
125
|
+
export function keepSelection(nabu: Nabu, snap: UndoSelection): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Scroll the moving end of the selection into view, "nearest": nothing moves when it is already visible (in the window and in
|
|
128
|
+
* the scroll container that holds the editor).
|
|
129
|
+
* @param {Block} block the block holding the focus end (its element is the fallback target)
|
|
130
|
+
*/
|
|
131
|
+
export function revealFocus(block: Block): void;
|
|
132
|
+
/**
|
|
133
|
+
* One end of a stored selection.
|
|
134
|
+
*/
|
|
135
|
+
export type Endpoint = {
|
|
136
|
+
blockId: string;
|
|
137
|
+
/**
|
|
138
|
+
* child index at each level, root first (see {@link blockPath})
|
|
139
|
+
*/
|
|
140
|
+
path: number[];
|
|
141
|
+
/**
|
|
142
|
+
* model offset when captured: the fallback when no cursor can be used
|
|
143
|
+
*/
|
|
144
|
+
offset: number;
|
|
145
|
+
/**
|
|
146
|
+
* length of the block's text when captured (see {@link resolveOffset}: both cursors dead)
|
|
147
|
+
*/
|
|
148
|
+
length?: number | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* id of the block's text container the cursors belong to
|
|
151
|
+
*/
|
|
152
|
+
container: string | null;
|
|
153
|
+
/**
|
|
154
|
+
* the first end of a range sticks to the character before it, every other end to the one after
|
|
155
|
+
*/
|
|
156
|
+
role: "start" | "end";
|
|
157
|
+
/**
|
|
158
|
+
* encoded Loro cursor (the UndoManager serializes what it stores: a live Cursor would not survive)
|
|
159
|
+
*/
|
|
160
|
+
next: Uint8Array | null;
|
|
161
|
+
prev: Uint8Array | null;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* The selection stored with an undo / redo step.
|
|
165
|
+
*/
|
|
166
|
+
export type UndoSelection = {
|
|
167
|
+
anchor: Endpoint;
|
|
168
|
+
/**
|
|
169
|
+
* Equal to `anchor` for a caret. The direction of a backward selection is kept by which end is which.
|
|
170
|
+
*/
|
|
171
|
+
focus: Endpoint;
|
|
172
|
+
};
|
|
173
|
+
import type { Block } from './block.svelte.js';
|
|
174
|
+
import type { Nabu } from './nabu.svelte.js';
|
|
175
|
+
import type { LoroDoc } from 'loro-crdt';
|