@vertebr/react 0.1.1 → 0.3.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/dist/{VertebrAdmin.d.ts → components/admin/VertebrAdmin.d.ts} +3 -1
- package/dist/components/admin/VertebrAdmin.d.ts.map +1 -0
- package/dist/components/admin/VertebrAdmin.js +375 -0
- package/dist/components/config/ConfigForm.d.ts +3 -0
- package/dist/components/config/ConfigForm.d.ts.map +1 -0
- package/dist/components/config/ConfigForm.js +1 -0
- package/dist/components/config/DescriptionInput.d.ts +18 -0
- package/dist/components/config/DescriptionInput.d.ts.map +1 -0
- package/dist/components/config/DescriptionInput.js +152 -0
- package/dist/components/config/ImagePickerModal.d.ts +18 -0
- package/dist/components/config/ImagePickerModal.d.ts.map +1 -0
- package/dist/components/config/ImagePickerModal.js +120 -0
- package/dist/components/config/PriceInput.d.ts +12 -0
- package/dist/components/config/PriceInput.d.ts.map +1 -0
- package/dist/components/config/PriceInput.js +20 -0
- package/dist/components/config/form/ConfigField.d.ts +21 -0
- package/dist/components/config/form/ConfigField.d.ts.map +1 -0
- package/dist/components/config/form/ConfigField.js +48 -0
- package/dist/components/config/form/ConfigForm.d.ts +4 -0
- package/dist/components/config/form/ConfigForm.d.ts.map +1 -0
- package/dist/components/config/form/ConfigForm.js +70 -0
- package/dist/components/config/form/ConfigFormActions.d.ts +10 -0
- package/dist/components/config/form/ConfigFormActions.d.ts.map +1 -0
- package/dist/components/config/form/ConfigFormActions.js +4 -0
- package/dist/components/config/form/RecordConfigForm.d.ts +21 -0
- package/dist/components/config/form/RecordConfigForm.d.ts.map +1 -0
- package/dist/components/config/form/RecordConfigForm.js +37 -0
- package/dist/components/config/form/SettingsConfigForm.d.ts +21 -0
- package/dist/components/config/form/SettingsConfigForm.d.ts.map +1 -0
- package/dist/components/config/form/SettingsConfigForm.js +7 -0
- package/dist/components/config/form/helpers.d.ts +16 -0
- package/dist/components/config/form/helpers.d.ts.map +1 -0
- package/dist/components/config/form/helpers.js +186 -0
- package/dist/components/config/form/types.d.ts +27 -0
- package/dist/components/config/form/types.d.ts.map +1 -0
- package/dist/{EnvSelect.d.ts → components/env/EnvSelect.d.ts} +1 -1
- package/dist/components/env/EnvSelect.d.ts.map +1 -0
- package/dist/components/gallery/GalleryBoard.d.ts +14 -0
- package/dist/components/gallery/GalleryBoard.d.ts.map +1 -0
- package/dist/components/gallery/GalleryBoard.js +14 -0
- package/dist/components/index.d.ts +9 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/{MetricsBoard.d.ts → components/metrics/MetricsBoard.d.ts} +1 -1
- package/dist/components/metrics/MetricsBoard.d.ts.map +1 -0
- package/dist/components/resources/BulkImageUploadModal.d.ts +17 -0
- package/dist/components/resources/BulkImageUploadModal.d.ts.map +1 -0
- package/dist/components/resources/BulkImageUploadModal.js +47 -0
- package/dist/components/resources/ColumnVisibilityMenu.d.ts +11 -0
- package/dist/components/resources/ColumnVisibilityMenu.d.ts.map +1 -0
- package/dist/components/resources/ColumnVisibilityMenu.js +40 -0
- package/dist/components/resources/ImageUploadControl.d.ts +10 -0
- package/dist/components/resources/ImageUploadControl.d.ts.map +1 -0
- package/dist/components/resources/ImageUploadControl.js +50 -0
- package/dist/components/resources/ResourceCell.d.ts +10 -0
- package/dist/components/resources/ResourceCell.d.ts.map +1 -0
- package/dist/components/resources/ResourceCell.js +100 -0
- package/dist/components/resources/ResourceTable.d.ts +34 -0
- package/dist/components/resources/ResourceTable.d.ts.map +1 -0
- package/dist/components/resources/ResourceTable.js +249 -0
- package/dist/components/resources/ResourceViewModal.d.ts +11 -0
- package/dist/components/resources/ResourceViewModal.d.ts.map +1 -0
- package/dist/components/resources/ResourceViewModal.js +44 -0
- package/dist/components/theme/ThemeToggle.d.ts +7 -0
- package/dist/components/theme/ThemeToggle.d.ts.map +1 -0
- package/dist/components/theme/ThemeToggle.js +10 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/{useVertebrControls.d.ts → hooks/useVertebrControls.d.ts} +2 -2
- package/dist/hooks/useVertebrControls.d.ts.map +1 -0
- package/dist/{useVertebrControls.js → hooks/useVertebrControls.js} +11 -21
- package/dist/hooks/useVertebrTheme.d.ts +7 -0
- package/dist/hooks/useVertebrTheme.d.ts.map +1 -0
- package/dist/hooks/useVertebrTheme.js +38 -0
- package/dist/index.d.ts +20 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -6
- package/dist/lib/description.d.ts +18 -0
- package/dist/lib/description.d.ts.map +1 -0
- package/dist/lib/description.js +85 -0
- package/dist/lib/images.d.ts +14 -0
- package/dist/lib/images.d.ts.map +1 -0
- package/dist/lib/images.js +63 -0
- package/dist/lib/price.d.ts +15 -0
- package/dist/lib/price.d.ts.map +1 -0
- package/dist/lib/price.js +50 -0
- package/dist/styles/auth.css +39 -0
- package/dist/styles/base.css +70 -0
- package/dist/styles/buttons.css +86 -0
- package/dist/styles/cells.css +178 -0
- package/dist/styles/columns.css +103 -0
- package/dist/styles/form.css +773 -0
- package/dist/styles/gallery.css +90 -0
- package/dist/styles/index.css +18 -0
- package/dist/styles/main.css +89 -0
- package/dist/styles/modal.css +225 -0
- package/dist/styles/nav.css +92 -0
- package/dist/styles/panel.css +215 -0
- package/dist/styles/select.css +151 -0
- package/dist/styles/sidebar.css +42 -0
- package/dist/styles/states.css +169 -0
- package/dist/styles/table.css +101 -0
- package/dist/styles/theme-toggle.css +87 -0
- package/dist/styles.css +2 -997
- package/dist/themes/dark.css +55 -0
- package/dist/themes/index.css +2 -0
- package/dist/themes/light.css +102 -0
- package/package.json +13 -3
- package/dist/ConfigForm.d.ts +0 -9
- package/dist/ConfigForm.d.ts.map +0 -1
- package/dist/ConfigForm.js +0 -87
- package/dist/EnvSelect.d.ts.map +0 -1
- package/dist/MetricsBoard.d.ts.map +0 -1
- package/dist/ResourceTable.d.ts +0 -23
- package/dist/ResourceTable.d.ts.map +0 -1
- package/dist/ResourceTable.js +0 -112
- package/dist/VertebrAdmin.d.ts.map +0 -1
- package/dist/VertebrAdmin.js +0 -269
- package/dist/client.d.ts +0 -32
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -65
- package/dist/types.d.ts +0 -103
- package/dist/types.d.ts.map +0 -1
- package/dist/useVertebrControls.d.ts.map +0 -1
- /package/dist/{types.js → components/config/form/types.js} +0 -0
- /package/dist/{EnvSelect.js → components/env/EnvSelect.js} +0 -0
- /package/dist/{MetricsBoard.js → components/metrics/MetricsBoard.js} +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FieldSchema, GalleryItem, ResourceActionMeta, ResourceUploadMeta } from "@vertebr/client";
|
|
2
|
+
type ResourcePanelProps = {
|
|
3
|
+
schema: Record<string, FieldSchema>;
|
|
4
|
+
items: Record<string, unknown>[];
|
|
5
|
+
permissions?: {
|
|
6
|
+
create?: boolean;
|
|
7
|
+
update?: boolean;
|
|
8
|
+
delete?: boolean;
|
|
9
|
+
};
|
|
10
|
+
actions?: Record<string, ResourceActionMeta>;
|
|
11
|
+
uploads?: Record<string, ResourceUploadMeta>;
|
|
12
|
+
rowIdKeys?: string[];
|
|
13
|
+
/** Persist column visibility under this key (e.g. resource id). */
|
|
14
|
+
storageKey?: string;
|
|
15
|
+
onUpdate?: (rowId: string, value: Record<string, unknown>) => Promise<void>;
|
|
16
|
+
onCreate?: (value: Record<string, unknown>) => Promise<void>;
|
|
17
|
+
onDelete?: (rowId: string) => Promise<void>;
|
|
18
|
+
onAction?: (rowId: string, actionId: string) => Promise<void>;
|
|
19
|
+
onUpload?: (field: string, files: File[]) => Promise<Array<{
|
|
20
|
+
url: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
}>>;
|
|
23
|
+
galleryUpload?: Pick<ResourceUploadMeta, "accept" | "maxBytes">;
|
|
24
|
+
onListGallery?: () => Promise<GalleryItem[]>;
|
|
25
|
+
onUploadGallery?: (files: File[]) => Promise<GalleryItem[]>;
|
|
26
|
+
};
|
|
27
|
+
export declare function ResourcePanel({ schema, items, permissions, actions, uploads, rowIdKeys, storageKey, onUpdate, onCreate, onDelete, onAction, onUpload, galleryUpload, onListGallery, onUploadGallery, }: ResourcePanelProps): import("react").JSX.Element;
|
|
28
|
+
/** @deprecated Prefer ResourcePanel */
|
|
29
|
+
export declare function ResourceTable(props: {
|
|
30
|
+
schema: Record<string, FieldSchema>;
|
|
31
|
+
items: Record<string, unknown>[];
|
|
32
|
+
}): import("react").JSX.Element;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=ResourceTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceTable.d.ts","sourceRoot":"","sources":["../../../src/components/resources/ResourceTable.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAMzB,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE;QACZ,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC7C,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,IAAI,EAAE,KACV,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IACpD,aAAa,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,QAAQ,GAAG,UAAU,CAAC,CAAC;IAChE,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7C,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CAC7D,CAAC;AA+DF,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,WAAW,EACX,OAAY,EACZ,OAAO,EACP,SAA0C,EAC1C,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,GAChB,EAAE,kBAAkB,+BA+ZpB;AAED,uCAAuC;AACvC,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CAClC,+BAEA"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { flexRender, getCoreRowModel, useReactTable, } from "@tanstack/react-table";
|
|
4
|
+
import { ConfigForm } from "../config/ConfigForm";
|
|
5
|
+
import { BulkImageUploadModal } from "./BulkImageUploadModal";
|
|
6
|
+
import { ColumnVisibilityMenu } from "./ColumnVisibilityMenu";
|
|
7
|
+
import { ResourceCell } from "./ResourceCell";
|
|
8
|
+
import { ResourceViewModal } from "./ResourceViewModal";
|
|
9
|
+
function resolveRowId(row, keys) {
|
|
10
|
+
for (const key of keys) {
|
|
11
|
+
const value = row[key];
|
|
12
|
+
if (typeof value === "string" && value.trim())
|
|
13
|
+
return value;
|
|
14
|
+
if (typeof value === "number")
|
|
15
|
+
return String(value);
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function humanizeKey(key) {
|
|
20
|
+
return key
|
|
21
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
22
|
+
.replace(/[_-]+/g, " ")
|
|
23
|
+
.replace(/\bcents\b/i, "")
|
|
24
|
+
.trim();
|
|
25
|
+
}
|
|
26
|
+
function rowTitle(row, keys) {
|
|
27
|
+
for (const key of ["name", "title", "label", ...keys]) {
|
|
28
|
+
const value = row[key];
|
|
29
|
+
if (typeof value === "string" && value.trim())
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
return "Record";
|
|
33
|
+
}
|
|
34
|
+
function readVisibility(storageKey) {
|
|
35
|
+
if (!storageKey || typeof localStorage === "undefined")
|
|
36
|
+
return {};
|
|
37
|
+
try {
|
|
38
|
+
const raw = localStorage.getItem(`vertebr:columns:${storageKey}`);
|
|
39
|
+
if (!raw)
|
|
40
|
+
return {};
|
|
41
|
+
const parsed = JSON.parse(raw);
|
|
42
|
+
if (!parsed || typeof parsed !== "object")
|
|
43
|
+
return {};
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function writeVisibility(storageKey, value) {
|
|
51
|
+
if (!storageKey || typeof localStorage === "undefined")
|
|
52
|
+
return;
|
|
53
|
+
try {
|
|
54
|
+
localStorage.setItem(`vertebr:columns:${storageKey}`, JSON.stringify(value));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
/* ignore quota / private mode */
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function titleFromFilename(name) {
|
|
61
|
+
return name
|
|
62
|
+
.replace(/\.[^.]+$/, "")
|
|
63
|
+
.replace(/[_-]+/g, " ")
|
|
64
|
+
.replace(/\s+/g, " ")
|
|
65
|
+
.trim();
|
|
66
|
+
}
|
|
67
|
+
export function ResourcePanel({ schema, items, permissions, actions = {}, uploads, rowIdKeys = ["id", "slug", "uid", "email"], storageKey, onUpdate, onCreate, onDelete, onAction, onUpload, galleryUpload, onListGallery, onUploadGallery, }) {
|
|
68
|
+
const [editing, setEditing] = useState(null);
|
|
69
|
+
const [viewing, setViewing] = useState(null);
|
|
70
|
+
const [bulkOpen, setBulkOpen] = useState(false);
|
|
71
|
+
const [busyAction, setBusyAction] = useState(null);
|
|
72
|
+
const tableWrapRef = useRef(null);
|
|
73
|
+
const [tableOverflow, setTableOverflow] = useState({
|
|
74
|
+
overflow: false,
|
|
75
|
+
canLeft: false,
|
|
76
|
+
canRight: false,
|
|
77
|
+
});
|
|
78
|
+
const [columnVisibility, setColumnVisibility] = useState(() => readVisibility(storageKey));
|
|
79
|
+
const canUpdate = Boolean(permissions?.update && onUpdate);
|
|
80
|
+
const canCreate = Boolean(permissions?.create && onCreate);
|
|
81
|
+
const canDelete = Boolean(permissions?.delete && onDelete);
|
|
82
|
+
const canUpload = Boolean(uploads && onUpload && Object.keys(uploads).length);
|
|
83
|
+
const actionEntries = Object.entries(actions);
|
|
84
|
+
const fieldKeys = Object.keys(schema);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
setColumnVisibility(readVisibility(storageKey));
|
|
87
|
+
}, [storageKey]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
writeVisibility(storageKey, columnVisibility);
|
|
90
|
+
}, [storageKey, columnVisibility]);
|
|
91
|
+
const updateTableOverflow = useCallback(() => {
|
|
92
|
+
const el = tableWrapRef.current;
|
|
93
|
+
if (!el) {
|
|
94
|
+
setTableOverflow({ overflow: false, canLeft: false, canRight: false });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const overflow = el.scrollWidth > el.clientWidth + 2;
|
|
98
|
+
setTableOverflow({
|
|
99
|
+
overflow,
|
|
100
|
+
canLeft: overflow && el.scrollLeft > 2,
|
|
101
|
+
canRight: overflow && el.scrollLeft + el.clientWidth < el.scrollWidth - 2,
|
|
102
|
+
});
|
|
103
|
+
}, []);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
const el = tableWrapRef.current;
|
|
106
|
+
if (!el)
|
|
107
|
+
return;
|
|
108
|
+
updateTableOverflow();
|
|
109
|
+
const onScroll = () => updateTableOverflow();
|
|
110
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
111
|
+
const observer = new ResizeObserver(updateTableOverflow);
|
|
112
|
+
observer.observe(el);
|
|
113
|
+
return () => {
|
|
114
|
+
el.removeEventListener("scroll", onScroll);
|
|
115
|
+
observer.disconnect();
|
|
116
|
+
};
|
|
117
|
+
}, [updateTableOverflow, items.length, columnVisibility]);
|
|
118
|
+
const scrollTable = (direction) => {
|
|
119
|
+
const el = tableWrapRef.current;
|
|
120
|
+
if (!el)
|
|
121
|
+
return;
|
|
122
|
+
const amount = Math.max(220, Math.round(el.clientWidth * 0.55));
|
|
123
|
+
el.scrollBy({
|
|
124
|
+
left: direction === "left" ? -amount : amount,
|
|
125
|
+
behavior: "smooth",
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const columnOptions = useMemo(() => fieldKeys.map((key) => ({
|
|
129
|
+
id: key,
|
|
130
|
+
label: schema[key]?.label ?? humanizeKey(key),
|
|
131
|
+
})), [fieldKeys, schema]);
|
|
132
|
+
const columns = useMemo(() => {
|
|
133
|
+
const defs = fieldKeys.length === 0
|
|
134
|
+
? [
|
|
135
|
+
{
|
|
136
|
+
id: "raw",
|
|
137
|
+
header: "Item",
|
|
138
|
+
cell: ({ row }) => (_jsx(ResourceCell, { fieldKey: "raw", value: row.original })),
|
|
139
|
+
},
|
|
140
|
+
]
|
|
141
|
+
: fieldKeys.map((key) => {
|
|
142
|
+
const field = schema[key];
|
|
143
|
+
const isImage = /(image|img|photo|avatar|thumbnail|thumb|cover)/i.test(key) ||
|
|
144
|
+
/(image|img|photo)/i.test(field?.label ?? "");
|
|
145
|
+
return {
|
|
146
|
+
id: key,
|
|
147
|
+
accessorKey: key,
|
|
148
|
+
header: field?.label ?? humanizeKey(key),
|
|
149
|
+
meta: { fieldKey: key, field },
|
|
150
|
+
cell: ({ getValue }) => (_jsx(ResourceCell, { fieldKey: key, field: field, value: getValue() })),
|
|
151
|
+
size: isImage ? 220 : undefined,
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
defs.push({
|
|
155
|
+
id: "_actions",
|
|
156
|
+
header: () => _jsx("span", { className: "vertebr-sr-only", children: "Actions" }),
|
|
157
|
+
enableHiding: false,
|
|
158
|
+
cell: ({ row }) => {
|
|
159
|
+
const rowId = resolveRowId(row.original, rowIdKeys);
|
|
160
|
+
return (_jsxs("div", { className: "vertebr-row-actions", onClick: (event) => event.stopPropagation(), onKeyDown: (event) => event.stopPropagation(), children: [_jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet", onClick: () => setViewing(row.original), children: "View" }), canUpdate ? (_jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet", onClick: () => setEditing(row.original), children: "Edit" })) : null, rowId
|
|
161
|
+
? actionEntries.map(([actionId, meta]) => (_jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet", disabled: busyAction === `${rowId}:${actionId}`, onClick: () => {
|
|
162
|
+
if (!onAction)
|
|
163
|
+
return;
|
|
164
|
+
setBusyAction(`${rowId}:${actionId}`);
|
|
165
|
+
void onAction(rowId, actionId).finally(() => setBusyAction(null));
|
|
166
|
+
}, children: meta.label }, actionId)))
|
|
167
|
+
: null, canDelete && rowId ? (_jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet vertebr-btn-danger-quiet", onClick: () => {
|
|
168
|
+
if (window.confirm("Delete this row? This cannot be undone.")) {
|
|
169
|
+
void onDelete?.(rowId);
|
|
170
|
+
}
|
|
171
|
+
}, children: "Delete" })) : null] }));
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
return defs;
|
|
175
|
+
}, [
|
|
176
|
+
schema,
|
|
177
|
+
fieldKeys,
|
|
178
|
+
canUpdate,
|
|
179
|
+
canDelete,
|
|
180
|
+
actionEntries,
|
|
181
|
+
busyAction,
|
|
182
|
+
onAction,
|
|
183
|
+
onDelete,
|
|
184
|
+
rowIdKeys,
|
|
185
|
+
]);
|
|
186
|
+
const table = useReactTable({
|
|
187
|
+
data: items,
|
|
188
|
+
columns,
|
|
189
|
+
state: { columnVisibility },
|
|
190
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
191
|
+
getCoreRowModel: getCoreRowModel(),
|
|
192
|
+
});
|
|
193
|
+
const editingId = editing ? resolveRowId(editing, rowIdKeys) : null;
|
|
194
|
+
if (editing && editingId && onUpdate) {
|
|
195
|
+
const editableSchema = Object.fromEntries(Object.entries(schema).filter(([, field]) => !field.readOnly));
|
|
196
|
+
const title = rowTitle(editing, rowIdKeys);
|
|
197
|
+
return (_jsxs("div", { className: "vertebr-resource-edit", children: [_jsxs("div", { className: "vertebr-resource-edit-head", children: [_jsxs("div", { className: "vertebr-resource-edit-heading", children: [_jsx("p", { className: "vertebr-resource-edit-eyebrow", children: "Editing record" }), _jsx("h2", { children: title }), _jsx("p", { className: "vertebr-resource-edit-id", children: editingId })] }), _jsx("button", { type: "button", className: "vertebr-btn", onClick: () => setEditing(null), children: "Back" })] }), _jsx(ConfigForm, { variant: "record", schema: editableSchema, value: editing, uploads: uploads, onUpload: onUpload, galleryUpload: galleryUpload, onListGallery: onListGallery, onUploadGallery: onUploadGallery, onSave: async (next) => {
|
|
198
|
+
await onUpdate(editingId, next);
|
|
199
|
+
setEditing(null);
|
|
200
|
+
} })] }));
|
|
201
|
+
}
|
|
202
|
+
const toolbar = (_jsxs("div", { className: "vertebr-table-toolbar", children: [_jsxs("div", { className: "vertebr-table-toolbar-start", children: [columnOptions.length > 0 ? (_jsx(ColumnVisibilityMenu, { columns: columnOptions, visibility: columnVisibility, onChange: setColumnVisibility })) : null, canUpload ? (_jsxs("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet vertebr-btn-icon", onClick: () => setBulkOpen(true), children: [_jsx(ImageUploadIcon, {}), "Bulk upload"] })) : null] }), tableOverflow.overflow ? (_jsxs("div", { className: "vertebr-table-scroll-controls", role: "group", "aria-label": "Scroll columns", children: [_jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet vertebr-btn-icon vertebr-table-scroll-btn", disabled: !tableOverflow.canLeft, onClick: () => scrollTable("left"), "aria-label": "Scroll columns left", children: _jsx(ChevronLeftIcon, {}) }), _jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet vertebr-btn-icon vertebr-table-scroll-btn", disabled: !tableOverflow.canRight, onClick: () => scrollTable("right"), "aria-label": "Scroll columns right", children: _jsx(ChevronRightIcon, {}) })] })) : null] }));
|
|
203
|
+
const bulkModal = bulkOpen && uploads && onUpload ? (_jsx(BulkImageUploadModal, { uploads: uploads, canCreate: canCreate, fieldLabels: Object.fromEntries(Object.keys(uploads).map((key) => [
|
|
204
|
+
key,
|
|
205
|
+
schema[key]?.label ?? humanizeKey(key),
|
|
206
|
+
])), onClose: () => setBulkOpen(false), onUpload: onUpload, onCreateFromUploads: canCreate && onCreate
|
|
207
|
+
? async (field, files) => {
|
|
208
|
+
for (const file of files) {
|
|
209
|
+
const name = titleFromFilename(file.name ?? "Image");
|
|
210
|
+
await onCreate({
|
|
211
|
+
[field]: file.url,
|
|
212
|
+
name,
|
|
213
|
+
title: name,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
: undefined })) : null;
|
|
218
|
+
if (items.length === 0) {
|
|
219
|
+
return (_jsxs("div", { className: "vertebr-resource-body", children: [_jsxs("div", { className: "vertebr-panel-head", children: [_jsx("h2", { children: "Records" }), _jsx("span", { className: "vertebr-count", children: "0" })] }), canUpload || columnOptions.length > 0 ? toolbar : null, _jsx("div", { className: "vertebr-empty", children: "No rows yet." }), bulkModal] }));
|
|
220
|
+
}
|
|
221
|
+
return (_jsxs("div", { className: "vertebr-resource-body", children: [_jsxs("div", { className: "vertebr-panel-head", children: [_jsx("h2", { children: "Records" }), _jsx("span", { className: "vertebr-count", children: items.length })] }), toolbar, _jsx("div", { className: "vertebr-table-wrap", ref: tableWrapRef, "data-overflow": tableOverflow.overflow ? "true" : undefined, "data-overflow-left": tableOverflow.canLeft ? "true" : undefined, "data-overflow-right": tableOverflow.canRight ? "true" : undefined, children: _jsxs("table", { className: "vertebr-table", children: [_jsx("thead", { children: table.getHeaderGroups().map((headerGroup) => (_jsx("tr", { children: headerGroup.headers.map((header) => (_jsx("th", { className: header.column.id === "_actions"
|
|
222
|
+
? "vertebr-col-actions"
|
|
223
|
+
: undefined, children: header.isPlaceholder
|
|
224
|
+
? null
|
|
225
|
+
: flexRender(header.column.columnDef.header, header.getContext()) }, header.id))) }, headerGroup.id))) }), _jsx("tbody", { children: table.getRowModel().rows.map((row) => (_jsx("tr", { className: "vertebr-table-row-clickable", tabIndex: 0, onClick: () => setViewing(row.original), onKeyDown: (event) => {
|
|
226
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
227
|
+
event.preventDefault();
|
|
228
|
+
setViewing(row.original);
|
|
229
|
+
}
|
|
230
|
+
}, children: row.getVisibleCells().map((cell) => (_jsx("td", { className: cell.column.id === "_actions"
|
|
231
|
+
? "vertebr-col-actions"
|
|
232
|
+
: undefined, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))) }, row.id))) })] }) }), viewing ? (_jsx(ResourceViewModal, { schema: schema, row: viewing, title: rowTitle(viewing, rowIdKeys), canEdit: canUpdate, onClose: () => setViewing(null), onEdit: () => {
|
|
233
|
+
setEditing(viewing);
|
|
234
|
+
setViewing(null);
|
|
235
|
+
} })) : null, bulkModal] }));
|
|
236
|
+
}
|
|
237
|
+
/** @deprecated Prefer ResourcePanel */
|
|
238
|
+
export function ResourceTable(props) {
|
|
239
|
+
return _jsx(ResourcePanel, { ...props });
|
|
240
|
+
}
|
|
241
|
+
function ChevronLeftIcon() {
|
|
242
|
+
return (_jsx("svg", { className: "vertebr-btn-glyph", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m15 18-6-6 6-6" }) }));
|
|
243
|
+
}
|
|
244
|
+
function ChevronRightIcon() {
|
|
245
|
+
return (_jsx("svg", { className: "vertebr-btn-glyph", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m9 18 6-6-6-6" }) }));
|
|
246
|
+
}
|
|
247
|
+
function ImageUploadIcon() {
|
|
248
|
+
return (_jsxs("svg", { className: "vertebr-btn-glyph", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M16 5h6" }), _jsx("path", { d: "M19 2v6" }), _jsx("rect", { x: "3", y: "7", width: "14", height: "14", rx: "2" }), _jsx("circle", { cx: "8.5", cy: "12.5", r: "1.5" }), _jsx("path", { d: "m17 21-4.5-4.5L7 21" })] }));
|
|
249
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FieldSchema } from "@vertebr/client";
|
|
2
|
+
export type ResourceViewModalProps = {
|
|
3
|
+
schema: Record<string, FieldSchema>;
|
|
4
|
+
row: Record<string, unknown>;
|
|
5
|
+
title: string;
|
|
6
|
+
canEdit?: boolean;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
onEdit?: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function ResourceViewModal({ schema, row, title, canEdit, onClose, onEdit, }: ResourceViewModalProps): import("react").JSX.Element;
|
|
11
|
+
//# sourceMappingURL=ResourceViewModal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceViewModal.d.ts","sourceRoot":"","sources":["../../../src/components/resources/ResourceViewModal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AA4BF,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,GAAG,EACH,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,GACP,EAAE,sBAAsB,+BAsFxB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { ResourceCell } from "./ResourceCell";
|
|
4
|
+
function humanizeKey(key) {
|
|
5
|
+
return key
|
|
6
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
7
|
+
.replace(/[_-]+/g, " ")
|
|
8
|
+
.replace(/\bcents\b/i, "")
|
|
9
|
+
.trim();
|
|
10
|
+
}
|
|
11
|
+
function findHeroImage(schema, row) {
|
|
12
|
+
for (const [key, value] of Object.entries(row)) {
|
|
13
|
+
if (typeof value !== "string" || !/^https?:\/\//i.test(value))
|
|
14
|
+
continue;
|
|
15
|
+
const field = schema[key];
|
|
16
|
+
if (/(image|img|photo|avatar|thumbnail|thumb|cover)/i.test(key) ||
|
|
17
|
+
/(image|img|photo)/i.test(field?.label ?? "") ||
|
|
18
|
+
/(image|img|media|cdn|photo)/i.test(value)) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
export function ResourceViewModal({ schema, row, title, canEdit, onClose, onEdit, }) {
|
|
25
|
+
const fields = Object.keys(schema);
|
|
26
|
+
const entries = fields.length > 0
|
|
27
|
+
? fields.map((key) => [key, row[key]])
|
|
28
|
+
: Object.entries(row);
|
|
29
|
+
const hero = findHeroImage(schema, row);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const onKeyDown = (event) => {
|
|
32
|
+
if (event.key === "Escape")
|
|
33
|
+
onClose();
|
|
34
|
+
};
|
|
35
|
+
window.addEventListener("keydown", onKeyDown);
|
|
36
|
+
const previous = document.body.style.overflow;
|
|
37
|
+
document.body.style.overflow = "hidden";
|
|
38
|
+
return () => {
|
|
39
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
40
|
+
document.body.style.overflow = previous;
|
|
41
|
+
};
|
|
42
|
+
}, [onClose]);
|
|
43
|
+
return (_jsx("div", { className: "vertebr-modal-backdrop", role: "presentation", onClick: onClose, children: _jsxs("div", { className: "vertebr-modal", role: "dialog", "aria-modal": "true", "aria-label": title, onClick: (event) => event.stopPropagation(), children: [_jsxs("header", { className: "vertebr-modal-head", children: [_jsxs("div", { className: "vertebr-modal-heading", children: [_jsx("p", { className: "vertebr-modal-eyebrow", children: "Record" }), _jsx("h2", { children: title })] }), _jsxs("div", { className: "vertebr-modal-actions", children: [canEdit && onEdit ? (_jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-primary", onClick: onEdit, children: "Edit" })) : null, _jsx("button", { type: "button", className: "vertebr-btn", onClick: onClose, "aria-label": "Close", children: "Close" })] })] }), _jsxs("div", { className: "vertebr-modal-body", children: [hero ? (_jsx("div", { className: "vertebr-modal-hero", children: _jsx("img", { src: hero, alt: "" }) })) : null, _jsx("dl", { className: "vertebr-modal-fields", children: entries.map(([key, value]) => (_jsxs("div", { className: "vertebr-modal-field", children: [_jsx("dt", { children: schema[key]?.label ?? humanizeKey(key) }), _jsx("dd", { children: _jsx(ResourceCell, { fieldKey: key, field: schema[key], value: value, variant: "detail" }) })] }, key))) })] })] }) }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VbTheme } from "../../hooks/useVertebrTheme";
|
|
2
|
+
export type ThemeToggleProps = {
|
|
3
|
+
theme: VbTheme;
|
|
4
|
+
onChange: (theme: VbTheme) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function ThemeToggle({ theme, onChange }: ThemeToggleProps): import("react").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=ThemeToggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeToggle.d.ts","sourceRoot":"","sources":["../../../src/components/theme/ThemeToggle.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAE3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,gBAAgB,+BAgChE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function ThemeToggle({ theme, onChange }) {
|
|
3
|
+
return (_jsxs("div", { className: "vertebr-theme", children: [_jsx("div", { className: "vertebr-nav-label", children: "Appearance" }), _jsxs("div", { className: "vertebr-theme-toggle", role: "group", "aria-label": "Color theme", children: [_jsxs("button", { type: "button", className: "vertebr-theme-option", "data-active": theme === "light", "aria-pressed": theme === "light", onClick: () => onChange("light"), children: [_jsx(ThemeSunIcon, {}), "Light"] }), _jsxs("button", { type: "button", className: "vertebr-theme-option", "data-active": theme === "dark", "aria-pressed": theme === "dark", onClick: () => onChange("dark"), children: [_jsx(ThemeMoonIcon, {}), "Dark"] })] })] }));
|
|
4
|
+
}
|
|
5
|
+
function ThemeSunIcon() {
|
|
6
|
+
return (_jsxs("svg", { className: "vertebr-theme-icon", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "4" }), _jsx("path", { d: "M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41" })] }));
|
|
7
|
+
}
|
|
8
|
+
function ThemeMoonIcon() {
|
|
9
|
+
return (_jsx("svg", { className: "vertebr-theme-icon", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "M21 14.5A8.5 8.5 0 0 1 9.5 3 7 7 0 1 0 21 14.5z" }) }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useVertebrTheme } from "./useVertebrTheme";
|
|
2
|
+
export type { VbTheme } from "./useVertebrTheme";
|
|
3
|
+
export { VertebrControlsProvider, useVertebrConfig, useVertebrControls, } from "./useVertebrControls";
|
|
4
|
+
export type { VertebrControlsProviderProps } from "./useVertebrControls";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
|
|
2
|
+
import { type VertebrControlsMap } from "@vertebr/client";
|
|
3
3
|
type ControlsContextValue = {
|
|
4
4
|
environment: string;
|
|
5
5
|
controls: VertebrControlsMap;
|
|
@@ -14,6 +14,7 @@ export type VertebrControlsProviderProps = {
|
|
|
14
14
|
environment: string;
|
|
15
15
|
children: ReactNode;
|
|
16
16
|
};
|
|
17
|
+
export type { VertebrControlsMap };
|
|
17
18
|
/**
|
|
18
19
|
* Loads all public Vertebr controls for the storefront once and shares them.
|
|
19
20
|
*/
|
|
@@ -30,5 +31,4 @@ export declare function useVertebrConfig<T extends Record<string, unknown>>(id:
|
|
|
30
31
|
};
|
|
31
32
|
/** Access the full public controls map (for gates like comingSoon). */
|
|
32
33
|
export declare function useVertebrControls(): ControlsContextValue;
|
|
33
|
-
export {};
|
|
34
34
|
//# sourceMappingURL=useVertebrControls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVertebrControls.d.ts","sourceRoot":"","sources":["../../src/hooks/useVertebrControls.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAAuB,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE/E,KAAK,oBAAoB,GAAG;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAIF,MAAM,MAAM,4BAA4B,GAAG;IACzC,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAEnC;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,OAAsB,EACtB,WAAW,EACX,QAAQ,GACT,EAAE,4BAA4B,+BAyC9B;AAYD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,GACV;IACD,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAMA;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,IAAI,oBAAoB,CAEzD"}
|
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { createVertebrClient } from "@vertebr/client";
|
|
4
4
|
const ControlsContext = createContext(null);
|
|
5
|
-
async function fetchPublicControls(apiBase, environment) {
|
|
6
|
-
const base = apiBase.replace(/\/$/, "");
|
|
7
|
-
const response = await fetch(`${base}/public/controls`, {
|
|
8
|
-
headers: {
|
|
9
|
-
Accept: "application/json",
|
|
10
|
-
[VERTEBR_ENV_HEADER]: environment,
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
if (!response.ok) {
|
|
14
|
-
const text = await response.text();
|
|
15
|
-
throw new Error(text || `Failed to load controls (${response.status})`);
|
|
16
|
-
}
|
|
17
|
-
const body = (await response.json());
|
|
18
|
-
return body.configs ?? {};
|
|
19
|
-
}
|
|
20
5
|
/**
|
|
21
6
|
* Loads all public Vertebr controls for the storefront once and shares them.
|
|
22
7
|
*/
|
|
@@ -24,11 +9,15 @@ export function VertebrControlsProvider({ apiBase = "/admin/api", environment, c
|
|
|
24
9
|
const [controls, setControls] = useState({});
|
|
25
10
|
const [loading, setLoading] = useState(true);
|
|
26
11
|
const [error, setError] = useState(null);
|
|
27
|
-
const
|
|
12
|
+
const client = useMemo(() => createVertebrClient({
|
|
13
|
+
apiBase,
|
|
14
|
+
getEnvironment: () => environment,
|
|
15
|
+
}), [apiBase, environment]);
|
|
16
|
+
const load = useCallback(async (opts) => {
|
|
28
17
|
setLoading(true);
|
|
29
18
|
setError(null);
|
|
30
19
|
try {
|
|
31
|
-
const next = await
|
|
20
|
+
const next = await client.getPublicControls(opts);
|
|
32
21
|
setControls(next);
|
|
33
22
|
}
|
|
34
23
|
catch (err) {
|
|
@@ -37,10 +26,11 @@ export function VertebrControlsProvider({ apiBase = "/admin/api", environment, c
|
|
|
37
26
|
finally {
|
|
38
27
|
setLoading(false);
|
|
39
28
|
}
|
|
40
|
-
}, [
|
|
29
|
+
}, [client]);
|
|
30
|
+
const refresh = useCallback(() => load({ fresh: true }), [load]);
|
|
41
31
|
useEffect(() => {
|
|
42
|
-
void
|
|
43
|
-
}, [
|
|
32
|
+
void load();
|
|
33
|
+
}, [load]);
|
|
44
34
|
const value = useMemo(() => ({ environment, controls, loading, error, refresh }), [environment, controls, loading, error, refresh]);
|
|
45
35
|
return (_jsx(ControlsContext.Provider, { value: value, children: children }));
|
|
46
36
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVertebrTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useVertebrTheme.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AA0BvC,wBAAgB,eAAe,CAAC,UAAU,SAAsB;;qBAU1B,OAAO;;EAS5C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
const DEFAULT_STORAGE_KEY = "vertebr:theme";
|
|
3
|
+
function readStoredTheme(key) {
|
|
4
|
+
try {
|
|
5
|
+
const value = localStorage.getItem(key);
|
|
6
|
+
if (value === "light" || value === "dark")
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
// ignore
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
function writeStoredTheme(key, theme) {
|
|
15
|
+
try {
|
|
16
|
+
localStorage.setItem(key, theme);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// ignore
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function applyTheme(theme) {
|
|
23
|
+
document.documentElement.setAttribute("data-vb-theme", theme);
|
|
24
|
+
}
|
|
25
|
+
export function useVertebrTheme(storageKey = DEFAULT_STORAGE_KEY) {
|
|
26
|
+
const [theme, setThemeState] = useState(() => readStoredTheme(storageKey) ?? "dark");
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
applyTheme(theme);
|
|
29
|
+
writeStoredTheme(storageKey, theme);
|
|
30
|
+
}, [theme, storageKey]);
|
|
31
|
+
const setTheme = useCallback((next) => {
|
|
32
|
+
setThemeState(next);
|
|
33
|
+
}, []);
|
|
34
|
+
const toggleTheme = useCallback(() => {
|
|
35
|
+
setThemeState((current) => (current === "dark" ? "light" : "dark"));
|
|
36
|
+
}, []);
|
|
37
|
+
return { theme, setTheme, toggleTheme };
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
export { VertebrAdmin } from "./VertebrAdmin";
|
|
2
|
-
export type { VertebrAdminProps } from "./VertebrAdmin";
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export {
|
|
1
|
+
export { VertebrAdmin } from "./components/admin/VertebrAdmin";
|
|
2
|
+
export type { VertebrAdminProps } from "./components/admin/VertebrAdmin";
|
|
3
|
+
export { MetricsBoard } from "./components/metrics/MetricsBoard";
|
|
4
|
+
export { GalleryBoard } from "./components/gallery/GalleryBoard";
|
|
5
|
+
export { ResourcePanel, ResourceTable } from "./components/resources/ResourceTable";
|
|
6
|
+
export { ThemeToggle } from "./components/theme/ThemeToggle";
|
|
7
|
+
export type { ThemeToggleProps } from "./components/theme/ThemeToggle";
|
|
8
|
+
export { ConfigForm } from "./components/config/ConfigForm";
|
|
9
|
+
export { formatPrice, formatPriceInput, parsePriceInput, isCentsField, isPriceField, } from "./lib/price";
|
|
10
|
+
export { isDescriptionField, descriptionStats, applyMarkdown, } from "./lib/description";
|
|
11
|
+
export type { MarkdownCommand, MarkdownEdit } from "./lib/description";
|
|
12
|
+
export { EnvSelect } from "./components/env/EnvSelect";
|
|
13
|
+
export { useVertebrTheme } from "./hooks/useVertebrTheme";
|
|
14
|
+
export type { VbTheme } from "./hooks/useVertebrTheme";
|
|
15
|
+
export { VertebrControlsProvider, useVertebrConfig, useVertebrControls, } from "./hooks/useVertebrControls";
|
|
16
|
+
export type { VertebrControlsProviderProps } from "./hooks/useVertebrControls";
|
|
17
|
+
export { createVertebrClient, VERTEBR_ENV_HEADER, renderMarkdown, } from "@vertebr/client";
|
|
18
|
+
export { VertebrMarkdown } from "@vertebr/client/react";
|
|
19
|
+
export type { VertebrMarkdownProps } from "@vertebr/client/react";
|
|
20
|
+
export type { VertebrClient, VertebrClientOptions, VertebrReadOptions, AdminEnvironment, BootstrapResponse, CatalogResponse, CatalogResource, CatalogConfig, CatalogConfigSection, EnvironmentAuthPublic, FieldSchema, FieldType, GalleryItem, GalleryMeta, GalleryResponse, MetricCard, MetricsResponse, ResourceListResponse, ResourceActionMeta, ResourceUploadMeta, ResourceUploadResponse, ResourceBulkUploadResponse, ConfigResponse, VertebrControlsMap, } from "@vertebr/client";
|
|
11
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,YAAY,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,YAAY,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAG/E,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACX,eAAe,EACf,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,cAAc,EACd,kBAAkB,GACnB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
export { VertebrAdmin } from "./VertebrAdmin";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { ResourcePanel, ResourceTable } from "./ResourceTable";
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
1
|
+
export { VertebrAdmin } from "./components/admin/VertebrAdmin";
|
|
2
|
+
export { MetricsBoard } from "./components/metrics/MetricsBoard";
|
|
3
|
+
export { GalleryBoard } from "./components/gallery/GalleryBoard";
|
|
4
|
+
export { ResourcePanel, ResourceTable } from "./components/resources/ResourceTable";
|
|
5
|
+
export { ThemeToggle } from "./components/theme/ThemeToggle";
|
|
6
|
+
export { ConfigForm } from "./components/config/ConfigForm";
|
|
7
|
+
export { formatPrice, formatPriceInput, parsePriceInput, isCentsField, isPriceField, } from "./lib/price";
|
|
8
|
+
export { isDescriptionField, descriptionStats, applyMarkdown, } from "./lib/description";
|
|
9
|
+
export { EnvSelect } from "./components/env/EnvSelect";
|
|
10
|
+
export { useVertebrTheme } from "./hooks/useVertebrTheme";
|
|
11
|
+
export { VertebrControlsProvider, useVertebrConfig, useVertebrControls, } from "./hooks/useVertebrControls";
|
|
12
|
+
// Re-export the framework-agnostic client for convenience.
|
|
13
|
+
export { createVertebrClient, VERTEBR_ENV_HEADER, renderMarkdown, } from "@vertebr/client";
|
|
14
|
+
export { VertebrMarkdown } from "@vertebr/client/react";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FieldSchema } from "@vertebr/client";
|
|
2
|
+
export declare function isDescriptionField(key: string, field?: Pick<FieldSchema, "label" | "type">): boolean;
|
|
3
|
+
export declare function descriptionStats(value: unknown): {
|
|
4
|
+
characters: number;
|
|
5
|
+
words: number;
|
|
6
|
+
};
|
|
7
|
+
export type MarkdownCommand = "bold" | "italic" | "heading" | "ul" | "ol" | "link";
|
|
8
|
+
export type MarkdownEdit = {
|
|
9
|
+
next: string;
|
|
10
|
+
inserted: string;
|
|
11
|
+
replaceStart: number;
|
|
12
|
+
replaceEnd: number;
|
|
13
|
+
selectionStart: number;
|
|
14
|
+
selectionEnd: number;
|
|
15
|
+
};
|
|
16
|
+
/** Apply a markdown format command around the current selection. */
|
|
17
|
+
export declare function applyMarkdown(text: string, start: number, end: number, command: MarkdownCommand): MarkdownEdit;
|
|
18
|
+
//# sourceMappingURL=description.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"description.d.ts","sourceRoot":"","sources":["../../src/lib/description.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,CAAC,GAC1C,OAAO,CAIT;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,CAOA;AAED,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,QAAQ,GACR,SAAS,GACT,IAAI,GACJ,IAAI,GACJ,MAAM,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AA8CF,oEAAoE;AACpE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,eAAe,GACvB,YAAY,CAsCd"}
|