@alea-design/ui 0.8.1 → 0.8.2

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.
@@ -1,93 +1,118 @@
1
1
  "use client";
2
- import { jsx as n, jsxs as m } from "react/jsx-runtime";
3
- import { forwardRef as B, useState as N, useEffect as D, useMemo as j, useRef as J } from "react";
4
- import { cx as P } from "../../utils/cx.js";
5
- import { useFilter as Y, Autocomplete as Z, SearchField as Q, Input as G, Menu as ee, MenuSection as te, Header as ne, Collection as se, MenuItem as z, Keyboard as ie } from "react-aria-components";
6
- import { Search as ae } from "lucide-react";
7
- import { DialogModal as le, Dialog as oe } from "../overlay/Overlay.js";
8
- import { Kbd as re } from "../typography/Typography.js";
2
+ import { jsx as n, jsxs as b } from "react/jsx-runtime";
3
+ import { forwardRef as $, useState as y, useEffect as K, useMemo as x, useRef as B } from "react";
4
+ import { cx as J } from "../../utils/cx.js";
5
+ import { useFilter as Y, Autocomplete as Z, SearchField as Q, Input as G, Menu as ee, MenuSection as te, Header as ne, Collection as ie, MenuItem as D, Keyboard as ae } from "react-aria-components";
6
+ import { Search as se } from "lucide-react";
7
+ import { DialogModal as oe, Dialog as re } from "../overlay/Overlay.js";
8
+ import { Kbd as le } from "../typography/Typography.js";
9
9
  import { useStrings as ce } from "../../i18n/strings.js";
