admin-lib-cms 1.2.0 → 1.2.1

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
@@ -86,15 +86,16 @@ interface EditableListProps<T = any> extends BaseProps {
86
86
  renderList?: (items: T[]) => React.ReactNode;
87
87
  itemSchema?: {
88
88
  key: string;
89
- type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
89
+ type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "number" | "select";
90
90
  label?: string;
91
91
  options?: string[];
92
92
  }[];
93
93
  fixedLength?: boolean;
94
94
  className?: string;
95
95
  listClassName?: string;
96
+ search?: boolean;
96
97
  }
97
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
98
+ declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
98
99
 
99
100
  declare function AdminApp({ apiUrl, projectId, email }: {
100
101
  apiUrl?: string;
package/dist/index.d.ts CHANGED
@@ -86,15 +86,16 @@ interface EditableListProps<T = any> extends BaseProps {
86
86
  renderList?: (items: T[]) => React.ReactNode;
87
87
  itemSchema?: {
88
88
  key: string;
89
- type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
89
+ type: "text" | "textarea" | "boolean" | "icon" | "image" | "file" | "number" | "select";
90
90
  label?: string;
91
91
  options?: string[];
92
92
  }[];
93
93
  fixedLength?: boolean;
94
94
  className?: string;
95
95
  listClassName?: string;
96
+ search?: boolean;
96
97
  }
97
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
98
+ declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, search, }: EditableListProps<T>): react.JSX.Element;
98
99
 
99
100
  declare function AdminApp({ apiUrl, projectId, email }: {
100
101
  apiUrl?: string;
package/dist/index.js CHANGED
@@ -451,13 +451,13 @@ function useSubmit(formId) {
451
451
  // src/editable.tsx
452
452
  var import_react4 = require("react");
453
453
  var import_jsx_runtime4 = require("react/jsx-runtime");
454
- function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength) {
454
+ function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search) {
455
455
  const ctx = useCmsOptional();
456
456
  (0, import_react4.useEffect)(() => {
457
457
  if (!ctx) return;
458
- ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength });
458
+ ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search });
459
459
  return () => ctx.unregisterEditable(id);
460
- }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength]);
460
+ }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search]);
461
461
  return ctx;
462
462
  }
463
463
  function editableClasses(active, selected) {
@@ -480,6 +480,8 @@ function EditableText({
480
480
  const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? String(ctx.overrides[id] ?? "") : children;
481
481
  const active = !!ctx?.editMode;
482
482
  const selected = ctx?.selectedId === id;
483
+ const isEmpty = !value || String(value).trim() === "";
484
+ const renderValue = active && isEmpty ? `[Empty: ${label || id}]` : value;
483
485
  const onClick = (e) => {
484
486
  if (!active || !ctx) return;
485
487
  e.preventDefault();
@@ -489,11 +491,15 @@ function EditableText({
489
491
  return (0, import_react4.createElement)(
490
492
  as,
491
493
  {
492
- className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
494
+ className: [
495
+ className,
496
+ editableClasses(active, selected),
497
+ active && isEmpty ? "opacity-50" : ""
498
+ ].filter(Boolean).join(" "),
493
499
  "data-cms-id": id,
494
500
  onClick: active ? onClick : void 0
495
501
  },
496
- value
502
+ renderValue
497
503
  );
498
504
  }
499
505
  function EditableImage({
@@ -606,6 +612,9 @@ function EditableLink({
606
612
  const isExternal = hrefValue.startsWith("http");
607
613
  const computedTarget = target || (isExternal ? "_blank" : void 0);
608
614
  const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
615
+ const content = typeof children !== "undefined" ? children : textValue;
616
+ const isEmpty = !content || String(content).trim() === "";
617
+ const renderContent = active && isEmpty ? `[Empty Link: ${label || id}]` : content;
609
618
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
610
619
  "a",
611
620
  {
@@ -614,8 +623,12 @@ function EditableLink({
614
623
  rel: computedRel,
615
624
  "data-cms-id": id,
616
625
  onClick: active ? onClick : void 0,
617
- className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
618
- children: typeof children !== "undefined" ? children : textValue
626
+ className: [
627
+ className,
628
+ editableClasses(active, selected),
629
+ active && isEmpty ? "opacity-50" : ""
630
+ ].filter(Boolean).join(" "),
631
+ children: renderContent
619
632
  }
620
633
  );
621
634
  }
@@ -630,9 +643,10 @@ function EditableList({
630
643
  itemSchema,
631
644
  fixedLength,
632
645
  className,
633
- listClassName
646
+ listClassName,
647
+ search
634
648
  }) {
635
- const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength);
649
+ const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search);
636
650
  const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
637
651
  const value = Array.isArray(rawValue) ? rawValue : initialItems;
638
652
  const active = !!ctx?.editMode;
@@ -643,13 +657,20 @@ function EditableList({
643
657
  e.stopPropagation();
644
658
  ctx.setSelectedId(id);
645
659
  };
646
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
660
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
647
661
  "div",
648
662
  {
649
663
  "data-cms-id": id,
650
664
  onClick: active ? onClick : void 0,
651
665
  className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
652
- children: renderList ? renderList(value) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: listClassName, children: renderItem && value.map(renderItem) })
666
+ children: [
667
+ renderList ? renderList(value) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: listClassName, children: renderItem && value.map(renderItem) }),
668
+ active && value.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { padding: "2rem", textAlign: "center", fontSize: "0.875rem", color: "#737373", backgroundColor: "rgba(245, 245, 245, 0.5)", border: "2px dashed #d4d4d4", borderRadius: "0.75rem", width: "100%", cursor: "pointer" }, children: [
669
+ "Empty List ",
670
+ label ? `(${label})` : "",
671
+ " \u2014 Click to add items"
672
+ ] })
673
+ ]
653
674
  }
654
675
  );
655
676
  }
@@ -838,6 +859,61 @@ function SideItem({
838
859
  }
839
860
  );
840
861
  }
