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.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;
|
|
@@ -95,8 +97,10 @@ interface EditableListProps<T = any> extends BaseProps {
|
|
|
95
97
|
className?: string;
|
|
96
98
|
listClassName?: string;
|
|
97
99
|
search?: boolean;
|
|
100
|
+
reorderable?: boolean;
|
|
101
|
+
sortable?: boolean;
|
|
98
102
|
}
|
|
99
|
-
declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
|
|
103
|
+
declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, reorderable, sortable, }: EditableListProps<T>): react.JSX.Element;
|
|
100
104
|
interface EditableReferenceProps extends BaseProps {
|
|
101
105
|
collection: string;
|
|
102
106
|
max?: number;
|
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;
|
|
@@ -95,8 +97,10 @@ interface EditableListProps<T = any> extends BaseProps {
|
|
|
95
97
|
className?: string;
|
|
96
98
|
listClassName?: string;
|
|
97
99
|
search?: boolean;
|
|
100
|
+
reorderable?: boolean;
|
|
101
|
+
sortable?: boolean;
|
|
98
102
|
}
|
|
99
|
-
declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
|
|
103
|
+
declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, reorderable, sortable, }: EditableListProps<T>): react.JSX.Element;
|
|
100
104
|
interface EditableReferenceProps extends BaseProps {
|
|
101
105
|
collection: string;
|
|
102
106
|
max?: number;
|
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
|
}, []);
|
|
@@ -452,13 +475,13 @@ function useSubmit(formId) {
|
|
|
452
475
|
// src/editable.tsx
|
|
453
476
|
var import_react4 = require("react");
|
|
454
477
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
455
|
-
function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField) {
|
|
478
|
+
function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable) {
|
|
456
479
|
const ctx = useCmsOptional();
|
|
457
480
|
(0, import_react4.useEffect)(() => {
|
|
458
481
|
if (!ctx) return;
|
|
459
|
-
ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField });
|
|
482
|
+
ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable });
|
|
460
483
|
return () => ctx.unregisterEditable(id);
|
|
461
|
-
}, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField]);
|
|
484
|
+
}, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable]);
|
|
462
485
|
return ctx;
|
|
463
486
|
}
|
|
464
487
|
function editableClasses(active, selected) {
|
|
@@ -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,
|
|
@@ -653,11 +687,20 @@ function EditableList({
|
|
|
653
687
|
fixedLength,
|
|
654
688
|
className,
|
|
655
689
|
listClassName,
|
|
656
|
-
search
|
|
690
|
+
search,
|
|
691
|
+
reorderable,
|
|
692
|
+
sortable
|
|
657
693
|
}) {
|
|
658
|
-
const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search);
|
|
694
|
+
const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search, void 0, void 0, void 0, reorderable, sortable);
|
|
659
695
|
const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
|
|
660
|
-
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;
|
|
661
704
|
const active = !!ctx?.editMode;
|
|
662
705
|
const selected = ctx?.selectedId === id;
|
|
663
706
|
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__ */ (0, import_jsx_runtime5.jsxs)(
|
|
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__ */ (0, import_jsx_runtime5.jsxs)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.GripVertical, { className: "w-4 h-4 cursor-grab active:cursor-grabbing hover:text-indigo-600" }),
|
|
1605
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
1606
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { className: "w-3.5 h-3.5" })
|
|
1622
|
-
}
|
|
1623
|
-
),
|
|
1624
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { className: "w-3.5 h-3.5" })
|
|
1640
|
-
}
|
|
1641
|
-
)
|
|
1642
|
-
] })
|
|
1643
|
-
]
|
|
1644
|
-
}
|
|
1645
|
-
),
|
|
1646
1642
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 w-full min-w-0", children: [
|
|
1647
1643
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
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__ */ (0, import_jsx_runtime5.
|
|
1649
|
+
isReorderable && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.GripVertical, { className: "w-4 h-4 cursor-grab active:cursor-grabbing hover:text-indigo-600" }),
|
|
1657
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-0.5", children: [
|
|
1658
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { className: "w-3.5 h-3.5" })
|
|
1674
|
+
}
|
|
1675
|
+
),
|
|
1676
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { className: "w-3.5 h-3.5" })
|
|
1692
|
+
}
|
|
1693
|
+
)
|
|
1694
|
+
] })
|
|
1695
|
+
]
|
|
1696
|
+
}
|
|
1697
|
+
),
|
|
1698
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { className: "w-4 h-4 text-slate-500 shrink-0" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.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__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
|
|
1700
|
-
] }) : 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: [
|
|
1701
1746
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
1702
1747
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (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)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)("option", { value: val, children: lab }, val);
|
|
2155
2218
|
}) })
|
|
2156
|
-
] }) : f.type === "image" ? f.multiple ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
2157
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) =>
|
|
2158
|
-
|
|
2159
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
2160
|
-
"
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
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
|
+
}) }),
|
|
2173
2239
|
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
2174
2240
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (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)(
|
|
2255
2328
|
"img",
|
|
2256
2329
|
{
|
|
2257
2330
|
src: String(editing[f.id]),
|