admin-lib-cms 1.1.9 → 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.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
  }
@@ -681,7 +702,22 @@ function AdminApp({ apiUrl, projectId, email }) {
681
702
  }
682
703
  function AdminAppContent() {
683
704
  const [section, setSection] = (0, import_react5.useState)("pages");
705
+ const [authChecking, setAuthChecking] = (0, import_react5.useState)(true);
706
+ const [authenticated, setAuthenticated] = (0, import_react5.useState)(false);
684
707
  const ctx = useCmsContext();
708
+ (0, import_react5.useEffect)(() => {
709
+ fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
710
+ if (data && data.authenticated) {
711
+ setAuthenticated(true);
712
+ } else {
713
+ window.location.href = "/admin/login";
714
+ }
715
+ }).catch(() => {
716
+ window.location.href = "/admin/login";
717
+ }).finally(() => {
718
+ setAuthChecking(false);
719
+ });
720
+ }, []);
685
721
  let subscriptionCtx = null;
686
722
  try {
687
723
  subscriptionCtx = useSubscription();
@@ -689,6 +725,15 @@ function AdminAppContent() {
689
725
  }
690
726
  const isSubscriptionActive = subscriptionCtx?.isSubscriptionActive ?? true;
691
727
  const daysOverdue = subscriptionCtx?.daysOverdue ?? 0;
728
+ if (authChecking) {
729
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex h-screen w-full items-center justify-center bg-slate-50", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-3 text-slate-500 font-medium text-sm", children: [
730
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "w-5 h-5 border-2 border-indigo-600 border-t-transparent rounded-full animate-spin" }),
731
+ "Authenticating Admin..."
732
+ ] }) });
733
+ }
734
+ if (!authenticated) {
735
+ return null;
736
+ }
692
737
  if (!isSubscriptionActive) {
693
738
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-col lg:flex-row h-screen w-full overflow-hidden bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionPage, {}) });
694
739
  }
@@ -814,6 +859,61 @@ function SideItem({
814
859
  }
815
860
  );
816
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
+ }
817
917
  function PagesSection() {
818
918
  const ctx = useCmsContext();
819
919
  const [selected, setSelected] = (0, import_react5.useState)(
@@ -824,14 +924,15 @@ function PagesSection() {
824
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: [
825
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" }),
826
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: [
827
- 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)(
828
- "button",
927
+ ctx.config.pages.map((p) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
928
+ PageListItem,
829
929
  {
830
- onClick: () => setSelected(p),
831
- 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"}`,
832
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `truncate ${selected?.id === p.id ? "text-slate-900" : "text-slate-700"}`, children: p.name })
833
- }
834
- ) }, p.id)),
930
+ p,
931
+ selected,
932
+ onSelect: setSelected
933
+ },
934
+ p.id
935
+ )),
835
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." })
836
937
  ] })
837
938
  ] }),
@@ -1018,20 +1119,38 @@ function PageEditor({ page, showList, onToggleList }) {
1018
1119
  },
1019
1120
  onClose: () => setSelectedId(null)
1020
1121
  }
1021
- ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1022
- SectionAccordion,
1023
- {
1024
- registered,
1025
- onSelect: (id) => {
1026
- setSelectedId(id);
1027
- setDrawerState((prev) => prev === "min" ? "half" : prev);
1028
- iframeRef.current?.contentWindow?.postMessage(
1029
- { __cms: true, type: "cms:select", id },
1030
- "*"
1031
- );
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
+ }
1032
1151
  }
1033
- }
1034
- )
1152
+ )
1153
+ ] })
1035
1154
  ] })
1036
1155
  ] })
1037
1156
  ] })
@@ -1122,6 +1241,8 @@ function FieldEditor({
1122
1241
  onClose
1123
1242
  }) {
1124
1243
  const ctx = useCmsContext();
1244
+ const [expandedItems, setExpandedItems] = (0, import_react5.useState)({});
1245
+ const [searchQuery, setSearchQuery] = (0, import_react5.useState)("");
1125
1246
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
1126
1247
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-5", children: [
1127
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 }),
@@ -1129,6 +1250,19 @@ function FieldEditor({
1129
1250
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "text-xs font-mono text-slate-400 mt-1", children: meta.id })
1130
1251
  ] }),
1131
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
+ ] }),
1132
1266
  meta.type === "text" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1133
1267
  "input",
