@aionbuilders/nabu 0.1.0-beta.0 → 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 +72 -341
- package/dist/behaviors/text/RichText.svelte +24 -4
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +3 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +35 -10
- package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
- package/dist/behaviors/text/markdown-syntax.js +81 -0
- package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
- package/dist/behaviors/text/rich-text.extension.js +95 -38
- package/dist/behaviors/text/text.behavior.svelte.d.ts +199 -48
- package/dist/behaviors/text/text.behavior.svelte.js +549 -83
- package/dist/behaviors/text/typography.extension.d.ts +2 -1
- package/dist/behaviors/text/typography.extension.js +3 -2
- package/dist/blocks/BlockList.svelte +48 -0
- package/dist/blocks/BlockList.svelte.d.ts +17 -0
- package/dist/blocks/Nabu.svelte +169 -25
- package/dist/blocks/Nabu.svelte.d.ts +13 -0
- package/dist/blocks/block.extension.d.ts +3 -0
- package/dist/blocks/block.extension.js +4 -7
- package/dist/blocks/block.svelte.d.ts +350 -86
- package/dist/blocks/block.svelte.js +370 -59
- package/dist/blocks/blockquote/Blockquote.svelte +1 -2
- package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -1
- package/dist/blocks/blockquote/blockquote.extension.js +14 -5
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +19 -11
- package/dist/blocks/blockquote/blockquote.svelte.js +58 -13
- package/dist/blocks/callout/Callout.svelte +6 -8
- package/dist/blocks/callout/callout.extension.d.ts +4 -1
- package/dist/blocks/callout/callout.extension.js +19 -3
- package/dist/blocks/callout/callout.svelte.d.ts +5 -3
- package/dist/blocks/callout/callout.svelte.js +11 -6
- package/dist/blocks/chunks.d.ts +49 -0
- package/dist/blocks/chunks.js +90 -0
- package/dist/blocks/code/Code.svelte +7 -8
- package/dist/blocks/code/code.extension.d.ts +4 -1
- package/dist/blocks/code/code.extension.js +22 -2
- package/dist/blocks/code/code.svelte.d.ts +9 -2
- package/dist/blocks/code/code.svelte.js +49 -25
- package/dist/blocks/container.utils.d.ts +85 -13
- package/dist/blocks/container.utils.js +338 -178
- package/dist/blocks/dialogue/Dialogue.svelte +8 -4
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +33 -2
- package/dist/blocks/dialogue/dialogue.svelte.js +58 -4
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
- package/dist/blocks/dialogue/index.d.ts +12 -1
- package/dist/blocks/dialogue/index.js +51 -35
- package/dist/blocks/divider/divider.extension.d.ts +23 -1
- package/dist/blocks/divider/divider.extension.js +85 -19
- package/dist/blocks/divider/divider.svelte.d.ts +7 -2
- package/dist/blocks/divider/divider.svelte.js +9 -4
- package/dist/blocks/file/File.svelte +13 -6
- package/dist/blocks/file/file.extension.d.ts +4 -1
- package/dist/blocks/file/file.extension.js +9 -1
- package/dist/blocks/file/file.svelte.d.ts +3 -3
- package/dist/blocks/file/file.svelte.js +20 -14
- package/dist/blocks/heading/Heading.svelte +1 -2
- package/dist/blocks/heading/heading.svelte.d.ts +23 -11
- package/dist/blocks/heading/heading.svelte.js +68 -13
- package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
- package/dist/blocks/heading/index.d.ts +2 -2
- package/dist/blocks/heading/index.js +33 -8
- package/dist/blocks/image/Image.svelte +5 -2
- package/dist/blocks/image/image.extension.d.ts +4 -1
- package/dist/blocks/image/image.extension.js +9 -1
- package/dist/blocks/image/image.svelte.d.ts +17 -6
- package/dist/blocks/image/image.svelte.js +33 -11
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +1 -1
- package/dist/blocks/list/List.svelte +1 -0
- package/dist/blocks/list/ListItem.svelte +1 -0
- package/dist/blocks/list/convert.d.ts +20 -0
- package/dist/blocks/list/convert.js +92 -0
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +49 -28
- package/dist/blocks/list/html-flat.d.ts +78 -0
- package/dist/blocks/list/html-flat.js +244 -0
- package/dist/blocks/list/indent.d.ts +86 -0
- package/dist/blocks/list/indent.js +205 -0
- package/dist/blocks/list/index.d.ts +6 -3
- package/dist/blocks/list/index.js +42 -31
- package/dist/blocks/list/list-item.svelte.d.ts +31 -17
- package/dist/blocks/list/list-item.svelte.js +99 -100
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -1
- package/dist/blocks/list/list.behavior.svelte.js +6 -1
- package/dist/blocks/list/list.svelte.d.ts +89 -18
- package/dist/blocks/list/list.svelte.js +129 -125
- package/dist/blocks/list/markdown.d.ts +149 -0
- package/dist/blocks/list/markdown.js +442 -0
- package/dist/blocks/list/normalize.d.ts +11 -0
- package/dist/blocks/list/normalize.js +396 -0
- package/dist/blocks/list/paste.d.ts +45 -0
- package/dist/blocks/list/paste.js +242 -0
- package/dist/blocks/list/step-back.d.ts +24 -0
- package/dist/blocks/list/step-back.js +87 -0
- package/dist/blocks/list/to-list.d.ts +7 -0
- package/dist/blocks/list/to-list.js +44 -0
- package/dist/blocks/list/todos-toggle.d.ts +20 -0
- package/dist/blocks/list/todos-toggle.js +48 -0
- package/dist/blocks/media/markdown.d.ts +12 -0
- package/dist/blocks/media/markdown.js +26 -0
- package/dist/blocks/media/media-block.svelte.d.ts +77 -2
- package/dist/blocks/media/media-block.svelte.js +124 -12
- package/dist/blocks/media/media.helpers.d.ts +6 -1
- package/dist/blocks/media/media.helpers.js +43 -6
- package/dist/blocks/megablock.svelte.d.ts +50 -19
- package/dist/blocks/megablock.svelte.js +114 -74
- package/dist/blocks/move.d.ts +23 -0
- package/dist/blocks/move.js +92 -0
- package/dist/blocks/nabu.svelte.d.ts +764 -71
- package/dist/blocks/nabu.svelte.js +1746 -189
- package/dist/blocks/paragraph/Paragraph.svelte +1 -2
- package/dist/blocks/paragraph/index.d.ts +2 -2
- package/dist/blocks/paragraph/index.js +35 -13
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +46 -14
- package/dist/blocks/paragraph/paragraph.svelte.js +77 -16
- package/dist/blocks/paragraph/table.html.d.ts +9 -0
- package/dist/blocks/paragraph/table.html.js +111 -0
- package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
- package/dist/blocks/paragraph/table.markdown.js +90 -0
- package/dist/blocks/region/Region.svelte +264 -0
- package/dist/blocks/region/Region.svelte.d.ts +11 -0
- package/dist/blocks/region/actions.d.ts +135 -0
- package/dist/blocks/region/actions.js +402 -0
- package/dist/blocks/region/close.d.ts +35 -0
- package/dist/blocks/region/close.js +130 -0
- package/dist/blocks/region/commands.d.ts +6 -0
- package/dist/blocks/region/commands.js +277 -0
- package/dist/blocks/region/create.d.ts +72 -0
- package/dist/blocks/region/create.js +208 -0
- package/dist/blocks/region/end-marker.d.ts +35 -0
- package/dist/blocks/region/end-marker.js +51 -0
- package/dist/blocks/region/facts.d.ts +69 -0
- package/dist/blocks/region/facts.js +152 -0
- package/dist/blocks/region/format.d.ts +91 -0
- package/dist/blocks/region/format.js +260 -0
- package/dist/blocks/region/index.d.ts +14 -0
- package/dist/blocks/region/index.js +14 -0
- package/dist/blocks/region/insert.d.ts +59 -0
- package/dist/blocks/region/insert.js +102 -0
- package/dist/blocks/region/messages.d.ts +254 -0
- package/dist/blocks/region/messages.js +131 -0
- package/dist/blocks/region/normalize.d.ts +7 -0
- package/dist/blocks/region/normalize.js +170 -0
- package/dist/blocks/region/region.extension.d.ts +58 -0
- package/dist/blocks/region/region.extension.js +119 -0
- package/dist/blocks/region/region.svelte.d.ts +221 -0
- package/dist/blocks/region/region.svelte.js +582 -0
- package/dist/blocks/region/regions.svelte.d.ts +141 -0
- package/dist/blocks/region/regions.svelte.js +276 -0
- package/dist/blocks/region/serialize.d.ts +57 -0
- package/dist/blocks/region/serialize.js +112 -0
- package/dist/blocks/region/types.d.ts +255 -0
- package/dist/blocks/region/types.js +204 -0
- package/dist/blocks/selection.svelte.d.ts +106 -8
- package/dist/blocks/selection.svelte.js +622 -74
- package/dist/blocks/subthread.d.ts +80 -0
- package/dist/blocks/subthread.js +167 -0
- package/dist/blocks/text-block.svelte.d.ts +34 -13
- package/dist/blocks/text-block.svelte.js +42 -8
- package/dist/blocks/toggle/Toggle.svelte +4 -15
- package/dist/blocks/toggle/markdown.d.ts +20 -0
- package/dist/blocks/toggle/markdown.js +112 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +4 -1
- package/dist/blocks/toggle/toggle.extension.js +6 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +54 -7
- package/dist/blocks/toggle/toggle.svelte.js +134 -34
- package/dist/blocks/undo-selection.d.ts +175 -0
- package/dist/blocks/undo-selection.js +360 -0
- package/dist/blocks/video/Video.svelte +5 -2
- package/dist/blocks/video/video.extension.d.ts +4 -1
- package/dist/blocks/video/video.extension.js +9 -1
- package/dist/blocks/video/video.svelte.d.ts +6 -5
- package/dist/blocks/video/video.svelte.js +18 -9
- package/dist/extend.d.ts +55 -0
- package/dist/extend.js +88 -0
- package/dist/files/assets.clipboard.d.ts +77 -0
- package/dist/files/assets.clipboard.js +152 -0
- package/dist/files/files.svelte.d.ts +321 -19
- package/dist/files/files.svelte.js +847 -43
- package/dist/files/index.d.ts +3 -1
- package/dist/files/index.js +3 -1
- package/dist/files/outbox.d.ts +69 -0
- package/dist/files/outbox.js +48 -0
- package/dist/files/status.d.ts +65 -0
- package/dist/files/status.js +87 -0
- package/dist/files/store.d.ts +97 -0
- package/dist/files/store.js +65 -0
- package/dist/files/uploads.svelte.d.ts +174 -0
- package/dist/files/uploads.svelte.js +504 -0
- package/dist/index.d.ts +68 -9
- package/dist/index.js +117 -10
- package/dist/nabu-theme.css +21 -1
- package/dist/paste/html.paste.d.ts +74 -3
- package/dist/paste/html.paste.js +550 -86
- package/dist/paste/markdown-inline.d.ts +86 -0
- package/dist/paste/markdown-inline.js +528 -0
- package/dist/paste/markdown.paste.d.ts +2 -8
- package/dist/paste/markdown.paste.js +78 -94
- package/dist/paste/nabu.paste.d.ts +3 -0
- package/dist/paste/nabu.paste.js +29 -3
- package/dist/paste/plain-text.paste.d.ts +2 -2
- package/dist/paste/plain-text.paste.js +3 -3
- package/dist/persistence/asset-store.d.ts +51 -0
- package/dist/persistence/asset-store.js +103 -0
- package/dist/persistence/autosave.d.ts +53 -0
- package/dist/persistence/autosave.js +62 -0
- package/dist/persistence/compact.d.ts +162 -0
- package/dist/persistence/compact.js +141 -0
- package/dist/persistence/history.d.ts +77 -0
- package/dist/persistence/history.js +176 -0
- package/dist/persistence/indexeddb.d.ts +190 -4
- package/dist/persistence/indexeddb.js +333 -29
- package/dist/persistence/merge.d.ts +38 -0
- package/dist/persistence/merge.js +36 -0
- package/dist/persistence/outbox.d.ts +25 -0
- package/dist/persistence/outbox.js +40 -0
- package/dist/persistence/persistence.d.ts +70 -9
- package/dist/persistence/persistence.js +507 -35
- package/dist/persistence/recovery.d.ts +79 -0
- package/dist/persistence/recovery.js +79 -0
- package/dist/persistence/release.d.ts +34 -0
- package/dist/persistence/release.js +64 -0
- package/dist/persistence/state.svelte.d.ts +53 -0
- package/dist/persistence/state.svelte.js +48 -0
- package/dist/persistence/sync.d.ts +39 -0
- package/dist/persistence/sync.js +138 -0
- package/dist/persistence/tail.d.ts +42 -0
- package/dist/persistence/tail.js +103 -0
- package/dist/presets.d.ts +29 -26
- package/dist/presets.js +35 -13
- package/dist/themes/atelier.css +318 -0
- package/dist/ui/CommandChooser.svelte +153 -0
- package/dist/ui/CommandChooser.svelte.d.ts +13 -0
- package/dist/ui/CommandInvite.svelte +99 -0
- package/dist/ui/CommandInvite.svelte.d.ts +12 -0
- package/dist/ui/DragHandle.svelte +97 -21
- package/dist/ui/FloatingToolbar.svelte +75 -27
- package/dist/ui/FloatingToolbar.svelte.d.ts +10 -0
- package/dist/ui/SlashMenu.svelte +147 -15
- package/dist/ui/SlashMenu.svelte.d.ts +20 -0
- package/dist/ui/anchor.d.ts +112 -0
- package/dist/ui/anchor.js +136 -0
- package/dist/ui/index.d.ts +7 -1
- package/dist/ui/index.js +12 -1
- package/dist/ui/slash-menu.svelte.d.ts +79 -7
- package/dist/ui/slash-menu.svelte.js +85 -51
- package/dist/utils/command-confirm.svelte.d.ts +349 -0
- package/dist/utils/command-confirm.svelte.js +673 -0
- package/dist/utils/commands.d.ts +328 -0
- package/dist/utils/commands.js +416 -0
- package/dist/utils/dom-scope.d.ts +14 -0
- package/dist/utils/dom-scope.js +20 -0
- package/dist/utils/drop.d.ts +160 -0
- package/dist/utils/drop.js +305 -0
- package/dist/utils/extensions.d.ts +439 -45
- package/dist/utils/extensions.js +271 -29
- package/dist/utils/html.d.ts +44 -0
- package/dist/utils/html.js +183 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/keys.d.ts +120 -0
- package/dist/utils/keys.js +248 -0
- package/dist/utils/links.d.ts +22 -0
- package/dist/utils/links.js +34 -0
- package/dist/utils/placeholders.d.ts +81 -3
- package/dist/utils/placeholders.js +73 -3
- package/dist/utils/selection.svelte.d.ts +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 +9 -3
- package/dist/vite.js +19 -8
- package/package.json +54 -20
- package/dist/blocks/variable.svelte.d.ts +0 -47
- package/dist/blocks/variable.svelte.js +0 -51
- package/dist/blocks/zone/TemplateEditor.svelte +0 -308
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +0 -11
- package/dist/blocks/zone/Zone.svelte +0 -272
- package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
- package/dist/blocks/zone/ZoneEditor.svelte +0 -289
- package/dist/blocks/zone/ZoneEditor.svelte.d.ts +0 -11
- package/dist/blocks/zone/ZoneTemplatesList.svelte +0 -188
- package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +0 -11
- package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +0 -3
- package/dist/blocks/zone/hooks/onBeforeInput.hook.js +0 -30
- package/dist/blocks/zone/index.d.ts +0 -2
- package/dist/blocks/zone/index.js +0 -2
- package/dist/blocks/zone/zone.extension.d.ts +0 -2
- package/dist/blocks/zone/zone.extension.js +0 -237
- package/dist/blocks/zone/zone.svelte.d.ts +0 -221
- package/dist/blocks/zone/zone.svelte.js +0 -608
- package/dist/overlays/context/Context.svelte +0 -182
- package/dist/overlays/context/Context.svelte.d.ts +0 -17
- package/dist/overlays/context/collect.d.ts +0 -17
- package/dist/overlays/context/collect.js +0 -33
- package/dist/overlays/context/context.extension.d.ts +0 -2
- package/dist/overlays/context/context.extension.js +0 -8
- package/dist/overlays/context/context.svelte.d.ts +0 -82
- package/dist/overlays/context/context.svelte.js +0 -159
- package/dist/overlays/context/index.d.ts +0 -3
- package/dist/overlays/context/index.js +0 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import RichText from '../../behaviors/text/RichText.svelte';
|
|
3
|
-
import { getPlaceholder } from '../../utils/placeholders.js';
|
|
4
3
|
/** @type {{block: import('./blockquote.svelte.js').BlockquoteBlock}}*/
|
|
5
4
|
let {block} = $props();
|
|
6
5
|
</script>
|
|
@@ -9,7 +8,7 @@
|
|
|
9
8
|
bind:this={block.element}
|
|
10
9
|
data-block-id={block.id}
|
|
11
10
|
data-block-type="blockquote"
|
|
12
|
-
data-placeholder={block.
|
|
11
|
+
data-placeholder={block.placeholder}
|
|
13
12
|
class="nabu-blockquote"
|
|
14
13
|
class:debug={block.nabu.debugging}
|
|
15
14
|
class:selected={block.selected}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The quote block: the `> ` shortcut, Backspace and Enter de-transformations, markdown and HTML paste rules, and the "Quote" slash entry.
|
|
3
|
+
*/
|
|
4
|
+
export const BlockquoteExtension: import("../../extend.js").Extension;
|
|
@@ -24,10 +24,10 @@ const onBeforeInput = (nabu, event, block) => {
|
|
|
24
24
|
const sel = behavior.selection;
|
|
25
25
|
if (!sel || !sel.isCollapsed) return CONTINUE;
|
|
26
26
|
|
|
27
|
-
/** @param {string} type */
|
|
28
|
-
const transformAndFocus = (type) => {
|
|
27
|
+
/** @param {string} type @param {() => void} [transform] */
|
|
28
|
+
const transformAndFocus = (type, transform = () => block.transformTo(type)) => {
|
|
29
29
|
const blockId = block.node.id.toString();
|
|
30
|
-
|
|
30
|
+
transform();
|
|
31
31
|
tick().then(() => {
|
|
32
32
|
const fresh = nabu.blocks.get(blockId);
|
|
33
33
|
if (fresh) fresh.focus({ start: 0, end: 0 });
|
|
@@ -51,17 +51,26 @@ const onBeforeInput = (nabu, event, block) => {
|
|
|
51
51
|
if (event.inputType === "insertText" && event.data === " ") {
|
|
52
52
|
const textBeforeCursor = behavior.text.slice(0, sel.from);
|
|
53
53
|
if (textBeforeCursor !== ">") return CONTINUE;
|
|
54
|
-
|
|
55
|
-
return transformAndFocus("blockquote")
|
|
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
|
+
}));
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
return CONTINUE;
|
|
59
62
|
};
|
|
60
63
|
|
|
64
|
+
/**
|
|
65
|
+
* The quote block: the `> ` shortcut, Backspace and Enter de-transformations, markdown and HTML paste rules, and the "Quote" slash entry.
|
|
66
|
+
*/
|
|
61
67
|
export const BlockquoteExtension = extension("blockquote", {
|
|
62
68
|
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
63
69
|
block: BlockquoteBlock,
|
|
64
70
|
component: BlockquoteComponent,
|
|
71
|
+
slashCommands: [
|
|
72
|
+
{ title: 'Quote', icon: '"', aliases: ['quote', 'blockquote'], group: 'blocks', order: 20, run: (e) => e.exec('blockquote') },
|
|
73
|
+
],
|
|
65
74
|
actions: {
|
|
66
75
|
'blockquote': (nabu) => nabu.exec('block:transform', { type: 'blockquote' }),
|
|
67
76
|
},
|
|
@@ -1,27 +1,35 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {NabuNode<{type: "blockquote", text: LoroText}>} BlockquoteNode
|
|
6
|
-
*/
|
|
7
1
|
export class BlockquoteBlock extends TextBlock {
|
|
2
|
+
static placeholder: string;
|
|
8
3
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
9
4
|
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
10
5
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
11
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
|
+
*/
|
|
12
17
|
static markdownRules: {
|
|
13
18
|
priority: number;
|
|
19
|
+
interruptsParagraph: boolean;
|
|
14
20
|
detect: RegExp;
|
|
15
|
-
consume(lines: string[], i: number): number;
|
|
21
|
+
consume(lines: string[], i: number, helpers: any): number;
|
|
16
22
|
}[];
|
|
17
23
|
/**
|
|
18
24
|
* @param {string[]} lines
|
|
19
|
-
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
20
|
-
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
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}
|
|
21
27
|
*/
|
|
22
|
-
static fromMarkdown(lines: string[], { parseInline }: {
|
|
28
|
+
static fromMarkdown(lines: string[], { parseInline, parseBlocks, joinLines }: {
|
|
23
29
|
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
24
|
-
|
|
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;
|
|
25
33
|
static htmlRules: {
|
|
26
34
|
selector: string;
|
|
27
35
|
priority: number;
|
|
@@ -11,13 +11,26 @@ import { deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
|
11
11
|
* @typedef {NabuNode<{type: "blockquote", text: LoroText}>} BlockquoteNode
|
|
12
12
|
*/
|
|
13
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
|
+
|
|
14
27
|
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
15
28
|
export class BlockquoteBlock extends TextBlock {
|
|
16
29
|
/** @param {Nabu} nabu @param {BlockquoteNode} node */
|
|
17
30
|
constructor(nabu, node) {
|
|
18
31
|
super(nabu, node);
|
|
19
32
|
|
|
20
|
-
this.serializers.set('markdown', () =>
|
|
33
|
+
this.serializers.set('markdown', () => { const md = this.behavior.toMarkdown(); return md ? `> ${md}` : ''; }); // an empty quote has no markdown
|
|
21
34
|
this.serializers.set('json', () => ({
|
|
22
35
|
id: this.id,
|
|
23
36
|
type: 'blockquote',
|
|
@@ -26,11 +39,14 @@ export class BlockquoteBlock extends TextBlock {
|
|
|
26
39
|
this.serializers.set('application/x-nabu+json', (ctx = {}) => this.behavior.toClipboardBlock(ctx));
|
|
27
40
|
}
|
|
28
41
|
|
|
42
|
+
static placeholder = 'Quote...';
|
|
43
|
+
|
|
29
44
|
component = $derived(this.nabu.components.get("blockquote") || BlockquoteComponent);
|
|
30
45
|
|
|
31
46
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
32
47
|
static toMarkdown(pb) {
|
|
33
|
-
|
|
48
|
+
const md = deltaToMarkdown(pb.delta || []);
|
|
49
|
+
return md ? `> ${md}` : ''; // an empty quote has no markdown
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
@@ -38,13 +54,36 @@ export class BlockquoteBlock extends TextBlock {
|
|
|
38
54
|
return `<blockquote>${deltaToHtml(pb.delta || [])}</blockquote>`;
|
|
39
55
|
}
|
|
40
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
|
+
*/
|
|
41
67
|
static markdownRules = [
|
|
42
68
|
{
|
|
43
69
|
priority: 10,
|
|
44
|
-
|
|
45
|
-
|
|
70
|
+
interruptsParagraph: true,
|
|
71
|
+
detect: /^ {0,3}>/,
|
|
72
|
+
consume(/** @type {string[]} */ lines, /** @type {number} */ i, /** @type {any} */ helpers) {
|
|
46
73
|
let j = i;
|
|
47
|
-
|
|
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
|
+
}
|
|
48
87
|
return Math.max(1, j - i);
|
|
49
88
|
},
|
|
50
89
|
}
|
|
@@ -52,14 +91,20 @@ export class BlockquoteBlock extends TextBlock {
|
|
|
52
91
|
|
|
53
92
|
/**
|
|
54
93
|
* @param {string[]} lines
|
|
55
|
-
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
56
|
-
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
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}
|
|
57
96
|
*/
|
|
58
|
-
static fromMarkdown(lines, { parseInline }) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
63
108
|
}
|
|
64
109
|
|
|
65
110
|
// priority 10 wins over Paragraph's fallback `blockquote` selector
|
|
@@ -80,7 +125,7 @@ export class BlockquoteBlock extends TextBlock {
|
|
|
80
125
|
|
|
81
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] */
|
|
82
127
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
83
|
-
const node = nabu.tree.createNode(/** @type {
|
|
128
|
+
const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
|
|
84
129
|
/** @type {any} */ (node.data).set("type", "blockquote");
|
|
85
130
|
const container = /** @type {any} */ (node.data).setContainer("text", new LoroText());
|
|
86
131
|
if (props.text) container.insert(0, props.text);
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import RichText from '../../behaviors/text/RichText.svelte';
|
|
3
|
-
import { getPlaceholder } from '../../utils/placeholders.js';
|
|
4
3
|
/** @type {{ block: import('./callout.svelte.js').CalloutBlock }} */
|
|
5
4
|
let { block } = $props();
|
|
6
5
|
/** @type {Record<string,string>} */
|
|
7
6
|
const ICONS = { note: 'ℹ️', tip: '💡', important: '❗', warning: '⚠️', caution: '🛑' };
|
|
8
7
|
</script>
|
|
9
8
|
|
|
10
|
-
<aside class="nabu-callout callout-{block.variant}" data-callout={block.variant}
|
|
11
|
-
<button
|
|
9
|
+
<aside class="nabu-callout callout-{block.variant}" data-callout={block.variant}><button
|
|
12
10
|
class="nabu-callout-icon"
|
|
13
11
|
data-nabu-ui
|
|
14
12
|
contenteditable="false"
|
|
15
13
|
type="button"
|
|
16
14
|
title="Change callout type ({block.variant})"
|
|
15
|
+
aria-label="Change callout type ({block.variant})"
|
|
16
|
+
aria-disabled={block.nabu.readonly ? 'true' : undefined}
|
|
17
17
|
onmousedown={(e) => { e.preventDefault(); block.cycleVariant(); }}
|
|
18
|
-
>{ICONS[block.variant] ?? ICONS.note}</button
|
|
19
|
-
<div
|
|
18
|
+
>{ICONS[block.variant] ?? ICONS.note}</button><div
|
|
20
19
|
class="nabu-callout-body"
|
|
21
20
|
bind:this={block.element}
|
|
22
21
|
data-block-id={block.id}
|
|
23
22
|
data-block-type="callout"
|
|
24
|
-
data-placeholder={block.
|
|
23
|
+
data-placeholder={block.placeholder}
|
|
25
24
|
class:selected={block.selected}
|
|
26
|
-
><RichText delta={block.delta} /></div>
|
|
27
|
-
</aside>
|
|
25
|
+
><RichText delta={block.delta} /></div></aside>
|
|
28
26
|
|
|
29
27
|
<style>
|
|
30
28
|
.nabu-callout {
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The callout block (`note`, `tip`, `important`, `warning`, `caution` variants): the `! ` shortcut, the `callout` action and the "Callout" slash entry.
|
|
3
|
+
*/
|
|
4
|
+
export const CalloutExtension: import("../../extend.js").Extension;
|
|
@@ -10,7 +10,8 @@ import CalloutComponent from "./Callout.svelte";
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* onBeforeInput hook for CalloutBlock:
|
|
13
|
-
* - Inside a callout block: Backspace on empty → transform back to paragraph
|
|
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).
|
|
14
15
|
* - In any other text block: "! " at the start → transform into a callout.
|
|
15
16
|
* (The "> " prefix is taken by Blockquote, so callouts use "! " — mnemonic
|
|
16
17
|
* for alert/important, and free of collisions.)
|
|
@@ -36,15 +37,24 @@ const onBeforeInput = (nabu, event, block) => {
|
|
|
36
37
|
});
|
|
37
38
|
return BREAK;
|
|
38
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
|
+
}
|
|
39
46
|
return CONTINUE;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
// "! " at the start of a text block → transform into a callout (variant note)
|
|
43
50
|
if (event.inputType === 'insertText' && event.data === ' ') {
|
|
44
51
|
if (behavior.text.slice(0, sel.from) !== '!') return CONTINUE;
|
|
45
|
-
behavior.delete({ index: 0, length: 1 });
|
|
46
52
|
const blockId = block.node.id.toString();
|
|
47
|
-
|
|
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
|
+
});
|
|
48
58
|
tick().then(() => {
|
|
49
59
|
const fresh = nabu.blocks.get(blockId);
|
|
50
60
|
if (fresh) fresh.focus({ start: 0, end: 0 });
|
|
@@ -55,10 +65,16 @@ const onBeforeInput = (nabu, event, block) => {
|
|
|
55
65
|
return CONTINUE;
|
|
56
66
|
};
|
|
57
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The callout block (`note`, `tip`, `important`, `warning`, `caution` variants): the `! ` shortcut, the `callout` action and the "Callout" slash entry.
|
|
70
|
+
*/
|
|
58
71
|
export const CalloutExtension = extension("callout", {
|
|
59
72
|
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
60
73
|
block: CalloutBlock,
|
|
61
74
|
component: CalloutComponent,
|
|
75
|
+
slashCommands: [
|
|
76
|
+
{ title: 'Callout', icon: '!', aliases: ['callout', 'note', 'info', 'warning'], group: 'blocks', order: 10, run: (e) => e.exec('callout') },
|
|
77
|
+
],
|
|
62
78
|
actions: {
|
|
63
79
|
'callout': (nabu) => nabu.exec('block:transform', { type: 'callout' }),
|
|
64
80
|
},
|
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export const CALLOUT_VARIANTS: string[];
|
|
8
8
|
export class CalloutBlock extends TextBlock {
|
|
9
|
+
static placeholder: string;
|
|
9
10
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
10
11
|
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
11
12
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
12
13
|
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
13
14
|
static markdownRules: {
|
|
14
15
|
priority: number;
|
|
16
|
+
interruptsParagraph: boolean;
|
|
15
17
|
detect: RegExp;
|
|
16
18
|
/**
|
|
17
19
|
* Consume the callout header line plus all subsequent ">" prefixed lines.
|
|
@@ -41,8 +43,8 @@ export class CalloutBlock extends TextBlock {
|
|
|
41
43
|
static fromHTML(el: Element, { parseInline }: {
|
|
42
44
|
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
43
45
|
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
44
|
-
/** @param {Nabu} nabu @param {string} type @param {
|
|
45
|
-
static create(nabu: Nabu, type: string, props?:
|
|
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;
|
|
46
48
|
/** @param {Nabu} nabu @param {CalloutNode} node */
|
|
47
49
|
constructor(nabu: Nabu, node: CalloutNode);
|
|
48
50
|
/** @type {string} */
|
|
@@ -56,7 +58,7 @@ export class CalloutBlock extends TextBlock {
|
|
|
56
58
|
*/
|
|
57
59
|
setVariant(v: string): void;
|
|
58
60
|
/**
|
|
59
|
-
* Cycle to the next callout variant.
|
|
61
|
+
* Cycle to the next callout variant (the user's gesture: a click on the icon). Does nothing in a read-only editor.
|
|
60
62
|
*/
|
|
61
63
|
cycleVariant(): void;
|
|
62
64
|
/**
|
|
@@ -2,6 +2,7 @@ import { TextBlock } from "../text-block.svelte.js";
|
|
|
2
2
|
import { LoroText } from "loro-crdt";
|
|
3
3
|
import CalloutComponent from "./Callout.svelte";
|
|
4
4
|
import { tick } from "svelte";
|
|
5
|
+
import { escapeAttr } from "../../utils/html.js";
|
|
5
6
|
import { deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -24,7 +25,7 @@ export class CalloutBlock extends TextBlock {
|
|
|
24
25
|
|
|
25
26
|
this.serializers.set('markdown', () => {
|
|
26
27
|
const header = '> [!' + this.variant.toUpperCase() + ']';
|
|
27
|
-
const body = this.behavior.toMarkdown();
|
|
28
|
+
const body = this.behavior.toMarkdown({ rawBreaks: true });
|
|
28
29
|
if (!body) return header;
|
|
29
30
|
return header + '\n' + body.split('\n').map(l => '> ' + l).join('\n');
|
|
30
31
|
});
|
|
@@ -54,6 +55,8 @@ export class CalloutBlock extends TextBlock {
|
|
|
54
55
|
/** @type {string} */
|
|
55
56
|
variant = $state('note');
|
|
56
57
|
|
|
58
|
+
static placeholder = 'Callout…';
|
|
59
|
+
|
|
57
60
|
component = $derived(this.nabu.components.get("callout") || CalloutComponent);
|
|
58
61
|
|
|
59
62
|
/**
|
|
@@ -68,9 +71,10 @@ export class CalloutBlock extends TextBlock {
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
|
-
* Cycle to the next callout variant.
|
|
74
|
+
* Cycle to the next callout variant (the user's gesture: a click on the icon). Does nothing in a read-only editor.
|
|
72
75
|
*/
|
|
73
76
|
cycleVariant() {
|
|
77
|
+
if (this.nabu.readonly) return;
|
|
74
78
|
const i = CALLOUT_VARIANTS.indexOf(this.variant);
|
|
75
79
|
this.setVariant(CALLOUT_VARIANTS[(i + 1) % CALLOUT_VARIANTS.length]);
|
|
76
80
|
}
|
|
@@ -109,20 +113,21 @@ export class CalloutBlock extends TextBlock {
|
|
|
109
113
|
static toMarkdown(pb) {
|
|
110
114
|
const v = (pb.props?.variant || 'note').toUpperCase();
|
|
111
115
|
const header = '> [!' + v + ']';
|
|
112
|
-
const body = deltaToMarkdown(pb.delta || []);
|
|
116
|
+
const body = deltaToMarkdown(pb.delta || [], { rawBreaks: true }); // the callout rule re-reads its own lines
|
|
113
117
|
if (!body) return header;
|
|
114
118
|
return header + '\n' + body.split('\n').map(l => '> ' + l).join('\n');
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
118
122
|
static toHtml(pb) {
|
|
119
|
-
const v = pb.props?.variant || 'note';
|
|
123
|
+
const v = escapeAttr(pb.props?.variant || 'note');
|
|
120
124
|
return '<aside class="callout callout-' + v + '" data-callout="' + v + '">' + deltaToHtml(pb.delta || []) + '</aside>';
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
static markdownRules = [
|
|
124
128
|
{
|
|
125
129
|
priority: 20,
|
|
130
|
+
interruptsParagraph: true,
|
|
126
131
|
detect: /^> \[!(note|tip|important|warning|caution)\]/i,
|
|
127
132
|
/**
|
|
128
133
|
* Consume the callout header line plus all subsequent ">" prefixed lines.
|
|
@@ -170,9 +175,9 @@ export class CalloutBlock extends TextBlock {
|
|
|
170
175
|
return { type: 'callout', props: { variant }, delta, partial: false };
|
|
171
176
|
}
|
|
172
177
|
|
|
173
|
-
/** @param {Nabu} nabu @param {string} type @param {
|
|
178
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
174
179
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
175
|
-
const node = nabu.tree.createNode(/** @type {
|
|
180
|
+
const node = nabu.tree.createNode(/** @type {import('loro-crdt').TreeID | undefined} */ (parentId || undefined), index ?? undefined);
|
|
176
181
|
/** @type {any} */ (node.data).set('type', 'callout');
|
|
177
182
|
const variant = CALLOUT_VARIANTS.includes(props.variant) ? props.variant : 'note';
|
|
178
183
|
/** @type {any} */ (node.data).set('variant', variant);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Whether the browser can skip off-screen boxes (`content-visibility: auto`). Without it chunking would only add wrappers, so it is not done. */
|
|
2
|
+
export function supportsChunking(): boolean;
|
|
3
|
+
/** Whether a chunk starts at the block with this id. @param {string} id */
|
|
4
|
+
export function startsChunk(id: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} Chunk
|
|
7
|
+
* @property {string} key the id of its first block (stable while that block exists)
|
|
8
|
+
* @property {import('./block.svelte.js').Block[]} blocks
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Cut `blocks` into chunks. A chunk starts at the first block and at every block for which {@link startsChunk} is true.
|
|
12
|
+
* A chunk of `previous` (a Map by key) with the same blocks in the same order is returned as is, so that a keyed render sees an
|
|
13
|
+
* unchanged object and does not look at it again.
|
|
14
|
+
* @param {import('./block.svelte.js').Block[]} blocks
|
|
15
|
+
* @param {Map<string, Chunk>} [previous]
|
|
16
|
+
* @returns {Chunk[]}
|
|
17
|
+
*/
|
|
18
|
+
export function chunkBlocks(blocks: import("./block.svelte.js").Block[], previous?: Map<string, Chunk>): Chunk[];
|
|
19
|
+
/**
|
|
20
|
+
* Large documents: how a long list of sibling blocks is cut into CHUNKS.
|
|
21
|
+
*
|
|
22
|
+
* WHY. A keystroke costs the page more than the engine does: the browser lays out, paints and syncs the selection of the WHOLE
|
|
23
|
+
* contenteditable on every edit, and that work grows with the number of elements it has to look at (measured: 1 ms of script and no DOM
|
|
24
|
+
* node created per key at 10,000 blocks, but ~90 ms from key to next paint, almost all of it inside Chromium). `content-visibility: auto`
|
|
25
|
+
* lets the browser skip the layout, paint and selection bookkeeping of everything that is off screen, but it is only cheap on a FEW
|
|
26
|
+
* large boxes: one per block costs as much as it saves. So a long list of siblings is rendered as a few hundred chunk wrappers of
|
|
27
|
+
* ~64 blocks, each one `content-visibility: auto` (see BlockList.svelte).
|
|
28
|
+
*
|
|
29
|
+
* HOW the cuts are chosen. By CONTENT, not by position: a block starts a chunk when a hash of its id says so (one in `CHUNK_AVG`
|
|
30
|
+
* on average), whatever its index. Inserting or deleting a block then moves at most the one cut that block is, so a keyed render only
|
|
31
|
+
* ever touches the chunk (or the two chunks) around the edit; cutting every 64 blocks by index would shift every chunk after an Enter.
|
|
32
|
+
*
|
|
33
|
+
* Nothing here knows a block type: any list of blocks can be chunked.
|
|
34
|
+
*/
|
|
35
|
+
/** A list of at least this many sibling blocks is rendered in chunks... */
|
|
36
|
+
export const CHUNK_ON: 500;
|
|
37
|
+
/** ...until it shrinks under this many (hysteresis: a list hovering around the threshold does not flip its markup on every key). */
|
|
38
|
+
export const CHUNK_OFF: 250;
|
|
39
|
+
/** Average number of blocks in a chunk (a cut every `CHUNK_AVG` blocks). */
|
|
40
|
+
export const CHUNK_AVG: 64;
|
|
41
|
+
/** A document of at least this many blocks (all levels) is "large" (`data-nabu-large` on the editor root): containers may skip their off-screen bodies. */
|
|
42
|
+
export const LARGE_DOC: 800;
|
|
43
|
+
export type Chunk = {
|
|
44
|
+
/**
|
|
45
|
+
* the id of its first block (stable while that block exists)
|
|
46
|
+
*/
|
|
47
|
+
key: string;
|
|
48
|
+
blocks: import("./block.svelte.js").Block[];
|
|
49
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Large documents: how a long list of sibling blocks is cut into CHUNKS.
|
|
3
|
+
*
|
|
4
|
+
* WHY. A keystroke costs the page more than the engine does: the browser lays out, paints and syncs the selection of the WHOLE
|
|
5
|
+
* contenteditable on every edit, and that work grows with the number of elements it has to look at (measured: 1 ms of script and no DOM
|
|
6
|
+
* node created per key at 10,000 blocks, but ~90 ms from key to next paint, almost all of it inside Chromium). `content-visibility: auto`
|
|
7
|
+
* lets the browser skip the layout, paint and selection bookkeeping of everything that is off screen, but it is only cheap on a FEW
|
|
8
|
+
* large boxes: one per block costs as much as it saves. So a long list of siblings is rendered as a few hundred chunk wrappers of
|
|
9
|
+
* ~64 blocks, each one `content-visibility: auto` (see BlockList.svelte).
|
|
10
|
+
*
|
|
11
|
+
* HOW the cuts are chosen. By CONTENT, not by position: a block starts a chunk when a hash of its id says so (one in `CHUNK_AVG`
|
|
12
|
+
* on average), whatever its index. Inserting or deleting a block then moves at most the one cut that block is, so a keyed render only
|
|
13
|
+
* ever touches the chunk (or the two chunks) around the edit; cutting every 64 blocks by index would shift every chunk after an Enter.
|
|
14
|
+
*
|
|
15
|
+
* Nothing here knows a block type: any list of blocks can be chunked.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** A list of at least this many sibling blocks is rendered in chunks... */
|
|
19
|
+
export const CHUNK_ON = 500;
|
|
20
|
+
/** ...until it shrinks under this many (hysteresis: a list hovering around the threshold does not flip its markup on every key). */
|
|
21
|
+
export const CHUNK_OFF = 250;
|
|
22
|
+
/** Average number of blocks in a chunk (a cut every `CHUNK_AVG` blocks). */
|
|
23
|
+
export const CHUNK_AVG = 64;
|
|
24
|
+
/** A document of at least this many blocks (all levels) is "large" (`data-nabu-large` on the editor root): containers may skip their off-screen bodies. */
|
|
25
|
+
export const LARGE_DOC = 800;
|
|
26
|
+
|
|
27
|
+
/** @type {boolean | undefined} */
|
|
28
|
+
let supported;
|
|
29
|
+
/** Whether the browser can skip off-screen boxes (`content-visibility: auto`). Without it chunking would only add wrappers, so it is not done. */
|
|
30
|
+
export function supportsChunking() {
|
|
31
|
+
if (supported === undefined) supported = typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('content-visibility', 'auto');
|
|
32
|
+
return supported;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** FNV-1a (32 bit) of a string. @param {string} s */
|
|
36
|
+
function fnv1a(s) {
|
|
37
|
+
let h = 0x811c9dc5;
|
|
38
|
+
for (let i = 0; i < s.length; i++) {
|
|
39
|
+
h ^= s.charCodeAt(i);
|
|
40
|
+
h = Math.imul(h, 0x01000193);
|
|
41
|
+
}
|
|
42
|
+
return h >>> 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whether a chunk starts at the block with this id. @param {string} id */
|
|
46
|
+
export function startsChunk(id) {
|
|
47
|
+
return fnv1a(id) % CHUNK_AVG === 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @typedef {Object} Chunk
|
|
52
|
+
* @property {string} key the id of its first block (stable while that block exists)
|
|
53
|
+
* @property {import('./block.svelte.js').Block[]} blocks
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Cut `blocks` into chunks. A chunk starts at the first block and at every block for which {@link startsChunk} is true.
|
|
58
|
+
* A chunk of `previous` (a Map by key) with the same blocks in the same order is returned as is, so that a keyed render sees an
|
|
59
|
+
* unchanged object and does not look at it again.
|
|
60
|
+
* @param {import('./block.svelte.js').Block[]} blocks
|
|
61
|
+
* @param {Map<string, Chunk>} [previous]
|
|
62
|
+
* @returns {Chunk[]}
|
|
63
|
+
*/
|
|
64
|
+
export function chunkBlocks(blocks, previous) {
|
|
65
|
+
/** @type {Chunk[]} */
|
|
66
|
+
const out = [];
|
|
67
|
+
/** @type {import('./block.svelte.js').Block[]} */
|
|
68
|
+
let current = [];
|
|
69
|
+
const flush = () => {
|
|
70
|
+
if (!current.length) return;
|
|
71
|
+
const key = current[0].id;
|
|
72
|
+
const old = previous?.get(key);
|
|
73
|
+
out.push(old && sameBlocks(old.blocks, current) ? old : { key, blocks: current });
|
|
74
|
+
current = [];
|
|
75
|
+
};
|
|
76
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
77
|
+
const block = blocks[i];
|
|
78
|
+
if (current.length && startsChunk(block.id)) flush();
|
|
79
|
+
current.push(block);
|
|
80
|
+
}
|
|
81
|
+
flush();
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @param {unknown[]} a @param {unknown[]} b */
|
|
86
|
+
function sameBlocks(a, b) {
|
|
87
|
+
if (a.length !== b.length) return false;
|
|
88
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getPlaceholder } from '../../utils/placeholders.js';
|
|
3
2
|
/** @type {{ block: import('./code.svelte.js').CodeBlock }} */
|
|
4
3
|
let { block } = $props();
|
|
5
4
|
const LANGS = ['plaintext', 'javascript', 'typescript', 'html', 'css', 'json', 'python', 'rust', 'bash', 'markdown', 'sql', 'go'];
|
|
6
5
|
</script>
|
|
7
6
|
|
|
8
|
-
<div class="nabu-code-wrapper"
|
|
9
|
-
<select
|
|
7
|
+
<div class="nabu-code-wrapper"><select
|
|
10
8
|
class="nabu-code-lang"
|
|
11
9
|
data-nabu-ui
|
|
12
10
|
contenteditable="false"
|
|
13
11
|
value={block.language ?? 'plaintext'}
|
|
12
|
+
disabled={block.nabu.readonly}
|
|
13
|
+
aria-label="Code language"
|
|
14
14
|
onchange={(e) => block.setLanguage(e.currentTarget.value === 'plaintext' ? null : e.currentTarget.value)}
|
|
15
15
|
>
|
|
16
16
|
{#each LANGS as lang}<option value={lang}>{lang}</option>{/each}
|
|
17
|
-
</select
|
|
18
|
-
<pre
|
|
17
|
+
</select><pre
|
|
19
18
|
bind:this={block.element}
|
|
20
19
|
data-block-id={block.id}
|
|
21
20
|
data-block-type="code"
|
|
22
|
-
|
|
21
|
+
spellcheck="false"
|
|
22
|
+
data-placeholder={block.placeholder}
|
|
23
23
|
class="nabu-code"
|
|
24
24
|
class:debug={block.nabu.debugging}
|
|
25
25
|
class:selected={block.selected}
|
|
26
|
-
><code>{block.text || '\n'}</code></pre>
|
|
27
|
-
</div>
|
|
26
|
+
><code>{block.text || '\n'}{#if block.text.endsWith('\n')}<br data-nabu-filler>{/if}</code></pre></div>
|
|
28
27
|
|
|
29
28
|
<style>
|
|
30
29
|
.nabu-code-wrapper {
|