medusa-plugin-content 0.2.0 → 0.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.
@@ -1,8 +1,8 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import React, { useState, useEffect, useMemo, useRef, useCallback } from "react";
2
+ import React, { useState, useEffect, useRef, useMemo, useCallback } from "react";
3
3
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
4
- import { FocusModal, Heading, Text, Select, Input, toast, Container, Button, Badge, Switch, Label, createDataTableColumnHelper, createDataTableCommandHelper, usePrompt, useDataTable, DataTable, DropdownMenu, IconButton, clx, Drawer, Textarea, DatePicker, Tooltip } from "@medusajs/ui";
5
- import { ImageSparkle, ChevronLeft, ChevronRight, Trash, Plus, PencilSquare, EllipsisHorizontal, ArrowUpRightOnBox, ArchiveBox, PaperPlane } from "@medusajs/icons";
4
+ import { FocusModal, Heading, Text, Select, Input, toast, Container, Button, Switch, Label, createDataTableColumnHelper, createDataTableCommandHelper, usePrompt, Badge, useDataTable, DataTable, DropdownMenu, IconButton, clx, Drawer, Textarea, DatePicker, Tooltip } from "@medusajs/ui";
5
+ import { ImageSparkle, Trash, Plus, PencilSquare, ChevronLeft, ChevronRight, EllipsisHorizontal, ArrowUpRightOnBox, ArchiveBox, PaperPlane } from "@medusajs/icons";
6
6
  import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
7
7
  import Medusa from "@medusajs/js-sdk";
8
8
  import { useNavigate, Link, useParams, useBlocker } from "react-router-dom";
@@ -291,136 +291,6 @@ const ProductVariantImageLibraryWidget = ({
291
291
  )
292
292
  ] });
293
293
  };
