@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.
Files changed (170) hide show
  1. package/README.md +216 -9
  2. package/dist/behaviors/text/RichText.svelte +4 -1
  3. package/dist/behaviors/text/index.d.ts +2 -0
  4. package/dist/behaviors/text/index.js +2 -0
  5. package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +2 -0
  6. package/dist/behaviors/text/markdown-shortcuts.extension.js +54 -0
  7. package/dist/behaviors/text/rich-text.extension.js +47 -22
  8. package/dist/behaviors/text/text.behavior.svelte.d.ts +25 -1
  9. package/dist/behaviors/text/text.behavior.svelte.js +154 -18
  10. package/dist/behaviors/text/typography.extension.d.ts +6 -0
  11. package/dist/behaviors/text/typography.extension.js +24 -0
  12. package/dist/blocks/Block.svelte +5 -2
  13. package/dist/blocks/Nabu.svelte +22 -0
  14. package/dist/blocks/block.extension.js +10 -8
  15. package/dist/blocks/block.svelte.d.ts +24 -0
  16. package/dist/blocks/block.svelte.js +35 -0
  17. package/dist/blocks/blockquote/Blockquote.svelte +40 -0
  18. package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
  19. package/dist/blocks/blockquote/blockquote.extension.d.ts +1 -0
  20. package/dist/blocks/blockquote/blockquote.extension.js +71 -0
  21. package/dist/blocks/blockquote/blockquote.svelte.d.ts +55 -0
  22. package/dist/blocks/blockquote/blockquote.svelte.js +91 -0
  23. package/dist/blocks/blockquote/index.d.ts +3 -0
  24. package/dist/blocks/blockquote/index.js +3 -0
  25. package/dist/blocks/callout/Callout.svelte +69 -0
  26. package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
  27. package/dist/blocks/callout/callout.extension.d.ts +1 -0
  28. package/dist/blocks/callout/callout.extension.js +68 -0
  29. package/dist/blocks/callout/callout.svelte.d.ts +78 -0
  30. package/dist/blocks/callout/callout.svelte.js +184 -0
  31. package/dist/blocks/callout/index.d.ts +3 -0
  32. package/dist/blocks/callout/index.js +3 -0
  33. package/dist/blocks/code/Code.svelte +85 -0
  34. package/dist/blocks/code/Code.svelte.d.ts +11 -0
  35. package/dist/blocks/code/code.extension.d.ts +1 -0
  36. package/dist/blocks/code/code.extension.js +68 -0
  37. package/dist/blocks/code/code.svelte.d.ts +61 -0
  38. package/dist/blocks/code/code.svelte.js +221 -0
  39. package/dist/blocks/code/index.d.ts +3 -0
  40. package/dist/blocks/code/index.js +3 -0
  41. package/dist/blocks/dialogue/Dialogue.svelte +2 -0
  42. package/dist/blocks/dialogue/dialogue.svelte.d.ts +3 -21
  43. package/dist/blocks/dialogue/dialogue.svelte.js +2 -50
  44. package/dist/blocks/divider/Divider.svelte +28 -0
  45. package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
  46. package/dist/blocks/divider/divider.extension.d.ts +1 -0
  47. package/dist/blocks/divider/divider.extension.js +87 -0
  48. package/dist/blocks/divider/divider.svelte.d.ts +49 -0
  49. package/dist/blocks/divider/divider.svelte.js +84 -0
  50. package/dist/blocks/divider/index.d.ts +3 -0
  51. package/dist/blocks/divider/index.js +3 -0
  52. package/dist/blocks/file/File.svelte +49 -0
  53. package/dist/blocks/file/File.svelte.d.ts +11 -0
  54. package/dist/blocks/file/file.extension.d.ts +1 -0
  55. package/dist/blocks/file/file.extension.js +19 -0
  56. package/dist/blocks/file/file.svelte.d.ts +29 -0
  57. package/dist/blocks/file/file.svelte.js +71 -0
  58. package/dist/blocks/file/index.d.ts +3 -0
  59. package/dist/blocks/file/index.js +3 -0
  60. package/dist/blocks/heading/Heading.svelte +3 -1
  61. package/dist/blocks/heading/heading.svelte.d.ts +4 -23
  62. package/dist/blocks/heading/heading.svelte.js +4 -47
  63. package/dist/blocks/image/Image.svelte +38 -0
  64. package/dist/blocks/image/Image.svelte.d.ts +11 -0
  65. package/dist/blocks/image/image.extension.d.ts +2 -0
  66. package/dist/blocks/image/image.extension.js +26 -0
  67. package/dist/blocks/image/image.svelte.d.ts +50 -0
  68. package/dist/blocks/image/image.svelte.js +92 -0
  69. package/dist/blocks/image/index.d.ts +3 -0
  70. package/dist/blocks/image/index.js +3 -0
  71. package/dist/blocks/index.d.ts +10 -0
  72. package/dist/blocks/index.js +10 -0
  73. package/dist/blocks/list/List.svelte +8 -2
  74. package/dist/blocks/list/ListItem.svelte +43 -7
  75. package/dist/blocks/list/hooks/onBeforeInput.hook.js +15 -2
  76. package/dist/blocks/list/index.d.ts +1 -0
  77. package/dist/blocks/list/index.js +1 -0
  78. package/dist/blocks/list/list-item.svelte.d.ts +14 -2
  79. package/dist/blocks/list/list-item.svelte.js +58 -7
  80. package/dist/blocks/list/list.behavior.svelte.d.ts +4 -4
  81. package/dist/blocks/list/list.behavior.svelte.js +5 -5
  82. package/dist/blocks/list/list.svelte.d.ts +13 -6
  83. package/dist/blocks/list/list.svelte.js +24 -6
  84. package/dist/blocks/list/todos.svelte.d.ts +35 -0
  85. package/dist/blocks/list/todos.svelte.js +76 -0
  86. package/dist/blocks/media/index.d.ts +2 -0
  87. package/dist/blocks/media/index.js +2 -0
  88. package/dist/blocks/media/media-block.svelte.d.ts +32 -0
  89. package/dist/blocks/media/media-block.svelte.js +69 -0
  90. package/dist/blocks/media/media.helpers.d.ts +19 -0
  91. package/dist/blocks/media/media.helpers.js +51 -0
  92. package/dist/blocks/megablock.svelte.js +1 -0
  93. package/dist/blocks/nabu.svelte.d.ts +94 -16
  94. package/dist/blocks/nabu.svelte.js +254 -3
  95. package/dist/blocks/paragraph/Paragraph.svelte +2 -0
  96. package/dist/blocks/paragraph/index.js +0 -3
  97. package/dist/blocks/paragraph/paragraph.svelte.d.ts +3 -21
  98. package/dist/blocks/paragraph/paragraph.svelte.js +4 -53
  99. package/dist/blocks/selection.svelte.js +11 -1
  100. package/dist/blocks/text-block.svelte.d.ts +49 -0
  101. package/dist/blocks/text-block.svelte.js +74 -0
  102. package/dist/blocks/toggle/Toggle.svelte +84 -0
  103. package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
  104. package/dist/blocks/toggle/index.d.ts +3 -0
  105. package/dist/blocks/toggle/index.js +3 -0
  106. package/dist/blocks/toggle/toggle.extension.d.ts +1 -0
  107. package/dist/blocks/toggle/toggle.extension.js +12 -0
  108. package/dist/blocks/toggle/toggle.svelte.d.ts +88 -0
  109. package/dist/blocks/toggle/toggle.svelte.js +252 -0
  110. package/dist/blocks/variable.svelte.d.ts +47 -0
  111. package/dist/blocks/variable.svelte.js +51 -0
  112. package/dist/blocks/video/Video.svelte +39 -0
  113. package/dist/blocks/video/Video.svelte.d.ts +11 -0
  114. package/dist/blocks/video/index.d.ts +3 -0
  115. package/dist/blocks/video/index.js +3 -0
  116. package/dist/blocks/video/video.extension.d.ts +1 -0
  117. package/dist/blocks/video/video.extension.js +19 -0
  118. package/dist/blocks/video/video.svelte.d.ts +28 -0
  119. package/dist/blocks/video/video.svelte.js +71 -0
  120. package/dist/blocks/zone/TemplateEditor.svelte +308 -0
  121. package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
  122. package/dist/blocks/zone/Zone.svelte +158 -144
  123. package/dist/blocks/zone/ZoneEditor.svelte +289 -0
  124. package/dist/blocks/zone/ZoneEditor.svelte.d.ts +11 -0
  125. package/dist/blocks/zone/ZoneTemplatesList.svelte +188 -0
  126. package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +11 -0
  127. package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +3 -0
  128. package/dist/blocks/zone/hooks/onBeforeInput.hook.js +30 -0
  129. package/dist/blocks/zone/zone.extension.js +22 -6
  130. package/dist/blocks/zone/zone.svelte.d.ts +111 -2
  131. package/dist/blocks/zone/zone.svelte.js +304 -17
  132. package/dist/files/files.svelte.d.ts +61 -0
  133. package/dist/files/files.svelte.js +93 -0
  134. package/dist/files/index.d.ts +1 -0
  135. package/dist/files/index.js +1 -0
  136. package/dist/index.d.ts +4 -1
  137. package/dist/index.js +5 -2
  138. package/dist/nabu-theme.css +92 -0
  139. package/dist/overlays/context/Context.svelte +182 -0
  140. package/dist/overlays/context/Context.svelte.d.ts +17 -0
  141. package/dist/overlays/context/collect.d.ts +17 -0
  142. package/dist/overlays/context/collect.js +33 -0
  143. package/dist/overlays/context/context.extension.d.ts +2 -0
  144. package/dist/overlays/context/context.extension.js +8 -0
  145. package/dist/overlays/context/context.svelte.d.ts +82 -0
  146. package/dist/overlays/context/context.svelte.js +159 -0
  147. package/dist/overlays/context/index.d.ts +3 -0
  148. package/dist/overlays/context/index.js +3 -0
  149. package/dist/paste/html.paste.js +9 -1
  150. package/dist/presets.d.ts +3 -1
  151. package/dist/presets.js +21 -6
  152. package/dist/ui/DragHandle.svelte +141 -0
  153. package/dist/ui/DragHandle.svelte.d.ts +11 -0
  154. package/dist/ui/FloatingToolbar.svelte +117 -0
  155. package/dist/ui/FloatingToolbar.svelte.d.ts +17 -0
  156. package/dist/ui/SlashMenu.svelte +83 -0
  157. package/dist/ui/SlashMenu.svelte.d.ts +13 -0
  158. package/dist/ui/index.d.ts +4 -0
  159. package/dist/ui/index.js +4 -0
  160. package/dist/ui/slash-menu.svelte.d.ts +40 -0
  161. package/dist/ui/slash-menu.svelte.js +116 -0
  162. package/dist/utils/extensions.d.ts +54 -0
  163. package/dist/utils/extensions.js +40 -1
  164. package/dist/utils/index.d.ts +1 -0
  165. package/dist/utils/index.js +1 -0
  166. package/dist/utils/placeholders.d.ts +10 -0
  167. package/dist/utils/placeholders.js +21 -0
  168. package/dist/vite.d.ts +16 -0
  169. package/dist/vite.js +23 -0
  170. package/package.json +10 -5
