admin-lib-cms 1.2.2 → 1.2.4

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 CHANGED
@@ -95,8 +95,10 @@ interface EditableListProps<T = any> extends BaseProps {
95
95
  className?: string;
96
96
  listClassName?: string;
97
97
  search?: boolean;
98
+ reorderable?: boolean;
99
+ sortable?: boolean;
98
100
  }
99
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
101
+ 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
102
  interface EditableReferenceProps extends BaseProps {
101
103
  collection: string;
102
104
  max?: number;
package/dist/index.d.ts CHANGED
@@ -95,8 +95,10 @@ interface EditableListProps<T = any> extends BaseProps {
95
95
  className?: string;
96
96
  listClassName?: string;
97
97
  search?: boolean;
98
+ reorderable?: boolean;
99
+ sortable?: boolean;
98
100
  }
99
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
101
+ 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
102
  interface EditableReferenceProps extends BaseProps {
101
103
  collection: string;
102
104
  max?: number;
package/dist/index.js CHANGED
@@ -452,13 +452,13 @@ function useSubmit(formId) {
452
452
  // src/editable.tsx
453
453
  var import_react4 = require("react");
454
454
  var import_jsx_runtime4 = require("react/jsx-runtime");
455
- function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField) {
455
+ function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable) {
456
456
  const ctx = useCmsOptional();
457
457
  (0, import_react4.useEffect)(() => {
458
458
  if (!ctx) return;
459
- ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField });
459
+ ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable });
460
460
  return () => ctx.unregisterEditable(id);
461
- }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField]);
461
+ }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable]);
462
462
  return ctx;
463
463
  }
464
464
  function editableClasses(active, selected) {
@@ -653,9 +653,11 @@ function EditableList({
653
653
  fixedLength,
654
654
  className,
655
655
  listClassName,
656
- search
656
+ search,
657
+ reorderable,
658
+ sortable
657
659
  }) {
658
- const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search);
660
+ const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search, void 0, void 0, void 0, reorderable, sortable);
659
661
  const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
660
662
  const value = Array.isArray(rawValue) ? rawValue : initialItems;
661
663
  const active = !!ctx?.editMode;