294
- const config$2 = defineRouteConfig({
295
- label: "Image Gallery",
296
- icon: ImageSparkle,
297
- rank: 7
298
- });
299
- const handle$4 = { breadcrumb: () => "Image Gallery" };
300
- const STATUS_COLORS$2 = {
301
- published: "green",
302
- draft: "orange",
303
- archived: "grey"
304
- };
305
- const PAGE_SIZE = 48;
306
- const ImageGalleryPage = () => {
307
- const navigate = useNavigate();
308
- const [selectedCollectionId, setSelectedCollectionId] = useState();
309
- const [search, setSearch] = useState("");
310
- const [pageIndex, setPageIndex] = useState(0);
311
- const { data: collectionsData } = useContentCollections({ limit: 100 });
312
- const imgCollections = ((collectionsData == null ? void 0 : collectionsData.content_collections) ?? []).filter((t2) => t2.format === "img");
313
- useEffect(() => {
314
- if (imgCollections.length > 0 && !selectedCollectionId) {
315
- setSelectedCollectionId(imgCollections[0].id);
316
- }
317
- }, [imgCollections.length]);
318
- useEffect(() => {
319
- setPageIndex(0);
320
- }, [selectedCollectionId, search]);
321
- const offset = useMemo(() => pageIndex * PAGE_SIZE, [pageIndex]);
322
- const { data: itemsData, isLoading } = useContentItems(
323
- selectedCollectionId,
324
- selectedCollectionId ? { limit: PAGE_SIZE, offset, q: search || void 0 } : {}
325
- );
326
- const items = (itemsData == null ? void 0 : itemsData.content_items) ?? [];
327
- const total = (itemsData == null ? void 0 : itemsData.count) ?? 0;
328
- const pageCount = Math.ceil(total / PAGE_SIZE);
329
- return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
330
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start justify-between gap-2 px-6 py-4 md:flex-row md:items-center", children: [
331
- /* @__PURE__ */ jsx(Heading, { children: "Image Gallery" }),
332
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
333
- /* @__PURE__ */ jsx(
334
- Input,
335
- {
336
- type: "search",
337
- placeholder: "Search images...",
338
- value: search,
339
- onChange: (e2) => setSearch(e2.target.value),
340
- className: "w-48 md:w-64"
341
- }
342
- ),
343
- imgCollections.length > 1 && /* @__PURE__ */ jsxs(
344
- Select,
345
- {
346
- value: selectedCollectionId ?? "",
347
- onValueChange: setSelectedCollectionId,
348
- children: [
349
- /* @__PURE__ */ jsx(Select.Trigger, { className: "w-48", children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select library..." }) }),
350
- /* @__PURE__ */ jsx(Select.Content, { children: imgCollections.map((t2) => /* @__PURE__ */ jsx(Select.Item, { value: t2.id, children: t2.label }, t2.id)) })
351
- ]
352
- }
353
- )
354
- ] })
355
- ] }),
356
- imgCollections.length === 0 ? /* @__PURE__ */ jsx(Text, { className: "px-6 py-8 text-center text-ui-fg-muted", children: "No image content collections found." }) : isLoading ? /* @__PURE__ */ jsx(Text, { className: "px-6 py-4 text-ui-fg-muted", children: "Loading..." }) : items.length === 0 ? /* @__PURE__ */ jsx(Text, { className: "px-6 py-8 text-center text-ui-fg-muted", children: search ? "No images match your search." : "No images in this library." }) : /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-4 p-6", children: items.map((item) => /* @__PURE__ */ jsxs(
357
- "div",
358
- {
359
- className: "group flex-none flex flex-col cursor-pointer overflow-hidden rounded-lg border border-ui-border-base bg-ui-bg-subtle",
360
- onClick: () => navigate(`/content/${selectedCollectionId}/items/${item.id}`),
361
- children: [
362
- item.body ? /* @__PURE__ */ jsx(
363
- "img",
364
- {
365
- src: item.body,
366
- alt: item.title,
367
- className: "block h-40 w-auto object-contain bg-ui-bg-component transition-transform group-hover:scale-105"
368
- }
369
- ) : /* @__PURE__ */ jsx("div", { className: "flex h-40 w-32 items-center justify-center bg-ui-bg-component", children: /* @__PURE__ */ jsx(Text, { className: "text-sm text-ui-fg-muted", children: "No image" }) }),
370
- /* @__PURE__ */ jsxs("div", { className: "w-0 min-w-full overflow-hidden p-2", children: [
371
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", className: "truncate", children: item.title }),
372
- /* @__PURE__ */ jsx(
373
- Badge,
374
- {
375
- size: "xsmall",
376
- color: STATUS_COLORS$2[item.status] ?? "grey",
377
- className: "mt-1",
378
- children: item.status
379
- }
380
- )
381
- ] })
382
- ]
383
- },
384
- item.id
385
- )) }),
386
- pageCount > 1 && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-3", children: [
387
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-muted", children: [
388
- offset + 1,
389
- "–",
390
- Math.min(offset + PAGE_SIZE, total),
391
- " of ",
392
- total
393
- ] }),
394
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
395
- /* @__PURE__ */ jsx(
396
- Button,
397
- {
398
- size: "small",
399
- variant: "transparent",
400
- disabled: pageIndex === 0,
401
- onClick: () => setPageIndex((p) => p - 1),
402
- children: /* @__PURE__ */ jsx(ChevronLeft, {})
403
- }
404
- ),
405
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "min-w-[4rem] text-center text-ui-fg-subtle", children: [
406
- pageIndex + 1,
407
- " / ",
408
- pageCount
409
- ] }),
410
- /* @__PURE__ */ jsx(
411
- Button,
412
- {
413
- size: "small",
414
- variant: "transparent",
415
- disabled: pageIndex >= pageCount - 1,
416
- onClick: () => setPageIndex((p) => p + 1),
417
- children: /* @__PURE__ */ jsx(ChevronRight, {})
418
- }
419
- )
420
- ] })
421
- ] })
422
- ] });
423
- };
424
294
  function $constructor(name, initializer2, params) {
425
295
  function init(inst, def) {
426
296
  if (!inst._zod) {
@@ -485,7 +355,7 @@ class $ZodEncodeError extends Error {
485
355
  }
486
356
  }
487
357
  const globalConfig = {};
488
- function config$1(newConfig) {
358
+ function config$2(newConfig) {
489
359
  return globalConfig;
490
360
  }
491
361
  function getEnumValues(entries) {
@@ -930,7 +800,7 @@ const _parse = (_Err) => (schema2, value, _ctx, _params) => {
930
800
  throw new $ZodAsyncError();
931
801
  }
932
802
  if (result.issues.length) {
933
- const e2 = new ((_params == null ? void 0 : _params.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config$1())));
803
+ const e2 = new ((_params == null ? void 0 : _params.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config$2())));
934
804
  captureStackTrace(e2, _params == null ? void 0 : _params.callee);
935
805
  throw e2;
936
806
  }
@@ -942,7 +812,7 @@ const _parseAsync = (_Err) => async (schema2, value, _ctx, params) => {
942
812
  if (result instanceof Promise)
943
813
  result = await result;
944
814
  if (result.issues.length) {
945
- const e2 = new ((params == null ? void 0 : params.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config$1())));
815
+ const e2 = new ((params == null ? void 0 : params.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config$2())));
946
816
  captureStackTrace(e2, params == null ? void 0 : params.callee);
947
817
  throw e2;
948
818
  }
@@ -956,7 +826,7 @@ const _safeParse = (_Err) => (schema2, value, _ctx) => {
956
826
  }
957
827
  return result.issues.length ? {
958
828
  success: false,
959
- error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config$1())))
829
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config$2())))
960
830
  } : { success: true, data: result.value };
