@colveor/admin 0.0.0-stage → 0.5.3
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/LICENSE.md +106 -0
- package/README.md +365 -2
- package/TAILWINDADMIN-LICENSE +21 -0
- package/dist/account/data.d.ts +1 -0
- package/dist/account/data.js +44 -0
- package/dist/account/profile.d.ts +6 -0
- package/dist/account/profile.js +118 -0
- package/dist/account/sessions.d.ts +1 -0
- package/dist/account/sessions.js +26 -0
- package/dist/account/shared.d.ts +26 -0
- package/dist/account/shared.js +44 -0
- package/dist/account/two-factor.d.ts +5 -0
- package/dist/account/two-factor.js +60 -0
- package/dist/actions.d.ts +39 -0
- package/dist/actions.js +81 -0
- package/dist/api/audit.gen.d.ts +80 -0
- package/dist/api/audit.gen.js +43 -0
- package/dist/api/auth.gen.d.ts +537 -0
- package/dist/api/auth.gen.js +313 -0
- package/dist/api/errors.gen.d.ts +16 -0
- package/dist/api/errors.gen.js +2 -0
- package/dist/api/gormx.gen.d.ts +60 -0
- package/dist/api/gormx.gen.js +16 -0
- package/dist/api/health.gen.d.ts +103 -0
- package/dist/api/health.gen.js +23 -0
- package/dist/api/index.gen.d.ts +21 -0
- package/dist/api/index.gen.js +22 -0
- package/dist/api/invitations.gen.d.ts +128 -0
- package/dist/api/invitations.gen.js +57 -0
- package/dist/api/ledger.gen.d.ts +269 -0
- package/dist/api/ledger.gen.js +113 -0
- package/dist/api/msgtemplate.gen.d.ts +31 -0
- package/dist/api/msgtemplate.gen.js +2 -0
- package/dist/api/notifications.gen.d.ts +66 -0
- package/dist/api/notifications.gen.js +28 -0
- package/dist/api/outbox.gen.d.ts +8 -0
- package/dist/api/outbox.gen.js +2 -0
- package/dist/api/queue.gen.d.ts +112 -0
- package/dist/api/queue.gen.js +15 -0
- package/dist/api/rbac.gen.d.ts +406 -0
- package/dist/api/rbac.gen.js +191 -0
- package/dist/api/reauth.gen.d.ts +289 -0
- package/dist/api/reauth.gen.js +122 -0
- package/dist/api/recorded_payments.gen.d.ts +171 -0
- package/dist/api/recorded_payments.gen.js +79 -0
- package/dist/api/sessions.gen.d.ts +64 -0
- package/dist/api/sessions.gen.js +48 -0
- package/dist/api/settings.gen.d.ts +147 -0
- package/dist/api/settings.gen.js +69 -0
- package/dist/api/storage.gen.d.ts +327 -0
- package/dist/api/storage.gen.js +208 -0
- package/dist/api/support_access.gen.d.ts +155 -0
- package/dist/api/support_access.gen.js +131 -0
- package/dist/api/users.gen.d.ts +407 -0
- package/dist/api/users.gen.js +159 -0
- package/dist/api/verification.gen.d.ts +427 -0
- package/dist/api/verification.gen.js +280 -0
- package/dist/api/webhooks.gen.d.ts +110 -0
- package/dist/api/webhooks.gen.js +45 -0
- package/dist/auth-layout.d.ts +9 -0
- package/dist/auth-layout.js +5 -0
- package/dist/banner.d.ts +1 -0
- package/dist/banner.js +49 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.js +72 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +82 -0
- package/dist/dates.d.ts +4 -0
- package/dist/dates.js +16 -0
- package/dist/header.d.ts +12 -0
- package/dist/header.js +105 -0
- package/dist/icons.d.ts +2 -0
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +42 -0
- package/dist/kit/avatar.d.ts +5 -0
- package/dist/kit/avatar.js +16 -0
- package/dist/kit/badge.d.ts +10 -0
- package/dist/kit/badge.js +31 -0
- package/dist/kit/card.d.ts +12 -0
- package/dist/kit/card.js +7 -0
- package/dist/kit/code-area.d.ts +15 -0
- package/dist/kit/code-area.js +69 -0
- package/dist/kit/dropdown.d.ts +26 -0
- package/dist/kit/dropdown.js +67 -0
- package/dist/kit/filter-tabs.d.ts +9 -0
- package/dist/kit/filter-tabs.js +7 -0
- package/dist/kit/modal.d.ts +8 -0
- package/dist/kit/modal.js +15 -0
- package/dist/kit/page-header.d.ts +13 -0
- package/dist/kit/page-header.js +13 -0
- package/dist/kit/search.d.ts +4 -0
- package/dist/kit/search.js +16 -0
- package/dist/kit/tooltip.d.ts +17 -0
- package/dist/kit/tooltip.js +52 -0
- package/dist/message-editor.d.ts +9 -0
- package/dist/message-editor.js +80 -0
- package/dist/money.d.ts +10 -0
- package/dist/money.js +17 -0
- package/dist/next.d.ts +6 -0
- package/dist/next.js +19 -0
- package/dist/pages/account.d.ts +1 -0
- package/dist/pages/account.js +47 -0
- package/dist/pages/audit.d.ts +1 -0
- package/dist/pages/audit.js +88 -0
- package/dist/pages/forgot-password.d.ts +1 -0
- package/dist/pages/forgot-password.js +73 -0
- package/dist/pages/ledger.d.ts +1 -0
- package/dist/pages/ledger.js +132 -0
- package/dist/pages/roles.d.ts +1 -0
- package/dist/pages/roles.js +102 -0
- package/dist/pages/settings.d.ts +1 -0
- package/dist/pages/settings.js +86 -0
- package/dist/pages/sign-in.d.ts +5 -0
- package/dist/pages/sign-in.js +117 -0
- package/dist/pages/status.d.ts +1 -0
- package/dist/pages/status.js +122 -0
- package/dist/pages/support.d.ts +1 -0
- package/dist/pages/support.js +90 -0
- package/dist/pages/teams.d.ts +1 -0
- package/dist/pages/teams.js +94 -0
- package/dist/pages/users.d.ts +1 -0
- package/dist/pages/users.js +158 -0
- package/dist/pages/webhooks.d.ts +1 -0
- package/dist/pages/webhooks.js +88 -0
- package/dist/permissions.d.ts +5 -0
- package/dist/permissions.js +31 -0
- package/dist/proof.d.ts +10 -0
- package/dist/proof.js +78 -0
- package/dist/proxy.d.ts +10 -0
- package/dist/proxy.js +166 -0
- package/dist/retry.d.ts +8 -0
- package/dist/retry.js +30 -0
- package/dist/router.d.ts +13 -0
- package/dist/router.js +14 -0
- package/dist/setting-fields.d.ts +12 -0
- package/dist/setting-fields.js +102 -0
- package/dist/setting-list.d.ts +22 -0
- package/dist/setting-list.js +78 -0
- package/dist/shell.d.ts +40 -0
- package/dist/shell.js +97 -0
- package/dist/support.d.ts +37 -0
- package/dist/support.js +76 -0
- package/dist/table.d.ts +40 -0
- package/dist/table.js +73 -0
- package/dist/ui.d.ts +39 -0
- package/dist/ui.js +56 -0
- package/dist/user-actions.d.ts +30 -0
- package/dist/user-actions.js +129 -0
- package/dist/user-roles.d.ts +4 -0
- package/dist/user-roles.js +51 -0
- package/dist/user-row-menu.d.ts +14 -0
- package/dist/user-row-menu.js +45 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/package.json +63 -4
package/dist/config.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// admin.config.ts: what a project sets (docs/admin.md, Adding a project page).
|
|
2
|
+
import * as audit from "./api/audit.gen";
|
|
3
|
+
import * as health from "./api/health.gen";
|
|
4
|
+
import * as ledger from "./api/ledger.gen";
|
|
5
|
+
import * as rbac from "./api/rbac.gen";
|
|
6
|
+
import * as settings from "./api/settings.gen";
|
|
7
|
+
import * as support from "./api/support_access.gen";
|
|
8
|
+
import * as users from "./api/users.gen";
|
|
9
|
+
import * as webhooks from "./api/webhooks.gen";
|
|
10
|
+
import { icons } from "./icons";
|
|
11
|
+
/** Declares admin.config.ts, typed: export default defineConfig({ ... }). */
|
|
12
|
+
export function defineConfig(config) {
|
|
13
|
+
return config;
|
|
14
|
+
}
|
|
15
|
+
// The framework's pages, added as they are built (docs/ADMIN_ROADMAP.md, A4).
|
|
16
|
+
export const coreNav = [
|
|
17
|
+
{
|
|
18
|
+
label: "Users",
|
|
19
|
+
href: "/users",
|
|
20
|
+
group: "Management",
|
|
21
|
+
icon: icons.users,
|
|
22
|
+
permission: users.PermissionUserRead,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: "Roles",
|
|
26
|
+
href: "/roles",
|
|
27
|
+
group: "Management",
|
|
28
|
+
icon: icons.roles,
|
|
29
|
+
permission: rbac.PermissionRead,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: "Teams",
|
|
33
|
+
href: "/teams",
|
|
34
|
+
group: "Management",
|
|
35
|
+
icon: icons.teams,
|
|
36
|
+
permission: rbac.PermissionSuspendTeams,
|
|
37
|
+
},
|
|
38
|
+
// Only while the support_access module is on (its permissions exist then).
|
|
39
|
+
{
|
|
40
|
+
label: "Support access",
|
|
41
|
+
href: "/support",
|
|
42
|
+
group: "Management",
|
|
43
|
+
icon: icons.support,
|
|
44
|
+
permission: [support.PermissionRequest, support.PermissionRead],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
label: "Settings",
|
|
48
|
+
href: "/settings",
|
|
49
|
+
group: "System",
|
|
50
|
+
icon: icons.settings,
|
|
51
|
+
permission: settings.PermissionSettingRead,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
label: "Audit log",
|
|
55
|
+
href: "/audit",
|
|
56
|
+
group: "System",
|
|
57
|
+
icon: icons.audit,
|
|
58
|
+
permission: audit.PermissionRead,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: "Webhook events",
|
|
62
|
+
href: "/webhooks",
|
|
63
|
+
group: "System",
|
|
64
|
+
icon: icons.webhooks,
|
|
65
|
+
permission: webhooks.PermissionRead,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
label: "System status",
|
|
69
|
+
href: "/status",
|
|
70
|
+
group: "System",
|
|
71
|
+
icon: icons.status,
|
|
72
|
+
permission: health.PermissionHealthRead,
|
|
73
|
+
},
|
|
74
|
+
// Any one of the ledger's admin permissions: the page shows its parts.
|
|
75
|
+
{
|
|
76
|
+
label: "Ledger",
|
|
77
|
+
href: "/ledger",
|
|
78
|
+
group: "Money",
|
|
79
|
+
icon: icons.ledger,
|
|
80
|
+
permission: [ledger.PermissionApprove, ledger.PermissionManage, ledger.PermissionAdjust],
|
|
81
|
+
},
|
|
82
|
+
];
|
package/dist/dates.d.ts
ADDED
package/dist/dates.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The panel's one date format: 1 Dec, 2026. Use these for every date shown,
|
|
2
|
+
// so the pages agree.
|
|
3
|
+
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
4
|
+
/** "1 Dec, 2026", in the viewer's time zone. */
|
|
5
|
+
export function formatDate(value) {
|
|
6
|
+
const d = new Date(value);
|
|
7
|
+
return `${d.getDate()} ${MONTHS[d.getMonth()]}, ${d.getFullYear()}`;
|
|
8
|
+
}
|
|
9
|
+
/** "1 Dec, 2026, 14:05": for a moment, not just a day. */
|
|
10
|
+
export function formatDateTime(value) {
|
|
11
|
+
const time = new Date(value).toLocaleTimeString(undefined, {
|
|
12
|
+
hour: "2-digit",
|
|
13
|
+
minute: "2-digit",
|
|
14
|
+
});
|
|
15
|
+
return `${formatDate(value)}, ${time}`;
|
|
16
|
+
}
|
package/dist/header.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Asks an open account page to show a tab (detail: its key). */
|
|
2
|
+
export declare const ACCOUNT_TAB_EVENT = "colveor:account-tab";
|
|
3
|
+
/** Search the menu: type, then pick a page (Enter takes the first). */
|
|
4
|
+
export declare function NavSearch(): import("react").JSX.Element;
|
|
5
|
+
/** The user's notifications: the unread count, the latest five, mark read. */
|
|
6
|
+
export declare function NotificationsMenu(): import("react").JSX.Element | null;
|
|
7
|
+
/** The signed-in admin: name and email, their account settings, sign out. */
|
|
8
|
+
/** The signed-in admin: their photo or initials; a menu with who they are,
|
|
9
|
+
* their account's pages, and sign out. */
|
|
10
|
+
export declare function UserMenu({ accountPath }: {
|
|
11
|
+
accountPath?: string;
|
|
12
|
+
}): import("react").JSX.Element;
|
package/dist/header.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// The header's parts, for the template's frame (or a project's own): a
|
|
4
|
+
// search over the menu, the notifications, and the user's menu. Dropdowns
|
|
5
|
+
// open with a short animation and close on a click outside or Escape.
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import * as notifications from "./api/notifications.gen";
|
|
8
|
+
import { api, signOut } from "./client";
|
|
9
|
+
import { Avatar } from "./kit/avatar";
|
|
10
|
+
import { Dropdown, iconButton } from "./kit/dropdown";
|
|
11
|
+
import { useAdmin, useCan, useNav } from "./shell";
|
|
12
|
+
/** Asks an open account page to show a tab (detail: its key). */
|
|
13
|
+
export const ACCOUNT_TAB_EVENT = "colveor:account-tab";
|
|
14
|
+
/** Search the menu: type, then pick a page (Enter takes the first). */
|
|
15
|
+
export function NavSearch() {
|
|
16
|
+
const { router } = useAdmin();
|
|
17
|
+
const nav = useNav();
|
|
18
|
+
const [q, setQ] = useState("");
|
|
19
|
+
const [focus, setFocus] = useState(false);
|
|
20
|
+
const matches = q.trim() === ""
|
|
21
|
+
? []
|
|
22
|
+
: nav.filter((i) => i.label.toLowerCase().includes(q.trim().toLowerCase()));
|
|
23
|
+
const go = (href) => {
|
|
24
|
+
setQ("");
|
|
25
|
+
router.navigate(href);
|
|
26
|
+
};
|
|
27
|
+
return (_jsxs("div", { className: "relative hidden w-full max-w-md xl:block", children: [_jsx("input", { type: "search", value: q, "aria-label": "Search the menu", placeholder: "Search pages\u2026", onChange: (e) => setQ(e.target.value), onFocus: () => setFocus(true), onBlur: () => setTimeout(() => setFocus(false), 150), onKeyDown: (e) => e.key === "Enter" && matches[0] && go(matches[0].href), className: "h-11 w-full rounded-lg border border-gray-200 bg-transparent px-4 text-sm text-gray-800 transition placeholder:text-gray-400 focus:border-brand-300 focus:outline-none focus:ring-3 focus:ring-brand-500/10 dark:border-gray-800 dark:text-white/90" }), focus && matches.length > 0 && (_jsx("ul", { className: "absolute z-50 mt-2 w-full animate-pop-in rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-gray-800 dark:bg-gray-900", children: matches.map((m) => (_jsx("li", { children: _jsx("button", { type: "button", onMouseDown: () => go(m.href), className: "w-full rounded-lg px-3 py-2 text-left text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-white/5", children: m.label }) }, m.href))) }))] }));
|
|
28
|
+
}
|
|
29
|
+
/** The user's notifications: the unread count, the latest five, mark read. */
|
|
30
|
+
export function NotificationsMenu() {
|
|
31
|
+
const can = useCan(notifications.PermissionNotificationRead);
|
|
32
|
+
const [unread, setUnread] = useState(0);
|
|
33
|
+
const [items, setItems] = useState([]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!can) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const count = () => api
|
|
39
|
+
.get("/v1/notifications/unread-count")
|
|
40
|
+
.then((r) => setUnread(r.unread))
|
|
41
|
+
.catch(() => undefined);
|
|
42
|
+
count();
|
|
43
|
+
const timer = setInterval(count, 60_000);
|
|
44
|
+
return () => clearInterval(timer);
|
|
45
|
+
}, [can]);
|
|
46
|
+
if (!can) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const load = () => api
|
|
50
|
+
.get("/v1/notifications", { limit: 5 })
|
|
51
|
+
.then((p) => setItems(p.items))
|
|
52
|
+
.catch(() => undefined);
|
|
53
|
+
return (_jsx(Dropdown, { label: "Notifications", width: "w-80", button: () => (_jsxs("span", { className: iconButton, onClickCapture: load, children: [unread > 0 && (_jsxs("span", { className: "absolute top-0.5 right-0 flex size-2.5", children: [_jsx("span", { className: "absolute inline-flex size-full animate-ping rounded-full bg-brand-400 opacity-75" }), _jsx("span", { className: "relative inline-flex size-2.5 rounded-full bg-brand-500" })] })), _jsx(BellIcon, {})] })), children: () => (_jsxs("div", { children: [_jsxs("div", { className: "mb-2 flex items-center justify-between px-2", children: [_jsx("span", { className: "font-medium text-gray-800 dark:text-white/90", children: "Notifications" }), unread > 0 && (_jsx("button", { type: "button", className: "text-xs text-brand-500 hover:text-brand-600", onClick: () => api
|
|
54
|
+
.post("/v1/notifications/read")
|
|
55
|
+
.then(() => setUnread(0))
|
|
56
|
+
.catch(() => undefined), children: "Mark all read" }))] }), items.length === 0 ? (_jsx("p", { className: "px-2 py-6 text-center text-sm text-gray-500 dark:text-gray-400", children: "Nothing new." })) : (_jsx("ul", { className: "max-h-80 space-y-1 overflow-y-auto", children: items.map((n) => (_jsxs("li", { className: "rounded-lg px-2 py-2 hover:bg-gray-50 dark:hover:bg-white/5", children: [_jsxs("p", { className: "text-sm text-gray-800 dark:text-white/90", children: [n.read_at == null && (_jsx("span", { className: "mr-1.5 inline-block size-1.5 rounded-full bg-brand-500 align-middle" })), n.title] }), _jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: n.body })] }, n.id))) }))] })) }));
|
|
57
|
+
}
|
|
58
|
+
/** The signed-in admin: name and email, their account settings, sign out. */
|
|
59
|
+
/** The signed-in admin: their photo or initials; a menu with who they are,
|
|
60
|
+
* their account's pages, and sign out. */
|
|
61
|
+
export function UserMenu({ accountPath = "/account" }) {
|
|
62
|
+
const { config, router, roles } = useAdmin();
|
|
63
|
+
const { Link } = router;
|
|
64
|
+
const [me, setMe] = useState(null);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
api
|
|
67
|
+
.get("/v1/me")
|
|
68
|
+
.then(setMe)
|
|
69
|
+
.catch(() => undefined);
|
|
70
|
+
}, []);
|
|
71
|
+
const p = me?.details;
|
|
72
|
+
const name = p?.display_name || [p?.first_name, p?.last_name].filter(Boolean).join(" ") || me?.email || "";
|
|
73
|
+
const role = p?.occupation || roles[0]?.replaceAll("_", " ") || "";
|
|
74
|
+
const links = [
|
|
75
|
+
["My profile", "Account settings", accountPath, _jsx(PersonTile, {}, "p")],
|
|
76
|
+
[
|
|
77
|
+
"Security",
|
|
78
|
+
"Password and two-step sign-in",
|
|
79
|
+
`${accountPath}?tab=two-factor`,
|
|
80
|
+
_jsx(ShieldTile, {}, "s"),
|
|
81
|
+
],
|
|
82
|
+
["Devices", "Where you're signed in", `${accountPath}?tab=sessions`, _jsx(DevicesTile, {}, "d")],
|
|
83
|
+
];
|
|
84
|
+
return (_jsx(Dropdown, { label: "Your account", width: "w-80", button: () => (_jsx(Avatar, { name: name, url: p?.photo?.url, className: "size-10 ring-2 ring-transparent transition hover:ring-brand-200 dark:hover:ring-brand-500/30" })), children: (close) => (_jsxs("div", { className: "p-3", children: [_jsx("p", { className: "text-lg font-medium text-gray-800 dark:text-white/90", children: "User Profile" }), _jsxs("div", { className: "mt-4 flex items-center gap-4 border-b border-gray-200 pb-5 dark:border-gray-800", children: [_jsx(Avatar, { name: name, url: p?.photo?.url, className: "size-16 text-xl" }), _jsxs("div", { className: "min-w-0", children: [_jsx("p", { className: "truncate font-medium text-gray-800 dark:text-white/90", children: name }), role !== "" && (_jsx("p", { className: "truncate text-sm text-gray-500 capitalize dark:text-gray-400", children: role })), me?.email && (_jsxs("p", { className: "mt-0.5 flex items-center gap-1.5 truncate text-sm text-gray-500 dark:text-gray-400", children: [_jsx(MailIcon, {}), _jsx("span", { className: "truncate", children: me.email })] }))] })] }), _jsx("div", { className: "space-y-1 py-4", onClickCapture: close, children: links.map(([title, about, href, tile]) => (_jsxs(Link, { href: href,
|
|
85
|
+
// An account page already open switches to the tab.
|
|
86
|
+
onClick: () => window.dispatchEvent(new CustomEvent(ACCOUNT_TAB_EVENT, {
|
|
87
|
+
detail: new URLSearchParams(href.split("?")[1] ?? "").get("tab") ?? "profile",
|
|
88
|
+
})), className: "group/link flex items-center gap-4 rounded-xl p-2 transition-all duration-200 hover:translate-x-0.5 hover:bg-gray-50 dark:hover:bg-white/5", children: [_jsx("span", { className: "flex size-12 shrink-0 items-center justify-center rounded-xl bg-brand-50 transition-colors group-hover/link:bg-brand-100 dark:bg-brand-500/10 dark:group-hover/link:bg-brand-500/20", children: tile }), _jsxs("span", { children: [_jsx("span", { className: "block font-medium text-gray-800 transition-colors group-hover/link:text-brand-500 dark:text-white/90", children: title }), _jsx("span", { className: "block text-sm text-gray-500 dark:text-gray-400", children: about })] })] }, title))) }), _jsx("button", { type: "button", onClick: () => signOut(config.signInPath), className: "w-full rounded-xl border border-brand-500 px-4 py-2.5 text-sm font-medium text-brand-500 transition-colors duration-200 hover:bg-brand-500 hover:text-white", children: "Logout" })] })) }));
|
|
89
|
+
}
|
|
90
|
+
// The menu's tiles: duotone shapes in the brand colours.
|
|
91
|
+
function PersonTile() {
|
|
92
|
+
return (_jsxs("svg", { width: 24, height: 24, viewBox: "0 0 24 24", "aria-hidden": "true", children: [_jsx("circle", { cx: 12, cy: 8, r: 4, className: "fill-brand-300" }), _jsx("path", { d: "M4 20a8 6 0 0116 0v1H4z", className: "fill-brand-500" })] }));
|
|
93
|
+
}
|
|
94
|
+
function ShieldTile() {
|
|
95
|
+
return (_jsxs("svg", { width: 24, height: 24, viewBox: "0 0 24 24", "aria-hidden": "true", children: [_jsx("path", { d: "M12 2l8 3v6c0 5.5-3.6 9.6-8 11-4.4-1.4-8-5.5-8-11V5z", className: "fill-brand-300" }), _jsx("path", { d: "M8.5 12l2.5 2.5 4.5-5", fill: "none", strokeWidth: 2, strokeLinecap: "round", className: "stroke-brand-600" })] }));
|
|
96
|
+
}
|
|
97
|
+
function DevicesTile() {
|
|
98
|
+
return (_jsxs("svg", { width: 24, height: 24, viewBox: "0 0 24 24", "aria-hidden": "true", children: [_jsx("rect", { x: 2, y: 4, width: 15, height: 11, rx: 2, className: "fill-brand-300" }), _jsx("rect", { x: 14, y: 8, width: 8, height: 13, rx: 2, className: "fill-brand-500" })] }));
|
|
99
|
+
}
|
|
100
|
+
function MailIcon() {
|
|
101
|
+
return (_jsx("svg", { width: 15, height: 15, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M4 6h16v12H4zM4 7l8 6 8-6", stroke: "currentColor", strokeWidth: 1.6, strokeLinejoin: "round" }) }));
|
|
102
|
+
}
|
|
103
|
+
function BellIcon() {
|
|
104
|
+
return (_jsx("svg", { width: 20, height: 20, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M15 17h5l-1.4-1.4A2 2 0 0118 14.2V11a6 6 0 10-12 0v3.2a2 2 0 01-.6 1.4L4 17h5m6 0a3 3 0 11-6 0m6 0H9", stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
105
|
+
}
|
package/dist/icons.d.ts
ADDED
package/dist/icons.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
function Icon({ d }) {
|
|
3
|
+
return (_jsx("svg", { width: 22, height: 22, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: d, stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
4
|
+
}
|
|
5
|
+
export const icons = {
|
|
6
|
+
settings: (_jsx(Icon, { d: "M12 15a3 3 0 100-6 3 3 0 000 6zm7.4-3a7.4 7.4 0 00-.1-1.2l2-1.6-2-3.4-2.4.9a7.3 7.3 0 00-2-1.2L14.5 3h-5l-.4 2.5a7.3 7.3 0 00-2 1.2l-2.4-.9-2 3.4 2 1.6a7.4 7.4 0 000 2.4l-2 1.6 2 3.4 2.4-.9a7.3 7.3 0 002 1.2l.4 2.5h5l.4-2.5a7.3 7.3 0 002-1.2l2.4.9 2-3.4-2-1.6c.1-.4.1-.8.1-1.2z" })),
|
|
7
|
+
users: (_jsx(Icon, { d: "M16 19v-1a4 4 0 00-4-4H6a4 4 0 00-4 4v1M9 10a4 4 0 100-8 4 4 0 000 8zm13 9v-1a4 4 0 00-3-3.9M16 2.1a4 4 0 010 7.8" })),
|
|
8
|
+
roles: _jsx(Icon, { d: "M12 3l8 3v6c0 5-3.5 8.5-8 9-4.5-.5-8-4-8-9V6l8-3zm-3 9l2 2 4-4" }),
|
|
9
|
+
teams: _jsx(Icon, { d: "M3 21h18M5 21V7l7-4 7 4v14M9 21v-6h6v6M9 10h.01M15 10h.01" }),
|
|
10
|
+
audit: (_jsx(Icon, { d: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4" })),
|
|
11
|
+
webhooks: _jsx(Icon, { d: "M13 2L3 14h9l-1 8 10-12h-9l1-8z" }),
|
|
12
|
+
status: _jsx(Icon, { d: "M3 12h4l3-8 4 16 3-8h4" }),
|
|
13
|
+
ledger: _jsx(Icon, { d: "M3 7h18v12H3zM3 7l2-4h14l2 4M16 13h2" }),
|
|
14
|
+
support: _jsx(Icon, { d: "M18 10a6 6 0 10-12 0v3a3 3 0 003 3h1m8-6v3a3 3 0 01-3 3h-1m-4 0a2 2 0 104 0" }),
|
|
15
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { Cancelled, ReasonDialog, StepUp, type StepUpProps, useAction, useIdempotencyKey, } from "./actions";
|
|
2
|
+
export * from "./api/index.gen";
|
|
3
|
+
export { AuthLayout } from "./auth-layout";
|
|
4
|
+
export { ApiError, api, type CallOptions, call, proxyPath, type SendOptions, signOut, } from "./client";
|
|
5
|
+
export { type AdminConfig, defineConfig, type NavItem } from "./config";
|
|
6
|
+
export { formatDate, formatDateTime } from "./dates";
|
|
7
|
+
export { NavSearch, NotificationsMenu, UserMenu } from "./header";
|
|
8
|
+
export { Avatar } from "./kit/avatar";
|
|
9
|
+
export { Badge, humanize, roleTone, type Tone } from "./kit/badge";
|
|
10
|
+
export { Card } from "./kit/card";
|
|
11
|
+
export { CodeArea, highlightHTML, highlightTemplate } from "./kit/code-area";
|
|
12
|
+
export { Dropdown, iconButton, RowMenu, type RowMenuItem } from "./kit/dropdown";
|
|
13
|
+
export { type FilterTab, FilterTabs } from "./kit/filter-tabs";
|
|
14
|
+
export { Modal } from "./kit/modal";
|
|
15
|
+
export { type Crumb, PageHeader } from "./kit/page-header";
|
|
16
|
+
export { SearchToggle } from "./kit/search";
|
|
17
|
+
export { InfoTip, Tooltip } from "./kit/tooltip";
|
|
18
|
+
export { PermissionPicker } from "./permissions";
|
|
19
|
+
export { type Proof, ProofForm, type ProofFormProps } from "./proof";
|
|
20
|
+
export { browserRouter, type LinkProps, type Router } from "./router";
|
|
21
|
+
export { AdminLayout, ColveorAdmin, type ColveorAdminProps, isPublicPath, RequirePermission, useAdmin, useCan, useConfig, useNav, } from "./shell";
|
|
22
|
+
export { type Grant, GrantStatus, grantColumns, TeamSupportGrants } from "./support";
|
|
23
|
+
export { type Column, DataTable, type DataTableProps } from "./table";
|
|
24
|
+
export { CodeInput } from "./ui";
|
|
25
|
+
export { type UserAction, UserActions, UserSessions, useUserActions } from "./user-actions";
|
|
26
|
+
export { UserRoles } from "./user-roles";
|
|
27
|
+
export { UserRowMenu, userName } from "./user-row-menu";
|
|
28
|
+
export { version } from "./version";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @colveor/admin: the admin panel's pages, API client and building blocks
|
|
2
|
+
// (docs/admin.md). The pages come with A2.2 onwards (docs/ADMIN_ROADMAP.md).
|
|
3
|
+
// The building blocks: changes with a reason or re-authentication, and
|
|
4
|
+
// paged tables.
|
|
5
|
+
export { Cancelled, ReasonDialog, StepUp, useAction, useIdempotencyKey, } from "./actions";
|
|
6
|
+
// The API's types, error codes and permission keys, one namespace per
|
|
7
|
+
// module (rbac.RoleResponse, rbac.PermissionRead), generated from the Go
|
|
8
|
+
// contracts by make generate.
|
|
9
|
+
export * from "./api/index.gen";
|
|
10
|
+
// The header's parts, the sign-in frame, and the code boxes.
|
|
11
|
+
export { AuthLayout } from "./auth-layout";
|
|
12
|
+
// Calling the API through the proxy, and signing out.
|
|
13
|
+
export { ApiError, api, call, proxyPath, signOut, } from "./client";
|
|
14
|
+
// The shell: admin.config.ts, the provider, permission checks and the menu.
|
|
15
|
+
export { defineConfig } from "./config";
|
|
16
|
+
// The building blocks every page is made of: use them on a project's own
|
|
17
|
+
// pages, so the whole panel looks the same.
|
|
18
|
+
export { formatDate, formatDateTime } from "./dates";
|
|
19
|
+
export { NavSearch, NotificationsMenu, UserMenu } from "./header";
|
|
20
|
+
export { Avatar } from "./kit/avatar";
|
|
21
|
+
export { Badge, humanize, roleTone } from "./kit/badge";
|
|
22
|
+
export { Card } from "./kit/card";
|
|
23
|
+
export { CodeArea, highlightHTML, highlightTemplate } from "./kit/code-area";
|
|
24
|
+
export { Dropdown, iconButton, RowMenu } from "./kit/dropdown";
|
|
25
|
+
export { FilterTabs } from "./kit/filter-tabs";
|
|
26
|
+
export { Modal } from "./kit/modal";
|
|
27
|
+
export { PageHeader } from "./kit/page-header";
|
|
28
|
+
export { SearchToggle } from "./kit/search";
|
|
29
|
+
export { InfoTip, Tooltip } from "./kit/tooltip";
|
|
30
|
+
// Permissions as checkboxes by module, and one user's roles.
|
|
31
|
+
export { PermissionPicker } from "./permissions";
|
|
32
|
+
export { ProofForm } from "./proof";
|
|
33
|
+
export { browserRouter } from "./router";
|
|
34
|
+
export { AdminLayout, ColveorAdmin, isPublicPath, RequirePermission, useAdmin, useCan, useConfig, useNav, } from "./shell";
|
|
35
|
+
export { GrantStatus, grantColumns, TeamSupportGrants } from "./support";
|
|
36
|
+
export { DataTable } from "./table";
|
|
37
|
+
export { CodeInput } from "./ui";
|
|
38
|
+
export { UserActions, UserSessions, useUserActions } from "./user-actions";
|
|
39
|
+
export { UserRoles } from "./user-roles";
|
|
40
|
+
export { UserRowMenu, userName } from "./user-row-menu";
|
|
41
|
+
// The colveor-go release this package is built for.
|
|
42
|
+
export { version } from "./version";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// A person: their photo, or their initials on the brand colour.
|
|
3
|
+
export function Avatar(props) {
|
|
4
|
+
const size = props.className ?? "size-10";
|
|
5
|
+
if (props.url) {
|
|
6
|
+
return _jsx("img", { src: props.url, alt: "", className: `shrink-0 rounded-full object-cover ${size}` });
|
|
7
|
+
}
|
|
8
|
+
const initials = props.name
|
|
9
|
+
.split(/[\s@._-]+/)
|
|
10
|
+
.filter(Boolean)
|
|
11
|
+
.map((w) => w[0])
|
|
12
|
+
.join("")
|
|
13
|
+
.slice(0, 2)
|
|
14
|
+
.toUpperCase() || "?";
|
|
15
|
+
return (_jsx("span", { className: `flex shrink-0 items-center justify-center rounded-full bg-brand-500 font-medium text-white ${size}`, children: initials }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type Tone = "brand" | "green" | "amber" | "red" | "purple" | "sky" | "gray";
|
|
3
|
+
export declare function Badge({ tone, children }: {
|
|
4
|
+
tone?: Tone;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
/** The same colour for a role everywhere: by name for the built-in ones. */
|
|
8
|
+
export declare function roleTone(slug: string): Tone;
|
|
9
|
+
/** "super_admin" → "Super admin". */
|
|
10
|
+
export declare function humanize(slug: string): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
const TONES = {
|
|
3
|
+
brand: "bg-brand-50 text-brand-600 dark:bg-brand-500/15 dark:text-brand-400",
|
|
4
|
+
green: "bg-green-50 text-green-700 dark:bg-green-500/15 dark:text-green-400",
|
|
5
|
+
amber: "bg-amber-50 text-amber-700 dark:bg-amber-500/15 dark:text-amber-400",
|
|
6
|
+
red: "bg-red-50 text-red-600 dark:bg-red-500/15 dark:text-red-400",
|
|
7
|
+
purple: "bg-purple-50 text-purple-700 dark:bg-purple-500/15 dark:text-purple-400",
|
|
8
|
+
sky: "bg-sky-50 text-sky-700 dark:bg-sky-500/15 dark:text-sky-400",
|
|
9
|
+
gray: "bg-gray-100 text-gray-600 dark:bg-white/5 dark:text-gray-400",
|
|
10
|
+
};
|
|
11
|
+
export function Badge({ tone = "gray", children }) {
|
|
12
|
+
return (_jsx("span", { className: `inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${TONES[tone]}`, children: children }));
|
|
13
|
+
}
|
|
14
|
+
/** The same colour for a role everywhere: by name for the built-in ones. */
|
|
15
|
+
export function roleTone(slug) {
|
|
16
|
+
const known = { super_admin: "amber", admin: "purple", user: "green" };
|
|
17
|
+
if (known[slug]) {
|
|
18
|
+
return known[slug];
|
|
19
|
+
}
|
|
20
|
+
const rest = ["sky", "brand", "red", "purple", "green", "amber"];
|
|
21
|
+
let h = 0;
|
|
22
|
+
for (const c of slug) {
|
|
23
|
+
h = (h * 31 + c.charCodeAt(0)) >>> 0;
|
|
24
|
+
}
|
|
25
|
+
return rest[h % rest.length];
|
|
26
|
+
}
|
|
27
|
+
/** "super_admin" → "Super admin". */
|
|
28
|
+
export function humanize(slug) {
|
|
29
|
+
const s = slug.replaceAll("_", " ");
|
|
30
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export declare function Card(props: {
|
|
3
|
+
title?: string;
|
|
4
|
+
/** Under the title. */
|
|
5
|
+
about?: ReactNode;
|
|
6
|
+
/** Behind a "?" beside the title (InfoTip), instead of under it. */
|
|
7
|
+
info?: ReactNode;
|
|
8
|
+
actions?: ReactNode;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
/** No inner padding: for a table that fills the card. */
|
|
11
|
+
flush?: boolean;
|
|
12
|
+
}): import("react").JSX.Element;
|
package/dist/kit/card.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { InfoTip } from "./tooltip";
|
|
4
|
+
export function Card(props) {
|
|
5
|
+
const head = props.title !== undefined || props.actions !== undefined;
|
|
6
|
+
return (_jsxs("section", { className: "animate-fade-in rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/[0.03]", children: [head && (_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 px-6 pt-6", children: [_jsxs("div", { children: [props.title && (_jsxs("h2", { className: "flex items-center gap-2 text-lg font-medium text-gray-800 dark:text-white/90", children: [props.title, props.info && _jsx(InfoTip, { label: `About ${props.title}`, children: props.info })] })), props.about && (_jsx("p", { className: "mt-1 text-sm text-gray-500 dark:text-gray-400", children: props.about }))] }), props.actions && _jsx("div", { className: "flex items-center gap-1", children: props.actions })] })), _jsx("div", { className: props.flush ? "pt-5" : head ? "p-6 pt-5" : "p-6", children: props.children })] }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Escapes text, colouring the template actions in it. */
|
|
2
|
+
export declare function highlightTemplate(s: string): string;
|
|
3
|
+
/** The source as coloured HTML. */
|
|
4
|
+
export declare function highlightHTML(src: string): string;
|
|
5
|
+
export declare function CodeArea(props: {
|
|
6
|
+
value: string;
|
|
7
|
+
onChange(v: string): void;
|
|
8
|
+
rows?: number;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
label?: string;
|
|
11
|
+
/** "html" (default), or "template": plain text with {{ }} coloured. */
|
|
12
|
+
lang?: "html" | "template";
|
|
13
|
+
/** One line, like an input: Enter adds no line, pasted lines are joined. */
|
|
14
|
+
singleLine?: boolean;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// A text box with syntax highlighting: HTML with Go template actions
|
|
4
|
+
// ({{.Code}}, {{if .IsLink}}), or plain text with only the actions coloured
|
|
5
|
+
// (lang "template", for an email's text part or an SMS). The coloured copy sits under a transparent
|
|
6
|
+
// textarea: typing, selecting and undo are the browser's own. No editor
|
|
7
|
+
// library: colours only, no autocomplete.
|
|
8
|
+
import { useRef } from "react";
|
|
9
|
+
const esc = (s) => s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
10
|
+
const span = (cls, s) => `<span class="${cls}">${s}</span>`;
|
|
11
|
+
const TEMPLATE = "font-medium text-brand-600 dark:text-brand-400";
|
|
12
|
+
/** Escapes text, colouring the template actions in it. */
|
|
13
|
+
export function highlightTemplate(s) {
|
|
14
|
+
return s
|
|
15
|
+
.split(/(\{\{[\s\S]*?\}\})/)
|
|
16
|
+
.map((part) => (part.startsWith("{{") ? span(TEMPLATE, esc(part)) : esc(part)))
|
|
17
|
+
.join("");
|
|
18
|
+
}
|
|
19
|
+
/** A tag: its name, attributes and quoted values. */
|
|
20
|
+
function tag(s) {
|
|
21
|
+
const m = s.match(/^(<\/?)([\w-]+)([\s\S]*?)(\/?>)$/);
|
|
22
|
+
if (m === null) {
|
|
23
|
+
return highlightTemplate(s);
|
|
24
|
+
}
|
|
25
|
+
const attrs = m[3].replace(/([^\s=]+)(\s*=\s*)?("[^"]*"|'[^']*')?|(\s+)/g, (all, name, eq, value, space) => {
|
|
26
|
+
if (space !== undefined) {
|
|
27
|
+
return space;
|
|
28
|
+
}
|
|
29
|
+
if (name === undefined) {
|
|
30
|
+
return highlightTemplate(all);
|
|
31
|
+
}
|
|
32
|
+
return (span("text-amber-600 dark:text-amber-400", highlightTemplate(name)) +
|
|
33
|
+
(eq ?? "") +
|
|
34
|
+
(value ? span("text-green-700 dark:text-green-400", highlightTemplate(value)) : ""));
|
|
35
|
+
});
|
|
36
|
+
return (span("text-gray-400", esc(m[1])) +
|
|
37
|
+
span("text-rose-600 dark:text-rose-400", esc(m[2])) +
|
|
38
|
+
attrs +
|
|
39
|
+
span("text-gray-400", esc(m[4])));
|
|
40
|
+
}
|
|
41
|
+
/** The source as coloured HTML. */
|
|
42
|
+
export function highlightHTML(src) {
|
|
43
|
+
return src
|
|
44
|
+
.split(/(<!--[\s\S]*?-->|<\/?[A-Za-z][^<>]*>)/)
|
|
45
|
+
.map((part) => {
|
|
46
|
+
if (part.startsWith("<!--")) {
|
|
47
|
+
return span("italic text-gray-400", esc(part));
|
|
48
|
+
}
|
|
49
|
+
return part.startsWith("<") ? tag(part) : highlightTemplate(part);
|
|
50
|
+
})
|
|
51
|
+
.join("");
|
|
52
|
+
}
|
|
53
|
+
const base = "m-0 w-full px-3 py-2 font-mono text-xs leading-relaxed";
|
|
54
|
+
const wrapped = `${base} whitespace-pre-wrap break-words [overflow-wrap:anywhere]`;
|
|
55
|
+
// One line scrolls sideways instead of wrapping.
|
|
56
|
+
const oneLine = `${base} whitespace-pre`;
|
|
57
|
+
export function CodeArea(props) {
|
|
58
|
+
const paint = props.lang === "template" ? highlightTemplate : highlightHTML;
|
|
59
|
+
const box = props.singleLine ? oneLine : wrapped;
|
|
60
|
+
const under = useRef(null);
|
|
61
|
+
return (_jsxs("div", { className: "relative overflow-hidden rounded-lg border border-gray-300 bg-white focus-within:border-brand-300 focus-within:ring-3 focus-within:ring-brand-500/10 dark:border-gray-700 dark:bg-gray-900", style: { height: `${(props.singleLine ? 1 : (props.rows ?? 8)) * 1.625 * 0.75 + 1}rem` }, children: [_jsx("pre", { ref: under, "aria-hidden": "true", className: `${box} pointer-events-none absolute inset-0 overflow-hidden text-gray-800 dark:text-gray-200`,
|
|
62
|
+
// The source is escaped first: only our spans are HTML.
|
|
63
|
+
dangerouslySetInnerHTML: { __html: `${paint(props.value)}\n` } }), _jsx("textarea", { "aria-label": props.label, spellCheck: false, wrap: props.singleLine ? "off" : "soft", value: props.value, disabled: props.disabled, onChange: (e) => props.onChange(props.singleLine ? e.target.value.replace(/\r?\n/g, " ") : e.target.value), onKeyDown: (e) => props.singleLine && e.key === "Enter" && e.preventDefault(), onScroll: (e) => {
|
|
64
|
+
if (under.current) {
|
|
65
|
+
under.current.scrollTop = e.currentTarget.scrollTop;
|
|
66
|
+
under.current.scrollLeft = e.currentTarget.scrollLeft;
|
|
67
|
+
}
|
|
68
|
+
}, className: `${box} absolute inset-0 h-full resize-none bg-transparent text-transparent caret-gray-800 outline-none selection:bg-brand-500/25 disabled:opacity-70 dark:caret-white` })] }));
|
|
69
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/** A dropdown: the button, and a panel under it while open. */
|
|
3
|
+
export declare function Dropdown(props: {
|
|
4
|
+
button: (open: boolean) => ReactNode;
|
|
5
|
+
label: string;
|
|
6
|
+
width?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Placed on the screen, not in the page: nothing clips it (a menu inside a
|
|
9
|
+
* table that scrolls). It opens upward near the bottom of the screen, and
|
|
10
|
+
* closes when the page scrolls.
|
|
11
|
+
*/
|
|
12
|
+
floating?: boolean;
|
|
13
|
+
children: (close: () => void) => ReactNode;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
/** A round, borderless icon button, tinted on hover: the header's, a card's. */
|
|
16
|
+
export declare const iconButton = "relative flex size-10 items-center justify-center rounded-full text-gray-500 transition-colors duration-200 hover:bg-brand-50 hover:text-brand-500 dark:text-gray-400 dark:hover:bg-brand-500/10 dark:hover:text-brand-400";
|
|
17
|
+
export interface RowMenuItem {
|
|
18
|
+
label: string;
|
|
19
|
+
onSelect(): void;
|
|
20
|
+
/** Red: a removal, a block. */
|
|
21
|
+
danger?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** A row's "…" menu. Its clicks don't reach the row. */
|
|
24
|
+
export declare function RowMenu({ items }: {
|
|
25
|
+
items: RowMenuItem[];
|
|
26
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// A dropdown that opens with a short animation and closes on a click
|
|
4
|
+
// outside or Escape (the header's menus), and RowMenu, a row's "…" menu.
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
/** A dropdown: the button, and a panel under it while open. */
|
|
7
|
+
export function Dropdown(props) {
|
|
8
|
+
const [open, setOpen] = useState(false);
|
|
9
|
+
const [place, setPlace] = useState();
|
|
10
|
+
const ref = useRef(null);
|
|
11
|
+
const toggle = () => {
|
|
12
|
+
const box = ref.current?.getBoundingClientRect();
|
|
13
|
+
if (props.floating && box && !open) {
|
|
14
|
+
const right = window.innerWidth - box.right;
|
|
15
|
+
// Room for a menu of about 280px below, or it opens upward.
|
|
16
|
+
setPlace(box.bottom + 280 > window.innerHeight
|
|
17
|
+
? { position: "fixed", right, bottom: window.innerHeight - box.top + 8 }
|
|
18
|
+
: { position: "fixed", right, top: box.bottom + 8 });
|
|
19
|
+
}
|
|
20
|
+
setOpen(!open);
|
|
21
|
+
};
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!open || !props.floating) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const close = () => setOpen(false);
|
|
27
|
+
window.addEventListener("scroll", close, true);
|
|
28
|
+
window.addEventListener("resize", close);
|
|
29
|
+
return () => {
|
|
30
|
+
window.removeEventListener("scroll", close, true);
|
|
31
|
+
window.removeEventListener("resize", close);
|
|
32
|
+
};
|
|
33
|
+
}, [open, props.floating]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!open) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const outside = (e) => {
|
|
39
|
+
if (!ref.current?.contains(e.target)) {
|
|
40
|
+
setOpen(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const onKey = (e) => e.key === "Escape" && setOpen(false);
|
|
44
|
+
document.addEventListener("mousedown", outside);
|
|
45
|
+
document.addEventListener("keydown", onKey);
|
|
46
|
+
return () => {
|
|
47
|
+
document.removeEventListener("mousedown", outside);
|
|
48
|
+
document.removeEventListener("keydown", onKey);
|
|
49
|
+
};
|
|
50
|
+
}, [open]);
|
|
51
|
+
return (_jsxs("div", { ref: ref, className: "relative", children: [_jsx("button", { type: "button", "aria-label": props.label, "aria-expanded": open, onClick: toggle, className: "flex items-center", children: props.button(open) }), open && (_jsx("div", { style: props.floating ? place : undefined, className: `${props.floating ? "" : "absolute right-0 mt-3"} z-50 origin-top-right animate-pop-in rounded-2xl border border-gray-200 bg-white p-3 shadow-lg dark:border-gray-800 dark:bg-gray-900 ${props.width ?? "w-72"}`, children: props.children(() => setOpen(false)) }))] }));
|
|
52
|
+
}
|
|
53
|
+
/** A round, borderless icon button, tinted on hover: the header's, a card's. */
|
|
54
|
+
export const iconButton = "relative flex size-10 items-center justify-center rounded-full text-gray-500 transition-colors duration-200 hover:bg-brand-50 hover:text-brand-500 dark:text-gray-400 dark:hover:bg-brand-500/10 dark:hover:text-brand-400";
|
|
55
|
+
/** A row's "…" menu. Its clicks don't reach the row. */
|
|
56
|
+
export function RowMenu({ items }) {
|
|
57
|
+
if (items.length === 0) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: only stops the row's click
|
|
62
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: only stops the row's click
|
|
63
|
+
_jsx("div", { onClick: (e) => e.stopPropagation(), className: "inline-block", children: _jsx(Dropdown, { label: "Actions", width: "w-52", floating: true, button: () => (_jsx("span", { className: `${iconButton} size-8`, children: _jsxs("svg", { width: 18, height: 18, viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [_jsx("circle", { cx: 5, cy: 12, r: 1.8 }), _jsx("circle", { cx: 12, cy: 12, r: 1.8 }), _jsx("circle", { cx: 19, cy: 12, r: 1.8 })] }) })), children: (close) => (_jsx("div", { className: "-m-1.5 space-y-0.5", children: items.map((item) => (_jsx("button", { type: "button", onClick: () => {
|
|
64
|
+
close();
|
|
65
|
+
item.onSelect();
|
|
66
|
+
}, className: `w-full rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-gray-100 dark:hover:bg-white/5 ${item.danger ? "text-red-600" : "text-gray-700 dark:text-gray-300"}`, children: item.label }, item.label))) })) }) }));
|
|
67
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export function FilterTabs(props) {
|
|
4
|
+
return (_jsx("div", { className: "inline-flex max-w-full flex-wrap gap-1 rounded-xl border border-gray-200 p-1 dark:border-gray-800", children: props.tabs.map((t) => (_jsx("button", { type: "button", onClick: () => props.onChange(t.key), className: `rounded-lg px-4 py-2 text-sm font-medium transition-all duration-200 ${props.value === t.key
|
|
5
|
+
? "bg-brand-500 text-white shadow-sm"
|
|
6
|
+
: "text-gray-600 hover:bg-gray-100 hover:text-gray-800 dark:text-gray-300 dark:hover:bg-white/5"}`, children: t.label }, t.key))) }));
|
|
7
|
+
}
|