@@ -1372,6 +1374,8 @@ function FieldEditor({
1372
1374
  const ctx = useCmsContext();
1373
1375
  const [expandedItems, setExpandedItems] = (0, import_react5.useState)({});
1374
1376
  const [searchQuery, setSearchQuery] = (0, import_react5.useState)("");
1377
+ const [listDragIdx, setListDragIdx] = (0, import_react5.useState)(null);
1378
+ const [listDragOverIdx, setListDragOverIdx] = (0, import_react5.useState)(null);
1375
1379
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
1376
1380
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-5", children: [
1377
1381
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "inline-flex items-center gap-1.5 px-2 py-1 rounded bg-indigo-50 text-indigo-700 text-[10px] font-bold uppercase tracking-wider mb-2", children: meta.type }),
@@ -1561,163 +1565,247 @@ function FieldEditor({
1561
1565
  if (!title.includes(searchQuery.toLowerCase())) return null;
1562
1566
  }
1563
1567
  const isExpanded = expandedItems[idx] ?? false;
1564
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-3 items-start bg-slate-50 p-3 rounded-xl border border-slate-100 relative group", children: [
1565
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex-1 space-y-3 w-full", children: [
1566
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1567
- "div",
1568
- {
1569
- className: "flex items-center justify-between cursor-pointer py-1 select-none",
1570
- onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1571
- children: [
1572
- /* @__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) }),
1573
- 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" })
1574
- ]
1568
+ const isReorderable = !!(meta.reorderable || meta.sortable);
1569
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1570
+ "div",
1571
+ {
1572
+ draggable: isReorderable,
1573
+ onDragStart: isReorderable ? (e) => {
1574
+ setListDragIdx(idx);
1575
+ e.dataTransfer.effectAllowed = "move";
1576
+ } : void 0,
1577
+ onDragOver: isReorderable ? (e) => {
1578
+ e.preventDefault();
1579
+ e.dataTransfer.dropEffect = "move";
1580
+ setListDragOverIdx(idx);
1581
+ } : void 0,
1582
+ onDragEnd: isReorderable ? () => {
1583
+ setListDragIdx(null);
1584
+ setListDragOverIdx(null);
1585
+ } : void 0,
1586
+ onDrop: isReorderable ? (e) => {
1587
+ e.preventDefault();
1588
+ if (listDragIdx === null || listDragIdx === idx) {
1589
+ setListDragOverIdx(null);
1590
+ return;
1575
1591
  }
1576
- ),
1577
- isExpanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "pt-3 border-t border-slate-200 mt-2 space-y-3", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1578
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1579
- schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1580
- SearchableSelect,
1581
- {
1582
- value: String(item?.[schemaField.key] ?? ""),
1583
- options: schemaField.options ?? [],
1584
- placeholder: "Search icon...",
1585
- iconMap: ctx.iconMap,
1586
- onChange: (val) => {
1587
- const arr = Array.isArray(value) ? [...value] : [];
1588
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1589
- onChange(arr);
1590
- }
1591
- }
1592
- ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1593
- "textarea",
1594
- {
1595
- rows: 3,
1596
- value: String(item?.[schemaField.key] ?? ""),
1597
- onChange: (e) => {
1598
- const arr = Array.isArray(value) ? [...value] : [];
1599
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1600
- onChange(arr);
1601
- },
1602
- 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"
1603
- }
1604
- ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1605
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1606
- "input",
1592
+ const arr = Array.isArray(value) ? [...value] : [];
1593
+ const [moved] = arr.splice(listDragIdx, 1);
1594
+ arr.splice(idx, 0, moved);
1595
+ onChange(arr);
1596
+ setListDragIdx(null);
1597
+ setListDragOverIdx(null);
1598
+ } : void 0,
1599
+ 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" : ""}`,
1600
+ children: [
1601
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 w-full min-w-0", children: [
1602
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1603
+ "div",
1607
1604
  {
1608
- type: "checkbox",
1609
- checked: !!item?.[schemaField.key],
1610
- onChange: (e) => {
1611
- const arr = Array.isArray(value) ? [...value] : [];
1612
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1613
- onChange(arr);
1614
- },
1615
- className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1605
+ className: "flex items-center justify-between cursor-pointer py-1 select-none gap-2",
1606
+ onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1607
+ children: [
1608
+ isReorderable && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1609
+ "div",
1610
+ {
1611
+ className: "flex items-center gap-1 text-slate-400 select-none shrink-0",
1612
+ title: "Drag or use arrows to reorder",
1613
+ onClick: (e) => e.stopPropagation(),
1614
+ children: [
1615
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.GripVertical, { className: "w-4 h-4 cursor-grab active:cursor-grabbing hover:text-indigo-600" }),
1616
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-0.5", children: [
1617
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1618
+ "button",
1619
+ {
1620
+ type: "button",
1621
+ disabled: idx === 0,
1622
+ onClick: (e) => {
1623
+ e.stopPropagation();
1624
+ if (idx === 0) return;
1625
+ const arr = Array.isArray(value) ? [...value] : [];
1626
+ const [moved] = arr.splice(idx, 1);
1627
+ arr.splice(idx - 1, 0, moved);
1628
+ onChange(arr);
1629
+ },
1630
+ className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
1631
+ title: "Move Up",
1632
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { className: "w-3.5 h-3.5" })
1633
+ }
1634
+ ),
1635
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1636
+ "button",
1637
+ {
1638
+ type: "button",
1639
+ disabled: idx === (Array.isArray(value) ? value.length - 1 : 0),
1640
+ onClick: (e) => {
1641
+ e.stopPropagation();
1642
+ const arr = Array.isArray(value) ? [...value] : [];
1643
+ if (idx >= arr.length - 1) return;
1644
+ const [moved] = arr.splice(idx, 1);
1645
+ arr.splice(idx + 1, 0, moved);
1646
+ onChange(arr);
1647
+ },
1648
+ className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
1649
+ title: "Move Down",
1650
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { className: "w-3.5 h-3.5" })
1651
+ }
1652
+ )
1653
+ ] })
1654
+ ]
1655
+ }
1656
+ ),
1657
+ /* @__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) }),
1658
+ 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" })
1659
+ ]
1616
1660
  }
1617
1661
  ),
1618
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1619
- ] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
1620
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1621
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1622
- "input",
1662
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "pt-3 border-t border-slate-200 mt-2 space-y-3", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1663
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1664
+ schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1665
+ SearchableSelect,
1623
1666
  {
1624
- type: "url",
1667
+ value: String(item?.[schemaField.key] ?? ""),
1668
+ options: schemaField.options ?? [],
1669
+ placeholder: "Search icon...",
1670
+ iconMap: ctx.iconMap,
1671
+ onChange: (val) => {
1672
+ const arr = Array.isArray(value) ? [...value] : [];
1673
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1674
+ onChange(arr);
1675
+ }
1676
+ }
1677
+ ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1678
+ "textarea",
1679
+ {
1680
+ rows: 3,
1625
1681
  value: String(item?.[schemaField.key] ?? ""),
1626
1682
  onChange: (e) => {
1627
1683
  const arr = Array.isArray(value) ? [...value] : [];
1628
1684
  arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1629
1685
  onChange(arr);
1630
1686
  },
1631
- placeholder: "https://...",
1632
1687
  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"
1633
1688
  }
1634
- ),
1635
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex-shrink-0 cursor-pointer rounded-lg bg-slate-100 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1636
- "Upload",
1689
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1637
1690
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1638
1691
  "input",
1639
1692
  {
1640
- type: "file",
1641
- accept: "image/*",
1642
- className: "hidden",
1693
+ type: "checkbox",
1694
+ checked: !!item?.[schemaField.key],
1643
1695
  onChange: (e) => {
1644
- const file = e.target.files?.[0];
1645
- if (file) {
1646
- void handleImageFile(
1647
- file,
1648
- (url) => {
1649
- const arr = Array.isArray(value) ? [...value] : [];
1650
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1651
- onChange(arr);
1652
- },
1653
- ctx.uploadImage
1654
- );
1655
- }
1696
+ const arr = Array.isArray(value) ? [...value] : [];
1697
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1698
+ onChange(arr);
1699
+ },
1700
+ className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1701
+ }
1702
+ ),
1703
+ /* @__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: [
1705
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1706
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1707
+ "input",
1708
+ {
1709
+ type: "url",
1710
+ value: String(item?.[schemaField.key] ?? ""),
1711
+ onChange: (e) => {
1712
+ const arr = Array.isArray(value) ? [...value] : [];
1713
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1714
+ onChange(arr);
1715
+ },
1716
+ placeholder: "https://...",
1717
+ 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"
1656
1718
  }
1719
+ ),
1720
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex-shrink-0 cursor-pointer rounded-lg bg-slate-100 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1721
+ "Upload",
1722
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1723
+ "input",
1724
+ {
1725
+ type: "file",
1726
+ accept: "image/*",
1727
+ className: "hidden",
1728
+ onChange: (e) => {
1729
+ const file = e.target.files?.[0];
1730
+ if (file) {
1731
+ void handleImageFile(
1732
+ file,
1733
+ (url) => {
1734
+ const arr = Array.isArray(value) ? [...value] : [];
1735
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1736
+ onChange(arr);
1737
+ },
1738
+ ctx.uploadImage
1739
+ );
1740
+ }
1741
+ }
1742
+ }
1743
+ )
1744
+ ] })
1745
+ ] }),
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)(
1747
+ "img",
1748
+ {
1749
+ src: String(item?.[schemaField.key]),
1750
+ alt: "",
1751
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1657
1752
  }
1658
- )
1659
- ] })
1660
- ] }),
1661
- 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)(
1662
- "img",
1753
+ ) }) : null
1754
+ ] }) : schemaField.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1755
+ "select",
1756
+ {
1757
+ value: String(item?.[schemaField.key] ?? ""),
1758
+ onChange: (e) => {
1759
+ const arr = Array.isArray(value) ? [...value] : [];
1760
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1761
+ onChange(arr);
1762
+ },
1763
+ 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 bg-white",
1764
+ children: schemaField.options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: opt, children: opt }, opt))
1765
+ }
1766
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1767
+ "input",
1768
+ {
1769
+ type: "text",
1770
+ value: String(item?.[schemaField.key] ?? ""),
1771
+ onChange: (e) => {
1772
+ const arr = Array.isArray(value) ? [...value] : [];
1773
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1774
+ onChange(arr);
1775
+ },
1776
+ 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"
1777
+ }
1778
+ )
1779
+ ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1780
+ "input",
1663
1781
  {
1664
- src: String(item?.[schemaField.key]),
1665
- alt: "",
1666
- className: "w-full h-auto max-h-32 object-contain rounded-md"
1782
+ type: "text",
1783
+ value: String(item),
1784
+ onChange: (e) => {
1785
+ const arr = Array.isArray(value) ? [...value] : [];
1786
+ arr[idx] = e.target.value;
1787
+ onChange(arr);
1788
+ },
1789
+ 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"
1667
1790
  }
1668
- ) }) : null
1669
- ] }) : schemaField.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1670
- "select",
1671
- {
1672
- value: String(item?.[schemaField.key] ?? ""),
1673
- onChange: (e) => {
1674
- const arr = Array.isArray(value) ? [...value] : [];
1675
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1676
- onChange(arr);
1677
- },
1678
- 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 bg-white",
1679
- children: schemaField.options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: opt, children: opt }, opt))
1680
- }
1681
- ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1682
- "input",
1791
+ ) })
1792
+ ] }),
1793
+ !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1794
+ "button",
1683
1795
  {
1684
- type: "text",
1685
- value: String(item?.[schemaField.key] ?? ""),
1686
- onChange: (e) => {
1796
+ onClick: () => {
1687
1797
  const arr = Array.isArray(value) ? [...value] : [];
1688
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1798
+ arr.splice(idx, 1);
1689
1799
  onChange(arr);
1690
1800
  },
1691
- 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"
1801
+ className: "p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors absolute top-2 right-2 opacity-0 group-hover:opacity-100",
1802
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1692
1803
  }
1693
1804
  )
1694
- ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1695
- "input",
1696
- {
1697
- type: "text",
1698
- value: String(item),
1699
- onChange: (e) => {
1700
- const arr = Array.isArray(value) ? [...value] : [];
1701
- arr[idx] = e.target.value;
1702
- onChange(arr);
1703
- },
1704
- 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"
1705
- }
1706
- ) })
1707
- ] }),
1708
- !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1709
- "button",
1710
- {
1711
- onClick: () => {
1712
- const arr = Array.isArray(value) ? [...value] : [];
1713
- arr.splice(idx, 1);
1714
- onChange(arr);
1715
- },
1716
- className: "p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors absolute top-2 right-2 opacity-0 group-hover:opacity-100",
1717
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1718
- }
1719
- )
1720
- ] }, idx);
1805
+ ]
1806
+ },
1807
+ idx
1808
+ );
1721
1809
  }),
1722
1810
  !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1723
1811
  "button",
@@ -1726,9 +1814,20 @@ function FieldEditor({
1726
1814
  const arr = Array.isArray(value) ? [...value] : [];
1727
1815
  if (meta.itemSchema) {
1728
1816
  const newItem = {};
1817
+ const now = /* @__PURE__ */ new Date();
1818
+ const month = now.toLocaleDateString("en-US", { month: "short" }).toUpperCase();
1819
+ const day = String(now.getDate()).padStart(2, "0");
1820
+ const year = now.getFullYear();
1821
+ const autoDate = `${month} ${day}, ${year}`;
1729
1822
  meta.itemSchema.forEach((s) => {
1730
- newItem[s.key] = "";
1823
+ if (s.key === "publishedAt" || s.key === "date") {
1824
+ newItem[s.key] = autoDate;
1825
+ } else {
1826
+ newItem[s.key] = "";
1827
+ }
1731
1828
  });
1829
+ newItem.publishedAt = autoDate;
1830
+ newItem.createdAt = now.toISOString();
1732
1831
  arr.push(newItem);
1733
1832
  } else {
1734
1833
  arr.push("New Item");
package/dist/index.mjs CHANGED
@@ -423,13 +423,13 @@ function useSubmit(formId) {
423
423
  // src/editable.tsx
424
424
  import { createElement, useEffect as useEffect3, useState as useState4, Fragment as Fragment2 } from "react";
425
425
  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) {
426
+ function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable) {
427
427
  const ctx = useCmsOptional();
428
428
  useEffect3(() => {
429
429
  if (!ctx) return;
430
- ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField });
430
+ ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable });
431
431
  return () => ctx.unregisterEditable(id);
432
- }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField]);
432
+ }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable]);
433
433
  return ctx;
