@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.
Files changed (177) 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/BlockGap.svelte +55 -0
  14. package/dist/blocks/BlockGap.svelte.d.ts +11 -0
  15. package/dist/blocks/Nabu.svelte +22 -0
  16. package/dist/blocks/block.extension.js +10 -8
  17. package/dist/blocks/block.svelte.d.ts +24 -0
  18. package/dist/blocks/block.svelte.js +35 -0
  19. package/dist/blocks/blockquote/Blockquote.svelte +40 -0
  20. package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
  21. package/dist/blocks/blockquote/blockquote.extension.d.ts +1 -0
  22. package/dist/blocks/blockquote/blockquote.extension.js +71 -0
  23. package/dist/blocks/blockquote/blockquote.svelte.d.ts +55 -0
  24. package/dist/blocks/blockquote/blockquote.svelte.js +91 -0
  25. package/dist/blocks/blockquote/index.d.ts +3 -0
  26. package/dist/blocks/blockquote/index.js +3 -0
  27. package/dist/blocks/callout/Callout.svelte +69 -0
  28. package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
  29. package/dist/blocks/callout/callout.extension.d.ts +1 -0
  30. package/dist/blocks/callout/callout.extension.js +68 -0
  31. package/dist/blocks/callout/callout.svelte.d.ts +78 -0
  32. package/dist/blocks/callout/callout.svelte.js +184 -0
  33. package/dist/blocks/callout/index.d.ts +3 -0
  34. package/dist/blocks/callout/index.js +3 -0
  35. package/dist/blocks/code/Code.svelte +85 -0
  36. package/dist/blocks/code/Code.svelte.d.ts +11 -0
  37. package/dist/blocks/code/code.extension.d.ts +1 -0
  38. package/dist/blocks/code/code.extension.js +68 -0
  39. package/dist/blocks/code/code.svelte.d.ts +61 -0
  40. package/dist/blocks/code/code.svelte.js +221 -0
  41. package/dist/blocks/code/index.d.ts +3 -0
  42. package/dist/blocks/code/index.js +3 -0
  43. package/dist/blocks/dialogue/Dialogue.svelte +2 -0
  44. package/dist/blocks/dialogue/dialogue.svelte.d.ts +3 -21
  45. package/dist/blocks/dialogue/dialogue.svelte.js +2 -50
  46. package/dist/blocks/divider/Divider.svelte +28 -0
  47. package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
  48. package/dist/blocks/divider/divider.extension.d.ts +1 -0
  49. package/dist/blocks/divider/divider.extension.js +87 -0
  50. package/dist/blocks/divider/divider.svelte.d.ts +49 -0
  51. package/dist/blocks/divider/divider.svelte.js +84 -0
  52. package/dist/blocks/divider/index.d.ts +3 -0
  53. package/dist/blocks/divider/index.js +3 -0
  54. package/dist/blocks/file/File.svelte +49 -0
  55. package/dist/blocks/file/File.svelte.d.ts +11 -0
  56. package/dist/blocks/file/file.extension.d.ts +1 -0
  57. package/dist/blocks/file/file.extension.js +19 -0
  58. package/dist/blocks/file/file.svelte.d.ts +29 -0
  59. package/dist/blocks/file/file.svelte.js +71 -0
  60. package/dist/blocks/file/index.d.ts +3 -0
  61. package/dist/blocks/file/index.js +3 -0
  62. package/dist/blocks/heading/Heading.svelte +3 -1
  63. package/dist/blocks/heading/heading.svelte.d.ts +4 -23
  64. package/dist/blocks/heading/heading.svelte.js +4 -47
  65. package/dist/blocks/image/Image.svelte +38 -0
  66. package/dist/blocks/image/Image.svelte.d.ts +11 -0
  67. package/dist/blocks/image/image.extension.d.ts +2 -0
  68. package/dist/blocks/image/image.extension.js +26 -0
  69. package/dist/blocks/image/image.svelte.d.ts +50 -0
  70. package/dist/blocks/image/image.svelte.js +92 -0
  71. package/dist/blocks/image/index.d.ts +3 -0
  72. package/dist/blocks/image/index.js +3 -0
  73. package/dist/blocks/index.d.ts +11 -0
  74. package/dist/blocks/index.js +11 -0
  75. package/dist/blocks/list/List.svelte +8 -2
  76. package/dist/blocks/list/ListItem.svelte +43 -7
  77. package/dist/blocks/list/hooks/onBeforeInput.hook.js +15 -2
  78. package/dist/blocks/list/index.d.ts +1 -0
  79. package/dist/blocks/list/index.js +1 -0
  80. package/dist/blocks/list/list-item.svelte.d.ts +14 -2
  81. package/dist/blocks/list/list-item.svelte.js +58 -7
  82. package/dist/blocks/list/list.behavior.svelte.d.ts +4 -4
  83. package/dist/blocks/list/list.behavior.svelte.js +5 -5
  84. package/dist/blocks/list/list.svelte.d.ts +13 -6
  85. package/dist/blocks/list/list.svelte.js +24 -6
  86. package/dist/blocks/list/todos.svelte.d.ts +35 -0
  87. package/dist/blocks/list/todos.svelte.js +76 -0
  88. package/dist/blocks/media/index.d.ts +2 -0
  89. package/dist/blocks/media/index.js +2 -0
  90. package/dist/blocks/media/media-block.svelte.d.ts +32 -0
  91. package/dist/blocks/media/media-block.svelte.js +69 -0
  92. package/dist/blocks/media/media.helpers.d.ts +19 -0
  93. package/dist/blocks/media/media.helpers.js +51 -0
  94. package/dist/blocks/megablock.svelte.js +1 -0
  95. package/dist/blocks/nabu.svelte.d.ts +94 -16
  96. package/dist/blocks/nabu.svelte.js +254 -3
  97. package/dist/blocks/paragraph/Paragraph.svelte +2 -0
  98. package/dist/blocks/paragraph/index.js +8 -3
  99. package/dist/blocks/paragraph/paragraph.svelte.d.ts +3 -21
  100. package/dist/blocks/paragraph/paragraph.svelte.js +4 -53
  101. package/dist/blocks/selection.svelte.d.ts +1 -0
  102. package/dist/blocks/selection.svelte.js +212 -16
  103. package/dist/blocks/text-block.svelte.d.ts +49 -0
  104. package/dist/blocks/text-block.svelte.js +74 -0
  105. package/dist/blocks/toggle/Toggle.svelte +84 -0
  106. package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
  107. package/dist/blocks/toggle/index.d.ts +3 -0
  108. package/dist/blocks/toggle/index.js +3 -0
  109. package/dist/blocks/toggle/toggle.extension.d.ts +1 -0
  110. package/dist/blocks/toggle/toggle.extension.js +12 -0
  111. package/dist/blocks/toggle/toggle.svelte.d.ts +88 -0
  112. package/dist/blocks/toggle/toggle.svelte.js +252 -0
  113. package/dist/blocks/variable.svelte.d.ts +47 -0
  114. package/dist/blocks/variable.svelte.js +51 -0
  115. package/dist/blocks/video/Video.svelte +39 -0
  116. package/dist/blocks/video/Video.svelte.d.ts +11 -0
  117. package/dist/blocks/video/index.d.ts +3 -0
  118. package/dist/blocks/video/index.js +3 -0
  119. package/dist/blocks/video/video.extension.d.ts +1 -0
  120. package/dist/blocks/video/video.extension.js +19 -0
  121. package/dist/blocks/video/video.svelte.d.ts +28 -0
  122. package/dist/blocks/video/video.svelte.js +71 -0
  123. package/dist/blocks/zone/TemplateEditor.svelte +308 -0
  124. package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
  125. package/dist/blocks/zone/Zone.svelte +272 -0
  126. package/dist/blocks/zone/Zone.svelte.d.ts +11 -0
  127. package/dist/blocks/zone/ZoneEditor.svelte +289 -0
  128. package/dist/blocks/zone/ZoneEditor.svelte.d.ts +11 -0
  129. package/dist/blocks/zone/ZoneTemplatesList.svelte +188 -0
  130. package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +11 -0
  131. package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +3 -0
  132. package/dist/blocks/zone/hooks/onBeforeInput.hook.js +30 -0
  133. package/dist/blocks/zone/index.d.ts +2 -0
  134. package/dist/blocks/zone/index.js +2 -0
  135. package/dist/blocks/zone/zone.extension.d.ts +2 -0
  136. package/dist/blocks/zone/zone.extension.js +237 -0
  137. package/dist/blocks/zone/zone.svelte.d.ts +221 -0
  138. package/dist/blocks/zone/zone.svelte.js +608 -0
  139. package/dist/files/files.svelte.d.ts +61 -0
  140. package/dist/files/files.svelte.js +93 -0
  141. package/dist/files/index.d.ts +1 -0
  142. package/dist/files/index.js +1 -0
  143. package/dist/index.d.ts +4 -1
  144. package/dist/index.js +5 -2
  145. package/dist/nabu-theme.css +92 -0
  146. package/dist/overlays/context/Context.svelte +182 -0
  147. package/dist/overlays/context/Context.svelte.d.ts +17 -0
  148. package/dist/overlays/context/collect.d.ts +17 -0
  149. package/dist/overlays/context/collect.js +33 -0
  150. package/dist/overlays/context/context.extension.d.ts +2 -0
  151. package/dist/overlays/context/context.extension.js +8 -0
  152. package/dist/overlays/context/context.svelte.d.ts +82 -0
  153. package/dist/overlays/context/context.svelte.js +159 -0
  154. package/dist/overlays/context/index.d.ts +3 -0
  155. package/dist/overlays/context/index.js +3 -0
  156. package/dist/paste/html.paste.js +9 -1
  157. package/dist/presets.d.ts +3 -1
  158. package/dist/presets.js +22 -6
  159. package/dist/ui/DragHandle.svelte +141 -0
  160. package/dist/ui/DragHandle.svelte.d.ts +11 -0
  161. package/dist/ui/FloatingToolbar.svelte +117 -0
  162. package/dist/ui/FloatingToolbar.svelte.d.ts +17 -0
  163. package/dist/ui/SlashMenu.svelte +83 -0
  164. package/dist/ui/SlashMenu.svelte.d.ts +13 -0
  165. package/dist/ui/index.d.ts +4 -0
  166. package/dist/ui/index.js +4 -0
  167. package/dist/ui/slash-menu.svelte.d.ts +40 -0
  168. package/dist/ui/slash-menu.svelte.js +116 -0
  169. package/dist/utils/extensions.d.ts +54 -0
  170. package/dist/utils/extensions.js +40 -1
  171. package/dist/utils/index.d.ts +1 -0
  172. package/dist/utils/index.js +1 -0
  173. package/dist/utils/placeholders.d.ts +10 -0
  174. package/dist/utils/placeholders.js +21 -0
  175. package/dist/vite.d.ts +16 -0
  176. package/dist/vite.js +23 -0
  177. package/package.json +10 -5
