@aionbuilders/nabu 0.1.0-alpha.9 → 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 +82 -144
- package/dist/behaviors/text/RichText.svelte +25 -2
- package/dist/behaviors/text/index.d.ts +2 -0
- package/dist/behaviors/text/index.js +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +5 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +79 -0
- 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 +135 -53
- package/dist/behaviors/text/text.behavior.svelte.d.ts +217 -42
- package/dist/behaviors/text/text.behavior.svelte.js +657 -55
- package/dist/behaviors/text/typography.extension.d.ts +7 -0
- package/dist/behaviors/text/typography.extension.js +25 -0
- package/dist/blocks/Block.svelte +5 -2
- package/dist/blocks/BlockList.svelte +48 -0
- package/dist/blocks/BlockList.svelte.d.ts +17 -0
- package/dist/blocks/Nabu.svelte +180 -14
- package/dist/blocks/Nabu.svelte.d.ts +13 -0
- package/dist/blocks/block.extension.d.ts +3 -0
- package/dist/blocks/block.extension.js +8 -9
- package/dist/blocks/block.svelte.d.ts +356 -68
- package/dist/blocks/block.svelte.js +388 -42
- package/dist/blocks/blockquote/Blockquote.svelte +39 -0
- package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
- package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -0
- package/dist/blocks/blockquote/blockquote.extension.js +80 -0
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +63 -0
- package/dist/blocks/blockquote/blockquote.svelte.js +136 -0
- package/dist/blocks/blockquote/index.d.ts +3 -0
- package/dist/blocks/blockquote/index.js +3 -0
- package/dist/blocks/callout/Callout.svelte +67 -0
- package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
- package/dist/blocks/callout/callout.extension.d.ts +4 -0
- package/dist/blocks/callout/callout.extension.js +84 -0
- package/dist/blocks/callout/callout.svelte.d.ts +80 -0
- package/dist/blocks/callout/callout.svelte.js +189 -0
- package/dist/blocks/callout/index.d.ts +3 -0
- package/dist/blocks/callout/index.js +3 -0
- package/dist/blocks/chunks.d.ts +49 -0
- package/dist/blocks/chunks.js +90 -0
- package/dist/blocks/code/Code.svelte +84 -0
- package/dist/blocks/code/Code.svelte.d.ts +11 -0
- package/dist/blocks/code/code.extension.d.ts +4 -0
- package/dist/blocks/code/code.extension.js +88 -0
- package/dist/blocks/code/code.svelte.d.ts +68 -0
- package/dist/blocks/code/code.svelte.js +245 -0
- package/dist/blocks/code/index.d.ts +3 -0
- package/dist/blocks/code/index.js +3 -0
- package/dist/blocks/container.utils.d.ts +85 -13
- package/dist/blocks/container.utils.js +338 -178
- package/dist/blocks/dialogue/Dialogue.svelte +8 -2
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +36 -23
- package/dist/blocks/dialogue/dialogue.svelte.js +51 -45
- 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.svelte +28 -0
- package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
- package/dist/blocks/divider/divider.extension.d.ts +23 -0
- package/dist/blocks/divider/divider.extension.js +153 -0
- package/dist/blocks/divider/divider.svelte.d.ts +54 -0
- package/dist/blocks/divider/divider.svelte.js +89 -0
- package/dist/blocks/divider/index.d.ts +3 -0
- package/dist/blocks/divider/index.js +3 -0
- package/dist/blocks/file/File.svelte +56 -0
- package/dist/blocks/file/File.svelte.d.ts +11 -0
- package/dist/blocks/file/file.extension.d.ts +4 -0
- package/dist/blocks/file/file.extension.js +27 -0
- package/dist/blocks/file/file.svelte.d.ts +29 -0
- package/dist/blocks/file/file.svelte.js +77 -0
- package/dist/blocks/file/index.d.ts +3 -0
- package/dist/blocks/file/index.js +3 -0
- package/dist/blocks/heading/Heading.svelte +2 -1
- package/dist/blocks/heading/heading.svelte.d.ts +27 -34
- package/dist/blocks/heading/heading.svelte.js +72 -60
- 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 +41 -0
- package/dist/blocks/image/Image.svelte.d.ts +11 -0
- package/dist/blocks/image/image.extension.d.ts +5 -0
- package/dist/blocks/image/image.extension.js +34 -0
- package/dist/blocks/image/image.svelte.d.ts +61 -0
- package/dist/blocks/image/image.svelte.js +114 -0
- package/dist/blocks/image/index.d.ts +3 -0
- package/dist/blocks/image/index.js +3 -0
- package/dist/blocks/index.d.ts +11 -1
- package/dist/blocks/index.js +11 -1
- package/dist/blocks/list/List.svelte +9 -2
- package/dist/blocks/list/ListItem.svelte +44 -7
- 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 +60 -26
- 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 +7 -3
- package/dist/blocks/list/index.js +43 -31
- package/dist/blocks/list/list-item.svelte.d.ts +43 -17
- package/dist/blocks/list/list-item.svelte.js +143 -93
- package/dist/blocks/list/list.behavior.svelte.d.ts +7 -4
- package/dist/blocks/list/list.behavior.svelte.js +10 -5
- package/dist/blocks/list/list.svelte.d.ts +101 -23
- package/dist/blocks/list/list.svelte.js +136 -114
- 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/list/todos.svelte.d.ts +35 -0
- package/dist/blocks/list/todos.svelte.js +76 -0
- package/dist/blocks/media/index.d.ts +2 -0
- package/dist/blocks/media/index.js +2 -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 +107 -0
- package/dist/blocks/media/media-block.svelte.js +181 -0
- package/dist/blocks/media/media.helpers.d.ts +24 -0
- package/dist/blocks/media/media.helpers.js +88 -0
- package/dist/blocks/megablock.svelte.d.ts +50 -19
- package/dist/blocks/megablock.svelte.js +115 -74
- package/dist/blocks/move.d.ts +23 -0
- package/dist/blocks/move.js +92 -0
- package/dist/blocks/nabu.svelte.d.ts +846 -75
- package/dist/blocks/nabu.svelte.js +1990 -182
- package/dist/blocks/paragraph/Paragraph.svelte +1 -0
- package/dist/blocks/paragraph/index.d.ts +2 -2
- package/dist/blocks/paragraph/index.js +35 -16
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +49 -35
- package/dist/blocks/paragraph/paragraph.svelte.js +81 -69
- 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 +632 -74
- package/dist/blocks/subthread.d.ts +80 -0
- package/dist/blocks/subthread.js +167 -0
- package/dist/blocks/text-block.svelte.d.ts +70 -0
- package/dist/blocks/text-block.svelte.js +108 -0
- package/dist/blocks/toggle/Toggle.svelte +73 -0
- package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
- package/dist/blocks/toggle/index.d.ts +3 -0
- package/dist/blocks/toggle/index.js +3 -0
- 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 -0
- package/dist/blocks/toggle/toggle.extension.js +18 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +135 -0
- package/dist/blocks/toggle/toggle.svelte.js +352 -0
- package/dist/blocks/undo-selection.d.ts +175 -0
- package/dist/blocks/undo-selection.js +360 -0
- package/dist/blocks/video/Video.svelte +42 -0
- package/dist/blocks/video/Video.svelte.d.ts +11 -0
- package/dist/blocks/video/index.d.ts +3 -0
- package/dist/blocks/video/index.js +3 -0
- package/dist/blocks/video/video.extension.d.ts +4 -0
- package/dist/blocks/video/video.extension.js +27 -0
- package/dist/blocks/video/video.svelte.d.ts +29 -0
- package/dist/blocks/video/video.svelte.js +80 -0
- 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 +363 -0
- package/dist/files/files.svelte.js +897 -0
- package/dist/files/index.d.ts +3 -0
- package/dist/files/index.js +3 -0
- 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 -6
- package/dist/index.js +117 -7
- package/dist/nabu-theme.css +112 -0
- package/dist/paste/html.paste.d.ts +74 -3
- package/dist/paste/html.paste.js +555 -83
- 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 -24
- package/dist/presets.js +51 -14
- 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 +217 -0
- package/dist/ui/DragHandle.svelte.d.ts +11 -0
- package/dist/ui/FloatingToolbar.svelte +165 -0
- package/dist/ui/FloatingToolbar.svelte.d.ts +27 -0
- package/dist/ui/SlashMenu.svelte +215 -0
- package/dist/ui/SlashMenu.svelte.d.ts +33 -0
- package/dist/ui/anchor.d.ts +112 -0
- package/dist/ui/anchor.js +136 -0
- package/dist/ui/index.d.ts +10 -0
- package/dist/ui/index.js +15 -0
- package/dist/ui/slash-menu.svelte.d.ts +112 -0
- package/dist/ui/slash-menu.svelte.js +150 -0
- 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 +488 -40
- package/dist/utils/extensions.js +300 -19
- package/dist/utils/html.d.ts +44 -0
- package/dist/utils/html.js +183 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -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 +88 -0
- package/dist/utils/placeholders.js +91 -0
- 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 +22 -0
- package/dist/vite.js +34 -0
- package/package.json +61 -22
- package/dist/blocks/zone/Zone.svelte +0 -258
- package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
- 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 -221
- package/dist/blocks/zone/zone.svelte.d.ts +0 -112
- package/dist/blocks/zone/zone.svelte.js +0 -321
|
@@ -2,6 +2,7 @@ import { tick } from "svelte";
|
|
|
2
2
|
import { TextBehavior } from "../../../behaviors/text";
|
|
3
3
|
import { List } from "../list.svelte.js";
|
|
4
4
|
import { ListItem } from "../list-item.svelte.js";
|
|
5
|
+
import { stepBack } from "../step-back.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @import { Nabu, Block } from "../..";
|
|
@@ -18,6 +19,16 @@ import { ListItem } from "../list-item.svelte.js";
|
|
|
18
19
|
export const onBeforeInput = (nabu, event, block) => {
|
|
19
20
|
const { BREAK, CONTINUE } = nabu;
|
|
20
21
|
|
|
22
|
+
// Backspace at offset 0 of a list item (collapsed caret): step back one level instead of merging into
|
|
23
|
+
// the previous block. A nested item is unindented, a top-level one becomes a paragraph (the next
|
|
24
|
+
// Backspace then merges it like any paragraph). See step-back.js.
|
|
25
|
+
if (event.inputType === "deleteContentBackward" && block instanceof ListItem) {
|
|
26
|
+
const sel = block.behavior.selection;
|
|
27
|
+
if (!sel || !sel.isCollapsed || sel.from !== 0) return CONTINUE;
|
|
28
|
+
stepBack(nabu, /** @type {import('../../nabu.svelte.js').NabuNode} */ (block.node));
|
|
29
|
+
return BREAK;
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
if (event.data !== " ") return CONTINUE;
|
|
22
33
|
if (block.type !== "paragraph") return CONTINUE;
|
|
23
34
|
|
|
@@ -29,9 +40,13 @@ export const onBeforeInput = (nabu, event, block) => {
|
|
|
29
40
|
|
|
30
41
|
const textBeforeCursor = behavior.text.slice(0, sel.from);
|
|
31
42
|
|
|
32
|
-
/** @type {"bullet" | "ordered" | null} */
|
|
43
|
+
/** @type {"bullet" | "ordered" | "todo" | null} */
|
|
33
44
|
let listType = null;
|
|
34
45
|
let prefixLength = 0;
|
|
46
|
+
/** @type {boolean | undefined} */
|
|
47
|
+
let checked = undefined;
|
|
48
|
+
/** @type {number | undefined} */
|
|
49
|
+
let start = undefined;
|
|
35
50
|
|
|
36
51
|
if (textBeforeCursor.match(/^-$/)) {
|
|
37
52
|
listType = "bullet";
|
|
@@ -39,37 +54,56 @@ export const onBeforeInput = (nabu, event, block) => {
|
|
|
39
54
|
} else if (textBeforeCursor.match(/^\d+\.$/)) {
|
|
40
55
|
listType = "ordered";
|
|
41
56
|
prefixLength = textBeforeCursor.length;
|
|
57
|
+
start = parseInt(textBeforeCursor, 10); // "3. " starts the list at 3 (List drops it when it is 1)
|
|
58
|
+
} else if (textBeforeCursor.match(/^\[\s?\]$/)) {
|
|
59
|
+
listType = "todo";
|
|
60
|
+
checked = false;
|
|
61
|
+
prefixLength = textBeforeCursor.length;
|
|
62
|
+
} else if (textBeforeCursor.match(/^\[[xX]\]$/)) {
|
|
63
|
+
listType = "todo";
|
|
64
|
+
checked = true;
|
|
65
|
+
prefixLength = textBeforeCursor.length;
|
|
42
66
|
}
|
|
43
67
|
|
|
44
68
|
if (!listType) return CONTINUE;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
const type = listType;
|
|
70
|
+
|
|
71
|
+
/** @type {string | null} */
|
|
72
|
+
let listItemId = null;
|
|
73
|
+
|
|
74
|
+
// Undo gives back the typed trigger ("- ", "1. "…, space included): see Nabu.shortcut()
|
|
75
|
+
nabu.shortcut(block, " ", (b) => {
|
|
76
|
+
// Delete the prefix and the trigger space ("- " -> "", "1. " -> "")
|
|
77
|
+
b.delete({ index: 0, length: prefixLength + 1 });
|
|
78
|
+
|
|
79
|
+
// Capture remaining text delta (everything after the prefix)
|
|
80
|
+
const delta = b.container.toDelta();
|
|
81
|
+
|
|
82
|
+
// Get current tree position from live Loro state (pre-commit)
|
|
83
|
+
const parentNode = block.node.parent();
|
|
84
|
+
const parentId = parentNode?.id.toString() ?? null;
|
|
85
|
+
const index = block.node.index();
|
|
86
|
+
|
|
87
|
+
// Create the List at the same position as the paragraph
|
|
88
|
+
/** @type {Record<string, any>} */
|
|
89
|
+
const listProps = { listType: type };
|
|
90
|
+
if (start !== undefined) listProps.start = start;
|
|
91
|
+
const list = List.create(nabu, "list", listProps, parentId, index);
|
|
92
|
+
|
|
93
|
+
// Create the ListItem inside the list with the captured content
|
|
94
|
+
/** @type {Record<string, any>} */
|
|
95
|
+
const itemProps = { delta };
|
|
96
|
+
if (checked !== undefined) itemProps.checked = checked;
|
|
97
|
+
const listItem = ListItem.create(nabu, "list-item", itemProps, list.node.id.toString());
|
|
98
|
+
listItemId = listItem.node.id.toString();
|
|
99
|
+
|
|
100
|
+
// Destroy the original paragraph; shortcut() commits the whole operation as one transaction
|
|
101
|
+
block.destroy();
|
|
102
|
+
});
|
|
68
103
|
|
|
69
104
|
// Restore focus to the new list-item
|
|
70
|
-
const listItemId = listItem.node.id.toString();
|
|
71
105
|
tick().then(() => {
|
|
72
|
-
const updatedListItem = nabu.blocks.get(listItemId);
|
|
106
|
+
const updatedListItem = listItemId ? nabu.blocks.get(listItemId) : null;
|
|
73
107
|
if (updatedListItem) updatedListItem.focus({ start: 0, end: 0 });
|
|
74
108
|
});
|
|
75
109
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a list element expresses its nesting by level (Docs) rather than by `<li>` containing sublists: an `<li
|
|
3
|
+
* aria-level>`, or a list nested straight in a list.
|
|
4
|
+
* @param {Element} listEl @returns {boolean}
|
|
5
|
+
*/
|
|
6
|
+
export function hasLeveledItems(listEl: Element): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The items of a Docs list element, in document order, with their level and kind.
|
|
9
|
+
* @param {Element} listEl
|
|
10
|
+
* @param {number} [depth] level of the items that carry no `aria-level` (their nesting depth)
|
|
11
|
+
* @param {RawEntry[]} [out]
|
|
12
|
+
* @returns {RawEntry[]}
|
|
13
|
+
*/
|
|
14
|
+
export function docsEntries(listEl: Element, depth?: number, out?: RawEntry[]): RawEntry[];
|
|
15
|
+
/**
|
|
16
|
+
* The `<ul>` / `<ol>` siblings that continue a Docs list: Docs sometimes writes each nesting level as its own list element.
|
|
17
|
+
* A following list element belongs to the same list when it goes DEEPER than where the list started, or when it comes back
|
|
18
|
+
* to that level after going deeper (same tag, no `start` of its own).
|
|
19
|
+
* @param {Element} el
|
|
20
|
+
* @returns {Element[]}
|
|
21
|
+
*/
|
|
22
|
+
export function docsSiblings(el: Element): Element[];
|
|
23
|
+
/**
|
|
24
|
+
* Bullet or numbered, and the number when the marker is one (`3.`).
|
|
25
|
+
* @param {string | null} marker
|
|
26
|
+
* @returns {{ listType: ListKind, start: number | null }}
|
|
27
|
+
*/
|
|
28
|
+
export function classifyWordMarker(marker: string | null): {
|
|
29
|
+
listType: ListKind;
|
|
30
|
+
start: number | null;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The Word list paragraphs that continue the list of `p` (same list and override id), straight after it.
|
|
34
|
+
* @param {Element} p
|
|
35
|
+
* @returns {Element[]}
|
|
36
|
+
*/
|
|
37
|
+
export function wordSiblings(p: Element): Element[];
|
|
38
|
+
/**
|
|
39
|
+
* @param {Element[]} paragraphs the list paragraphs of ONE Word list, in order
|
|
40
|
+
* @returns {RawEntry[]}
|
|
41
|
+
*/
|
|
42
|
+
export function wordEntries(paragraphs: Element[]): RawEntry[];
|
|
43
|
+
/**
|
|
44
|
+
* Build the nested list of flat, leveled items. Depth is the level relative to the first item; an item can go at most ONE
|
|
45
|
+
* level deeper than the previous one (a jump is clamped), and an item shallower than the first one sits at the top.
|
|
46
|
+
* Each depth keeps the kind of its first item (a bullet sublist under a numbered item, and so on); a change of kind at the
|
|
47
|
+
* same depth inside a sublist starts a sibling sublist. A list holding a checked / unchecked item is a to-do list.
|
|
48
|
+
* @param {Array<{ level: number, listType: ListKind, start: number | null, item: PasteBlock }>} entries
|
|
49
|
+
* @param {(listType: string, start: number | null) => Record<string, any>} propsOf list props for a kind and a first number
|
|
50
|
+
* @returns {PasteBlock | null}
|
|
51
|
+
*/
|
|
52
|
+
export function nestEntries(entries: Array<{
|
|
53
|
+
level: number;
|
|
54
|
+
listType: ListKind;
|
|
55
|
+
start: number | null;
|
|
56
|
+
item: PasteBlock;
|
|
57
|
+
}>, propsOf: (listType: string, start: number | null) => Record<string, any>): PasteBlock | null;
|
|
58
|
+
export function isWordListParagraph(el: Element): boolean;
|
|
59
|
+
export type ListKind = "bullet" | "ordered" | "todo";
|
|
60
|
+
/**
|
|
61
|
+
* an item of a flat list, before its content is parsed
|
|
62
|
+
*/
|
|
63
|
+
export type RawEntry = {
|
|
64
|
+
/**
|
|
65
|
+
* the `<li>` (Docs) or `<p>` (Word)
|
|
66
|
+
*/
|
|
67
|
+
el: Element;
|
|
68
|
+
/**
|
|
69
|
+
* 1-based, as written by the source
|
|
70
|
+
*/
|
|
71
|
+
level: number;
|
|
72
|
+
listType: ListKind;
|
|
73
|
+
/**
|
|
74
|
+
* first number of an ordered list, when this item opens a list element that says so
|
|
75
|
+
*/
|
|
76
|
+
start: number | null;
|
|
77
|
+
};
|
|
78
|
+
import type { PasteBlock } from "../../utils/extensions.js";
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lists in the HTML of Google Docs and Microsoft Word: nesting is not expressed by `<ul>` inside `<li>` but by a LEVEL
|
|
3
|
+
* attached to flat items. This module reads those levels and rebuilds real nested lists (PasteBlocks).
|
|
4
|
+
*
|
|
5
|
+
* - Google Docs: `<li aria-level="N" style="list-style-type:…">` (the level), items of one list in a single `<ul>`, or a
|
|
6
|
+
* `<ul>` nested straight inside the `<ul>` (invalid HTML the parser keeps), or one `<ul>` per level as siblings;
|
|
7
|
+
* `<ol start>` is kept; `aria-checked` items are to-do items.
|
|
8
|
+
* - Word: consecutive `<p class=MsoListParagraph… style="mso-list:l0 level2 lfo1">`: the list is `l0 lfo1`, the level is
|
|
9
|
+
* `level2`, and the kind (bullet / numbered) comes from the marker Word writes in a `mso-list:Ignore` span (`·`, `o`, `§`
|
|
10
|
+
* for bullets; `1.`, `a)`, `i.` for numbers).
|
|
11
|
+
*
|
|
12
|
+
* Pure DOM / PasteBlock functions, no editor access. Used by `List.fromHTML` / `List.htmlSiblings`.
|
|
13
|
+
*
|
|
14
|
+
* @import { PasteBlock } from "../../utils/extensions.js";
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {'bullet' | 'ordered' | 'todo'} ListKind
|
|
19
|
+
* @typedef {Object} RawEntry an item of a flat list, before its content is parsed
|
|
20
|
+
* @property {Element} el the `<li>` (Docs) or `<p>` (Word)
|
|
21
|
+
* @property {number} level 1-based, as written by the source
|
|
22
|
+
* @property {ListKind} listType
|
|
23
|
+
* @property {number | null} start first number of an ordered list, when this item opens a list element that says so
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** The value of one CSS property of the `style` attribute (lower-cased, `!important` dropped), or ''. @param {Element} el @param {string} prop */
|
|
27
|
+
function styleValue(el, prop) {
|
|
28
|
+
const style = el.getAttribute('style');
|
|
29
|
+
if (!style) return '';
|
|
30
|
+
let value = '';
|
|
31
|
+
for (const decl of style.split(';')) {
|
|
32
|
+
const i = decl.indexOf(':');
|
|
33
|
+
if (i > 0 && decl.slice(0, i).trim().toLowerCase() === prop) value = decl.slice(i + 1).replace(/!\s*important/i, '').trim().toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ORDERED_STYLE = /^(decimal|lower-|upper-|armenian|georgian|hebrew|cjk-|hiragana|katakana|arabic-indic|persian|devanagari|bengali|gujarati|gurmukhi|kannada|khmer|lao|malayalam|myanmar|oriya|tamil|telugu|thai|tibetan)/;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The kind of list an item belongs to, from its `list-style-type` (`disc` / `circle` / `square` → bullet, `decimal` /
|
|
42
|
+
* `lower-alpha` / `upper-roman`… → ordered); no (or `none`) style: the kind of the list tag.
|
|
43
|
+
* @param {string} styleType @param {ListKind} fallback @returns {ListKind}
|
|
44
|
+
*/
|
|
45
|
+
function kindFromStyle(styleType, fallback) {
|
|
46
|
+
if (!styleType || styleType === 'none') return fallback;
|
|
47
|
+
return ORDERED_STYLE.test(styleType) ? 'ordered' : 'bullet';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @param {unknown} start @returns {number | null} */
|
|
51
|
+
const startNumber = (start) => {
|
|
52
|
+
if (start === null || start === undefined || start === '') return null;
|
|
53
|
+
const n = Number(start);
|
|
54
|
+
return Number.isInteger(n) && n >= 0 ? n : null;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** The ul / ol elements are the list tags. @param {Element | null | undefined} el */
|
|
58
|
+
const isListTag = (el) => !!el && (el.localName === 'ul' || el.localName === 'ol');
|
|
59
|
+
|
|
60
|
+
/** The next sibling ELEMENT, over blank text and comments only; `null` when something else (text, an element) is met first. @param {Element} el */
|
|
61
|
+
function nextSiblingElement(el) {
|
|
62
|
+
for (let n = el.nextSibling; n; n = n.nextSibling) {
|
|
63
|
+
if (n.nodeType === 1) return /** @type {Element} */ (n);
|
|
64
|
+
if (n.nodeType === 8 || (n.nodeType === 3 && !/\S/.test(n.textContent ?? ''))) continue;
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── Google Docs ──────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Whether a list element expresses its nesting by level (Docs) rather than by `<li>` containing sublists: an `<li
|
|
74
|
+
* aria-level>`, or a list nested straight in a list.
|
|
75
|
+
* @param {Element} listEl @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
export function hasLeveledItems(listEl) {
|
|
78
|
+
return [...listEl.children].some((c) => (c.localName === 'li' && c.hasAttribute('aria-level')) || isListTag(c));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The items of a Docs list element, in document order, with their level and kind.
|
|
83
|
+
* @param {Element} listEl
|
|
84
|
+
* @param {number} [depth] level of the items that carry no `aria-level` (their nesting depth)
|
|
85
|
+
* @param {RawEntry[]} [out]
|
|
86
|
+
* @returns {RawEntry[]}
|
|
87
|
+
*/
|
|
88
|
+
export function docsEntries(listEl, depth = 1, out = []) {
|
|
89
|
+
const tagKind = /** @type {ListKind} */ (listEl.localName === 'ol' ? 'ordered' : 'bullet');
|
|
90
|
+
const start = listEl.localName === 'ol' ? startNumber(listEl.getAttribute('start')) : null;
|
|
91
|
+
let first = true;
|
|
92
|
+
for (const child of listEl.children) {
|
|
93
|
+
if (child.localName === 'li') {
|
|
94
|
+
const aria = parseInt(child.getAttribute('aria-level') ?? '', 10);
|
|
95
|
+
out.push({ el: child, level: aria > 0 ? aria : depth, listType: kindFromStyle(styleValue(child, 'list-style-type'), tagKind), start: first ? start : null });
|
|
96
|
+
first = false;
|
|
97
|
+
} else if (isListTag(child)) {
|
|
98
|
+
docsEntries(child, depth + 1, out);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The `<ul>` / `<ol>` siblings that continue a Docs list: Docs sometimes writes each nesting level as its own list element.
|
|
106
|
+
* A following list element belongs to the same list when it goes DEEPER than where the list started, or when it comes back
|
|
107
|
+
* to that level after going deeper (same tag, no `start` of its own).
|
|
108
|
+
* @param {Element} el
|
|
109
|
+
* @returns {Element[]}
|
|
110
|
+
*/
|
|
111
|
+
export function docsSiblings(el) {
|
|
112
|
+
if (!isListTag(el) || !hasLeveledItems(el)) return [];
|
|
113
|
+
const own = docsEntries(el);
|
|
114
|
+
if (!own.length) return [];
|
|
115
|
+
const base = own[0].level;
|
|
116
|
+
let last = own[own.length - 1].level;
|
|
117
|
+
/** @type {Element[]} */
|
|
118
|
+
const out = [];
|
|
119
|
+
for (let n = nextSiblingElement(el); isListTag(n) && hasLeveledItems(/** @type {Element} */ (n)); n = nextSiblingElement(/** @type {Element} */ (n))) {
|
|
120
|
+
const list = /** @type {Element} */ (n);
|
|
121
|
+
const entries = docsEntries(list);
|
|
122
|
+
if (!entries.length) break;
|
|
123
|
+
const deeper = entries[0].level > base;
|
|
124
|
+
const back = entries[0].level === base && last > base && list.localName === el.localName && !list.hasAttribute('start');
|
|
125
|
+
if (!deeper && !back) break;
|
|
126
|
+
out.push(list);
|
|
127
|
+
last = entries[entries.length - 1].level;
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ── Microsoft Word ───────────────────────────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
const WORD_LIST = /mso-list\s*:\s*(l\d+)\s+level(\d+)(?:\s+(lfo\d+))?/i;
|
|
135
|
+
|
|
136
|
+
/** @param {Element} el @returns {{ key: string, level: number } | null} */
|
|
137
|
+
function wordInfo(el) {
|
|
138
|
+
const m = WORD_LIST.exec(el.getAttribute('style') ?? '');
|
|
139
|
+
return m ? { key: m[1].toLowerCase() + (m[3] ? ' ' + m[3].toLowerCase() : ''), level: Number(m[2]) } : null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Whether an element is a Word list paragraph (`mso-list:l0 level1 lfo1`). @param {Element} el @returns {boolean} */
|
|
143
|
+
export const isWordListParagraph = (el) => wordInfo(el) !== null;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The marker Word writes before the text of a list paragraph (the content of its `mso-list:Ignore` span), or `null`.
|
|
147
|
+
* @param {Element} p @returns {string | null}
|
|
148
|
+
*/
|
|
149
|
+
function wordMarker(p) {
|
|
150
|
+
for (const span of p.querySelectorAll('[style]')) {
|
|
151
|
+
if (/mso-list\s*:\s*ignore/i.test(span.getAttribute('style') ?? '')) return (span.textContent ?? '').replace(/[\s ]+/g, ' ').trim();
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Bullet or numbered, and the number when the marker is one (`3.`).
|
|
158
|
+
* @param {string | null} marker
|
|
159
|
+
* @returns {{ listType: ListKind, start: number | null }}
|
|
160
|
+
*/
|
|
161
|
+
export function classifyWordMarker(marker) {
|
|
162
|
+
if (!marker) return { listType: 'bullet', start: null };
|
|
163
|
+
const number = /^\(?(\d+)[.)]?$/.exec(marker);
|
|
164
|
+
if (number) return { listType: 'ordered', start: startNumber(number[1]) };
|
|
165
|
+
if (/^\(?[A-Za-z]+[.)]$/.test(marker)) return { listType: 'ordered', start: null }; // a. A) i. IV.
|
|
166
|
+
if (marker.length === 1 && /[A-Za-z]/.test(marker) && marker !== 'o' && marker !== 'O') return { listType: 'ordered', start: null };
|
|
167
|
+
return { listType: 'bullet', start: null }; // · • o § - ▪ and the private-use glyphs of the Symbol / Wingdings fonts
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The Word list paragraphs that continue the list of `p` (same list and override id), straight after it.
|
|
172
|
+
* @param {Element} p
|
|
173
|
+
* @returns {Element[]}
|
|
174
|
+
*/
|
|
175
|
+
export function wordSiblings(p) {
|
|
176
|
+
const info = wordInfo(p);
|
|
177
|
+
if (!info) return [];
|
|
178
|
+
/** @type {Element[]} */
|
|
179
|
+
const out = [];
|
|
180
|
+
for (let n = nextSiblingElement(p); n && n.localName === 'p' && wordInfo(n)?.key === info.key; n = nextSiblingElement(n)) out.push(n);
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param {Element[]} paragraphs the list paragraphs of ONE Word list, in order
|
|
186
|
+
* @returns {RawEntry[]}
|
|
187
|
+
*/
|
|
188
|
+
export function wordEntries(paragraphs) {
|
|
189
|
+
/** @type {RawEntry[]} */
|
|
190
|
+
const out = [];
|
|
191
|
+
paragraphs.forEach((el, i) => {
|
|
192
|
+
const info = wordInfo(el);
|
|
193
|
+
if (!info) return;
|
|
194
|
+
const { listType, start } = classifyWordMarker(wordMarker(el));
|
|
195
|
+
out.push({ el, level: info.level, listType, start: i === 0 ? start : null });
|
|
196
|
+
});
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ── Levels → nested lists ────────────────────────────────────────────────────
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Build the nested list of flat, leveled items. Depth is the level relative to the first item; an item can go at most ONE
|
|
204
|
+
* level deeper than the previous one (a jump is clamped), and an item shallower than the first one sits at the top.
|
|
205
|
+
* Each depth keeps the kind of its first item (a bullet sublist under a numbered item, and so on); a change of kind at the
|
|
206
|
+
* same depth inside a sublist starts a sibling sublist. A list holding a checked / unchecked item is a to-do list.
|
|
207
|
+
* @param {Array<{ level: number, listType: ListKind, start: number | null, item: PasteBlock }>} entries
|
|
208
|
+
* @param {(listType: string, start: number | null) => Record<string, any>} propsOf list props for a kind and a first number
|
|
209
|
+
* @returns {PasteBlock | null}
|
|
210
|
+
*/
|
|
211
|
+
export function nestEntries(entries, propsOf) {
|
|
212
|
+
if (!entries.length) return null;
|
|
213
|
+
const base = entries[0].level;
|
|
214
|
+
/** @param {{ listType: ListKind, start: number | null }} e @returns {PasteBlock} */
|
|
215
|
+
const makeList = (e) => ({ type: 'list', props: propsOf(e.listType, e.listType === 'ordered' ? e.start : null), children: [], partial: false });
|
|
216
|
+
const root = makeList(entries[0]);
|
|
217
|
+
/** @type {PasteBlock[]} */
|
|
218
|
+
const lists = [root];
|
|
219
|
+
/** @type {PasteBlock[]} */
|
|
220
|
+
const lastItem = [];
|
|
221
|
+
let previous = -1;
|
|
222
|
+
for (const e of entries) {
|
|
223
|
+
const depth = Math.max(0, Math.min(e.level - base, previous + 1));
|
|
224
|
+
lastItem.length = Math.min(lastItem.length, depth);
|
|
225
|
+
if (depth > 0 && (!lists[depth] || lists[depth].props?.listType !== e.listType)) {
|
|
226
|
+
const list = makeList(e);
|
|
227
|
+
const parent = lastItem[depth - 1];
|
|
228
|
+
(parent.children ??= []).push(list);
|
|
229
|
+
lists[depth] = list;
|
|
230
|
+
}
|
|
231
|
+
lists.length = depth + 1;
|
|
232
|
+
/** @type {PasteBlock[]} */ (lists[depth].children).push(e.item);
|
|
233
|
+
lastItem[depth] = e.item;
|
|
234
|
+
previous = depth;
|
|
235
|
+
}
|
|
236
|
+
/** @param {PasteBlock} list */
|
|
237
|
+
const promote = (list) => {
|
|
238
|
+
const items = list.children ?? [];
|
|
239
|
+
if (items.some((item) => item.props?.checked !== undefined)) list.props = { ...list.props, listType: 'todo' };
|
|
240
|
+
for (const item of items) for (const sub of item.children ?? []) promote(sub);
|
|
241
|
+
};
|
|
242
|
+
promote(root);
|
|
243
|
+
return root;
|
|
244
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deletes a list this batch just emptied. The normalizer would do it too, but it spares a list created by
|
|
3
|
+
* the same transaction (it may still be "under construction"), and a batch of moves creates then empties
|
|
4
|
+
* such lists (an item unindented, then its adopted follower unindented in turn).
|
|
5
|
+
* @param {Nabu} nabu
|
|
6
|
+
* @param {NabuNode | null | undefined} list
|
|
7
|
+
*/
|
|
8
|
+
export function dropIfEmpty(nabu: Nabu, list: NabuNode | null | undefined): void;
|
|
9
|
+
/**
|
|
10
|
+
* Indent one item: it goes under its previous sibling, at the end of that sibling's LAST sublist when that
|
|
11
|
+
* sublist has the same type as the item's current list, otherwise in a new sublist of that type appended
|
|
12
|
+
* after the sibling's sublists. Its whole subtree moves along (its own sublists stay attached to it). Moves
|
|
13
|
+
* only; no commit.
|
|
14
|
+
* @param {Nabu} nabu
|
|
15
|
+
* @param {NabuNode} item
|
|
16
|
+
* @returns {boolean} whether the item moved
|
|
17
|
+
*/
|
|
18
|
+
export function indentNode(nabu: Nabu, item: NabuNode): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Unindent one item: it goes right after its parent item, and the siblings that followed it become its
|
|
21
|
+
* children, in a sublist of THEIR list type appended after the sublists it already has (its own subtree
|
|
22
|
+
* stays attached). To keep the document order, the sublists of the parent item that came after the item's
|
|
23
|
+
* list follow them. Moves only; no commit.
|
|
24
|
+
* @param {Nabu} nabu
|
|
25
|
+
* @param {NabuNode} item
|
|
26
|
+
* @returns {boolean} whether the item moved
|
|
27
|
+
*/
|
|
28
|
+
export function unindentNode(nabu: Nabu, item: NabuNode): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {{ block: Block, offset: number }} CaretPoint
|
|
31
|
+
* @typedef {{ anchor: CaretPoint, focus: CaretPoint }} SelectionSnapshot
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Model position (block + text offset) of the live selection's anchor and focus, or null when one of
|
|
35
|
+
* them is not in a text block.
|
|
36
|
+
* @param {Nabu} nabu
|
|
37
|
+
* @returns {SelectionSnapshot | null}
|
|
38
|
+
*/
|
|
39
|
+
export function captureSelection(nabu: Nabu): SelectionSnapshot | null;
|
|
40
|
+
/**
|
|
41
|
+
* Put the selection back after a re-render: same blocks (looked up again by id), same offsets, so a
|
|
42
|
+
* collapsed caret stays collapsed and a range stays a range.
|
|
43
|
+
* @param {Nabu} nabu
|
|
44
|
+
* @param {SelectionSnapshot | null} snapshot
|
|
45
|
+
* @returns {Promise<void>}
|
|
46
|
+
*/
|
|
47
|
+
export function restoreSelection(nabu: Nabu, snapshot: SelectionSnapshot | null): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Indent (`unindent = false`) or unindent every given list item, in document order, as ONE transaction.
|
|
50
|
+
* Items that cannot move (e.g. the first item of a list on indent) stay. The selection is restored.
|
|
51
|
+
* @param {Nabu} nabu
|
|
52
|
+
* @param {NabuNode[]} items list-item nodes, in document order
|
|
53
|
+
* @param {boolean} unindent
|
|
54
|
+
* @returns {Promise<boolean>} whether at least one item moved
|
|
55
|
+
*/
|
|
56
|
+
export function moveItems(nabu: Nabu, items: NabuNode[], unindent: boolean): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* The list items a selection touches, in document order: the anchor block alone when the selection is
|
|
59
|
+
* inside one block, otherwise every list item between the start and the end block.
|
|
60
|
+
* @param {Nabu} nabu
|
|
61
|
+
* @returns {NabuNode[]}
|
|
62
|
+
*/
|
|
63
|
+
export function selectedItems(nabu: Nabu): NabuNode[];
|
|
64
|
+
/**
|
|
65
|
+
* Tab / Shift+Tab on the current selection. Returns true (= the key is handled, the default prevented)
|
|
66
|
+
* whenever the selection touches list items, even when none of them could move: focus never leaves the editor.
|
|
67
|
+
* @param {Nabu} nabu
|
|
68
|
+
* @param {KeyboardEvent} event
|
|
69
|
+
* @returns {boolean}
|
|
70
|
+
*/
|
|
71
|
+
export function handleTab(nabu: Nabu, event: KeyboardEvent): boolean;
|
|
72
|
+
export function typeOf(node: NabuNode | null | undefined): any;
|
|
73
|
+
export function kids(node: NabuNode): NabuNode[];
|
|
74
|
+
export function listTypeOf(list: NabuNode | null | undefined): any;
|
|
75
|
+
export function sublistsOf(item: NabuNode): NabuNode[];
|
|
76
|
+
export type CaretPoint = {
|
|
77
|
+
block: Block;
|
|
78
|
+
offset: number;
|
|
79
|
+
};
|
|
80
|
+
export type SelectionSnapshot = {
|
|
81
|
+
anchor: CaretPoint;
|
|
82
|
+
focus: CaretPoint;
|
|
83
|
+
};
|
|
84
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
85
|
+
import type { NabuNode } from "../nabu.svelte.js";
|
|
86
|
+
import type { Block } from "../block.svelte.js";
|