@tableslayer/ui 0.2.3 → 0.2.4
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/dist/components/ContextMenu/ContextMenu.svelte +71 -21
- package/dist/components/ContextMenu/ContextMenu.svelte.d.ts +4 -1
- package/dist/components/ContextMenu/types.d.ts +6 -2
- package/dist/components/Editor/Editor.svelte +13 -0
- package/dist/components/MarkerTooltip/MarkerTooltip.svelte +17 -18
- package/package.json +1 -1
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { computePosition, flip, shift, offset, platform } from '@floating-ui/dom';
|
|
3
|
+
import { IconCheck } from '@tabler/icons-svelte';
|
|
3
4
|
import type { ContextMenuProps, ContextMenuItem } from './types';
|
|
4
5
|
import { goto } from '$app/navigation';
|
|
5
6
|
import { fly } from 'svelte/transition';
|
|
6
7
|
import { tick, onDestroy } from 'svelte';
|
|
7
8
|
import { Hr } from '../Hr';
|
|
9
|
+
import { Icon } from '../Icon';
|
|
8
10
|
import Spacer from '../Spacer/Spacer.svelte';
|
|
9
11
|
|
|
10
12
|
let { items, trigger }: ContextMenuProps = $props();
|
|
11
13
|
|
|
12
|
-
let triggerElement
|
|
14
|
+
let triggerElement = $state<HTMLElement | null>(null);
|
|
13
15
|
let menuElement = $state<HTMLElement | null>(null);
|
|
14
16
|
let isOpen = $state(false);
|
|
15
17
|
let floatingStyles = $state('');
|
|
16
18
|
let clickPosition = $state({ x: 0, y: 0 });
|
|
17
19
|
|
|
18
20
|
const handleItemClick = (item: ContextMenuItem) => {
|
|
21
|
+
if (item.disabled) return;
|
|
19
22
|
isOpen = false;
|
|
20
23
|
if (item.href) {
|
|
21
24
|
goto(item.href);
|
|
@@ -52,21 +55,27 @@
|
|
|
52
55
|
floatingStyles = `position: ${strategy}; left: ${x}px; top: ${y}px;`;
|
|
53
56
|
};
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
// Stops propagation so the window-level close handlers never see the
|
|
59
|
+
// opening event itself
|
|
60
|
+
export const open = async (e: MouseEvent) => {
|
|
56
61
|
e.preventDefault();
|
|
62
|
+
e.stopPropagation();
|
|
57
63
|
clickPosition = { x: e.clientX, y: e.clientY };
|
|
58
64
|
isOpen = true;
|
|
59
65
|
await tick();
|
|
60
66
|
updatePosition();
|
|
61
67
|
};
|
|
62
68
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
export const close = () => {
|
|
70
|
+
isOpen = false;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const handleGlobalPointer = (e: MouseEvent) => {
|
|
74
|
+
if (!isOpen || !menuElement) return;
|
|
75
|
+
const target = e.target as Node;
|
|
76
|
+
if (menuElement.contains(target)) return;
|
|
77
|
+
if (triggerElement?.contains(target)) return;
|
|
78
|
+
isOpen = false;
|
|
70
79
|
};
|
|
71
80
|
|
|
72
81
|
const handleKeydown = (e: KeyboardEvent) => {
|
|
@@ -80,22 +89,40 @@
|
|
|
80
89
|
});
|
|
81
90
|
</script>
|
|
82
91
|
|
|
83
|
-
<svelte:window onclick={
|
|
92
|
+
<svelte:window onclick={handleGlobalPointer} oncontextmenu={handleGlobalPointer} onkeydown={handleKeydown} />
|
|
84
93
|
|
|
85
|
-
|
|
86
|
-
{
|
|
87
|
-
|
|
94
|
+
{#if trigger}
|
|
95
|
+
<button bind:this={triggerElement} oncontextmenu={open} class="cMenuTrigger">
|
|
96
|
+
{@render trigger()}
|
|
97
|
+
</button>
|
|
98
|
+
{/if}
|
|
88
99
|
|
|
89
100
|
{#if isOpen}
|
|
90
101
|
<div bind:this={menuElement} class="cMenu" style={floatingStyles} transition:fly={{ duration: 50 }} role="menu">
|
|
91
|
-
{#each items as item}
|
|
102
|
+
{#each items as item (item)}
|
|
92
103
|
{#if item.type === 'divider'}
|
|
93
104
|
<Spacer size="0.5rem" />
|
|
94
105
|
<Hr />
|
|
95
106
|
<Spacer size="0.5rem" />
|
|
107
|
+
{:else if item.type === 'label'}
|
|
108
|
+
<div class="cMenuLabel">{item.label}</div>
|
|
96
109
|
{:else}
|
|
97
|
-
<button
|
|
98
|
-
{item
|
|
110
|
+
<button
|
|
111
|
+
onclick={() => handleItemClick(item)}
|
|
112
|
+
class={['cMenuItem', item.variant === 'danger' && 'cMenuItem--danger']}
|
|
113
|
+
disabled={item.disabled}
|
|
114
|
+
role="menuitem"
|
|
115
|
+
>
|
|
116
|
+
<span class="cMenuItemLabel">
|
|
117
|
+
{#if item.selected !== undefined}
|
|
118
|
+
<span class="cMenuItemCheck">
|
|
119
|
+
{#if item.selected}
|
|
120
|
+
<Icon Icon={IconCheck} size="1rem" />
|
|
121
|
+
{/if}
|
|
122
|
+
</span>
|
|
123
|
+
{/if}
|
|
124
|
+
{item.label}
|
|
125
|
+
</span>
|
|
99
126
|
{#if item.end}
|
|
100
127
|
<div class="cMenuItemEnd">
|
|
101
128
|
{@render item.end()}
|
|
@@ -140,15 +167,38 @@
|
|
|
140
167
|
border: solid 2px transparent;
|
|
141
168
|
justify-content: space-between;
|
|
142
169
|
}
|
|
143
|
-
.cMenuItem:hover,
|
|
144
|
-
.cMenuItem:focus,
|
|
145
|
-
.cMenuItem:active {
|
|
146
|
-
background-color: var(--
|
|
147
|
-
border: var(--
|
|
170
|
+
.cMenuItem:hover:not(:disabled),
|
|
171
|
+
.cMenuItem:focus:not(:disabled),
|
|
172
|
+
.cMenuItem:active:not(:disabled) {
|
|
173
|
+
background-color: var(--cMenuItemHover);
|
|
174
|
+
border: var(--cMenuItemBorderHover);
|
|
175
|
+
}
|
|
176
|
+
.cMenuItem:disabled {
|
|
177
|
+
cursor: not-allowed;
|
|
178
|
+
opacity: 0.5;
|
|
179
|
+
}
|
|
180
|
+
.cMenuItem--danger {
|
|
181
|
+
color: var(--fgDanger);
|
|
182
|
+
}
|
|
183
|
+
.cMenuItemLabel {
|
|
184
|
+
display: flex;
|
|
185
|
+
align-items: center;
|
|
186
|
+
gap: 0.5rem;
|
|
187
|
+
}
|
|
188
|
+
.cMenuItemCheck {
|
|
189
|
+
display: flex;
|
|
190
|
+
align-items: center;
|
|
191
|
+
justify-content: center;
|
|
192
|
+
width: 1rem;
|
|
148
193
|
}
|
|
149
194
|
.cMenuItemEnd {
|
|
150
195
|
justify-self: flex-end;
|
|
151
196
|
}
|
|
197
|
+
.cMenuLabel {
|
|
198
|
+
padding: 0.25rem 1rem;
|
|
199
|
+
font-size: 0.875rem;
|
|
200
|
+
color: var(--fgMuted);
|
|
201
|
+
}
|
|
152
202
|
.cMenuTrigger {
|
|
153
203
|
display: block;
|
|
154
204
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ContextMenuProps } from './types';
|
|
2
|
-
declare const ContextMenu: import("svelte").Component<ContextMenuProps, {
|
|
2
|
+
declare const ContextMenu: import("svelte").Component<ContextMenuProps, {
|
|
3
|
+
open: (e: MouseEvent) => Promise<void>;
|
|
4
|
+
close: () => void;
|
|
5
|
+
}, "">;
|
|
3
6
|
type ContextMenu = ReturnType<typeof ContextMenu>;
|
|
4
7
|
export default ContextMenu;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
export type ContextMenuItem = {
|
|
3
|
-
type?: 'divider';
|
|
3
|
+
type?: 'divider' | 'label';
|
|
4
4
|
label?: string;
|
|
5
5
|
href?: string;
|
|
6
6
|
onclick?: () => void;
|
|
7
7
|
end?: Snippet;
|
|
8
8
|
disabled?: boolean;
|
|
9
|
+
/** When defined, reserves a leading check slot; true renders a check mark */
|
|
10
|
+
selected?: boolean;
|
|
11
|
+
variant?: 'default' | 'danger';
|
|
9
12
|
};
|
|
10
13
|
export type ContextMenuProps = {
|
|
11
14
|
items: ContextMenuItem[];
|
|
12
|
-
|
|
15
|
+
/** Optional right-click target. When omitted, open the menu imperatively via open(event) */
|
|
16
|
+
trigger?: Snippet;
|
|
13
17
|
};
|
|
@@ -230,6 +230,16 @@
|
|
|
230
230
|
const target = e.target as HTMLElement;
|
|
231
231
|
const linkElement = target.closest('a');
|
|
232
232
|
|
|
233
|
+
if (!editable) {
|
|
234
|
+
const href = linkElement?.getAttribute('href');
|
|
235
|
+
if (href) {
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
e.stopPropagation();
|
|
238
|
+
window.open(href, '_blank', 'noopener,noreferrer');
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
233
243
|
if (linkElement && linkElement.classList.contains('editor-link')) {
|
|
234
244
|
e.preventDefault();
|
|
235
245
|
e.stopPropagation();
|
|
@@ -760,6 +770,9 @@
|
|
|
760
770
|
.editor__content a:hover {
|
|
761
771
|
text-decoration: underline;
|
|
762
772
|
}
|
|
773
|
+
.editor--notEdtiable .editor__content a {
|
|
774
|
+
pointer-events: auto;
|
|
775
|
+
}
|
|
763
776
|
.editor__content strong {
|
|
764
777
|
font-weight: 700;
|
|
765
778
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
Hover: 3
|
|
11
11
|
} as const;
|
|
12
12
|
type MarkerVisibility = (typeof MarkerVisibility)[keyof typeof MarkerVisibility];
|
|
13
|
-
import {
|
|
13
|
+
import { onDestroy } from 'svelte';
|
|
14
14
|
import { IconPin, IconPinFilled } from '@tabler/icons-svelte';
|
|
15
15
|
|
|
16
16
|
interface MarkerData {
|
|
@@ -202,30 +202,26 @@
|
|
|
202
202
|
}, 0);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
// Portal lives inside the stage container (not document.body) so tooltips stack
|
|
206
|
+
// below surrounding app chrome like the editor toolbar and side panes
|
|
205
207
|
function createPortalContainer() {
|
|
206
|
-
|
|
208
|
+
if (!containerElement) return;
|
|
209
|
+
const existingContainer = containerElement.querySelector<HTMLDivElement>(':scope > .markerTooltipPortal');
|
|
207
210
|
if (existingContainer) {
|
|
208
|
-
portalContainer = existingContainer
|
|
211
|
+
portalContainer = existingContainer;
|
|
209
212
|
return;
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
const container = document.createElement('div');
|
|
213
|
-
container.
|
|
216
|
+
container.className = 'markerTooltipPortal';
|
|
214
217
|
container.style.position = 'absolute';
|
|
215
|
-
container.style.
|
|
216
|
-
container.style.left = '0';
|
|
217
|
-
container.style.width = '0';
|
|
218
|
-
container.style.height = '0';
|
|
218
|
+
container.style.inset = '0';
|
|
219
219
|
container.style.pointerEvents = 'none';
|
|
220
220
|
container.style.zIndex = '1';
|
|
221
|
-
|
|
221
|
+
containerElement.appendChild(container);
|
|
222
222
|
portalContainer = container;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
onMount(() => {
|
|
226
|
-
createPortalContainer();
|
|
227
|
-
});
|
|
228
|
-
|
|
229
225
|
onDestroy(() => {
|
|
230
226
|
if (cleanup) {
|
|
231
227
|
cleanup();
|
|
@@ -241,13 +237,15 @@
|
|
|
241
237
|
}
|
|
242
238
|
|
|
243
239
|
if (portalContainer && portalContainer.childNodes.length === 0) {
|
|
244
|
-
|
|
245
|
-
document.body.removeChild(portalContainer);
|
|
246
|
-
}
|
|
240
|
+
portalContainer.remove();
|
|
247
241
|
}
|
|
248
242
|
});
|
|
249
243
|
|
|
250
244
|
$effect(() => {
|
|
245
|
+
if (containerElement && !portalContainer) {
|
|
246
|
+
createPortalContainer();
|
|
247
|
+
}
|
|
248
|
+
|
|
251
249
|
if (tooltipElement && position && containerElement && portalContainer) {
|
|
252
250
|
if (!portalContainer.contains(tooltipElement)) {
|
|
253
251
|
portalContainer.appendChild(tooltipElement);
|
|
@@ -310,13 +308,13 @@
|
|
|
310
308
|
const { x, y, placement } = await computePosition(virtualEl, tooltipElement!, {
|
|
311
309
|
placement: bestPlacement,
|
|
312
310
|
middleware,
|
|
313
|
-
strategy: '
|
|
311
|
+
strategy: 'absolute'
|
|
314
312
|
});
|
|
315
313
|
|
|
316
314
|
currentPlacement = placement.split('-')[0] as 'top' | 'bottom' | 'left' | 'right';
|
|
317
315
|
|
|
318
316
|
Object.assign(tooltipElement!.style, {
|
|
319
|
-
position: '
|
|
317
|
+
position: 'absolute',
|
|
320
318
|
left: `${x}px`,
|
|
321
319
|
top: `${y}px`,
|
|
322
320
|
pointerEvents: 'auto'
|
|
@@ -381,6 +379,7 @@
|
|
|
381
379
|
|
|
382
380
|
<style>
|
|
383
381
|
.markerTooltip {
|
|
382
|
+
width: max-content;
|
|
384
383
|
max-width: 400px;
|
|
385
384
|
background-color: var(--bg);
|
|
386
385
|
padding: 0.5rem 1rem;
|