@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
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { tick } from "svelte";
|
|
2
|
+
import { TextBehavior } from "../../../behaviors/text";
|
|
3
|
+
import { Dialogue } from "../dialogue.svelte.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import { Nabu, Block } from "../../..";
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @param {Nabu} nabu @param {InputEvent} event @param {Block} block */
|
|
10
|
+
export const onBeforeInput = (nabu, event, block) => {
|
|
11
|
+
const { BREAK, CONTINUE } = nabu;
|
|
12
|
+
|
|
13
|
+
// Backspace au début d'un bloc dialogue → retour en paragraphe
|
|
14
|
+
if (event.inputType === "deleteContentBackward" && block instanceof Dialogue) {
|
|
15
|
+
const behavior = block.behaviors.get("text");
|
|
16
|
+
if (!behavior || !(behavior instanceof TextBehavior)) return CONTINUE;
|
|
17
|
+
const sel = behavior.selection;
|
|
18
|
+
if (!sel || !sel.isCollapsed || sel.from !== 0) return CONTINUE;
|
|
19
|
+
const blockId = block.node.id.toString();
|
|
20
|
+
block.transformTo("paragraph");
|
|
21
|
+
tick().then(() => {
|
|
22
|
+
const b = nabu.blocks.get(blockId);
|
|
23
|
+
if (b) b.focus({ start: 0, end: 0 });
|
|
24
|
+
});
|
|
25
|
+
return BREAK;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// `-- ` en début de paragraphe → transforme en bloc dialogue
|
|
29
|
+
if (event.data !== " ") return CONTINUE;
|
|
30
|
+
if (block.type !== "paragraph") return CONTINUE;
|
|
31
|
+
|
|
32
|
+
const behavior = block.behaviors.get("text");
|
|
33
|
+
if (!behavior || !(behavior instanceof TextBehavior)) return CONTINUE;
|
|
34
|
+
|
|
35
|
+
const sel = behavior.selection;
|
|
36
|
+
if (!sel || !sel.isCollapsed) return CONTINUE;
|
|
37
|
+
|
|
38
|
+
const textBeforeCursor = behavior.text.slice(0, sel.from);
|
|
39
|
+
if (textBeforeCursor !== "--") return CONTINUE;
|
|
40
|
+
|
|
41
|
+
behavior.delete({ index: 0, length: 2 });
|
|
42
|
+
|
|
43
|
+
const blockId = block.node.id.toString();
|
|
44
|
+
block.transformTo("dialogue");
|
|
45
|
+
|
|
46
|
+
tick().then(() => {
|
|
47
|
+
const b = nabu.blocks.get(blockId);
|
|
48
|
+
if (b) b.focus({ start: 0, end: 0 });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return BREAK;
|
|
52
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { tick } from "svelte";
|
|
2
|
+
import { extension } from "../../utils/extensions";
|
|
3
|
+
import { Dialogue } from "./dialogue.svelte.js";
|
|
4
|
+
import DialogueComponent from "./Dialogue.svelte";
|
|
5
|
+
import { onBeforeInput } from "./hooks/onBeforeInput.hook.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import { Nabu } from "../nabu.svelte.js";
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const DialogueExtension = extension("dialogue", {
|
|
12
|
+
block: Dialogue,
|
|
13
|
+
component: DialogueComponent,
|
|
14
|
+
hooks: {
|
|
15
|
+
/** @param {Nabu} nabu @param {Dialogue} block @param {Event} event @param {{offset: number, delta: import('loro-crdt').Delta<string>}} data */
|
|
16
|
+
onSplit: (nabu, block, event, data) => {
|
|
17
|
+
const { offset, delta } = data;
|
|
18
|
+
|
|
19
|
+
// Bloc dialogue vide + Entrée → sortir du mode dialogue
|
|
20
|
+
if (block.text.length === 0) {
|
|
21
|
+
const blockId = block.node.id.toString();
|
|
22
|
+
block.transformTo("paragraph");
|
|
23
|
+
tick().then(() => {
|
|
24
|
+
const b = nabu.blocks.get(blockId);
|
|
25
|
+
if (b) b.focus({ start: 0, end: 0 });
|
|
26
|
+
});
|
|
27
|
+
return { block };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Bloc non vide + Entrée → créer un nouveau bloc dialogue après
|
|
31
|
+
block.delete({ from: offset, to: -1 });
|
|
32
|
+
|
|
33
|
+
const currentIndex = block.node.index();
|
|
34
|
+
const parent = block.node.parent();
|
|
35
|
+
const parentId = parent?.id.toString() || null;
|
|
36
|
+
|
|
37
|
+
const newBlock = nabu.insert("dialogue", { delta }, parentId, currentIndex + 1);
|
|
38
|
+
|
|
39
|
+
block.commit().then(() => nabu.selection.setCursor(newBlock, 0));
|
|
40
|
+
|
|
41
|
+
return { block: newBlock };
|
|
42
|
+
},
|
|
43
|
+
onBeforeInput,
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export { DialogueExtension, DialogueComponent, Dialogue };
|
|
@@ -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}
|
|
@@ -17,19 +18,22 @@
|
|
|
17
18
|
|
|
18
19
|
<style>
|
|
19
20
|
.nabu-heading {
|
|
20
|
-
margin-top:
|
|
21
|
+
margin-top: 0rem;
|
|
21
22
|
margin-bottom: 0.5rem;
|
|
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
|
|
|
@@ -1,11 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { Nabu, NabuNode } from "../nabu.svelte";
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
3
|
* @import { TextNode } from "../../behaviors/text";
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {NabuNode<{type: "heading", text: LoroText, level: number}>} HeadingNode
|
|
7
7
|
*/
|
|
8
8
|
export class Heading extends Block {
|
|
9
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
10
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
11
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
12
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
13
|
+
static markdownRules: {
|
|
14
|
+
priority: number;
|
|
15
|
+
detect: RegExp;
|
|
16
|
+
consume: () => number;
|
|
17
|
+
}[];
|
|
18
|
+
/**
|
|
19
|
+
* @param {string[]} lines
|
|
20
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
21
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
22
|
+
*/
|
|
23
|
+
static fromMarkdown(lines: string[], { parseInline }: {
|
|
24
|
+
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
25
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
26
|
+
static htmlRules: {
|
|
27
|
+
selector: string;
|
|
28
|
+
props: {
|
|
29
|
+
level: number;
|
|
30
|
+
};
|
|
31
|
+
}[];
|
|
32
|
+
/**
|
|
33
|
+
* @param {Element} el
|
|
34
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
|
|
35
|
+
* @param {{ props?: { level?: number } }} [rule]
|
|
36
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
37
|
+
*/
|
|
38
|
+
static fromHTML(el: Element, { parseInline }: {
|
|
39
|
+
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
40
|
+
}, rule?: {
|
|
41
|
+
props?: {
|
|
42
|
+
level?: number;
|
|
43
|
+
};
|
|
44
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
9
45
|
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
10
46
|
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): Heading;
|
|
11
47
|
/** @param {Nabu} nabu @param {HeadingNode} node */
|
|
@@ -38,8 +74,8 @@ export type HeadingNode = NabuNode<{
|
|
|
38
74
|
text: LoroText;
|
|
39
75
|
level: number;
|
|
40
76
|
}>;
|
|
41
|
-
import { Block } from "../block.svelte";
|
|
77
|
+
import { Block } from "../block.svelte.js";
|
|
42
78
|
import { LoroText } from "loro-crdt";
|
|
43
79
|
import { TextBehavior } from "../../behaviors/text";
|
|
44
|
-
import type { Nabu } from "../nabu.svelte";
|
|
45
|
-
import type { NabuNode } from "../nabu.svelte";
|
|
80
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
81
|
+
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { TextBehavior } from "../../behaviors/text";
|
|
1
|
+
import { TextBehavior, deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
2
2
|
import HeadingComponent from "./Heading.svelte";
|
|
3
|
-
import { Block } from "../block.svelte";
|
|
3
|
+
import { Block } from "../block.svelte.js";
|
|
4
4
|
import { LoroText } from "loro-crdt";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @import { Nabu, NabuNode } from "../nabu.svelte";
|
|
7
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
8
8
|
* @import { TextNode } from "../../behaviors/text";
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -32,6 +32,7 @@ export class Heading extends Block {
|
|
|
32
32
|
props: { level: this.level },
|
|
33
33
|
content: this.behavior.toJSON()
|
|
34
34
|
}));
|
|
35
|
+
this.serializers.set('application/x-nabu+json', (ctx) => this.behavior.toClipboardBlock({ ...ctx, props: { level: this.level } }));
|
|
35
36
|
|
|
36
37
|
// Synchronisation du niveau
|
|
37
38
|
this.node.data.subscribe(() => {
|
|
@@ -53,7 +54,8 @@ export class Heading extends Block {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
selection = $derived(this.behavior.selection);
|
|
56
|
-
|
|
57
|
+
positions = $derived(this.behavior.positions);
|
|
58
|
+
|
|
57
59
|
/** @param {InputEvent} event */
|
|
58
60
|
beforeinput(event) {
|
|
59
61
|
return this.behavior.handleBeforeInput(event);
|
|
@@ -80,6 +82,60 @@ export class Heading extends Block {
|
|
|
80
82
|
/** @param {Parameters<Block["split"]>[0]} [options] @returns {ReturnType<Block["split"]>} */
|
|
81
83
|
split(options) { return this.behavior.split(options); }
|
|
82
84
|
|
|
85
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
86
|
+
static toMarkdown(pb) {
|
|
87
|
+
const level = pb.props?.level ?? 1;
|
|
88
|
+
return `${'#'.repeat(level)} ${deltaToMarkdown(pb.delta || [])}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
92
|
+
static toHtml(pb) {
|
|
93
|
+
const level = pb.props?.level ?? 1;
|
|
94
|
+
return `<h${level}>${deltaToHtml(pb.delta || [])}</h${level}>`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static markdownRules = [
|
|
98
|
+
{
|
|
99
|
+
priority: 10,
|
|
100
|
+
detect: /^#{1,6} /,
|
|
101
|
+
consume: () => 1,
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {string[]} lines
|
|
107
|
+
* @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
|
|
108
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
109
|
+
*/
|
|
110
|
+
static fromMarkdown(lines, { parseInline }) {
|
|
111
|
+
const m = lines[0].match(/^(#{1,6})\s+(.*)/);
|
|
112
|
+
if (!m) return null;
|
|
113
|
+
const delta = parseInline(m[2]);
|
|
114
|
+
if (!delta.length) return null;
|
|
115
|
+
return { type: 'heading', props: { level: m[1].length }, delta, partial: false };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static htmlRules = [
|
|
119
|
+
{ selector: 'h1', props: { level: 1 } },
|
|
120
|
+
{ selector: 'h2', props: { level: 2 } },
|
|
121
|
+
{ selector: 'h3', props: { level: 3 } },
|
|
122
|
+
{ selector: 'h4', props: { level: 4 } },
|
|
123
|
+
{ selector: 'h5', props: { level: 5 } },
|
|
124
|
+
{ selector: 'h6', props: { level: 6 } },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {Element} el
|
|
129
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
|
|
130
|
+
* @param {{ props?: { level?: number } }} [rule]
|
|
131
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
132
|
+
*/
|
|
133
|
+
static fromHTML(el, { parseInline }, rule) {
|
|
134
|
+
const delta = parseInline(el);
|
|
135
|
+
if (!delta.length) return null;
|
|
136
|
+
return { type: 'heading', props: { level: rule?.props?.level ?? 1 }, delta, partial: false };
|
|
137
|
+
}
|
|
138
|
+
|
|
83
139
|
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
84
140
|
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
85
141
|
const node = nabu.tree.createNode(parentId || undefined, index || undefined);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { Nabu } from "../nabu.svelte";
|
|
2
|
+
* @import { Nabu } from "../nabu.svelte.js";
|
|
3
3
|
*/
|
|
4
4
|
export const HeadingExtension: import("../..").Extension;
|
|
5
5
|
import HeadingComponent from "./Heading.svelte";
|
|
6
|
-
import { Heading } from "./heading.svelte";
|
|
6
|
+
import { Heading } from "./heading.svelte.js";
|
|
7
7
|
export { HeadingComponent, Heading };
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { tick } from "svelte";
|
|
2
2
|
import { TextBehavior } from "../../behaviors/text";
|
|
3
3
|
import { extension } from "../../utils/extensions";
|
|
4
|
-
import { Heading } from "./heading.svelte";
|
|
4
|
+
import { Heading } from "./heading.svelte.js";
|
|
5
5
|
import HeadingComponent from "./Heading.svelte";
|
|
6
6
|
import { onBeforeInput } from "./hooks/onBeforeInput.hook";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @import { Nabu } from "../nabu.svelte";
|
|
9
|
+
* @import { Nabu } from "../nabu.svelte.js";
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const HeadingExtension = extension("heading", {
|
|
13
13
|
block: Heading,
|
|
14
14
|
component: HeadingComponent,
|
|
15
|
+
actions: {
|
|
16
|
+
'heading:1': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 1 } }),
|
|
17
|
+
'heading:2': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 2 } }),
|
|
18
|
+
'heading:3': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 3 } }),
|
|
19
|
+
'heading:4': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 4 } }),
|
|
20
|
+
'heading:5': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 5 } }),
|
|
21
|
+
'heading:6': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 6 } }),
|
|
22
|
+
},
|
|
15
23
|
hooks: {
|
|
16
24
|
/** @param {Nabu} nabu @param {Heading} block @param {Event} event @param {{offset: number, delta: import('loro-crdt').Delta<string>}} data */
|
|
17
25
|
onSplit: (nabu, block, event, data) => {
|
|
@@ -26,11 +34,7 @@ const HeadingExtension = extension("heading", {
|
|
|
26
34
|
// On split souvent un titre pour créer un paragraphe après
|
|
27
35
|
const newBlock = nabu.insert("paragraph", { delta }, parentId, currentIndex + 1);
|
|
28
36
|
|
|
29
|
-
block.commit();
|
|
30
|
-
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
nabu.selection.setCursor(newBlock, 0);
|
|
33
|
-
}, 0);
|
|
37
|
+
block.commit().then(() => nabu.selection.setCursor(newBlock, 0));
|
|
34
38
|
|
|
35
39
|
return { block: newBlock };
|
|
36
40
|
},
|
package/dist/blocks/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export * from "./block.svelte";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./block.svelte.js";
|
|
2
|
+
export * from "./block.extension.js";
|
|
3
|
+
export * from "./nabu.svelte.js";
|
|
4
|
+
export * from "./megablock.svelte.js";
|
|
4
5
|
export * from "./container.utils";
|
|
5
6
|
export * from "./paragraph";
|
|
6
7
|
export * from "./heading";
|
|
7
8
|
export * from "./list";
|
|
8
|
-
export * from "./
|
|
9
|
+
export * from "./dialogue";
|
|
10
|
+
export * from "./zone";
|
|
11
|
+
export * from "./selection.svelte.js";
|
|
9
12
|
export { default as NabuEditor } from "./Nabu.svelte";
|
|
10
13
|
export { default as BlockComponent } from "./Block.svelte";
|
package/dist/blocks/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./block.svelte";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./block.svelte.js";
|
|
2
|
+
export * from "./block.extension.js";
|
|
3
|
+
export * from "./nabu.svelte.js";
|
|
4
|
+
export * from "./megablock.svelte.js";
|
|
4
5
|
export { default as NabuEditor } from "./Nabu.svelte";
|
|
5
6
|
export { default as BlockComponent } from "./Block.svelte";
|
|
6
7
|
export * from "./container.utils";
|
|
@@ -8,5 +9,7 @@ export * from "./container.utils";
|
|
|
8
9
|
export * from "./paragraph";
|
|
9
10
|
export * from "./heading";
|
|
10
11
|
export * from "./list";
|
|
12
|
+
export * from "./dialogue";
|
|
13
|
+
export * from "./zone";
|
|
11
14
|
|
|
12
|
-
export * from "./selection.svelte";
|
|
15
|
+
export * from "./selection.svelte.js";
|
|
@@ -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 {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { tick } from "svelte";
|
|
2
|
+
import { TextBehavior } from "../../../behaviors/text";
|
|
3
|
+
import { List } from "../list.svelte.js";
|
|
4
|
+
import { ListItem } from "../list-item.svelte.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @import { Nabu, Block } from "../..";
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Markdown shortcut: typing "- " or "1. " at the start of an empty/new paragraph
|
|
12
|
+
* converts it into a list item inside a new bullet/ordered list.
|
|
13
|
+
*
|
|
14
|
+
* @param {Nabu} nabu
|
|
15
|
+
* @param {InputEvent} event
|
|
16
|
+
* @param {Block} block
|
|
17
|
+
*/
|
|
18
|
+
export const onBeforeInput = (nabu, event, block) => {
|
|
19
|
+
const { BREAK, CONTINUE } = nabu;
|
|
20
|
+
|
|
21
|
+
if (event.data !== " ") return CONTINUE;
|
|
22
|
+
if (block.type !== "paragraph") return CONTINUE;
|
|
23
|
+
|
|
24
|
+
const behavior = block.behaviors.get("text");
|
|
25
|
+
if (!behavior || !(behavior instanceof TextBehavior)) return CONTINUE;
|
|
26
|
+
|
|
27
|
+
const sel = behavior.selection;
|
|
28
|
+
if (!sel || !sel.isCollapsed) return CONTINUE;
|
|
29
|
+
|
|
30
|
+
const textBeforeCursor = behavior.text.slice(0, sel.from);
|
|
31
|
+
|
|
32
|
+
/** @type {"bullet" | "ordered" | null} */
|
|
33
|
+
let listType = null;
|
|
34
|
+
let prefixLength = 0;
|
|
35
|
+
|
|
36
|
+
if (textBeforeCursor.match(/^-$/)) {
|
|
37
|
+
listType = "bullet";
|
|
38
|
+
prefixLength = 1;
|
|
39
|
+
} else if (textBeforeCursor.match(/^\d+\.$/)) {
|
|
40
|
+
listType = "ordered";
|
|
41
|
+
prefixLength = textBeforeCursor.length;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!listType) return CONTINUE;
|
|
45
|
+
|
|
46
|
+
// Delete the prefix ("- " trigger: delete the "-"; "1. " trigger: delete the "1.")
|
|
47
|
+
behavior.delete({ index: 0, length: prefixLength });
|
|
48
|
+
|
|
49
|
+
// Capture remaining text delta (everything after the prefix)
|
|
50
|
+
const delta = behavior.container.toDelta();
|
|
51
|
+
|
|
52
|
+
// Get current tree position from live Loro state (pre-commit)
|
|
53
|
+
const parentNode = block.node.parent();
|
|
54
|
+
const parentId = parentNode?.id.toString() ?? null;
|
|
55
|
+
const index = block.node.index();
|
|
56
|
+
|
|
57
|
+
// Create the List at the same position as the paragraph
|
|
58
|
+
const list = List.create(nabu, "list", { listType }, parentId, index);
|
|
59
|
+
|
|
60
|
+
// Create the ListItem inside the list with the captured content
|
|
61
|
+
const listItem = ListItem.create(nabu, "list-item", { delta }, list.node.id.toString());
|
|
62
|
+
|
|
63
|
+
// Destroy the original paragraph (no commit)
|
|
64
|
+
block.destroy();
|
|
65
|
+
|
|
66
|
+
// Commit the whole operation as a single transaction
|
|
67
|
+
nabu.commit();
|
|
68
|
+
|
|
69
|
+
// Restore focus to the new list-item
|
|
70
|
+
const listItemId = listItem.node.id.toString();
|
|
71
|
+
tick().then(() => {
|
|
72
|
+
const updatedListItem = nabu.blocks.get(listItemId);
|
|
73
|
+
if (updatedListItem) updatedListItem.focus({ start: 0, end: 0 });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return BREAK;
|
|
77
|
+
};
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const ListExtension: import("../..").Extension;
|
|
5
5
|
export const ListItemExtension: import("../..").Extension;
|
|
6
|
-
import { List } from "./list.svelte";
|
|
7
|
-
import { ListItem } from "./list-item.svelte";
|
|
6
|
+
import { List } from "./list.svelte.js";
|
|
7
|
+
import { ListItem } from "./list-item.svelte.js";
|
|
8
8
|
import ListComponent from "./List.svelte";
|
|
9
9
|
import ListItemComponent from "./ListItem.svelte";
|
|
10
10
|
export { List, ListItem, ListComponent, ListItemComponent };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { extension } from "../../utils/extensions";
|
|
2
|
-
import { List } from "./list.svelte";
|
|
2
|
+
import { List } from "./list.svelte.js";
|
|
3
3
|
import ListComponent from "./List.svelte";
|
|
4
|
-
import { ListItem } from "./list-item.svelte";
|
|
4
|
+
import { ListItem, indentListItem, unindentListItem } from "./list-item.svelte.js";
|
|
5
5
|
import ListItemComponent from "./ListItem.svelte";
|
|
6
|
-
import { ListBehavior } from "./list.behavior.svelte";
|
|
6
|
+
import { ListBehavior } from "./list.behavior.svelte.js";
|
|
7
|
+
import { onBeforeInput } from "./hooks/onBeforeInput.hook.js";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @import {SvelteSet} from "svelte/reactivity";
|
|
@@ -13,6 +14,7 @@ const ListExtension = extension("list", {
|
|
|
13
14
|
block: List,
|
|
14
15
|
component: ListComponent,
|
|
15
16
|
hooks: {
|
|
17
|
+
onBeforeInput,
|
|
16
18
|
onBeforeTransaction(nabu) {
|
|
17
19
|
const lists = /** @type {SvelteSet<List>} */ (nabu.blocksByType.get("list"));
|
|
18
20
|
lists?.forEach(list => {
|
|
@@ -36,6 +38,18 @@ const ListExtension = extension("list", {
|
|
|
36
38
|
const ListItemExtension = extension("list-item", {
|
|
37
39
|
block: ListItem,
|
|
38
40
|
component: ListItemComponent,
|
|
41
|
+
actions: {
|
|
42
|
+
'list:indent': (nabu) => {
|
|
43
|
+
const block = nabu.selection.anchorBlock;
|
|
44
|
+
if (block?.type !== 'list-item') return;
|
|
45
|
+
indentListItem(/** @type {ListItem} */ (block));
|
|
46
|
+
},
|
|
47
|
+
'list:unindent': (nabu) => {
|
|
48
|
+
const block = nabu.selection.anchorBlock;
|
|
49
|
+
if (block?.type !== 'list-item') return;
|
|
50
|
+
unindentListItem(/** @type {ListItem} */ (block));
|
|
51
|
+
},
|
|
52
|
+
}
|
|
39
53
|
});
|
|
40
54
|
|
|
41
55
|
export { ListExtension, ListItemExtension, List, ListItem, ListComponent, ListItemComponent };
|