@oddmash/ui 0.4.0 → 0.5.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/button.d.ts +22 -7
- package/dist/button.js +9 -3
- package/dist/{chunk-BMVVSFAU.js → chunk-2H7CEOL5.js} +1 -1
- 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-TBR4HCBJ.js → chunk-ITEJEMEF.js} +12 -3
- package/dist/chunk-OJJPFVTC.js +154 -0
- package/dist/chunk-OUFCQ2JE.js +126 -0
- package/dist/chunk-QW7IHDAG.js +36 -0
- package/dist/chunk-U7RNP366.js +16 -0
- package/dist/chunk-URS474NU.js +228 -0
- package/dist/chunk-WHFF7XSS.js +224 -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 +9 -1
- package/dist/command-palette.js +1 -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 +108 -26
- 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/styles.css +707 -6
- package/dist/toast-provider.d.ts +30 -0
- package/dist/toast-provider.js +11 -0
- package/dist/toast.d.ts +5 -3
- package/dist/toast.js +1 -1
- package/package.json +45 -1
- package/dist/chunk-3TIYT55P.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,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
|
+
};
|
|
@@ -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,228 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Button
|
|
4
|
+
} from "./chunk-A3PPKK5J.js";
|
|
5
|
+
import {
|
|
6
|
+
cx
|
|
7
|
+
} from "./chunk-54STG2JB.js";
|
|
8
|
+
|
|
9
|
+
// src/docs-navigation.tsx
|
|
10
|
+
import {
|
|
11
|
+
forwardRef,
|
|
12
|
+
useEffect,
|
|
13
|
+
useId,
|
|
14
|
+
useRef,
|
|
15
|
+
useState
|
|
16
|
+
} from "react";
|
|
17
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
var isOrdinaryClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
|
|
19
|
+
var useDisclosure = (mobileLabel, defaultOpen = false) => {
|
|
20
|
+
const panelId = useId();
|
|
21
|
+
const toggle = useRef(null);
|
|
22
|
+
const [enhanced, setEnhanced] = useState(false);
|
|
23
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setEnhanced(true);
|
|
26
|
+
}, []);
|
|
27
|
+
const close = (event, heading) => {
|
|
28
|
+
if (!open || !isOrdinaryClick(event)) return;
|
|
29
|
+
setOpen(false);
|
|
30
|
+
const button = toggle.current;
|
|
31
|
+
const view = button?.ownerDocument.defaultView;
|
|
32
|
+
if (!button || view?.getComputedStyle(button).display === "none") return;
|
|
33
|
+
heading?.focus({ preventScroll: true });
|
|
34
|
+
if (!heading || button.ownerDocument.activeElement !== heading) button.focus({ preventScroll: true });
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
panelId,
|
|
38
|
+
toggle,
|
|
39
|
+
open,
|
|
40
|
+
setOpen,
|
|
41
|
+
close,
|
|
42
|
+
attributes: {
|
|
43
|
+
"data-enhanced": enhanced ? "true" : void 0,
|
|
44
|
+
"data-collapsible": mobileLabel ? "true" : void 0,
|
|
45
|
+
"data-expanded": String(open)
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var DocsNavigation = forwardRef(({
|
|
50
|
+
groups,
|
|
51
|
+
currentId,
|
|
52
|
+
mobileLabel,
|
|
53
|
+
defaultMobileOpen,
|
|
54
|
+
onNavigate,
|
|
55
|
+
className,
|
|
56
|
+
...props
|
|
57
|
+
}, ref) => {
|
|
58
|
+
const disclosure = useDisclosure(mobileLabel, defaultMobileOpen);
|
|
59
|
+
return /* @__PURE__ */ jsxs("nav", { ...props, ...disclosure.attributes, ref, className: cx("om-docs-navigation", className), children: [
|
|
60
|
+
mobileLabel && /* @__PURE__ */ jsx(
|
|
61
|
+
Button,
|
|
62
|
+
{
|
|
63
|
+
ref: disclosure.toggle,
|
|
64
|
+
className: "om-docs-toggle",
|
|
65
|
+
variant: "secondary",
|
|
66
|
+
size: "sm",
|
|
67
|
+
"aria-controls": disclosure.panelId,
|
|
68
|
+
"aria-expanded": disclosure.open,
|
|
69
|
+
onClick: () => disclosure.setOpen((open) => !open),
|
|
70
|
+
children: mobileLabel
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
/* @__PURE__ */ jsx("div", { className: "om-docs-panel", id: disclosure.panelId, children: groups.map((group) => /* @__PURE__ */ jsxs("div", { className: "om-docs-group", children: [
|
|
74
|
+
group.label && /* @__PURE__ */ jsx("p", { className: "om-docs-group-label", children: group.label }),
|
|
75
|
+
/* @__PURE__ */ jsx("ul", { className: "om-docs-links", role: "list", children: group.items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
76
|
+
"a",
|
|
77
|
+
{
|
|
78
|
+
href: item.href,
|
|
79
|
+
"aria-current": item.id === currentId ? "page" : void 0,
|
|
80
|
+
onClick: (event) => {
|
|
81
|
+
if (!isOrdinaryClick(event)) return;
|
|
82
|
+
onNavigate?.(item, event);
|
|
83
|
+
disclosure.close(event);
|
|
84
|
+
},
|
|
85
|
+
children: item.label
|
|
86
|
+
}
|
|
87
|
+
) }, item.id)) })
|
|
88
|
+
] }, group.id)) })
|
|
89
|
+
] });
|
|
90
|
+
});
|
|
91
|
+
DocsNavigation.displayName = "DocsNavigation";
|
|
92
|
+
var observeActiveHeading = (content, headingIds, onActiveChange, { offset = 0 } = {}) => {
|
|
93
|
+
const doc = content.ownerDocument;
|
|
94
|
+
const view = doc.defaultView;
|
|
95
|
+
if (!view) return () => {
|
|
96
|
+
};
|
|
97
|
+
const headings = () => headingIds.flatMap((id) => {
|
|
98
|
+
const heading = doc.getElementById(id);
|
|
99
|
+
return heading && content.contains(heading) ? [heading] : [];
|
|
100
|
+
});
|
|
101
|
+
let frame;
|
|
102
|
+
let active;
|
|
103
|
+
let disposed = false;
|
|
104
|
+
const publish = (next) => {
|
|
105
|
+
if (next === active) return;
|
|
106
|
+
active = next;
|
|
107
|
+
onActiveChange(next);
|
|
108
|
+
};
|
|
109
|
+
const update = () => {
|
|
110
|
+
frame = void 0;
|
|
111
|
+
if (disposed) return;
|
|
112
|
+
const sections = headings();
|
|
113
|
+
const bottom = view.scrollY > 0 && view.scrollY + view.innerHeight >= doc.documentElement.scrollHeight - 2;
|
|
114
|
+
if (bottom) {
|
|
115
|
+
publish(sections.at(-1)?.id);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const current = sections.slice().reverse().find((heading) => {
|
|
119
|
+
const margin = Number.parseFloat(view.getComputedStyle(heading).scrollMarginTop) || 0;
|
|
120
|
+
return heading.getBoundingClientRect().top <= Math.max(offset, margin) + 24;
|
|
121
|
+
});
|
|
122
|
+
publish(current?.id);
|
|
123
|
+
};
|
|
124
|
+
const schedule = () => {
|
|
125
|
+
if (frame !== void 0) return;
|
|
126
|
+
if (typeof view.requestAnimationFrame === "function") frame = view.requestAnimationFrame(update);
|
|
127
|
+
else update();
|
|
128
|
+
};
|
|
129
|
+
const syncHash = () => {
|
|
130
|
+
const hash = view.location.hash.slice(1);
|
|
131
|
+
let id = hash;
|
|
132
|
+
try {
|
|
133
|
+
id = decodeURIComponent(hash);
|
|
134
|
+
} catch {
|
|
135
|
+
id = hash;
|
|
136
|
+
}
|
|
137
|
+
const match = headings().find((heading) => heading.id === id);
|
|
138
|
+
if (match) publish(match.id);
|
|
139
|
+
else schedule();
|
|
140
|
+
};
|
|
141
|
+
const resize = typeof view.ResizeObserver === "undefined" ? void 0 : new view.ResizeObserver(schedule);
|
|
142
|
+
resize?.observe(content);
|
|
143
|
+
view.addEventListener("scroll", schedule, { passive: true });
|
|
144
|
+
view.addEventListener("resize", schedule);
|
|
145
|
+
view.addEventListener("hashchange", syncHash);
|
|
146
|
+
syncHash();
|
|
147
|
+
return () => {
|
|
148
|
+
disposed = true;
|
|
149
|
+
if (frame !== void 0) view.cancelAnimationFrame(frame);
|
|
150
|
+
resize?.disconnect();
|
|
151
|
+
view.removeEventListener("scroll", schedule);
|
|
152
|
+
view.removeEventListener("resize", schedule);
|
|
153
|
+
view.removeEventListener("hashchange", syncHash);
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
var useActiveHeading = (headingIds, {
|
|
157
|
+
contentId,
|
|
158
|
+
offset,
|
|
159
|
+
enabled = true
|
|
160
|
+
} = {}) => {
|
|
161
|
+
const [active, setActive] = useState();
|
|
162
|
+
const key = JSON.stringify(headingIds);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
setActive(void 0);
|
|
165
|
+
if (!enabled) return;
|
|
166
|
+
const content = contentId ? document.getElementById(contentId) : document.body;
|
|
167
|
+
if (!content) return;
|
|
168
|
+
return observeActiveHeading(content, JSON.parse(key), setActive, { offset });
|
|
169
|
+
}, [key, contentId, offset, enabled]);
|
|
170
|
+
return active;
|
|
171
|
+
};
|
|
172
|
+
var TableOfContents = forwardRef(({
|
|
173
|
+
headings,
|
|
174
|
+
label,
|
|
175
|
+
mobileLabel,
|
|
176
|
+
defaultMobileOpen,
|
|
177
|
+
contentId,
|
|
178
|
+
offset,
|
|
179
|
+
activeId,
|
|
180
|
+
onNavigate,
|
|
181
|
+
className,
|
|
182
|
+
...props
|
|
183
|
+
}, ref) => {
|
|
184
|
+
const observed = useActiveHeading(headings.map((heading) => heading.id), {
|
|
185
|
+
contentId,
|
|
186
|
+
offset,
|
|
187
|
+
enabled: activeId === void 0
|
|
188
|
+
});
|
|
189
|
+
const currentId = activeId === void 0 ? observed : activeId;
|
|
190
|
+
const disclosure = useDisclosure(mobileLabel, defaultMobileOpen);
|
|
191
|
+
return /* @__PURE__ */ jsxs("nav", { "aria-label": label, ...props, ...disclosure.attributes, ref, className: cx("om-table-of-contents", className), children: [
|
|
192
|
+
/* @__PURE__ */ jsx("p", { className: "om-toc-label", children: label }),
|
|
193
|
+
mobileLabel && /* @__PURE__ */ jsx(
|
|
194
|
+
Button,
|
|
195
|
+
{
|
|
196
|
+
ref: disclosure.toggle,
|
|
197
|
+
className: "om-docs-toggle",
|
|
198
|
+
variant: "secondary",
|
|
199
|
+
size: "sm",
|
|
200
|
+
"aria-controls": disclosure.panelId,
|
|
201
|
+
"aria-expanded": disclosure.open,
|
|
202
|
+
onClick: () => disclosure.setOpen((open) => !open),
|
|
203
|
+
children: mobileLabel
|
|
204
|
+
}
|
|
205
|
+
),
|
|
206
|
+
/* @__PURE__ */ jsx("ul", { className: "om-docs-panel om-toc-links", id: disclosure.panelId, role: "list", children: headings.map((heading) => /* @__PURE__ */ jsx("li", { "data-level": heading.level ?? 2, children: /* @__PURE__ */ jsx(
|
|
207
|
+
"a",
|
|
208
|
+
{
|
|
209
|
+
href: "#" + encodeURIComponent(heading.id),
|
|
210
|
+
"aria-current": heading.id === currentId ? "location" : void 0,
|
|
211
|
+
onClick: (event) => {
|
|
212
|
+
if (!isOrdinaryClick(event)) return;
|
|
213
|
+
onNavigate?.(heading, event);
|
|
214
|
+
disclosure.close(event, event.currentTarget.ownerDocument.getElementById(heading.id));
|
|
215
|
+
},
|
|
216
|
+
children: heading.label
|
|
217
|
+
}
|
|
218
|
+
) }, heading.id)) })
|
|
219
|
+
] });
|
|
220
|
+
});
|
|
221
|
+
TableOfContents.displayName = "TableOfContents";
|
|
222
|
+
|
|
223
|
+
export {
|
|
224
|
+
DocsNavigation,
|
|
225
|
+
observeActiveHeading,
|
|
226
|
+
useActiveHeading,
|
|
227
|
+
TableOfContents
|
|
228
|
+
};
|
|
@@ -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,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 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
|
|
4
|
+
type CodeBlockProps = ComponentPropsWithoutRef<'div'>;
|
|
5
|
+
declare const CodeBlock: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
type CodeBlockHeaderProps = ComponentPropsWithoutRef<'div'>;
|
|
7
|
+
declare const CodeBlockHeader: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
type CodeBlockCaptionProps = ComponentPropsWithoutRef<'span'>;
|
|
9
|
+
declare const CodeBlockCaption: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & react.RefAttributes<HTMLSpanElement>>;
|
|
10
|
+
type CodeBlockContentProps = ComponentPropsWithoutRef<'pre'>;
|
|
11
|
+
declare const CodeBlockContent: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLPreElement>, HTMLPreElement>, "ref"> & react.RefAttributes<HTMLPreElement>>;
|
|
12
|
+
type CodeBlockCopyProps = ComponentPropsWithoutRef<'button'>;
|
|
13
|
+
declare const CodeBlockCopy: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & react.RefAttributes<HTMLButtonElement>>;
|
|
14
|
+
|
|
15
|
+
export { CodeBlock, CodeBlockCaption, CodeBlockContent, CodeBlockCopy, CodeBlockHeader };
|
|
16
|
+
export type { CodeBlockCaptionProps, CodeBlockContentProps, CodeBlockCopyProps, CodeBlockHeaderProps, CodeBlockProps };
|