@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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import RichText from '../../behaviors/text/RichText.svelte';
|
|
3
|
+
/** @type {{block: import('./blockquote.svelte.js').BlockquoteBlock}}*/
|
|
4
|
+
let {block} = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<blockquote
|
|
8
|
+
bind:this={block.element}
|
|
9
|
+
data-block-id={block.id}
|
|
10
|
+
data-block-type="blockquote"
|
|
11
|
+
data-placeholder={block.placeholder}
|
|
12
|
+
class="nabu-blockquote"
|
|
13
|
+
class:debug={block.nabu.debugging}
|
|
14
|
+
class:selected={block.selected}
|
|
15
|
+
class:first={block.isSelectionStart}
|
|
16
|
+
class:last={block.isSelectionEnd}
|
|
17
|
+
><RichText delta={block.delta} /></blockquote>
|
|
18
|
+
|
|
19
|
+
<style>
|
|
20
|
+
.nabu-blockquote {
|
|
21
|
+
white-space: pre-wrap;
|
|
22
|
+
margin: 0 0 0.5em 0;
|
|
23
|
+
padding: 0.25em 0 0.25em 0.875em;
|
|
24
|
+
border-left: 3px solid var(--nb-border, rgba(255, 255, 255, 0.25));
|
|
25
|
+
color: var(--nb-text-secondary, inherit);
|
|
26
|
+
|
|
27
|
+
&.debug{
|
|
28
|
+
&.selected {
|
|
29
|
+
background-color: rgba(59, 130, 246, 0.25);
|
|
30
|
+
}
|
|
31
|
+
&.first {
|
|
32
|
+
border-top: 1px solid rgba(59, 130, 246, 0.5);
|
|
33
|
+
}
|
|
34
|
+
&.last {
|
|
35
|
+
border-bottom: 1px solid rgba(59, 130, 246, 0.5);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Blockquote;
|
|
2
|
+
type Blockquote = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Blockquote: import("svelte").Component<{
|
|
7
|
+
block: import("./blockquote.svelte.js").BlockquoteBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./blockquote.svelte.js").BlockquoteBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { tick } from "svelte";
|
|
2
|
+
import { TextBehavior } from "../../behaviors/text";
|
|
3
|
+
import { extension } from "../../utils/extensions";
|
|
4
|
+
import { BlockquoteBlock } from "./blockquote.svelte.js";
|
|
5
|
+
import BlockquoteComponent from "./Blockquote.svelte";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import { Nabu, Block } from "..";
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Markdown shortcut + de-transformation hooks for blockquotes:
|
|
13
|
+
* - `> ` at the start of a block → transform into blockquote
|
|
14
|
+
* - Backspace at the start of a blockquote → transform back into paragraph
|
|
15
|
+
* - Enter in an empty blockquote → exit the quote (becomes a paragraph)
|
|
16
|
+
*
|
|
17
|
+
* @param {Nabu} nabu @param {InputEvent} event @param {Block} block
|
|
18
|
+
*/
|
|
19
|
+
const onBeforeInput = (nabu, event, block) => {
|
|
20
|
+
const { BREAK, CONTINUE } = nabu;
|
|
21
|
+
|
|
22
|
+
const behavior = block.behaviors.get("text");
|
|
23
|
+
if (!behavior || !(behavior instanceof TextBehavior)) return CONTINUE;
|
|
24
|
+
const sel = behavior.selection;
|
|
25
|
+
if (!sel || !sel.isCollapsed) return CONTINUE;
|
|
26
|
+
|
|
27
|
+
/** @param {string} type @param {() => void} [transform] */
|
|
28
|
+
const transformAndFocus = (type, transform = () => block.transformTo(type)) => {
|
|
29
|
+
const blockId = block.node.id.toString();
|
|
30
|
+
transform();
|
|
31
|
+
tick().then(() => {
|
|
32
|
+
const fresh = nabu.blocks.get(blockId);
|
|
33
|
+
if (fresh) fresh.focus({ start: 0, end: 0 });
|
|
34
|
+
});
|
|
35
|
+
return BREAK;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (block instanceof BlockquoteBlock) {
|
|
39
|
+
// Backspace at the very start → back to paragraph
|
|
40
|
+
if (event.inputType === "deleteContentBackward" && sel.from === 0) {
|
|
41
|
+
return transformAndFocus("paragraph");
|
|
42
|
+
}
|
|
43
|
+
// Enter in an empty blockquote → exit the quote
|
|
44
|
+
if (event.inputType === "insertParagraph" && behavior.text.length === 0) {
|
|
45
|
+
return transformAndFocus("paragraph");
|
|
46
|
+
}
|
|
47
|
+
return CONTINUE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// `> ` markdown shortcut (typed space after a lone ">" at block start)
|
|
51
|
+
if (event.inputType === "insertText" && event.data === " ") {
|
|
52
|
+
const textBeforeCursor = behavior.text.slice(0, sel.from);
|
|
53
|
+
if (textBeforeCursor !== ">") return CONTINUE;
|
|
54
|
+
// Undo gives back "> " (trigger space included): see Nabu.shortcut()
|
|
55
|
+
return transformAndFocus("blockquote", () => nabu.shortcut(block, " ", (b) => {
|
|
56
|
+
b.delete({ index: 0, length: 2 });
|
|
57
|
+
block.transformTo("blockquote");
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return CONTINUE;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The quote block: the `> ` shortcut, Backspace and Enter de-transformations, markdown and HTML paste rules, and the "Quote" slash entry.
|
|
66
|
+
*/
|
|
67
|
+
export const BlockquoteExtension = extension("blockquote", {
|
|
68
|
+
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
69
|
+
block: BlockquoteBlock,
|
|
70
|
+
component: BlockquoteComponent,
|
|
71
|
+
slashCommands: [
|
|
72
|
+
{ title: 'Quote', icon: '"', aliases: ['quote', 'blockquote'], group: 'blocks', order: 20, run: (e) => e.exec('blockquote') },
|
|
73
|
+
],
|
|
74
|
+
actions: {
|
|
75
|
+
'blockquote': (nabu) => nabu.exec('block:transform', { type: 'blockquote' }),
|
|
76
|
+
},
|
|
77
|
+
hooks: {
|
|
78
|
+
onBeforeInput,
|
|
79
|
+
}
|
|
80
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class BlockquoteBlock extends TextBlock {
|
|
2
|
+
static placeholder: string;
|
|
3
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
4
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
5
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
6
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
7
|
+
/**
|
|
8
|
+
* A quote is a block of TEXT (it cannot hold other blocks), so:
|
|
9
|
+
* - nested levels (`> > x`) are FLATTENED into the one quote, the text is kept;
|
|
10
|
+
* - a lazy continuation line (no `>`) belongs to the quote on import (CommonMark) and in a paste after a hard break;
|
|
11
|
+
* - the content is parsed as a document of its own: its text paragraphs become quotes (one per paragraph, the lines of
|
|
12
|
+
* a paragraph joined by a line break in a paste, by a space on import), and what it holds that is not text (a list, a
|
|
13
|
+
* fenced code, a heading, a divider, an image, a table) becomes the block it is, in order, outside any quote: the
|
|
14
|
+
* quote mark is lost, no text is.
|
|
15
|
+
* A callout (`> [!NOTE]`) has a higher priority rule of its own.
|
|
16
|
+
*/
|
|
17
|
+
static markdownRules: {
|
|
18
|
+
priority: number;
|
|
19
|
+
interruptsParagraph: boolean;
|
|
20
|
+
detect: RegExp;
|
|
21
|
+
consume(lines: string[], i: number, helpers: any): number;
|
|
22
|
+
}[];
|
|
23
|
+
/**
|
|
24
|
+
* @param {string[]} lines
|
|
25
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[], parseBlocks?: (lines: string[], overrides?: object) => import('../../utils/extensions.js').PasteBlock[], joinLines?: boolean }} helpers
|
|
26
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | import('../../utils/extensions.js').PasteBlock[] | null}
|
|
27
|
+
*/
|
|
28
|
+
static fromMarkdown(lines: string[], { parseInline, parseBlocks, joinLines }: {
|
|
29
|
+
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
30
|
+
parseBlocks?: (lines: string[], overrides?: object) => import("../../utils/extensions.js").PasteBlock[];
|
|
31
|
+
joinLines?: boolean;
|
|
32
|
+
}): import("../../utils/extensions.js").PasteBlock | import("../../utils/extensions.js").PasteBlock[] | null;
|
|
33
|
+
static htmlRules: {
|
|
34
|
+
selector: string;
|
|
35
|
+
priority: number;
|
|
36
|
+
}[];
|
|
37
|
+
/**
|
|
38
|
+
* @param {Element} el
|
|
39
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
|
|
40
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
41
|
+
*/
|
|
42
|
+
static fromHTML(el: Element, { parseInline }: {
|
|
43
|
+
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
44
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
45
|
+
/** @param {Nabu} nabu @param {string} type @param {{text?: string, delta?: import('loro-crdt').Delta<string>[]}} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
46
|
+
static create(nabu: Nabu, type: string, props?: {
|
|
47
|
+
text?: string;
|
|
48
|
+
delta?: import("loro-crdt").Delta<string>[];
|
|
49
|
+
}, parentId?: string | null, index?: number | null): BlockquoteBlock;
|
|
50
|
+
/** @param {Nabu} nabu @param {BlockquoteNode} node */
|
|
51
|
+
constructor(nabu: Nabu, node: BlockquoteNode);
|
|
52
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
53
|
+
block: import("./blockquote.svelte.js").BlockquoteBlock;
|
|
54
|
+
}, {}, "">;
|
|
55
|
+
}
|
|
56
|
+
export type BlockquoteNode = NabuNode<{
|
|
57
|
+
type: "blockquote";
|
|
58
|
+
text: LoroText;
|
|
59
|
+
}>;
|
|
60
|
+
import { TextBlock } from "../text-block.svelte.js";
|
|
61
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
62
|
+
import { LoroText } from "loro-crdt";
|
|
63
|
+
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { TextBlock } from "../text-block.svelte.js";
|
|
2
|
+
import { LoroText } from "loro-crdt";
|
|
3
|
+
import BlockquoteComponent from "./Blockquote.svelte";
|
|
4
|
+
import { deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {NabuNode<{type: "blockquote", text: LoroText}>} BlockquoteNode
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const QUOTE_MARK = /^ {0,3}>/;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A quote line without its `>` marks, however deeply nested (`> > x` gives `x`); a lazy line is returned as it is.
|
|
18
|
+
* @param {string} line
|
|
19
|
+
* @returns {string}
|
|
20
|
+
*/
|
|
21
|
+
function stripQuote(line) {
|
|
22
|
+
let out = line;
|
|
23
|
+
while (QUOTE_MARK.test(out)) out = out.replace(/^ {0,3}> ?/, '');
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
28
|
+
export class BlockquoteBlock extends TextBlock {
|
|
29
|
+
/** @param {Nabu} nabu @param {BlockquoteNode} node */
|
|
30
|
+
constructor(nabu, node) {
|
|
31
|
+
super(nabu, node);
|
|
32
|
+
|
|
33
|
+
this.serializers.set('markdown', () => { const md = this.behavior.toMarkdown(); return md ? `> ${md}` : ''; }); // an empty quote has no markdown
|
|
34
|
+
this.serializers.set('json', () => ({
|
|
35
|
+
id: this.id,
|
|
36
|
+
type: 'blockquote',
|
|
37
|
+
content: this.behavior.toJSON()
|
|
38
|
+
}));
|
|
39
|
+
this.serializers.set('application/x-nabu+json', (ctx = {}) => this.behavior.toClipboardBlock(ctx));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static placeholder = 'Quote...';
|
|
43
|
+
|
|
44
|
+
component = $derived(this.nabu.components.get("blockquote") || BlockquoteComponent);
|
|
45
|
+
|
|
46
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
47
|
+
static toMarkdown(pb) {
|
|
48
|
+
const md = deltaToMarkdown(pb.delta || []);
|
|
49
|
+
return md ? `> ${md}` : ''; // an empty quote has no markdown
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
53
|
+
static toHtml(pb) {
|
|
54
|
+
return `<blockquote>${deltaToHtml(pb.delta || [])}</blockquote>`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A quote is a block of TEXT (it cannot hold other blocks), so:
|
|
59
|
+
* - nested levels (`> > x`) are FLATTENED into the one quote, the text is kept;
|
|
60
|
+
* - a lazy continuation line (no `>`) belongs to the quote on import (CommonMark) and in a paste after a hard break;
|
|
61
|
+
* - the content is parsed as a document of its own: its text paragraphs become quotes (one per paragraph, the lines of
|
|
62
|
+
* a paragraph joined by a line break in a paste, by a space on import), and what it holds that is not text (a list, a
|
|
63
|
+
* fenced code, a heading, a divider, an image, a table) becomes the block it is, in order, outside any quote: the
|
|
64
|
+
* quote mark is lost, no text is.
|
|
65
|
+
* A callout (`> [!NOTE]`) has a higher priority rule of its own.
|
|
66
|
+
*/
|
|
67
|
+
static markdownRules = [
|
|
68
|
+
{
|
|
69
|
+
priority: 10,
|
|
70
|
+
interruptsParagraph: true,
|
|
71
|
+
detect: /^ {0,3}>/,
|
|
72
|
+
consume(/** @type {string[]} */ lines, /** @type {number} */ i, /** @type {any} */ helpers) {
|
|
73
|
+
let j = i;
|
|
74
|
+
/** @type {string} */
|
|
75
|
+
let previous = '';
|
|
76
|
+
while (j < lines.length) {
|
|
77
|
+
const line = lines[j];
|
|
78
|
+
if (QUOTE_MARK.test(line)) { previous = stripQuote(line); j++; continue; }
|
|
79
|
+
// lazy continuation: plain text under a text line of the quote
|
|
80
|
+
const lazy = j > i && line.trim() && previous.trim()
|
|
81
|
+
&& (helpers?.joinLines || /(?: {2,}|\\)$/.test(lines[j - 1]))
|
|
82
|
+
&& !helpers?.interrupts?.(lines, j) && !helpers?.interrupts?.([previous], 0);
|
|
83
|
+
if (!lazy) break;
|
|
84
|
+
previous = line;
|
|
85
|
+
j++;
|
|
86
|
+
}
|
|
87
|
+
return Math.max(1, j - i);
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {string[]} lines
|
|
94
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[], parseBlocks?: (lines: string[], overrides?: object) => import('../../utils/extensions.js').PasteBlock[], joinLines?: boolean }} helpers
|
|
95
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | import('../../utils/extensions.js').PasteBlock[] | null}
|
|
96
|
+
*/
|
|
97
|
+
static fromMarkdown(lines, { parseInline, parseBlocks, joinLines }) {
|
|
98
|
+
const inner = lines.map(stripQuote);
|
|
99
|
+
if (!parseBlocks) {
|
|
100
|
+
const delta = parseInline(inner.join('\n'));
|
|
101
|
+
return delta.length ? { type: 'blockquote', delta, partial: false } : null;
|
|
102
|
+
}
|
|
103
|
+
/** @type {import('../../utils/extensions.js').PasteBlock[]} */
|
|
104
|
+
const blocks = parseBlocks(inner, { joinLines: true, softBreak: joinLines ? ' ' : '\n' }).map((pb) =>
|
|
105
|
+
pb.type === 'paragraph' ? { type: 'blockquote', delta: pb.delta, partial: false } : pb);
|
|
106
|
+
if (!blocks.length) return null;
|
|
107
|
+
return blocks.length === 1 ? blocks[0] : blocks;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// priority 10 wins over Paragraph's fallback `blockquote` selector
|
|
111
|
+
static htmlRules = [
|
|
112
|
+
{ selector: 'blockquote', priority: 10 },
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {Element} el
|
|
117
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
|
|
118
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
119
|
+
*/
|
|
120
|
+
static fromHTML(el, { parseInline }) {
|
|
121
|
+
const delta = parseInline(el);
|
|
122
|
+
if (!delta.length) return null;
|
|
123
|
+
return { type: 'blockquote', delta, partial: false };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {Nabu} nabu @param {string} type @param {{text?: string, delta?: import('loro-crdt').Delta<string>[]}} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
127
|
+
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
128
|
+
const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
|
|
129
|
+
/** @type {any} */ (node.data).set("type", "blockquote");
|
|
130
|
+
const container = /** @type {any} */ (node.data).setContainer("text", new LoroText());
|
|
131
|
+
if (props.text) container.insert(0, props.text);
|
|
132
|
+
if (props.delta) container.applyDelta([...props.delta]);
|
|
133
|
+
const block = new BlockquoteBlock(nabu, /** @type {BlockquoteNode} */ (/** @type {unknown} */ (node)));
|
|
134
|
+
return block;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import RichText from '../../behaviors/text/RichText.svelte';
|
|
3
|
+
/** @type {{ block: import('./callout.svelte.js').CalloutBlock }} */
|
|
4
|
+
let { block } = $props();
|
|
5
|
+
/** @type {Record<string,string>} */
|
|
6
|
+
const ICONS = { note: 'ℹ️', tip: '💡', important: '❗', warning: '⚠️', caution: '🛑' };
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<aside class="nabu-callout callout-{block.variant}" data-callout={block.variant}><button
|
|
10
|
+
class="nabu-callout-icon"
|
|
11
|
+
data-nabu-ui
|
|
12
|
+
contenteditable="false"
|
|
13
|
+
type="button"
|
|
14
|
+
title="Change callout type ({block.variant})"
|
|
15
|
+
aria-label="Change callout type ({block.variant})"
|
|
16
|
+
aria-disabled={block.nabu.readonly ? 'true' : undefined}
|
|
17
|
+
onmousedown={(e) => { e.preventDefault(); block.cycleVariant(); }}
|
|
18
|
+
>{ICONS[block.variant] ?? ICONS.note}</button><div
|
|
19
|
+
class="nabu-callout-body"
|
|
20
|
+
bind:this={block.element}
|
|
21
|
+
data-block-id={block.id}
|
|
22
|
+
data-block-type="callout"
|
|
23
|
+
data-placeholder={block.placeholder}
|
|
24
|
+
class:selected={block.selected}
|
|
25
|
+
><RichText delta={block.delta} /></div></aside>
|
|
26
|
+
|
|
27
|
+
<style>
|
|
28
|
+
.nabu-callout {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: row;
|
|
31
|
+
align-items: flex-start;
|
|
32
|
+
gap: 0.5em;
|
|
33
|
+
margin: 0.5em 0;
|
|
34
|
+
padding: 0.625em 0.875em;
|
|
35
|
+
border-radius: 6px;
|
|
36
|
+
border-left: 3px solid var(--callout-accent, var(--nb-border, rgba(255, 255, 255, 0.3)));
|
|
37
|
+
background: color-mix(in srgb, var(--callout-accent, var(--nb-border, rgba(255, 255, 255, 0.3))) 8%, transparent);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.callout-note { --callout-accent: #6b8cff; }
|
|
41
|
+
.callout-tip { --callout-accent: #3ecf8e; }
|
|
42
|
+
.callout-important { --callout-accent: #a78bfa; }
|
|
43
|
+
.callout-warning { --callout-accent: #f59e0b; }
|
|
44
|
+
.callout-caution { --callout-accent: #ef4444; }
|
|
45
|
+
|
|
46
|
+
.nabu-callout-icon {
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
background: none;
|
|
49
|
+
border: none;
|
|
50
|
+
padding: 0;
|
|
51
|
+
margin: 0;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
user-select: none;
|
|
54
|
+
font-size: 1.1em;
|
|
55
|
+
line-height: 1.5;
|
|
56
|
+
outline: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.nabu-callout-body {
|
|
60
|
+
flex: 1;
|
|
61
|
+
white-space: pre-wrap;
|
|
62
|
+
outline: none;
|
|
63
|
+
line-height: 1.6;
|
|
64
|
+
min-height: 1.6em;
|
|
65
|
+
color: var(--nb-text-primary, rgba(255, 255, 255, 0.85));
|
|
66
|
+
}
|
|
67
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Callout;
|
|
2
|
+
type Callout = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Callout: import("svelte").Component<{
|
|
7
|
+
block: import("./callout.svelte.js").CalloutBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./callout.svelte.js").CalloutBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { tick } from "svelte";
|
|
2
|
+
import { TextBehavior } from "../../behaviors/text";
|
|
3
|
+
import { extension } from "../../utils/extensions";
|
|
4
|
+
import { CalloutBlock } from "./callout.svelte.js";
|
|
5
|
+
import CalloutComponent from "./Callout.svelte";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import { Nabu, Block } from "..";
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* onBeforeInput hook for CalloutBlock:
|
|
13
|
+
* - Inside a callout block: Backspace on empty → transform back to paragraph; Backspace at offset 0 of a
|
|
14
|
+
* non-empty callout → no-op (interim, the callout is planned to become a container).
|
|
15
|
+
* - In any other text block: "! " at the start → transform into a callout.
|
|
16
|
+
* (The "> " prefix is taken by Blockquote, so callouts use "! " — mnemonic
|
|
17
|
+
* for alert/important, and free of collisions.)
|
|
18
|
+
*
|
|
19
|
+
* @param {Nabu} nabu @param {InputEvent} event @param {Block} block
|
|
20
|
+
*/
|
|
21
|
+
const onBeforeInput = (nabu, event, block) => {
|
|
22
|
+
const { BREAK, CONTINUE } = nabu;
|
|
23
|
+
|
|
24
|
+
const behavior = block.behaviors.get('text');
|
|
25
|
+
if (!(behavior instanceof TextBehavior)) return CONTINUE;
|
|
26
|
+
const sel = behavior.selection;
|
|
27
|
+
if (!sel || !sel.isCollapsed) return CONTINUE;
|
|
28
|
+
|
|
29
|
+
if (block instanceof CalloutBlock) {
|
|
30
|
+
// Backspace at position 0 in an empty callout block → back to paragraph
|
|
31
|
+
if (event.inputType === 'deleteContentBackward' && sel.from === 0 && behavior.text.length === 0) {
|
|
32
|
+
const blockId = block.node.id.toString();
|
|
33
|
+
block.transformTo('paragraph');
|
|
34
|
+
tick().then(() => {
|
|
35
|
+
const fresh = nabu.blocks.get(blockId);
|
|
36
|
+
if (fresh) fresh.focus({ start: 0, end: 0 });
|
|
37
|
+
});
|
|
38
|
+
return BREAK;
|
|
39
|
+
}
|
|
40
|
+
// Backspace at position 0 in a NON-empty callout → no-op (INTERIM): nothing merges into the previous
|
|
41
|
+
// block, the text / variant / caret are kept. The callout is planned to become a container (so a
|
|
42
|
+
// callout will no longer be a flat text block that can be merged or de-transformed with Backspace).
|
|
43
|
+
if (event.inputType === 'deleteContentBackward' && sel.from === 0 && behavior.text.length > 0) {
|
|
44
|
+
return BREAK;
|
|
45
|
+
}
|
|
46
|
+
return CONTINUE;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// "! " at the start of a text block → transform into a callout (variant note)
|
|
50
|
+
if (event.inputType === 'insertText' && event.data === ' ') {
|
|
51
|
+
if (behavior.text.slice(0, sel.from) !== '!') return CONTINUE;
|
|
52
|
+
const blockId = block.node.id.toString();
|
|
53
|
+
// Undo gives back "! " (trigger space included): see Nabu.shortcut()
|
|
54
|
+
nabu.shortcut(block, ' ', (b) => {
|
|
55
|
+
b.delete({ index: 0, length: 2 });
|
|
56
|
+
block.transformTo('callout');
|
|
57
|
+
});
|
|
58
|
+
tick().then(() => {
|
|
59
|
+
const fresh = nabu.blocks.get(blockId);
|
|
60
|
+
if (fresh) fresh.focus({ start: 0, end: 0 });
|
|
61
|
+
});
|
|
62
|
+
return BREAK;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return CONTINUE;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The callout block (`note`, `tip`, `important`, `warning`, `caution` variants): the `! ` shortcut, the `callout` action and the "Callout" slash entry.
|
|
70
|
+
*/
|
|
71
|
+
export const CalloutExtension = extension("callout", {
|
|
72
|
+
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
73
|
+
block: CalloutBlock,
|
|
74
|
+
component: CalloutComponent,
|
|
75
|
+
slashCommands: [
|
|
76
|
+
{ title: 'Callout', icon: '!', aliases: ['callout', 'note', 'info', 'warning'], group: 'blocks', order: 10, run: (e) => e.exec('callout') },
|
|
77
|
+
],
|
|
78
|
+
actions: {
|
|
79
|
+
'callout': (nabu) => nabu.exec('block:transform', { type: 'callout' }),
|
|
80
|
+
},
|
|
81
|
+
hooks: {
|
|
82
|
+
onBeforeInput,
|
|
83
|
+
}
|
|
84
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{type: "callout", text: LoroText, variant: string}>} CalloutNode
|
|
6
|
+
*/
|
|
7
|
+
export const CALLOUT_VARIANTS: string[];
|
|
8
|
+
export class CalloutBlock extends TextBlock {
|
|
9
|
+
static placeholder: string;
|
|
10
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
11
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
12
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
13
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
14
|
+
static markdownRules: {
|
|
15
|
+
priority: number;
|
|
16
|
+
interruptsParagraph: boolean;
|
|
17
|
+
detect: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Consume the callout header line plus all subsequent ">" prefixed lines.
|
|
20
|
+
* @param {string[]} lines
|
|
21
|
+
* @param {number} i
|
|
22
|
+
* @returns {number}
|
|
23
|
+
*/
|
|
24
|
+
consume(lines: string[], i: number): number;
|
|
25
|
+
}[];
|
|
26
|
+
/**
|
|
27
|
+
* @param {string[]} lines
|
|
28
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
29
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
30
|
+
*/
|
|
31
|
+
static fromMarkdown(lines: string[], { parseInline }: {
|
|
32
|
+
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
33
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
34
|
+
static htmlRules: {
|
|
35
|
+
selector: string;
|
|
36
|
+
priority: number;
|
|
37
|
+
}[];
|
|
38
|
+
/**
|
|
39
|
+
* @param {Element} el
|
|
40
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
|
|
41
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
42
|
+
*/
|
|
43
|
+
static fromHTML(el: Element, { parseInline }: {
|
|
44
|
+
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
45
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
46
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
47
|
+
static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): CalloutBlock;
|
|
48
|
+
/** @param {Nabu} nabu @param {CalloutNode} node */
|
|
49
|
+
constructor(nabu: Nabu, node: CalloutNode);
|
|
50
|
+
/** @type {string} */
|
|
51
|
+
variant: string;
|
|
52
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
53
|
+
block: import("./callout.svelte.js").CalloutBlock;
|
|
54
|
+
}, {}, "">;
|
|
55
|
+
/**
|
|
56
|
+
* Set the callout variant and commit.
|
|
57
|
+
* @param {string} v
|
|
58
|
+
*/
|
|
59
|
+
setVariant(v: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Cycle to the next callout variant (the user's gesture: a click on the icon). Does nothing in a read-only editor.
|
|
62
|
+
*/
|
|
63
|
+
cycleVariant(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Handle special keydown events: ArrowDown escape.
|
|
66
|
+
* Returns true if handled (engine should preventDefault).
|
|
67
|
+
* @param {KeyboardEvent} event
|
|
68
|
+
* @returns {boolean}
|
|
69
|
+
*/
|
|
70
|
+
keydown(event: KeyboardEvent): boolean;
|
|
71
|
+
}
|
|
72
|
+
export type CalloutNode = NabuNode<{
|
|
73
|
+
type: "callout";
|
|
74
|
+
text: LoroText;
|
|
75
|
+
variant: string;
|
|
76
|
+
}>;
|
|
77
|
+
import { TextBlock } from "../text-block.svelte.js";
|
|
78
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
79
|
+
import { LoroText } from "loro-crdt";
|
|
80
|
+
import type { NabuNode } from "../nabu.svelte.js";
|