admin-lib-cms 1.2.4 → 1.2.5
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/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +95 -37
- package/dist/index.mjs +95 -37
- package/dist/storage/firebase.d.mts +32 -0
- package/dist/storage/firebase.d.ts +32 -0
- package/dist/storage/firebase.js +185 -0
- package/dist/storage/firebase.mjs +173 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +16 -3
package/dist/index.d.mts
CHANGED
|
@@ -56,8 +56,10 @@ interface EditableTextProps extends BaseProps {
|
|
|
56
56
|
as?: "span" | "p" | "h1" | "h2" | "h3" | "h4" | "div";
|
|
57
57
|
className?: string;
|
|
58
58
|
type?: "text" | "textarea" | "richtext";
|
|
59
|
+
lineClassNames?: string[];
|
|
60
|
+
renderLine?: (line: string, index: number) => React.ReactNode;
|
|
59
61
|
}
|
|
60
|
-
declare function EditableText({ id, label, section, pageId, children, as, className, type, }: EditableTextProps): react.ReactElement<any, string | react.JSXElementConstructor<any>>;
|
|
62
|
+
declare function EditableText({ id, label, section, pageId, children, as, className, type, lineClassNames, renderLine, }: EditableTextProps): react.ReactElement<any, string | react.JSXElementConstructor<any>>;
|
|
61
63
|
interface EditableImageProps extends BaseProps {
|
|
62
64
|
src: string;
|
|
63
65
|
alt?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -56,8 +56,10 @@ interface EditableTextProps extends BaseProps {
|
|
|
56
56
|
as?: "span" | "p" | "h1" | "h2" | "h3" | "h4" | "div";
|
|
57
57
|
className?: string;
|
|
58
58
|
type?: "text" | "textarea" | "richtext";
|
|
59
|
+
lineClassNames?: string[];
|
|
60
|
+
renderLine?: (line: string, index: number) => React.ReactNode;
|
|
59
61
|
}
|
|
60
|
-
declare function EditableText({ id, label, section, pageId, children, as, className, type, }: EditableTextProps): react.ReactElement<any, string | react.JSXElementConstructor<any>>;
|
|
62
|
+
declare function EditableText({ id, label, section, pageId, children, as, className, type, lineClassNames, renderLine, }: EditableTextProps): react.ReactElement<any, string | react.JSXElementConstructor<any>>;
|
|
61
63
|
interface EditableImageProps extends BaseProps {
|
|
62
64
|
src: string;
|
|
63
65
|
alt?: string;
|
package/dist/index.js
CHANGED
|
@@ -286,6 +286,7 @@ function CmsProviderInner({ config, adapter, children, iconMap, initialOverrides
|
|
|
286
286
|
const [editMode, setEditMode] = (0, import_react3.useState)(false);
|
|
287
287
|
const [collectionChangedAt, setCollectionChangedAt] = (0, import_react3.useState)(0);
|
|
288
288
|
const registryRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
289
|
+
const refCountRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
289
290
|
(0, import_react3.useEffect)(() => {
|
|
290
291
|
if (typeof window === "undefined" || typeof BroadcastChannel === "undefined") return;
|
|
291
292
|
const bc = new BroadcastChannel("admin-cms:collection-changed");
|
|
@@ -346,32 +347,54 @@ function CmsProviderInner({ config, adapter, children, iconMap, initialOverrides
|
|
|
346
347
|
},
|
|
347
348
|
[editMode]
|
|
348
349
|
);
|
|
350
|
+
const getSafeItems = (0, import_react3.useCallback)(() => {
|
|
351
|
+
try {
|
|
352
|
+
return JSON.parse(
|
|
353
|
+
JSON.stringify(Array.from(registryRef.current.values()), (_key, value2) => {
|
|
354
|
+
if (typeof value2 === "function") {
|
|
355
|
+
return value2.name || void 0;
|
|
356
|
+
}
|
|
357
|
+
return value2;
|
|
358
|
+
})
|
|
359
|
+
);
|
|
360
|
+
} catch {
|
|
361
|
+
return Array.from(registryRef.current.values());
|
|
362
|
+
}
|
|
363
|
+
}, []);
|
|
349
364
|
const registerEditable = (0, import_react3.useCallback)((meta) => {
|
|
365
|
+
refCountRef.current.set(meta.id, (refCountRef.current.get(meta.id) || 0) + 1);
|
|
350
366
|
registryRef.current.set(meta.id, meta);
|
|
351
367
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
352
368
|
window.parent.postMessage(
|
|
353
369
|
{
|
|
354
370
|
__cms: true,
|
|
355
371
|
type: "cms:register",
|
|
356
|
-
items:
|
|
372
|
+
items: getSafeItems()
|
|
357
373
|
},
|
|
358
374
|
"*"
|
|
359
375
|
);
|
|
360
376
|
}
|
|
361
|
-
}, []);
|
|
377
|
+
}, [getSafeItems]);
|
|
362
378
|
const unregisterEditable = (0, import_react3.useCallback)((id) => {
|
|
363
|
-
|
|
379
|
+
const count = (refCountRef.current.get(id) || 1) - 1;
|
|
380
|
+
if (count <= 0) {
|
|
381
|
+
refCountRef.current.delete(id);
|
|
382
|
+
registryRef.current.delete(id);
|
|
383
|
+
} else {
|
|
384
|
+
refCountRef.current.set(id, count);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
364
387
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
365
388
|
window.parent.postMessage(
|
|
366
389
|
{
|
|
367
390
|
__cms: true,
|
|
368
391
|
type: "cms:register",
|
|
369
|
-
items:
|
|
392
|
+
items: getSafeItems()
|
|
370
393
|
},
|
|
371
394
|
"*"
|
|
372
395
|
);
|
|
373
396
|
}
|
|
374
|
-
}, []);
|
|
397
|
+
}, [getSafeItems]);
|
|
375
398
|
const setOverride = (0, import_react3.useCallback)((id, value2) => {
|
|
376
399
|
setOverrides((prev) => ({ ...prev, [id]: value2 }));
|
|
377
400
|
}, []);
|
|
@@ -476,7 +499,9 @@ function EditableText({
|
|
|
476
499
|
children,
|
|
477
500
|
as = "span",
|
|
478
501
|
className,
|
|
479
|
-
type = "text"
|
|
502
|
+
type = "text",
|
|
503
|
+
lineClassNames,
|
|
504
|
+
renderLine
|
|
480
505
|
}) {
|
|
481
506
|
const ctx = useRegister(id, type, label, section, pageId, children);
|
|
482
507
|
const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? String(ctx.overrides[id] ?? "") : children;
|
|
@@ -492,10 +517,19 @@ function EditableText({
|
|
|
492
517
|
};
|
|
493
518
|
let finalChildren = renderValue;
|
|
494
519
|
if (typeof renderValue === "string" && renderValue.includes("\n")) {
|
|
495
|
-
finalChildren = renderValue.split("\n").map((line, i, arr) =>
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
520
|
+
finalChildren = renderValue.split("\n").map((line, i, arr) => {
|
|
521
|
+
if (renderLine) {
|
|
522
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react4.Fragment, { children: [
|
|
523
|
+
renderLine(line, i),
|
|
524
|
+
i < arr.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("br", {})
|
|
525
|
+
] }, i);
|
|
526
|
+
}
|
|
527
|
+
const lineClass = lineClassNames?.[i];
|
|
528
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react4.Fragment, { children: [
|
|
529
|
+
lineClass ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: lineClass, children: line }) : line,
|
|
530
|
+
i < arr.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("br", {})
|
|
531
|
+
] }, i);
|
|
532
|
+
});
|
|
499
533
|
}
|
|
500
534
|
return (0, import_react4.createElement)(
|
|
501
535
|
as,
|
|
@@ -659,7 +693,14 @@ function EditableList({
|
|
|
659
693
|
}) {
|
|
660
694
|
const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search, void 0, void 0, void 0, reorderable, sortable);
|
|
661
695
|
const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
|
|
662
|
-
const
|
|
696
|
+
const rawList = Array.isArray(rawValue) ? rawValue : initialItems;
|
|
697
|
+
const value = Array.isArray(rawList) ? rawList.map((item, idx) => {
|
|
698
|
+
const def = Array.isArray(initialItems) ? initialItems[idx] : void 0;
|
|
699
|
+
if (def && typeof def === "object" && item && typeof item === "object") {
|
|
700
|
+
return { ...def, ...item };
|
|
701
|
+
}
|
|
702
|
+
return item;
|
|
703
|
+
}) : initialItems;
|
|
663
704
|
const active = !!ctx?.editMode;
|
|
664
705
|
const selected = ctx?.selectedId === id;
|
|
665
706
|
const onClick = (e) => {
|
|
@@ -1664,7 +1705,7 @@ function FieldEditor({
|
|
|
1664
1705
|
schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1665
1706
|
SearchableSelect,
|
|
1666
1707
|
{
|
|
1667
|
-
value: String(item?.[schemaField.key] ?? ""),
|
|
1708
|
+
value: String(item?.[schemaField.key] ?? (Array.isArray(meta.defaultValue) ? meta.defaultValue[idx]?.[schemaField.key] : "") ?? ""),
|
|
1668
1709
|
options: schemaField.options ?? [],
|
|
1669
1710
|
placeholder: "Search icon...",
|
|
1670
1711
|
iconMap: ctx.iconMap,
|
|
@@ -1701,7 +1742,7 @@ function FieldEditor({
|
|
|
1701
1742
|
}
|
|
1702
1743
|
),
|
|
1703
1744
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
|
|
1704
|
-
] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
|
|
1745
|
+
] }) : schemaField.type === "image" || schemaField.type === "file" || schemaField.type === "video" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
|
|
1705
1746
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
1706
1747
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1707
1748
|
"input",
|
|
@@ -1713,7 +1754,7 @@ function FieldEditor({
|
|
|
1713
1754
|
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1714
1755
|
onChange(arr);
|
|
1715
1756
|
},
|
|
1716
|
-
placeholder: "https://...",
|
|
1757
|
+
placeholder: "https://... or upload",
|
|
1717
1758
|
className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
1718
1759
|
}
|
|
1719
1760
|
),
|
|
@@ -1723,7 +1764,7 @@ function FieldEditor({
|
|
|
1723
1764
|
"input",
|
|
1724
1765
|
{
|
|
1725
1766
|
type: "file",
|
|
1726
|
-
accept: "image/*",
|
|
1767
|
+
accept: "image/*,video/*",
|
|
1727
1768
|
className: "hidden",
|
|
1728
1769
|
onChange: (e) => {
|
|
1729
1770
|
const file = e.target.files?.[0];
|
|
@@ -1743,7 +1784,14 @@ function FieldEditor({
|
|
|
1743
1784
|
)
|
|
1744
1785
|
] })
|
|
1745
1786
|
] }),
|
|
1746
|
-
item?.[schemaField.key] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1787
|
+
item?.[schemaField.key] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(item?.[schemaField.key]).match(/\.(mp4|webm|ogg|mov)(\?.*)?$/i) || schemaField.type === "video" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1788
|
+
"video",
|
|
1789
|
+
{
|
|
1790
|
+
src: String(item?.[schemaField.key]),
|
|
1791
|
+
controls: true,
|
|
1792
|
+
className: "w-full h-auto max-h-32 object-contain rounded-md"
|
|
1793
|
+
}
|
|
1794
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1747
1795
|
"img",
|
|
1748
1796
|
{
|
|
1749
1797
|
src: String(item?.[schemaField.key]),
|
|
@@ -2168,29 +2216,32 @@ function CollectionEditor({ collection }) {
|
|
|
2168
2216
|
const lab = typeof opt === "string" ? opt : opt.label;
|
|
2169
2217
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: val, children: lab }, val);
|
|
2170
2218
|
}) })
|
|
2171
|
-
] }) : f.type === "image" ? f.multiple ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
2172
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) =>
|
|
2173
|
-
|
|
2174
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
2175
|
-
"
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2219
|
+
] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
2220
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
|
|
2221
|
+
const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
|
|
2222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
|
|
2223
|
+
isVideo ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2224
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2225
|
+
"button",
|
|
2226
|
+
{
|
|
2227
|
+
type: "button",
|
|
2228
|
+
onClick: () => {
|
|
2229
|
+
const arr = [...editing[f.id] || []];
|
|
2230
|
+
arr.splice(i, 1);
|
|
2231
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2232
|
+
},
|
|
2233
|
+
className: "absolute top-2 right-2 bg-red-500/80 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500",
|
|
2234
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.X, { className: "w-3 h-3" })
|
|
2235
|
+
}
|
|
2236
|
+
)
|
|
2237
|
+
] }, i);
|
|
2238
|
+
}) }),
|
|
2188
2239
|
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
2189
2240
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2190
2241
|
"input",
|
|
2191
2242
|
{
|
|
2192
2243
|
type: "url",
|
|
2193
|
-
placeholder: "Add
|
|
2244
|
+
placeholder: "Add media URL and press Enter...",
|
|
2194
2245
|
onKeyDown: (e) => {
|
|
2195
2246
|
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2196
2247
|
e.preventDefault();
|
|
@@ -2208,7 +2259,7 @@ function CollectionEditor({ collection }) {
|
|
|
2208
2259
|
"input",
|
|
2209
2260
|
{
|
|
2210
2261
|
type: "file",
|
|
2211
|
-
accept: "image/*",
|
|
2262
|
+
accept: "image/*,video/*",
|
|
2212
2263
|
multiple: true,
|
|
2213
2264
|
className: "hidden",
|
|
2214
2265
|
onChange: (e) => {
|
|
@@ -2250,7 +2301,7 @@ function CollectionEditor({ collection }) {
|
|
|
2250
2301
|
"input",
|
|
2251
2302
|
{
|
|
2252
2303
|
type: "file",
|
|
2253
|
-
accept: "image/*",
|
|
2304
|
+
accept: "image/*,video/*",
|
|
2254
2305
|
className: "hidden",
|
|
2255
2306
|
onChange: (e) => {
|
|
2256
2307
|
const file = e.target.files?.[0];
|
|
@@ -2266,7 +2317,14 @@ function CollectionEditor({ collection }) {
|
|
|
2266
2317
|
)
|
|
2267
2318
|
] })
|
|
2268
2319
|
] }),
|
|
2269
|
-
editing[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2320
|
+
editing[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(editing[f.id]).match(/\.(mp4|webm|mov|ogg)$/i) || String(editing[f.id]).includes("video") ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2321
|
+
"video",
|
|
2322
|
+
{
|
|
2323
|
+
src: String(editing[f.id]),
|
|
2324
|
+
controls: true,
|
|
2325
|
+
className: "w-full h-auto max-h-48 object-contain rounded-lg"
|
|
2326
|
+
}
|
|
2327
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2270
2328
|
"img",
|
|
2271
2329
|
{
|
|
2272
2330
|
src: String(editing[f.id]),
|
package/dist/index.mjs
CHANGED
|
@@ -257,6 +257,7 @@ function CmsProviderInner({ config, adapter, children, iconMap, initialOverrides
|
|
|
257
257
|
const [editMode, setEditMode] = useState3(false);
|
|
258
258
|
const [collectionChangedAt, setCollectionChangedAt] = useState3(0);
|
|
259
259
|
const registryRef = useRef(/* @__PURE__ */ new Map());
|
|
260
|
+
const refCountRef = useRef(/* @__PURE__ */ new Map());
|
|
260
261
|
useEffect2(() => {
|
|
261
262
|
if (typeof window === "undefined" || typeof BroadcastChannel === "undefined") return;
|
|
262
263
|
const bc = new BroadcastChannel("admin-cms:collection-changed");
|
|
@@ -317,32 +318,54 @@ function CmsProviderInner({ config, adapter, children, iconMap, initialOverrides
|
|
|
317
318
|
},
|
|
318
319
|
[editMode]
|
|
319
320
|
);
|
|
321
|
+
const getSafeItems = useCallback2(() => {
|
|
322
|
+
try {
|
|
323
|
+
return JSON.parse(
|
|
324
|
+
JSON.stringify(Array.from(registryRef.current.values()), (_key, value2) => {
|
|
325
|
+
if (typeof value2 === "function") {
|
|
326
|
+
return value2.name || void 0;
|
|
327
|
+
}
|
|
328
|
+
return value2;
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
} catch {
|
|
332
|
+
return Array.from(registryRef.current.values());
|
|
333
|
+
}
|
|
334
|
+
}, []);
|
|
320
335
|
const registerEditable = useCallback2((meta) => {
|
|
336
|
+
refCountRef.current.set(meta.id, (refCountRef.current.get(meta.id) || 0) + 1);
|
|
321
337
|
registryRef.current.set(meta.id, meta);
|
|
322
338
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
323
339
|
window.parent.postMessage(
|
|
324
340
|
{
|
|
325
341
|
__cms: true,
|
|
326
342
|
type: "cms:register",
|
|
327
|
-
items:
|
|
343
|
+
items: getSafeItems()
|
|
328
344
|
},
|
|
329
345
|
"*"
|
|
330
346
|
);
|
|
331
347
|
}
|
|
332
|
-
}, []);
|
|
348
|
+
}, [getSafeItems]);
|
|
333
349
|
const unregisterEditable = useCallback2((id) => {
|
|
334
|
-
|
|
350
|
+
const count = (refCountRef.current.get(id) || 1) - 1;
|
|
351
|
+
if (count <= 0) {
|
|
352
|
+
refCountRef.current.delete(id);
|
|
353
|
+
registryRef.current.delete(id);
|
|
354
|
+
} else {
|
|
355
|
+
refCountRef.current.set(id, count);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
335
358
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
336
359
|
window.parent.postMessage(
|
|
337
360
|
{
|
|
338
361
|
__cms: true,
|
|
339
362
|
type: "cms:register",
|
|
340
|
-
items:
|
|
363
|
+
items: getSafeItems()
|
|
341
364
|
},
|
|
342
365
|
"*"
|
|
343
366
|
);
|
|
344
367
|
}
|
|
345
|
-
}, []);
|
|
368
|
+
}, [getSafeItems]);
|
|
346
369
|
const setOverride = useCallback2((id, value2) => {
|
|
347
370
|
setOverrides((prev) => ({ ...prev, [id]: value2 }));
|
|
348
371
|
}, []);
|
|
@@ -447,7 +470,9 @@ function EditableText({
|
|
|
447
470
|
children,
|
|
448
471
|
as = "span",
|
|
449
472
|
className,
|
|
450
|
-
type = "text"
|
|
473
|
+
type = "text",
|
|
474
|
+
lineClassNames,
|
|
475
|
+
renderLine
|
|
451
476
|
}) {
|
|
452
477
|
const ctx = useRegister(id, type, label, section, pageId, children);
|
|
453
478
|
const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? String(ctx.overrides[id] ?? "") : children;
|
|
@@ -463,10 +488,19 @@ function EditableText({
|
|
|
463
488
|
};
|
|
464
489
|
let finalChildren = renderValue;
|
|
465
490
|
if (typeof renderValue === "string" && renderValue.includes("\n")) {
|
|
466
|
-
finalChildren = renderValue.split("\n").map((line, i, arr) =>
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
491
|
+
finalChildren = renderValue.split("\n").map((line, i, arr) => {
|
|
492
|
+
if (renderLine) {
|
|
493
|
+
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
494
|
+
renderLine(line, i),
|
|
495
|
+
i < arr.length - 1 && /* @__PURE__ */ jsx4("br", {})
|
|
496
|
+
] }, i);
|
|
497
|
+
}
|
|
498
|
+
const lineClass = lineClassNames?.[i];
|
|
499
|
+
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
500
|
+
lineClass ? /* @__PURE__ */ jsx4("span", { className: lineClass, children: line }) : line,
|
|
501
|
+
i < arr.length - 1 && /* @__PURE__ */ jsx4("br", {})
|
|
502
|
+
] }, i);
|
|
503
|
+
});
|
|
470
504
|
}
|
|
471
505
|
return createElement(
|
|
472
506
|
as,
|
|
@@ -630,7 +664,14 @@ function EditableList({
|
|
|
630
664
|
}) {
|
|
631
665
|
const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search, void 0, void 0, void 0, reorderable, sortable);
|
|
632
666
|
const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
|
|
633
|
-
const
|
|
667
|
+
const rawList = Array.isArray(rawValue) ? rawValue : initialItems;
|
|
668
|
+
const value = Array.isArray(rawList) ? rawList.map((item, idx) => {
|
|
669
|
+
const def = Array.isArray(initialItems) ? initialItems[idx] : void 0;
|
|
670
|
+
if (def && typeof def === "object" && item && typeof item === "object") {
|
|
671
|
+
return { ...def, ...item };
|
|
672
|
+
}
|
|
673
|
+
return item;
|
|
674
|
+
}) : initialItems;
|
|
634
675
|
const active = !!ctx?.editMode;
|
|
635
676
|
const selected = ctx?.selectedId === id;
|
|
636
677
|
const onClick = (e) => {
|
|
@@ -1664,7 +1705,7 @@ function FieldEditor({
|
|
|
1664
1705
|
schemaField.type === "icon" ? /* @__PURE__ */ jsx5(
|
|
1665
1706
|
SearchableSelect,
|
|
1666
1707
|
{
|
|
1667
|
-
value: String(item?.[schemaField.key] ?? ""),
|
|
1708
|
+
value: String(item?.[schemaField.key] ?? (Array.isArray(meta.defaultValue) ? meta.defaultValue[idx]?.[schemaField.key] : "") ?? ""),
|
|
1668
1709
|
options: schemaField.options ?? [],
|
|
1669
1710
|
placeholder: "Search icon...",
|
|
1670
1711
|
iconMap: ctx.iconMap,
|
|
@@ -1701,7 +1742,7 @@ function FieldEditor({
|
|
|
1701
1742
|
}
|
|
1702
1743
|
),
|
|
1703
1744
|
/* @__PURE__ */ jsx5("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
|
|
1704
|
-
] }) : schemaField.type === "image" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3 mt-1", children: [
|
|
1745
|
+
] }) : schemaField.type === "image" || schemaField.type === "file" || schemaField.type === "video" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3 mt-1", children: [
|
|
1705
1746
|
/* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
1706
1747
|
/* @__PURE__ */ jsx5(
|
|
1707
1748
|
"input",
|
|
@@ -1713,7 +1754,7 @@ function FieldEditor({
|
|
|
1713
1754
|
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1714
1755
|
onChange(arr);
|
|
1715
1756
|
},
|
|
1716
|
-
placeholder: "https://...",
|
|
1757
|
+
placeholder: "https://... or upload",
|
|
1717
1758
|
className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
1718
1759
|
}
|
|
1719
1760
|
),
|
|
@@ -1723,7 +1764,7 @@ function FieldEditor({
|
|
|
1723
1764
|
"input",
|
|
1724
1765
|
{
|
|
1725
1766
|
type: "file",
|
|
1726
|
-
accept: "image/*",
|
|
1767
|
+
accept: "image/*,video/*",
|
|
1727
1768
|
className: "hidden",
|
|
1728
1769
|
onChange: (e) => {
|
|
1729
1770
|
const file = e.target.files?.[0];
|
|
@@ -1743,7 +1784,14 @@ function FieldEditor({
|
|
|
1743
1784
|
)
|
|
1744
1785
|
] })
|
|
1745
1786
|
] }),
|
|
1746
|
-
item?.[schemaField.key] ? /* @__PURE__ */ jsx5("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ jsx5(
|
|
1787
|
+
item?.[schemaField.key] ? /* @__PURE__ */ jsx5("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(item?.[schemaField.key]).match(/\.(mp4|webm|ogg|mov)(\?.*)?$/i) || schemaField.type === "video" ? /* @__PURE__ */ jsx5(
|
|
1788
|
+
"video",
|
|
1789
|
+
{
|
|
1790
|
+
src: String(item?.[schemaField.key]),
|
|
1791
|
+
controls: true,
|
|
1792
|
+
className: "w-full h-auto max-h-32 object-contain rounded-md"
|
|
1793
|
+
}
|
|
1794
|
+
) : /* @__PURE__ */ jsx5(
|
|
1747
1795
|
"img",
|
|
1748
1796
|
{
|
|
1749
1797
|
src: String(item?.[schemaField.key]),
|
|
@@ -2168,29 +2216,32 @@ function CollectionEditor({ collection }) {
|
|
|
2168
2216
|
const lab = typeof opt === "string" ? opt : opt.label;
|
|
2169
2217
|
return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
|
|
2170
2218
|
}) })
|
|
2171
|
-
] }) : f.type === "image" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2172
|
-
/* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) =>
|
|
2173
|
-
|
|
2174
|
-
/* @__PURE__ */
|
|
2175
|
-
"
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2219
|
+
] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2220
|
+
/* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
|
|
2221
|
+
const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
|
|
2222
|
+
return /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
|
|
2223
|
+
isVideo ? /* @__PURE__ */ jsx5("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ jsx5("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2224
|
+
/* @__PURE__ */ jsx5(
|
|
2225
|
+
"button",
|
|
2226
|
+
{
|
|
2227
|
+
type: "button",
|
|
2228
|
+
onClick: () => {
|
|
2229
|
+
const arr = [...editing[f.id] || []];
|
|
2230
|
+
arr.splice(i, 1);
|
|
2231
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2232
|
+
},
|
|
2233
|
+
className: "absolute top-2 right-2 bg-red-500/80 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500",
|
|
2234
|
+
children: /* @__PURE__ */ jsx5(X, { className: "w-3 h-3" })
|
|
2235
|
+
}
|
|
2236
|
+
)
|
|
2237
|
+
] }, i);
|
|
2238
|
+
}) }),
|
|
2188
2239
|
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2189
2240
|
/* @__PURE__ */ jsx5(
|
|
2190
2241
|
"input",
|
|
2191
2242
|
{
|
|
2192
2243
|
type: "url",
|
|
2193
|
-
placeholder: "Add
|
|
2244
|
+
placeholder: "Add media URL and press Enter...",
|
|
2194
2245
|
onKeyDown: (e) => {
|
|
2195
2246
|
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2196
2247
|
e.preventDefault();
|
|
@@ -2208,7 +2259,7 @@ function CollectionEditor({ collection }) {
|
|
|
2208
2259
|
"input",
|
|
2209
2260
|
{
|
|
2210
2261
|
type: "file",
|
|
2211
|
-
accept: "image/*",
|
|
2262
|
+
accept: "image/*,video/*",
|
|
2212
2263
|
multiple: true,
|
|
2213
2264
|
className: "hidden",
|
|
2214
2265
|
onChange: (e) => {
|
|
@@ -2250,7 +2301,7 @@ function CollectionEditor({ collection }) {
|
|
|
2250
2301
|
"input",
|
|
2251
2302
|
{
|
|
2252
2303
|
type: "file",
|
|
2253
|
-
accept: "image/*",
|
|
2304
|
+
accept: "image/*,video/*",
|
|
2254
2305
|
className: "hidden",
|
|
2255
2306
|
onChange: (e) => {
|
|
2256
2307
|
const file = e.target.files?.[0];
|
|
@@ -2266,7 +2317,14 @@ function CollectionEditor({ collection }) {
|
|
|
2266
2317
|
)
|
|
2267
2318
|
] })
|
|
2268
2319
|
] }),
|
|
2269
|
-
editing[f.id] ? /* @__PURE__ */ jsx5("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ jsx5(
|
|
2320
|
+
editing[f.id] ? /* @__PURE__ */ jsx5("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(editing[f.id]).match(/\.(mp4|webm|mov|ogg)$/i) || String(editing[f.id]).includes("video") ? /* @__PURE__ */ jsx5(
|
|
2321
|
+
"video",
|
|
2322
|
+
{
|
|
2323
|
+
src: String(editing[f.id]),
|
|
2324
|
+
controls: true,
|
|
2325
|
+
className: "w-full h-auto max-h-48 object-contain rounded-lg"
|
|
2326
|
+
}
|
|
2327
|
+
) : /* @__PURE__ */ jsx5(
|
|
2270
2328
|
"img",
|
|
2271
2329
|
{
|
|
2272
2330
|
src: String(editing[f.id]),
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StorageAdapter } from '../types.mjs';
|
|
2
|
+
import { Firestore } from 'firebase/firestore';
|
|
3
|
+
import { FirebaseStorage } from 'firebase/storage';
|
|
4
|
+
|
|
5
|
+
interface FirebaseAdapterConfig {
|
|
6
|
+
/**
|
|
7
|
+
* An already-initialised Firestore instance, e.g.:
|
|
8
|
+
* import { getFirestore } from "firebase/firestore";
|
|
9
|
+
* const db = getFirestore(app);
|
|
10
|
+
*/
|
|
11
|
+
db: Firestore;
|
|
12
|
+
/**
|
|
13
|
+
* (Optional) An already-initialised Firebase Storage instance, e.g.:
|
|
14
|
+
* import { getStorage } from "firebase/storage";
|
|
15
|
+
* const storage = getStorage(app);
|
|
16
|
+
* Required only if you want `uploadImage` support.
|
|
17
|
+
*/
|
|
18
|
+
storage?: FirebaseStorage;
|
|
19
|
+
/**
|
|
20
|
+
* (Optional) Firestore collection name prefix for all CMS documents.
|
|
21
|
+
* Defaults to "admin_cms".
|
|
22
|
+
*/
|
|
23
|
+
collectionPrefix?: string;
|
|
24
|
+
/**
|
|
25
|
+
* (Optional) Firebase Storage path prefix for uploaded images.
|
|
26
|
+
* Defaults to "admin_cms/images".
|
|
27
|
+
*/
|
|
28
|
+
storagePath?: string;
|
|
29
|
+
}
|
|
30
|
+
declare function createFirebaseAdapter(config: FirebaseAdapterConfig): StorageAdapter;
|
|
31
|
+
|
|
32
|
+
export { type FirebaseAdapterConfig, createFirebaseAdapter };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StorageAdapter } from '../types.js';
|
|
2
|
+
import { Firestore } from 'firebase/firestore';
|
|
3
|
+
import { FirebaseStorage } from 'firebase/storage';
|
|
4
|
+
|
|
5
|
+
interface FirebaseAdapterConfig {
|
|
6
|
+
/**
|
|
7
|
+
* An already-initialised Firestore instance, e.g.:
|
|
8
|
+
* import { getFirestore } from "firebase/firestore";
|
|
9
|
+
* const db = getFirestore(app);
|
|
10
|
+
*/
|
|
11
|
+
db: Firestore;
|
|
12
|
+
/**
|
|
13
|
+
* (Optional) An already-initialised Firebase Storage instance, e.g.:
|
|
14
|
+
* import { getStorage } from "firebase/storage";
|
|
15
|
+
* const storage = getStorage(app);
|
|
16
|
+
* Required only if you want `uploadImage` support.
|
|
17
|
+
*/
|
|
18
|
+
storage?: FirebaseStorage;
|
|
19
|
+
/**
|
|
20
|
+
* (Optional) Firestore collection name prefix for all CMS documents.
|
|
21
|
+
* Defaults to "admin_cms".
|
|
22
|
+
*/
|
|
23
|
+
collectionPrefix?: string;
|
|
24
|
+
/**
|
|
25
|
+
* (Optional) Firebase Storage path prefix for uploaded images.
|
|
26
|
+
* Defaults to "admin_cms/images".
|
|
27
|
+
*/
|
|
28
|
+
storagePath?: string;
|
|
29
|
+
}
|
|
30
|
+
declare function createFirebaseAdapter(config: FirebaseAdapterConfig): StorageAdapter;
|
|
31
|
+
|
|
32
|
+
export { type FirebaseAdapterConfig, createFirebaseAdapter };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/storage/firebase.ts
|
|
21
|
+
var firebase_exports = {};
|
|
22
|
+
__export(firebase_exports, {
|
|
23
|
+
createFirebaseAdapter: () => createFirebaseAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(firebase_exports);
|
|
26
|
+
var import_firestore = require("firebase/firestore");
|
|
27
|
+
var import_storage = require("firebase/storage");
|
|
28
|
+
function createFirebaseAdapter(config) {
|
|
29
|
+
const prefix = config.collectionPrefix ?? "admin_cms";
|
|
30
|
+
const imgPath = config.storagePath ?? "admin_cms/images";
|
|
31
|
+
const OVERRIDES_COL = `${prefix}_overrides`;
|
|
32
|
+
const ENTRIES_COL = `${prefix}_entries`;
|
|
33
|
+
const SUBMISSIONS_COL = `${prefix}_submissions`;
|
|
34
|
+
const OVERRIDES_DOC_ID = "global";
|
|
35
|
+
const { db } = config;
|
|
36
|
+
return {
|
|
37
|
+
name: "firebase",
|
|
38
|
+
// ── Overrides ─────────────────────────────────────────────────────────────
|
|
39
|
+
async getOverrides() {
|
|
40
|
+
try {
|
|
41
|
+
const snap = await (0, import_firestore.getDoc)((0, import_firestore.doc)(db, OVERRIDES_COL, OVERRIDES_DOC_ID));
|
|
42
|
+
if (snap.exists()) {
|
|
43
|
+
const raw = snap.data().data;
|
|
44
|
+
if (raw) return JSON.parse(raw);
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error("Firebase Adapter: failed to fetch overrides", err);
|
|
48
|
+
}
|
|
49
|
+
return {};
|
|
50
|
+
},
|
|
51
|
+
async setOverrides(map) {
|
|
52
|
+
try {
|
|
53
|
+
await (0, import_firestore.setDoc)(
|
|
54
|
+
(0, import_firestore.doc)(db, OVERRIDES_COL, OVERRIDES_DOC_ID),
|
|
55
|
+
{ data: JSON.stringify(map), updatedAt: (/* @__PURE__ */ new Date()).toISOString() },
|
|
56
|
+
{ merge: true }
|
|
57
|
+
);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error("Firebase Adapter: failed to save overrides", err);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// ── Collection entries ─────────────────────────────────────────────────────
|
|
63
|
+
async listEntries(collectionId) {
|
|
64
|
+
try {
|
|
65
|
+
const q = (0, import_firestore.query)(
|
|
66
|
+
(0, import_firestore.collection)(db, ENTRIES_COL),
|
|
67
|
+
(0, import_firestore.where)("collectionId", "==", collectionId)
|
|
68
|
+
);
|
|
69
|
+
const snapshot = await (0, import_firestore.getDocs)(q);
|
|
70
|
+
return snapshot.docs.map((d) => d.data()).filter((d) => typeof d.data === "string").map((d) => JSON.parse(d.data));
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error(
|
|
73
|
+
`Firebase Adapter: failed to list entries for ${collectionId}`,
|
|
74
|
+
err
|
|
75
|
+
);
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async putEntry(collectionId, entry) {
|
|
80
|
+
try {
|
|
81
|
+
const docId = `${collectionId}_${entry.id}`;
|
|
82
|
+
await (0, import_firestore.setDoc)(
|
|
83
|
+
(0, import_firestore.doc)(db, ENTRIES_COL, docId),
|
|
84
|
+
{
|
|
85
|
+
collectionId,
|
|
86
|
+
entryId: entry.id,
|
|
87
|
+
data: JSON.stringify(entry),
|
|
88
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
89
|
+
},
|
|
90
|
+
{ merge: true }
|
|
91
|
+
);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.error(
|
|
94
|
+
`Firebase Adapter: failed to save entry ${entry.id}`,
|
|
95
|
+
err
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
async deleteEntry(collectionId, entryId) {
|
|
100
|
+
try {
|
|
101
|
+
await (0, import_firestore.deleteDoc)((0, import_firestore.doc)(db, ENTRIES_COL, `${collectionId}_${entryId}`));
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.error(
|
|
104
|
+
`Firebase Adapter: failed to delete entry ${entryId}`,
|
|
105
|
+
err
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
// ── Submissions ────────────────────────────────────────────────────────────
|
|
110
|
+
async saveSubmission(submission) {
|
|
111
|
+
try {
|
|
112
|
+
await (0, import_firestore.setDoc)((0, import_firestore.doc)(db, SUBMISSIONS_COL, submission.id), {
|
|
113
|
+
id: submission.id,
|
|
114
|
+
formId: submission.formId,
|
|
115
|
+
submittedAt: submission.submittedAt,
|
|
116
|
+
data: JSON.stringify(submission.data),
|
|
117
|
+
read: submission.read ?? false
|
|
118
|
+
});
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.error("Firebase Adapter: failed to save submission", err);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
async listSubmissions(formId) {
|
|
124
|
+
try {
|
|
125
|
+
const col = (0, import_firestore.collection)(db, SUBMISSIONS_COL);
|
|
126
|
+
const q = formId ? (0, import_firestore.query)(col, (0, import_firestore.where)("formId", "==", formId)) : (0, import_firestore.query)(col);
|
|
127
|
+
const snapshot = await (0, import_firestore.getDocs)(q);
|
|
128
|
+
const result = snapshot.docs.map((d) => d.data()).filter((d) => typeof d.data === "string").map((d) => ({
|
|
129
|
+
id: d.id,
|
|
130
|
+
formId: d.formId,
|
|
131
|
+
submittedAt: d.submittedAt,
|
|
132
|
+
data: JSON.parse(d.data),
|
|
133
|
+
read: d.read ?? false
|
|
134
|
+
}));
|
|
135
|
+
result.sort(
|
|
136
|
+
(a, b) => new Date(b.submittedAt).getTime() - new Date(a.submittedAt).getTime()
|
|
137
|
+
);
|
|
138
|
+
return result;
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.error("Firebase Adapter: failed to list submissions", err);
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
async deleteSubmission(id) {
|
|
145
|
+
try {
|
|
146
|
+
await (0, import_firestore.deleteDoc)((0, import_firestore.doc)(db, SUBMISSIONS_COL, id));
|
|
147
|
+
} catch (err) {
|
|
148
|
+
console.error(
|
|
149
|
+
`Firebase Adapter: failed to delete submission ${id}`,
|
|
150
|
+
err
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async markSubmissionRead(id) {
|
|
155
|
+
try {
|
|
156
|
+
await (0, import_firestore.setDoc)((0, import_firestore.doc)(db, SUBMISSIONS_COL, id), { read: true }, { merge: true });
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error(
|
|
159
|
+
`Firebase Adapter: failed to mark submission read ${id}`,
|
|
160
|
+
err
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
// ── Image Upload ───────────────────────────────────────────────────────────
|
|
165
|
+
async uploadImage(file) {
|
|
166
|
+
if (!config.storage) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
"Firebase Adapter: storage instance not provided. Pass `storage` to createFirebaseAdapter()."
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const timestamp = Date.now();
|
|
172
|
+
const safeName = file.name.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
173
|
+
const fileRef = (0, import_storage.ref)(
|
|
174
|
+
config.storage,
|
|
175
|
+
`${imgPath}/${timestamp}_${safeName}`
|
|
176
|
+
);
|
|
177
|
+
const snapshot = await (0, import_storage.uploadBytes)(fileRef, file);
|
|
178
|
+
return (0, import_storage.getDownloadURL)(snapshot.ref);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
+
0 && (module.exports = {
|
|
184
|
+
createFirebaseAdapter
|
|
185
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// src/storage/firebase.ts
|
|
2
|
+
import {
|
|
3
|
+
doc,
|
|
4
|
+
getDoc,
|
|
5
|
+
setDoc,
|
|
6
|
+
deleteDoc,
|
|
7
|
+
collection,
|
|
8
|
+
query,
|
|
9
|
+
where,
|
|
10
|
+
getDocs
|
|
11
|
+
} from "firebase/firestore";
|
|
12
|
+
import {
|
|
13
|
+
ref as storageRef,
|
|
14
|
+
uploadBytes,
|
|
15
|
+
getDownloadURL
|
|
16
|
+
} from "firebase/storage";
|
|
17
|
+
function createFirebaseAdapter(config) {
|
|
18
|
+
const prefix = config.collectionPrefix ?? "admin_cms";
|
|
19
|
+
const imgPath = config.storagePath ?? "admin_cms/images";
|
|
20
|
+
const OVERRIDES_COL = `${prefix}_overrides`;
|
|
21
|
+
const ENTRIES_COL = `${prefix}_entries`;
|
|
22
|
+
const SUBMISSIONS_COL = `${prefix}_submissions`;
|
|
23
|
+
const OVERRIDES_DOC_ID = "global";
|
|
24
|
+
const { db } = config;
|
|
25
|
+
return {
|
|
26
|
+
name: "firebase",
|
|
27
|
+
// ── Overrides ─────────────────────────────────────────────────────────────
|
|
28
|
+
async getOverrides() {
|
|
29
|
+
try {
|
|
30
|
+
const snap = await getDoc(doc(db, OVERRIDES_COL, OVERRIDES_DOC_ID));
|
|
31
|
+
if (snap.exists()) {
|
|
32
|
+
const raw = snap.data().data;
|
|
33
|
+
if (raw) return JSON.parse(raw);
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error("Firebase Adapter: failed to fetch overrides", err);
|
|
37
|
+
}
|
|
38
|
+
return {};
|
|
39
|
+
},
|
|
40
|
+
async setOverrides(map) {
|
|
41
|
+
try {
|
|
42
|
+
await setDoc(
|
|
43
|
+
doc(db, OVERRIDES_COL, OVERRIDES_DOC_ID),
|
|
44
|
+
{ data: JSON.stringify(map), updatedAt: (/* @__PURE__ */ new Date()).toISOString() },
|
|
45
|
+
{ merge: true }
|
|
46
|
+
);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error("Firebase Adapter: failed to save overrides", err);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
// ── Collection entries ─────────────────────────────────────────────────────
|
|
52
|
+
async listEntries(collectionId) {
|
|
53
|
+
try {
|
|
54
|
+
const q = query(
|
|
55
|
+
collection(db, ENTRIES_COL),
|
|
56
|
+
where("collectionId", "==", collectionId)
|
|
57
|
+
);
|
|
58
|
+
const snapshot = await getDocs(q);
|
|
59
|
+
return snapshot.docs.map((d) => d.data()).filter((d) => typeof d.data === "string").map((d) => JSON.parse(d.data));
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error(
|
|
62
|
+
`Firebase Adapter: failed to list entries for ${collectionId}`,
|
|
63
|
+
err
|
|
64
|
+
);
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
async putEntry(collectionId, entry) {
|
|
69
|
+
try {
|
|
70
|
+
const docId = `${collectionId}_${entry.id}`;
|
|
71
|
+
await setDoc(
|
|
72
|
+
doc(db, ENTRIES_COL, docId),
|
|
73
|
+
{
|
|
74
|
+
collectionId,
|
|
75
|
+
entryId: entry.id,
|
|
76
|
+
data: JSON.stringify(entry),
|
|
77
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
78
|
+
},
|
|
79
|
+
{ merge: true }
|
|
80
|
+
);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(
|
|
83
|
+
`Firebase Adapter: failed to save entry ${entry.id}`,
|
|
84
|
+
err
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
async deleteEntry(collectionId, entryId) {
|
|
89
|
+
try {
|
|
90
|
+
await deleteDoc(doc(db, ENTRIES_COL, `${collectionId}_${entryId}`));
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.error(
|
|
93
|
+
`Firebase Adapter: failed to delete entry ${entryId}`,
|
|
94
|
+
err
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
// ── Submissions ────────────────────────────────────────────────────────────
|
|
99
|
+
async saveSubmission(submission) {
|
|
100
|
+
try {
|
|
101
|
+
await setDoc(doc(db, SUBMISSIONS_COL, submission.id), {
|
|
102
|
+
id: submission.id,
|
|
103
|
+
formId: submission.formId,
|
|
104
|
+
submittedAt: submission.submittedAt,
|
|
105
|
+
data: JSON.stringify(submission.data),
|
|
106
|
+
read: submission.read ?? false
|
|
107
|
+
});
|
|
108
|
+
} catch (err) {
|
|
109
|
+
console.error("Firebase Adapter: failed to save submission", err);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
async listSubmissions(formId) {
|
|
113
|
+
try {
|
|
114
|
+
const col = collection(db, SUBMISSIONS_COL);
|
|
115
|
+
const q = formId ? query(col, where("formId", "==", formId)) : query(col);
|
|
116
|
+
const snapshot = await getDocs(q);
|
|
117
|
+
const result = snapshot.docs.map((d) => d.data()).filter((d) => typeof d.data === "string").map((d) => ({
|
|
118
|
+
id: d.id,
|
|
119
|
+
formId: d.formId,
|
|
120
|
+
submittedAt: d.submittedAt,
|
|
121
|
+
data: JSON.parse(d.data),
|
|
122
|
+
read: d.read ?? false
|
|
123
|
+
}));
|
|
124
|
+
result.sort(
|
|
125
|
+
(a, b) => new Date(b.submittedAt).getTime() - new Date(a.submittedAt).getTime()
|
|
126
|
+
);
|
|
127
|
+
return result;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error("Firebase Adapter: failed to list submissions", err);
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
async deleteSubmission(id) {
|
|
134
|
+
try {
|
|
135
|
+
await deleteDoc(doc(db, SUBMISSIONS_COL, id));
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error(
|
|
138
|
+
`Firebase Adapter: failed to delete submission ${id}`,
|
|
139
|
+
err
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
async markSubmissionRead(id) {
|
|
144
|
+
try {
|
|
145
|
+
await setDoc(doc(db, SUBMISSIONS_COL, id), { read: true }, { merge: true });
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error(
|
|
148
|
+
`Firebase Adapter: failed to mark submission read ${id}`,
|
|
149
|
+
err
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
// ── Image Upload ───────────────────────────────────────────────────────────
|
|
154
|
+
async uploadImage(file) {
|
|
155
|
+
if (!config.storage) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
"Firebase Adapter: storage instance not provided. Pass `storage` to createFirebaseAdapter()."
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const timestamp = Date.now();
|
|
161
|
+
const safeName = file.name.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
162
|
+
const fileRef = storageRef(
|
|
163
|
+
config.storage,
|
|
164
|
+
`${imgPath}/${timestamp}_${safeName}`
|
|
165
|
+
);
|
|
166
|
+
const snapshot = await uploadBytes(fileRef, file);
|
|
167
|
+
return getDownloadURL(snapshot.ref);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
createFirebaseAdapter
|
|
173
|
+
};
|
package/dist/types.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ interface EditableMeta {
|
|
|
8
8
|
defaultValue?: unknown;
|
|
9
9
|
itemSchema?: {
|
|
10
10
|
key: string;
|
|
11
|
-
type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "number" | "select";
|
|
11
|
+
type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "video" | "number" | "select";
|
|
12
12
|
label?: string;
|
|
13
13
|
options?: string[];
|
|
14
14
|
}[];
|
package/dist/types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface EditableMeta {
|
|
|
8
8
|
defaultValue?: unknown;
|
|
9
9
|
itemSchema?: {
|
|
10
10
|
key: string;
|
|
11
|
-
type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "number" | "select";
|
|
11
|
+
type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "video" | "number" | "select";
|
|
12
12
|
label?: string;
|
|
13
13
|
options?: string[];
|
|
14
14
|
}[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "admin-lib-cms",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Agnostic Admin CMS Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"dashboard",
|
|
11
11
|
"headless-cms",
|
|
12
12
|
"sanity",
|
|
13
|
+
"firebase",
|
|
13
14
|
"editable"
|
|
14
15
|
],
|
|
15
16
|
"author": "bgarizaot",
|
|
@@ -49,6 +50,12 @@
|
|
|
49
50
|
"require": "./dist/storage.js",
|
|
50
51
|
"default": "./dist/storage.js"
|
|
51
52
|
},
|
|
53
|
+
"./storage/firebase": {
|
|
54
|
+
"types": "./dist/storage/firebase.d.ts",
|
|
55
|
+
"import": "./dist/storage/firebase.mjs",
|
|
56
|
+
"require": "./dist/storage/firebase.js",
|
|
57
|
+
"default": "./dist/storage/firebase.js"
|
|
58
|
+
},
|
|
52
59
|
"./types": {
|
|
53
60
|
"types": "./dist/types.d.ts",
|
|
54
61
|
"import": "./dist/types.mjs",
|
|
@@ -57,8 +64,8 @@
|
|
|
57
64
|
}
|
|
58
65
|
},
|
|
59
66
|
"scripts": {
|
|
60
|
-
"build": "tsup \"src/*.ts\" \"src/emails/index.ts\" --format cjs,esm --dts --external next",
|
|
61
|
-
"dev": "tsup \"src/*.ts\" \"src/emails/index.ts\" --format cjs,esm --dts --external next --watch"
|
|
67
|
+
"build": "tsup \"src/*.ts\" \"src/emails/index.ts\" \"src/storage/firebase.ts\" --format cjs,esm --dts --external next --external @sanity/client --external firebase",
|
|
68
|
+
"dev": "tsup \"src/*.ts\" \"src/emails/index.ts\" \"src/storage/firebase.ts\" --format cjs,esm --dts --external next --external @sanity/client --external firebase --watch"
|
|
62
69
|
},
|
|
63
70
|
"dependencies": {
|
|
64
71
|
"bcryptjs": "^3.0.3",
|
|
@@ -66,10 +73,12 @@
|
|
|
66
73
|
"lucide-react": "^0.300.0"
|
|
67
74
|
},
|
|
68
75
|
"devDependencies": {
|
|
76
|
+
"@sanity/client": "^8.6.2",
|
|
69
77
|
"@types/bcryptjs": "^2.4.6",
|
|
70
78
|
"@types/node": "^26.1.0",
|
|
71
79
|
"@types/react": "^18.2.0",
|
|
72
80
|
"@types/react-dom": "^18.2.0",
|
|
81
|
+
"firebase": "^12.19.0",
|
|
73
82
|
"next": "^16.2.10",
|
|
74
83
|
"react": "^18.2.0",
|
|
75
84
|
"react-dom": "^18.2.0",
|
|
@@ -78,6 +87,7 @@
|
|
|
78
87
|
},
|
|
79
88
|
"peerDependencies": {
|
|
80
89
|
"@sanity/client": "^6.15.0 || ^7.0.0",
|
|
90
|
+
"firebase": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
81
91
|
"next": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
82
92
|
"react": "^18.0.0 || ^19.0.0",
|
|
83
93
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
@@ -85,6 +95,9 @@
|
|
|
85
95
|
"peerDependenciesMeta": {
|
|
86
96
|
"@sanity/client": {
|
|
87
97
|
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"firebase": {
|
|
100
|
+
"optional": true
|
|
88
101
|
}
|
|
89
102
|
}
|
|
90
103
|
}
|