@oddmash/ui 0.4.1 → 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.
Files changed (48) hide show
  1. package/README.md +2 -1
  2. package/dist/alert.js +2 -2
  3. package/dist/button.d.ts +22 -7
  4. package/dist/button.js +9 -3
  5. package/dist/{chunk-BMVVSFAU.js → chunk-2H7CEOL5.js} +1 -1
  6. package/dist/chunk-77W2JTCK.js +116 -0
  7. package/dist/chunk-A3PPKK5J.js +23 -0
  8. package/dist/chunk-BAJCEDO3.js +17 -0
  9. package/dist/chunk-DOCL5Y45.js +14 -0
  10. package/dist/chunk-FKO6T5XG.js +71 -0
  11. package/dist/chunk-GRQMKQRL.js +21 -0
  12. package/dist/chunk-I5VJBLHP.js +36 -0
  13. package/dist/chunk-OJJPFVTC.js +154 -0
  14. package/dist/chunk-OUFCQ2JE.js +126 -0
  15. package/dist/chunk-QW7IHDAG.js +36 -0
  16. package/dist/chunk-U7RNP366.js +16 -0
  17. package/dist/chunk-URS474NU.js +228 -0
  18. package/dist/chunk-WHFF7XSS.js +224 -0
  19. package/dist/clipboard-button.d.ts +28 -0
  20. package/dist/clipboard-button.js +11 -0
  21. package/dist/code-block.d.ts +16 -0
  22. package/dist/code-block.js +16 -0
  23. package/dist/command-palette.d.ts +9 -1
  24. package/dist/command-palette.js +1 -1
  25. package/dist/docs-navigation.d.ts +64 -0
  26. package/dist/docs-navigation.js +15 -0
  27. package/dist/index.d.ts +12 -1
  28. package/dist/index.js +107 -25
  29. package/dist/kbd.d.ts +8 -0
  30. package/dist/kbd.js +8 -0
  31. package/dist/link-card.d.ts +8 -0
  32. package/dist/link-card.js +8 -0
  33. package/dist/locale-picker.d.ts +18 -0
  34. package/dist/locale-picker.js +9 -0
  35. package/dist/platform-link.d.ts +15 -0
  36. package/dist/platform-link.js +10 -0
  37. package/dist/prose.d.ts +10 -0
  38. package/dist/prose.js +10 -0
  39. package/dist/scroll-header.d.ts +17 -0
  40. package/dist/scroll-header.js +10 -0
  41. package/dist/site-layout.d.ts +16 -0
  42. package/dist/site-layout.js +16 -0
  43. package/dist/styles.css +693 -0
  44. package/dist/toast-provider.d.ts +30 -0
  45. package/dist/toast-provider.js +11 -0
  46. package/package.json +45 -1
  47. package/dist/chunk-3TIYT55P.js +0 -14
  48. package/dist/chunk-WODRU2UN.js +0 -69
package/README.md CHANGED
@@ -16,6 +16,7 @@ Oddmash UI is the shared interface foundation for Oddmash products. It gives sma
16
16
  - Light and dark themes that can be applied to a whole app or a single subtree.
17
17
  - A documentation site with live examples, API guidance, accessibility notes, and a token explorer.
18
18
  - An Interaction Lab that shows how the components work together in a developer-tool interface.
19
+ - Documentation and landing primitives for linked cards, code examples, site navigation, rendered Markdown, platform/icon links, copy feedback, managed notifications, language selection, scroll-aware headers, and grouped search, with static HTML class contracts.
19
20
 
20
21
  ## Who it is for
21
22
 
@@ -31,6 +32,6 @@ Oddmash UI is for focused tools such as Interaction Inspector: products that nee
31
32
 
32
33
  ## Current scope
33
34
 
34
- Oddmash UI is under active pre-1.0 development. Version 0.4.1 includes 24 component families, including Toast.
35
+ Oddmash UI is under active pre-1.0 development. Version 0.5.0 expands the shared library with documentation, landing, navigation and feedback components. React 18.3.1 and React 19 remain supported.
35
36
 
