@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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{type: "divider"}>} DividerNode
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Horizontal rule. First non-textual block: no TextBehavior, renders an
|
|
9
|
+
* inert <hr> and exposes a single cursor position so document-offset
|
|
10
|
+
* resolution can step over it.
|
|
11
|
+
*/
|
|
12
|
+
export class DividerBlock extends Block {
|
|
13
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
14
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
15
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
16
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
17
|
+
static markdownRules: {
|
|
18
|
+
priority: number;
|
|
19
|
+
detect: RegExp;
|
|
20
|
+
consume: () => number;
|
|
21
|
+
}[];
|
|
22
|
+
/**
|
|
23
|
+
* @param {string[]} lines
|
|
24
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
25
|
+
*/
|
|
26
|
+
static fromMarkdown(lines: string[]): import("../../utils/extensions.js").PasteBlock | null;
|
|
27
|
+
static htmlRules: {
|
|
28
|
+
selector: string;
|
|
29
|
+
}[];
|
|
30
|
+
/**
|
|
31
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
32
|
+
*/
|
|
33
|
+
static fromHTML(): import("../../utils/extensions.js").PasteBlock;
|
|
34
|
+
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
35
|
+
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): DividerBlock;
|
|
36
|
+
/** @param {Nabu} nabu @param {DividerNode} node */
|
|
37
|
+
constructor(nabu: Nabu, node: DividerNode);
|
|
38
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
39
|
+
block: import("./divider.svelte.js").DividerBlock;
|
|
40
|
+
}, {}, "">;
|
|
41
|
+
/** @param {InputEvent} event */
|
|
42
|
+
beforeinput(event: InputEvent): boolean;
|
|
43
|
+
}
|
|
44
|
+
export type DividerNode = NabuNode<{
|
|
45
|
+
type: "divider";
|
|
46
|
+
}>;
|
|
47
|
+
import { Block } from "../block.svelte.js";
|
|
48
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
49
|
+
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Block } from "../block.svelte.js";
|
|
2
|
+
import DividerComponent from "./Divider.svelte";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {NabuNode<{type: "divider"}>} DividerNode
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Horizontal rule. First non-textual block: no TextBehavior, renders an
|
|
14
|
+
* inert <hr> and exposes a single cursor position so document-offset
|
|
15
|
+
* resolution can step over it.
|
|
16
|
+
*/
|
|
17
|
+
// @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
|
|
18
|
+
export class DividerBlock extends Block {
|
|
19
|
+
/** @param {Nabu} nabu @param {DividerNode} node */
|
|
20
|
+
constructor(nabu, node) {
|
|
21
|
+
super(nabu, node);
|
|
22
|
+
|
|
23
|
+
this.serializers.set('markdown', () => '---');
|
|
24
|
+
this.serializers.set('json', () => ({ id: this.id, type: 'divider' }));
|
|
25
|
+
this.serializers.set('application/x-nabu+json', () => ({ type: 'divider', partial: false }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
component = $derived(this.nabu.components.get("divider") || DividerComponent);
|
|
29
|
+
|
|
30
|
+
// Un seul point de curseur — avant le bloc
|
|
31
|
+
positions = $derived(1);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* No editable text — callers (focus, setCursor) handle null gracefully.
|
|
35
|
+
* @param {number} offset
|
|
36
|
+
* @returns {{node: Node, offset: number} | null}
|
|
37
|
+
*/
|
|
38
|
+
getDOMPoint(offset) { return null; }
|
|
39
|
+
|
|
40
|
+
/** @param {InputEvent} event */
|
|
41
|
+
beforeinput(event) { return false; }
|
|
42
|
+
|
|
43
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
44
|
+
static toMarkdown(pb) { return '---'; }
|
|
45
|
+
|
|
46
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
47
|
+
static toHtml(pb) { return '<hr>'; }
|
|
48
|
+
|
|
49
|
+
static markdownRules = [
|
|
50
|
+
{
|
|
51
|
+
priority: 20,
|
|
52
|
+
detect: /^\s*(---+|\*\*\*+|___+)\s*$/,
|
|
53
|
+
consume: () => 1,
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string[]} lines
|
|
59
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
60
|
+
*/
|
|
61
|
+
static fromMarkdown(lines) {
|
|
62
|
+
if (!/^\s*(---+|\*\*\*+|___+)\s*$/.test(lines[0])) return null;
|
|
63
|
+
return { type: 'divider', partial: false };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static htmlRules = [
|
|
67
|
+
{ selector: 'hr' },
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
72
|
+
*/
|
|
73
|
+
static fromHTML() {
|
|
74
|
+
return { type: 'divider', partial: false };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
78
|
+
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
79
|
+
const node = nabu.tree.createNode(/** @type {any} */ (parentId || undefined), index || undefined);
|
|
80
|
+
/** @type {any} */ (node.data).set("type", "divider");
|
|
81
|
+
const block = new DividerBlock(nabu, /** @type {DividerNode} */ (/** @type {unknown} */ (node)));
|
|
82
|
+
return block;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {{ block: import('./file.svelte.js').FileBlock }} */
|
|
3
|
+
let { block } = $props();
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<div
|
|
7
|
+
bind:this={block.element}
|
|
8
|
+
data-block-id={block.id}
|
|
9
|
+
data-block-type="file"
|
|
10
|
+
data-nabu-inert
|
|
11
|
+
contenteditable="false"
|
|
12
|
+
class="nabu-file"
|
|
13
|
+
class:selected={block.selected}
|
|
14
|
+
class:pending={block.status === 'pending'}
|
|
15
|
+
class:error={block.status === 'error'}
|
|
16
|
+
>
|
|
17
|
+
{#if block.status === 'error'}
|
|
18
|
+
<div class="nabu-file-chip nabu-file-chip--error">⚠️ Upload failed</div>
|
|
19
|
+
{:else if block.status === 'pending'}
|
|
20
|
+
<div class="nabu-file-chip nabu-file-chip--pending">
|
|
21
|
+
<span>📎</span>
|
|
22
|
+
<span>{block.name || 'file'}</span>
|
|
23
|
+
<span class="nabu-file-chip-status">Uploading…</span>
|
|
24
|
+
</div>
|
|
25
|
+
{:else}
|
|
26
|
+
<a href={block.displaySrc} download={block.name} class="nabu-file-chip">
|
|
27
|
+
<span>📎</span>
|
|
28
|
+
<span>{block.name || 'file'}</span>
|
|
29
|
+
</a>
|
|
30
|
+
{/if}
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<style>
|
|
34
|
+
.nabu-file { margin: 0.25em 0; user-select: none; display: block; }
|
|
35
|
+
.nabu-file-chip {
|
|
36
|
+
display: inline-flex; align-items: center; gap: 0.4em;
|
|
37
|
+
padding: 0.3em 0.75em; border-radius: 999px;
|
|
38
|
+
border: 1px solid var(--nb-border, rgba(255,255,255,0.2));
|
|
39
|
+
background: var(--nb-bg-surface, rgba(255,255,255,0.06));
|
|
40
|
+
color: var(--nb-text-primary, inherit);
|
|
41
|
+
font-size: 0.875em; text-decoration: none; cursor: pointer;
|
|
42
|
+
transition: background 0.15s;
|
|
43
|
+
}
|
|
44
|
+
.nabu-file-chip:hover { background: var(--nb-bg-hover, rgba(255,255,255,0.12)); }
|
|
45
|
+
.nabu-file.selected .nabu-file-chip { outline: 2px solid var(--nb-accent, #4d9fff); }
|
|
46
|
+
.nabu-file-chip--pending { opacity: 0.6; cursor: default; }
|
|
47
|
+
.nabu-file-chip--error { border-color: var(--nb-error, #f44); color: var(--nb-error, #f44); cursor: default; }
|
|
48
|
+
.nabu-file-chip-status { font-size: 0.8em; opacity: 0.7; }
|
|
49
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default File;
|
|
2
|
+
type File = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const File: import("svelte").Component<{
|
|
7
|
+
block: import("./file.svelte.js").FileBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./file.svelte.js").FileBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const FileExtension: import("../..").Extension;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { extension } from "../../utils/extensions";
|
|
2
|
+
import { FileBlock } from "./file.svelte.js";
|
|
3
|
+
import FileComponent from "./File.svelte";
|
|
4
|
+
import { pickMedia, insertMediaUrl } from "../media/media.helpers.js";
|
|
5
|
+
|
|
6
|
+
export const FileExtension = extension("file", {
|
|
7
|
+
// @ts-ignore — static-side variance on create()
|
|
8
|
+
block: FileBlock,
|
|
9
|
+
component: FileComponent,
|
|
10
|
+
actions: {
|
|
11
|
+
'file:pick': (nabu) => pickMedia(nabu, 'file', '*/*'),
|
|
12
|
+
/**
|
|
13
|
+
* Insert from a URL/ref. data: { ref, name? }
|
|
14
|
+
* @param {import('../nabu.svelte.js').Nabu} nabu
|
|
15
|
+
* @param {{ ref: string, name?: string }} data
|
|
16
|
+
*/
|
|
17
|
+
'file:insert': (nabu, data) => insertMediaUrl(nabu, 'file', data),
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Void file (attachment) block. Extends MediaBlock for shared void/metadata behavior.
|
|
6
|
+
* Renders as a downloadable chip — not an inline media preview.
|
|
7
|
+
*/
|
|
8
|
+
export class FileBlock extends MediaBlock {
|
|
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 htmlRules: {
|
|
14
|
+
selector: string;
|
|
15
|
+
priority: number;
|
|
16
|
+
}[];
|
|
17
|
+
/**
|
|
18
|
+
* @param {Element} el
|
|
19
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
20
|
+
*/
|
|
21
|
+
static fromHTML(el: Element): import("../../utils/extensions.js").PasteBlock;
|
|
22
|
+
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
23
|
+
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): FileBlock;
|
|
24
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
25
|
+
block: import("./file.svelte.js").FileBlock;
|
|
26
|
+
}, {}, "">;
|
|
27
|
+
}
|
|
28
|
+
import { MediaBlock } from "../media/media-block.svelte.js";
|
|
29
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { MediaBlock } from "../media/media-block.svelte.js";
|
|
3
|
+
import FileComponent from "./File.svelte";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Void file (attachment) block. Extends MediaBlock for shared void/metadata behavior.
|
|
11
|
+
* Renders as a downloadable chip — not an inline media preview.
|
|
12
|
+
*/
|
|
13
|
+
// @ts-ignore — static-side variance on create()
|
|
14
|
+
export class FileBlock extends MediaBlock {
|
|
15
|
+
/** @param {Nabu} nabu @param {NabuNode} node */
|
|
16
|
+
constructor(nabu, node) {
|
|
17
|
+
super(nabu, node);
|
|
18
|
+
|
|
19
|
+
this.serializers.set('markdown', () => '[' + (this.name || 'file') + '](' + this.ref + ')');
|
|
20
|
+
this.serializers.set('json', () => ({
|
|
21
|
+
id: this.id,
|
|
22
|
+
type: 'file',
|
|
23
|
+
props: { ref: this.ref, name: this.name },
|
|
24
|
+
}));
|
|
25
|
+
this.serializers.set('application/x-nabu+json', () => ({
|
|
26
|
+
type: 'file',
|
|
27
|
+
props: { ref: this.ref, name: this.name },
|
|
28
|
+
partial: false,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
component = $derived(this.nabu.components.get("file") || FileComponent);
|
|
33
|
+
|
|
34
|
+
// ── Statics ──────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
37
|
+
static toMarkdown(pb) {
|
|
38
|
+
return '[' + (pb.props?.name || 'file') + '](' + (pb.props?.ref || '') + ')';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
42
|
+
static toHtml(pb) {
|
|
43
|
+
return '<a href="' + (pb.props?.ref || '') + '" download="' + (pb.props?.name || '') + '">' + (pb.props?.name || 'file') + '</a>';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static htmlRules = [
|
|
47
|
+
{ selector: 'a[download]', priority: 10 },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {Element} el
|
|
52
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
53
|
+
*/
|
|
54
|
+
static fromHTML(el) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'file',
|
|
57
|
+
props: {
|
|
58
|
+
ref: el.getAttribute('href') || '',
|
|
59
|
+
name: el.getAttribute('download') || el.textContent || '',
|
|
60
|
+
},
|
|
61
|
+
partial: false,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
66
|
+
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
67
|
+
const node = MediaBlock.createNode(nabu, 'file', props, parentId, index);
|
|
68
|
+
const block = new FileBlock(nabu, /** @type {any} */ (node));
|
|
69
|
+
return block;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import RichText from '../../behaviors/text/RichText.svelte';
|
|
3
|
+
import { getPlaceholder } from '../../utils/placeholders.js';
|
|
3
4
|
/** @type {{block: import('./heading.svelte.js').Heading}}*/
|
|
4
5
|
let {block} = $props();
|
|
5
6
|
</script>
|
|
@@ -9,6 +10,7 @@
|
|
|
9
10
|
bind:this={block.element}
|
|
10
11
|
data-block-id={block.id}
|
|
11
12
|
data-block-type="heading"
|
|
13
|
+
data-placeholder={block.text ? '' : getPlaceholder('heading', block.level)}
|
|
12
14
|
class="nabu-heading"
|
|
13
15
|
class:debug={block.nabu.debugging}
|
|
14
16
|
class:selected={block.selected}
|
|
@@ -18,7 +20,7 @@
|
|
|
18
20
|
|
|
19
21
|
<style>
|
|
20
22
|
.nabu-heading {
|
|
21
|
-
margin-top:
|
|
23
|
+
margin-top: 0rem;
|
|
22
24
|
margin-bottom: 0.5rem;
|
|
23
25
|
white-space: pre-wrap;
|
|
24
26
|
outline: none;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
-
* @import { TextNode } from "../../behaviors/text";
|
|
4
3
|
*/
|
|
5
4
|
/**
|
|
6
5
|
* @typedef {NabuNode<{type: "heading", text: LoroText, level: number}>} HeadingNode
|
|
7
6
|
*/
|
|
8
|
-
export class Heading extends
|
|
7
|
+
export class Heading extends TextBlock {
|
|
9
8
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
10
9
|
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
11
10
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
@@ -46,36 +45,18 @@ export class Heading extends Block {
|
|
|
46
45
|
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): Heading;
|
|
47
46
|
/** @param {Nabu} nabu @param {HeadingNode} node */
|
|
48
47
|
constructor(nabu: Nabu, node: HeadingNode);
|
|
49
|
-
container: LoroText;
|
|
50
|
-
/** @type {TextBehavior} */
|
|
51
|
-
behavior: TextBehavior;
|
|
52
48
|
/** @type {number} */
|
|
53
49
|
level: number;
|
|
54
50
|
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
55
|
-
block: import("./heading.svelte").Heading;
|
|
51
|
+
block: import("./heading.svelte.js").Heading;
|
|
56
52
|
}, {}, "">;
|
|
57
|
-
get text(): string;
|
|
58
|
-
get delta(): import("loro-crdt").Delta<string>[];
|
|
59
|
-
selection: {
|
|
60
|
-
from: number;
|
|
61
|
-
to: number;
|
|
62
|
-
isCollapsed: boolean;
|
|
63
|
-
direction: "forward" | "backward" | "none";
|
|
64
|
-
} | null;
|
|
65
|
-
/** @param {Block} block */
|
|
66
|
-
absorbs(block: Block): boolean;
|
|
67
|
-
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
68
|
-
applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
|
|
69
|
-
/** @param {Parameters<Block["split"]>[0]} [options] @returns {ReturnType<Block["split"]>} */
|
|
70
|
-
split(options?: Parameters<Block["split"]>[0]): ReturnType<Block["split"]>;
|
|
71
53
|
}
|
|
72
54
|
export type HeadingNode = NabuNode<{
|
|
73
55
|
type: "heading";
|
|
74
56
|
text: LoroText;
|
|
75
57
|
level: number;
|
|
76
58
|
}>;
|
|
77
|
-
import {
|
|
78
|
-
import { LoroText } from "loro-crdt";
|
|
79
|
-
import { TextBehavior } from "../../behaviors/text";
|
|
59
|
+
import { TextBlock } from "../text-block.svelte.js";
|
|
80
60
|
import type { Nabu } from "../nabu.svelte.js";
|
|
61
|
+
import { LoroText } from "loro-crdt";
|
|
81
62
|
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TextBlock } from "../text-block.svelte.js";
|
|
2
|
+
import { deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
2
3
|
import HeadingComponent from "./Heading.svelte";
|
|
3
|
-
import { Block } from "../block.svelte.js";
|
|
4
4
|
import { LoroText } from "loro-crdt";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
8
|
-
* @import { TextNode } from "../../behaviors/text";
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* @typedef {NabuNode<{type: "heading", text: LoroText, level: number}>} HeadingNode
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
|
-
export class Heading extends
|
|
14
|
+
export class Heading extends TextBlock {
|
|
16
15
|
/** @param {Nabu} nabu @param {HeadingNode} node */
|
|
17
16
|
constructor(nabu, node) {
|
|
18
17
|
super(nabu, node);
|
|
19
18
|
const data = node.data;
|
|
20
|
-
this.container = data.get("text") ?? data.setContainer("text", new LoroText());
|
|
21
|
-
|
|
22
|
-
/** @type {TextBehavior} */
|
|
23
|
-
this.behavior = new TextBehavior(this, this.container);
|
|
24
|
-
this.behaviors.set("text", this.behavior);
|
|
25
19
|
|
|
26
20
|
this.level = data.get("level") || 1;
|
|
27
21
|
|
|
@@ -33,7 +27,7 @@ export class Heading extends Block {
|
|
|
33
27
|
content: this.behavior.toJSON()
|
|
34
28
|
}));
|
|
35
29
|
this.serializers.set('application/x-nabu+json', (ctx) => this.behavior.toClipboardBlock({ ...ctx, props: { level: this.level } }));
|
|
36
|
-
|
|
30
|
+
|
|
37
31
|
// Synchronisation du niveau
|
|
38
32
|
this.node.data.subscribe(() => {
|
|
39
33
|
this.level = this.node.data.get("level") || 1;
|
|
@@ -44,43 +38,6 @@ export class Heading extends Block {
|
|
|
44
38
|
level = $state(1);
|
|
45
39
|
|
|
46
40
|
component = $derived(this.nabu.components.get("heading") || HeadingComponent);
|
|
47
|
-
|
|
48
|
-
get text() {
|
|
49
|
-
return this.behavior.text;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get delta() {
|
|
53
|
-
return this.behavior.delta;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
selection = $derived(this.behavior.selection);
|
|
57
|
-
positions = $derived(this.behavior.positions);
|
|
58
|
-
|
|
59
|
-
/** @param {InputEvent} event */
|
|
60
|
-
beforeinput(event) {
|
|
61
|
-
return this.behavior.handleBeforeInput(event);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @param {number} targetOffset
|
|
66
|
-
* @returns {{node: Node, offset: number} | null}
|
|
67
|
-
*/
|
|
68
|
-
getDOMPoint(targetOffset) { return this.behavior.getDOMPoint(targetOffset); }
|
|
69
|
-
|
|
70
|
-
/** @param {Block} block */
|
|
71
|
-
absorbs(block) { return this.behavior.absorbs(block); }
|
|
72
|
-
|
|
73
|
-
/** @param {number} index @param {string} text */
|
|
74
|
-
insert(index, text) { return this.behavior.insert(index, text); }
|
|
75
|
-
|
|
76
|
-
/** @param {Parameters<Block["delete"]>[0]} [deletion] */
|
|
77
|
-
delete(deletion) { return this.behavior.delete(deletion); }
|
|
78
|
-
|
|
79
|
-
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
80
|
-
applyDelta(data = []) { return this.behavior.applyDelta(data); }
|
|
81
|
-
|
|
82
|
-
/** @param {Parameters<Block["split"]>[0]} [options] @returns {ReturnType<Block["split"]>} */
|
|
83
|
-
split(options) { return this.behavior.split(options); }
|
|
84
41
|
|
|
85
42
|
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
86
43
|
static toMarkdown(pb) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {{ block: import('./image.svelte.js').ImageBlock }} */
|
|
3
|
+
let { block } = $props();
|
|
4
|
+
const src = $derived(block.displaySrc);
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<figure
|
|
8
|
+
bind:this={block.element}
|
|
9
|
+
data-block-id={block.id}
|
|
10
|
+
data-block-type="image"
|
|
11
|
+
data-nabu-inert
|
|
12
|
+
contenteditable="false"
|
|
13
|
+
class="nabu-image"
|
|
14
|
+
class:selected={block.selected}
|
|
15
|
+
class:pending={block.status === 'pending'}
|
|
16
|
+
class:error={block.status === 'error'}
|
|
17
|
+
>
|
|
18
|
+
{#if block.status === 'error'}
|
|
19
|
+
<div class="nabu-image-error">⚠️ Upload failed</div>
|
|
20
|
+
{:else if src}
|
|
21
|
+
<img src={src} alt={block.alt} draggable="false" />
|
|
22
|
+
{#if block.status === 'pending'}<div class="nabu-image-spinner">Uploading…</div>{/if}
|
|
23
|
+
{:else}
|
|
24
|
+
<div class="nabu-image-empty">No image</div>
|
|
25
|
+
{/if}
|
|
26
|
+
</figure>
|
|
27
|
+
|
|
28
|
+
<style>
|
|
29
|
+
.nabu-image { margin: 0.5em 0; user-select: none; position: relative; display: block; max-width: 100%; }
|
|
30
|
+
.nabu-image img { max-width: 100%; height: auto; border-radius: 6px; display: block; }
|
|
31
|
+
.nabu-image.selected img { outline: 2px solid var(--nb-accent, #4d9fff); }
|
|
32
|
+
.nabu-image.pending img { opacity: 0.6; }
|
|
33
|
+
.nabu-image-spinner, .nabu-image-error, .nabu-image-empty {
|
|
34
|
+
position: absolute; inset: auto 0 0 0; padding: 4px 8px; font-size: 12px;
|
|
35
|
+
background: var(--nb-bg-surface, rgba(0,0,0,0.6)); color: var(--nb-text-primary, #fff); border-radius: 0 0 6px 6px;
|
|
36
|
+
}
|
|
37
|
+
.nabu-image-empty, .nabu-image-error { position: static; padding: 1.5em; text-align: center; border: 1px dashed var(--nb-border, rgba(255,255,255,0.2)); border-radius: 6px; color: var(--nb-text-muted, rgba(255,255,255,0.4)); }
|
|
38
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Image;
|
|
2
|
+
type Image = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Image: import("svelte").Component<{
|
|
7
|
+
block: import("./image.svelte.js").ImageBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./image.svelte.js").ImageBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { extension } from "../../utils/extensions";
|
|
2
|
+
import { ImageBlock } from "./image.svelte.js";
|
|
3
|
+
import ImageComponent from "./Image.svelte";
|
|
4
|
+
import { insertMediaFromFile, pickMedia, insertMediaUrl } from "../media/media.helpers.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Insert an image block from a local File: optimistic preview → persist → ref.
|
|
8
|
+
* Re-exported for back-compat.
|
|
9
|
+
* @param {import('../nabu.svelte.js').Nabu} nabu @param {File} file
|
|
10
|
+
*/
|
|
11
|
+
export const insertImageFromFile = (nabu, file) => insertMediaFromFile(nabu, 'image', file);
|
|
12
|
+
|
|
13
|
+
export const ImageExtension = extension("image", {
|
|
14
|
+
// @ts-ignore — static-side variance on create()
|
|
15
|
+
block: ImageBlock,
|
|
16
|
+
component: ImageComponent,
|
|
17
|
+
actions: {
|
|
18
|
+
'image:pick': (nabu) => pickMedia(nabu, 'image', 'image/*'),
|
|
19
|
+
/**
|
|
20
|
+
* Insert from a URL (external ref). data: { ref, alt? }
|
|
21
|
+
* @param {import('../nabu.svelte.js').Nabu} nabu
|
|
22
|
+
* @param {{ ref: string, alt?: string }} data
|
|
23
|
+
*/
|
|
24
|
+
'image:insert': (nabu, data) => insertMediaUrl(nabu, 'image', data),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{type: "image", ref: string, alt: string, status: string}>} ImageNode
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Void image block. Extends MediaBlock for shared void/metadata behavior.
|
|
9
|
+
* No editable text — renders an inert <figure> with a single cursor position.
|
|
10
|
+
*/
|
|
11
|
+
export class ImageBlock extends MediaBlock {
|
|
12
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
13
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
14
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
15
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
16
|
+
static htmlRules: {
|
|
17
|
+
selector: string;
|
|
18
|
+
}[];
|
|
19
|
+
/**
|
|
20
|
+
* @param {Element} el
|
|
21
|
+
* @returns {import('../../utils/extensions.js').PasteBlock}
|
|
22
|
+
*/
|
|
23
|
+
static fromHTML(el: Element): import("../../utils/extensions.js").PasteBlock;
|
|
24
|
+
static markdownRules: {
|
|
25
|
+
priority: number;
|
|
26
|
+
detect: RegExp;
|
|
27
|
+
consume: () => number;
|
|
28
|
+
}[];
|
|
29
|
+
/**
|
|
30
|
+
* @param {string[]} lines
|
|
31
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
32
|
+
*/
|
|
33
|
+
static fromMarkdown(lines: string[]): import("../../utils/extensions.js").PasteBlock | null;
|
|
34
|
+
/** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
35
|
+
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): ImageBlock;
|
|
36
|
+
/** @param {Nabu} nabu @param {ImageNode} node */
|
|
37
|
+
constructor(nabu: Nabu, node: ImageNode);
|
|
38
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
39
|
+
block: import("./image.svelte.js").ImageBlock;
|
|
40
|
+
}, {}, "">;
|
|
41
|
+
}
|
|
42
|
+
export type ImageNode = NabuNode<{
|
|
43
|
+
type: "image";
|
|
44
|
+
ref: string;
|
|
45
|
+
alt: string;
|
|
46
|
+
status: string;
|
|
47
|
+
}>;
|
|
48
|
+
import { MediaBlock } from "../media/media-block.svelte.js";
|
|
49
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
50
|
+
import type { NabuNode } from "../nabu.svelte.js";
|