@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,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart typography input rules.
|
|
3
|
+
* Currently: `-- ` → `— ` (em-dash substitution while typing). A longer run of dashes (`--- `,
|
|
4
|
+
* a divider-like `-----`) is left alone: the `--` must not be preceded by another `-`.
|
|
5
|
+
*/
|
|
6
|
+
export const TypographyExtension: Extension;
|
|
7
|
+
import { Extension } from '../../utils/extensions.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Extension } from '../../utils/extensions.js';
|
|
2
|
+
import { TextBehavior } from './text.behavior.svelte.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Smart typography input rules.
|
|
6
|
+
* Currently: `-- ` → `— ` (em-dash substitution while typing). A longer run of dashes (`--- `,
|
|
7
|
+
* a divider-like `-----`) is left alone: the `--` must not be preceded by another `-`.
|
|
8
|
+
*/
|
|
9
|
+
export const TypographyExtension = new Extension('typography', {
|
|
10
|
+
inputRules: [
|
|
11
|
+
{
|
|
12
|
+
pattern: /(?<!-)--$/,
|
|
13
|
+
handler(nabu, block, match, sel) {
|
|
14
|
+
// Only convert when the trailing space is typed, so sequences
|
|
15
|
+
// like `--help` keep their double dash.
|
|
16
|
+
if (sel.data !== ' ') return;
|
|
17
|
+
const behavior = block.behaviors.get('text');
|
|
18
|
+
if (!(behavior instanceof TextBehavior)) return;
|
|
19
|
+
behavior.delete({ index: sel.from - 2, length: 2 });
|
|
20
|
+
behavior.insert(sel.from - 2, '— ');
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
});
|
package/dist/blocks/Block.svelte
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
2
|
+
// BlockGap (the hover "+" between blocks) is intentionally disabled — it
|
|
3
|
+
// injected an inert div between every block, causing cursor/selection edge
|
|
4
|
+
// cases. The component + its `gap:click` handler remain, dormant, for a
|
|
5
|
+
// possible future revisit. Re-enable by rendering <BlockGap {block} /> below.
|
|
3
6
|
|
|
4
7
|
/** @type {{ block: import('./block.svelte.js').Block }} */
|
|
5
8
|
let { block } = $props();
|
|
@@ -15,4 +18,4 @@
|
|
|
15
18
|
<div style="color: red; border: 1px dashed red; padding: 0.5rem; margin: 0.5rem 0;" contenteditable="false">
|
|
16
19
|
⚠️ Unknown block type: <strong>{block.type}</strong>
|
|
17
20
|
</div>
|
|
18
|
-
{/if}
|
|
21
|
+
{/if}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Block from "./Block.svelte";
|
|
3
|
+
import { chunkBlocks, supportsChunking, CHUNK_ON, CHUNK_OFF } from "./chunks.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A list of sibling blocks: the root of the editor, the body of a region. Short lists are rendered as they are, one block
|
|
7
|
+
* after the other, with no markup of their own. A long one (`CHUNK_ON` blocks and more) is rendered in chunks of ~64 blocks, each
|
|
8
|
+
* in a wrapper that the browser may skip while it is off screen (`content-visibility: auto`), which is what keeps a keystroke
|
|
9
|
+
* in a 10,000-block document within a frame (see chunks.js for the why and the how).
|
|
10
|
+
* @type {{ blocks: import('./block.svelte.js').Block[] }}
|
|
11
|
+
*/
|
|
12
|
+
let { blocks } = $props();
|
|
13
|
+
|
|
14
|
+
// Hysteresis: switches on at CHUNK_ON blocks, off under CHUNK_OFF. (Plain variable on purpose: it is only read back by this derived.)
|
|
15
|
+
let was = false;
|
|
16
|
+
const chunked = $derived.by(() => {
|
|
17
|
+
was = blocks.length >= (was ? CHUNK_OFF : CHUNK_ON);
|
|
18
|
+
return was && supportsChunking();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// The chunks of the last render, to hand back the unchanged ones as they were.
|
|
22
|
+
let memo = new Map();
|
|
23
|
+
const chunks = $derived.by(() => {
|
|
24
|
+
if (!chunked) return [];
|
|
25
|
+
const next = chunkBlocks(blocks, memo);
|
|
26
|
+
memo = new Map(next.map((c) => [c.key, c]));
|
|
27
|
+
return next;
|
|
28
|
+
});
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- No whitespace between the tags: the editor preserves whitespace, any text node here would render as a selectable line. -->
|
|
32
|
+
{#if chunked}{#each chunks as chunk (chunk.key)}<div class="nabu-chunk" style:--nb-chunk-blocks={chunk.blocks.length}>{#each chunk.blocks as block (block.id)}<Block {block} />{/each}</div>{/each}{:else}{#each blocks as block (block.id)}<Block {block} />{/each}{/if}
|
|
33
|
+
|
|
34
|
+
<style>
|
|
35
|
+
/* Off screen, the browser skips the layout, paint and selection bookkeeping of a chunk. Its height is then an estimate (the number
|
|
36
|
+
of blocks times --nb-block-estimate, which a theme may tune) until the chunk has been shown once: `auto` remembers the real one. */
|
|
37
|
+
.nabu-chunk {
|
|
38
|
+
content-visibility: auto;
|
|
39
|
+
contain-intrinsic-block-size: auto calc(var(--nb-chunk-blocks, 64) * var(--nb-block-estimate, 72px));
|
|
40
|
+
/* `content-visibility: auto` clips what hangs out of the box (paint containment): the margin rail of a region sits in the
|
|
41
|
+
margin, left of its box. */
|
|
42
|
+
overflow-clip-margin: var(--nb-clip-margin, 3rem);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@media print {
|
|
46
|
+
.nabu-chunk { content-visibility: visible; }
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default BlockList;
|
|
2
|
+
type BlockList = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const BlockList: import("svelte").Component<{
|
|
7
|
+
blocks: import("./block.svelte.js").Block[];
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
/**
|
|
10
|
+
* A list of sibling blocks: the root of the editor, the body of a region. Short lists are rendered as they are, one block
|
|
11
|
+
* after the other, with no markup of their own. A long one (`CHUNK_ON` blocks and more) is rendered in chunks of ~64 blocks, each
|
|
12
|
+
* in a wrapper that the browser may skip while it is off screen (`content-visibility: auto`), which is what keeps a keystroke
|
|
13
|
+
* in a 10,000-block document within a frame (see chunks.js for the why and the how).
|
|
14
|
+
*/
|
|
15
|
+
type $$ComponentProps = {
|
|
16
|
+
blocks: import("./block.svelte.js").Block[];
|
|
17
|
+
};
|
package/dist/blocks/Nabu.svelte
CHANGED
|
@@ -1,34 +1,200 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { Nabu } from "./nabu.svelte.js";
|
|
3
|
-
import
|
|
3
|
+
import BlockList from "./BlockList.svelte";
|
|
4
|
+
import { LARGE_DOC } from "./chunks.js";
|
|
5
|
+
import { commandTargetElement } from "../utils/command-confirm.svelte.js";
|
|
4
6
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* - `label`: the accessible name of the editor (`aria-label` on the contenteditable root), e.g. "Chapter text".
|
|
9
|
+
* - `labelledby`: the id of the element that names it (`aria-labelledby`), for a visible `<label>`. Wins over `label` for
|
|
10
|
+
* assistive technology when both are set. No `role` is ever set on an editable root: it would flatten the headings inside.
|
|
11
|
+
* - `readonly`: show the document without letting anyone edit it. Reactive (toggle it live). When omitted, the editor follows
|
|
12
|
+
* `engine.readonly` (the `readonly` option of the engine); when given, it sets `engine.readonly`.
|
|
13
|
+
* @type {{ engine: Nabu, label?: string, labelledby?: string, readonly?: boolean }}
|
|
14
|
+
*/
|
|
15
|
+
let { engine = new Nabu(), label = undefined, labelledby = undefined, readonly = undefined } = $props();
|
|
16
|
+
|
|
17
|
+
// The prop drives the engine (set now, so that the first render and the server render already agree, then kept in sync live):
|
|
18
|
+
// the engine is where every guard reads it. `isReadonly` is what this component draws.
|
|
19
|
+
function syncReadonly() { if (readonly !== undefined) engine.readonly = !!readonly; }
|
|
20
|
+
syncReadonly();
|
|
21
|
+
$effect.pre(syncReadonly);
|
|
22
|
+
// A large document (800 blocks, at any level): its containers may skip their off-screen body, see blocks/chunks.js. `data-nabu-large` on the root.
|
|
23
|
+
const isLarge = $derived(engine.blocks.size >= LARGE_DOC);
|
|
24
|
+
const isReadonly = $derived(readonly !== undefined ? !!readonly : engine.readonly);
|
|
25
|
+
|
|
26
|
+
// The engine learns which element is its own root (an attachment: set when the root mounts, cleared when it goes away, and re-run
|
|
27
|
+
// if `engine` changes). Everything the engine does with the page-wide DOM selection or a document-level event is limited to
|
|
28
|
+
// this element, so that several editors can share a page without ever acting on each other's caret (see NabuSelection).
|
|
29
|
+
/** @type {import('svelte/attachments').Attachment<HTMLElement>} */
|
|
30
|
+
const claimRoot = (node) => engine.internals.selection.attachRoot(node);
|
|
31
|
+
|
|
32
|
+
// An event that bubbles from a NESTED editor (one mounted in a UI island of this editor) reaches the root of this editor too:
|
|
33
|
+
// only the editor whose root is the nearest one handles it.
|
|
34
|
+
/** @param {Event} e */
|
|
35
|
+
function mine(e) {
|
|
36
|
+
const target = e.target;
|
|
37
|
+
const el = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
|
|
38
|
+
return !el || el.closest('[data-nabu-root]') === e.currentTarget;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
$effect(() => {
|
|
42
|
+
engine.systems.forEach(system => system.start?.());
|
|
43
|
+
return () => engine.systems.forEach(system => system.stop?.());
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// The target of a pending confirmation (ADR 017 §3.4a) is marked so that it can draw the progress: `data-command-target`
|
|
47
|
+
// (the strategy) and `--nb-command-progress` (0 → 1). A block that draws its own may read `engine.pendingCommandOn(block)`.
|
|
48
|
+
$effect(() => {
|
|
49
|
+
const pending = engine.pendingCommand;
|
|
50
|
+
const el = pending ? commandTargetElement(pending.target) : null;
|
|
51
|
+
if (!pending || !el) return;
|
|
52
|
+
el.setAttribute('data-command-target', pending.strategy);
|
|
53
|
+
$effect(() => { el.style.setProperty('--nb-command-progress', String(pending.progress)); });
|
|
54
|
+
return () => { el.removeAttribute('data-command-target'); el.style.removeProperty('--nb-command-progress'); };
|
|
55
|
+
});
|
|
7
56
|
</script>
|
|
8
57
|
|
|
58
|
+
<!-- With spellcheck off, the data-gramm* attributes are the documented opt-out hints of the Grammarly extension (it would
|
|
59
|
+
otherwise inject its own DOM into the editor, which Nabu does not support). Code blocks set spellcheck="false" themselves. -->
|
|
9
60
|
<div
|
|
10
|
-
contenteditable=
|
|
61
|
+
contenteditable={isReadonly ? 'false' : 'true'}
|
|
11
62
|
class="nabu-editor"
|
|
12
|
-
|
|
63
|
+
aria-label={label}
|
|
64
|
+
aria-labelledby={labelledby}
|
|
65
|
+
role={isReadonly ? 'document' : undefined}
|
|
66
|
+
data-nabu-readonly={isReadonly ? '' : undefined}
|
|
67
|
+
spellcheck={engine.spellcheck ? 'true' : 'false'}
|
|
68
|
+
lang={engine.lang}
|
|
69
|
+
{...(engine.tabDescription ? { 'aria-description': engine.tabDescription } : {})}
|
|
70
|
+
data-gramm={engine.spellcheck ? undefined : 'false'}
|
|
71
|
+
data-gramm_editor={engine.spellcheck ? undefined : 'false'}
|
|
72
|
+
data-enable-grammarly={engine.spellcheck ? undefined : 'false'}
|
|
13
73
|
translate="no"
|
|
14
74
|
data-nabu-root="true"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
75
|
+
{@attach claimRoot}
|
|
76
|
+
data-nabu-range={engine.selection?.isRange ? '' : undefined}
|
|
77
|
+
data-nabu-large={isLarge ? '' : undefined}
|
|
78
|
+
onbeforeinput={(e) => mine(e) && engine.handleBeforeinput(e)}
|
|
79
|
+
onkeydown={(e) => mine(e) && engine.handleKeydown(e)}
|
|
80
|
+
onmousedown={(e) => mine(e) && engine.handleMousedown(e)}
|
|
81
|
+
onfocusout={() => engine.rearmTab()}
|
|
82
|
+
oncopy={(e) => mine(e) && engine.handleCopy(e)}
|
|
83
|
+
oncut={(e) => mine(e) && engine.handleCut(e)}
|
|
84
|
+
onpaste={(e) => mine(e) && engine.handlePaste(e)}
|
|
85
|
+
ondragstart={(e) => engine.handleDragStart(e)}
|
|
86
|
+
ondragenter={(e) => engine.handleDragOver(e)}
|
|
87
|
+
ondragover={(e) => engine.handleDragOver(e)}
|
|
88
|
+
ondragleave={(e) => engine.handleDragLeave(e)}
|
|
89
|
+
ondragend={(e) => engine.handleDragEnd(e)}
|
|
90
|
+
ondrop={(e) => engine.handleDrop(e)}
|
|
91
|
+
oncompositionstart={(e) => mine(e) && engine.handleCompositionStart(e)}
|
|
92
|
+
oncompositionupdate={(e) => mine(e) && engine.handleCompositionUpdate(e)}
|
|
93
|
+
oncompositionend={(e) => mine(e) && engine.handleCompositionEnd(e)}
|
|
20
94
|
>
|
|
21
|
-
{
|
|
22
|
-
<Block {block} />
|
|
23
|
-
{/each}
|
|
95
|
+
<BlockList blocks={engine.children} />
|
|
24
96
|
</div>
|
|
25
97
|
|
|
98
|
+
<!-- One polite live region per editor: prompts and outcomes of command confirmations (hold, invite, choose). Visually hidden. -->
|
|
99
|
+
<div class="nabu-live" role="status" aria-live="polite" aria-atomic="true" data-nabu-ui data-nabu-live>{engine.commandAnnouncement}</div>
|
|
100
|
+
|
|
26
101
|
<style>
|
|
102
|
+
.nabu-live {
|
|
103
|
+
position: absolute;
|
|
104
|
+
width: 1px;
|
|
105
|
+
height: 1px;
|
|
106
|
+
margin: -1px;
|
|
107
|
+
padding: 0;
|
|
108
|
+
overflow: hidden;
|
|
109
|
+
clip-path: inset(50%);
|
|
110
|
+
white-space: nowrap;
|
|
111
|
+
border: 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
27
114
|
.nabu-editor {
|
|
28
|
-
outline: none;
|
|
115
|
+
outline: none; /* replaced by the focus ring below */
|
|
29
116
|
min-height: 100px;
|
|
30
117
|
padding: 1rem;
|
|
31
118
|
white-space: pre-wrap; /* Important pour le comportement éditeur */
|
|
32
119
|
word-break: break-word;
|
|
33
120
|
}
|
|
121
|
+
|
|
122
|
+
/* Focus indicator (WCAG 2.4.7 / 1.4.11): a 2px ring in --nb-focus-ring, defined by the base theme (nabu-theme.css: #0b57d0, 6.4:1 on white,
|
|
123
|
+
and #8ab4f8, 7.9:1 on #1e1e1e). Without the theme the fallbacks below are the same two colours, picked by prefers-color-scheme.
|
|
124
|
+
Drawn INSIDE the box (negative offset) so that an `overflow: hidden` ancestor never clips it. A theme that draws its own
|
|
125
|
+
indicator (Atelier: the border of the pane) overrides this with a more specific rule and sets `outline: none`. */
|
|
126
|
+
.nabu-editor:focus-visible {
|
|
127
|
+
outline: var(--nb-focus-ring-width, 2px) solid var(--nb-focus-ring, #0b57d0);
|
|
128
|
+
outline-offset: calc(var(--nb-focus-ring-width, 2px) * -1);
|
|
129
|
+
}
|
|
130
|
+
@media (prefers-color-scheme: dark) {
|
|
131
|
+
.nabu-editor:focus-visible { outline-color: var(--nb-focus-ring, #8ab4f8); }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* Target of a pending confirmation (ADR 017): a neutral default, a thin outline + a fill that follows --nb-command-progress
|
|
135
|
+
(0 → 1). Override --nb-command-* freely, or draw your own from [data-command-target] / engine.pendingCommandOn(block). */
|
|
136
|
+
.nabu-editor :global([data-command-target]) {
|
|
137
|
+
outline: 2px solid var(--nb-command-accent, currentColor);
|
|
138
|
+
outline-offset: 2px;
|
|
139
|
+
border-radius: var(--nb-command-radius, 3px);
|
|
140
|
+
background-image: linear-gradient(to right, var(--nb-command-fill, color-mix(in srgb, currentColor 12%, transparent)) calc(var(--nb-command-progress, 0) * 100%), transparent 0);
|
|
141
|
+
}
|
|
142
|
+
.nabu-editor :global([data-command-target='invite']) {
|
|
143
|
+
background-image: none;
|
|
144
|
+
}
|
|
145
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
146
|
+
.nabu-editor :global([data-command-target]) { transition: outline-color 0.1s; }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Paragraph indent (the French "alinéa") is LAYOUT, not content: --nb-paragraph-indent (default 0, so nothing changes until a
|
|
150
|
+
host sets it, e.g. `--nb-paragraph-indent: 1.5em`) becomes the text-indent of every paragraph, EXCEPT by the classic
|
|
151
|
+
typographic rule the first one of a text: the first block of the document, of a region body, of any container (:first-child),
|
|
152
|
+
and the one right after a heading or a divider. (A region seam is not a sibling of its body: the body's first block is
|
|
153
|
+
:first-child.) Sibling selectors on the existing markup only, no class, no model. */
|
|
154
|
+
.nabu-editor :global([data-block-type='paragraph']) {
|
|
155
|
+
text-indent: var(--nb-paragraph-indent, 0);
|
|
156
|
+
}
|
|
157
|
+
.nabu-editor :global([data-block-type='paragraph']:first-child),
|
|
158
|
+
.nabu-editor :global(:is([data-block-type='heading'], [data-block-type='divider']) + [data-block-type='paragraph']) {
|
|
159
|
+
text-indent: 0;
|
|
160
|
+
}
|
|
161
|
+
/* A long list of blocks is rendered in chunks (BlockList.svelte): the first block of a chunk is not the first of its text, except in the first chunk. */
|
|
162
|
+
.nabu-editor :global(.nabu-chunk:not(:first-child) > [data-block-type='paragraph']:first-child) {
|
|
163
|
+
text-indent: var(--nb-paragraph-indent, 0);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* A selection across several blocks leaves out the blocks that isolate their text (a region title, ADR 018 §3.9): the model
|
|
167
|
+
does not touch them, and they are not drawn as selected. Only the highlight changes (the DOM of the block stays as it is,
|
|
168
|
+
so a drag in progress is not disturbed). */
|
|
169
|
+
.nabu-editor[data-nabu-range] :global([data-nabu-isolated]::selection),
|
|
170
|
+
.nabu-editor[data-nabu-range] :global([data-nabu-isolated] *::selection) {
|
|
171
|
+
background: transparent;
|
|
172
|
+
color: inherit;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* Placeholders — blocks expose data-placeholder when it must be shown
|
|
176
|
+
(empty, and holding the cursor by default; see the `placeholders` option).
|
|
177
|
+
Uses ::after (not ::before) so blocks that decorate themselves with
|
|
178
|
+
::before (e.g. dialogue's dash) keep working. Absolutely positioned so it
|
|
179
|
+
never takes part in the layout, the caret placement or the text. It is
|
|
180
|
+
pinned to the top-left and inherits the block's padding (the empty block
|
|
181
|
+
holds a "\n", which would push an auto-positioned box onto a 2nd line). */
|
|
182
|
+
.nabu-editor :global([data-block-id][data-placeholder]) {
|
|
183
|
+
position: relative; /* containing block of the absolute ::after */
|
|
184
|
+
}
|
|
185
|
+
.nabu-editor :global([data-block-id][data-placeholder]:not([data-placeholder=''])::after) {
|
|
186
|
+
content: attr(data-placeholder);
|
|
187
|
+
color: var(--nb-text-placeholder, color-mix(in srgb, currentColor 60%, transparent));
|
|
188
|
+
pointer-events: none;
|
|
189
|
+
position: absolute;
|
|
190
|
+
top: 0;
|
|
191
|
+
left: 0;
|
|
192
|
+
right: 0;
|
|
193
|
+
box-sizing: border-box;
|
|
194
|
+
padding: inherit;
|
|
195
|
+
overflow: hidden;
|
|
196
|
+
text-overflow: ellipsis;
|
|
197
|
+
user-select: none;
|
|
198
|
+
white-space: nowrap;
|
|
199
|
+
}
|
|
34
200
|
</style>
|
|
@@ -5,8 +5,21 @@ type Nabu = {
|
|
|
5
5
|
};
|
|
6
6
|
declare const Nabu: import("svelte").Component<{
|
|
7
7
|
engine: Nabu;
|
|
8
|
+
label?: string;
|
|
9
|
+
labelledby?: string;
|
|
10
|
+
readonly?: boolean;
|
|
8
11
|
}, {}, "">;
|
|
9
12
|
import { Nabu } from "./nabu.svelte.js";
|
|
13
|
+
/**
|
|
14
|
+
* - `label`: the accessible name of the editor (`aria-label` on the contenteditable root), e.g. "Chapter text".
|
|
15
|
+
* - `labelledby`: the id of the element that names it (`aria-labelledby`), for a visible `<label>`. Wins over `label` for
|
|
16
|
+
* assistive technology when both are set. No `role` is ever set on an editable root: it would flatten the headings inside.
|
|
17
|
+
* - `readonly`: show the document without letting anyone edit it. Reactive (toggle it live). When omitted, the editor follows
|
|
18
|
+
* `engine.readonly` (the `readonly` option of the engine); when given, it sets `engine.readonly`.
|
|
19
|
+
*/
|
|
10
20
|
type $$ComponentProps = {
|
|
11
21
|
engine: Nabu;
|
|
22
|
+
label?: string;
|
|
23
|
+
labelledby?: string;
|
|
24
|
+
readonly?: boolean;
|
|
12
25
|
};
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `block:transform` action: turn a block into another type (`exec('block:transform', { type, props })`). The block extensions' own actions (`heading:1`, `callout`...) and the slash menu go through it.
|
|
3
|
+
*/
|
|
1
4
|
export const BlockExtension: Extension;
|
|
2
5
|
import { Extension } from '../utils/extensions.js';
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @import { Nabu } from './nabu.svelte.js'
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { tick } from 'svelte';
|
|
6
5
|
import { Extension } from '../utils/extensions.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -11,20 +10,20 @@ import { Extension } from '../utils/extensions.js';
|
|
|
11
10
|
* @param {string} type
|
|
12
11
|
* @param {Object} [props={}]
|
|
13
12
|
*/
|
|
14
|
-
function transformBlock(nabu, type, props = {}) {
|
|
15
|
-
console.log(`Transforming block to type "${type}" with props`, props);
|
|
13
|
+
async function transformBlock(nabu, type, props = {}) {
|
|
16
14
|
const block = nabu.selection.anchorBlock;
|
|
17
15
|
if (!block) return;
|
|
18
16
|
const blockId = block.id;
|
|
19
17
|
const offset = block.behaviors?.get('text')?.selection?.from ?? 0;
|
|
20
|
-
block.
|
|
21
|
-
// After
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (newBlock) nabu.focus({ from: { block: newBlock, offset }, to: { block: newBlock, offset } });
|
|
25
|
-
});
|
|
18
|
+
await nabu.transact(() => block.retype(type, props));
|
|
19
|
+
// After the commit, updateRoots() replaces the block instance — fetch the new one.
|
|
20
|
+
const newBlock = nabu.blocks.get(blockId);
|
|
21
|
+
if (newBlock) nabu.focus({ from: { block: newBlock, offset }, to: { block: newBlock, offset } });
|
|
26
22
|
}
|
|
27
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The `block:transform` action: turn a block into another type (`exec('block:transform', { type, props })`). The block extensions' own actions (`heading:1`, `callout`...) and the slash menu go through it.
|
|
26
|
+
*/
|
|
28
27
|
export const BlockExtension = new Extension('block', {
|
|
29
28
|
actions: {
|
|
30
29
|
'block:transform': (nabu, data) => transformBlock(nabu, data?.type, data?.props ?? {}),
|