@aionbuilders/nabu 0.1.0-alpha.8 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -9
- package/dist/behaviors/text/RichText.svelte +4 -1
- package/dist/behaviors/text/index.d.ts +2 -0
- package/dist/behaviors/text/index.js +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +54 -0
- package/dist/behaviors/text/rich-text.extension.js +47 -22
- package/dist/behaviors/text/text.behavior.svelte.d.ts +25 -1
- package/dist/behaviors/text/text.behavior.svelte.js +154 -18
- package/dist/behaviors/text/typography.extension.d.ts +6 -0
- package/dist/behaviors/text/typography.extension.js +24 -0
- package/dist/blocks/Block.svelte +5 -2
- package/dist/blocks/BlockGap.svelte +55 -0
- package/dist/blocks/BlockGap.svelte.d.ts +11 -0
- package/dist/blocks/Nabu.svelte +22 -0
- package/dist/blocks/block.extension.js +10 -8
- package/dist/blocks/block.svelte.d.ts +24 -0
- package/dist/blocks/block.svelte.js +35 -0
- package/dist/blocks/blockquote/Blockquote.svelte +40 -0
- package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
- package/dist/blocks/blockquote/blockquote.extension.d.ts +1 -0
- package/dist/blocks/blockquote/blockquote.extension.js +71 -0
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +55 -0
- package/dist/blocks/blockquote/blockquote.svelte.js +91 -0
- package/dist/blocks/blockquote/index.d.ts +3 -0
- package/dist/blocks/blockquote/index.js +3 -0
- package/dist/blocks/callout/Callout.svelte +69 -0
- package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
- package/dist/blocks/callout/callout.extension.d.ts +1 -0
- package/dist/blocks/callout/callout.extension.js +68 -0
- package/dist/blocks/callout/callout.svelte.d.ts +78 -0
- package/dist/blocks/callout/callout.svelte.js +184 -0
- package/dist/blocks/callout/index.d.ts +3 -0
- package/dist/blocks/callout/index.js +3 -0
- package/dist/blocks/code/Code.svelte +85 -0
- package/dist/blocks/code/Code.svelte.d.ts +11 -0
- package/dist/blocks/code/code.extension.d.ts +1 -0
- package/dist/blocks/code/code.extension.js +68 -0
- package/dist/blocks/code/code.svelte.d.ts +61 -0
- package/dist/blocks/code/code.svelte.js +221 -0
- package/dist/blocks/code/index.d.ts +3 -0
- package/dist/blocks/code/index.js +3 -0
- package/dist/blocks/dialogue/Dialogue.svelte +2 -0
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +3 -21
- package/dist/blocks/dialogue/dialogue.svelte.js +2 -50
- package/dist/blocks/divider/Divider.svelte +28 -0
- package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
- package/dist/blocks/divider/divider.extension.d.ts +1 -0
- package/dist/blocks/divider/divider.extension.js +87 -0
- package/dist/blocks/divider/divider.svelte.d.ts +49 -0
- package/dist/blocks/divider/divider.svelte.js +84 -0
- package/dist/blocks/divider/index.d.ts +3 -0
- package/dist/blocks/divider/index.js +3 -0
- package/dist/blocks/file/File.svelte +49 -0
- package/dist/blocks/file/File.svelte.d.ts +11 -0
- package/dist/blocks/file/file.extension.d.ts +1 -0
- package/dist/blocks/file/file.extension.js +19 -0
- package/dist/blocks/file/file.svelte.d.ts +29 -0
- package/dist/blocks/file/file.svelte.js +71 -0
- package/dist/blocks/file/index.d.ts +3 -0
- package/dist/blocks/file/index.js +3 -0
- package/dist/blocks/heading/Heading.svelte +3 -1
- package/dist/blocks/heading/heading.svelte.d.ts +4 -23
- package/dist/blocks/heading/heading.svelte.js +4 -47
- package/dist/blocks/image/Image.svelte +38 -0
- package/dist/blocks/image/Image.svelte.d.ts +11 -0
- package/dist/blocks/image/image.extension.d.ts +2 -0
- package/dist/blocks/image/image.extension.js +26 -0
- package/dist/blocks/image/image.svelte.d.ts +50 -0
- package/dist/blocks/image/image.svelte.js +92 -0
- package/dist/blocks/image/index.d.ts +3 -0
- package/dist/blocks/image/index.js +3 -0
- package/dist/blocks/index.d.ts +11 -0
- package/dist/blocks/index.js +11 -0
- package/dist/blocks/list/List.svelte +8 -2
- package/dist/blocks/list/ListItem.svelte +43 -7
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +15 -2
- package/dist/blocks/list/index.d.ts +1 -0
- package/dist/blocks/list/index.js +1 -0
- package/dist/blocks/list/list-item.svelte.d.ts +14 -2
- package/dist/blocks/list/list-item.svelte.js +58 -7
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -4
- package/dist/blocks/list/list.behavior.svelte.js +5 -5
- package/dist/blocks/list/list.svelte.d.ts +13 -6
- package/dist/blocks/list/list.svelte.js +24 -6
- package/dist/blocks/list/todos.svelte.d.ts +35 -0
- package/dist/blocks/list/todos.svelte.js +76 -0
- package/dist/blocks/media/index.d.ts +2 -0
- package/dist/blocks/media/index.js +2 -0
- package/dist/blocks/media/media-block.svelte.d.ts +32 -0
- package/dist/blocks/media/media-block.svelte.js +69 -0
- package/dist/blocks/media/media.helpers.d.ts +19 -0
- package/dist/blocks/media/media.helpers.js +51 -0
- package/dist/blocks/megablock.svelte.js +1 -0
- package/dist/blocks/nabu.svelte.d.ts +94 -16
- package/dist/blocks/nabu.svelte.js +254 -3
- package/dist/blocks/paragraph/Paragraph.svelte +2 -0
- package/dist/blocks/paragraph/index.js +8 -3
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +3 -21
- package/dist/blocks/paragraph/paragraph.svelte.js +4 -53
- package/dist/blocks/selection.svelte.d.ts +1 -0
- package/dist/blocks/selection.svelte.js +212 -16
- package/dist/blocks/text-block.svelte.d.ts +49 -0
- package/dist/blocks/text-block.svelte.js +74 -0
- package/dist/blocks/toggle/Toggle.svelte +84 -0
- package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
- package/dist/blocks/toggle/index.d.ts +3 -0
- package/dist/blocks/toggle/index.js +3 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +1 -0
- package/dist/blocks/toggle/toggle.extension.js +12 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +88 -0
- package/dist/blocks/toggle/toggle.svelte.js +252 -0
- package/dist/blocks/variable.svelte.d.ts +47 -0
- package/dist/blocks/variable.svelte.js +51 -0
- package/dist/blocks/video/Video.svelte +39 -0
- package/dist/blocks/video/Video.svelte.d.ts +11 -0
- package/dist/blocks/video/index.d.ts +3 -0
- package/dist/blocks/video/index.js +3 -0
- package/dist/blocks/video/video.extension.d.ts +1 -0
- package/dist/blocks/video/video.extension.js +19 -0
- package/dist/blocks/video/video.svelte.d.ts +28 -0
- package/dist/blocks/video/video.svelte.js +71 -0
- package/dist/blocks/zone/TemplateEditor.svelte +308 -0
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/Zone.svelte +272 -0
- package/dist/blocks/zone/Zone.svelte.d.ts +11 -0
- package/dist/blocks/zone/ZoneEditor.svelte +289 -0
- package/dist/blocks/zone/ZoneEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte +188 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +11 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.js +30 -0
- package/dist/blocks/zone/index.d.ts +2 -0
- package/dist/blocks/zone/index.js +2 -0
- package/dist/blocks/zone/zone.extension.d.ts +2 -0
- package/dist/blocks/zone/zone.extension.js +237 -0
- package/dist/blocks/zone/zone.svelte.d.ts +221 -0
- package/dist/blocks/zone/zone.svelte.js +608 -0
- package/dist/files/files.svelte.d.ts +61 -0
- package/dist/files/files.svelte.js +93 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/nabu-theme.css +92 -0
- package/dist/overlays/context/Context.svelte +182 -0
- package/dist/overlays/context/Context.svelte.d.ts +17 -0
- package/dist/overlays/context/collect.d.ts +17 -0
- package/dist/overlays/context/collect.js +33 -0
- package/dist/overlays/context/context.extension.d.ts +2 -0
- package/dist/overlays/context/context.extension.js +8 -0
- package/dist/overlays/context/context.svelte.d.ts +82 -0
- package/dist/overlays/context/context.svelte.js +159 -0
- package/dist/overlays/context/index.d.ts +3 -0
- package/dist/overlays/context/index.js +3 -0
- package/dist/paste/html.paste.js +9 -1
- package/dist/presets.d.ts +3 -1
- package/dist/presets.js +22 -6
- package/dist/ui/DragHandle.svelte +141 -0
- package/dist/ui/DragHandle.svelte.d.ts +11 -0
- package/dist/ui/FloatingToolbar.svelte +117 -0
- package/dist/ui/FloatingToolbar.svelte.d.ts +17 -0
- package/dist/ui/SlashMenu.svelte +83 -0
- package/dist/ui/SlashMenu.svelte.d.ts +13 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/slash-menu.svelte.d.ts +40 -0
- package/dist/ui/slash-menu.svelte.js +116 -0
- package/dist/utils/extensions.d.ts +54 -0
- package/dist/utils/extensions.js +40 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/placeholders.d.ts +10 -0
- package/dist/utils/placeholders.js +21 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +23 -0
- package/package.json +10 -5
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { createContext, mount, unmount } from "svelte";
|
|
2
|
+
import { BROWSER } from "esm-env";
|
|
3
|
+
import ContextComponent from "./Context.svelte";
|
|
4
|
+
|
|
5
|
+
/** @type {[() => Context, (ctx: Context) => Context]} */
|
|
6
|
+
export const [getMenuContext, setMenuContext] = createContext();
|
|
7
|
+
|
|
8
|
+
/** @import {Nabu} from "../../index.js" */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} ContextMenuItem
|
|
12
|
+
* @property {string} label
|
|
13
|
+
* @property {string} [icon]
|
|
14
|
+
* @property {() => void} action
|
|
15
|
+
* @property {boolean} [disabled]
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} ContextMenuSection
|
|
20
|
+
* @property {string} key
|
|
21
|
+
* @property {import('svelte').Component} [component]
|
|
22
|
+
* @property {Record<string, any>} [props]
|
|
23
|
+
* @property {ContextMenuItem[]} [items]
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} ContextView
|
|
28
|
+
* @property {string} id
|
|
29
|
+
* @property {string} [title]
|
|
30
|
+
* @property {ContextMenuSection[]} sections
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
export const CONTEXT_COLLECT_EVENT = 'nabu-context-collect';
|
|
34
|
+
|
|
35
|
+
export class ContextMenu {
|
|
36
|
+
/** @param {Nabu} nabu */
|
|
37
|
+
constructor(nabu) {
|
|
38
|
+
this.nabu = nabu;
|
|
39
|
+
|
|
40
|
+
if (nabu.systems.has('context')) {
|
|
41
|
+
const c = nabu.systems.get('context');
|
|
42
|
+
if (c instanceof ContextMenu) return c;
|
|
43
|
+
else throw new Error('Context system already exists but is not an instance of ContextMenu');
|
|
44
|
+
} else {
|
|
45
|
+
nabu.systems.set('context', this);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.component = $state(ContextComponent);
|
|
49
|
+
this.instance = null;
|
|
50
|
+
|
|
51
|
+
this.handleClick = this.handleClick.bind(this);
|
|
52
|
+
this.handleContextMenu = this.handleContextMenu.bind(this);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
close() {
|
|
56
|
+
if (this.instance) {
|
|
57
|
+
unmount(this.instance);
|
|
58
|
+
this.instance = null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @param {MouseEvent} event */
|
|
63
|
+
handleClick(event) {
|
|
64
|
+
if (!this.instance) return;
|
|
65
|
+
|
|
66
|
+
const target = /** @type {Element} */ (event.target);
|
|
67
|
+
if (target?.closest('.nabu-context-menu')) return;
|
|
68
|
+
|
|
69
|
+
// Fix: Si l'élément cliqué n'est plus dans le DOM au moment où l'événement
|
|
70
|
+
// atteint 'window' (ex: le bouton retour a été démonté par Svelte),
|
|
71
|
+
// on ignore le clic pour ne pas fermer le menu par erreur.
|
|
72
|
+
if (target && !document.documentElement.contains(target)) return;
|
|
73
|
+
|
|
74
|
+
this.close();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {MouseEvent} event */
|
|
78
|
+
handleContextMenu(event) {
|
|
79
|
+
this.close();
|
|
80
|
+
|
|
81
|
+
if (!this.component || !event.target) return;
|
|
82
|
+
|
|
83
|
+
// Fire collecting event — bubbles up through the DOM path.
|
|
84
|
+
// Each element along the way can push to detail.sections.
|
|
85
|
+
/** @type {{ sections: ContextMenuSection[] }} */
|
|
86
|
+
const detail = { sections: [] };
|
|
87
|
+
event.target.dispatchEvent(
|
|
88
|
+
new CustomEvent(CONTEXT_COLLECT_EVENT, { bubbles: true, detail })
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Only suppress the native menu if something was collected.
|
|
92
|
+
if (!detail.sections.length) return;
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
|
|
95
|
+
const { clientX: x, clientY: y } = event;
|
|
96
|
+
this.instance = mount(this.component, {
|
|
97
|
+
target: document.body,
|
|
98
|
+
props: { x, y, context: new Context(this.nabu, this, detail) },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
start() {
|
|
103
|
+
if (BROWSER && typeof window !== 'undefined') {
|
|
104
|
+
window.addEventListener('click', this.handleClick);
|
|
105
|
+
window.addEventListener('contextmenu', this.handleContextMenu);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
stop() {
|
|
110
|
+
if (BROWSER && typeof window !== 'undefined') {
|
|
111
|
+
window.removeEventListener('click', this.handleClick);
|
|
112
|
+
window.removeEventListener('contextmenu', this.handleContextMenu);
|
|
113
|
+
}
|
|
114
|
+
this.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
export class Context {
|
|
120
|
+
/**
|
|
121
|
+
* @param {Nabu} nabu
|
|
122
|
+
* @param {ContextMenu} menu
|
|
123
|
+
* @param {{sections?: ContextMenuSection[]}} [init]
|
|
124
|
+
*/
|
|
125
|
+
constructor(nabu, menu, init = {}) {
|
|
126
|
+
this.nabu = nabu;
|
|
127
|
+
this.menu = menu;
|
|
128
|
+
|
|
129
|
+
/** @type {ContextView[]} */
|
|
130
|
+
this.history = $state([{
|
|
131
|
+
id: 'root',
|
|
132
|
+
sections: init.sections || []
|
|
133
|
+
}]);
|
|
134
|
+
|
|
135
|
+
/** @type {number} */
|
|
136
|
+
this.direction = $state(1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get currentView() {
|
|
140
|
+
return this.history[this.history.length - 1];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** @param {ContextView} view */
|
|
144
|
+
push(view) {
|
|
145
|
+
this.direction = 1;
|
|
146
|
+
this.history.push(view);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
pop() {
|
|
150
|
+
if (this.history.length > 1) {
|
|
151
|
+
this.direction = -1;
|
|
152
|
+
this.history.pop();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
close() {
|
|
157
|
+
this.menu.close();
|
|
158
|
+
}
|
|
159
|
+
}
|
package/dist/paste/html.paste.js
CHANGED
|
@@ -74,6 +74,11 @@ export function parseInline(el, marks = {}) {
|
|
|
74
74
|
const markName = MARK_TAGS[tag];
|
|
75
75
|
const styleMarks = { ...marks };
|
|
76
76
|
if (markName) styleMarks[markName] = true;
|
|
77
|
+
// <a href> → link mark (value = href)
|
|
78
|
+
if (tag === 'a') {
|
|
79
|
+
const href = el2.getAttribute('href');
|
|
80
|
+
if (href) styleMarks['link'] = /** @type {any} */ (href);
|
|
81
|
+
}
|
|
77
82
|
// Detect marks from inline styles (e.g. Google Docs uses font-weight:700 on <span>)
|
|
78
83
|
if (el2.nodeType === Node.ELEMENT_NODE) {
|
|
79
84
|
const style = /** @type {HTMLElement} */ (el2).style;
|
|
@@ -93,8 +98,10 @@ export function parseInline(el, marks = {}) {
|
|
|
93
98
|
|
|
94
99
|
/**
|
|
95
100
|
* Build the ordered ruleset from all BlockClasses registered in nabu.
|
|
101
|
+
* Sorted by rule priority descending so specific blocks (e.g. blockquote)
|
|
102
|
+
* win over generic fallbacks (e.g. paragraph's blockquote selector).
|
|
96
103
|
* @param {import('../blocks/nabu.svelte.js').Nabu} nabu
|
|
97
|
-
* @returns {Array<{ BlockClass: any, rule: { selector: string, props?: Record<string,any> } }>}
|
|
104
|
+
* @returns {Array<{ BlockClass: any, rule: { selector: string, priority?: number, props?: Record<string,any> } }>}
|
|
98
105
|
*/
|
|
99
106
|
function buildRuleset(nabu) {
|
|
100
107
|
/** @type {Array<{ BlockClass: any, rule: any }>} */
|
|
@@ -104,6 +111,7 @@ function buildRuleset(nabu) {
|
|
|
104
111
|
if (!Array.isArray(rules)) continue;
|
|
105
112
|
for (const rule of rules) ruleset.push({ BlockClass, rule });
|
|
106
113
|
}
|
|
114
|
+
ruleset.sort((a, b) => (b.rule.priority ?? 0) - (a.rule.priority ?? 0));
|
|
107
115
|
return ruleset;
|
|
108
116
|
}
|
|
109
117
|
|
package/dist/presets.d.ts
CHANGED
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
* @param {object} [options]
|
|
5
5
|
* @param {typeof ParagraphExtension[]} [options.preset] - Base preset (default: FullPreset)
|
|
6
6
|
* @param {typeof ParagraphExtension[]} [options.extensions] - Extra extensions to append
|
|
7
|
+
* @param {import('./files/files.svelte.js').FilesConfig} [options.files] - File/upload config (forwarded to Nabu)
|
|
7
8
|
* @returns {Nabu}
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* const engine = createEditor({ preset: DocumentPreset, extensions: [MyCustomExtension] });
|
|
11
12
|
*/
|
|
12
|
-
export function createEditor({ preset, extensions }?: {
|
|
13
|
+
export function createEditor({ preset, extensions, ...init }?: {
|
|
13
14
|
preset?: import("./index.js").Extension[] | undefined;
|
|
14
15
|
extensions?: import("./index.js").Extension[] | undefined;
|
|
16
|
+
files?: import("./files/files.svelte.js").FilesConfig | undefined;
|
|
15
17
|
}): Nabu;
|
|
16
18
|
/** Paragraph only. The simplest possible editor. */
|
|
17
19
|
export const MinimalPreset: import("./index.js").Extension[];
|
package/dist/presets.js
CHANGED
|
@@ -3,9 +3,19 @@ import { ParagraphExtension } from './blocks/paragraph/index.js';
|
|
|
3
3
|
import { HeadingExtension } from './blocks/heading/index.js';
|
|
4
4
|
import { ListExtension, ListItemExtension } from './blocks/list/index.js';
|
|
5
5
|
import { DialogueExtension } from './blocks/dialogue/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { BlockquoteExtension } from './blocks/blockquote/index.js';
|
|
7
|
+
import { DividerExtension } from './blocks/divider/index.js';
|
|
8
|
+
import { CodeExtension } from './blocks/code/index.js';
|
|
9
|
+
import { CalloutExtension } from './blocks/callout/index.js';
|
|
10
|
+
import { ToggleExtension } from './blocks/toggle/index.js';
|
|
11
|
+
import { RichTextExtension, TypographyExtension, MarkdownShortcutsExtension } from './behaviors/text/index.js';
|
|
7
12
|
import { PlainTextPasteExtension, NabuPasteExtension, HtmlPasteExtension, MarkdownPasteExtension } from './paste/index.js';
|
|
8
13
|
import { BlockExtension } from './blocks/block.extension.js';
|
|
14
|
+
import { ZoneExtension } from './blocks/zone/zone.extension.js';
|
|
15
|
+
import { ContextExtension } from './overlays/context/context.extension.js';
|
|
16
|
+
import { ImageExtension } from './blocks/image/index.js';
|
|
17
|
+
import { VideoExtension } from './blocks/video/index.js';
|
|
18
|
+
import { FileExtension } from './blocks/file/index.js';
|
|
9
19
|
|
|
10
20
|
// ---------------------------------------------------------------------------
|
|
11
21
|
// Presets — composable extension arrays
|
|
@@ -15,13 +25,16 @@ import { BlockExtension } from './blocks/block.extension.js';
|
|
|
15
25
|
export const MinimalPreset = [ParagraphExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, BlockExtension];
|
|
16
26
|
|
|
17
27
|
/** Paragraph + rich text marks (bold, italic, underline, code, strikethrough). */
|
|
18
|
-
export const TextPreset = [ParagraphExtension, RichTextExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, MarkdownPasteExtension, BlockExtension];
|
|
28
|
+
export const TextPreset = [ParagraphExtension, RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, MarkdownPasteExtension, BlockExtension];
|
|
19
29
|
|
|
20
30
|
/** Paragraph + headings + rich text. Document-like, no lists. */
|
|
21
|
-
export const DocumentPreset = [ParagraphExtension, HeadingExtension, RichTextExtension, PlainTextPasteExtension, HtmlPasteExtension, MarkdownPasteExtension, NabuPasteExtension, BlockExtension];
|
|
31
|
+
export const DocumentPreset = [ParagraphExtension, HeadingExtension, BlockquoteExtension, DividerExtension, CodeExtension, CalloutExtension, ToggleExtension, ImageExtension, VideoExtension, FileExtension, RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, PlainTextPasteExtension, HtmlPasteExtension, MarkdownPasteExtension, NabuPasteExtension, BlockExtension];
|
|
22
32
|
|
|
23
33
|
/** All built-in block types + rich text. */
|
|
24
|
-
export const FullPreset =
|
|
34
|
+
export const FullPreset = [
|
|
35
|
+
ParagraphExtension, HeadingExtension, BlockquoteExtension, DividerExtension, CodeExtension, CalloutExtension, ToggleExtension, ImageExtension, VideoExtension, FileExtension, ListExtension, ListItemExtension, DialogueExtension, ZoneExtension, RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, PlainTextPasteExtension, HtmlPasteExtension, MarkdownPasteExtension, NabuPasteExtension, BlockExtension,
|
|
36
|
+
ContextExtension
|
|
37
|
+
];
|
|
25
38
|
|
|
26
39
|
// ---------------------------------------------------------------------------
|
|
27
40
|
// Factory — generic createEditor
|
|
@@ -33,13 +46,16 @@ export const FullPreset = [ParagraphExtension, HeadingExtension, ListExtension,
|
|
|
33
46
|
* @param {object} [options]
|
|
34
47
|
* @param {typeof ParagraphExtension[]} [options.preset] - Base preset (default: FullPreset)
|
|
35
48
|
* @param {typeof ParagraphExtension[]} [options.extensions] - Extra extensions to append
|
|
49
|
+
* @param {import('./files/files.svelte.js').FilesConfig} [options.files] - File/upload config (forwarded to Nabu)
|
|
36
50
|
* @returns {Nabu}
|
|
37
51
|
*
|
|
38
52
|
* @example
|
|
39
53
|
* const engine = createEditor({ preset: DocumentPreset, extensions: [MyCustomExtension] });
|
|
40
54
|
*/
|
|
41
|
-
export function createEditor({ preset = FullPreset, extensions = [] } = {}) {
|
|
42
|
-
|
|
55
|
+
export function createEditor({ preset = FullPreset, extensions = [], ...init } = {}) {
|
|
56
|
+
// Forward any remaining Nabu init options (e.g. `files`, `snapshot`) so the
|
|
57
|
+
// ergonomic factories expose the full constructor surface, not just extensions.
|
|
58
|
+
return new Nabu({ ...init, extensions: [...preset, ...extensions] });
|
|
43
59
|
}
|
|
44
60
|
|
|
45
61
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { wrapOrphan } from '../blocks/container.utils.js';
|
|
3
|
+
/** @type {{ engine: import('../blocks/nabu.svelte.js').Nabu }} */
|
|
4
|
+
let { engine } = $props();
|
|
5
|
+
|
|
6
|
+
let handle = $state({ visible: false, top: 0, left: 0, blockId: /** @type {string|null} */ (null) });
|
|
7
|
+
let dragging = $state(false);
|
|
8
|
+
let indicator = $state({ visible: false, top: 0, left: 0, width: 0 });
|
|
9
|
+
/** @type {{ blockId: string, position: 'before'|'after' } | null} */
|
|
10
|
+
let dropTarget = null;
|
|
11
|
+
let draggedId = /** @type {string|null} */ (null);
|
|
12
|
+
|
|
13
|
+
const HANDLE_W = 24;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Find the nearest block element under a point (skipping the dragged one + UI islands).
|
|
17
|
+
* @param {number} x
|
|
18
|
+
* @param {number} y
|
|
19
|
+
* @param {string|null} excludeId
|
|
20
|
+
* @returns {Element|null}
|
|
21
|
+
*/
|
|
22
|
+
function blockElAt(x, y, excludeId) {
|
|
23
|
+
let el = /** @type {Element|null} */ (document.elementFromPoint(x, y));
|
|
24
|
+
const root = el?.closest?.('.nabu-editor');
|
|
25
|
+
if (!root) return null;
|
|
26
|
+
const b = el?.closest?.('[data-block-id]');
|
|
27
|
+
if (!b) return null;
|
|
28
|
+
if (excludeId && b.getAttribute('data-block-id') === excludeId) return null;
|
|
29
|
+
// don't target a UI island
|
|
30
|
+
if (b.closest('[data-nabu-ui]')) return null;
|
|
31
|
+
return b;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @param {PointerEvent} e */
|
|
35
|
+
function onPointerMove(e) {
|
|
36
|
+
if (dragging) { onDragMove(e); return; }
|
|
37
|
+
// The handle lives OUTSIDE the editor; while the pointer is over the handle
|
|
38
|
+
// itself, keep it visible — else moving onto it to grab it would hide it.
|
|
39
|
+
const over = document.elementFromPoint(e.clientX, e.clientY);
|
|
40
|
+
if (over?.closest?.('.nabu-drag-handle')) return;
|
|
41
|
+
const b = blockElAt(e.clientX, e.clientY, null);
|
|
42
|
+
if (!b) { handle.visible = false; return; }
|
|
43
|
+
const r = b.getBoundingClientRect();
|
|
44
|
+
// Flush against the block's left edge — no dead gap to cross when grabbing.
|
|
45
|
+
handle = { visible: true, top: r.top + 2, left: r.left - HANDLE_W, blockId: b.getAttribute('data-block-id') };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @param {PointerEvent} e */
|
|
49
|
+
function onHandleDown(e) {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
draggedId = handle.blockId;
|
|
53
|
+
if (!draggedId) return;
|
|
54
|
+
dragging = true;
|
|
55
|
+
// dim the dragged block
|
|
56
|
+
const el = document.querySelector(`[data-block-id="${cssEscape(draggedId)}"]`);
|
|
57
|
+
el?.classList.add('nabu-dragging');
|
|
58
|
+
try { /** @type {any} */ (e.target).setPointerCapture?.(e.pointerId); } catch {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {PointerEvent} e */
|
|
62
|
+
function onDragMove(e) {
|
|
63
|
+
handle.visible = false;
|
|
64
|
+
const b = blockElAt(e.clientX, e.clientY, draggedId);
|
|
65
|
+
if (!b) { indicator.visible = false; dropTarget = null; return; }
|
|
66
|
+
const r = b.getBoundingClientRect();
|
|
67
|
+
const after = e.clientY > r.top + r.height / 2;
|
|
68
|
+
dropTarget = { blockId: /** @type {string} */ (b.getAttribute('data-block-id')), position: after ? 'after' : 'before' };
|
|
69
|
+
indicator = { visible: true, top: after ? r.bottom : r.top, left: r.left, width: r.width };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function onPointerUp() {
|
|
73
|
+
if (dragging) {
|
|
74
|
+
const el = draggedId ? document.querySelector(`[data-block-id="${cssEscape(draggedId)}"]`) : null;
|
|
75
|
+
el?.classList.remove('nabu-dragging');
|
|
76
|
+
performDrop();
|
|
77
|
+
}
|
|
78
|
+
dragging = false; draggedId = null; indicator.visible = false; dropTarget = null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function performDrop() {
|
|
82
|
+
const id = draggedId;
|
|
83
|
+
if (!dropTarget || !id) return;
|
|
84
|
+
const dragged = engine.blocks.get(id);
|
|
85
|
+
const target = engine.blocks.get(dropTarget.blockId);
|
|
86
|
+
if (!dragged || !target || dragged === target) return;
|
|
87
|
+
// never drop a block into its own subtree (cycle)
|
|
88
|
+
if (target.parents?.some((p) => p.id === dragged.id)) return;
|
|
89
|
+
if (dropTarget.position === 'after') dragged.node.moveAfter(target.node);
|
|
90
|
+
else dragged.node.moveBefore(target.node);
|
|
91
|
+
// repair structural integrity (e.g. a list-item dropped at root → wrap in a list).
|
|
92
|
+
// No-op for blocks without a requiredParent (paragraph, heading, …).
|
|
93
|
+
const orphan = /** @type {any} */ (dragged);
|
|
94
|
+
try { wrapOrphan(engine, orphan); } catch {}
|
|
95
|
+
engine.commit().then(() => {
|
|
96
|
+
// keep the moved block focusable: move the cursor into it if it has text
|
|
97
|
+
const fresh = engine.blocks.get(id);
|
|
98
|
+
if (fresh?.behaviors?.has('text')) engine.selection.setCursor(fresh, 0);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Minimal CSS.escape fallback for the attribute selector. @param {string} s */
|
|
103
|
+
function cssEscape(s) { return (window.CSS && CSS.escape) ? CSS.escape(s) : String(s).replace(/["\\\]]/g, '\\$&'); }
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<svelte:window onpointermove={onPointerMove} onpointerup={onPointerUp} />
|
|
107
|
+
|
|
108
|
+
{#if handle.visible && !dragging}
|
|
109
|
+
<button
|
|
110
|
+
class="nabu-drag-handle"
|
|
111
|
+
data-nabu-ui
|
|
112
|
+
contenteditable="false"
|
|
113
|
+
type="button"
|
|
114
|
+
aria-label="Drag to reorder"
|
|
115
|
+
title="Drag to reorder"
|
|
116
|
+
style="top: {handle.top}px; left: {handle.left}px;"
|
|
117
|
+
onpointerdown={onHandleDown}
|
|
118
|
+
>⠿</button>
|
|
119
|
+
{/if}
|
|
120
|
+
|
|
121
|
+
{#if indicator.visible}
|
|
122
|
+
<div class="nabu-drop-indicator" style="top: {indicator.top}px; left: {indicator.left}px; width: {indicator.width}px;"></div>
|
|
123
|
+
{/if}
|
|
124
|
+
|
|
125
|
+
<style>
|
|
126
|
+
.nabu-drag-handle {
|
|
127
|
+
position: fixed; z-index: 150; width: 24px; height: 22px;
|
|
128
|
+
display: flex; align-items: center; justify-content: center;
|
|
129
|
+
border: none; background: transparent; cursor: grab;
|
|
130
|
+
color: var(--nb-text-muted, rgba(255,255,255,0.35)); font-size: 14px;
|
|
131
|
+
border-radius: 4px; user-select: none; padding: 0; line-height: 1;
|
|
132
|
+
}
|
|
133
|
+
.nabu-drag-handle:hover { background: var(--nb-bg-surface-hover, rgba(255,255,255,0.08)); color: var(--nb-text-primary, rgba(255,255,255,0.8)); }
|
|
134
|
+
.nabu-drag-handle:active { cursor: grabbing; }
|
|
135
|
+
.nabu-drop-indicator {
|
|
136
|
+
position: fixed; z-index: 150; height: 2px; pointer-events: none;
|
|
137
|
+
background: var(--nb-accent, #4d9fff); border-radius: 2px;
|
|
138
|
+
box-shadow: 0 0 4px var(--nb-accent, #4d9fff);
|
|
139
|
+
}
|
|
140
|
+
:global(.nabu-dragging) { opacity: 0.4; }
|
|
141
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default DragHandle;
|
|
2
|
+
type DragHandle = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const DragHandle: import("svelte").Component<{
|
|
7
|
+
engine: import("../blocks/nabu.svelte.js").Nabu;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
engine: import("../blocks/nabu.svelte.js").Nabu;
|
|
11
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Floating mark toolbar. Appears above the current (non-collapsed) selection.
|
|
4
|
+
* Positioned with `position: fixed` in viewport coordinates, so it works
|
|
5
|
+
* inside any layout (scrollable containers, overflow: hidden ancestors…)
|
|
6
|
+
* without a positioning wrapper.
|
|
7
|
+
*
|
|
8
|
+
* @type {{ engine: import('../blocks/nabu.svelte.js').Nabu }}
|
|
9
|
+
*/
|
|
10
|
+
let { engine } = $props();
|
|
11
|
+
|
|
12
|
+
/** @type {HTMLElement | null} */
|
|
13
|
+
let toolbarEl = $state(null);
|
|
14
|
+
let visible = $state(false);
|
|
15
|
+
let position = $state({ top: 0, left: 0 });
|
|
16
|
+
|
|
17
|
+
$effect(() => {
|
|
18
|
+
const sel = engine.selection;
|
|
19
|
+
if (!sel || sel.isCollapsed) {
|
|
20
|
+
visible = false;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Position above the selection via Range.getBoundingClientRect()
|
|
24
|
+
const range = sel.firstRange;
|
|
25
|
+
if (!range) {
|
|
26
|
+
visible = false;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const rect = range.getBoundingClientRect();
|
|
30
|
+
// Collapsed-looking rect (e.g. selection cleared mid-update) → hide
|
|
31
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
32
|
+
visible = false;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
visible = true;
|
|
36
|
+
// Viewport coordinates — the toolbar is position: fixed
|
|
37
|
+
position = {
|
|
38
|
+
top: Math.max(8, rect.top - (toolbarEl?.offsetHeight ?? 40) - 8),
|
|
39
|
+
left: rect.left + rect.width / 2,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const marks = [
|
|
44
|
+
{ key: 'bold', label: 'B', title: 'Bold (Ctrl+B)' },
|
|
45
|
+
{ key: 'italic', label: 'I', title: 'Italic (Ctrl+I)' },
|
|
46
|
+
{ key: 'underline', label: 'U', title: 'Underline (Ctrl+U)' },
|
|
47
|
+
{ key: 'code', label: '<>', title: 'Code (Ctrl+E)' },
|
|
48
|
+
{ key: 'strikethrough', label: 'S', title: 'Strikethrough (Ctrl+Shift+X)' },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
function toggleLink() {
|
|
52
|
+
if (engine.isMarkActive('link')) {
|
|
53
|
+
engine.exec('link:remove');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const href = window.prompt('Link URL');
|
|
57
|
+
if (href) engine.exec('link:set', { href });
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
{#if visible}
|
|
62
|
+
<div
|
|
63
|
+
bind:this={toolbarEl}
|
|
64
|
+
class="nabu-toolbar"
|
|
65
|
+
style="top: {position.top}px; left: {position.left}px;"
|
|
66
|
+
contenteditable="false"
|
|
67
|
+
data-nabu-ui
|
|
68
|
+
>
|
|
69
|
+
{#each marks as mark}
|
|
70
|
+
<button
|
|
71
|
+
class="nabu-toolbar-btn"
|
|
72
|
+
class:active={engine.isMarkActive(mark.key)}
|
|
73
|
+
title={mark.title}
|
|
74
|
+
onmousedown={(e) => { e.preventDefault(); engine.exec('mark:toggle', { mark: mark.key }); }}
|
|
75
|
+
>
|
|
76
|
+
{mark.label}
|
|
77
|
+
</button>
|
|
78
|
+
{/each}
|
|
79
|
+
<button
|
|
80
|
+
class="nabu-toolbar-btn"
|
|
81
|
+
class:active={engine.isMarkActive('link')}
|
|
82
|
+
title="Link"
|
|
83
|
+
onmousedown={(e) => { e.preventDefault(); toggleLink(); }}
|
|
84
|
+
>
|
|
85
|
+
🔗
|
|
86
|
+
</button>
|
|
87
|
+
</div>
|
|
88
|
+
{/if}
|
|
89
|
+
|
|
90
|
+
<style>
|
|
91
|
+
.nabu-toolbar {
|
|
92
|
+
position: fixed;
|
|
93
|
+
transform: translateX(-50%);
|
|
94
|
+
display: flex;
|
|
95
|
+
gap: 2px;
|
|
96
|
+
padding: 4px;
|
|
97
|
+
background: var(--nb-bg-surface, #1a1a1a);
|
|
98
|
+
border: 1px solid var(--nb-border, rgba(255,255,255,0.1));
|
|
99
|
+
border-radius: 8px;
|
|
100
|
+
box-shadow: 0 4px 16px rgba(0,0,0,0.3);
|
|
101
|
+
z-index: 100;
|
|
102
|
+
pointer-events: all;
|
|
103
|
+
}
|
|
104
|
+
.nabu-toolbar-btn {
|
|
105
|
+
padding: 4px 8px;
|
|
106
|
+
border: none;
|
|
107
|
+
background: transparent;
|
|
108
|
+
color: var(--nb-text-primary, rgba(255,255,255,0.85));
|
|
109
|
+
border-radius: 4px;
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
font-size: 13px;
|
|
112
|
+
font-weight: 600;
|
|
113
|
+
transition: background 0.1s;
|
|
114
|
+
}
|
|
115
|
+
.nabu-toolbar-btn:hover { background: var(--nb-bg-surface-hover, rgba(255,255,255,0.08)); }
|
|
116
|
+
.nabu-toolbar-btn.active { background: var(--nb-bg-surface-active, rgba(255,255,255,0.15)); }
|
|
117
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default FloatingToolbar;
|
|
2
|
+
type FloatingToolbar = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const FloatingToolbar: import("svelte").Component<{
|
|
7
|
+
engine: import("../blocks/nabu.svelte.js").Nabu;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
/**
|
|
10
|
+
* Floating mark toolbar. Appears above the current (non-collapsed) selection.
|
|
11
|
+
* Positioned with `position: fixed` in viewport coordinates, so it works
|
|
12
|
+
* inside any layout (scrollable containers, overflow: hidden ancestors…)
|
|
13
|
+
* without a positioning wrapper.
|
|
14
|
+
*/
|
|
15
|
+
type $$ComponentProps = {
|
|
16
|
+
engine: import("../blocks/nabu.svelte.js").Nabu;
|
|
17
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { SlashMenuController, DEFAULT_SLASH_COMMANDS } from './slash-menu.svelte.js';
|
|
3
|
+
/** @type {{ engine: import('../blocks/nabu.svelte.js').Nabu, commands?: import('./slash-menu.svelte.js').SlashCommand[] }} */
|
|
4
|
+
let { engine, commands = DEFAULT_SLASH_COMMANDS } = $props();
|
|
5
|
+
const ctrl = new SlashMenuController(engine, commands);
|
|
6
|
+
let pos = $state({ top: 0, left: 0 });
|
|
7
|
+
|
|
8
|
+
// Reset the highlighted item whenever the query changes.
|
|
9
|
+
$effect(() => { ctrl.query; ctrl.selectedIndex = 0; });
|
|
10
|
+
|
|
11
|
+
// Position the popup just below the caret when open.
|
|
12
|
+
$effect(() => {
|
|
13
|
+
if (!ctrl.open) return;
|
|
14
|
+
const range = engine.selection?.firstRange;
|
|
15
|
+
if (!range) return;
|
|
16
|
+
const r = range.getBoundingClientRect();
|
|
17
|
+
pos = { top: r.bottom + window.scrollY + 4, left: r.left + window.scrollX };
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Capture keyboard navigation ONLY while the menu is open (capture phase so it
|
|
21
|
+
// beats the editor's own keydown handler).
|
|
22
|
+
$effect(() => {
|
|
23
|
+
if (!ctrl.open) return;
|
|
24
|
+
/** @param {KeyboardEvent} ev */
|
|
25
|
+
const onKey = (ev) => {
|
|
26
|
+
if (ev.key === 'ArrowDown') { ev.preventDefault(); ev.stopImmediatePropagation(); ctrl.moveSelection(1); }
|
|
27
|
+
else if (ev.key === 'ArrowUp') { ev.preventDefault(); ev.stopImmediatePropagation(); ctrl.moveSelection(-1); }
|
|
28
|
+
else if (ev.key === 'Enter' || ev.key === 'Tab') { ev.preventDefault(); ev.stopImmediatePropagation(); ctrl.select(); }
|
|
29
|
+
else if (ev.key === 'Escape') { ev.preventDefault(); ev.stopImmediatePropagation(); ctrl.close(); }
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener('keydown', onKey, true);
|
|
32
|
+
return () => document.removeEventListener('keydown', onKey, true);
|
|
33
|
+
});
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{#if ctrl.open}
|
|
37
|
+
<div class="nabu-slash" data-nabu-ui contenteditable="false" style="top: {pos.top}px; left: {pos.left}px;">
|
|
38
|
+
{#each ctrl.filteredItems as item, i (item.title)}
|
|
39
|
+
<button
|
|
40
|
+
class="nabu-slash-item"
|
|
41
|
+
class:active={i === ctrl.selectedIndex}
|
|
42
|
+
onmousedown={(e) => { e.preventDefault(); ctrl.select(i); }}
|
|
43
|
+
onmouseenter={() => ctrl.selectedIndex = i}
|
|
44
|
+
>
|
|
45
|
+
<span class="nabu-slash-icon">{item.icon ?? ''}</span>
|
|
46
|
+
<span class="nabu-slash-title">{item.title}</span>
|
|
47
|
+
{#if item.subtitle}<span class="nabu-slash-sub">{item.subtitle}</span>{/if}
|
|
48
|
+
</button>
|
|
49
|
+
{/each}
|
|
50
|
+
</div>
|
|
51
|
+
{/if}
|
|
52
|
+
|
|
53
|
+
<style>
|
|
54
|
+
.nabu-slash {
|
|
55
|
+
position: fixed;
|
|
56
|
+
z-index: 200;
|
|
57
|
+
min-width: 220px;
|
|
58
|
+
max-height: 320px;
|
|
59
|
+
overflow-y: auto;
|
|
60
|
+
padding: 4px;
|
|
61
|
+
background: var(--nb-bg-surface, #1a1a1a);
|
|
62
|
+
border: 1px solid var(--nb-border, rgba(255,255,255,0.12));
|
|
63
|
+
border-radius: 8px;
|
|
64
|
+
box-shadow: 0 8px 24px rgba(0,0,0,0.35);
|
|
65
|
+
pointer-events: all;
|
|
66
|
+
}
|
|
67
|
+
.nabu-slash-item {
|
|
68
|
+
display: flex; align-items: center; gap: 8px;
|
|
69
|
+
width: 100%; padding: 6px 8px; border: none; background: transparent;
|
|
70
|
+
color: var(--nb-text-primary, rgba(255,255,255,0.85));
|
|
71
|
+
border-radius: 5px; cursor: pointer; text-align: left; font-size: 13px;
|
|
72
|
+
}
|
|
73
|
+
.nabu-slash-item.active { background: var(--nb-bg-surface-active, rgba(255,255,255,0.1)); }
|
|
74
|
+
.nabu-slash-icon {
|
|
75
|
+
flex-shrink: 0; width: 22px; height: 22px;
|
|
76
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
77
|
+
font-size: 12px; font-weight: 600;
|
|
78
|
+
color: var(--nb-text-secondary, rgba(255,255,255,0.5));
|
|
79
|
+
border: 1px solid var(--nb-border, rgba(255,255,255,0.1)); border-radius: 4px;
|
|
80
|
+
}
|
|
81
|
+
.nabu-slash-title { flex: 1; }
|
|
82
|
+
.nabu-slash-sub { color: var(--nb-text-secondary, rgba(255,255,255,0.4)); font-size: 11px; }
|
|
83
|
+
</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default SlashMenu;
|
|
2
|
+
type SlashMenu = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const SlashMenu: import("svelte").Component<{
|
|
7
|
+
engine: import("../blocks/nabu.svelte.js").Nabu;
|
|
8
|
+
commands?: import("./slash-menu.svelte.js").SlashCommand[];
|
|
9
|
+
}, {}, "">;
|
|
10
|
+
type $$ComponentProps = {
|
|
11
|
+
engine: import("../blocks/nabu.svelte.js").Nabu;
|
|
12
|
+
commands?: import("./slash-menu.svelte.js").SlashCommand[];
|
|
13
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as FloatingToolbar } from "./FloatingToolbar.svelte";
|
|
2
|
+
export { default as SlashMenu } from "./SlashMenu.svelte";
|
|
3
|
+
export { default as DragHandle } from "./DragHandle.svelte";
|
|
4
|
+
export { SlashMenuController, DEFAULT_SLASH_COMMANDS } from "./slash-menu.svelte.js";
|