@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,84 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Block from "../Block.svelte";
|
|
3
|
+
import RichText from '../../behaviors/text/RichText.svelte';
|
|
4
|
+
import { getPlaceholder } from '../../utils/placeholders.js';
|
|
5
|
+
/** @type {{ block: import('./toggle.svelte.js').ToggleBlock }} */
|
|
6
|
+
let { block } = $props();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div class="nabu-toggle" class:collapsed={block.collapsed}>
|
|
10
|
+
<div class="nabu-toggle-head">
|
|
11
|
+
<button
|
|
12
|
+
class="nabu-toggle-arrow"
|
|
13
|
+
data-nabu-ui
|
|
14
|
+
contenteditable="false"
|
|
15
|
+
type="button"
|
|
16
|
+
aria-expanded={!block.collapsed}
|
|
17
|
+
onmousedown={(e) => { e.preventDefault(); block.toggleCollapsed(); }}
|
|
18
|
+
>{block.collapsed ? '▸' : '▾'}</button>
|
|
19
|
+
<div
|
|
20
|
+
bind:this={block.element}
|
|
21
|
+
class="nabu-toggle-header"
|
|
22
|
+
data-block-id={block.id}
|
|
23
|
+
data-block-type="toggle"
|
|
24
|
+
data-placeholder={block.text ? '' : getPlaceholder('toggle')}
|
|
25
|
+
><RichText delta={block.delta} /></div>
|
|
26
|
+
</div>
|
|
27
|
+
{#if !block.collapsed}
|
|
28
|
+
<div class="nabu-toggle-body">
|
|
29
|
+
{#each block.children as child (child.id)}<Block block={child} />{/each}
|
|
30
|
+
</div>
|
|
31
|
+
{/if}
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<style>
|
|
35
|
+
.nabu-toggle {
|
|
36
|
+
margin: 0.25em 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.nabu-toggle-head {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: row;
|
|
42
|
+
align-items: flex-start;
|
|
43
|
+
gap: 0.25em;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.nabu-toggle-arrow {
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
width: 1.4em;
|
|
49
|
+
height: 1.5em;
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
background: none;
|
|
54
|
+
border: none;
|
|
55
|
+
padding: 0;
|
|
56
|
+
margin: 0;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
user-select: none;
|
|
59
|
+
font-size: 0.85em;
|
|
60
|
+
line-height: 1.6;
|
|
61
|
+
outline: none;
|
|
62
|
+
color: var(--nb-text-secondary, rgba(255, 255, 255, 0.45));
|
|
63
|
+
transition: color 0.15s ease;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.nabu-toggle-arrow:hover {
|
|
67
|
+
color: var(--nb-text-primary, rgba(255, 255, 255, 0.85));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.nabu-toggle-header {
|
|
71
|
+
flex: 1;
|
|
72
|
+
outline: none;
|
|
73
|
+
white-space: pre-wrap;
|
|
74
|
+
min-height: 1.5em;
|
|
75
|
+
line-height: 1.6;
|
|
76
|
+
color: var(--nb-text-primary, rgba(255, 255, 255, 0.85));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.nabu-toggle-body {
|
|
80
|
+
margin-left: 1.4em;
|
|
81
|
+
padding-left: 0.25em;
|
|
82
|
+
border-left: 2px solid var(--nb-border, rgba(255, 255, 255, 0.1));
|
|
83
|
+
}
|
|
84
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Toggle;
|
|
2
|
+
type Toggle = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Toggle: import("svelte").Component<{
|
|
7
|
+
block: import("./toggle.svelte.js").ToggleBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./toggle.svelte.js").ToggleBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ToggleExtension: import("../..").Extension;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { extension } from "../../utils/extensions";
|
|
2
|
+
import { ToggleBlock } from "./toggle.svelte.js";
|
|
3
|
+
import ToggleComponent from "./Toggle.svelte";
|
|
4
|
+
|
|
5
|
+
export const ToggleExtension = extension("toggle", {
|
|
6
|
+
// @ts-ignore — static-side variance on create()
|
|
7
|
+
block: ToggleBlock,
|
|
8
|
+
component: ToggleComponent,
|
|
9
|
+
actions: {
|
|
10
|
+
'toggle': (nabu) => nabu.exec('block:transform', { type: 'toggle' }),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{type: "toggle", text: LoroText, collapsed: boolean}>} ToggleNode
|
|
6
|
+
*/
|
|
7
|
+
export class ToggleBlock extends MegaBlock {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
10
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string }} helpers
|
|
11
|
+
*/
|
|
12
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
13
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock, ctx?: object) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
17
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
18
|
+
*/
|
|
19
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock, { recurse }: {
|
|
20
|
+
recurse: (child: import("../../utils/extensions.js").PasteBlock) => string;
|
|
21
|
+
}): string;
|
|
22
|
+
static htmlRules: {
|
|
23
|
+
selector: string;
|
|
24
|
+
}[];
|
|
25
|
+
/**
|
|
26
|
+
* @param {Element} el
|
|
27
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[], parseChildren?: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
28
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
29
|
+
*/
|
|
30
|
+
static fromHTML(el: Element, { parseInline, parseChildren }: {
|
|
31
|
+
parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
|
|
32
|
+
parseChildren?: (el: Element) => import("../../utils/extensions.js").PasteBlock[];
|
|
33
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
34
|
+
/**
|
|
35
|
+
* @param {Nabu} nabu
|
|
36
|
+
* @param {string} type
|
|
37
|
+
* @param {Object} [props={}]
|
|
38
|
+
* @param {string|null} [parentId=null]
|
|
39
|
+
* @param {number|null} [index=null]
|
|
40
|
+
*/
|
|
41
|
+
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): ToggleBlock;
|
|
42
|
+
/** @param {Nabu} nabu @param {ToggleNode} node */
|
|
43
|
+
constructor(nabu: Nabu, node: ToggleNode);
|
|
44
|
+
container: LoroText;
|
|
45
|
+
/** @type {TextBehavior} */
|
|
46
|
+
behavior: TextBehavior;
|
|
47
|
+
/** @type {boolean} */
|
|
48
|
+
collapsed: boolean;
|
|
49
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
50
|
+
block: import("./toggle.svelte.js").ToggleBlock;
|
|
51
|
+
}, {}, "">;
|
|
52
|
+
get text(): string;
|
|
53
|
+
get delta(): import("loro-crdt").Delta<string>[];
|
|
54
|
+
selection: {
|
|
55
|
+
from: number;
|
|
56
|
+
to: number;
|
|
57
|
+
isCollapsed: boolean;
|
|
58
|
+
direction: "forward" | "backward" | "none";
|
|
59
|
+
} | null;
|
|
60
|
+
/**
|
|
61
|
+
* Set the collapsed state and persist to Loro.
|
|
62
|
+
* @param {boolean} v
|
|
63
|
+
*/
|
|
64
|
+
setCollapsed(v: boolean): void;
|
|
65
|
+
/**
|
|
66
|
+
* Toggle the collapsed state.
|
|
67
|
+
*/
|
|
68
|
+
toggleCollapsed(): void;
|
|
69
|
+
/** @param {import('../block.svelte.js').Block} block */
|
|
70
|
+
absorbs(block: import("../block.svelte.js").Block): boolean;
|
|
71
|
+
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
72
|
+
applyDelta(data?: import("loro-crdt").Delta<string>[]): void;
|
|
73
|
+
/**
|
|
74
|
+
* @param {InputEvent} event
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
beforeinput(event: InputEvent): boolean;
|
|
78
|
+
}
|
|
79
|
+
export type ToggleNode = NabuNode<{
|
|
80
|
+
type: "toggle";
|
|
81
|
+
text: LoroText;
|
|
82
|
+
collapsed: boolean;
|
|
83
|
+
}>;
|
|
84
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
85
|
+
import { LoroText } from "loro-crdt";
|
|
86
|
+
import { TextBehavior } from "../../behaviors/text";
|
|
87
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
88
|
+
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { MegaBlock } from "../megablock.svelte.js";
|
|
2
|
+
import { TextBehavior, deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
|
|
3
|
+
import { LoroText } from "loro-crdt";
|
|
4
|
+
import ToggleComponent from "./Toggle.svelte";
|
|
5
|
+
import { tick } from "svelte";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {NabuNode<{type: "toggle", text: LoroText, collapsed: boolean}>} ToggleNode
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// @ts-ignore — static-side variance on create()
|
|
16
|
+
export class ToggleBlock extends MegaBlock {
|
|
17
|
+
/** @param {Nabu} nabu @param {ToggleNode} node */
|
|
18
|
+
constructor(nabu, node) {
|
|
19
|
+
super(nabu, node);
|
|
20
|
+
|
|
21
|
+
const data = node.data;
|
|
22
|
+
this.container = data.get("text") ?? data.setContainer("text", new LoroText());
|
|
23
|
+
|
|
24
|
+
/** @type {TextBehavior} */
|
|
25
|
+
this.behavior = new TextBehavior(this, this.container);
|
|
26
|
+
this.behaviors.set("text", this.behavior);
|
|
27
|
+
|
|
28
|
+
// Initialize collapsed from Loro metadata
|
|
29
|
+
this.collapsed = !!data.get('collapsed');
|
|
30
|
+
// Subscribe to data changes to keep collapsed in sync
|
|
31
|
+
this.node.data.subscribe(() => {
|
|
32
|
+
this.collapsed = !!this.node.data.get('collapsed');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.serializers.set('markdown', () => {
|
|
36
|
+
const head = this.behavior.toMarkdown();
|
|
37
|
+
const body = this.children.map(c => c.serialize('markdown')).filter(Boolean).join('\n\n');
|
|
38
|
+
return '<details><summary>' + head + '</summary>\n\n' + body + '\n\n</details>';
|
|
39
|
+
});
|
|
40
|
+
this.serializers.set('json', () => ({
|
|
41
|
+
id: this.id,
|
|
42
|
+
type: 'toggle',
|
|
43
|
+
props: { collapsed: this.collapsed },
|
|
44
|
+
content: this.behavior.toJSON(),
|
|
45
|
+
children: this.children.map(c => c.serialize('json')).filter(Boolean)
|
|
46
|
+
}));
|
|
47
|
+
this.serializers.set('application/x-nabu+json', () => ({
|
|
48
|
+
type: 'toggle',
|
|
49
|
+
props: { collapsed: this.collapsed },
|
|
50
|
+
delta: this.container.sliceDelta(0, this.container.length),
|
|
51
|
+
children: this.children.map(c => c.serialize('application/x-nabu+json')).filter(Boolean)
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── Capability flags ────────────────────────────────────────────────────
|
|
56
|
+
// A typed "# " must not transform the toggle header away
|
|
57
|
+
transformsEnabled = false;
|
|
58
|
+
// marksEnabled stays true (default) — bold/italic work inside the header
|
|
59
|
+
// splitsOnEnter is not set (defaults true) but Enter is overridden in beforeinput
|
|
60
|
+
|
|
61
|
+
/** @type {boolean} */
|
|
62
|
+
collapsed = $state(false);
|
|
63
|
+
|
|
64
|
+
component = $derived(this.nabu.components.get("toggle") || ToggleComponent);
|
|
65
|
+
|
|
66
|
+
get text() { return this.behavior.text; }
|
|
67
|
+
get delta() { return this.behavior.delta; }
|
|
68
|
+
|
|
69
|
+
selection = $derived(this.behavior.selection);
|
|
70
|
+
|
|
71
|
+
// When collapsed, exclude children from positions so cursor cannot enter hidden body
|
|
72
|
+
positions = $derived(this.behavior.positions + (this.collapsed ? 0 : super.positions));
|
|
73
|
+
|
|
74
|
+
// Count body words regardless of collapse state
|
|
75
|
+
wordCount = $derived((this.behavior?.wordCount ?? 0) + this.children.reduce((s, c) => s + (c.wordCount ?? 0), 0));
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Mixed block: own text comes first, then children.
|
|
79
|
+
* When collapsed, children are excluded from navigation.
|
|
80
|
+
* @param {number} localOffset
|
|
81
|
+
* @returns {{ block: import('../block.svelte.js').Block, offset: number } | null}
|
|
82
|
+
*/
|
|
83
|
+
resolveOffset(localOffset) {
|
|
84
|
+
const textPositions = this.behavior.positions; // text.length + 1
|
|
85
|
+
if (this.collapsed || localOffset < textPositions || !this.children.length) {
|
|
86
|
+
return { block: this, offset: Math.min(localOffset, this.behavior.text.length) };
|
|
87
|
+
}
|
|
88
|
+
let remaining = localOffset - textPositions;
|
|
89
|
+
for (const child of this.children) {
|
|
90
|
+
const cp = child.positions ?? 0;
|
|
91
|
+
if (remaining < cp) return child.resolveOffset(remaining);
|
|
92
|
+
remaining -= cp;
|
|
93
|
+
}
|
|
94
|
+
return { block: this, offset: this.behavior.text.length };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── Collapse control ────────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Set the collapsed state and persist to Loro.
|
|
101
|
+
* @param {boolean} v
|
|
102
|
+
*/
|
|
103
|
+
setCollapsed(v) {
|
|
104
|
+
this.collapsed = !!v;
|
|
105
|
+
/** @type {any} */ (this.node.data).set('collapsed', !!v);
|
|
106
|
+
this.commit();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Toggle the collapsed state.
|
|
111
|
+
*/
|
|
112
|
+
toggleCollapsed() {
|
|
113
|
+
this.setCollapsed(!this.collapsed);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ── Proxies to TextBehavior ─────────────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {number} targetOffset
|
|
120
|
+
* @returns {{node: Node, offset: number} | null}
|
|
121
|
+
*/
|
|
122
|
+
getDOMPoint(targetOffset) { return this.behavior.getDOMPoint(targetOffset); }
|
|
123
|
+
|
|
124
|
+
/** @param {import('../block.svelte.js').Block} block */
|
|
125
|
+
absorbs(block) { return this.behavior.absorbs(block); }
|
|
126
|
+
|
|
127
|
+
/** @param {number} index @param {string} text */
|
|
128
|
+
insert(index, text) { return this.behavior.insert(index, text); }
|
|
129
|
+
|
|
130
|
+
/** @param {Parameters<import('../block.svelte.js').Block["delete"]>[0]} [deletion] */
|
|
131
|
+
delete(deletion) { return this.behavior.delete(deletion); }
|
|
132
|
+
|
|
133
|
+
/** @param {import('loro-crdt').Delta<string>[]} data */
|
|
134
|
+
applyDelta(data = []) { return this.behavior.applyDelta(data); }
|
|
135
|
+
|
|
136
|
+
// ── Custom beforeinput (handles Enter and Backspace-to-untoggle) ────────
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {InputEvent} event
|
|
140
|
+
* @returns {boolean}
|
|
141
|
+
*/
|
|
142
|
+
beforeinput(event) {
|
|
143
|
+
const sel = this.behavior.selection;
|
|
144
|
+
|
|
145
|
+
// Enter in the header → split: keep before-cursor in header, move after-cursor
|
|
146
|
+
// into a new paragraph as the FIRST body child; expand the toggle; focus it.
|
|
147
|
+
// NOTE: Two commits happen — one from setCollapsed (if needed) + one from nabu.commit().
|
|
148
|
+
// This is intentional for simplicity; correctness over micro-optimization.
|
|
149
|
+
if (event.inputType === 'insertParagraph' && sel) {
|
|
150
|
+
const from = sel.from;
|
|
151
|
+
const to = sel.isCollapsed ? this.behavior.text.length : sel.to;
|
|
152
|
+
const delta = this.container.sliceDelta(from, to);
|
|
153
|
+
if (this.behavior.text.length > from) {
|
|
154
|
+
this.behavior.delete({ index: from, length: this.behavior.text.length - from });
|
|
155
|
+
}
|
|
156
|
+
if (this.collapsed) {
|
|
157
|
+
// setCollapsed commits; the insert below commits again — acceptable
|
|
158
|
+
this.setCollapsed(false);
|
|
159
|
+
}
|
|
160
|
+
const p = this.nabu.insert('paragraph', { delta }, this.node.id.toString(), 0);
|
|
161
|
+
this.nabu.commit().then(() => {
|
|
162
|
+
const f = this.nabu.blocks.get(p.id);
|
|
163
|
+
if (f) this.nabu.selection.setCursor(f, 0);
|
|
164
|
+
});
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Backspace at start of an EMPTY header with NO body → de-transform to paragraph.
|
|
169
|
+
if (event.inputType === 'deleteContentBackward' && sel?.isCollapsed && sel.from === 0
|
|
170
|
+
&& this.behavior.text.length === 0 && this.children.length === 0) {
|
|
171
|
+
const id = this.node.id.toString();
|
|
172
|
+
this.transformTo('paragraph');
|
|
173
|
+
tick().then(() => {
|
|
174
|
+
const f = this.nabu.blocks.get(id);
|
|
175
|
+
if (f) f.focus({ start: 0, end: 0 });
|
|
176
|
+
});
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return this.behavior.handleBeforeInput(event);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ── Statics ─────────────────────────────────────────────────────────────
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
187
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock, ctx?: object) => string }} helpers
|
|
188
|
+
*/
|
|
189
|
+
static toMarkdown(pb, { recurse }) {
|
|
190
|
+
const head = deltaToMarkdown(pb.delta || []);
|
|
191
|
+
const body = (pb.children || []).map(c => recurse(c)).join('\n\n');
|
|
192
|
+
return '<details><summary>' + head + '</summary>\n\n' + body + '\n\n</details>';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @param {import('../../utils/extensions.js').PasteBlock} pb
|
|
197
|
+
* @param {{ recurse: (child: import('../../utils/extensions.js').PasteBlock) => string }} helpers
|
|
198
|
+
*/
|
|
199
|
+
static toHtml(pb, { recurse }) {
|
|
200
|
+
const open = pb.props?.collapsed ? '' : ' open';
|
|
201
|
+
const head = deltaToHtml(pb.delta || []);
|
|
202
|
+
const body = (pb.children || []).map(c => recurse(c)).join('');
|
|
203
|
+
return '<details' + open + '><summary>' + head + '</summary>' + body + '</details>';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static htmlRules = [{ selector: 'details' }];
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @param {Element} el
|
|
210
|
+
* @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[], parseChildren?: (el: Element) => import('../../utils/extensions.js').PasteBlock[] }} helpers
|
|
211
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
212
|
+
*/
|
|
213
|
+
static fromHTML(el, { parseInline, parseChildren }) {
|
|
214
|
+
// Use 'summary' without :scope because happy-dom doesn't support :scope pseudo-class
|
|
215
|
+
const summary = /** @type {Element | null} */ ([...el.children].find(c => c.tagName.toLowerCase() === 'summary') || null);
|
|
216
|
+
const delta = summary ? parseInline(summary) : [];
|
|
217
|
+
const collapsed = !el.hasAttribute('open');
|
|
218
|
+
// Parse non-summary child elements as body blocks
|
|
219
|
+
const bodyEls = [...el.children].filter(c => c.tagName.toLowerCase() !== 'summary');
|
|
220
|
+
/** @type {import('../../utils/extensions.js').PasteBlock[]} */
|
|
221
|
+
let children = [];
|
|
222
|
+
if (parseChildren && bodyEls.length) {
|
|
223
|
+
// Create a temporary wrapper with only the non-summary children
|
|
224
|
+
const ownerDoc = el.ownerDocument;
|
|
225
|
+
if (ownerDoc) {
|
|
226
|
+
const wrapper = ownerDoc.createElement('div');
|
|
227
|
+
for (const bodyEl of bodyEls) {
|
|
228
|
+
wrapper.appendChild(bodyEl.cloneNode(true));
|
|
229
|
+
}
|
|
230
|
+
children = parseChildren(wrapper);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return { type: 'toggle', props: { collapsed }, delta, partial: false, ...(children.length ? { children } : {}) };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @param {Nabu} nabu
|
|
238
|
+
* @param {string} type
|
|
239
|
+
* @param {Object} [props={}]
|
|
240
|
+
* @param {string|null} [parentId=null]
|
|
241
|
+
* @param {number|null} [index=null]
|
|
242
|
+
*/
|
|
243
|
+
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
244
|
+
const node = nabu.tree.createNode(parentId || undefined, index != null ? index : undefined);
|
|
245
|
+
/** @type {any} */ (node.data).set('type', 'toggle');
|
|
246
|
+
/** @type {any} */ (node.data).set('collapsed', props.collapsed ?? false);
|
|
247
|
+
const container = /** @type {any} */ (node.data).setContainer('text', new LoroText());
|
|
248
|
+
if (props.text) container.insert(0, props.text);
|
|
249
|
+
if (props.delta) container.applyDelta([...props.delta]);
|
|
250
|
+
return new ToggleBlock(nabu, /** @type {ToggleNode} */ (/** @type {unknown} */ (node)));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Block} from "./block.svelte.js"
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @template {Block} [TBlock=Block]
|
|
6
|
+
* @typedef {Object} VariableInit
|
|
7
|
+
* @property {"string"|"number"|"boolean"} type - The variable type (e.g., "string", "number", "boolean").
|
|
8
|
+
* @property {function(TBlock): any} get - A function that returns the current value of the variable.
|
|
9
|
+
* @property {function(TBlock, any): void} [set] - A function that updates the variable's value.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @template {Block} [TBlock=Block]
|
|
13
|
+
*/
|
|
14
|
+
export class Variable<TBlock extends Block = Block> {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Variable instance.
|
|
17
|
+
* @param {TBlock} block - The block that owns this variable.
|
|
18
|
+
* @param {string} name
|
|
19
|
+
* @param {VariableInit<TBlock>} init
|
|
20
|
+
*/
|
|
21
|
+
constructor(block: TBlock, name: string, init: VariableInit<TBlock>);
|
|
22
|
+
block: TBlock;
|
|
23
|
+
name: string;
|
|
24
|
+
init: VariableInit<TBlock>;
|
|
25
|
+
type: "string" | "number" | "boolean";
|
|
26
|
+
get: (arg0: TBlock) => any;
|
|
27
|
+
set: ((arg0: TBlock, arg1: any) => void) | undefined;
|
|
28
|
+
writable: boolean;
|
|
29
|
+
set value(newValue: any);
|
|
30
|
+
get value(): any;
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
33
|
+
export type VariableInit<TBlock extends Block = Block> = {
|
|
34
|
+
/**
|
|
35
|
+
* - The variable type (e.g., "string", "number", "boolean").
|
|
36
|
+
*/
|
|
37
|
+
type: "string" | "number" | "boolean";
|
|
38
|
+
/**
|
|
39
|
+
* - A function that returns the current value of the variable.
|
|
40
|
+
*/
|
|
41
|
+
get: (arg0: TBlock) => any;
|
|
42
|
+
/**
|
|
43
|
+
* - A function that updates the variable's value.
|
|
44
|
+
*/
|
|
45
|
+
set?: ((arg0: TBlock, arg1: any) => void) | undefined;
|
|
46
|
+
};
|
|
47
|
+
import type { Block } from "./block.svelte.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {Block} from "./block.svelte.js"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @template {Block} [TBlock=Block]
|
|
8
|
+
* @typedef {Object} VariableInit
|
|
9
|
+
* @property {"string"|"number"|"boolean"} type - The variable type (e.g., "string", "number", "boolean").
|
|
10
|
+
* @property {function(TBlock): any} get - A function that returns the current value of the variable.
|
|
11
|
+
* @property {function(TBlock, any): void} [set] - A function that updates the variable's value.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @template {Block} [TBlock=Block]
|
|
16
|
+
*/
|
|
17
|
+
export class Variable {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new Variable instance.
|
|
20
|
+
* @param {TBlock} block - The block that owns this variable.
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @param {VariableInit<TBlock>} init
|
|
23
|
+
*/
|
|
24
|
+
constructor(block, name, init) {
|
|
25
|
+
this.block = block;
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.init = init;
|
|
28
|
+
this.type = init.type;
|
|
29
|
+
this.get = init.get;
|
|
30
|
+
this.set = init.set;
|
|
31
|
+
|
|
32
|
+
this.block.variables.set(name, this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
writable = $derived(!!this.set);
|
|
36
|
+
|
|
37
|
+
set value(newValue) {
|
|
38
|
+
if (!this.set) {
|
|
39
|
+
throw new Error(`Variable "${this.name}" is read-only.`);
|
|
40
|
+
}
|
|
41
|
+
this.set(this.block, newValue);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get value() {
|
|
45
|
+
return this.get(this.block);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
destroy() {
|
|
49
|
+
this.block.variables.delete(this.name);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {{ block: import('./video.svelte.js').VideoBlock }} */
|
|
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="video"
|
|
11
|
+
data-nabu-inert
|
|
12
|
+
contenteditable="false"
|
|
13
|
+
class="nabu-video"
|
|
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-video-error">⚠️ Upload failed</div>
|
|
20
|
+
{:else if src}
|
|
21
|
+
<!-- svelte-ignore a11y_media_has_caption -->
|
|
22
|
+
<video src={src} controls draggable="false"></video>
|
|
23
|
+
{#if block.status === 'pending'}<div class="nabu-video-spinner">Uploading…</div>{/if}
|
|
24
|
+
{:else}
|
|
25
|
+
<div class="nabu-video-empty">No video</div>
|
|
26
|
+
{/if}
|
|
27
|
+
</figure>
|
|
28
|
+
|
|
29
|
+
<style>
|
|
30
|
+
.nabu-video { margin: 0.5em 0; user-select: none; position: relative; display: block; max-width: 100%; }
|
|
31
|
+
.nabu-video video { max-width: 100%; height: auto; border-radius: 6px; display: block; }
|
|
32
|
+
.nabu-video.selected video { outline: 2px solid var(--nb-accent, #4d9fff); }
|
|
33
|
+
.nabu-video.pending video { opacity: 0.6; }
|
|
34
|
+
.nabu-video-spinner, .nabu-video-error, .nabu-video-empty {
|
|
35
|
+
position: absolute; inset: auto 0 0 0; padding: 4px 8px; font-size: 12px;
|
|
36
|
+
background: var(--nb-bg-surface, rgba(0,0,0,0.6)); color: var(--nb-text-primary, #fff); border-radius: 0 0 6px 6px;
|
|
37
|
+
}
|
|
38
|
+
.nabu-video-empty, .nabu-video-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)); }
|
|
39
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Video;
|
|
2
|
+
type Video = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Video: import("svelte").Component<{
|
|
7
|
+
block: import("./video.svelte.js").VideoBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./video.svelte.js").VideoBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VideoExtension: import("../..").Extension;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { extension } from "../../utils/extensions";
|
|
2
|
+
import { VideoBlock } from "./video.svelte.js";
|
|
3
|
+
import VideoComponent from "./Video.svelte";
|
|
4
|
+
import { pickMedia, insertMediaUrl } from "../media/media.helpers.js";
|
|
5
|
+
|
|
6
|
+
export const VideoExtension = extension("video", {
|
|
7
|
+
// @ts-ignore — static-side variance on create()
|
|
8
|
+
block: VideoBlock,
|
|
9
|
+
component: VideoComponent,
|
|
10
|
+
actions: {
|
|
11
|
+
'video:pick': (nabu) => pickMedia(nabu, 'video', 'video/*'),
|
|
12
|
+
/**
|
|
13
|
+
* Insert from a URL (external ref). data: { ref, alt?, name? }
|
|
14
|
+
* @param {import('../nabu.svelte.js').Nabu} nabu
|
|
15
|
+
* @param {{ ref: string, alt?: string, name?: string }} data
|
|
16
|
+
*/
|
|
17
|
+
'video:insert': (nabu, data) => insertMediaUrl(nabu, 'video', data),
|
|
18
|
+
},
|
|
19
|
+
});
|