10
- const M = "__more:";
11
- function de({ children: K }) {
12
- const o = J(null), [h, w] = N(!1);
13
- return D(() => {
14
- const a = o.current;
15
- if (!a) return;
16
- const f = () => w(a.scrollHeight > a.clientHeight + 1);
17
- if (f(), typeof ResizeObserver > "u") return;
18
- const c = new ResizeObserver(f);
19
- return c.observe(a), a.firstElementChild && c.observe(a.firstElementChild), () => c.disconnect();
20
- }, []), /* @__PURE__ */ n("div", { ref: o, className: "alea-command-scroll", tabIndex: h ? 0 : void 0, children: K });
10
+ const A = "__more:";
11
+ function de({ children: C }) {
12
+ const d = B(null), [N, g] = y(!1);
13
+ return K(() => {
14
+ const o = d.current;
15
+ if (!o) return;
16
+ const r = () => g(o.scrollHeight > o.clientHeight + 1);
17
+ if (r(), typeof ResizeObserver > "u") return;
18
+ const c = new ResizeObserver(r);
19
+ return c.observe(o), o.firstElementChild && c.observe(o.firstElementChild), () => c.disconnect();
20
+ }, []), K(() => {
21
+ var h;
22
+ const o = d.current;
23
+ if (!o) return;
24
+ const r = (h = o.closest(".alea-command")) == null ? void 0 : h.querySelector(".alea-command-input");
25
+ if (!r) return;
26
+ const c = () => o.querySelector('[role="menuitem"][data-focused]'), v = () => {
27
+ var m;
28
+ const i = ((m = c()) == null ? void 0 : m.id) ?? null;
29
+ r.getAttribute("aria-activedescendant") !== i && (i ? r.setAttribute("aria-activedescendant", i) : r.removeAttribute("aria-activedescendant"));
30
+ }, u = new MutationObserver(v);
31
+ u.observe(o, { subtree: !0, childList: !0, attributes: !0, attributeFilter: ["data-focused"] }), u.observe(r, { attributes: !0, attributeFilter: ["aria-activedescendant"] });
32
+ const f = (i) => {
33
+ var m;
34
+ if (i.key === "Enter") {
35
+ if (i.isComposing || i.keyCode === 229) {
36
+ i.stopPropagation();
37
+ return;
38
+ }
39
+ i.preventDefault(), i.stopPropagation(), (m = c()) == null || m.click();
40
+ }
41
+ };
42
+ return r.addEventListener("keydown", f), v(), () => {
43
+ u.disconnect(), r.removeEventListener("keydown", f);
44
+ };
45
+ }, []), /* @__PURE__ */ n("div", { ref: d, className: "alea-command-scroll", tabIndex: N ? 0 : void 0, children: C });
21
46
  }
22
- const ve = B(function({ commands: o, isOpen: h, defaultOpen: w, onOpenChange: a, motion: f, hotkey: c = !0, slashHotkey: R, onQueryChange: b, filter: p, isLoading: v, maxPerGroup: d, placeholder: I, emptyText: k, className: F, style: L, surface: T, radius: V }, H) {
47
+ const Ne = $(function({ commands: d, isOpen: N, defaultOpen: g, onOpenChange: o, motion: r, hotkey: c = !0, slashHotkey: v, onQueryChange: u, filter: f, isLoading: h, maxPerGroup: i, placeholder: m, emptyText: R, className: j, style: z, surface: O, radius: T }, V) {
23
48
  const l = ce();
24
- I ?? (I = l.commandPlaceholder), k ?? (k = l.noResults);
25
- const [O, _] = N(w ?? !1), g = h ?? O, [r, U] = N(""), [x, A] = N(/* @__PURE__ */ new Set()), C = (i) => {
26
- U(i), b == null || b(i);
27
- }, S = (i) => {
28
- i || (r && C(""), A(/* @__PURE__ */ new Set())), h === void 0 && _(i), a == null || a(i);
49
+ m ?? (m = l.commandPlaceholder), R ?? (R = l.noResults);
50
+ const [q, H] = y(g ?? !1), S = N ?? q, [p, P] = y(""), [F, I] = y(/* @__PURE__ */ new Set()), L = (s) => {
51
+ P(s), u == null || u(s);
52
+ }, E = (s) => {
53
+ s || (p && L(""), I(/* @__PURE__ */ new Set())), N === void 0 && H(s), o == null || o(s);
29
54
  };
30
- D(() => {
31
- if (!c && !R) return;
32
- const i = (t) => {
55
+ K(() => {
56
+ if (!c && !v) return;
57
+ const s = (t) => {
33
58
  if (c && t.key.toLowerCase() === "k" && (t.metaKey || t.ctrlKey)) {
34
- t.preventDefault(), S(!g);
59
+ t.preventDefault(), E(!S);
35
60
  return;
36
61
  }
37
- if (R && !g && t.key === "/" && !t.metaKey && !t.ctrlKey && !t.altKey) {
62
+ if (v && !S && t.key === "/" && !t.metaKey && !t.ctrlKey && !t.altKey) {
38
63
  const e = t.target;
39
64
  if (e && (e.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName))) return;
40
- t.preventDefault(), S(!0);
65
+ t.preventDefault(), E(!0);
41
66
  }
42
67
  };
43
- return window.addEventListener("keydown", i), () => window.removeEventListener("keydown", i);
68
+ return window.addEventListener("keydown", s), () => window.removeEventListener("keydown", s);
44
69
  });
45
- const { contains: W } = Y({ sensitivity: "base" }), { groups: y, total: X } = j(() => {
46
- const i = (s) => p === !1 || !r ? !0 : p ? p(s, r) : W([s.label, ...s.keywords || []].join(" "), r), t = [];
70
+ const { contains: W } = Y({ sensitivity: "base" }), { groups: k, total: _ } = x(() => {
71
+ const s = (a) => f === !1 || !p ? !0 : f ? f(a, p) : W([a.label, ...a.keywords || []].join(" "), p), t = [];
47
72
  let e = 0;
48
- for (const s of o) {
49
- if (!i(s)) continue;
73
+ for (const a of d) {
74
+ if (!s(a)) continue;
50
75
  e++;
51
- const u = s.group || "";
52
- let E = t.find((q) => q.id === u);
53
- E || t.push(E = { id: u, title: u, items: [] }), E.items.push(s);
76
+ const w = a.group || "";
77
+ let M = t.find((X) => X.id === w);
78
+ M || t.push(M = { id: w, title: w, items: [] }), M.items.push(a);
54
79
  }
55
- if (d && d > 0) for (const s of t) {
56
- if (x.has(s.id) || s.items.length <= d) continue;
57
- const u = s.items.length - d;
58
- s.items = [...s.items.slice(0, d), { id: M + s.id, more: u, group: s.id }];
80
+ if (i && i > 0) for (const a of t) {
81
+ if (F.has(a.id) || a.items.length <= i) continue;
82
+ const w = a.items.length - i;
83
+ a.items = [...a.items.slice(0, i), { id: A + a.id, more: w, group: a.id }];
59
84
  }
60
85
  return { groups: t, total: e };
61
- }, [o, r, p, d, x]), $ = j(() => new Map(o.map((i) => [i.id, i])), [o]);
62
- return /* @__PURE__ */ n(le, { isOpen: g, onOpenChange: S, size: "md", className: "alea-command-overlay", motion: f, surface: T, radius: V, children: /* @__PURE__ */ n(oe, { ref: H, style: L, "aria-label": l.commandPalette, hideClose: !0, className: P("alea-command", F), children: ({ close: i }) => /* @__PURE__ */ m(Z, { inputValue: r, onInputChange: C, filter: () => !0, children: [
63
- /* @__PURE__ */ m(Q, { "aria-label": l.searchCommands, autoFocus: !0, className: "alea-command-search", children: [
64
- /* @__PURE__ */ n(ae, { size: 18, "aria-hidden": "true" }),
65
- /* @__PURE__ */ n(G, { placeholder: I, className: "alea-command-input" }),
66
- /* @__PURE__ */ n(re, { children: l.esc })
86
+ }, [d, p, f, i, F]), U = x(() => new Map(d.map((s) => [s.id, s])), [d]);
87
+ return /* @__PURE__ */ n(oe, { isOpen: S, onOpenChange: E, size: "md", className: "alea-command-overlay", motion: r, surface: O, radius: T, children: /* @__PURE__ */ n(re, { ref: V, style: z, "aria-label": l.commandPalette, hideClose: !0, className: J("alea-command", j), children: ({ close: s }) => /* @__PURE__ */ b(Z, { inputValue: p, onInputChange: L, filter: () => !0, children: [
88
+ /* @__PURE__ */ b(Q, { "aria-label": l.searchCommands, autoFocus: !0, className: "alea-command-search", children: [
89
+ /* @__PURE__ */ n(se, { size: 18, "aria-hidden": "true" }),
90
+ /* @__PURE__ */ n(G, { placeholder: m, className: "alea-command-input" }),
91
+ /* @__PURE__ */ n(le, { children: l.esc })
67
92
  ] }),
68
- /* @__PURE__ */ m(de, { children: [
69
- y.length > 0 && /* @__PURE__ */ n(ee, { items: y, className: "alea-command-list", "aria-busy": v || void 0, onAction: (t) => {
70
- if (String(t).startsWith(M)) {
71
- A((s) => new Set(s).add(String(t).slice(M.length)));
93
+ /* @__PURE__ */ b(de, { children: [
94
+ k.length > 0 && /* @__PURE__ */ n(ee, { shouldFocusWrap: !1, items: k, className: "alea-command-list", "aria-busy": h || void 0, onAction: (t) => {
95
+ if (String(t).startsWith(A)) {
96
+ I((a) => new Set(a).add(String(t).slice(A.length)));
72
97
  return;
73
98
  }
74
- const e = $.get(t);
75
- i(), e == null || e.onAction();
76
- }, children: (t) => /* @__PURE__ */ m(te, { id: t.id, className: "alea-option-section", children: [
99
+ const e = U.get(t);
100
+ s(), e == null || e.onAction();
101
+ }, children: (t) => /* @__PURE__ */ b(te, { id: t.id, className: "alea-option-section", children: [
77
102
  t.title && /* @__PURE__ */ n(ne, { className: "alea-option-header", children: t.title }),
78
- /* @__PURE__ */ n(se, { items: t.items, children: (e) => "more" in e ? /* @__PURE__ */ n(z, { id: e.id, textValue: l.showNMore(e.more), className: "alea-option alea-command-item alea-command-more", children: /* @__PURE__ */ n("span", { className: "alea-option-text", children: /* @__PURE__ */ n("span", { slot: "label", children: l.showNMore(e.more) }) }) }) : /* @__PURE__ */ m(z, { id: e.id, textValue: [e.label, ...e.keywords || []].join(" "), className: "alea-option alea-command-item", children: [
103
+ /* @__PURE__ */ n(ie, { items: t.items, children: (e) => "more" in e ? /* @__PURE__ */ n(D, { id: e.id, textValue: l.showNMore(e.more), className: "alea-option alea-command-item alea-command-more", children: /* @__PURE__ */ n("span", { className: "alea-option-text", children: /* @__PURE__ */ n("span", { slot: "label", children: l.showNMore(e.more) }) }) }) : /* @__PURE__ */ b(D, { id: e.id, textValue: [e.label, ...e.keywords || []].join(" "), className: "alea-option alea-command-item", children: [
79
104
  e.icon && /* @__PURE__ */ n("span", { className: "alea-option-icon", "aria-hidden": "true", children: e.icon }),
80
- /* @__PURE__ */ m("span", { className: "alea-option-text", children: [
105
+ /* @__PURE__ */ b("span", { className: "alea-option-text", children: [
81
106
  /* @__PURE__ */ n("span", { slot: "label", children: e.label }),
82
107
  e.description && /* @__PURE__ */ n("span", { className: "alea-option-desc", slot: "description", children: e.description })
83
108
  ] }),
84
- e.shortcut && /* @__PURE__ */ n(ie, { className: "alea-menu-shortcut", children: e.shortcut })
109
+ e.shortcut && /* @__PURE__ */ n(ae, { className: "alea-menu-shortcut", children: e.shortcut })
85
110
  ] }) })
86
111
  ] }) }),
87
- /* @__PURE__ */ n("div", { role: "status", children: y.length === 0 ? /* @__PURE__ */ n("p", { className: "alea-command-empty", children: v ? l.loading : k }) : v ? /* @__PURE__ */ n("p", { className: "alea-command-loading", children: l.loading }) : r ? /* @__PURE__ */ n("span", { className: "alea-visually-hidden", children: l.resultsCount(X) }) : null })
112
+ /* @__PURE__ */ n("div", { role: "status", children: k.length === 0 ? /* @__PURE__ */ n("p", { className: "alea-command-empty", children: h ? l.loading : R }) : h ? /* @__PURE__ */ n("p", { className: "alea-command-loading", children: l.loading }) : p ? /* @__PURE__ */ n("span", { className: "alea-visually-hidden", children: l.resultsCount(_) }) : null })
88
113
  ] })
89
114
  ] }) }) });
90
115
  });
91
116
  export {
92
- ve as CommandPalette
117
+ Ne as CommandPalette
93
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alea-design/ui",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Alea: the complete React design system. Accessible components from forms to AI, charts and editors, Alea Motion, and W3C design tokens for dark, light and high contrast.",
5
5
  "keywords": [
6
6
  "react",
@@ -61,8 +61,8 @@
61
61
  "react-dom": ">=18.3"
62
62
  },
63
63
  "dependencies": {
64
- "@alea-design/motion": "0.8.1",
65
- "@alea-design/tokens": "0.8.1",
64
+ "@alea-design/motion": "0.8.2",
65
+ "@alea-design/tokens": "0.8.2",
66
66
  "@internationalized/date": "^3.8.0",
67
67
  "lucide-react": "^0.525.0",
68
68
  "qrcode-generator": "^1.5.2",