961
831
  };
962
832
  const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
@@ -967,7 +837,7 @@ const _safeParseAsync = (_Err) => async (schema2, value, _ctx) => {
967
837
  result = await result;
968
838
  return result.issues.length ? {
969
839
  success: false,
970
- error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config$1())))
840
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config$2())))
971
841
  } : { success: true, data: result.value };
972
842
  };
973
843
  const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
@@ -2021,7 +1891,7 @@ function handleUnionResults(results, final, inst, ctx) {
2021
1891
  code: "invalid_union",
2022
1892
  input: final.value,
2023
1893
  inst,
2024
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config$1())))
1894
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config$2())))
2025
1895
  });
2026
1896
  return final;
2027
1897
  }
@@ -2346,7 +2216,7 @@ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
2346
2216
  payload.value = def.catchValue({
2347
2217
  ...payload,
2348
2218
  error: {
2349
- issues: result2.issues.map((iss) => finalizeIssue(iss, ctx, config$1()))
2219
+ issues: result2.issues.map((iss) => finalizeIssue(iss, ctx, config$2()))
2350
2220
  },
2351
2221
  input: payload.value
2352
2222
  });
@@ -2360,7 +2230,7 @@ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
2360
2230
  payload.value = def.catchValue({
2361
2231
  ...payload,
2362
2232
  error: {
2363
- issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config$1()))
2233
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config$2()))
2364
2234
  },
2365
2235
  input: payload.value
2366
2236
  });
@@ -6057,12 +5927,12 @@ const CreateContentCollectionModal = ({ open, onOpenChange }) => {
6057
5927
  ] }) })
6058
5928
  ] }) }) });
6059
5929
  };
6060
- const config = defineRouteConfig({
5930
+ const config$1 = defineRouteConfig({
6061
5931
  label: "Content",
6062
5932
  icon: PencilSquare,
6063
5933
  rank: 6
6064
5934
  });
6065
- const handle$3 = { breadcrumb: () => "Content" };
5935
+ const handle$4 = { breadcrumb: () => "Content" };
6066
5936
  const FORMAT_LABELS$1 = {
6067
5937
  html: "HTML",
6068
5938
  img: "Image",
@@ -6166,6 +6036,136 @@ const ContentCollectionsPage = () => {
6166
6036
  /* @__PURE__ */ jsx(CreateContentCollectionModal, { open: createOpen, onOpenChange: setCreateOpen })
6167
6037
  ] });
6168
6038
  };
