@okjt/dashboard 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +149 -2
  2. package/dist/AcceptInvitePage.js +86 -0
  3. package/dist/AccountMenu.js +73 -0
  4. package/dist/ActivityPanel.js +48 -0
  5. package/dist/AdminBulkActions.js +109 -0
  6. package/dist/AdminCard.js +7 -0
  7. package/dist/AdminChromeContext.js +16 -0
  8. package/dist/AdminFloatingToolbar.js +147 -0
  9. package/dist/AdminInput.js +66 -0
  10. package/dist/AdminListPanel.js +26 -0
  11. package/dist/AdminModal.js +23 -0
  12. package/dist/AdminPageHero.js +101 -0
  13. package/dist/AdminPageLayout.js +54 -0
  14. package/dist/AdminPagination.js +92 -0
  15. package/dist/AdminSidePanel.js +479 -0
  16. package/dist/AdminSummaryCards.js +51 -0
  17. package/dist/AdminToolbarFilters.js +168 -0
  18. package/dist/AdminToolbarSearch.js +61 -0
  19. package/dist/AdminTutorial.js +221 -0
  20. package/dist/AuthContext.js +194 -0
  21. package/dist/AuthLayout.js +94 -0
  22. package/dist/CollaborationContext.js +84 -0
  23. package/dist/CollaboratorAvatars.js +36 -0
  24. package/dist/DashboardHeader.js +140 -0
  25. package/dist/DashboardProvider.js +45 -0
  26. package/dist/DashboardShell.js +93 -0
  27. package/dist/DashboardSidebar.js +97 -0
  28. package/dist/DeleteButton.js +21 -0
  29. package/dist/EditableFieldset.js +9 -0
  30. package/dist/EmptyState.js +22 -0
  31. package/dist/GoogleButton.js +22 -0
  32. package/dist/GoogleCallbackPage.js +81 -0
  33. package/dist/NotificationsBell.js +149 -0
  34. package/dist/QueryError.js +23 -0
  35. package/dist/SearchContext.js +16 -0
  36. package/dist/ShareModal.js +228 -0
  37. package/dist/SignInPage.js +198 -0
  38. package/dist/StatCard.js +33 -0
  39. package/dist/ToggleButton.js +26 -0
  40. package/dist/TwoFactorForm.js +26 -0
  41. package/dist/UnsavedChangesStatus.js +13 -0
  42. package/dist/VerifyEmailPage.js +42 -0
  43. package/dist/VersionHistoryDrawer.js +172 -0
  44. package/dist/index.js +125 -0
  45. package/dist/modules.js +32 -0
  46. package/dist/passkeys.js +84 -0
  47. package/dist/useActivityPanel.js +34 -0
  48. package/dist/useAdminAction.js +77 -0
  49. package/dist/useCrudHandlers.js +54 -0
  50. package/dist/useFilteredItems.js +19 -0
  51. package/dist/useSavedViews.js +30 -0
  52. package/dist/useUnsavedChangesGuard.js +41 -0
  53. package/package.json +40 -4
