@aionbuilders/nabu 0.1.0-alpha.2 → 0.1.0-alpha.3
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/dist/behaviors/text/text.behavior.svelte.js +1 -1
- package/dist/blocks/block.svelte.js +7 -7
- package/dist/blocks/container.utils.js +1 -1
- package/dist/blocks/heading/Heading.svelte +12 -8
- package/dist/blocks/list/ListItem.svelte +6 -2
- package/dist/blocks/list/list.behavior.svelte.d.ts +1 -0
- package/dist/blocks/list/list.behavior.svelte.js +5 -4
- package/dist/blocks/megablock.svelte.js +1 -1
- package/dist/blocks/nabu.svelte.d.ts +3 -0
- package/dist/blocks/nabu.svelte.js +11 -2
- package/dist/blocks/paragraph/Paragraph.svelte +11 -15
- package/package.json +1 -1
|
@@ -120,7 +120,7 @@ export class TextBehavior {
|
|
|
120
120
|
case "insertParagraph":
|
|
121
121
|
return this.handleInsertParagraph(event, selection);
|
|
122
122
|
default:
|
|
123
|
-
|
|
123
|
+
this.nabu.warn("Unhandled input type:", event.inputType);
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -194,17 +194,17 @@ export class Block {
|
|
|
194
194
|
|
|
195
195
|
/** @param {number} index @param {string} text */
|
|
196
196
|
insert(index, text) {
|
|
197
|
-
|
|
197
|
+
this.nabu.warn("Not implemented: insert text", text, "at index", index, "in block", this.id);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
/** @param {{from?: number, to?: number, index?: number, length?: number}} [deletion] */
|
|
201
201
|
delete(deletion) {
|
|
202
|
-
|
|
202
|
+
this.nabu.warn("Not implemented: delete block", this.id, "with deletion range", deletion);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/** @param {Block} block @returns {any} */
|
|
206
206
|
absorbs(block) {
|
|
207
|
-
|
|
207
|
+
this.nabu.warn("Not implemented: check if block", this.id, "absorbs block", block.id);
|
|
208
208
|
return false;
|
|
209
209
|
}
|
|
210
210
|
|
|
@@ -258,12 +258,12 @@ export class Block {
|
|
|
258
258
|
|
|
259
259
|
/** @param {Block[]} children @param {number | null} [index] */
|
|
260
260
|
adoptChildren(children, index = null) {
|
|
261
|
-
|
|
261
|
+
this.nabu.warn("Not implemented: adopt children", children.map(c => c.id), "into block", this.id, "at index", index);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
/** @param {{from?: number, to?: number, index?: number, length?: number, offset?: number}} options @returns {{block: Block} | null} */
|
|
265
265
|
split(options) {
|
|
266
|
-
|
|
266
|
+
this.nabu.warn("Not implemented: split block", this.id, "with options", options);
|
|
267
267
|
return null;
|
|
268
268
|
}
|
|
269
269
|
|
|
@@ -287,7 +287,7 @@ export class Block {
|
|
|
287
287
|
* @returns {{node: Node, offset: number} | null}
|
|
288
288
|
*/
|
|
289
289
|
getDOMPoint(offset) {
|
|
290
|
-
|
|
290
|
+
this.nabu.warn("getDOMPoint not implemented for block", this.type, this.id);
|
|
291
291
|
return null;
|
|
292
292
|
}
|
|
293
293
|
|
|
@@ -338,7 +338,7 @@ export class Block {
|
|
|
338
338
|
if (serializer) {
|
|
339
339
|
return serializer(this);
|
|
340
340
|
} else {
|
|
341
|
-
|
|
341
|
+
this.nabu.warn(`No serializer found for format "${format}" on block type "${this.type}"`);
|
|
342
342
|
return null;
|
|
343
343
|
}
|
|
344
344
|
}
|
|
@@ -87,7 +87,7 @@ export function handleContainerBeforeInput(container, nabu, event) {
|
|
|
87
87
|
const text = event.data || (inputType === 'insertLineBreak' ? '\n' : '');
|
|
88
88
|
startBlock.insert(focusData.options.startOffset, text);
|
|
89
89
|
} else {
|
|
90
|
-
|
|
90
|
+
nabu.warn('Unhandled input type in container:', inputType);
|
|
91
91
|
return false;
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
data-block-id={block.id}
|
|
11
11
|
data-block-type="heading"
|
|
12
12
|
class="nabu-heading"
|
|
13
|
+
class:debug={block.nabu.debugging}
|
|
13
14
|
class:selected={block.selected}
|
|
14
15
|
class:first={block.isSelectionStart}
|
|
15
16
|
class:last={block.isSelectionEnd}
|
|
@@ -22,14 +23,17 @@
|
|
|
22
23
|
white-space: pre-wrap;
|
|
23
24
|
outline: none;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
|
|
27
|
+
&.debug{
|
|
28
|
+
&.selected {
|
|
29
|
+
background-color: rgba(59, 130, 246, 0.25);
|
|
30
|
+
}
|
|
31
|
+
&.first {
|
|
32
|
+
border-top: 1px solid rgba(59, 130, 246, 0.5);
|
|
33
|
+
}
|
|
34
|
+
&.last {
|
|
35
|
+
border-bottom: 1px solid rgba(59, 130, 246, 0.5);
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
data-block-id={block.id}
|
|
11
11
|
data-block-type="list-item"
|
|
12
12
|
class="nabu-list-item"
|
|
13
|
+
class:debug={block.nabu.debugging}
|
|
13
14
|
class:selected={block.selected}
|
|
14
15
|
class:first={block.isSelectionStart}
|
|
15
16
|
class:last={block.isSelectionEnd}
|
|
@@ -28,9 +29,12 @@
|
|
|
28
29
|
.nabu-list-item {
|
|
29
30
|
margin: 0.25rem 0;
|
|
30
31
|
|
|
31
|
-
&.
|
|
32
|
-
|
|
32
|
+
&.debug{
|
|
33
|
+
&.selected > .item-content {
|
|
34
|
+
background-color: rgba(59, 130, 246, 0.25);
|
|
35
|
+
}
|
|
33
36
|
}
|
|
37
|
+
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
.item-content {
|
|
@@ -13,6 +13,7 @@ export class ListBehavior {
|
|
|
13
13
|
/** @param {Block} block */
|
|
14
14
|
constructor(block) {
|
|
15
15
|
this.block = block;
|
|
16
|
+
this.nabu = block.nabu;
|
|
16
17
|
this.node = /** @type {ListNode} */ (block.node);
|
|
17
18
|
this.listType = /** @type {"bullet" | "ordered"} */ (this.node.data.get("listType") || "bullet");
|
|
18
19
|
this.node.data.subscribe(() => {
|
|
@@ -27,23 +28,23 @@ export class ListBehavior {
|
|
|
27
28
|
absorbs(block) {
|
|
28
29
|
const behavior = block?.behaviors.get("list");
|
|
29
30
|
if (!(behavior && behavior instanceof ListBehavior)) {
|
|
30
|
-
|
|
31
|
+
this.nabu.warn("Cannot merge: target block is not a list.");
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
if (!(block instanceof MegaBlock)) {
|
|
34
|
-
|
|
35
|
+
this.nabu.warn("Cannot merge: target block is not a mega block.");
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
if (behavior.listType !== this.listType) {
|
|
39
|
-
|
|
40
|
+
this.nabu.warn("Cannot merge lists of different types.");
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// 1. On fusionne les enfants de l'autre liste dans la nôtre
|
|
44
45
|
const otherChildren = block.node.children() || [];
|
|
45
46
|
otherChildren.forEach(child => {
|
|
46
|
-
|
|
47
|
+
this.nabu.warn("Merging child with id", child.id.toString(), "from list", block.id, "into list", this.block.id);
|
|
47
48
|
const data = /** @type {LoroText} */ (child.data.get("text"));
|
|
48
49
|
const targetIndex = this.block.node.children()?.length; // On ajoute à la fin de notre liste
|
|
49
50
|
if (targetIndex === undefined || targetIndex === null) {
|
|
@@ -47,7 +47,7 @@ export class MegaBlock extends Block {
|
|
|
47
47
|
if (!childNode) return;
|
|
48
48
|
if (false) {
|
|
49
49
|
//TODO: conditions de skip, ex: si le block est déjà dans la mega block, ou si c'est un block parent de la mega block, etc.
|
|
50
|
-
|
|
50
|
+
this.nabu.warn("Skipping child with id", child.id, "because ...");
|
|
51
51
|
return skipped.push(child);
|
|
52
52
|
}
|
|
53
53
|
this.nabu.tree.move(childNode.id, this.node.id, index);
|
|
@@ -37,6 +37,7 @@ export class Nabu {
|
|
|
37
37
|
/** @type {SvelteMap<string, any>} */
|
|
38
38
|
systems: SvelteMap<string, any>;
|
|
39
39
|
hooks: Map<any, any>;
|
|
40
|
+
debugging: boolean;
|
|
40
41
|
/**
|
|
41
42
|
* Root-level serializers. Each function receives the Nabu instance and returns the serialized document.
|
|
42
43
|
* @type {Map<string, (nabu: Nabu) => any>}
|
|
@@ -99,6 +100,8 @@ export class Nabu {
|
|
|
99
100
|
handleKeydown(e: KeyboardEvent): void;
|
|
100
101
|
/** @param {InputEvent} e */
|
|
101
102
|
beforeinput(e: InputEvent): any;
|
|
103
|
+
/** @param {...any} args */
|
|
104
|
+
warn(...args: any[]): void;
|
|
102
105
|
}
|
|
103
106
|
export type NabuNode<T extends {
|
|
104
107
|
[x: string]: any;
|
|
@@ -160,6 +160,8 @@ export class Nabu {
|
|
|
160
160
|
|
|
161
161
|
hooks = new Map();
|
|
162
162
|
|
|
163
|
+
debugging = $state(false);
|
|
164
|
+
|
|
163
165
|
/**
|
|
164
166
|
* Root-level serializers. Each function receives the Nabu instance and returns the serialized document.
|
|
165
167
|
* @type {Map<string, (nabu: Nabu) => any>}
|
|
@@ -188,7 +190,7 @@ export class Nabu {
|
|
|
188
190
|
serialize(format) {
|
|
189
191
|
const fn = this.serializers.get(format);
|
|
190
192
|
if (!fn) {
|
|
191
|
-
|
|
193
|
+
this.warn(`No serializer registered for format "${format}" on Nabu`);
|
|
192
194
|
return null;
|
|
193
195
|
}
|
|
194
196
|
return fn(this);
|
|
@@ -389,7 +391,14 @@ export class Nabu {
|
|
|
389
391
|
return handleContainerBeforeInput(this, this, e);
|
|
390
392
|
}
|
|
391
393
|
|
|
392
|
-
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
/** @param {...any} args */
|
|
399
|
+
warn(...args) {
|
|
400
|
+
if (this.debugging) console.warn("[Nabu]", ...args);
|
|
401
|
+
}
|
|
393
402
|
}
|
|
394
403
|
|
|
395
404
|
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
data-block-id={block.id}
|
|
10
10
|
data-block-type="paragraph"
|
|
11
11
|
class="nabu-paragraph"
|
|
12
|
+
class:debug={block.nabu.debugging}
|
|
12
13
|
class:selected={block.selected}
|
|
13
14
|
class:first={block.isSelectionStart}
|
|
14
15
|
class:last={block.isSelectionEnd}
|
|
@@ -18,21 +19,16 @@
|
|
|
18
19
|
.nabu-paragraph {
|
|
19
20
|
white-space: pre-wrap;
|
|
20
21
|
margin-bottom: 0.5em;
|
|
21
|
-
&.
|
|
22
|
-
|
|
22
|
+
&.debug{
|
|
23
|
+
&.selected {
|
|
24
|
+
background-color: rgba(59, 130, 246, 0.25);
|
|
25
|
+
}
|
|
26
|
+
&.first {
|
|
27
|
+
border-top: 1px solid rgba(59, 130, 246, 0.5);
|
|
28
|
+
}
|
|
29
|
+
&.last {
|
|
30
|
+
border-bottom: 1px solid rgba(59, 130, 246, 0.5);
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
|
-
&.first {
|
|
25
|
-
border-top: 1px solid rgba(59, 130, 246, 0.5);
|
|
26
|
-
}
|
|
27
|
-
&.last {
|
|
28
|
-
border-bottom: 1px solid rgba(59, 130, 246, 0.5);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/* &::before {
|
|
33
|
-
content: " ";
|
|
34
|
-
display: inline-block;
|
|
35
|
-
width: 0;
|
|
36
|
-
} */
|
|
37
33
|
}
|
|
38
34
|
</style>
|