@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,21 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { Nabu, NabuNode } from "./nabu.svelte.js";
|
|
3
3
|
* @import { MegaBlock } from "./megablock.svelte.js";
|
|
4
|
-
* @import { VariableInit } from "./variable.svelte.js";
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { tick } from "svelte";
|
|
8
7
|
import { SvelteMap, SvelteSet } from "svelte/reactivity";
|
|
9
|
-
import {
|
|
8
|
+
import { resolvePlaceholderText } from "../utils/placeholders.js";
|
|
10
9
|
|
|
11
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The first descendant of `block`, depth first in document order, that satisfies `predicate` (the block itself is not
|
|
13
|
+
* tested). Does not enter a block that hides its children. Each node is visited once.
|
|
14
|
+
* @param {Block} block @param {(block: Block) => boolean} predicate @returns {Block | null}
|
|
15
|
+
*/
|
|
16
|
+
function findInDescendants(block, predicate) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const children = block.children;
|
|
19
|
+
if (!children?.length || block.hidesChildren) return null;
|
|
20
|
+
for (const child of children) {
|
|
21
|
+
if (predicate(child)) return child;
|
|
22
|
+
const found = findInDescendants(child, predicate);
|
|
23
|
+
if (found) return found;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The base class of every block. A block wraps a node of the document tree (Loro) and holds the behaviour of one block type: the capability flags, the tree accessors, and the handlers for typing, keys, splitting, merging, pasting and serialization that a subclass overrides.
|
|
31
|
+
*/
|
|
12
32
|
export class Block {
|
|
13
33
|
/** @param {Nabu} nabu @param {NabuNode} node */
|
|
14
34
|
constructor(nabu, node) {
|
|
35
|
+
/**
|
|
36
|
+
* The editor this block belongs to.
|
|
37
|
+
* @type {Nabu}
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
15
40
|
this.nabu = nabu;
|
|
41
|
+
/**
|
|
42
|
+
* The block's node in the document tree (Loro): `node.data` holds its `type` and props, `node.parent()` / `node.children()` the structure.
|
|
43
|
+
* @type {NabuNode}
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
16
46
|
this.node = node;
|
|
17
47
|
const metadata = node.data;
|
|
18
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The Loro tree id of the node (also the key in `nabu.blocks`).
|
|
50
|
+
* @type {import('loro-crdt').TreeID}
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
this.id = /** @type {import('loro-crdt').TreeID} */ (node.id.toString());
|
|
54
|
+
/**
|
|
55
|
+
* The block type, as registered by its extension (`'paragraph'`, `'callout'`...). Read from the node when the block is built; `retype()` changes the node, and the engine builds a new block.
|
|
56
|
+
* @type {string}
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
19
59
|
this.type = metadata.get("type") || "block";
|
|
20
60
|
this.nabu.blocks.set(this.id, this);
|
|
21
61
|
const blocksOfType = this.nabu.blocksByType.get(this.type) || new SvelteSet();
|
|
@@ -26,42 +66,48 @@ export class Block {
|
|
|
26
66
|
|
|
27
67
|
const parent = node.parent();
|
|
28
68
|
if (parent) {
|
|
29
|
-
this.parent = this.nabu.blocks.get(parent.id.toString()) || null;
|
|
69
|
+
this.parent = /** @type {MegaBlock | null} */ (this.nabu.blocks.get(parent.id.toString()) || null);
|
|
30
70
|
}
|
|
31
71
|
}
|
|
32
72
|
|
|
33
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Serializers of this block by format: `'markdown'`, `'json'`, `'application/x-nabu+json'` (the clipboard) or one of your own.
|
|
75
|
+
* Each receives the context of the call (`{ from, to, partial }` for the clipboard) and returns the serialized block.
|
|
76
|
+
* @type {SvelteMap<string, function(any): any>}
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
34
79
|
serializers = new SvelteMap();
|
|
35
|
-
behaviors = new SvelteMap();
|
|
36
|
-
/** @type {SvelteMap<string, Variable<this>>} */
|
|
37
|
-
variables = new SvelteMap();
|
|
38
|
-
|
|
39
80
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
43
|
-
* @returns {Variable<this>}
|
|
81
|
+
* The behaviors of the block by name; a text block has `'text'` (a `TextBehavior`).
|
|
82
|
+
* @type {SvelteMap<string, any>}
|
|
83
|
+
* @public
|
|
44
84
|
*/
|
|
45
|
-
|
|
46
|
-
const variable = new Variable(this, name, init);
|
|
47
|
-
return variable;
|
|
48
|
-
}
|
|
85
|
+
behaviors = new SvelteMap();
|
|
49
86
|
|
|
50
87
|
|
|
88
|
+
/** The selection covers this block (reactive). @public */
|
|
51
89
|
selected = $state(false);
|
|
90
|
+
/** The selection starts in this block (reactive). @public */
|
|
52
91
|
isSelectionStart = $state(false);
|
|
92
|
+
/** The selection ends in this block (reactive). @public */
|
|
53
93
|
isSelectionEnd = $state(false);
|
|
94
|
+
/** The selection covers this block and neither starts nor ends in it (reactive). @public */
|
|
54
95
|
isIntermediate = $derived(this.selected && !this.isSelectionStart && !this.isSelectionEnd);
|
|
55
96
|
|
|
97
|
+
/** @public */
|
|
56
98
|
clearSelection() {
|
|
57
99
|
this.selected = false;
|
|
58
100
|
this.isSelectionStart = false;
|
|
59
101
|
this.isSelectionEnd = false;
|
|
60
102
|
}
|
|
61
103
|
|
|
62
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* @type {{from: number, to: number, direction: "forward" | "backward" | "none"} | null}
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
63
108
|
selection = $derived(null);
|
|
64
109
|
|
|
110
|
+
/** @public */
|
|
65
111
|
positions = $derived(0);
|
|
66
112
|
|
|
67
113
|
/**
|
|
@@ -69,18 +115,60 @@ export class Block {
|
|
|
69
115
|
* (own text) and containers (sum of children) so that parents can
|
|
70
116
|
* aggregate without re-traversing the whole subtree.
|
|
71
117
|
* @type {number}
|
|
118
|
+
* @public
|
|
72
119
|
*/
|
|
73
120
|
wordCount = $derived(0);
|
|
74
121
|
|
|
75
122
|
// ── Capability flags ─────────────────────────────────────────────────────
|
|
76
123
|
// Declarative opt-outs respected centrally by the engine. Default true;
|
|
77
124
|
// override to false in a subclass (e.g. CodeBlock) to disable a behavior.
|
|
78
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* When false, Enter inserts a literal "\n" in place instead of splitting the block.
|
|
127
|
+
* @type {boolean}
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
79
130
|
splitsOnEnter = true;
|
|
80
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* When false, onBeforeInput markdown-shortcut hooks and inputRules are skipped in this block.
|
|
133
|
+
* @type {boolean}
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
81
136
|
transformsEnabled = true;
|
|
82
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* When false, inline marks (bold/italic/...) are never applied to this block.
|
|
139
|
+
* @type {boolean}
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
83
142
|
marksEnabled = true;
|
|
143
|
+
/**
|
|
144
|
+
* True when the block currently hides its children (they are not rendered, e.g. a collapsed
|
|
145
|
+
* foldable block): navigation (`findForward` / `findBackward` / `findLastDescendant`, caret
|
|
146
|
+
* normalisation) never enters them. Override with a getter in a subclass.
|
|
147
|
+
* @type {boolean}
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
get hidesChildren() { return false; }
|
|
151
|
+
/**
|
|
152
|
+
* When true, the text of this block is an ISOLATED FIELD (like a form input embedded in the document): a text selection
|
|
153
|
+
* that does not lie entirely inside this block never touches its text. For such a selection (the engine's rules, see
|
|
154
|
+
* `container.utils.js`, `selection.svelte.js`):
|
|
155
|
+
* - range deletion, typing over it, cut and the marks skip the text of this block, and delete neither this block nor its
|
|
156
|
+
* container; the clipboard gets the TEXT blocks only (the block's own text and its container are not copied);
|
|
157
|
+
* - two text blocks on either side of an isolated block, or in different "isolation owners" (the nearest ancestor that
|
|
158
|
+
* isolates), never merge, so a deletion across them clears both sides without joining them;
|
|
159
|
+
* - the block is not highlighted (`data-nabu-isolated` + the root's `data-nabu-range`), and a selection end that would
|
|
160
|
+
* land in it is moved past it, in the direction of travel; a selection that STARTS in it stays bounded to it;
|
|
161
|
+
* - the caret enters it at its start going down / right, at its end going up / left; Select All inside it selects its text.
|
|
162
|
+
* @type {boolean}
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
isolatesSelection = false;
|
|
166
|
+
/**
|
|
167
|
+
* When true, pasting inside this block inserts the clipboard's text/plain verbatim (replacing the selection), skipping every paste interpreter: no blocks created, no markdown/HTML interpretation.
|
|
168
|
+
* @type {boolean}
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
pastesAsPlainText = false;
|
|
84
172
|
|
|
85
173
|
/**
|
|
86
174
|
* Resolve a document-local offset to { block, offset } within this block.
|
|
@@ -88,19 +176,31 @@ export class Block {
|
|
|
88
176
|
* Override in MegaBlock (pure containers) and mixed blocks (e.g. ListItem).
|
|
89
177
|
* @param {number} localOffset
|
|
90
178
|
* @returns {{ block: Block, offset: number } | null}
|
|
179
|
+
* @public
|
|
91
180
|
*/
|
|
92
181
|
resolveOffset(localOffset) {
|
|
93
182
|
return { block: this, offset: localOffset };
|
|
94
183
|
}
|
|
95
184
|
|
|
96
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* @type {MegaBlock | null}
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
97
189
|
parent = $state(null);
|
|
190
|
+
/** @public */
|
|
98
191
|
index = $state(0);
|
|
99
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* @type {Block?}
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
100
196
|
previous = $derived(this.index > 0 && this.parent ? this.parent.children[this.index - 1] : null);
|
|
101
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* @type {Block?}
|
|
199
|
+
* @public
|
|
200
|
+
*/
|
|
102
201
|
next = $derived(this.parent && this.index < this.parent.children.length - 1 ? this.parent.children[this.index + 1] : null);
|
|
103
202
|
|
|
203
|
+
/** @public */
|
|
104
204
|
parents = $derived.by(() => {
|
|
105
205
|
const parents = [];
|
|
106
206
|
let current = this.parent;
|
|
@@ -111,25 +211,57 @@ export class Block {
|
|
|
111
211
|
return parents;
|
|
112
212
|
});
|
|
113
213
|
|
|
214
|
+
/** @public */
|
|
114
215
|
component = $derived(this.nabu.components.get(this.type) || null);
|
|
115
216
|
|
|
116
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Resolved placeholder to render in `data-placeholder` ('' = none). Combines the
|
|
219
|
+
* Nabu `placeholders` option, the block's emptiness and — with `show: 'focus'`
|
|
220
|
+
* (default) — whether it holds the collapsed cursor.
|
|
221
|
+
*
|
|
222
|
+
* The default text is declared by each block class as `static placeholder`
|
|
223
|
+
* (string, `false`, or `(block) => string | false`), overridable per type through
|
|
224
|
+
* the `placeholders.text` option. Blocks without a text behavior never show one.
|
|
225
|
+
* (No `static placeholder` is declared here: Svelte forbids a static and a
|
|
226
|
+
* reactive field with the same name in one class.)
|
|
227
|
+
* @type {string}
|
|
228
|
+
* @public
|
|
229
|
+
*/
|
|
230
|
+
placeholder = $derived.by(() => {
|
|
231
|
+
const config = this.nabu.placeholders;
|
|
232
|
+
if (!config.enabled) return '';
|
|
233
|
+
const text = this.behaviors.get("text");
|
|
234
|
+
if (!text || text.text) return '';
|
|
235
|
+
// The composed text is on screen (the model only catches up at compositionend): a placeholder would overlap it.
|
|
236
|
+
if (this.nabu.composingBlock === this) return '';
|
|
237
|
+
if (config.show === 'focus') {
|
|
238
|
+
const sel = this.nabu.selection;
|
|
239
|
+
if (!sel.isCollapsed || sel.anchorBlock !== this) return '';
|
|
240
|
+
}
|
|
241
|
+
return resolvePlaceholderText(/** @type {any} */ (this), config.text);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @type {HTMLElement | null}
|
|
246
|
+
* @public
|
|
247
|
+
*/
|
|
117
248
|
element = $state(null);
|
|
118
249
|
|
|
119
|
-
/**
|
|
250
|
+
/**
|
|
251
|
+
* The next block in document order (own descendants first, then the following siblings with their descendants, then
|
|
252
|
+
* those of each ancestor) that satisfies `predicate`, or null. A block that hides its children is not entered.
|
|
253
|
+
* LINEAR: every block is visited at most once (the following siblings are only DESCENDED into, never searched
|
|
254
|
+
* "forward" again, which would revisit everything after them).
|
|
255
|
+
* @param {(block: Block) => boolean} predicate @returns {Block | null}
|
|
256
|
+
* @public
|
|
257
|
+
*/
|
|
120
258
|
findForward(predicate) {
|
|
121
|
-
// 1.
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
for (const child of this.children) {
|
|
126
|
-
if (predicate(child)) return child;
|
|
127
|
-
const found = child.findForward(predicate);
|
|
128
|
-
if (found) return found;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
259
|
+
// 1. Descendre dans nos propres enfants
|
|
260
|
+
const inside = findInDescendants(this, predicate);
|
|
261
|
+
if (inside) return inside;
|
|
131
262
|
|
|
132
|
-
// 2.
|
|
263
|
+
// 2. Frères suivants (eux et leurs descendants), puis remonter d'un niveau
|
|
264
|
+
/** @type {Block | null} */
|
|
133
265
|
let current = this;
|
|
134
266
|
while (current) {
|
|
135
267
|
const parent = current.parent || current.nabu;
|
|
@@ -138,7 +270,7 @@ export class Block {
|
|
|
138
270
|
for (let j = i + 1; j < parent.children.length; j++) {
|
|
139
271
|
const sibling = parent.children[j];
|
|
140
272
|
if (predicate(sibling)) return sibling;
|
|
141
|
-
const found = sibling
|
|
273
|
+
const found = findInDescendants(sibling, predicate);
|
|
142
274
|
if (found) return found;
|
|
143
275
|
}
|
|
144
276
|
}
|
|
@@ -147,8 +279,13 @@ export class Block {
|
|
|
147
279
|
return null;
|
|
148
280
|
}
|
|
149
281
|
|
|
150
|
-
/**
|
|
282
|
+
/**
|
|
283
|
+
* @param {(block: Block) => boolean} predicate
|
|
284
|
+
* @returns {Block | null}
|
|
285
|
+
* @public
|
|
286
|
+
*/
|
|
151
287
|
findBackward(predicate) {
|
|
288
|
+
/** @type {Block | null} */
|
|
152
289
|
let current = this;
|
|
153
290
|
while (current) {
|
|
154
291
|
const parent = current.parent || current.nabu;
|
|
@@ -161,7 +298,7 @@ export class Block {
|
|
|
161
298
|
|
|
162
299
|
// Si le frère a des enfants, le "précédent" est le DERNIER de ses descendants
|
|
163
300
|
// @ts-ignore
|
|
164
|
-
if (sibling.children?.length) {
|
|
301
|
+
if (sibling.children?.length && !sibling.hidesChildren) {
|
|
165
302
|
// @ts-ignore
|
|
166
303
|
const lastDescendant = sibling.findLastDescendant(predicate);
|
|
167
304
|
if (lastDescendant) return lastDescendant;
|
|
@@ -184,6 +321,7 @@ export class Block {
|
|
|
184
321
|
|
|
185
322
|
/**
|
|
186
323
|
* Returns real, uncommitted siblings, which is useful for extensions that want to check the document structure before the transaction is committed.
|
|
324
|
+
* @public
|
|
187
325
|
*/
|
|
188
326
|
getAdjacentSiblings() {
|
|
189
327
|
const parent = this.node.parent();
|
|
@@ -210,10 +348,11 @@ export class Block {
|
|
|
210
348
|
* Helper pour trouver le dernier descendant profond qui matche
|
|
211
349
|
* @param {(block: Block) => boolean} predicate
|
|
212
350
|
* @returns {Block | null}
|
|
351
|
+
* @public
|
|
213
352
|
*/
|
|
214
353
|
findLastDescendant(predicate) {
|
|
215
354
|
// @ts-ignore
|
|
216
|
-
const children = this.children || [];
|
|
355
|
+
const children = this.hidesChildren ? [] : (this.children || []);
|
|
217
356
|
for (let i = children.length - 1; i >= 0; i--) {
|
|
218
357
|
const child = children[i];
|
|
219
358
|
const found = child.findLastDescendant(predicate);
|
|
@@ -223,6 +362,7 @@ export class Block {
|
|
|
223
362
|
return null;
|
|
224
363
|
}
|
|
225
364
|
|
|
365
|
+
/** @public */
|
|
226
366
|
destroy() {
|
|
227
367
|
this.nabu.delete(this);
|
|
228
368
|
}
|
|
@@ -230,35 +370,64 @@ export class Block {
|
|
|
230
370
|
/**
|
|
231
371
|
* Transforme ce bloc en un autre type de bloc.
|
|
232
372
|
* @param {string} newType
|
|
233
|
-
* @param {
|
|
373
|
+
* @param {Record<string, any>} [props={}]
|
|
374
|
+
* @public
|
|
234
375
|
*/
|
|
235
376
|
transformTo(newType, props = {}) {
|
|
377
|
+
this.retype(newType, props);
|
|
378
|
+
this.commit();
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* The mutations of a type change, without the commit: the caller owns the transaction
|
|
383
|
+
* (`transformTo`, the `block:transform` action…). By default the block is retyped IN PLACE (same node:
|
|
384
|
+
* its id, text and position survive). Override it when a block cannot simply change type where it
|
|
385
|
+
* stands (e.g. because its parent only accepts some children): do the same job with Loro mutations only.
|
|
386
|
+
* @param {string} newType
|
|
387
|
+
* @param {Record<string, any>} [props={}]
|
|
388
|
+
* @public
|
|
389
|
+
*/
|
|
390
|
+
retype(newType, props = {}) {
|
|
236
391
|
const data = this.node.data;
|
|
237
392
|
data.set("type", newType);
|
|
238
393
|
for (const [key, value] of Object.entries(props)) {
|
|
239
394
|
data.set(key, value);
|
|
240
395
|
}
|
|
241
|
-
this.commit();
|
|
242
396
|
}
|
|
243
397
|
|
|
244
|
-
/**
|
|
398
|
+
/**
|
|
399
|
+
* @param {number} index
|
|
400
|
+
* @param {string} text
|
|
401
|
+
* @public
|
|
402
|
+
*/
|
|
245
403
|
insert(index, text) {
|
|
246
404
|
this.nabu.warn("Not implemented: insert text", text, "at index", index, "in block", this.id);
|
|
247
405
|
}
|
|
248
406
|
|
|
249
|
-
/**
|
|
407
|
+
/**
|
|
408
|
+
* @param {{from?: number, to?: number, index?: number, length?: number}} [deletion]
|
|
409
|
+
* @public
|
|
410
|
+
*/
|
|
250
411
|
delete(deletion) {
|
|
251
412
|
this.nabu.warn("Not implemented: delete block", this.id, "with deletion range", deletion);
|
|
252
413
|
}
|
|
253
414
|
|
|
254
|
-
/**
|
|
415
|
+
/**
|
|
416
|
+
* @param {Block} block
|
|
417
|
+
* @returns {any}
|
|
418
|
+
* @public
|
|
419
|
+
*/
|
|
255
420
|
absorbs(block) {
|
|
256
421
|
this.nabu.warn("Not implemented: check if block", this.id, "absorbs block", block.id);
|
|
257
422
|
return false;
|
|
258
423
|
}
|
|
259
424
|
|
|
260
425
|
|
|
261
|
-
/**
|
|
426
|
+
/**
|
|
427
|
+
* @param {Block} block
|
|
428
|
+
* @returns {any}
|
|
429
|
+
* @public
|
|
430
|
+
*/
|
|
262
431
|
mergeWith(block) {
|
|
263
432
|
const success = this.absorbs(block);
|
|
264
433
|
if (success) {
|
|
@@ -273,6 +442,7 @@ export class Block {
|
|
|
273
442
|
* @param {Block} otherBlock - The block to consume or be consumed by
|
|
274
443
|
* @param {'into' | 'from'} direction - 'into' = this merges into other, 'from' = other merges into this
|
|
275
444
|
* @returns {Block} The surviving block
|
|
445
|
+
* @public
|
|
276
446
|
*/
|
|
277
447
|
consume(otherBlock, direction = 'from') {
|
|
278
448
|
const [survivor, victim] = direction === 'into'
|
|
@@ -313,16 +483,61 @@ export class Block {
|
|
|
313
483
|
* Override in subclasses (e.g. ListItem requires a "list" parent).
|
|
314
484
|
* Used by wrapOrphan() after block relocations.
|
|
315
485
|
* @returns {{ type: string, props: () => Record<string, any> } | null}
|
|
486
|
+
* @public
|
|
316
487
|
*/
|
|
317
488
|
get requiredParent() { return null; }
|
|
318
489
|
|
|
319
|
-
/**
|
|
490
|
+
/**
|
|
491
|
+
* Whether an EMPTY child of this block takes the type of a whole block pasted into it (a `# Title` pasted
|
|
492
|
+
* into an empty paragraph makes it a heading). Always true for root blocks; a container with structural
|
|
493
|
+
* rules about its children (a list) keeps it `false`, a container with a free-form body (a toggle) opts in.
|
|
494
|
+
* @returns {boolean}
|
|
495
|
+
* @public
|
|
496
|
+
*/
|
|
497
|
+
get adoptsPastedTypes() { return false; }
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Paste extension point: lets the block that holds the caret decide how a pasted fragment lands, instead
|
|
501
|
+
* of the engine's default (first block merged into the caret block, the rest inserted after it as
|
|
502
|
+
* siblings). A block that lives in a container with its own rules about what it can hold overrides it
|
|
503
|
+
* (e.g. a list item turns pasted paragraphs into siblings items and splits its list around a block it
|
|
504
|
+
* cannot hold). The engine has already removed the selection; it commits the whole paste as ONE
|
|
505
|
+
* transaction (one undo step) and puts the caret at the returned point.
|
|
506
|
+
*
|
|
507
|
+
* Contract: return null to DECLINE, and then touch nothing (the default insertion runs). Otherwise
|
|
508
|
+
* apply the whole paste on the tree (the blocks are created through `nabu.createPasteBlock` /
|
|
509
|
+
* `nabu.insertPasteBlock`), do NOT commit, and return where the caret goes.
|
|
510
|
+
* @param {import('../utils/extensions.js').PasteBlock[]} blocks the sanitized fragment
|
|
511
|
+
* @param {{ offset: number }} ctx the caret offset in this block's text
|
|
512
|
+
* @returns {{ block: Block | null, offset: number } | null} `block: null` leaves the caret to the engine
|
|
513
|
+
* @public
|
|
514
|
+
*/
|
|
515
|
+
acceptPaste(blocks, ctx) { return null; }
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* The blocks that travel together when THIS block is dragged by its handle (P-81): this block and anything the drag must carry
|
|
519
|
+
* with it, in document order, all in the same parent. The default is the block alone (a container carries its own children:
|
|
520
|
+
* they are its tree children). A block whose "extent" is not its subtree overrides it (an extension may widen the range). The drop rules are the same for any range: it cannot land inside itself.
|
|
521
|
+
* @returns {Block[]}
|
|
522
|
+
* @public
|
|
523
|
+
*/
|
|
524
|
+
dragRange() { return [this]; }
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* @param {{from?: number, to?: number, index?: number, length?: number, offset?: number}} options
|
|
528
|
+
* @returns {{block: Block} | null}
|
|
529
|
+
* @public
|
|
530
|
+
*/
|
|
320
531
|
split(options) {
|
|
321
532
|
this.nabu.warn("Not implemented: split block", this.id, "with options", options);
|
|
322
533
|
return null;
|
|
323
534
|
}
|
|
324
535
|
|
|
325
|
-
/**
|
|
536
|
+
/**
|
|
537
|
+
* @param {{start?: number, end?: number, offset?: number} | null } options
|
|
538
|
+
* @param {boolean} [passive=false]
|
|
539
|
+
* @public
|
|
540
|
+
*/
|
|
326
541
|
focus(options = {}, passive = false) {
|
|
327
542
|
let start = options?.start ?? options?.offset ?? this.selection?.from ?? 0;
|
|
328
543
|
let end = options?.end ?? options?.offset ?? this.selection?.to ?? 0;
|
|
@@ -340,6 +555,7 @@ export class Block {
|
|
|
340
555
|
/**
|
|
341
556
|
* @param {number} offset
|
|
342
557
|
* @returns {{node: Node, offset: number} | null}
|
|
558
|
+
* @public
|
|
343
559
|
*/
|
|
344
560
|
getDOMPoint(offset) {
|
|
345
561
|
this.nabu.warn("getDOMPoint not implemented for block", this.type, this.id);
|
|
@@ -348,17 +564,34 @@ export class Block {
|
|
|
348
564
|
|
|
349
565
|
// -- Event Handling --
|
|
350
566
|
|
|
351
|
-
/**
|
|
567
|
+
/**
|
|
568
|
+
* @param {string} eventName
|
|
569
|
+
* @param {Event | null} event
|
|
570
|
+
* @param {Object} [data={}]
|
|
571
|
+
* @public
|
|
572
|
+
*/
|
|
352
573
|
ascend(eventName, event, data = {}) {
|
|
353
574
|
//@ts-ignore
|
|
354
575
|
if (this.parent && typeof this.parent[eventName] === "function") {
|
|
576
|
+
// A container handles the event for its children; a falsy result DECLINES it (e.g. a toggle only
|
|
577
|
+
// takes the Enter that exits its body), and the registered hooks below get their turn.
|
|
355
578
|
//@ts-ignore
|
|
356
|
-
|
|
579
|
+
const handled = this.parent[eventName](event, { ...data, from: this });
|
|
580
|
+
if (handled) return handled;
|
|
357
581
|
}
|
|
358
582
|
|
|
359
583
|
// 2. On essaye les hooks d'extensions enregistrés dans Nabu
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
584
|
+
const registered = /** @type {Function[] | undefined} */ (this.nabu.hooks.get(eventName));
|
|
585
|
+
if (registered) {
|
|
586
|
+
// A hook registered by the extension that owns this block's type runs BEFORE the generic ones
|
|
587
|
+
// (extension order must not let a catch-all hook shadow a block-specific handler).
|
|
588
|
+
const owners = this.nabu.hookOwners;
|
|
589
|
+
const hooks = owners
|
|
590
|
+
? [
|
|
591
|
+
...registered.filter(h => owners.get(h) === this.type),
|
|
592
|
+
...registered.filter(h => owners.get(h) !== this.type),
|
|
593
|
+
]
|
|
594
|
+
: registered;
|
|
362
595
|
for (const hook of hooks) {
|
|
363
596
|
|
|
364
597
|
// Si un hook retourne 'true', on considère l'événement géré
|
|
@@ -370,24 +603,37 @@ export class Block {
|
|
|
370
603
|
return false;
|
|
371
604
|
}
|
|
372
605
|
|
|
373
|
-
/**
|
|
606
|
+
/**
|
|
607
|
+
* @param {InputEvent} event
|
|
608
|
+
* @returns {any}
|
|
609
|
+
* @public
|
|
610
|
+
*/
|
|
374
611
|
beforeinput(event) {
|
|
375
612
|
// On peut intercepter les événements d'input ici pour faire des choses comme :
|
|
376
613
|
}
|
|
377
614
|
|
|
378
|
-
/**
|
|
615
|
+
/**
|
|
616
|
+
* @param {KeyboardEvent} event
|
|
617
|
+
* @returns {any}
|
|
618
|
+
* @public
|
|
619
|
+
*/
|
|
379
620
|
keydown(event) {
|
|
380
621
|
// Intercepter les touches spéciales (Tab, Enter, flèches)
|
|
381
622
|
}
|
|
382
623
|
|
|
383
624
|
// -- UTILS --
|
|
384
625
|
|
|
626
|
+
/** @public */
|
|
385
627
|
commit() {
|
|
386
628
|
return this.nabu.commit();
|
|
387
629
|
}
|
|
388
630
|
|
|
389
631
|
|
|
390
|
-
/**
|
|
632
|
+
/**
|
|
633
|
+
* @param {string} format
|
|
634
|
+
* @param {Record<string, any>} [context]
|
|
635
|
+
* @public
|
|
636
|
+
*/
|
|
391
637
|
serialize(format, context = {}) {
|
|
392
638
|
const serializer = this.serializers.get(format);
|
|
393
639
|
if (serializer) {
|
|
@@ -399,7 +645,11 @@ export class Block {
|
|
|
399
645
|
}
|
|
400
646
|
|
|
401
647
|
|
|
402
|
-
/**
|
|
648
|
+
/**
|
|
649
|
+
* @param {Nabu} nabu
|
|
650
|
+
* @param {NabuNode} node
|
|
651
|
+
* @public
|
|
652
|
+
*/
|
|
403
653
|
static load(nabu, node) {
|
|
404
654
|
const metadata = node.data;
|
|
405
655
|
const type = metadata.get("type") || "block";
|
|
@@ -408,12 +658,73 @@ export class Block {
|
|
|
408
658
|
return block;
|
|
409
659
|
}
|
|
410
660
|
|
|
411
|
-
/**
|
|
661
|
+
/**
|
|
662
|
+
* @param {Nabu} nabu
|
|
663
|
+
* @param {string} type
|
|
664
|
+
* @param {Record<string, any>} [props={}]
|
|
665
|
+
* @param {string|null} [parentId=null]
|
|
666
|
+
* @param {number|null} [index=null]
|
|
667
|
+
* @public
|
|
668
|
+
*/
|
|
412
669
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
413
|
-
const node = nabu.tree.createNode(parentId || undefined, index
|
|
670
|
+
const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
|
|
414
671
|
node.data.set("type", type);
|
|
415
672
|
const block = Block.load(nabu, node);
|
|
416
673
|
return block;
|
|
417
674
|
}
|
|
418
675
|
|
|
676
|
+
// ── Static contract: clipboard, markdown and HTML ────────────────────────────────────────────────────────────────
|
|
677
|
+
// Optional members a block class declares to take part in paste, `importMarkdown` and the clipboard / `serialize` output. Not
|
|
678
|
+
// defined here (they default to `undefined`); the engine looks them up on the registered class. The built-ins (`Blockquote`,
|
|
679
|
+
// `Divider`, `Heading`...) are the model. They work on `PasteBlock`s (plain data), never on live blocks.
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Which HTML elements this block reads on paste (see {@link HtmlRule}). Declare it together with `fromHTML`.
|
|
683
|
+
* @type {import('../utils/extensions.js').HtmlRule[] | undefined}
|
|
684
|
+
* @public
|
|
685
|
+
*/
|
|
686
|
+
static htmlRules = undefined;
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Make the block(s) of an element matched by one of `htmlRules`; `null` / `[]` declines. `siblings` are the following
|
|
690
|
+
* elements `htmlSiblings` claimed.
|
|
691
|
+
* @type {((el: Element, helpers: import('../utils/extensions.js').HtmlHelpers, rule: import('../utils/extensions.js').HtmlRule, siblings: Element[]) => import('../utils/extensions.js').PasteBlock | import('../utils/extensions.js').PasteBlock[] | null) | undefined}
|
|
692
|
+
* @public
|
|
693
|
+
*/
|
|
694
|
+
static fromHTML = undefined;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Ask to absorb the elements that follow `el` (a structure that spans several elements, a list in Google Docs); returns them in order.
|
|
698
|
+
* @type {((el: Element, rule: import('../utils/extensions.js').HtmlRule, helpers: import('../utils/extensions.js').HtmlHelpers) => Element[]) | undefined}
|
|
699
|
+
* @public
|
|
700
|
+
*/
|
|
701
|
+
static htmlSiblings = undefined;
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* How this block starts and how many lines it takes in markdown (see {@link MarkdownRule}). Declare it together with `fromMarkdown`.
|
|
705
|
+
* @type {import('../utils/extensions.js').MarkdownRule[] | undefined}
|
|
706
|
+
* @public
|
|
707
|
+
*/
|
|
708
|
+
static markdownRules = undefined;
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Make the block(s) of the lines a `markdownRules` rule consumed; `null` declines (the next rule is tried).
|
|
712
|
+
* @type {((lines: string[], helpers: import('../utils/extensions.js').MarkdownHelpers, rule: import('../utils/extensions.js').MarkdownRule) => import('../utils/extensions.js').PasteBlock | import('../utils/extensions.js').PasteBlock[] | null) | undefined}
|
|
713
|
+
* @public
|
|
714
|
+
*/
|
|
715
|
+
static fromMarkdown = undefined;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* The markdown of a block of this type, for the clipboard's `text/plain` and for containers that serialize their children.
|
|
719
|
+
* @type {((pb: import('../utils/extensions.js').PasteBlock, ctx: import('../utils/extensions.js').SerializeContext) => string) | undefined}
|
|
720
|
+
* @public
|
|
721
|
+
*/
|
|
722
|
+
static toMarkdown = undefined;
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* The HTML of a block of this type, for the clipboard's `text/html`.
|
|
726
|
+
* @type {((pb: import('../utils/extensions.js').PasteBlock, ctx: import('../utils/extensions.js').SerializeContext) => string) | undefined}
|
|
727
|
+
* @public
|
|
728
|
+
*/
|
|
729
|
+
static toHtml = undefined;
|
|
419
730
|
}
|