@aionbuilders/nabu 0.1.0-alpha.8 → 0.1.0-beta.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/README.md +216 -9
- package/dist/behaviors/text/RichText.svelte +4 -1
- 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 +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +54 -0
- package/dist/behaviors/text/rich-text.extension.js +47 -22
- package/dist/behaviors/text/text.behavior.svelte.d.ts +25 -1
- package/dist/behaviors/text/text.behavior.svelte.js +154 -18
- package/dist/behaviors/text/typography.extension.d.ts +6 -0
- package/dist/behaviors/text/typography.extension.js +24 -0
- package/dist/blocks/Block.svelte +5 -2
- package/dist/blocks/BlockGap.svelte +55 -0
- package/dist/blocks/BlockGap.svelte.d.ts +11 -0
- package/dist/blocks/Nabu.svelte +22 -0
- package/dist/blocks/block.extension.js +10 -8
- package/dist/blocks/block.svelte.d.ts +24 -0
- package/dist/blocks/block.svelte.js +35 -0
- package/dist/blocks/blockquote/Blockquote.svelte +40 -0
- package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
- package/dist/blocks/blockquote/blockquote.extension.d.ts +1 -0
- package/dist/blocks/blockquote/blockquote.extension.js +71 -0
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +55 -0
- package/dist/blocks/blockquote/blockquote.svelte.js +91 -0
- package/dist/blocks/blockquote/index.d.ts +3 -0
- package/dist/blocks/blockquote/index.js +3 -0
- package/dist/blocks/callout/Callout.svelte +69 -0
- package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
- package/dist/blocks/callout/callout.extension.d.ts +1 -0
- package/dist/blocks/callout/callout.extension.js +68 -0
- package/dist/blocks/callout/callout.svelte.d.ts +78 -0
- package/dist/blocks/callout/callout.svelte.js +184 -0
- package/dist/blocks/callout/index.d.ts +3 -0
- package/dist/blocks/callout/index.js +3 -0
- package/dist/blocks/code/Code.svelte +85 -0
- package/dist/blocks/code/Code.svelte.d.ts +11 -0
- package/dist/blocks/code/code.extension.d.ts +1 -0
- package/dist/blocks/code/code.extension.js +68 -0
- package/dist/blocks/code/code.svelte.d.ts +61 -0
- package/dist/blocks/code/code.svelte.js +221 -0
- package/dist/blocks/code/index.d.ts +3 -0
- package/dist/blocks/code/index.js +3 -0
- package/dist/blocks/dialogue/Dialogue.svelte +2 -0
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +3 -21
- package/dist/blocks/dialogue/dialogue.svelte.js +2 -50
- 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 +1 -0
- package/dist/blocks/divider/divider.extension.js +87 -0
- package/dist/blocks/divider/divider.svelte.d.ts +49 -0
- package/dist/blocks/divider/divider.svelte.js +84 -0
- package/dist/blocks/divider/index.d.ts +3 -0
- package/dist/blocks/divider/index.js +3 -0
- package/dist/blocks/file/File.svelte +49 -0
- package/dist/blocks/file/File.svelte.d.ts +11 -0
- package/dist/blocks/file/file.extension.d.ts +1 -0
- package/dist/blocks/file/file.extension.js +19 -0
- package/dist/blocks/file/file.svelte.d.ts +29 -0
- package/dist/blocks/file/file.svelte.js +71 -0
- package/dist/blocks/file/index.d.ts +3 -0
- package/dist/blocks/file/index.js +3 -0
- package/dist/blocks/heading/Heading.svelte +3 -1
- package/dist/blocks/heading/heading.svelte.d.ts +4 -23
- package/dist/blocks/heading/heading.svelte.js +4 -47
- package/dist/blocks/image/Image.svelte +38 -0
- package/dist/blocks/image/Image.svelte.d.ts +11 -0
- package/dist/blocks/image/image.extension.d.ts +2 -0
- package/dist/blocks/image/image.extension.js +26 -0
- package/dist/blocks/image/image.svelte.d.ts +50 -0
- package/dist/blocks/image/image.svelte.js +92 -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 -0
- package/dist/blocks/index.js +11 -0
- package/dist/blocks/list/List.svelte +8 -2
- package/dist/blocks/list/ListItem.svelte +43 -7
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +15 -2
- package/dist/blocks/list/index.d.ts +1 -0
- package/dist/blocks/list/index.js +1 -0
- package/dist/blocks/list/list-item.svelte.d.ts +14 -2
- package/dist/blocks/list/list-item.svelte.js +58 -7
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -4
- package/dist/blocks/list/list.behavior.svelte.js +5 -5
- package/dist/blocks/list/list.svelte.d.ts +13 -6
- package/dist/blocks/list/list.svelte.js +24 -6
- 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/media-block.svelte.d.ts +32 -0
- package/dist/blocks/media/media-block.svelte.js +69 -0
- package/dist/blocks/media/media.helpers.d.ts +19 -0
- package/dist/blocks/media/media.helpers.js +51 -0
- package/dist/blocks/megablock.svelte.js +1 -0
- package/dist/blocks/nabu.svelte.d.ts +94 -16
- package/dist/blocks/nabu.svelte.js +254 -3
- package/dist/blocks/paragraph/Paragraph.svelte +2 -0
- package/dist/blocks/paragraph/index.js +8 -3
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +3 -21
- package/dist/blocks/paragraph/paragraph.svelte.js +4 -53
- package/dist/blocks/selection.svelte.d.ts +1 -0
- package/dist/blocks/selection.svelte.js +212 -16
- package/dist/blocks/text-block.svelte.d.ts +49 -0
- package/dist/blocks/text-block.svelte.js +74 -0
- package/dist/blocks/toggle/Toggle.svelte +84 -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/toggle.extension.d.ts +1 -0
- package/dist/blocks/toggle/toggle.extension.js +12 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +88 -0
- package/dist/blocks/toggle/toggle.svelte.js +252 -0
- package/dist/blocks/variable.svelte.d.ts +47 -0
- package/dist/blocks/variable.svelte.js +51 -0
- package/dist/blocks/video/Video.svelte +39 -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 +1 -0
- package/dist/blocks/video/video.extension.js +19 -0
- package/dist/blocks/video/video.svelte.d.ts +28 -0
- package/dist/blocks/video/video.svelte.js +71 -0
- package/dist/blocks/zone/TemplateEditor.svelte +308 -0
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/Zone.svelte +272 -0
- package/dist/blocks/zone/Zone.svelte.d.ts +11 -0
- package/dist/blocks/zone/ZoneEditor.svelte +289 -0
- package/dist/blocks/zone/ZoneEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte +188 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +11 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.js +30 -0
- package/dist/blocks/zone/index.d.ts +2 -0
- package/dist/blocks/zone/index.js +2 -0
- package/dist/blocks/zone/zone.extension.d.ts +2 -0
- package/dist/blocks/zone/zone.extension.js +237 -0
- package/dist/blocks/zone/zone.svelte.d.ts +221 -0
- package/dist/blocks/zone/zone.svelte.js +608 -0
- package/dist/files/files.svelte.d.ts +61 -0
- package/dist/files/files.svelte.js +93 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/nabu-theme.css +92 -0
- package/dist/overlays/context/Context.svelte +182 -0
- package/dist/overlays/context/Context.svelte.d.ts +17 -0
- package/dist/overlays/context/collect.d.ts +17 -0
- package/dist/overlays/context/collect.js +33 -0
- package/dist/overlays/context/context.extension.d.ts +2 -0
- package/dist/overlays/context/context.extension.js +8 -0
- package/dist/overlays/context/context.svelte.d.ts +82 -0
- package/dist/overlays/context/context.svelte.js +159 -0
- package/dist/overlays/context/index.d.ts +3 -0
- package/dist/overlays/context/index.js +3 -0
- package/dist/paste/html.paste.js +9 -1
- package/dist/presets.d.ts +3 -1
- package/dist/presets.js +22 -6
- package/dist/ui/DragHandle.svelte +141 -0
- package/dist/ui/DragHandle.svelte.d.ts +11 -0
- package/dist/ui/FloatingToolbar.svelte +117 -0
- package/dist/ui/FloatingToolbar.svelte.d.ts +17 -0
- package/dist/ui/SlashMenu.svelte +83 -0
- package/dist/ui/SlashMenu.svelte.d.ts +13 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/slash-menu.svelte.d.ts +40 -0
- package/dist/ui/slash-menu.svelte.js +116 -0
- package/dist/utils/extensions.d.ts +54 -0
- package/dist/utils/extensions.js +40 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/placeholders.d.ts +10 -0
- package/dist/utils/placeholders.js +21 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +23 -0
- package/package.json +10 -5
|
@@ -15,25 +15,111 @@ export class NabuSelection extends SvelteSelection {
|
|
|
15
15
|
|
|
16
16
|
$effect.root(() => {
|
|
17
17
|
$effect(() => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
if (this.blocks) {
|
|
19
|
+
this.previous.forEach(block => block.clearSelection());
|
|
20
|
+
let i = 0;
|
|
21
|
+
const lastIndex = this.blocks.size - 1;
|
|
22
|
+
this.blocks.forEach((block) => {
|
|
23
|
+
block.selected = true;
|
|
24
|
+
block.isSelectionStart = (i === 0);
|
|
25
|
+
block.isSelectionEnd = i === lastIndex;
|
|
26
|
+
i++;
|
|
27
|
+
});
|
|
28
|
+
this.previous = new Set(this.blocks);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
// Track the intended navigation direction from arrow key presses.
|
|
33
|
+
// This is the only reliable source of direction — DOM position comparisons
|
|
34
|
+
// break when anchorNode is an ancestor of the previous position.
|
|
35
|
+
$effect(() => {
|
|
36
|
+
/** @param {KeyboardEvent} e */
|
|
37
|
+
const onKeydown = (e) => {
|
|
38
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
|
|
39
|
+
this.#pendingDirection = 'forward';
|
|
40
|
+
this.nabu.storedMarks = null;
|
|
41
|
+
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
|
|
42
|
+
this.#pendingDirection = 'backward';
|
|
43
|
+
this.nabu.storedMarks = null;
|
|
44
|
+
} else {
|
|
45
|
+
this.#pendingDirection = null;
|
|
46
|
+
if (e.key === 'Home' || e.key === 'End' || e.key === 'PageUp' || e.key === 'PageDown') {
|
|
47
|
+
this.nabu.storedMarks = null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const onMousedown = () => { this.nabu.storedMarks = null; };
|
|
52
|
+
document.addEventListener('keydown', onKeydown, true);
|
|
53
|
+
document.addEventListener('mousedown', onMousedown, true);
|
|
54
|
+
return () => {
|
|
55
|
+
document.removeEventListener('keydown', onKeydown, true);
|
|
56
|
+
document.removeEventListener('mousedown', onMousedown, true);
|
|
57
|
+
};
|
|
58
|
+
});
|
|
33
59
|
|
|
34
|
-
|
|
60
|
+
// Normalize invalid caret/focus positions: inert elements and element-node
|
|
61
|
+
// cursors (which happen in container padding / between block children).
|
|
62
|
+
// Works for both collapsed cursors and non-collapsed selections (shift+arrow):
|
|
63
|
+
// - anchor invalid → collapse to corrected anchor
|
|
64
|
+
// - only focus invalid → keep anchor, correct only focus (preserves the selection)
|
|
65
|
+
$effect(() => {
|
|
66
|
+
const activeEl = document.activeElement;
|
|
67
|
+
if (activeEl && activeEl.closest?.('[data-nabu-ui], input, textarea, select, button')) {
|
|
68
|
+
this.#pendingDirection = null;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const anchor = this.anchorNode;
|
|
73
|
+
const anchorOffset = this.anchorOffset;
|
|
74
|
+
const focus = this.focusNode;
|
|
75
|
+
const focusOffset = this.focusOffset;
|
|
76
|
+
if (!anchor) return;
|
|
77
|
+
|
|
78
|
+
const anchorEl = /** @type {Element | null} */ (anchor.nodeType === Node.ELEMENT_NODE ? anchor : anchor.parentElement);
|
|
79
|
+
const focusEl = /** @type {Element | null} */ (focus?.nodeType === Node.ELEMENT_NODE ? focus : focus?.parentElement);
|
|
80
|
+
|
|
81
|
+
// Skip normalization when the selection touches a UI element (e.g. zone title input).
|
|
82
|
+
if (anchorEl?.closest('[data-nabu-ui]') || focusEl?.closest('[data-nabu-ui]')) {
|
|
83
|
+
this.#pendingDirection = null;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const anchorInvalid = isInInert(anchor) || (
|
|
88
|
+
anchor.nodeType !== Node.TEXT_NODE &&
|
|
89
|
+
!!/** @type {Element} */ (anchor).closest?.('[data-block-id]')
|
|
90
|
+
);
|
|
91
|
+
const focusInvalid = !!focus && (isInInert(focus) || (
|
|
92
|
+
focus.nodeType !== Node.TEXT_NODE &&
|
|
93
|
+
!!/** @type {Element} */ (focus).closest?.('[data-block-id]')
|
|
94
|
+
));
|
|
95
|
+
|
|
96
|
+
if (!anchorInvalid && !focusInvalid) {
|
|
97
|
+
this.#pendingDirection = null;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (anchorInvalid) {
|
|
102
|
+
const dir = this.#pendingDirection ?? offsetHeuristic(anchor, anchorOffset);
|
|
103
|
+
this.#pendingDirection = null;
|
|
104
|
+
const target = findNearestTextNode(anchor, anchorOffset, dir);
|
|
105
|
+
if (!target) return;
|
|
106
|
+
const offset = dir === 'forward' ? 0 : (target.textContent?.length ?? 0);
|
|
107
|
+
this.setBaseAndExtent(target, offset, target, offset);
|
|
108
|
+
} else if (focusInvalid && focus) {
|
|
109
|
+
const dir = this.#pendingDirection ?? offsetHeuristic(focus, focusOffset);
|
|
110
|
+
this.#pendingDirection = null;
|
|
111
|
+
const target = findNearestTextNode(focus, focusOffset, dir);
|
|
112
|
+
if (!target) return;
|
|
113
|
+
const offset = dir === 'forward' ? 0 : (target.textContent?.length ?? 0);
|
|
114
|
+
this.setBaseAndExtent(anchor, anchorOffset, target, offset);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
35
118
|
}
|
|
36
|
-
|
|
119
|
+
|
|
120
|
+
/** @type {'forward' | 'backward' | null} */
|
|
121
|
+
#pendingDirection = null;
|
|
122
|
+
|
|
37
123
|
anchorBlock = $derived.by(() => {
|
|
38
124
|
this.anchorNode;
|
|
39
125
|
const id = this.anchorNode?.parentElement?.closest("[data-block-id]")?.getAttribute("data-block-id");
|
|
@@ -95,6 +181,116 @@ export class NabuSelection extends SvelteSelection {
|
|
|
95
181
|
|
|
96
182
|
|
|
97
183
|
|
|
184
|
+
/** @param {Node | null} node */
|
|
185
|
+
function isInInert(node) {
|
|
186
|
+
if (!node) return false;
|
|
187
|
+
const el = node.nodeType === Node.ELEMENT_NODE
|
|
188
|
+
? /** @type {Element} */ (node)
|
|
189
|
+
: node.parentElement;
|
|
190
|
+
return !!el?.closest('[data-nabu-inert]');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Heuristic for mouse clicks: infer direction from where in the element the
|
|
195
|
+
* cursor landed. At/past the last child → user likely moving forward; otherwise
|
|
196
|
+
* backward.
|
|
197
|
+
* @param {Node} anchor
|
|
198
|
+
* @param {number} anchorOffset
|
|
199
|
+
* @returns {'forward' | 'backward'}
|
|
200
|
+
*/
|
|
201
|
+
function offsetHeuristic(anchor, anchorOffset) {
|
|
202
|
+
if (anchor.nodeType !== Node.TEXT_NODE) {
|
|
203
|
+
return anchorOffset >= anchor.childNodes.length ? 'forward' : 'backward';
|
|
204
|
+
}
|
|
205
|
+
return 'backward';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** @type {NodeFilter} */
|
|
209
|
+
const TEXT_FILTER = {
|
|
210
|
+
acceptNode(/** @type {Node} */ node) {
|
|
211
|
+
if (isInInert(node)) return NodeFilter.FILTER_REJECT;
|
|
212
|
+
if (!/** @type {Text} */ (node).parentElement?.closest('[data-block-id]')) return NodeFilter.FILTER_REJECT;
|
|
213
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Returns the deepest last descendant of a node (for positioning a TreeWalker
|
|
219
|
+
* so that nextNode() starts at the node immediately after the subtree).
|
|
220
|
+
* @param {Node} node
|
|
221
|
+
*/
|
|
222
|
+
function getLastDescendant(node) {
|
|
223
|
+
let n = node;
|
|
224
|
+
while (n.lastChild) n = n.lastChild;
|
|
225
|
+
return n;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Find the nearest valid (non-inert, inside a block) text node from a given
|
|
230
|
+
* DOM position, respecting the intended navigation direction.
|
|
231
|
+
*
|
|
232
|
+
* For element-node cursors, (fromNode, fromOffset) means the caret sits between
|
|
233
|
+
* child[fromOffset-1] and child[fromOffset]. We use fromOffset to start the
|
|
234
|
+
* search at the right position — NOT from the beginning/end of the element —
|
|
235
|
+
* so we never jump back to a position the user is trying to leave.
|
|
236
|
+
*
|
|
237
|
+
* @param {Node} fromNode
|
|
238
|
+
* @param {number} fromOffset
|
|
239
|
+
* @param {'forward' | 'backward'} direction
|
|
240
|
+
* @returns {Text | null}
|
|
241
|
+
*/
|
|
242
|
+
function findNearestTextNode(fromNode, fromOffset, direction) {
|
|
243
|
+
// @ts-ignore — TreeWalker filter shape is correct, TS typedef is overly strict
|
|
244
|
+
const bodyWalker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, TEXT_FILTER);
|
|
245
|
+
|
|
246
|
+
if (fromNode.nodeType === Node.TEXT_NODE) {
|
|
247
|
+
bodyWalker.currentNode = fromNode;
|
|
248
|
+
return /** @type {Text | null} */ (
|
|
249
|
+
direction === 'backward' ? bodyWalker.previousNode() : bodyWalker.nextNode()
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Element-node cursor: caret is between child[fromOffset-1] and child[fromOffset].
|
|
254
|
+
const childCount = fromNode.childNodes.length;
|
|
255
|
+
|
|
256
|
+
if (direction === 'backward') {
|
|
257
|
+
if (fromOffset === 0) {
|
|
258
|
+
// Before all children → escape before element
|
|
259
|
+
bodyWalker.currentNode = fromNode;
|
|
260
|
+
return /** @type {Text | null} */ (bodyWalker.previousNode());
|
|
261
|
+
}
|
|
262
|
+
if (fromOffset < childCount) {
|
|
263
|
+
// Between child[fromOffset-1] and child[fromOffset]:
|
|
264
|
+
// last valid text before child[fromOffset] (may be inside or before element)
|
|
265
|
+
bodyWalker.currentNode = fromNode.childNodes[fromOffset];
|
|
266
|
+
return /** @type {Text | null} */ (bodyWalker.previousNode());
|
|
267
|
+
}
|
|
268
|
+
// Past last child → last valid text inside the element (sub-walker), or before it
|
|
269
|
+
// @ts-ignore
|
|
270
|
+
const sub = document.createTreeWalker(fromNode, NodeFilter.SHOW_TEXT, TEXT_FILTER);
|
|
271
|
+
let last = null, n;
|
|
272
|
+
while ((n = sub.nextNode())) last = n;
|
|
273
|
+
if (last) return /** @type {Text} */ (last);
|
|
274
|
+
bodyWalker.currentNode = fromNode;
|
|
275
|
+
return /** @type {Text | null} */ (bodyWalker.previousNode());
|
|
276
|
+
} else {
|
|
277
|
+
if (fromOffset >= childCount) {
|
|
278
|
+
// Past last child → escape after element
|
|
279
|
+
bodyWalker.currentNode = getLastDescendant(fromNode);
|
|
280
|
+
return /** @type {Text | null} */ (bodyWalker.nextNode());
|
|
281
|
+
}
|
|
282
|
+
// Between child[fromOffset-1] and child[fromOffset]:
|
|
283
|
+
// first valid text at or after child[fromOffset] (may be inside or after element).
|
|
284
|
+
// Pivot to the last descendant of child[fromOffset-1] so nextNode() starts
|
|
285
|
+
// from child[fromOffset] onward — never re-entering already-visited content.
|
|
286
|
+
const pivot = fromOffset > 0
|
|
287
|
+
? getLastDescendant(fromNode.childNodes[fromOffset - 1])
|
|
288
|
+
: fromNode;
|
|
289
|
+
bodyWalker.currentNode = pivot;
|
|
290
|
+
return /** @type {Text | null} */ (bodyWalker.nextNode());
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
98
294
|
/**
|
|
99
295
|
* Récupère tous les nœuds situés entre deux nœuds dans un arbre Loro (version aplatie).
|
|
100
296
|
* L'ordre dans lequel on passe A et B n'a pas d'importance.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "./nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{text: LoroText}>} TextBlockNode
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base class for purely textual blocks (paragraph, heading, dialogue…).
|
|
9
|
+
* Owns a single TextBehavior and proxies the standard Block text API to it,
|
|
10
|
+
* removing the proxy boilerplate previously duplicated in every text block.
|
|
11
|
+
*
|
|
12
|
+
* Hybrid blocks (MegaBlock + TextBehavior, like ListItem) must NOT extend
|
|
13
|
+
* this class — their children/positions logic differs.
|
|
14
|
+
*/
|
|
15
|
+
export class TextBlock extends Block {
|
|
16
|
+
/**
|
|
17
|
+
* @param {Nabu} nabu
|
|
18
|
+
* @param {NabuNode} node
|
|
19
|
+
* @param {LoroText} [textContainer] - Existing LoroText container. Defaults to the node's "text" container (created if missing).
|
|
20
|
+
*/
|
|
21
|
+
constructor(nabu: Nabu, node: NabuNode, textContainer?: LoroText);
|
|
22
|
+
/** @type {LoroText} */
|
|
23
|
+
container: LoroText;
|
|
24
|
+
/** @returns {TextBehavior} */
|
|
25
|
+
get behavior(): TextBehavior;
|
|
26
|
+
get text(): string;
|
|
27
|
+
get delta(): import("loro-crdt").Delta<string>[];
|
|
28
|
+
selection: {
|
|
29
|
+
from: number;
|
|
30
|
+
to: number;
|
|
31
|
+
isCollapsed: boolean;
|
|
32
|
+
direction: "forward" | "backward" | "none";
|
|
33
|
+
} | null;
|
|
34
|
+
/** @param {Block} block */
|
|
35
|
+
absorbs(block: Block): boolean;
|
|
36
|
+
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
37
|
+
applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
|
|
38
|
+
/** @param {Parameters<Block["split"]>[0]} [options] @returns {ReturnType<Block["split"]>} */
|
|
39
|
+
split(options?: Parameters<Block["split"]>[0]): ReturnType<Block["split"]>;
|
|
40
|
+
#private;
|
|
41
|
+
}
|
|
42
|
+
export type TextBlockNode = NabuNode<{
|
|
43
|
+
text: LoroText;
|
|
44
|
+
}>;
|
|
45
|
+
import { Block } from "./block.svelte.js";
|
|
46
|
+
import { LoroText } from "loro-crdt";
|
|
47
|
+
import { TextBehavior } from "../behaviors/text/text.behavior.svelte.js";
|
|
48
|
+
import type { Nabu } from "./nabu.svelte.js";
|
|
49
|
+
import type { NabuNode } from "./nabu.svelte.js";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Block } from "./block.svelte.js";
|
|
2
|
+
import { LoroText } from "loro-crdt";
|
|
3
|
+
import { TextBehavior } from "../behaviors/text/text.behavior.svelte.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import { Nabu, NabuNode } from "./nabu.svelte.js";
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {NabuNode<{text: LoroText}>} TextBlockNode
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Base class for purely textual blocks (paragraph, heading, dialogue…).
|
|
15
|
+
* Owns a single TextBehavior and proxies the standard Block text API to it,
|
|
16
|
+
* removing the proxy boilerplate previously duplicated in every text block.
|
|
17
|
+
*
|
|
18
|
+
* Hybrid blocks (MegaBlock + TextBehavior, like ListItem) must NOT extend
|
|
19
|
+
* this class — their children/positions logic differs.
|
|
20
|
+
*/
|
|
21
|
+
export class TextBlock extends Block {
|
|
22
|
+
/** @type {TextBehavior} */
|
|
23
|
+
#behavior;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {Nabu} nabu
|
|
27
|
+
* @param {NabuNode} node
|
|
28
|
+
* @param {LoroText} [textContainer] - Existing LoroText container. Defaults to the node's "text" container (created if missing).
|
|
29
|
+
*/
|
|
30
|
+
constructor(nabu, node, textContainer) {
|
|
31
|
+
super(nabu, node);
|
|
32
|
+
const data = /** @type {TextBlockNode} */ (node).data;
|
|
33
|
+
/** @type {LoroText} */
|
|
34
|
+
this.container = textContainer ?? data.get("text") ?? data.setContainer("text", new LoroText());
|
|
35
|
+
this.#behavior = new TextBehavior(/** @type {Block} */ (/** @type {unknown} */ (this)), this.container);
|
|
36
|
+
this.behaviors.set("text", this.#behavior);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @returns {TextBehavior} */
|
|
40
|
+
get behavior() { return this.#behavior; }
|
|
41
|
+
|
|
42
|
+
get text() { return this.behavior.text; }
|
|
43
|
+
|
|
44
|
+
get delta() { return this.behavior.delta; }
|
|
45
|
+
|
|
46
|
+
selection = $derived(this.behavior.selection);
|
|
47
|
+
positions = $derived(this.behavior.positions);
|
|
48
|
+
wordCount = $derived(this.behavior.wordCount);
|
|
49
|
+
|
|
50
|
+
/** @param {InputEvent} event */
|
|
51
|
+
beforeinput(event) { return this.behavior.handleBeforeInput(event); }
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Retrouve le nœud texte et l'offset DOM pour un offset Modèle donné
|
|
55
|
+
* @param {number} targetOffset
|
|
56
|
+
* @returns {{node: Node, offset: number} | null}
|
|
57
|
+
*/
|
|
58
|
+
getDOMPoint(targetOffset) { return this.behavior.getDOMPoint(targetOffset); }
|
|
59
|
+
|
|
60
|
+
/** @param {Block} block */
|
|
61
|
+
absorbs(block) { return this.behavior.absorbs(block); }
|
|
62
|
+
|
|
63
|
+
/** @param {number} index @param {string} text */
|
|
64
|
+
insert(index, text) { return this.behavior.insert(index, text); }
|
|
65
|
+
|
|
66
|
+
/** @param {Parameters<Block["delete"]>[0]} [deletion] */
|
|
67
|
+
delete(deletion) { return this.behavior.delete(deletion); }
|
|
68
|
+
|
|
69
|
+
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
70
|
+
applyDelta(data = []) { return this.behavior.applyDelta(data); }
|
|
71
|
+
|
|
72
|
+
/** @param {Parameters<Block["split"]>[0]} [options] @returns {ReturnType<Block["split"]>} */
|
|
73
|
+
split(options) { return this.behavior.split(options); }
|
|
74
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Block from "../Block.svelte";
|
|
3
|
+
import RichText from '../../behaviors/text/RichText.svelte';
|
|
4
|
+
import { getPlaceholder } from '../../utils/placeholders.js';
|
|
5
|
+
/** @type {{ block: import('./toggle.svelte.js').ToggleBlock }} */
|
|
6
|
+
let { block } = $props();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div class="nabu-toggle" class:collapsed={block.collapsed}>
|
|
10
|
+
<div class="nabu-toggle-head">
|
|
11
|
+
<button
|
|
12
|
+
class="nabu-toggle-arrow"
|
|
13
|
+
data-nabu-ui
|
|
14
|
+
contenteditable="false"
|
|
15
|
+
type="button"
|
|
16
|
+
aria-expanded={!block.collapsed}
|
|
17
|
+
onmousedown={(e) => { e.preventDefault(); block.toggleCollapsed(); }}
|
|
18
|
+
>{block.collapsed ? '▸' : '▾'}</button>
|
|
19
|
+
<div
|
|
20
|
+
bind:this={block.element}
|
|
21
|
+
class="nabu-toggle-header"
|
|
22
|
+
data-block-id={block.id}
|
|
23
|
+
data-block-type="toggle"
|
|
24
|
+
data-placeholder={block.text ? '' : getPlaceholder('toggle')}
|
|
25
|
+
><RichText delta={block.delta} /></div>
|
|
26
|
+
</div>
|
|
27
|
+
{#if !block.collapsed}
|
|
28
|
+
<div class="nabu-toggle-body">
|
|
29
|
+
{#each block.children as child (child.id)}<Block block={child} />{/each}
|
|
30
|
+
</div>
|
|
31
|
+
{/if}
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<style>
|
|
35
|
+
.nabu-toggle {
|
|
36
|
+
margin: 0.25em 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.nabu-toggle-head {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: row;
|
|
42
|
+
align-items: flex-start;
|
|
43
|
+
gap: 0.25em;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.nabu-toggle-arrow {
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
width: 1.4em;
|
|
49
|
+
height: 1.5em;
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
background: none;
|
|
54
|
+
border: none;
|
|
55
|
+
padding: 0;
|
|
56
|
+
margin: 0;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
user-select: none;
|
|
59
|
+
font-size: 0.85em;
|
|
60
|
+
line-height: 1.6;
|
|
61
|
+
outline: none;
|
|
62
|
+
color: var(--nb-text-secondary, rgba(255, 255, 255, 0.45));
|
|
63
|
+
transition: color 0.15s ease;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.nabu-toggle-arrow:hover {
|
|
67
|
+
color: var(--nb-text-primary, rgba(255, 255, 255, 0.85));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.nabu-toggle-header {
|
|
71
|
+
flex: 1;
|
|
72
|
+
outline: none;
|
|
73
|
+
white-space: pre-wrap;
|
|
74
|
+
min-height: 1.5em;
|
|
75
|
+
line-height: 1.6;
|
|
76
|
+
color: var(--nb-text-primary, rgba(255, 255, 255, 0.85));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.nabu-toggle-body {
|
|
80
|
+
margin-left: 1.4em;
|
|
81
|
+
padding-left: 0.25em;
|
|
82
|
+
border-left: 2px solid var(--nb-border, rgba(255, 255, 255, 0.1));
|
|
83
|
+
}
|
|
84
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Toggle;
|
|
2
|
+
type Toggle = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Toggle: import("svelte").Component<{
|
|
7
|
+
block: import("./toggle.svelte.js").ToggleBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./toggle.svelte.js").ToggleBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ToggleExtension: import("../..").Extension;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { extension } from "../../utils/extensions";
|
|
2
|
+
import { ToggleBlock } from "./toggle.svelte.js";
|
|
3
|
+
import ToggleComponent from "./Toggle.svelte";
|
|
4
|
+
|
|
5
|
+
export const ToggleExtension = extension("toggle", {
|
|
6
|
+
// @ts-ignore — static-side variance on create()
|
|
7
|
+
block: ToggleBlock,
|
|
8
|
+
component: ToggleComponent,
|
|
9
|
+
actions: {
|
|
10
|
+
'toggle': (nabu) => nabu.exec('block:transform', { type: 'toggle' }),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{type: "toggle", text: LoroText, collapsed: boolean}>} ToggleNode
|
|
6
|
+
*/
|
|
7
|
+
export class ToggleBlock extends MegaBlock {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
10
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string }} helpers
|
|
11
|
+
*/
|
|
12
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
13
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock, ctx?: object) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
17
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
18
|
+
*/
|
|
19
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
20
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock) => string;
|
|
21
|
+
}): string;
|
|
22
|
+
static htmlRules: {
|
|
23
|
+
selector: string;
|
|
24
|
+
}[];
|
|
25
|
+
/**
|
|
26
|
+
* @param {Element} el
|
|
27
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[], parseChildren?: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
28
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
29
|
+
*/
|
|
30
|
+
static fromHTML(el: Element, { parseInline, parseChildren }: {
|
|
31
|
+
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
32
|
+
parseChildren?: (el: Element) => import("../../utils/extensions.js").PasteBlock[];
|
|
33
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
34
|
+
/**
|
|
35
|
+
* @param {Nabu} nabu
|
|
36
|
+
* @param {string} type
|
|
37
|
+
* @param {Object} [props={}]
|
|
38
|
+
* @param {string|null} [parentId=null]
|
|
39
|
+
* @param {number|null} [index=null]
|
|
40
|
+
*/
|
|
41
|
+
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): ToggleBlock;
|
|
42
|
+
/** @param {Nabu} nabu @param {ToggleNode} node */
|
|
43
|
+
constructor(nabu: Nabu, node: ToggleNode);
|
|
44
|
+
container: LoroText;
|
|
45
|
+
/** @type {TextBehavior} */
|
|
46
|
+
behavior: TextBehavior;
|
|
47
|
+
/** @type {boolean} */
|
|
48
|
+
collapsed: boolean;
|
|
49
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
50
|
+
block: import("./toggle.svelte.js").ToggleBlock;
|
|
51
|
+
}, {}, "">;
|
|
52
|
+
get text(): string;
|
|
53
|
+
get delta(): import("loro-crdt").Delta<string>[];
|
|
54
|
+
selection: {
|
|
55
|
+
from: number;
|
|
56
|
+
to: number;
|
|
57
|
+
isCollapsed: boolean;
|
|
58
|
+
direction: "forward" | "backward" | "none";
|
|
59
|
+
} | null;
|
|
60
|
+
/**
|
|
61
|
+
* Set the collapsed state and persist to Loro.
|
|
62
|
+
* @param {boolean} v
|
|
63
|
+
*/
|
|
64
|
+
setCollapsed(v: boolean): void;
|
|
65
|
+
/**
|
|
66
|
+
* Toggle the collapsed state.
|
|
67
|
+
*/
|
|
68
|
+
toggleCollapsed(): void;
|
|
69
|
+
/** @param {import('../block.svelte.js').Block} block */
|
|
70
|
+
absorbs(block: import("../block.svelte.js").Block): boolean;
|
|
71
|
+
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
72
|
+
applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
|
|
73
|
+
/**
|
|
74
|
+
* @param {InputEvent} event
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
beforeinput(event: InputEvent): boolean;
|
|
78
|
+
}
|
|
79
|
+
export type ToggleNode = NabuNode<{
|
|
80
|
+
type: "toggle";
|
|
81
|
+
text: LoroText;
|
|
82
|
+
collapsed: boolean;
|
|
83
|
+
}>;
|
|
84
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
85
|
+
import { LoroText } from "loro-crdt";
|
|
86
|
+
import { TextBehavior } from "../../behaviors/text";
|
|
87
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
88
|
+
import type { NabuNode } from "../nabu.svelte.js";
|