862
+ function PageListItem({
863
+ p,
864
+ selected,
865
+ onSelect,
866
+ depth = 0
867
+ }) {
868
+ const [expanded, setExpanded] = (0, import_react5.useState)(false);
869
+ if (p.isSeparator) {
870
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "my-2 border-t border-slate-200/60" });
871
+ }
872
+ const hasChildren = p.children && p.children.length > 0;
873
+ const isSelected = selected?.id === p.id;
874
+ const hasSelectedChild = hasChildren && p.children?.some((child) => child.id === selected?.id);
875
+ (0, import_react5.useEffect)(() => {
876
+ if (hasSelectedChild) {
877
+ setExpanded(true);
878
+ }
879
+ }, [hasSelectedChild]);
880
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { className: "shrink-0 lg:w-full", children: [
881
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex items-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
882
+ "button",
883
+ {
884
+ onClick: () => {
885
+ if (hasChildren) {
886
+ setExpanded(!expanded);
887
+ }
888
+ if (p.path || !hasChildren) {
889
+ onSelect(p);
890
+ }
891
+ },
892
+ className: `flex-1 w-full rounded-lg py-2.5 text-left text-sm transition-all duration-200 ${depth === 0 ? "px-3" : "px-3 ml-2"} ${isSelected ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
893
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between", children: [
894
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
895
+ "div",
896
+ {
897
+ className: `truncate ${isSelected ? "text-slate-900" : "text-slate-700"}`,
898
+ children: p.name
899
+ }
900
+ ),
901
+ hasChildren && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-slate-400", children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { size: 14 }) })
902
+ ] })
903
+ }
904
+ ) }),
905
+ hasChildren && expanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { className: `mt-1 space-y-1 ${depth === 0 ? "ml-4 border-l-2 border-slate-100 pl-1" : "ml-2"}`, children: p.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
906
+ PageListItem,
907
+ {
908
+ p: child,
909
+ selected,
910
+ onSelect,
911
+ depth: depth + 1
912
+ },
913
+ child.id
914
+ )) })
915
+ ] });
916
+ }
841
917
  function PagesSection() {
842
918
  const ctx = useCmsContext();
843
919
  const [selected, setSelected] = (0, import_react5.useState)(
@@ -848,14 +924,15 @@ function PagesSection() {
848
924
  showList && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "w-full lg:w-72 shrink-0 border-b lg:border-b-0 lg:border-r border-slate-200 bg-white/50 p-3 lg:p-4 overflow-x-auto lg:overflow-y-auto hide-scrollbar", children: [
849
925
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500 hidden lg:block", children: "Pages" }),
850
926
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("ul", { className: "flex flex-row lg:flex-col space-x-2 lg:space-x-0 lg:space-y-1", children: [
851
- ctx.config.pages.map((p) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "shrink-0 w-32 lg:w-full", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
852
- "button",
927
+ ctx.config.pages.map((p) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
928
+ PageListItem,
853
929
  {
854
- onClick: () => setSelected(p),
855
- className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selected?.id === p.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
856
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `truncate ${selected?.id === p.id ? "text-slate-900" : "text-slate-700"}`, children: p.name })
857
- }
858
- ) }, p.id)),
930
+ p,
931
+ selected,
932
+ onSelect: setSelected
933
+ },
934
+ p.id
935
+ )),
859
936
  ctx.config.pages.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200 w-full", children: "No pages registered." })
860
937
  ] })
861
938
  ] }),
@@ -1042,20 +1119,38 @@ function PageEditor({ page, showList, onToggleList }) {
1042
1119
  },
1043
1120
  onClose: () => setSelectedId(null)
1044
1121
  }
1045
- ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1046
- SectionAccordion,
1047
- {
1048
- registered,
1049
- onSelect: (id) => {
1050
- setSelectedId(id);
1051
- setDrawerState((prev) => prev === "min" ? "half" : prev);
1052
- iframeRef.current?.contentWindow?.postMessage(
1053
- { __cms: true, type: "cms:select", id },
1054
- "*"
1055
- );
1122
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1123
+ page.hideable && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "px-5 py-4 border-b border-slate-100 bg-slate-50/50", children: [
1124
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center space-x-3", children: [
1125
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1126
+ "input",
1127
+ {
1128
+ type: "checkbox",
1129
+ id: `page-visible-toggle-${page.id}`,
1130
+ checked: ctx.overrides[`page-${page.id}-visible`] !== false,
1131
+ onChange: (e) => updateOverride(`page-${page.id}-visible`, e.target.checked),
1132
+ className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-600 focus:ring-offset-0"
1133
+ }
1134
+ ),
1135
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `page-visible-toggle-${page.id}`, className: "text-sm font-medium text-slate-800 cursor-pointer flex-1", children: "Page is Visible" })
1136
+ ] }),
1137
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-[11px] text-slate-500 mt-1.5 pl-8", children: "If unchecked, this page will be hidden from navigation and URL access." })
1138
+ ] }),
1139
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1140
+ SectionAccordion,
1141
+ {
1142
+ registered,
1143
+ onSelect: (id) => {
1144
+ setSelectedId(id);
1145
+ setDrawerState((prev) => prev === "min" ? "half" : prev);
1146
+ iframeRef.current?.contentWindow?.postMessage(
1147
+ { __cms: true, type: "cms:select", id },
1148
+ "*"
1149
+ );
1150
+ }
1056
1151
  }
1057
- }
1058
- )
1152
+ )
1153
+ ] })
1059
1154
  ] })
1060
1155
  ] })
1061
1156
  ] })
@@ -1146,6 +1241,8 @@ function FieldEditor({
1146
1241
  onClose
1147
1242
  }) {
1148
1243
  const ctx = useCmsContext();
1244
+ const [expandedItems, setExpandedItems] = (0, import_react5.useState)({});
1245
+ const [searchQuery, setSearchQuery] = (0, import_react5.useState)("");
1149
1246
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
1150
1247
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-5", children: [
1151
1248
  /* @__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 }),
@@ -1153,6 +1250,19 @@ function FieldEditor({
1153
1250
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "text-xs font-mono text-slate-400 mt-1", children: meta.id })
1154
1251
  ] }),
1155
1252
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4", children: [
1253
+ meta.type === "boolean" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center space-x-3 py-1", children: [
1254
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1255
+ "input",
1256
+ {
1257
+ type: "checkbox",
1258
+ id: meta.id,
1259
+ checked: value === void 0 ? meta.defaultValue : !!value,
1260
+ onChange: (e) => onChange(e.target.checked),
1261
+ className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-600 focus:ring-offset-0"
1262
+ }
1263
+ ),
1264
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: meta.id, className: "text-sm font-medium text-slate-700 cursor-pointer", children: meta.label || "Enabled" })
1265
+ ] }),
1156
1266
  meta.type === "text" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1157
1267
  "input",
1158
1268
  {
@@ -1303,138 +1413,183 @@ function FieldEditor({
1303
1413
  }
1304
1414
  ),
1305
1415
  meta.type === "list" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4", children: [
1306
- (Array.isArray(value) ? value : []).map((item, idx) => /* @__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: [
1307
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex-1 space-y-3 w-full", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1308
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1309
- schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1310
- SearchableSelect,
1311
- {
1312
- value: String(item?.[schemaField.key] ?? ""),
1313
- options: schemaField.options ?? [],
1314
- placeholder: "Search icon...",
1315
- iconMap: ctx.iconMap,
1316
- onChange: (val) => {
1317
- const arr = Array.isArray(value) ? [...value] : [];
1318
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1319
- onChange(arr);
1320
- }
1321
- }
1322
- ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1323
- "textarea",
1324
- {
1325
- rows: 3,
1326
- value: String(item?.[schemaField.key] ?? ""),
1327
- onChange: (e) => {
1328
- const arr = Array.isArray(value) ? [...value] : [];
1329
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1330
- onChange(arr);
1331
- },
1332
- 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"
1333
- }
1334
- ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1335
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1336
- "input",
1416
+ meta.search && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
1417
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Search, { className: "absolute left-3 top-2.5 h-4 w-4 text-slate-400" }),
1418
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1419
+ "input",
1420
+ {
1421
+ type: "text",
1422
+ placeholder: "Search by title...",
1423
+ value: searchQuery,
1424
+ onChange: (e) => setSearchQuery(e.target.value),
1425
+ className: "w-full rounded-lg border border-slate-200 pl-9 pr-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1426
+ }
1427
+ )
1428
+ ] }),
1429
+ (Array.isArray(value) ? value : []).map((item, idx) => {
1430
+ if (meta.search && searchQuery) {
1431
+ const title = String(item?.title || item?.name || "").toLowerCase();
1432
+ if (!title.includes(searchQuery.toLowerCase())) return null;
1433
+ }
1434
+ const isExpanded = expandedItems[idx] ?? false;
1435
+ 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: [
1436
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex-1 space-y-3 w-full", children: [
1437
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1438
+ "div",
1337
1439
  {
1338
- type: "checkbox",
1339
- checked: !!item?.[schemaField.key],
1340
- onChange: (e) => {
1341
- const arr = Array.isArray(value) ? [...value] : [];
1342
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1343
- onChange(arr);
1344
- },
1345
- className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1440
+ className: "flex items-center justify-between cursor-pointer py-1 select-none",
1441
+ onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1442
+ children: [
1443
+ /* @__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) }),
1444
+ 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" })
1445
+ ]
1346
1446
  }
1347
1447
  ),
1348
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1349
- ] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
1350
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1351
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1352
- "input",
1448
+ 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: [
1449
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1450
+ schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1451
+ SearchableSelect,
1353
1452
  {
1354
- type: "url",
1453
+ value: String(item?.[schemaField.key] ?? ""),
1454
+ options: schemaField.options ?? [],
1455
+ placeholder: "Search icon...",
1456
+ iconMap: ctx.iconMap,
1457
+ onChange: (val) => {
1458
+ const arr = Array.isArray(value) ? [...value] : [];
1459
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1460
+ onChange(arr);
1461
+ }
1462
+ }
1463
+ ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1464
+ "textarea",
1465
+ {
1466
+ rows: 3,
1355
1467
  value: String(item?.[schemaField.key] ?? ""),
1356
1468
  onChange: (e) => {
1357
1469
  const arr = Array.isArray(value) ? [...value] : [];
1358
1470
  arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1359
1471
  onChange(arr);
1360
1472
  },
1361
- placeholder: "https://...",
1362
1473
  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"
1363
1474
  }
1364
- ),
1365
- /* @__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: [
1366
- "Upload",
1475
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1367
1476
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1368
1477
  "input",
1369
1478
  {
1370
- type: "file",
1371
- accept: "image/*",
1372
- className: "hidden",
1479
+ type: "checkbox",
1480
+ checked: !!item?.[schemaField.key],
1373
1481
  onChange: (e) => {
1374
- const file = e.target.files?.[0];
1375
- if (file) {
1376
- void handleImageFile(
1377
- file,
1378
- (url) => {
1379
- const arr = Array.isArray(value) ? [...value] : [];
1380
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1381
- onChange(arr);
1382
- },
1383
- ctx.uploadImage
1384
- );
1385
- }
1482
+ const arr = Array.isArray(value) ? [...value] : [];
1483
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1484
+ onChange(arr);
1485
+ },
1486
+ className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1487
+ }
1488
+ ),
1489
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1490
+ ] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
1491
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1492
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1493
+ "input",
1494
+ {
1495
+ type: "url",
1496
+ value: String(item?.[schemaField.key] ?? ""),
1497
+ onChange: (e) => {
1498
+ const arr = Array.isArray(value) ? [...value] : [];
1499
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1500
+ onChange(arr);
1501
+ },
1502
+ placeholder: "https://...",
1503
+ 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"
1386
1504
  }
1505
+ ),
1506
+ /* @__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: [
1507
+ "Upload",
1508
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1509
+ "input",
1510
+ {
1511
+ type: "file",
1512
+ accept: "image/*",
1513
+ className: "hidden",
1514
+ onChange: (e) => {
1515
+ const file = e.target.files?.[0];
1516
+ if (file) {
1517
+ void handleImageFile(
1518
+ file,
1519
+ (url) => {
1520
+ const arr = Array.isArray(value) ? [...value] : [];
1521
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1522
+ onChange(arr);
1523
+ },
1524
+ ctx.uploadImage
1525
+ );
1526
+ }
1527
+ }
1528
+ }
1529
+ )
1530
+ ] })
1531
+ ] }),
1532
+ 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)(
1533
+ "img",
1534
+ {
1535
+ src: String(item?.[schemaField.key]),
1536
+ alt: "",
1537
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1387
1538
  }
1388
- )
1389
- ] })
1390
- ] }),
1391
- 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)(
1392
- "img",
1539
+ ) }) : null
1540
+ ] }) : schemaField.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1541
+ "select",
1542
+ {
1543
+ value: String(item?.[schemaField.key] ?? ""),
1544
+ onChange: (e) => {
1545
+ const arr = Array.isArray(value) ? [...value] : [];
1546
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1547
+ onChange(arr);
1548
+ },
1549
+ 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",
1550
+ children: schemaField.options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: opt, children: opt }, opt))
1551
+ }
1552
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1553
+ "input",
1554
+ {
1555
+ type: "text",
1556
+ value: String(item?.[schemaField.key] ?? ""),
1557
+ onChange: (e) => {
1558
+ const arr = Array.isArray(value) ? [...value] : [];
1559
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1560
+ onChange(arr);
1561
+ },
1562
+ 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"
1563
+ }
1564
+ )
1565
+ ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1566
+ "input",
1393
1567
  {
1394
- src: String(item?.[schemaField.key]),
1395
- alt: "",
1396
- className: "w-full h-auto max-h-32 object-contain rounded-md"
1568
+ type: "text",
1569
+ value: String(item),
1570
+ onChange: (e) => {
1571
+ const arr = Array.isArray(value) ? [...value] : [];
1572
+ arr[idx] = e.target.value;
1573
+ onChange(arr);
1574
+ },
1575
+ 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"
1397
1576
  }
1398
- ) }) : null
1399
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1400
- "input",
1577
+ ) })
1578
+ ] }),
1579
+ !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1580
+ "button",
1401
1581
  {
1402
- type: "text",
1403
- value: String(item?.[schemaField.key] ?? ""),
1404
- onChange: (e) => {
1582
+ onClick: () => {
1405
1583
  const arr = Array.isArray(value) ? [...value] : [];
1406
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1584
+ arr.splice(idx, 1);
1407
1585
  onChange(arr);
1408
1586
  },
1409
- 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"
1587
+ 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",
1588
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1410
1589
  }
1411
1590
  )
1412
- ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1413
- "input",
1414
- {
1415
- type: "text",
1416
- value: String(item),
1417
- onChange: (e) => {
1418
- const arr = Array.isArray(value) ? [...value] : [];
1419
- arr[idx] = e.target.value;
1420
- onChange(arr);
1421
- },
1422
- 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"
1423
- }
1424
- ) }),
1425
- !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1426
- "button",
1427
- {
1428
- onClick: () => {
1429
- const arr = Array.isArray(value) ? [...value] : [];
1430
- arr.splice(idx, 1);
1431
- onChange(arr);
1432
- },
1433
- 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",
1434
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1435
- }
1436
- )
1437
- ] }, idx)),
1591
+ ] }, idx);
1592
+ }),
1438
1593
  !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1439
1594
  "button",
1440
1595
  {
@@ -1557,7 +1712,7 @@ function CollectionEditor({ collection }) {
1557
1712
  } else if (f.defaultValue !== void 0) {
1558
1713
  base[f.id] = f.defaultValue;
1559
1714
  } else {
1560
- base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : "";
1715
+ base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : f.type === "select" ? f.options?.[0] ?? "" : "";
1561
1716
  }
1562
1717
  });
1563
1718
  setEditing(base);