svelte-comp 1.3.5 → 1.3.6
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/LICENSE.md +21 -21
- package/README.md +101 -101
- package/dist/App.svelte +1046 -1046
- package/dist/Container.svelte +59 -59
- package/dist/app.css +234 -234
- package/dist/app.d.ts +10 -10
- package/dist/lib/Accordion.svelte +155 -155
- package/dist/lib/Badge.svelte +44 -44
- package/dist/lib/Button.svelte +185 -185
- package/dist/lib/Calendar.svelte +384 -384
- package/dist/lib/Card.svelte +103 -103
- package/dist/lib/Carousel.svelte +293 -293
- package/dist/lib/CheckBox.svelte +210 -210
- package/dist/lib/CodeView.svelte +308 -308
- package/dist/lib/ColorPicker.svelte +159 -159
- package/dist/lib/ContextMenu.svelte +328 -328
- package/dist/lib/DatePicker.svelte +246 -246
- package/dist/lib/Dialog.svelte +233 -233
- package/dist/lib/Field.svelte +299 -299
- package/dist/lib/FilePicker.svelte +295 -295
- package/dist/lib/Form.svelte +438 -438
- package/dist/lib/Hamburger.svelte +217 -217
- package/dist/lib/InstallPWA.svelte +94 -94
- package/dist/lib/Menu.svelte +623 -623
- package/dist/lib/NoticeBase.svelte +140 -140
- package/dist/lib/PaginatedCard.svelte +73 -73
- package/dist/lib/Pagination.svelte +119 -119
- package/dist/lib/PrimaryColorSelect.svelte +111 -111
- package/dist/lib/ProgressBar.svelte +141 -141
- package/dist/lib/ProgressCircle.svelte +190 -190
- package/dist/lib/Radio.svelte +189 -189
- package/dist/lib/SearchInput.svelte +104 -104
- package/dist/lib/Select.svelte +524 -524
- package/dist/lib/Slider.svelte +253 -253
- package/dist/lib/Splitter.svelte +159 -159
- package/dist/lib/Switch.svelte +168 -168
- package/dist/lib/Table.svelte +299 -299
- package/dist/lib/Tabs.svelte +213 -213
- package/dist/lib/ThemeToggle.svelte +128 -128
- package/dist/lib/TimePicker.svelte +312 -312
- package/dist/lib/TimePickerNew.svelte +634 -634
- package/dist/lib/Toast.svelte +123 -123
- package/dist/lib/Tooltip.svelte +110 -110
- package/dist/lib/Topbar.svelte +112 -112
- package/dist/styles.css +234 -234
- package/package.json +52 -52
|
@@ -1,328 +1,328 @@
|
|
|
1
|
-
<!-- src/lib/ContextMenu.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
/**
|
|
4
|
-
* @component ContextMenu
|
|
5
|
-
* @description Right-click context menu for editor actions.
|
|
6
|
-
*
|
|
7
|
-
* @prop onUndo {() => void} - Fired when Undo is selected
|
|
8
|
-
* @prop onRedo {() => void} - Fired when Redo is selected
|
|
9
|
-
* @prop onCopy {() => void} - Fired when Copy is selected
|
|
10
|
-
* @prop onCut {() => void} - Fired when Cut is selected
|
|
11
|
-
* @prop onPaste {() => void} - Fired when Paste is selected
|
|
12
|
-
* @prop onDelete {() => void} - Fired when Delete is selected
|
|
13
|
-
*
|
|
14
|
-
* @note Call `openAt(event)` to show the menu at the pointer.
|
|
15
|
-
* @note Uses lang-context for localization.
|
|
16
|
-
*/
|
|
17
|
-
import {
|
|
18
|
-
getComponentText,
|
|
19
|
-
getLangContext,
|
|
20
|
-
getLangKey,
|
|
21
|
-
} from "./lang-context";
|
|
22
|
-
|
|
23
|
-
interface Props {
|
|
24
|
-
onUndo?: () => void;
|
|
25
|
-
onRedo?: () => void;
|
|
26
|
-
onCopy?: () => void;
|
|
27
|
-
onCut?: () => void;
|
|
28
|
-
onPaste?: () => void;
|
|
29
|
-
onDelete?: () => void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let {
|
|
33
|
-
onUndo = () => {},
|
|
34
|
-
onRedo = () => {},
|
|
35
|
-
onCopy = () => {},
|
|
36
|
-
onCut = () => {},
|
|
37
|
-
onPaste = () => {},
|
|
38
|
-
onDelete = () => {},
|
|
39
|
-
}: Props = $props();
|
|
40
|
-
const langCtx = getLangContext();
|
|
41
|
-
const langKey = $derived(getLangKey(langCtx));
|
|
42
|
-
const L = $derived(getComponentText("contextMenu", langKey));
|
|
43
|
-
|
|
44
|
-
let visible = $state(false);
|
|
45
|
-
let x = $state(0);
|
|
46
|
-
let y = $state(0);
|
|
47
|
-
|
|
48
|
-
function clampToViewport(): void {
|
|
49
|
-
requestAnimationFrame(() => {
|
|
50
|
-
const menu = document.getElementById("ctx-menu");
|
|
51
|
-
if (!menu) return;
|
|
52
|
-
const rect = menu.getBoundingClientRect();
|
|
53
|
-
const pad = 8;
|
|
54
|
-
let nextX = x;
|
|
55
|
-
let nextY = y;
|
|
56
|
-
if (rect.right > window.innerWidth - pad) {
|
|
57
|
-
nextX = Math.max(
|
|
58
|
-
pad,
|
|
59
|
-
x - (rect.right - (window.innerWidth - pad))
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (rect.bottom > window.innerHeight - pad) {
|
|
63
|
-
nextY = Math.max(
|
|
64
|
-
pad,
|
|
65
|
-
y - (rect.bottom - (window.innerHeight - pad))
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
if (nextX !== x) x = nextX;
|
|
69
|
-
if (nextY !== y) y = nextY;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function openAt(event: MouseEvent): void {
|
|
74
|
-
event?.preventDefault?.();
|
|
75
|
-
const hasClient =
|
|
76
|
-
Number.isFinite(event?.clientX) && Number.isFinite(event?.clientY);
|
|
77
|
-
const hasPage =
|
|
78
|
-
Number.isFinite(event?.pageX) && Number.isFinite(event?.pageY);
|
|
79
|
-
if (hasClient && (event.clientX !== 0 || event.clientY !== 0)) {
|
|
80
|
-
x = event.clientX;
|
|
81
|
-
y = event.clientY;
|
|
82
|
-
} else if (hasPage) {
|
|
83
|
-
x = event.pageX - window.scrollX;
|
|
84
|
-
y = event.pageY - window.scrollY;
|
|
85
|
-
} else {
|
|
86
|
-
x = 0;
|
|
87
|
-
y = 0;
|
|
88
|
-
}
|
|
89
|
-
visible = true;
|
|
90
|
-
clampToViewport();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function close(): void {
|
|
94
|
-
visible = false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function handleDocClick(e: MouseEvent): void {
|
|
98
|
-
if (!visible) return;
|
|
99
|
-
const menu = document.getElementById("ctx-menu");
|
|
100
|
-
if (!menu) return;
|
|
101
|
-
if (!menu.contains(e.target as Node)) close();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function handleEsc(e: KeyboardEvent): void {
|
|
105
|
-
if (e.key === "Escape" && visible) close();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
$effect(() => {
|
|
109
|
-
document.addEventListener("click", handleDocClick);
|
|
110
|
-
document.addEventListener("keydown", handleEsc);
|
|
111
|
-
return () => {
|
|
112
|
-
document.removeEventListener("click", handleDocClick);
|
|
113
|
-
document.removeEventListener("keydown", handleEsc);
|
|
114
|
-
};
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const doUndo = () => (onUndo(), close());
|
|
118
|
-
const doRedo = () => (onRedo(), close());
|
|
119
|
-
const doCopy = () => (onCopy(), close());
|
|
120
|
-
const doCut = () => (onCut(), close());
|
|
121
|
-
const doPaste = () => (onPaste(), close());
|
|
122
|
-
const doDelete = () => (onDelete(), close());
|
|
123
|
-
|
|
124
|
-
const menuPanelClass =
|
|
125
|
-
"fixed bg-[var(--color-bg-surface)] border border-[var(--border-color-default)] rounded-[var(--radius-md)] min-w-[160px] max-w-[260px] py-[var(--spacing-xs)] z-[9999] box-border text-[var(--text-sm)] shadow-[0_2px_4px_var(--shadow-color)] font-[var(--font-sans)] text-[var(--color-text-default)] m-0 scale-90 origin-top-left";
|
|
126
|
-
const itemClass =
|
|
127
|
-
"w-full flex items-center justify-between bg-transparent border-0 text-[var(--color-text-default)] px-[calc(var(--spacing-sm)+var(--spacing-xs))] py-[var(--spacing-sm)] m-0 font-inherit cursor-pointer rounded-[var(--radius-sm)] whitespace-nowrap leading-[var(--line-height-normal)] gap-[calc(var(--spacing-sm)+var(--spacing-xs))] outline-none shadow-none relative hover:bg-[var(--color-bg-hover)] hover:text-[var(--color-text-default)] active:bg-[color-mix(in_srgb,var(--color-primary)_12%,var(--color-bg-hover)_88%)] active:text-[var(--color-text-default)] transition-colors duration-[var(--transition-fast)]";
|
|
128
|
-
const itemContentClass = "flex items-center gap-[calc(var(--spacing-sm)+var(--spacing-xs)/2)]";
|
|
129
|
-
</script>
|
|
130
|
-
|
|
131
|
-
{#if visible}
|
|
132
|
-
<div
|
|
133
|
-
id="ctx-menu"
|
|
134
|
-
class={menuPanelClass}
|
|
135
|
-
style="top: {y}px; left: {x}px;"
|
|
136
|
-
role="menu"
|
|
137
|
-
tabindex="-1"
|
|
138
|
-
>
|
|
139
|
-
<button
|
|
140
|
-
class={itemClass}
|
|
141
|
-
onclick={(e) => {
|
|
142
|
-
e.stopPropagation();
|
|
143
|
-
doUndo();
|
|
144
|
-
}}
|
|
145
|
-
title={L.hotkeys.undo}
|
|
146
|
-
>
|
|
147
|
-
<div class={itemContentClass}>
|
|
148
|
-
<svg
|
|
149
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
150
|
-
width="24"
|
|
151
|
-
height="24"
|
|
152
|
-
viewBox="0 0 24 24"
|
|
153
|
-
fill="none"
|
|
154
|
-
stroke="currentColor"
|
|
155
|
-
stroke-width="2"
|
|
156
|
-
stroke-linecap="round"
|
|
157
|
-
stroke-linejoin="round"
|
|
158
|
-
class="w-4 h-4 opacity-80"
|
|
159
|
-
aria-hidden="true"
|
|
160
|
-
>
|
|
161
|
-
<path d="M3 7v6h6" />
|
|
162
|
-
<path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" />
|
|
163
|
-
</svg>
|
|
164
|
-
<span>{L.contextMenu.undo.replace(/↩️\s*/, "")}</span>
|
|
165
|
-
</div>
|
|
166
|
-
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.undo}</span>
|
|
167
|
-
</button>
|
|
168
|
-
|
|
169
|
-
<button
|
|
170
|
-
class={itemClass}
|
|
171
|
-
onclick={(e) => {
|
|
172
|
-
e.stopPropagation();
|
|
173
|
-
doRedo();
|
|
174
|
-
}}
|
|
175
|
-
title={L.hotkeys.redo}
|
|
176
|
-
>
|
|
177
|
-
<div class={itemContentClass}>
|
|
178
|
-
<svg
|
|
179
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
180
|
-
width="24"
|
|
181
|
-
height="24"
|
|
182
|
-
viewBox="0 0 24 24"
|
|
183
|
-
fill="none"
|
|
184
|
-
stroke="currentColor"
|
|
185
|
-
stroke-width="2"
|
|
186
|
-
stroke-linecap="round"
|
|
187
|
-
stroke-linejoin="round"
|
|
188
|
-
class="w-4 h-4 opacity-80"
|
|
189
|
-
aria-hidden="true"
|
|
190
|
-
>
|
|
191
|
-
<path d="M21 7v6h-6" />
|
|
192
|
-
<path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" />
|
|
193
|
-
</svg>
|
|
194
|
-
<span>{L.contextMenu.redo.replace(/↪️\s*/, "")}</span>
|
|
195
|
-
</div>
|
|
196
|
-
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.redo}</span>
|
|
197
|
-
</button>
|
|
198
|
-
|
|
199
|
-
<button
|
|
200
|
-
class={itemClass}
|
|
201
|
-
onclick={(e) => {
|
|
202
|
-
e.stopPropagation();
|
|
203
|
-
doCopy();
|
|
204
|
-
}}
|
|
205
|
-
title={L.hotkeys.copy}
|
|
206
|
-
>
|
|
207
|
-
<div class={itemContentClass}>
|
|
208
|
-
<svg
|
|
209
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
210
|
-
width="24"
|
|
211
|
-
height="24"
|
|
212
|
-
viewBox="0 0 24 24"
|
|
213
|
-
fill="none"
|
|
214
|
-
stroke="currentColor"
|
|
215
|
-
stroke-width="2"
|
|
216
|
-
stroke-linecap="round"
|
|
217
|
-
stroke-linejoin="round"
|
|
218
|
-
class="w-4 h-4 opacity-80"
|
|
219
|
-
aria-hidden="true"
|
|
220
|
-
>
|
|
221
|
-
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
|
|
222
|
-
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
|
|
223
|
-
</svg>
|
|
224
|
-
<span>{L.contextMenu.copy.replace(/📑\s*/, "")}</span>
|
|
225
|
-
</div>
|
|
226
|
-
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.copy}</span>
|
|
227
|
-
</button>
|
|
228
|
-
|
|
229
|
-
<button
|
|
230
|
-
class={itemClass}
|
|
231
|
-
onclick={(e) => {
|
|
232
|
-
e.stopPropagation();
|
|
233
|
-
doCut();
|
|
234
|
-
}}
|
|
235
|
-
title={L.hotkeys.cut}
|
|
236
|
-
>
|
|
237
|
-
<div class={itemContentClass}>
|
|
238
|
-
<svg
|
|
239
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
240
|
-
width="24"
|
|
241
|
-
height="24"
|
|
242
|
-
viewBox="0 0 24 24"
|
|
243
|
-
fill="none"
|
|
244
|
-
stroke="currentColor"
|
|
245
|
-
stroke-width="2"
|
|
246
|
-
stroke-linecap="round"
|
|
247
|
-
stroke-linejoin="round"
|
|
248
|
-
class="w-4 h-4 opacity-80"
|
|
249
|
-
aria-hidden="true"
|
|
250
|
-
>
|
|
251
|
-
<circle cx="6" cy="6" r="3" />
|
|
252
|
-
<path d="M8.12 8.12 12 12" />
|
|
253
|
-
<path d="M20 4 8.12 15.88" />
|
|
254
|
-
<circle cx="6" cy="18" r="3" />
|
|
255
|
-
<path d="M14.8 14.8 20 20" />
|
|
256
|
-
</svg>
|
|
257
|
-
<span>{L.contextMenu.cut.replace(/✂️\s*/, "")}</span>
|
|
258
|
-
</div>
|
|
259
|
-
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.cut}</span>
|
|
260
|
-
</button>
|
|
261
|
-
|
|
262
|
-
<button
|
|
263
|
-
class={itemClass}
|
|
264
|
-
onclick={(e) => {
|
|
265
|
-
e.stopPropagation();
|
|
266
|
-
doPaste();
|
|
267
|
-
}}
|
|
268
|
-
title={L.hotkeys.paste}
|
|
269
|
-
>
|
|
270
|
-
<div class={itemContentClass}>
|
|
271
|
-
<svg
|
|
272
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
273
|
-
width="24"
|
|
274
|
-
height="24"
|
|
275
|
-
viewBox="0 0 24 24"
|
|
276
|
-
fill="none"
|
|
277
|
-
stroke="currentColor"
|
|
278
|
-
stroke-width="2"
|
|
279
|
-
stroke-linecap="round"
|
|
280
|
-
stroke-linejoin="round"
|
|
281
|
-
class="w-4 h-4 opacity-80"
|
|
282
|
-
aria-hidden="true"
|
|
283
|
-
>
|
|
284
|
-
<path d="M11 14h10" />
|
|
285
|
-
<path d="M16 4h2a2 2 0 0 1 2 2v1.344" />
|
|
286
|
-
<path d="m17 18 4-4-4-4" />
|
|
287
|
-
<path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113" />
|
|
288
|
-
<rect x="8" y="2" width="8" height="4" rx="1" />
|
|
289
|
-
</svg>
|
|
290
|
-
<span>{L.contextMenu.paste.replace(/📋\s*/, "")}</span>
|
|
291
|
-
</div>
|
|
292
|
-
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.paste}</span>
|
|
293
|
-
</button>
|
|
294
|
-
|
|
295
|
-
<button
|
|
296
|
-
class={itemClass}
|
|
297
|
-
onclick={(e) => {
|
|
298
|
-
e.stopPropagation();
|
|
299
|
-
doDelete();
|
|
300
|
-
}}
|
|
301
|
-
title={L.hotkeys.delete}
|
|
302
|
-
>
|
|
303
|
-
<div class={itemContentClass}>
|
|
304
|
-
<svg
|
|
305
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
306
|
-
width="24"
|
|
307
|
-
height="24"
|
|
308
|
-
viewBox="0 0 24 24"
|
|
309
|
-
fill="none"
|
|
310
|
-
stroke="currentColor"
|
|
311
|
-
stroke-width="2"
|
|
312
|
-
stroke-linecap="round"
|
|
313
|
-
stroke-linejoin="round"
|
|
314
|
-
class="w-4 h-4 opacity-80"
|
|
315
|
-
aria-hidden="true"
|
|
316
|
-
>
|
|
317
|
-
<path d="M10 11v6" />
|
|
318
|
-
<path d="M14 11v6" />
|
|
319
|
-
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
|
|
320
|
-
<path d="M3 6h18" />
|
|
321
|
-
<path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
|
322
|
-
</svg>
|
|
323
|
-
<span>{L.contextMenu.delete}</span>
|
|
324
|
-
</div>
|
|
325
|
-
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.delete}</span>
|
|
326
|
-
</button>
|
|
327
|
-
</div>
|
|
328
|
-
{/if}
|
|
1
|
+
<!-- src/lib/ContextMenu.svelte -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
/**
|
|
4
|
+
* @component ContextMenu
|
|
5
|
+
* @description Right-click context menu for editor actions.
|
|
6
|
+
*
|
|
7
|
+
* @prop onUndo {() => void} - Fired when Undo is selected
|
|
8
|
+
* @prop onRedo {() => void} - Fired when Redo is selected
|
|
9
|
+
* @prop onCopy {() => void} - Fired when Copy is selected
|
|
10
|
+
* @prop onCut {() => void} - Fired when Cut is selected
|
|
11
|
+
* @prop onPaste {() => void} - Fired when Paste is selected
|
|
12
|
+
* @prop onDelete {() => void} - Fired when Delete is selected
|
|
13
|
+
*
|
|
14
|
+
* @note Call `openAt(event)` to show the menu at the pointer.
|
|
15
|
+
* @note Uses lang-context for localization.
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
getComponentText,
|
|
19
|
+
getLangContext,
|
|
20
|
+
getLangKey,
|
|
21
|
+
} from "./lang-context";
|
|
22
|
+
|
|
23
|
+
interface Props {
|
|
24
|
+
onUndo?: () => void;
|
|
25
|
+
onRedo?: () => void;
|
|
26
|
+
onCopy?: () => void;
|
|
27
|
+
onCut?: () => void;
|
|
28
|
+
onPaste?: () => void;
|
|
29
|
+
onDelete?: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let {
|
|
33
|
+
onUndo = () => {},
|
|
34
|
+
onRedo = () => {},
|
|
35
|
+
onCopy = () => {},
|
|
36
|
+
onCut = () => {},
|
|
37
|
+
onPaste = () => {},
|
|
38
|
+
onDelete = () => {},
|
|
39
|
+
}: Props = $props();
|
|
40
|
+
const langCtx = getLangContext();
|
|
41
|
+
const langKey = $derived(getLangKey(langCtx));
|
|
42
|
+
const L = $derived(getComponentText("contextMenu", langKey));
|
|
43
|
+
|
|
44
|
+
let visible = $state(false);
|
|
45
|
+
let x = $state(0);
|
|
46
|
+
let y = $state(0);
|
|
47
|
+
|
|
48
|
+
function clampToViewport(): void {
|
|
49
|
+
requestAnimationFrame(() => {
|
|
50
|
+
const menu = document.getElementById("ctx-menu");
|
|
51
|
+
if (!menu) return;
|
|
52
|
+
const rect = menu.getBoundingClientRect();
|
|
53
|
+
const pad = 8;
|
|
54
|
+
let nextX = x;
|
|
55
|
+
let nextY = y;
|
|
56
|
+
if (rect.right > window.innerWidth - pad) {
|
|
57
|
+
nextX = Math.max(
|
|
58
|
+
pad,
|
|
59
|
+
x - (rect.right - (window.innerWidth - pad))
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (rect.bottom > window.innerHeight - pad) {
|
|
63
|
+
nextY = Math.max(
|
|
64
|
+
pad,
|
|
65
|
+
y - (rect.bottom - (window.innerHeight - pad))
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (nextX !== x) x = nextX;
|
|
69
|
+
if (nextY !== y) y = nextY;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function openAt(event: MouseEvent): void {
|
|
74
|
+
event?.preventDefault?.();
|
|
75
|
+
const hasClient =
|
|
76
|
+
Number.isFinite(event?.clientX) && Number.isFinite(event?.clientY);
|
|
77
|
+
const hasPage =
|
|
78
|
+
Number.isFinite(event?.pageX) && Number.isFinite(event?.pageY);
|
|
79
|
+
if (hasClient && (event.clientX !== 0 || event.clientY !== 0)) {
|
|
80
|
+
x = event.clientX;
|
|
81
|
+
y = event.clientY;
|
|
82
|
+
} else if (hasPage) {
|
|
83
|
+
x = event.pageX - window.scrollX;
|
|
84
|
+
y = event.pageY - window.scrollY;
|
|
85
|
+
} else {
|
|
86
|
+
x = 0;
|
|
87
|
+
y = 0;
|
|
88
|
+
}
|
|
89
|
+
visible = true;
|
|
90
|
+
clampToViewport();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function close(): void {
|
|
94
|
+
visible = false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function handleDocClick(e: MouseEvent): void {
|
|
98
|
+
if (!visible) return;
|
|
99
|
+
const menu = document.getElementById("ctx-menu");
|
|
100
|
+
if (!menu) return;
|
|
101
|
+
if (!menu.contains(e.target as Node)) close();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function handleEsc(e: KeyboardEvent): void {
|
|
105
|
+
if (e.key === "Escape" && visible) close();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
$effect(() => {
|
|
109
|
+
document.addEventListener("click", handleDocClick);
|
|
110
|
+
document.addEventListener("keydown", handleEsc);
|
|
111
|
+
return () => {
|
|
112
|
+
document.removeEventListener("click", handleDocClick);
|
|
113
|
+
document.removeEventListener("keydown", handleEsc);
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const doUndo = () => (onUndo(), close());
|
|
118
|
+
const doRedo = () => (onRedo(), close());
|
|
119
|
+
const doCopy = () => (onCopy(), close());
|
|
120
|
+
const doCut = () => (onCut(), close());
|
|
121
|
+
const doPaste = () => (onPaste(), close());
|
|
122
|
+
const doDelete = () => (onDelete(), close());
|
|
123
|
+
|
|
124
|
+
const menuPanelClass =
|
|
125
|
+
"fixed bg-[var(--color-bg-surface)] border border-[var(--border-color-default)] rounded-[var(--radius-md)] min-w-[160px] max-w-[260px] py-[var(--spacing-xs)] z-[9999] box-border text-[var(--text-sm)] shadow-[0_2px_4px_var(--shadow-color)] font-[var(--font-sans)] text-[var(--color-text-default)] m-0 scale-90 origin-top-left";
|
|
126
|
+
const itemClass =
|
|
127
|
+
"w-full flex items-center justify-between bg-transparent border-0 text-[var(--color-text-default)] px-[calc(var(--spacing-sm)+var(--spacing-xs))] py-[var(--spacing-sm)] m-0 font-inherit cursor-pointer rounded-[var(--radius-sm)] whitespace-nowrap leading-[var(--line-height-normal)] gap-[calc(var(--spacing-sm)+var(--spacing-xs))] outline-none shadow-none relative hover:bg-[var(--color-bg-hover)] hover:text-[var(--color-text-default)] active:bg-[color-mix(in_srgb,var(--color-primary)_12%,var(--color-bg-hover)_88%)] active:text-[var(--color-text-default)] transition-colors duration-[var(--transition-fast)]";
|
|
128
|
+
const itemContentClass = "flex items-center gap-[calc(var(--spacing-sm)+var(--spacing-xs)/2)]";
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
{#if visible}
|
|
132
|
+
<div
|
|
133
|
+
id="ctx-menu"
|
|
134
|
+
class={menuPanelClass}
|
|
135
|
+
style="top: {y}px; left: {x}px;"
|
|
136
|
+
role="menu"
|
|
137
|
+
tabindex="-1"
|
|
138
|
+
>
|
|
139
|
+
<button
|
|
140
|
+
class={itemClass}
|
|
141
|
+
onclick={(e) => {
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
doUndo();
|
|
144
|
+
}}
|
|
145
|
+
title={L.hotkeys.undo}
|
|
146
|
+
>
|
|
147
|
+
<div class={itemContentClass}>
|
|
148
|
+
<svg
|
|
149
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
150
|
+
width="24"
|
|
151
|
+
height="24"
|
|
152
|
+
viewBox="0 0 24 24"
|
|
153
|
+
fill="none"
|
|
154
|
+
stroke="currentColor"
|
|
155
|
+
stroke-width="2"
|
|
156
|
+
stroke-linecap="round"
|
|
157
|
+
stroke-linejoin="round"
|
|
158
|
+
class="w-4 h-4 opacity-80"
|
|
159
|
+
aria-hidden="true"
|
|
160
|
+
>
|
|
161
|
+
<path d="M3 7v6h6" />
|
|
162
|
+
<path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" />
|
|
163
|
+
</svg>
|
|
164
|
+
<span>{L.contextMenu.undo.replace(/↩️\s*/, "")}</span>
|
|
165
|
+
</div>
|
|
166
|
+
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.undo}</span>
|
|
167
|
+
</button>
|
|
168
|
+
|
|
169
|
+
<button
|
|
170
|
+
class={itemClass}
|
|
171
|
+
onclick={(e) => {
|
|
172
|
+
e.stopPropagation();
|
|
173
|
+
doRedo();
|
|
174
|
+
}}
|
|
175
|
+
title={L.hotkeys.redo}
|
|
176
|
+
>
|
|
177
|
+
<div class={itemContentClass}>
|
|
178
|
+
<svg
|
|
179
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
180
|
+
width="24"
|
|
181
|
+
height="24"
|
|
182
|
+
viewBox="0 0 24 24"
|
|
183
|
+
fill="none"
|
|
184
|
+
stroke="currentColor"
|
|
185
|
+
stroke-width="2"
|
|
186
|
+
stroke-linecap="round"
|
|
187
|
+
stroke-linejoin="round"
|
|
188
|
+
class="w-4 h-4 opacity-80"
|
|
189
|
+
aria-hidden="true"
|
|
190
|
+
>
|
|
191
|
+
<path d="M21 7v6h-6" />
|
|
192
|
+
<path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" />
|
|
193
|
+
</svg>
|
|
194
|
+
<span>{L.contextMenu.redo.replace(/↪️\s*/, "")}</span>
|
|
195
|
+
</div>
|
|
196
|
+
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.redo}</span>
|
|
197
|
+
</button>
|
|
198
|
+
|
|
199
|
+
<button
|
|
200
|
+
class={itemClass}
|
|
201
|
+
onclick={(e) => {
|
|
202
|
+
e.stopPropagation();
|
|
203
|
+
doCopy();
|
|
204
|
+
}}
|
|
205
|
+
title={L.hotkeys.copy}
|
|
206
|
+
>
|
|
207
|
+
<div class={itemContentClass}>
|
|
208
|
+
<svg
|
|
209
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
210
|
+
width="24"
|
|
211
|
+
height="24"
|
|
212
|
+
viewBox="0 0 24 24"
|
|
213
|
+
fill="none"
|
|
214
|
+
stroke="currentColor"
|
|
215
|
+
stroke-width="2"
|
|
216
|
+
stroke-linecap="round"
|
|
217
|
+
stroke-linejoin="round"
|
|
218
|
+
class="w-4 h-4 opacity-80"
|
|
219
|
+
aria-hidden="true"
|
|
220
|
+
>
|
|
221
|
+
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
|
|
222
|
+
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
|
|
223
|
+
</svg>
|
|
224
|
+
<span>{L.contextMenu.copy.replace(/📑\s*/, "")}</span>
|
|
225
|
+
</div>
|
|
226
|
+
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.copy}</span>
|
|
227
|
+
</button>
|
|
228
|
+
|
|
229
|
+
<button
|
|
230
|
+
class={itemClass}
|
|
231
|
+
onclick={(e) => {
|
|
232
|
+
e.stopPropagation();
|
|
233
|
+
doCut();
|
|
234
|
+
}}
|
|
235
|
+
title={L.hotkeys.cut}
|
|
236
|
+
>
|
|
237
|
+
<div class={itemContentClass}>
|
|
238
|
+
<svg
|
|
239
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
240
|
+
width="24"
|
|
241
|
+
height="24"
|
|
242
|
+
viewBox="0 0 24 24"
|
|
243
|
+
fill="none"
|
|
244
|
+
stroke="currentColor"
|
|
245
|
+
stroke-width="2"
|
|
246
|
+
stroke-linecap="round"
|
|
247
|
+
stroke-linejoin="round"
|
|
248
|
+
class="w-4 h-4 opacity-80"
|
|
249
|
+
aria-hidden="true"
|
|
250
|
+
>
|
|
251
|
+
<circle cx="6" cy="6" r="3" />
|
|
252
|
+
<path d="M8.12 8.12 12 12" />
|
|
253
|
+
<path d="M20 4 8.12 15.88" />
|
|
254
|
+
<circle cx="6" cy="18" r="3" />
|
|
255
|
+
<path d="M14.8 14.8 20 20" />
|
|
256
|
+
</svg>
|
|
257
|
+
<span>{L.contextMenu.cut.replace(/✂️\s*/, "")}</span>
|
|
258
|
+
</div>
|
|
259
|
+
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.cut}</span>
|
|
260
|
+
</button>
|
|
261
|
+
|
|
262
|
+
<button
|
|
263
|
+
class={itemClass}
|
|
264
|
+
onclick={(e) => {
|
|
265
|
+
e.stopPropagation();
|
|
266
|
+
doPaste();
|
|
267
|
+
}}
|
|
268
|
+
title={L.hotkeys.paste}
|
|
269
|
+
>
|
|
270
|
+
<div class={itemContentClass}>
|
|
271
|
+
<svg
|
|
272
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
273
|
+
width="24"
|
|
274
|
+
height="24"
|
|
275
|
+
viewBox="0 0 24 24"
|
|
276
|
+
fill="none"
|
|
277
|
+
stroke="currentColor"
|
|
278
|
+
stroke-width="2"
|
|
279
|
+
stroke-linecap="round"
|
|
280
|
+
stroke-linejoin="round"
|
|
281
|
+
class="w-4 h-4 opacity-80"
|
|
282
|
+
aria-hidden="true"
|
|
283
|
+
>
|
|
284
|
+
<path d="M11 14h10" />
|
|
285
|
+
<path d="M16 4h2a2 2 0 0 1 2 2v1.344" />
|
|
286
|
+
<path d="m17 18 4-4-4-4" />
|
|
287
|
+
<path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113" />
|
|
288
|
+
<rect x="8" y="2" width="8" height="4" rx="1" />
|
|
289
|
+
</svg>
|
|
290
|
+
<span>{L.contextMenu.paste.replace(/📋\s*/, "")}</span>
|
|
291
|
+
</div>
|
|
292
|
+
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.paste}</span>
|
|
293
|
+
</button>
|
|
294
|
+
|
|
295
|
+
<button
|
|
296
|
+
class={itemClass}
|
|
297
|
+
onclick={(e) => {
|
|
298
|
+
e.stopPropagation();
|
|
299
|
+
doDelete();
|
|
300
|
+
}}
|
|
301
|
+
title={L.hotkeys.delete}
|
|
302
|
+
>
|
|
303
|
+
<div class={itemContentClass}>
|
|
304
|
+
<svg
|
|
305
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
306
|
+
width="24"
|
|
307
|
+
height="24"
|
|
308
|
+
viewBox="0 0 24 24"
|
|
309
|
+
fill="none"
|
|
310
|
+
stroke="currentColor"
|
|
311
|
+
stroke-width="2"
|
|
312
|
+
stroke-linecap="round"
|
|
313
|
+
stroke-linejoin="round"
|
|
314
|
+
class="w-4 h-4 opacity-80"
|
|
315
|
+
aria-hidden="true"
|
|
316
|
+
>
|
|
317
|
+
<path d="M10 11v6" />
|
|
318
|
+
<path d="M14 11v6" />
|
|
319
|
+
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
|
|
320
|
+
<path d="M3 6h18" />
|
|
321
|
+
<path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
|
322
|
+
</svg>
|
|
323
|
+
<span>{L.contextMenu.delete}</span>
|
|
324
|
+
</div>
|
|
325
|
+
<span class="text-[var(--color-text-muted)] text-[0.7rem]">{L.hotkeys.delete}</span>
|
|
326
|
+
</button>
|
|
327
|
+
</div>
|
|
328
|
+
{/if}
|