@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
|
@@ -1,86 +1,55 @@
|
|
|
1
1
|
import { MegaBlock } from "../megablock.svelte.js";
|
|
2
2
|
import ListItemComponent from "./ListItem.svelte";
|
|
3
|
+
import { List, listStart } from "./list.svelte.js";
|
|
4
|
+
import { moveItems, handleTab } from "./indent.js";
|
|
5
|
+
import { retypeItem } from "./convert.js";
|
|
6
|
+
import { pasteIntoItem } from "./paste.js";
|
|
3
7
|
import { LoroText } from "loro-crdt";
|
|
4
8
|
import { TextBehavior, deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
9
|
+
import { renderItem, adjacentRun, markerWidth } from "./markdown.js";
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* @import { Nabu, NabuNode, Block } from "..";
|
|
8
13
|
*/
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
|
-
* @typedef {NabuNode<{type: "list-item", text: LoroText}>} ListItemNode
|
|
16
|
+
* @typedef {NabuNode<{type: "list-item", text: LoroText, checked?: boolean}>} ListItemNode
|
|
12
17
|
*/
|
|
13
18
|
|
|
19
|
+
/** What the list renderers (markdown.js) need from outside: the inline serializer and the `start` normalizer. */
|
|
20
|
+
const markdownEnv = { toMarkdown: (/** @type {any[]} */ delta) => deltaToMarkdown(delta), listStart };
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
|
-
* Indent a list item (Tab behavior): move
|
|
23
|
+
* Indent a list item (Tab behavior): move under the previous sibling (into its last sublist when of the same type, else a new one).
|
|
24
|
+
* The selection (collapsed caret or range) is restored afterwards. See indent.js.
|
|
16
25
|
* @param {ListItem} item
|
|
17
26
|
* @returns {boolean}
|
|
18
27
|
*/
|
|
19
28
|
export function indentListItem(item) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!parentList) return false;
|
|
25
|
-
|
|
26
|
-
const previousNode = parentList.children()?.[currentIndex - 1];
|
|
27
|
-
if (!previousNode) return false;
|
|
28
|
-
const previousItem = item.nabu.blocks.get(previousNode.id.toString());
|
|
29
|
-
if (!previousItem || previousItem.type !== 'list-item') return false;
|
|
30
|
-
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
const targetSublist = previousItem.getOrCreateSublist();
|
|
33
|
-
const targetSublistId = targetSublist.node.id.toString();
|
|
34
|
-
|
|
35
|
-
item.nabu.tree.move(item.node.id.toString(), targetSublistId);
|
|
36
|
-
|
|
37
|
-
if (item.sublist) {
|
|
38
|
-
for (const childNode of item.sublist.node.children()) {
|
|
39
|
-
item.nabu.tree.move(childNode.id.toString(), targetSublistId);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
item.commit().then(() => item.behavior.block.focus());
|
|
44
|
-
return true;
|
|
29
|
+
const node = /** @type {import("../nabu.svelte.js").NabuNode} */ (item.node);
|
|
30
|
+
const movable = !!node.index() && node.parent()?.children()?.[/** @type {number} */ (node.index()) - 1]?.data.get('type') === 'list-item';
|
|
31
|
+
if (movable) moveItems(item.nabu, [node], false);
|
|
32
|
+
return movable;
|
|
45
33
|
}
|
|
46
34
|
|
|
47
35
|
/**
|
|
48
36
|
* Unindent a list item (Shift+Tab behavior): move out of parent sublist, carry followers.
|
|
37
|
+
* The selection (collapsed caret or range) is restored afterwards. See indent.js.
|
|
49
38
|
* @param {ListItem} item
|
|
50
39
|
* @returns {boolean}
|
|
51
40
|
*/
|
|
52
41
|
export function unindentListItem(item) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!grandParentItemNode || grandParentItemNode.data.get('type') !== 'list-item') return false;
|
|
58
|
-
|
|
59
|
-
const myIndex = item.node.index();
|
|
60
|
-
const followers = parentListNode.children().slice(myIndex + 1);
|
|
61
|
-
|
|
62
|
-
if (followers.length > 0) {
|
|
63
|
-
const mySublist = item.getOrCreateSublist();
|
|
64
|
-
for (const follower of followers) {
|
|
65
|
-
item.nabu.tree.move(follower.id.toString(), mySublist.node.id.toString());
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const targetParentListNode = grandParentItemNode.parent();
|
|
70
|
-
if (!targetParentListNode) return false;
|
|
71
|
-
|
|
72
|
-
const targetIndex = grandParentItemNode.index() + 1;
|
|
73
|
-
item.nabu.tree.move(item.node.id.toString(), targetParentListNode.id.toString(), targetIndex);
|
|
74
|
-
|
|
75
|
-
item.commit().then(() => item.behavior.block.focus());
|
|
76
|
-
return true;
|
|
42
|
+
const node = /** @type {import("../nabu.svelte.js").NabuNode} */ (item.node);
|
|
43
|
+
const movable = node.parent()?.parent()?.data.get('type') === 'list-item';
|
|
44
|
+
if (movable) moveItems(item.nabu, [node], true);
|
|
45
|
+
return movable;
|
|
77
46
|
}
|
|
78
47
|
|
|
79
48
|
export class ListItem extends MegaBlock {
|
|
80
49
|
/** @param {Nabu} nabu @param {ListItemNode} node */
|
|
81
50
|
constructor(nabu, node) {
|
|
82
51
|
super(nabu, node);
|
|
83
|
-
|
|
52
|
+
|
|
84
53
|
const data = node.data;
|
|
85
54
|
this.container = data.get("text") ?? data.setContainer("text", new LoroText());
|
|
86
55
|
|
|
@@ -88,24 +57,36 @@ export class ListItem extends MegaBlock {
|
|
|
88
57
|
this.behavior = new TextBehavior(this, this.container);
|
|
89
58
|
this.behaviors.set("text", this.behavior);
|
|
90
59
|
|
|
60
|
+
// Initialize checked from Loro metadata
|
|
61
|
+
this.checked = !!node.data.get('checked');
|
|
62
|
+
// Subscribe to data changes to keep checked in sync
|
|
63
|
+
this.node.data.subscribe(() => {
|
|
64
|
+
this.checked = !!this.node.data.get('checked');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// One item (and its sublists), indented under the items that hold it. A whole list is rendered by the List.
|
|
91
68
|
this.serializers.set('markdown', () => {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (this.sublist) {
|
|
98
|
-
const sublistMd = this.sublist.serialize('markdown');
|
|
99
|
-
if (sublistMd) lines.push(sublistMd);
|
|
69
|
+
const list = /** @type {any} */ (this.parent);
|
|
70
|
+
let indent = '';
|
|
71
|
+
for (let item = /** @type {any} */ (this); item.parent?.parent?.type === 'list-item'; item = item.parent.parent) {
|
|
72
|
+
const outer = item.parent.parent;
|
|
73
|
+
indent = ' '.repeat(markerWidth(outer.parent?.listType, (outer.parent?.start ?? 1) + outer.index)) + indent;
|
|
100
74
|
}
|
|
101
|
-
return
|
|
75
|
+
return renderItem(this.toPasteBlock(), markdownEnv, {
|
|
76
|
+
listType: list?.listType ?? 'bullet',
|
|
77
|
+
index: this.index,
|
|
78
|
+
start: list?.start ?? 1,
|
|
79
|
+
run: list ? adjacentRun(list.listType, list.siblingsBefore()) : 0,
|
|
80
|
+
indent,
|
|
81
|
+
});
|
|
102
82
|
});
|
|
103
83
|
this.serializers.set('json', () => {
|
|
104
84
|
/** @type {Record<string, any>} */
|
|
105
85
|
const result = {
|
|
106
86
|
id: this.id,
|
|
107
87
|
type: 'list-item',
|
|
108
|
-
content: this.behavior.toJSON()
|
|
88
|
+
content: this.behavior.toJSON(),
|
|
89
|
+
...(this.isTodo ? { props: { checked: this.checked } } : {})
|
|
109
90
|
};
|
|
110
91
|
const childrenJson = this.children.map(c => c.serialize('json')).filter(Boolean);
|
|
111
92
|
if (childrenJson.length) result.children = childrenJson;
|
|
@@ -115,7 +96,45 @@ export class ListItem extends MegaBlock {
|
|
|
115
96
|
}
|
|
116
97
|
|
|
117
98
|
component = $derived(this.nabu.components.get("list-item") || ListItemComponent);
|
|
118
|
-
|
|
99
|
+
|
|
100
|
+
/** @type {boolean} */
|
|
101
|
+
checked = $state(false);
|
|
102
|
+
|
|
103
|
+
isTodo = $derived(/** @type {any} */ (this.parent)?.listType === 'todo');
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* This item and its sublists as PasteBlocks (the shape the static serializers read).
|
|
107
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
108
|
+
*/
|
|
109
|
+
toPasteBlock() {
|
|
110
|
+
const pb = this.behavior.toClipboardBlock({ props: this.clipboardProps });
|
|
111
|
+
const sublists = this.sublists;
|
|
112
|
+
return sublists.length ? { ...pb, children: sublists.map(sub => /** @type {any} */ (sub).toPasteBlock()) } : pb;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A to-do item carries its `checked` state onto the clipboard. */
|
|
116
|
+
get clipboardProps() {
|
|
117
|
+
return this.isTodo ? { checked: this.checked } : {};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Set the checked state and persist to Loro.
|
|
122
|
+
* @param {boolean} v
|
|
123
|
+
*/
|
|
124
|
+
setChecked(v) {
|
|
125
|
+
this.checked = !!v;
|
|
126
|
+
/** @type {any} */ (this.node.data).set('checked', !!v);
|
|
127
|
+
this.commit();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Toggle the checked state (the user's gesture: a click on the box, the key). Does nothing in a read-only editor.
|
|
132
|
+
*/
|
|
133
|
+
toggleChecked() {
|
|
134
|
+
if (this.nabu.readonly) return;
|
|
135
|
+
this.setChecked(!this.checked);
|
|
136
|
+
}
|
|
137
|
+
|
|
119
138
|
get text() {
|
|
120
139
|
return this.behavior.text;
|
|
121
140
|
}
|
|
@@ -126,8 +145,11 @@ export class ListItem extends MegaBlock {
|
|
|
126
145
|
|
|
127
146
|
selection = $derived(this.behavior.selection);
|
|
128
147
|
|
|
148
|
+
// @ts-ignore — `super.positions`: Svelte compiles the parent's `$derived` field to a prototype accessor, which TS sees as a field
|
|
129
149
|
positions = $derived(this.behavior.positions + super.positions);
|
|
130
150
|
|
|
151
|
+
wordCount = $derived((this.behavior?.wordCount ?? 0) + this.children.reduce((sum, c) => sum + (c.wordCount ?? 0), 0));
|
|
152
|
+
|
|
131
153
|
/**
|
|
132
154
|
* Mixed block: own text comes first, then children (sublists).
|
|
133
155
|
* @param {number} localOffset
|
|
@@ -147,7 +169,11 @@ export class ListItem extends MegaBlock {
|
|
|
147
169
|
return { block: this, offset: this.behavior.text.length };
|
|
148
170
|
}
|
|
149
171
|
|
|
150
|
-
sublist
|
|
172
|
+
/** Every sublist, in order: an item may hold several, of different types (`a > [ul[…], ol[…], ul[…]]`). */
|
|
173
|
+
sublists = $derived(this.children.filter(child => child.node.data.get("type") === "list"));
|
|
174
|
+
|
|
175
|
+
/** The first sublist (see `sublists`). */
|
|
176
|
+
sublist = $derived(this.sublists[0]);
|
|
151
177
|
|
|
152
178
|
/**
|
|
153
179
|
* A ListItem must always live inside a List.
|
|
@@ -167,29 +193,46 @@ export class ListItem extends MegaBlock {
|
|
|
167
193
|
}
|
|
168
194
|
|
|
169
195
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
196
|
+
* The sublist that receives a child of type `listType`: the LAST sublist when it has that type, otherwise
|
|
197
|
+
* a new one appended after the existing sublists (an item may hold several sublists of different types).
|
|
198
|
+
* @param {"bullet" | "ordered" | "todo"} [listType]
|
|
172
199
|
*/
|
|
173
|
-
getOrCreateSublist(listType = "bullet") {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
200
|
+
getOrCreateSublist(listType = /** @type {any} */ (this.parent)?.listType || "bullet") {
|
|
201
|
+
const last = this.sublists.at(-1);
|
|
202
|
+
if (last && /** @type {any} */ (last).listType === listType) return last;
|
|
203
|
+
|
|
204
|
+
// No nabu.insert() here: it commits, and the list schema normalizer would delete this still-empty
|
|
205
|
+
// list before the caller had the chance to fill it.
|
|
206
|
+
return List.create(this.nabu, "list", { listType }, this.node.id.toString());
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A list item cannot simply change type where it stands (a list only holds items): it leaves its list,
|
|
211
|
+
* which is split around it, and keeps its text, marks and caret. See convert.js.
|
|
212
|
+
* @param {string} newType
|
|
213
|
+
* @param {Record<string, any>} [props={}]
|
|
214
|
+
*/
|
|
215
|
+
retype(newType, props = {}) {
|
|
216
|
+
retypeItem(this.nabu, /** @type {NabuNode} */ (this.node), newType, props);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* A paste landing in a list item: paragraphs and lists are absorbed as items of this list, any block an
|
|
221
|
+
* item cannot hold splits the list. See paste.js.
|
|
222
|
+
* @param {import('../../utils/extensions.js').PasteBlock[]} blocks
|
|
223
|
+
* @param {{ offset: number }} ctx
|
|
224
|
+
*/
|
|
225
|
+
acceptPaste(blocks, ctx) {
|
|
226
|
+
return pasteIntoItem(/** @type {any} */ (this), ctx.offset, blocks);
|
|
179
227
|
}
|
|
180
228
|
|
|
181
229
|
/** @param {KeyboardEvent} event */
|
|
182
230
|
keydown(event) {
|
|
183
|
-
if (event.key
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
indentListItem(this);
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
return false;
|
|
231
|
+
if (event.key !== 'Tab') return false;
|
|
232
|
+
// Single item, or a selection spanning several items that landed here (see ListExtension's onKeyDown).
|
|
233
|
+
if (handleTab(this.nabu, event)) return true;
|
|
234
|
+
// Plain Tab inside the item (modifier combos aside): never let the focus leave the editor.
|
|
235
|
+
return !(event.ctrlKey || event.altKey || event.metaKey);
|
|
193
236
|
}
|
|
194
237
|
|
|
195
238
|
/** @param {InputEvent} event */
|
|
@@ -221,20 +264,16 @@ export class ListItem extends MegaBlock {
|
|
|
221
264
|
split(options) {
|
|
222
265
|
return this.ascend("onSplit", null, {
|
|
223
266
|
offset: options?.offset || 0,
|
|
224
|
-
delta: this.behavior.container.sliceDelta(options?.offset || 0, this.
|
|
267
|
+
delta: this.behavior.container.sliceDelta(options?.offset || 0, this.behavior.container.length)
|
|
225
268
|
});
|
|
226
269
|
}
|
|
227
270
|
|
|
228
271
|
/**
|
|
229
272
|
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
230
|
-
* @param {
|
|
273
|
+
* @param {Partial<import('../../utils/extensions.js').SerializeContext> & { listType?: string, index?: number, start?: number, run?: number, indent?: string }} helpers `run`: position of the list among adjacent lists (marker alternation), `indent`: what the item is nested under
|
|
231
274
|
*/
|
|
232
|
-
static toMarkdown(pb, {
|
|
233
|
-
|
|
234
|
-
const prefix = listType === 'ordered' ? `${index + 1}.` : '-';
|
|
235
|
-
const text = deltaToMarkdown(pb.delta || []);
|
|
236
|
-
const sublists = (pb.children || []).map(sub => recurse(sub, { depth: depth + 1 })).join('\n');
|
|
237
|
-
return `${indent}${prefix} ${text}${sublists ? '\n' + sublists : ''}`;
|
|
275
|
+
static toMarkdown(pb, { listType = 'bullet', index = 0, start = 1, run = 0, indent = '' }) {
|
|
276
|
+
return renderItem(pb, markdownEnv, { listType, index, start, run, indent });
|
|
238
277
|
}
|
|
239
278
|
|
|
240
279
|
/**
|
|
@@ -244,6 +283,10 @@ export class ListItem extends MegaBlock {
|
|
|
244
283
|
static toHtml(pb, { recurse }) {
|
|
245
284
|
const text = deltaToHtml(pb.delta || []);
|
|
246
285
|
const sublists = (pb.children || []).map(recurse).join('');
|
|
286
|
+
if (pb.props?.checked !== undefined) {
|
|
287
|
+
const checkedAttr = pb.props.checked ? ' checked' : '';
|
|
288
|
+
return `<li><input type="checkbox" disabled${checkedAttr}> ${text}${sublists}</li>`;
|
|
289
|
+
}
|
|
247
290
|
return `<li>${text}${sublists}</li>`;
|
|
248
291
|
}
|
|
249
292
|
|
|
@@ -262,20 +305,27 @@ export class ListItem extends MegaBlock {
|
|
|
262
305
|
.map(parseBlock)
|
|
263
306
|
.filter(Boolean)
|
|
264
307
|
);
|
|
308
|
+
// Detect checkbox: <li><input type="checkbox"> or <li><p><input type="checkbox">
|
|
309
|
+
const cb = el.querySelector(':scope > input[type=checkbox], :scope > p > input[type=checkbox]') ||
|
|
310
|
+
el.querySelector('input[type=checkbox]');
|
|
265
311
|
/** @type {import('../../utils/extensions.js').PasteBlock} */
|
|
266
312
|
const result = { type: 'list-item', delta, partial: false };
|
|
313
|
+
if (cb) result.props = { checked: cb.hasAttribute('checked') };
|
|
314
|
+
// Google Docs checklist: `<li role="checkbox" aria-checked="true">`
|
|
315
|
+
else if (el.getAttribute('aria-checked') === 'true' || el.getAttribute('aria-checked') === 'false') result.props = { checked: el.getAttribute('aria-checked') === 'true' };
|
|
267
316
|
if (childLists.length) result.children = childLists;
|
|
268
317
|
return result;
|
|
269
318
|
}
|
|
270
319
|
|
|
271
|
-
/** @param {Nabu} nabu @param {string} type @param {
|
|
320
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
272
321
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
273
|
-
const node = nabu.tree.createNode(parentId || undefined, index
|
|
322
|
+
const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
|
|
274
323
|
node.data.set("type", "list-item");
|
|
275
324
|
const container = node.data.setContainer("text", new LoroText());
|
|
276
325
|
if (props.text) container.insert(0, props.text);
|
|
277
326
|
if (props.delta) container.applyDelta([...props.delta]);
|
|
278
|
-
|
|
327
|
+
if (props.checked !== undefined) /** @type {any} */ (node.data).set('checked', !!props.checked);
|
|
328
|
+
const block = new ListItem(nabu, /** @type {ListItemNode} */ (node));
|
|
279
329
|
return block;
|
|
280
330
|
}
|
|
281
331
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @import {LoroText} from "loro-crdt";
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered"}>} ListNode
|
|
6
|
+
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered" | "todo", start?: number}>} ListNode
|
|
7
7
|
*/
|
|
8
8
|
export class ListBehavior {
|
|
9
9
|
/** @param {Block} block */
|
|
@@ -11,14 +11,17 @@ export class ListBehavior {
|
|
|
11
11
|
block: Block;
|
|
12
12
|
nabu: import("..").Nabu;
|
|
13
13
|
node: ListNode;
|
|
14
|
-
/** @type {"bullet" | "ordered"} */
|
|
15
|
-
listType: "bullet" | "ordered";
|
|
14
|
+
/** @type {"bullet" | "ordered" | "todo"} */
|
|
15
|
+
listType: "bullet" | "ordered" | "todo";
|
|
16
|
+
/** Raw `start` number from the node (null = unset); List.start normalizes it. @type {number | null} */
|
|
17
|
+
start: number | null;
|
|
16
18
|
/** @param {Block} block */
|
|
17
19
|
absorbs(block: Block): true | undefined;
|
|
18
20
|
}
|
|
19
21
|
export type ListNode = NabuNode<{
|
|
20
22
|
type: "list";
|
|
21
|
-
listType: "bullet" | "ordered";
|
|
23
|
+
listType: "bullet" | "ordered" | "todo";
|
|
24
|
+
start?: number;
|
|
22
25
|
}>;
|
|
23
26
|
import type { Block } from "..";
|
|
24
27
|
import type { NabuNode } from "..";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MegaBlock } from "
|
|
1
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @import {Block, NabuNode} from "..";
|
|
@@ -6,7 +6,7 @@ import { MegaBlock } from "..";
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered"}>} ListNode
|
|
9
|
+
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered" | "todo", start?: number}>} ListNode
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export class ListBehavior {
|
|
@@ -15,13 +15,18 @@ export class ListBehavior {
|
|
|
15
15
|
this.block = block;
|
|
16
16
|
this.nabu = block.nabu;
|
|
17
17
|
this.node = /** @type {ListNode} */ (block.node);
|
|
18
|
-
this.listType = /** @type {"bullet" | "ordered"} */ (this.node.data.get("listType") || "bullet");
|
|
18
|
+
this.listType = /** @type {"bullet" | "ordered" | "todo"} */ (this.node.data.get("listType") || "bullet");
|
|
19
|
+
this.start = /** @type {any} */ (this.node.data.get("start")) ?? null;
|
|
19
20
|
this.node.data.subscribe(() => {
|
|
20
|
-
this.listType = /** @type {"bullet" | "ordered"} */ (this.node.data.get("listType") || "bullet");
|
|
21
|
+
this.listType = /** @type {"bullet" | "ordered" | "todo"} */ (this.node.data.get("listType") || "bullet");
|
|
22
|
+
this.start = /** @type {any} */ (this.node.data.get("start")) ?? null;
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
/** @type {
|
|
26
|
+
/** Raw `start` number from the node (null = unset); List.start normalizes it. @type {number | null} */
|
|
27
|
+
start = $state(null);
|
|
28
|
+
|
|
29
|
+
/** @type {"bullet" | "ordered" | "todo"} */
|
|
25
30
|
listType = $state("bullet");
|
|
26
31
|
|
|
27
32
|
/** @param {Block} block */
|
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered"}>} ListNode
|
|
5
|
+
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered" | "todo", start?: number}>} ListNode
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a list's `start` number: only meaningful for ORDERED lists, and `1` is the default.
|
|
9
|
+
* @param {string | undefined} listType
|
|
10
|
+
* @param {any} start a number, a numeric string (markdown / `<ol start>`), or nothing
|
|
11
|
+
* @returns {number | null} the number to store / emit, or null = default (omit it)
|
|
12
|
+
*/
|
|
13
|
+
export function listStart(listType: string | undefined, start: any): number | null;
|
|
7
14
|
export class List extends MegaBlock {
|
|
8
15
|
/**
|
|
16
|
+
* Markdown of a list and its sublists. Adjacent lists alternate their marker (`-` / `*`, `.` / `)`), see `adjacentRun`.
|
|
9
17
|
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
10
|
-
* @param {{
|
|
18
|
+
* @param {{ indent?: string, before?: import('../../utils/extensions.js').PasteBlock[] }} helpers `before`: the siblings before the list
|
|
11
19
|
*/
|
|
12
|
-
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, {
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { indent, before }: {
|
|
21
|
+
indent?: string;
|
|
22
|
+
before?: import("../../utils/extensions.js").PasteBlock[];
|
|
15
23
|
}): string;
|
|
16
24
|
/**
|
|
17
25
|
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
@@ -20,49 +28,116 @@ export class List extends MegaBlock {
|
|
|
20
28
|
static toHtml(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
21
29
|
recurse: (child: import("../../utils/extensions.js").PasteBlock) => string;
|
|
22
30
|
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* Markdown lists, see markdown.js: markers `-` `*` `+` `1.` `1)`, nesting by indentation (2 / 4 spaces, TAB), tasks,
|
|
33
|
+
* loose lists, continuation paragraphs of an item.
|
|
34
|
+
*/
|
|
23
35
|
static markdownRules: {
|
|
24
36
|
priority: number;
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
interruptsParagraph: (line: string) => boolean;
|
|
38
|
+
detect: (line: string) => boolean;
|
|
39
|
+
consume: (lines: string[], i: number, helpers: any) => number;
|
|
27
40
|
}[];
|
|
28
41
|
/**
|
|
29
|
-
* Parse markdown list lines into a nested List/ListItem PasteBlock tree
|
|
30
|
-
*
|
|
42
|
+
* Parse markdown list lines into a nested List/ListItem PasteBlock tree (an array when the marker type changes at
|
|
43
|
+
* the root: several lists).
|
|
31
44
|
*
|
|
32
45
|
* @param {string[]} lines
|
|
33
|
-
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
34
|
-
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
46
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[], joinLines?: boolean, softBreak?: string }} helpers
|
|
47
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | import('../../utils/extensions.js').PasteBlock[] | null}
|
|
35
48
|
*/
|
|
36
|
-
static fromMarkdown(lines: string[],
|
|
49
|
+
static fromMarkdown(lines: string[], helpers: {
|
|
37
50
|
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
joinLines?: boolean;
|
|
52
|
+
softBreak?: string;
|
|
53
|
+
}): import("../../utils/extensions.js").PasteBlock | import("../../utils/extensions.js").PasteBlock[] | null;
|
|
54
|
+
static htmlRules: ({
|
|
40
55
|
selector: string;
|
|
41
56
|
props: {
|
|
42
57
|
listType: string;
|
|
43
58
|
};
|
|
44
|
-
|
|
59
|
+
priority: number;
|
|
60
|
+
filter?: undefined;
|
|
61
|
+
} | {
|
|
62
|
+
selector: string;
|
|
63
|
+
filter: (el: Element) => boolean;
|
|
64
|
+
props: {
|
|
65
|
+
listType: string;
|
|
66
|
+
};
|
|
67
|
+
priority: number;
|
|
68
|
+
} | {
|
|
69
|
+
selector: string;
|
|
70
|
+
props: {
|
|
71
|
+
listType: string;
|
|
72
|
+
};
|
|
73
|
+
priority?: undefined;
|
|
74
|
+
filter?: undefined;
|
|
75
|
+
})[];
|
|
76
|
+
/**
|
|
77
|
+
* The elements after `el` that continue its list (the `html` interpreter reads them as part of this list): the `<ul>`
|
|
78
|
+
* per nesting level of Google Docs, the following list paragraphs of Word.
|
|
79
|
+
* @param {Element} el
|
|
80
|
+
* @returns {Element[]}
|
|
81
|
+
*/
|
|
82
|
+
static htmlSiblings(el: Element): Element[];
|
|
45
83
|
/**
|
|
46
84
|
* @param {Element} el
|
|
47
|
-
* @param {{ parseChildren: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
85
|
+
* @param {{ parseChildren: (el: Element) => import('../../utils/extensions.js').PasteBlock[], parseBlock: (el: Element) => import('../../utils/extensions.js').PasteBlock | null, parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
|
|
48
86
|
* @param {{ props?: { listType?: string } }} [rule]
|
|
87
|
+
* @param {Element[]} [siblings] what `htmlSiblings` absorbed
|
|
49
88
|
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
50
89
|
*/
|
|
51
|
-
static fromHTML(el: Element,
|
|
90
|
+
static fromHTML(el: Element, helpers: {
|
|
52
91
|
parseChildren: (el: Element) => import("../../utils/extensions.js").PasteBlock[];
|
|
92
|
+
parseBlock: (el: Element) => import("../../utils/extensions.js").PasteBlock | null;
|
|
93
|
+
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
53
94
|
}, rule?: {
|
|
54
95
|
props?: {
|
|
55
96
|
listType?: string;
|
|
56
97
|
};
|
|
57
|
-
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
58
|
-
/** @param {Nabu} nabu @param {string} type @param {
|
|
59
|
-
static create(nabu: Nabu, type: string, props?:
|
|
98
|
+
}, siblings?: Element[]): import("../../utils/extensions.js").PasteBlock | null;
|
|
99
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
100
|
+
static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): List;
|
|
60
101
|
/** @param {Nabu} nabu @param {ListNode} node */
|
|
61
102
|
constructor(nabu: Nabu, node: ListNode);
|
|
62
103
|
behavior: ListBehavior;
|
|
63
|
-
|
|
104
|
+
/**
|
|
105
|
+
* This list, its items and their sublists as PasteBlocks (the shape the static serializers read).
|
|
106
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
107
|
+
*/
|
|
108
|
+
toPasteBlock(): import("../../utils/extensions.js").PasteBlock;
|
|
109
|
+
/**
|
|
110
|
+
* The siblings before this list (the lists right before it decide its marker, see `adjacentRun`).
|
|
111
|
+
* @returns {Array<{ type: string, props: { listType?: string } }>}
|
|
112
|
+
*/
|
|
113
|
+
siblingsBefore(): Array<{
|
|
114
|
+
type: string;
|
|
115
|
+
props: {
|
|
116
|
+
listType?: string;
|
|
117
|
+
};
|
|
118
|
+
}>;
|
|
119
|
+
listType: "bullet" | "ordered" | "todo";
|
|
120
|
+
/** First number of an ORDERED list (`<ol start>`); null = 1, the default. @type {number | null} */
|
|
121
|
+
start: number | null;
|
|
122
|
+
/** `start` is only emitted when it is not the default. */
|
|
64
123
|
get clipboardProps(): {
|
|
65
|
-
listType: "bullet" | "ordered";
|
|
124
|
+
listType: "bullet" | "ordered" | "todo";
|
|
125
|
+
start?: undefined;
|
|
126
|
+
} | {
|
|
127
|
+
listType: "bullet" | "ordered" | "todo";
|
|
128
|
+
start: number;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Copying a slice that starts at item `firstChildIndex` of an ORDERED list: the copy is numbered from that item's
|
|
132
|
+
* visual number (`start + index`), not from the original list start.
|
|
133
|
+
* @param {number} firstChildIndex
|
|
134
|
+
*/
|
|
135
|
+
clipboardPropsFrom(firstChildIndex: number): {
|
|
136
|
+
listType: "bullet" | "ordered" | "todo";
|
|
137
|
+
start?: undefined;
|
|
138
|
+
} | {
|
|
139
|
+
listType: "bullet" | "ordered" | "todo";
|
|
140
|
+
start: number;
|
|
66
141
|
};
|
|
67
142
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
68
143
|
block: import("./list.svelte.js").List;
|
|
@@ -79,12 +154,15 @@ export class List extends MegaBlock {
|
|
|
79
154
|
offset: number;
|
|
80
155
|
delta: import("loro-crdt").Delta<string>;
|
|
81
156
|
}): {
|
|
157
|
+
block: import("./list-item.svelte.js").ListItem;
|
|
158
|
+
} | {
|
|
82
159
|
block: import("../block.svelte.js").Block;
|
|
83
160
|
};
|
|
84
161
|
}
|
|
85
162
|
export type ListNode = NabuNode<{
|
|
86
163
|
type: "list";
|
|
87
|
-
listType: "bullet" | "ordered";
|
|
164
|
+
listType: "bullet" | "ordered" | "todo";
|
|
165
|
+
start?: number;
|
|
88
166
|
}>;
|
|
89
167
|
import { MegaBlock } from "../megablock.svelte.js";
|
|
90
168
|
import { ListBehavior } from "./list.behavior.svelte.js";
|