@oddmash/ui 0.4.1 → 0.6.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/README.md +2 -1
- package/dist/alert.js +2 -2
- package/dist/badge.d.ts +2 -2
- package/dist/button.d.ts +22 -7
- package/dist/button.js +9 -3
- package/dist/chunk-77W2JTCK.js +116 -0
- package/dist/chunk-A3PPKK5J.js +23 -0
- package/dist/chunk-BAJCEDO3.js +17 -0
- package/dist/chunk-DOCL5Y45.js +14 -0
- package/dist/chunk-FKO6T5XG.js +71 -0
- package/dist/chunk-GRQMKQRL.js +21 -0
- package/dist/chunk-I5VJBLHP.js +36 -0
- package/dist/{chunk-OGJ3KIBM.js → chunk-LKCU6TJK.js} +3 -0
- package/dist/chunk-OJKYDXOE.js +223 -0
- package/dist/chunk-OUFCQ2JE.js +126 -0
- package/dist/chunk-PG3JE6RB.js +160 -0
- package/dist/chunk-QW7IHDAG.js +36 -0
- package/dist/{chunk-BMVVSFAU.js → chunk-TZHTKOPH.js} +3 -3
- package/dist/chunk-U7RNP366.js +16 -0
- package/dist/chunk-WHFF7XSS.js +224 -0
- package/dist/chunk-ZRMUD4KO.js +57 -0
- package/dist/clipboard-button.d.ts +28 -0
- package/dist/clipboard-button.js +11 -0
- package/dist/code-block.d.ts +16 -0
- package/dist/code-block.js +16 -0
- package/dist/command-palette.d.ts +10 -1
- package/dist/command-palette.js +2 -1
- package/dist/docs-navigation.d.ts +64 -0
- package/dist/docs-navigation.js +15 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +109 -27
- package/dist/kbd.d.ts +8 -0
- package/dist/kbd.js +8 -0
- package/dist/link-card.d.ts +8 -0
- package/dist/link-card.js +8 -0
- package/dist/locale-picker.d.ts +18 -0
- package/dist/locale-picker.js +9 -0
- package/dist/platform-link.d.ts +15 -0
- package/dist/platform-link.js +10 -0
- package/dist/prose.d.ts +10 -0
- package/dist/prose.js +10 -0
- package/dist/scroll-header.d.ts +17 -0
- package/dist/scroll-header.js +10 -0
- package/dist/site-layout.d.ts +16 -0
- package/dist/site-layout.js +16 -0
- package/dist/slider.js +1 -1
- package/dist/styles.css +785 -0
- package/dist/toast-provider.d.ts +30 -0
- package/dist/toast-provider.js +11 -0
- package/dist/tokens.css +10 -0
- package/dist/tokens.d.ts +3 -0
- package/dist/tokens.js +1 -1
- package/package.json +45 -1
- package/tokens/primitive.json +18 -0
- package/tokens/semantic/dark.json +12 -0
- package/tokens/semantic/light.json +12 -0
- package/dist/chunk-3TIYT55P.js +0 -14
- package/dist/chunk-U2Y2DJXG.js +0 -14
- package/dist/chunk-WODRU2UN.js +0 -69
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
cx
|
|
4
|
+
} from "./chunk-54STG2JB.js";
|
|
5
|
+
|
|
6
|
+
// src/scroll-header.tsx
|
|
7
|
+
import {
|
|
8
|
+
forwardRef,
|
|
9
|
+
useEffect,
|
|
10
|
+
useImperativeHandle,
|
|
11
|
+
useRef
|
|
12
|
+
} from "react";
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
var observeScrollHeader = (header, {
|
|
15
|
+
enabled = true,
|
|
16
|
+
media,
|
|
17
|
+
locked = false,
|
|
18
|
+
hideThreshold = 24,
|
|
19
|
+
revealThreshold = 8,
|
|
20
|
+
topOffset = 8
|
|
21
|
+
} = {}) => {
|
|
22
|
+
const doc = header.ownerDocument;
|
|
23
|
+
const view = doc.defaultView;
|
|
24
|
+
if (!view) return () => {
|
|
25
|
+
};
|
|
26
|
+
const original = header.getAttribute("data-om-scroll-hidden");
|
|
27
|
+
const reduced = typeof view.matchMedia === "function" ? view.matchMedia("(prefers-reduced-motion: reduce)") : void 0;
|
|
28
|
+
const breakpoint = media && typeof view.matchMedia === "function" ? view.matchMedia(media) : void 0;
|
|
29
|
+
let hidden = false;
|
|
30
|
+
let last = Math.max(0, view.scrollY);
|
|
31
|
+
let distance = 0;
|
|
32
|
+
let direction = 0;
|
|
33
|
+
let frame;
|
|
34
|
+
let disposed = false;
|
|
35
|
+
const show = (nextHidden) => {
|
|
36
|
+
hidden = nextHidden;
|
|
37
|
+
header.dataset.omScrollHidden = String(nextHidden);
|
|
38
|
+
};
|
|
39
|
+
const isLocked = () => !enabled || locked || reduced?.matches || breakpoint && !breakpoint.matches || header.contains(doc.activeElement) || header.querySelector('details[open], [aria-expanded="true"]');
|
|
40
|
+
const reveal = () => {
|
|
41
|
+
distance = 0;
|
|
42
|
+
direction = 0;
|
|
43
|
+
last = Math.max(0, view.scrollY);
|
|
44
|
+
show(false);
|
|
45
|
+
};
|
|
46
|
+
const update = () => {
|
|
47
|
+
frame = void 0;
|
|
48
|
+
if (disposed) return;
|
|
49
|
+
const next = Math.max(0, view.scrollY);
|
|
50
|
+
const delta = next - last;
|
|
51
|
+
last = next;
|
|
52
|
+
if (next <= Math.max(0, topOffset) || isLocked()) {
|
|
53
|
+
reveal();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!delta) return;
|
|
57
|
+
const nextDirection = Math.sign(delta);
|
|
58
|
+
if (nextDirection !== direction) {
|
|
59
|
+
distance = 0;
|
|
60
|
+
direction = nextDirection;
|
|
61
|
+
}
|
|
62
|
+
distance += Math.abs(delta);
|
|
63
|
+
if (!hidden && direction > 0 && distance >= Math.max(0, hideThreshold)) {
|
|
64
|
+
show(true);
|
|
65
|
+
distance = 0;
|
|
66
|
+
} else if (hidden && direction < 0 && distance >= Math.max(0, revealThreshold)) {
|
|
67
|
+
show(false);
|
|
68
|
+
distance = 0;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const schedule = () => {
|
|
72
|
+
if (frame !== void 0) return;
|
|
73
|
+
if (typeof view.requestAnimationFrame === "function") frame = view.requestAnimationFrame(update);
|
|
74
|
+
else update();
|
|
75
|
+
};
|
|
76
|
+
const menuChange = () => {
|
|
77
|
+
if (isLocked()) reveal();
|
|
78
|
+
};
|
|
79
|
+
const mutation = typeof view.MutationObserver === "undefined" ? void 0 : new view.MutationObserver(menuChange);
|
|
80
|
+
mutation?.observe(header, { subtree: true, childList: true, attributes: true, attributeFilter: ["open", "aria-expanded"] });
|
|
81
|
+
view.addEventListener("scroll", schedule, { passive: true });
|
|
82
|
+
view.addEventListener("resize", schedule);
|
|
83
|
+
view.addEventListener("pageshow", reveal);
|
|
84
|
+
header.addEventListener("focusin", reveal);
|
|
85
|
+
reduced?.addEventListener("change", reveal);
|
|
86
|
+
breakpoint?.addEventListener("change", reveal);
|
|
87
|
+
reveal();
|
|
88
|
+
return () => {
|
|
89
|
+
disposed = true;
|
|
90
|
+
if (frame !== void 0) view.cancelAnimationFrame(frame);
|
|
91
|
+
mutation?.disconnect();
|
|
92
|
+
view.removeEventListener("scroll", schedule);
|
|
93
|
+
view.removeEventListener("resize", schedule);
|
|
94
|
+
view.removeEventListener("pageshow", reveal);
|
|
95
|
+
header.removeEventListener("focusin", reveal);
|
|
96
|
+
reduced?.removeEventListener("change", reveal);
|
|
97
|
+
breakpoint?.removeEventListener("change", reveal);
|
|
98
|
+
if (original === null) header.removeAttribute("data-om-scroll-hidden");
|
|
99
|
+
else header.setAttribute("data-om-scroll-hidden", original);
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
var ScrollHeader = forwardRef(({
|
|
103
|
+
enabled,
|
|
104
|
+
media,
|
|
105
|
+
locked,
|
|
106
|
+
hideThreshold,
|
|
107
|
+
revealThreshold,
|
|
108
|
+
topOffset,
|
|
109
|
+
className,
|
|
110
|
+
...props
|
|
111
|
+
}, ref) => {
|
|
112
|
+
const header = useRef(null);
|
|
113
|
+
useImperativeHandle(ref, () => header.current, []);
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const element = header.current;
|
|
116
|
+
if (!element) return;
|
|
117
|
+
return observeScrollHeader(element, { enabled, media, locked, hideThreshold, revealThreshold, topOffset });
|
|
118
|
+
}, [enabled, media, locked, hideThreshold, revealThreshold, topOffset]);
|
|
119
|
+
return /* @__PURE__ */ jsx("header", { ...props, ref: header, className: cx("om-site-header", "om-scroll-header", className) });
|
|
120
|
+
});
|
|
121
|
+
ScrollHeader.displayName = "ScrollHeader";
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
observeScrollHeader,
|
|
125
|
+
ScrollHeader
|
|
126
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Dialog,
|
|
4
|
+
DialogClose,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogDescription,
|
|
7
|
+
DialogTitle,
|
|
8
|
+
DialogTrigger
|
|
9
|
+
} from "./chunk-ME34NDSX.js";
|
|
10
|
+
import {
|
|
11
|
+
Button
|
|
12
|
+
} from "./chunk-A3PPKK5J.js";
|
|
13
|
+
import {
|
|
14
|
+
Input
|
|
15
|
+
} from "./chunk-5NGRPREI.js";
|
|
16
|
+
|
|
17
|
+
// src/command-palette.tsx
|
|
18
|
+
import { useCallback, useEffect, useId, useMemo, useState } from "react";
|
|
19
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
20
|
+
var defaultFilter = (item, query) => [item.label, item.description, item.group, ...item.keywords ?? []].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase());
|
|
21
|
+
var CommandPalette = ({
|
|
22
|
+
trigger,
|
|
23
|
+
title,
|
|
24
|
+
description,
|
|
25
|
+
searchLabel,
|
|
26
|
+
emptyLabel,
|
|
27
|
+
dismissLabel,
|
|
28
|
+
items,
|
|
29
|
+
theme,
|
|
30
|
+
container,
|
|
31
|
+
open: controlledOpen,
|
|
32
|
+
defaultOpen = false,
|
|
33
|
+
onOpenChange,
|
|
34
|
+
shortcut = false,
|
|
35
|
+
maxResults,
|
|
36
|
+
filter = defaultFilter
|
|
37
|
+
}) => {
|
|
38
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
39
|
+
const [query, setQuery] = useState("");
|
|
40
|
+
const [active, setActive] = useState(null);
|
|
41
|
+
const open = controlledOpen ?? internalOpen;
|
|
42
|
+
const id = useId();
|
|
43
|
+
const setOpen = useCallback((value) => {
|
|
44
|
+
if (controlledOpen === void 0) setInternalOpen(value);
|
|
45
|
+
onOpenChange?.(value);
|
|
46
|
+
if (!value) {
|
|
47
|
+
setQuery("");
|
|
48
|
+
setActive(null);
|
|
49
|
+
}
|
|
50
|
+
}, [controlledOpen, onOpenChange]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!open) {
|
|
53
|
+
setQuery("");
|
|
54
|
+
setActive(null);
|
|
55
|
+
}
|
|
56
|
+
}, [open]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!shortcut) return;
|
|
59
|
+
const owner = container?.ownerDocument ?? document;
|
|
60
|
+
const onKeyDown = (event) => {
|
|
61
|
+
if (event.defaultPrevented || event.isComposing || event.repeat || event.altKey || event.shiftKey || !event.metaKey && !event.ctrlKey || event.key.toLowerCase() !== "k") return;
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
if (!open) setOpen(true);
|
|
64
|
+
};
|
|
65
|
+
owner.addEventListener("keydown", onKeyDown);
|
|
66
|
+
return () => owner.removeEventListener("keydown", onKeyDown);
|
|
67
|
+
}, [container, open, setOpen, shortcut]);
|
|
68
|
+
const groups = useMemo(() => {
|
|
69
|
+
const matches = items.filter((item) => filter(item, query.trim()));
|
|
70
|
+
const limit = maxResults === void 0 ? matches.length : Math.max(0, Math.floor(maxResults));
|
|
71
|
+
const result = /* @__PURE__ */ new Map();
|
|
72
|
+
for (const item of matches.slice(0, limit)) {
|
|
73
|
+
const group = item.group || void 0;
|
|
74
|
+
if (!result.has(group)) result.set(group, []);
|
|
75
|
+
result.get(group).push(item);
|
|
76
|
+
}
|
|
77
|
+
return Array.from(result, ([label, entries]) => ({ label, entries }));
|
|
78
|
+
}, [filter, items, maxResults, query]);
|
|
79
|
+
const list = useMemo(() => groups.flatMap((group) => group.entries), [groups]);
|
|
80
|
+
const available = list.filter((item) => !item.disabled);
|
|
81
|
+
const selected = available.find((item) => item.id === active) ?? available[0];
|
|
82
|
+
const optionId = (item) => `${id}-${list.indexOf(item)}`;
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (open && selected) {
|
|
85
|
+
const owner = container?.ownerDocument ?? document;
|
|
86
|
+
owner.getElementById(`${id}-${list.indexOf(selected)}`)?.scrollIntoView?.({ block: "nearest" });
|
|
87
|
+
}
|
|
88
|
+
}, [container, open, selected, id, list]);
|
|
89
|
+
const select = (item) => {
|
|
90
|
+
if (item.disabled) return;
|
|
91
|
+
setOpen(false);
|
|
92
|
+
item.onSelect();
|
|
93
|
+
};
|
|
94
|
+
const renderOption = (item) => /* @__PURE__ */ jsxs(
|
|
95
|
+
"div",
|
|
96
|
+
{
|
|
97
|
+
id: optionId(item),
|
|
98
|
+
role: "option",
|
|
99
|
+
"aria-label": item.label,
|
|
100
|
+
"aria-describedby": item.description ? `${optionId(item)}-description` : void 0,
|
|
101
|
+
"aria-selected": selected?.id === item.id,
|
|
102
|
+
"aria-disabled": item.disabled || void 0,
|
|
103
|
+
onPointerMove: () => {
|
|
104
|
+
if (!item.disabled) setActive(item.id);
|
|
105
|
+
},
|
|
106
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
107
|
+
onClick: () => select(item),
|
|
108
|
+
children: [
|
|
109
|
+
/* @__PURE__ */ jsx("span", { className: "om-command-label", children: item.label }),
|
|
110
|
+
item.description && /* @__PURE__ */ jsx("span", { id: `${optionId(item)}-description`, className: "om-command-description", children: item.description })
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
item.id
|
|
114
|
+
);
|
|
115
|
+
return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange: setOpen, children: [
|
|
116
|
+
/* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: trigger }),
|
|
117
|
+
/* @__PURE__ */ jsxs(DialogContent, { theme, container, className: "om-command-palette", children: [
|
|
118
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: title }),
|
|
119
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: description }),
|
|
120
|
+
/* @__PURE__ */ jsx(
|
|
121
|
+
Input,
|
|
122
|
+
{
|
|
123
|
+
role: "combobox",
|
|
124
|
+
"aria-label": searchLabel,
|
|
125
|
+
"aria-autocomplete": "list",
|
|
126
|
+
"aria-expanded": "true",
|
|
127
|
+
"aria-controls": id,
|
|
128
|
+
"aria-activedescendant": selected ? optionId(selected) : void 0,
|
|
129
|
+
value: query,
|
|
130
|
+
onChange: (event) => {
|
|
131
|
+
setQuery(event.target.value);
|
|
132
|
+
setActive(null);
|
|
133
|
+
},
|
|
134
|
+
onKeyDown: (event) => {
|
|
135
|
+
if (event.nativeEvent.isComposing) return;
|
|
136
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
if (!available.length) return;
|
|
139
|
+
const index = selected ? available.indexOf(selected) : 0;
|
|
140
|
+
setActive(available[(index + (event.key === "ArrowDown" ? 1 : available.length - 1)) % available.length].id);
|
|
141
|
+
} else if (event.key === "Enter" && selected && !event.nativeEvent.isComposing) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
select(selected);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__PURE__ */ jsx("div", { role: "listbox", id, "aria-label": title, className: "om-command-list", children: groups.map((group) => group.label ? /* @__PURE__ */ jsxs("div", { role: "group", "aria-label": group.label, className: "om-command-group", children: [
|
|
149
|
+
/* @__PURE__ */ jsx("div", { "aria-hidden": "true", className: "om-command-group-label", children: group.label }),
|
|
150
|
+
group.entries.map(renderOption)
|
|
151
|
+
] }, group.label) : group.entries.map(renderOption)) }),
|
|
152
|
+
!list.length && /* @__PURE__ */ jsx("p", { role: "status", children: emptyLabel }),
|
|
153
|
+
dismissLabel && /* @__PURE__ */ jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "om-command-dismiss", children: dismissLabel }) })
|
|
154
|
+
] })
|
|
155
|
+
] });
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
CommandPalette
|
|
160
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
cx
|
|
4
|
+
} from "./chunk-54STG2JB.js";
|
|
5
|
+
|
|
6
|
+
// src/site-layout.tsx
|
|
7
|
+
import { forwardRef } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var SiteHeader = /* @__PURE__ */ forwardRef(
|
|
10
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("header", { ...props, ref, className: cx("om-site-header", className) })
|
|
11
|
+
);
|
|
12
|
+
SiteHeader.displayName = "SiteHeader";
|
|
13
|
+
var SiteHeaderInner = /* @__PURE__ */ forwardRef(
|
|
14
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ...props, ref, className: cx("om-site-header-inner", className) })
|
|
15
|
+
);
|
|
16
|
+
SiteHeaderInner.displayName = "SiteHeaderInner";
|
|
17
|
+
var SiteFooter = /* @__PURE__ */ forwardRef(
|
|
18
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("footer", { ...props, ref, className: cx("om-site-footer", className) })
|
|
19
|
+
);
|
|
20
|
+
SiteFooter.displayName = "SiteFooter";
|
|
21
|
+
var SiteFooterInner = /* @__PURE__ */ forwardRef(
|
|
22
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ...props, ref, className: cx("om-site-footer-inner", className) })
|
|
23
|
+
);
|
|
24
|
+
SiteFooterInner.displayName = "SiteFooterInner";
|
|
25
|
+
var SiteNav = /* @__PURE__ */ forwardRef(
|
|
26
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("nav", { ...props, ref, className: cx("om-site-nav", className) })
|
|
27
|
+
);
|
|
28
|
+
SiteNav.displayName = "SiteNav";
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
SiteHeader,
|
|
32
|
+
SiteHeaderInner,
|
|
33
|
+
SiteFooter,
|
|
34
|
+
SiteFooterInner,
|
|
35
|
+
SiteNav
|
|
36
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
Button
|
|
4
|
-
} from "./chunk-3TIYT55P.js";
|
|
5
2
|
import {
|
|
6
3
|
Dialog,
|
|
7
4
|
DialogContent,
|
|
8
5
|
DialogDescription,
|
|
9
6
|
DialogTitle
|
|
10
7
|
} from "./chunk-ME34NDSX.js";
|
|
8
|
+
import {
|
|
9
|
+
Button
|
|
10
|
+
} from "./chunk-A3PPKK5J.js";
|
|
11
11
|
import {
|
|
12
12
|
cx
|
|
13
13
|
} from "./chunk-54STG2JB.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
cx
|
|
4
|
+
} from "./chunk-54STG2JB.js";
|
|
5
|
+
|
|
6
|
+
// src/link-card.tsx
|
|
7
|
+
import { forwardRef } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var LinkCard = /* @__PURE__ */ forwardRef(
|
|
10
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("a", { ...props, ref, className: cx("om-link-card", className) })
|
|
11
|
+
);
|
|
12
|
+
LinkCard.displayName = "LinkCard";
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
LinkCard
|
|
16
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Toast,
|
|
4
|
+
ToastViewport
|
|
5
|
+
} from "./chunk-ITEJEMEF.js";
|
|
6
|
+
|
|
7
|
+
// src/toast-provider.tsx
|
|
8
|
+
import {
|
|
9
|
+
createContext,
|
|
10
|
+
forwardRef,
|
|
11
|
+
useCallback,
|
|
12
|
+
useContext,
|
|
13
|
+
useEffect,
|
|
14
|
+
useImperativeHandle,
|
|
15
|
+
useMemo,
|
|
16
|
+
useRef,
|
|
17
|
+
useState
|
|
18
|
+
} from "react";
|
|
19
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
20
|
+
var ToastContext = /* @__PURE__ */ createContext(null);
|
|
21
|
+
var useToast = () => {
|
|
22
|
+
const controller = useContext(ToastContext);
|
|
23
|
+
if (!controller) throw new Error("useToast requires a ToastProvider.");
|
|
24
|
+
return controller;
|
|
25
|
+
};
|
|
26
|
+
var activeElement = (node) => {
|
|
27
|
+
const root = node?.getRootNode();
|
|
28
|
+
const active = root?.activeElement ?? node?.ownerDocument.activeElement ?? null;
|
|
29
|
+
const view = node?.ownerDocument.defaultView;
|
|
30
|
+
return view && active instanceof view.HTMLElement ? active : null;
|
|
31
|
+
};
|
|
32
|
+
var capacityFor = (maxVisible) => Number.isFinite(maxVisible) ? Math.max(1, Math.floor(maxVisible)) : 4;
|
|
33
|
+
var durationFor = ({ tone, duration }) => {
|
|
34
|
+
if (duration === null) return null;
|
|
35
|
+
if (duration !== void 0 && Number.isFinite(duration) && duration > 0) return duration;
|
|
36
|
+
return tone === "warning" || tone === "danger" || tone === "error" || tone === "loading" ? null : 3e3;
|
|
37
|
+
};
|
|
38
|
+
var admit = (entries, capacity) => {
|
|
39
|
+
let slots = capacity - entries.filter(({ phase }) => phase !== "waiting").length;
|
|
40
|
+
if (slots <= 0 || !entries.some(({ phase }) => phase === "waiting")) return entries;
|
|
41
|
+
return entries.map((entry) => {
|
|
42
|
+
if (entry.phase !== "waiting" || slots <= 0) return entry;
|
|
43
|
+
slots -= 1;
|
|
44
|
+
return { ...entry, phase: "queued" };
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
var ManagedToast = ({ entry, paused, dismissLabel, register, open, dismiss, exited }) => {
|
|
48
|
+
const root = useRef(null);
|
|
49
|
+
const remaining = useRef(entry.duration);
|
|
50
|
+
const { id, phase, trigger, options } = entry;
|
|
51
|
+
const ref = useCallback((node) => {
|
|
52
|
+
root.current = node;
|
|
53
|
+
register(id, node ? { node, trigger } : null);
|
|
54
|
+
}, [id, trigger, register]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (phase !== "queued") return;
|
|
57
|
+
const view = root.current?.ownerDocument.defaultView;
|
|
58
|
+
if (!view) return;
|
|
59
|
+
if (typeof view.requestAnimationFrame !== "function") {
|
|
60
|
+
const timeout = view.setTimeout(() => open(id), 0);
|
|
61
|
+
return () => view.clearTimeout(timeout);
|
|
62
|
+
}
|
|
63
|
+
const frame = view.requestAnimationFrame(() => open(id));
|
|
64
|
+
return () => view.cancelAnimationFrame(frame);
|
|
65
|
+
}, [id, phase, open]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (phase !== "open" || paused || remaining.current === null) return;
|
|
68
|
+
const view = root.current?.ownerDocument.defaultView;
|
|
69
|
+
if (!view) return;
|
|
70
|
+
const time = remaining.current;
|
|
71
|
+
const started = Date.now();
|
|
72
|
+
const timeout = view.setTimeout(() => {
|
|
73
|
+
remaining.current = 0;
|
|
74
|
+
dismiss(id);
|
|
75
|
+
}, time);
|
|
76
|
+
return () => {
|
|
77
|
+
view.clearTimeout(timeout);
|
|
78
|
+
remaining.current = Math.max(0, time - (Date.now() - started));
|
|
79
|
+
};
|
|
80
|
+
}, [id, phase, paused, dismiss]);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (phase !== "closing") return;
|
|
83
|
+
const node = root.current;
|
|
84
|
+
const view = node?.ownerDocument.defaultView;
|
|
85
|
+
if (!node || !view) return;
|
|
86
|
+
const finish = () => {
|
|
87
|
+
if (node.dataset.state === "closed") exited(id);
|
|
88
|
+
};
|
|
89
|
+
if (node.dataset.state === "closed") {
|
|
90
|
+
finish();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (typeof view.MutationObserver !== "function") {
|
|
94
|
+
const timeout = view.setTimeout(() => exited(id), 250);
|
|
95
|
+
return () => view.clearTimeout(timeout);
|
|
96
|
+
}
|
|
97
|
+
const observer = new view.MutationObserver(finish);
|
|
98
|
+
observer.observe(node, { attributes: true, attributeFilter: ["data-state"] });
|
|
99
|
+
return () => observer.disconnect();
|
|
100
|
+
}, [id, phase, exited]);
|
|
101
|
+
return /* @__PURE__ */ jsx(
|
|
102
|
+
Toast,
|
|
103
|
+
{
|
|
104
|
+
ref,
|
|
105
|
+
open: phase === "open",
|
|
106
|
+
title: options.title,
|
|
107
|
+
tone: options.tone,
|
|
108
|
+
icon: options.icon,
|
|
109
|
+
dismissLabel: options.dismissLabel ?? dismissLabel,
|
|
110
|
+
onDismiss: () => dismiss(id),
|
|
111
|
+
"data-toast-id": id,
|
|
112
|
+
children: options.description
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
var ToastProvider = /* @__PURE__ */ forwardRef(
|
|
117
|
+
({
|
|
118
|
+
children,
|
|
119
|
+
maxVisible = 4,
|
|
120
|
+
dismissLabel = "Dismiss notification",
|
|
121
|
+
onPointerEnter,
|
|
122
|
+
onPointerLeave,
|
|
123
|
+
onFocusCapture,
|
|
124
|
+
onBlurCapture,
|
|
125
|
+
...props
|
|
126
|
+
}, ref) => {
|
|
127
|
+
const viewport = useRef(null);
|
|
128
|
+
useImperativeHandle(ref, () => viewport.current, []);
|
|
129
|
+
const regions = useRef(/* @__PURE__ */ new Map());
|
|
130
|
+
const nextId = useRef(0);
|
|
131
|
+
const [entries, setEntries] = useState([]);
|
|
132
|
+
const [hovered, setHovered] = useState(false);
|
|
133
|
+
const [focused, setFocused] = useState(false);
|
|
134
|
+
const capacity = capacityFor(maxVisible);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
setEntries((previous) => admit(previous, capacity));
|
|
137
|
+
}, [capacity]);
|
|
138
|
+
const register = useCallback((id, region) => {
|
|
139
|
+
if (region) regions.current.set(id, region);
|
|
140
|
+
else regions.current.delete(id);
|
|
141
|
+
}, []);
|
|
142
|
+
const open = useCallback((id) => {
|
|
143
|
+
setEntries((previous) => {
|
|
144
|
+
const target = previous.find((entry) => entry.id === id);
|
|
145
|
+
if (target?.phase !== "queued") return previous;
|
|
146
|
+
return previous.map((entry) => entry.id === id ? { ...entry, phase: "open" } : entry);
|
|
147
|
+
});
|
|
148
|
+
}, []);
|
|
149
|
+
const exited = useCallback((id) => {
|
|
150
|
+
setEntries((previous) => admit(previous.filter((entry) => entry.id !== id), capacity));
|
|
151
|
+
}, [capacity]);
|
|
152
|
+
const showToast = useCallback((options) => {
|
|
153
|
+
const id = String(++nextId.current);
|
|
154
|
+
const trigger = options.restoreFocusTo === void 0 ? activeElement(viewport.current) : options.restoreFocusTo;
|
|
155
|
+
setEntries((previous) => admit([
|
|
156
|
+
...previous,
|
|
157
|
+
{ id, options, duration: durationFor(options), phase: "waiting", trigger }
|
|
158
|
+
], capacity));
|
|
159
|
+
return id;
|
|
160
|
+
}, [capacity]);
|
|
161
|
+
const dismissToast = useCallback((id) => {
|
|
162
|
+
const region = regions.current.get(id);
|
|
163
|
+
if (region && region.node.contains(activeElement(region.node))) {
|
|
164
|
+
const remaining = Array.from(regions.current.entries()).reverse().find(
|
|
165
|
+
([otherId, value]) => otherId !== id && value.node.dataset.state === "open"
|
|
166
|
+
)?.[1].node.querySelector(".om-toast > button");
|
|
167
|
+
const target = remaining ?? region.trigger;
|
|
168
|
+
if (target?.isConnected) target.focus();
|
|
169
|
+
}
|
|
170
|
+
setEntries((previous) => {
|
|
171
|
+
const target = previous.find((entry) => entry.id === id);
|
|
172
|
+
if (!target || target.phase === "closing") return previous;
|
|
173
|
+
if (target.phase !== "open") return admit(previous.filter((entry) => entry.id !== id), capacity);
|
|
174
|
+
return previous.map((entry) => entry.id === id ? { ...entry, phase: "closing" } : entry);
|
|
175
|
+
});
|
|
176
|
+
}, [capacity]);
|
|
177
|
+
const controller = useMemo(() => ({ showToast, dismissToast }), [showToast, dismissToast]);
|
|
178
|
+
return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: controller, children: [
|
|
179
|
+
children,
|
|
180
|
+
/* @__PURE__ */ jsx(
|
|
181
|
+
ToastViewport,
|
|
182
|
+
{
|
|
183
|
+
...props,
|
|
184
|
+
ref: viewport,
|
|
185
|
+
onPointerEnter: (event) => {
|
|
186
|
+
onPointerEnter?.(event);
|
|
187
|
+
if (event.pointerType === "mouse") setHovered(true);
|
|
188
|
+
},
|
|
189
|
+
onPointerLeave: (event) => {
|
|
190
|
+
onPointerLeave?.(event);
|
|
191
|
+
setHovered(false);
|
|
192
|
+
},
|
|
193
|
+
onFocusCapture: (event) => {
|
|
194
|
+
onFocusCapture?.(event);
|
|
195
|
+
setFocused(true);
|
|
196
|
+
},
|
|
197
|
+
onBlurCapture: (event) => {
|
|
198
|
+
onBlurCapture?.(event);
|
|
199
|
+
setFocused(event.currentTarget.contains(event.relatedTarget));
|
|
200
|
+
},
|
|
201
|
+
children: entries.filter((entry) => entry.phase !== "waiting").map((entry) => /* @__PURE__ */ jsx(
|
|
202
|
+
ManagedToast,
|
|
203
|
+
{
|
|
204
|
+
entry,
|
|
205
|
+
paused: hovered || focused,
|
|
206
|
+
dismissLabel,
|
|
207
|
+
register,
|
|
208
|
+
open,
|
|
209
|
+
dismiss: dismissToast,
|
|
210
|
+
exited
|
|
211
|
+
},
|
|
212
|
+
entry.id
|
|
213
|
+
))
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
] });
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
ToastProvider.displayName = "ToastProvider";
|
|
220
|
+
|
|
221
|
+
export {
|
|
222
|
+
useToast,
|
|
223
|
+
ToastProvider
|
|
224
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
cx
|
|
4
|
+
} from "./chunk-54STG2JB.js";
|
|
5
|
+
|
|
6
|
+
// src/slider.tsx
|
|
7
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var finiteNumber = (value, fallback) => {
|
|
10
|
+
const number = typeof value === "number" || typeof value === "string" && value.trim() ? Number(value) : NaN;
|
|
11
|
+
return Number.isFinite(number) ? number : fallback;
|
|
12
|
+
};
|
|
13
|
+
var progress = (value, min, max) => {
|
|
14
|
+
const lower = finiteNumber(min, 0);
|
|
15
|
+
const upper = finiteNumber(max, 100);
|
|
16
|
+
const current = finiteNumber(value, lower + (upper - lower) / 2);
|
|
17
|
+
return `${upper > lower ? Math.min(100, Math.max(0, (current - lower) / (upper - lower) * 100)) : 0}%`;
|
|
18
|
+
};
|
|
19
|
+
var syncProgress = (input) => {
|
|
20
|
+
input.style.setProperty("--om-slider-progress", progress(input.valueAsNumber, input.min, input.max));
|
|
21
|
+
};
|
|
22
|
+
var Slider = forwardRef(({ className, onInput, style, ...props }, ref) => {
|
|
23
|
+
const inputRef = useRef(null);
|
|
24
|
+
useImperativeHandle(ref, () => inputRef.current, []);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (inputRef.current) syncProgress(inputRef.current);
|
|
27
|
+
});
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const input = inputRef.current;
|
|
30
|
+
const form = input?.form;
|
|
31
|
+
if (!input || !form) return;
|
|
32
|
+
const reset = () => queueMicrotask(() => {
|
|
33
|
+
if (inputRef.current === input) syncProgress(input);
|
|
34
|
+
});
|
|
35
|
+
form.addEventListener("reset", reset);
|
|
36
|
+
return () => form.removeEventListener("reset", reset);
|
|
37
|
+
}, [props.form]);
|
|
38
|
+
return /* @__PURE__ */ jsx(
|
|
39
|
+
"input",
|
|
40
|
+
{
|
|
41
|
+
...props,
|
|
42
|
+
ref: inputRef,
|
|
43
|
+
type: "range",
|
|
44
|
+
className: cx("om-slider", className),
|
|
45
|
+
style: { ...style, "--om-slider-progress": progress(props.value ?? props.defaultValue, props.min, props.max) },
|
|
46
|
+
onInput: (event) => {
|
|
47
|
+
if (props.value == null) syncProgress(event.currentTarget);
|
|
48
|
+
onInput?.(event);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
Slider.displayName = "Slider";
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
Slider
|
|
57
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ButtonProps } from './button.js';
|
|
4
|
+
|
|
5
|
+
type ClipboardState = 'idle' | 'pending' | 'copied' | 'error';
|
|
6
|
+
type ClipboardLabels = Record<ClipboardState, string>;
|
|
7
|
+
declare const copyText: (text: string) => Promise<void>;
|
|
8
|
+
type ClipboardButtonProps = Omit<ButtonProps, 'children'> & {
|
|
9
|
+
text: string;
|
|
10
|
+
labels?: ClipboardLabels;
|
|
11
|
+
children?: ReactNode | ((state: ClipboardState) => ReactNode);
|
|
12
|
+
resetDelay?: number | null;
|
|
13
|
+
announce?: boolean;
|
|
14
|
+
onCopied?: (text: string) => void;
|
|
15
|
+
onCopyError?: (error: unknown) => void;
|
|
16
|
+
};
|
|
17
|
+
declare const ClipboardButton: react.ForwardRefExoticComponent<Omit<ButtonProps, "children"> & {
|
|
18
|
+
text: string;
|
|
19
|
+
labels?: ClipboardLabels;
|
|
20
|
+
children?: ReactNode | ((state: ClipboardState) => ReactNode);
|
|
21
|
+
resetDelay?: number | null;
|
|
22
|
+
announce?: boolean;
|
|
23
|
+
onCopied?: (text: string) => void;
|
|
24
|
+
onCopyError?: (error: unknown) => void;
|
|
25
|
+
} & react.RefAttributes<HTMLButtonElement>>;
|
|
26
|
+
|
|
27
|
+
export { ClipboardButton, copyText };
|
|
28
|
+
export type { ClipboardButtonProps, ClipboardLabels, ClipboardState };
|