@@ -0,0 +1,93 @@
1
+ import { LoroMap } from 'loro-crdt';
2
+
3
+ /**
4
+ * @typedef {Object} FilesConfig
5
+ * @property {(file: File, ctx: { signal?: AbortSignal, onProgress?: (p: number) => void }) => Promise<{ ref: string } | void>} [onBeforePersist]
6
+ * Intercept before default persistence. Return `{ ref }` to redirect to your own
7
+ * storage (the bytes are NOT stored in Loro). Return nothing to fall back to default.
8
+ * @property {(ref: string) => string} [resolve] Turn a stored ref into a display URL.
9
+ * @property {number} [maxInlineSize] Byte threshold above which the default (Loro) mode warns. Default 2MB.
10
+ */
11
+
12
+ /**
13
+ * Document-level file/asset manager. Default mode stores bytes in a Loro `assets`
14
+ * map (source of truth stays in Loro). Lazy: Files.get(nabu).
15
+ */
16
+ export class Files {
17
+ /** @type {import('../blocks/nabu.svelte.js').Nabu} */
18
+ #nabu;
19
+ /** @type {Map<string,string>} ref → objectURL cache for nabu-asset: refs */
20
+ #urlCache = new Map();
21
+
22
+ /** @param {import('../blocks/nabu.svelte.js').Nabu} nabu */
23
+ constructor(nabu) {
24
+ this.#nabu = nabu;
25
+ this.assets = nabu.doc.getMap('assets');
26
+ }
27
+
28
+ /** @param {import('../blocks/nabu.svelte.js').Nabu} nabu @returns {Files} */
29
+ static get(nabu) {
30
+ if (!nabu.systems.has('files')) {
31
+ const f = new Files(nabu);
32
+ nabu.systems.set('files', f);
33
+ return f;
34
+ }
35
+ return /** @type {Files} */ (nabu.systems.get('files'));
36
+ }
37
+
38
+ /** @returns {FilesConfig} */
39
+ get config() { return this.#nabu.fileConfig || {}; }
40
+
41
+ get maxInlineSize() { return this.config.maxInlineSize ?? 2 * 1024 * 1024; }
42
+
43
+ /**
44
+ * Persist a File → durable ref. Uses onBeforePersist if configured, else stores
45
+ * the bytes in the Loro `assets` map.
46
+ * @param {File} file
47
+ * @param {{ signal?: AbortSignal, onProgress?: (p:number)=>void }} [ctx]
48
+ * @returns {Promise<string>}
49
+ */
50
+ async persist(file, ctx = {}) {
51
+ const hook = this.config.onBeforePersist;
52
+ if (hook) {
53
+ const result = await hook(file, ctx);
54
+ if (result && result.ref) return result.ref;
55
+ // fell through → default
56
+ }
57
+ if (file.size > this.maxInlineSize) {
58
+ console.warn(`[Nabu] File "${file.name}" is ${(file.size / 1048576).toFixed(1)}MB — stored inline in the Loro document (default mode). For large media, configure files.onBeforePersist to upload to your own storage.`);
59
+ }
60
+ const buf = new Uint8Array(await file.arrayBuffer());
61
+ const id = (globalThis.crypto?.randomUUID?.() ?? String(Date.now()) + Math.random().toString(36).slice(2));
62
+ const sub = this.assets.setContainer(id, new LoroMap());
63
+ sub.set('data', buf);
64
+ sub.set('type', file.type || 'application/octet-stream');
65
+ sub.set('name', file.name || '');
66
+ this.#nabu.doc.commit();
67
+ return 'nabu-asset:' + id;
68
+ }
69
+
70
+ /**
71
+ * Resolve a ref to a displayable URL. nabu-asset: refs → objectURL from Loro
72
+ * bytes (cached); external URLs → config.resolve or identity.
73
+ * @param {string} ref @returns {string}
74
+ */
75
+ resolve(ref) {
76
+ if (!ref) return '';
77
+ if (ref.startsWith('nabu-asset:')) {
78
+ const cached = this.#urlCache.get(ref);
79
+ if (cached) return cached;
80
+ const id = ref.slice('nabu-asset:'.length);
81
+ const sub = /** @type {any} */ (this.assets.get(id));
82
+ if (!sub || typeof sub.get !== 'function') return '';
83
+ const data = sub.get('data');
84
+ const type = sub.get('type') || 'application/octet-stream';
85
+ if (!data) return '';
86
+ const url = URL.createObjectURL(new Blob([data], { type }));
87
+ this.#urlCache.set(ref, url);
88
+ return url;
89
+ }
90
+ if (this.config.resolve) return this.config.resolve(ref);
91
+ return ref;
92
+ }
93
+ }
@@ -0,0 +1 @@
1
+ export { Files } from "./files.svelte.js";
@@ -0,0 +1 @@
1
+ export { Files } from './files.svelte.js';
package/dist/index.d.ts CHANGED
@@ -3,4 +3,7 @@ export * from "./utils";
3
3
  export * from "./behaviors";
4
4
  export * from "./presets";
5
5
  export * from "./paste";
6
- export { RichTextExtension, RichText } from "./behaviors/text";
6
+ export * from "./overlays/context";
7
+ export * from "./ui";
8
+ export * from "./files";
9
+ export { RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, RichText } from "./behaviors/text";
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  // Reexport your entry components here
2
- export { RichTextExtension, RichText } from './behaviors/text';
2
+ export { RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, RichText } from './behaviors/text';
3
3
  export * from './blocks';
4
4
  export * from "./utils";
5
5
  export * from './behaviors';
6
6
  export * from './presets';
7
- export * from './paste';
7
+ export * from './paste';
8
+ export * from './overlays/context';
9
+ export * from './ui';
10
+ export * from './files';
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Nabu Theme Configuration
3
+ * State-of-the-art Semantic Design Tokens for UI Modularity
4
+ */
5
+
6
+ :root, [data-nabu-theme="light"] {
7
+ /* UI Backgrounds */
8
+ --nb-bg-surface: hsla(0, 0%, 100%, 0.85); /* Light glass */
9
+ --nb-bg-surface-sunken: hsla(0, 0%, 0%, 0.04);
10
+ --nb-bg-surface-hover: hsla(0, 0%, 0%, 0.04);
11
+ --nb-bg-surface-active: hsla(0, 0%, 0%, 0.08);
12
+
13
+ /* UI Borders & Lines */
14
+ --nb-border: hsla(0, 0%, 0%, 0.1);
15
+ --nb-border-subtle: hsla(0, 0%, 0%, 0.05);
16
+ --nb-border-focus: hsla(0, 0%, 0%, 0.15);
17
+
18
+ /* Text Colors */
19
+ --nb-text-primary: hsla(0, 0%, 0%, 0.9);
20
+ --nb-text-secondary: hsla(0, 0%, 0%, 0.6);
21
+ --nb-text-muted: hsla(0, 0%, 0%, 0.4);
22
+
23
+ /* Accent & Status Colors */
24
+ --nb-accent: hsla(210, 100%, 50%, 0.2);
25
+ --nb-success: hsla(150, 100%, 35%, 0.9);
26
+ --nb-success-bg: hsla(150, 100%, 40%, 0.15);
27
+ --nb-warning: rgba(245, 158, 11, 0.4);
28
+ --nb-danger: rgba(239, 68, 68, 0.4);
29
+
30
+ /* Shadows */
31
+ --nb-shadow-lg: 0 16px 32px -12px rgba(0,0,0,0.15);
32
+ --nb-shadow-inset: inset 0 2px 4px rgba(0,0,0,0.03);
33
+ --nb-shadow-glow: 0 0 0 2px hsla(0, 0%, 0%, 0.05);
34
+
35
+ /* Backdrop Filter for Glassmorphism */
36
+ --nb-glass-blur: blur(24px) saturate(180%);
37
+ --nb-glass-blur-sm: blur(12px) saturate(140%);
38
+ }
39
+
40
+ @media (prefers-color-scheme: dark) {
41
+ :root:not([data-nabu-theme="light"]) {
42
+ /* Dark glass overrides natively */
43
+ --nb-bg-surface: hsla(0, 0%, 12%, 0.75);
44
+ --nb-bg-surface-sunken: hsla(0, 0%, 0%, 0.2);
45
+ --nb-bg-surface-hover: hsla(0, 0%, 100%, 0.08);
46
+ --nb-bg-surface-active: hsla(0, 0%, 100%, 0.15);
47
+
48
+ --nb-border: hsla(0, 0%, 100%, 0.1);
49
+ --nb-border-subtle: hsla(0, 0%, 100%, 0.05);
50
+ --nb-border-focus: hsla(0, 0%, 100%, 0.2);
51
+
52
+ --nb-text-primary: hsla(0, 0%, 100%, 0.9);
53
+ --nb-text-secondary: hsla(0, 0%, 100%, 0.6);
54
+ --nb-text-muted: hsla(0, 0%, 100%, 0.4);
55
+
56
+ --nb-accent: hsla(210, 100%, 60%, 0.25);
57
+ --nb-success: hsla(150, 100%, 60%, 0.9);
58
+ --nb-success-bg: hsla(150, 100%, 60%, 0.15);
59
+ --nb-warning: rgba(245, 158, 11, 0.4);
60
+ --nb-danger: rgba(239, 68, 68, 0.4);
61
+
62
+ --nb-shadow-lg: 0 16px 32px -12px rgba(0,0,0,0.5);
63
+ --nb-shadow-inset: inset 0 2px 4px rgba(0,0,0,0.2);
64
+ --nb-shadow-glow: 0 0 0 2px hsla(0, 0%, 100%, 0.05);
65
+ }
66
+ }
67
+
68
+ [data-nabu-theme="dark"] {
69
+ /* Dark glass explicit override */
70
+ --nb-bg-surface: hsla(0, 0%, 12%, 0.75);
71
+ --nb-bg-surface-sunken: hsla(0, 0%, 0%, 0.2);
72
+ --nb-bg-surface-hover: hsla(0, 0%, 100%, 0.08);
73
+ --nb-bg-surface-active: hsla(0, 0%, 100%, 0.15);
74
+
75
+ --nb-border: hsla(0, 0%, 100%, 0.1);
76
+ --nb-border-subtle: hsla(0, 0%, 100%, 0.05);
77
+ --nb-border-focus: hsla(0, 0%, 100%, 0.2);
78
+
79
+ --nb-text-primary: hsla(0, 0%, 100%, 0.9);
80
+ --nb-text-secondary: hsla(0, 0%, 100%, 0.6);
81
+ --nb-text-muted: hsla(0, 0%, 100%, 0.4);
82
+
83
+ --nb-accent: hsla(210, 100%, 60%, 0.25);
84
+ --nb-success: hsla(150, 100%, 60%, 0.9);
85
+ --nb-success-bg: hsla(150, 100%, 60%, 0.15);
86
+ --nb-warning: rgba(245, 158, 11, 0.4);
87
+ --nb-danger: rgba(239, 68, 68, 0.4);
88
+
89
+ --nb-shadow-lg: 0 16px 32px -12px rgba(0,0,0,0.5);
90
+ --nb-shadow-inset: inset 0 2px 4px rgba(0,0,0,0.2);
91
+ --nb-shadow-glow: 0 0 0 2px hsla(0, 0%, 100%, 0.05);
92
+ }
@@ -0,0 +1,182 @@
1
+ <script>
2
+ /**
3
+ * @typedef {import('./context.svelte.js').ContextMenuSection} ContextMenuSection
4
+ * @typedef {import('./context.svelte.js').Context} Context
5
+ */
6
+ import { untrack } from 'svelte';
7
+ import { fly } from 'svelte/transition';
8
+ import { setMenuContext } from './context.svelte.js';
9
+
10
+ /** @type {{ x: number, y: number, context: Context }} */
11
+ let { x, y, context } = $props();
12
+
13
+ setMenuContext(untrack(() => context));
14
+
15
+ // Clamp to viewport so the menu never goes off-screen
16
+ const menuWidth = 220;
17
+ const menuMaxHeight = 400;
18
+ const left = $derived(Math.min(x, window.innerWidth - menuWidth) + 'px');
19
+ const top = $derived(Math.min(y, window.innerHeight - menuMaxHeight) + 'px');
20
+ </script>
21
+
22
+ <div class="nabu-context-menu" style:left style:top role="menu">
23
+ {#if context.history.length > 1}
24
+ <div class="nabu-context-header">
25
+ <button class="nabu-context-back" onclick={() => context.pop()}>
26
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
27
+ <path d="m15 18-6-6 6-6"/>
28
+ </svg>
29
+ </button>
30
+ <span class="nabu-context-title">{context.currentView.title || 'Retour'}</span>
31
+ </div>
32
+ {/if}
33
+
34
+ <div class="nabu-context-viewport">
35
+ {#key context.currentView.id}
36
+ <div
37
+ class="nabu-context-view"
38
+ in:fly={{ x: context.direction === 1 ? 50 : -50, duration: 200 }}
39
+ out:fly={{ x: context.direction === 1 ? -50 : 50, duration: 200 }}
40
+ >
41
+ {#each context.currentView.sections as section, i (section.key)}
42
+ {#if i > 0}
43
+ <div class="nabu-context-sep" role="separator"></div>
44
+ {/if}
45
+
46
+ {#if section.component}
47
+ <section.component {...(section.props ?? {})} />
48
+ {:else if section.items}
49
+ <!-- {#each section.items as item}
50
+ <button
51
+ class="nabu-context-item"
52
+ class:disabled={item.disabled}
53
+ disabled={item.disabled}
54
+ role="menuitem"
55
+ onclick={item.action}
56
+ >
57
+ {#if item.icon}
58
+ <span class="nabu-context-icon">{item.icon}</span>
59
+ {/if}
60
+ <span class="nabu-context-label">{item.label}</span>
61
+ </button>
62
+ {/each} -->
63
+ {/if}
64
+ {/each}
65
+ </div>
66
+ {/key}
67
+ </div>
68
+ </div>
69
+
70
+ <style>
71
+ .nabu-context-menu {
72
+ position: fixed;
73
+ z-index: 9999;
74
+ min-width: 240px;
75
+ font-family: 'Inter', system-ui, sans-serif;
76
+ font-size: 13px;
77
+ color: var(--nb-text-primary, #eee);
78
+ display: flex;
79
+ flex-direction: column;
80
+ gap: 8px;
81
+ }
82
+
83
+ .nabu-context-header {
84
+ display: flex;
85
+ align-items: center;
86
+ padding: 6px 8px;
87
+ gap: 8px;
88
+ font-weight: 500;
89
+ background: var(--nb-bg-surface, hsla(0, 0%, 12%, 0.75));
90
+ backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
91
+ -webkit-backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
92
+ border: 1px solid var(--nb-border, hsla(0, 0%, 100%, 0.1));
93
+ border-radius: 12px;
94
+ box-shadow: var(--nb-shadow-lg, 0 8px 24px -8px rgba(0,0,0,0.5));
95
+ }
96
+
97
+ .nabu-context-back {
98
+ background: transparent;
99
+ border: none;
100
+ cursor: pointer;
101
+ display: flex;
102
+ align-items: center;
103
+ justify-content: center;
104
+ padding: 4px;
105
+ border-radius: 6px;
106
+ color: var(--nb-text-secondary, hsla(0, 0%, 100%, 0.6));
107
+ transition: background 0.15s, color 0.15s;
108
+ }
109
+
110
+ .nabu-context-back:hover {
111
+ background: var(--nb-bg-surface-hover, hsla(0, 0%, 100%, 0.1));
112
+ color: var(--nb-text-primary, hsla(0, 0%, 100%, 1));
113
+ }
114
+
115
+ .nabu-context-title {
116
+ flex: 1;
117
+ text-align: left;
118
+ font-size: 13px;
119
+ color: var(--nb-text-primary, hsla(0, 0%, 100%, 0.9));
120
+ letter-spacing: 0.2px;
121
+ }
122
+
123
+ .nabu-context-viewport {
124
+ position: relative;
125
+ display: grid;
126
+ }
127
+
128
+ .nabu-context-view {
129
+ grid-area: 1 / 1;
130
+ width: 100%;
131
+ display: flex;
132
+ flex-direction: column;
133
+ gap: 8px;
134
+ }
135
+
136
+ .nabu-context-sep {
137
+ display: none;
138
+ }
139
+
140
+ .nabu-context-item {
141
+ display: flex;
142
+ align-items: center;
143
+ gap: 8px;
144
+ width: 100%;
145
+ padding: 6px 10px;
146
+ border: none;
147
+ background: var(--nb-bg-surface, hsla(0, 0%, 12%, 0.75));
148
+ backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
149
+ -webkit-backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
150
+ border: 1px solid var(--nb-border, hsla(0, 0%, 100%, 0.1));
151
+ border-radius: 12px;
152
+ box-shadow: var(--nb-shadow-lg, 0 8px 24px -8px rgba(0,0,0,0.5));
153
+ cursor: pointer;
154
+ text-align: left;
155
+ color: var(--nb-text-primary, hsla(0, 0%, 100%, 0.8));
156
+ transition: transform 0.1s, background 0.1s;
157
+ }
158
+
159
+ .nabu-context-item:hover:not(.disabled) {
160
+ background: var(--nb-bg-surface-active, hsla(0, 0%, 100%, 0.15));
161
+ }
162
+
163
+ .nabu-context-item:active:not(.disabled) {
164
+ transform: scale(0.98);
165
+ }
166
+
167
+ .nabu-context-item.disabled {
168
+ opacity: 0.4;
169
+ cursor: default;
170
+ }
171
+
172
+ .nabu-context-icon {
173
+ width: 16px;
174
+ text-align: center;
175
+ flex-shrink: 0;
176
+ opacity: 0.6;
177
+ }
178
+
179
+ .nabu-context-label {
180
+ flex: 1;
181
+ }
182
+ </style>
@@ -0,0 +1,17 @@
1
+ export default Context;
2
+ export type ContextMenuSection = import("./context.svelte.js").ContextMenuSection;
3
+ export type Context = import("./context.svelte.js").Context;
4
+ type Context = {
5
+ $on?(type: string, callback: (e: any) => void): () => void;
6
+ $set?(props: Partial<$$ComponentProps>): void;
7
+ };
8
+ declare const Context: import("svelte").Component<{
9
+ x: number;
10
+ y: number;
11
+ context: Context;
12
+ }, {}, "">;
13
+ type $$ComponentProps = {
14
+ x: number;
15
+ y: number;
16
+ context: Context;
17
+ };
@@ -0,0 +1,17 @@
1
+ /** @import { ContextMenuSection } from './context.svelte.js' */
2
+ /**
3
+ * Svelte action — registers an element as a context menu contributor.
4
+ * The callback receives the collect event and should push sections into event.detail.sections.
5
+ *
6
+ * Usage:
7
+ * <div use:collect={() => [{ key: 'my-section', items: [...] }]}>
8
+ *
9
+ * @param {HTMLElement} node
10
+ * @param {() => ContextMenuSection[]} getSections
11
+ */
12
+ export function collect(node: HTMLElement, getSections: () => ContextMenuSection[]): {
13
+ /** @param {() => ContextMenuSection[]} newGetSections */
14
+ update(newGetSections: () => ContextMenuSection[]): void;
15
+ destroy(): void;
16
+ };
17
+ import type { ContextMenuSection } from './context.svelte.js';
@@ -0,0 +1,33 @@
1
+ import { CONTEXT_COLLECT_EVENT } from './context.svelte.js';
2
+
3
+ /** @import { ContextMenuSection } from './context.svelte.js' */
4
+
5
+ /**
6
+ * Svelte action — registers an element as a context menu contributor.
7
+ * The callback receives the collect event and should push sections into event.detail.sections.
8
+ *
9
+ * Usage:
10
+ * <div use:collect={() => [{ key: 'my-section', items: [...] }]}>
11
+ *
12
+ * @param {HTMLElement} node
13
+ * @param {() => ContextMenuSection[]} getSections
14
+ */
15
+ export function collect(node, getSections) {
16
+ /** @param {Event} e */
17
+ const handler = (e) => {
18
+ const event = /** @type {CustomEvent<{ sections: ContextMenuSection[] }>} */ (e);
19
+ getSections().forEach(section => event.detail.sections.push(section));
20
+ };
21
+
22
+ node.addEventListener(CONTEXT_COLLECT_EVENT, handler);
23
+
24
+ return {
25
+ /** @param {() => ContextMenuSection[]} newGetSections */
26
+ update(newGetSections) {
27
+ getSections = newGetSections;
28
+ },
29
+ destroy() {
30
+ node.removeEventListener(CONTEXT_COLLECT_EVENT, handler);
31
+ },
32
+ };
33
+ }
@@ -0,0 +1,2 @@
1
+ export const ContextExtension: Extension;
2
+ import { Extension } from '../../utils/extensions.js';
@@ -0,0 +1,8 @@
1
+ import { Extension } from '../../utils/extensions.js';
2
+ import { ContextMenu } from './context.svelte.js';
3
+
4
+ export const ContextExtension = new Extension('context', {
5
+ hooks: {
6
+ onInit: (nabu) => new ContextMenu(nabu),
7
+ },
8
+ });
@@ -0,0 +1,82 @@
1
+ export const getMenuContext: () => Context;
2
+ export const setMenuContext: (ctx: Context) => Context;
3
+ /** @import {Nabu} from "../../index.js" */
4
+ /**
5
+ * @typedef {Object} ContextMenuItem
6
+ * @property {string} label
7
+ * @property {string} [icon]
8
+ * @property {() => void} action
9
+ * @property {boolean} [disabled]
10
+ */
11
+ /**
12
+ * @typedef {Object} ContextMenuSection
13
+ * @property {string} key
14
+ * @property {import('svelte').Component} [component]
15
+ * @property {Record<string, any>} [props]
16
+ * @property {ContextMenuItem[]} [items]
17
+ */
18
+ /**
19
+ * @typedef {Object} ContextView
20
+ * @property {string} id
21
+ * @property {string} [title]
22
+ * @property {ContextMenuSection[]} sections
23
+ */
24
+ export const CONTEXT_COLLECT_EVENT: "nabu-context-collect";
25
+ export class ContextMenu {
26
+ /** @param {Nabu} nabu */
27
+ constructor(nabu: Nabu);
28
+ nabu: Nabu;
29
+ component: import("svelte").Component<{
30
+ x: number;
31
+ y: number;
32
+ context: ContextComponent;
33
+ }, {}, ""> | undefined;
34
+ instance: {} | null;
35
+ /** @param {MouseEvent} event */
36
+ handleClick(event: MouseEvent): void;
37
+ /** @param {MouseEvent} event */
38
+ handleContextMenu(event: MouseEvent): void;
39
+ close(): void;
40
+ start(): void;
41
+ stop(): void;
42
+ }
43
+ export class Context {
44
+ /**
45
+ * @param {Nabu} nabu
46
+ * @param {ContextMenu} menu
47
+ * @param {{sections?: ContextMenuSection[]}} [init]
48
+ */
49
+ constructor(nabu: Nabu, menu: ContextMenu, init?: {
50
+ sections?: ContextMenuSection[];
51
+ });
52
+ nabu: Nabu;
53
+ menu: ContextMenu;
54
+ /** @type {ContextView[]} */
55
+ history: ContextView[];
56
+ /** @type {number} */
57
+ direction: number;
58
+ get currentView(): ContextView;
59
+ /** @param {ContextView} view */
60
+ push(view: ContextView): void;
61
+ pop(): void;
62
+ close(): void;
63
+ }
64
+ export type ContextMenuItem = {
65
+ label: string;
66
+ icon?: string | undefined;
67
+ action: () => void;
68
+ disabled?: boolean | undefined;
69
+ };
70
+ export type ContextMenuSection = {
71
+ key: string;
72
+ component?: import("svelte").Component<any, any, string> | undefined;
73
+ props?: Record<string, any> | undefined;
74
+ items?: ContextMenuItem[] | undefined;
75
+ };
76
+ export type ContextView = {
77
+ id: string;
78
+ title?: string | undefined;
79
+ sections: ContextMenuSection[];
80
+ };
81
+ import type { Nabu } from "../../index.js";
82
+ import ContextComponent from "./Context.svelte";