@@ -0,0 +1,91 @@
1
+ import { TextBlock } from "../text-block.svelte.js";
2
+ import { LoroText } from "loro-crdt";
3
+ import BlockquoteComponent from "./Blockquote.svelte";
4
+ import { deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
5
+
6
+ /**
7
+ * @import { Nabu, NabuNode } from "../nabu.svelte.js";
8
+ */
9
+
10
+ /**
11
+ * @typedef {NabuNode<{type: "blockquote", text: LoroText}>} BlockquoteNode
12
+ */
13
+
14
+ // @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
15
+ export class BlockquoteBlock extends TextBlock {
16
+ /** @param {Nabu} nabu @param {BlockquoteNode} node */
17
+ constructor(nabu, node) {
18
+ super(nabu, node);
19
+
20
+ this.serializers.set('markdown', () => `> ${this.behavior.toMarkdown()}`);
21
+ this.serializers.set('json', () => ({
22
+ id: this.id,
23
+ type: 'blockquote',
24
+ content: this.behavior.toJSON()
25
+ }));
26
+ this.serializers.set('application/x-nabu+json', (ctx = {}) => this.behavior.toClipboardBlock(ctx));
27
+ }
28
+
29
+ component = $derived(this.nabu.components.get("blockquote") || BlockquoteComponent);
30
+
31
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
32
+ static toMarkdown(pb) {
33
+ return `> ${deltaToMarkdown(pb.delta || [])}`;
34
+ }
35
+
36
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
37
+ static toHtml(pb) {
38
+ return `<blockquote>${deltaToHtml(pb.delta || [])}</blockquote>`;
39
+ }
40
+
41
+ static markdownRules = [
42
+ {
43
+ priority: 10,
44
+ detect: /^> /,
45
+ consume(/** @type {string[]} */ lines, /** @type {number} */ i) {
46
+ let j = i;
47
+ while (j < lines.length && /^> ?/.test(lines[j])) j++;
48
+ return Math.max(1, j - i);
49
+ },
50
+ }
51
+ ];
52
+
53
+ /**
54
+ * @param {string[]} lines
55
+ * @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
56
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
57
+ */
58
+ static fromMarkdown(lines, { parseInline }) {
59
+ const text = lines.map(line => line.replace(/^> ?/, '')).join('\n');
60
+ const delta = parseInline(text);
61
+ if (!delta.length) return null;
62
+ return { type: 'blockquote', delta, partial: false };
63
+ }
64
+
65
+ // priority 10 wins over Paragraph's fallback `blockquote` selector
66
+ static htmlRules = [
67
+ { selector: 'blockquote', priority: 10 },
68
+ ];
69
+
70
+ /**
71
+ * @param {Element} el
72
+ * @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
73
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
74
+ */
75
+ static fromHTML(el, { parseInline }) {
76
+ const delta = parseInline(el);
77
+ if (!delta.length) return null;
78
+ return { type: 'blockquote', delta, partial: false };
79
+ }
80
+
81
+ /** @param {Nabu} nabu @param {string} type @param {{text?: string, delta?: import('loro-crdt').Delta<string>[]}} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
82
+ static create(nabu, type, props = {}, parentId = null, index = null) {
83
+ const node = nabu.tree.createNode(/** @type {any} */ (parentId || undefined), index || undefined);
84
+ /** @type {any} */ (node.data).set("type", "blockquote");
85
+ const container = /** @type {any} */ (node.data).setContainer("text", new LoroText());
86
+ if (props.text) container.insert(0, props.text);
87
+ if (props.delta) container.applyDelta([...props.delta]);
88
+ const block = new BlockquoteBlock(nabu, /** @type {BlockquoteNode} */ (/** @type {unknown} */ (node)));
89
+ return block;
90
+ }
91
+ }
@@ -0,0 +1,3 @@
1
+ export { BlockquoteBlock } from "./blockquote.svelte.js";
2
+ export { BlockquoteExtension } from "./blockquote.extension.js";
3
+ export { default as BlockquoteComponent } from "./Blockquote.svelte";
@@ -0,0 +1,3 @@
1
+ export { BlockquoteBlock } from './blockquote.svelte.js';
2
+ export { BlockquoteExtension } from './blockquote.extension.js';
3
+ export { default as BlockquoteComponent } from './Blockquote.svelte';
@@ -0,0 +1,69 @@
1
+ <script>
2
+ import RichText from '../../behaviors/text/RichText.svelte';
3
+ import { getPlaceholder } from '../../utils/placeholders.js';
4
+ /** @type {{ block: import('./callout.svelte.js').CalloutBlock }} */
5
+ let { block } = $props();
6
+ /** @type {Record<string,string>} */
7
+ const ICONS = { note: 'ℹ️', tip: '💡', important: '❗', warning: '⚠️', caution: '🛑' };
8
+ </script>
9
+
10
+ <aside class="nabu-callout callout-{block.variant}" data-callout={block.variant}>
11
+ <button
12
+ class="nabu-callout-icon"
13
+ data-nabu-ui
14
+ contenteditable="false"
15
+ type="button"
16
+ title="Change callout type ({block.variant})"
17
+ onmousedown={(e) => { e.preventDefault(); block.cycleVariant(); }}
18
+ >{ICONS[block.variant] ?? ICONS.note}</button>
19
+ <div
20
+ class="nabu-callout-body"
21
+ bind:this={block.element}
22
+ data-block-id={block.id}
23
+ data-block-type="callout"
24
+ data-placeholder={block.text ? '' : getPlaceholder('callout')}
25
+ class:selected={block.selected}
26
+ ><RichText delta={block.delta} /></div>
27
+ </aside>
28
+
29
+ <style>
30
+ .nabu-callout {
31
+ display: flex;
32
+ flex-direction: row;
33
+ align-items: flex-start;
34
+ gap: 0.5em;
35
+ margin: 0.5em 0;
36
+ padding: 0.625em 0.875em;
37
+ border-radius: 6px;
38
+ border-left: 3px solid var(--callout-accent, var(--nb-border, rgba(255, 255, 255, 0.3)));
39
+ background: color-mix(in srgb, var(--callout-accent, var(--nb-border, rgba(255, 255, 255, 0.3))) 8%, transparent);
40
+ }
41
+
42
+ .callout-note { --callout-accent: #6b8cff; }
43
+ .callout-tip { --callout-accent: #3ecf8e; }
44
+ .callout-important { --callout-accent: #a78bfa; }
45
+ .callout-warning { --callout-accent: #f59e0b; }
46
+ .callout-caution { --callout-accent: #ef4444; }
47
+
48
+ .nabu-callout-icon {
49
+ flex-shrink: 0;
50
+ background: none;
51
+ border: none;
52
+ padding: 0;
53
+ margin: 0;
54
+ cursor: pointer;
55
+ user-select: none;
56
+ font-size: 1.1em;
57
+ line-height: 1.5;
58
+ outline: none;
59
+ }
60
+
61
+ .nabu-callout-body {
62
+ flex: 1;
63
+ white-space: pre-wrap;
64
+ outline: none;
65
+ line-height: 1.6;
66
+ min-height: 1.6em;
67
+ color: var(--nb-text-primary, rgba(255, 255, 255, 0.85));
68
+ }
69
+ </style>
@@ -0,0 +1,11 @@
1
+ export default Callout;
2
+ type Callout = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const Callout: import("svelte").Component<{
7
+ block: import("./callout.svelte.js").CalloutBlock;
8
+ }, {}, "">;
9
+ type $$ComponentProps = {
10
+ block: import("./callout.svelte.js").CalloutBlock;
11
+ };
@@ -0,0 +1 @@
1
+ export const CalloutExtension: import("../..").Extension;
@@ -0,0 +1,68 @@
1
+ import { tick } from "svelte";
2
+ import { TextBehavior } from "../../behaviors/text";
3
+ import { extension } from "../../utils/extensions";
4
+ import { CalloutBlock } from "./callout.svelte.js";
5
+ import CalloutComponent from "./Callout.svelte";
6
+
7
+ /**
8
+ * @import { Nabu, Block } from "..";
9
+ */
10
+
11
+ /**
12
+ * onBeforeInput hook for CalloutBlock:
13
+ * - Inside a callout block: Backspace on empty → transform back to paragraph.
14
+ * - In any other text block: "! " at the start → transform into a callout.
15
+ * (The "> " prefix is taken by Blockquote, so callouts use "! " — mnemonic
16
+ * for alert/important, and free of collisions.)
17
+ *
18
+ * @param {Nabu} nabu @param {InputEvent} event @param {Block} block
19
+ */
20
+ const onBeforeInput = (nabu, event, block) => {
21
+ const { BREAK, CONTINUE } = nabu;
22
+
23
+ const behavior = block.behaviors.get('text');
24
+ if (!(behavior instanceof TextBehavior)) return CONTINUE;
25
+ const sel = behavior.selection;
26
+ if (!sel || !sel.isCollapsed) return CONTINUE;
27
+
28
+ if (block instanceof CalloutBlock) {
29
+ // Backspace at position 0 in an empty callout block → back to paragraph
30
+ if (event.inputType === 'deleteContentBackward' && sel.from === 0 && behavior.text.length === 0) {
31
+ const blockId = block.node.id.toString();
32
+ block.transformTo('paragraph');
33
+ tick().then(() => {
34
+ const fresh = nabu.blocks.get(blockId);
35
+ if (fresh) fresh.focus({ start: 0, end: 0 });
36
+ });
37
+ return BREAK;
38
+ }
39
+ return CONTINUE;
40
+ }
41
+
42
+ // "! " at the start of a text block → transform into a callout (variant note)
43
+ if (event.inputType === 'insertText' && event.data === ' ') {
44
+ if (behavior.text.slice(0, sel.from) !== '!') return CONTINUE;
45
+ behavior.delete({ index: 0, length: 1 });
46
+ const blockId = block.node.id.toString();
47
+ block.transformTo('callout');
48
+ tick().then(() => {
49
+ const fresh = nabu.blocks.get(blockId);
50
+ if (fresh) fresh.focus({ start: 0, end: 0 });
51
+ });
52
+ return BREAK;
53
+ }
54
+
55
+ return CONTINUE;
56
+ };
57
+
58
+ export const CalloutExtension = extension("callout", {
59
+ // @ts-ignore — static-side variance on create() (same pattern as Paragraph/Heading)
60
+ block: CalloutBlock,
61
+ component: CalloutComponent,
62
+ actions: {
63
+ 'callout': (nabu) => nabu.exec('block:transform', { type: 'callout' }),
64
+ },
65
+ hooks: {
66
+ onBeforeInput,
67
+ }
68
+ });
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @import { Nabu, NabuNode } from "../nabu.svelte.js";
3
+ */
4
+ /**
5
+ * @typedef {NabuNode<{type: "callout", text: LoroText, variant: string}>} CalloutNode
6
+ */
7
+ export const CALLOUT_VARIANTS: string[];
8
+ export class CalloutBlock extends TextBlock {
9
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
10
+ static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): string;
11
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
12
+ static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
13
+ static markdownRules: {
14
+ priority: number;
15
+ detect: RegExp;
16
+ /**
17
+ * Consume the callout header line plus all subsequent ">" prefixed lines.
18
+ * @param {string[]} lines
19
+ * @param {number} i
20
+ * @returns {number}
21
+ */
22
+ consume(lines: string[], i: number): number;
23
+ }[];
24
+ /**
25
+ * @param {string[]} lines
26
+ * @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
27
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
28
+ */
29
+ static fromMarkdown(lines: string[], { parseInline }: {
30
+ parseInline: (text: string) => import("loro-crdt").Delta<string>[];
31
+ }): import("../../utils/extensions.js").PasteBlock | null;
32
+ static htmlRules: {
33
+ selector: string;
34
+ priority: number;
35
+ }[];
36
+ /**
37
+ * @param {Element} el
38
+ * @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
39
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
40
+ */
41
+ static fromHTML(el: Element, { parseInline }: {
42
+ parseInline: (el: Element) => import("loro-crdt").Delta<string>[];
43
+ }): import("../../utils/extensions.js").PasteBlock | null;
44
+ /** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
45
+ static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): CalloutBlock;
46
+ /** @param {Nabu} nabu @param {CalloutNode} node */
47
+ constructor(nabu: Nabu, node: CalloutNode);
48
+ /** @type {string} */
49
+ variant: string;
50
+ component: import("svelte").Component<any, any, string> | import("svelte").Component<{
51
+ block: import("./callout.svelte.js").CalloutBlock;
52
+ }, {}, "">;
53
+ /**
54
+ * Set the callout variant and commit.
55
+ * @param {string} v
56
+ */
57
+ setVariant(v: string): void;
58
+ /**
59
+ * Cycle to the next callout variant.
60
+ */
61
+ cycleVariant(): void;
62
+ /**
63
+ * Handle special keydown events: ArrowDown escape.
64
+ * Returns true if handled (engine should preventDefault).
65
+ * @param {KeyboardEvent} event
66
+ * @returns {boolean}
67
+ */
68
+ keydown(event: KeyboardEvent): boolean;
69
+ }
70
+ export type CalloutNode = NabuNode<{
71
+ type: "callout";
72
+ text: LoroText;
73
+ variant: string;
74
+ }>;
75
+ import { TextBlock } from "../text-block.svelte.js";
76
+ import type { Nabu } from "../nabu.svelte.js";
77
+ import { LoroText } from "loro-crdt";
78
+ import type { NabuNode } from "../nabu.svelte.js";
@@ -0,0 +1,184 @@
1
+ import { TextBlock } from "../text-block.svelte.js";
2
+ import { LoroText } from "loro-crdt";
3
+ import CalloutComponent from "./Callout.svelte";
4
+ import { tick } from "svelte";
5
+ import { deltaToHtml, deltaToMarkdown } from "../../behaviors/text";
6
+
7
+ /**
8
+ * @import { Nabu, NabuNode } from "../nabu.svelte.js";
9
+ */
10
+
11
+ /**
12
+ * @typedef {NabuNode<{type: "callout", text: LoroText, variant: string}>} CalloutNode
13
+ */
14
+
15
+ export const CALLOUT_VARIANTS = ['note', 'tip', 'important', 'warning', 'caution'];
16
+
17
+ // @ts-ignore — static-side variance on create()
18
+ export class CalloutBlock extends TextBlock {
19
+ /** @param {Nabu} nabu @param {CalloutNode} node */
20
+ constructor(nabu, node) {
21
+ super(nabu, node);
22
+
23
+ this.variant = node.data.get('variant') || 'note';
24
+
25
+ this.serializers.set('markdown', () => {
26
+ const header = '> [!' + this.variant.toUpperCase() + ']';
27
+ const body = this.behavior.toMarkdown();
28
+ if (!body) return header;
29
+ return header + '\n' + body.split('\n').map(l => '> ' + l).join('\n');
30
+ });
31
+ this.serializers.set('json', () => ({
32
+ id: this.id,
33
+ type: 'callout',
34
+ props: { variant: this.variant },
35
+ content: this.behavior.toJSON()
36
+ }));
37
+ this.serializers.set('application/x-nabu+json', (ctx = {}) =>
38
+ this.behavior.toClipboardBlock({ ...ctx, props: { variant: this.variant } })
39
+ );
40
+
41
+ // Sync variant from Loro data changes (mirrors Heading's level sync)
42
+ this.node.data.subscribe(() => {
43
+ this.variant = this.node.data.get('variant') || 'note';
44
+ });
45
+ }
46
+
47
+ // ── Capability flags ─────────────────────────────────────────────────────
48
+ /** Enter inserts a literal \n (multi-line cohesive note) */
49
+ splitsOnEnter = false;
50
+ /** a typed "# " or "> " must NOT transform the callout away */
51
+ transformsEnabled = false;
52
+ // marksEnabled stays true (default) — bold/italic work inside callouts
53
+
54
+ /** @type {string} */
55
+ variant = $state('note');
56
+
57
+ component = $derived(this.nabu.components.get("callout") || CalloutComponent);
58
+
59
+ /**
60
+ * Set the callout variant and commit.
61
+ * @param {string} v
62
+ */
63
+ setVariant(v) {
64
+ if (!CALLOUT_VARIANTS.includes(v)) return;
65
+ this.variant = v;
66
+ /** @type {any} */ (this.node.data).set('variant', v);
67
+ this.commit();
68
+ }
69
+
70
+ /**
71
+ * Cycle to the next callout variant.
72
+ */
73
+ cycleVariant() {
74
+ const i = CALLOUT_VARIANTS.indexOf(this.variant);
75
+ this.setVariant(CALLOUT_VARIANTS[(i + 1) % CALLOUT_VARIANTS.length]);
76
+ }
77
+
78
+ /**
79
+ * Handle special keydown events: ArrowDown escape.
80
+ * Returns true if handled (engine should preventDefault).
81
+ * @param {KeyboardEvent} event
82
+ * @returns {boolean}
83
+ */
84
+ keydown(event) {
85
+ const sel = this.behavior.selection;
86
+ if (!sel) return false;
87
+
88
+ // ArrowDown (no modifiers, collapsed) — escape callout by creating a paragraph after
89
+ if (event.key === 'ArrowDown' && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey && sel.isCollapsed) {
90
+ const onLastLine = this.text.indexOf('\n', sel.from) === -1;
91
+ const hasNextTextBlock = !!this.findForward(b => b.behaviors?.has('text'));
92
+ if (onLastLine && !hasNextTextBlock) {
93
+ const p = this.nabu.insert('paragraph', {}, this.node.parent()?.id.toString() || null, (this.node.index() ?? 0) + 1);
94
+ this.nabu.commit().then(() => {
95
+ const fresh = this.nabu.blocks.get(p.id);
96
+ if (fresh) this.nabu.selection.setCursor(fresh, 0);
97
+ });
98
+ return true;
99
+ }
100
+ return false;
101
+ }
102
+
103
+ return false;
104
+ }
105
+
106
+ // ── Statics ──────────────────────────────────────────────────────────────
107
+
108
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
109
+ static toMarkdown(pb) {
110
+ const v = (pb.props?.variant || 'note').toUpperCase();
111
+ const header = '> [!' + v + ']';
112
+ const body = deltaToMarkdown(pb.delta || []);
113
+ if (!body) return header;
114
+ return header + '\n' + body.split('\n').map(l => '> ' + l).join('\n');
115
+ }
116
+
117
+ /** @param {import('../../utils/extensions.js').PasteBlock} pb */
118
+ static toHtml(pb) {
119
+ const v = pb.props?.variant || 'note';
120
+ return '<aside class="callout callout-' + v + '" data-callout="' + v + '">' + deltaToHtml(pb.delta || []) + '</aside>';
121
+ }
122
+
123
+ static markdownRules = [
124
+ {
125
+ priority: 20,
126
+ detect: /^> \[!(note|tip|important|warning|caution)\]/i,
127
+ /**
128
+ * Consume the callout header line plus all subsequent ">" prefixed lines.
129
+ * @param {string[]} lines
130
+ * @param {number} i
131
+ * @returns {number}
132
+ */
133
+ consume(lines, i) {
134
+ let j = i + 1;
135
+ while (j < lines.length && /^>\s?/.test(lines[j])) j++;
136
+ return j - i;
137
+ }
138
+ }
139
+ ];
140
+
141
+ /**
142
+ * @param {string[]} lines
143
+ * @param {{ parseInline: (text: string) => import('loro-crdt').Delta<string>[] }} helpers
144
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
145
+ */
146
+ static fromMarkdown(lines, { parseInline }) {
147
+ const m = lines[0].match(/^> \[!(\w+)\]/i);
148
+ if (!m) return null;
149
+ let variant = m[1].toLowerCase();
150
+ if (!CALLOUT_VARIANTS.includes(variant)) variant = 'note';
151
+ const body = lines.slice(1).map(l => l.replace(/^>\s?/, '')).join('\n');
152
+ const delta = parseInline(body);
153
+ return { type: 'callout', props: { variant }, delta, partial: false };
154
+ }
155
+
156
+ static htmlRules = [
157
+ { selector: '[data-callout]', priority: 20 },
158
+ { selector: 'aside.callout', priority: 20 },
159
+ ];
160
+
161
+ /**
162
+ * @param {Element} el
163
+ * @param {{ parseInline: (el: Element) => import('loro-crdt').Delta<string>[] }} helpers
164
+ * @returns {import('../../utils/extensions.js').PasteBlock | null}
165
+ */
166
+ static fromHTML(el, { parseInline }) {
167
+ let variant = el.getAttribute('data-callout') || (el.className.match(/callout-(\w+)/)?.[1]) || 'note';
168
+ if (!CALLOUT_VARIANTS.includes(variant)) variant = 'note';
169
+ const delta = parseInline(el);
170
+ return { type: 'callout', props: { variant }, delta, partial: false };
171
+ }
172
+
173
+ /** @param {Nabu} nabu @param {string} type @param {Object} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
174
+ static create(nabu, type, props = {}, parentId = null, index = null) {
175
+ const node = nabu.tree.createNode(/** @type {any} */ (parentId || undefined), index || undefined);
176
+ /** @type {any} */ (node.data).set('type', 'callout');
177
+ const variant = CALLOUT_VARIANTS.includes(props.variant) ? props.variant : 'note';
178
+ /** @type {any} */ (node.data).set('variant', variant);
179
+ const container = /** @type {any} */ (node.data).setContainer('text', new LoroText());
180
+ if (props.text) container.insert(0, props.text);
181
+ if (props.delta) container.applyDelta([...props.delta]);
182
+ return new CalloutBlock(nabu, /** @type {CalloutNode} */ (/** @type {unknown} */ (node)));
183
+ }
184
+ }
@@ -0,0 +1,3 @@
1
+ export { CalloutBlock } from "./callout.svelte.js";
2
+ export { CalloutExtension } from "./callout.extension.js";
3
+ export { default as CalloutComponent } from "./Callout.svelte";
@@ -0,0 +1,3 @@
1
+ export { CalloutBlock } from './callout.svelte.js';
2
+ export { CalloutExtension } from './callout.extension.js';
3
+ export { default as CalloutComponent } from './Callout.svelte';
@@ -0,0 +1,85 @@
1
+ <script>
2
+ import { getPlaceholder } from '../../utils/placeholders.js';
3
+ /** @type {{ block: import('./code.svelte.js').CodeBlock }} */
4
+ let { block } = $props();
5
+ const LANGS = ['plaintext', 'javascript', 'typescript', 'html', 'css', 'json', 'python', 'rust', 'bash', 'markdown', 'sql', 'go'];
6
+ </script>
7
+
8
+ <div class="nabu-code-wrapper">
9
+ <select
10
+ class="nabu-code-lang"
11
+ data-nabu-ui
12
+ contenteditable="false"
13
+ value={block.language ?? 'plaintext'}
14
+ onchange={(e) => block.setLanguage(e.currentTarget.value === 'plaintext' ? null : e.currentTarget.value)}
15
+ >
16
+ {#each LANGS as lang}<option value={lang}>{lang}</option>{/each}
17
+ </select>
18
+ <pre
19
+ bind:this={block.element}
20
+ data-block-id={block.id}
21
+ data-block-type="code"
22
+ data-placeholder={block.text ? '' : getPlaceholder('code')}
23
+ class="nabu-code"
24
+ class:debug={block.nabu.debugging}
25
+ class:selected={block.selected}
26
+ ><code>{block.text || '\n'}</code></pre>
27
+ </div>
28
+
29
+ <style>
30
+ .nabu-code-wrapper {
31
+ position: relative;
32
+ margin: 0.5em 0;
33
+ border-radius: 6px;
34
+ border: 1px solid var(--nb-border, rgba(255, 255, 255, 0.12));
35
+ background: var(--nb-bg-surface-sunken, rgba(0, 0, 0, 0.25));
36
+ overflow: hidden;
37
+ }
38
+
39
+ .nabu-code-lang {
40
+ position: absolute;
41
+ top: 0.4em;
42
+ right: 0.5em;
43
+ font-size: 10px;
44
+ font-family: inherit;
45
+ color: var(--nb-text-muted, rgba(255, 255, 255, 0.4));
46
+ background: var(--nb-bg-surface, rgba(255, 255, 255, 0.05));
47
+ border: 1px solid var(--nb-border-subtle, rgba(255, 255, 255, 0.08));
48
+ border-radius: 4px;
49
+ padding: 1px 4px;
50
+ cursor: pointer;
51
+ user-select: none;
52
+ outline: none;
53
+ z-index: 1;
54
+ }
55
+
56
+ .nabu-code-lang:focus {
57
+ border-color: var(--nb-border, rgba(255, 255, 255, 0.2));
58
+ }
59
+
60
+ .nabu-code {
61
+ display: block;
62
+ white-space: pre;
63
+ font-family: var(--nb-font-mono, 'Menlo', 'Monaco', 'Consolas', monospace);
64
+ font-size: 0.85em;
65
+ line-height: 1.6;
66
+ padding: 0.75em 1em;
67
+ margin: 0;
68
+ overflow-x: auto;
69
+ color: var(--nb-text-primary, rgba(255, 255, 255, 0.85));
70
+ outline: none;
71
+ min-height: 1.6em;
72
+ }
73
+
74
+ .nabu-code.debug.selected {
75
+ background-color: rgba(59, 130, 246, 0.1);
76
+ }
77
+
78
+ .nabu-code code {
79
+ font-family: inherit;
80
+ font-size: inherit;
81
+ background: none;
82
+ padding: 0;
83
+ white-space: inherit;
84
+ }
85
+ </style>
@@ -0,0 +1,11 @@
1
+ export default Code;
2
+ type Code = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const Code: import("svelte").Component<{
7
+ block: import("./code.svelte.js").CodeBlock;
8
+ }, {}, "">;
9
+ type $$ComponentProps = {
10
+ block: import("./code.svelte.js").CodeBlock;
11
+ };
@@ -0,0 +1 @@
1
+ export const CodeExtension: import("../..").Extension;