@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
|
@@ -4,7 +4,48 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {NabuNode<{type: "list-item", text: LoroText}>} ListItemNode
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Indent a list item (Tab behavior): move into previous sibling's sublist, hoist own children.
|
|
9
|
+
* @param {ListItem} item
|
|
10
|
+
* @returns {boolean}
|
|
11
|
+
*/
|
|
12
|
+
export function indentListItem(item: ListItem): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Unindent a list item (Shift+Tab behavior): move out of parent sublist, carry followers.
|
|
15
|
+
* @param {ListItem} item
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
export function unindentListItem(item: ListItem): boolean;
|
|
7
19
|
export class ListItem extends MegaBlock {
|
|
20
|
+
/**
|
|
21
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
22
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string, listType?: string, index?: number, depth?: number }} helpers
|
|
23
|
+
*/
|
|
24
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { recurse, listType, index, depth }: {
|
|
25
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock, ctx?: object) => string;
|
|
26
|
+
listType?: string;
|
|
27
|
+
index?: number;
|
|
28
|
+
depth?: number;
|
|
29
|
+
}): string;
|
|
30
|
+
/**
|
|
31
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
32
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
33
|
+
*/
|
|
34
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
35
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock) => string;
|
|
36
|
+
}): string;
|
|
37
|
+
static htmlRules: {
|
|
38
|
+
selector: string;
|
|
39
|
+
}[];
|
|
40
|
+
/**
|
|
41
|
+
* @param {Element} el
|
|
42
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[], parseBlock: (el: Element) => import('../../utils/extensions.js').PasteBlock | null }} helpers
|
|
43
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
44
|
+
*/
|
|
45
|
+
static fromHTML(el: Element, { parseInline, parseBlock }: {
|
|
46
|
+
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
47
|
+
parseBlock: (el: Element) => import("../../utils/extensions.js").PasteBlock | null;
|
|
48
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
8
49
|
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
9
50
|
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): ListItem;
|
|
10
51
|
/** @param {Nabu} nabu @param {ListItemNode} node */
|
|
@@ -13,7 +54,7 @@ export class ListItem extends MegaBlock {
|
|
|
13
54
|
/** @type {TextBehavior} */
|
|
14
55
|
behavior: TextBehavior;
|
|
15
56
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
16
|
-
block: import("./list-item.svelte").ListItem;
|
|
57
|
+
block: import("./list-item.svelte.js").ListItem;
|
|
17
58
|
}, {}, "">;
|
|
18
59
|
get text(): string;
|
|
19
60
|
get delta(): import("loro-crdt").Delta<string>[];
|
|
@@ -24,6 +65,18 @@ export class ListItem extends MegaBlock {
|
|
|
24
65
|
direction: "forward" | "backward" | "none";
|
|
25
66
|
} | null;
|
|
26
67
|
sublist: Block | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* A ListItem must always live inside a List.
|
|
70
|
+
* wrapOrphan() uses this to auto-create a List wrapper when a ListItem
|
|
71
|
+
* is relocated to a context that doesn't have a List parent.
|
|
72
|
+
* props() reads this.parent (stale Svelte state) which still points to the
|
|
73
|
+
* original List at relocation time, giving us the correct listType.
|
|
74
|
+
* @returns {{ type: string, props: () => Record<string, any> }}
|
|
75
|
+
*/
|
|
76
|
+
get requiredParent(): {
|
|
77
|
+
type: string;
|
|
78
|
+
props: () => Record<string, any>;
|
|
79
|
+
};
|
|
27
80
|
/**
|
|
28
81
|
* Retourne la sous-liste existante, ou en crée une nouvelle à la fin des enfants.
|
|
29
82
|
* @param {"bullet" | "ordered"} [listType="bullet"]
|
|
@@ -31,18 +84,18 @@ export class ListItem extends MegaBlock {
|
|
|
31
84
|
getOrCreateSublist(listType?: "bullet" | "ordered"): Block;
|
|
32
85
|
/** @param {KeyboardEvent} event */
|
|
33
86
|
keydown(event: KeyboardEvent): boolean;
|
|
34
|
-
/** @param {import('../block.svelte').Block} block */
|
|
35
|
-
absorbs(block: import("../block.svelte").Block): boolean;
|
|
87
|
+
/** @param {import('../block.svelte.js').Block} block */
|
|
88
|
+
absorbs(block: import("../block.svelte.js").Block): boolean;
|
|
36
89
|
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
37
90
|
applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
|
|
38
|
-
/** @param {Parameters<import('../block.svelte').Block["split"]>[0]} [options] @returns {ReturnType<import('../block.svelte').Block["split"]>} */
|
|
39
|
-
split(options?: Parameters<import("../block.svelte").Block["split"]>[0]): ReturnType<import("../block.svelte").Block["split"]>;
|
|
91
|
+
/** @param {Parameters<import('../block.svelte.js').Block["split"]>[0]} [options] @returns {ReturnType<import('../block.svelte.js').Block["split"]>} */
|
|
92
|
+
split(options?: Parameters<import("../block.svelte.js").Block["split"]>[0]): ReturnType<import("../block.svelte.js").Block["split"]>;
|
|
40
93
|
}
|
|
41
94
|
export type ListItemNode = NabuNode<{
|
|
42
95
|
type: "list-item";
|
|
43
96
|
text: LoroText;
|
|
44
97
|
}>;
|
|
45
|
-
import { MegaBlock } from "../megablock.svelte";
|
|
98
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
46
99
|
import { LoroText } from "loro-crdt";
|
|
47
100
|
import { TextBehavior } from "../../behaviors/text";
|
|
48
101
|
import type { Block } from "..";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MegaBlock } from "../megablock.svelte";
|
|
1
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
2
2
|
import ListItemComponent from "./ListItem.svelte";
|
|
3
3
|
import { LoroText } from "loro-crdt";
|
|
4
|
-
import { TextBehavior } from "../../behaviors/text";
|
|
4
|
+
import { TextBehavior, deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @import { Nabu, NabuNode, Block } from "..";
|
|
@@ -11,6 +11,71 @@ import { TextBehavior } from "../../behaviors/text";
|
|
|
11
11
|
* @typedef {NabuNode<{type: "list-item", text: LoroText}>} ListItemNode
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Indent a list item (Tab behavior): move into previous sibling's sublist, hoist own children.
|
|
16
|
+
* @param {ListItem} item
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
export function indentListItem(item) {
|
|
20
|
+
const currentIndex = item.node.index();
|
|
21
|
+
if (currentIndex === 0) return false;
|
|
22
|
+
|
|
23
|
+
const parentList = item.node.parent();
|
|
24
|
+
if (!parentList) return false;
|
|
25
|
+
|
|
26
|
+
const previousNode = parentList.children()?.[currentIndex - 1];
|
|
27
|
+
if (!previousNode) return false;
|
|
28
|
+
const previousItem = item.nabu.blocks.get(previousNode.id.toString());
|
|
29
|
+
if (!previousItem || previousItem.type !== 'list-item') return false;
|
|
30
|
+
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const targetSublist = previousItem.getOrCreateSublist();
|
|
33
|
+
const targetSublistId = targetSublist.node.id.toString();
|
|
34
|
+
|
|
35
|
+
item.nabu.tree.move(item.node.id.toString(), targetSublistId);
|
|
36
|
+
|
|
37
|
+
if (item.sublist) {
|
|
38
|
+
for (const childNode of item.sublist.node.children()) {
|
|
39
|
+
item.nabu.tree.move(childNode.id.toString(), targetSublistId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
item.commit().then(() => item.behavior.block.focus());
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Unindent a list item (Shift+Tab behavior): move out of parent sublist, carry followers.
|
|
49
|
+
* @param {ListItem} item
|
|
50
|
+
* @returns {boolean}
|
|
51
|
+
*/
|
|
52
|
+
export function unindentListItem(item) {
|
|
53
|
+
const parentListNode = item.node.parent();
|
|
54
|
+
if (!parentListNode) return false;
|
|
55
|
+
|
|
56
|
+
const grandParentItemNode = parentListNode.parent();
|
|
57
|
+
if (!grandParentItemNode || grandParentItemNode.data.get('type') !== 'list-item') return false;
|
|
58
|
+
|
|
59
|
+
const myIndex = item.node.index();
|
|
60
|
+
const followers = parentListNode.children().slice(myIndex + 1);
|
|
61
|
+
|
|
62
|
+
if (followers.length > 0) {
|
|
63
|
+
const mySublist = item.getOrCreateSublist();
|
|
64
|
+
for (const follower of followers) {
|
|
65
|
+
item.nabu.tree.move(follower.id.toString(), mySublist.node.id.toString());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const targetParentListNode = grandParentItemNode.parent();
|
|
70
|
+
if (!targetParentListNode) return false;
|
|
71
|
+
|
|
72
|
+
const targetIndex = grandParentItemNode.index() + 1;
|
|
73
|
+
item.nabu.tree.move(item.node.id.toString(), targetParentListNode.id.toString(), targetIndex);
|
|
74
|
+
|
|
75
|
+
item.commit().then(() => item.behavior.block.focus());
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
14
79
|
export class ListItem extends MegaBlock {
|
|
15
80
|
/** @param {Nabu} nabu @param {ListItemNode} node */
|
|
16
81
|
constructor(nabu, node) {
|
|
@@ -24,7 +89,7 @@ export class ListItem extends MegaBlock {
|
|
|
24
89
|
this.behaviors.set("text", this.behavior);
|
|
25
90
|
|
|
26
91
|
this.serializers.set('markdown', () => {
|
|
27
|
-
const depth = this.parents.filter(p => p.type === '
|
|
92
|
+
const depth = this.parents.filter(p => p.type === 'list-item').length;
|
|
28
93
|
const indent = ' '.repeat(depth);
|
|
29
94
|
const listType = /** @type {any} */ (this.parent)?.listType ?? 'bullet';
|
|
30
95
|
const prefix = listType === 'ordered' ? `${this.index + 1}.` : '-';
|
|
@@ -46,6 +111,7 @@ export class ListItem extends MegaBlock {
|
|
|
46
111
|
if (childrenJson.length) result.children = childrenJson;
|
|
47
112
|
return result;
|
|
48
113
|
});
|
|
114
|
+
this.serializers.set('application/x-nabu+json', (ctx = {}) => this.behavior.toClipboardBlock(ctx));
|
|
49
115
|
}
|
|
50
116
|
|
|
51
117
|
component = $derived(this.nabu.components.get("list-item") || ListItemComponent);
|
|
@@ -60,8 +126,46 @@ export class ListItem extends MegaBlock {
|
|
|
60
126
|
|
|
61
127
|
selection = $derived(this.behavior.selection);
|
|
62
128
|
|
|
129
|
+
positions = $derived(this.behavior.positions + super.positions);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Mixed block: own text comes first, then children (sublists).
|
|
133
|
+
* @param {number} localOffset
|
|
134
|
+
* @returns {{ block: import('../block.svelte.js').Block, offset: number } | null}
|
|
135
|
+
*/
|
|
136
|
+
resolveOffset(localOffset) {
|
|
137
|
+
const textPositions = this.behavior.positions; // text.length + 1
|
|
138
|
+
if (localOffset < textPositions || !this.children.length) {
|
|
139
|
+
return { block: this, offset: Math.min(localOffset, this.behavior.text.length) };
|
|
140
|
+
}
|
|
141
|
+
let remaining = localOffset - textPositions;
|
|
142
|
+
for (const child of this.children) {
|
|
143
|
+
const childPositions = child.positions ?? 0;
|
|
144
|
+
if (remaining < childPositions) return child.resolveOffset(remaining);
|
|
145
|
+
remaining -= childPositions;
|
|
146
|
+
}
|
|
147
|
+
return { block: this, offset: this.behavior.text.length };
|
|
148
|
+
}
|
|
149
|
+
|
|
63
150
|
sublist = $derived(this.children.find(child => child.node.data.get("type") === "list"));
|
|
64
151
|
|
|
152
|
+
/**
|
|
153
|
+
* A ListItem must always live inside a List.
|
|
154
|
+
* wrapOrphan() uses this to auto-create a List wrapper when a ListItem
|
|
155
|
+
* is relocated to a context that doesn't have a List parent.
|
|
156
|
+
* props() reads this.parent (stale Svelte state) which still points to the
|
|
157
|
+
* original List at relocation time, giving us the correct listType.
|
|
158
|
+
* @returns {{ type: string, props: () => Record<string, any> }}
|
|
159
|
+
*/
|
|
160
|
+
get requiredParent() {
|
|
161
|
+
return {
|
|
162
|
+
type: "list",
|
|
163
|
+
props: () => ({
|
|
164
|
+
listType: this.parent?.behaviors?.get("list")?.listType || "bullet"
|
|
165
|
+
})
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
65
169
|
/**
|
|
66
170
|
* Retourne la sous-liste existante, ou en crée une nouvelle à la fin des enfants.
|
|
67
171
|
* @param {"bullet" | "ordered"} [listType="bullet"]
|
|
@@ -76,94 +180,15 @@ export class ListItem extends MegaBlock {
|
|
|
76
180
|
|
|
77
181
|
/** @param {KeyboardEvent} event */
|
|
78
182
|
keydown(event) {
|
|
79
|
-
if (event.key ===
|
|
80
|
-
event.preventDefault();
|
|
81
|
-
|
|
183
|
+
if (event.key === 'Tab') {
|
|
184
|
+
event.preventDefault();
|
|
82
185
|
if (event.shiftKey) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// 1. Notre parent immédiat (une List)
|
|
86
|
-
const parentListNode = this.node.parent();
|
|
87
|
-
if (!parentListNode) return true;
|
|
88
|
-
|
|
89
|
-
// 2. Le ListItem qui contient cette liste (le "grand-parent" logique)
|
|
90
|
-
const grandParentItemNode = parentListNode.parent();
|
|
91
|
-
|
|
92
|
-
// Si on n'a pas de ListItem au-dessus (on est déjà au premier niveau)
|
|
93
|
-
if (!grandParentItemNode || grandParentItemNode.data.get("type") !== "list-item") {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 3. Gérer le "Carry" : emporter les frères suivants avec nous
|
|
98
|
-
const myIndex = this.node.index();
|
|
99
|
-
const siblings = parentListNode.children();
|
|
100
|
-
const followers = siblings.slice(myIndex + 1);
|
|
101
|
-
|
|
102
|
-
if (followers.length > 0) {
|
|
103
|
-
// On s'assure d'avoir notre propre sous-liste pour accueillir nos anciens frères
|
|
104
|
-
const mySublist = this.getOrCreateSublist();
|
|
105
|
-
for (const follower of followers) {
|
|
106
|
-
this.nabu.tree.move(follower.id.toString(), mySublist.node.id.toString());
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 4. Le parent cible est la List qui contient notre grand-parent
|
|
111
|
-
const targetParentListNode = grandParentItemNode.parent();
|
|
112
|
-
if (!targetParentListNode) return true;
|
|
113
|
-
|
|
114
|
-
// 5. On se place juste après notre ancien grand-parent
|
|
115
|
-
const targetIndex = grandParentItemNode.index() + 1;
|
|
116
|
-
|
|
117
|
-
this.nabu.tree.move(this.node.id.toString(), targetParentListNode.id.toString(), targetIndex);
|
|
118
|
-
|
|
119
|
-
this.commit();
|
|
120
|
-
|
|
121
|
-
// 6. Restauration du focus
|
|
122
|
-
setTimeout(() => this.behavior.block.focus(), 0);
|
|
186
|
+
unindentListItem(this);
|
|
123
187
|
} else {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// 1. On trouve notre index actuel
|
|
127
|
-
const currentIndex = this.node.index();
|
|
128
|
-
if (currentIndex === 0) return true; // Impossible d'indenter le premier item
|
|
129
|
-
|
|
130
|
-
// 2. On trouve le frère précédent (qui va devenir notre parent "logique")
|
|
131
|
-
const parentList = this.node.parent();
|
|
132
|
-
if (!parentList) return true;
|
|
133
|
-
|
|
134
|
-
const previousNode = parentList.children()?.[currentIndex - 1];
|
|
135
|
-
if (!previousNode) return true;
|
|
136
|
-
const previousItem = this.nabu.blocks.get(previousNode.id.toString());
|
|
137
|
-
|
|
138
|
-
// Si le frère précédent n'est pas un ListItem
|
|
139
|
-
if (!previousItem || previousItem.type !== "list-item") return true;
|
|
140
|
-
|
|
141
|
-
// 3. On demande au frère précédent sa sous-liste (ou de la créer)
|
|
142
|
-
// @ts-ignore : On sait que c'est un ListItem
|
|
143
|
-
const targetSublist = previousItem.getOrCreateSublist();
|
|
144
|
-
const targetSublistId = targetSublist.node.id.toString();
|
|
145
|
-
|
|
146
|
-
// 4. On se déplace à la fin de cette sous-liste cible
|
|
147
|
-
this.nabu.tree.move(this.node.id.toString(), targetSublistId);
|
|
148
|
-
|
|
149
|
-
// 5. Si on avait des enfants (Hoist), on les remonte avec nous en tant que frères
|
|
150
|
-
if (this.sublist) {
|
|
151
|
-
const childrenNodes = this.sublist.node.children();
|
|
152
|
-
for (const childNode of childrenNodes) {
|
|
153
|
-
// Ils se placeront après nous dans la nouvelle liste
|
|
154
|
-
this.nabu.tree.move(childNode.id.toString(), targetSublistId);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this.commit();
|
|
159
|
-
|
|
160
|
-
// 6. On restaure le curseur
|
|
161
|
-
setTimeout(() => this.behavior.block.focus(), 0);
|
|
188
|
+
indentListItem(this);
|
|
162
189
|
}
|
|
163
190
|
return true;
|
|
164
191
|
}
|
|
165
|
-
|
|
166
|
-
// On délègue les flèches etc.
|
|
167
192
|
return false;
|
|
168
193
|
}
|
|
169
194
|
|
|
@@ -178,7 +203,7 @@ export class ListItem extends MegaBlock {
|
|
|
178
203
|
*/
|
|
179
204
|
getDOMPoint(targetOffset) { return this.behavior.getDOMPoint(targetOffset); }
|
|
180
205
|
|
|
181
|
-
/** @param {import('../block.svelte').Block} block */
|
|
206
|
+
/** @param {import('../block.svelte.js').Block} block */
|
|
182
207
|
absorbs(block) { return this.behavior.absorbs(block); }
|
|
183
208
|
|
|
184
209
|
|
|
@@ -186,13 +211,13 @@ export class ListItem extends MegaBlock {
|
|
|
186
211
|
/** @param {number} index @param {string} text */
|
|
187
212
|
insert(index, text) { return this.behavior.insert(index, text); }
|
|
188
213
|
|
|
189
|
-
/** @param {Parameters<import('../block.svelte').Block["delete"]>[0]} [deletion] */
|
|
214
|
+
/** @param {Parameters<import('../block.svelte.js').Block["delete"]>[0]} [deletion] */
|
|
190
215
|
delete(deletion) { return this.behavior.delete(deletion); }
|
|
191
216
|
|
|
192
217
|
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
193
218
|
applyDelta(data = []) { return this.behavior.applyDelta(data); }
|
|
194
219
|
|
|
195
|
-
/** @param {Parameters<import('../block.svelte').Block["split"]>[0]} [options] @returns {ReturnType<import('../block.svelte').Block["split"]>} */
|
|
220
|
+
/** @param {Parameters<import('../block.svelte.js').Block["split"]>[0]} [options] @returns {ReturnType<import('../block.svelte.js').Block["split"]>} */
|
|
196
221
|
split(options) {
|
|
197
222
|
return this.ascend("onSplit", null, {
|
|
198
223
|
offset: options?.offset || 0,
|
|
@@ -200,6 +225,49 @@ export class ListItem extends MegaBlock {
|
|
|
200
225
|
});
|
|
201
226
|
}
|
|
202
227
|
|
|
228
|
+
/**
|
|
229
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
230
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string, listType?: string, index?: number, depth?: number }} helpers
|
|
231
|
+
*/
|
|
232
|
+
static toMarkdown(pb, { recurse, listType = 'bullet', index = 0, depth = 0 }) {
|
|
233
|
+
const indent = ' '.repeat(depth);
|
|
234
|
+
const prefix = listType === 'ordered' ? `${index + 1}.` : '-';
|
|
235
|
+
const text = deltaToMarkdown(pb.delta || []);
|
|
236
|
+
const sublists = (pb.children || []).map(sub => recurse(sub, { depth: depth + 1 })).join('\n');
|
|
237
|
+
return `${indent}${prefix} ${text}${sublists ? '\n' + sublists : ''}`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
242
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
243
|
+
*/
|
|
244
|
+
static toHtml(pb, { recurse }) {
|
|
245
|
+
const text = deltaToHtml(pb.delta || []);
|
|
246
|
+
const sublists = (pb.children || []).map(recurse).join('');
|
|
247
|
+
return `<li>${text}${sublists}</li>`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
static htmlRules = [{ selector: 'li' }];
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @param {Element} el
|
|
254
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[], parseBlock: (el: Element) => import('../../utils/extensions.js').PasteBlock | null }} helpers
|
|
255
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
256
|
+
*/
|
|
257
|
+
static fromHTML(el, { parseInline, parseBlock }) {
|
|
258
|
+
const delta = parseInline(el);
|
|
259
|
+
const childLists = /** @type {import('../../utils/extensions.js').PasteBlock[]} */ (
|
|
260
|
+
[...el.children]
|
|
261
|
+
.filter(child => child.matches('ul, ol'))
|
|
262
|
+
.map(parseBlock)
|
|
263
|
+
.filter(Boolean)
|
|
264
|
+
);
|
|
265
|
+
/** @type {import('../../utils/extensions.js').PasteBlock} */
|
|
266
|
+
const result = { type: 'list-item', delta, partial: false };
|
|
267
|
+
if (childLists.length) result.children = childLists;
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
|
|
203
271
|
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
204
272
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
205
273
|
const node = nabu.tree.createNode(parentId || undefined, index || undefined);
|
|
@@ -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) {
|
|
@@ -1,18 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { Nabu, NabuNode } from "../nabu.svelte";
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered"}>} ListNode
|
|
6
6
|
*/
|
|
7
7
|
export class List extends MegaBlock {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
10
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string, depth?: number }} helpers
|
|
11
|
+
*/
|
|
12
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { recurse, depth }: {
|
|
13
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock, ctx?: object) => string;
|
|
14
|
+
depth?: number;
|
|
15
|
+
}): string;
|
|
16
|
+
/**
|
|
17
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
18
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
19
|
+
*/
|
|
20
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
21
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock) => string;
|
|
22
|
+
}): string;
|
|
23
|
+
static markdownRules: {
|
|
24
|
+
priority: number;
|
|
25
|
+
detect: RegExp;
|
|
26
|
+
consume(lines: string[], i: number): number;
|
|
27
|
+
}[];
|
|
28
|
+
/**
|
|
29
|
+
* Parse markdown list lines into a nested List/ListItem PasteBlock tree.
|
|
30
|
+
* Uses indent depth to reconstruct nesting recursively.
|
|
31
|
+
*
|
|
32
|
+
* @param {string[]} lines
|
|
33
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
34
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
35
|
+
*/
|
|
36
|
+
static fromMarkdown(lines: string[], { parseInline }: {
|
|
37
|
+
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
38
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
39
|
+
static htmlRules: {
|
|
40
|
+
selector: string;
|
|
41
|
+
props: {
|
|
42
|
+
listType: string;
|
|
43
|
+
};
|
|
44
|
+
}[];
|
|
45
|
+
/**
|
|
46
|
+
* @param {Element} el
|
|
47
|
+
* @param {{ parseChildren: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
48
|
+
* @param {{ props?: { listType?: string } }} [rule]
|
|
49
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
50
|
+
*/
|
|
51
|
+
static fromHTML(el: Element, { parseChildren }: {
|
|
52
|
+
parseChildren: (el: Element) => import("../../utils/extensions.js").PasteBlock[];
|
|
53
|
+
}, rule?: {
|
|
54
|
+
props?: {
|
|
55
|
+
listType?: string;
|
|
56
|
+
};
|
|
57
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
8
58
|
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
9
59
|
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): List;
|
|
10
60
|
/** @param {Nabu} nabu @param {ListNode} node */
|
|
11
61
|
constructor(nabu: Nabu, node: ListNode);
|
|
12
62
|
behavior: ListBehavior;
|
|
13
63
|
listType: "bullet" | "ordered";
|
|
64
|
+
get clipboardProps(): {
|
|
65
|
+
listType: "bullet" | "ordered";
|
|
66
|
+
};
|
|
14
67
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
15
|
-
block: import("./list.svelte").List;
|
|
68
|
+
block: import("./list.svelte.js").List;
|
|
16
69
|
}, {}, "">;
|
|
17
70
|
root: boolean;
|
|
18
71
|
/** @param {List} otherList */
|
|
@@ -26,14 +79,14 @@ export class List extends MegaBlock {
|
|
|
26
79
|
offset: number;
|
|
27
80
|
delta: import("loro-crdt").Delta<string>;
|
|
28
81
|
}): {
|
|
29
|
-
block: import("
|
|
82
|
+
block: import("../block.svelte.js").Block;
|
|
30
83
|
};
|
|
31
84
|
}
|
|
32
85
|
export type ListNode = NabuNode<{
|
|
33
86
|
type: "list";
|
|
34
87
|
listType: "bullet" | "ordered";
|
|
35
88
|
}>;
|
|
36
|
-
import { MegaBlock } from "../megablock.svelte";
|
|
37
|
-
import { ListBehavior } from "./list.behavior.svelte";
|
|
38
|
-
import type { Nabu } from "../nabu.svelte";
|
|
39
|
-
import type { NabuNode } from "../nabu.svelte";
|
|
89
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
90
|
+
import { ListBehavior } from "./list.behavior.svelte.js";
|
|
91
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
92
|
+
import type { NabuNode } from "../nabu.svelte.js";
|