admin-lib-cms 1.2.2 → 1.2.3

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.
Files changed (3) hide show
  1. package/dist/index.js +212 -128
  2. package/dist/index.mjs +214 -129
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1372,6 +1372,8 @@ function FieldEditor({
1372
1372
  const ctx = useCmsContext();
1373
1373
  const [expandedItems, setExpandedItems] = (0, import_react5.useState)({});
1374
1374
  const [searchQuery, setSearchQuery] = (0, import_react5.useState)("");
1375
+ const [listDragIdx, setListDragIdx] = (0, import_react5.useState)(null);
1376
+ const [listDragOverIdx, setListDragOverIdx] = (0, import_react5.useState)(null);
1375
1377
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
1376
1378
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-5", children: [
1377
1379
  /* @__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 +1563,245 @@ function FieldEditor({
1561
1563
  if (!title.includes(searchQuery.toLowerCase())) return null;
1562
1564
  }
1563
1565
  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
- ]
1566
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1567
+ "div",
1568
+ {
1569
+ draggable: true,
1570
+ onDragStart: (e) => {
1571
+ setListDragIdx(idx);
1572
+ e.dataTransfer.effectAllowed = "move";
1573
+ },
1574
+ onDragOver: (e) => {
1575
+ e.preventDefault();
1576
+ e.dataTransfer.dropEffect = "move";
1577
+ setListDragOverIdx(idx);
1578
+ },
1579
+ onDragEnd: () => {
1580
+ setListDragIdx(null);
1581
+ setListDragOverIdx(null);
1582
+ },
1583
+ onDrop: (e) => {
1584
+ e.preventDefault();
1585
+ if (listDragIdx === null || listDragIdx === idx) {
1586
+ setListDragOverIdx(null);
1587
+ return;
1575
1588
  }
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",
1589
+ const arr = Array.isArray(value) ? [...value] : [];
1590
+ const [moved] = arr.splice(listDragIdx, 1);
1591
+ arr.splice(idx, 0, moved);
1592
+ onChange(arr);
1593
+ setListDragIdx(null);
1594
+ 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" : ""}`,
1597
+ children: [
1598
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1599
+ "div",
1594
1600
  {
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"
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
+ ]
1603
1644
  }
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",
1645
+ ),
1646
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 w-full min-w-0", children: [
1647
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1648
+ "div",
1607
1649
  {
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"
1650
+ className: "flex items-center justify-between cursor-pointer py-1 select-none",
1651
+ onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1652
+ children: [
1653
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "font-semibold text-slate-700 text-sm flex-1 truncate pr-6 pl-0.5 group-hover:pl-20 transition-all duration-200", children: meta.itemSchema ? item?.title || item?.name || `Item ${idx + 1}` : String(item) }),
1654
+ 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
+ ]
1616
1656
  }
1617
1657
  ),
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",
1658
+ 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: [
1659
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1660
+ schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1661
+ SearchableSelect,
1623
1662
  {
1624
- type: "url",
1663
+ value: String(item?.[schemaField.key] ?? ""),
1664
+ options: schemaField.options ?? [],
1665
+ placeholder: "Search icon...",
1666
+ iconMap: ctx.iconMap,
1667
+ onChange: (val) => {
1668
+ const arr = Array.isArray(value) ? [...value] : [];
1669
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1670
+ onChange(arr);
1671
+ }
1672
+ }
1673
+ ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1674
+ "textarea",
1675
+ {
1676
+ rows: 3,
1625
1677
  value: String(item?.[schemaField.key] ?? ""),
1626
1678
  onChange: (e) => {
1627
1679
  const arr = Array.isArray(value) ? [...value] : [];
1628
1680
  arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1629
1681
  onChange(arr);
1630
1682
  },
1631
- placeholder: "https://...",
1632
1683
  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
1684
  }
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",
1685
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1637
1686
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1638
1687
  "input",
1639
1688
  {
1640
- type: "file",
1641
- accept: "image/*",
1642
- className: "hidden",
1689
+ type: "checkbox",
1690
+ checked: !!item?.[schemaField.key],
1643
1691
  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
- }
1692
+ const arr = Array.isArray(value) ? [...value] : [];
1693
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1694
+ onChange(arr);
1695
+ },
1696
+ className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1697
+ }
1698
+ ),
1699
+ /* @__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: [
1701
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1702
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1703
+ "input",
1704
+ {
1705
+ type: "url",
1706
+ value: String(item?.[schemaField.key] ?? ""),
1707
+ onChange: (e) => {
1708
+ const arr = Array.isArray(value) ? [...value] : [];
1709
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1710
+ onChange(arr);
1711
+ },
1712
+ placeholder: "https://...",
1713
+ 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
1714
  }
1715
+ ),
1716
+ /* @__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: [
1717
+ "Upload",
1718
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1719
+ "input",
1720
+ {
1721
+ type: "file",
1722
+ accept: "image/*",
1723
+ className: "hidden",
1724
+ onChange: (e) => {
1725
+ const file = e.target.files?.[0];
1726
+ if (file) {
1727
+ void handleImageFile(
1728
+ file,
1729
+ (url) => {
1730
+ const arr = Array.isArray(value) ? [...value] : [];
1731
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1732
+ onChange(arr);
1733
+ },
1734
+ ctx.uploadImage
1735
+ );
1736
+ }
1737
+ }
1738
+ }
1739
+ )
1740
+ ] })
1741
+ ] }),
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)(
1743
+ "img",
1744
+ {
1745
+ src: String(item?.[schemaField.key]),
1746
+ alt: "",
1747
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1657
1748
  }
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",
1749
+ ) }) : null
1750
+ ] }) : schemaField.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1751
+ "select",
1752
+ {
1753
+ value: String(item?.[schemaField.key] ?? ""),
1754
+ onChange: (e) => {
1755
+ const arr = Array.isArray(value) ? [...value] : [];
1756
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1757
+ onChange(arr);
1758
+ },
1759
+ 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",
1760
+ children: schemaField.options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: opt, children: opt }, opt))
1761
+ }
1762
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1763
+ "input",
1764
+ {
1765
+ type: "text",
1766
+ value: String(item?.[schemaField.key] ?? ""),
1767
+ onChange: (e) => {
1768
+ const arr = Array.isArray(value) ? [...value] : [];
1769
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1770
+ onChange(arr);
1771
+ },
1772
+ 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"
1773
+ }
1774
+ )
1775
+ ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1776
+ "input",
1663
1777
  {
1664
- src: String(item?.[schemaField.key]),
1665
- alt: "",
1666
- className: "w-full h-auto max-h-32 object-contain rounded-md"
1778
+ type: "text",
1779
+ value: String(item),
1780
+ onChange: (e) => {
1781
+ const arr = Array.isArray(value) ? [...value] : [];
1782
+ arr[idx] = e.target.value;
1783
+ onChange(arr);
1784
+ },
1785
+ 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
1786
  }
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",
1787
+ ) })
1788
+ ] }),
1789
+ !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1790
+ "button",
1683
1791
  {
1684
- type: "text",
1685
- value: String(item?.[schemaField.key] ?? ""),
1686
- onChange: (e) => {
1792
+ onClick: () => {
1687
1793
  const arr = Array.isArray(value) ? [...value] : [];
1688
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1794
+ arr.splice(idx, 1);
1689
1795
  onChange(arr);
1690
1796
  },
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"
1797
+ 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",
1798
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1692
1799
  }
1693
1800
  )
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);
1801
+ ]
1802
+ },
1803
+ idx
1804
+ );
1721
1805
  }),
1722
1806
  !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1723
1807
  "button",
package/dist/index.mjs CHANGED
@@ -736,7 +736,8 @@ import {
736
736
  SlidersHorizontal,
737
737
  LogOut,
738
738
  ExternalLink as ExternalLink2,
739
- Check
739
+ Check,
740
+ GripVertical
740
741
  } from "lucide-react";
741
742
  import { CreditCard as CreditCard2 } from "lucide-react";
742
743
  import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
@@ -1371,6 +1372,8 @@ function FieldEditor({
1371
1372
  const ctx = useCmsContext();
1372
1373
  const [expandedItems, setExpandedItems] = useState5({});
1373
1374
  const [searchQuery, setSearchQuery] = useState5("");
1375
+ const [listDragIdx, setListDragIdx] = useState5(null);
1376
+ const [listDragOverIdx, setListDragOverIdx] = useState5(null);
1374
1377
  return /* @__PURE__ */ jsxs4("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
1375
1378
  /* @__PURE__ */ jsxs4("div", { className: "mb-5", children: [
1376
1379
  /* @__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 +1563,245 @@ function FieldEditor({
1560
1563
  if (!title.includes(searchQuery.toLowerCase())) return null;
1561
1564
  }
1562
1565
  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
- ]
1566
+ return /* @__PURE__ */ jsxs4(
1567
+ "div",
1568
+ {
1569
+ draggable: true,
1570
+ onDragStart: (e) => {
1571
+ setListDragIdx(idx);
1572
+ e.dataTransfer.effectAllowed = "move";
1573
+ },
1574
+ onDragOver: (e) => {
1575
+ e.preventDefault();
1576
+ e.dataTransfer.dropEffect = "move";
1577
+ setListDragOverIdx(idx);
1578
+ },
1579
+ onDragEnd: () => {
1580
+ setListDragIdx(null);
1581
+ setListDragOverIdx(null);
1582
+ },
1583
+ onDrop: (e) => {
1584
+ e.preventDefault();
1585
+ if (listDragIdx === null || listDragIdx === idx) {
1586
+ setListDragOverIdx(null);
1587
+ return;
1574
1588
  }
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",
1589
+ const arr = Array.isArray(value) ? [...value] : [];
1590
+ const [moved] = arr.splice(listDragIdx, 1);
1591
+ arr.splice(idx, 0, moved);
1592
+ onChange(arr);
1593
+ setListDragIdx(null);
1594
+ 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" : ""}`,
1597
+ children: [
1598
+ /* @__PURE__ */ jsxs4(
1599
+ "div",
1593
1600
  {
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"
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
+ ]
1602
1644
  }
1603
- ) : schemaField.type === "boolean" ? /* @__PURE__ */ jsxs4("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1604
- /* @__PURE__ */ jsx5(
1605
- "input",
1645
+ ),
1646
+ /* @__PURE__ */ jsxs4("div", { className: "space-y-3 w-full min-w-0", children: [
1647
+ /* @__PURE__ */ jsxs4(
1648
+ "div",
1606
1649
  {
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"
1650
+ className: "flex items-center justify-between cursor-pointer py-1 select-none",
1651
+ onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1652
+ children: [
1653
+ /* @__PURE__ */ jsx5("div", { className: "font-semibold text-slate-700 text-sm flex-1 truncate pr-6 pl-0.5 group-hover:pl-20 transition-all duration-200", children: meta.itemSchema ? item?.title || item?.name || `Item ${idx + 1}` : String(item) }),
1654
+ 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
+ ]
1615
1656
  }
1616
1657
  ),
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",
1658
+ 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: [
1659
+ /* @__PURE__ */ jsx5("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1660
+ schemaField.type === "icon" ? /* @__PURE__ */ jsx5(
1661
+ SearchableSelect,
1622
1662
  {
1623
- type: "url",
1663
+ value: String(item?.[schemaField.key] ?? ""),
1664
+ options: schemaField.options ?? [],
1665
+ placeholder: "Search icon...",
1666
+ iconMap: ctx.iconMap,
1667
+ onChange: (val) => {
1668
+ const arr = Array.isArray(value) ? [...value] : [];
1669
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1670
+ onChange(arr);
1671
+ }
1672
+ }
1673
+ ) : schemaField.type === "textarea" ? /* @__PURE__ */ jsx5(
1674
+ "textarea",
1675
+ {
1676
+ rows: 3,
1624
1677
  value: String(item?.[schemaField.key] ?? ""),
1625
1678
  onChange: (e) => {
1626
1679
  const arr = Array.isArray(value) ? [...value] : [];
1627
1680
  arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1628
1681
  onChange(arr);
1629
1682
  },
1630
- placeholder: "https://...",
1631
1683
  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
1684
  }
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",
1685
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ jsxs4("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1636
1686
  /* @__PURE__ */ jsx5(
1637
1687
  "input",
1638
1688
  {
1639
- type: "file",
1640
- accept: "image/*",
1641
- className: "hidden",
1689
+ type: "checkbox",
1690
+ checked: !!item?.[schemaField.key],
1642
1691
  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
- }
1692
+ const arr = Array.isArray(value) ? [...value] : [];
1693
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1694
+ onChange(arr);
1695
+ },
1696
+ className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1697
+ }
1698
+ ),
1699
+ /* @__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: [
1701
+ /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
1702
+ /* @__PURE__ */ jsx5(
1703
+ "input",
1704
+ {
1705
+ type: "url",
1706
+ value: String(item?.[schemaField.key] ?? ""),
1707
+ onChange: (e) => {
1708
+ const arr = Array.isArray(value) ? [...value] : [];
1709
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1710
+ onChange(arr);
1711
+ },
1712
+ placeholder: "https://...",
1713
+ 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
1714
  }
1715
+ ),
1716
+ /* @__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: [
1717
+ "Upload",
1718
+ /* @__PURE__ */ jsx5(
1719
+ "input",
1720
+ {
1721
+ type: "file",
1722
+ accept: "image/*",
1723
+ className: "hidden",
1724
+ onChange: (e) => {
1725
+ const file = e.target.files?.[0];
1726
+ if (file) {
1727
+ void handleImageFile(
1728
+ file,
1729
+ (url) => {
1730
+ const arr = Array.isArray(value) ? [...value] : [];
1731
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1732
+ onChange(arr);
1733
+ },
1734
+ ctx.uploadImage
1735
+ );
1736
+ }
1737
+ }
1738
+ }
1739
+ )
1740
+ ] })
1741
+ ] }),
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(
1743
+ "img",
1744
+ {
1745
+ src: String(item?.[schemaField.key]),
1746
+ alt: "",
1747
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1656
1748
  }
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",
1749
+ ) }) : null
1750
+ ] }) : schemaField.type === "select" ? /* @__PURE__ */ jsx5(
1751
+ "select",
1752
+ {
1753
+ value: String(item?.[schemaField.key] ?? ""),
1754
+ onChange: (e) => {
1755
+ const arr = Array.isArray(value) ? [...value] : [];
1756
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1757
+ onChange(arr);
1758
+ },
1759
+ 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",
1760
+ children: schemaField.options?.map((opt) => /* @__PURE__ */ jsx5("option", { value: opt, children: opt }, opt))
1761
+ }
1762
+ ) : /* @__PURE__ */ jsx5(
1763
+ "input",
1764
+ {
1765
+ type: "text",
1766
+ value: String(item?.[schemaField.key] ?? ""),
1767
+ onChange: (e) => {
1768
+ const arr = Array.isArray(value) ? [...value] : [];
1769
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1770
+ onChange(arr);
1771
+ },
1772
+ 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"
1773
+ }
1774
+ )
1775
+ ] }, schemaField.key)) : /* @__PURE__ */ jsx5(
1776
+ "input",
1662
1777
  {
1663
- src: String(item?.[schemaField.key]),
1664
- alt: "",
1665
- className: "w-full h-auto max-h-32 object-contain rounded-md"
1778
+ type: "text",
1779
+ value: String(item),
1780
+ onChange: (e) => {
1781
+ const arr = Array.isArray(value) ? [...value] : [];
1782
+ arr[idx] = e.target.value;
1783
+ onChange(arr);
1784
+ },
1785
+ 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
1786
  }
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",
1787
+ ) })
1788
+ ] }),
1789
+ !meta.fixedLength && /* @__PURE__ */ jsx5(
1790
+ "button",
1682
1791
  {
1683
- type: "text",
1684
- value: String(item?.[schemaField.key] ?? ""),
1685
- onChange: (e) => {
1792
+ onClick: () => {
1686
1793
  const arr = Array.isArray(value) ? [...value] : [];
1687
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1794
+ arr.splice(idx, 1);
1688
1795
  onChange(arr);
1689
1796
  },
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"
1797
+ 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",
1798
+ children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
1691
1799
  }
1692
1800
  )
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);
1801
+ ]
1802
+ },
1803
+ idx
1804
+ );
1720
1805
  }),
1721
1806
  !meta.fixedLength && /* @__PURE__ */ jsxs4(
1722
1807
  "button",
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.3",
4
4
  "description": "Agnostic Admin CMS Library",
5
5
  "keywords": [
6
6
  "cms",