@aionbuilders/nabu 0.1.0-alpha.8 → 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/BlockGap.svelte +55 -0
- package/dist/blocks/BlockGap.svelte.d.ts +11 -0
- 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 +11 -0
- package/dist/blocks/index.js +11 -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 +8 -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.d.ts +1 -0
- package/dist/blocks/selection.svelte.js +212 -16
- 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 +272 -0
- package/dist/blocks/zone/Zone.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 +237 -0
- package/dist/blocks/zone/zone.svelte.d.ts +221 -0
- package/dist/blocks/zone/zone.svelte.js +608 -0
- 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 +22 -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
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as FloatingToolbar } from './FloatingToolbar.svelte';
|
|
2
|
+
export { default as SlashMenu } from './SlashMenu.svelte';
|
|
3
|
+
export { default as DragHandle } from './DragHandle.svelte';
|
|
4
|
+
export { SlashMenuController, DEFAULT_SLASH_COMMANDS } from './slash-menu.svelte.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} SlashCommand
|
|
3
|
+
* @property {string} title
|
|
4
|
+
* @property {string} [subtitle]
|
|
5
|
+
* @property {string} [icon]
|
|
6
|
+
* @property {string[]} [aliases]
|
|
7
|
+
* @property {(engine: import('../blocks/nabu.svelte.js').Nabu) => void} run
|
|
8
|
+
*/
|
|
9
|
+
/** @type {SlashCommand[]} */
|
|
10
|
+
export const DEFAULT_SLASH_COMMANDS: SlashCommand[];
|
|
11
|
+
export class SlashMenuController {
|
|
12
|
+
/** @param {import('../blocks/nabu.svelte.js').Nabu} engine @param {SlashCommand[]} commands */
|
|
13
|
+
constructor(engine: import("../blocks/nabu.svelte.js").Nabu, commands: SlashCommand[]);
|
|
14
|
+
commands: SlashCommand[];
|
|
15
|
+
/** @type {{ block: any, slashStart: number, cursor: number, query: string } | null} */
|
|
16
|
+
match: {
|
|
17
|
+
block: any;
|
|
18
|
+
slashStart: number;
|
|
19
|
+
cursor: number;
|
|
20
|
+
query: string;
|
|
21
|
+
} | null;
|
|
22
|
+
query: string;
|
|
23
|
+
filteredItems: SlashCommand[];
|
|
24
|
+
open: boolean;
|
|
25
|
+
selectedIndex: number;
|
|
26
|
+
/** @param {number} delta */
|
|
27
|
+
moveSelection(delta: number): void;
|
|
28
|
+
/** Run the command at the given index (default: the selected one). @param {number} [index] */
|
|
29
|
+
select(index?: number): Promise<void>;
|
|
30
|
+
/** Dismiss the menu for the current trigger position (Escape). */
|
|
31
|
+
close(): void;
|
|
32
|
+
#private;
|
|
33
|
+
}
|
|
34
|
+
export type SlashCommand = {
|
|
35
|
+
title: string;
|
|
36
|
+
subtitle?: string | undefined;
|
|
37
|
+
icon?: string | undefined;
|
|
38
|
+
aliases?: string[] | undefined;
|
|
39
|
+
run: (engine: import("../blocks/nabu.svelte.js").Nabu) => void;
|
|
40
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { List } from '../blocks/list/list.svelte.js';
|
|
2
|
+
import { ListItem } from '../blocks/list/list-item.svelte.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Transform the current anchor block (a paragraph) into a list of the given type.
|
|
6
|
+
* Mirrors the "- "/"1. " creation flow. Isolated here so the slash menu doesn't
|
|
7
|
+
* depend on internal list actions.
|
|
8
|
+
* @param {import('../blocks/nabu.svelte.js').Nabu} nabu
|
|
9
|
+
* @param {"bullet"|"ordered"|"todo"} listType
|
|
10
|
+
*/
|
|
11
|
+
function createListInBlock(nabu, listType) {
|
|
12
|
+
const block = nabu.selection.anchorBlock;
|
|
13
|
+
if (!block) return;
|
|
14
|
+
const beh = block.behaviors?.get('text');
|
|
15
|
+
const delta = beh ? beh.container.toDelta() : [];
|
|
16
|
+
const parentNode = block.node.parent();
|
|
17
|
+
const parentId = parentNode?.id.toString() ?? null;
|
|
18
|
+
const index = block.node.index();
|
|
19
|
+
const list = List.create(nabu, 'list', { listType }, parentId, index);
|
|
20
|
+
const itemProps = listType === 'todo' ? { delta, checked: false } : { delta };
|
|
21
|
+
const item = ListItem.create(nabu, 'list-item', itemProps, list.node.id.toString());
|
|
22
|
+
block.destroy();
|
|
23
|
+
nabu.commit().then(() => { const f = nabu.blocks.get(item.id); if (f) f.focus({ start: 0, end: 0 }); });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} SlashCommand
|
|
28
|
+
* @property {string} title
|
|
29
|
+
* @property {string} [subtitle]
|
|
30
|
+
* @property {string} [icon]
|
|
31
|
+
* @property {string[]} [aliases]
|
|
32
|
+
* @property {(engine: import('../blocks/nabu.svelte.js').Nabu) => void} run
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** @type {SlashCommand[]} */
|
|
36
|
+
export const DEFAULT_SLASH_COMMANDS = [
|
|
37
|
+
{ title: 'Text', icon: '¶', aliases: ['paragraph','p','plain'], run: (e) => e.exec('paragraph') },
|
|
38
|
+
{ title: 'Heading 1', icon: 'H1', aliases: ['h1','title','heading'], run: (e) => e.exec('heading:1') },
|
|
39
|
+
{ title: 'Heading 2', icon: 'H2', aliases: ['h2','subtitle'], run: (e) => e.exec('heading:2') },
|
|
40
|
+
{ title: 'Heading 3', icon: 'H3', aliases: ['h3'], run: (e) => e.exec('heading:3') },
|
|
41
|
+
{ title: 'Bulleted list', icon: '•', aliases: ['bullet','ul','list'], run: (e) => createListInBlock(e, 'bullet') },
|
|
42
|
+
{ title: 'Numbered list', icon: '1.', aliases: ['numbered','ol','ordered'], run: (e) => createListInBlock(e, 'ordered') },
|
|
43
|
+
{ title: 'To-do list', icon: '☑', aliases: ['todo','task','checkbox','checklist'], run: (e) => createListInBlock(e, 'todo') },
|
|
44
|
+
{ title: 'Code', icon: '<>', aliases: ['code','snippet'], run: (e) => e.exec('code') },
|
|
45
|
+
{ title: 'Callout', icon: '💡', aliases: ['callout','note','info','warning'], run: (e) => e.exec('callout') },
|
|
46
|
+
{ title: 'Quote', icon: '"', aliases: ['quote','blockquote'], run: (e) => e.exec('blockquote') },
|
|
47
|
+
{ title: 'Toggle', icon: '▸', aliases: ['toggle','collapse','details'], run: (e) => e.exec('toggle') },
|
|
48
|
+
{ title: 'Divider', icon: '—', aliases: ['divider','hr','separator','rule'], run: (e) => e.exec('divider:insert') },
|
|
49
|
+
{ title: 'Image', icon: '🖼', aliases: ['image','img','photo','picture'], run: (e) => e.exec('image:pick') },
|
|
50
|
+
{ title: 'Video', icon: '🎬', aliases: ['video','movie','mp4'], run: (e) => e.exec('video:pick') },
|
|
51
|
+
{ title: 'File', icon: '📎', aliases: ['file','attachment','upload','document'], run: (e) => e.exec('file:pick') },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export class SlashMenuController {
|
|
55
|
+
/** @type {import('../blocks/nabu.svelte.js').Nabu} */
|
|
56
|
+
#engine;
|
|
57
|
+
/** @param {import('../blocks/nabu.svelte.js').Nabu} engine @param {SlashCommand[]} commands */
|
|
58
|
+
constructor(engine, commands) { this.#engine = engine; this.commands = commands ?? DEFAULT_SLASH_COMMANDS; }
|
|
59
|
+
|
|
60
|
+
/** @type {{ block: any, slashStart: number, cursor: number, query: string } | null} */
|
|
61
|
+
match = $derived.by(() => {
|
|
62
|
+
const sel = this.#engine.selection;
|
|
63
|
+
const block = sel?.anchorBlock;
|
|
64
|
+
if (!block) return null;
|
|
65
|
+
const beh = block.behaviors?.get('text');
|
|
66
|
+
const bsel = beh?.selection;
|
|
67
|
+
if (!beh || !bsel || !bsel.isCollapsed) return null;
|
|
68
|
+
const before = beh.text.slice(0, bsel.from);
|
|
69
|
+
// "/" at block start OR after whitespace, then non-space chars = the query
|
|
70
|
+
const m = before.match(/(?:^|\s)\/(\S*)$/);
|
|
71
|
+
if (!m) return null;
|
|
72
|
+
const query = m[1];
|
|
73
|
+
return { block, slashStart: bsel.from - query.length - 1, cursor: bsel.from, query };
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
query = $derived(this.match?.query ?? '');
|
|
77
|
+
|
|
78
|
+
filteredItems = $derived.by(() => {
|
|
79
|
+
if (!this.match) return [];
|
|
80
|
+
const q = this.query.toLowerCase();
|
|
81
|
+
if (!q) return this.commands;
|
|
82
|
+
return this.commands.filter(c =>
|
|
83
|
+
c.title.toLowerCase().includes(q) ||
|
|
84
|
+
(c.aliases || []).some(a => a.toLowerCase().includes(q)));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/** @type {number | null} slashStart of a dismissed (Escape) trigger */
|
|
88
|
+
#dismissedKey = $state(null);
|
|
89
|
+
|
|
90
|
+
open = $derived(!!this.match && this.filteredItems.length > 0 && this.match.slashStart !== this.#dismissedKey);
|
|
91
|
+
|
|
92
|
+
selectedIndex = $state(0);
|
|
93
|
+
|
|
94
|
+
/** @param {number} delta */
|
|
95
|
+
moveSelection(delta) {
|
|
96
|
+
const n = this.filteredItems.length;
|
|
97
|
+
if (!n) return;
|
|
98
|
+
this.selectedIndex = (this.selectedIndex + delta + n) % n;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Run the command at the given index (default: the selected one). @param {number} [index] */
|
|
102
|
+
async select(index) {
|
|
103
|
+
const item = this.filteredItems[index ?? this.selectedIndex];
|
|
104
|
+
const m = this.match;
|
|
105
|
+
if (!item || !m) return;
|
|
106
|
+
const beh = m.block.behaviors?.get('text');
|
|
107
|
+
if (beh) beh.delete({ index: m.slashStart, length: m.cursor - m.slashStart });
|
|
108
|
+
await this.#engine.commit();
|
|
109
|
+
this.#engine.selection.setCursor(m.block, m.slashStart);
|
|
110
|
+
this.close();
|
|
111
|
+
item.run(this.#engine);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Dismiss the menu for the current trigger position (Escape). */
|
|
115
|
+
close() { this.#dismissedKey = this.match?.slashStart ?? null; }
|
|
116
|
+
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a `serialize('json')` document export back into PasteBlocks.
|
|
3
|
+
* The json format stores text as Slate-like runs (`{text, ...marks}`);
|
|
4
|
+
* PasteBlocks store Loro deltas (`{insert, attributes}`).
|
|
5
|
+
* @param {Array<{type: string, props?: Record<string, any>, content?: Array<{text: string, [mark: string]: any}>, children?: any[]}>} blocks
|
|
6
|
+
* @returns {PasteBlock[]}
|
|
7
|
+
*/
|
|
8
|
+
export function jsonToPasteBlocks(blocks: Array<{
|
|
9
|
+
type: string;
|
|
10
|
+
props?: Record<string, any>;
|
|
11
|
+
content?: Array<{
|
|
12
|
+
text: string;
|
|
13
|
+
[mark: string]: any;
|
|
14
|
+
}>;
|
|
15
|
+
children?: any[];
|
|
16
|
+
}>): PasteBlock[];
|
|
1
17
|
/**
|
|
2
18
|
* @import { Nabu, Block } from '../blocks'
|
|
3
19
|
*/
|
|
@@ -19,6 +35,14 @@
|
|
|
19
35
|
* @property {number} [priority] - Plus haut = appelé en premier (default: 0)
|
|
20
36
|
* @property {(raw: string, nabu: Nabu) => PasteFragment | null} interpret
|
|
21
37
|
*/
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {Object} InputRule
|
|
40
|
+
* @property {RegExp} pattern - Testé sur le texte AVANT le curseur (avec l'inputType "insertText")
|
|
41
|
+
* @property {string} [inputType] - Défaut: "insertText"
|
|
42
|
+
* @property {(nabu: Nabu, block: Block, match: RegExpMatchArray, sel: {from: number, to: number, isCollapsed: boolean, data: string}) => boolean | void} handler
|
|
43
|
+
* - `sel.data` est le texte en cours d'insertion (event.data).
|
|
44
|
+
* - Retourne true pour BREAK. NE PAS appeler commit() dans le handler.
|
|
45
|
+
*/
|
|
22
46
|
/**
|
|
23
47
|
* @typedef {{
|
|
24
48
|
* onInit: function(Nabu): void,
|
|
@@ -41,6 +65,9 @@
|
|
|
41
65
|
* @property {Record<string, (nabu: Nabu) => any>} [serializers]
|
|
42
66
|
* @property {Record<string, (nabu: Nabu, data: any, topic: string) => any>} [actions]
|
|
43
67
|
* @property {PasteInterpreter[]} [pasteInterpreters]
|
|
68
|
+
* @property {InputRule[]} [inputRules]
|
|
69
|
+
* Declarative text-replacement rules applied while typing (e.g. markdown
|
|
70
|
+
* shortcuts, smart typography). Tested against the text before the cursor.
|
|
44
71
|
* @property {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} [loroTextStyles]
|
|
45
72
|
* Loro text style configuration required by this extension.
|
|
46
73
|
* Passed to `LoroDoc.configTextStyle()` during Nabu initialization so that
|
|
@@ -60,6 +87,8 @@ export class Extension {
|
|
|
60
87
|
actions: Record<string, (nabu: Nabu, data: any, topic: string) => any>;
|
|
61
88
|
/** @type {PasteInterpreter[]} */
|
|
62
89
|
pasteInterpreters: PasteInterpreter[];
|
|
90
|
+
/** @type {InputRule[]} */
|
|
91
|
+
inputRules: InputRule[];
|
|
63
92
|
/** @type {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} */
|
|
64
93
|
loroTextStyles: Record<string, {
|
|
65
94
|
expand: "after" | "before" | "both" | "none";
|
|
@@ -87,6 +116,26 @@ export type PasteInterpreter = {
|
|
|
87
116
|
priority?: number | undefined;
|
|
88
117
|
interpret: (raw: string, nabu: Nabu) => PasteFragment | null;
|
|
89
118
|
};
|
|
119
|
+
export type InputRule = {
|
|
120
|
+
/**
|
|
121
|
+
* - Testé sur le texte AVANT le curseur (avec l'inputType "insertText")
|
|
122
|
+
*/
|
|
123
|
+
pattern: RegExp;
|
|
124
|
+
/**
|
|
125
|
+
* - Défaut: "insertText"
|
|
126
|
+
*/
|
|
127
|
+
inputType?: string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* - `sel.data` est le texte en cours d'insertion (event.data).
|
|
130
|
+
* - Retourne true pour BREAK. NE PAS appeler commit() dans le handler.
|
|
131
|
+
*/
|
|
132
|
+
handler: (nabu: Nabu, block: Block, match: RegExpMatchArray, sel: {
|
|
133
|
+
from: number;
|
|
134
|
+
to: number;
|
|
135
|
+
isCollapsed: boolean;
|
|
136
|
+
data: string;
|
|
137
|
+
}) => boolean | void;
|
|
138
|
+
};
|
|
90
139
|
export type ExtensionHooks = {
|
|
91
140
|
onInit: (arg0: Nabu) => void;
|
|
92
141
|
onBlockCreate: (arg0: Nabu, arg1: Block) => void;
|
|
@@ -119,6 +168,11 @@ export type ExtensionInit = {
|
|
|
119
168
|
serializers?: Record<string, (nabu: Nabu) => any> | undefined;
|
|
120
169
|
actions?: Record<string, (nabu: Nabu, data: any, topic: string) => any> | undefined;
|
|
121
170
|
pasteInterpreters?: PasteInterpreter[] | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* Declarative text-replacement rules applied while typing (e.g. markdown
|
|
173
|
+
* shortcuts, smart typography). Tested against the text before the cursor.
|
|
174
|
+
*/
|
|
175
|
+
inputRules?: InputRule[] | undefined;
|
|
122
176
|
/**
|
|
123
177
|
* Loro text style configuration required by this extension.
|
|
124
178
|
* Passed to `LoroDoc.configTextStyle()` during Nabu initialization so that
|
package/dist/utils/extensions.js
CHANGED
|
@@ -23,6 +23,15 @@
|
|
|
23
23
|
* @property {(raw: string, nabu: Nabu) => PasteFragment | null} interpret
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} InputRule
|
|
28
|
+
* @property {RegExp} pattern - Testé sur le texte AVANT le curseur (avec l'inputType "insertText")
|
|
29
|
+
* @property {string} [inputType] - Défaut: "insertText"
|
|
30
|
+
* @property {(nabu: Nabu, block: Block, match: RegExpMatchArray, sel: {from: number, to: number, isCollapsed: boolean, data: string}) => boolean | void} handler
|
|
31
|
+
* - `sel.data` est le texte en cours d'insertion (event.data).
|
|
32
|
+
* - Retourne true pour BREAK. NE PAS appeler commit() dans le handler.
|
|
33
|
+
*/
|
|
34
|
+
|
|
26
35
|
/**
|
|
27
36
|
* @typedef {{
|
|
28
37
|
* onInit: function(Nabu): void,
|
|
@@ -46,6 +55,9 @@
|
|
|
46
55
|
* @property {Record<string, (nabu: Nabu) => any>} [serializers]
|
|
47
56
|
* @property {Record<string, (nabu: Nabu, data: any, topic: string) => any>} [actions]
|
|
48
57
|
* @property {PasteInterpreter[]} [pasteInterpreters]
|
|
58
|
+
* @property {InputRule[]} [inputRules]
|
|
59
|
+
* Declarative text-replacement rules applied while typing (e.g. markdown
|
|
60
|
+
* shortcuts, smart typography). Tested against the text before the cursor.
|
|
49
61
|
* @property {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} [loroTextStyles]
|
|
50
62
|
* Loro text style configuration required by this extension.
|
|
51
63
|
* Passed to `LoroDoc.configTextStyle()` during Nabu initialization so that
|
|
@@ -66,6 +78,8 @@ export class Extension {
|
|
|
66
78
|
this.actions = init.actions || {};
|
|
67
79
|
/** @type {PasteInterpreter[]} */
|
|
68
80
|
this.pasteInterpreters = init.pasteInterpreters || [];
|
|
81
|
+
/** @type {InputRule[]} */
|
|
82
|
+
this.inputRules = init.inputRules || [];
|
|
69
83
|
/** @type {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} */
|
|
70
84
|
this.loroTextStyles = init.loroTextStyles || {};
|
|
71
85
|
}
|
|
@@ -73,4 +87,29 @@ export class Extension {
|
|
|
73
87
|
|
|
74
88
|
|
|
75
89
|
/** @param {string} name @param {ExtensionInit} init */
|
|
76
|
-
export const extension = (name, init) => new Extension(name, init);
|
|
90
|
+
export const extension = (name, init) => new Extension(name, init);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Convert a `serialize('json')` document export back into PasteBlocks.
|
|
94
|
+
* The json format stores text as Slate-like runs (`{text, ...marks}`);
|
|
95
|
+
* PasteBlocks store Loro deltas (`{insert, attributes}`).
|
|
96
|
+
* @param {Array<{type: string, props?: Record<string, any>, content?: Array<{text: string, [mark: string]: any}>, children?: any[]}>} blocks
|
|
97
|
+
* @returns {PasteBlock[]}
|
|
98
|
+
*/
|
|
99
|
+
export function jsonToPasteBlocks(blocks) {
|
|
100
|
+
return (blocks || []).map(b => {
|
|
101
|
+
/** @type {PasteBlock} */
|
|
102
|
+
const pb = { type: b.type, partial: false };
|
|
103
|
+
if (b.props) pb.props = b.props;
|
|
104
|
+
if (Array.isArray(b.content)) {
|
|
105
|
+
pb.delta = b.content.map(run => {
|
|
106
|
+
const { text, ...marks } = run;
|
|
107
|
+
return Object.keys(marks).length
|
|
108
|
+
? { insert: text, attributes: marks }
|
|
109
|
+
: { insert: text };
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (Array.isArray(b.children)) pb.children = jsonToPasteBlocks(b.children);
|
|
113
|
+
return pb;
|
|
114
|
+
});
|
|
115
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default placeholder text for empty blocks, keyed by block type.
|
|
3
|
+
* Used by block components via the `data-placeholder` attribute,
|
|
4
|
+
* rendered by the global CSS rule in Nabu.svelte.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} type
|
|
7
|
+
* @param {number} [level] - Heading level (1–6)
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export function getPlaceholder(type: string, level?: number): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default placeholder text for empty blocks, keyed by block type.
|
|
3
|
+
* Used by block components via the `data-placeholder` attribute,
|
|
4
|
+
* rendered by the global CSS rule in Nabu.svelte.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} type
|
|
7
|
+
* @param {number} [level] - Heading level (1–6)
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export function getPlaceholder(type, level = 1) {
|
|
11
|
+
switch (type) {
|
|
12
|
+
case 'paragraph': return 'Start writing...';
|
|
13
|
+
case 'heading': return `Heading ${level}`;
|
|
14
|
+
case 'dialogue': return 'Dialogue...';
|
|
15
|
+
case 'blockquote': return 'Quote...';
|
|
16
|
+
case 'code': return 'Code…';
|
|
17
|
+
case 'callout': return 'Callout…';
|
|
18
|
+
case 'toggle': return 'Toggle…';
|
|
19
|
+
default: return '';
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin preset for Nabu.
|
|
3
|
+
* Loro-CRDT ships a WASM module, which requires `vite-plugin-wasm` and
|
|
4
|
+
* `vite-plugin-top-level-await`. This helper bundles both so consumers
|
|
5
|
+
* only add one entry to their Vite config:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* // vite.config.js
|
|
9
|
+
* import { nabu } from '@aionbuilders/nabu/vite';
|
|
10
|
+
* export default defineConfig({ plugins: [sveltekit(), nabu()] });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @returns {Promise<import('vite').Plugin[]>}
|
|
14
|
+
*/
|
|
15
|
+
export function nabu(): Promise<import("vite").Plugin[]>;
|
|
16
|
+
export default nabu;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin preset for Nabu.
|
|
3
|
+
* Loro-CRDT ships a WASM module, which requires `vite-plugin-wasm` and
|
|
4
|
+
* `vite-plugin-top-level-await`. This helper bundles both so consumers
|
|
5
|
+
* only add one entry to their Vite config:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* // vite.config.js
|
|
9
|
+
* import { nabu } from '@aionbuilders/nabu/vite';
|
|
10
|
+
* export default defineConfig({ plugins: [sveltekit(), nabu()] });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @returns {Promise<import('vite').Plugin[]>}
|
|
14
|
+
*/
|
|
15
|
+
export async function nabu() {
|
|
16
|
+
const [{ default: wasm }, { default: topLevelAwait }] = await Promise.all([
|
|
17
|
+
import('vite-plugin-wasm'),
|
|
18
|
+
import('vite-plugin-top-level-await'),
|
|
19
|
+
]);
|
|
20
|
+
return [wasm(), topLevelAwait()];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default nabu;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aionbuilders/nabu",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build && npm run prepack",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"svelte": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./vite": {
|
|
34
|
+
"types": "./dist/vite.d.ts",
|
|
35
|
+
"default": "./dist/vite.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"peerDependencies": {
|
|
@@ -47,8 +51,6 @@
|
|
|
47
51
|
"svelte-check": "^4.3.6",
|
|
48
52
|
"typescript": "^5.9.3",
|
|
49
53
|
"vite": "^7.3.1",
|
|
50
|
-
"vite-plugin-top-level-await": "^1.6.0",
|
|
51
|
-
"vite-plugin-wasm": "^3.5.0",
|
|
52
54
|
"vitest": "^3.0.0",
|
|
53
55
|
"@vitest/coverage-v8": "^3.0.0",
|
|
54
56
|
"happy-dom": "^16.0.0"
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
"license": "MIT",
|
|
65
67
|
"repository": {
|
|
66
68
|
"type": "git",
|
|
67
|
-
"url": "https://github.com/aionbuilders/nabu"
|
|
69
|
+
"url": "git+https://github.com/aionbuilders/nabu.git"
|
|
68
70
|
},
|
|
69
71
|
"homepage": "https://github.com/aionbuilders/nabu#readme",
|
|
70
72
|
"keywords": [
|
|
@@ -80,6 +82,9 @@
|
|
|
80
82
|
],
|
|
81
83
|
"dependencies": {
|
|
82
84
|
"@aionbuilders/pulse": "^1.0.1",
|
|
83
|
-
"
|
|
85
|
+
"esm-env": "^1.2.2",
|
|
86
|
+
"loro-crdt": "^1.10.6",
|
|
87
|
+
"vite-plugin-top-level-await": "^1.6.0",
|
|
88
|
+
"vite-plugin-wasm": "^3.5.0"
|
|
84
89
|
}
|
|
85
90
|
}
|