@aionbuilders/nabu 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +15 -1
- package/dist/behaviors/text/index.d.ts +1 -1
- package/dist/behaviors/text/index.js +1 -1
- package/dist/behaviors/text/rich-text.extension.js +96 -30
- package/dist/behaviors/text/text.behavior.svelte.d.ts +19 -0
- package/dist/behaviors/text/text.behavior.svelte.js +64 -2
- package/dist/blocks/Block.svelte +3 -3
- package/dist/blocks/BlockGap.svelte +55 -0
- package/dist/blocks/BlockGap.svelte.d.ts +11 -0
- package/dist/blocks/Nabu.svelte +8 -0
- package/dist/blocks/block.extension.d.ts +2 -0
- package/dist/blocks/block.extension.js +32 -0
- package/dist/blocks/block.svelte.d.ts +41 -9
- package/dist/blocks/block.svelte.js +55 -18
- package/dist/blocks/container.utils.d.ts +54 -4
- package/dist/blocks/container.utils.js +211 -8
- package/dist/blocks/dialogue/Dialogue.svelte +46 -0
- package/dist/blocks/dialogue/Dialogue.svelte.d.ts +11 -0
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +41 -0
- package/dist/blocks/dialogue/dialogue.svelte.js +87 -0
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +52 -0
- package/dist/blocks/dialogue/index.d.ts +7 -0
- package/dist/blocks/dialogue/index.js +47 -0
- package/dist/blocks/heading/Heading.svelte +13 -9
- package/dist/blocks/heading/heading.svelte.d.ts +40 -4
- package/dist/blocks/heading/heading.svelte.js +60 -4
- package/dist/blocks/heading/hooks/onBeforeInput.hook.js +1 -1
- package/dist/blocks/heading/index.d.ts +2 -2
- package/dist/blocks/heading/index.js +11 -7
- package/dist/blocks/index.d.ts +7 -4
- package/dist/blocks/index.js +7 -4
- package/dist/blocks/list/ListItem.svelte +6 -2
- package/dist/blocks/list/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +77 -0
- package/dist/blocks/list/index.d.ts +2 -2
- package/dist/blocks/list/index.js +17 -3
- package/dist/blocks/list/list-item.svelte.d.ts +59 -6
- package/dist/blocks/list/list-item.svelte.js +157 -89
- package/dist/blocks/list/list.behavior.svelte.d.ts +1 -0
- package/dist/blocks/list/list.behavior.svelte.js +5 -4
- package/dist/blocks/list/list.svelte.d.ts +60 -7
- package/dist/blocks/list/list.svelte.js +116 -15
- package/dist/blocks/megablock.svelte.d.ts +30 -5
- package/dist/blocks/megablock.svelte.js +113 -17
- package/dist/blocks/nabu.svelte.d.ts +44 -6
- package/dist/blocks/nabu.svelte.js +397 -15
- package/dist/blocks/paragraph/Paragraph.svelte +12 -16
- package/dist/blocks/paragraph/Paragraph.svelte.d.ts +2 -2
- package/dist/blocks/paragraph/index.d.ts +2 -2
- package/dist/blocks/paragraph/index.js +29 -8
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +33 -5
- package/dist/blocks/paragraph/paragraph.svelte.js +55 -3
- package/dist/blocks/selection.svelte.d.ts +6 -5
- package/dist/blocks/selection.svelte.js +209 -18
- package/dist/blocks/variable.svelte.d.ts +47 -0
- package/dist/blocks/variable.svelte.js +51 -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 copy.svelte +118 -0
- package/dist/blocks/zone/ZoneEditor copy.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 +227 -0
- package/dist/blocks/zone/zone.svelte.d.ts +222 -0
- package/dist/blocks/zone/zone.svelte.js +620 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/nabu-theme.css +92 -0
- package/dist/overlays/context/Context.svelte +179 -0
- package/dist/overlays/context/Context.svelte.d.ts +16 -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 +81 -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.d.ts +12 -0
- package/dist/paste/html.paste.js +192 -0
- package/dist/paste/index.d.ts +4 -0
- package/dist/paste/index.js +4 -0
- package/dist/paste/markdown.paste.d.ts +12 -0
- package/dist/paste/markdown.paste.js +140 -0
- package/dist/paste/nabu.paste.d.ts +2 -0
- package/dist/paste/nabu.paste.js +20 -0
- package/dist/paste/plain-text.paste.d.ts +8 -0
- package/dist/paste/plain-text.paste.js +42 -0
- package/dist/persistence/indexeddb.d.ts +19 -0
- package/dist/persistence/indexeddb.js +71 -0
- package/dist/persistence/persistence.d.ts +48 -0
- package/dist/persistence/persistence.js +80 -0
- package/dist/presets.d.ts +1 -0
- package/dist/presets.js +18 -4
- package/dist/utils/extensions.d.ts +63 -0
- package/dist/utils/extensions.js +33 -0
- package/dist/utils/selection.svelte.js +0 -5
- package/package.json +14 -3
|
@@ -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,179 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @import { ContextMenuSection, Context } from './context.svelte.js' */
|
|
3
|
+
import { untrack } from 'svelte';
|
|
4
|
+
import { fly } from 'svelte/transition';
|
|
5
|
+
import { setMenuContext } from './context.svelte.js';
|
|
6
|
+
|
|
7
|
+
/** @type {{ x: number, y: number, context: Context }} */
|
|
8
|
+
let { x, y, context } = $props();
|
|
9
|
+
|
|
10
|
+
setMenuContext(untrack(() => context));
|
|
11
|
+
|
|
12
|
+
// Clamp to viewport so the menu never goes off-screen
|
|
13
|
+
const menuWidth = 220;
|
|
14
|
+
const menuMaxHeight = 400;
|
|
15
|
+
const left = $derived(Math.min(x, window.innerWidth - menuWidth) + 'px');
|
|
16
|
+
const top = $derived(Math.min(y, window.innerHeight - menuMaxHeight) + 'px');
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div class="nabu-context-menu" style:left style:top role="menu">
|
|
20
|
+
{#if context.history.length > 1}
|
|
21
|
+
<div class="nabu-context-header">
|
|
22
|
+
<button class="nabu-context-back" onclick={() => context.pop()}>
|
|
23
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
24
|
+
<path d="m15 18-6-6 6-6"/>
|
|
25
|
+
</svg>
|
|
26
|
+
</button>
|
|
27
|
+
<span class="nabu-context-title">{context.currentView.title || 'Retour'}</span>
|
|
28
|
+
</div>
|
|
29
|
+
{/if}
|
|
30
|
+
|
|
31
|
+
<div class="nabu-context-viewport">
|
|
32
|
+
{#key context.currentView.id}
|
|
33
|
+
<div
|
|
34
|
+
class="nabu-context-view"
|
|
35
|
+
in:fly={{ x: context.direction === 1 ? 50 : -50, duration: 200 }}
|
|
36
|
+
out:fly={{ x: context.direction === 1 ? -50 : 50, duration: 200 }}
|
|
37
|
+
>
|
|
38
|
+
{#each context.currentView.sections as section, i (section.key)}
|
|
39
|
+
{#if i > 0}
|
|
40
|
+
<div class="nabu-context-sep" role="separator"></div>
|
|
41
|
+
{/if}
|
|
42
|
+
|
|
43
|
+
{#if section.component}
|
|
44
|
+
<section.component {...(section.props ?? {})} />
|
|
45
|
+
{:else if section.items}
|
|
46
|
+
<!-- {#each section.items as item}
|
|
47
|
+
<button
|
|
48
|
+
class="nabu-context-item"
|
|
49
|
+
class:disabled={item.disabled}
|
|
50
|
+
disabled={item.disabled}
|
|
51
|
+
role="menuitem"
|
|
52
|
+
onclick={item.action}
|
|
53
|
+
>
|
|
54
|
+
{#if item.icon}
|
|
55
|
+
<span class="nabu-context-icon">{item.icon}</span>
|
|
56
|
+
{/if}
|
|
57
|
+
<span class="nabu-context-label">{item.label}</span>
|
|
58
|
+
</button>
|
|
59
|
+
{/each} -->
|
|
60
|
+
{/if}
|
|
61
|
+
{/each}
|
|
62
|
+
</div>
|
|
63
|
+
{/key}
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<style>
|
|
68
|
+
.nabu-context-menu {
|
|
69
|
+
position: fixed;
|
|
70
|
+
z-index: 9999;
|
|
71
|
+
min-width: 240px;
|
|
72
|
+
font-family: 'Inter', system-ui, sans-serif;
|
|
73
|
+
font-size: 13px;
|
|
74
|
+
color: var(--nb-text-primary, #eee);
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-direction: column;
|
|
77
|
+
gap: 8px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.nabu-context-header {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
padding: 6px 8px;
|
|
84
|
+
gap: 8px;
|
|
85
|
+
font-weight: 500;
|
|
86
|
+
background: var(--nb-bg-surface, hsla(0, 0%, 12%, 0.75));
|
|
87
|
+
backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
|
|
88
|
+
-webkit-backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
|
|
89
|
+
border: 1px solid var(--nb-border, hsla(0, 0%, 100%, 0.1));
|
|
90
|
+
border-radius: 12px;
|
|
91
|
+
box-shadow: var(--nb-shadow-lg, 0 8px 24px -8px rgba(0,0,0,0.5));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.nabu-context-back {
|
|
95
|
+
background: transparent;
|
|
96
|
+
border: none;
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
display: flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
justify-content: center;
|
|
101
|
+
padding: 4px;
|
|
102
|
+
border-radius: 6px;
|
|
103
|
+
color: var(--nb-text-secondary, hsla(0, 0%, 100%, 0.6));
|
|
104
|
+
transition: background 0.15s, color 0.15s;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.nabu-context-back:hover {
|
|
108
|
+
background: var(--nb-bg-surface-hover, hsla(0, 0%, 100%, 0.1));
|
|
109
|
+
color: var(--nb-text-primary, hsla(0, 0%, 100%, 1));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.nabu-context-title {
|
|
113
|
+
flex: 1;
|
|
114
|
+
text-align: left;
|
|
115
|
+
font-size: 13px;
|
|
116
|
+
color: var(--nb-text-primary, hsla(0, 0%, 100%, 0.9));
|
|
117
|
+
letter-spacing: 0.2px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.nabu-context-viewport {
|
|
121
|
+
position: relative;
|
|
122
|
+
display: grid;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.nabu-context-view {
|
|
126
|
+
grid-area: 1 / 1;
|
|
127
|
+
width: 100%;
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-direction: column;
|
|
130
|
+
gap: 8px;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.nabu-context-sep {
|
|
134
|
+
display: none;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.nabu-context-item {
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
gap: 8px;
|
|
141
|
+
width: 100%;
|
|
142
|
+
padding: 6px 10px;
|
|
143
|
+
border: none;
|
|
144
|
+
background: var(--nb-bg-surface, hsla(0, 0%, 12%, 0.75));
|
|
145
|
+
backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
|
|
146
|
+
-webkit-backdrop-filter: var(--nb-glass-blur, blur(24px) saturate(180%));
|
|
147
|
+
border: 1px solid var(--nb-border, hsla(0, 0%, 100%, 0.1));
|
|
148
|
+
border-radius: 12px;
|
|
149
|
+
box-shadow: var(--nb-shadow-lg, 0 8px 24px -8px rgba(0,0,0,0.5));
|
|
150
|
+
cursor: pointer;
|
|
151
|
+
text-align: left;
|
|
152
|
+
color: var(--nb-text-primary, hsla(0, 0%, 100%, 0.8));
|
|
153
|
+
transition: transform 0.1s, background 0.1s;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.nabu-context-item:hover:not(.disabled) {
|
|
157
|
+
background: var(--nb-bg-surface-active, hsla(0, 0%, 100%, 0.15));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.nabu-context-item:active:not(.disabled) {
|
|
161
|
+
transform: scale(0.98);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.nabu-context-item.disabled {
|
|
165
|
+
opacity: 0.4;
|
|
166
|
+
cursor: default;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.nabu-context-icon {
|
|
170
|
+
width: 16px;
|
|
171
|
+
text-align: center;
|
|
172
|
+
flex-shrink: 0;
|
|
173
|
+
opacity: 0.6;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.nabu-context-label {
|
|
177
|
+
flex: 1;
|
|
178
|
+
}
|
|
179
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default Context;
|
|
2
|
+
type Context = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Context: import("svelte").Component<{
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
context: Context;
|
|
10
|
+
}, {}, "">;
|
|
11
|
+
import type { Context } from './context.svelte.js';
|
|
12
|
+
type $$ComponentProps = {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
context: Context;
|
|
16
|
+
};
|
|
@@ -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,81 @@
|
|
|
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: Context;
|
|
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";
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { createContext, mount, unmount } from "svelte";
|
|
2
|
+
import { browser } from "$app/environment";
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse the inline content of a DOM element into a Loro-compatible delta array.
|
|
3
|
+
* Recurses into inline and unknown elements, inheriting marks.
|
|
4
|
+
* Skips block-level children (ul, ol, table…) — those are handled by fromHTML.
|
|
5
|
+
*
|
|
6
|
+
* @param {Element} el
|
|
7
|
+
* @param {Record<string, true>} [marks]
|
|
8
|
+
* @returns {import('loro-crdt').Delta<string>[]}
|
|
9
|
+
*/
|
|
10
|
+
export function parseInline(el: Element, marks?: Record<string, true>): import("loro-crdt").Delta<string>[];
|
|
11
|
+
export const HtmlPasteExtension: Extension;
|
|
12
|
+
import { Extension } from '../utils/extensions.js';
|