434
434
  }
435
435
  function editableClasses(active, selected) {
@@ -624,9 +624,11 @@ function EditableList({
624
624
  fixedLength,
625
625
  className,
626
626
  listClassName,
627
- search
627
+ search,
628
+ reorderable,
629
+ sortable
628
630
  }) {
629
- const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search);
631
+ const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search, void 0, void 0, void 0, reorderable, sortable);
630
632
  const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
631
633
  const value = Array.isArray(rawValue) ? rawValue : initialItems;
632
634
  const active = !!ctx?.editMode;
@@ -736,7 +738,8 @@ import {
736
738
  SlidersHorizontal,
737
739
  LogOut,
738
740
  ExternalLink as ExternalLink2,
739
- Check
741
+ Check,
742
+ GripVertical
740
743
  } from "lucide-react";
741
744
  import { CreditCard as CreditCard2 } from "lucide-react";
742
745
  import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
@@ -1371,6 +1374,8 @@ function FieldEditor({
1371
1374
  const ctx = useCmsContext();
1372
1375
  const [expandedItems, setExpandedItems] = useState5({});
1373
1376
  const [searchQuery, setSearchQuery] = useState5("");
1377
+ const [listDragIdx, setListDragIdx] = useState5(null);
1378
+ const [listDragOverIdx, setListDragOverIdx] = useState5(null);
1374
1379
  return /* @__PURE__ */ jsxs4("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
1375
1380
  /* @__PURE__ */ jsxs4("div", { className: "mb-5", children: [
1376
1381
  /* @__PURE__ */ jsx5("div", { className: "inline-flex items-center gap-1.5 px-2 py-1 rounded bg-indigo-50 text-indigo-700 text-[10px] font-bold uppercase tracking-wider mb-2", children: meta.type }),
@@ -1560,163 +1565,247 @@ function FieldEditor({
1560
1565
  if (!title.includes(searchQuery.toLowerCase())) return null;
1561
1566
  }
1562
1567
  const isExpanded = expandedItems[idx] ?? false;
1563
- return /* @__PURE__ */ jsxs4("div", { className: "flex gap-3 items-start bg-slate-50 p-3 rounded-xl border border-slate-100 relative group", children: [
1564
- /* @__PURE__ */ jsxs4("div", { className: "flex-1 space-y-3 w-full", children: [
1565
- /* @__PURE__ */ jsxs4(
1566
- "div",
1567
- {
1568
- className: "flex items-center justify-between cursor-pointer py-1 select-none",
1569
- onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1570
- children: [
1571
- /* @__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) }),
1572
- 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" })
1573
- ]
1568
+ const isReorderable = !!(meta.reorderable || meta.sortable);
1569
+ return /* @__PURE__ */ jsxs4(
1570
+ "div",
1571
+ {
1572
+ draggable: isReorderable,
1573
+ onDragStart: isReorderable ? (e) => {
1574
+ setListDragIdx(idx);
1575
+ e.dataTransfer.effectAllowed = "move";
1576
+ } : void 0,
1577
+ onDragOver: isReorderable ? (e) => {
1578
+ e.preventDefault();
1579
+ e.dataTransfer.dropEffect = "move";
1580
+ setListDragOverIdx(idx);
1581
+ } : void 0,
1582
+ onDragEnd: isReorderable ? () => {
1583
+ setListDragIdx(null);
1584
+ setListDragOverIdx(null);
1585
+ } : void 0,
1586
+ onDrop: isReorderable ? (e) => {
1587
+ e.preventDefault();
1588
+ if (listDragIdx === null || listDragIdx === idx) {
1589
+ setListDragOverIdx(null);
1590
+ return;
1574
1591
  }
1575
- ),
1576
- isExpanded && /* @__PURE__ */ jsx5("div", { className: "pt-3 border-t border-slate-200 mt-2 space-y-3", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ jsxs4("div", { children: [
1577
- /* @__PURE__ */ jsx5("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1578
- schemaField.type === "icon" ? /* @__PURE__ */ jsx5(
1579
- SearchableSelect,
1580
- {
1581
- value: String(item?.[schemaField.key] ?? ""),
1582
- options: schemaField.options ?? [],
1583
- placeholder: "Search icon...",
1584
- iconMap: ctx.iconMap,
1585
- onChange: (val) => {
1586
- const arr = Array.isArray(value) ? [...value] : [];
1587
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1588
- onChange(arr);
1589
- }
1590
- }
1591
- ) : schemaField.type === "textarea" ? /* @__PURE__ */ jsx5(
1592
- "textarea",
1593
- {
1594
- rows: 3,
1595
- value: String(item?.[schemaField.key] ?? ""),
1596
- onChange: (e) => {
1597
- const arr = Array.isArray(value) ? [...value] : [];
1598
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1599
- onChange(arr);
1600
- },
1601
- 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"
1602
- }
1603
- ) : schemaField.type === "boolean" ? /* @__PURE__ */ jsxs4("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1604
- /* @__PURE__ */ jsx5(
1605
- "input",
1592
+ const arr = Array.isArray(value) ? [...value] : [];
1593
+ const [moved] = arr.splice(listDragIdx, 1);
1594
+ arr.splice(idx, 0, moved);
1595
+ onChange(arr);
1596
+ setListDragIdx(null);
1597
+ setListDragOverIdx(null);
1598
+ } : void 0,
1599
+ 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" : ""}`,
1600
+ children: [
1601
+ /* @__PURE__ */ jsxs4("div", { className: "space-y-3 w-full min-w-0", children: [
1602
+ /* @__PURE__ */ jsxs4(
1603
+ "div",
1606
1604
  {
1607
- type: "checkbox",
1608
- checked: !!item?.[schemaField.key],
1609
- onChange: (e) => {
1610
- const arr = Array.isArray(value) ? [...value] : [];
1611
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1612
- onChange(arr);
1613
- },
1614
- className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1605
+ className: "flex items-center justify-between cursor-pointer py-1 select-none gap-2",
1606
+ onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1607
+ children: [
1608
+ isReorderable && /* @__PURE__ */ jsxs4(
1609
+ "div",
1610
+ {
1611
+ className: "flex items-center gap-1 text-slate-400 select-none shrink-0",
1612
+ title: "Drag or use arrows to reorder",
1613
+ onClick: (e) => e.stopPropagation(),
1614
+ children: [
1615
+ /* @__PURE__ */ jsx5(GripVertical, { className: "w-4 h-4 cursor-grab active:cursor-grabbing hover:text-indigo-600" }),
1616
+ /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-0.5", children: [
1617
+ /* @__PURE__ */ jsx5(
1618
+ "button",
1619
+ {
1620
+ type: "button",
1621
+ disabled: idx === 0,
1622
+ onClick: (e) => {
1623
+ e.stopPropagation();
1624
+ if (idx === 0) return;
1625
+ const arr = Array.isArray(value) ? [...value] : [];
1626
+ const [moved] = arr.splice(idx, 1);
1627
+ arr.splice(idx - 1, 0, moved);
1628
+ onChange(arr);
1629
+ },
1630
+ className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
1631
+ title: "Move Up",
1632
+ children: /* @__PURE__ */ jsx5(ChevronUp, { className: "w-3.5 h-3.5" })
1633
+ }
1634
+ ),
1635
+ /* @__PURE__ */ jsx5(
1636
+ "button",
1637
+ {
1638
+ type: "button",
1639
+ disabled: idx === (Array.isArray(value) ? value.length - 1 : 0),
1640
+ onClick: (e) => {
1641
+ e.stopPropagation();
1642
+ const arr = Array.isArray(value) ? [...value] : [];
1643
+ if (idx >= arr.length - 1) return;
1644
+ const [moved] = arr.splice(idx, 1);
1645
+ arr.splice(idx + 1, 0, moved);
1646
+ onChange(arr);
1647
+ },
1648
+ className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
1649
+ title: "Move Down",
1650
+ children: /* @__PURE__ */ jsx5(ChevronDown, { className: "w-3.5 h-3.5" })
1651
+ }
1652
+ )
1653
+ ] })
1654
+ ]
1655
+ }
1656
+ ),
1657
+ /* @__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) }),
1658
+ 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" })
1659
+ ]
1615
1660
  }
1616
1661
  ),
1617
- /* @__PURE__ */ jsx5("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1618
- ] }) : schemaField.type === "image" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3 mt-1", children: [
1619
- /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
1620
- /* @__PURE__ */ jsx5(
1621
- "input",
1662
+ isExpanded && /* @__PURE__ */ jsx5("div", { className: "pt-3 border-t border-slate-200 mt-2 space-y-3", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ jsxs4("div", { children: [
1663
+ /* @__PURE__ */ jsx5("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1664
+ schemaField.type === "icon" ? /* @__PURE__ */ jsx5(
1665
+ SearchableSelect,
1622
1666
  {
1623
- type: "url",
1667
+ value: String(item?.[schemaField.key] ?? ""),
1668
+ options: schemaField.options ?? [],
1669
+ placeholder: "Search icon...",
1670
+ iconMap: ctx.iconMap,
1671
+ onChange: (val) => {
1672
+ const arr = Array.isArray(value) ? [...value] : [];
1673
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1674
+ onChange(arr);
1675
+ }
1676
+ }
1677
+ ) : schemaField.type === "textarea" ? /* @__PURE__ */ jsx5(
1678
+ "textarea",
1679
+ {
1680
+ rows: 3,
1624
1681
  value: String(item?.[schemaField.key] ?? ""),
1625
1682
  onChange: (e) => {
1626
1683
  const arr = Array.isArray(value) ? [...value] : [];
1627
1684
  arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1628
1685
  onChange(arr);
1629
1686
  },
1630
- placeholder: "https://...",
1631
1687
  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"
1632
1688
  }
1633
- ),
1634
- /* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-lg bg-slate-100 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1635
- "Upload",
1689
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ jsxs4("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1636
1690
  /* @__PURE__ */ jsx5(
1637
1691
  "input",
1638
1692
  {
1639
- type: "file",
1640
- accept: "image/*",
1641
- className: "hidden",
1693
+ type: "checkbox",
1694
+ checked: !!item?.[schemaField.key],
1642
1695
  onChange: (e) => {
1643
- const file = e.target.files?.[0];
1644
- if (file) {
1645
- void handleImageFile(
1646
- file,
1647
- (url) => {
1648
- const arr = Array.isArray(value) ? [...value] : [];
1649
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1650
- onChange(arr);
1651
- },
1652
- ctx.uploadImage
1653
- );
1654
- }
1696
+ const arr = Array.isArray(value) ? [...value] : [];
1697
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1698
+ onChange(arr);
1699
+ },
1700
+ className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1701
+ }
1702
+ ),
1703
+ /* @__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: [
1705
+ /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
1706
+ /* @__PURE__ */ jsx5(
1707
+ "input",
1708
+ {
1709
+ type: "url",
1710
+ value: String(item?.[schemaField.key] ?? ""),
1711
+ onChange: (e) => {
1712
+ const arr = Array.isArray(value) ? [...value] : [];
1713
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1714
+ onChange(arr);
1715
+ },
1716
+ placeholder: "https://...",
1717
+ 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"
1655
1718
  }
1719
+ ),
1720
+ /* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-lg bg-slate-100 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1721
+ "Upload",
1722
+ /* @__PURE__ */ jsx5(
1723
+ "input",
1724
+ {
1725
+ type: "file",
1726
+ accept: "image/*",
1727
+ className: "hidden",
1728
+ onChange: (e) => {
1729
+ const file = e.target.files?.[0];
1730
+ if (file) {
1731
+ void handleImageFile(
1732
+ file,
1733
+ (url) => {
1734
+ const arr = Array.isArray(value) ? [...value] : [];
1735
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1736
+ onChange(arr);
1737
+ },
1738
+ ctx.uploadImage
1739
+ );
1740
+ }
1741
+ }
1742
+ }
1743
+ )
1744
+ ] })
1745
+ ] }),
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(
1747
+ "img",
1748
+ {
1749
+ src: String(item?.[schemaField.key]),
1750
+ alt: "",
1751
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1656
1752
  }
1657
- )
1658
- ] })
1659
- ] }),
1660
- 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(
1661
- "img",
1753
+ ) }) : null
1754
+ ] }) : schemaField.type === "select" ? /* @__PURE__ */ jsx5(
1755
+ "select",
1756
+ {
1757
+ value: String(item?.[schemaField.key] ?? ""),
1758
+ onChange: (e) => {
1759
+ const arr = Array.isArray(value) ? [...value] : [];
1760
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1761
+ onChange(arr);
1762
+ },
1763
+ 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 bg-white",
1764
+ children: schemaField.options?.map((opt) => /* @__PURE__ */ jsx5("option", { value: opt, children: opt }, opt))
1765
+ }
1766
+ ) : /* @__PURE__ */ jsx5(
1767
+ "input",
1768
+ {
1769
+ type: "text",
1770
+ value: String(item?.[schemaField.key] ?? ""),
1771
+ onChange: (e) => {
1772
+ const arr = Array.isArray(value) ? [...value] : [];
1773
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1774
+ onChange(arr);
1775
+ },
1776
+ 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"
1777
+ }
1778
+ )
1779
+ ] }, schemaField.key)) : /* @__PURE__ */ jsx5(
1780
+ "input",
1662
1781
  {
1663
- src: String(item?.[schemaField.key]),
1664
- alt: "",
1665
- className: "w-full h-auto max-h-32 object-contain rounded-md"
1782
+ type: "text",
1783
+ value: String(item),
1784
+ onChange: (e) => {
1785
+ const arr = Array.isArray(value) ? [...value] : [];
1786
+ arr[idx] = e.target.value;
1787
+ onChange(arr);
1788
+ },
1789
+ 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"
1666
1790
  }
1667
- ) }) : null
1668
- ] }) : schemaField.type === "select" ? /* @__PURE__ */ jsx5(
1669
- "select",
1670
- {
1671
- value: String(item?.[schemaField.key] ?? ""),
1672
- onChange: (e) => {
1673
- const arr = Array.isArray(value) ? [...value] : [];
1674
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1675
- onChange(arr);
1676
- },
1677
- 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 bg-white",
1678
- children: schemaField.options?.map((opt) => /* @__PURE__ */ jsx5("option", { value: opt, children: opt }, opt))
1679
- }
1680
- ) : /* @__PURE__ */ jsx5(
1681
- "input",
1791
+ ) })
1792
+ ] }),
1793
+ !meta.fixedLength && /* @__PURE__ */ jsx5(
1794
+ "button",
1682
1795
  {
1683
- type: "text",
1684
- value: String(item?.[schemaField.key] ?? ""),
1685
- onChange: (e) => {
1796
+ onClick: () => {
1686
1797
  const arr = Array.isArray(value) ? [...value] : [];
1687
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1798
+ arr.splice(idx, 1);
1688
1799
  onChange(arr);
1689
1800
  },
1690
- 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"
1801
+ className: "p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors absolute top-2 right-2 opacity-0 group-hover:opacity-100",
1802
+ children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
1691
1803
  }
1692
1804
  )
1693
- ] }, schemaField.key)) : /* @__PURE__ */ jsx5(
1694
- "input",
1695
- {
1696
- type: "text",
1697
- value: String(item),
1698
- onChange: (e) => {
1699
- const arr = Array.isArray(value) ? [...value] : [];
1700
- arr[idx] = e.target.value;
1701
- onChange(arr);
1702
- },
1703
- 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"
1704
- }
1705
- ) })
1706
- ] }),
1707
- !meta.fixedLength && /* @__PURE__ */ jsx5(
1708
- "button",
1709
- {
1710
- onClick: () => {
1711
- const arr = Array.isArray(value) ? [...value] : [];
1712
- arr.splice(idx, 1);
1713
- onChange(arr);
1714
- },
1715
- className: "p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors absolute top-2 right-2 opacity-0 group-hover:opacity-100",
1716
- children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
1717
- }
1718
- )
1719
- ] }, idx);
1805
+ ]
1806
+ },
1807
+ idx
1808
+ );
1720
1809
  }),
