@aionbuilders/nabu 0.1.0-alpha.0 → 0.1.0-alpha.10
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 +70 -1
- package/dist/behaviors/text/index.d.ts +1 -1
- package/dist/behaviors/text/index.js +1 -1
- package/dist/behaviors/text/rich-text.extension.js +96 -30
- package/dist/behaviors/text/text.behavior.svelte.d.ts +19 -0
- package/dist/behaviors/text/text.behavior.svelte.js +64 -2
- package/dist/blocks/Block.svelte +3 -3
- package/dist/blocks/BlockGap.svelte +55 -0
- package/dist/blocks/BlockGap.svelte.d.ts +11 -0
- package/dist/blocks/Nabu.svelte +8 -0
- package/dist/blocks/block.extension.d.ts +2 -0
- package/dist/blocks/block.extension.js +32 -0
- package/dist/blocks/block.svelte.d.ts +41 -9
- package/dist/blocks/block.svelte.js +55 -18
- package/dist/blocks/container.utils.d.ts +54 -4
- package/dist/blocks/container.utils.js +211 -8
- package/dist/blocks/dialogue/Dialogue.svelte +46 -0
- package/dist/blocks/dialogue/Dialogue.svelte.d.ts +11 -0
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +41 -0
- package/dist/blocks/dialogue/dialogue.svelte.js +87 -0
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +52 -0
- package/dist/blocks/dialogue/index.d.ts +7 -0
- package/dist/blocks/dialogue/index.js +47 -0
- package/dist/blocks/heading/Heading.svelte +13 -9
- package/dist/blocks/heading/heading.svelte.d.ts +40 -4
- package/dist/blocks/heading/heading.svelte.js +60 -4
- package/dist/blocks/heading/hooks/onBeforeInput.hook.js +1 -1
- package/dist/blocks/heading/index.d.ts +2 -2
- package/dist/blocks/heading/index.js +11 -7
- package/dist/blocks/index.d.ts +7 -4
- package/dist/blocks/index.js +7 -4
- package/dist/blocks/list/ListItem.svelte +6 -2
- package/dist/blocks/list/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +77 -0
- package/dist/blocks/list/index.d.ts +2 -2
- package/dist/blocks/list/index.js +17 -3
- package/dist/blocks/list/list-item.svelte.d.ts +59 -6
- package/dist/blocks/list/list-item.svelte.js +157 -89
- package/dist/blocks/list/list.behavior.svelte.d.ts +1 -0
- package/dist/blocks/list/list.behavior.svelte.js +5 -4
- package/dist/blocks/list/list.svelte.d.ts +60 -7
- package/dist/blocks/list/list.svelte.js +116 -15
- package/dist/blocks/megablock.svelte.d.ts +30 -5
- package/dist/blocks/megablock.svelte.js +113 -17
- package/dist/blocks/nabu.svelte.d.ts +44 -6
- package/dist/blocks/nabu.svelte.js +397 -15
- package/dist/blocks/paragraph/Paragraph.svelte +12 -16
- package/dist/blocks/paragraph/Paragraph.svelte.d.ts +2 -2
- package/dist/blocks/paragraph/index.d.ts +2 -2
- package/dist/blocks/paragraph/index.js +29 -8
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +33 -5
- package/dist/blocks/paragraph/paragraph.svelte.js +55 -3
- package/dist/blocks/selection.svelte.d.ts +6 -5
- package/dist/blocks/selection.svelte.js +209 -18
- package/dist/blocks/variable.svelte.d.ts +47 -0
- package/dist/blocks/variable.svelte.js +51 -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 copy.svelte +118 -0
- package/dist/blocks/zone/ZoneEditor copy.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 +227 -0
- package/dist/blocks/zone/zone.svelte.d.ts +222 -0
- package/dist/blocks/zone/zone.svelte.js +620 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -1
- package/dist/nabu-theme.css +92 -0
- package/dist/overlays/context/Context.svelte +179 -0
- package/dist/overlays/context/Context.svelte.d.ts +16 -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 +81 -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.d.ts +12 -0
- package/dist/paste/html.paste.js +192 -0
- package/dist/paste/index.d.ts +4 -0
- package/dist/paste/index.js +4 -0
- package/dist/paste/markdown.paste.d.ts +12 -0
- package/dist/paste/markdown.paste.js +140 -0
- package/dist/paste/nabu.paste.d.ts +2 -0
- package/dist/paste/nabu.paste.js +20 -0
- package/dist/paste/plain-text.paste.d.ts +8 -0
- package/dist/paste/plain-text.paste.js +42 -0
- package/dist/persistence/indexeddb.d.ts +19 -0
- package/dist/persistence/indexeddb.js +71 -0
- package/dist/persistence/persistence.d.ts +48 -0
- package/dist/persistence/persistence.js +80 -0
- package/dist/presets.d.ts +38 -0
- package/dist/presets.js +86 -0
- package/dist/utils/extensions.d.ts +63 -0
- package/dist/utils/extensions.js +33 -0
- package/dist/utils/selection.svelte.js +0 -5
- package/package.json +14 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MegaBlock } from "../megablock.svelte";
|
|
2
|
-
import { ListBehavior } from "./list.behavior.svelte";
|
|
1
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
2
|
+
import { ListBehavior } from "./list.behavior.svelte.js";
|
|
3
3
|
import ListComponent from "./List.svelte";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @import { Nabu, NabuNode } from "../nabu.svelte";
|
|
6
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -36,6 +36,8 @@ export class List extends MegaBlock {
|
|
|
36
36
|
|
|
37
37
|
listType = $derived(this.behavior.listType);
|
|
38
38
|
|
|
39
|
+
get clipboardProps() { return { listType: this.listType }; }
|
|
40
|
+
|
|
39
41
|
component = $derived(this.nabu.components.get("list") || ListComponent);
|
|
40
42
|
|
|
41
43
|
root = $derived(!this.parent);
|
|
@@ -83,11 +85,7 @@ export class List extends MegaBlock {
|
|
|
83
85
|
this.destroy();
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
this.nabu.commit();
|
|
87
|
-
|
|
88
|
-
setTimeout(() => {
|
|
89
|
-
this.nabu.selection.setCursor(newParagraph, 0);
|
|
90
|
-
}, 0);
|
|
88
|
+
this.nabu.commit().then(() => this.nabu.selection.setCursor(newParagraph, 0));
|
|
91
89
|
|
|
92
90
|
return { block: newParagraph };
|
|
93
91
|
}
|
|
@@ -118,19 +116,122 @@ export class List extends MegaBlock {
|
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
this.nabu.commit();
|
|
122
|
-
|
|
123
|
-
// 4. On replace le curseur au début du nouvel item
|
|
124
|
-
setTimeout(() => {
|
|
125
|
-
this.nabu.selection.setCursor(newItem, 0);
|
|
126
|
-
}, 0);
|
|
119
|
+
this.nabu.commit().then(() => this.nabu.selection.setCursor(newItem, 0));
|
|
127
120
|
|
|
128
121
|
return { block: newItem };
|
|
129
122
|
}
|
|
130
123
|
|
|
124
|
+
/**
|
|
125
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
126
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string, depth?: number }} helpers
|
|
127
|
+
*/
|
|
128
|
+
static toMarkdown(pb, { recurse, depth = 0 }) {
|
|
129
|
+
const listType = pb.props?.listType ?? 'bullet';
|
|
130
|
+
return (pb.children || [])
|
|
131
|
+
.map((child, i) => recurse(child, { listType, index: i, depth }))
|
|
132
|
+
.join('\n');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
137
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
138
|
+
*/
|
|
139
|
+
static toHtml(pb, { recurse }) {
|
|
140
|
+
const tag = pb.props?.listType === 'ordered' ? 'ol' : 'ul';
|
|
141
|
+
return `<${tag}>${(pb.children || []).map(recurse).join('')}</${tag}>`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static markdownRules = [
|
|
145
|
+
{
|
|
146
|
+
priority: 10,
|
|
147
|
+
detect: /^[ \t]*([-*+]|\d+[.)]) /,
|
|
148
|
+
consume(/** @type {string[]} */ lines, /** @type {number} */ i) {
|
|
149
|
+
const LIST_RE = /^[ \t]*([-*+]|\d+[.)]) /;
|
|
150
|
+
let j = i;
|
|
151
|
+
while (j < lines.length && lines[j].trim() && LIST_RE.test(lines[j])) j++;
|
|
152
|
+
return Math.max(1, j - i);
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Parse markdown list lines into a nested List/ListItem PasteBlock tree.
|
|
159
|
+
* Uses indent depth to reconstruct nesting recursively.
|
|
160
|
+
*
|
|
161
|
+
* @param {string[]} lines
|
|
162
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
163
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
164
|
+
*/
|
|
165
|
+
static fromMarkdown(lines, { parseInline }) {
|
|
166
|
+
/** @typedef {{ depth: number, ordered: boolean, text: string }} ListToken */
|
|
167
|
+
|
|
168
|
+
/** @type {ListToken[]} */
|
|
169
|
+
const tokens = lines.flatMap(line => {
|
|
170
|
+
const m = line.match(/^([ \t]*)([-*+]|\d+[.)]) +(.*)/);
|
|
171
|
+
if (!m) return [];
|
|
172
|
+
return [{ depth: m[1].length, ordered: /^\d/.test(m[2]), text: m[3] }];
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (!tokens.length) return null;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Recursively build a List PasteBlock from a flat token array.
|
|
179
|
+
* Items at `baseDepth` become direct children; deeper tokens become sublists.
|
|
180
|
+
* @param {ListToken[]} toks
|
|
181
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
182
|
+
*/
|
|
183
|
+
function buildList(toks) {
|
|
184
|
+
const baseDepth = Math.min(...toks.map(t => t.depth));
|
|
185
|
+
const listType = toks.find(t => t.depth === baseDepth)?.ordered ? 'ordered' : 'bullet';
|
|
186
|
+
/** @type {import('../../utils/extensions.js').PasteBlock[]} */
|
|
187
|
+
const items = [];
|
|
188
|
+
let i = 0;
|
|
189
|
+
|
|
190
|
+
while (i < toks.length) {
|
|
191
|
+
if (toks[i].depth !== baseDepth) { i++; continue; }
|
|
192
|
+
|
|
193
|
+
// Collect all sub-tokens directly following this item (deeper indent)
|
|
194
|
+
const subToks = /** @type {ListToken[]} */ ([]);
|
|
195
|
+
let j = i + 1;
|
|
196
|
+
while (j < toks.length && toks[j].depth > baseDepth) {
|
|
197
|
+
subToks.push(toks[j]);
|
|
198
|
+
j++;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** @type {import('../../utils/extensions.js').PasteBlock} */
|
|
202
|
+
const item = { type: 'list-item', delta: parseInline(toks[i].text), partial: false };
|
|
203
|
+
if (subToks.length) item.children = [buildList(subToks)];
|
|
204
|
+
|
|
205
|
+
items.push(item);
|
|
206
|
+
i = j;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return { type: 'list', props: { listType }, children: items, partial: false };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return buildList(tokens);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
static htmlRules = [
|
|
216
|
+
{ selector: 'ul', props: { listType: 'bullet' } },
|
|
217
|
+
{ selector: 'ol', props: { listType: 'ordered' } },
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @param {Element} el
|
|
222
|
+
* @param {{ parseChildren: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
223
|
+
* @param {{ props?: { listType?: string } }} [rule]
|
|
224
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
225
|
+
*/
|
|
226
|
+
static fromHTML(el, { parseChildren }, rule) {
|
|
227
|
+
const children = parseChildren(el);
|
|
228
|
+
if (!children.length) return null;
|
|
229
|
+
return { type: 'list', props: { listType: rule?.props?.listType ?? 'bullet' }, children, partial: false };
|
|
230
|
+
}
|
|
231
|
+
|
|
131
232
|
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
132
233
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
133
|
-
const node = nabu.tree.createNode(parentId || undefined, index
|
|
234
|
+
const node = nabu.tree.createNode(parentId || undefined, index != null ? index : undefined);
|
|
134
235
|
node.data.set("type", "list");
|
|
135
236
|
node.data.set("listType", props.listType || "bullet");
|
|
136
237
|
const block = new List(nabu, node);
|
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { Nabu, NabuNode } from "./nabu.svelte";
|
|
2
|
+
* @import { Nabu, NabuNode } from "./nabu.svelte.js";
|
|
3
3
|
*/
|
|
4
4
|
export class MegaBlock extends Block {
|
|
5
5
|
/** @type {Block[]} */
|
|
6
6
|
children: Block[];
|
|
7
7
|
updateChildren(): void;
|
|
8
8
|
/** @param {Block[]} children @param {number | null} [index] */
|
|
9
|
-
adoptChildren(children: Block[], index?: number | null):
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
adoptChildren(children: Block[], index?: number | null): void;
|
|
10
|
+
/**
|
|
11
|
+
* Props to include in the clipboard representation of this container block.
|
|
12
|
+
* Override in subclasses that carry structural props (e.g. List → { listType }).
|
|
13
|
+
* @returns {Record<string, any>}
|
|
14
|
+
*/
|
|
15
|
+
get clipboardProps(): Record<string, any>;
|
|
16
|
+
/**
|
|
17
|
+
* Serializes the portion of this MegaBlock that falls within the given
|
|
18
|
+
* selection boundaries, recursively.
|
|
19
|
+
*
|
|
20
|
+
* For hybrid blocks (MegaBlock + text behavior, like ListItem):
|
|
21
|
+
* if startBlock or endBlock IS this block, serialize text directly.
|
|
22
|
+
* if neither boundary is set, this block is fully selected — serialize all text.
|
|
23
|
+
*
|
|
24
|
+
* For pure containers (like List):
|
|
25
|
+
* find direct children that contain/are the boundaries, slice children in range,
|
|
26
|
+
* recurse into each with propagated context.
|
|
27
|
+
*
|
|
28
|
+
* @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null }} [ctx]
|
|
29
|
+
* @returns {import('../utils/extensions.js').PasteBlock | null}
|
|
30
|
+
*/
|
|
31
|
+
serializeForClipboard({ startBlock, startFrom, endBlock, endTo }?: {
|
|
32
|
+
startBlock?: Block | null;
|
|
33
|
+
startFrom?: number;
|
|
34
|
+
endBlock?: Block | null;
|
|
35
|
+
endTo?: number | null;
|
|
36
|
+
}): import("../utils/extensions.js").PasteBlock | null;
|
|
12
37
|
}
|
|
13
|
-
import { Block } from "./block.svelte";
|
|
38
|
+
import { Block } from "./block.svelte.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Block } from "./block.svelte";
|
|
2
|
-
import { handleContainerBeforeInput } from "./container.utils.js";
|
|
1
|
+
import { Block } from "./block.svelte.js";
|
|
2
|
+
import { handleContainerBeforeInput, findDirectChildOf } from "./container.utils.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @import { Nabu, NabuNode } from "./nabu.svelte";
|
|
5
|
+
* @import { Nabu, NabuNode } from "./nabu.svelte.js";
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
export class MegaBlock extends Block {
|
|
@@ -15,6 +15,24 @@ export class MegaBlock extends Block {
|
|
|
15
15
|
|
|
16
16
|
/** @type {Block[]} */
|
|
17
17
|
children = $state([]);
|
|
18
|
+
positions = $derived(this.children.reduce((sum, child) => sum + (child.positions ?? 0), 0));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Pure container: no own text, delegate entirely to children.
|
|
22
|
+
* @param {number} localOffset
|
|
23
|
+
* @returns {{ block: Block, offset: number } | null}
|
|
24
|
+
*/
|
|
25
|
+
resolveOffset(localOffset) {
|
|
26
|
+
let remaining = localOffset;
|
|
27
|
+
for (const child of this.children) {
|
|
28
|
+
const childPositions = child.positions ?? 0;
|
|
29
|
+
if (remaining < childPositions) return child.resolveOffset(remaining);
|
|
30
|
+
remaining -= childPositions;
|
|
31
|
+
}
|
|
32
|
+
// Fallback: clamp to end of last child
|
|
33
|
+
const last = this.children[this.children.length - 1];
|
|
34
|
+
return last ? last.resolveOffset(Math.max(0, (last.positions ?? 1) - 1)) : null;
|
|
35
|
+
}
|
|
18
36
|
|
|
19
37
|
updateChildren() {
|
|
20
38
|
const childrenNodes = this.node.children();
|
|
@@ -40,20 +58,14 @@ export class MegaBlock extends Block {
|
|
|
40
58
|
|
|
41
59
|
/** @param {Block[]} children @param {number | null} [index] */
|
|
42
60
|
adoptChildren(children, index = null) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return skipped.push(child);
|
|
52
|
-
}
|
|
53
|
-
this.nabu.tree.move(childNode.id, this.node.id, index);
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
return {skipped: skipped.length ? skipped.reverse() : false};
|
|
61
|
+
// Reverse so that when index is specified, children are inserted in original
|
|
62
|
+
// order (each insert at the same position pushes others down, so reverse of
|
|
63
|
+
// reverse = original). With index=null (append), order doesn't matter.
|
|
64
|
+
// Spread to avoid mutating the input array (which may be a reactive Svelte array).
|
|
65
|
+
[...children].reverse().forEach(child => {
|
|
66
|
+
if (!child.node) return;
|
|
67
|
+
this.nabu.tree.move(child.node.id, this.node.id, index);
|
|
68
|
+
});
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
|
|
@@ -61,4 +73,88 @@ export class MegaBlock extends Block {
|
|
|
61
73
|
beforeinput(event) {
|
|
62
74
|
return handleContainerBeforeInput(this, this.nabu, event);
|
|
63
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Props to include in the clipboard representation of this container block.
|
|
79
|
+
* Override in subclasses that carry structural props (e.g. List → { listType }).
|
|
80
|
+
* @returns {Record<string, any>}
|
|
81
|
+
*/
|
|
82
|
+
get clipboardProps() { return {}; }
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Serializes the portion of this MegaBlock that falls within the given
|
|
86
|
+
* selection boundaries, recursively.
|
|
87
|
+
*
|
|
88
|
+
* For hybrid blocks (MegaBlock + text behavior, like ListItem):
|
|
89
|
+
* if startBlock or endBlock IS this block, serialize text directly.
|
|
90
|
+
* if neither boundary is set, this block is fully selected — serialize all text.
|
|
91
|
+
*
|
|
92
|
+
* For pure containers (like List):
|
|
93
|
+
* find direct children that contain/are the boundaries, slice children in range,
|
|
94
|
+
* recurse into each with propagated context.
|
|
95
|
+
*
|
|
96
|
+
* @param {{ startBlock?: Block|null, startFrom?: number, endBlock?: Block|null, endTo?: number|null }} [ctx]
|
|
97
|
+
* @returns {import('../utils/extensions.js').PasteBlock | null}
|
|
98
|
+
*/
|
|
99
|
+
serializeForClipboard({ startBlock = null, startFrom = 0, endBlock = null, endTo = null } = {}) {
|
|
100
|
+
const tb = this.behaviors?.get('text');
|
|
101
|
+
const imStart = startBlock === this;
|
|
102
|
+
const imEnd = endBlock === this;
|
|
103
|
+
|
|
104
|
+
// ── Hybrid block (has text): this block IS a selection boundary or fully selected ──
|
|
105
|
+
if (tb && (imStart || imEnd || (!startBlock && !endBlock))) {
|
|
106
|
+
const from = imStart ? startFrom : 0;
|
|
107
|
+
const to = imEnd ? endTo : tb.container.length;
|
|
108
|
+
const partial = imStart && imEnd ? 'both' : imStart ? 'start' : imEnd ? 'end' : false;
|
|
109
|
+
const delta = tb.container.sliceDelta(from, to ?? tb.container.length);
|
|
110
|
+
const result = /** @type {import('../utils/extensions.js').PasteBlock} */ (
|
|
111
|
+
{ type: this.type, props: this.clipboardProps, partial, delta }
|
|
112
|
+
);
|
|
113
|
+
// If fully selected and has children (e.g. ListItem with sublist), include them too
|
|
114
|
+
if (!imStart && !imEnd && this.children?.length) {
|
|
115
|
+
const childrenSerialized = this.children.map(child =>
|
|
116
|
+
typeof child.serializeForClipboard === 'function'
|
|
117
|
+
? child.serializeForClipboard({})
|
|
118
|
+
: child.serialize('application/x-nabu+json', { partial: false })
|
|
119
|
+
).filter(Boolean);
|
|
120
|
+
if (childrenSerialized.length) result.children = childrenSerialized;
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ── Pure container: find relevant children by walking up from boundaries ──
|
|
126
|
+
if (!this.children?.length) return null;
|
|
127
|
+
|
|
128
|
+
const sc = (startBlock ? findDirectChildOf(startBlock, this) : null) ?? this.children[0];
|
|
129
|
+
const ec = (endBlock ? findDirectChildOf(endBlock, this) : null) ?? this.children.at(-1);
|
|
130
|
+
if (!sc || !ec) return null;
|
|
131
|
+
|
|
132
|
+
const si = this.children.indexOf(sc);
|
|
133
|
+
const ei = this.children.indexOf(ec);
|
|
134
|
+
if (si === -1 || ei === -1) return null;
|
|
135
|
+
|
|
136
|
+
const relevant = this.children.slice(si, ei + 1);
|
|
137
|
+
const lastI = relevant.length - 1;
|
|
138
|
+
|
|
139
|
+
const children = relevant.map((child, i) => {
|
|
140
|
+
const isFirst = i === 0;
|
|
141
|
+
const isLast = i === lastI;
|
|
142
|
+
const childCtx = {
|
|
143
|
+
startBlock: isFirst ? startBlock : null,
|
|
144
|
+
startFrom: isFirst ? startFrom : 0,
|
|
145
|
+
endBlock: isLast ? endBlock : null,
|
|
146
|
+
endTo: isLast ? endTo : null,
|
|
147
|
+
};
|
|
148
|
+
if (typeof child.serializeForClipboard === 'function') {
|
|
149
|
+
return child.serializeForClipboard(childCtx);
|
|
150
|
+
}
|
|
151
|
+
return child.serialize('application/x-nabu+json', {
|
|
152
|
+
from: isFirst && startBlock ? startFrom : 0,
|
|
153
|
+
to: isLast && endBlock ? endTo : null,
|
|
154
|
+
partial: isFirst && isLast ? 'both' : isFirst ? 'start' : isLast ? 'end' : false,
|
|
155
|
+
});
|
|
156
|
+
}).filter(Boolean);
|
|
157
|
+
|
|
158
|
+
return children.length ? { type: this.type, props: this.clipboardProps, children } : null;
|
|
159
|
+
}
|
|
64
160
|
}
|
|
@@ -34,9 +34,19 @@ export class Nabu {
|
|
|
34
34
|
blocks: SvelteMap<string, Block>;
|
|
35
35
|
/** @type {SvelteMap<string, SvelteSet<Block>>} */
|
|
36
36
|
blocksByType: SvelteMap<string, SvelteSet<Block>>;
|
|
37
|
-
/**
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Registered subsystems. Each system should implement:
|
|
39
|
+
* - `start(): void` — called when the editor mounts
|
|
40
|
+
* - `stop(): void` — called when the editor unmounts
|
|
41
|
+
* @type {SvelteMap<string, { start?: () => void, stop?: () => void, [key: string]: any }>}
|
|
42
|
+
*/
|
|
43
|
+
systems: SvelteMap<string, {
|
|
44
|
+
start?: () => void;
|
|
45
|
+
stop?: () => void;
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}>;
|
|
39
48
|
hooks: Map<any, any>;
|
|
49
|
+
debugging: boolean;
|
|
40
50
|
/**
|
|
41
51
|
* Root-level serializers. Each function receives the Nabu instance and returns the serialized document.
|
|
42
52
|
* @type {Map<string, (nabu: Nabu) => any>}
|
|
@@ -44,14 +54,22 @@ export class Nabu {
|
|
|
44
54
|
serializers: Map<string, (nabu: Nabu) => any>;
|
|
45
55
|
/** @type {Block[]} */
|
|
46
56
|
children: Block[];
|
|
57
|
+
positions: number;
|
|
47
58
|
get isEmpty(): boolean;
|
|
48
59
|
/** @param {string} format */
|
|
49
60
|
serialize(format: string): any;
|
|
50
61
|
init(): void;
|
|
51
62
|
/** Rafraîchit les blocs racines de l'éditeur */
|
|
52
63
|
updateRoots(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Dispatch an action to all registered handlers for the given topic.
|
|
66
|
+
* @param {string} topic
|
|
67
|
+
* @param {any} [data]
|
|
68
|
+
* @returns {Promise<import('@aionbuilders/pulse').PulseEvent>}
|
|
69
|
+
*/
|
|
70
|
+
exec(topic: string, data?: any): Promise<import("@aionbuilders/pulse").PulseEvent>;
|
|
53
71
|
trigger(hookName: any, ...args: any[]): void;
|
|
54
|
-
commit(): void
|
|
72
|
+
commit(): Promise<void>;
|
|
55
73
|
/**
|
|
56
74
|
* Undo the last operation
|
|
57
75
|
*/
|
|
@@ -60,7 +78,7 @@ export class Nabu {
|
|
|
60
78
|
* Redo the last undone operation
|
|
61
79
|
*/
|
|
62
80
|
redo(): void;
|
|
63
|
-
/** @param {{from: {offset: number, block: Block}, to: {offset: number, block: Block}}} [options={}] */
|
|
81
|
+
/** @param {{from: {offset: number, block: Block}, to: {offset: number, block: Block}, offset?: number}} [options={}] */
|
|
64
82
|
focus(options?: {
|
|
65
83
|
from: {
|
|
66
84
|
offset: number;
|
|
@@ -70,6 +88,7 @@ export class Nabu {
|
|
|
70
88
|
offset: number;
|
|
71
89
|
block: Block;
|
|
72
90
|
};
|
|
91
|
+
offset?: number;
|
|
73
92
|
}): void;
|
|
74
93
|
/**
|
|
75
94
|
* Insère un nouveau bloc dans le document
|
|
@@ -99,6 +118,25 @@ export class Nabu {
|
|
|
99
118
|
handleKeydown(e: KeyboardEvent): void;
|
|
100
119
|
/** @param {InputEvent} e */
|
|
101
120
|
beforeinput(e: InputEvent): any;
|
|
121
|
+
/** @param {ClipboardEvent} e */
|
|
122
|
+
handleCopy(e: ClipboardEvent): void;
|
|
123
|
+
/** @param {ClipboardEvent} e */
|
|
124
|
+
handleCut(e: ClipboardEvent): void;
|
|
125
|
+
/** @param {ClipboardEvent} e */
|
|
126
|
+
handlePaste(e: ClipboardEvent): void;
|
|
127
|
+
/**
|
|
128
|
+
* Insère un PasteFragment à la position du curseur courant.
|
|
129
|
+
* @param {import('../utils/extensions.js').PasteFragment} fragment
|
|
130
|
+
*/
|
|
131
|
+
insertFragment(fragment: import("../utils/extensions.js").PasteFragment): void;
|
|
132
|
+
/** @param {number} globalOffset */
|
|
133
|
+
resolveDocumentOffset(globalOffset: number): {
|
|
134
|
+
block: Block;
|
|
135
|
+
offset: number;
|
|
136
|
+
} | null;
|
|
137
|
+
/** @param {...any} args */
|
|
138
|
+
warn(...args: any[]): void;
|
|
139
|
+
#private;
|
|
102
140
|
}
|
|
103
141
|
export type NabuNode<T extends {
|
|
104
142
|
[x: string]: any;
|
|
@@ -110,12 +148,12 @@ export type NabuInit = {
|
|
|
110
148
|
snapshot?: Uint8Array<ArrayBufferLike> | undefined;
|
|
111
149
|
};
|
|
112
150
|
import { LoroDoc } from 'loro-crdt';
|
|
113
|
-
import { NabuSelection } from './selection.svelte';
|
|
151
|
+
import { NabuSelection } from './selection.svelte.js';
|
|
114
152
|
import type { LoroTree } from "loro-crdt";
|
|
115
153
|
import { UndoManager } from 'loro-crdt';
|
|
116
154
|
import type { Extension } from '../utils/extensions.js';
|
|
117
155
|
import { SvelteMap } from 'svelte/reactivity';
|
|
118
|
-
import { Block } from './block.svelte';
|
|
156
|
+
import { Block } from './block.svelte.js';
|
|
119
157
|
import type { Component } from "svelte";
|
|
120
158
|
import { SvelteSet } from 'svelte/reactivity';
|
|
121
159
|
import type { LoroTreeNode } from "loro-crdt";
|