1134
1268
  {
@@ -1279,138 +1413,183 @@ function FieldEditor({
1279
1413
  }
1280
1414
  ),
1281
1415
  meta.type === "list" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4", children: [
1282
- (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: [
1283
- /* @__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: [
1284
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1285
- schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1286
- SearchableSelect,
1287
- {
1288
- value: String(item?.[schemaField.key] ?? ""),
1289
- options: schemaField.options ?? [],
1290
- placeholder: "Search icon...",
1291
- iconMap: ctx.iconMap,
1292
- onChange: (val) => {
1293
- const arr = Array.isArray(value) ? [...value] : [];
1294
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1295
- onChange(arr);
1296
- }
1297
- }
1298
- ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1299
- "textarea",
1300
- {
1301
- rows: 3,
1302
- value: String(item?.[schemaField.key] ?? ""),
1303
- onChange: (e) => {
1304
- const arr = Array.isArray(value) ? [...value] : [];
1305
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1306
- onChange(arr);
1307
- },
1308
- 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"
1309
- }
1310
- ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1311
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1312
- "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",
1313
1439
  {
1314
- type: "checkbox",
1315
- checked: !!item?.[schemaField.key],
1316
- onChange: (e) => {
1317
- const arr = Array.isArray(value) ? [...value] : [];
1318
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1319
- onChange(arr);
1320
- },
1321
- 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
+ ]
1322
1446
  }
1323
1447
  ),
1324
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1325
- ] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
1326
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1327
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1328
- "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,
1329
1452
  {
1330
- 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,
1331
1467
  value: String(item?.[schemaField.key] ?? ""),
1332
1468
  onChange: (e) => {
1333
1469
  const arr = Array.isArray(value) ? [...value] : [];
1334
1470
  arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1335
1471
  onChange(arr);
1336
1472
  },
1337
- placeholder: "https://...",
1338
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"
1339
1474
  }
1340
- ),
1341
- /* @__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: [
1342
- "Upload",
1475
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1343
1476
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1344
1477
  "input",
1345
1478
  {
1346
- type: "file",
1347
- accept: "image/*",
1348
- className: "hidden",
1479
+ type: "checkbox",
1480
+ checked: !!item?.[schemaField.key],
1349
1481
  onChange: (e) => {
1350
- const file = e.target.files?.[0];
1351
- if (file) {
1352
- void handleImageFile(
1353
- file,
1354
- (url) => {
1355
- const arr = Array.isArray(value) ? [...value] : [];
1356
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1357
- onChange(arr);
1358
- },
1359
- ctx.uploadImage
1360
- );
1361
- }
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"
1362
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"
1363
1538
  }
1364
- )
1365
- ] })
1366
- ] }),
1367
- 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)(
1368
- "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",
1369
1567
  {
1370
- src: String(item?.[schemaField.key]),
1371
- alt: "",
1372
- 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"
1373
1576
  }
1374
- ) }) : null
1375
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1376
- "input",
1577
+ ) })
1578
+ ] }),
1579
+ !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1580
+ "button",
1377
1581
  {
1378
- type: "text",
1379
- value: String(item?.[schemaField.key] ?? ""),
1380
- onChange: (e) => {
1582
+ onClick: () => {
1381
1583
  const arr = Array.isArray(value) ? [...value] : [];
1382
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1584
+ arr.splice(idx, 1);
1383
1585
  onChange(arr);
1384
1586
  },
1385
- 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" })
1386
1589
  }
1387
1590
  )
1388
- ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1389
- "input",
1390
- {
1391
- type: "text",
1392
- value: String(item),
1393
- onChange: (e) => {
1394
- const arr = Array.isArray(value) ? [...value] : [];
1395
- arr[idx] = e.target.value;
1396
- onChange(arr);
1397
- },
1398
- 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"
1399
- }
1400
- ) }),
1401
- !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1402
- "button",
1403
- {
1404
- onClick: () => {
1405
- const arr = Array.isArray(value) ? [...value] : [];
1406
- arr.splice(idx, 1);
1407
- onChange(arr);
1408
- },
1409
- 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",
1410
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1411
- }
1412
- )
1413
- ] }, idx)),
1591
+ ] }, idx);
1592
+ }),
1414
1593
  !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1415
1594
  "button",
1416
1595
  {
@@ -1533,7 +1712,7 @@ function CollectionEditor({ collection }) {
1533
1712
  } else if (f.defaultValue !== void 0) {
1534
1713
  base[f.id] = f.defaultValue;
1535
1714
  } else {
1536
- 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] ?? "" : "";
1537
1716
  }
1538
1717
  });
1539
1718
  setEditing(base);
@@ -2776,7 +2955,8 @@ async function sendEmailNotification(content, apiUrl) {
2776
2955
  }
2777
2956
  return result;
2778
2957
  } else {
2779
- console.warn("Email API endpoint error:", response.status);
2958
+ const errText = await response.text().catch(() => "");
2959
+ console.warn("Email API endpoint error:", response.status, errText);
2780
2960
  }
2781
2961
  } catch (error) {
2782
2962
  console.error("Error sending email:", error);