@aionbuilders/nabu 0.1.0-alpha.9 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -9
- package/dist/behaviors/text/RichText.svelte +4 -1
- package/dist/behaviors/text/index.d.ts +2 -0
- package/dist/behaviors/text/index.js +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +54 -0
- package/dist/behaviors/text/rich-text.extension.js +47 -22
- package/dist/behaviors/text/text.behavior.svelte.d.ts +25 -1
- package/dist/behaviors/text/text.behavior.svelte.js +154 -18
- package/dist/behaviors/text/typography.extension.d.ts +6 -0
- package/dist/behaviors/text/typography.extension.js +24 -0
- package/dist/blocks/Block.svelte +5 -2
- package/dist/blocks/Nabu.svelte +22 -0
- package/dist/blocks/block.extension.js +10 -8
- package/dist/blocks/block.svelte.d.ts +24 -0
- package/dist/blocks/block.svelte.js +35 -0
- package/dist/blocks/blockquote/Blockquote.svelte +40 -0
- package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
- package/dist/blocks/blockquote/blockquote.extension.d.ts +1 -0
- package/dist/blocks/blockquote/blockquote.extension.js +71 -0
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +55 -0
- package/dist/blocks/blockquote/blockquote.svelte.js +91 -0
- package/dist/blocks/blockquote/index.d.ts +3 -0
- package/dist/blocks/blockquote/index.js +3 -0
- package/dist/blocks/callout/Callout.svelte +69 -0
- package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
- package/dist/blocks/callout/callout.extension.d.ts +1 -0
- package/dist/blocks/callout/callout.extension.js +68 -0
- package/dist/blocks/callout/callout.svelte.d.ts +78 -0
- package/dist/blocks/callout/callout.svelte.js +184 -0
- package/dist/blocks/callout/index.d.ts +3 -0
- package/dist/blocks/callout/index.js +3 -0
- package/dist/blocks/code/Code.svelte +85 -0
- package/dist/blocks/code/Code.svelte.d.ts +11 -0
- package/dist/blocks/code/code.extension.d.ts +1 -0
- package/dist/blocks/code/code.extension.js +68 -0
- package/dist/blocks/code/code.svelte.d.ts +61 -0
- package/dist/blocks/code/code.svelte.js +221 -0
- package/dist/blocks/code/index.d.ts +3 -0
- package/dist/blocks/code/index.js +3 -0
- package/dist/blocks/dialogue/Dialogue.svelte +2 -0
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +3 -21
- package/dist/blocks/dialogue/dialogue.svelte.js +2 -50
- package/dist/blocks/divider/Divider.svelte +28 -0
- package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
- package/dist/blocks/divider/divider.extension.d.ts +1 -0
- package/dist/blocks/divider/divider.extension.js +87 -0
- package/dist/blocks/divider/divider.svelte.d.ts +49 -0
- package/dist/blocks/divider/divider.svelte.js +84 -0
- package/dist/blocks/divider/index.d.ts +3 -0
- package/dist/blocks/divider/index.js +3 -0
- package/dist/blocks/file/File.svelte +49 -0
- package/dist/blocks/file/File.svelte.d.ts +11 -0
- package/dist/blocks/file/file.extension.d.ts +1 -0
- package/dist/blocks/file/file.extension.js +19 -0
- package/dist/blocks/file/file.svelte.d.ts +29 -0
- package/dist/blocks/file/file.svelte.js +71 -0
- package/dist/blocks/file/index.d.ts +3 -0
- package/dist/blocks/file/index.js +3 -0
- package/dist/blocks/heading/Heading.svelte +3 -1
- package/dist/blocks/heading/heading.svelte.d.ts +4 -23
- package/dist/blocks/heading/heading.svelte.js +4 -47
- package/dist/blocks/image/Image.svelte +38 -0
- package/dist/blocks/image/Image.svelte.d.ts +11 -0
- package/dist/blocks/image/image.extension.d.ts +2 -0
- package/dist/blocks/image/image.extension.js +26 -0
- package/dist/blocks/image/image.svelte.d.ts +50 -0
- package/dist/blocks/image/image.svelte.js +92 -0
- package/dist/blocks/image/index.d.ts +3 -0
- package/dist/blocks/image/index.js +3 -0
- package/dist/blocks/index.d.ts +10 -0
- package/dist/blocks/index.js +10 -0
- package/dist/blocks/list/List.svelte +8 -2
- package/dist/blocks/list/ListItem.svelte +43 -7
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +15 -2
- package/dist/blocks/list/index.d.ts +1 -0
- package/dist/blocks/list/index.js +1 -0
- package/dist/blocks/list/list-item.svelte.d.ts +14 -2
- package/dist/blocks/list/list-item.svelte.js +58 -7
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -4
- package/dist/blocks/list/list.behavior.svelte.js +5 -5
- package/dist/blocks/list/list.svelte.d.ts +13 -6
- package/dist/blocks/list/list.svelte.js +24 -6
- package/dist/blocks/list/todos.svelte.d.ts +35 -0
- package/dist/blocks/list/todos.svelte.js +76 -0
- package/dist/blocks/media/index.d.ts +2 -0
- package/dist/blocks/media/index.js +2 -0
- package/dist/blocks/media/media-block.svelte.d.ts +32 -0
- package/dist/blocks/media/media-block.svelte.js +69 -0
- package/dist/blocks/media/media.helpers.d.ts +19 -0
- package/dist/blocks/media/media.helpers.js +51 -0
- package/dist/blocks/megablock.svelte.js +1 -0
- package/dist/blocks/nabu.svelte.d.ts +94 -16
- package/dist/blocks/nabu.svelte.js +254 -3
- package/dist/blocks/paragraph/Paragraph.svelte +2 -0
- package/dist/blocks/paragraph/index.js +0 -3
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +3 -21
- package/dist/blocks/paragraph/paragraph.svelte.js +4 -53
- package/dist/blocks/selection.svelte.js +11 -1
- package/dist/blocks/text-block.svelte.d.ts +49 -0
- package/dist/blocks/text-block.svelte.js +74 -0
- package/dist/blocks/toggle/Toggle.svelte +84 -0
- package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
- package/dist/blocks/toggle/index.d.ts +3 -0
- package/dist/blocks/toggle/index.js +3 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +1 -0
- package/dist/blocks/toggle/toggle.extension.js +12 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +88 -0
- package/dist/blocks/toggle/toggle.svelte.js +252 -0
- package/dist/blocks/variable.svelte.d.ts +47 -0
- package/dist/blocks/variable.svelte.js +51 -0
- package/dist/blocks/video/Video.svelte +39 -0
- package/dist/blocks/video/Video.svelte.d.ts +11 -0
- package/dist/blocks/video/index.d.ts +3 -0
- package/dist/blocks/video/index.js +3 -0
- package/dist/blocks/video/video.extension.d.ts +1 -0
- package/dist/blocks/video/video.extension.js +19 -0
- package/dist/blocks/video/video.svelte.d.ts +28 -0
- package/dist/blocks/video/video.svelte.js +71 -0
- package/dist/blocks/zone/TemplateEditor.svelte +308 -0
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/Zone.svelte +158 -144
- package/dist/blocks/zone/ZoneEditor.svelte +289 -0
- package/dist/blocks/zone/ZoneEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte +188 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +11 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.js +30 -0
- package/dist/blocks/zone/zone.extension.js +22 -6
- package/dist/blocks/zone/zone.svelte.d.ts +111 -2
- package/dist/blocks/zone/zone.svelte.js +304 -17
- package/dist/files/files.svelte.d.ts +61 -0
- package/dist/files/files.svelte.js +93 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/nabu-theme.css +92 -0
- package/dist/overlays/context/Context.svelte +182 -0
- package/dist/overlays/context/Context.svelte.d.ts +17 -0
- package/dist/overlays/context/collect.d.ts +17 -0
- package/dist/overlays/context/collect.js +33 -0
- package/dist/overlays/context/context.extension.d.ts +2 -0
- package/dist/overlays/context/context.extension.js +8 -0
- package/dist/overlays/context/context.svelte.d.ts +82 -0
- package/dist/overlays/context/context.svelte.js +159 -0
- package/dist/overlays/context/index.d.ts +3 -0
- package/dist/overlays/context/index.js +3 -0
- package/dist/paste/html.paste.js +9 -1
- package/dist/presets.d.ts +3 -1
- package/dist/presets.js +21 -6
- package/dist/ui/DragHandle.svelte +141 -0
- package/dist/ui/DragHandle.svelte.d.ts +11 -0
- package/dist/ui/FloatingToolbar.svelte +117 -0
- package/dist/ui/FloatingToolbar.svelte.d.ts +17 -0
- package/dist/ui/SlashMenu.svelte +83 -0
- package/dist/ui/SlashMenu.svelte.d.ts +13 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/slash-menu.svelte.d.ts +40 -0
- package/dist/ui/slash-menu.svelte.js +116 -0
- package/dist/utils/extensions.d.ts +54 -0
- package/dist/utils/extensions.js +40 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/placeholders.d.ts +10 -0
- package/dist/utils/placeholders.js +21 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +23 -0
- package/package.json +10 -5
|
@@ -0,0 +1,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,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";
|
|
@@ -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,10 +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';
|
|
9
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';
|
|
10
19
|
|
|
11
20
|
// ---------------------------------------------------------------------------
|
|
12
21
|
// Presets — composable extension arrays
|
|
@@ -16,13 +25,16 @@ import { ZoneExtension } from './blocks/zone/zone.extension.js';
|
|
|
16
25
|
export const MinimalPreset = [ParagraphExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, BlockExtension];
|
|
17
26
|
|
|
18
27
|
/** Paragraph + rich text marks (bold, italic, underline, code, strikethrough). */
|
|
19
|
-
export const TextPreset = [ParagraphExtension, RichTextExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, MarkdownPasteExtension, BlockExtension];
|
|
28
|
+
export const TextPreset = [ParagraphExtension, RichTextExtension, TypographyExtension, MarkdownShortcutsExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, MarkdownPasteExtension, BlockExtension];
|
|
20
29
|
|
|
21
30
|
/** Paragraph + headings + rich text. Document-like, no lists. */
|
|
22
|
-
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];
|
|
23
32
|
|
|
24
33
|
/** All built-in block types + rich text. */
|
|
25
|
-
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
|
+
];
|
|
26
38
|
|
|
27
39
|
// ---------------------------------------------------------------------------
|
|
28
40
|
// Factory — generic createEditor
|
|
@@ -34,13 +46,16 @@ export const FullPreset = [ParagraphExtension, HeadingExtension, ListExtensi
|
|
|
34
46
|
* @param {object} [options]
|
|
35
47
|
* @param {typeof ParagraphExtension[]} [options.preset] - Base preset (default: FullPreset)
|
|
36
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)
|
|
37
50
|
* @returns {Nabu}
|
|
38
51
|
*
|
|
39
52
|
* @example
|
|
40
53
|
* const engine = createEditor({ preset: DocumentPreset, extensions: [MyCustomExtension] });
|
|
41
54
|
*/
|
|
42
|
-
export function createEditor({ preset = FullPreset, extensions = [] } = {}) {
|
|
43
|
-
|
|
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] });
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
// ---------------------------------------------------------------------------
|