@vertz/ui-primitives 0.2.15 → 0.2.17
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/shared/chunk-0mcr52hc.js +78 -0
- package/dist/shared/chunk-18y8gfk0.js +308 -0
- package/dist/shared/chunk-34yfm2b0.js +182 -0
- package/dist/shared/chunk-4085nbdq.js +196 -0
- package/dist/shared/chunk-4da5zksy.js +46 -0
- package/dist/shared/chunk-7ffg0caj.js +265 -0
- package/dist/shared/chunk-7kpsyjd7.js +61 -0
- package/dist/shared/chunk-7krvqrwq.js +177 -0
- package/dist/shared/chunk-8ak7vdk1.js +151 -0
- package/dist/shared/chunk-8nk0ya7a.js +163 -0
- package/dist/shared/chunk-8tvzqry6.js +218 -0
- package/dist/shared/chunk-8y1jf6xr.js +17 -0
- package/dist/shared/chunk-96d9nr7y.js +19 -0
- package/dist/shared/chunk-9hj9p7s2.js +95 -0
- package/dist/shared/chunk-a6wp8c32.js +32 -0
- package/dist/shared/chunk-avxcmmk6.js +178 -0
- package/dist/shared/chunk-bew4bjgf.js +165 -0
- package/dist/shared/chunk-dpsgb1xw.js +18 -0
- package/dist/shared/chunk-e2v1c9ex.js +62 -0
- package/dist/shared/chunk-g9qvd20g.js +133 -0
- package/dist/shared/chunk-gkddsbmh.js +73 -0
- package/dist/shared/chunk-gt0wth9h.js +128 -0
- package/dist/shared/chunk-hr9hx58m.js +71 -0
- package/dist/shared/chunk-j4cm8avr.js +175 -0
- package/dist/shared/chunk-jctqs9m4.js +60 -0
- package/dist/shared/chunk-jz0s6srh.js +161 -0
- package/dist/shared/chunk-kg27s15c.js +282 -0
- package/dist/shared/chunk-m1ptgp1s.js +142 -0
- package/dist/shared/chunk-n9nwx58j.js +60 -0
- package/dist/shared/chunk-ppcv3ehd.js +85 -0
- package/dist/shared/chunk-rnjm61t0.js +34 -0
- package/dist/shared/chunk-sqs8kyb2.js +288 -0
- package/dist/shared/chunk-t1vkvsz2.js +175 -0
- package/dist/shared/chunk-tfyg0qrp.js +117 -0
- package/dist/shared/chunk-ttsyf6ma.js +239 -0
- package/dist/shared/chunk-vvjyx7fe.js +62 -0
- package/dist/shared/chunk-x0we8gcy.js +219 -0
- package/dist/shared/chunk-x2hz98qn.js +108 -0
- package/dist/shared/chunk-yr9yzpvq.js +107 -0
- package/dist/src/accordion/accordion.d.ts +35 -0
- package/dist/src/accordion/accordion.js +10 -0
- package/dist/src/alert-dialog/alert-dialog.d.ts +26 -0
- package/dist/src/alert-dialog/alert-dialog.js +9 -0
- package/dist/src/badge/badge.d.ts +22 -0
- package/dist/src/badge/badge.js +8 -0
- package/dist/src/button/button.d.ts +20 -0
- package/dist/src/button/button.js +8 -0
- package/dist/src/calendar/calendar.d.ts +52 -0
- package/dist/src/calendar/calendar.js +7 -0
- package/dist/src/carousel/carousel.d.ts +39 -0
- package/dist/src/carousel/carousel.js +9 -0
- package/dist/src/checkbox/checkbox.d.ts +22 -0
- package/dist/src/checkbox/checkbox.js +9 -0
- package/dist/src/collapsible/collapsible.d.ts +33 -0
- package/dist/src/collapsible/collapsible.js +9 -0
- package/dist/src/combobox/combobox.d.ts +35 -0
- package/dist/src/combobox/combobox.js +10 -0
- package/dist/src/command/command.d.ts +41 -0
- package/dist/src/command/command.js +10 -0
- package/dist/src/context-menu/context-menu.d.ts +51 -0
- package/dist/src/context-menu/context-menu.js +12 -0
- package/dist/src/date-picker/date-picker.d.ts +47 -0
- package/dist/src/date-picker/date-picker.js +15 -0
- package/dist/src/dialog/dialog.d.ts +36 -0
- package/dist/src/dialog/dialog.js +11 -0
- package/dist/src/dropdown-menu/dropdown-menu.d.ts +54 -0
- package/dist/src/dropdown-menu/dropdown-menu.js +13 -0
- package/dist/src/hover-card/hover-card.d.ts +45 -0
- package/dist/src/hover-card/hover-card.js +11 -0
- package/dist/{index.d.ts → src/index.d.ts} +132 -140
- package/dist/src/index.js +137 -0
- package/dist/src/menu/menu.d.ts +51 -0
- package/dist/src/menu/menu.js +12 -0
- package/dist/src/menubar/menubar.d.ts +52 -0
- package/dist/src/menubar/menubar.js +13 -0
- package/dist/src/navigation-menu/navigation-menu.d.ts +37 -0
- package/dist/src/navigation-menu/navigation-menu.js +11 -0
- package/dist/src/popover/popover.d.ts +44 -0
- package/dist/src/popover/popover.js +13 -0
- package/dist/src/progress/progress.d.ts +32 -0
- package/dist/src/progress/progress.js +9 -0
- package/dist/src/radio/radio.d.ts +30 -0
- package/dist/src/radio/radio.js +11 -0
- package/dist/src/resizable-panel/resizable-panel.d.ts +36 -0
- package/dist/src/resizable-panel/resizable-panel.js +9 -0
- package/dist/src/scroll-area/scroll-area.d.ts +37 -0
- package/dist/src/scroll-area/scroll-area.js +7 -0
- package/dist/src/select/select.d.ts +53 -0
- package/dist/src/select/select.js +12 -0
- package/dist/src/sheet/sheet.d.ts +24 -0
- package/dist/src/sheet/sheet.js +10 -0
- package/dist/src/slider/slider.d.ts +36 -0
- package/dist/src/slider/slider.js +10 -0
- package/dist/src/switch/switch.d.ts +21 -0
- package/dist/src/switch/switch.js +9 -0
- package/dist/src/tabs/tabs.d.ts +35 -0
- package/dist/src/tabs/tabs.js +11 -0
- package/dist/src/toast/toast.d.ts +36 -0
- package/dist/src/toast/toast.js +9 -0
- package/dist/src/toggle/toggle.d.ts +21 -0
- package/dist/src/toggle/toggle.js +9 -0
- package/dist/src/toggle-group/toggle-group.d.ts +34 -0
- package/dist/src/toggle-group/toggle-group.js +10 -0
- package/dist/src/tooltip/tooltip.d.ts +44 -0
- package/dist/src/tooltip/tooltip.js +11 -0
- package/dist/src/utils.d.ts +176 -0
- package/dist/src/utils.js +72 -0
- package/package.json +12 -10
- package/dist/index.js +0 -3675
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/utils/id.ts
|
|
2
|
+
var counter = 0;
|
|
3
|
+
function uniqueId(prefix = "vz") {
|
|
4
|
+
return `${prefix}-${++counter}`;
|
|
5
|
+
}
|
|
6
|
+
function linkedIds(prefix = "vz") {
|
|
7
|
+
const base = uniqueId(prefix);
|
|
8
|
+
return {
|
|
9
|
+
triggerId: `${base}-trigger`,
|
|
10
|
+
contentId: `${base}-content`
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function resetIdCounter() {
|
|
14
|
+
counter = 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { uniqueId, linkedIds, resetIdCounter };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Menu
|
|
3
|
+
} from "./chunk-7ffg0caj.js";
|
|
4
|
+
|
|
5
|
+
// src/dropdown-menu/dropdown-menu.ts
|
|
6
|
+
var DropdownMenu = {
|
|
7
|
+
Root(options = {}) {
|
|
8
|
+
const { positioning, ...rest } = options;
|
|
9
|
+
return Menu.Root({
|
|
10
|
+
...rest,
|
|
11
|
+
positioning: {
|
|
12
|
+
placement: "bottom-start",
|
|
13
|
+
...positioning
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { DropdownMenu };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFloatingPosition
|
|
3
|
+
} from "./chunk-0mcr52hc.js";
|
|
4
|
+
import {
|
|
5
|
+
Keys,
|
|
6
|
+
isKey
|
|
7
|
+
} from "./chunk-jctqs9m4.js";
|
|
8
|
+
import {
|
|
9
|
+
setDataState,
|
|
10
|
+
setDescribedBy,
|
|
11
|
+
setHidden,
|
|
12
|
+
setHiddenAnimated
|
|
13
|
+
} from "./chunk-vvjyx7fe.js";
|
|
14
|
+
import {
|
|
15
|
+
applyAttrs
|
|
16
|
+
} from "./chunk-dpsgb1xw.js";
|
|
17
|
+
import {
|
|
18
|
+
uniqueId
|
|
19
|
+
} from "./chunk-8y1jf6xr.js";
|
|
20
|
+
|
|
21
|
+
// src/tooltip/tooltip.tsx
|
|
22
|
+
import { __element, __on } from "@vertz/ui/internals";
|
|
23
|
+
import { signal } from "@vertz/ui";
|
|
24
|
+
function TooltipRoot(options = {}) {
|
|
25
|
+
const { delay = 300, onOpenChange, positioning, ...attrs } = options;
|
|
26
|
+
const contentId = uniqueId("tooltip");
|
|
27
|
+
const state = { open: signal(false) };
|
|
28
|
+
let showTimeout = null;
|
|
29
|
+
let floatingCleanup = null;
|
|
30
|
+
function show() {
|
|
31
|
+
if (showTimeout !== null)
|
|
32
|
+
return;
|
|
33
|
+
showTimeout = setTimeout(() => {
|
|
34
|
+
state.open.value = true;
|
|
35
|
+
setHidden(content, false);
|
|
36
|
+
setDataState(content, "open");
|
|
37
|
+
if (positioning) {
|
|
38
|
+
const effectivePlacement = positioning.placement ?? "top";
|
|
39
|
+
const result = createFloatingPosition(trigger, content, {
|
|
40
|
+
...positioning,
|
|
41
|
+
placement: effectivePlacement
|
|
42
|
+
});
|
|
43
|
+
floatingCleanup = result.cleanup;
|
|
44
|
+
}
|
|
45
|
+
onOpenChange?.(true);
|
|
46
|
+
showTimeout = null;
|
|
47
|
+
}, delay);
|
|
48
|
+
}
|
|
49
|
+
function hide() {
|
|
50
|
+
if (showTimeout !== null) {
|
|
51
|
+
clearTimeout(showTimeout);
|
|
52
|
+
showTimeout = null;
|
|
53
|
+
}
|
|
54
|
+
state.open.value = false;
|
|
55
|
+
setDataState(content, "closed");
|
|
56
|
+
setHiddenAnimated(content, true);
|
|
57
|
+
floatingCleanup?.();
|
|
58
|
+
floatingCleanup = null;
|
|
59
|
+
onOpenChange?.(false);
|
|
60
|
+
}
|
|
61
|
+
const trigger = (() => {
|
|
62
|
+
const __el0 = __element("span");
|
|
63
|
+
__on(__el0, "mouseenter", show);
|
|
64
|
+
__on(__el0, "mouseleave", hide);
|
|
65
|
+
__on(__el0, "focus", show);
|
|
66
|
+
__on(__el0, "blur", hide);
|
|
67
|
+
__on(__el0, "keydown", (event) => {
|
|
68
|
+
if (isKey(event, Keys.Escape)) {
|
|
69
|
+
hide();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return __el0;
|
|
73
|
+
})();
|
|
74
|
+
setDescribedBy(trigger, contentId);
|
|
75
|
+
const content = (() => {
|
|
76
|
+
const __el1 = __element("div");
|
|
77
|
+
__el1.setAttribute("role", "tooltip");
|
|
78
|
+
{
|
|
79
|
+
const __v = contentId;
|
|
80
|
+
if (__v != null && __v !== false)
|
|
81
|
+
__el1.setAttribute("id", __v === true ? "" : __v);
|
|
82
|
+
}
|
|
83
|
+
__el1.setAttribute("aria-hidden", "true");
|
|
84
|
+
__el1.setAttribute("data-state", "closed");
|
|
85
|
+
__el1.setAttribute("style", "display: none");
|
|
86
|
+
return __el1;
|
|
87
|
+
})();
|
|
88
|
+
applyAttrs(trigger, attrs);
|
|
89
|
+
return { trigger, content, state };
|
|
90
|
+
}
|
|
91
|
+
var Tooltip = {
|
|
92
|
+
Root: TooltipRoot
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { Tooltip };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/utils/dismiss.ts
|
|
2
|
+
function createDismiss(options) {
|
|
3
|
+
const { onDismiss, insideElements, escapeKey = true, clickOutside = true } = options;
|
|
4
|
+
function handlePointerDown(event) {
|
|
5
|
+
const target = event.target;
|
|
6
|
+
const isInside = insideElements.some((el) => el.contains(target));
|
|
7
|
+
if (!isInside) {
|
|
8
|
+
onDismiss();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function handleKeyDown(event) {
|
|
12
|
+
if (event.key === "Escape") {
|
|
13
|
+
onDismiss();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (clickOutside) {
|
|
17
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
18
|
+
}
|
|
19
|
+
if (escapeKey) {
|
|
20
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
21
|
+
}
|
|
22
|
+
return function cleanup() {
|
|
23
|
+
if (clickOutside) {
|
|
24
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
25
|
+
}
|
|
26
|
+
if (escapeKey) {
|
|
27
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { createDismiss };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Keys,
|
|
3
|
+
handleListNavigation,
|
|
4
|
+
isKey
|
|
5
|
+
} from "./chunk-jctqs9m4.js";
|
|
6
|
+
import {
|
|
7
|
+
setDataState,
|
|
8
|
+
setExpanded,
|
|
9
|
+
setHidden,
|
|
10
|
+
setHiddenAnimated
|
|
11
|
+
} from "./chunk-vvjyx7fe.js";
|
|
12
|
+
import {
|
|
13
|
+
applyAttrs
|
|
14
|
+
} from "./chunk-dpsgb1xw.js";
|
|
15
|
+
import {
|
|
16
|
+
uniqueId
|
|
17
|
+
} from "./chunk-8y1jf6xr.js";
|
|
18
|
+
|
|
19
|
+
// src/accordion/accordion.tsx
|
|
20
|
+
import { __element, __enterChildren, __exitChildren, __insert, __on } from "@vertz/ui/internals";
|
|
21
|
+
import { signal } from "@vertz/ui";
|
|
22
|
+
function AccordionRoot(options = {}) {
|
|
23
|
+
const { multiple = false, defaultValue = [], onValueChange, ...attrs } = options;
|
|
24
|
+
const state = { value: signal([...defaultValue]) };
|
|
25
|
+
const triggers = [];
|
|
26
|
+
const itemMap = new Map;
|
|
27
|
+
function updateItemState(val, open) {
|
|
28
|
+
const entry = itemMap.get(val);
|
|
29
|
+
if (!entry)
|
|
30
|
+
return;
|
|
31
|
+
const { trigger: t, content: c } = entry;
|
|
32
|
+
if (open) {
|
|
33
|
+
setHidden(c, false);
|
|
34
|
+
}
|
|
35
|
+
const height = c.scrollHeight;
|
|
36
|
+
c.style.setProperty("--accordion-content-height", `${height}px`);
|
|
37
|
+
setExpanded(t, open);
|
|
38
|
+
setDataState(t, open ? "open" : "closed");
|
|
39
|
+
setDataState(c, open ? "open" : "closed");
|
|
40
|
+
if (!open) {
|
|
41
|
+
setHiddenAnimated(c, true);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function toggleItem(value) {
|
|
45
|
+
const prev = [...state.value.peek()];
|
|
46
|
+
const current = [...prev];
|
|
47
|
+
const idx = current.indexOf(value);
|
|
48
|
+
if (idx >= 0) {
|
|
49
|
+
current.splice(idx, 1);
|
|
50
|
+
} else {
|
|
51
|
+
if (multiple) {
|
|
52
|
+
current.push(value);
|
|
53
|
+
} else {
|
|
54
|
+
current.length = 0;
|
|
55
|
+
current.push(value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
state.value.value = current;
|
|
59
|
+
onValueChange?.(current);
|
|
60
|
+
for (const v of prev) {
|
|
61
|
+
if (!current.includes(v)) {
|
|
62
|
+
updateItemState(v, false);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const v of current) {
|
|
66
|
+
if (!prev.includes(v)) {
|
|
67
|
+
updateItemState(v, true);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const root = (() => {
|
|
72
|
+
const __el0 = __element("div");
|
|
73
|
+
__el0.setAttribute("data-orientation", "vertical");
|
|
74
|
+
__on(__el0, "keydown", (event) => {
|
|
75
|
+
if (isKey(event, Keys.ArrowUp, Keys.ArrowDown, Keys.Home, Keys.End)) {
|
|
76
|
+
handleListNavigation(event, triggers, { orientation: "vertical" });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return __el0;
|
|
80
|
+
})();
|
|
81
|
+
function Item(value) {
|
|
82
|
+
const baseId = uniqueId("accordion");
|
|
83
|
+
const triggerId = `${baseId}-trigger`;
|
|
84
|
+
const contentId = `${baseId}-content`;
|
|
85
|
+
const isOpen = state.value.peek().includes(value);
|
|
86
|
+
const trigger = (() => {
|
|
87
|
+
const __el1 = __element("button");
|
|
88
|
+
__el1.setAttribute("type", "button");
|
|
89
|
+
{
|
|
90
|
+
const __v = triggerId;
|
|
91
|
+
if (__v != null && __v !== false)
|
|
92
|
+
__el1.setAttribute("id", __v === true ? "" : __v);
|
|
93
|
+
}
|
|
94
|
+
{
|
|
95
|
+
const __v = contentId;
|
|
96
|
+
if (__v != null && __v !== false)
|
|
97
|
+
__el1.setAttribute("aria-controls", __v === true ? "" : __v);
|
|
98
|
+
}
|
|
99
|
+
{
|
|
100
|
+
const __v = value;
|
|
101
|
+
if (__v != null && __v !== false)
|
|
102
|
+
__el1.setAttribute("data-value", __v === true ? "" : __v);
|
|
103
|
+
}
|
|
104
|
+
{
|
|
105
|
+
const __v = isOpen ? "true" : "false";
|
|
106
|
+
if (__v != null && __v !== false)
|
|
107
|
+
__el1.setAttribute("aria-expanded", __v === true ? "" : __v);
|
|
108
|
+
}
|
|
109
|
+
{
|
|
110
|
+
const __v = isOpen ? "open" : "closed";
|
|
111
|
+
if (__v != null && __v !== false)
|
|
112
|
+
__el1.setAttribute("data-state", __v === true ? "" : __v);
|
|
113
|
+
}
|
|
114
|
+
__on(__el1, "click", () => toggleItem(value));
|
|
115
|
+
return __el1;
|
|
116
|
+
})();
|
|
117
|
+
const content = (() => {
|
|
118
|
+
const __el2 = __element("div");
|
|
119
|
+
__el2.setAttribute("role", "region");
|
|
120
|
+
{
|
|
121
|
+
const __v = contentId;
|
|
122
|
+
if (__v != null && __v !== false)
|
|
123
|
+
__el2.setAttribute("id", __v === true ? "" : __v);
|
|
124
|
+
}
|
|
125
|
+
{
|
|
126
|
+
const __v = triggerId;
|
|
127
|
+
if (__v != null && __v !== false)
|
|
128
|
+
__el2.setAttribute("aria-labelledby", __v === true ? "" : __v);
|
|
129
|
+
}
|
|
130
|
+
{
|
|
131
|
+
const __v = isOpen ? "false" : "true";
|
|
132
|
+
if (__v != null && __v !== false)
|
|
133
|
+
__el2.setAttribute("aria-hidden", __v === true ? "" : __v);
|
|
134
|
+
}
|
|
135
|
+
{
|
|
136
|
+
const __v = isOpen ? "open" : "closed";
|
|
137
|
+
if (__v != null && __v !== false)
|
|
138
|
+
__el2.setAttribute("data-state", __v === true ? "" : __v);
|
|
139
|
+
}
|
|
140
|
+
{
|
|
141
|
+
const __v = isOpen ? "" : "display: none";
|
|
142
|
+
if (__v != null && __v !== false)
|
|
143
|
+
__el2.setAttribute("style", __v === true ? "" : __v);
|
|
144
|
+
}
|
|
145
|
+
return __el2;
|
|
146
|
+
})();
|
|
147
|
+
const item = (() => {
|
|
148
|
+
const __el3 = __element("div");
|
|
149
|
+
{
|
|
150
|
+
const __v = value;
|
|
151
|
+
if (__v != null && __v !== false)
|
|
152
|
+
__el3.setAttribute("data-value", __v === true ? "" : __v);
|
|
153
|
+
}
|
|
154
|
+
__enterChildren(__el3);
|
|
155
|
+
__insert(__el3, trigger);
|
|
156
|
+
__insert(__el3, content);
|
|
157
|
+
__exitChildren();
|
|
158
|
+
return __el3;
|
|
159
|
+
})();
|
|
160
|
+
itemMap.set(value, { trigger, content });
|
|
161
|
+
triggers.push(trigger);
|
|
162
|
+
root.appendChild(item);
|
|
163
|
+
if (isOpen) {
|
|
164
|
+
requestAnimationFrame(() => {
|
|
165
|
+
const height = content.scrollHeight;
|
|
166
|
+
content.style.setProperty("--accordion-content-height", `${height}px`);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return { item, trigger, content };
|
|
170
|
+
}
|
|
171
|
+
applyAttrs(root, attrs);
|
|
172
|
+
return { root, state, Item };
|
|
173
|
+
}
|
|
174
|
+
var Accordion = {
|
|
175
|
+
Root: AccordionRoot
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export { Accordion };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFloatingPosition
|
|
3
|
+
} from "./chunk-0mcr52hc.js";
|
|
4
|
+
import {
|
|
5
|
+
Keys,
|
|
6
|
+
isKey
|
|
7
|
+
} from "./chunk-jctqs9m4.js";
|
|
8
|
+
import {
|
|
9
|
+
setDataState,
|
|
10
|
+
setExpanded,
|
|
11
|
+
setHidden,
|
|
12
|
+
setHiddenAnimated
|
|
13
|
+
} from "./chunk-vvjyx7fe.js";
|
|
14
|
+
import {
|
|
15
|
+
applyAttrs
|
|
16
|
+
} from "./chunk-dpsgb1xw.js";
|
|
17
|
+
import {
|
|
18
|
+
uniqueId
|
|
19
|
+
} from "./chunk-8y1jf6xr.js";
|
|
20
|
+
|
|
21
|
+
// src/hover-card/hover-card.tsx
|
|
22
|
+
import { __element, __on } from "@vertz/ui/internals";
|
|
23
|
+
import { signal } from "@vertz/ui";
|
|
24
|
+
function HoverCardRoot(options = {}) {
|
|
25
|
+
const { openDelay = 700, closeDelay = 300, onOpenChange, positioning, ...attrs } = options;
|
|
26
|
+
const contentId = uniqueId("hovercard");
|
|
27
|
+
const state = { open: signal(false) };
|
|
28
|
+
let openTimeout = null;
|
|
29
|
+
let closeTimeout = null;
|
|
30
|
+
let floatingCleanup = null;
|
|
31
|
+
function cancelTimers() {
|
|
32
|
+
if (openTimeout) {
|
|
33
|
+
clearTimeout(openTimeout);
|
|
34
|
+
openTimeout = null;
|
|
35
|
+
}
|
|
36
|
+
if (closeTimeout) {
|
|
37
|
+
clearTimeout(closeTimeout);
|
|
38
|
+
closeTimeout = null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function cancelCloseTimer() {
|
|
42
|
+
if (closeTimeout) {
|
|
43
|
+
clearTimeout(closeTimeout);
|
|
44
|
+
closeTimeout = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function positionContent() {
|
|
48
|
+
if (positioning) {
|
|
49
|
+
floatingCleanup?.();
|
|
50
|
+
const effectivePlacement = positioning.placement ?? "bottom";
|
|
51
|
+
const result = createFloatingPosition(trigger, content, {
|
|
52
|
+
...positioning,
|
|
53
|
+
placement: effectivePlacement
|
|
54
|
+
});
|
|
55
|
+
floatingCleanup = result.cleanup;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function show() {
|
|
59
|
+
cancelTimers();
|
|
60
|
+
if (state.open.peek())
|
|
61
|
+
return;
|
|
62
|
+
openTimeout = setTimeout(() => {
|
|
63
|
+
state.open.value = true;
|
|
64
|
+
setExpanded(trigger, true);
|
|
65
|
+
setHidden(content, false);
|
|
66
|
+
setDataState(content, "open");
|
|
67
|
+
positionContent();
|
|
68
|
+
onOpenChange?.(true);
|
|
69
|
+
openTimeout = null;
|
|
70
|
+
}, openDelay);
|
|
71
|
+
}
|
|
72
|
+
function showImmediate() {
|
|
73
|
+
cancelTimers();
|
|
74
|
+
state.open.value = true;
|
|
75
|
+
setExpanded(trigger, true);
|
|
76
|
+
setHidden(content, false);
|
|
77
|
+
setDataState(content, "open");
|
|
78
|
+
positionContent();
|
|
79
|
+
onOpenChange?.(true);
|
|
80
|
+
}
|
|
81
|
+
function hide() {
|
|
82
|
+
cancelTimers();
|
|
83
|
+
if (!state.open.peek())
|
|
84
|
+
return;
|
|
85
|
+
closeTimeout = setTimeout(() => {
|
|
86
|
+
state.open.value = false;
|
|
87
|
+
setExpanded(trigger, false);
|
|
88
|
+
setDataState(content, "closed");
|
|
89
|
+
setHiddenAnimated(content, true);
|
|
90
|
+
floatingCleanup?.();
|
|
91
|
+
floatingCleanup = null;
|
|
92
|
+
onOpenChange?.(false);
|
|
93
|
+
closeTimeout = null;
|
|
94
|
+
}, closeDelay);
|
|
95
|
+
}
|
|
96
|
+
function hideImmediate() {
|
|
97
|
+
cancelTimers();
|
|
98
|
+
state.open.value = false;
|
|
99
|
+
setExpanded(trigger, false);
|
|
100
|
+
setDataState(content, "closed");
|
|
101
|
+
setHiddenAnimated(content, true);
|
|
102
|
+
floatingCleanup?.();
|
|
103
|
+
floatingCleanup = null;
|
|
104
|
+
onOpenChange?.(false);
|
|
105
|
+
}
|
|
106
|
+
function handleTriggerBlur(event) {
|
|
107
|
+
const related = event.relatedTarget;
|
|
108
|
+
if (related && (trigger.contains(related) || content.contains(related)))
|
|
109
|
+
return;
|
|
110
|
+
hide();
|
|
111
|
+
}
|
|
112
|
+
function handleTriggerKeydown(event) {
|
|
113
|
+
if (isKey(event, Keys.Escape) && state.open.peek()) {
|
|
114
|
+
hideImmediate();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function handleContentFocusout(event) {
|
|
118
|
+
const related = event.relatedTarget;
|
|
119
|
+
if (related && (trigger.contains(related) || content.contains(related)))
|
|
120
|
+
return;
|
|
121
|
+
hide();
|
|
122
|
+
}
|
|
123
|
+
function handleContentKeydown(event) {
|
|
124
|
+
if (isKey(event, Keys.Escape)) {
|
|
125
|
+
hideImmediate();
|
|
126
|
+
trigger.focus();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const trigger = (() => {
|
|
130
|
+
const __el0 = __element("span");
|
|
131
|
+
__el0.setAttribute("aria-haspopup", "dialog");
|
|
132
|
+
__el0.setAttribute("aria-expanded", "false");
|
|
133
|
+
__on(__el0, "mouseenter", show);
|
|
134
|
+
__on(__el0, "mouseleave", hide);
|
|
135
|
+
__on(__el0, "focus", showImmediate);
|
|
136
|
+
__on(__el0, "blur", handleTriggerBlur);
|
|
137
|
+
__on(__el0, "keydown", handleTriggerKeydown);
|
|
138
|
+
return __el0;
|
|
139
|
+
})();
|
|
140
|
+
const content = (() => {
|
|
141
|
+
const __el1 = __element("div");
|
|
142
|
+
__el1.setAttribute("role", "dialog");
|
|
143
|
+
{
|
|
144
|
+
const __v = contentId;
|
|
145
|
+
if (__v != null && __v !== false)
|
|
146
|
+
__el1.setAttribute("id", __v === true ? "" : __v);
|
|
147
|
+
}
|
|
148
|
+
__el1.setAttribute("aria-hidden", "true");
|
|
149
|
+
__el1.setAttribute("data-state", "closed");
|
|
150
|
+
__el1.setAttribute("style", "display: none");
|
|
151
|
+
__on(__el1, "mouseenter", cancelCloseTimer);
|
|
152
|
+
__on(__el1, "mouseleave", hide);
|
|
153
|
+
__on(__el1, "focusin", cancelCloseTimer);
|
|
154
|
+
__on(__el1, "focusout", handleContentFocusout);
|
|
155
|
+
__on(__el1, "keydown", handleContentKeydown);
|
|
156
|
+
return __el1;
|
|
157
|
+
})();
|
|
158
|
+
applyAttrs(trigger, attrs);
|
|
159
|
+
return { trigger, content, state };
|
|
160
|
+
}
|
|
161
|
+
var HoverCard = {
|
|
162
|
+
Root: HoverCardRoot
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export { HoverCard };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/utils/attrs.ts
|
|
2
|
+
function applyAttrs(el, attrs) {
|
|
3
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
4
|
+
if (value == null)
|
|
5
|
+
continue;
|
|
6
|
+
if (key === "class") {
|
|
7
|
+
const existing = el.getAttribute("class");
|
|
8
|
+
el.setAttribute("class", existing ? `${existing} ${String(value)}` : String(value));
|
|
9
|
+
} else if (key === "style") {
|
|
10
|
+
const existing = el.getAttribute("style");
|
|
11
|
+
el.setAttribute("style", existing ? `${existing}; ${String(value)}` : String(value));
|
|
12
|
+
} else {
|
|
13
|
+
el.setAttribute(key, String(value));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { applyAttrs };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/utils/focus.ts
|
|
2
|
+
var FOCUSABLE_SELECTOR = [
|
|
3
|
+
"a[href]",
|
|
4
|
+
"button:not([disabled])",
|
|
5
|
+
"input:not([disabled])",
|
|
6
|
+
"select:not([disabled])",
|
|
7
|
+
"textarea:not([disabled])",
|
|
8
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
9
|
+
"[contenteditable]"
|
|
10
|
+
].join(", ");
|
|
11
|
+
function getFocusableElements(container) {
|
|
12
|
+
return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR));
|
|
13
|
+
}
|
|
14
|
+
function trapFocus(container) {
|
|
15
|
+
function handleKeyDown(event) {
|
|
16
|
+
if (event.key !== "Tab")
|
|
17
|
+
return;
|
|
18
|
+
const focusable = getFocusableElements(container);
|
|
19
|
+
if (focusable.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
const first = focusable[0];
|
|
22
|
+
const last = focusable[focusable.length - 1];
|
|
23
|
+
if (!first || !last)
|
|
24
|
+
return;
|
|
25
|
+
if (event.shiftKey) {
|
|
26
|
+
if (document.activeElement === first) {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
last.focus();
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
if (document.activeElement === last) {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
first.focus();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
container.addEventListener("keydown", handleKeyDown);
|
|
38
|
+
return () => {
|
|
39
|
+
container.removeEventListener("keydown", handleKeyDown);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function focusFirst(container) {
|
|
43
|
+
const focusable = getFocusableElements(container);
|
|
44
|
+
if (focusable.length > 0) {
|
|
45
|
+
focusable[0]?.focus();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function saveFocus() {
|
|
49
|
+
const previously = document.activeElement;
|
|
50
|
+
return () => {
|
|
51
|
+
if (previously && typeof previously.focus === "function") {
|
|
52
|
+
previously.focus();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function setRovingTabindex(items, activeIndex) {
|
|
57
|
+
for (let i = 0;i < items.length; i++) {
|
|
58
|
+
items[i]?.setAttribute("tabindex", i === activeIndex ? "0" : "-1");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { getFocusableElements, trapFocus, focusFirst, saveFocus, setRovingTabindex };
|