1721
1810
  !meta.fixedLength && /* @__PURE__ */ jsxs4(
1722
1811
  "button",
@@ -1725,9 +1814,20 @@ function FieldEditor({
1725
1814
  const arr = Array.isArray(value) ? [...value] : [];
1726
1815
  if (meta.itemSchema) {
1727
1816
  const newItem = {};
1817
+ const now = /* @__PURE__ */ new Date();
1818
+ const month = now.toLocaleDateString("en-US", { month: "short" }).toUpperCase();
1819
+ const day = String(now.getDate()).padStart(2, "0");
1820
+ const year = now.getFullYear();
1821
+ const autoDate = `${month} ${day}, ${year}`;
1728
1822
  meta.itemSchema.forEach((s) => {
1729
- newItem[s.key] = "";
1823
+ if (s.key === "publishedAt" || s.key === "date") {
1824
+ newItem[s.key] = autoDate;
1825
+ } else {
1826
+ newItem[s.key] = "";
1827
+ }
1730
1828
  });
1829
+ newItem.publishedAt = autoDate;
1830
+ newItem.createdAt = now.toISOString();
1731
1831
  arr.push(newItem);
1732
1832
  } else {
1733
1833
  arr.push("New Item");
package/dist/types.d.mts CHANGED
@@ -14,6 +14,8 @@ interface EditableMeta {
14
14
  }[];
15
15
  fixedLength?: boolean;
16
16
  search?: boolean;
17
+ reorderable?: boolean;
18
+ sortable?: boolean;
17
19
  collection?: string;
18
20
  max?: number;
19
21
  displayField?: string;
package/dist/types.d.ts CHANGED
@@ -14,6 +14,8 @@ interface EditableMeta {
14
14
  }[];
15
15
  fixedLength?: boolean;
16
16
  search?: boolean;
17
+ reorderable?: boolean;
18
+ sortable?: boolean;
17
19
  collection?: string;
18
20
  max?: number;
19
21
  displayField?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin-lib-cms",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Agnostic Admin CMS Library",
5
5
  "keywords": [
6
6
  "cms",