@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.
- package/README.md +149 -2
- package/dist/AcceptInvitePage.js +86 -0
- package/dist/AccountMenu.js +73 -0
- package/dist/ActivityPanel.js +48 -0
- package/dist/AdminBulkActions.js +109 -0
- package/dist/AdminCard.js +7 -0
- package/dist/AdminChromeContext.js +16 -0
- package/dist/AdminFloatingToolbar.js +147 -0
- package/dist/AdminInput.js +66 -0
- package/dist/AdminListPanel.js +26 -0
- package/dist/AdminModal.js +23 -0
- package/dist/AdminPageHero.js +101 -0
- package/dist/AdminPageLayout.js +54 -0
- package/dist/AdminPagination.js +92 -0
- package/dist/AdminSidePanel.js +479 -0
- package/dist/AdminSummaryCards.js +51 -0
- package/dist/AdminToolbarFilters.js +168 -0
- package/dist/AdminToolbarSearch.js +61 -0
- package/dist/AdminTutorial.js +221 -0
- package/dist/AuthContext.js +194 -0
- package/dist/AuthLayout.js +94 -0
- package/dist/CollaborationContext.js +84 -0
- package/dist/CollaboratorAvatars.js +36 -0
- package/dist/DashboardHeader.js +140 -0
- package/dist/DashboardProvider.js +45 -0
- package/dist/DashboardShell.js +93 -0
- package/dist/DashboardSidebar.js +97 -0
- package/dist/DeleteButton.js +21 -0
- package/dist/EditableFieldset.js +9 -0
- package/dist/EmptyState.js +22 -0
- package/dist/GoogleButton.js +22 -0
- package/dist/GoogleCallbackPage.js +81 -0
- package/dist/NotificationsBell.js +149 -0
- package/dist/QueryError.js +23 -0
- package/dist/SearchContext.js +16 -0
- package/dist/ShareModal.js +228 -0
- package/dist/SignInPage.js +198 -0
- package/dist/StatCard.js +33 -0
- package/dist/ToggleButton.js +26 -0
- package/dist/TwoFactorForm.js +26 -0
- package/dist/UnsavedChangesStatus.js +13 -0
- package/dist/VerifyEmailPage.js +42 -0
- package/dist/VersionHistoryDrawer.js +172 -0
- package/dist/index.js +125 -0
- package/dist/modules.js +32 -0
- package/dist/passkeys.js +84 -0
- package/dist/useActivityPanel.js +34 -0
- package/dist/useAdminAction.js +77 -0
- package/dist/useCrudHandlers.js +54 -0
- package/dist/useFilteredItems.js +19 -0
- package/dist/useSavedViews.js +30 -0
- package/dist/useUnsavedChangesGuard.js +41 -0
- package/package.json +40 -4
package/dist/modules.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useDashboard } from "./DashboardProvider.js";
|
|
3
|
+
function moduleForPathIn(modules, pathname = "") {
|
|
4
|
+
const path = pathname.replace(/\/+$/, "") || "/";
|
|
5
|
+
let best = null;
|
|
6
|
+
for (const m of modules) {
|
|
7
|
+
if ((path === m.path || path.startsWith(`${m.path}/`)) && (!best || m.path.length > best.path.length)) best = m;
|
|
8
|
+
}
|
|
9
|
+
return best;
|
|
10
|
+
}
|
|
11
|
+
function useModules() {
|
|
12
|
+
const { modules } = useDashboard();
|
|
13
|
+
return useMemo(() => {
|
|
14
|
+
const byKey = Object.fromEntries(modules.map((m) => [m.key, m]));
|
|
15
|
+
return {
|
|
16
|
+
modules,
|
|
17
|
+
moduleByKey: (key) => byKey[key] || null,
|
|
18
|
+
moduleForPath: (pathname) => moduleForPathIn(modules, pathname)
|
|
19
|
+
};
|
|
20
|
+
}, [modules]);
|
|
21
|
+
}
|
|
22
|
+
function initials(name = "") {
|
|
23
|
+
return name.trim().split(/\s+/).slice(0, 2).map((p) => p[0]?.toUpperCase() || "").join("") || "?";
|
|
24
|
+
}
|
|
25
|
+
const COLLABORATOR_COLORS = ["#A67B5B", "#6B8E7F", "#8B6FA6", "#C27C5A", "#5B7FA6", "#A65B7B", "#7F8E5B"];
|
|
26
|
+
const collaboratorColor = (id = 0) => COLLABORATOR_COLORS[Math.abs(Number(id) || 0) % COLLABORATOR_COLORS.length];
|
|
27
|
+
export {
|
|
28
|
+
collaboratorColor,
|
|
29
|
+
initials,
|
|
30
|
+
moduleForPathIn,
|
|
31
|
+
useModules
|
|
32
|
+
};
|
package/dist/passkeys.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
function b64urlToBuffer(b64url) {
|
|
2
|
+
const bin = atob(b64url.replace(/-/g, "+").replace(/_/g, "/"));
|
|
3
|
+
const bytes = new Uint8Array(bin.length);
|
|
4
|
+
for (let i = 0; i < bin.length; i += 1) bytes[i] = bin.charCodeAt(i);
|
|
5
|
+
return bytes.buffer;
|
|
6
|
+
}
|
|
7
|
+
function bufferToB64url(buffer) {
|
|
8
|
+
let bin = "";
|
|
9
|
+
new Uint8Array(buffer).forEach((b) => {
|
|
10
|
+
bin += String.fromCharCode(b);
|
|
11
|
+
});
|
|
12
|
+
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
13
|
+
}
|
|
14
|
+
function decodeOptions(options, listKey) {
|
|
15
|
+
return {
|
|
16
|
+
...options,
|
|
17
|
+
challenge: b64urlToBuffer(options.challenge),
|
|
18
|
+
[listKey]: (options[listKey] || []).map((c) => ({ ...c, id: b64urlToBuffer(c.id) }))
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function encodeCredential(credential) {
|
|
22
|
+
const { response } = credential;
|
|
23
|
+
const base = {
|
|
24
|
+
id: credential.id,
|
|
25
|
+
rawId: bufferToB64url(credential.rawId),
|
|
26
|
+
type: credential.type,
|
|
27
|
+
clientExtensionResults: credential.getClientExtensionResults?.() || {}
|
|
28
|
+
};
|
|
29
|
+
if ("attestationObject" in response) {
|
|
30
|
+
return {
|
|
31
|
+
...base,
|
|
32
|
+
response: {
|
|
33
|
+
attestationObject: bufferToB64url(response.attestationObject),
|
|
34
|
+
clientDataJSON: bufferToB64url(response.clientDataJSON),
|
|
35
|
+
transports: response.getTransports?.() || []
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...base,
|
|
41
|
+
response: {
|
|
42
|
+
authenticatorData: bufferToB64url(response.authenticatorData),
|
|
43
|
+
clientDataJSON: bufferToB64url(response.clientDataJSON),
|
|
44
|
+
signature: bufferToB64url(response.signature),
|
|
45
|
+
userHandle: response.userHandle ? bufferToB64url(response.userHandle) : null
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function fetchOptions(url, headers, failure) {
|
|
50
|
+
const res = await fetch(url, { headers: { Accept: "application/json", ...headers }, credentials: "same-origin" });
|
|
51
|
+
if (!res.ok) throw new Error(failure);
|
|
52
|
+
const payload = await res.json();
|
|
53
|
+
return payload.data?.options || payload.options;
|
|
54
|
+
}
|
|
55
|
+
async function send(url, headers, body, failure) {
|
|
56
|
+
const res = await fetch(url, {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers: { "Content-Type": "application/json", Accept: "application/json", ...headers },
|
|
59
|
+
credentials: "same-origin",
|
|
60
|
+
body: JSON.stringify(body)
|
|
61
|
+
});
|
|
62
|
+
const payload = await res.json();
|
|
63
|
+
if (!res.ok) throw new Error(payload.message || failure);
|
|
64
|
+
return payload.data || payload;
|
|
65
|
+
}
|
|
66
|
+
async function loginWithPasskey({ base = "/api" } = {}) {
|
|
67
|
+
const options = await fetchOptions(`${base}/passkeys/login/options`, {}, "Could not start passkey sign-in.");
|
|
68
|
+
const credential = await navigator.credentials.get({ publicKey: decodeOptions(options, "allowCredentials") });
|
|
69
|
+
return send(`${base}/passkeys/login`, {}, { credential: encodeCredential(credential) }, "Passkey sign-in failed.");
|
|
70
|
+
}
|
|
71
|
+
async function registerPasskey(name, token, { base = "/api" } = {}) {
|
|
72
|
+
const auth = { Authorization: `Bearer ${token}` };
|
|
73
|
+
const options = await fetchOptions(`${base}/passkeys/options`, auth, "Could not start passkey registration.");
|
|
74
|
+
const credential = await navigator.credentials.create({ publicKey: decodeOptions(options, "excludeCredentials") });
|
|
75
|
+
return send(`${base}/passkeys`, auth, { name, credential: encodeCredential(credential) }, "Could not save passkey.");
|
|
76
|
+
}
|
|
77
|
+
function passkeysSupported() {
|
|
78
|
+
return typeof window !== "undefined" && !!window.PublicKeyCredential;
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
loginWithPasskey,
|
|
82
|
+
passkeysSupported,
|
|
83
|
+
registerPasskey
|
|
84
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Activity, History } from "lucide-react";
|
|
3
|
+
import ActivityPanel from "./ActivityPanel.js";
|
|
4
|
+
import { CollaboratorAvatar } from "./CollaboratorAvatars.js";
|
|
5
|
+
import { useCollaboration } from "./CollaborationContext.js";
|
|
6
|
+
function useActivityPanel() {
|
|
7
|
+
const { othersHere, openHistory } = useCollaboration();
|
|
8
|
+
return {
|
|
9
|
+
id: "activity",
|
|
10
|
+
title: "Activity",
|
|
11
|
+
icon: Activity,
|
|
12
|
+
subtitle: "Who\u2019s here and what changed",
|
|
13
|
+
defaultCollapsed: true,
|
|
14
|
+
mobile: false,
|
|
15
|
+
content: /* @__PURE__ */ jsx(ActivityPanel, {}),
|
|
16
|
+
rail: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17
|
+
othersHere.slice(0, 3).map((person) => /* @__PURE__ */ jsx(CollaboratorAvatar, { person, size: "xs" }, person.id)),
|
|
18
|
+
/* @__PURE__ */ jsx(
|
|
19
|
+
"button",
|
|
20
|
+
{
|
|
21
|
+
type: "button",
|
|
22
|
+
onClick: openHistory,
|
|
23
|
+
"aria-label": "Version history",
|
|
24
|
+
title: "Version history",
|
|
25
|
+
className: "p-2 rounded-lg text-tone-500 hover:bg-tone-100 hover:text-accent",
|
|
26
|
+
children: /* @__PURE__ */ jsx(History, { className: "w-4 h-4" })
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
] })
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
useActivityPanel as default
|
|
34
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { toast } from "react-hot-toast";
|
|
4
|
+
import { usePermissions, confirmAction, notifyError, notifySuccess } from "@okjt/ui";
|
|
5
|
+
import { useDashboard } from "./DashboardProvider.js";
|
|
6
|
+
const resolve = (value, ...args) => typeof value === "function" ? value(...args) : value;
|
|
7
|
+
const deniedByRole = (err) => err?.response?.status === 403 && err.response.data?.reason === "role";
|
|
8
|
+
function useAdminAction(fn, options = {}) {
|
|
9
|
+
const { canEdit, isOwner } = usePermissions();
|
|
10
|
+
const allowed = options.role === "owner" ? isOwner : canEdit;
|
|
11
|
+
const queryClient = useQueryClient();
|
|
12
|
+
const refreshCollaboration = useDashboard().useAfterChange();
|
|
13
|
+
const [pendingKeys, setPendingKeys] = useState(() => /* @__PURE__ */ new Set());
|
|
14
|
+
const latest = useRef({ fn, options });
|
|
15
|
+
latest.current = { fn, options };
|
|
16
|
+
const run = useCallback(async (...args) => {
|
|
17
|
+
const { fn: write, options: opts } = latest.current;
|
|
18
|
+
if (!allowed) {
|
|
19
|
+
toast.error(opts.role === "owner" ? "Only owners can do this." : "You have view-only access.", { id: "role-denied" });
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
const confirmInput = resolve(opts.confirm, ...args);
|
|
23
|
+
if (confirmInput && !await confirmAction(confirmInput)) return void 0;
|
|
24
|
+
const key = opts.key ? opts.key(...args) : args[0];
|
|
25
|
+
setPendingKeys((keys) => new Set(keys).add(key));
|
|
26
|
+
try {
|
|
27
|
+
const result = await write(...args);
|
|
28
|
+
const message = resolve(opts.success, result, ...args);
|
|
29
|
+
if (message) notifySuccess(message);
|
|
30
|
+
await Promise.all([
|
|
31
|
+
...(opts.invalidate || []).map((queryKey) => queryClient.invalidateQueries({ queryKey })),
|
|
32
|
+
queryClient.invalidateQueries({ queryKey: ["revisions"] })
|
|
33
|
+
]);
|
|
34
|
+
refreshCollaboration?.();
|
|
35
|
+
opts.onSuccess?.(result, ...args);
|
|
36
|
+
return result;
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if (opts.error !== false && !deniedByRole(err)) notifyError(err, resolve(opts.error, err, ...args) || "Something went wrong");
|
|
39
|
+
opts.onError?.(err, ...args);
|
|
40
|
+
if (opts.rethrow) throw err;
|
|
41
|
+
return void 0;
|
|
42
|
+
} finally {
|
|
43
|
+
setPendingKeys((keys) => {
|
|
44
|
+
const next = new Set(keys);
|
|
45
|
+
next.delete(key);
|
|
46
|
+
return next;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}, [allowed, queryClient, refreshCollaboration]);
|
|
50
|
+
return useMemo(() => ({
|
|
51
|
+
run,
|
|
52
|
+
allowed,
|
|
53
|
+
pending: pendingKeys.size > 0,
|
|
54
|
+
isPending: (key) => pendingKeys.has(key),
|
|
55
|
+
isAdminAction: true
|
|
56
|
+
}), [run, allowed, pendingKeys]);
|
|
57
|
+
}
|
|
58
|
+
function useBulkAdminAction(fn, options = {}) {
|
|
59
|
+
return useAdminAction(async (ids) => {
|
|
60
|
+
const results = await Promise.allSettled(ids.map((id) => fn(id)));
|
|
61
|
+
const failed = results.filter((r) => r.status === "rejected").length;
|
|
62
|
+
if (failed) {
|
|
63
|
+
const err = new Error(`${failed} of ${ids.length} failed`);
|
|
64
|
+
err.failed = failed;
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
return ids.length;
|
|
68
|
+
}, {
|
|
69
|
+
key: () => "bulk",
|
|
70
|
+
error: (err, ids) => err.failed ? `${err.failed} of ${ids.length} couldn't be updated` : "Something went wrong",
|
|
71
|
+
...options
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
useAdminAction as default,
|
|
76
|
+
useBulkAdminAction
|
|
77
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import useAdminAction from "./useAdminAction.js";
|
|
3
|
+
function useCrudHandlers({ service, onRefresh, labels = {} }) {
|
|
4
|
+
const [selectedItem, setSelectedItem] = useState(null);
|
|
5
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
6
|
+
const handleAdd = useCallback(() => {
|
|
7
|
+
setSelectedItem(null);
|
|
8
|
+
setModalOpen(true);
|
|
9
|
+
}, []);
|
|
10
|
+
const handleEdit = useCallback((item) => {
|
|
11
|
+
setSelectedItem(item);
|
|
12
|
+
setModalOpen(true);
|
|
13
|
+
}, []);
|
|
14
|
+
const removeAction = useAdminAction(
|
|
15
|
+
(id, opts = {}) => opts.deleteFn ? opts.deleteFn(id) : service?.delete?.(id),
|
|
16
|
+
{
|
|
17
|
+
confirm: (id, opts = {}) => opts.confirmMessage || "Delete this item?",
|
|
18
|
+
success: labels.deleted,
|
|
19
|
+
error: "Failed to delete",
|
|
20
|
+
onSuccess: () => onRefresh?.()
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
const saveAction = useAdminAction(
|
|
24
|
+
(data) => selectedItem ? service.update(selectedItem.id, data) : service.create(data),
|
|
25
|
+
{
|
|
26
|
+
key: () => "save",
|
|
27
|
+
success: labels.saved,
|
|
28
|
+
error: "Failed to save",
|
|
29
|
+
rethrow: true,
|
|
30
|
+
onSuccess: () => {
|
|
31
|
+
setModalOpen(false);
|
|
32
|
+
setSelectedItem(null);
|
|
33
|
+
onRefresh?.();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
const handleDelete = removeAction.run;
|
|
38
|
+
const handleSave = saveAction.run;
|
|
39
|
+
return {
|
|
40
|
+
selectedItem,
|
|
41
|
+
modalOpen,
|
|
42
|
+
setModalOpen,
|
|
43
|
+
isProcessing: removeAction.isPending,
|
|
44
|
+
handleAdd,
|
|
45
|
+
handleEdit,
|
|
46
|
+
handleDelete,
|
|
47
|
+
handleSave,
|
|
48
|
+
removeAction,
|
|
49
|
+
saveAction
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
useCrudHandlers as default
|
|
54
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
function useFilteredItems(items, searchQuery, filterFn) {
|
|
3
|
+
return useMemo(() => {
|
|
4
|
+
if (!items) return [];
|
|
5
|
+
const searchLower = (searchQuery || "").toLowerCase();
|
|
6
|
+
if (!searchLower) return items;
|
|
7
|
+
return items.filter((item) => {
|
|
8
|
+
if (filterFn) return filterFn(item, searchLower);
|
|
9
|
+
return Object.values(item).some((val) => {
|
|
10
|
+
if (typeof val === "string") return val.toLowerCase().includes(searchLower);
|
|
11
|
+
if (val && typeof val === "object") return JSON.stringify(val).toLowerCase().includes(searchLower);
|
|
12
|
+
return false;
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}, [items, searchQuery, filterFn]);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
useFilteredItems as default
|
|
19
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
const read = (key) => {
|
|
3
|
+
try {
|
|
4
|
+
const stored = JSON.parse(localStorage.getItem(key) || "[]");
|
|
5
|
+
return Array.isArray(stored) ? stored : [];
|
|
6
|
+
} catch {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function useSavedViews(storageKey) {
|
|
11
|
+
const [views, setViews] = useState(() => read(storageKey));
|
|
12
|
+
const persist = useCallback((next) => {
|
|
13
|
+
setViews(next);
|
|
14
|
+
try {
|
|
15
|
+
localStorage.setItem(storageKey, JSON.stringify(next));
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
}, [storageKey]);
|
|
19
|
+
const saveView = useCallback((name, state) => {
|
|
20
|
+
const trimmed = name.trim();
|
|
21
|
+
if (!trimmed) return;
|
|
22
|
+
const others = views.filter((v) => v.name.toLowerCase() !== trimmed.toLowerCase());
|
|
23
|
+
persist([...others, { id: `${Date.now()}`, name: trimmed, state }]);
|
|
24
|
+
}, [views, persist]);
|
|
25
|
+
const deleteView = useCallback((id) => persist(views.filter((v) => v.id !== id)), [views, persist]);
|
|
26
|
+
return { views, saveView, deleteView };
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
useSavedViews as default
|
|
30
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useNavigate } from "react-router-dom";
|
|
3
|
+
import { confirmAction } from "@okjt/ui";
|
|
4
|
+
function useUnsavedChangesGuard(dirty, message = "You have unsaved changes. Leave without saving?") {
|
|
5
|
+
const navigate = useNavigate();
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!dirty) return void 0;
|
|
8
|
+
const onBeforeUnload = (e) => {
|
|
9
|
+
e.preventDefault();
|
|
10
|
+
e.returnValue = "";
|
|
11
|
+
};
|
|
12
|
+
const onClick = async (e) => {
|
|
13
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
14
|
+
const link = e.target.closest?.("a[href]");
|
|
15
|
+
if (!link || link.target === "_blank" || link.hasAttribute("download")) return;
|
|
16
|
+
const url = new URL(link.href, window.location.href);
|
|
17
|
+
if (url.origin !== window.location.origin || url.pathname === window.location.pathname) return;
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
e.stopPropagation();
|
|
20
|
+
if (await confirmAction({ title: "Leave without saving?", message, confirmLabel: "Leave", tone: "danger" })) {
|
|
21
|
+
navigate(url.pathname + url.search + url.hash);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
window.addEventListener("beforeunload", onBeforeUnload);
|
|
25
|
+
document.addEventListener("click", onClick, true);
|
|
26
|
+
return () => {
|
|
27
|
+
window.removeEventListener("beforeunload", onBeforeUnload);
|
|
28
|
+
document.removeEventListener("click", onClick, true);
|
|
29
|
+
};
|
|
30
|
+
}, [dirty, message, navigate]);
|
|
31
|
+
}
|
|
32
|
+
function useUnsavedChanges(value) {
|
|
33
|
+
const [baseline, setBaseline] = useState(null);
|
|
34
|
+
const dirty = baseline !== null && JSON.stringify(value) !== JSON.stringify(baseline);
|
|
35
|
+
useUnsavedChangesGuard(dirty);
|
|
36
|
+
return { dirty, markSaved: setBaseline, baseline };
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
useUnsavedChangesGuard as default,
|
|
40
|
+
useUnsavedChanges
|
|
41
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okjt/dashboard",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Dashboard pages for OKJTech projects: page layout, hero, summary cards, floating toolbar with search and filters, side panel, lists, bulk actions, one way to save, and working together: presence, version history, sharing; the dashboard shell, sign-in pages and account menu",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Juniortambo2628/OKJT.git",
|
|
10
|
+
"directory": "packages/dashboard"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "node build.mjs",
|
|
22
|
+
"prepack": "node build.mjs",
|
|
23
|
+
"test": "node build.mjs && vitest run"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@okjt/ui": "^0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@tanstack/react-query": ">=5",
|
|
30
|
+
"date-fns": ">=3",
|
|
31
|
+
"framer-motion": ">=11",
|
|
32
|
+
"lucide-react": ">=0.400.0",
|
|
33
|
+
"react": ">=18",
|
|
34
|
+
"react-dom": ">=18",
|
|
35
|
+
"react-hook-form": ">=7",
|
|
36
|
+
"react-hot-toast": ">=2",
|
|
37
|
+
"react-router-dom": ">=6.4"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|