@okjt/dashboard 0.2.2 → 0.4.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.
@@ -1,5 +1,8 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { motion } from "framer-motion";
3
+ import { Minus, TrendingDown, TrendingUp } from "lucide-react";
4
+ import DashboardIcon from "./DashboardIcon.js";
5
+ import { useComponentDefaults } from "./DashboardProvider.js";
3
6
  const gridColumns = {
4
7
  1: "md:grid-cols-1",
5
8
  2: "md:grid-cols-2",
@@ -8,7 +11,11 @@ const gridColumns = {
8
11
  5: "md:grid-cols-3 xl:grid-cols-5",
9
12
  6: "md:grid-cols-3 xl:grid-cols-6"
10
13
  };
11
- function AdminSummaryCards({ cards = [], columns = 4 }) {
14
+ function AdminSummaryCards(ownProps) {
15
+ const { variant = "plain", ...props } = useComponentDefaults("SummaryCards", ownProps);
16
+ return variant === "bold" ? /* @__PURE__ */ jsx(BoldSummaryCards, { ...props }) : /* @__PURE__ */ jsx(PlainSummaryCards, { ...props });
17
+ }
18
+ function PlainSummaryCards({ cards = [], columns = 4 }) {
12
19
  if (!cards.length) return null;
13
20
  const gridCols = gridColumns[columns] || gridColumns[4];
14
21
  const iconVisibility = columns >= 5 ? "flex xl:hidden 2xl:flex" : "flex";
@@ -24,7 +31,7 @@ function AdminSummaryCards({ cards = [], columns = 4 }) {
24
31
  animate: { opacity: 1, y: 0 },
25
32
  transition: { delay: index * 0.05, duration: 0.2 },
26
33
  "aria-pressed": stat.onClick ? !!stat.active : void 0,
27
- className: `px-3.5 py-3 rounded-2xl bg-white flex items-center gap-3 text-left min-w-0 transition-shadow ${stat.onClick ? "cursor-pointer hover:ring-2 hover:ring-accent/20" : ""} ${stat.active ? "ring-2 ring-accent/50" : ""}`,
34
+ className: `px-3.5 py-3 rounded-2xl bg-surface flex items-center gap-3 text-left min-w-0 transition-shadow ${stat.onClick ? "cursor-pointer hover:ring-2 hover:ring-accent/20" : ""} ${stat.active ? "ring-2 ring-accent/50" : ""}`,
28
35
  style: { boxShadow: "0 4px 20px color-mix(in srgb, var(--color-accent) 8%, transparent)" },
29
36
  children: [
30
37
  /* @__PURE__ */ jsx(
@@ -46,6 +53,62 @@ function AdminSummaryCards({ cards = [], columns = 4 }) {
46
53
  );
47
54
  }) });
48
55
  }
56
+ const boldColumns = {
57
+ 1: "grid-cols-1",
58
+ 2: "grid-cols-2",
59
+ 3: "grid-cols-2 md:grid-cols-3",
60
+ 4: "grid-cols-2 xl:grid-cols-4",
61
+ 5: "grid-cols-2 md:grid-cols-3 xl:grid-cols-5",
62
+ 6: "grid-cols-2 md:grid-cols-3 xl:grid-cols-6"
63
+ };
64
+ function BoldSummaryCards({ cards = [], columns, stackOnPhones = false }) {
65
+ if (!cards.length) return null;
66
+ let cols = boldColumns[columns ?? Math.min(cards.length, 4)] || boldColumns[4];
67
+ const compact = (columns ?? cards.length) >= 5;
68
+ if (stackOnPhones) cols = cols.replace(/^grid-cols-2\b/, "grid-cols-1 sm:grid-cols-2");
69
+ return /* @__PURE__ */ jsx("div", { className: `grid gap-3 lg:gap-4 ${cols}`, children: cards.map((card) => /* @__PURE__ */ jsx(BoldStatCard, { compact, ...card }, card.label)) });
70
+ }
71
+ function BoldStatCard({ icon, label, value, trend, hint, onClick, active = false, compact = false }) {
72
+ const up = trend > 0;
73
+ const down = trend < 0;
74
+ const trendColor = up ? "text-emerald-300" : down ? "text-accent-dark" : "text-tone-500";
75
+ const Tag = onClick ? "button" : "div";
76
+ const interactive = onClick ? "w-full text-left transition hover:border-accent-dark/30 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-strong/60" : "";
77
+ const pressed = active ? "border-accent-strong/50 ring-1 ring-accent-strong/40" : "";
78
+ return /* @__PURE__ */ jsx(
79
+ Tag,
80
+ {
81
+ type: onClick ? "button" : void 0,
82
+ onClick,
83
+ "aria-pressed": onClick ? active : void 0,
84
+ className: `block rounded-2xl border border-tone-100 bg-surface backdrop-blur-xl ${compact ? "p-4 2xl:p-5" : "p-5 sm:p-6"} ${interactive} ${pressed}`,
85
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
86
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
87
+ /* @__PURE__ */ jsx("p", { className: "mb-2 text-sm text-tone-500", children: label }),
88
+ /* @__PURE__ */ jsx("p", { className: `truncate font-semibold tracking-tight text-ink ${compact ? "text-xl 2xl:text-2xl" : "text-2xl sm:text-3xl"}`, title: typeof value === "string" ? value : void 0, children: value }),
89
+ hint && /* @__PURE__ */ jsx("p", { className: "mt-1 truncate text-xs text-tone-400", title: hint, children: hint }),
90
+ trend !== void 0 && trend !== null && /* @__PURE__ */ jsxs("div", { className: "mt-3 flex items-center gap-1.5", children: [
91
+ /* @__PURE__ */ jsx(
92
+ DashboardIcon,
93
+ {
94
+ icon: up ? "trend-up" : down ? "trend-down" : "trend-flat",
95
+ fallback: up ? TrendingUp : down ? TrendingDown : Minus,
96
+ className: `${trendColor} text-[10px]`
97
+ }
98
+ ),
99
+ /* @__PURE__ */ jsxs("span", { className: `text-xs font-medium ${trendColor}`, children: [
100
+ Math.abs(trend),
101
+ "%"
102
+ ] }),
103
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-contrast/35", children: "vs. last month" })
104
+ ] })
105
+ ] }),
106
+ /* @__PURE__ */ jsx("div", { className: `h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-accent-soft/10 bg-action/30 ${compact ? "flex xl:hidden 2xl:flex" : "flex"}`, children: /* @__PURE__ */ jsx(DashboardIcon, { icon, className: "text-base text-accent-soft" }) })
107
+ ] })
108
+ }
109
+ );
110
+ }
49
111
  export {
112
+ BoldStatCard,
50
113
  AdminSummaryCards as default
51
114
  };