6039
+ const config = defineRouteConfig({
6040
+ label: "Image Gallery",
6041
+ icon: ImageSparkle,
6042
+ rank: 7
6043
+ });
6044
+ const handle$3 = { breadcrumb: () => "Image Gallery" };
6045
+ const STATUS_COLORS$2 = {
6046
+ published: "green",
6047
+ draft: "orange",
6048
+ archived: "grey"
6049
+ };
6050
+ const PAGE_SIZE = 48;
6051
+ const ImageGalleryPage = () => {
6052
+ const navigate = useNavigate();
6053
+ const [selectedCollectionId, setSelectedCollectionId] = useState();
6054
+ const [search, setSearch] = useState("");
6055
+ const [pageIndex, setPageIndex] = useState(0);
6056
+ const { data: collectionsData } = useContentCollections({ limit: 100 });
6057
+ const imgCollections = ((collectionsData == null ? void 0 : collectionsData.content_collections) ?? []).filter((t2) => t2.format === "img");
6058
+ useEffect(() => {
6059
+ if (imgCollections.length > 0 && !selectedCollectionId) {
6060
+ setSelectedCollectionId(imgCollections[0].id);
6061
+ }
6062
+ }, [imgCollections.length]);
6063
+ useEffect(() => {
6064
+ setPageIndex(0);
6065
+ }, [selectedCollectionId, search]);
6066
+ const offset = useMemo(() => pageIndex * PAGE_SIZE, [pageIndex]);
6067
+ const { data: itemsData, isLoading } = useContentItems(
6068
+ selectedCollectionId,
6069
+ selectedCollectionId ? { limit: PAGE_SIZE, offset, q: search || void 0 } : {}
6070
+ );
6071
+ const items = (itemsData == null ? void 0 : itemsData.content_items) ?? [];
6072
+ const total = (itemsData == null ? void 0 : itemsData.count) ?? 0;
6073
+ const pageCount = Math.ceil(total / PAGE_SIZE);
6074
+ return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
6075
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start justify-between gap-2 px-6 py-4 md:flex-row md:items-center", children: [
6076
+ /* @__PURE__ */ jsx(Heading, { children: "Image Gallery" }),
6077
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
6078
+ /* @__PURE__ */ jsx(
6079
+ Input,
6080
+ {
6081
+ type: "search",
6082
+ placeholder: "Search images...",
6083
+ value: search,
6084
+ onChange: (e2) => setSearch(e2.target.value),
6085
+ className: "w-48 md:w-64"
6086
+ }
6087
+ ),
6088
+ imgCollections.length > 1 && /* @__PURE__ */ jsxs(
6089
+ Select,
6090
+ {
6091
+ value: selectedCollectionId ?? "",
6092
+ onValueChange: setSelectedCollectionId,
6093
+ children: [
6094
+ /* @__PURE__ */ jsx(Select.Trigger, { className: "w-48", children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select library..." }) }),
6095
+ /* @__PURE__ */ jsx(Select.Content, { children: imgCollections.map((t2) => /* @__PURE__ */ jsx(Select.Item, { value: t2.id, children: t2.label }, t2.id)) })
6096
+ ]
6097
+ }
6098
+ )
6099
+ ] })
6100
+ ] }),
6101
+ imgCollections.length === 0 ? /* @__PURE__ */ jsx(Text, { className: "px-6 py-8 text-center text-ui-fg-muted", children: "No image content collections found." }) : isLoading ? /* @__PURE__ */ jsx(Text, { className: "px-6 py-4 text-ui-fg-muted", children: "Loading..." }) : items.length === 0 ? /* @__PURE__ */ jsx(Text, { className: "px-6 py-8 text-center text-ui-fg-muted", children: search ? "No images match your search." : "No images in this library." }) : /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-4 p-6", children: items.map((item) => /* @__PURE__ */ jsxs(
6102
+ "div",
6103
+ {
6104
+ className: "group flex-none flex flex-col cursor-pointer overflow-hidden rounded-lg border border-ui-border-base bg-ui-bg-subtle",
6105
+ onClick: () => navigate(`/content/${selectedCollectionId}/items/${item.id}`),
6106
+ children: [
6107
+ item.body ? /* @__PURE__ */ jsx(
6108
+ "img",
6109
+ {
6110
+ src: item.body,
6111
+ alt: item.title,
6112
+ className: "block h-40 w-auto object-contain bg-ui-bg-component transition-transform group-hover:scale-105"
6113
+ }
6114
+ ) : /* @__PURE__ */ jsx("div", { className: "flex h-40 w-32 items-center justify-center bg-ui-bg-component", children: /* @__PURE__ */ jsx(Text, { className: "text-sm text-ui-fg-muted", children: "No image" }) }),
6115
+ /* @__PURE__ */ jsxs("div", { className: "w-0 min-w-full overflow-hidden p-2", children: [
6116
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", className: "truncate", children: item.title }),
6117
+ /* @__PURE__ */ jsx(
6118
+ Badge,
6119
+ {
6120
+ size: "xsmall",
6121
+ color: STATUS_COLORS$2[item.status] ?? "grey",
6122
+ className: "mt-1",
6123
+ children: item.status
6124
+ }
6125
+ )
6126
+ ] })
6127
+ ]
6128
+ },
6129
+ item.id
6130
+ )) }),
6131
+ pageCount > 1 && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-3", children: [
6132
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-muted", children: [
6133
+ offset + 1,
6134
+ "–",
6135
+ Math.min(offset + PAGE_SIZE, total),
6136
+ " of ",
6137
+ total
6138
+ ] }),
6139
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
6140
+ /* @__PURE__ */ jsx(
6141
+ Button,
6142
+ {
6143
+ size: "small",
6144
+ variant: "transparent",
6145
+ disabled: pageIndex === 0,
6146
+ onClick: () => setPageIndex((p) => p - 1),
6147
+ children: /* @__PURE__ */ jsx(ChevronLeft, {})
6148
+ }
6149
+ ),
6150
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "min-w-[4rem] text-center text-ui-fg-subtle", children: [
6151
+ pageIndex + 1,
6152
+ " / ",
6153
+ pageCount
6154
+ ] }),
6155
+ /* @__PURE__ */ jsx(
6156
+ Button,
6157
+ {
6158
+ size: "small",
6159
+ variant: "transparent",
6160
+ disabled: pageIndex >= pageCount - 1,
6161
+ onClick: () => setPageIndex((p) => p + 1),
6162
+ children: /* @__PURE__ */ jsx(ChevronRight, {})
6163
+ }
6164
+ )
6165
+ ] })
6166
+ ] })
6167
+ ] });
6168
+ };
6169
6169
  const ActionMenu = ({ groups }) => {
6170
6170
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
6171
6171
  /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsx(EllipsisHorizontal, {}) }) }),
