@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
@@ -0,0 +1,198 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useForm } from "react-hook-form";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
6
+ import TwoFactorForm from "./TwoFactorForm.js";
7
+ import { loginWithPasskey, passkeysSupported } from "./passkeys.js";
8
+ function SignInPage({
9
+ layout: Layout = AuthLayout,
10
+ onSignedIn,
11
+ title = "Welcome back",
12
+ subtitle,
13
+ footer,
14
+ forgotHint,
15
+ google,
16
+ idPrefix = "sign-in"
17
+ }) {
18
+ const { login, verify2fa, resendVerification, signedIn } = useAuth();
19
+ const [error, setError] = useState(null);
20
+ const [loading, setLoading] = useState(false);
21
+ const [is2faRequired, setIs2faRequired] = useState(false);
22
+ const [emailFor2fa, setEmailFor2fa] = useState("");
23
+ const [twoFactorCode, setTwoFactorCode] = useState("");
24
+ const [needsVerification, setNeedsVerification] = useState(null);
25
+ const [resendState, setResendState] = useState(null);
26
+ const { register, handleSubmit, formState: { errors } } = useForm();
27
+ const done = (result) => {
28
+ const problem = onSignedIn?.(result);
29
+ if (typeof problem === "string") setError(problem);
30
+ };
31
+ const onSubmit = async (data) => {
32
+ setLoading(true);
33
+ setError(null);
34
+ const result = await login(data.email, data.password);
35
+ if (result.requires_verification) {
36
+ setNeedsVerification(result.email);
37
+ setError(null);
38
+ } else if (result.success) {
39
+ if (result.requires_2fa) {
40
+ setIs2faRequired(true);
41
+ setEmailFor2fa(result.email);
42
+ } else {
43
+ done(result);
44
+ }
45
+ } else {
46
+ setError(result.message);
47
+ }
48
+ setLoading(false);
49
+ };
50
+ const handleResend = async () => {
51
+ setResendState("sending");
52
+ const result = await resendVerification(needsVerification);
53
+ setResendState(result.success ? "sent" : result.message);
54
+ };
55
+ const handlePasskey = async () => {
56
+ setLoading(true);
57
+ setError(null);
58
+ try {
59
+ const result = await loginWithPasskey();
60
+ if (result.requires_verification) {
61
+ setNeedsVerification(result.email);
62
+ return;
63
+ }
64
+ if (result.requires_2fa) {
65
+ setIs2faRequired(true);
66
+ setEmailFor2fa(result.email);
67
+ return;
68
+ }
69
+ done(signedIn(result));
70
+ } catch (err) {
71
+ setError(err.message || "Passkey sign-in failed.");
72
+ } finally {
73
+ setLoading(false);
74
+ }
75
+ };
76
+ const handle2faVerify = async (e) => {
77
+ e.preventDefault();
78
+ setLoading(true);
79
+ setError(null);
80
+ const result = await verify2fa(emailFor2fa, twoFactorCode);
81
+ if (result.success) {
82
+ done(result);
83
+ } else {
84
+ setError(result.message);
85
+ }
86
+ setLoading(false);
87
+ };
88
+ if (needsVerification) {
89
+ return /* @__PURE__ */ jsxs(
90
+ Layout,
91
+ {
92
+ title: "Verify your email",
93
+ subtitle: "One quick step \u2014 we sent a verification link so we know this address is yours.",
94
+ footer: /* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
95
+ setNeedsVerification(null);
96
+ setResendState(null);
97
+ }, className: "hover:text-body", children: "\u2190 Back to sign in" }),
98
+ children: [
99
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-muted mb-4", children: [
100
+ "Open ",
101
+ /* @__PURE__ */ jsx("strong", { className: "text-body", children: needsVerification }),
102
+ " and click the link we just sent. After that, sign in as usual."
103
+ ] }),
104
+ resendState === "sent" && /* @__PURE__ */ jsx("p", { className: "text-sm text-green-700 mb-4", children: "Sent \u2014 check your inbox (and spam, just in case)." }),
105
+ typeof resendState === "string" && resendState !== "sent" && resendState !== "sending" && /* @__PURE__ */ jsx("p", { className: "text-sm text-red-600 mb-4", children: resendState }),
106
+ /* @__PURE__ */ jsx(
107
+ "button",
108
+ {
109
+ type: "button",
110
+ onClick: handleResend,
111
+ disabled: resendState === "sending",
112
+ className: "text-sm font-semibold text-accent-strong hover:underline disabled:opacity-50",
113
+ children: resendState === "sending" ? "Sending\u2026" : "Resend the email"
114
+ }
115
+ )
116
+ ]
117
+ }
118
+ );
119
+ }
120
+ if (is2faRequired) {
121
+ return /* @__PURE__ */ jsxs(
122
+ Layout,
123
+ {
124
+ title: "Two-step verification",
125
+ subtitle: "Enter the 6-digit code from your authenticator app to finish signing in.",
126
+ footer: /* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
127
+ setIs2faRequired(false);
128
+ setError(null);
129
+ }, className: "hover:text-body", children: "\u2190 Use a different account" }),
130
+ children: [
131
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
132
+ /* @__PURE__ */ jsx(TwoFactorForm, { id: `${idPrefix}-2fa`, code: twoFactorCode, onCode: setTwoFactorCode, loading, onSubmit: handle2faVerify })
133
+ ]
134
+ }
135
+ );
136
+ }
137
+ return /* @__PURE__ */ jsxs(Layout, { title, subtitle, footer, children: [
138
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
139
+ /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-5", noValidate: true, children: [
140
+ /* @__PURE__ */ jsx(
141
+ AuthField,
142
+ {
143
+ id: `${idPrefix}-email`,
144
+ label: "Email",
145
+ type: "email",
146
+ autoComplete: "email",
147
+ placeholder: "you@example.com",
148
+ error: errors.email?.message,
149
+ ...register("email", {
150
+ required: "Email is required",
151
+ pattern: {
152
+ value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
153
+ message: "Invalid email address"
154
+ }
155
+ })
156
+ }
157
+ ),
158
+ /* @__PURE__ */ jsx(
159
+ AuthField,
160
+ {
161
+ id: `${idPrefix}-password`,
162
+ label: "Password",
163
+ type: "password",
164
+ autoComplete: "current-password",
165
+ placeholder: "Type your password",
166
+ error: errors.password?.message,
167
+ ...register("password", {
168
+ required: "Password is required",
169
+ minLength: { value: 6, message: "Password must be at least 6 characters" }
170
+ })
171
+ }
172
+ ),
173
+ forgotHint && /* @__PURE__ */ jsx("div", { className: "text-xs text-faint text-right -mt-1", children: forgotHint }),
174
+ /* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Signing in\u2026" : "Sign in" }) })
175
+ ] }),
176
+ /* @__PURE__ */ jsxs("div", { className: "relative my-5", "aria-hidden": "true", children: [
177
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center", children: /* @__PURE__ */ jsx("div", { className: "w-full border-t border-tone-200" }) }),
178
+ /* @__PURE__ */ jsx("div", { className: "relative flex justify-center text-xs", children: /* @__PURE__ */ jsx("span", { className: "bg-white px-3 text-faint", children: "or" }) })
179
+ ] }),
180
+ passkeysSupported() && /* @__PURE__ */ jsxs(
181
+ "button",
182
+ {
183
+ type: "button",
184
+ onClick: handlePasskey,
185
+ disabled: loading,
186
+ className: "mb-3 flex w-full items-center justify-center gap-2 rounded-full border border-tone-200 bg-white px-4 py-3 text-sm font-semibold text-ink shadow-sm transition-colors hover:bg-tone-50 disabled:opacity-50",
187
+ children: [
188
+ /* @__PURE__ */ jsx("svg", { className: "h-5 w-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: "1.8", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15.75 5.25a3 3 0 0 1 3 3m3 0a6 6 0 0 1-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1 1 21.75 8.25Z" }) }),
189
+ "Sign in with a passkey"
190
+ ]
191
+ }
192
+ ),
193
+ google
194
+ ] });
195
+ }
196
+ export {
197
+ SignInPage as default
198
+ };
@@ -0,0 +1,33 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { TrendingUp } from "lucide-react";
4
+ function StatCard({ icon, label, value, color }) {
5
+ return /* @__PURE__ */ jsxs(
6
+ "div",
7
+ {
8
+ className: "p-6 rounded-2xl transition-all hover:scale-[1.02]",
9
+ style: {
10
+ background: "white",
11
+ boxShadow: "0 4px 20px rgba(166, 123, 91, 0.08)"
12
+ },
13
+ children: [
14
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-4", children: [
15
+ /* @__PURE__ */ jsx(
16
+ "div",
17
+ {
18
+ className: "w-12 h-12 rounded-xl flex items-center justify-center",
19
+ style: { background: `${color}15` },
20
+ children: React.cloneElement(icon, { style: { color } })
21
+ }
22
+ ),
23
+ /* @__PURE__ */ jsx(TrendingUp, { className: "w-5 h-5 text-positive" })
24
+ ] }),
25
+ /* @__PURE__ */ jsx("p", { className: "text-3xl font-semibold mb-1 text-body", children: value }),
26
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted", children: label })
27
+ ]
28
+ }
29
+ );
30
+ }
31
+ export {
32
+ StatCard as default
33
+ };
@@ -0,0 +1,26 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { usePermissions } from "@okjt/ui";
3
+ function ToggleButton({ enabled, onToggle, label }) {
4
+ const { canEdit } = usePermissions();
5
+ return /* @__PURE__ */ jsxs(
6
+ "button",
7
+ {
8
+ type: "button",
9
+ onClick: onToggle,
10
+ disabled: !canEdit,
11
+ className: `relative inline-flex h-6 w-11 items-center rounded-full transition-colors disabled:opacity-60 disabled:cursor-not-allowed ${enabled ? "bg-accent" : "bg-tone-200"}`,
12
+ children: [
13
+ /* @__PURE__ */ jsx(
14
+ "span",
15
+ {
16
+ className: `inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${enabled ? "translate-x-6" : "translate-x-1"}`
17
+ }
18
+ ),
19
+ label && /* @__PURE__ */ jsx("span", { className: "sr-only", children: label })
20
+ ]
21
+ }
22
+ );
23
+ }
24
+ export {
25
+ ToggleButton as default
26
+ };
@@ -0,0 +1,26 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AuthField, AuthSubmit } from "./AuthLayout.js";
3
+ function TwoFactorForm({ id, code, onCode, loading, onSubmit }) {
4
+ return /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-6", children: [
5
+ /* @__PURE__ */ jsx(
6
+ AuthField,
7
+ {
8
+ id,
9
+ label: "Verification code",
10
+ value: code,
11
+ onChange: (e) => onCode(e.target.value.replace(/\D/g, "")),
12
+ inputMode: "numeric",
13
+ autoComplete: "one-time-code",
14
+ placeholder: "000000",
15
+ maxLength: 6,
16
+ required: true,
17
+ autoFocus: true,
18
+ inputClassName: "text-center text-xl tracking-[0.6em] font-semibold"
19
+ }
20
+ ),
21
+ /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Verifying\u2026" : "Verify & sign in" })
22
+ ] });
23
+ }
24
+ export {
25
+ TwoFactorForm as default
26
+ };
@@ -0,0 +1,13 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AlertCircle } from "lucide-react";
3
+ import { AdminHeaderStatus } from "./AdminChromeContext.js";
4
+ function UnsavedChangesStatus({ dirty }) {
5
+ if (!dirty) return null;
6
+ return /* @__PURE__ */ jsx(AdminHeaderStatus, { children: /* @__PURE__ */ jsxs("span", { role: "status", className: "px-3 py-1.5 rounded-full text-xs font-semibold flex items-center gap-2 bg-amber-50 text-amber-800 whitespace-nowrap", children: [
7
+ /* @__PURE__ */ jsx(AlertCircle, { className: "w-3.5 h-3.5" }),
8
+ " Unsaved changes"
9
+ ] }) });
10
+ }
11
+ export {
12
+ UnsavedChangesStatus as default
13
+ };
@@ -0,0 +1,42 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { useNavigate, useParams } from "react-router-dom";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError } from "./AuthLayout.js";
6
+ function VerifyEmailPage({ layout: Layout = AuthLayout, next = "/", signInPath = "/sign-in" }) {
7
+ const { id, hash } = useParams();
8
+ const navigate = useNavigate();
9
+ const { verifyEmail } = useAuth();
10
+ const [error, setError] = useState(null);
11
+ const [done, setDone] = useState(false);
12
+ useEffect(() => {
13
+ let cancelled = false;
14
+ (async () => {
15
+ const result = await verifyEmail({ id, hash });
16
+ if (cancelled) return;
17
+ if (result.success) {
18
+ setDone(true);
19
+ setTimeout(() => navigate(next, { replace: true }), 1200);
20
+ } else {
21
+ setError(result.message);
22
+ }
23
+ })();
24
+ return () => {
25
+ cancelled = true;
26
+ };
27
+ }, [id, hash]);
28
+ return /* @__PURE__ */ jsxs(
29
+ Layout,
30
+ {
31
+ title: done ? "Email verified" : "Verifying\u2026",
32
+ subtitle: done ? "You\u2019re all set \u2014 taking you in." : "One moment while we confirm your address.",
33
+ children: [
34
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
35
+ error && /* @__PURE__ */ jsx("a", { href: signInPath, className: "inline-flex text-sm font-semibold text-body underline underline-offset-4", children: "Back to sign in" })
36
+ ]
37
+ }
38
+ );
39
+ }
40
+ export {
41
+ VerifyEmailPage as default
42
+ };
@@ -0,0 +1,172 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { motion } from "framer-motion";
4
+ import { useInfiniteQuery, useQueryClient } from "@tanstack/react-query";
5
+ import { format, formatDistanceToNow, isToday, isYesterday } from "date-fns";
6
+ import { History, X, RotateCcw, Globe2 } from "lucide-react";
7
+ import { Overlay, Button, Spinner, SegmentedControl, confirmAction, notifyError, notifySuccess, usePermissions } from "@okjt/ui";
8
+ import { CollaboratorAvatar } from "./CollaboratorAvatars.js";
9
+ import { useDashboard } from "./DashboardProvider.js";
10
+ import { useModules } from "./modules.js";
11
+ const ACTION_WORDS = { created: "added", updated: "edited", deleted: "deleted", restored: "restored" };
12
+ const dayLabel = (date) => isToday(date) ? "Today" : isYesterday(date) ? "Yesterday" : format(date, "EEEE, d MMM yyyy");
13
+ const fieldLabel = (field) => field.replace(/_/g, " ").replace(/^\w/, (c) => c.toUpperCase());
14
+ function Change({ change }) {
15
+ return /* @__PURE__ */ jsxs("li", { className: "text-xs text-tone-600 break-words", children: [
16
+ /* @__PURE__ */ jsxs("span", { className: "font-medium text-tone-700", children: [
17
+ fieldLabel(change.field),
18
+ ": "
19
+ ] }),
20
+ change.before !== null && /* @__PURE__ */ jsx("del", { className: "text-tone-400 decoration-red-300", children: change.before }),
21
+ change.before !== null && " \u2192 ",
22
+ /* @__PURE__ */ jsx("span", { className: "text-tone-800", children: change.after ?? "\u2014" })
23
+ ] });
24
+ }
25
+ function Entry({ revision, batchSize, showModule, onRestore, restoring, canRestore }) {
26
+ const { anonymousName } = useDashboard();
27
+ const { moduleByKey } = useModules();
28
+ const who = revision.user || { id: 0, name: anonymousName };
29
+ const when = new Date(revision.updated_at || revision.created_at);
30
+ const moduleLabel = moduleByKey(revision.module)?.label || revision.module;
31
+ return /* @__PURE__ */ jsxs("li", { className: "flex gap-3 py-3", children: [
32
+ /* @__PURE__ */ jsx(CollaboratorAvatar, { person: who, size: "sm" }),
33
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-1", children: [
34
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-tone-700 leading-snug", children: [
35
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-tone-900", children: who.name }),
36
+ " ",
37
+ ACTION_WORDS[revision.action] || revision.action,
38
+ " ",
39
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-tone-900", children: revision.subject_label || revision.subject_type })
40
+ ] }),
41
+ /* @__PURE__ */ jsxs("p", { className: "text-[11px] text-tone-500 flex flex-wrap gap-x-2", children: [
42
+ /* @__PURE__ */ jsx("span", { title: format(when, "PPpp"), children: formatDistanceToNow(when, { addSuffix: true }) }),
43
+ showModule && /* @__PURE__ */ jsx("span", { className: "px-1.5 rounded bg-tone-100 text-tone-600", children: moduleLabel })
44
+ ] }),
45
+ revision.changes?.length > 0 && /* @__PURE__ */ jsxs("ul", { className: "space-y-0.5 pt-0.5", children: [
46
+ revision.changes.slice(0, 4).map((change) => /* @__PURE__ */ jsx(Change, { change }, change.field)),
47
+ revision.changes.length > 4 && /* @__PURE__ */ jsxs("li", { className: "text-[11px] text-tone-400", children: [
48
+ "+",
49
+ revision.changes.length - 4,
50
+ " more fields"
51
+ ] })
52
+ ] }),
53
+ canRestore && revision.restorable && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1.5 pt-1", children: [
54
+ /* @__PURE__ */ jsx(Button, { size: "sm", icon: RotateCcw, disabled: restoring, onClick: () => onRestore(revision, false), children: revision.action === "deleted" ? "Restore deleted item" : "Restore this version" }),
55
+ batchSize > 1 && /* @__PURE__ */ jsxs(Button, { size: "sm", disabled: restoring, onClick: () => onRestore(revision, true), children: [
56
+ "Restore whole save (",
57
+ batchSize,
58
+ ")"
59
+ ] })
60
+ ] })
61
+ ] })
62
+ ] });
63
+ }
64
+ function VersionHistoryDrawer({ module, onClose, onRestored }) {
65
+ const queryClient = useQueryClient();
66
+ const [scope, setScope] = useState(module ? "page" : "all");
67
+ const [restoring, setRestoring] = useState(false);
68
+ const { canEdit } = usePermissions();
69
+ const { api } = useDashboard();
70
+ const { moduleByKey } = useModules();
71
+ const filterModule = scope === "page" ? module : null;
72
+ const moduleLabel = moduleByKey(module)?.label;
73
+ const query = useInfiniteQuery({
74
+ queryKey: ["revisions", filterModule],
75
+ queryFn: async ({ pageParam }) => (await api.get("/revisions", { params: { module: filterModule || void 0, page: pageParam } })).data,
76
+ initialPageParam: 1,
77
+ getNextPageParam: (last) => last && last.current_page < last.last_page ? last.current_page + 1 : void 0,
78
+ staleTime: 0
79
+ });
80
+ const revisions = query.data?.pages.flatMap((p) => p?.data || []) || [];
81
+ const batchSizes = revisions.reduce((acc, r) => ({ ...acc, [r.batch]: (acc[r.batch] || 0) + 1 }), {});
82
+ const restore = async (revision, wholeBatch) => {
83
+ const ok = await confirmAction({
84
+ title: wholeBatch ? "Restore the whole save?" : "Restore this version?",
85
+ message: wholeBatch ? `Every change saved together with "${revision.subject_label}" goes back to how it was then. You can undo this from the history too.` : `"${revision.subject_label}" goes back to this version. Your current version stays in the history, so you can undo this.`,
86
+ confirmLabel: "Restore"
87
+ });
88
+ if (!ok) return;
89
+ setRestoring(true);
90
+ try {
91
+ const res = await api.post(`/revisions/${revision.id}/restore`, { batch: wholeBatch });
92
+ notifySuccess(res.data?.restored > 1 ? `${res.data.restored} changes restored` : "Version restored");
93
+ await queryClient.invalidateQueries();
94
+ onRestored?.();
95
+ } catch (err) {
96
+ notifyError(err, "Could not restore this version");
97
+ } finally {
98
+ setRestoring(false);
99
+ }
100
+ };
101
+ let lastDay = null;
102
+ return /* @__PURE__ */ jsx(Overlay, { onClose, className: "flex justify-end", backdropClassName: "bg-black/30", zIndex: 90, children: /* @__PURE__ */ jsxs(
103
+ motion.aside,
104
+ {
105
+ role: "dialog",
106
+ "aria-modal": "true",
107
+ "aria-label": "Version history",
108
+ initial: { x: "100%" },
109
+ animate: { x: 0 },
110
+ exit: { x: "100%" },
111
+ transition: { type: "spring", damping: 32, stiffness: 300 },
112
+ onClick: (e) => e.stopPropagation(),
113
+ className: "h-full w-full max-w-md bg-white shadow-2xl flex flex-col",
114
+ children: [
115
+ /* @__PURE__ */ jsxs("div", { className: "shrink-0 px-4 py-3 border-b border-tone-100 space-y-3", children: [
116
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
117
+ /* @__PURE__ */ jsx(History, { className: "w-5 h-5 text-accent" }),
118
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-medium text-tone-800 flex-1", children: "Version history" }),
119
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: onClose, "aria-label": "Close version history", className: "p-1.5 rounded-lg text-tone-500 hover:bg-tone-100", children: /* @__PURE__ */ jsx(X, { className: "w-5 h-5" }) })
120
+ ] }),
121
+ module && /* @__PURE__ */ jsx(
122
+ SegmentedControl,
123
+ {
124
+ size: "sm",
125
+ fullWidth: true,
126
+ "aria-label": "Show changes for",
127
+ value: scope,
128
+ onChange: setScope,
129
+ options: [
130
+ { value: "page", label: moduleLabel || "This page" },
131
+ { value: "all", label: "All pages", icon: Globe2 }
132
+ ]
133
+ }
134
+ )
135
+ ] }),
136
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 min-h-0 overflow-y-auto px-4", children: [
137
+ query.isLoading ? /* @__PURE__ */ jsx("div", { className: "py-10 flex justify-center", children: /* @__PURE__ */ jsx(Spinner, {}) }) : query.isError ? /* @__PURE__ */ jsx("p", { className: "py-10 text-center text-sm text-tone-500", children: "Couldn't load the history. Try again in a moment." }) : revisions.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "py-12 text-center space-y-1", children: [
138
+ /* @__PURE__ */ jsx(History, { className: "w-10 h-10 mx-auto text-tone-200" }),
139
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-tone-500", children: [
140
+ "No changes recorded ",
141
+ scope === "page" ? "on this page " : "",
142
+ "yet."
143
+ ] }),
144
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-400", children: "Every save from now on can be restored here." })
145
+ ] }) : /* @__PURE__ */ jsx("ul", { children: revisions.map((revision) => {
146
+ const day = dayLabel(new Date(revision.updated_at || revision.created_at));
147
+ const header = day !== lastDay ? day : null;
148
+ lastDay = day;
149
+ return /* @__PURE__ */ jsxs("li", { children: [
150
+ header && /* @__PURE__ */ jsx("h3", { className: "sticky top-0 z-10 bg-white/95 backdrop-blur pt-3 pb-1 text-[11px] font-bold uppercase tracking-wider text-tone-500", children: header }),
151
+ /* @__PURE__ */ jsx("ul", { className: "divide-y divide-tone-100", children: /* @__PURE__ */ jsx(
152
+ Entry,
153
+ {
154
+ revision,
155
+ batchSize: batchSizes[revision.batch] || 1,
156
+ showModule: scope === "all",
157
+ onRestore: restore,
158
+ restoring,
159
+ canRestore: canEdit
160
+ }
161
+ ) })
162
+ ] }, revision.id);
163
+ }) }),
164
+ query.hasNextPage && /* @__PURE__ */ jsx("div", { className: "py-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { size: "sm", loading: query.isFetchingNextPage, onClick: () => query.fetchNextPage(), children: "Load older changes" }) })
165
+ ] })
166
+ ]
167
+ }
168
+ ) });
169
+ }
170
+ export {
171
+ VersionHistoryDrawer as default
172
+ };
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ import { DashboardProvider, useDashboard } from "./DashboardProvider.js";
2
+ import { AdminChromeProvider, useAdminChrome, AdminHeaderStatus } from "./AdminChromeContext.js";
3
+ import { SearchProvider, useSearch } from "./SearchContext.js";
4
+ import { default as default2 } from "./AdminPageLayout.js";
5
+ import { default as default3 } from "./AdminPageHero.js";
6
+ import { default as default4 } from "./AdminSummaryCards.js";
7
+ import { default as default5 } from "./StatCard.js";
8
+ import { default as default6 } from "./AdminFloatingToolbar.js";
9
+ import { default as default7 } from "./AdminToolbarSearch.js";
10
+ import { default as default8, countActiveFilters } from "./AdminToolbarFilters.js";
11
+ import { SidePanelNav, SidePanelAside, SidePanelMobileBar } from "./AdminSidePanel.js";
12
+ import { default as default9 } from "./AdminListPanel.js";
13
+ import { default as default10, pageWindow } from "./AdminPagination.js";
14
+ import { default as default11 } from "./AdminBulkActions.js";
15
+ import { default as default12 } from "./AdminCard.js";
16
+ import { AdminInput, AdminTextarea, AdminSelect } from "./AdminInput.js";
17
+ import { default as default13 } from "./AdminModal.js";
18
+ import { default as default14 } from "./EditableFieldset.js";
19
+ import { default as default15 } from "./DeleteButton.js";
20
+ import { default as default16 } from "./ToggleButton.js";
21
+ import { default as default17 } from "./EmptyState.js";
22
+ import { default as default18 } from "./QueryError.js";
23
+ import { default as default19 } from "./UnsavedChangesStatus.js";
24
+ import { default as default20 } from "./AdminTutorial.js";
25
+ import { default as default21, useBulkAdminAction } from "./useAdminAction.js";
26
+ import { default as default22 } from "./useCrudHandlers.js";
27
+ import { default as default23, useUnsavedChanges } from "./useUnsavedChangesGuard.js";
28
+ import { default as default24 } from "./useFilteredItems.js";
29
+ import { default as default25 } from "./useSavedViews.js";
30
+ import { useModules, moduleForPathIn, initials, collaboratorColor } from "./modules.js";
31
+ import { CollaborationProvider, useCollaboration, HEARTBEAT_MS } from "./CollaborationContext.js";
32
+ import { default as default26, CollaboratorAvatar } from "./CollaboratorAvatars.js";
33
+ import { default as default27 } from "./ActivityPanel.js";
34
+ import { default as default28 } from "./useActivityPanel.js";
35
+ import { default as default29 } from "./VersionHistoryDrawer.js";
36
+ import { default as default30 } from "./ShareModal.js";
37
+ import { default as default31 } from "./DashboardShell.js";
38
+ import { default as default32 } from "./DashboardSidebar.js";
39
+ import { default as default33 } from "./DashboardHeader.js";
40
+ import { AuthProvider, useAuth, default as default34 } from "./AuthContext.js";
41
+ import { default as default35 } from "./GoogleButton.js";
42
+ import { default as default36 } from "./NotificationsBell.js";
43
+ import { loginWithPasskey, registerPasskey, passkeysSupported } from "./passkeys.js";
44
+ import { default as default37, AuthField, AuthSubmit, AuthError } from "./AuthLayout.js";
45
+ import { default as default38 } from "./SignInPage.js";
46
+ import { default as default39 } from "./GoogleCallbackPage.js";
47
+ import { default as default40 } from "./VerifyEmailPage.js";
48
+ import { default as default41 } from "./AcceptInvitePage.js";
49
+ import { default as default42 } from "./AccountMenu.js";
50
+ export {
51
+ default41 as AcceptInvitePage,
52
+ default42 as AccountMenu,
53
+ default27 as ActivityPanel,
54
+ default11 as AdminBulkActions,
55
+ default12 as AdminCard,
56
+ AdminChromeProvider,
57
+ default6 as AdminFloatingToolbar,
58
+ AdminHeaderStatus,
59
+ AdminInput,
60
+ default9 as AdminListPanel,
61
+ default13 as AdminModal,
62
+ default3 as AdminPageHero,
63
+ default2 as AdminPageLayout,
64
+ default10 as AdminPagination,
65
+ AdminSelect,
66
+ default4 as AdminSummaryCards,
67
+ AdminTextarea,
68
+ default8 as AdminToolbarFilters,
69
+ default7 as AdminToolbarSearch,
70
+ default20 as AdminTutorial,
71
+ default34 as AuthContext,
72
+ AuthError,
73
+ AuthField,
74
+ default37 as AuthLayout,
75
+ AuthProvider,
76
+ AuthSubmit,
77
+ CollaborationProvider,
78
+ CollaboratorAvatar,
79
+ default26 as CollaboratorAvatars,
80
+ default33 as DashboardHeader,
81
+ DashboardProvider,
82
+ default31 as DashboardShell,
83
+ default32 as DashboardSidebar,
84
+ default15 as DeleteButton,
85
+ default14 as EditableFieldset,
86
+ default17 as EmptyState,
87
+ default35 as GoogleButton,
88
+ default39 as GoogleCallbackPage,
89
+ HEARTBEAT_MS,
90
+ default36 as NotificationsBell,
91
+ default18 as QueryError,
92
+ SearchProvider,
93
+ default30 as ShareModal,
94
+ SidePanelAside,
95
+ SidePanelMobileBar,
96
+ SidePanelNav,
97
+ default38 as SignInPage,
98
+ default5 as StatCard,
99
+ default16 as ToggleButton,
100
+ default19 as UnsavedChangesStatus,
101
+ default40 as VerifyEmailPage,
102
+ default29 as VersionHistoryDrawer,
103
+ collaboratorColor,
104
+ countActiveFilters,
105
+ initials,
106
+ loginWithPasskey,
107
+ moduleForPathIn,
108
+ pageWindow,
109
+ passkeysSupported,
110
+ registerPasskey,
111
+ default28 as useActivityPanel,
112
+ default21 as useAdminAction,
113
+ useAdminChrome,
114
+ useAuth,
115
+ useBulkAdminAction,
116
+ useCollaboration,
117
+ default22 as useCrudHandlers,
118
+ useDashboard,
119
+ default24 as useFilteredItems,
120
+ useModules,
121
+ default25 as useSavedViews,
122
+ useSearch,
123
+ useUnsavedChanges,
124
+ default23 as useUnsavedChangesGuard
125
+ };