package/README.md CHANGED
@@ -1,3 +1,150 @@
1
- # Temporary Holding Version
1
+ # @okjt/dashboard
2
+
3
+ The pages of an OKJTech dashboard, as Naoa builds them: every page has the
4
+ same shape — a hero with breadcrumbs, optional summary cards that double as
5
+ filters, the page's content with a side panel beside it, and one floating
6
+ toolbar for search, filters, views and actions. Lists fit the screen and only
7
+ their rows scroll. Saving works one way everywhere (`useAdminAction`):
8
+ confirm, pending state, toast, refresh, and hidden for people who may only
9
+ view.
10
+
11
+ Colours and fonts come from `@okjt/ui`'s theme.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm i @okjt/dashboard @okjt/ui
17
+ ```
18
+
19
+ Peer dependencies: `react`, `react-dom`, `react-router-dom`,
20
+ `@tanstack/react-query`, `framer-motion`, `lucide-react`, `react-hot-toast`.
21
+
22
+ ```css
23
+ @import "tailwindcss";
24
+ @import "./okjt-theme.css";
25
+ @source "../node_modules/@okjt/ui/dist";
26
+ @source "../node_modules/@okjt/dashboard/dist";
27
+ ```
28
+
29
+ ## Set it up
30
+
31
+ ```jsx
32
+ import { PermissionsProvider, ConfirmHost } from '@okjt/ui';
33
+ import { DashboardProvider, SearchProvider, AdminChromeProvider } from '@okjt/dashboard';
34
+
35
+ const dashboard = {
36
+ home: { label: 'Dashboard', path: '/dashboard' }, // first breadcrumb on every page
37
+ useDefaultPanel: () => null, // side panel for pages without one
38
+ useAfterChange: () => undefined, // called after every successful save
39
+ };
40
+
41
+ function Providers({ children }) {
42
+ const permissions = useMyPermissions(); // { role, isOwner, canEdit }
43
+ return (
44
+ <PermissionsProvider value={permissions}>
45
+ <DashboardProvider dashboard={dashboard}>
46
+ <SearchProvider>
47
+ <AdminChromeProvider>
48
+ {children}
49
+ <ConfirmHost />
50
+ </AdminChromeProvider>
51
+ </SearchProvider>
52
+ </DashboardProvider>
53
+ </PermissionsProvider>
54
+ );
55
+ }
56
+ ```
57
+
58
+ Outside a `PermissionsProvider` everything is allowed; outside a
59
+ `DashboardProvider` the defaults above apply.
60
+
61
+ ## A page
62
+
63
+ ```jsx
64
+ import { Plus } from 'lucide-react';
65
+ import { AdminPageLayout, AdminPageHero, AdminSummaryCards, AdminListPanel, useAdminAction, useFilteredItems, useSearch } from '@okjt/dashboard';
66
+
67
+ export default function Expenses() {
68
+ const { data: expenses = [] } = useQuery({ queryKey: ['expenses'], queryFn: api.expenses });
69
+ const { searchQuery } = useSearch();
70
+ const shown = useFilteredItems(expenses, searchQuery);
71
+ const remove = useAdminAction((id) => api.deleteExpense(id), {
72
+ confirm: 'Delete this expense?', success: 'Expense deleted', invalidate: [['expenses']],
73
+ });
74
+
75
+ return (
76
+ <AdminPageLayout
77
+ fill
78
+ hero={<AdminPageHero title="Expenses" breadcrumb="Expenses" />}
79
+ summary={<AdminSummaryCards cards={[{ label: 'This month', value: total(expenses) }]} />}
80
+ search="Search expenses"
81
+ actions={[{ id: 'add', label: 'Add expense', icon: Plus, onClick: openForm }]}
82
+ >
83
+ <AdminListPanel>{shown.map((e) => <Row key={e.id} expense={e} onDelete={() => remove.run(e.id)} />)}</AdminListPanel>
84
+ </AdminPageLayout>
85
+ );
86
+ }
87
+ ```
88
+
89
+ ## Building blocks
90
+
91
+ | Export | What it is |
92
+ |---|---|
93
+ | `AdminPageLayout` | The page: `hero`, `summary`, content, `panel`, and the toolbar's `actions`, `search`, `filters`; `fill` fits the viewport |
94
+ | `AdminPageHero` | Title, breadcrumbs, description; a compact copy appears in the header once it scrolls away |
95
+ | `AdminSummaryCards`, `StatCard` | Summary numbers; a card can apply a filter |
96
+ | `AdminFloatingToolbar`, `AdminToolbarSearch`, `AdminToolbarFilters`, `countActiveFilters` | The toolbar and its parts |
97
+ | `SidePanelAside`, `SidePanelMobileBar`, `SidePanelNav` | The side panel: sections, tools, lists; chips and a sheet on phones |
98
+ | `AdminListPanel`, `AdminPagination`, `pageWindow`, `AdminBulkActions` | Lists, paging, actions on a selection |
99
+ | `AdminCard`, `AdminInput`, `AdminTextarea`, `AdminSelect`, `AdminModal` | Cards, fields, dialogs |
100
+ | `EditableFieldset`, `DeleteButton`, `ToggleButton` | Controls that disable or hide themselves for viewers |
101
+ | `EmptyState`, `QueryError` | Nothing to show; something failed to load |
102
+ | `UnsavedChangesStatus`, `useUnsavedChangesGuard`, `useUnsavedChanges` | Warn before leaving with unsaved edits |
103
+ | `AdminTutorial` | A guided tour; pass `steps` |
104
+ | `useAdminAction`, `useBulkAdminAction`, `useCrudHandlers` | One way to save |
105
+ | `useFilteredItems`, `useSavedViews` | Search across a list; remembered views |
106
+ | `SearchProvider`/`useSearch`, `AdminChromeProvider`/`useAdminChrome`, `AdminHeaderStatus` | The shared search box and the header's slots |
107
+ | `DashboardProvider`, `useDashboard` | The settings above |
108
+
109
+ ## Working together
110
+
111
+ With `okjt/laravel-kit`'s collaboration routes on the server, add to the
112
+ dashboard settings:
113
+
114
+ ```js
115
+ const dashboard = {
116
+ // …
117
+ api, // axios-like, sends the workspace header, resolves to the body
118
+ modules: [{ key: 'expenses', path: '/dashboard/expenses', label: 'Expenses' }],
119
+ roles: [{ value: 'owner', label: 'Owner', description: '…' }, /* editor, viewer */],
120
+ anonymousName: 'Someone', // changes nobody signed in made
121
+ useDefaultPanel: useActivityPanel, // who's here and what changed, on pages without a panel
122
+ useAfterChange: () => useCollaboration().refresh,
123
+ };
124
+ ```
125
+
126
+ and wrap the dashboard in `<CollaborationProvider>` (inside the router). Then
127
+ `ShareModal`, `VersionHistoryDrawer`, `ActivityPanel` and
128
+ `CollaboratorAvatars` work as in Naoa.
129
+
130
+ ## Signing in
131
+
132
+ | Export | What it is |
133
+ |---|---|
134
+ | `AuthProvider`, `useAuth` | Who is signed in: `api`, plus `extend` for what the project adds |
135
+ | `GoogleButton` | Sends the browser to the kit's Google route |
136
+ | `loginWithPasskey`, `registerPasskey`, `passkeysSupported` | Passkeys against the kit's `PasskeyController`; `{ base }` if the routes aren't under `/api` |
137
+ | `NotificationsBell` | The header's notifications |
138
+ | `AuthLayout`, `AuthField`, `AuthSubmit`, `AuthError` | The sign-in pages' frame (`brand`, `backLabel`, and a desktop panel `aside`) and its fields |
139
+ | `SignInPage` | Email and password, a passkey, `google`; then verifying the email or a two-step code. `onSignedIn(result)` decides where to go (return a message to show instead) |
140
+ | `GoogleCallbackPage`, `VerifyEmailPage`, `AcceptInvitePage` | Where Google sign-in, the verification email and invitation links land |
141
+ | `AccountMenu` | The header's avatar menu: who you are, the project's own entries (`extra`), account pages (`links`), log out |
142
+
143
+ Each page takes `layout`: the project's own `AuthLayout` with its logo and panel.
144
+ `SignInPage` needs `react-hook-form`.
145
+
146
+ ## The shell
147
+
148
+ `DashboardShell` (with `DashboardSidebar` and `DashboardHeader`) is the frame
149
+ around every page, set up through `shell` in the dashboard settings.
2
150
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
@@ -0,0 +1,86 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { Link, useSearchParams } from "react-router-dom";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
6
+ function AcceptInvitePage({
7
+ layout: Layout = AuthLayout,
8
+ accept,
9
+ onSignedIn,
10
+ signInPath = "/sign-in",
11
+ title = "You\u2019re invited",
12
+ subtitle = "Choose a password to finish setting up your access."
13
+ }) {
14
+ const [params] = useSearchParams();
15
+ const { signedIn } = useAuth();
16
+ const email = params.get("email") || "";
17
+ const token = params.get("token") || "";
18
+ const [password, setPassword] = useState("");
19
+ const [confirmation, setConfirmation] = useState("");
20
+ const [error, setError] = useState(null);
21
+ const [saving, setSaving] = useState(false);
22
+ const onSubmit = async (e) => {
23
+ e.preventDefault();
24
+ if (password !== confirmation) {
25
+ setError("The passwords don\u2019t match.");
26
+ return;
27
+ }
28
+ setSaving(true);
29
+ setError(null);
30
+ try {
31
+ const data = await accept({ email, token, password, password_confirmation: confirmation });
32
+ onSignedIn?.(signedIn(data));
33
+ } catch (err) {
34
+ setError(err.response?.data?.errors?.password?.[0] || err.response?.data?.message || "Something went wrong. Try again.");
35
+ } finally {
36
+ setSaving(false);
37
+ }
38
+ };
39
+ return /* @__PURE__ */ jsx(
40
+ Layout,
41
+ {
42
+ title,
43
+ subtitle,
44
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [
45
+ "Already set up? ",
46
+ /* @__PURE__ */ jsx(Link, { to: signInPath, className: "font-medium text-accent-strong hover:underline", children: "Sign in" })
47
+ ] }),
48
+ children: !email || !token ? /* @__PURE__ */ jsx(AuthError, { children: "This invitation link is incomplete. Open the link from your email again, or ask for a new invitation." }) : /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-5", children: [
49
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
50
+ /* @__PURE__ */ jsx(AuthField, { id: "invite-email", label: "Email", value: email, readOnly: true }),
51
+ /* @__PURE__ */ jsx(
52
+ AuthField,
53
+ {
54
+ id: "invite-password",
55
+ label: "Password",
56
+ type: "password",
57
+ autoComplete: "new-password",
58
+ minLength: 8,
59
+ required: true,
60
+ placeholder: "At least 8 characters",
61
+ value: password,
62
+ onChange: (e) => setPassword(e.target.value)
63
+ }
64
+ ),
65
+ /* @__PURE__ */ jsx(
66
+ AuthField,
67
+ {
68
+ id: "invite-password-confirm",
69
+ label: "Confirm password",
70
+ type: "password",
71
+ autoComplete: "new-password",
72
+ minLength: 8,
73
+ required: true,
74
+ placeholder: "Type it again",
75
+ value: confirmation,
76
+ onChange: (e) => setConfirmation(e.target.value)
77
+ }
78
+ ),
79
+ /* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading: saving, children: "Set password & continue" }) })
80
+ ] })
81
+ }
82
+ );
83
+ }
84
+ export {
85
+ AcceptInvitePage as default
86
+ };
@@ -0,0 +1,73 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useRef, useState } from "react";
3
+ import { Link } from "react-router-dom";
4
+ import { AnimatePresence, motion } from "framer-motion";
5
+ import { ChevronDown, LogOut } from "lucide-react";
6
+ import { useDismiss } from "@okjt/ui";
7
+ import { useAuth } from "./AuthContext.js";
8
+ function AccountMenu({ compactLinks = [], links = [], roleText, extra, fallbackName = "Admin" }) {
9
+ const { user, logout } = useAuth();
10
+ const [open, setOpen] = useState(false);
11
+ const ref = useRef(null);
12
+ const close = useCallback(() => setOpen(false), []);
13
+ useDismiss(ref, open, close);
14
+ const handleLogout = async () => {
15
+ close();
16
+ await logout();
17
+ };
18
+ const initial = user?.name?.charAt(0)?.toUpperCase() || fallbackName.charAt(0).toUpperCase();
19
+ const itemClass = "flex items-center gap-3 px-4 py-2.5 text-sm text-tone-700 hover:bg-paper-warm focus:bg-paper-warm focus:outline-none";
20
+ return /* @__PURE__ */ jsxs("div", { className: "relative", ref, children: [
21
+ /* @__PURE__ */ jsxs(
22
+ "button",
23
+ {
24
+ id: "header-account",
25
+ type: "button",
26
+ onClick: () => setOpen((v) => !v),
27
+ "aria-haspopup": "menu",
28
+ "aria-expanded": open,
29
+ "aria-label": `Account menu for ${user?.name || fallbackName.toLowerCase()}`,
30
+ className: "flex items-center gap-2 p-1 pr-2 rounded-full hover:bg-black/5 transition-colors",
31
+ children: [
32
+ /* @__PURE__ */ jsx("span", { className: "w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-medium bg-accent", children: initial }),
33
+ /* @__PURE__ */ jsx("span", { className: "hidden xl:block max-w-[8rem] truncate text-sm font-medium text-body", children: user?.name || fallbackName }),
34
+ /* @__PURE__ */ jsx(ChevronDown, { className: `w-4 h-4 text-tone-400 transition-transform ${open ? "rotate-180" : ""}` })
35
+ ]
36
+ }
37
+ ),
38
+ /* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsxs(
39
+ motion.div,
40
+ {
41
+ role: "menu",
42
+ initial: { opacity: 0, y: 8, scale: 0.97 },
43
+ animate: { opacity: 1, y: 0, scale: 1 },
44
+ exit: { opacity: 0, y: 8, scale: 0.97 },
45
+ transition: { duration: 0.15 },
46
+ className: "absolute right-0 top-full mt-2 w-64 bg-white rounded-2xl shadow-xl border border-tone-100 py-2 z-50",
47
+ children: [
48
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 border-b border-tone-100 mb-1", children: [
49
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-tone-800 truncate", children: user?.name || fallbackName }),
50
+ user?.email && /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-500 truncate", children: user.email }),
51
+ roleText && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-accent font-medium mt-0.5", children: roleText })
52
+ ] }),
53
+ extra?.({ itemClass, close }),
54
+ compactLinks.length > 0 && /* @__PURE__ */ jsx("div", { className: "md:hidden border-b border-tone-100 pb-1 mb-1", children: compactLinks.map((link) => /* @__PURE__ */ jsxs(Link, { to: link.path, role: "menuitem", onClick: close, className: itemClass, children: [
55
+ /* @__PURE__ */ jsx(link.icon, { className: "w-4 h-4 text-accent" }),
56
+ link.label
57
+ ] }, link.path)) }),
58
+ links.map((link) => /* @__PURE__ */ jsxs(Link, { id: link.id, to: link.path, role: "menuitem", onClick: close, className: itemClass, children: [
59
+ /* @__PURE__ */ jsx(link.icon, { className: "w-4 h-4 text-accent" }),
60
+ link.label
61
+ ] }, link.path)),
62
+ /* @__PURE__ */ jsx("div", { className: "border-t border-tone-100 mt-1 pt-1", children: /* @__PURE__ */ jsxs("button", { type: "button", role: "menuitem", onClick: handleLogout, className: `${itemClass} w-full text-red-600`, children: [
63
+ /* @__PURE__ */ jsx(LogOut, { className: "w-4 h-4" }),
64
+ "Log out"
65
+ ] }) })
66
+ ]
67
+ }
68
+ ) })
69
+ ] });
70
+ }
71
+ export {
72
+ AccountMenu as default
73
+ };
@@ -0,0 +1,48 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { formatDistanceToNow } from "date-fns";
4
+ import { History, Share2 } from "lucide-react";
5
+ import { Button } from "@okjt/ui";
6
+ import { CollaboratorAvatar } from "./CollaboratorAvatars.js";
7
+ import { useCollaboration } from "./CollaborationContext.js";
8
+ import { useDashboard } from "./DashboardProvider.js";
9
+ const ACTION_WORDS = { created: "added", updated: "edited", deleted: "deleted", restored: "restored" };
10
+ function ActivityPanel() {
11
+ const { module, othersHere, openHistory, setShareOpen } = useCollaboration();
12
+ const { api, anonymousName } = useDashboard();
13
+ const { data: recent = [], isLoading } = useQuery({
14
+ queryKey: ["revisions", module, "recent"],
15
+ queryFn: async () => (await api.get("/revisions", { params: { module, per_page: 5 } })).data?.data || [],
16
+ enabled: !!module,
17
+ staleTime: 15e3
18
+ });
19
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-5", children: [
20
+ /* @__PURE__ */ jsxs("section", { className: "space-y-2", children: [
21
+ /* @__PURE__ */ jsx("h3", { className: "text-[11px] font-bold uppercase tracking-wider text-tone-500", children: "On this page" }),
22
+ othersHere.length ? /* @__PURE__ */ jsxs("ul", { className: "space-y-1.5", children: [
23
+ othersHere.map((person) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2 text-sm text-tone-700", children: [
24
+ /* @__PURE__ */ jsx(CollaboratorAvatar, { person, size: "xs" }),
25
+ " ",
26
+ person.name
27
+ ] }, person.id)),
28
+ /* @__PURE__ */ jsx("li", { className: "text-xs text-amber-700", children: "Save often \u2014 the last save wins if you edit the same thing." })
29
+ ] }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-500", children: "Only you right now." })
30
+ ] }),
31
+ /* @__PURE__ */ jsxs("section", { className: "space-y-2", children: [
32
+ /* @__PURE__ */ jsx("h3", { className: "text-[11px] font-bold uppercase tracking-wider text-tone-500", children: "Recent changes" }),
33
+ isLoading ? /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-400", children: "Loading\u2026" }) : recent.length ? /* @__PURE__ */ jsx("ul", { className: "space-y-2", children: recent.map((r) => /* @__PURE__ */ jsxs("li", { className: "text-xs text-tone-600 leading-snug", children: [
34
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-tone-800", children: r.user?.name || anonymousName }),
35
+ " ",
36
+ ACTION_WORDS[r.action] || r.action,
37
+ " ",
38
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-tone-800", children: r.subject_label }),
39
+ /* @__PURE__ */ jsx("span", { className: "block text-[11px] text-tone-400", children: formatDistanceToNow(new Date(r.updated_at || r.created_at), { addSuffix: true }) })
40
+ ] }, r.id)) }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-500", children: "No changes recorded here yet." }),
41
+ /* @__PURE__ */ jsx(Button, { size: "sm", icon: History, fullWidth: true, onClick: openHistory, children: "Version history" })
42
+ ] }),
43
+ /* @__PURE__ */ jsx(Button, { size: "sm", icon: Share2, fullWidth: true, onClick: () => setShareOpen(true), children: "Invite collaborators" })
44
+ ] });
45
+ }
46
+ export {
47
+ ActivityPanel as default
48
+ };
@@ -0,0 +1,109 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useEffect } from "react";
3
+ import { motion, AnimatePresence } from "framer-motion";
4
+ import { X, MoreHorizontal, Users } from "lucide-react";
5
+ import { Button, useVisibleActions } from "@okjt/ui";
6
+ function AdminBulkActions({ selectedCount = 0, onClearSelection, actions: allActions = [] }) {
7
+ const actions = useVisibleActions(allActions);
8
+ const [menuOpen, setMenuOpen] = useState(false);
9
+ const menuRef = useRef(null);
10
+ useEffect(() => {
11
+ function handleClickOutside(e) {
12
+ if (menuRef.current && !menuRef.current.contains(e.target)) {
13
+ setMenuOpen(false);
14
+ }
15
+ }
16
+ if (menuOpen) document.addEventListener("mousedown", handleClickOutside);
17
+ return () => document.removeEventListener("mousedown", handleClickOutside);
18
+ }, [menuOpen]);
19
+ if (selectedCount === 0 || actions.length === 0) return null;
20
+ const primaryActions = actions.slice(0, 3);
21
+ const overflowActions = actions.slice(3);
22
+ const hasOverflow = overflowActions.length > 0;
23
+ return /* @__PURE__ */ jsxs(
24
+ motion.div,
25
+ {
26
+ initial: { opacity: 0, y: -10 },
27
+ animate: { opacity: 1, y: 0 },
28
+ exit: { opacity: 0, y: -10 },
29
+ className: "mb-6 p-3 rounded-xl bg-accent/5 border border-accent/10 flex flex-col sm:flex-row sm:items-center justify-between gap-3",
30
+ children: [
31
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
32
+ /* @__PURE__ */ jsx("div", { className: "w-8 h-8 rounded-lg bg-accent/10 flex items-center justify-center", children: /* @__PURE__ */ jsx(Users, { className: "w-4 h-4 text-accent" }) }),
33
+ /* @__PURE__ */ jsxs("div", { children: [
34
+ /* @__PURE__ */ jsxs("p", { className: "text-sm font-medium text-body", children: [
35
+ selectedCount,
36
+ " selected"
37
+ ] }),
38
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted", children: "Use the actions below or click items to deselect." })
39
+ ] })
40
+ ] }),
41
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [
42
+ primaryActions.map((action) => /* @__PURE__ */ jsx(
43
+ Button,
44
+ {
45
+ variant: action.variant || "primary",
46
+ icon: action.icon,
47
+ onClick: action.onClick,
48
+ disabled: action.disabled,
49
+ children: /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: action.label })
50
+ },
51
+ action.id
52
+ )),
53
+ hasOverflow && /* @__PURE__ */ jsxs("div", { className: "relative", ref: menuRef, children: [
54
+ /* @__PURE__ */ jsx(
55
+ Button,
56
+ {
57
+ size: "icon",
58
+ icon: MoreHorizontal,
59
+ "aria-label": "More actions",
60
+ onClick: () => setMenuOpen((v) => !v)
61
+ }
62
+ ),
63
+ /* @__PURE__ */ jsx(AnimatePresence, { children: menuOpen && /* @__PURE__ */ jsx(
64
+ motion.div,
65
+ {
66
+ initial: { opacity: 0, y: 8, scale: 0.96 },
67
+ animate: { opacity: 1, y: 0, scale: 1 },
68
+ exit: { opacity: 0, y: 8, scale: 0.96 },
69
+ className: "absolute right-0 bottom-full mb-2 min-w-[10rem] bg-white rounded-xl shadow-xl border border-tone-100 py-2 overflow-hidden z-20",
70
+ children: overflowActions.map((action) => {
71
+ const Icon = action.icon;
72
+ return /* @__PURE__ */ jsxs(
73
+ "button",
74
+ {
75
+ onClick: () => {
76
+ action.onClick();
77
+ setMenuOpen(false);
78
+ },
79
+ disabled: action.disabled,
80
+ className: `w-full text-left px-4 py-2.5 text-sm flex items-center gap-2 hover:bg-tone-50 transition-colors ${action.variant === "danger" ? "text-red-600" : "text-tone-700"} ${action.disabled ? "opacity-50 cursor-not-allowed" : ""}`,
81
+ children: [
82
+ Icon && /* @__PURE__ */ jsx(Icon, { className: "w-4 h-4" }),
83
+ action.label
84
+ ]
85
+ },
86
+ action.id
87
+ );
88
+ })
89
+ }
90
+ ) })
91
+ ] }),
92
+ /* @__PURE__ */ jsx(
93
+ "button",
94
+ {
95
+ "aria-label": "Clear selection",
96
+ onClick: onClearSelection,
97
+ className: "p-2 rounded-lg text-tone-400 hover:text-tone-600 hover:bg-white transition-colors",
98
+ title: "Clear selection",
99
+ children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" })
100
+ }
101
+ )
102
+ ] })
103
+ ]
104
+ }
105
+ );
106
+ }
107
+ export {
108
+ AdminBulkActions as default
109
+ };
@@ -0,0 +1,7 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ function AdminCard({ children, className = "", padding = true }) {
3
+ return /* @__PURE__ */ jsx("div", { className: `bg-white rounded-2xl shadow-sm border border-tone-100 ${padding ? "p-4 sm:p-5" : ""} ${className}`, children });
4
+ }
5
+ export {
6
+ AdminCard as default
7
+ };
@@ -0,0 +1,16 @@
1
+ import { createContext, useContext } from "react";
2
+ import { createPortal } from "react-dom";
3
+ const AdminChromeContext = createContext({ titleSlot: null, statusSlot: null });
4
+ const AdminChromeProvider = AdminChromeContext.Provider;
5
+ function useAdminChrome() {
6
+ return useContext(AdminChromeContext);
7
+ }
8
+ function AdminHeaderStatus({ children }) {
9
+ const { statusSlot } = useAdminChrome();
10
+ return statusSlot ? createPortal(children, statusSlot) : null;
11
+ }
12
+ export {
13
+ AdminChromeProvider,
14
+ AdminHeaderStatus,
15
+ useAdminChrome
16
+ };
@@ -0,0 +1,147 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { motion, AnimatePresence } from "framer-motion";
5
+ import { MoreHorizontal, ChevronUp, ChevronDown, SlidersHorizontal } from "lucide-react";
6
+ import AdminToolbarSearch from "./AdminToolbarSearch.js";
7
+ import AdminToolbarFilters, { countActiveFilters } from "./AdminToolbarFilters.js";
8
+ import { useSearch } from "./SearchContext.js";
9
+ import { Button, useVisibleActions } from "@okjt/ui";
10
+ function AdminFloatingToolbar({
11
+ actions = [],
12
+ children = null,
13
+ search = null,
14
+ filters = null,
15
+ z = "z-50",
16
+ wrapperClassName = ""
17
+ }) {
18
+ const [menuOpen, setMenuOpen] = useState(false);
19
+ const [visible, setVisible] = useState(true);
20
+ const [toolsOpen, setToolsOpen] = useState(false);
21
+ const { searchQuery } = useSearch();
22
+ const visibleActions = useVisibleActions(actions).filter((a) => !a.hidden);
23
+ const searchProps = !search ? null : typeof search === "string" ? { placeholder: search } : typeof search === "object" ? search : {};
24
+ const hasLeading = !!searchProps || !!filters;
25
+ if (visibleActions.length === 0 && !children && !hasLeading) return null;
26
+ const narrowed = searchProps && (searchProps.value ?? searchQuery) || countActiveFilters(filters) > 0;
27
+ const maxPrimary = hasLeading ? 2 : 4;
28
+ const primaryActions = visibleActions.slice(0, maxPrimary);
29
+ const overflowActions = visibleActions.slice(maxPrimary);
30
+ const hasOverflow = overflowActions.length > 0;
31
+ return createPortal(
32
+ /* @__PURE__ */ jsx(AnimatePresence, { children: visible ? /* @__PURE__ */ jsx(
33
+ motion.div,
34
+ {
35
+ initial: { opacity: 0, y: 30, scale: 0.96 },
36
+ animate: { opacity: 1, y: 0, scale: 1 },
37
+ exit: { opacity: 0, y: 20, scale: 0.96 },
38
+ transition: { type: "spring", stiffness: 300, damping: 25 },
39
+ className: `fixed bottom-[max(0.75rem,env(safe-area-inset-bottom))] sm:bottom-6 left-1/2 lg:left-[calc(50%+140px)] -translate-x-1/2 ${z} w-max max-w-[calc(100vw-1rem)] sm:max-w-[calc(100vw-1.5rem)] lg:max-w-[calc(100vw-280px-1.5rem)] ${wrapperClassName}`,
40
+ children: /* @__PURE__ */ jsxs(
41
+ "div",
42
+ {
43
+ className: "admin-floating-toolbar flex flex-wrap items-center justify-center gap-1 sm:gap-2 p-1.5 sm:p-2 rounded-2xl border border-white/40 shadow-2xl backdrop-blur-md",
44
+ style: {
45
+ background: "rgba(255, 249, 245, 0.92)",
46
+ boxShadow: "0 12px 40px rgba(74, 63, 53, 0.18)"
47
+ },
48
+ children: [
49
+ searchProps && /* @__PURE__ */ jsx(AdminToolbarSearch, { ...searchProps }),
50
+ filters && /* @__PURE__ */ jsx(AdminToolbarFilters, { filters }),
51
+ hasLeading && (children || visibleActions.length > 0) && /* @__PURE__ */ jsx("div", { className: "hidden sm:block w-px h-6 bg-tone-200/70 mx-0.5" }),
52
+ children && /* @__PURE__ */ jsx(
53
+ Button,
54
+ {
55
+ variant: toolsOpen ? "secondary" : "primary",
56
+ icon: SlidersHorizontal,
57
+ onClick: () => setToolsOpen((v) => !v),
58
+ "aria-expanded": toolsOpen,
59
+ className: "sm:hidden",
60
+ children: "Tools"
61
+ }
62
+ ),
63
+ children && /* @__PURE__ */ jsx("div", { className: toolsOpen ? "contents" : "hidden sm:contents", children }),
64
+ children && visibleActions.length > 0 && /* @__PURE__ */ jsx("div", { className: "hidden sm:block w-px h-6 bg-tone-200/70 mx-0.5" }),
65
+ primaryActions.map((action) => /* @__PURE__ */ jsx(
66
+ Button,
67
+ {
68
+ variant: action.variant,
69
+ icon: action.icon,
70
+ onClick: action.onClick,
71
+ disabled: action.disabled,
72
+ title: action.label,
73
+ "aria-label": action.label,
74
+ children: /* @__PURE__ */ jsx("span", { className: children ? "hidden 2xl:inline" : "hidden sm:inline", children: action.label })
75
+ },
76
+ action.id
77
+ )),
78
+ hasOverflow && /* @__PURE__ */ jsxs("div", { className: "relative", children: [
79
+ /* @__PURE__ */ jsx(Button, { icon: MoreHorizontal, onClick: () => setMenuOpen((v) => !v), "aria-label": "More actions", children: /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "More" }) }),
80
+ /* @__PURE__ */ jsx(AnimatePresence, { children: menuOpen && /* @__PURE__ */ jsx(
81
+ motion.div,
82
+ {
83
+ initial: { opacity: 0, y: 8, scale: 0.96 },
84
+ animate: { opacity: 1, y: 0, scale: 1 },
85
+ exit: { opacity: 0, y: 8, scale: 0.96 },
86
+ className: "absolute bottom-full left-1/2 -translate-x-1/2 mb-2 min-w-[10rem] bg-white rounded-xl shadow-xl border border-tone-100 py-2 overflow-hidden",
87
+ children: overflowActions.map((action) => {
88
+ const Icon = action.icon;
89
+ return /* @__PURE__ */ jsxs(
90
+ "button",
91
+ {
92
+ onClick: () => {
93
+ action.onClick();
94
+ setMenuOpen(false);
95
+ },
96
+ disabled: action.disabled,
97
+ className: `w-full text-left px-4 py-2.5 text-sm flex items-center gap-2 hover:bg-tone-50 transition-colors ${action.variant === "danger" ? "text-red-600" : "text-tone-700"} ${action.disabled ? "opacity-50 cursor-not-allowed" : ""}`,
98
+ children: [
99
+ Icon && /* @__PURE__ */ jsx(Icon, { className: "w-4 h-4" }),
100
+ action.label
101
+ ]
102
+ },
103
+ action.id
104
+ );
105
+ })
106
+ }
107
+ ) })
108
+ ] }),
109
+ /* @__PURE__ */ jsx(
110
+ "button",
111
+ {
112
+ "aria-label": "Hide toolbar",
113
+ onClick: () => setVisible(false),
114
+ className: "p-2 rounded-xl text-tone-400 hover:text-tone-600 hover:bg-white/60 transition-colors",
115
+ title: "Hide toolbar",
116
+ children: /* @__PURE__ */ jsx(ChevronDown, { className: "w-4 h-4" })
117
+ }
118
+ )
119
+ ]
120
+ }
121
+ )
122
+ },
123
+ "toolbar"
124
+ ) : /* @__PURE__ */ jsxs(
125
+ motion.button,
126
+ {
127
+ initial: { opacity: 0, y: 20 },
128
+ animate: { opacity: 1, y: 0 },
129
+ exit: { opacity: 0, y: 20 },
130
+ whileHover: { scale: 1.05 },
131
+ whileTap: { scale: 0.95 },
132
+ onClick: () => setVisible(true),
133
+ className: `fixed bottom-[max(0.75rem,env(safe-area-inset-bottom))] sm:bottom-6 left-1/2 lg:left-[calc(50%+140px)] -translate-x-1/2 ${z} p-2.5 rounded-full bg-white/90 border border-tone-200 shadow-lg text-accent hover:bg-white transition-colors ${wrapperClassName}`,
134
+ title: narrowed ? "Show toolbar (search or filters active)" : "Show toolbar",
135
+ children: [
136
+ /* @__PURE__ */ jsx(ChevronUp, { className: "w-5 h-5" }),
137
+ narrowed && /* @__PURE__ */ jsx("span", { className: "absolute top-1 right-1 w-2 h-2 rounded-full bg-accent" })
138
+ ]
139
+ },
140
+ "toolbar-toggle"
141
+ ) }),
142
+ document.body
143
+ );
144
+ }
145
+ export {
146
+ AdminFloatingToolbar as default
147
+ };