@skiddph/prui 0.7.0 → 0.9.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/dist/app/resource.d.ts +44 -1
- package/dist/app.js +1 -1
- package/dist/chunks/auth-shell-DQJ4UmUv.js +1208 -0
- package/dist/chunks/data-table-toolbar-B-5J2Ozl.js +736 -0
- package/dist/core/accordion.d.ts +16 -0
- package/dist/core/accordion.js +108 -0
- package/dist/core/alert.d.ts +20 -0
- package/dist/core/alert.js +63 -0
- package/dist/core/anchor.d.ts +35 -0
- package/dist/core/anchor.js +39 -0
- package/dist/core/breadcrumb.d.ts +30 -0
- package/dist/core/breadcrumb.js +67 -0
- package/dist/core/button.d.ts +8 -1
- package/dist/core/button.js +23 -18
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +180 -0
- package/dist/core/card.d.ts +5 -1
- package/dist/core/card.js +33 -29
- package/dist/core/checkbox.d.ts +19 -0
- package/dist/core/checkbox.js +55 -0
- package/dist/core/combobox.d.ts +32 -0
- package/dist/core/combobox.js +193 -0
- package/dist/core/date-picker.d.ts +62 -0
- package/dist/core/date-picker.js +314 -0
- package/dist/core/dialog.d.ts +15 -0
- package/dist/core/dialog.js +77 -60
- package/dist/core/drawer.d.ts +34 -0
- package/dist/core/drawer.js +129 -0
- package/dist/core/dropdown.d.ts +8 -4
- package/dist/core/dropdown.js +136 -51
- package/dist/core/file-upload.d.ts +28 -0
- package/dist/core/file-upload.js +111 -0
- package/dist/core/index.d.ts +23 -1
- package/dist/core/list-nav.d.ts +27 -0
- package/dist/core/list-nav.js +51 -0
- package/dist/core/modal.d.ts +14 -5
- package/dist/core/modal.js +163 -156
- package/dist/core/overlay.d.ts +93 -0
- package/dist/core/overlay.js +189 -0
- package/dist/core/popover.d.ts +29 -0
- package/dist/core/popover.js +124 -0
- package/dist/core/progress.d.ts +21 -0
- package/dist/core/progress.js +59 -0
- package/dist/core/radio.d.ts +20 -0
- package/dist/core/radio.js +115 -0
- package/dist/core/select.d.ts +6 -0
- package/dist/core/select.js +187 -98
- package/dist/core/skeleton.d.ts +20 -0
- package/dist/core/skeleton.js +41 -0
- package/dist/core/spinner.d.ts +15 -0
- package/dist/core/spinner.js +41 -0
- package/dist/core/tabs.js +82 -53
- package/dist/core/time-picker.d.ts +68 -0
- package/dist/core/time-picker.js +305 -0
- package/dist/core/timeline.d.ts +22 -0
- package/dist/core/timeline.js +57 -0
- package/dist/core/toast.d.ts +36 -0
- package/dist/core/toast.js +123 -0
- package/dist/core/tooltip.d.ts +23 -0
- package/dist/core/tooltip.js +96 -0
- package/dist/core/tree-view.d.ts +34 -0
- package/dist/core/tree-view.js +133 -0
- package/dist/core.js +160 -62
- package/dist/data-table/data-table.d.ts +22 -1
- package/dist/data-table.js +1 -1
- package/dist/forms/form.d.ts +8 -0
- package/dist/forms.js +213 -200
- package/dist/i18n/index.d.ts +89 -0
- package/dist/i18n.js +105 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +263 -155
- package/dist/prui-utilities.css +1 -1
- package/dist/prui.css +111 -4
- package/dist/theme/base.css +110 -3
- package/dist/theme/index.d.ts +27 -0
- package/dist/theme.js +86 -58
- package/package.json +9 -2
- package/dist/chunks/auth-shell-BG5vx9eG.js +0 -1054
- package/dist/chunks/data-table-toolbar-BUy2EWPy.js +0 -581
|
@@ -0,0 +1,1208 @@
|
|
|
1
|
+
import { jsx as e, jsxs as f, Fragment as Oe } from "react/jsx-runtime";
|
|
2
|
+
import * as l from "react";
|
|
3
|
+
import { createPortal as ut } from "react-dom";
|
|
4
|
+
import { Routes as dt, Route as ke, Navigate as mt, MemoryRouter as pt, BrowserRouter as ft, useLocation as De, useNavigate as ze, Outlet as ht, Link as bt, NavLink as vt } from "react-router-dom";
|
|
5
|
+
import { ChevronsRight as Se, ChevronsLeft as Te, X as gt, Menu as xt, Search as yt, Palette as wt, ChevronDown as Nt, Pencil as kt, Trash2 as St, Plus as Tt, Clock as Ct } from "lucide-react";
|
|
6
|
+
import { cn as C } from "../core/cn.js";
|
|
7
|
+
import { Dropdown as Rt } from "../core/dropdown.js";
|
|
8
|
+
import { Button as K } from "../core/button.js";
|
|
9
|
+
import { useOverlay as Ae, Portal as $e, useOverlayStack as Et, useEscapeKey as Mt } from "../core/overlay.js";
|
|
10
|
+
import { endIndex as jt, homeIndex as Pt, moveIndex as Ce } from "../core/list-nav.js";
|
|
11
|
+
import { resolveThemeName as Ot, themeMode as Dt, readPersistedTheme as zt, applyTheme as Re, listThemes as At, clearAppliedTokens as $t } from "../theme.js";
|
|
12
|
+
import { usePruiI18n as J } from "../i18n.js";
|
|
13
|
+
import { Modal as Fe, confirmModal as Ft } from "../core/modal.js";
|
|
14
|
+
import { b as It, D as Lt, a as Kt } from "./data-table-toolbar-B-5J2Ozl.js";
|
|
15
|
+
import { Textarea as Bt, Input as ie } from "../core/input.js";
|
|
16
|
+
import { Label as Ut } from "../core/label.js";
|
|
17
|
+
import { Select as Ie } from "../core/select.js";
|
|
18
|
+
import { Switch as Le } from "../core/switch.js";
|
|
19
|
+
import { Card as Ke, CardHeader as Be, CardDescription as Ue, CardTitle as Ve, CardContent as _e } from "../core/card.js";
|
|
20
|
+
const Vt = [
|
|
21
|
+
{ path: "/login", name: "login" },
|
|
22
|
+
{ path: "/register", name: "register" },
|
|
23
|
+
{ path: "/forgot-password", name: "forgotPassword" },
|
|
24
|
+
{ path: "/reset-password", name: "resetPassword" },
|
|
25
|
+
{ path: "/otp", name: "otp" },
|
|
26
|
+
{ path: "/logout", name: "logout" }
|
|
27
|
+
], _t = [
|
|
28
|
+
{ path: "/404", name: "notFound" },
|
|
29
|
+
{ path: "/error", name: "error" },
|
|
30
|
+
{ path: "/profile", name: "profile" },
|
|
31
|
+
{ path: "/settings", name: "settings" },
|
|
32
|
+
{ path: "/admin-setup", name: "adminSetup" }
|
|
33
|
+
];
|
|
34
|
+
function qt({ mode: t, config: a, children: n }) {
|
|
35
|
+
const r = t === "auth" || t === "auth+utility", o = t === "utility" || t === "auth+utility", d = [
|
|
36
|
+
...r ? Vt : [],
|
|
37
|
+
...o ? _t : []
|
|
38
|
+
], [m, T] = l.useState(null);
|
|
39
|
+
return l.useEffect(() => {
|
|
40
|
+
let k = !1;
|
|
41
|
+
return import("../pages.js").then((x) => {
|
|
42
|
+
k || T(x.PagesRegistry);
|
|
43
|
+
}), () => {
|
|
44
|
+
k = !0;
|
|
45
|
+
};
|
|
46
|
+
}, []), m ? /* @__PURE__ */ f(dt, { children: [
|
|
47
|
+
d.map(({ path: k, name: x }) => {
|
|
48
|
+
const y = m[x];
|
|
49
|
+
return y ? /* @__PURE__ */ e(ke, { path: k, element: /* @__PURE__ */ e(y, { ...(a == null ? void 0 : a[x]) ?? {} }) }, k) : null;
|
|
50
|
+
}),
|
|
51
|
+
n,
|
|
52
|
+
r ? /* @__PURE__ */ e(ke, { path: "*", element: /* @__PURE__ */ e(mt, { to: "/login", replace: !0 }) }) : null
|
|
53
|
+
] }) : /* @__PURE__ */ e("div", { className: "p-8 text-center text-sm text-[var(--prui-dim)]", children: "Loading…" });
|
|
54
|
+
}
|
|
55
|
+
const Ht = l.lazy(
|
|
56
|
+
() => Promise.resolve().then(() => or).then((t) => ({ default: t.SessionTimeout }))
|
|
57
|
+
);
|
|
58
|
+
function Jt(t) {
|
|
59
|
+
const a = t !== !1, n = typeof t == "object" ? t : {}, r = n.persist !== !1, o = Ot(n.default ?? "control"), d = Dt(o), [m, T] = l.useState(() => (r ? zt() : null) ?? { theme: o, mode: d }), k = l.useCallback(
|
|
60
|
+
(x) => {
|
|
61
|
+
T(x), Re({ theme: x.theme, mode: x.mode, storageKey: r ? "prui:theme" : null });
|
|
62
|
+
},
|
|
63
|
+
[r]
|
|
64
|
+
);
|
|
65
|
+
return l.useEffect(() => {
|
|
66
|
+
Re({ theme: m.theme, mode: m.mode, storageKey: r ? "prui:theme" : null });
|
|
67
|
+
}, [m, r]), { enabled: a, state: m, setTheme: k };
|
|
68
|
+
}
|
|
69
|
+
function Yt({ config: t }) {
|
|
70
|
+
const { enabled: a, state: n, setTheme: r } = Jt(t), { t: o } = J();
|
|
71
|
+
return a ? /* @__PURE__ */ e(
|
|
72
|
+
Rt,
|
|
73
|
+
{
|
|
74
|
+
align: "end",
|
|
75
|
+
trigger: /* @__PURE__ */ e(
|
|
76
|
+
"button",
|
|
77
|
+
{
|
|
78
|
+
type: "button",
|
|
79
|
+
"aria-label": o.switchTheme,
|
|
80
|
+
title: `Theme: ${n.theme}`,
|
|
81
|
+
"data-testid": "theme-toggle",
|
|
82
|
+
className: "inline-flex h-8 w-8 items-center justify-center rounded-[var(--prui-radius)] text-[var(--prui-dim)] hover:bg-[var(--prui-raise)] hover:text-[var(--prui-fg)] cursor-pointer",
|
|
83
|
+
children: /* @__PURE__ */ e(wt, { className: "h-4 w-4", "aria-hidden": !0 })
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
items: At().map((d) => ({
|
|
87
|
+
label: `${d}${d === n.theme ? " (active)" : ""}`,
|
|
88
|
+
onSelect: () => {
|
|
89
|
+
$t(), r({ theme: d, mode: d === "daylight" ? "light" : "dark" });
|
|
90
|
+
}
|
|
91
|
+
}))
|
|
92
|
+
}
|
|
93
|
+
) : null;
|
|
94
|
+
}
|
|
95
|
+
function se(t, a) {
|
|
96
|
+
return a === "/" ? t === "/" : t === a || t.startsWith(a + "/");
|
|
97
|
+
}
|
|
98
|
+
function Wt({ item: t, onNavigate: a, expandAllOn: n, collapsed: r }) {
|
|
99
|
+
var O;
|
|
100
|
+
const { pathname: o } = De(), d = ze(), m = (t.items ?? []).some(
|
|
101
|
+
(v) => v.href ? se(o, v.href) : (v.items ?? []).some((i) => i.href && se(o, i.href))
|
|
102
|
+
), [T, k] = l.useState(m || n !== void 0 && o === n);
|
|
103
|
+
l.useEffect(() => {
|
|
104
|
+
m && k(!0);
|
|
105
|
+
}, [m]);
|
|
106
|
+
const x = t.icon, [y, R] = l.useState(!1), [w, P] = l.useState(null), g = l.useRef(null), u = l.useRef(null), [b, E] = l.useState(-1), M = l.useCallback(() => {
|
|
107
|
+
var i, S;
|
|
108
|
+
R(!1), E(-1);
|
|
109
|
+
const v = document.activeElement;
|
|
110
|
+
v && ((i = u.current) != null && i.contains(v)) && ((S = g.current) == null || S.focus());
|
|
111
|
+
}, []), { setElement: $, isTop: A } = Et(y);
|
|
112
|
+
if (Mt(y, A, () => M()), l.useEffect(() => {
|
|
113
|
+
var v;
|
|
114
|
+
y && ((v = u.current) == null || v.focus());
|
|
115
|
+
}, [y]), r) {
|
|
116
|
+
const v = [];
|
|
117
|
+
for (const c of t.items ?? [])
|
|
118
|
+
if ((O = c.items) != null && O.length) {
|
|
119
|
+
c.items.some((h) => h.href) && v.push({ heading: c.label });
|
|
120
|
+
for (const h of c.items) h.href && v.push({ label: h.label, href: h.href });
|
|
121
|
+
} else c.href && v.push({ label: c.label, href: c.href });
|
|
122
|
+
const i = v.filter((c) => c.href), S = () => {
|
|
123
|
+
var h;
|
|
124
|
+
const c = (h = g.current) == null ? void 0 : h.getBoundingClientRect();
|
|
125
|
+
if (c) {
|
|
126
|
+
const B = Math.min(v.length * 32 + 40, 320);
|
|
127
|
+
P({
|
|
128
|
+
left: c.right + 8,
|
|
129
|
+
top: Math.max(8, Math.min(c.top, window.innerHeight - B - 8))
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
R((B) => !B);
|
|
133
|
+
}, N = (c) => {
|
|
134
|
+
var L, V;
|
|
135
|
+
E(c);
|
|
136
|
+
const h = (L = u.current) == null ? void 0 : L.querySelectorAll("[role='menuitem']");
|
|
137
|
+
if (!h) return;
|
|
138
|
+
(V = Array.from(h)[c]) == null || V.focus();
|
|
139
|
+
}, p = (c) => {
|
|
140
|
+
const h = i.length;
|
|
141
|
+
switch (c.key) {
|
|
142
|
+
case "ArrowDown":
|
|
143
|
+
c.preventDefault(), N(Ce(b, 1, h));
|
|
144
|
+
break;
|
|
145
|
+
case "ArrowUp":
|
|
146
|
+
c.preventDefault(), N(Ce(b, -1, h));
|
|
147
|
+
break;
|
|
148
|
+
case "Home":
|
|
149
|
+
c.preventDefault(), N(Pt(h));
|
|
150
|
+
break;
|
|
151
|
+
case "End":
|
|
152
|
+
c.preventDefault(), N(jt(h));
|
|
153
|
+
break;
|
|
154
|
+
case "Tab":
|
|
155
|
+
M();
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return /* @__PURE__ */ f("li", { "data-testid": "nav-group", children: [
|
|
160
|
+
/* @__PURE__ */ e(
|
|
161
|
+
"button",
|
|
162
|
+
{
|
|
163
|
+
ref: g,
|
|
164
|
+
type: "button",
|
|
165
|
+
title: t.label,
|
|
166
|
+
"aria-haspopup": "menu",
|
|
167
|
+
"aria-expanded": y,
|
|
168
|
+
onClick: S,
|
|
169
|
+
onKeyDown: (c) => {
|
|
170
|
+
!y && (c.key === "ArrowDown" || c.key === "Enter" || c.key === " ") && (c.preventDefault(), S());
|
|
171
|
+
},
|
|
172
|
+
"data-testid": "rail-group-trigger",
|
|
173
|
+
className: C(
|
|
174
|
+
"flex w-full items-center justify-center rounded-[var(--prui-radius)] px-2.5 py-1.5 text-sm cursor-pointer",
|
|
175
|
+
m || y ? "text-[var(--prui-brand)]" : "text-[var(--prui-dim)] hover:text-[var(--prui-fg)]"
|
|
176
|
+
),
|
|
177
|
+
children: x ? /* @__PURE__ */ e(x, { className: "h-4 w-4 shrink-0", "aria-hidden": !0 }) : /* @__PURE__ */ e("span", { className: "prui-nav-mono text-[10px] font-semibold", children: t.label.slice(0, 2).toUpperCase() })
|
|
178
|
+
}
|
|
179
|
+
),
|
|
180
|
+
y && w ? ut(
|
|
181
|
+
/* @__PURE__ */ f(Oe, { children: [
|
|
182
|
+
/* @__PURE__ */ e("div", { className: "fixed inset-0 z-[var(--prui-z-flyout)]", onClick: () => M(), "data-testid": "rail-flyout-backdrop" }),
|
|
183
|
+
/* @__PURE__ */ f(
|
|
184
|
+
"div",
|
|
185
|
+
{
|
|
186
|
+
ref: (c) => {
|
|
187
|
+
u.current = c, $(c);
|
|
188
|
+
},
|
|
189
|
+
role: "menu",
|
|
190
|
+
"aria-label": t.label,
|
|
191
|
+
tabIndex: -1,
|
|
192
|
+
onKeyDown: p,
|
|
193
|
+
"data-testid": "rail-flyout",
|
|
194
|
+
className: "fixed z-[calc(var(--prui-z-flyout)+1)] flex w-56 max-h-80 flex-col overflow-y-auto rounded-[var(--prui-radius)] border border-[var(--prui-line)] bg-[var(--prui-surface)] py-1.5 shadow-[var(--prui-shadow-lg)] outline-none",
|
|
195
|
+
style: { top: w.top, left: w.left },
|
|
196
|
+
children: [
|
|
197
|
+
/* @__PURE__ */ e("div", { className: "px-3 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-[0.1em] text-[var(--prui-dim)]", children: t.label }),
|
|
198
|
+
v.map(
|
|
199
|
+
(c, h) => c.heading ? /* @__PURE__ */ e("div", { className: "px-3 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-[0.1em] text-[var(--prui-dim)]", children: c.heading }, `h-${h}`) : /* @__PURE__ */ e(
|
|
200
|
+
"button",
|
|
201
|
+
{
|
|
202
|
+
type: "button",
|
|
203
|
+
role: "menuitem",
|
|
204
|
+
tabIndex: -1,
|
|
205
|
+
"data-testid": "rail-flyout-item",
|
|
206
|
+
className: C(
|
|
207
|
+
"flex cursor-pointer items-center rounded-[calc(var(--prui-radius)-1px)] px-3 py-1.5 text-left text-sm",
|
|
208
|
+
c.href && se(o, c.href) ? "bg-[var(--prui-brand)]/15 text-[var(--prui-brand)]" : "text-[var(--prui-fg)] hover:bg-[var(--prui-raise)] focus-visible:bg-[var(--prui-raise)] outline-none"
|
|
209
|
+
),
|
|
210
|
+
onClick: () => {
|
|
211
|
+
M(), a == null || a(), c.href && d(c.href);
|
|
212
|
+
},
|
|
213
|
+
children: c.label
|
|
214
|
+
},
|
|
215
|
+
c.href
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
] }),
|
|
222
|
+
document.body
|
|
223
|
+
) : null
|
|
224
|
+
] });
|
|
225
|
+
}
|
|
226
|
+
return /* @__PURE__ */ f("li", { "data-testid": "nav-group", children: [
|
|
227
|
+
/* @__PURE__ */ f(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
type: "button",
|
|
231
|
+
"aria-expanded": T,
|
|
232
|
+
onClick: () => k((v) => !v),
|
|
233
|
+
className: C(
|
|
234
|
+
"flex w-full items-center gap-2 rounded-[var(--prui-radius)] px-2.5 py-1.5 text-sm cursor-pointer",
|
|
235
|
+
m ? "text-[var(--prui-fg)]" : "text-[var(--prui-dim)] hover:text-[var(--prui-fg)]"
|
|
236
|
+
),
|
|
237
|
+
children: [
|
|
238
|
+
x ? /* @__PURE__ */ e(x, { className: "h-4 w-4 shrink-0", "aria-hidden": !0 }) : /* @__PURE__ */ e("span", { className: C("prui-nav-mono text-[10px] font-semibold"), children: t.label.slice(0, 2).toUpperCase() }),
|
|
239
|
+
/* @__PURE__ */ e("span", { className: C("flex-1 text-left truncate", "prui-nav-label"), children: t.label }),
|
|
240
|
+
/* @__PURE__ */ e(Nt, { className: C("prui-nav-chevron h-4 w-4 transition-transform", !T && "-rotate-90"), "aria-hidden": !0 })
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
),
|
|
244
|
+
T ? /* @__PURE__ */ e("ul", { className: "ml-4 mt-0.5 flex flex-col gap-0.5 border-l border-[var(--prui-line)] pl-2", children: (t.items ?? []).map((v) => /* @__PURE__ */ e(qe, { item: v, onNavigate: a, nested: !0, expandAllOn: n, collapsed: r }, v.href ?? v.label)) }) : null
|
|
245
|
+
] });
|
|
246
|
+
}
|
|
247
|
+
function Xt({ label: t }) {
|
|
248
|
+
return /* @__PURE__ */ e("li", { className: "px-2.5 pb-1 pt-3 text-[10px] font-semibold uppercase tracking-[0.1em] text-[var(--prui-dim)]", "data-testid": "nav-subgroup", children: t });
|
|
249
|
+
}
|
|
250
|
+
function qe({ item: t, onNavigate: a, nested: n, expandAllOn: r, collapsed: o }) {
|
|
251
|
+
return t.items && t.items.length > 0 ? /* @__PURE__ */ e(Wt, { item: t, onNavigate: a, expandAllOn: r, collapsed: o }) : t.heading || !t.href && !t.items ? o ? null : /* @__PURE__ */ e(Xt, { label: t.label }) : t.href ? /* @__PURE__ */ e("li", { children: /* @__PURE__ */ f(
|
|
252
|
+
vt,
|
|
253
|
+
{
|
|
254
|
+
to: t.href,
|
|
255
|
+
onClick: a,
|
|
256
|
+
className: ({ isActive: d }) => C(
|
|
257
|
+
"flex items-center gap-2 rounded-[var(--prui-radius)] px-2.5 py-1.5 text-sm",
|
|
258
|
+
n && "pl-2.5",
|
|
259
|
+
d ? "bg-[var(--prui-brand)]/15 text-[var(--prui-brand)] font-medium" : "text-[var(--prui-dim)] hover:text-[var(--prui-fg)] hover:bg-[var(--prui-raise)]"
|
|
260
|
+
),
|
|
261
|
+
children: [
|
|
262
|
+
t.icon && !n ? /* @__PURE__ */ e(t.icon, { className: "h-4 w-4 shrink-0", "aria-hidden": !0 }) : o ? /* @__PURE__ */ e("span", { className: C("prui-nav-mono text-[10px] font-semibold"), children: t.label.slice(0, 2).toUpperCase() }) : null,
|
|
263
|
+
/* @__PURE__ */ e("span", { className: C("truncate", o && n && "prui-nav-label", "prui-nav-label"), children: t.label })
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
) }) : null;
|
|
267
|
+
}
|
|
268
|
+
function Ee({ nav: t, onNavigate: a, expandAllOn: n, collapsed: r }) {
|
|
269
|
+
const { t: o } = J();
|
|
270
|
+
return /* @__PURE__ */ e("nav", { "aria-label": o.mainNavigation, className: "prui-app-nav", children: /* @__PURE__ */ e("ul", { className: "flex flex-col gap-0.5", children: t.map((d) => /* @__PURE__ */ e(qe, { item: d, onNavigate: a, expandAllOn: n, collapsed: r }, d.href ?? d.label)) }) });
|
|
271
|
+
}
|
|
272
|
+
function Me({ brand: t }) {
|
|
273
|
+
if (!t) return null;
|
|
274
|
+
const a = /* @__PURE__ */ f(Oe, { children: [
|
|
275
|
+
t.mark ? /* @__PURE__ */ e("img", { src: t.mark, alt: "", className: "h-6 w-6 rounded-[var(--prui-radius-1)] object-cover" }) : null,
|
|
276
|
+
/* @__PURE__ */ e("span", { className: "prui-nav-label truncate font-semibold text-[var(--prui-fg)]", children: t.name })
|
|
277
|
+
] }), n = "flex items-center gap-2 px-1 py-1 min-w-0";
|
|
278
|
+
return t.href === null ? /* @__PURE__ */ e("div", { className: n, children: a }) : /* @__PURE__ */ e(bt, { to: t.href ?? "/", className: n, "aria-label": t.name, children: a });
|
|
279
|
+
}
|
|
280
|
+
function Gt({
|
|
281
|
+
open: t,
|
|
282
|
+
onOpenChange: a,
|
|
283
|
+
entries: n,
|
|
284
|
+
placeholder: r,
|
|
285
|
+
onNavigate: o
|
|
286
|
+
}) {
|
|
287
|
+
const { t: d } = J(), [m, T] = l.useState(""), [k, x] = l.useState(0), y = l.useRef(null), R = r ?? d.commandPlaceholder, w = l.useMemo(() => {
|
|
288
|
+
const u = m.trim().toLowerCase();
|
|
289
|
+
return u ? n.filter((b) => b.label.toLowerCase().includes(u)) : n;
|
|
290
|
+
}, [n, m]);
|
|
291
|
+
l.useEffect(() => x(0), [m]);
|
|
292
|
+
const { ref: P } = Ae({
|
|
293
|
+
open: t,
|
|
294
|
+
onEscape: () => a(!1),
|
|
295
|
+
initialFocus: y
|
|
296
|
+
}), g = (u) => {
|
|
297
|
+
a(!1), u.onSelect ? u.onSelect() : u.href && (o == null || o(u.href));
|
|
298
|
+
};
|
|
299
|
+
return t ? /* @__PURE__ */ e($e, { children: /* @__PURE__ */ e("div", { ref: P, children: /* @__PURE__ */ e(
|
|
300
|
+
"div",
|
|
301
|
+
{
|
|
302
|
+
className: "prui-dialog-overlay fixed inset-0 z-[var(--prui-z-overlay)] flex items-start justify-center pt-24",
|
|
303
|
+
style: { backgroundColor: "var(--prui-scrim)" },
|
|
304
|
+
onMouseDown: (u) => {
|
|
305
|
+
u.target === u.currentTarget && a(!1);
|
|
306
|
+
},
|
|
307
|
+
children: /* @__PURE__ */ f(
|
|
308
|
+
"div",
|
|
309
|
+
{
|
|
310
|
+
role: "dialog",
|
|
311
|
+
"aria-modal": "true",
|
|
312
|
+
"aria-label": "Command palette",
|
|
313
|
+
"data-testid": "command-palette",
|
|
314
|
+
className: "w-full max-w-md rounded-[var(--prui-radius)] border border-[var(--prui-line)] bg-[var(--prui-surface)] shadow-[var(--prui-shadow-lg)]",
|
|
315
|
+
children: [
|
|
316
|
+
/* @__PURE__ */ e(
|
|
317
|
+
"input",
|
|
318
|
+
{
|
|
319
|
+
ref: y,
|
|
320
|
+
type: "text",
|
|
321
|
+
role: "combobox",
|
|
322
|
+
"aria-expanded": "true",
|
|
323
|
+
"aria-controls": "prui-palette-listbox",
|
|
324
|
+
"aria-label": "Command palette search",
|
|
325
|
+
"aria-activedescendant": w[k] ? `palette-option-${k}` : void 0,
|
|
326
|
+
placeholder: R,
|
|
327
|
+
value: m,
|
|
328
|
+
onChange: (u) => T(u.target.value),
|
|
329
|
+
onKeyDown: (u) => {
|
|
330
|
+
if (u.key === "ArrowDown" && (u.preventDefault(), x((b) => Math.min(b + 1, w.length - 1))), u.key === "ArrowUp" && (u.preventDefault(), x((b) => Math.max(b - 1, 0))), u.key === "Home" && w.length > 0 && (u.preventDefault(), x(0)), u.key === "End" && w.length > 0 && (u.preventDefault(), x(w.length - 1)), u.key === "Enter") {
|
|
331
|
+
const b = w[k];
|
|
332
|
+
b && g(b);
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
className: "w-full bg-transparent px-4 py-3 text-sm text-[var(--prui-fg)] placeholder:text-[var(--prui-dim)] outline-none border-b border-[var(--prui-line)] rounded-t-[var(--prui-radius)]"
|
|
336
|
+
}
|
|
337
|
+
),
|
|
338
|
+
/* @__PURE__ */ e("ul", { id: "prui-palette-listbox", role: "listbox", "aria-label": "Commands", className: "max-h-64 overflow-auto p-1", children: w.length === 0 ? /* @__PURE__ */ e("li", { className: "px-3 py-2 text-sm text-[var(--prui-dim)]", role: "option", "aria-selected": "false", "aria-disabled": "true", children: d.commandNoMatches }) : w.map((u, b) => /* @__PURE__ */ f(
|
|
339
|
+
"li",
|
|
340
|
+
{
|
|
341
|
+
id: `palette-option-${b}`,
|
|
342
|
+
role: "option",
|
|
343
|
+
"aria-selected": b === k,
|
|
344
|
+
onMouseEnter: () => x(b),
|
|
345
|
+
onClick: () => g(u),
|
|
346
|
+
className: C(
|
|
347
|
+
"cursor-pointer rounded-[calc(var(--prui-radius)-1px)] px-3 py-2 text-sm text-[var(--prui-fg)]",
|
|
348
|
+
b === k && "bg-[var(--prui-raise)]"
|
|
349
|
+
),
|
|
350
|
+
children: [
|
|
351
|
+
u.group ? /* @__PURE__ */ e("span", { className: "mr-2 text-xs text-[var(--prui-dim)]", children: u.group }) : null,
|
|
352
|
+
u.label
|
|
353
|
+
]
|
|
354
|
+
},
|
|
355
|
+
`${u.label}-${b}`
|
|
356
|
+
)) })
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
) }) }) : null;
|
|
362
|
+
}
|
|
363
|
+
function Qt(t) {
|
|
364
|
+
const {
|
|
365
|
+
brand: a,
|
|
366
|
+
nav: n = [],
|
|
367
|
+
search: r = !0,
|
|
368
|
+
theme: o = !0,
|
|
369
|
+
auth: d = !1,
|
|
370
|
+
sidebar: m = {},
|
|
371
|
+
header: T,
|
|
372
|
+
pages: k,
|
|
373
|
+
pagesConfig: x,
|
|
374
|
+
expandAllOn: y,
|
|
375
|
+
layoutType: R = "A",
|
|
376
|
+
sidebarHeader: w,
|
|
377
|
+
sidebarFooter: P,
|
|
378
|
+
children: g
|
|
379
|
+
} = t, { t: u } = J(), b = typeof r == "object" ? r : { enabled: r !== !1 }, E = b.enabled !== !1, M = b.hotkey ?? "/", $ = m.collapsible !== !1, [A, O] = l.useState(m.defaultOpen === !0), [v, i] = l.useState(!0), [S, N] = l.useState(!1), p = De(), c = ze(), h = l.useMemo(
|
|
380
|
+
() => d === !1 ? null : d === !0 ? {} : d,
|
|
381
|
+
[d]
|
|
382
|
+
), B = l.useCallback(() => {
|
|
383
|
+
h != null && h.onTimeout ? h.onTimeout() : c((h == null ? void 0 : h.loginPath) ?? "/login");
|
|
384
|
+
}, [h, c]), L = l.useMemo(() => {
|
|
385
|
+
const F = [];
|
|
386
|
+
for (const j of n)
|
|
387
|
+
if (j.items)
|
|
388
|
+
for (const I of j.items)
|
|
389
|
+
I.href && F.push({ label: `${j.label} / ${I.label}`, href: I.href, group: j.label });
|
|
390
|
+
else j.href && F.push({ label: j.label, href: j.href });
|
|
391
|
+
return F;
|
|
392
|
+
}, [n]);
|
|
393
|
+
l.useEffect(() => {
|
|
394
|
+
if (!E) return;
|
|
395
|
+
const F = (j) => {
|
|
396
|
+
const I = j.target, q = I && (I.tagName === "INPUT" || I.tagName === "TEXTAREA" || I.isContentEditable);
|
|
397
|
+
j.key === M && !q && !j.metaKey && !j.ctrlKey && !j.altKey && (j.preventDefault(), N(!0));
|
|
398
|
+
};
|
|
399
|
+
return document.addEventListener("keydown", F), () => document.removeEventListener("keydown", F);
|
|
400
|
+
}, [M, E]);
|
|
401
|
+
const V = l.useRef(p.pathname);
|
|
402
|
+
l.useEffect(() => {
|
|
403
|
+
V.current !== p.pathname && (V.current = p.pathname, O(!1));
|
|
404
|
+
}, [p.pathname]);
|
|
405
|
+
const Y = l.useRef(null), { ref: re } = Ae({
|
|
406
|
+
open: A,
|
|
407
|
+
onEscape: () => O(!1),
|
|
408
|
+
initialFocus: Y
|
|
409
|
+
}), ae = m.width ?? 240, D = !v && R !== "D";
|
|
410
|
+
return /* @__PURE__ */ f(
|
|
411
|
+
"div",
|
|
412
|
+
{
|
|
413
|
+
className: "prui-app prui-shell min-h-dvh bg-[var(--prui-background)] text-[var(--prui-fg)]",
|
|
414
|
+
"data-layout": R,
|
|
415
|
+
"data-collapsed": D ? "true" : void 0,
|
|
416
|
+
style: { "--prui-shell-sidebar": D ? "var(--prui-rail-width, 64px)" : `${ae}px` },
|
|
417
|
+
children: [
|
|
418
|
+
/* @__PURE__ */ f("aside", { "data-testid": "sidebar", className: "prui-shell-sidebar hidden md:flex md:flex-col md:min-h-0", children: [
|
|
419
|
+
/* @__PURE__ */ e("div", { className: "flex min-h-0 flex-1 flex-col overflow-y-auto p-2 pt-4 scrollbar-thin", children: /* @__PURE__ */ e(Ee, { nav: n, expandAllOn: y, collapsed: D }) }),
|
|
420
|
+
P ? /* @__PURE__ */ e(
|
|
421
|
+
"div",
|
|
422
|
+
{
|
|
423
|
+
className: C("border-t border-[var(--prui-line)] p-2", D && "flex justify-center px-1"),
|
|
424
|
+
"data-testid": "sidebar-footer",
|
|
425
|
+
children: P
|
|
426
|
+
}
|
|
427
|
+
) : null,
|
|
428
|
+
R !== "D" ? /* @__PURE__ */ e("div", { className: "border-t border-[var(--prui-line)] p-2", children: /* @__PURE__ */ e(
|
|
429
|
+
K,
|
|
430
|
+
{
|
|
431
|
+
variant: "ghost",
|
|
432
|
+
size: "sm",
|
|
433
|
+
className: "w-full justify-center",
|
|
434
|
+
"aria-label": D ? u.expandSidebar : u.collapseSidebar,
|
|
435
|
+
"data-testid": "sidebar-toggle",
|
|
436
|
+
onClick: () => i((F) => !F),
|
|
437
|
+
children: D ? /* @__PURE__ */ e(Se, { className: "h-4 w-4", "aria-hidden": !0 }) : /* @__PURE__ */ e(Te, { className: "h-4 w-4", "aria-hidden": !0 })
|
|
438
|
+
}
|
|
439
|
+
) }) : null
|
|
440
|
+
] }),
|
|
441
|
+
A ? /* @__PURE__ */ e($e, { children: /* @__PURE__ */ f("div", { ref: re, className: "md:hidden fixed inset-0 z-[var(--prui-z-drawer)]", "data-testid": "mobile-drawer", children: [
|
|
442
|
+
/* @__PURE__ */ e(
|
|
443
|
+
"div",
|
|
444
|
+
{
|
|
445
|
+
className: "absolute inset-0",
|
|
446
|
+
style: { backgroundColor: "var(--prui-scrim)" },
|
|
447
|
+
onClick: () => O(!1),
|
|
448
|
+
"data-testid": "drawer-backdrop"
|
|
449
|
+
}
|
|
450
|
+
),
|
|
451
|
+
/* @__PURE__ */ f(
|
|
452
|
+
"aside",
|
|
453
|
+
{
|
|
454
|
+
className: "absolute left-0 top-0 h-full w-64 overflow-y-auto border-r border-[var(--prui-line)] bg-[var(--prui-surface)] p-2",
|
|
455
|
+
role: "dialog",
|
|
456
|
+
"aria-modal": "true",
|
|
457
|
+
"aria-label": "Navigation",
|
|
458
|
+
children: [
|
|
459
|
+
/* @__PURE__ */ e("div", { className: "mb-2 flex h-10 items-center justify-end px-1", children: /* @__PURE__ */ e(
|
|
460
|
+
"button",
|
|
461
|
+
{
|
|
462
|
+
type: "button",
|
|
463
|
+
ref: Y,
|
|
464
|
+
"aria-label": u.closeNavigation,
|
|
465
|
+
onClick: () => O(!1),
|
|
466
|
+
className: "rounded-[var(--prui-radius)] p-1 text-[var(--prui-dim)] hover:text-[var(--prui-fg)] cursor-pointer",
|
|
467
|
+
children: /* @__PURE__ */ e(gt, { className: "h-4 w-4", "aria-hidden": !0 })
|
|
468
|
+
}
|
|
469
|
+
) }),
|
|
470
|
+
/* @__PURE__ */ e(Ee, { nav: n, onNavigate: () => O(!1), expandAllOn: y, collapsed: !1 })
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
] }) }) : null,
|
|
475
|
+
R === "C" ? /* @__PURE__ */ e(
|
|
476
|
+
"div",
|
|
477
|
+
{
|
|
478
|
+
"data-testid": "sidebar-header",
|
|
479
|
+
className: "prui-shell-sidehead hidden h-14 items-center gap-2 border-b border-[var(--prui-line)] bg-[var(--prui-surface)] px-4 md:flex",
|
|
480
|
+
children: w ?? /* @__PURE__ */ e(Me, { brand: a })
|
|
481
|
+
}
|
|
482
|
+
) : null,
|
|
483
|
+
/* @__PURE__ */ f(
|
|
484
|
+
"header",
|
|
485
|
+
{
|
|
486
|
+
"data-testid": "app-header",
|
|
487
|
+
className: "prui-shell-header sticky top-0 z-[var(--prui-z-header)] grid h-14 grid-cols-[1fr_auto_1fr] items-center gap-4 border-b border-[var(--prui-line)] bg-[var(--prui-surface)] px-4 md:px-6",
|
|
488
|
+
children: [
|
|
489
|
+
$ ? /* @__PURE__ */ e(
|
|
490
|
+
K,
|
|
491
|
+
{
|
|
492
|
+
variant: "ghost",
|
|
493
|
+
size: "icon",
|
|
494
|
+
"aria-label": u.openNavigation,
|
|
495
|
+
className: "md:hidden",
|
|
496
|
+
onClick: () => O(!0),
|
|
497
|
+
"data-testid": "drawer-toggle",
|
|
498
|
+
children: /* @__PURE__ */ e(xt, { className: "h-4 w-4", "aria-hidden": !0 })
|
|
499
|
+
}
|
|
500
|
+
) : null,
|
|
501
|
+
$ && R !== "D" ? /* @__PURE__ */ e(
|
|
502
|
+
K,
|
|
503
|
+
{
|
|
504
|
+
variant: "ghost",
|
|
505
|
+
size: "icon",
|
|
506
|
+
"aria-label": D ? u.expandSidebar : u.collapseSidebar,
|
|
507
|
+
className: "md:hidden",
|
|
508
|
+
onClick: () => i((F) => !F),
|
|
509
|
+
"data-testid": "rail-toggle-mobile",
|
|
510
|
+
children: D ? /* @__PURE__ */ e(Se, { className: "h-4 w-4", "aria-hidden": !0 }) : /* @__PURE__ */ e(Te, { className: "h-4 w-4", "aria-hidden": !0 })
|
|
511
|
+
}
|
|
512
|
+
) : null,
|
|
513
|
+
/* @__PURE__ */ e("div", { className: "min-w-0 justify-self-start", children: /* @__PURE__ */ e(Me, { brand: a }) }),
|
|
514
|
+
E ? /* @__PURE__ */ f(
|
|
515
|
+
"button",
|
|
516
|
+
{
|
|
517
|
+
type: "button",
|
|
518
|
+
onClick: () => N(!0),
|
|
519
|
+
"data-testid": "search-trigger",
|
|
520
|
+
className: "hidden h-8 w-[min(420px,34vw)] items-center gap-2 rounded-[var(--prui-radius)] border border-[var(--prui-line)] bg-[var(--prui-background)] px-3.5 text-sm text-[var(--prui-dim)] hover:border-[var(--prui-dim)] cursor-pointer md:flex",
|
|
521
|
+
children: [
|
|
522
|
+
/* @__PURE__ */ e(yt, { className: "h-4 w-4", "aria-hidden": !0 }),
|
|
523
|
+
/* @__PURE__ */ e("span", { className: "flex-1 text-left", children: b.placeholder ?? `${u.search}...` }),
|
|
524
|
+
/* @__PURE__ */ e("kbd", { className: "ml-auto rounded-[var(--prui-radius-1)] border border-[var(--prui-line)] bg-[var(--prui-raise)] px-1.5 py-0.5 text-xs", children: M })
|
|
525
|
+
]
|
|
526
|
+
}
|
|
527
|
+
) : null,
|
|
528
|
+
/* @__PURE__ */ f("div", { className: "flex items-center gap-2 justify-self-end", children: [
|
|
529
|
+
T,
|
|
530
|
+
/* @__PURE__ */ e(Yt, { config: o })
|
|
531
|
+
] })
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
),
|
|
535
|
+
/* @__PURE__ */ e(
|
|
536
|
+
"main",
|
|
537
|
+
{
|
|
538
|
+
"data-testid": "app-content",
|
|
539
|
+
tabIndex: 0,
|
|
540
|
+
className: "prui-shell-content min-h-0 flex-1 p-4 outline-none md:p-6",
|
|
541
|
+
children: k ? /* @__PURE__ */ e(qt, { mode: k, config: x, children: g }) : g ?? /* @__PURE__ */ e(ht, {})
|
|
542
|
+
}
|
|
543
|
+
),
|
|
544
|
+
h ? /* @__PURE__ */ e(l.Suspense, { fallback: null, children: /* @__PURE__ */ e(
|
|
545
|
+
Ht,
|
|
546
|
+
{
|
|
547
|
+
timeout: h.sessionTimeout,
|
|
548
|
+
warningTime: h.warningTime,
|
|
549
|
+
onTimeout: B
|
|
550
|
+
}
|
|
551
|
+
) }) : null,
|
|
552
|
+
E ? /* @__PURE__ */ e(Gt, { open: S, onOpenChange: N, entries: L, placeholder: b.placeholder, onNavigate: c }) : null
|
|
553
|
+
]
|
|
554
|
+
}
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
function Rr(t) {
|
|
558
|
+
const { router: a = "browser", initialEntries: n } = t;
|
|
559
|
+
return /* @__PURE__ */ e(a === "memory" ? pt : ft, { initialEntries: n, children: /* @__PURE__ */ e(Qt, { ...t }) });
|
|
560
|
+
}
|
|
561
|
+
const Er = {
|
|
562
|
+
name: "App",
|
|
563
|
+
props: [
|
|
564
|
+
{ name: "brand", type: "{ name, mark?, href? }", default: "undefined", control: "object" },
|
|
565
|
+
{ name: "nav", type: "NavItem[]", default: "[]", control: "object" },
|
|
566
|
+
{ name: "search", type: "boolean | { enabled?, hotkey?, placeholder? }", default: "true", control: "boolean" },
|
|
567
|
+
{ name: "theme", type: "boolean | { default?: ThemeName | 'dark' | 'light', persist? }", default: "true", control: "boolean" },
|
|
568
|
+
{ name: "auth", type: "boolean | { sessionTimeout?, warningTime?, onTimeout?, loginPath? }", default: "false", control: "boolean" },
|
|
569
|
+
{ name: "sidebar", type: "{ width?, collapsible?, defaultOpen? }", default: "{}", control: "object" },
|
|
570
|
+
{ name: "router", type: "'browser' | 'memory'", default: "'browser'", control: "select", options: ["browser", "memory", "react-router"] },
|
|
571
|
+
{ name: "initialEntries", type: "string[]", default: "undefined", control: "object" },
|
|
572
|
+
{ name: "pages", type: "'auth' | 'utility' | 'auth+utility'", default: "undefined", control: "select", options: ["auth", "utility", "auth+utility"] },
|
|
573
|
+
{ name: "expandAllOn", type: "string (pathname)", default: "undefined", control: "text" },
|
|
574
|
+
{ name: "layoutType", type: "'A' | 'B' | 'C' | 'D'", default: "'A'", control: "select", options: ["A", "B", "C", "D"] },
|
|
575
|
+
{ name: "sidebarHeader", type: "ReactNode (layout C sidebar header)", default: "brand", control: "none" },
|
|
576
|
+
{ name: "sidebarFooter", type: "ReactNode", default: null, control: "none" },
|
|
577
|
+
{ name: "header", type: "ReactNode", default: null, control: "none" },
|
|
578
|
+
{ name: "children", type: "ReactNode", default: "Outlet", control: "none" }
|
|
579
|
+
]
|
|
580
|
+
};
|
|
581
|
+
function Zt(t) {
|
|
582
|
+
return Array.isArray(t) ? { fields: t } : t;
|
|
583
|
+
}
|
|
584
|
+
function er(t) {
|
|
585
|
+
if (t)
|
|
586
|
+
return t.map((a) => typeof a == "string" || typeof a == "number" ? { label: String(a), value: String(a) } : a);
|
|
587
|
+
}
|
|
588
|
+
function je(t, a) {
|
|
589
|
+
const n = {};
|
|
590
|
+
for (const r of t.fields)
|
|
591
|
+
a && r.name in a ? n[r.name] = a[r.name] : r.defaultValue !== void 0 ? n[r.name] = r.defaultValue : r.type === "boolean" ? n[r.name] = !1 : n[r.name] = "";
|
|
592
|
+
return n;
|
|
593
|
+
}
|
|
594
|
+
function tr({
|
|
595
|
+
schema: t,
|
|
596
|
+
initialValues: a,
|
|
597
|
+
defaultValues: n,
|
|
598
|
+
onSubmit: r,
|
|
599
|
+
onCancel: o,
|
|
600
|
+
cancelLabel: d,
|
|
601
|
+
submitting: m = !1,
|
|
602
|
+
error: T,
|
|
603
|
+
className: k
|
|
604
|
+
}) {
|
|
605
|
+
const { t: x } = J(), y = l.useMemo(() => Zt(t), [t]), R = a ?? n, [w, P] = l.useState(() => je(y, R)), [g, u] = l.useState({}), [b, E] = l.useState(null), [M, $] = l.useState(!1);
|
|
606
|
+
l.useEffect(() => {
|
|
607
|
+
P(je(y, R));
|
|
608
|
+
}, [JSON.stringify(y), JSON.stringify(R ?? {})]);
|
|
609
|
+
const A = (i, S) => {
|
|
610
|
+
P((N) => ({ ...N, [i]: S })), u((N) => {
|
|
611
|
+
if (!N[i]) return N;
|
|
612
|
+
const p = { ...N };
|
|
613
|
+
return delete p[i], p;
|
|
614
|
+
});
|
|
615
|
+
}, O = async (i) => {
|
|
616
|
+
var N;
|
|
617
|
+
i.preventDefault();
|
|
618
|
+
const S = {};
|
|
619
|
+
for (const p of y.fields) {
|
|
620
|
+
if (p.required) {
|
|
621
|
+
const h = w[p.name];
|
|
622
|
+
(h === "" || h == null || Array.isArray(h) && h.length === 0) && (S[p.name] = x.requiredField.replace("{label}", p.label));
|
|
623
|
+
}
|
|
624
|
+
const c = (N = p.validate) == null ? void 0 : N.call(p, w[p.name], w);
|
|
625
|
+
c && (S[p.name] = c);
|
|
626
|
+
}
|
|
627
|
+
if (u(S), !(Object.keys(S).length > 0)) {
|
|
628
|
+
E(null);
|
|
629
|
+
try {
|
|
630
|
+
const p = r == null ? void 0 : r({ ...w });
|
|
631
|
+
p && typeof p.then == "function" && ($(!0), await p);
|
|
632
|
+
} catch (p) {
|
|
633
|
+
E(p instanceof Error ? p.message : String(p));
|
|
634
|
+
} finally {
|
|
635
|
+
$(!1);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}, v = m || M;
|
|
639
|
+
return /* @__PURE__ */ f("form", { onSubmit: O, className: C("prui-form flex flex-col gap-4", k), noValidate: !0, children: [
|
|
640
|
+
/* @__PURE__ */ e("div", { className: C("grid gap-4", y.columns === 2 && "md:grid-cols-2"), children: y.fields.map((i) => {
|
|
641
|
+
const S = g[i.name], N = {
|
|
642
|
+
id: `prui-form-${i.name}`,
|
|
643
|
+
"aria-invalid": S ? !0 : void 0,
|
|
644
|
+
"aria-describedby": S ? `prui-form-${i.name}-error` : void 0
|
|
645
|
+
};
|
|
646
|
+
return /* @__PURE__ */ f("div", { className: C("flex flex-col gap-1.5", i.colSpan === 2 && "md:col-span-2", i.className), children: [
|
|
647
|
+
/* @__PURE__ */ f(Ut, { htmlFor: N.id, children: [
|
|
648
|
+
i.label,
|
|
649
|
+
i.required ? /* @__PURE__ */ e("span", { className: "ml-0.5 text-[var(--prui-danger)]", children: "*" }) : null
|
|
650
|
+
] }),
|
|
651
|
+
i.type === "textarea" ? /* @__PURE__ */ e(
|
|
652
|
+
Bt,
|
|
653
|
+
{
|
|
654
|
+
...N,
|
|
655
|
+
placeholder: i.placeholder,
|
|
656
|
+
disabled: i.disabled || v,
|
|
657
|
+
value: String(w[i.name] ?? ""),
|
|
658
|
+
onChange: (p) => A(i.name, p.target.value)
|
|
659
|
+
}
|
|
660
|
+
) : i.type === "select" ? /* @__PURE__ */ e(
|
|
661
|
+
Ie,
|
|
662
|
+
{
|
|
663
|
+
...N,
|
|
664
|
+
options: er(i.options),
|
|
665
|
+
placeholder: i.placeholder,
|
|
666
|
+
disabled: i.disabled || v,
|
|
667
|
+
value: String(w[i.name] ?? ""),
|
|
668
|
+
onChange: (p) => A(i.name, p)
|
|
669
|
+
}
|
|
670
|
+
) : i.type === "date" ? /* @__PURE__ */ e(
|
|
671
|
+
ie,
|
|
672
|
+
{
|
|
673
|
+
...N,
|
|
674
|
+
type: "date",
|
|
675
|
+
placeholder: i.placeholder,
|
|
676
|
+
disabled: i.disabled || v,
|
|
677
|
+
value: String(w[i.name] ?? ""),
|
|
678
|
+
onChange: (p) => A(i.name, p.target.value)
|
|
679
|
+
}
|
|
680
|
+
) : i.type === "boolean" ? /* @__PURE__ */ e(
|
|
681
|
+
Le,
|
|
682
|
+
{
|
|
683
|
+
...N,
|
|
684
|
+
disabled: i.disabled || v,
|
|
685
|
+
checked: !!w[i.name],
|
|
686
|
+
onChange: (p) => A(i.name, p)
|
|
687
|
+
}
|
|
688
|
+
) : /* @__PURE__ */ e(
|
|
689
|
+
ie,
|
|
690
|
+
{
|
|
691
|
+
...N,
|
|
692
|
+
type: i.type ?? "text",
|
|
693
|
+
placeholder: i.placeholder,
|
|
694
|
+
disabled: i.disabled || v,
|
|
695
|
+
value: String(w[i.name] ?? ""),
|
|
696
|
+
onChange: (p) => A(i.name, i.type === "number" ? p.target.value === "" ? "" : Number(p.target.value) : p.target.value)
|
|
697
|
+
}
|
|
698
|
+
),
|
|
699
|
+
S ? /* @__PURE__ */ e("p", { id: `prui-form-${i.name}-error`, role: "alert", className: "text-xs text-[var(--prui-danger)]", children: S }) : null
|
|
700
|
+
] }, i.name);
|
|
701
|
+
}) }),
|
|
702
|
+
T ?? b ? /* @__PURE__ */ e("p", { role: "alert", "data-testid": "form-error", className: "rounded-[var(--prui-radius)] border border-[var(--prui-danger)]/40 bg-[var(--prui-danger)]/10 px-3 py-2 text-sm text-[var(--prui-danger)]", children: T ?? b }) : null,
|
|
703
|
+
/* @__PURE__ */ f("div", { className: "flex items-center justify-end gap-2", children: [
|
|
704
|
+
o ? /* @__PURE__ */ e(K, { type: "button", variant: "ghost", onClick: o, disabled: v, children: d ?? x.cancel }) : null,
|
|
705
|
+
/* @__PURE__ */ e(K, { type: "submit", variant: "primary", loading: v, children: y.submitLabel ?? "Submit" })
|
|
706
|
+
] })
|
|
707
|
+
] });
|
|
708
|
+
}
|
|
709
|
+
const Mr = {
|
|
710
|
+
name: "Form",
|
|
711
|
+
props: [
|
|
712
|
+
{ name: "schema", type: "FormSchema", default: null, control: "object" },
|
|
713
|
+
{ name: "initialValues", type: "Record<string, unknown>", default: "{}", control: "object" },
|
|
714
|
+
{ name: "onSubmit", type: "(values) => void | Promise<void>", default: null, control: "none" },
|
|
715
|
+
{ name: "onCancel", type: "() => void", default: null, control: "none" },
|
|
716
|
+
{ name: "submitting", type: "boolean", default: "false", control: "boolean" },
|
|
717
|
+
{ name: "error", type: "string | null", default: "null", control: "text" }
|
|
718
|
+
]
|
|
719
|
+
};
|
|
720
|
+
function He(t) {
|
|
721
|
+
if (t)
|
|
722
|
+
return t.map((a) => typeof a == "string" || typeof a == "number" ? { label: String(a), value: String(a) } : a);
|
|
723
|
+
}
|
|
724
|
+
function rr(t, a) {
|
|
725
|
+
return { fields: t.filter((r) => r.formField !== !1 && !r.hidden).filter((r) => r.key !== "id" && r.key !== "actions").map((r) => {
|
|
726
|
+
var o;
|
|
727
|
+
return {
|
|
728
|
+
name: r.key,
|
|
729
|
+
label: typeof r.label == "string" ? r.label : r.key,
|
|
730
|
+
type: ar(r, a),
|
|
731
|
+
options: (o = He(r.filterOptions ?? r.options)) == null ? void 0 : o.map((d) => ({ label: d.label, value: d.value })),
|
|
732
|
+
required: !1
|
|
733
|
+
};
|
|
734
|
+
}), submitLabel: a ? "Save" : "Create" };
|
|
735
|
+
}
|
|
736
|
+
function ar(t, a) {
|
|
737
|
+
return t.filter === "select" ? "select" : typeof (a == null ? void 0 : a[t.key]) == "number" || t.filter === "number" || t.filter === "numberrange" || t.filter === "price" ? "number" : t.filter === "date" || t.filter === "daterange" ? "date" : "text";
|
|
738
|
+
}
|
|
739
|
+
function jr({
|
|
740
|
+
name: t,
|
|
741
|
+
columns: a,
|
|
742
|
+
list: n,
|
|
743
|
+
create: r,
|
|
744
|
+
update: o,
|
|
745
|
+
remove: d,
|
|
746
|
+
delete: m,
|
|
747
|
+
actions: T,
|
|
748
|
+
form: k,
|
|
749
|
+
formSchema: x,
|
|
750
|
+
rowKey: y,
|
|
751
|
+
searchPlaceholder: R,
|
|
752
|
+
pageSize: w,
|
|
753
|
+
state: P,
|
|
754
|
+
defaultState: g,
|
|
755
|
+
onStateChange: u,
|
|
756
|
+
onPageChange: b,
|
|
757
|
+
onFilterChange: E,
|
|
758
|
+
onSortChange: M,
|
|
759
|
+
onSearchChange: $,
|
|
760
|
+
onPageSizeChange: A,
|
|
761
|
+
onSelectionChange: O,
|
|
762
|
+
selectable: v,
|
|
763
|
+
renderExpandedRow: i,
|
|
764
|
+
virtualized: S,
|
|
765
|
+
searchDebounce: N = 250,
|
|
766
|
+
className: p
|
|
767
|
+
}) {
|
|
768
|
+
const { t: c } = J(), h = d ?? m, B = T ?? ["create", "edit", "delete"], L = (s) => B.includes(s) && (s === "create" ? !!r : s === "edit" ? !!o : !!h), V = l.useMemo(
|
|
769
|
+
() => ({
|
|
770
|
+
page: 1,
|
|
771
|
+
pageSize: w ?? (g == null ? void 0 : g.pageSize) ?? 20,
|
|
772
|
+
search: (g == null ? void 0 : g.search) ?? "",
|
|
773
|
+
filters: (g == null ? void 0 : g.filters) ?? {},
|
|
774
|
+
sort: (g == null ? void 0 : g.sort) ?? null,
|
|
775
|
+
selection: (g == null ? void 0 : g.selection) ?? [],
|
|
776
|
+
expandedRows: (g == null ? void 0 : g.expandedRows) ?? []
|
|
777
|
+
}),
|
|
778
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- defaults are read once
|
|
779
|
+
[]
|
|
780
|
+
), [Y, re] = l.useState(V), ae = l.useMemo(
|
|
781
|
+
() => ({ ...Y, ...Object.fromEntries(Object.entries(P ?? {}).filter(([, s]) => s !== void 0)) }),
|
|
782
|
+
[Y, P]
|
|
783
|
+
), D = l.useCallback(
|
|
784
|
+
(s) => {
|
|
785
|
+
re((z) => {
|
|
786
|
+
const U = { ...z }, X = P;
|
|
787
|
+
for (const [G, ct] of Object.entries(s))
|
|
788
|
+
X && G in X && X[G] !== void 0 || (U[G] = ct);
|
|
789
|
+
const te = { ...U, ...Object.fromEntries(Object.entries(P ?? {}).filter(([, G]) => G !== void 0)) };
|
|
790
|
+
return u == null || u(te), U;
|
|
791
|
+
});
|
|
792
|
+
},
|
|
793
|
+
[P, u]
|
|
794
|
+
), { page: F, pageSize: j, search: I, filters: q, sort: ne, selection: Je, expandedRows: Ye } = ae, [We, oe] = l.useState([]), [ce, ue] = l.useState(null), [Xe, de] = l.useState([null]), [Ge, me] = l.useState(!0), [pe, fe] = l.useState(null), [_, he] = l.useState(null), [Qe, W] = l.useState(!1), [be, ve] = l.useState(!1), [le, Ze] = l.useState(I);
|
|
795
|
+
l.useEffect(() => {
|
|
796
|
+
const s = setTimeout(() => Ze(I), N);
|
|
797
|
+
return () => clearTimeout(s);
|
|
798
|
+
}, [I, N]);
|
|
799
|
+
const ge = Xe[F - 1] ?? null, xe = JSON.stringify(q), Q = l.useCallback(async () => {
|
|
800
|
+
me(!0), fe(null);
|
|
801
|
+
try {
|
|
802
|
+
const s = await n({ search: le, cursor: ge, pageSize: j, sort: ne, filters: q });
|
|
803
|
+
oe(s.rows), ue(s.nextCursor ?? s.cursor ?? null);
|
|
804
|
+
} catch (s) {
|
|
805
|
+
fe(s instanceof Error ? s.message : String(s)), oe([]), ue(null);
|
|
806
|
+
} finally {
|
|
807
|
+
me(!1);
|
|
808
|
+
}
|
|
809
|
+
}, [le, ge, j, ne, xe, n]);
|
|
810
|
+
l.useEffect(() => {
|
|
811
|
+
Q();
|
|
812
|
+
}, [Q]), l.useEffect(() => {
|
|
813
|
+
D({ page: 1 }), de([null]);
|
|
814
|
+
}, [le, j, xe]);
|
|
815
|
+
const et = l.useMemo(
|
|
816
|
+
() => a.filter((s) => s.filter).map((s) => ({
|
|
817
|
+
key: s.key,
|
|
818
|
+
label: typeof s.label == "string" ? s.label : s.key,
|
|
819
|
+
type: s.filter === "numberrange" ? "number" : s.filter,
|
|
820
|
+
options: He(s.filterOptions ?? s.options)
|
|
821
|
+
})),
|
|
822
|
+
[a]
|
|
823
|
+
), tt = (s, z) => {
|
|
824
|
+
const U = { ...q, [s]: z };
|
|
825
|
+
D({ filters: U }), E == null || E(U);
|
|
826
|
+
}, rt = (s) => {
|
|
827
|
+
D({ search: s }), $ == null || $(s);
|
|
828
|
+
}, at = (s) => {
|
|
829
|
+
D({ sort: s }), M == null || M(s);
|
|
830
|
+
}, nt = (s, z) => {
|
|
831
|
+
if (z === "next") {
|
|
832
|
+
const U = ce;
|
|
833
|
+
de((X) => {
|
|
834
|
+
const te = [...X];
|
|
835
|
+
return te[s - 1] = U, te;
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
D({ page: s }), b == null || b(s);
|
|
839
|
+
}, lt = l.useMemo(
|
|
840
|
+
() => [
|
|
841
|
+
...a.filter((s) => !s.hidden),
|
|
842
|
+
...L("edit") || L("delete") ? [
|
|
843
|
+
{
|
|
844
|
+
key: "actions",
|
|
845
|
+
label: "",
|
|
846
|
+
align: "right",
|
|
847
|
+
render: (s) => /* @__PURE__ */ f("div", { className: "flex items-center justify-end gap-1", children: [
|
|
848
|
+
L("edit") ? /* @__PURE__ */ e(K, { variant: "ghost", size: "icon", "aria-label": "Edit", onClick: () => {
|
|
849
|
+
var z;
|
|
850
|
+
return (z = Z.current) == null ? void 0 : z.call(Z, s);
|
|
851
|
+
}, "data-testid": "resource-edit", children: /* @__PURE__ */ e(kt, { className: "h-3.5 w-3.5", "aria-hidden": !0 }) }) : null,
|
|
852
|
+
L("delete") ? /* @__PURE__ */ e(K, { variant: "ghost", size: "icon", "aria-label": "Delete", disabled: be, onClick: () => {
|
|
853
|
+
var z;
|
|
854
|
+
return void ((z = ee.current) == null ? void 0 : z.call(ee, s));
|
|
855
|
+
}, "data-testid": "resource-delete", children: /* @__PURE__ */ e(St, { className: "h-3.5 w-3.5 text-[var(--prui-danger)]", "aria-hidden": !0 }) }) : null
|
|
856
|
+
] })
|
|
857
|
+
}
|
|
858
|
+
] : []
|
|
859
|
+
],
|
|
860
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- can() depends only on the action functions
|
|
861
|
+
[a, r, o, h, be]
|
|
862
|
+
), st = () => {
|
|
863
|
+
he(null), W(!0);
|
|
864
|
+
}, ye = (s) => {
|
|
865
|
+
he(s), W(!0);
|
|
866
|
+
}, we = async (s) => {
|
|
867
|
+
if (!(!await Ft({
|
|
868
|
+
title: `${c.delete} ${H}?`,
|
|
869
|
+
message: c.deleteConfirmMessage,
|
|
870
|
+
confirmText: c.delete,
|
|
871
|
+
cancelText: c.cancel,
|
|
872
|
+
type: "danger"
|
|
873
|
+
}) || !h)) {
|
|
874
|
+
ve(!0);
|
|
875
|
+
try {
|
|
876
|
+
await h(s), await Q();
|
|
877
|
+
} finally {
|
|
878
|
+
ve(!1);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}, Z = l.useRef(ye);
|
|
882
|
+
Z.current = ye;
|
|
883
|
+
const ee = l.useRef(we);
|
|
884
|
+
ee.current = we;
|
|
885
|
+
const it = l.useCallback(
|
|
886
|
+
(s, z) => String(y ? y(s, z) : s.id ?? z),
|
|
887
|
+
[y]
|
|
888
|
+
), Ne = x ?? rr(a, _), ot = _ ? Object.fromEntries(
|
|
889
|
+
Ne.fields.map((s) => [s.name, _[s.name] ?? ""])
|
|
890
|
+
) : void 0, H = t.replace(/s$/, "");
|
|
891
|
+
return /* @__PURE__ */ f("div", { className: C("prui-resource flex flex-col gap-2", p), "data-testid": "resource", children: [
|
|
892
|
+
/* @__PURE__ */ e("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ e("h1", { className: "text-xl font-semibold capitalize text-[var(--prui-fg)]", children: t }) }),
|
|
893
|
+
/* @__PURE__ */ e(
|
|
894
|
+
It,
|
|
895
|
+
{
|
|
896
|
+
searchPlaceholder: R ?? c.searchEntity.replace("{name}", t),
|
|
897
|
+
searchValue: I,
|
|
898
|
+
onSearchChange: rt,
|
|
899
|
+
filters: et,
|
|
900
|
+
filterValues: q,
|
|
901
|
+
onFilterChange: tt,
|
|
902
|
+
actions: L("create") ? /* @__PURE__ */ f(K, { variant: "primary", size: "sm", onClick: st, "data-testid": "resource-create", children: [
|
|
903
|
+
/* @__PURE__ */ e(Tt, { className: "h-4 w-4", "aria-hidden": !0 }),
|
|
904
|
+
c.newEntity.replace("{name}", H)
|
|
905
|
+
] }) : void 0
|
|
906
|
+
}
|
|
907
|
+
),
|
|
908
|
+
pe ? /* @__PURE__ */ e("div", { role: "alert", "data-testid": "resource-error", className: "rounded-[var(--prui-radius)] border border-[var(--prui-danger)]/40 bg-[var(--prui-danger)]/10 px-3 py-2 text-sm text-[var(--prui-danger)]", children: pe }) : null,
|
|
909
|
+
/* @__PURE__ */ e(
|
|
910
|
+
Lt,
|
|
911
|
+
{
|
|
912
|
+
columns: lt,
|
|
913
|
+
rows: We,
|
|
914
|
+
rowKey: it,
|
|
915
|
+
sort: ne,
|
|
916
|
+
onSortChange: at,
|
|
917
|
+
loading: Ge,
|
|
918
|
+
selectable: v,
|
|
919
|
+
selectedRowKeys: Je,
|
|
920
|
+
onSelectionChange: (s, z) => {
|
|
921
|
+
D({ selection: s }), O == null || O(s, z);
|
|
922
|
+
},
|
|
923
|
+
renderExpandedRow: i,
|
|
924
|
+
expandedRowKeys: Ye,
|
|
925
|
+
onExpandedRowsChange: (s) => D({ expandedRows: s }),
|
|
926
|
+
virtualized: S
|
|
927
|
+
}
|
|
928
|
+
),
|
|
929
|
+
/* @__PURE__ */ e(
|
|
930
|
+
Kt,
|
|
931
|
+
{
|
|
932
|
+
page: F,
|
|
933
|
+
pageSize: j,
|
|
934
|
+
hasNextPage: ce != null,
|
|
935
|
+
hasPreviousPage: F > 1,
|
|
936
|
+
onPageChange: nt,
|
|
937
|
+
onPageSizeChange: (s) => {
|
|
938
|
+
D({ pageSize: s }), A == null || A(s);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
),
|
|
942
|
+
/* @__PURE__ */ f(Fe, { open: Qe, onClose: () => W(!1), size: "sm", ariaLabel: _ ? c.editEntity.replace("{name}", H) : c.newEntity.replace("{name}", H), noPadding: !0, children: [
|
|
943
|
+
/* @__PURE__ */ e("div", { className: "px-8 pt-8 pb-2", children: /* @__PURE__ */ e("h2", { className: "text-lg font-semibold", style: { color: "var(--prui-fg)" }, children: _ ? c.editEntity.replace("{name}", H) : c.newEntity.replace("{name}", H) }) }),
|
|
944
|
+
/* @__PURE__ */ e("div", { className: "px-8 pb-8", children: k ?? /* @__PURE__ */ e(
|
|
945
|
+
tr,
|
|
946
|
+
{
|
|
947
|
+
schema: Ne,
|
|
948
|
+
initialValues: ot,
|
|
949
|
+
onCancel: () => W(!1),
|
|
950
|
+
onSubmit: async (s) => {
|
|
951
|
+
_ ? await (o == null ? void 0 : o(_, s)) : await (r == null ? void 0 : r(s)), W(!1), await Q();
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
) })
|
|
955
|
+
] })
|
|
956
|
+
] });
|
|
957
|
+
}
|
|
958
|
+
const Pr = {
|
|
959
|
+
name: "Resource",
|
|
960
|
+
props: [
|
|
961
|
+
{ name: "name", type: "string", default: null, control: "text" },
|
|
962
|
+
{ name: "columns", type: "ResourceColumn<T>[]", default: null, control: "object" },
|
|
963
|
+
{ name: "list", type: "(query) => Promise<{rows, cursor}>", default: null, control: "none" },
|
|
964
|
+
{ name: "create", type: "(values) => Promise<void>", default: null, control: "none" },
|
|
965
|
+
{ name: "update", type: "(row, values) => Promise<void>", default: null, control: "none" },
|
|
966
|
+
{ name: "remove", type: "(row) => Promise<void>", default: null, control: "none" },
|
|
967
|
+
{ name: "delete", type: "(row) => Promise<void>", default: "alias of remove", control: "none" },
|
|
968
|
+
{ name: "actions", type: "('create' | 'edit' | 'delete')[]", default: "all provided", control: "multiselect", options: ["create", "edit", "delete"] },
|
|
969
|
+
{ name: "form", type: "ReactNode", default: "built-in schema form", control: "none" },
|
|
970
|
+
{ name: "formSchema", type: "FormSchema", default: "derived from columns", control: "object" },
|
|
971
|
+
{ name: "pageSize", type: "number", default: "20", control: "number" },
|
|
972
|
+
{ name: "state", type: "Partial<ResourceState>", default: "undefined", control: "object", description: "Controlled page/pageSize/search/filters/sort/selection/expandedRows." },
|
|
973
|
+
{ name: "defaultState", type: "Partial<ResourceState>", default: "{}", control: "object" },
|
|
974
|
+
{ name: "onStateChange", type: "(state: ResourceState) => void", default: null, control: "none" },
|
|
975
|
+
{ name: "onPageChange", type: "(page: number) => void", default: null, control: "none" },
|
|
976
|
+
{ name: "onPageSizeChange", type: "(size: number) => void", default: null, control: "none" },
|
|
977
|
+
{ name: "onFilterChange", type: "(filters: ToolbarFilterValues) => void", default: null, control: "none" },
|
|
978
|
+
{ name: "onSortChange", type: "(sort: ResourceState['sort']) => void", default: null, control: "none" },
|
|
979
|
+
{ name: "onSearchChange", type: "(search: string) => void", default: null, control: "none" },
|
|
980
|
+
{ name: "onSelectionChange", type: "(keys, rows) => void", default: null, control: "none" },
|
|
981
|
+
{ name: "selectable", type: "boolean | { multiple?: boolean }", default: "undefined", control: "boolean" },
|
|
982
|
+
{ name: "renderExpandedRow", type: "(row: T) => ReactNode", default: null, control: "none" },
|
|
983
|
+
{ name: "virtualized", type: "boolean", default: "false", control: "boolean" },
|
|
984
|
+
{ name: "searchDebounce", type: "number (ms)", default: "250", control: "number" }
|
|
985
|
+
]
|
|
986
|
+
};
|
|
987
|
+
function Or({ items: t, className: a }) {
|
|
988
|
+
return /* @__PURE__ */ e("div", { className: C("prui-stat-row grid gap-3 sm:grid-cols-2 lg:grid-cols-4", a), children: t.map((n, r) => {
|
|
989
|
+
const o = n.icon;
|
|
990
|
+
return /* @__PURE__ */ f(Ke, { "data-testid": "stat-card", children: [
|
|
991
|
+
/* @__PURE__ */ f(Be, { className: "pb-2", children: [
|
|
992
|
+
/* @__PURE__ */ f(Ue, { className: "flex items-center gap-1.5 text-xs", children: [
|
|
993
|
+
o ? /* @__PURE__ */ e(o, { className: "h-3.5 w-3.5", "aria-hidden": !0 }) : null,
|
|
994
|
+
n.label
|
|
995
|
+
] }),
|
|
996
|
+
/* @__PURE__ */ e(Ve, { className: "text-2xl", children: n.value })
|
|
997
|
+
] }),
|
|
998
|
+
n.delta ? /* @__PURE__ */ e(_e, { className: "pb-3", children: /* @__PURE__ */ e(
|
|
999
|
+
"span",
|
|
1000
|
+
{
|
|
1001
|
+
className: C(
|
|
1002
|
+
"text-xs font-medium",
|
|
1003
|
+
n.trend === "up" && "text-[var(--prui-ok)]",
|
|
1004
|
+
n.trend === "down" && "text-[var(--prui-danger)]",
|
|
1005
|
+
(!n.trend || n.trend === "flat") && "text-[var(--prui-dim)]"
|
|
1006
|
+
),
|
|
1007
|
+
children: n.delta
|
|
1008
|
+
}
|
|
1009
|
+
) }) : null
|
|
1010
|
+
] }, `${n.label}-${r}`);
|
|
1011
|
+
}) });
|
|
1012
|
+
}
|
|
1013
|
+
const Dr = {
|
|
1014
|
+
name: "StatRow",
|
|
1015
|
+
props: [
|
|
1016
|
+
{ name: "items", type: "StatItem[]", default: null, control: "object" },
|
|
1017
|
+
{ name: "className", type: "string", default: "undefined", control: "text" }
|
|
1018
|
+
]
|
|
1019
|
+
};
|
|
1020
|
+
function nr(t) {
|
|
1021
|
+
if (t)
|
|
1022
|
+
return t.map((a) => typeof a == "string" || typeof a == "number" ? { label: String(a), value: String(a) } : a);
|
|
1023
|
+
}
|
|
1024
|
+
function lr({ field: t }) {
|
|
1025
|
+
const { name: a, type: n, value: r, onChange: o } = t;
|
|
1026
|
+
if (!n || !a) return null;
|
|
1027
|
+
const d = `prui-settings-${a}`;
|
|
1028
|
+
return n === "switch" ? /* @__PURE__ */ e("label", { className: "flex items-center gap-2", htmlFor: d, children: /* @__PURE__ */ e(
|
|
1029
|
+
Le,
|
|
1030
|
+
{
|
|
1031
|
+
id: d,
|
|
1032
|
+
checked: !!r,
|
|
1033
|
+
onChange: (m) => o == null ? void 0 : o(m),
|
|
1034
|
+
"aria-label": t.label
|
|
1035
|
+
}
|
|
1036
|
+
) }) : n === "select" ? /* @__PURE__ */ e(
|
|
1037
|
+
Ie,
|
|
1038
|
+
{
|
|
1039
|
+
id: d,
|
|
1040
|
+
className: "w-56",
|
|
1041
|
+
options: nr(t.options) ?? [],
|
|
1042
|
+
value: String(r ?? ""),
|
|
1043
|
+
onChange: (m) => o == null ? void 0 : o(m),
|
|
1044
|
+
"aria-label": t.label
|
|
1045
|
+
}
|
|
1046
|
+
) : /* @__PURE__ */ e(
|
|
1047
|
+
ie,
|
|
1048
|
+
{
|
|
1049
|
+
id: d,
|
|
1050
|
+
type: n === "number" ? "number" : "text",
|
|
1051
|
+
className: "h-8 w-56",
|
|
1052
|
+
value: String(r ?? ""),
|
|
1053
|
+
onChange: (m) => o == null ? void 0 : o(n === "number" ? m.target.value === "" ? "" : Number(m.target.value) : m.target.value),
|
|
1054
|
+
"aria-label": t.label
|
|
1055
|
+
}
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
function zr({ title: t = "Settings", sections: a, className: n }) {
|
|
1059
|
+
return /* @__PURE__ */ f("div", { className: C("prui-settings mx-auto flex w-full max-w-4xl flex-col gap-6", n), children: [
|
|
1060
|
+
/* @__PURE__ */ e("h1", { className: "text-xl font-semibold text-[var(--prui-fg)]", children: t }),
|
|
1061
|
+
/* @__PURE__ */ f("div", { className: "flex flex-col gap-6 md:flex-row", children: [
|
|
1062
|
+
/* @__PURE__ */ e("nav", { "aria-label": "Settings sections", className: "md:w-56 md:shrink-0", children: /* @__PURE__ */ e("ul", { className: "flex flex-row flex-wrap gap-1 md:flex-col", children: a.map((r) => /* @__PURE__ */ e("li", { children: /* @__PURE__ */ e(
|
|
1063
|
+
"a",
|
|
1064
|
+
{
|
|
1065
|
+
href: `#settings-${r.id}`,
|
|
1066
|
+
className: "block rounded-[var(--prui-radius)] px-2.5 py-1.5 text-sm text-[var(--prui-dim)] hover:bg-[var(--prui-raise)] hover:text-[var(--prui-fg)]",
|
|
1067
|
+
children: r.title ?? r.label ?? r.id
|
|
1068
|
+
}
|
|
1069
|
+
) }, r.id)) }) }),
|
|
1070
|
+
/* @__PURE__ */ e("div", { className: "flex min-w-0 flex-1 flex-col gap-4", children: a.map((r) => /* @__PURE__ */ f(Ke, { id: `settings-${r.id}`, "data-testid": "settings-section", children: [
|
|
1071
|
+
/* @__PURE__ */ f(Be, { children: [
|
|
1072
|
+
/* @__PURE__ */ e(Ve, { children: r.title ?? r.label ?? r.id }),
|
|
1073
|
+
r.description ? /* @__PURE__ */ e(Ue, { children: r.description }) : null
|
|
1074
|
+
] }),
|
|
1075
|
+
/* @__PURE__ */ e(_e, { children: r.content ?? /* @__PURE__ */ e("dl", { className: "flex flex-col divide-y divide-[var(--prui-line)]", children: (r.fields ?? []).map((o, d) => /* @__PURE__ */ f("div", { className: "flex flex-col gap-2 py-3 first:pt-0 last:pb-0 sm:flex-row sm:items-center sm:justify-between", children: [
|
|
1076
|
+
/* @__PURE__ */ f("div", { className: "min-w-0", children: [
|
|
1077
|
+
/* @__PURE__ */ e("dt", { className: "text-sm font-medium text-[var(--prui-fg)]", children: o.label }),
|
|
1078
|
+
o.description ? /* @__PURE__ */ e("dd", { className: "text-xs text-[var(--prui-dim)]", children: o.description }) : null
|
|
1079
|
+
] }),
|
|
1080
|
+
/* @__PURE__ */ e("div", { className: "shrink-0", children: o.control ?? /* @__PURE__ */ e(lr, { field: o }) })
|
|
1081
|
+
] }, `${o.label}-${d}`)) }) })
|
|
1082
|
+
] }, r.id)) })
|
|
1083
|
+
] })
|
|
1084
|
+
] });
|
|
1085
|
+
}
|
|
1086
|
+
const Ar = {
|
|
1087
|
+
name: "Settings",
|
|
1088
|
+
props: [
|
|
1089
|
+
{ name: "title", type: "string", default: "'Settings'", control: "text" },
|
|
1090
|
+
{ name: "sections", type: "SettingsSection[]", default: null, control: "object" }
|
|
1091
|
+
]
|
|
1092
|
+
}, Pe = ["mousedown", "keydown", "scroll", "touchstart", "click"];
|
|
1093
|
+
function sr({
|
|
1094
|
+
timeout: t = 15,
|
|
1095
|
+
warningTime: a = 2,
|
|
1096
|
+
onTimeout: n,
|
|
1097
|
+
onExtend: r,
|
|
1098
|
+
title: o = "Session expiring soon",
|
|
1099
|
+
message: d = "Your session is about to expire due to inactivity."
|
|
1100
|
+
}) {
|
|
1101
|
+
const m = Math.max(0, t) * 6e4, T = Math.min(Math.max(0, a) * 6e4, m), [k, x] = l.useState(!1), [y, R] = l.useState(T), w = l.useRef(null), P = l.useRef(null), g = l.useRef(null), u = l.useRef(!1), b = l.useCallback(() => {
|
|
1102
|
+
for (const i of [w, P, g])
|
|
1103
|
+
i.current != null && (clearInterval(i.current), clearTimeout(i.current), i.current = null);
|
|
1104
|
+
}, []), E = l.useCallback(() => {
|
|
1105
|
+
b(), x(!1), n == null || n();
|
|
1106
|
+
}, [b, n]), M = l.useCallback(() => {
|
|
1107
|
+
b(), x(!1), u.current = !1, w.current = window.setTimeout(() => {
|
|
1108
|
+
u.current = !0, R(T), x(!0), g.current = window.setInterval(() => {
|
|
1109
|
+
R((i) => i <= 1e3 ? (E(), 0) : i - 1e3);
|
|
1110
|
+
}, 1e3);
|
|
1111
|
+
}, m - T), P.current = window.setTimeout(E, m);
|
|
1112
|
+
}, [b, E, m, T]);
|
|
1113
|
+
l.useEffect(() => {
|
|
1114
|
+
const i = () => {
|
|
1115
|
+
u.current || M();
|
|
1116
|
+
};
|
|
1117
|
+
for (const S of Pe) document.addEventListener(S, i, { passive: !0 });
|
|
1118
|
+
return M(), () => {
|
|
1119
|
+
b();
|
|
1120
|
+
for (const S of Pe) document.removeEventListener(S, i);
|
|
1121
|
+
};
|
|
1122
|
+
}, [M, b]);
|
|
1123
|
+
const $ = () => {
|
|
1124
|
+
r == null || r(), M();
|
|
1125
|
+
}, A = Math.floor(y / 6e4), O = Math.floor(y % 6e4 / 1e3), v = `${A}:${String(O).padStart(2, "0")}`;
|
|
1126
|
+
return /* @__PURE__ */ f(
|
|
1127
|
+
Fe,
|
|
1128
|
+
{
|
|
1129
|
+
open: k,
|
|
1130
|
+
onClose: $,
|
|
1131
|
+
size: "sm",
|
|
1132
|
+
ariaLabel: o,
|
|
1133
|
+
children: [
|
|
1134
|
+
/* @__PURE__ */ f("div", { className: "flex flex-col items-center gap-1 px-8 pb-2 pt-8 text-center", children: [
|
|
1135
|
+
/* @__PURE__ */ e("div", { className: "mb-2 flex h-12 w-12 items-center justify-center rounded-full bg-[var(--prui-warn)]/15", children: /* @__PURE__ */ e(Ct, { className: "h-6 w-6 text-[var(--prui-warn)]", "aria-hidden": !0 }) }),
|
|
1136
|
+
/* @__PURE__ */ e("h2", { className: "text-lg font-semibold text-[var(--prui-fg)]", children: o }),
|
|
1137
|
+
/* @__PURE__ */ e("p", { className: "text-sm text-[var(--prui-dim)]", children: d }),
|
|
1138
|
+
/* @__PURE__ */ e("div", { className: "py-4 font-mono text-4xl font-bold text-[var(--prui-fg)]", "data-testid": "session-countdown", children: v })
|
|
1139
|
+
] }),
|
|
1140
|
+
/* @__PURE__ */ f("div", { className: "flex flex-col gap-2 px-8 pb-8 sm:flex-row", children: [
|
|
1141
|
+
/* @__PURE__ */ e(K, { variant: "default", className: "flex-1", onClick: E, "data-testid": "session-logout", children: "Log out now" }),
|
|
1142
|
+
/* @__PURE__ */ e(K, { variant: "primary", className: "flex-1", onClick: $, "data-testid": "session-extend", children: "Continue session" })
|
|
1143
|
+
] })
|
|
1144
|
+
]
|
|
1145
|
+
}
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
const ir = {
|
|
1149
|
+
name: "SessionTimeout",
|
|
1150
|
+
props: [
|
|
1151
|
+
{ name: "timeout", type: "number", default: "15", control: "number" },
|
|
1152
|
+
{ name: "warningTime", type: "number", default: "2", control: "number" },
|
|
1153
|
+
{ name: "onTimeout", type: "() => void", default: null, control: "none" },
|
|
1154
|
+
{ name: "onExtend", type: "() => void", default: null, control: "none" }
|
|
1155
|
+
]
|
|
1156
|
+
}, or = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1157
|
+
__proto__: null,
|
|
1158
|
+
SessionTimeout: sr,
|
|
1159
|
+
sessionTimeoutPropsMeta: ir
|
|
1160
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1161
|
+
function $r({ title: t, description: a, brand: n, width: r = "max-w-sm", footer: o, children: d, className: m }) {
|
|
1162
|
+
return /* @__PURE__ */ e("div", { className: C("prui-auth-shell flex min-h-[100dvh] items-center justify-center bg-[var(--prui-background)] p-4", m), "data-testid": "auth-shell", children: /* @__PURE__ */ f("div", { className: C("w-full", r), children: [
|
|
1163
|
+
n ? /* @__PURE__ */ f("div", { className: "mb-6 flex items-center justify-center gap-2", "data-testid": "auth-shell-brand", children: [
|
|
1164
|
+
n.mark ? /* @__PURE__ */ e("img", { src: n.mark, alt: "", className: "h-8 w-8 rounded-[var(--prui-radius-1)] object-cover" }) : null,
|
|
1165
|
+
/* @__PURE__ */ e("span", { className: "text-lg font-semibold text-[var(--prui-fg)]", children: n.name })
|
|
1166
|
+
] }) : null,
|
|
1167
|
+
/* @__PURE__ */ f("div", { className: "rounded-[var(--prui-radius)] border border-[var(--prui-line)] bg-[var(--prui-surface)] p-6", children: [
|
|
1168
|
+
/* @__PURE__ */ f("div", { className: "mb-4 flex flex-col gap-1 text-center", children: [
|
|
1169
|
+
/* @__PURE__ */ e("h1", { className: "text-lg font-semibold text-[var(--prui-fg)]", children: t }),
|
|
1170
|
+
a ? /* @__PURE__ */ e("p", { className: "text-sm text-[var(--prui-dim)]", children: a }) : null
|
|
1171
|
+
] }),
|
|
1172
|
+
d,
|
|
1173
|
+
o ? /* @__PURE__ */ e("div", { className: "mt-4 text-center text-sm text-[var(--prui-dim)]", children: o }) : null
|
|
1174
|
+
] })
|
|
1175
|
+
] }) });
|
|
1176
|
+
}
|
|
1177
|
+
const Fr = {
|
|
1178
|
+
name: "AuthShell",
|
|
1179
|
+
props: [
|
|
1180
|
+
{ name: "title", type: "string", default: null, control: "text" },
|
|
1181
|
+
{ name: "description", type: "ReactNode", default: null, control: "text" },
|
|
1182
|
+
{ name: "brand", type: "{ name, mark?, href? }", default: "undefined", control: "object" },
|
|
1183
|
+
{ name: "width", type: "string", default: "'max-w-sm'", control: "text" },
|
|
1184
|
+
{ name: "footer", type: "ReactNode", default: null, control: "none" },
|
|
1185
|
+
{ name: "children", type: "ReactNode", default: null, control: "none" }
|
|
1186
|
+
]
|
|
1187
|
+
};
|
|
1188
|
+
export {
|
|
1189
|
+
Rr as A,
|
|
1190
|
+
Gt as C,
|
|
1191
|
+
tr as F,
|
|
1192
|
+
jr as R,
|
|
1193
|
+
sr as S,
|
|
1194
|
+
Qt as a,
|
|
1195
|
+
$r as b,
|
|
1196
|
+
qt as c,
|
|
1197
|
+
zr as d,
|
|
1198
|
+
Ee as e,
|
|
1199
|
+
Or as f,
|
|
1200
|
+
Er as g,
|
|
1201
|
+
Fr as h,
|
|
1202
|
+
Mr as i,
|
|
1203
|
+
Ar as j,
|
|
1204
|
+
Dr as k,
|
|
1205
|
+
Pr as r,
|
|
1206
|
+
ir as s,
|
|
1207
|
+
Jt as u
|
|
1208
|
+
};
|