admin-lib-cms 1.2.3 → 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 +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +176 -103
- package/dist/index.mjs +176 -103
- 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 +3 -1
- package/dist/types.d.ts +3 -1
- package/package.json +16 -3
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
|
}, []);
|
|
@@ -423,13 +446,13 @@ function useSubmit(formId) {
|
|
|
423
446
|
// src/editable.tsx
|
|
424
447
|
import { createElement, useEffect as useEffect3, useState as useState4, Fragment as Fragment2 } from "react";
|
|
425
448
|
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
426
|
-
function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField) {
|
|
449
|
+
function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable) {
|
|
427
450
|
const ctx = useCmsOptional();
|
|
428
451
|
useEffect3(() => {
|
|
429
452
|
if (!ctx) return;
|
|
430
|
-
ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField });
|
|
453
|
+
ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable });
|
|
431
454
|
return () => ctx.unregisterEditable(id);
|
|
432
|
-
}, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField]);
|
|
455
|
+
}, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable]);
|
|
433
456
|
return ctx;
|
|
434
457
|
}
|
|
435
458
|
function editableClasses(active, selected) {
|
|
@@ -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,
|
|
@@ -624,11 +658,20 @@ function EditableList({
|
|
|
624
658
|
fixedLength,
|
|
625
659
|
className,
|
|
626
660
|
listClassName,
|
|
627
|
-
search
|
|
661
|
+
search,
|
|
662
|
+
reorderable,
|
|
663
|
+
sortable
|
|
628
664
|
}) {
|
|
629
|
-
const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search);
|
|
665
|
+
const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search, void 0, void 0, void 0, reorderable, sortable);
|
|
630
666
|
const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
|
|
631
|
-
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;
|
|
632
675
|
const active = !!ctx?.editMode;
|
|
633
676
|
const selected = ctx?.selectedId === id;
|
|
634
677
|
const onClick = (e) => {
|
|
@@ -1563,24 +1606,25 @@ function FieldEditor({
|
|
|
1563
1606
|
if (!title.includes(searchQuery.toLowerCase())) return null;
|
|
1564
1607
|
}
|
|
1565
1608
|
const isExpanded = expandedItems[idx] ?? false;
|
|
1609
|
+
const isReorderable = !!(meta.reorderable || meta.sortable);
|
|
1566
1610
|
return /* @__PURE__ */ jsxs4(
|
|
1567
1611
|
"div",
|
|
1568
1612
|
{
|
|
1569
|
-
draggable:
|
|
1570
|
-
onDragStart: (e) => {
|
|
1613
|
+
draggable: isReorderable,
|
|
1614
|
+
onDragStart: isReorderable ? (e) => {
|
|
1571
1615
|
setListDragIdx(idx);
|
|
1572
1616
|
e.dataTransfer.effectAllowed = "move";
|
|
1573
|
-
},
|
|
1574
|
-
onDragOver: (e) => {
|
|
1617
|
+
} : void 0,
|
|
1618
|
+
onDragOver: isReorderable ? (e) => {
|
|
1575
1619
|
e.preventDefault();
|
|
1576
1620
|
e.dataTransfer.dropEffect = "move";
|
|
1577
1621
|
setListDragOverIdx(idx);
|
|
1578
|
-
},
|
|
1579
|
-
onDragEnd: () => {
|
|
1622
|
+
} : void 0,
|
|
1623
|
+
onDragEnd: isReorderable ? () => {
|
|
1580
1624
|
setListDragIdx(null);
|
|
1581
1625
|
setListDragOverIdx(null);
|
|
1582
|
-
},
|
|
1583
|
-
onDrop: (e) => {
|
|
1626
|
+
} : void 0,
|
|
1627
|
+
onDrop: isReorderable ? (e) => {
|
|
1584
1628
|
e.preventDefault();
|
|
1585
1629
|
if (listDragIdx === null || listDragIdx === idx) {
|
|
1586
1630
|
setListDragOverIdx(null);
|
|
@@ -1592,65 +1636,66 @@ function FieldEditor({
|
|
|
1592
1636
|
onChange(arr);
|
|
1593
1637
|
setListDragIdx(null);
|
|
1594
1638
|
setListDragOverIdx(null);
|
|
1595
|
-
},
|
|
1596
|
-
className: `bg-slate-50 p-3 rounded-xl border transition-all relative group ${listDragOverIdx === idx ? "border-indigo-500 border-2 bg-indigo-50/40" : "border-slate-200 hover:border-slate-300"} ${listDragIdx === idx ? "opacity-40" : ""}`,
|
|
1639
|
+
} : void 0,
|
|
1640
|
+
className: `bg-slate-50 p-3 rounded-xl border transition-all relative group ${isReorderable && listDragOverIdx === idx ? "border-indigo-500 border-2 bg-indigo-50/40" : "border-slate-200 hover:border-slate-300"} ${isReorderable && listDragIdx === idx ? "opacity-40" : ""}`,
|
|
1597
1641
|
children: [
|
|
1598
|
-
/* @__PURE__ */ jsxs4(
|
|
1599
|
-
"div",
|
|
1600
|
-
{
|
|
1601
|
-
className: "absolute left-3 top-3.5 z-10 flex items-center gap-1 text-slate-400 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none group-hover:pointer-events-auto select-none",
|
|
1602
|
-
title: "Drag or use arrows to reorder",
|
|
1603
|
-
children: [
|
|
1604
|
-
/* @__PURE__ */ jsx5(GripVertical, { className: "w-4 h-4 cursor-grab active:cursor-grabbing hover:text-indigo-600" }),
|
|
1605
|
-
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-1", children: [
|
|
1606
|
-
/* @__PURE__ */ jsx5(
|
|
1607
|
-
"button",
|
|
1608
|
-
{
|
|
1609
|
-
type: "button",
|
|
1610
|
-
disabled: idx === 0,
|
|
1611
|
-
onClick: (e) => {
|
|
1612
|
-
e.stopPropagation();
|
|
1613
|
-
if (idx === 0) return;
|
|
1614
|
-
const arr = Array.isArray(value) ? [...value] : [];
|
|
1615
|
-
const [moved] = arr.splice(idx, 1);
|
|
1616
|
-
arr.splice(idx - 1, 0, moved);
|
|
1617
|
-
onChange(arr);
|
|
1618
|
-
},
|
|
1619
|
-
className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
|
|
1620
|
-
title: "Move Up",
|
|
1621
|
-
children: /* @__PURE__ */ jsx5(ChevronUp, { className: "w-3.5 h-3.5" })
|
|
1622
|
-
}
|
|
1623
|
-
),
|
|
1624
|
-
/* @__PURE__ */ jsx5(
|
|
1625
|
-
"button",
|
|
1626
|
-
{
|
|
1627
|
-
type: "button",
|
|
1628
|
-
disabled: idx === (Array.isArray(value) ? value.length - 1 : 0),
|
|
1629
|
-
onClick: (e) => {
|
|
1630
|
-
e.stopPropagation();
|
|
1631
|
-
const arr = Array.isArray(value) ? [...value] : [];
|
|
1632
|
-
if (idx >= arr.length - 1) return;
|
|
1633
|
-
const [moved] = arr.splice(idx, 1);
|
|
1634
|
-
arr.splice(idx + 1, 0, moved);
|
|
1635
|
-
onChange(arr);
|
|
1636
|
-
},
|
|
1637
|
-
className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
|
|
1638
|
-
title: "Move Down",
|
|
1639
|
-
children: /* @__PURE__ */ jsx5(ChevronDown, { className: "w-3.5 h-3.5" })
|
|
1640
|
-
}
|
|
1641
|
-
)
|
|
1642
|
-
] })
|
|
1643
|
-
]
|
|
1644
|
-
}
|
|
1645
|
-
),
|
|
1646
1642
|
/* @__PURE__ */ jsxs4("div", { className: "space-y-3 w-full min-w-0", children: [
|
|
1647
1643
|
/* @__PURE__ */ jsxs4(
|
|
1648
1644
|
"div",
|
|
1649
1645
|
{
|
|
1650
|
-
className: "flex items-center justify-between cursor-pointer py-1 select-none",
|
|
1646
|
+
className: "flex items-center justify-between cursor-pointer py-1 select-none gap-2",
|
|
1651
1647
|
onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
|
|
1652
1648
|
children: [
|
|
1653
|
-
/* @__PURE__ */
|
|
1649
|
+
isReorderable && /* @__PURE__ */ jsxs4(
|
|
1650
|
+
"div",
|
|
1651
|
+
{
|
|
1652
|
+
className: "flex items-center gap-1 text-slate-400 select-none shrink-0",
|
|
1653
|
+
title: "Drag or use arrows to reorder",
|
|
1654
|
+
onClick: (e) => e.stopPropagation(),
|
|
1655
|
+
children: [
|
|
1656
|
+
/* @__PURE__ */ jsx5(GripVertical, { className: "w-4 h-4 cursor-grab active:cursor-grabbing hover:text-indigo-600" }),
|
|
1657
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-0.5", children: [
|
|
1658
|
+
/* @__PURE__ */ jsx5(
|
|
1659
|
+
"button",
|
|
1660
|
+
{
|
|
1661
|
+
type: "button",
|
|
1662
|
+
disabled: idx === 0,
|
|
1663
|
+
onClick: (e) => {
|
|
1664
|
+
e.stopPropagation();
|
|
1665
|
+
if (idx === 0) return;
|
|
1666
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1667
|
+
const [moved] = arr.splice(idx, 1);
|
|
1668
|
+
arr.splice(idx - 1, 0, moved);
|
|
1669
|
+
onChange(arr);
|
|
1670
|
+
},
|
|
1671
|
+
className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
|
|
1672
|
+
title: "Move Up",
|
|
1673
|
+
children: /* @__PURE__ */ jsx5(ChevronUp, { className: "w-3.5 h-3.5" })
|
|
1674
|
+
}
|
|
1675
|
+
),
|
|
1676
|
+
/* @__PURE__ */ jsx5(
|
|
1677
|
+
"button",
|
|
1678
|
+
{
|
|
1679
|
+
type: "button",
|
|
1680
|
+
disabled: idx === (Array.isArray(value) ? value.length - 1 : 0),
|
|
1681
|
+
onClick: (e) => {
|
|
1682
|
+
e.stopPropagation();
|
|
1683
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1684
|
+
if (idx >= arr.length - 1) return;
|
|
1685
|
+
const [moved] = arr.splice(idx, 1);
|
|
1686
|
+
arr.splice(idx + 1, 0, moved);
|
|
1687
|
+
onChange(arr);
|
|
1688
|
+
},
|
|
1689
|
+
className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
|
|
1690
|
+
title: "Move Down",
|
|
1691
|
+
children: /* @__PURE__ */ jsx5(ChevronDown, { className: "w-3.5 h-3.5" })
|
|
1692
|
+
}
|
|
1693
|
+
)
|
|
1694
|
+
] })
|
|
1695
|
+
]
|
|
1696
|
+
}
|
|
1697
|
+
),
|
|
1698
|
+
/* @__PURE__ */ jsx5("div", { className: "font-semibold text-slate-700 text-sm flex-1 truncate pr-4", children: meta.itemSchema ? item?.title || item?.name || `Item ${idx + 1}` : String(item) }),
|
|
1654
1699
|
isExpanded ? /* @__PURE__ */ jsx5(ChevronUp, { className: "w-4 h-4 text-slate-500 shrink-0" }) : /* @__PURE__ */ jsx5(ChevronDown, { className: "w-4 h-4 text-slate-500 shrink-0" })
|
|
1655
1700
|
]
|
|
1656
1701
|
}
|
|
@@ -1660,7 +1705,7 @@ function FieldEditor({
|
|
|
1660
1705
|
schemaField.type === "icon" ? /* @__PURE__ */ jsx5(
|
|
1661
1706
|
SearchableSelect,
|
|
1662
1707
|
{
|
|
1663
|
-
value: String(item?.[schemaField.key] ?? ""),
|
|
1708
|
+
value: String(item?.[schemaField.key] ?? (Array.isArray(meta.defaultValue) ? meta.defaultValue[idx]?.[schemaField.key] : "") ?? ""),
|
|
1664
1709
|
options: schemaField.options ?? [],
|
|
1665
1710
|
placeholder: "Search icon...",
|
|
1666
1711
|
iconMap: ctx.iconMap,
|
|
@@ -1697,7 +1742,7 @@ function FieldEditor({
|
|
|
1697
1742
|
}
|
|
1698
1743
|
),
|
|
1699
1744
|
/* @__PURE__ */ jsx5("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
|
|
1700
|
-
] }) : 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: [
|
|
1701
1746
|
/* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
1702
1747
|
/* @__PURE__ */ jsx5(
|
|
1703
1748
|
"input",
|
|
@@ -1709,7 +1754,7 @@ function FieldEditor({
|
|
|
1709
1754
|
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1710
1755
|
onChange(arr);
|
|
1711
1756
|
},
|
|
1712
|
-
placeholder: "https://...",
|
|
1757
|
+
placeholder: "https://... or upload",
|
|
1713
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"
|
|
1714
1759
|
}
|
|
1715
1760
|
),
|
|
@@ -1719,7 +1764,7 @@ function FieldEditor({
|
|
|
1719
1764
|
"input",
|
|
1720
1765
|
{
|
|
1721
1766
|
type: "file",
|
|
1722
|
-
accept: "image/*",
|
|
1767
|
+
accept: "image/*,video/*",
|
|
1723
1768
|
className: "hidden",
|
|
1724
1769
|
onChange: (e) => {
|
|
1725
1770
|
const file = e.target.files?.[0];
|
|
@@ -1739,7 +1784,14 @@ function FieldEditor({
|
|
|
1739
1784
|
)
|
|
1740
1785
|
] })
|
|
1741
1786
|
] }),
|
|
1742
|
-
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(
|
|
1743
1795
|
"img",
|
|
1744
1796
|
{
|
|
1745
1797
|
src: String(item?.[schemaField.key]),
|
|
@@ -1810,9 +1862,20 @@ function FieldEditor({
|
|
|
1810
1862
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1811
1863
|
if (meta.itemSchema) {
|
|
1812
1864
|
const newItem = {};
|
|
1865
|
+
const now = /* @__PURE__ */ new Date();
|
|
1866
|
+
const month = now.toLocaleDateString("en-US", { month: "short" }).toUpperCase();
|
|
1867
|
+
const day = String(now.getDate()).padStart(2, "0");
|
|
1868
|
+
const year = now.getFullYear();
|
|
1869
|
+
const autoDate = `${month} ${day}, ${year}`;
|
|
1813
1870
|
meta.itemSchema.forEach((s) => {
|
|
1814
|
-
|
|
1871
|
+
if (s.key === "publishedAt" || s.key === "date") {
|
|
1872
|
+
newItem[s.key] = autoDate;
|
|
1873
|
+
} else {
|
|
1874
|
+
newItem[s.key] = "";
|
|
1875
|
+
}
|
|
1815
1876
|
});
|
|
1877
|
+
newItem.publishedAt = autoDate;
|
|
1878
|
+
newItem.createdAt = now.toISOString();
|
|
1816
1879
|
arr.push(newItem);
|
|
1817
1880
|
} else {
|
|
1818
1881
|
arr.push("New Item");
|
|
@@ -2153,29 +2216,32 @@ function CollectionEditor({ collection }) {
|
|
|
2153
2216
|
const lab = typeof opt === "string" ? opt : opt.label;
|
|
2154
2217
|
return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
|
|
2155
2218
|
}) })
|
|
2156
|
-
] }) : f.type === "image" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2157
|
-
/* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) =>
|
|
2158
|
-
|
|
2159
|
-
/* @__PURE__ */
|
|
2160
|
-
"
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
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
|
+
}) }),
|
|
2173
2239
|
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2174
2240
|
/* @__PURE__ */ jsx5(
|
|
2175
2241
|
"input",
|
|
2176
2242
|
{
|
|
2177
2243
|
type: "url",
|
|
2178
|
-
placeholder: "Add
|
|
2244
|
+
placeholder: "Add media URL and press Enter...",
|
|
2179
2245
|
onKeyDown: (e) => {
|
|
2180
2246
|
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2181
2247
|
e.preventDefault();
|
|
@@ -2193,7 +2259,7 @@ function CollectionEditor({ collection }) {
|
|
|
2193
2259
|
"input",
|
|
2194
2260
|
{
|
|
2195
2261
|
type: "file",
|
|
2196
|
-
accept: "image/*",
|
|
2262
|
+
accept: "image/*,video/*",
|
|
2197
2263
|
multiple: true,
|
|
2198
2264
|
className: "hidden",
|
|
2199
2265
|
onChange: (e) => {
|
|
@@ -2235,7 +2301,7 @@ function CollectionEditor({ collection }) {
|
|
|
2235
2301
|
"input",
|
|
2236
2302
|
{
|
|
2237
2303
|
type: "file",
|
|
2238
|
-
accept: "image/*",
|
|
2304
|
+
accept: "image/*,video/*",
|
|
2239
2305
|
className: "hidden",
|
|
2240
2306
|
onChange: (e) => {
|
|
2241
2307
|
const file = e.target.files?.[0];
|
|
@@ -2251,7 +2317,14 @@ function CollectionEditor({ collection }) {
|
|
|
2251
2317
|
)
|
|
2252
2318
|
] })
|
|
2253
2319
|
] }),
|
|
2254
|
-
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(
|
|
2255
2328
|
"img",
|
|
2256
2329
|
{
|
|
2257
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 };
|