36
37
  [Docs](https://oddmash.github.io/oddmash-ui/) · [npm](https://www.npmjs.com/package/@oddmash/ui) · [GitHub](https://github.com/Oddmash/oddmash-ui) · [Contributor guide](CONTRIBUTING.md) · [MIT License](LICENSE)
package/dist/alert.js CHANGED
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  Alert,
4
4
  AlertDialog
5
- } from "./chunk-BMVVSFAU.js";
6
- import "./chunk-3TIYT55P.js";
5
+ } from "./chunk-2H7CEOL5.js";
6
+ import "./chunk-A3PPKK5J.js";
7
7
  import "./chunk-ME34NDSX.js";
8
8
  import "./chunk-54STG2JB.js";
9
9
  export {
package/dist/button.d.ts CHANGED
@@ -1,14 +1,29 @@
1
1
  import * as react from 'react';
2
2
  import { ComponentPropsWithoutRef } from 'react';
3
3
 
4
- type ButtonProps = ComponentPropsWithoutRef<'button'> & {
4
+ type ButtonAppearance = {
5
5
  variant?: 'primary' | 'secondary' | 'ghost';
6
6
  size?: 'sm' | 'md';
7
7
  };
8
- declare const Button: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
9
- variant?: "primary" | "secondary" | "ghost";
10
- size?: "sm" | "md";
11
- } & react.RefAttributes<HTMLButtonElement>>;
8
+ type ButtonProps = ComponentPropsWithoutRef<'button'> & ButtonAppearance;
9
+ declare const Button: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & ButtonAppearance & react.RefAttributes<HTMLButtonElement>>;
10
+ type ButtonLinkProps = ComponentPropsWithoutRef<'a'> & ButtonAppearance & {
11
+ href: string;
12
+ };
13
+ declare const ButtonLink: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "ref"> & ButtonAppearance & {
14
+ href: string;
15
+ } & react.RefAttributes<HTMLAnchorElement>>;
16
+ type IconControlName = {
17
+ 'aria-label': string;
18
+ 'aria-labelledby'?: string;
19
+ } | {
20
+ 'aria-label'?: string;
21
+ 'aria-labelledby': string;
22
+ };
23
+ type IconButtonProps = Omit<ButtonProps, 'aria-label' | 'aria-labelledby'> & IconControlName;
24
+ declare const IconButton: react.ForwardRefExoticComponent<IconButtonProps & react.RefAttributes<HTMLButtonElement>>;
25
+ type IconLinkProps = Omit<ButtonLinkProps, 'aria-label' | 'aria-labelledby'> & IconControlName;
26
+ declare const IconLink: react.ForwardRefExoticComponent<IconLinkProps & react.RefAttributes<HTMLAnchorElement>>;
12
27
 
13
- export { Button };
14
- export type { ButtonProps };
28
+ export { Button, ButtonLink, IconButton, IconLink };
29
+ export type { ButtonLinkProps, ButtonProps, IconButtonProps, IconControlName, IconLinkProps };
package/dist/button.js CHANGED
@@ -1,8 +1,14 @@
1
1
  "use client";
2
2
  import {
3
- Button
4
- } from "./chunk-3TIYT55P.js";
3
+ Button,
4
+ ButtonLink,
5
+ IconButton,
6
+ IconLink
7
+ } from "./chunk-A3PPKK5J.js";
5
8
  import "./chunk-54STG2JB.js";
