admin-lib-cms 1.0.6 → 1.0.8

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
@@ -67,7 +67,8 @@ interface EditableLinkProps extends BaseProps {
67
67
  declare function EditableLink({ id, label, section, pageId, href, children, className, }: EditableLinkProps): react.JSX.Element;
68
68
  interface EditableListProps<T = any> extends BaseProps {
69
69
  initialItems: T[];
70
- renderItem: (item: T, index: number) => React.ReactNode;
70
+ renderItem?: (item: T, index: number) => React.ReactNode;
71
+ renderList?: (items: T[]) => React.ReactNode;
71
72
  itemSchema?: {
72
73
  key: string;
73
74
  type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
@@ -78,7 +79,7 @@ interface EditableListProps<T = any> extends BaseProps {
78
79
  className?: string;
79
80
  listClassName?: string;
80
81
  }
81
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
82
+ declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
82
83
 
83
84
  declare function AdminApp({ apiUrl, projectId, email }: {
84
85
  apiUrl?: string;
package/dist/index.d.ts CHANGED
@@ -67,7 +67,8 @@ interface EditableLinkProps extends BaseProps {
67
67
  declare function EditableLink({ id, label, section, pageId, href, children, className, }: EditableLinkProps): react.JSX.Element;
68
68
  interface EditableListProps<T = any> extends BaseProps {
69
69
  initialItems: T[];
70
- renderItem: (item: T, index: number) => React.ReactNode;
70
+ renderItem?: (item: T, index: number) => React.ReactNode;
71
+ renderList?: (items: T[]) => React.ReactNode;
71
72
  itemSchema?: {
72
73
  key: string;
73
74
  type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
@@ -78,7 +79,7 @@ interface EditableListProps<T = any> extends BaseProps {
78
79
  className?: string;
79
80
  listClassName?: string;
80
81
  }
81
- declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
82
+ declare function EditableList<T = any>({ id, label, section, pageId, initialItems, renderItem, renderList, itemSchema, fixedLength, className, listClassName, }: EditableListProps<T>): react.JSX.Element;
82
83
 
83
84
  declare function AdminApp({ apiUrl, projectId, email }: {
84
85
  apiUrl?: string;
package/dist/index.js CHANGED
@@ -343,6 +343,7 @@ function EditableList({
343
343
  pageId,
344
344
  initialItems,
345
345
  renderItem,
346
+ renderList,
346
347
  itemSchema,
347
348
  fixedLength,
348
349
  className,
@@ -365,7 +366,7 @@ function EditableList({
365
366
  "data-cms-id": id,
366
367
  onClick: active ? onClick : void 0,
367
368
  className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
368
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: listClassName, children: value.map(renderItem) })
369
+ children: renderList ? renderList(value) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: listClassName, children: renderItem && value.map(renderItem) })
369
370
  }
370
371
  );
371
372
  }
@@ -1160,6 +1161,56 @@ function FieldEditor({
1160
1161
  }
1161
1162
  ),
1162
1163
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1164
+ ] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
1165
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1166
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1167
+ "input",
1168
+ {
1169
+ type: "url",
1170
+ value: String(item?.[schemaField.key] ?? ""),
1171
+ onChange: (e) => {
1172
+ const arr = Array.isArray(value) ? [...value] : [];
1173
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1174
+ onChange(arr);
1175
+ },
1176
+ placeholder: "https://...",
1177
+ 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"
1178
+ }
1179
+ ),
1180
+ /* @__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: [
1181
+ "Upload",
1182
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1183
+ "input",
1184
+ {
1185
+ type: "file",
1186
+ accept: "image/*",
1187
+ className: "hidden",
1188
+ onChange: (e) => {
1189
+ const file = e.target.files?.[0];
1190
+ if (file) {
1191
+ void handleImageFile(
1192
+ file,
1193
+ (url) => {
1194
+ const arr = Array.isArray(value) ? [...value] : [];
1195
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1196
+ onChange(arr);
1197
+ },
1198
+ ctx.uploadImage
1199
+ );
1200
+ }
1201
+ }
1202
+ }
1203
+ )
1204
+ ] })
1205
+ ] }),
1206
+ 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)(
1207
+ "img",
1208
+ {
1209
+ src: String(item?.[schemaField.key]),
1210
+ alt: "",
1211
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1212
+ }
1213
+ ) }) : null
1163
1214
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1164
1215
  "input",
1165
1216
  {
package/dist/index.mjs CHANGED
@@ -315,6 +315,7 @@ function EditableList({
315
315
  pageId,
316
316
  initialItems,
317
317
  renderItem,
318
+ renderList,
318
319
  itemSchema,
319
320
  fixedLength,
320
321
  className,
@@ -337,7 +338,7 @@ function EditableList({
337
338
  "data-cms-id": id,
338
339
  onClick: active ? onClick : void 0,
339
340
  className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
340
- children: /* @__PURE__ */ jsx2("div", { className: listClassName, children: value.map(renderItem) })
341
+ children: renderList ? renderList(value) : /* @__PURE__ */ jsx2("div", { className: listClassName, children: renderItem && value.map(renderItem) })
341
342
  }
342
343
  );
343
344
  }
@@ -1157,6 +1158,56 @@ function FieldEditor({
1157
1158
  }
1158
1159
  ),
1159
1160
  /* @__PURE__ */ jsx5("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1161
+ ] }) : schemaField.type === "image" ? /* @__PURE__ */ jsxs2("div", { className: "space-y-3 mt-1", children: [
1162
+ /* @__PURE__ */ jsxs2("div", { className: "flex gap-2", children: [
1163
+ /* @__PURE__ */ jsx5(
1164
+ "input",
1165
+ {
1166
+ type: "url",
1167
+ value: String(item?.[schemaField.key] ?? ""),
1168
+ onChange: (e) => {
1169
+ const arr = Array.isArray(value) ? [...value] : [];
1170
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1171
+ onChange(arr);
1172
+ },
1173
+ placeholder: "https://...",
1174
+ 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"
1175
+ }
1176
+ ),
1177
+ /* @__PURE__ */ jsxs2("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: [
1178
+ "Upload",
1179
+ /* @__PURE__ */ jsx5(
1180
+ "input",
1181
+ {
1182
+ type: "file",
1183
+ accept: "image/*",
1184
+ className: "hidden",
1185
+ onChange: (e) => {
1186
+ const file = e.target.files?.[0];
1187
+ if (file) {
1188
+ void handleImageFile(
1189
+ file,
1190
+ (url) => {
1191
+ const arr = Array.isArray(value) ? [...value] : [];
1192
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1193
+ onChange(arr);
1194
+ },
1195
+ ctx.uploadImage
1196
+ );
1197
+ }
1198
+ }
1199
+ }
1200
+ )
1201
+ ] })
1202
+ ] }),
1203
+ 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(
1204
+ "img",
1205
+ {
1206
+ src: String(item?.[schemaField.key]),
1207
+ alt: "",
1208
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1209
+ }
1210
+ ) }) : null
1160
1211
  ] }) : /* @__PURE__ */ jsx5(
1161
1212
  "input",
1162
1213
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin-lib-cms",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Agnostic Admin CMS Library",
5
5
  "keywords": [
6
6
  "cms",
@@ -77,7 +77,7 @@
77
77
  "typescript": "^5.0.0"
78
78
  },
79
79
  "peerDependencies": {
80
- "@sanity/client": "^6.15.0",
80
+ "@sanity/client": "^6.15.0 || ^7.0.0",
81
81
  "next": "^14.0.0 || ^15.0.0 || ^16.0.0",
82
82
  "react": "^18.0.0 || ^19.0.0",
83
83
  "react-dom": "^18.0.0 || ^19.0.0"