@okjt/dashboard 0.3.0 → 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.
@@ -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
+ };
@@ -0,0 +1,41 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useAuth } from "./AuthContext.js";
4
+ import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
5
+ function ConfirmPasswordPage({
6
+ layout: Layout = AuthLayout,
7
+ onConfirmed,
8
+ title = "Confirm it\u2019s you",
9
+ subtitle = "This is a secure area. Please confirm your password to carry on.",
10
+ footer,
11
+ submitLabel = "Confirm",
12
+ idPrefix = "confirm"
13
+ }) {
14
+ const { confirmPassword } = useAuth();
15
+ const [password, setPassword] = useState("");
16
+ const [error, setError] = useState(null);
17
+ const [loading, setLoading] = useState(false);
18
+ const onSubmit = async (e) => {
19
+ e.preventDefault();
20
+ setLoading(true);
21
+ setError(null);
22
+ const result = await confirmPassword(password);
23
+ setLoading(false);
24
+ if (result.success) {
25
+ onConfirmed?.();
26
+ return;
27
+ }
28
+ setError(result.errors?.password?.[0] || result.message);
29
+ setPassword("");
30
+ };
31
+ return /* @__PURE__ */ jsxs(Layout, { title, subtitle, footer, children: [
32
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
33
+ /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-5", children: [
34
+ /* @__PURE__ */ jsx(AuthField, { id: `${idPrefix}-password`, label: "Password", type: "password", autoComplete: "current-password", value: password, onChange: (e) => setPassword(e.target.value), required: true, autoFocus: true }),
35
+ /* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Checking\u2026" : submitLabel }) })
36
+ ] })
37
+ ] });
38
+ }
39
+ export {
40
+ ConfirmPasswordPage as default
41
+ };
@@ -33,7 +33,7 @@ function DashboardHeader({ onMenuClick, onRestartTutorial, titleSlotRef, statusS
33
33
  className: `${shell.collapsible ? "" : "lg:hidden "}relative p-2 rounded-lg shrink-0 ${shell.menuButtonClass}`,
34
34
  children: [
35
35
  shell.MenuIcon ? /* @__PURE__ */ jsx(shell.MenuIcon, {}) : /* @__PURE__ */ jsx(Menu, { className: "w-6 h-6 text-body" }),
36
- hasNews && /* @__PURE__ */ jsx("span", { className: `absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-accent ring-2 ring-paper ${shell.collapsible ? "lg:hidden" : ""}`, "aria-hidden": "true" })
36
+ hasNews && shell.menuNewsDot && /* @__PURE__ */ jsx("span", { className: `absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-accent ring-2 ring-paper ${shell.collapsible ? "lg:hidden" : ""}`, "aria-hidden": "true" })
37
37
  ]
38
38
  }
39
39
  ),
@@ -0,0 +1,15 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useDashboard } from "./DashboardProvider.js";
3
+ function DashboardIcon({ icon, fallback = null, className = "", ...rest }) {
4
+ const { iconFor } = useDashboard();
5
+ const Icon = (typeof icon === "string" ? iconFor(icon) : icon) || fallback;
6
+ return Icon ? /* @__PURE__ */ jsx(Icon, { className, "aria-hidden": "true", ...rest }) : null;
7
+ }
8
+ function toIcon(icon, iconFor) {
9
+ if (!icon) return null;
10
+ return typeof icon === "string" ? iconFor?.(icon) || null : icon;
11
+ }
12
+ export {
13
+ DashboardIcon as default,
14
+ toIcon
15
+ };
@@ -16,7 +16,9 @@ const DEFAULTS = {
16
16
  roleLabel: (role) => DEFAULT_ROLES.find((r) => r.value === role)?.label || role,
17
17
  anonymousName: "Someone",
18
18
  removeCollaborator: null,
19
- tutorialSteps: []
19
+ tutorialSteps: [],
20
+ iconFor: () => null,
21
+ componentDefaults: {}
20
22
  };
21
23
  const DEFAULT_SHELL = {
22
24
  logo: { src: "", alt: "", to: "/" },
@@ -50,6 +52,7 @@ const DEFAULT_SHELL = {
50
52
  headerEndClass: "gap-1 sm:gap-2 shrink-0",
51
53
  menuButtonClass: "hover:bg-contrast/5",
52
54
  MenuIcon: null,
55
+ menuNewsDot: true,
53
56
  mainClass: "p-4 sm:p-6",
54
57
  headerButtonClass: "text-soft hover:bg-accent/10 hover:text-accent",
55
58
  headerActions: ["online", "share", "history", "tour"],
@@ -61,11 +64,17 @@ const DEFAULT_SHELL = {
61
64
  function DashboardProvider({ dashboard, children }) {
62
65
  return /* @__PURE__ */ jsx(DashboardContext.Provider, { value: dashboard, children });
63
66
  }
67
+ function useComponentDefaults(name, props) {
68
+ const { componentDefaults } = useDashboard();
69
+ const defaults = componentDefaults?.[name];
70
+ return defaults ? { ...defaults, ...props } : props;
71
+ }
64
72
  function useDashboard() {
65
73
  const settings = useContext(DashboardContext);
66
74
  return { ...DEFAULTS, ...settings, shell: { ...DEFAULT_SHELL, ...settings?.shell, logo: { ...DEFAULT_SHELL.logo, ...settings?.shell?.logo } } };
67
75
  }
68
76
  export {
69
77
  DashboardProvider,
78
+ useComponentDefaults,
70
79
  useDashboard
71
80
  };