@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
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* @import { Nabu } from './nabu.svelte.js';
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { MegaBlock } from './megablock.svelte.js';
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Walks up from `block` toward `container` and returns the direct child of
|
|
10
8
|
* `container` that is (or contains) `block`.
|
|
@@ -101,217 +99,379 @@ export function wrapOrphan(nabu, block) {
|
|
|
101
99
|
return wrapper;
|
|
102
100
|
}
|
|
103
101
|
|
|
102
|
+
|
|
103
|
+
// ── Deleting a range across blocks ──────────────────────────────────────────
|
|
104
|
+
|
|
104
105
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
106
|
+
* A selected range of the document, as model positions.
|
|
107
|
+
* @typedef {object} DeletionRange
|
|
108
|
+
* @property {Block} startBlock Block holding the start of the range (earlier in document order).
|
|
109
|
+
* @property {number} startOffset Text offset of the start inside `startBlock`.
|
|
110
|
+
* @property {Block} endBlock Block holding the end of the range.
|
|
111
|
+
* @property {number} endOffset Text offset of the end inside `endBlock`.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/** @param {Block | null | undefined} block @returns {Block[]} */
|
|
115
|
+
const kidsOf = (block) => /** @type {Block[]} */ (/** @type {any} */ (block)?.children ?? []);
|
|
116
|
+
|
|
117
|
+
/** Children of `parent`, or the root blocks when `parent` is null. @param {Nabu} nabu @param {Block | null} parent */
|
|
118
|
+
const childrenOf = (nabu, parent) => (parent ? kidsOf(parent) : /** @type {Block[]} */ (nabu.children));
|
|
119
|
+
|
|
120
|
+
/** @param {Block} block @returns {import('../behaviors/text/text.behavior.svelte.js').TextBehavior | null} */
|
|
121
|
+
const textOf = (block) => /** @type {any} */ (block.behaviors?.get('text')) ?? null;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* `block` and its ancestors, up to (and excluding) `stop`: `[block, parent, …, child of stop]`.
|
|
125
|
+
* @param {Block} block
|
|
126
|
+
* @param {Block | null} stop
|
|
127
|
+
* @returns {Block[]}
|
|
128
|
+
*/
|
|
129
|
+
function pathUp(block, stop) {
|
|
130
|
+
/** @type {Block[]} */
|
|
131
|
+
const path = [];
|
|
132
|
+
for (let cur = /** @type {Block | null} */ (block); cur && cur !== stop; cur = cur.parent ?? null) path.push(cur);
|
|
133
|
+
return path;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Re-homes `blocks`, in order, right after `anchor` (a block of the tree), wrapping the ones whose type
|
|
138
|
+
* demands a specific parent (`requiredParent`) in a fresh wrapper. No commit.
|
|
139
|
+
* @param {Nabu} nabu
|
|
140
|
+
* @param {Block} anchor
|
|
141
|
+
* @param {Block[]} blocks
|
|
142
|
+
*/
|
|
143
|
+
function rehomeAfter(nabu, anchor, blocks) {
|
|
144
|
+
let after = anchor.node;
|
|
145
|
+
for (const block of blocks) {
|
|
146
|
+
block.node.moveAfter(after);
|
|
147
|
+
const wrapper = wrapOrphan(nabu, block);
|
|
148
|
+
after = (wrapper ?? block).node;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The deletion of a range whose text positions are all plain (no isolated block inside: see {@link deleteRange}).
|
|
154
|
+
* Mutates the Loro tree and texts, never commits.
|
|
110
155
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
156
|
+
* Model: document order is pre-order, a block's own text coming before its children. The range runs from
|
|
157
|
+
* (`startBlock`, `startOffset`) to (`endBlock`, `endOffset`):
|
|
158
|
+
* - the head of the start block and the tail of the end block are merged at the junction (the end block's
|
|
159
|
+
* children follow it: adopted by the start block when it can hold children, else promoted after it);
|
|
160
|
+
* - everything strictly inside the range is destroyed: blocks between the two spines, the later children of
|
|
161
|
+
* every block on the start spine, the earlier children of every block on the end spine, and the blocks of
|
|
162
|
+
* the end spine themselves (their own text lies inside the range);
|
|
163
|
+
* - what follows the end point inside the partially-selected blocks of the end spine SURVIVES, in document
|
|
164
|
+
* order, re-homed right after the start block (`wrapOrphan` honours `requiredParent`), so it keeps its
|
|
165
|
+
* position relative to everything outside the range; blocks that follow the end spine at the level of the
|
|
166
|
+
* common ancestor are untouched;
|
|
167
|
+
* - when the start block is an ANCESTOR of the end block (it starts in a hybrid's text and ends in its
|
|
168
|
+
* body), the remaining body stays where it is: structure-only blocks of the end spine are kept in place
|
|
169
|
+
* and only the blocks whose own text was inside the range are removed.
|
|
170
|
+
* Survivors are always moved out BEFORE their former ancestors are destroyed (deleting a Loro node deletes
|
|
171
|
+
* its whole subtree). The result may violate type-specific invariants; the normalizers fix them on commit.
|
|
117
172
|
*
|
|
118
|
-
* @param {{ children: Block[], commit: () => void }} container
|
|
119
173
|
* @param {Nabu} nabu
|
|
120
|
-
* @param {
|
|
174
|
+
* @param {DeletionRange} range
|
|
175
|
+
* @returns {{ block: Block, offset: number } | null} the junction (where the caret belongs), or null if the range is unusable
|
|
121
176
|
*/
|
|
122
|
-
|
|
123
|
-
const startBlock
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
177
|
+
function deleteRangeRaw(nabu, range) {
|
|
178
|
+
const { startBlock: start, startOffset, endBlock: end, endOffset } = range;
|
|
179
|
+
const startText = textOf(start);
|
|
180
|
+
const endText = textOf(end);
|
|
181
|
+
|
|
182
|
+
// ── One block: a plain text deletion ──
|
|
183
|
+
if (start === end) {
|
|
184
|
+
if (startText && endOffset > startOffset) startText.delete({ from: startOffset, to: endOffset });
|
|
185
|
+
return { block: start, offset: startOffset };
|
|
186
|
+
}
|
|
131
187
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
188
|
+
const lca = findLCA(start, end);
|
|
189
|
+
if (lca === end) return null; // end encloses start: the range is reversed
|
|
190
|
+
const nested = lca === start; // the start block holds the end block in its subtree
|
|
191
|
+
const startPath = nested ? [] : pathUp(start, lca);
|
|
192
|
+
const endPath = pathUp(end, lca);
|
|
193
|
+
if (!endPath.length) return null;
|
|
194
|
+
|
|
195
|
+
/** Blocks destroyed at the end (with their subtree). @type {Set<Block>} */
|
|
196
|
+
const doomed = new Set();
|
|
197
|
+
/** Blocks that outlive the cut, in document order, to re-home after `anchor`. @type {Block[]} */
|
|
198
|
+
const survivors = [];
|
|
199
|
+
let anchor = start;
|
|
200
|
+
/** Nested case: the outermost block of the end spine (below `start`) that has own text. @type {Block | null} */
|
|
201
|
+
let hybrid = null;
|
|
202
|
+
|
|
203
|
+
if (!nested) {
|
|
204
|
+
const siblings = childrenOf(nabu, lca);
|
|
205
|
+
const first = /** @type {Block} */ (startPath.at(-1));
|
|
206
|
+
const last = /** @type {Block} */ (endPath.at(-1));
|
|
207
|
+
const firstIndex = siblings.indexOf(first);
|
|
208
|
+
const lastIndex = siblings.indexOf(last);
|
|
209
|
+
if (firstIndex < 0 || lastIndex <= firstIndex) return null;
|
|
210
|
+
|
|
211
|
+
// Between the two spines.
|
|
212
|
+
siblings.slice(firstIndex + 1, lastIndex).forEach(block => doomed.add(block));
|
|
213
|
+
// After the start, inside the start spine (the start block's own children come right after its text).
|
|
214
|
+
for (const node of startPath) {
|
|
215
|
+
if (node === first) break;
|
|
216
|
+
const brothers = kidsOf(node.parent);
|
|
217
|
+
brothers.slice(brothers.indexOf(node) + 1).forEach(block => doomed.add(block));
|
|
143
218
|
}
|
|
219
|
+
kidsOf(start).forEach(block => doomed.add(block));
|
|
220
|
+
// Before the end, inside the end spine; what follows the end point survives.
|
|
221
|
+
endPath.forEach((node, i) => {
|
|
222
|
+
if (node !== last) {
|
|
223
|
+
const brothers = kidsOf(node.parent);
|
|
224
|
+
const at = brothers.indexOf(node);
|
|
225
|
+
brothers.slice(0, at).forEach(block => doomed.add(block));
|
|
226
|
+
survivors.push(...brothers.slice(at + 1));
|
|
227
|
+
}
|
|
228
|
+
if (i > 0) doomed.add(node);
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
for (let i = endPath.length - 1; i >= 1; i--) {
|
|
232
|
+
if (textOf(endPath[i])) { hybrid = endPath[i]; break; }
|
|
233
|
+
}
|
|
234
|
+
const hybridIndex = hybrid ? endPath.indexOf(hybrid) : -1;
|
|
235
|
+
endPath.forEach((node, i) => {
|
|
236
|
+
const brothers = kidsOf(node.parent);
|
|
237
|
+
const at = brothers.indexOf(node);
|
|
238
|
+
brothers.slice(0, at).forEach(block => doomed.add(block));
|
|
239
|
+
// Only what sits under a block that is removed has to move; the rest stays in place.
|
|
240
|
+
if (hybrid && i < hybridIndex) survivors.push(...brothers.slice(at + 1));
|
|
241
|
+
});
|
|
242
|
+
if (hybrid) { doomed.add(hybrid); anchor = hybrid; }
|
|
144
243
|
}
|
|
145
244
|
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
245
|
+
// ── Text: head of the start block + tail of the end block ──
|
|
246
|
+
if (startText) {
|
|
247
|
+
const length = startText.container.length;
|
|
248
|
+
if (length > startOffset) startText.delete({ from: startOffset, to: length });
|
|
249
|
+
}
|
|
250
|
+
if (endText && endOffset > 0) endText.delete({ from: 0, to: endOffset });
|
|
251
|
+
|
|
252
|
+
const absorbed = !!(startText && endText && start.absorbs(end));
|
|
253
|
+
const endChildren = [...kidsOf(end)];
|
|
254
|
+
if (absorbed || !endText) doomed.add(end);
|
|
255
|
+
else if (!nested) survivors.unshift(end); // could not be merged: it stays, right after the start
|
|
256
|
+
|
|
257
|
+
// The end block's children: adopted by the start block when it holds children, else promoted.
|
|
258
|
+
/** @type {any} */
|
|
259
|
+
const host = start;
|
|
260
|
+
const adopts = typeof host.adoptChildren === 'function';
|
|
261
|
+
let adoptAfterMoves = false;
|
|
262
|
+
if (endChildren.length && (absorbed || !endText)) {
|
|
263
|
+
if (nested && !hybrid) {
|
|
264
|
+
host.adoptChildren(endChildren, kidsOf(start).indexOf(/** @type {Block} */ (endPath.at(-1))));
|
|
265
|
+
} else if (!nested && !hybrid && adopts) {
|
|
266
|
+
adoptAfterMoves = true;
|
|
267
|
+
} else {
|
|
268
|
+
survivors.unshift(...endChildren);
|
|
157
269
|
}
|
|
158
270
|
}
|
|
159
271
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const startOfStartSpine = directChild(startSpine);
|
|
163
|
-
const startOfEndSpine = directChild(endSpine);
|
|
164
|
-
if (!startOfStartSpine || !startOfEndSpine) return false;
|
|
272
|
+
rehomeAfter(nabu, anchor, survivors);
|
|
273
|
+
if (adoptAfterMoves) host.adoptChildren(endChildren);
|
|
165
274
|
|
|
166
|
-
//
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (startBlock === endBlock) {
|
|
172
|
-
return startBlock.beforeinput(event);
|
|
275
|
+
// ── Destroy, outermost blocks only (a Loro delete takes the subtree along) ──
|
|
276
|
+
for (const block of doomed) {
|
|
277
|
+
let covered = false;
|
|
278
|
+
for (let p = block.parent ?? null; p; p = p.parent ?? null) if (doomed.has(p)) { covered = true; break; }
|
|
279
|
+
if (!covered && !block.node.isDeleted?.()) block.destroy();
|
|
173
280
|
}
|
|
174
281
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
endBlock.delete();
|
|
282
|
+
return { block: start, offset: startOffset };
|
|
283
|
+
}
|
|
178
284
|
|
|
179
|
-
|
|
285
|
+
// ── Isolated text fields (`Block#isolatesSelection`) ─────────────────────────
|
|
180
286
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
} else if (inputType === 'insertParagraph') {
|
|
184
|
-
const { block: newBlock } = startBlock.split({ offset: focusData.options.startOffset }) || {};
|
|
185
|
-
if (newBlock) focusBlock = newBlock;
|
|
186
|
-
} else if (inputType === 'insertText' || inputType === 'insertLineBreak') {
|
|
187
|
-
const text = event.data || (inputType === 'insertLineBreak' ? '\n' : '');
|
|
188
|
-
startBlock.insert(focusData.options.startOffset, text);
|
|
189
|
-
} else {
|
|
190
|
-
nabu.warn('Unhandled input type in container:', inputType);
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
287
|
+
/** Whether `block` holds text. @param {Block} block */
|
|
288
|
+
const hasTextBehavior = (block) => !!block.behaviors?.has('text');
|
|
193
289
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
if (startOfEndSpine === startOfStartSpine) {
|
|
216
|
-
if (startOfStartSpine instanceof MegaBlock) {
|
|
217
|
-
startOfStartSpine.children.filter(c => c.selected).forEach(c => toDestroy.add(c));
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (startOfEndSpine !== startOfStartSpine) {
|
|
222
|
-
startOfEndSpine?.destroy();
|
|
223
|
-
if (startOfStartSpine !== startBlock && startBlock instanceof MegaBlock) {
|
|
224
|
-
startBlock.children.forEach(child => child.destroy());
|
|
290
|
+
/**
|
|
291
|
+
* The text blocks of the document in document order (a block's own text before its children). With `visible`, the children of
|
|
292
|
+
* a block that hides them are skipped (they are not rendered: no caret, no DOM point).
|
|
293
|
+
* @param {Nabu} nabu
|
|
294
|
+
* @param {{ visible?: boolean }} [options]
|
|
295
|
+
* @returns {Block[]}
|
|
296
|
+
*/
|
|
297
|
+
export function textBlocksInOrder(nabu, { visible = false } = {}) {
|
|
298
|
+
/** @type {Block[]} */
|
|
299
|
+
const out = [];
|
|
300
|
+
/** @param {Block[]} blocks */
|
|
301
|
+
const walk = (blocks) => {
|
|
302
|
+
for (const block of blocks) {
|
|
303
|
+
if (hasTextBehavior(block)) out.push(block);
|
|
304
|
+
const kids = kidsOf(block);
|
|
305
|
+
if (kids.length && !(visible && block.hidesChildren)) walk(kids);
|
|
225
306
|
}
|
|
226
|
-
}
|
|
307
|
+
};
|
|
308
|
+
walk(/** @type {Block[]} */ (nabu.children));
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
227
311
|
|
|
228
|
-
|
|
312
|
+
/**
|
|
313
|
+
* The ISOLATION OWNER of a block: its nearest ancestor that isolates its text (`Block#isolatesSelection`), or null. Two text
|
|
314
|
+
* blocks with different owners (the body of a chapter and the body of a scene inside it) never merge by a range deletion.
|
|
315
|
+
* @param {Block} block
|
|
316
|
+
* @returns {Block | null}
|
|
317
|
+
*/
|
|
318
|
+
export function isolationOwnerOf(block) {
|
|
319
|
+
for (let cur = block.parent ?? null; cur; cur = cur.parent ?? null) if (cur.isolatesSelection) return cur;
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
229
322
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
323
|
+
/**
|
|
324
|
+
* Splits a range into the RUNS that a deletion may act on (ADR 018 §3.9): maximal sequences of consecutive text blocks, in
|
|
325
|
+
* document order, that do not contain an isolated block and share one isolation owner. The text of an isolated block is
|
|
326
|
+
* outside every run (a range starting or ending in it starts after it / ends before it), and a run boundary is never merged
|
|
327
|
+
* across. A document without isolated blocks gives a single run, the range itself.
|
|
328
|
+
* @param {Nabu} nabu
|
|
329
|
+
* @param {DeletionRange} range
|
|
330
|
+
* @returns {DeletionRange[] | null} the runs in document order (possibly empty), or null when the range cannot be placed in the document
|
|
331
|
+
*/
|
|
332
|
+
export function isolatedRuns(nabu, range) {
|
|
333
|
+
const { startBlock, endBlock } = range;
|
|
334
|
+
const order = textBlocksInOrder(nabu);
|
|
335
|
+
const first = order.indexOf(startBlock);
|
|
336
|
+
const last = order.indexOf(endBlock);
|
|
337
|
+
if (first < 0 || last < first) return null;
|
|
338
|
+
|
|
339
|
+
/** @type {Block[][]} */
|
|
340
|
+
const groups = [];
|
|
341
|
+
/** @type {Block[] | null} */
|
|
342
|
+
let current = null;
|
|
343
|
+
let owner = /** @type {Block | null} */ (null);
|
|
344
|
+
for (const block of order.slice(first, last + 1)) {
|
|
345
|
+
if (block.isolatesSelection) { current = null; continue; }
|
|
346
|
+
const blockOwner = isolationOwnerOf(block);
|
|
347
|
+
if (!current || blockOwner !== owner) { current = []; owner = blockOwner; groups.push(current); }
|
|
348
|
+
current.push(block);
|
|
349
|
+
}
|
|
350
|
+
return groups.map((blocks) => {
|
|
351
|
+
const head = /** @type {Block} */ (blocks[0]);
|
|
352
|
+
const tail = /** @type {Block} */ (blocks.at(-1));
|
|
353
|
+
return {
|
|
354
|
+
startBlock: head,
|
|
355
|
+
startOffset: head === startBlock ? range.startOffset : 0,
|
|
356
|
+
endBlock: tail,
|
|
357
|
+
endOffset: tail === endBlock ? range.endOffset : (textOf(tail)?.container.length ?? 0),
|
|
358
|
+
};
|
|
233
359
|
});
|
|
234
|
-
return true;
|
|
235
360
|
}
|
|
236
361
|
|
|
237
362
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* Returns the resulting insertion position {block, offset}, or null on failure.
|
|
363
|
+
* THE one implementation of "delete the selected range across blocks" (cut, Backspace / Delete, typing over a
|
|
364
|
+
* selection, paste over a selection, move by drag). Mutates the Loro tree and texts, never commits.
|
|
241
365
|
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
366
|
+
* A range that crosses ISOLATED text (`Block#isolatesSelection`, e.g. the title of a region) acts on its {@link isolatedRuns}
|
|
367
|
+
* only: the text of an isolated block is never touched, an isolated block and its container are never deleted, and the runs
|
|
368
|
+
* are never merged with one another (each one is deleted like a range of its own, the LAST run first so that the earlier
|
|
369
|
+
* ones are not disturbed). What is left is the first block of every run, emptied: that is where a caret still has a home.
|
|
370
|
+
* Without isolated block in the range it is exactly {@link deleteRangeRaw}.
|
|
371
|
+
*
|
|
372
|
+
* @param {Nabu} nabu
|
|
373
|
+
* @param {DeletionRange} range
|
|
374
|
+
* @returns {{ block: Block, offset: number } | null} the junction (where the caret belongs: the start of the first run), or null if the range is unusable or holds no deletable text
|
|
245
375
|
*/
|
|
246
|
-
export function
|
|
247
|
-
|
|
248
|
-
const
|
|
376
|
+
export function deleteRange(nabu, range) {
|
|
377
|
+
if (range.startBlock === range.endBlock) return deleteRangeRaw(nabu, range);
|
|
378
|
+
const runs = isolatedRuns(nabu, range);
|
|
379
|
+
if (!runs) return deleteRangeRaw(nabu, range);
|
|
380
|
+
if (runs.length === 1 && runs[0].startBlock === range.startBlock && runs[0].endBlock === range.endBlock) return deleteRangeRaw(nabu, range);
|
|
381
|
+
if (!runs.length) return null;
|
|
382
|
+
for (let i = runs.length - 1; i >= 0; i--) {
|
|
383
|
+
const run = /** @type {DeletionRange} */ (runs[i]);
|
|
384
|
+
const empty = run.startBlock === run.endBlock && run.endOffset <= run.startOffset;
|
|
385
|
+
if (!empty) deleteRangeRaw(nabu, run);
|
|
386
|
+
}
|
|
387
|
+
const head = /** @type {DeletionRange} */ (runs[0]);
|
|
388
|
+
return { block: head.startBlock, offset: head.startOffset };
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* The current selection as a {@link DeletionRange}, or null when there is none.
|
|
393
|
+
* A selection inside one block has `startBlock === endBlock`.
|
|
394
|
+
* @param {Nabu} nabu
|
|
395
|
+
* @returns {DeletionRange | null}
|
|
396
|
+
*/
|
|
397
|
+
export function selectionRange(nabu) {
|
|
398
|
+
const startBlock = /** @type {Block | null} */ (nabu.selection.startBlock);
|
|
399
|
+
const endBlock = /** @type {Block | null} */ (nabu.selection.endBlock);
|
|
249
400
|
if (!startBlock || !endBlock) return null;
|
|
401
|
+
const startSel = /** @type {any} */ (startBlock.selection);
|
|
402
|
+
const startOffset = startSel?.from ?? 0;
|
|
403
|
+
if (startBlock === endBlock) return { startBlock, startOffset, endBlock, endOffset: startSel?.to ?? startOffset };
|
|
404
|
+
const endSel = /** @type {any} */ (endBlock.selection);
|
|
405
|
+
return { startBlock, startOffset, endBlock, endOffset: endSel?.to ?? 0 };
|
|
406
|
+
}
|
|
250
407
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
408
|
+
/**
|
|
409
|
+
* Shared beforeinput logic for block containers (Nabu root and MegaBlock) when the selection spans SEVERAL
|
|
410
|
+
* blocks (a selection inside one block is that block's business). Backspace / Delete / word deletions delete the
|
|
411
|
+
* range; typing replaces it; Enter replaces it and splits at the junction. All of it is {@link deleteRange}
|
|
412
|
+
* followed by the plain single-block edit at the junction, then ONE commit (one undo step).
|
|
413
|
+
*
|
|
414
|
+
* The `container` (the lowest common ancestor the event was routed to) is not needed any more: the range is
|
|
415
|
+
* resolved from the selection alone, which also makes the same code correct for every depth.
|
|
416
|
+
*
|
|
417
|
+
* @param {{ children: Block[], commit: () => void }} container
|
|
418
|
+
* @param {Nabu} nabu
|
|
419
|
+
* @param {InputEvent} event
|
|
420
|
+
*/
|
|
421
|
+
export function handleContainerBeforeInput(container, nabu, event) {
|
|
422
|
+
const range = selectionRange(nabu);
|
|
423
|
+
if (!range) return false;
|
|
259
424
|
|
|
260
|
-
//
|
|
261
|
-
|
|
425
|
+
// Single-block selection: delegate directly to that block.
|
|
426
|
+
if (range.startBlock === range.endBlock) return range.startBlock.beforeinput(event);
|
|
262
427
|
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
428
|
+
const inputType = event.inputType;
|
|
429
|
+
const typed = inputType === 'insertText' ? (event.data || '')
|
|
430
|
+
: (inputType === 'insertReplacementText' || inputType === 'insertFromYank') ? (event.data || event.dataTransfer?.getData?.('text/plain') || '')
|
|
431
|
+
: (inputType === 'insertLineBreak' || inputType === 'insertSoftLineBreak') ? '\n'
|
|
432
|
+
: null;
|
|
433
|
+
const isDeletion = inputType.startsWith('delete');
|
|
434
|
+
const isParagraph = inputType === 'insertParagraph';
|
|
435
|
+
if (!isDeletion && !isParagraph && typed === null) {
|
|
436
|
+
if (inputType.startsWith('history')) return true; // undo / redo go through the keydown handler
|
|
437
|
+
if (inputType.startsWith('format') || inputType === 'insertTranspose') return true; // formatting: extension hooks; transpose: meaningless across blocks
|
|
438
|
+
nabu.warn('Unhandled input type in container:', inputType);
|
|
439
|
+
return false;
|
|
273
440
|
}
|
|
274
441
|
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
442
|
+
const junction = deleteRange(nabu, range);
|
|
443
|
+
if (!junction) return false;
|
|
444
|
+
const { block } = junction;
|
|
445
|
+
let { offset } = junction;
|
|
446
|
+
|
|
447
|
+
if (typed !== null) {
|
|
448
|
+
block.insert(offset, typed);
|
|
449
|
+
offset += typed.length;
|
|
450
|
+
} else if (isParagraph) {
|
|
451
|
+
const text = textOf(block);
|
|
452
|
+
const split = block.split({ offset, to: text ? text.container.length : offset });
|
|
453
|
+
if (split?.block) {
|
|
454
|
+
// The split commits the whole operation (deletion included) and puts the caret in the new block.
|
|
455
|
+
nabu.commit();
|
|
456
|
+
return true;
|
|
284
457
|
}
|
|
285
458
|
}
|
|
286
459
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (!startOfStartSpine || !startOfEndSpine) return null;
|
|
291
|
-
|
|
292
|
-
const intermediates = container.children.slice(startOfStartSpine.index + 1, startOfEndSpine.index);
|
|
293
|
-
intermediates.forEach(block => block.destroy());
|
|
294
|
-
|
|
295
|
-
startBlock.delete();
|
|
296
|
-
endBlock.delete();
|
|
297
|
-
startBlock.consume(endBlock);
|
|
298
|
-
|
|
299
|
-
endSpine.forEach(block => {
|
|
300
|
-
if (block === container) return;
|
|
301
|
-
const brotherhood = block.parent?.children || [];
|
|
302
|
-
const index = brotherhood.indexOf(block);
|
|
303
|
-
if (index !== -1) {
|
|
304
|
-
const nextSiblings = brotherhood.slice(index + 1);
|
|
305
|
-
if (nextSiblings.length) {
|
|
306
|
-
[...nextSiblings].reverse().forEach(sibling => {
|
|
307
|
-
sibling.node.moveAfter(startBlock.node);
|
|
308
|
-
wrapOrphan(nabu, sibling);
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
startOfEndSpine?.destroy();
|
|
460
|
+
nabu.commit().then(() => nabu.selection.setCursor(nabu.blocks.get(block.id) ?? block, offset));
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
315
463
|
|
|
316
|
-
|
|
464
|
+
/**
|
|
465
|
+
* Deletes the current selection content without committing (cut, paste over a selection).
|
|
466
|
+
* Handles both single-block and multi-block selections — see {@link deleteRange}.
|
|
467
|
+
* Returns the resulting insertion position {block, offset}, or null on failure.
|
|
468
|
+
*
|
|
469
|
+
* @param {{ children: import('./block.svelte.js').Block[] }} container (unused: the range comes from the selection)
|
|
470
|
+
* @param {import('./nabu.svelte.js').Nabu} nabu
|
|
471
|
+
* @returns {{ block: import('./block.svelte.js').Block, offset: number } | null}
|
|
472
|
+
*/
|
|
473
|
+
export function deleteSelectionContent(container, nabu) {
|
|
474
|
+
const range = selectionRange(nabu);
|
|
475
|
+
if (!range) return null;
|
|
476
|
+
return deleteRange(nabu, range);
|
|
317
477
|
}
|
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
import RichText from '../../behaviors/text/RichText.svelte';
|
|
3
3
|
/** @type {{block: import('./dialogue.svelte.js').Dialogue}}*/
|
|
4
4
|
let {block} = $props();
|
|
5
|
+
|
|
6
|
+
/** The configured dash as a CSS string (`"–"`): fed to the `::before` below. */
|
|
7
|
+
const dashCss = $derived(JSON.stringify(String(block.dash).replace(/[\n\r]/g, ' ')));
|
|
5
8
|
</script>
|
|
6
9
|
|
|
7
10
|
<div
|
|
8
11
|
bind:this={block.element}
|
|
9
12
|
data-block-id={block.id}
|
|
10
13
|
data-block-type="dialogue"
|
|
14
|
+
data-placeholder={block.placeholder}
|
|
11
15
|
class="nabu-dialogue"
|
|
16
|
+
style:--nb-dialogue-dash-configured={dashCss}
|
|
12
17
|
class:debug={block.nabu.debugging}
|
|
13
18
|
class:selected={block.selected}
|
|
14
19
|
class:first={block.isSelectionStart}
|
|
@@ -24,8 +29,9 @@
|
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
.nabu-dialogue::before {
|
|
27
|
-
/*
|
|
28
|
-
|
|
32
|
+
/* `--nb-dialogue-dash` is the host override (any ancestor / rule); the configured dash
|
|
33
|
+
(createDialogueExtension({ dash })) is the fallback. */
|
|
34
|
+
content: var(--nb-dialogue-dash, var(--nb-dialogue-dash-configured, "–"));
|
|
29
35
|
position: absolute;
|
|
30
36
|
left: 0;
|
|
31
37
|
user-select: none;
|