6
9
  export {
7
- Button
10
+ Button,
11
+ ButtonLink,
12
+ IconButton,
13
+ IconLink
8
14
  };
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  Button
4
- } from "./chunk-3TIYT55P.js";
4
+ } from "./chunk-A3PPKK5J.js";
5
5
  import {
6
6
  Dialog,
7
7
  DialogContent,
@@ -0,0 +1,116 @@
1
+ "use client";
2
+ import {
3
+ Button
4
+ } from "./chunk-A3PPKK5J.js";
5
+ import {
6
+ cx
7
+ } from "./chunk-54STG2JB.js";
8
+
9
+ // src/clipboard-button.tsx
10
+ import {
11
+ forwardRef,
12
+ useEffect,
13
+ useImperativeHandle,
14
+ useRef,
15
+ useState
16
+ } from "react";
17
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
18
+ var defaultLabels = {
19
+ idle: "Copy",
20
+ pending: "Copying",
21
+ copied: "Copied",
22
+ error: "Could not copy. Select the text and copy it manually."
23
+ };
24
+ var copyText = async (text) => {
25
+ const clipboard = globalThis.navigator?.clipboard;
26
+ if (!clipboard || typeof clipboard.writeText !== "function") {
27
+ throw new Error("Clipboard writing is unavailable.");
28
+ }
29
+ await clipboard.writeText(text);
30
+ };
31
+ var ClipboardButton = /* @__PURE__ */ forwardRef(
32
+ ({
33
+ text,
34
+ labels = defaultLabels,
35
+ children,
36
+ resetDelay = 2500,
37
+ announce = true,
38
+ onCopied,
39
+ onCopyError,
40
+ onClick,
41
+ className,
42
+ variant = "secondary",
43
+ ...props
44
+ }, ref) => {
45
+ const [state, setState] = useState("idle");
46
+ const button = useRef(null);
47
+ useImperativeHandle(ref, () => button.current, []);
48
+ const currentText = useRef(text);
49
+ const pending = useRef(false);
50
+ const reset = useRef(void 0);
51
+ useEffect(() => () => clearTimeout(reset.current), []);
52
+ useEffect(() => {
53
+ currentText.current = text;
54
+ clearTimeout(reset.current);
55
+ if (!pending.current) setState("idle");
56
+ }, [text]);
57
+ const click = (event) => {
58
+ onClick?.(event);
59
+ if (event.defaultPrevented || pending.current || props.disabled) return;
60
+ pending.current = true;
61
+ clearTimeout(reset.current);
62
+ setState("pending");
63
+ const complete = async () => {
64
+ let result;
65
+ try {
66
+ await copyText(text);
67
+ result = { ok: true };
68
+ } catch (error) {
69
+ result = { ok: false, error };
70
+ }
71
+ pending.current = false;
72
+ if (!button.current) return;
73
+ if (currentText.current !== text) {
74
+ setState("idle");
75
+ return;
76
+ }
77
+ if (result.ok) {
78
+ setState("copied");
79
+ if (resetDelay !== null && Number.isFinite(resetDelay) && resetDelay >= 0) {
80
+ reset.current = setTimeout(() => {
81
+ if (button.current && !pending.current && currentText.current === text) setState("idle");
82
+ }, resetDelay);
83
+ }
84
+ onCopied?.(text);
85
+ } else {
86
+ setState("error");
87
+ onCopyError?.(result.error);
88
+ }
89
+ };
90
+ void complete();
91
+ };
92
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
93
+ /* @__PURE__ */ jsx(
94
+ Button,
95
+ {
96
+ ...props,
97
+ ref: button,
98
+ variant,
99
+ className: cx("om-clipboard-button", className),
100
+ onClick: click,
101
+ "aria-busy": state === "pending" || props["aria-busy"],
102
+ "aria-label": props["aria-label"] ?? labels[state],
103
+ "data-copy-state": state,
104
+ children: typeof children === "function" ? children(state) : children ?? labels[state]
105
+ }
106
+ ),
107
+ announce && /* @__PURE__ */ jsx("span", { className: "om-clipboard-announcement", role: "status", "aria-atomic": "true", children: state === "copied" || state === "error" ? labels[state] : "" })
108
+ ] });
109
+ }
110
+ );
111
+ ClipboardButton.displayName = "ClipboardButton";
112
+
113
+ export {
114
+ copyText,
115
+ ClipboardButton
116
+ };
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import {
3
+ cx
4
+ } from "./chunk-54STG2JB.js";
5
+
6
+ // src/button.tsx
7
+ import { forwardRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var Button = /* @__PURE__ */ forwardRef(({ className, variant = "primary", size = "md", type = "button", ...props }, ref) => /* @__PURE__ */ jsx("button", { ...props, ref, type, className: cx("om-button", `om-button--${variant}`, `om-button--${size}`, className) }));
10
+ Button.displayName = "Button";
11
+ var ButtonLink = /* @__PURE__ */ forwardRef(({ className, variant = "primary", size = "md", ...props }, ref) => /* @__PURE__ */ jsx("a", { ...props, ref, className: cx("om-button", "om-button--link", `om-button--${variant}`, `om-button--${size}`, className) }));
12
+ ButtonLink.displayName = "ButtonLink";
13
+ var IconButton = /* @__PURE__ */ forwardRef(({ className, variant = "ghost", ...props }, ref) => /* @__PURE__ */ jsx(Button, { ...props, ref, variant, className: cx("om-button--icon", className) }));
14
+ IconButton.displayName = "IconButton";
15
+ var IconLink = /* @__PURE__ */ forwardRef(({ className, variant = "ghost", ...props }, ref) => /* @__PURE__ */ jsx(ButtonLink, { ...props, ref, variant, className: cx("om-button--icon", className) }));
16
+ IconLink.displayName = "IconLink";
17
+
18
+ export {
19
+ Button,
20
+ ButtonLink,
21
+ IconButton,
22
+ IconLink
23
+ };
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import {
3
+ cx
4
+ } from "./chunk-54STG2JB.js";
5
+
6
+ // src/platform-link.tsx
7
+ import { forwardRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var PlatformLink = /* @__PURE__ */ forwardRef(({ className, platform, ...props }, ref) => /* @__PURE__ */ jsx("a", { ...props, ref, className: cx("om-platform-link", className), "data-platform": platform, children: platform === "github" ? /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "24", height: "24", "aria-hidden": "true", focusable: "false", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M12 1.3a10.7 10.7 0 0 0-3.38 20.85c.54.1.73-.23.73-.52V19.6c-2.98.65-3.61-1.27-3.61-1.27-.49-1.23-1.19-1.56-1.19-1.56-.97-.67.08-.66.08-.66 1.08.08 1.65 1.11 1.65 1.11.95 1.64 2.49 1.16 3.1.89.1-.69.37-1.16.67-1.43-2.38-.27-4.88-1.19-4.88-5.29 0-1.17.42-2.13 1.1-2.88-.11-.27-.48-1.36.11-2.84 0 0 .9-.29 2.94 1.1a10.2 10.2 0 0 1 5.36 0c2.04-1.39 2.93-1.1 2.93-1.1.59 1.48.22 2.57.11 2.84.68.75 1.1 1.71 1.1 2.88 0 4.11-2.51 5.01-4.9 5.28.39.34.73 1 .73 2.01v2.95c0 .29.19.63.74.52A10.7 10.7 0 0 0 12 1.3Z" }) }) : /* @__PURE__ */ jsx("svg", { viewBox: "0 0 32 12", width: "32", height: "12", "aria-hidden": "true", focusable: "false", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { fillRule: "evenodd", d: "M0 0H32V12H0ZM2 2V10H4V4H6V10H8V2ZM10 2V10H12V8H18V2ZM12 4H16V6H12ZM20 2V10H22V4H24V10H26V4H28V10H30V2Z" }) }) }));
10
+ PlatformLink.displayName = "PlatformLink";
11
+ var PlatformLinks = /* @__PURE__ */ forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ...props, ref, className: cx("om-platform-links", className) }));
12
+ PlatformLinks.displayName = "PlatformLinks";
13
+
14
+ export {
15
+ PlatformLink,
16
+ PlatformLinks
17
+ };
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import {
3
+ cx
4
+ } from "./chunk-54STG2JB.js";
5
+
6
+ // src/kbd.tsx
7
+ import { forwardRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var Kbd = /* @__PURE__ */ forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("kbd", { ...props, ref, className: cx("om-kbd", className) }));
10
+ Kbd.displayName = "Kbd";
11
+
12
+ export {
13
+ Kbd
14
+ };
@@ -0,0 +1,71 @@
1
+ "use client";
2
+ import {
3
+ Select
4
+ } from "./chunk-Z6HKBFCS.js";
5
+ import {
6
+ cx
7
+ } from "./chunk-54STG2JB.js";
8
+
9
+ // src/locale-picker.tsx
10
+ import {
11
+ forwardRef,
12
+ useEffect,
13
+ useImperativeHandle,
14
+ useRef,
15
+ useState
16
+ } from "react";
17
+ import { jsx, jsxs } from "react/jsx-runtime";
18
+ var LocalePicker = forwardRef(({
19
+ label,
20
+ options,
21
+ value,
22
+ onValueChange,
23
+ className,
24
+ selectProps
25
+ }, ref) => {
26
+ const fallback = useRef(null);
27
+ const trigger = useRef(null);
28
+ const transferFocus = useRef(false);
29
+ const [enhanced, setEnhanced] = useState(false);
30
+ const current = options.find((option) => option.value === value);
31
+ useImperativeHandle(ref, () => trigger.current, [enhanced]);
32
+ useEffect(() => {
33
+ const element = fallback.current;
34
+ transferFocus.current = Boolean(element?.contains(element.ownerDocument.activeElement));
35
+ setEnhanced(true);
36
+ }, []);
37
+ useEffect(() => {
38
+ if (enhanced && transferFocus.current) {
39
+ trigger.current?.focus({ preventScroll: true });
40
+ transferFocus.current = false;
41
+ }
42
+ }, [enhanced]);
43
+ return /* @__PURE__ */ jsxs("div", { className: cx("om-locale-picker", className), children: [
44
+ /* @__PURE__ */ jsxs("details", { ref: fallback, className: "om-locale-fallback", hidden: enhanced, children: [
45
+ /* @__PURE__ */ jsx("summary", { "aria-label": label, "aria-disabled": selectProps?.disabled || void 0, lang: current?.lang, children: current?.label ?? label }),
46
+ /* @__PURE__ */ jsx("ul", { className: "om-locale-options", role: "list", children: options.map((option) => /* @__PURE__ */ jsx("li", { lang: option.lang, children: option.disabled || selectProps?.disabled ? /* @__PURE__ */ jsx("span", { "aria-disabled": "true", children: option.label }) : /* @__PURE__ */ jsx("a", { href: option.href, hrefLang: option.lang, "aria-current": option.value === value ? "page" : void 0, children: option.label }) }, option.value)) })
47
+ ] }),
48
+ enhanced && /* @__PURE__ */ jsx(
49
+ Select,
50
+ {
51
+ ...selectProps,
52
+ ref: trigger,
53
+ "aria-label": label,
54
+ lang: selectProps?.lang ?? current?.lang,
55
+ options,
56
+ value,
57
+ onValueChange: (next) => {
58
+ const option = options.find((item) => item.value === next && !item.disabled);
59
+ if (!option) return;
60
+ if (onValueChange) onValueChange(next, option);
61
+ else trigger.current?.ownerDocument.defaultView?.location.assign(option.href);
62
+ }
63
+ }
64
+ )
65
+ ] });
66
+ });
67
+ LocalePicker.displayName = "LocalePicker";
68
+
69
+ export {
70
+ LocalePicker
71
+ };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import {
3
+ cx
4
+ } from "./chunk-54STG2JB.js";
5
+
6
+ // src/prose.tsx
7
+ import { forwardRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var Prose = /* @__PURE__ */ forwardRef(
10
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx("article", { ...props, ref, className: cx("om-prose", className) })
11
+ );
12
+ Prose.displayName = "Prose";
13
+ var ProseScroll = /* @__PURE__ */ forwardRef(
14
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ...props, ref, className: cx("om-prose-scroll", className) })
15
+ );
16
+ ProseScroll.displayName = "ProseScroll";
17
+
18
+ export {
19
+ Prose,
20
+ ProseScroll
21
+ };
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import {
3
+ cx
4
+ } from "./chunk-54STG2JB.js";
5
+
6
+ // src/code-block.tsx
7
+ import { forwardRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var CodeBlock = /* @__PURE__ */ forwardRef(
10
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ...props, ref, className: cx("om-code-block", className) })
11
+ );
12
+ CodeBlock.displayName = "CodeBlock";
13
+ var CodeBlockHeader = /* @__PURE__ */ forwardRef(
14
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ...props, ref, className: cx("om-code-block-header", className) })
15
+ );
16
+ CodeBlockHeader.displayName = "CodeBlockHeader";
17
+ var CodeBlockCaption = /* @__PURE__ */ forwardRef(
18
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx("span", { ...props, ref, className: cx("om-code-block-caption", className) })
19
+ );
20
+ CodeBlockCaption.displayName = "CodeBlockCaption";
21
+ var CodeBlockContent = /* @__PURE__ */ forwardRef(
22
+ ({ className, ...props }, ref) => /* @__PURE__ */ jsx("pre", { ...props, ref, className: cx("om-code-block-content", className) })
23
+ );
24
+ CodeBlockContent.displayName = "CodeBlockContent";
25
+ var CodeBlockCopy = /* @__PURE__ */ forwardRef(
26
+ ({ className, type = "button", ...props }, ref) => /* @__PURE__ */ jsx("button", { ...props, ref, type, className: cx("om-code-block-copy", className) })
27
+ );
28
+ CodeBlockCopy.displayName = "CodeBlockCopy";
29
+
30
+ export {
31
+ CodeBlock,
32
+ CodeBlockHeader,
33
+ CodeBlockCaption,
34
+ CodeBlockContent,
35
+ CodeBlockCopy
36
+ };
@@ -0,0 +1,154 @@
1
+ "use client";
2
+ import {
3
+ Dialog,
4
+ DialogContent,
5
+ DialogDescription,
6
+ DialogTitle,
7
+ DialogTrigger
8
+ } from "./chunk-ME34NDSX.js";
9
+ import {
10
+ Input
11
+ } from "./chunk-5NGRPREI.js";
12
+
13
+ // src/command-palette.tsx
14
+ import { useCallback, useEffect, useId, useMemo, useState } from "react";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var defaultFilter = (item, query) => [item.label, item.description, item.group, ...item.keywords ?? []].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase());
17
+ var CommandPalette = ({
18
+ trigger,
19
+ title,
20
+ description,
21
+ searchLabel,
22
+ emptyLabel,
23
+ items,
24
+ theme,
25
+ container,
26
+ open: controlledOpen,
27
+ defaultOpen = false,
28
+ onOpenChange,
29
+ shortcut = false,
30
+ maxResults,
31
+ filter = defaultFilter
32
+ }) => {
33
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
34
+ const [query, setQuery] = useState("");
35
+ const [active, setActive] = useState(null);
36
+ const open = controlledOpen ?? internalOpen;
37
+ const id = useId();
38
+ const setOpen = useCallback((value) => {
39
+ if (controlledOpen === void 0) setInternalOpen(value);
40
+ onOpenChange?.(value);
41
+ if (!value) {
42
+ setQuery("");
43
+ setActive(null);
44
+ }
45
+ }, [controlledOpen, onOpenChange]);
46
+ useEffect(() => {
47
+ if (!open) {
48
+ setQuery("");
49
+ setActive(null);
50
+ }
51
+ }, [open]);
52
+ useEffect(() => {
53
+ if (!shortcut) return;
54
+ const owner = container?.ownerDocument ?? document;
55
+ const onKeyDown = (event) => {
56
+ if (event.defaultPrevented || event.isComposing || event.repeat || event.altKey || event.shiftKey || !event.metaKey && !event.ctrlKey || event.key.toLowerCase() !== "k") return;
57
+ event.preventDefault();
58
+ if (!open) setOpen(true);
59
+ };
60
+ owner.addEventListener("keydown", onKeyDown);
61
+ return () => owner.removeEventListener("keydown", onKeyDown);
62
+ }, [container, open, setOpen, shortcut]);
63
+ const groups = useMemo(() => {
64
+ const matches = items.filter((item) => filter(item, query.trim()));
65
+ const limit = maxResults === void 0 ? matches.length : Math.max(0, Math.floor(maxResults));
66
+ const result = /* @__PURE__ */ new Map();
67
+ for (const item of matches.slice(0, limit)) {
68
+ const group = item.group || void 0;
69
+ if (!result.has(group)) result.set(group, []);
70
+ result.get(group).push(item);
71
+ }
72
+ return Array.from(result, ([label, entries]) => ({ label, entries }));
73
+ }, [filter, items, maxResults, query]);
74
+ const list = useMemo(() => groups.flatMap((group) => group.entries), [groups]);
75
+ const available = list.filter((item) => !item.disabled);
76
+ const selected = available.find((item) => item.id === active) ?? available[0];
77
+ const optionId = (item) => `${id}-${list.indexOf(item)}`;
78
+ useEffect(() => {
79
+ if (open && selected) {
80
+ const owner = container?.ownerDocument ?? document;
81
+ owner.getElementById(`${id}-${list.indexOf(selected)}`)?.scrollIntoView?.({ block: "nearest" });
82
+ }
83
+ }, [container, open, selected, id, list]);
84
+ const select = (item) => {
85
+ if (item.disabled) return;
86
+ setOpen(false);
87
+ item.onSelect();
88
+ };
89
+ const renderOption = (item) => /* @__PURE__ */ jsxs(
90
+ "div",
91
+ {
92
+ id: optionId(item),
93
+ role: "option",
94
+ "aria-label": item.label,
95
+ "aria-describedby": item.description ? `${optionId(item)}-description` : void 0,
96
+ "aria-selected": selected?.id === item.id,
97
+ "aria-disabled": item.disabled || void 0,
98
+ onPointerMove: () => {
99
+ if (!item.disabled) setActive(item.id);
100
+ },
101
+ onMouseDown: (event) => event.preventDefault(),
102
+ onClick: () => select(item),
103
+ children: [
104
+ /* @__PURE__ */ jsx("span", { className: "om-command-label", children: item.label }),
105
+ item.description && /* @__PURE__ */ jsx("span", { id: `${optionId(item)}-description`, className: "om-command-description", children: item.description })
106
+ ]
107
+ },
108
+ item.id
109
+ );
110
+ return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange: setOpen, children: [
111
+ /* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: trigger }),
112
+ /* @__PURE__ */ jsxs(DialogContent, { theme, container, className: "om-command-palette", children: [
113
+ /* @__PURE__ */ jsx(DialogTitle, { children: title }),
114
+ /* @__PURE__ */ jsx(DialogDescription, { children: description }),
115
+ /* @__PURE__ */ jsx(
116
+ Input,
117
+ {
118
+ role: "combobox",
119
+ "aria-label": searchLabel,
120
+ "aria-autocomplete": "list",
121
+ "aria-expanded": "true",
122
+ "aria-controls": id,
123
+ "aria-activedescendant": selected ? optionId(selected) : void 0,
124
+ value: query,
125
+ onChange: (event) => {
126
+ setQuery(event.target.value);
127
+ setActive(null);
128
+ },
129
+ onKeyDown: (event) => {
130
+ if (event.nativeEvent.isComposing) return;
131
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
132
+ event.preventDefault();
133
+ if (!available.length) return;
134
+ const index = selected ? available.indexOf(selected) : 0;
135
+ setActive(available[(index + (event.key === "ArrowDown" ? 1 : available.length - 1)) % available.length].id);
136
+ } else if (event.key === "Enter" && selected && !event.nativeEvent.isComposing) {
137
+ event.preventDefault();
138
+ select(selected);
139
+ }
140
+ }
141
+ }
142
+ ),
143
+ /* @__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: [
144
+ /* @__PURE__ */ jsx("div", { "aria-hidden": "true", className: "om-command-group-label", children: group.label }),
145
+ group.entries.map(renderOption)
146
+ ] }, group.label) : group.entries.map(renderOption)) }),
147
+ !list.length && /* @__PURE__ */ jsx("p", { role: "status", children: emptyLabel })
148
+ ] })
149
+ ] });
150
+ };
151
+
152
+ export {
153
+ CommandPalette
154
+ };