@aionbuilders/nabu 0.1.0-alpha.9 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -9
- package/dist/behaviors/text/RichText.svelte +4 -1
- package/dist/behaviors/text/index.d.ts +2 -0
- package/dist/behaviors/text/index.js +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +54 -0
- package/dist/behaviors/text/rich-text.extension.js +47 -22
- package/dist/behaviors/text/text.behavior.svelte.d.ts +25 -1
- package/dist/behaviors/text/text.behavior.svelte.js +154 -18
- package/dist/behaviors/text/typography.extension.d.ts +6 -0
- package/dist/behaviors/text/typography.extension.js +24 -0
- package/dist/blocks/Block.svelte +5 -2
- package/dist/blocks/Nabu.svelte +22 -0
- package/dist/blocks/block.extension.js +10 -8
- package/dist/blocks/block.svelte.d.ts +24 -0
- package/dist/blocks/block.svelte.js +35 -0
- package/dist/blocks/blockquote/Blockquote.svelte +40 -0
- package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
- package/dist/blocks/blockquote/blockquote.extension.d.ts +1 -0
- package/dist/blocks/blockquote/blockquote.extension.js +71 -0
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +55 -0
- package/dist/blocks/blockquote/blockquote.svelte.js +91 -0
- package/dist/blocks/blockquote/index.d.ts +3 -0
- package/dist/blocks/blockquote/index.js +3 -0
- package/dist/blocks/callout/Callout.svelte +69 -0
- package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
- package/dist/blocks/callout/callout.extension.d.ts +1 -0
- package/dist/blocks/callout/callout.extension.js +68 -0
- package/dist/blocks/callout/callout.svelte.d.ts +78 -0
- package/dist/blocks/callout/callout.svelte.js +184 -0
- package/dist/blocks/callout/index.d.ts +3 -0
- package/dist/blocks/callout/index.js +3 -0
- package/dist/blocks/code/Code.svelte +85 -0
- package/dist/blocks/code/Code.svelte.d.ts +11 -0
- package/dist/blocks/code/code.extension.d.ts +1 -0
- package/dist/blocks/code/code.extension.js +68 -0
- package/dist/blocks/code/code.svelte.d.ts +61 -0
- package/dist/blocks/code/code.svelte.js +221 -0
- package/dist/blocks/code/index.d.ts +3 -0
- package/dist/blocks/code/index.js +3 -0
- package/dist/blocks/dialogue/Dialogue.svelte +2 -0
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +3 -21
- package/dist/blocks/dialogue/dialogue.svelte.js +2 -50
- package/dist/blocks/divider/Divider.svelte +28 -0
- package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
- package/dist/blocks/divider/divider.extension.d.ts +1 -0
- package/dist/blocks/divider/divider.extension.js +87 -0
- package/dist/blocks/divider/divider.svelte.d.ts +49 -0
- package/dist/blocks/divider/divider.svelte.js +84 -0
- package/dist/blocks/divider/index.d.ts +3 -0
- package/dist/blocks/divider/index.js +3 -0
- package/dist/blocks/file/File.svelte +49 -0
- package/dist/blocks/file/File.svelte.d.ts +11 -0
- package/dist/blocks/file/file.extension.d.ts +1 -0
- package/dist/blocks/file/file.extension.js +19 -0
- package/dist/blocks/file/file.svelte.d.ts +29 -0
- package/dist/blocks/file/file.svelte.js +71 -0
- package/dist/blocks/file/index.d.ts +3 -0
- package/dist/blocks/file/index.js +3 -0
- package/dist/blocks/heading/Heading.svelte +3 -1
- package/dist/blocks/heading/heading.svelte.d.ts +4 -23
- package/dist/blocks/heading/heading.svelte.js +4 -47
- package/dist/blocks/image/Image.svelte +38 -0
- package/dist/blocks/image/Image.svelte.d.ts +11 -0
- package/dist/blocks/image/image.extension.d.ts +2 -0
- package/dist/blocks/image/image.extension.js +26 -0
- package/dist/blocks/image/image.svelte.d.ts +50 -0
- package/dist/blocks/image/image.svelte.js +92 -0
- package/dist/blocks/image/index.d.ts +3 -0
- package/dist/blocks/image/index.js +3 -0
- package/dist/blocks/index.d.ts +10 -0
- package/dist/blocks/index.js +10 -0
- package/dist/blocks/list/List.svelte +8 -2
- package/dist/blocks/list/ListItem.svelte +43 -7
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +15 -2
- package/dist/blocks/list/index.d.ts +1 -0
- package/dist/blocks/list/index.js +1 -0
- package/dist/blocks/list/list-item.svelte.d.ts +14 -2
- package/dist/blocks/list/list-item.svelte.js +58 -7
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -4
- package/dist/blocks/list/list.behavior.svelte.js +5 -5
- package/dist/blocks/list/list.svelte.d.ts +13 -6
- package/dist/blocks/list/list.svelte.js +24 -6
- package/dist/blocks/list/todos.svelte.d.ts +35 -0
- package/dist/blocks/list/todos.svelte.js +76 -0
- package/dist/blocks/media/index.d.ts +2 -0
- package/dist/blocks/media/index.js +2 -0
- package/dist/blocks/media/media-block.svelte.d.ts +32 -0
- package/dist/blocks/media/media-block.svelte.js +69 -0
- package/dist/blocks/media/media.helpers.d.ts +19 -0
- package/dist/blocks/media/media.helpers.js +51 -0
- package/dist/blocks/megablock.svelte.js +1 -0
- package/dist/blocks/nabu.svelte.d.ts +94 -16
- package/dist/blocks/nabu.svelte.js +254 -3
- package/dist/blocks/paragraph/Paragraph.svelte +2 -0
- package/dist/blocks/paragraph/index.js +0 -3
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +3 -21
- package/dist/blocks/paragraph/paragraph.svelte.js +4 -53
- package/dist/blocks/selection.svelte.js +11 -1
- package/dist/blocks/text-block.svelte.d.ts +49 -0
- package/dist/blocks/text-block.svelte.js +74 -0
- package/dist/blocks/toggle/Toggle.svelte +84 -0
- package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
- package/dist/blocks/toggle/index.d.ts +3 -0
- package/dist/blocks/toggle/index.js +3 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +1 -0
- package/dist/blocks/toggle/toggle.extension.js +12 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +88 -0
- package/dist/blocks/toggle/toggle.svelte.js +252 -0
- package/dist/blocks/variable.svelte.d.ts +47 -0
- package/dist/blocks/variable.svelte.js +51 -0
- package/dist/blocks/video/Video.svelte +39 -0
- package/dist/blocks/video/Video.svelte.d.ts +11 -0
- package/dist/blocks/video/index.d.ts +3 -0
- package/dist/blocks/video/index.js +3 -0
- package/dist/blocks/video/video.extension.d.ts +1 -0
- package/dist/blocks/video/video.extension.js +19 -0
- package/dist/blocks/video/video.svelte.d.ts +28 -0
- package/dist/blocks/video/video.svelte.js +71 -0
- package/dist/blocks/zone/TemplateEditor.svelte +308 -0
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/Zone.svelte +158 -144
- 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/zone.extension.js +22 -6
- package/dist/blocks/zone/zone.svelte.d.ts +111 -2
- package/dist/blocks/zone/zone.svelte.js +304 -17
- package/dist/files/files.svelte.d.ts +61 -0
- package/dist/files/files.svelte.js +93 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/nabu-theme.css +92 -0
- package/dist/overlays/context/Context.svelte +182 -0
- package/dist/overlays/context/Context.svelte.d.ts +17 -0
- package/dist/overlays/context/collect.d.ts +17 -0
- package/dist/overlays/context/collect.js +33 -0
- package/dist/overlays/context/context.extension.d.ts +2 -0
- package/dist/overlays/context/context.extension.js +8 -0
- package/dist/overlays/context/context.svelte.d.ts +82 -0
- package/dist/overlays/context/context.svelte.js +159 -0
- package/dist/overlays/context/index.d.ts +3 -0
- package/dist/overlays/context/index.js +3 -0
- package/dist/paste/html.paste.js +9 -1
- package/dist/presets.d.ts +3 -1
- package/dist/presets.js +21 -6
- package/dist/ui/DragHandle.svelte +141 -0
- package/dist/ui/DragHandle.svelte.d.ts +11 -0
- package/dist/ui/FloatingToolbar.svelte +117 -0
- package/dist/ui/FloatingToolbar.svelte.d.ts +17 -0
- package/dist/ui/SlashMenu.svelte +83 -0
- package/dist/ui/SlashMenu.svelte.d.ts +13 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/slash-menu.svelte.d.ts +40 -0
- package/dist/ui/slash-menu.svelte.js +116 -0
- package/dist/utils/extensions.d.ts +54 -0
- package/dist/utils/extensions.js +40 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/placeholders.d.ts +10 -0
- package/dist/utils/placeholders.js +21 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +23 -0
- package/package.json +10 -5
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { MediaBlock } from "../media/media-block.svelte.js";
|
|
2
|
+
import ImageComponent from "./Image.svelte";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {NabuNode<{type: "image", ref: string, alt: string, status: string}>} ImageNode
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Void image block. Extends MediaBlock for shared void/metadata behavior.
|
|
14
|
+
* No editable text — renders an inert <figure> with a single cursor position.
|
|
15
|
+
*/
|
|
16
|
+
// @ts-ignore — static-side variance on create()
|
|
17
|
+
export class ImageBlock extends MediaBlock {
|
|
18
|
+
/** @param {Nabu} nabu @param {ImageNode} node */
|
|
19
|
+
constructor(nabu, node) {
|
|
20
|
+
super(nabu, node);
|
|
21
|
+
|
|
22
|
+
this.serializers.set('markdown', () => '');
|
|
23
|
+
this.serializers.set('json', () => ({
|
|
24
|
+
id: this.id,
|
|
25
|
+
type: 'image',
|
|
26
|
+
props: { ref: this.ref, alt: this.alt },
|
|
27
|
+
}));
|
|
28
|
+
this.serializers.set('application/x-nabu+json', () => ({
|
|
29
|
+
type: 'image',
|
|
30
|
+
props: { ref: this.ref, alt: this.alt },
|
|
31
|
+
partial: false,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
component = $derived(this.nabu.components.get("image") || ImageComponent);
|
|
36
|
+
|
|
37
|
+
// ── Statics ──────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
40
|
+
static toMarkdown(pb) {
|
|
41
|
+
return ' + ')';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
45
|
+
static toHtml(pb) {
|
|
46
|
+
return '<img src="' + (pb.props?.ref || '') + '" alt="' + (pb.props?.alt || '') + '">';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static htmlRules = [
|
|
50
|
+
{ selector: 'img' },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {Element} el
|
|
55
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
56
|
+
*/
|
|
57
|
+
static fromHTML(el) {
|
|
58
|
+
return {
|
|
59
|
+
type: 'image',
|
|
60
|
+
props: {
|
|
61
|
+
ref: el.getAttribute('src') || '',
|
|
62
|
+
alt: el.getAttribute('alt') || '',
|
|
63
|
+
},
|
|
64
|
+
partial: false,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static markdownRules = [
|
|
69
|
+
{
|
|
70
|
+
priority: 25,
|
|
71
|
+
detect: /^!\[[^\]]*\]\([^)]+\)/,
|
|
72
|
+
consume: () => 1,
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {string[]} lines
|
|
78
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
79
|
+
*/
|
|
80
|
+
static fromMarkdown(lines) {
|
|
81
|
+
const m = lines[0].match(/^!\[([^\]]*)\]\(([^)]+)\)/);
|
|
82
|
+
if (!m) return null;
|
|
83
|
+
return { type: 'image', props: { alt: m[1], ref: m[2] }, partial: false };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
87
|
+
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
88
|
+
const node = MediaBlock.createNode(nabu, 'image', props, parentId, index);
|
|
89
|
+
const block = new ImageBlock(nabu, /** @type {ImageNode} */ (/** @type {unknown} */ (node)));
|
|
90
|
+
return block;
|
|
91
|
+
}
|
|
92
|
+
}
|
package/dist/blocks/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./block.svelte.js";
|
|
2
|
+
export * from "./text-block.svelte.js";
|
|
2
3
|
export * from "./block.extension.js";
|
|
3
4
|
export * from "./nabu.svelte.js";
|
|
4
5
|
export * from "./megablock.svelte.js";
|
|
@@ -8,6 +9,15 @@ export * from "./heading";
|
|
|
8
9
|
export * from "./list";
|
|
9
10
|
export * from "./dialogue";
|
|
10
11
|
export * from "./zone";
|
|
12
|
+
export * from "./blockquote";
|
|
13
|
+
export * from "./divider";
|
|
14
|
+
export * from "./code";
|
|
15
|
+
export * from "./callout";
|
|
16
|
+
export * from "./toggle";
|
|
17
|
+
export * from "./image";
|
|
18
|
+
export * from "./media";
|
|
19
|
+
export * from "./video";
|
|
20
|
+
export * from "./file";
|
|
11
21
|
export * from "./selection.svelte.js";
|
|
12
22
|
export { default as NabuEditor } from "./Nabu.svelte";
|
|
13
23
|
export { default as BlockComponent } from "./Block.svelte";
|
package/dist/blocks/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./block.svelte.js";
|
|
2
|
+
export * from "./text-block.svelte.js";
|
|
2
3
|
export * from "./block.extension.js";
|
|
3
4
|
export * from "./nabu.svelte.js";
|
|
4
5
|
export * from "./megablock.svelte.js";
|
|
@@ -11,5 +12,14 @@ export * from "./heading";
|
|
|
11
12
|
export * from "./list";
|
|
12
13
|
export * from "./dialogue";
|
|
13
14
|
export * from "./zone";
|
|
15
|
+
export * from "./blockquote";
|
|
16
|
+
export * from "./divider";
|
|
17
|
+
export * from "./code";
|
|
18
|
+
export * from "./callout";
|
|
19
|
+
export * from "./toggle";
|
|
20
|
+
export * from "./image";
|
|
21
|
+
export * from "./media";
|
|
22
|
+
export * from "./video";
|
|
23
|
+
export * from "./file";
|
|
14
24
|
|
|
15
25
|
export * from "./selection.svelte.js";
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
let {block} = $props();
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
|
-
<svelte:element
|
|
9
|
-
this={block.listType === 'ordered' ? 'ol' : 'ul'}
|
|
8
|
+
<svelte:element
|
|
9
|
+
this={block.listType === 'ordered' ? 'ol' : 'ul'}
|
|
10
10
|
data-block-id={block.id}
|
|
11
11
|
data-block-type="list"
|
|
12
12
|
class="nabu-list"
|
|
13
|
+
class:todo={block.listType === 'todo'}
|
|
13
14
|
>
|
|
14
15
|
{#each block.children as child (child.id)}
|
|
15
16
|
<Block block={child} />
|
|
@@ -22,4 +23,9 @@
|
|
|
22
23
|
margin-bottom: 0.5rem;
|
|
23
24
|
padding-left: 1.5rem;
|
|
24
25
|
}
|
|
26
|
+
|
|
27
|
+
.nabu-list.todo {
|
|
28
|
+
list-style: none;
|
|
29
|
+
padding-left: 0;
|
|
30
|
+
}
|
|
25
31
|
</style>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
let {block} = $props();
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
|
-
<li
|
|
9
|
+
<li
|
|
10
10
|
data-block-id={block.id}
|
|
11
11
|
data-block-type="list-item"
|
|
12
12
|
class="nabu-list-item"
|
|
@@ -14,8 +14,15 @@
|
|
|
14
14
|
class:selected={block.selected}
|
|
15
15
|
class:first={block.isSelectionStart}
|
|
16
16
|
class:last={block.isSelectionEnd}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
class:todo={block.isTodo}
|
|
18
|
+
>{#if block.isTodo}<button
|
|
19
|
+
class="nabu-todo-check"
|
|
20
|
+
data-nabu-ui
|
|
21
|
+
contenteditable="false"
|
|
22
|
+
type="button"
|
|
23
|
+
aria-pressed={block.checked}
|
|
24
|
+
onmousedown={(e) => { e.preventDefault(); block.toggleChecked(); }}
|
|
25
|
+
>{block.checked ? '☑' : '☐'}</button>{/if}<div bind:this={block.element} class="item-content" class:checked={block.checked}><RichText delta={block.delta} /></div><!--
|
|
19
26
|
-->{#if block.children && block.children.length > 0}
|
|
20
27
|
<div class="item-children">
|
|
21
28
|
{#each block.children as child (child.id)}
|
|
@@ -28,22 +35,51 @@
|
|
|
28
35
|
<style>
|
|
29
36
|
.nabu-list-item {
|
|
30
37
|
margin: 0.25rem 0;
|
|
31
|
-
|
|
38
|
+
|
|
32
39
|
&.debug{
|
|
33
40
|
&.selected > .item-content {
|
|
34
41
|
background-color: rgba(59, 130, 246, 0.25);
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
|
-
|
|
44
|
+
|
|
45
|
+
&.todo {
|
|
46
|
+
display: flex;
|
|
47
|
+
flex-wrap: wrap;
|
|
48
|
+
align-items: flex-start;
|
|
49
|
+
gap: 0.2em 0.4em;
|
|
50
|
+
}
|
|
51
|
+
/* Checkbox + content share line 1; a nested sublist wraps to its own
|
|
52
|
+
full-width line below (without flex-wrap it would sit to the right). */
|
|
53
|
+
&.todo > .item-content { flex: 1; min-width: 0; }
|
|
54
|
+
&.todo > .item-children { flex-basis: 100%; }
|
|
38
55
|
}
|
|
39
|
-
|
|
56
|
+
|
|
40
57
|
.item-content {
|
|
41
58
|
outline: none;
|
|
42
59
|
white-space: pre-wrap;
|
|
43
60
|
min-height: 1.5em; /* Permet de cliquer dans un item vide */
|
|
61
|
+
|
|
62
|
+
&.checked {
|
|
63
|
+
text-decoration: line-through;
|
|
64
|
+
opacity: 0.55;
|
|
65
|
+
}
|
|
44
66
|
}
|
|
45
|
-
|
|
67
|
+
|
|
46
68
|
.item-children {
|
|
47
69
|
/* Pas de margin-left ici, c'est le <ul> imbriqué qui gèrera l'indentation */
|
|
48
70
|
}
|
|
71
|
+
|
|
72
|
+
.nabu-todo-check {
|
|
73
|
+
flex-shrink: 0;
|
|
74
|
+
background: none;
|
|
75
|
+
border: none;
|
|
76
|
+
padding: 0;
|
|
77
|
+
margin: 0;
|
|
78
|
+
cursor: pointer;
|
|
79
|
+
user-select: none;
|
|
80
|
+
font-size: 1em;
|
|
81
|
+
line-height: 1.5;
|
|
82
|
+
outline: none;
|
|
83
|
+
vertical-align: top;
|
|
84
|
+
}
|
|
49
85
|
</style>
|
|
@@ -29,9 +29,11 @@ export const onBeforeInput = (nabu, event, block) => {
|
|
|
29
29
|
|
|
30
30
|
const textBeforeCursor = behavior.text.slice(0, sel.from);
|
|
31
31
|
|
|
32
|
-
/** @type {"bullet" | "ordered" | null} */
|
|
32
|
+
/** @type {"bullet" | "ordered" | "todo" | null} */
|
|
33
33
|
let listType = null;
|
|
34
34
|
let prefixLength = 0;
|
|
35
|
+
/** @type {boolean | undefined} */
|
|
36
|
+
let checked = undefined;
|
|
35
37
|
|
|
36
38
|
if (textBeforeCursor.match(/^-$/)) {
|
|
37
39
|
listType = "bullet";
|
|
@@ -39,6 +41,14 @@ export const onBeforeInput = (nabu, event, block) => {
|
|
|
39
41
|
} else if (textBeforeCursor.match(/^\d+\.$/)) {
|
|
40
42
|
listType = "ordered";
|
|
41
43
|
prefixLength = textBeforeCursor.length;
|
|
44
|
+
} else if (textBeforeCursor.match(/^\[\s?\]$/)) {
|
|
45
|
+
listType = "todo";
|
|
46
|
+
checked = false;
|
|
47
|
+
prefixLength = textBeforeCursor.length;
|
|
48
|
+
} else if (textBeforeCursor.match(/^\[[xX]\]$/)) {
|
|
49
|
+
listType = "todo";
|
|
50
|
+
checked = true;
|
|
51
|
+
prefixLength = textBeforeCursor.length;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
if (!listType) return CONTINUE;
|
|
@@ -58,7 +68,10 @@ export const onBeforeInput = (nabu, event, block) => {
|
|
|
58
68
|
const list = List.create(nabu, "list", { listType }, parentId, index);
|
|
59
69
|
|
|
60
70
|
// Create the ListItem inside the list with the captured content
|
|
61
|
-
|
|
71
|
+
/** @type {Record<string, any>} */
|
|
72
|
+
const itemProps = { delta };
|
|
73
|
+
if (checked !== undefined) itemProps.checked = checked;
|
|
74
|
+
const listItem = ListItem.create(nabu, "list-item", itemProps, list.node.id.toString());
|
|
62
75
|
|
|
63
76
|
// Destroy the original paragraph (no commit)
|
|
64
77
|
block.destroy();
|
|
@@ -53,9 +53,21 @@ export class ListItem extends MegaBlock {
|
|
|
53
53
|
container: LoroText;
|
|
54
54
|
/** @type {TextBehavior} */
|
|
55
55
|
behavior: TextBehavior;
|
|
56
|
+
/** @type {boolean} */
|
|
57
|
+
checked: boolean;
|
|
56
58
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
57
59
|
block: import("./list-item.svelte.js").ListItem;
|
|
58
60
|
}, {}, "">;
|
|
61
|
+
isTodo: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Set the checked state and persist to Loro.
|
|
64
|
+
* @param {boolean} v
|
|
65
|
+
*/
|
|
66
|
+
setChecked(v: boolean): void;
|
|
67
|
+
/**
|
|
68
|
+
* Toggle the checked state.
|
|
69
|
+
*/
|
|
70
|
+
toggleChecked(): void;
|
|
59
71
|
get text(): string;
|
|
60
72
|
get delta(): import("loro-crdt").Delta<string>[];
|
|
61
73
|
selection: {
|
|
@@ -79,9 +91,9 @@ export class ListItem extends MegaBlock {
|
|
|
79
91
|
};
|
|
80
92
|
/**
|
|
81
93
|
* Retourne la sous-liste existante, ou en crée une nouvelle à la fin des enfants.
|
|
82
|
-
* @param {"bullet" | "ordered"} [listType
|
|
94
|
+
* @param {"bullet" | "ordered" | "todo"} [listType]
|
|
83
95
|
*/
|
|
84
|
-
getOrCreateSublist(listType?: "bullet" | "ordered"): Block;
|
|
96
|
+
getOrCreateSublist(listType?: "bullet" | "ordered" | "todo"): Block;
|
|
85
97
|
/** @param {KeyboardEvent} event */
|
|
86
98
|
keydown(event: KeyboardEvent): boolean;
|
|
87
99
|
/** @param {import('../block.svelte.js').Block} block */
|
|
@@ -80,7 +80,7 @@ export class ListItem extends MegaBlock {
|
|
|
80
80
|
/** @param {Nabu} nabu @param {ListItemNode} node */
|
|
81
81
|
constructor(nabu, node) {
|
|
82
82
|
super(nabu, node);
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
const data = node.data;
|
|
85
85
|
this.container = data.get("text") ?? data.setContainer("text", new LoroText());
|
|
86
86
|
|
|
@@ -88,11 +88,23 @@ export class ListItem extends MegaBlock {
|
|
|
88
88
|
this.behavior = new TextBehavior(this, this.container);
|
|
89
89
|
this.behaviors.set("text", this.behavior);
|
|
90
90
|
|
|
91
|
+
// Initialize checked from Loro metadata
|
|
92
|
+
this.checked = !!node.data.get('checked');
|
|
93
|
+
// Subscribe to data changes to keep checked in sync
|
|
94
|
+
this.node.data.subscribe(() => {
|
|
95
|
+
this.checked = !!this.node.data.get('checked');
|
|
96
|
+
});
|
|
97
|
+
|
|
91
98
|
this.serializers.set('markdown', () => {
|
|
92
99
|
const depth = this.parents.filter(p => p.type === 'list-item').length;
|
|
93
100
|
const indent = ' '.repeat(depth);
|
|
94
101
|
const listType = /** @type {any} */ (this.parent)?.listType ?? 'bullet';
|
|
95
|
-
|
|
102
|
+
let prefix;
|
|
103
|
+
if (listType === 'todo') {
|
|
104
|
+
prefix = `- [${this.checked ? 'x' : ' '}]`;
|
|
105
|
+
} else {
|
|
106
|
+
prefix = listType === 'ordered' ? `${this.index + 1}.` : '-';
|
|
107
|
+
}
|
|
96
108
|
const lines = [`${indent}${prefix} ${this.behavior.toMarkdown()}`];
|
|
97
109
|
if (this.sublist) {
|
|
98
110
|
const sublistMd = this.sublist.serialize('markdown');
|
|
@@ -105,7 +117,8 @@ export class ListItem extends MegaBlock {
|
|
|
105
117
|
const result = {
|
|
106
118
|
id: this.id,
|
|
107
119
|
type: 'list-item',
|
|
108
|
-
content: this.behavior.toJSON()
|
|
120
|
+
content: this.behavior.toJSON(),
|
|
121
|
+
...(this.isTodo ? { checked: this.checked } : {})
|
|
109
122
|
};
|
|
110
123
|
const childrenJson = this.children.map(c => c.serialize('json')).filter(Boolean);
|
|
111
124
|
if (childrenJson.length) result.children = childrenJson;
|
|
@@ -115,7 +128,29 @@ export class ListItem extends MegaBlock {
|
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
component = $derived(this.nabu.components.get("list-item") || ListItemComponent);
|
|
118
|
-
|
|
131
|
+
|
|
132
|
+
/** @type {boolean} */
|
|
133
|
+
checked = $state(false);
|
|
134
|
+
|
|
135
|
+
isTodo = $derived(/** @type {any} */ (this.parent)?.listType === 'todo');
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Set the checked state and persist to Loro.
|
|
139
|
+
* @param {boolean} v
|
|
140
|
+
*/
|
|
141
|
+
setChecked(v) {
|
|
142
|
+
this.checked = !!v;
|
|
143
|
+
/** @type {any} */ (this.node.data).set('checked', !!v);
|
|
144
|
+
this.commit();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Toggle the checked state.
|
|
149
|
+
*/
|
|
150
|
+
toggleChecked() {
|
|
151
|
+
this.setChecked(!this.checked);
|
|
152
|
+
}
|
|
153
|
+
|
|
119
154
|
get text() {
|
|
120
155
|
return this.behavior.text;
|
|
121
156
|
}
|
|
@@ -128,6 +163,8 @@ export class ListItem extends MegaBlock {
|
|
|
128
163
|
|
|
129
164
|
positions = $derived(this.behavior.positions + super.positions);
|
|
130
165
|
|
|
166
|
+
wordCount = $derived((this.behavior?.wordCount ?? 0) + this.children.reduce((sum, c) => sum + (c.wordCount ?? 0), 0));
|
|
167
|
+
|
|
131
168
|
/**
|
|
132
169
|
* Mixed block: own text comes first, then children (sublists).
|
|
133
170
|
* @param {number} localOffset
|
|
@@ -168,9 +205,9 @@ export class ListItem extends MegaBlock {
|
|
|
168
205
|
|
|
169
206
|
/**
|
|
170
207
|
* Retourne la sous-liste existante, ou en crée une nouvelle à la fin des enfants.
|
|
171
|
-
* @param {"bullet" | "ordered"} [listType
|
|
208
|
+
* @param {"bullet" | "ordered" | "todo"} [listType]
|
|
172
209
|
*/
|
|
173
|
-
getOrCreateSublist(listType = "bullet") {
|
|
210
|
+
getOrCreateSublist(listType = /** @type {any} */ (this.parent)?.listType || "bullet") {
|
|
174
211
|
if (this.sublist) return this.sublist;
|
|
175
212
|
|
|
176
213
|
// S'il n'y en a pas, on demande à Nabu d'en créer une en tant qu'enfant de ce ListItem
|
|
@@ -231,7 +268,12 @@ export class ListItem extends MegaBlock {
|
|
|
231
268
|
*/
|
|
232
269
|
static toMarkdown(pb, { recurse, listType = 'bullet', index = 0, depth = 0 }) {
|
|
233
270
|
const indent = ' '.repeat(depth);
|
|
234
|
-
|
|
271
|
+
let prefix;
|
|
272
|
+
if (listType === 'todo') {
|
|
273
|
+
prefix = `- [${pb.props?.checked ? 'x' : ' '}]`;
|
|
274
|
+
} else {
|
|
275
|
+
prefix = listType === 'ordered' ? `${index + 1}.` : '-';
|
|
276
|
+
}
|
|
235
277
|
const text = deltaToMarkdown(pb.delta || []);
|
|
236
278
|
const sublists = (pb.children || []).map(sub => recurse(sub, { depth: depth + 1 })).join('\n');
|
|
237
279
|
return `${indent}${prefix} ${text}${sublists ? '\n' + sublists : ''}`;
|
|
@@ -244,6 +286,10 @@ export class ListItem extends MegaBlock {
|
|
|
244
286
|
static toHtml(pb, { recurse }) {
|
|
245
287
|
const text = deltaToHtml(pb.delta || []);
|
|
246
288
|
const sublists = (pb.children || []).map(recurse).join('');
|
|
289
|
+
if (pb.props?.checked !== undefined) {
|
|
290
|
+
const checkedAttr = pb.props.checked ? ' checked' : '';
|
|
291
|
+
return `<li><input type="checkbox" disabled${checkedAttr}> ${text}${sublists}</li>`;
|
|
292
|
+
}
|
|
247
293
|
return `<li>${text}${sublists}</li>`;
|
|
248
294
|
}
|
|
249
295
|
|
|
@@ -262,8 +308,12 @@ export class ListItem extends MegaBlock {
|
|
|
262
308
|
.map(parseBlock)
|
|
263
309
|
.filter(Boolean)
|
|
264
310
|
);
|
|
311
|
+
// Detect checkbox: <li><input type="checkbox"> or <li><p><input type="checkbox">
|
|
312
|
+
const cb = el.querySelector(':scope > input[type=checkbox], :scope > p > input[type=checkbox]') ||
|
|
313
|
+
el.querySelector('input[type=checkbox]');
|
|
265
314
|
/** @type {import('../../utils/extensions.js').PasteBlock} */
|
|
266
315
|
const result = { type: 'list-item', delta, partial: false };
|
|
316
|
+
if (cb) result.props = { checked: cb.hasAttribute('checked') };
|
|
267
317
|
if (childLists.length) result.children = childLists;
|
|
268
318
|
return result;
|
|
269
319
|
}
|
|
@@ -275,6 +325,7 @@ export class ListItem extends MegaBlock {
|
|
|
275
325
|
const container = node.data.setContainer("text", new LoroText());
|
|
276
326
|
if (props.text) container.insert(0, props.text);
|
|
277
327
|
if (props.delta) container.applyDelta([...props.delta]);
|
|
328
|
+
if (props.checked !== undefined) /** @type {any} */ (node.data).set('checked', !!props.checked);
|
|
278
329
|
const block = new ListItem(nabu, node);
|
|
279
330
|
return block;
|
|
280
331
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @import {LoroText} from "loro-crdt";
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered"}>} ListNode
|
|
6
|
+
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered" | "todo"}>} ListNode
|
|
7
7
|
*/
|
|
8
8
|
export class ListBehavior {
|
|
9
9
|
/** @param {Block} block */
|
|
@@ -11,14 +11,14 @@ export class ListBehavior {
|
|
|
11
11
|
block: Block;
|
|
12
12
|
nabu: import("..").Nabu;
|
|
13
13
|
node: ListNode;
|
|
14
|
-
/** @type {"bullet" | "ordered"} */
|
|
15
|
-
listType: "bullet" | "ordered";
|
|
14
|
+
/** @type {"bullet" | "ordered" | "todo"} */
|
|
15
|
+
listType: "bullet" | "ordered" | "todo";
|
|
16
16
|
/** @param {Block} block */
|
|
17
17
|
absorbs(block: Block): true | undefined;
|
|
18
18
|
}
|
|
19
19
|
export type ListNode = NabuNode<{
|
|
20
20
|
type: "list";
|
|
21
|
-
listType: "bullet" | "ordered";
|
|
21
|
+
listType: "bullet" | "ordered" | "todo";
|
|
22
22
|
}>;
|
|
23
23
|
import type { Block } from "..";
|
|
24
24
|
import type { NabuNode } from "..";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MegaBlock } from "
|
|
1
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @import {Block, NabuNode} from "..";
|
|
@@ -6,7 +6,7 @@ import { MegaBlock } from "..";
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered"}>} ListNode
|
|
9
|
+
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered" | "todo"}>} ListNode
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export class ListBehavior {
|
|
@@ -15,13 +15,13 @@ export class ListBehavior {
|
|
|
15
15
|
this.block = block;
|
|
16
16
|
this.nabu = block.nabu;
|
|
17
17
|
this.node = /** @type {ListNode} */ (block.node);
|
|
18
|
-
this.listType = /** @type {"bullet" | "ordered"} */ (this.node.data.get("listType") || "bullet");
|
|
18
|
+
this.listType = /** @type {"bullet" | "ordered" | "todo"} */ (this.node.data.get("listType") || "bullet");
|
|
19
19
|
this.node.data.subscribe(() => {
|
|
20
|
-
this.listType = /** @type {"bullet" | "ordered"} */ (this.node.data.get("listType") || "bullet");
|
|
20
|
+
this.listType = /** @type {"bullet" | "ordered" | "todo"} */ (this.node.data.get("listType") || "bullet");
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/** @type {"bullet" | "ordered"} */
|
|
24
|
+
/** @type {"bullet" | "ordered" | "todo"} */
|
|
25
25
|
listType = $state("bullet");
|
|
26
26
|
|
|
27
27
|
/** @param {Block} block */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered"}>} ListNode
|
|
5
|
+
* @typedef {NabuNode<{type: "list", listType: "bullet" | "ordered" | "todo"}>} ListNode
|
|
6
6
|
*/
|
|
7
7
|
export class List extends MegaBlock {
|
|
8
8
|
/**
|
|
@@ -36,12 +36,19 @@ export class List extends MegaBlock {
|
|
|
36
36
|
static fromMarkdown(lines: string[], { parseInline }: {
|
|
37
37
|
parseInline: (text: string) => import("loro-crdt").Delta<string>[];
|
|
38
38
|
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
39
|
-
static htmlRules: {
|
|
39
|
+
static htmlRules: ({
|
|
40
40
|
selector: string;
|
|
41
41
|
props: {
|
|
42
42
|
listType: string;
|
|
43
43
|
};
|
|
44
|
-
|
|
44
|
+
priority: number;
|
|
45
|
+
} | {
|
|
46
|
+
selector: string;
|
|
47
|
+
props: {
|
|
48
|
+
listType: string;
|
|
49
|
+
};
|
|
50
|
+
priority?: undefined;
|
|
51
|
+
})[];
|
|
45
52
|
/**
|
|
46
53
|
* @param {Element} el
|
|
47
54
|
* @param {{ parseChildren: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
@@ -60,9 +67,9 @@ export class List extends MegaBlock {
|
|
|
60
67
|
/** @param {Nabu} nabu @param {ListNode} node */
|
|
61
68
|
constructor(nabu: Nabu, node: ListNode);
|
|
62
69
|
behavior: ListBehavior;
|
|
63
|
-
listType: "bullet" | "ordered";
|
|
70
|
+
listType: "bullet" | "ordered" | "todo";
|
|
64
71
|
get clipboardProps(): {
|
|
65
|
-
listType: "bullet" | "ordered";
|
|
72
|
+
listType: "bullet" | "ordered" | "todo";
|
|
66
73
|
};
|
|
67
74
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
68
75
|
block: import("./list.svelte.js").List;
|
|
@@ -84,7 +91,7 @@ export class List extends MegaBlock {
|
|
|
84
91
|
}
|
|
85
92
|
export type ListNode = NabuNode<{
|
|
86
93
|
type: "list";
|
|
87
|
-
listType: "bullet" | "ordered";
|
|
94
|
+
listType: "bullet" | "ordered" | "todo";
|
|
88
95
|
}>;
|
|
89
96
|
import { MegaBlock } from "../megablock.svelte.js";
|
|
90
97
|
import { ListBehavior } from "./list.behavior.svelte.js";
|