@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
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { cx as
|
|
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
|
|
6
|
-
import { Search as
|
|
7
|
-
import { DialogModal as
|
|
8
|
-
import { Kbd as
|
|
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
|
|
11
|
-
function de({ children:
|
|
12
|
-
const
|
|
13
|
-
return
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
const c = new ResizeObserver(
|
|
19
|
-
return c.observe(
|
|
20
|
-
}, []),
|
|
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
|
|
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
|
-
|
|
25
|
-
const [
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
if (!c && !
|
|
32
|
-
const
|
|
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(),
|
|
59
|
+
t.preventDefault(), E(!S);
|
|
35
60
|
return;
|
|
36
61
|
}
|
|
37
|
-
if (
|
|
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(),
|
|
65
|
+
t.preventDefault(), E(!0);
|
|
41
66
|
}
|
|
42
67
|
};
|
|
43
|
-
return window.addEventListener("keydown",
|
|
68
|
+
return window.addEventListener("keydown", s), () => window.removeEventListener("keydown", s);
|
|
44
69
|
});
|
|
45
|
-
const { contains: W } = Y({ sensitivity: "base" }), { groups:
|
|
46
|
-
const
|
|
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
|
|
49
|
-
if (!
|
|
73
|
+
for (const a of d) {
|
|
74
|
+
if (!s(a)) continue;
|
|
50
75
|
e++;
|
|
51
|
-
const
|
|
52
|
-
let
|
|
53
|
-
|
|
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 (
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
58
|
-
|
|
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
|
-
}, [
|
|
62
|
-
return /* @__PURE__ */ n(
|
|
63
|
-
/* @__PURE__ */
|
|
64
|
-
/* @__PURE__ */ n(
|
|
65
|
-
/* @__PURE__ */ n(G, { placeholder:
|
|
66
|
-
/* @__PURE__ */ n(
|
|
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__ */
|
|
69
|
-
|
|
70
|
-
if (String(t).startsWith(
|
|
71
|
-
|
|
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 =
|
|
75
|
-
|
|
76
|
-
}, children: (t) => /* @__PURE__ */
|
|
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(
|
|
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__ */
|
|
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(
|
|
109
|
+
e.shortcut && /* @__PURE__ */ n(ae, { className: "alea-menu-shortcut", children: e.shortcut })
|
|
85
110
|
] }) })
|
|
86
111
|
] }) }),
|
|
87
|
-
/* @__PURE__ */ n("div", { role: "status", children:
|
|
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
|
-
|
|
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.
|
|
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.
|
|
65
|
-
"@alea-design/tokens": "0.8.
|
|
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",
|