@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
|
@@ -4,38 +4,51 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {NabuNode<{type: "dialogue", text: LoroText}>} DialogueNode
|
|
6
6
|
*/
|
|
7
|
-
export class Dialogue extends
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export class Dialogue extends TextBlock {
|
|
8
|
+
static placeholder: string;
|
|
9
|
+
/**
|
|
10
|
+
* Dialogue marker DISPLAYED in front of the line (CSS `::before`, see `--nb-dialogue-dash`). Purely visual:
|
|
11
|
+
* overridden by `createDialogueExtension({ dash })`, which registers a subclass. It never reaches the markdown.
|
|
12
|
+
*/
|
|
13
|
+
static dash: string;
|
|
14
|
+
/**
|
|
15
|
+
* Markdown syntax of a dialogue line: `-- text`. Fixed, independent of the displayed `dash` (an exchange
|
|
16
|
+
* format must not depend on a visual preference); `–` / `—` at the start of a line are NOT dialogue.
|
|
17
|
+
*/
|
|
18
|
+
static markdownMarker: string;
|
|
19
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
20
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
21
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
22
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
23
|
+
static markdownRules: {
|
|
24
|
+
priority: number;
|
|
25
|
+
interruptsParagraph: boolean;
|
|
26
|
+
detect: RegExp;
|
|
27
|
+
consume: () => number;
|
|
28
|
+
}[];
|
|
29
|
+
/**
|
|
30
|
+
* @param {string[]} lines
|
|
31
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
32
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
33
|
+
*/
|
|
34
|
+
static fromMarkdown(lines: string[], { parseInline }: {
|
|
35
|
+
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
36
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
37
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
38
|
+
static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): any;
|
|
10
39
|
/** @param {Nabu} nabu @param {DialogueNode} node */
|
|
11
40
|
constructor(nabu: Nabu, node: DialogueNode);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
behavior: TextBehavior;
|
|
41
|
+
/** @returns {string} */
|
|
42
|
+
get dash(): string;
|
|
15
43
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
16
44
|
block: import("./dialogue.svelte.js").Dialogue;
|
|
17
45
|
}, {}, "">;
|
|
18
|
-
get text(): string;
|
|
19
|
-
get delta(): import("loro-crdt").Delta<string>[];
|
|
20
|
-
selection: {
|
|
21
|
-
from: number;
|
|
22
|
-
to: number;
|
|
23
|
-
isCollapsed: boolean;
|
|
24
|
-
direction: "forward" | "backward" | "none";
|
|
25
|
-
} | null;
|
|
26
|
-
/** @param {Block} block */
|
|
27
|
-
absorbs(block: Block): boolean;
|
|
28
|
-
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
29
|
-
applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
|
|
30
|
-
/** @param {Parameters<Block["split"]>[0]} [options] @returns {ReturnType<Block["split"]>} */
|
|
31
|
-
split(options?: Parameters<Block["split"]>[0]): ReturnType<Block["split"]>;
|
|
32
46
|
}
|
|
33
47
|
export type DialogueNode = NabuNode<{
|
|
34
48
|
type: "dialogue";
|
|
35
49
|
text: LoroText;
|
|
36
50
|
}>;
|
|
37
|
-
import {
|
|
38
|
-
import { LoroText } from "loro-crdt";
|
|
39
|
-
import { TextBehavior } from "../../behaviors/text";
|
|
51
|
+
import { TextBlock } from "../text-block.svelte.js";
|
|
40
52
|
import type { Nabu } from "../nabu.svelte.js";
|
|
53
|
+
import { LoroText } from "loro-crdt";
|
|
41
54
|
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TextBlock } from "../text-block.svelte.js";
|
|
2
2
|
import { LoroText } from "loro-crdt";
|
|
3
3
|
import DialogueComponent from "./Dialogue.svelte";
|
|
4
|
-
import {
|
|
4
|
+
import { deltaToMarkdown, deltaToHtml } from "../../behaviors/text";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
@@ -11,19 +11,12 @@ import { TextBehavior } from "../../behaviors/text";
|
|
|
11
11
|
* @typedef {NabuNode<{type: "dialogue", text: LoroText}>} DialogueNode
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
export class Dialogue extends
|
|
14
|
+
export class Dialogue extends TextBlock {
|
|
15
15
|
/** @param {Nabu} nabu @param {DialogueNode} node */
|
|
16
16
|
constructor(nabu, node) {
|
|
17
17
|
super(nabu, node);
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
this.container = data.get("text") ?? data.setContainer("text", new LoroText());
|
|
21
|
-
|
|
22
|
-
/** @type {TextBehavior} */
|
|
23
|
-
this.behavior = new TextBehavior(this, this.container);
|
|
24
|
-
this.behaviors.set("text", this.behavior);
|
|
25
|
-
|
|
26
|
-
this.serializers.set('markdown', () => `— ${this.behavior.toMarkdown()}`);
|
|
19
|
+
this.serializers.set('markdown', () => { const md = this.behavior.toMarkdown(); return md ? `${Dialogue.markdownMarker} ${md}` : ''; }); // an empty line has no markdown
|
|
27
20
|
this.serializers.set('json', () => ({
|
|
28
21
|
id: this.id,
|
|
29
22
|
type: 'dialogue',
|
|
@@ -32,56 +25,69 @@ export class Dialogue extends Block {
|
|
|
32
25
|
this.serializers.set('application/x-nabu+json', (ctx) => this.behavior.toClipboardBlock(ctx));
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
|
|
28
|
+
static placeholder = 'Dialogue...';
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Dialogue marker DISPLAYED in front of the line (CSS `::before`, see `--nb-dialogue-dash`). Purely visual:
|
|
32
|
+
* overridden by `createDialogueExtension({ dash })`, which registers a subclass. It never reaches the markdown.
|
|
33
|
+
*/
|
|
34
|
+
static dash = '–';
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Markdown syntax of a dialogue line: `-- text`. Fixed, independent of the displayed `dash` (an exchange
|
|
38
|
+
* format must not depend on a visual preference); `–` / `—` at the start of a line are NOT dialogue.
|
|
39
|
+
*/
|
|
40
|
+
static markdownMarker = '--';
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
/** @returns {string} */
|
|
43
|
+
get dash() { return /** @type {typeof Dialogue} */ (this.constructor).dash; }
|
|
47
44
|
|
|
48
|
-
/** @param {
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
46
|
+
static toMarkdown(pb) {
|
|
47
|
+
const md = deltaToMarkdown(pb.delta || []);
|
|
48
|
+
return md ? `${Dialogue.markdownMarker} ${md}` : ''; // an empty line has no markdown
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*/
|
|
57
|
-
getDOMPoint(targetOffset) {
|
|
58
|
-
if (!this.element) return null;
|
|
59
|
-
return this.behavior.getDOMPoint(targetOffset);
|
|
51
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
52
|
+
static toHtml(pb) {
|
|
53
|
+
return `<p>${deltaToHtml(pb.delta || [])}</p>`;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
static markdownRules = [
|
|
57
|
+
{
|
|
58
|
+
priority: 10,
|
|
59
|
+
interruptsParagraph: true,
|
|
60
|
+
detect: /^-- /,
|
|
61
|
+
consume: () => 1,
|
|
62
|
+
}
|
|
63
|
+
];
|
|
70
64
|
|
|
71
|
-
/**
|
|
72
|
-
|
|
65
|
+
/**
|
|
66
|
+
* @param {string[]} lines
|
|
67
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
68
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
69
|
+
*/
|
|
70
|
+
static fromMarkdown(lines, { parseInline }) {
|
|
71
|
+
const m = lines[0].match(/^-- +(.*)/);
|
|
72
|
+
if (!m) return null;
|
|
73
|
+
const delta = parseInline(m[1]);
|
|
74
|
+
if (!delta.length) return null;
|
|
75
|
+
return { type: 'dialogue', delta, partial: false };
|
|
76
|
+
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
split(options) { return this.behavior.split(options); }
|
|
78
|
+
component = $derived(this.nabu.components.get("dialogue") || DialogueComponent);
|
|
76
79
|
|
|
77
|
-
/** @param {Nabu} nabu @param {string} type @param {
|
|
80
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
78
81
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
79
|
-
const node = nabu.tree.createNode(parentId || undefined, index
|
|
82
|
+
const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
|
|
80
83
|
node.data.set("type", "dialogue");
|
|
81
84
|
const container = node.data.setContainer("text", new LoroText());
|
|
82
85
|
if (props.text) container.insert(0, props.text);
|
|
83
86
|
if (props.delta) container.applyDelta([...props.delta]);
|
|
84
|
-
|
|
87
|
+
// The registered class: a configured subclass (see createDialogueExtension) must be the one instantiated.
|
|
88
|
+
/** @type {any} */
|
|
89
|
+
const BlockClass = nabu.registry.get("dialogue") || Dialogue;
|
|
90
|
+
const block = new BlockClass(nabu, node);
|
|
85
91
|
return block;
|
|
86
92
|
}
|
|
87
93
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export function onBeforeInput(nabu: Nabu, event: InputEvent, block: Block): symbol;
|
|
2
|
-
import type { Nabu } from "
|
|
3
|
-
import type { Block } from "
|
|
2
|
+
import type { Nabu } from "../..";
|
|
3
|
+
import type { Block } from "../..";
|
|
@@ -3,7 +3,7 @@ import { TextBehavior } from "../../../behaviors/text";
|
|
|
3
3
|
import { Dialogue } from "../dialogue.svelte.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @import { Nabu, Block } from "
|
|
6
|
+
* @import { Nabu, Block } from "../..";
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/** @param {Nabu} nabu @param {InputEvent} event @param {Block} block */
|
|
@@ -38,10 +38,12 @@ export const onBeforeInput = (nabu, event, block) => {
|
|
|
38
38
|
const textBeforeCursor = behavior.text.slice(0, sel.from);
|
|
39
39
|
if (textBeforeCursor !== "--") return CONTINUE;
|
|
40
40
|
|
|
41
|
-
behavior.delete({ index: 0, length: 2 });
|
|
42
|
-
|
|
43
41
|
const blockId = block.node.id.toString();
|
|
44
|
-
|
|
42
|
+
// Undo gives back "-- " (trigger space included): see Nabu.shortcut()
|
|
43
|
+
nabu.shortcut(block, " ", (b) => {
|
|
44
|
+
b.delete({ index: 0, length: 3 });
|
|
45
|
+
block.transformTo("dialogue");
|
|
46
|
+
});
|
|
45
47
|
|
|
46
48
|
tick().then(() => {
|
|
47
49
|
const b = nabu.blocks.get(blockId);
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { Nabu } from "../nabu.svelte.js";
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Dialogue extension factory.
|
|
6
|
+
* @param {{ dash?: string }} [options]
|
|
7
|
+
* `dash` (default `–`, EN dash): the marker DISPLAYED in front of a dialogue line (CSS custom property
|
|
8
|
+
* `--nb-dialogue-dash`, which a host can also override in CSS). Display only: the markdown syntax of a
|
|
9
|
+
* dialogue line is always `-- text`, whatever the dash.
|
|
10
|
+
*/
|
|
11
|
+
export function createDialogueExtension({ dash }?: {
|
|
12
|
+
dash?: string;
|
|
13
|
+
}): import("../../extend.js").Extension;
|
|
14
|
+
/** Default instance (dash `–`). */
|
|
15
|
+
export const DialogueExtension: import("../../extend.js").Extension;
|
|
5
16
|
import DialogueComponent from "./Dialogue.svelte";
|
|
6
17
|
import { Dialogue } from "./dialogue.svelte.js";
|
|
7
18
|
export { DialogueComponent, Dialogue };
|
|
@@ -8,40 +8,56 @@ import { onBeforeInput } from "./hooks/onBeforeInput.hook.js";
|
|
|
8
8
|
* @import { Nabu } from "../nabu.svelte.js";
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Dialogue extension factory.
|
|
13
|
+
* @param {{ dash?: string }} [options]
|
|
14
|
+
* `dash` (default `–`, EN dash): the marker DISPLAYED in front of a dialogue line (CSS custom property
|
|
15
|
+
* `--nb-dialogue-dash`, which a host can also override in CSS). Display only: the markdown syntax of a
|
|
16
|
+
* dialogue line is always `-- text`, whatever the dash.
|
|
17
|
+
*/
|
|
18
|
+
export function createDialogueExtension({ dash = '–' } = {}) {
|
|
19
|
+
const BlockClass = dash === Dialogue.dash
|
|
20
|
+
? Dialogue
|
|
21
|
+
: class extends Dialogue { static dash = dash; };
|
|
22
|
+
return extension("dialogue", {
|
|
23
|
+
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
24
|
+
block: BlockClass,
|
|
25
|
+
component: DialogueComponent,
|
|
26
|
+
hooks: {
|
|
27
|
+
/** @param {Nabu} nabu @param {Dialogue} block @param {Event | null} event @param {import('../../utils/extensions.js').SplitData} data */
|
|
28
|
+
onSplit: (nabu, block, event, data) => {
|
|
29
|
+
const { offset, delta } = data;
|
|
30
|
+
|
|
31
|
+
// Bloc dialogue vide + Entrée → sortir du mode dialogue
|
|
32
|
+
if (block.text.length === 0) {
|
|
33
|
+
const blockId = block.node.id.toString();
|
|
34
|
+
block.transformTo("paragraph");
|
|
35
|
+
tick().then(() => {
|
|
36
|
+
const b = nabu.blocks.get(blockId);
|
|
37
|
+
if (b) b.focus({ start: 0, end: 0 });
|
|
38
|
+
});
|
|
39
|
+
return { block };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Bloc non vide + Entrée → créer un nouveau bloc dialogue après
|
|
43
|
+
block.delete({ from: offset, to: -1 });
|
|
44
|
+
|
|
45
|
+
const currentIndex = block.node.index() ?? 0;
|
|
46
|
+
const parent = block.node.parent();
|
|
47
|
+
const parentId = parent?.id.toString() || null;
|
|
48
|
+
|
|
49
|
+
const newBlock = nabu.insert("dialogue", { delta }, parentId, currentIndex + 1);
|
|
50
|
+
|
|
51
|
+
block.commit().then(() => nabu.selection.setCursor(newBlock, 0));
|
|
52
|
+
|
|
53
|
+
return { block: newBlock };
|
|
54
|
+
},
|
|
55
|
+
onBeforeInput,
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Default instance (dash `–`). */
|
|
61
|
+
const DialogueExtension = createDialogueExtension();
|
|
46
62
|
|
|
47
63
|
export { DialogueExtension, DialogueComponent, Dialogue };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {{block: import('./divider.svelte.js').DividerBlock}}*/
|
|
3
|
+
let {block} = $props();
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<hr
|
|
7
|
+
bind:this={block.element}
|
|
8
|
+
data-block-id={block.id}
|
|
9
|
+
data-block-type="divider"
|
|
10
|
+
data-nabu-inert
|
|
11
|
+
contenteditable="false"
|
|
12
|
+
class="nabu-divider"
|
|
13
|
+
class:debug={block.nabu.debugging}
|
|
14
|
+
class:selected={block.selected}
|
|
15
|
+
/>
|
|
16
|
+
|
|
17
|
+
<style>
|
|
18
|
+
.nabu-divider {
|
|
19
|
+
border: none;
|
|
20
|
+
border-top: 1px solid var(--nb-border, rgba(255, 255, 255, 0.15));
|
|
21
|
+
margin: 1em 0;
|
|
22
|
+
user-select: none;
|
|
23
|
+
|
|
24
|
+
&.debug.selected {
|
|
25
|
+
background-color: rgba(59, 130, 246, 0.25);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Divider;
|
|
2
|
+
type Divider = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Divider: import("svelte").Component<{
|
|
7
|
+
block: import("./divider.svelte.js").DividerBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./divider.svelte.js").DividerBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, Block } from "..";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The ONE divider-insertion path, shared by the `--- ` markdown shortcut and the `divider:insert`
|
|
6
|
+
* action (slash menu `/divider`). Mutations only: the caller commits.
|
|
7
|
+
* - `block` is EMPTY (a paragraph; also any other childless text block except a list item, so `--- `
|
|
8
|
+
* still works in a heading / quote…) → it becomes the divider;
|
|
9
|
+
* - otherwise → a divider is inserted right after the block (after its outermost list when the block
|
|
10
|
+
* sits in one: a divider must not become a child of a list).
|
|
11
|
+
* Either way an empty paragraph is created below the divider, ready for the caret.
|
|
12
|
+
*
|
|
13
|
+
* @param {Nabu} nabu
|
|
14
|
+
* @param {Block} block the block the divider is typed / inserted in
|
|
15
|
+
* @returns {Block | null} the new empty paragraph below the divider
|
|
16
|
+
*/
|
|
17
|
+
export function insertDivider(nabu: Nabu, block: Block): Block | null;
|
|
18
|
+
/**
|
|
19
|
+
* The divider block (a horizontal rule): the `--- ` shortcut, markdown and HTML paste rules, and the "Divider" slash entry.
|
|
20
|
+
*/
|
|
21
|
+
export const DividerExtension: import("../../extend.js").Extension;
|
|
22
|
+
import type { Nabu } from "..";
|
|
23
|
+
import type { Block } from "..";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { TextBehavior } from "../../behaviors/text";
|
|
2
|
+
import { extension } from "../../utils/extensions";
|
|
3
|
+
import { DividerBlock } from "./divider.svelte.js";
|
|
4
|
+
import DividerComponent from "./Divider.svelte";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @import { Nabu, Block } from "..";
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The ONE divider-insertion path, shared by the `--- ` markdown shortcut and the `divider:insert`
|
|
12
|
+
* action (slash menu `/divider`). Mutations only: the caller commits.
|
|
13
|
+
* - `block` is EMPTY (a paragraph; also any other childless text block except a list item, so `--- `
|
|
14
|
+
* still works in a heading / quote…) → it becomes the divider;
|
|
15
|
+
* - otherwise → a divider is inserted right after the block (after its outermost list when the block
|
|
16
|
+
* sits in one: a divider must not become a child of a list).
|
|
17
|
+
* Either way an empty paragraph is created below the divider, ready for the caret.
|
|
18
|
+
*
|
|
19
|
+
* @param {Nabu} nabu
|
|
20
|
+
* @param {Block} block the block the divider is typed / inserted in
|
|
21
|
+
* @returns {Block | null} the new empty paragraph below the divider
|
|
22
|
+
*/
|
|
23
|
+
export function insertDivider(nabu, block) {
|
|
24
|
+
const behavior = block.behaviors.get("text");
|
|
25
|
+
const isEmpty = behavior instanceof TextBehavior && behavior.container.length === 0
|
|
26
|
+
&& block.type !== "list-item" && !(/** @type {any} */ (block).children?.length);
|
|
27
|
+
|
|
28
|
+
/** @type {Block} */
|
|
29
|
+
let anchor = block;
|
|
30
|
+
if (!isEmpty) {
|
|
31
|
+
while (anchor.parent && (anchor.parent.type === "list" || anchor.parent.type === "list-item")) anchor = /** @type {Block} */ (/** @type {unknown} */ (anchor.parent));
|
|
32
|
+
}
|
|
33
|
+
const node = anchor.node;
|
|
34
|
+
const parentId = node.parent()?.id.toString() || null;
|
|
35
|
+
let index = node.index() ?? 0;
|
|
36
|
+
|
|
37
|
+
if (isEmpty) {
|
|
38
|
+
block.node.data.set("type", "divider");
|
|
39
|
+
} else {
|
|
40
|
+
DividerBlock.create(nabu, "divider", {}, parentId, index + 1);
|
|
41
|
+
index += 1;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const PClass = nabu.registry.get("paragraph");
|
|
45
|
+
return PClass ? PClass.create(nabu, "paragraph", {}, parentId, index + 1) : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Commit a divider insertion and move the caret into the paragraph below it.
|
|
50
|
+
* @param {Nabu} nabu @param {Block} block @returns {Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
async function commitDivider(nabu, block) {
|
|
53
|
+
const paragraph = insertDivider(nabu, block);
|
|
54
|
+
await nabu.commit();
|
|
55
|
+
if (!paragraph) return;
|
|
56
|
+
const fresh = nabu.blocks.get(paragraph.id);
|
|
57
|
+
if (fresh) nabu.selection.setCursor(fresh, 0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Divider hooks:
|
|
62
|
+
* - `---` + space in a block containing only `---` → replace it with a
|
|
63
|
+
* divider and insert an empty paragraph after (see insertDivider).
|
|
64
|
+
* - Backspace at the start of a block whose previous sibling is a divider
|
|
65
|
+
* → delete the divider (otherwise the text merge would skip over it and
|
|
66
|
+
* leave it orphaned).
|
|
67
|
+
* - Delete at the end of a block whose next sibling is a divider → delete the divider (symmetric).
|
|
68
|
+
*
|
|
69
|
+
* @param {Nabu} nabu @param {InputEvent} event @param {Block} block
|
|
70
|
+
*/
|
|
71
|
+
const onBeforeInput = (nabu, event, block) => {
|
|
72
|
+
const { BREAK, CONTINUE } = nabu;
|
|
73
|
+
|
|
74
|
+
const behavior = block.behaviors.get("text");
|
|
75
|
+
if (!behavior || !(behavior instanceof TextBehavior)) return CONTINUE;
|
|
76
|
+
const sel = behavior.selection;
|
|
77
|
+
if (!sel || !sel.isCollapsed) return CONTINUE;
|
|
78
|
+
|
|
79
|
+
// Backspace right after a divider → delete the divider
|
|
80
|
+
if (event.inputType === "deleteContentBackward" && sel.from === 0) {
|
|
81
|
+
const { previous } = block.getAdjacentSiblings();
|
|
82
|
+
if (previous?.type !== 'divider') return CONTINUE;
|
|
83
|
+
const blockId = block.id;
|
|
84
|
+
nabu.tree.delete(previous.node.id);
|
|
85
|
+
nabu.commit().then(() => {
|
|
86
|
+
const fresh = nabu.blocks.get(blockId);
|
|
87
|
+
if (fresh) nabu.selection.setCursor(fresh, 0);
|
|
88
|
+
});
|
|
89
|
+
return BREAK;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Delete at the END of the block right BEFORE a divider → delete the divider (symmetric with Backspace
|
|
93
|
+
// after it). The text and the caret are kept; one transaction = one undo step.
|
|
94
|
+
if (event.inputType === "deleteContentForward" && sel.from === behavior.text.length) {
|
|
95
|
+
const { next } = block.getAdjacentSiblings();
|
|
96
|
+
if (next?.type !== 'divider') return CONTINUE;
|
|
97
|
+
const blockId = block.id;
|
|
98
|
+
const offset = sel.from;
|
|
99
|
+
nabu.tree.delete(next.node.id);
|
|
100
|
+
nabu.commit().then(() => {
|
|
101
|
+
const fresh = nabu.blocks.get(blockId);
|
|
102
|
+
if (fresh) nabu.selection.setCursor(fresh, offset);
|
|
103
|
+
});
|
|
104
|
+
return BREAK;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// `--- ` markdown shortcut: block contains exactly `---` and a space is typed
|
|
108
|
+
if (event.inputType === "insertText" && event.data === " ") {
|
|
109
|
+
if (behavior.text !== "---" || sel.from !== 3) return CONTINUE;
|
|
110
|
+
|
|
111
|
+
/** @type {Block | null} */
|
|
112
|
+
let paragraph = null;
|
|
113
|
+
// Undo gives back "--- " (trigger space included): see Nabu.shortcut()
|
|
114
|
+
nabu.shortcut(block, " ", (b) => {
|
|
115
|
+
b.delete({ index: 0, length: 4 });
|
|
116
|
+
paragraph = insertDivider(nabu, block);
|
|
117
|
+
}).then(() => {
|
|
118
|
+
const fresh = paragraph && nabu.blocks.get(/** @type {Block} */ (paragraph).id);
|
|
119
|
+
if (fresh) nabu.selection.setCursor(fresh, 0);
|
|
120
|
+
});
|
|
121
|
+
return BREAK;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return CONTINUE;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The divider block (a horizontal rule): the `--- ` shortcut, markdown and HTML paste rules, and the "Divider" slash entry.
|
|
129
|
+
*/
|
|
130
|
+
export const DividerExtension = extension("divider", {
|
|
131
|
+
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
132
|
+
block: DividerBlock,
|
|
133
|
+
component: DividerComponent,
|
|
134
|
+
slashCommands: [
|
|
135
|
+
{ title: 'Divider', icon: '—', aliases: ['divider', 'hr', 'separator', 'rule'], group: 'blocks', order: 40, run: (e) => e.exec('divider:insert') },
|
|
136
|
+
],
|
|
137
|
+
actions: {
|
|
138
|
+
/**
|
|
139
|
+
* Insert a divider like the `--- ` shortcut does (see insertDivider): an empty paragraph
|
|
140
|
+
* becomes the divider, any other block gets one right after it; the caret lands in a new
|
|
141
|
+
* paragraph below the divider.
|
|
142
|
+
* @param {Nabu} nabu
|
|
143
|
+
*/
|
|
144
|
+
'divider:insert': (nabu) => {
|
|
145
|
+
const anchor = nabu.selection.anchorBlock;
|
|
146
|
+
if (!anchor) return;
|
|
147
|
+
return commitDivider(nabu, anchor);
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
hooks: {
|
|
151
|
+
onBeforeInput,
|
|
152
|
+
}
|
|
153
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{type: "divider"}>} DividerNode
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Horizontal rule. First non-textual block: no TextBehavior, renders an
|
|
9
|
+
* inert <hr> and exposes a single cursor position so document-offset
|
|
10
|
+
* resolution can step over it.
|
|
11
|
+
*/
|
|
12
|
+
export class DividerBlock extends Block {
|
|
13
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
14
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
15
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
16
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
17
|
+
/**
|
|
18
|
+
* Thematic break (CommonMark): 3+ `-`, `*` or `_` (the same one), spaces allowed between (`* * *`), up to 3 spaces of
|
|
19
|
+
* indent. A `---` right under a line of text is a setext heading underline, not a divider (see the heading block).
|
|
20
|
+
*/
|
|
21
|
+
static markdownRules: {
|
|
22
|
+
priority: number;
|
|
23
|
+
interruptsParagraph: boolean;
|
|
24
|
+
detect: RegExp;
|
|
25
|
+
consume: () => number;
|
|
26
|
+
}[];
|
|
27
|
+
/**
|
|
28
|
+
* @param {string[]} lines
|
|
29
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
30
|
+
*/
|
|
31
|
+
static fromMarkdown(lines: string[]): import("../../utils/extensions.js").PasteBlock | null;
|
|
32
|
+
static htmlRules: {
|
|
33
|
+
selector: string;
|
|
34
|
+
}[];
|
|
35
|
+
/**
|
|
36
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
37
|
+
*/
|
|
38
|
+
static fromHTML(): import("../../utils/extensions.js").PasteBlock;
|
|
39
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
40
|
+
static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): DividerBlock;
|
|
41
|
+
/** @param {Nabu} nabu @param {DividerNode} node */
|
|
42
|
+
constructor(nabu: Nabu, node: DividerNode);
|
|
43
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
44
|
+
block: import("./divider.svelte.js").DividerBlock;
|
|
45
|
+
}, {}, "">;
|
|
46
|
+
/** @param {InputEvent} event */
|
|
47
|
+
beforeinput(event: InputEvent): boolean;
|
|
48
|
+
}
|
|
49
|
+
export type DividerNode = NabuNode<{
|
|
50
|
+
type: "divider";
|
|
51
|
+
}>;
|
|
52
|
+
import { Block } from "../block.svelte.js";
|
|
53
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
54
|
+
import type { NabuNode } from "../nabu.svelte.js";
|