@@ -7560,13 +7560,13 @@ const widgetModule = { widgets: [
7560
7560
  const routeModule = {
7561
7561
  routes: [
7562
7562
  {
7563
- Component: ImageGalleryPage,
7564
- path: "/images",
7563
+ Component: ContentCollectionsPage,
7564
+ path: "/content",
7565
7565
  handle: handle$4
7566
7566
  },
7567
7567
  {
7568
- Component: ContentCollectionsPage,
7569
- path: "/content",
7568
+ Component: ImageGalleryPage,
7569
+ path: "/images",
7570
7570
  handle: handle$3
7571
7571
  },
7572
7572
  {
@@ -7591,16 +7591,16 @@ const routeModule = {
7591
7591
  const menuItemModule = {
7592
7592
  menuItems: [
7593
7593
  {
7594
- label: config.label,
7595
- icon: config.icon,
7594
+ label: config$1.label,
7595
+ icon: config$1.icon,
7596
7596
  path: "/content",
7597
7597
  nested: void 0,
7598
7598
  rank: 6,
7599
7599
  translationNs: void 0
7600
7600
  },
7601
7601
  {
7602
- label: config$2.label,
7603
- icon: config$2.icon,
7602
+ label: config.label,
7603
+ icon: config.icon,
7604
7604
  path: "/images",
7605
7605
  nested: void 0,
7606
7606
  rank: 7,