@aionbuilders/nabu 0.1.0-beta.0 → 0.1.1
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 +531 -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 +195 -55
- package/dist/behaviors/text/text.behavior.svelte.js +531 -103
- 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 +32 -18
- 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 +1753 -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 +35 -14
- 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 +55 -8
- 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/composition.d.ts +28 -0
- package/dist/utils/composition.js +51 -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 +48 -20
- 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 +42 -0
- package/dist/utils/words.js +147 -0
- package/dist/vite.d.ts +9 -3
- package/dist/vite.js +19 -8
- package/package.json +56 -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,38 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { Nabu, NabuNode } from "./nabu.svelte.js";
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* A block that holds child blocks (a container): list, list item, toggle, region. It keeps its `children` in sync with the tree and delegates positions, word count and event handling to them.
|
|
6
|
+
*/
|
|
4
7
|
export class MegaBlock extends Block {
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @type {Block[]}
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
public children: Block[];
|
|
13
|
+
/**
|
|
14
|
+
* @param {Set<string>} [retyped] ids whose `type` just changed; without it, the type of every child is checked
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
public updateChildren(retyped?: Set<string>): void;
|
|
18
|
+
/**
|
|
19
|
+
* @param {Block[]} children
|
|
20
|
+
* @param {number | null} [index]
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
public adoptChildren(children: Block[], index?: number | null): void;
|
|
10
24
|
/**
|
|
11
25
|
* Props to include in the clipboard representation of this container block.
|
|
12
|
-
* Override in subclasses that carry structural props (e.g. List
|
|
26
|
+
* Override in subclasses that carry structural props (e.g. List -> { listType }, ListItem -> { checked },
|
|
27
|
+
* Toggle -> { collapsed }).
|
|
28
|
+
* @returns {Record<string, any>}
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
public get clipboardProps(): Record<string, any>;
|
|
32
|
+
/**
|
|
33
|
+
* Clipboard props when the copied slice starts at `firstChildIndex` (the children before it are NOT copied).
|
|
34
|
+
* Containers whose props depend on their first copied child (an ordered list's `start`) override this.
|
|
35
|
+
* @param {number} firstChildIndex
|
|
13
36
|
* @returns {Record<string, any>}
|
|
37
|
+
* @public
|
|
14
38
|
*/
|
|
15
|
-
|
|
39
|
+
public clipboardPropsFrom(firstChildIndex: number): Record<string, any>;
|
|
16
40
|
/**
|
|
17
|
-
* Serializes the portion of this MegaBlock that falls within the given
|
|
18
|
-
* selection boundaries, recursively.
|
|
41
|
+
* Serializes the portion of this MegaBlock that falls within the given selection boundaries, recursively.
|
|
19
42
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
43
|
+
* The context carries the selection boundary blocks that belong to THIS subtree (`startBlock` / `endBlock`, null =
|
|
44
|
+
* the selection extends past this block on that side, i.e. it is fully selected on that side). Document order of a
|
|
45
|
+
* block is: own text (hybrid blocks only), then its children. So:
|
|
46
|
+
* - own text is copied unless the selection starts inside a child; it is clipped to `startFrom` when this block IS
|
|
47
|
+
* the start boundary, and to `endTo` when it IS the end boundary;
|
|
48
|
+
* - children are copied unless the selection ends in the own text; only those between the child holding the start
|
|
49
|
+
* boundary and the child holding the end boundary (inclusive) are kept, each one recursively clipped.
|
|
50
|
+
* A pure container (no text) simply has no own-text part. Nothing here depends on a concrete block type.
|
|
23
51
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
52
|
+
* With `textOnly` (the context of a TEXT selection: copy, cut, drag), a block that ISOLATES its text (`isolatesSelection`) is
|
|
53
|
+
* transparent to a selection that is not entirely inside it: its own text is not copied and its container is not created, its
|
|
54
|
+
* selected children are returned directly (an ARRAY, to be spliced in the list of its siblings). Without it (the structure of
|
|
55
|
+
* a whole block), the container is serialized as it is.
|
|
27
56
|
*
|
|
28
|
-
* @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null }} [ctx]
|
|
29
|
-
* @returns {import('../utils/extensions.js').PasteBlock | null}
|
|
57
|
+
* @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null, textOnly?: boolean }} [ctx]
|
|
58
|
+
* @returns {import('../utils/extensions.js').PasteBlock | import('../utils/extensions.js').PasteBlock[] | null}
|
|
59
|
+
* @public
|
|
30
60
|
*/
|
|
31
|
-
serializeForClipboard({ startBlock, startFrom, endBlock, endTo }?: {
|
|
61
|
+
public serializeForClipboard({ startBlock, startFrom, endBlock, endTo, textOnly }?: {
|
|
32
62
|
startBlock?: Block | null;
|
|
33
63
|
startFrom?: number;
|
|
34
64
|
endBlock?: Block | null;
|
|
35
65
|
endTo?: number | null;
|
|
36
|
-
|
|
66
|
+
textOnly?: boolean;
|
|
67
|
+
}): import("../utils/extensions.js").PasteBlock | import("../utils/extensions.js").PasteBlock[] | null;
|
|
37
68
|
}
|
|
38
69
|
import { Block } from "./block.svelte.js";
|
|
@@ -5,6 +5,9 @@ import { handleContainerBeforeInput, findDirectChildOf } from "./container.utils
|
|
|
5
5
|
* @import { Nabu, NabuNode } from "./nabu.svelte.js";
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A block that holds child blocks (a container): list, list item, toggle, region. It keeps its `children` in sync with the tree and delegates positions, word count and event handling to them.
|
|
10
|
+
*/
|
|
8
11
|
export class MegaBlock extends Block {
|
|
9
12
|
|
|
10
13
|
/** @param {Nabu} nabu @param {NabuNode} node */
|
|
@@ -13,15 +16,21 @@ export class MegaBlock extends Block {
|
|
|
13
16
|
this.updateChildren();
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* @type {Block[]}
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
17
23
|
children = $state([]);
|
|
24
|
+
/** @public */
|
|
18
25
|
positions = $derived(this.children.reduce((sum, child) => sum + (child.positions ?? 0), 0));
|
|
26
|
+
/** @public */
|
|
19
27
|
wordCount = $derived(this.children.reduce((sum, c) => sum + (c.wordCount ?? 0), 0));
|
|
20
28
|
|
|
21
29
|
/**
|
|
22
30
|
* Pure container: no own text, delegate entirely to children.
|
|
23
31
|
* @param {number} localOffset
|
|
24
32
|
* @returns {{ block: Block, offset: number } | null}
|
|
33
|
+
* @public
|
|
25
34
|
*/
|
|
26
35
|
resolveOffset(localOffset) {
|
|
27
36
|
let remaining = localOffset;
|
|
@@ -35,20 +44,26 @@ export class MegaBlock extends Block {
|
|
|
35
44
|
return last ? last.resolveOffset(Math.max(0, (last.positions ?? 1) - 1)) : null;
|
|
36
45
|
}
|
|
37
46
|
|
|
38
|
-
|
|
47
|
+
/**
|
|
48
|
+
* @param {Set<string>} [retyped] ids whose `type` just changed; without it, the type of every child is checked
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
updateChildren(retyped) {
|
|
39
52
|
const childrenNodes = this.node.children();
|
|
40
53
|
if (!childrenNodes) return;
|
|
41
54
|
this.children = childrenNodes.map((childNode, i) => {
|
|
42
55
|
const id = childNode.id.toString();
|
|
43
56
|
let block = this.nabu.blocks.get(id);
|
|
44
|
-
const currentType = childNode.data.get("type");
|
|
45
57
|
|
|
46
|
-
if (!block ||
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
if (!block || !retyped || retyped.has(id)) {
|
|
59
|
+
const currentType = childNode.data.get("type");
|
|
60
|
+
if (!block || block.type !== currentType) {
|
|
61
|
+
if (block) {
|
|
62
|
+
this.nabu.blocks.delete(id);
|
|
63
|
+
this.nabu.blocksByType.get(block.type)?.delete(block);
|
|
64
|
+
}
|
|
65
|
+
block = Block.load(this.nabu, childNode);
|
|
50
66
|
}
|
|
51
|
-
block = Block.load(this.nabu, childNode);
|
|
52
67
|
}
|
|
53
68
|
block.parent = this;
|
|
54
69
|
block.index = i;
|
|
@@ -57,7 +72,11 @@ export class MegaBlock extends Block {
|
|
|
57
72
|
}
|
|
58
73
|
|
|
59
74
|
|
|
60
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* @param {Block[]} children
|
|
77
|
+
* @param {number | null} [index]
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
61
80
|
adoptChildren(children, index = null) {
|
|
62
81
|
// Reverse so that when index is specified, children are inserted in original
|
|
63
82
|
// order (each insert at the same position pushes others down, so reverse of
|
|
@@ -70,92 +89,113 @@ export class MegaBlock extends Block {
|
|
|
70
89
|
}
|
|
71
90
|
|
|
72
91
|
|
|
73
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* @param {InputEvent} event
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
74
96
|
beforeinput(event) {
|
|
75
97
|
return handleContainerBeforeInput(this, this.nabu, event);
|
|
76
98
|
}
|
|
77
99
|
|
|
78
100
|
/**
|
|
79
101
|
* Props to include in the clipboard representation of this container block.
|
|
80
|
-
* Override in subclasses that carry structural props (e.g. List
|
|
102
|
+
* Override in subclasses that carry structural props (e.g. List -> { listType }, ListItem -> { checked },
|
|
103
|
+
* Toggle -> { collapsed }).
|
|
81
104
|
* @returns {Record<string, any>}
|
|
105
|
+
* @public
|
|
82
106
|
*/
|
|
83
107
|
get clipboardProps() { return {}; }
|
|
84
108
|
|
|
85
109
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
110
|
+
* Clipboard props when the copied slice starts at `firstChildIndex` (the children before it are NOT copied).
|
|
111
|
+
* Containers whose props depend on their first copied child (an ordered list's `start`) override this.
|
|
112
|
+
* @param {number} firstChildIndex
|
|
113
|
+
* @returns {Record<string, any>}
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
clipboardPropsFrom(firstChildIndex) { return this.clipboardProps; }
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Serializes the portion of this MegaBlock that falls within the given selection boundaries, recursively.
|
|
88
120
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
121
|
+
* The context carries the selection boundary blocks that belong to THIS subtree (`startBlock` / `endBlock`, null =
|
|
122
|
+
* the selection extends past this block on that side, i.e. it is fully selected on that side). Document order of a
|
|
123
|
+
* block is: own text (hybrid blocks only), then its children. So:
|
|
124
|
+
* - own text is copied unless the selection starts inside a child; it is clipped to `startFrom` when this block IS
|
|
125
|
+
* the start boundary, and to `endTo` when it IS the end boundary;
|
|
126
|
+
* - children are copied unless the selection ends in the own text; only those between the child holding the start
|
|
127
|
+
* boundary and the child holding the end boundary (inclusive) are kept, each one recursively clipped.
|
|
128
|
+
* A pure container (no text) simply has no own-text part. Nothing here depends on a concrete block type.
|
|
92
129
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
130
|
+
* With `textOnly` (the context of a TEXT selection: copy, cut, drag), a block that ISOLATES its text (`isolatesSelection`) is
|
|
131
|
+
* transparent to a selection that is not entirely inside it: its own text is not copied and its container is not created, its
|
|
132
|
+
* selected children are returned directly (an ARRAY, to be spliced in the list of its siblings). Without it (the structure of
|
|
133
|
+
* a whole block), the container is serialized as it is.
|
|
96
134
|
*
|
|
97
|
-
* @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null }} [ctx]
|
|
98
|
-
* @returns {import('../utils/extensions.js').PasteBlock | null}
|
|
135
|
+
* @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null, textOnly?: boolean }} [ctx]
|
|
136
|
+
* @returns {import('../utils/extensions.js').PasteBlock | import('../utils/extensions.js').PasteBlock[] | null}
|
|
137
|
+
* @public
|
|
99
138
|
*/
|
|
100
|
-
serializeForClipboard({ startBlock = null, startFrom = 0, endBlock = null, endTo = null } = {}) {
|
|
139
|
+
serializeForClipboard({ startBlock = null, startFrom = 0, endBlock = null, endTo = null, textOnly = false } = {}) {
|
|
101
140
|
const tb = this.behaviors?.get('text');
|
|
102
141
|
const imStart = startBlock === this;
|
|
103
142
|
const imEnd = endBlock === this;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
143
|
+
const childOfThis = (/** @type {Block|null} */ block) => {
|
|
144
|
+
for (let cur = block; cur; cur = cur.parent ?? null) if (cur.parent === this) return cur;
|
|
145
|
+
return null;
|
|
146
|
+
};
|
|
147
|
+
const startChild = startBlock && !imStart ? childOfThis(startBlock) : null;
|
|
148
|
+
const endChild = endBlock && !imEnd ? childOfThis(endBlock) : null;
|
|
149
|
+
|
|
150
|
+
const isolated = textOnly && this.isolatesSelection && !(imStart && imEnd);
|
|
151
|
+
const textIncluded = !!tb && !startChild && !isolated;
|
|
152
|
+
const childrenIncluded = !imEnd && !!this.children?.length;
|
|
153
|
+
if (!textIncluded && imEnd) return null;
|
|
154
|
+
|
|
155
|
+
// ── Own text ──
|
|
156
|
+
/** @type {import('../utils/extensions.js').PasteBlock | null} */
|
|
157
|
+
let result = null;
|
|
158
|
+
if (tb && textIncluded) {
|
|
159
|
+
const length = tb.container.length;
|
|
107
160
|
const from = imStart ? startFrom : 0;
|
|
108
|
-
const to = imEnd ? endTo
|
|
161
|
+
const to = imEnd ? (endTo ?? length) : length;
|
|
109
162
|
const partial = imStart && imEnd ? 'both' : imStart ? 'start' : imEnd ? 'end' : false;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
{ type: this.type, props: this.clipboardProps, partial, delta }
|
|
163
|
+
result = /** @type {import('../utils/extensions.js').PasteBlock} */ (
|
|
164
|
+
{ type: this.type, props: this.clipboardProps, partial, delta: tb.container.sliceDelta(from, to) }
|
|
113
165
|
);
|
|
114
|
-
// If fully selected and has children (e.g. ListItem with sublist), include them too
|
|
115
|
-
if (!imStart && !imEnd && this.children?.length) {
|
|
116
|
-
const childrenSerialized = this.children.map(child =>
|
|
117
|
-
typeof child.serializeForClipboard === 'function'
|
|
118
|
-
? child.serializeForClipboard({})
|
|
119
|
-
: child.serialize('application/x-nabu+json', { partial: false })
|
|
120
|
-
).filter(Boolean);
|
|
121
|
-
if (childrenSerialized.length) result.children = childrenSerialized;
|
|
122
|
-
}
|
|
123
|
-
return result;
|
|
124
166
|
}
|
|
125
167
|
|
|
126
|
-
// ──
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return children.length ? { type: this.type, props: this.clipboardProps, children } : null;
|
|
168
|
+
// ── Children inside the selection ──
|
|
169
|
+
/** @type {any[]} */
|
|
170
|
+
let kids = [];
|
|
171
|
+
let firstIndex = 0;
|
|
172
|
+
if (childrenIncluded) {
|
|
173
|
+
const si = startChild ? this.children.indexOf(/** @type {Block} */ (startChild)) : 0;
|
|
174
|
+
const ei = endChild ? this.children.indexOf(/** @type {Block} */ (endChild)) : this.children.length - 1;
|
|
175
|
+
if (si === -1 || ei === -1 || si > ei) return result;
|
|
176
|
+
firstIndex = si;
|
|
177
|
+
const relevant = this.children.slice(si, ei + 1);
|
|
178
|
+
const lastI = relevant.length - 1;
|
|
179
|
+
kids = relevant.map((child, i) => {
|
|
180
|
+
const cs = i === 0 && startChild ? startBlock : null;
|
|
181
|
+
const ce = i === lastI && endChild ? endBlock : null;
|
|
182
|
+
const mb = /** @type {any} */ (child);
|
|
183
|
+
if (typeof mb.serializeForClipboard === 'function') {
|
|
184
|
+
return mb.serializeForClipboard({ startBlock: cs, startFrom: cs ? startFrom : 0, endBlock: ce, endTo: ce ? endTo : null, textOnly });
|
|
185
|
+
}
|
|
186
|
+
return child.serialize('application/x-nabu+json', {
|
|
187
|
+
from: cs ? startFrom : 0,
|
|
188
|
+
to: ce ? endTo : null,
|
|
189
|
+
partial: cs && ce ? 'both' : cs ? 'start' : ce ? 'end' : false,
|
|
190
|
+
});
|
|
191
|
+
}).flat().filter(Boolean);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (result) {
|
|
195
|
+
if (kids.length) result.children = kids;
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
if (isolated) return /** @type {import('../utils/extensions.js').PasteBlock[]} */ (kids);
|
|
199
|
+
return kids.length ? { type: this.type, props: this.clipboardPropsFrom(firstIndex), children: kids } : null;
|
|
160
200
|
}
|
|
161
|
-
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run of sibling blocks a selection covers: `{ siblings, from, to }` (indexes in `siblings`, `from <= to`).
|
|
3
|
+
* @param {Block} a one end of the selection
|
|
4
|
+
* @param {Block} b the other end (the same block for a caret)
|
|
5
|
+
* @param {Nabu} nabu
|
|
6
|
+
* @returns {{ siblings: Block[], from: number, to: number } | null}
|
|
7
|
+
*/
|
|
8
|
+
export function siblingRun(a: Block, b: Block, nabu: Nabu): {
|
|
9
|
+
siblings: Block[];
|
|
10
|
+
from: number;
|
|
11
|
+
to: number;
|
|
12
|
+
} | null;
|
|
13
|
+
/**
|
|
14
|
+
* Move the selected blocks (or `data.block`) one step among their siblings.
|
|
15
|
+
* @param {Nabu} nabu
|
|
16
|
+
* @param {'up' | 'down'} direction
|
|
17
|
+
* @param {Block | string | null} [target] a block (or its id) to move instead of the selected ones
|
|
18
|
+
* @returns {Promise<boolean> | boolean} `false` = nothing to act on (no selection in the editor): the key is not handled;
|
|
19
|
+
* otherwise a promise of `true` (handled, also when the block already is at the edge and nothing moved)
|
|
20
|
+
*/
|
|
21
|
+
export function moveBlocks(nabu: Nabu, direction: "up" | "down", target?: Block | string | null): Promise<boolean> | boolean;
|
|
22
|
+
import type { Block } from './block.svelte.js';
|
|
23
|
+
import type { Nabu } from './nabu.svelte.js';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyboard block moves (`block:move-up` / `block:move-down`, P-80): the keyboard alternative to dragging (WCAG 2.5.7).
|
|
3
|
+
*
|
|
4
|
+
* Generic: it names no block type. The blocks that move are the SIBLINGS of one parent (the root, or a container's children):
|
|
5
|
+
* - the caret in a block moves that block; a list item moves among the items of its list, with its sub-lists;
|
|
6
|
+
* - a selection moves the whole contiguous run of its top-most blocks together: the blocks covered by the selection, taken at
|
|
7
|
+
* the level of the deepest container that holds both ends (a container selected from its own text to a descendant moves as
|
|
8
|
+
* one block);
|
|
9
|
+
* - one step at a time; at the edge of the parent nothing moves (leaving a container is a structural decision of its own:
|
|
10
|
+
* indent / outdent for lists, drag for the rest) and the key is still consumed;
|
|
11
|
+
* - one undo step; the selection stays on the same characters.
|
|
12
|
+
*
|
|
13
|
+
* @import { Nabu } from './nabu.svelte.js'
|
|
14
|
+
* @import { Block } from './block.svelte.js'
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { tick } from 'svelte';
|
|
18
|
+
import { livePoints, placePoints, revealFocus } from './undo-selection.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The run of sibling blocks a selection covers: `{ siblings, from, to }` (indexes in `siblings`, `from <= to`).
|
|
22
|
+
* @param {Block} a one end of the selection
|
|
23
|
+
* @param {Block} b the other end (the same block for a caret)
|
|
24
|
+
* @param {Nabu} nabu
|
|
25
|
+
* @returns {{ siblings: Block[], from: number, to: number } | null}
|
|
26
|
+
*/
|
|
27
|
+
export function siblingRun(a, b, nabu) {
|
|
28
|
+
/** @param {Block} block @returns {Block[]} root first */
|
|
29
|
+
const chain = (block) => {
|
|
30
|
+
/** @type {Block[]} */
|
|
31
|
+
const out = [];
|
|
32
|
+
for (let x = /** @type {Block | null} */ (block); x; x = /** @type {Block | null} */ (x.parent)) out.unshift(x);
|
|
33
|
+
return out;
|
|
34
|
+
};
|
|
35
|
+
const ca = chain(a);
|
|
36
|
+
const cb = chain(b);
|
|
37
|
+
let k = 0;
|
|
38
|
+
while (k < ca.length && k < cb.length && ca[k] === cb[k]) k++;
|
|
39
|
+
// One end holds the other (or they are the same block): that block moves as a whole.
|
|
40
|
+
if (k > 0 && (k === ca.length || k === cb.length)) {
|
|
41
|
+
const whole = ca[k - 1];
|
|
42
|
+
const siblings = /** @type {Block[]} */ (whole.parent ? /** @type {any} */ (whole.parent).children : nabu.children);
|
|
43
|
+
const at = siblings.indexOf(whole);
|
|
44
|
+
return at < 0 ? null : { siblings, from: at, to: at };
|
|
45
|
+
}
|
|
46
|
+
const siblings = /** @type {Block[]} */ (k === 0 ? nabu.children : /** @type {any} */ (ca[k - 1]).children);
|
|
47
|
+
const i = siblings.indexOf(ca[k]);
|
|
48
|
+
const j = siblings.indexOf(cb[k]);
|
|
49
|
+
if (i < 0 || j < 0) return null;
|
|
50
|
+
return { siblings, from: Math.min(i, j), to: Math.max(i, j) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Move the selected blocks (or `data.block`) one step among their siblings.
|
|
55
|
+
* @param {Nabu} nabu
|
|
56
|
+
* @param {'up' | 'down'} direction
|
|
57
|
+
* @param {Block | string | null} [target] a block (or its id) to move instead of the selected ones
|
|
58
|
+
* @returns {Promise<boolean> | boolean} `false` = nothing to act on (no selection in the editor): the key is not handled;
|
|
59
|
+
* otherwise a promise of `true` (handled, also when the block already is at the edge and nothing moved)
|
|
60
|
+
*/
|
|
61
|
+
export function moveBlocks(nabu, direction, target = null) {
|
|
62
|
+
const given = typeof target === 'string' ? nabu.blocks.get(target) : target;
|
|
63
|
+
const a = given ?? nabu.selection.anchorBlock ?? nabu.selection.focusBlock ?? null;
|
|
64
|
+
const b = given ?? nabu.selection.focusBlock ?? a;
|
|
65
|
+
if (!a || !b) return false;
|
|
66
|
+
const run = siblingRun(a, b, nabu);
|
|
67
|
+
if (!run) return false;
|
|
68
|
+
const { siblings, from, to } = run;
|
|
69
|
+
const edge = direction === 'up' ? siblings[from - 1] : siblings[to + 1];
|
|
70
|
+
if (!edge) return Promise.resolve(true);
|
|
71
|
+
return perform(nabu, () => {
|
|
72
|
+
// Moving the ONE neighbour past the run is the same order as moving the run, in a single tree operation, and the
|
|
73
|
+
// selected blocks keep their elements.
|
|
74
|
+
if (direction === 'up') edge.node.moveAfter(siblings[to].node);
|
|
75
|
+
else edge.node.moveBefore(siblings[from].node);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {Nabu} nabu
|
|
81
|
+
* @param {() => void} mutate
|
|
82
|
+
* @returns {Promise<boolean>}
|
|
83
|
+
*/
|
|
84
|
+
async function perform(nabu, mutate) {
|
|
85
|
+
const kept = livePoints(nabu);
|
|
86
|
+
await nabu.transact(mutate);
|
|
87
|
+
if (kept) {
|
|
88
|
+
await tick();
|
|
89
|
+
if (placePoints(nabu, kept)) revealFocus(kept.focus.block);
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|