@@ -55,7 +55,7 @@ function AdminToolbarFilters({ filters }) {
55
55
  onClick: () => setOpen((v) => !v),
56
56
  "aria-haspopup": "dialog",
57
57
  "aria-expanded": open,
58
- className: `flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-all border ${activeCount > 0 ? "bg-accent/10 text-accent-dark border-accent/30" : "bg-white/80 text-body hover:bg-white border-tone-200/60"}`,
58
+ className: `flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-all border ${activeCount > 0 ? "bg-accent/10 text-accent-dark border-accent/30" : "bg-surface/80 text-body hover:bg-surface border-tone-200/60"}`,
59
59
  title: "Filter & sort",
60
60
  children: [
61
61
  /* @__PURE__ */ jsx(SlidersHorizontal, { className: "w-4 h-4" }),
@@ -73,7 +73,7 @@ function AdminToolbarFilters({ filters }) {
73
73
  animate: { opacity: 1, y: 0, scale: 1 },
74
74
  exit: { opacity: 0, y: 8, scale: 0.97 },
75
75
  transition: { duration: 0.15 },
76
- className: "absolute bottom-full left-0 mb-3 w-[min(20rem,calc(100vw-2rem))] max-h-[60vh] overflow-y-auto bg-white rounded-2xl shadow-2xl border border-tone-100 p-4 space-y-4 text-left",
76
+ className: "absolute bottom-full left-0 mb-3 w-[min(20rem,calc(100vw-2rem))] max-h-[60vh] overflow-y-auto bg-surface rounded-2xl shadow-2xl border border-tone-100 p-4 space-y-4 text-left",
77
77
  children: [
78
78
  groups.map((group) => /* @__PURE__ */ jsxs("div", { children: [
79
79
  /* @__PURE__ */ jsx("p", { className: "text-[11px] font-semibold uppercase tracking-wider text-tone-500 mb-2", children: group.label || "Show" }),
@@ -38,7 +38,7 @@ function AdminToolbarSearch({ placeholder = "Search...", value, onChange }) {
38
38
  placeholder,
39
39
  "aria-label": placeholder,
40
40
  title: "Search (press / to focus)",
41
- className: "w-28 sm:w-52 xl:w-60 pl-9 pr-8 py-2 sm:py-2.5 rounded-xl border border-tone-200/60 bg-white/80 text-sm text-tone-700 focus:bg-white focus:outline-none focus:ring-2 focus:ring-accent/30 focus:border-accent [&::-webkit-search-cancel-button]:hidden"
41
+ className: "w-28 sm:w-52 xl:w-60 pl-9 pr-8 py-2 sm:py-2.5 rounded-xl border border-tone-200/60 bg-surface/80 text-sm text-tone-700 focus:bg-surface focus:outline-none focus:ring-2 focus:ring-accent/30 focus:border-accent [&::-webkit-search-cancel-button]:hidden"
42
42
  }
43
43
  ),
44
44
  query && /* @__PURE__ */ jsx(
@@ -140,7 +140,7 @@ function AdminTutorial({ steps, onComplete, isRestarted = false }) {
140
140
  initial: { opacity: 0, scale: 0.95 },
141
141
  animate: { opacity: 1, scale: 1 },
142
142
  style: boxStyle,
143
- className: "absolute w-[calc(100%-48px)] max-w-sm max-h-[calc(100vh-32px)] flex flex-col bg-white rounded-3xl shadow-2xl overflow-hidden pointer-events-auto border-2 border-accent/30",
143
+ className: "absolute w-[calc(100%-48px)] max-w-sm max-h-[calc(100vh-32px)] flex flex-col bg-surface rounded-3xl shadow-2xl overflow-hidden pointer-events-auto border-2 border-accent/30",
144
144
  children: [
145
145
  /* @__PURE__ */ jsx("div", { className: "h-1.5 w-full bg-tone-100", children: /* @__PURE__ */ jsx(
146
146
  motion.div,
@@ -182,7 +182,7 @@ function AdminTutorial({ steps, onComplete, isRestarted = false }) {
182
182
  },
183
183
  currentStep
184
184
  ) }) }),
185
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 border-t border-tone-100 bg-white rounded-b-3xl", children: [
185
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 border-t border-tone-100 bg-surface rounded-b-3xl", children: [
186
186
  /* @__PURE__ */ jsxs("div", { className: "flex gap-1.5", children: [
187
187
  /* @__PURE__ */ jsx(
188
188
  Button,
@@ -2,73 +2,116 @@ import { jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useState, useEffect } from "react";
3
3
  import { useQueryClient } from "@tanstack/react-query";
4
4
  const AuthContext = createContext(null);
5
- function AuthProvider({ api, extend, children }) {
5
+ function AuthProvider({ api, extend, mode = "token", initialUser, children }) {
6
+ const session = mode === "session";
6
7
  const queryClient = useQueryClient();
7
8
  const [user, setUser] = useState(null);
8
9
  const [loading, setLoading] = useState(true);
9
10
  const [isAuthenticated, setIsAuthenticated] = useState(false);
10
11
  const [signedOut, setSignedOut] = useState(false);
11
12
  useEffect(() => {
13
+ if (initialUser !== void 0) {
14
+ setUser(initialUser);
15
+ setIsAuthenticated(!!initialUser);
16
+ setLoading(false);
17
+ return;
18
+ }
12
19
  checkAuth();
13
20
  }, []);
21
+ const keepToken = (token) => {
22
+ if (!session && token) localStorage.setItem("auth_token", token);
23
+ };
24
+ const forgetToken = () => {
25
+ if (!session) localStorage.removeItem("auth_token");
26
+ };
14
27
  const checkAuth = async () => {
15
- const token = localStorage.getItem("auth_token");
16
- if (token) {
28
+ if (session || localStorage.getItem("auth_token")) {
17
29
  try {
18
30
  const response = await api.get("/user");
19
31
  setUser(response.data);
20
32
  setIsAuthenticated(true);
21
33
  } catch {
22
- localStorage.removeItem("auth_token");
34
+ forgetToken();
23
35
  setUser(null);
24
36
  setIsAuthenticated(false);
25
37
  }
26
38
  }
27
39
  setLoading(false);
28
40
  };
29
- const login = async (email, password) => {
30
- try {
31
- const response = await api.post("/login", { email, password });
32
- if (response.data.requires_verification) {
33
- return {
34
- success: false,
35
- requires_verification: true,
36
- email: response.data.email,
37
- message: response.data.message || "Please verify your email before signing in."
38
- };
39
- }
40
- if (response.data.requires_2fa) {
41
- return {
42
- success: true,
43
- requires_2fa: true,
44
- email: response.data.email
45
- };
46
- }
47
- const { token, user: user2, ...extra } = response.data;
48
- localStorage.setItem("auth_token", token);
49
- setUser({ ...user2, ...extra });
50
- setIsAuthenticated(true);
51
- return { success: true, ...extra };
52
- } catch (error) {
41
+ const answer = (response) => {
42
+ const data = response.data ?? {};
43
+ if (data.requires_verification) {
53
44
  return {
54
45
  success: false,
55
- message: error.response?.data?.message || "Login failed"
46
+ requires_verification: true,
47
+ email: data.email,
48
+ message: data.message || response.message || "Please verify your email before signing in."
56
49
  };
57
50
  }
51
+ if (data.requires_2fa) {
52
+ return { success: true, requires_2fa: true, email: data.email, challenge: data.challenge };
53
+ }
54
+ return signedIn(data);
58
55
  };
59
- const verify2fa = async (email, code) => {
56
+ const failure = (error, fallback) => ({
57
+ success: false,
58
+ message: error.response?.data?.message || fallback,
59
+ errors: error.response?.data?.errors || {}
60
+ });
61
+ const login = async (email, password, options = {}) => {
60
62
  try {
61
- const response = await api.post("/verify-2fa", { email, code });
62
- const { token, user: user2, ...extra } = response.data;
63
- localStorage.setItem("auth_token", token);
64
- setUser({ ...user2, ...extra });
65
- setIsAuthenticated(true);
66
- return { success: true, ...extra };
63
+ const response = await api.post("/login", { email, password, ...options.remember ? { remember: true } : {} });
64
+ return answer(response);
67
65
  } catch (error) {
68
- return {
69
- success: false,
70
- message: error.response?.data?.message || "Invalid 2FA code"
71
- };
66
+ return failure(error, "Login failed");
67
+ }
68
+ };
69
+ const verify2fa = async (challenge, code) => {
70
+ try {
71
+ const response = await api.post("/verify-2fa", { challenge, code });
72
+ return answer(response);
73
+ } catch (error) {
74
+ return failure(error, "Invalid 2FA code");
75
+ }
76
+ };
77
+ const requestLoginCode = async (email) => {
78
+ try {
79
+ const response = await api.post("/login-code", { email });
80
+ return { success: true, message: response.message ?? response.data?.message };
81
+ } catch (error) {
82
+ return failure(error, "Could not send a code \u2014 try again.");
83
+ }
84
+ };
85
+ const verifyLoginCode = async (email, code) => {
86
+ try {
87
+ const response = await api.post("/login-code/verify", { email, code });
88
+ return answer(response);
89
+ } catch (error) {
90
+ return failure(error, "That sign-in code is invalid or expired.");
91
+ }
92
+ };
93
+ const forgotPassword = async (email) => {
94
+ try {
95
+ const response = await api.post("/forgot-password", { email });
96
+ return { success: true, message: response.message ?? response.data?.message };
97
+ } catch (error) {
98
+ return failure(error, "Could not send the link \u2014 try again.");
99
+ }
100
+ };
101
+ const resetPassword = async (data) => {
102
+ try {
103
+ const response = await api.post("/reset-password", data);
104
+ return { success: true, message: response.message ?? response.data?.message };
105
+ } catch (error) {
106
+ return failure(error, "Could not reset the password \u2014 try again.");
107
+ }
108
+ };
109
+ const confirmPassword = async (password) => {
110
+ try {
111
+ await api.post("/confirm-password", { password });
112
+ return { success: true };
113
+ } catch (error) {
114
+ return failure(error, "That password is incorrect.");
72
115
  }
73
116
  };
74
117
  const register = async (data) => {
@@ -83,10 +126,7 @@ function AuthProvider({ api, extend, children }) {
83
126
  message: payload.message
84
127
  };
85
128
  }
86
- const { token, user: user2, ...extra } = payload;
87
- localStorage.setItem("auth_token", token);
88
- setUser({ ...user2, ...extra });
89
- setIsAuthenticated(true);
129
+ signedIn(payload);
90
130
  return { success: true };
91
131
  } catch (error) {
92
132
  return {
@@ -108,8 +148,8 @@ function AuthProvider({ api, extend, children }) {
108
148
  try {
109
149
  const response = await api.post("/email/verify", { id, hash, expires, signature });
110
150
  const { token, user: user2, message: _message, email_verified: _verified, ...extra } = response.data;
111
- if (token) {
112
- localStorage.setItem("auth_token", token);
151
+ if (token || session && user2) {
152
+ keepToken(token);
113
153
  setUser({ ...user2, ...extra });
114
154
  setIsAuthenticated(true);
115
155
  } else {
@@ -123,14 +163,7 @@ function AuthProvider({ api, extend, children }) {
123
163
  const loginWithGoogle = async (code) => {
124
164
  try {
125
165
  const response = await api.post("/auth/google", { code });
126
- if (response.data.requires_2fa) {
127
- return { success: true, requires_2fa: true, email: response.data.email };
128
- }
129
- const { token, user: user2, ...extra } = response.data;
130
- localStorage.setItem("auth_token", token);
131
- setUser({ ...user2, ...extra });
132
- setIsAuthenticated(true);
133
- return { success: true, ...extra };
166
+ return answer(response);
134
167
  } catch (error) {
135
168
  return {
136
169
  success: false,
@@ -139,7 +172,7 @@ function AuthProvider({ api, extend, children }) {
139
172
  }
140
173
  };
141
174
  const loginWithToken = (token, authUser, extra = {}) => {
142
- localStorage.setItem("auth_token", token);
175
+ keepToken(token);
143
176
  setUser({ ...authUser, ...extra });
144
177
  setIsAuthenticated(true);
145
178
  };
@@ -153,7 +186,7 @@ function AuthProvider({ api, extend, children }) {
153
186
  } catch (error) {
154
187
  console.error("Logout error:", error);
155
188
  } finally {
156
- localStorage.removeItem("auth_token");
189
+ forgetToken();
157
190
  queryClient.clear();
158
191
  setUser(null);
159
192
  setIsAuthenticated(false);
@@ -168,6 +201,12 @@ function AuthProvider({ api, extend, children }) {
168
201
  login,
169
202
  register,
170
203
  verify2fa,
204
+ requestLoginCode,
205
+ verifyLoginCode,
206
+ forgotPassword,
207
+ resetPassword,
208
+ confirmPassword,
209
+ mode,
171
210
  loginWithToken,
172
211
  signedIn,
173
212
  loginWithGoogle,
@@ -0,0 +1,272 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { Link } from "react-router-dom";
5
+ import { AnimatePresence, motion } from "framer-motion";
6
+ import { Bookmark, ChevronDown, ChevronUp, MoreHorizontal, Search, SlidersHorizontal, X } from "lucide-react";
7
+ import { promptAction, useDismiss } from "@okjt/ui";
8
+ import DashboardIcon from "./DashboardIcon.js";
9
+ import useSavedViews from "./useSavedViews.js";
10
+ function countActiveFilterLists(filters = []) {
11
+ return filters.filter((f) => f.value !== (f.defaultValue ?? f.options?.[0]?.value)).length;
12
+ }
13
+ const actionClass = {
14
+ primary: "bg-gradient-to-r from-action to-accent text-white hover:shadow-lg hover:shadow-action/25",
15
+ secondary: "border border-contrast/10 bg-contrast/5 text-body hover:bg-contrast/10 hover:text-ink",
16
+ danger: "border border-red-500/30 bg-red-500/10 text-red-300 hover:bg-red-500/20 hover:text-red-200"
17
+ };
18
+ const Named = ({ name, fallback, className }) => /* @__PURE__ */ jsx(DashboardIcon, { icon: name, fallback, className });
19
+ function ActionLink({ action, ...props }) {
20
+ return action.download ? /* @__PURE__ */ jsx("a", { href: action.href, download: true, ...props }) : /* @__PURE__ */ jsx(Link, { to: action.href, ...props });
21
+ }
22
+ function Action({ action, compact }) {
23
+ const className = `inline-flex items-center gap-2 rounded-xl px-3 py-2 text-sm font-semibold transition disabled:opacity-50 disabled:cursor-not-allowed ${actionClass[action.variant || "secondary"]}`;
24
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
25
+ /* @__PURE__ */ jsx(DashboardIcon, { icon: action.icon }),
26
+ /* @__PURE__ */ jsx("span", { className: compact ? "sr-only" : "hidden sm:inline", children: action.label })
27
+ ] });
28
+ return action.href ? /* @__PURE__ */ jsx(ActionLink, { action, className, title: action.label, "aria-label": action.label, children: content }) : /* @__PURE__ */ jsx("button", { type: "button", onClick: action.onClick, disabled: action.disabled, className, title: action.label, "aria-label": action.label, children: content });
29
+ }
30
+ const snapshot = (filters, search) => ({
31
+ filters: Object.fromEntries(filters.map((f) => [f.name, f.value])),
32
+ search: search?.value ?? ""
33
+ });
34
+ function SavedViews({ filters, search, storageKey, onApplied }) {
35
+ const { views, saveView, deleteView } = useSavedViews(storageKey);
36
+ const apply = (view) => {
37
+ filters.forEach((f) => {
38
+ const value = view.state.filters?.[f.name];
39
+ if (value !== void 0 && f.options.some((o) => String(o.value) === String(value))) f.onChange(value);
40
+ });
41
+ if (search && typeof view.state.search === "string") search.onChange(view.state.search);
42
+ onApplied();
43
+ };
44
+ const save = async () => {
45
+ const name = await promptAction({ title: "Save this view", label: "Name", placeholder: "e.g. Pending receipts", confirmLabel: "Save view" });
46
+ if (name) saveView(name, snapshot(filters, search));
47
+ };
48
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-1.5 border-t border-contrast/10 pt-3", children: [
49
+ /* @__PURE__ */ jsx("span", { className: "block text-xs font-semibold capitalize text-soft", children: "Saved views" }),
50
+ views.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: views.map((view) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-1", children: [
51
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: () => apply(view), className: "min-w-0 flex-1 truncate rounded-lg px-2 py-1 text-left text-sm text-body hover:bg-contrast/5 hover:text-ink", children: view.name }),
52
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: () => deleteView(view.id), "aria-label": `Delete view ${view.name}`, className: "rounded-lg p-1 text-faint hover:bg-contrast/5 hover:text-accent-dark", children: /* @__PURE__ */ jsx(Named, { name: "close", fallback: X, className: "text-xs" }) })
53
+ ] }, view.id)) }),
54
+ /* @__PURE__ */ jsxs("button", { type: "button", onClick: save, className: "text-xs font-semibold text-body transition hover:text-ink", children: [
55
+ /* @__PURE__ */ jsx(Named, { name: "bookmark", fallback: Bookmark, className: "mr-1.5" }),
56
+ "Save current view\u2026"
57
+ ] })
58
+ ] });
59
+ }
60
+ const popover = { initial: { opacity: 0, y: 8, scale: 0.97 }, animate: { opacity: 1, y: 0, scale: 1 }, exit: { opacity: 0, y: 8, scale: 0.97 }, transition: { duration: 0.15 } };
61
+ function FiltersMenu({ filters, search, storageKey }) {
62
+ const [open, setOpen] = useState(false);
63
+ const ref = useRef(null);
64
+ useDismiss(ref, open, () => setOpen(false));
65
+ const active = countActiveFilterLists(filters);
66
+ return /* @__PURE__ */ jsxs("div", { className: "relative", ref, children: [
67
+ /* @__PURE__ */ jsxs(
68
+ "button",
69
+ {
70
+ type: "button",
71
+ onClick: () => setOpen((v) => !v),
72
+ "aria-expanded": open,
73
+ className: `inline-flex items-center gap-2 rounded-xl px-3 py-2 text-sm font-semibold transition border ${active ? "border-accent/40 bg-action/15 text-ink" : "border-contrast/10 bg-contrast/5 text-body hover:bg-contrast/10"}`,
74
+ children: [
75
+ /* @__PURE__ */ jsx(Named, { name: "filters", fallback: SlidersHorizontal }),
76
+ /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "Filters" }),
77
+ active > 0 && /* @__PURE__ */ jsx("span", { className: "min-w-[1.25rem] h-5 px-1 rounded-full bg-accent text-[11px] leading-5 text-white text-center", children: active })
78
+ ]
79
+ }
80
+ ),
81
+ /* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsxs(motion.div, { ...popover, className: "absolute bottom-full left-1/2 -translate-x-1/2 mb-3 w-72 max-w-[calc(100vw-2rem)] rounded-2xl border border-tone-100 bg-surface p-4 shadow-2xl space-y-3", children: [
82
+ filters.map((filter) => /* @__PURE__ */ jsxs("label", { className: "block", children: [
83
+ /* @__PURE__ */ jsx("span", { className: "mb-1 block text-xs font-semibold capitalize text-soft", children: filter.title || filter.label }),
84
+ /* @__PURE__ */ jsx("select", { value: filter.value, onChange: (e) => filter.onChange(e.target.value), className: "w-full py-2", children: filter.options.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value)) })
85
+ ] }, filter.name)),
86
+ active > 0 && /* @__PURE__ */ jsx(
87
+ "button",
88
+ {
89
+ type: "button",
90
+ onClick: () => filters.forEach((f) => f.onChange(f.defaultValue ?? f.options?.[0]?.value)),
91
+ className: "text-xs font-semibold text-accent-dark hover:text-ink transition",
92
+ children: "Reset filters"
93
+ }
94
+ ),
95
+ /* @__PURE__ */ jsx(SavedViews, { filters, search, storageKey, onApplied: () => setOpen(false) })
96
+ ] }) })
97
+ ] });
98
+ }
99
+ function MoreMenu({ actions }) {
100
+ const [open, setOpen] = useState(false);
101
+ const ref = useRef(null);
102
+ useDismiss(ref, open, () => setOpen(false));
103
+ return /* @__PURE__ */ jsxs("div", { className: "relative", ref, children: [
104
+ /* @__PURE__ */ jsxs(
105
+ "button",
106
+ {
107
+ type: "button",
108
+ onClick: () => setOpen((v) => !v),
109
+ "aria-expanded": open,
110
+ "aria-label": "More actions",
111
+ className: "inline-flex items-center gap-2 rounded-xl px-3 py-2 text-sm font-semibold border border-contrast/10 bg-contrast/5 text-body hover:bg-contrast/10 transition",
112
+ children: [
113
+ /* @__PURE__ */ jsx(Named, { name: "more", fallback: MoreHorizontal }),
114
+ /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "More" })
115
+ ]
116
+ }
117
+ ),
118
+ /* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsx(motion.div, { ...popover, className: "absolute bottom-full right-0 mb-3 min-w-[12rem] rounded-xl border border-tone-100 bg-surface py-2 shadow-2xl", children: actions.map((action) => {
119
+ const className = `flex w-full items-center gap-3 px-4 py-2.5 text-left text-sm transition hover:bg-contrast/[0.06] ${action.variant === "danger" ? "text-red-300" : "text-body"}`;
120
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
121
+ /* @__PURE__ */ jsx(DashboardIcon, { icon: action.icon, className: "w-4 text-center" }),
122
+ action.label
123
+ ] });
124
+ return action.href ? /* @__PURE__ */ jsx(ActionLink, { action, className, onClick: () => setOpen(false), children: content }, action.id) : /* @__PURE__ */ jsx("button", { type: "button", disabled: action.disabled, className, onClick: () => {
125
+ setOpen(false);
126
+ action.onClick?.();
127
+ }, children: content }, action.id);
128
+ }) }) })
129
+ ] });
130
+ }
131
+ const Divider = () => /* @__PURE__ */ jsx("div", { "aria-hidden": "true", className: "hidden sm:block w-px h-6 bg-contrast/10 mx-0.5" });
132
+ function BoldToolbar({ search, filters = [], view, actions = [], selection, children, savedViewsKey }) {
133
+ const [visible, setVisible] = useState(true);
134
+ const searchRef = useRef(null);
135
+ const selecting = selection && selection.count > 0;
136
+ const storageKey = savedViewsKey || `okjt.views.${typeof window === "undefined" ? "" : window.location.pathname}`;
137
+ useEffect(() => {
138
+ if (!search) return void 0;
139
+ const onKey = (e) => {
140
+ if (e.key !== "/" || e.metaKey || e.ctrlKey || e.altKey) return;
141
+ const tag = e.target?.tagName;
142
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || e.target?.isContentEditable) return;
143
+ e.preventDefault();
144
+ setVisible(true);
145
+ requestAnimationFrame(() => searchRef.current?.focus());
146
+ };
147
+ document.addEventListener("keydown", onKey);
148
+ return () => document.removeEventListener("keydown", onKey);
149
+ }, [search]);
150
+ const hasLeading = !!search || filters.length > 0 || !!view;
151
+ const max = hasLeading ? 2 : 4;
152
+ const primary = actions.slice(0, max);
153
+ const overflow = actions.slice(max);
154
+ const narrowed = !!search?.value || countActiveFilterLists(filters) > 0;
155
+ const position = "fixed z-[25] bottom-[max(0.75rem,env(safe-area-inset-bottom))] sm:bottom-6 left-1/2 lg:left-[calc(50%_+_var(--okjt-sidebar-w,16rem)_/_2)] transition-[left] duration-300";
156
+ const centre = { x: "-50%" };
157
+ if (typeof document === "undefined") return null;
158
+ if (!hasLeading && !actions.length && !selection && !children) return null;
159
+ return createPortal(
160
+ /* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: visible ? /* @__PURE__ */ jsx(
161
+ motion.div,
162
+ {
163
+ role: "toolbar",
164
+ "aria-label": "Page tools",
165
+ initial: { ...centre, opacity: 0, y: 24 },
166
+ animate: { ...centre, opacity: 1, y: 0 },
167
+ exit: { ...centre, opacity: 0, y: 16 },
168
+ transition: { type: "spring", stiffness: 320, damping: 28 },
169
+ className: `${position} w-max max-w-[calc(100vw-1rem)] lg:max-w-[calc(100vw_-_var(--okjt-sidebar-w,16rem)_-_2rem)]`,
170
+ children: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-center gap-1.5 sm:gap-2 rounded-2xl border border-tone-100 bg-paper-warm/90 p-1.5 sm:p-2 shadow-[0_16px_48px_rgba(0,0,0,0.55)] backdrop-blur-xl", children: [
171
+ selecting ? /* @__PURE__ */ jsxs(Fragment, { children: [
172
+ /* @__PURE__ */ jsxs("span", { className: "px-2 text-sm font-semibold text-ink whitespace-nowrap", children: [
173
+ selection.count,
174
+ " selected"
175
+ ] }),
176
+ selection.onSelectAll && /* @__PURE__ */ jsx(
177
+ "button",
178
+ {
179
+ type: "button",
180
+ onClick: selection.count === selection.total ? selection.onDeselectAll : selection.onSelectAll,
181
+ className: "rounded-xl px-3 py-2 text-sm font-semibold text-body hover:bg-contrast/[0.06] hover:text-ink transition",
182
+ children: selection.count === selection.total ? "Deselect all" : `Select all ${selection.total}`
183
+ }
184
+ ),
185
+ /* @__PURE__ */ jsx(Divider, {}),
186
+ (selection.actions || []).map((action) => /* @__PURE__ */ jsx(Action, { action }, action.id)),
187
+ /* @__PURE__ */ jsx(
188
+ "button",
189
+ {
190
+ type: "button",
191
+ onClick: selection.onDeselectAll,
192
+ "aria-label": "Clear selection",
193
+ title: "Clear selection",
194
+ className: "rounded-xl p-2 text-soft hover:bg-contrast/[0.06] hover:text-ink transition",
195
+ children: /* @__PURE__ */ jsx(Named, { name: "close", fallback: X })
196
+ }
197
+ )
198
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
199
+ search && /* @__PURE__ */ jsxs("div", { className: "relative", children: [
200
+ /* @__PURE__ */ jsx(Named, { name: "search", fallback: Search, className: "pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-xs text-soft" }),
201
+ /* @__PURE__ */ jsx(
202
+ "input",
203
+ {
204
+ ref: searchRef,
205
+ type: "search",
206
+ value: search.value,
207
+ onChange: (e) => search.onChange(e.target.value),
208
+ placeholder: search.placeholder || "Search\u2026",
209
+ "aria-label": search.placeholder || "Search this page",
210
+ className: "w-40 sm:w-56 sm:focus:w-72 rounded-xl border border-contrast/10 bg-contrast/5 py-2 pl-9 pr-9 text-sm transition-all"
211
+ }
212
+ ),
213
+ /* @__PURE__ */ jsx("kbd", { className: "pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 hidden sm:block rounded border border-contrast/15 px-1.5 text-[10px] text-soft", children: "/" })
214
+ ] }),
215
+ filters.length > 0 && /* @__PURE__ */ jsx(FiltersMenu, { filters, search, storageKey }),
216
+ view && view.modes?.length > 1 && /* @__PURE__ */ jsx("div", { className: "flex gap-1 rounded-xl border border-contrast/10 bg-ink-deep/30 p-1", children: view.modes.map((mode) => /* @__PURE__ */ jsx(
217
+ "button",
218
+ {
219
+ type: "button",
220
+ onClick: () => view.onChange(mode.value),
221
+ "aria-label": mode.label || `${mode.value} view`,
222
+ "aria-pressed": view.current === mode.value,
223
+ title: mode.label || `${mode.value} view`,
224
+ className: `rounded-lg px-2.5 py-1 text-sm transition-colors ${view.current === mode.value ? "bg-action text-white" : "text-soft hover:text-ink"}`,
225
+ children: /* @__PURE__ */ jsx(DashboardIcon, { icon: mode.icon })
226
+ },
227
+ mode.value
228
+ )) }),
229
+ hasLeading && (children || actions.length > 0) && /* @__PURE__ */ jsx(Divider, {}),
230
+ children,
231
+ primary.map((action) => /* @__PURE__ */ jsx(Action, { action }, action.id)),
232
+ overflow.length > 0 && /* @__PURE__ */ jsx(MoreMenu, { actions: overflow })
233
+ ] }),
234
+ /* @__PURE__ */ jsx(
235
+ "button",
236
+ {
237
+ type: "button",
238
+ onClick: () => setVisible(false),
239
+ "aria-label": "Hide toolbar",
240
+ title: "Hide toolbar",
241
+ className: "rounded-xl p-2 text-faint hover:bg-contrast/[0.06] hover:text-ink transition",
242
+ children: /* @__PURE__ */ jsx(Named, { name: "hide-toolbar", fallback: ChevronDown })
243
+ }
244
+ )
245
+ ] })
246
+ },
247
+ "toolbar"
248
+ ) : /* @__PURE__ */ jsxs(
249
+ motion.button,
250
+ {
251
+ type: "button",
252
+ initial: { ...centre, opacity: 0, y: 16 },
253
+ animate: { ...centre, opacity: 1, y: 0 },
254
+ exit: { ...centre, opacity: 0, y: 16 },
255
+ onClick: () => setVisible(true),
256
+ "aria-label": narrowed || selecting ? "Show toolbar (search, filters or selection active)" : "Show toolbar",
257
+ title: narrowed || selecting ? "Show toolbar (search, filters or selection active)" : "Show toolbar",
258
+ className: `${position} rounded-full border border-contrast/10 bg-paper-warm/90 p-3 text-body shadow-xl backdrop-blur-xl hover:text-ink`,
259
+ children: [
260
+ /* @__PURE__ */ jsx(Named, { name: "chevron-up", fallback: ChevronUp }),
261
+ (narrowed || selecting) && /* @__PURE__ */ jsx("span", { className: "absolute right-1 top-1 h-2.5 w-2.5 rounded-full bg-accent" })
262
+ ]
263
+ },
264
+ "toolbar-show"
265
+ ) }),
266
+ document.body
267
+ );
268
+ }
269
+ export {
270
+ countActiveFilterLists,
271
+ BoldToolbar as default
272
+ };