sinwan-ui-core 1.5.1 → 2.0.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/CHANGELOG.md +52 -0
- package/README.md +29 -1
- package/agents/internal/llms.controlled.txt +39 -0
- package/agents/internal/llms.form.txt +43 -0
- package/agents/internal/llms.ids.txt +46 -0
- package/agents/internal/llms.modal.txt +51 -0
- package/agents/llms.controls.txt +82 -0
- package/agents/llms.core.txt +73 -0
- package/agents/llms.direction.txt +51 -0
- package/agents/llms.dismiss.txt +79 -0
- package/agents/llms.floating.txt +47 -0
- package/agents/llms.index.txt +46 -0
- package/agents/llms.menu-sub.txt +66 -0
- package/agents/llms.menu.txt +94 -0
- package/agents/llms.overlay.txt +122 -0
- package/agents/llms.sinwan-preload.txt +33 -0
- package/agents/llms.slot.txt +51 -0
- package/agents/llms.theme.txt +59 -0
- package/agents/llms.txt +45 -0
- package/agents/llms.types.txt +39 -0
- package/dist/chunks/chunk-7c8ct63g.js +126 -0
- package/dist/chunks/{chunk-16d43dkc.js → chunk-assqp8wg.js} +86 -13
- package/dist/chunks/{chunk-saen52f0.js → chunk-eczk2z48.js} +26 -14
- package/dist/chunks/{chunk-f6hw8ash.js → chunk-fe933s8d.js} +2 -2
- package/dist/chunks/chunk-rxbeqj7g.js +65 -0
- package/dist/chunks/{chunk-0dsacv44.js → chunk-s84my297.js} +124 -27
- package/dist/chunks/{chunk-6bm550r5.js → chunk-w6wwgdg6.js} +205 -46
- package/dist/chunks/{chunk-bw9vp0y9.js → chunk-wjzadrvr.js} +54 -0
- package/dist/chunks/{chunk-zmvg5gy1.js → chunk-y1ag4hk4.js} +57 -9
- package/dist/controls.d.ts +4 -0
- package/dist/controls.js +4 -4
- package/dist/core.d.ts +8 -0
- package/dist/core.js +4 -2
- package/dist/direction.d.ts +7 -1
- package/dist/direction.js +1 -1
- package/dist/dismiss.d.ts +18 -0
- package/dist/dismiss.js +9 -3
- package/dist/floating.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +54 -26
- package/dist/internal/controlled.d.ts +1 -0
- package/dist/internal/form.d.ts +6 -0
- package/dist/internal/ids.d.ts +8 -0
- package/dist/internal/modal.d.ts +8 -0
- package/dist/menu-sub.d.ts +10 -2
- package/dist/menu-sub.js +3 -2
- package/dist/menu.d.ts +66 -0
- package/dist/menu.js +16 -0
- package/dist/overlay.d.ts +27 -2
- package/dist/overlay.js +6 -4
- package/dist/slot.d.ts +1 -0
- package/dist/slot.js +1 -1
- package/dist/theme.d.ts +30 -2
- package/dist/theme.js +5 -1
- package/dist/types.d.ts +1 -0
- package/package.json +16 -7
- package/dist/chunks/chunk-9whagkb6.js +0 -31
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Slot2
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-wjzadrvr.js";
|
|
4
4
|
import {
|
|
5
5
|
isControlledProp,
|
|
6
|
+
treeId,
|
|
6
7
|
Presence2,
|
|
7
8
|
UiPortal2,
|
|
8
9
|
trapFocus2
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-eczk2z48.js";
|
|
10
11
|
import {
|
|
11
12
|
useAnchorPosition2
|
|
12
13
|
} from "./chunk-6r59k5mb.js";
|
|
13
14
|
import {
|
|
14
|
-
isDismissExemptPointerTarget2
|
|
15
|
-
|
|
15
|
+
isDismissExemptPointerTarget2,
|
|
16
|
+
useDismissLayer2
|
|
17
|
+
} from "./chunk-rxbeqj7g.js";
|
|
16
18
|
|
|
17
19
|
// src/overlay.tsx
|
|
18
20
|
import { _$createTemplate } from "sinwan/renderer/web";
|
|
@@ -27,12 +29,77 @@ import {
|
|
|
27
29
|
createLiveRest as _$createLiveRest,
|
|
28
30
|
getSpreadProps as _$getSpreadProps
|
|
29
31
|
} from "sinwan/component";
|
|
30
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
computed,
|
|
34
|
+
effect,
|
|
35
|
+
signal,
|
|
36
|
+
untrack
|
|
37
|
+
} from "sinwan/reactivity";
|
|
38
|
+
|
|
39
|
+
// src/internal/modal.ts
|
|
40
|
+
var lockCount = 0;
|
|
41
|
+
var savedOverflow = "";
|
|
42
|
+
var savedPaddingRight = "";
|
|
43
|
+
function lockScroll() {
|
|
44
|
+
const body = document.body;
|
|
45
|
+
if (lockCount === 0) {
|
|
46
|
+
savedOverflow = body.style.overflow;
|
|
47
|
+
savedPaddingRight = body.style.paddingRight;
|
|
48
|
+
const scrollbar = window.innerWidth - document.documentElement.clientWidth;
|
|
49
|
+
if (scrollbar > 0)
|
|
50
|
+
body.style.paddingRight = `${scrollbar}px`;
|
|
51
|
+
body.style.overflow = "hidden";
|
|
52
|
+
}
|
|
53
|
+
lockCount += 1;
|
|
54
|
+
let released = false;
|
|
55
|
+
return () => {
|
|
56
|
+
if (released)
|
|
57
|
+
return;
|
|
58
|
+
released = true;
|
|
59
|
+
lockCount -= 1;
|
|
60
|
+
if (lockCount === 0) {
|
|
61
|
+
body.style.overflow = savedOverflow;
|
|
62
|
+
body.style.paddingRight = savedPaddingRight;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var KEEP_VISIBLE = "[aria-live], [data-slot$='-overlay'], [data-sinwan-keep-visible]";
|
|
67
|
+
function hideOthers(layer) {
|
|
68
|
+
let top = layer;
|
|
69
|
+
while (top.parentElement && top.parentElement !== document.body)
|
|
70
|
+
top = top.parentElement;
|
|
71
|
+
const hidden = [];
|
|
72
|
+
for (const sibling of Array.from(document.body.children)) {
|
|
73
|
+
if (sibling === top || sibling.hasAttribute("aria-hidden"))
|
|
74
|
+
continue;
|
|
75
|
+
if (sibling.matches(KEEP_VISIBLE) || sibling.querySelector(KEEP_VISIBLE))
|
|
76
|
+
continue;
|
|
77
|
+
if (sibling.tagName === "SCRIPT" || sibling.tagName === "STYLE")
|
|
78
|
+
continue;
|
|
79
|
+
sibling.setAttribute("aria-hidden", "true");
|
|
80
|
+
hidden.push(sibling);
|
|
81
|
+
}
|
|
82
|
+
return () => {
|
|
83
|
+
for (const element of hidden)
|
|
84
|
+
element.removeAttribute("aria-hidden");
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function enterModal(layer) {
|
|
88
|
+
const unlock = lockScroll();
|
|
89
|
+
const unhide = hideOthers(layer);
|
|
90
|
+
return () => {
|
|
91
|
+
unhide();
|
|
92
|
+
unlock();
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/overlay.tsx
|
|
31
97
|
import { jsx, Fragment } from "sinwan/jsx-runtime";
|
|
32
98
|
var _$tmpl_0 = {
|
|
33
|
-
html: '<button type="button" data-slot="dialog-trigger"></button>',
|
|
99
|
+
html: '<button type="button" data-slot="dialog-trigger" aria-haspopup="dialog" aria-expanded=""></button>',
|
|
34
100
|
slots: [
|
|
35
101
|
{ path: [], type: "attr", name: "class" },
|
|
102
|
+
{ path: [], type: "attr", name: "aria-expanded" },
|
|
36
103
|
{ path: [], type: "event", name: "onclick" },
|
|
37
104
|
{ path: [], type: "ref", name: "ref" },
|
|
38
105
|
{ path: [], type: "child" }
|
|
@@ -64,7 +131,7 @@ var _$tmpl_3 = {
|
|
|
64
131
|
]
|
|
65
132
|
};
|
|
66
133
|
var _$tmpl_4 = {
|
|
67
|
-
html: '<button type="button" data-slot="popover-trigger" aria-expanded=""></button>',
|
|
134
|
+
html: '<button type="button" data-slot="popover-trigger" aria-haspopup="dialog" aria-expanded=""></button>',
|
|
68
135
|
slots: [
|
|
69
136
|
{ path: [], type: "attr", name: "class" },
|
|
70
137
|
{ path: [], type: "attr", name: "aria-expanded" },
|
|
@@ -74,7 +141,7 @@ var _$tmpl_4 = {
|
|
|
74
141
|
]
|
|
75
142
|
};
|
|
76
143
|
var REOPEN_LOCK_MS = 280;
|
|
77
|
-
function createOpenState(props, component) {
|
|
144
|
+
function createOpenState(props, component, reopenLockMs = REOPEN_LOCK_MS) {
|
|
78
145
|
const openLocal = signal(props.defaultOpen ?? false);
|
|
79
146
|
const open = isControlledProp(props, "open", component) ? computed(() => Boolean(props.open)) : openLocal;
|
|
80
147
|
const set = (next) => {
|
|
@@ -99,7 +166,7 @@ function createOpenState(props, component) {
|
|
|
99
166
|
} else {
|
|
100
167
|
if (pointerOverTrigger)
|
|
101
168
|
hoverOpenBlocked = true;
|
|
102
|
-
reopenLockUntil = Date.now() +
|
|
169
|
+
reopenLockUntil = Date.now() + reopenLockMs;
|
|
103
170
|
}
|
|
104
171
|
set(value);
|
|
105
172
|
props.onOpenChange?.(value);
|
|
@@ -132,15 +199,13 @@ function createOpenState(props, component) {
|
|
|
132
199
|
}
|
|
133
200
|
var DialogKey2 = Symbol("sinwan-ui.dialog");
|
|
134
201
|
var DialogLabelsKey2 = Symbol("sinwan-ui.dialog-labels");
|
|
135
|
-
var dialogCount = 0;
|
|
136
202
|
var DialogRoot2 = cc((props) => {
|
|
137
203
|
const api = createOpenState(props, "DialogRoot");
|
|
138
|
-
provide(DialogKey2, api);
|
|
139
|
-
dialogCount += 1;
|
|
204
|
+
provide(DialogKey2, { ...api, modal: props.modal ?? true });
|
|
140
205
|
provide(DialogLabelsKey2, {
|
|
141
206
|
title: signal(null),
|
|
142
207
|
description: signal(null),
|
|
143
|
-
baseId:
|
|
208
|
+
baseId: treeId("dialog")
|
|
144
209
|
});
|
|
145
210
|
return /* @__PURE__ */ jsx(Fragment, {
|
|
146
211
|
children: () => _$unwrap(props).children
|
|
@@ -186,9 +251,14 @@ var DialogTrigger2 = cc((props) => {
|
|
|
186
251
|
const ref = (el) => {
|
|
187
252
|
api.triggerEl.value = el;
|
|
188
253
|
};
|
|
254
|
+
function expanded() {
|
|
255
|
+
return api.open.value;
|
|
256
|
+
}
|
|
189
257
|
if (props.asChild) {
|
|
190
258
|
return /* @__PURE__ */ jsx(Slot2, {
|
|
191
259
|
class: () => _$unwrap(props).class,
|
|
260
|
+
"aria-haspopup": "dialog",
|
|
261
|
+
"aria-expanded": expanded,
|
|
192
262
|
onclick: onClick,
|
|
193
263
|
ref,
|
|
194
264
|
children: () => _$unwrap(props).children
|
|
@@ -196,6 +266,7 @@ var DialogTrigger2 = cc((props) => {
|
|
|
196
266
|
}
|
|
197
267
|
return _$createTemplate(_$tmpl_0, [
|
|
198
268
|
() => _$unwrap(props).class,
|
|
269
|
+
expanded,
|
|
199
270
|
onClick,
|
|
200
271
|
ref,
|
|
201
272
|
() => _$unwrap(props).children
|
|
@@ -260,9 +331,28 @@ var DialogContent2 = cc((props) => {
|
|
|
260
331
|
const labels = inject(DialogLabelsKey2, null);
|
|
261
332
|
let contentEl = null;
|
|
262
333
|
let previousFocus = null;
|
|
334
|
+
const layer = useDismissLayer2(() => api.open.value);
|
|
335
|
+
const contentNode = signal(null);
|
|
336
|
+
let releaseModal;
|
|
337
|
+
const release = () => {
|
|
338
|
+
releaseModal?.();
|
|
339
|
+
releaseModal = undefined;
|
|
340
|
+
};
|
|
341
|
+
if (api.modal) {
|
|
342
|
+
effect(() => {
|
|
343
|
+
const node = api.open.value ? contentNode.value : null;
|
|
344
|
+
untrack(() => {
|
|
345
|
+
if (node && !releaseModal)
|
|
346
|
+
releaseModal = enterModal(node);
|
|
347
|
+
if (!node)
|
|
348
|
+
release();
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
onUnmounted(release);
|
|
352
|
+
}
|
|
263
353
|
onMounted(() => {
|
|
264
354
|
function onKey(e) {
|
|
265
|
-
if (!api.open.value)
|
|
355
|
+
if (!api.open.value || !layer.isTop())
|
|
266
356
|
return;
|
|
267
357
|
if (e.key === "Escape") {
|
|
268
358
|
props.onEscapeKeyDown?.(e);
|
|
@@ -294,13 +384,14 @@ var DialogContent2 = cc((props) => {
|
|
|
294
384
|
..._$getSpreadProps(dataAttrs),
|
|
295
385
|
role: () => _$unwrap(props).role === undefined ? "dialog" : _$unwrap(props).role,
|
|
296
386
|
"aria-modal": "true",
|
|
297
|
-
"data-slot":
|
|
387
|
+
"data-slot": props["data-slot"] === undefined ? "dialog-content" : props["data-slot"],
|
|
298
388
|
"data-state": contentState,
|
|
299
|
-
"data-side":
|
|
300
|
-
"data-size":
|
|
301
|
-
"data-vaul-drawer-direction":
|
|
389
|
+
"data-side": props["data-side"],
|
|
390
|
+
"data-size": props["data-size"],
|
|
391
|
+
"data-vaul-drawer-direction": props["data-vaul-drawer-direction"],
|
|
302
392
|
class: () => _$unwrap(props).class,
|
|
303
393
|
ref: function contentRef(el) {
|
|
394
|
+
contentNode.value = el;
|
|
304
395
|
if (el) {
|
|
305
396
|
contentEl = el;
|
|
306
397
|
previousFocus = document.activeElement;
|
|
@@ -351,18 +442,20 @@ var CollapsibleTrigger2 = cc((props) => {
|
|
|
351
442
|
const toggle = () => {
|
|
352
443
|
api.setOpen(!api.open.value);
|
|
353
444
|
};
|
|
445
|
+
function expanded() {
|
|
446
|
+
return api.open.value;
|
|
447
|
+
}
|
|
354
448
|
if (props.asChild) {
|
|
355
449
|
return /* @__PURE__ */ jsx(Slot2, {
|
|
356
450
|
class: () => _$unwrap(props).class,
|
|
451
|
+
"aria-expanded": expanded,
|
|
357
452
|
onclick: toggle,
|
|
358
453
|
children: () => _$unwrap(props).children
|
|
359
454
|
});
|
|
360
455
|
}
|
|
361
456
|
return _$createTemplate(_$tmpl_3, [
|
|
362
457
|
() => _$unwrap(props).class,
|
|
363
|
-
|
|
364
|
-
return api.open.value;
|
|
365
|
-
},
|
|
458
|
+
expanded,
|
|
366
459
|
toggle,
|
|
367
460
|
() => _$unwrap(props).children
|
|
368
461
|
]);
|
|
@@ -415,9 +508,14 @@ var PopoverTrigger2 = cc((props) => {
|
|
|
415
508
|
const ref = (el) => {
|
|
416
509
|
api.triggerEl.value = el;
|
|
417
510
|
};
|
|
511
|
+
function expanded() {
|
|
512
|
+
return api.open.value;
|
|
513
|
+
}
|
|
418
514
|
if (props.asChild) {
|
|
419
515
|
return /* @__PURE__ */ jsx(Slot2, {
|
|
420
516
|
class: () => _$unwrap(props).class,
|
|
517
|
+
"aria-haspopup": "dialog",
|
|
518
|
+
"aria-expanded": expanded,
|
|
421
519
|
onclick: onClick,
|
|
422
520
|
ref,
|
|
423
521
|
children: () => _$unwrap(props).children
|
|
@@ -425,9 +523,7 @@ var PopoverTrigger2 = cc((props) => {
|
|
|
425
523
|
}
|
|
426
524
|
return _$createTemplate(_$tmpl_4, [
|
|
427
525
|
() => _$unwrap(props).class,
|
|
428
|
-
|
|
429
|
-
return api.open.value;
|
|
430
|
-
},
|
|
526
|
+
expanded,
|
|
431
527
|
onClick,
|
|
432
528
|
ref,
|
|
433
529
|
() => _$unwrap(props).children
|
|
@@ -436,6 +532,7 @@ var PopoverTrigger2 = cc((props) => {
|
|
|
436
532
|
var PopoverContent2 = cc((props) => {
|
|
437
533
|
const api = inject(PopoverKey2);
|
|
438
534
|
const contentEl = signal(null);
|
|
535
|
+
const layer = useDismissLayer2(() => api.open.value);
|
|
439
536
|
const { style, side: resolvedSide } = useAnchorPosition2({
|
|
440
537
|
open: api.open,
|
|
441
538
|
trigger: api.triggerEl,
|
|
@@ -456,7 +553,7 @@ var PopoverContent2 = cc((props) => {
|
|
|
456
553
|
api.setOpen(false);
|
|
457
554
|
}
|
|
458
555
|
function onKey(e) {
|
|
459
|
-
if (e.key === "Escape") {
|
|
556
|
+
if (e.key === "Escape" && api.open.value && layer.isTop()) {
|
|
460
557
|
api.setOpen(false);
|
|
461
558
|
}
|
|
462
559
|
}
|
|
@@ -480,8 +577,14 @@ var PopoverContent2 = cc((props) => {
|
|
|
480
577
|
class: () => _$unwrap(props).class,
|
|
481
578
|
style: () => style.value,
|
|
482
579
|
role: "dialog",
|
|
483
|
-
onmouseenter:
|
|
484
|
-
|
|
580
|
+
onmouseenter: (_$event) => {
|
|
581
|
+
const _$handler = props.onmouseenter;
|
|
582
|
+
return typeof _$handler === "function" ? _$handler.call(_$event.currentTarget, _$event) : undefined;
|
|
583
|
+
},
|
|
584
|
+
onmouseleave: (_$event) => {
|
|
585
|
+
const _$handler = props.onmouseleave;
|
|
586
|
+
return typeof _$handler === "function" ? _$handler.call(_$event.currentTarget, _$event) : undefined;
|
|
587
|
+
},
|
|
485
588
|
ref: (el) => {
|
|
486
589
|
contentEl.value = el;
|
|
487
590
|
},
|
|
@@ -490,35 +593,74 @@ var PopoverContent2 = cc((props) => {
|
|
|
490
593
|
})
|
|
491
594
|
});
|
|
492
595
|
});
|
|
596
|
+
var TOOLTIP_CLOSE_MS = 100;
|
|
493
597
|
var TooltipKey2 = Symbol("sinwan-ui.tooltip");
|
|
598
|
+
var TooltipProviderKey2 = Symbol("sinwan-ui.tooltip-provider");
|
|
494
599
|
var TooltipProvider2 = cc((props) => {
|
|
495
|
-
props.delayDuration;
|
|
496
|
-
return
|
|
600
|
+
provide(TooltipProviderKey2, { delayDuration: props.delayDuration ?? 0 });
|
|
601
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
602
|
+
children: () => _$unwrap(props).children
|
|
603
|
+
});
|
|
497
604
|
});
|
|
498
605
|
var TooltipRoot2 = cc((props) => {
|
|
499
|
-
const api = createOpenState(props, "TooltipRoot");
|
|
500
|
-
|
|
606
|
+
const api = createOpenState(props, "TooltipRoot", 0);
|
|
607
|
+
const provider = inject(TooltipProviderKey2, null);
|
|
608
|
+
let openTimer;
|
|
609
|
+
const cancelOpen = () => {
|
|
610
|
+
if (openTimer !== undefined) {
|
|
611
|
+
window.clearTimeout(openTimer);
|
|
612
|
+
openTimer = undefined;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const scheduleOpen = () => {
|
|
616
|
+
api.cancelClose();
|
|
617
|
+
cancelOpen();
|
|
618
|
+
if (api.open.value)
|
|
619
|
+
return;
|
|
620
|
+
const delay = props.delayDuration ?? provider?.delayDuration ?? 0;
|
|
621
|
+
if (delay <= 0) {
|
|
622
|
+
api.setOpen(true);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
openTimer = window.setTimeout(() => {
|
|
626
|
+
openTimer = undefined;
|
|
627
|
+
api.setOpen(true);
|
|
628
|
+
}, delay);
|
|
629
|
+
};
|
|
630
|
+
onUnmounted(cancelOpen);
|
|
631
|
+
provide(TooltipKey2, {
|
|
632
|
+
...api,
|
|
633
|
+
scheduleOpen,
|
|
634
|
+
cancelOpen,
|
|
635
|
+
contentId: treeId("tooltip")
|
|
636
|
+
});
|
|
501
637
|
return /* @__PURE__ */ jsx(Fragment, {
|
|
502
638
|
children: () => _$unwrap(props).children
|
|
503
639
|
});
|
|
504
640
|
});
|
|
505
641
|
var TooltipTrigger2 = cc((props) => {
|
|
506
642
|
const api = inject(TooltipKey2);
|
|
507
|
-
const show = () => {
|
|
508
|
-
api.setOpen(true);
|
|
509
|
-
};
|
|
510
|
-
const hide = () => {
|
|
511
|
-
api.setOpen(false);
|
|
512
|
-
};
|
|
513
|
-
const ref = (el) => {
|
|
514
|
-
api.triggerEl.value = el;
|
|
515
|
-
};
|
|
516
643
|
const handlers = {
|
|
517
|
-
onmouseenter:
|
|
518
|
-
onmouseleave:
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
644
|
+
onmouseenter: () => api.scheduleOpen(),
|
|
645
|
+
onmouseleave: () => {
|
|
646
|
+
api.cancelOpen();
|
|
647
|
+
if (api.open.value)
|
|
648
|
+
api.requestClose(TOOLTIP_CLOSE_MS);
|
|
649
|
+
},
|
|
650
|
+
onfocus: () => {
|
|
651
|
+
api.cancelOpen();
|
|
652
|
+
api.cancelClose();
|
|
653
|
+
api.setOpen(true);
|
|
654
|
+
},
|
|
655
|
+
onblur: () => {
|
|
656
|
+
api.cancelOpen();
|
|
657
|
+
if (api.open.value)
|
|
658
|
+
api.setOpen(false);
|
|
659
|
+
},
|
|
660
|
+
ref: (el) => {
|
|
661
|
+
api.triggerEl.value = el;
|
|
662
|
+
},
|
|
663
|
+
"aria-describedby": () => api.open.value ? api.contentId : undefined
|
|
522
664
|
};
|
|
523
665
|
if (props.asChild) {
|
|
524
666
|
return /* @__PURE__ */ jsx(Slot2, {
|
|
@@ -538,6 +680,7 @@ var TooltipTrigger2 = cc((props) => {
|
|
|
538
680
|
var TooltipContent2 = cc((props) => {
|
|
539
681
|
const api = inject(TooltipKey2);
|
|
540
682
|
const contentEl = signal(null);
|
|
683
|
+
const layer = useDismissLayer2(() => api.open.value);
|
|
541
684
|
const { style, side: resolvedSide } = useAnchorPosition2({
|
|
542
685
|
open: api.open,
|
|
543
686
|
trigger: api.triggerEl,
|
|
@@ -547,6 +690,16 @@ var TooltipContent2 = cc((props) => {
|
|
|
547
690
|
gap: props.sideOffset === undefined ? 8 : props.sideOffset,
|
|
548
691
|
fallbackSize: { width: 120, height: 32 }
|
|
549
692
|
});
|
|
693
|
+
onMounted(() => {
|
|
694
|
+
function onKey(e) {
|
|
695
|
+
if (e.key === "Escape" && api.open.value && layer.isTop()) {
|
|
696
|
+
api.cancelOpen();
|
|
697
|
+
api.setOpen(false);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
document.addEventListener("keydown", onKey);
|
|
701
|
+
onUnmounted(() => document.removeEventListener("keydown", onKey));
|
|
702
|
+
});
|
|
550
703
|
function tooltipState() {
|
|
551
704
|
return api.open.value ? "open" : "closed";
|
|
552
705
|
}
|
|
@@ -555,11 +708,17 @@ var TooltipContent2 = cc((props) => {
|
|
|
555
708
|
children: /* @__PURE__ */ jsx(UiPortal2, {
|
|
556
709
|
children: /* @__PURE__ */ jsx("div", {
|
|
557
710
|
role: "tooltip",
|
|
711
|
+
id: api.contentId,
|
|
558
712
|
"data-slot": "tooltip-content",
|
|
559
713
|
"data-state": tooltipState,
|
|
560
714
|
"data-side": () => resolvedSide.value,
|
|
561
715
|
class: () => _$unwrap(props).class,
|
|
562
716
|
style: () => style.value,
|
|
717
|
+
onmouseenter: () => api.cancelClose(),
|
|
718
|
+
onmouseleave: () => {
|
|
719
|
+
if (api.open.value)
|
|
720
|
+
api.requestClose(TOOLTIP_CLOSE_MS);
|
|
721
|
+
},
|
|
563
722
|
ref: (el) => {
|
|
564
723
|
contentEl.value = el;
|
|
565
724
|
},
|
|
@@ -569,4 +728,4 @@ var TooltipContent2 = cc((props) => {
|
|
|
569
728
|
});
|
|
570
729
|
});
|
|
571
730
|
|
|
572
|
-
export { DialogKey2, DialogLabelsKey2, DialogRoot2, DialogTitle2, DialogDescription2, DialogTrigger2, DialogClose2, DialogOverlay2, DialogContent2, CollapsibleKey2, CollapsibleRoot2, CollapsibleTrigger2, CollapsibleContent2, PopoverKey2, PopoverRoot2, PopoverTrigger2, PopoverContent2, TooltipKey2, TooltipProvider2, TooltipRoot2, TooltipTrigger2, TooltipContent2 };
|
|
731
|
+
export { DialogKey2, DialogLabelsKey2, DialogRoot2, DialogTitle2, DialogDescription2, DialogTrigger2, DialogClose2, DialogOverlay2, DialogContent2, CollapsibleKey2, CollapsibleRoot2, CollapsibleTrigger2, CollapsibleContent2, PopoverKey2, PopoverRoot2, PopoverTrigger2, PopoverContent2, TooltipKey2, TooltipProviderKey2, TooltipProvider2, TooltipRoot2, TooltipTrigger2, TooltipContent2 };
|
|
@@ -30,6 +30,52 @@ function mergeClass(a, b) {
|
|
|
30
30
|
return;
|
|
31
31
|
return parts.join(" ");
|
|
32
32
|
}
|
|
33
|
+
function setRef(ref, el) {
|
|
34
|
+
if (typeof ref === "function")
|
|
35
|
+
ref(el);
|
|
36
|
+
else if (ref !== null && typeof ref === "object" && "current" in ref)
|
|
37
|
+
Reflect.set(ref, "current", el);
|
|
38
|
+
}
|
|
39
|
+
function composeRefs(childRef, slotRef) {
|
|
40
|
+
if (childRef == null)
|
|
41
|
+
return slotRef;
|
|
42
|
+
if (slotRef == null)
|
|
43
|
+
return childRef;
|
|
44
|
+
return (el) => {
|
|
45
|
+
setRef(childRef, el);
|
|
46
|
+
setRef(slotRef, el);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var UNITLESS = /^(opacity|z-index|flex|flex-grow|flex-shrink|order|font-weight|line-height|zoom|scale)$/;
|
|
50
|
+
function kebab(key) {
|
|
51
|
+
return key.startsWith("--") ? key : key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
52
|
+
}
|
|
53
|
+
function styleText(style) {
|
|
54
|
+
return Object.entries(style).filter(([, value]) => value != null && value !== false && value !== "").map(([key, value]) => {
|
|
55
|
+
const name = kebab(key);
|
|
56
|
+
const text = typeof value === "number" && value !== 0 && !UNITLESS.test(name) && !name.startsWith("--") ? `${value}px` : String(value);
|
|
57
|
+
return `${name}: ${text}`;
|
|
58
|
+
}).join("; ");
|
|
59
|
+
}
|
|
60
|
+
function isStyleObject(value) {
|
|
61
|
+
return value !== null && typeof value === "object" && !isSignal(value) && !isComputed(value);
|
|
62
|
+
}
|
|
63
|
+
function mergeStyleValues(a, b) {
|
|
64
|
+
if (a == null || a === "")
|
|
65
|
+
return b;
|
|
66
|
+
if (b == null || b === "")
|
|
67
|
+
return a;
|
|
68
|
+
if (isStyleObject(a) && isStyleObject(b))
|
|
69
|
+
return { ...a, ...b };
|
|
70
|
+
const text = (value) => isStyleObject(value) ? styleText(value) : String(value).trim().replace(/;+$/, "");
|
|
71
|
+
return `${text(a)}; ${text(b)}`;
|
|
72
|
+
}
|
|
73
|
+
function mergeStyle(a, b) {
|
|
74
|
+
const live = (value) => isSignal(value) || isComputed(value) || typeof value === "function" && value.length === 0;
|
|
75
|
+
if (live(a) || live(b))
|
|
76
|
+
return () => mergeStyleValues(resolve(a), resolve(b));
|
|
77
|
+
return mergeStyleValues(a, b);
|
|
78
|
+
}
|
|
33
79
|
function mergeProps(slotProps, childProps) {
|
|
34
80
|
const merged = { ...childProps, ...slotProps };
|
|
35
81
|
const className = mergeClass(childProps.class, slotProps.class);
|
|
@@ -38,6 +84,14 @@ function mergeProps(slotProps, childProps) {
|
|
|
38
84
|
else {
|
|
39
85
|
delete merged.class;
|
|
40
86
|
}
|
|
87
|
+
const ref = composeRefs(childProps.ref, slotProps.ref);
|
|
88
|
+
if (ref !== undefined)
|
|
89
|
+
merged.ref = ref;
|
|
90
|
+
const style = mergeStyle(childProps.style, slotProps.style);
|
|
91
|
+
if (style !== undefined)
|
|
92
|
+
merged.style = style;
|
|
93
|
+
else
|
|
94
|
+
delete merged.style;
|
|
41
95
|
for (const key of Object.keys(slotProps)) {
|
|
42
96
|
if (!key.startsWith("on"))
|
|
43
97
|
continue;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Presence2,
|
|
3
3
|
UiPortal2
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-eczk2z48.js";
|
|
5
5
|
import {
|
|
6
|
+
readDocumentRtl2,
|
|
6
7
|
useAnchorPosition2
|
|
7
8
|
} from "./chunk-6r59k5mb.js";
|
|
9
|
+
import {
|
|
10
|
+
isKeyboardClick2,
|
|
11
|
+
useMenuFocus2
|
|
12
|
+
} from "./chunk-7c8ct63g.js";
|
|
8
13
|
|
|
9
14
|
// src/menu-sub.tsx
|
|
10
15
|
import { unwrap as _$unwrap } from "sinwan/reactivity";
|
|
@@ -56,23 +61,39 @@ function createMenuSubApi2(options) {
|
|
|
56
61
|
});
|
|
57
62
|
}
|
|
58
63
|
onUnmounted(cancelClose);
|
|
59
|
-
return {
|
|
64
|
+
return {
|
|
65
|
+
open,
|
|
66
|
+
setOpen,
|
|
67
|
+
triggerEl,
|
|
68
|
+
cancelClose,
|
|
69
|
+
requestClose,
|
|
70
|
+
openedByKeyboard: false
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function isRtlAt(el) {
|
|
74
|
+
const scope = el?.closest("[dir]");
|
|
75
|
+
if (scope)
|
|
76
|
+
return scope.getAttribute("dir") === "rtl";
|
|
77
|
+
return readDocumentRtl2();
|
|
60
78
|
}
|
|
61
79
|
function createMenuSubTriggerHandlers2(api) {
|
|
62
|
-
function openSub() {
|
|
80
|
+
function openSub(byKeyboard) {
|
|
63
81
|
api.cancelClose();
|
|
64
|
-
if (
|
|
65
|
-
|
|
82
|
+
if (api.open.value)
|
|
83
|
+
return;
|
|
84
|
+
api.openedByKeyboard = byKeyboard;
|
|
85
|
+
api.setOpen(true);
|
|
66
86
|
}
|
|
67
87
|
return {
|
|
68
|
-
onMouseEnter: openSub,
|
|
88
|
+
onMouseEnter: () => openSub(false),
|
|
69
89
|
onMouseLeave: () => api.requestClose(),
|
|
70
|
-
onClick: openSub,
|
|
90
|
+
onClick: (event) => openSub(event ? isKeyboardClick2(event) : false),
|
|
71
91
|
onKeyDown: (event) => {
|
|
72
|
-
|
|
92
|
+
const target = event.currentTarget instanceof Element ? event.currentTarget : api.triggerEl.value;
|
|
93
|
+
if (event.key !== (isRtlAt(target) ? "ArrowLeft" : "ArrowRight"))
|
|
73
94
|
return;
|
|
74
95
|
event.preventDefault();
|
|
75
|
-
openSub();
|
|
96
|
+
openSub(true);
|
|
76
97
|
}
|
|
77
98
|
};
|
|
78
99
|
}
|
|
@@ -93,17 +114,44 @@ var MenuSubContentLayer2 = cc(function MenuSubContentLayer(props) {
|
|
|
93
114
|
function subState() {
|
|
94
115
|
return props.api.open.value ? "open" : "closed";
|
|
95
116
|
}
|
|
117
|
+
const focus = useMenuFocus2({
|
|
118
|
+
open: () => props.api.open.value,
|
|
119
|
+
content: contentEl,
|
|
120
|
+
trigger: props.api.triggerEl,
|
|
121
|
+
close: () => props.api.setOpen(false),
|
|
122
|
+
openedByKeyboard: () => props.api.openedByKeyboard,
|
|
123
|
+
restoreFromBody: false
|
|
124
|
+
});
|
|
125
|
+
function onKeyDown(event) {
|
|
126
|
+
const el = contentEl.value;
|
|
127
|
+
if (!el)
|
|
128
|
+
return;
|
|
129
|
+
const back = isRtlAt(el) ? "ArrowRight" : "ArrowLeft";
|
|
130
|
+
if (event.key === back || event.key === "Escape") {
|
|
131
|
+
const from = event.target instanceof Element ? event.target : null;
|
|
132
|
+
if (from && from.closest('[role="menu"]') !== el)
|
|
133
|
+
return;
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
event.stopPropagation();
|
|
136
|
+
props.api.setOpen(false);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
focus.onKeyDown(event);
|
|
140
|
+
}
|
|
96
141
|
return /* @__PURE__ */ jsx(Presence2, {
|
|
97
142
|
present: () => _$unwrap(props).api.open.value,
|
|
98
143
|
children: /* @__PURE__ */ jsx(UiPortal2, {
|
|
99
144
|
children: /* @__PURE__ */ jsx("div", {
|
|
100
145
|
"data-slot": () => _$unwrap(props).slot,
|
|
146
|
+
role: "menu",
|
|
147
|
+
tabIndex: -1,
|
|
101
148
|
"data-state": subState,
|
|
102
149
|
"data-side": () => side.value,
|
|
103
150
|
class: () => _$unwrap(props).class,
|
|
104
151
|
style: () => style.value,
|
|
105
152
|
onmouseenter: () => props.api.cancelClose(),
|
|
106
153
|
onmouseleave: () => props.api.requestClose(),
|
|
154
|
+
onkeydown: onKeyDown,
|
|
107
155
|
ref: (el) => {
|
|
108
156
|
contentEl.value = el;
|
|
109
157
|
},
|
package/dist/controls.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Agent docs: node_modules/sinwan-ui-core/agents/llms.controls.txt (start at node_modules/sinwan-ui-core/agents/llms.txt). */
|
|
1
2
|
import { type InjectionKey, type SinwanNode } from "sinwan/component";
|
|
2
3
|
import { For, Show } from "sinwan/control-flow";
|
|
3
4
|
import { type Computed, type Signal } from "sinwan/reactivity";
|
|
@@ -102,6 +103,9 @@ export declare const SwitchRoot: import("sinwan/component").SinwanComponent<{
|
|
|
102
103
|
disabled?: boolean;
|
|
103
104
|
class?: string;
|
|
104
105
|
id?: string;
|
|
106
|
+
/** With a name, a hidden input submits `value` (default `"on"`) when on. */
|
|
107
|
+
name?: string;
|
|
108
|
+
value?: string;
|
|
105
109
|
children?: SinwanNode;
|
|
106
110
|
"data-size"?: string;
|
|
107
111
|
} & AriaProps>;
|
package/dist/controls.js
CHANGED
|
@@ -21,13 +21,13 @@ import {
|
|
|
21
21
|
ToggleGroupKey2,
|
|
22
22
|
ToggleGroupRoot2,
|
|
23
23
|
ToggleGroupItem2
|
|
24
|
-
} from "./chunks/chunk-
|
|
25
|
-
import"./chunks/chunk-f6hw8ash.js";
|
|
24
|
+
} from "./chunks/chunk-s84my297.js";
|
|
26
25
|
import {
|
|
27
26
|
Slot2
|
|
28
|
-
} from "./chunks/chunk-
|
|
27
|
+
} from "./chunks/chunk-wjzadrvr.js";
|
|
29
28
|
import"./chunks/chunk-7r6fwdyt.js";
|
|
30
|
-
import"./chunks/chunk-
|
|
29
|
+
import"./chunks/chunk-fe933s8d.js";
|
|
30
|
+
import"./chunks/chunk-eczk2z48.js";
|
|
31
31
|
import"./chunks/chunk-6r59k5mb.js";
|
|
32
32
|
export {
|
|
33
33
|
AccordionContent2 as AccordionContent,
|
package/dist/core.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Agent docs: node_modules/sinwan-ui-core/agents/llms.core.txt (start at node_modules/sinwan-ui-core/agents/llms.txt). */
|
|
1
2
|
import { type SinwanNode } from "sinwan/component";
|
|
2
3
|
import { Portal as SinwanPortal, Show } from "sinwan/control-flow";
|
|
3
4
|
import { signal, type Signal } from "sinwan/reactivity";
|
|
@@ -22,3 +23,10 @@ export declare function getFocusableElements(root: HTMLElement): HTMLElement[];
|
|
|
22
23
|
export declare function trapFocus(event: KeyboardEvent, root: HTMLElement): void;
|
|
23
24
|
export { basePlacement, computePosition, createPointReference, createRectReference, createSizeFloating, estimatePosition, readDocumentRtl, toFloatingPlacement, useAnchorPosition, usePointPosition, type Align, type FloatingPosition, type FloatingStyle, type Placement, type RectLike, type UseAnchorPositionOptions, type UsePointPositionOptions, } from "./floating";
|
|
24
25
|
export { signal, Show, SinwanPortal };
|
|
26
|
+
/**
|
|
27
|
+
* A stable id for linking a component's parts (`aria-controls`,
|
|
28
|
+
* `aria-activedescendant`, `aria-labelledby`): from the component's place in
|
|
29
|
+
* the tree, so server-rendered and hydrated ids match; unique per mount
|
|
30
|
+
* otherwise. Call in a component body. Ids start with `sinwan-ui-<prefix>-`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function usePartId(prefix: string): string;
|
package/dist/core.js
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
UiPortal2,
|
|
7
7
|
useControllableState2,
|
|
8
8
|
getFocusableElements2,
|
|
9
|
-
trapFocus2
|
|
10
|
-
|
|
9
|
+
trapFocus2,
|
|
10
|
+
usePartId2
|
|
11
|
+
} from "./chunks/chunk-eczk2z48.js";
|
|
11
12
|
import {
|
|
12
13
|
toFloatingPlacement2,
|
|
13
14
|
basePlacement2,
|
|
@@ -38,5 +39,6 @@ export {
|
|
|
38
39
|
trapFocus2 as trapFocus,
|
|
39
40
|
useAnchorPosition2 as useAnchorPosition,
|
|
40
41
|
useControllableState2 as useControllableState,
|
|
42
|
+
usePartId2 as usePartId,
|
|
41
43
|
usePointPosition2 as usePointPosition
|
|
42
44
|
};
|