@mercurjs/admin 2.2.0-canary.19 → 2.2.0-canary.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/{add-campaign-promotions-KK4JMLSK.js → add-campaign-promotions-BNLH6QN5.js} +3 -3
  2. package/dist/{attribute-create-TJRNP5SK.js → attribute-create-JW7OXOK2.js} +8 -8
  3. package/dist/{attribute-detail-7I2SQCDK.js → attribute-detail-3Z6MTMJT.js} +7 -7
  4. package/dist/{attribute-edit-UBG6SMUF.js → attribute-edit-4YPWXZRX.js} +2 -2
  5. package/dist/{attribute-edit-possible-value-3BYEPC4X.js → attribute-edit-possible-value-YHEWXK6L.js} +2 -2
  6. package/dist/{campaign-detail-H32E6EDD.js → campaign-detail-ROTJ4SWD.js} +10 -10
  7. package/dist/{category-create-S3K54WKP.js → category-create-AR33DJYX.js} +4 -1
  8. package/dist/{category-detail-5MRHPG6T.js → category-detail-ICACLNJ3.js} +14 -12
  9. package/dist/category-icon-edit-4GXAK4JZ.js +117 -0
  10. package/dist/{category-list-4YSI36HW.js → category-list-PFOINLTU.js} +4 -1
  11. package/dist/category-media-7SLAXXXM.js +654 -0
  12. package/dist/{category-products-3KYY662O.js → category-products-V4H3B6ML.js} +12 -12
  13. package/dist/{chunk-UT2O7IS7.js → chunk-2HMWS5UW.js} +2 -2
  14. package/dist/{chunk-HYQPZADS.js → chunk-2L4W75VS.js} +1 -1
  15. package/dist/{chunk-ZDJWTF64.js → chunk-2MYHGOPY.js} +2 -2
  16. package/dist/{chunk-O63MLTQV.js → chunk-2NA54XKC.js} +51 -0
  17. package/dist/{chunk-GFUCELIZ.js → chunk-3JN4WUVU.js} +1 -1
  18. package/dist/{chunk-RV7DWZZB.js → chunk-4UWPTSZK.js} +1 -1
  19. package/dist/{chunk-5GXPXVVD.js → chunk-4VXYPZMT.js} +2 -2
  20. package/dist/{chunk-Y7FNFQCU.js → chunk-6FLSBL4Q.js} +1 -0
  21. package/dist/{chunk-3F6U44M6.js → chunk-7JZVZ5EX.js} +1 -1
  22. package/dist/{chunk-EASE3NLF.js → chunk-7VPJ4C6F.js} +1 -1
  23. package/dist/{chunk-UCHVBAUB.js → chunk-7XBB24GO.js} +2 -2
  24. package/dist/{chunk-MFIT2RX5.js → chunk-A7RM5JXC.js} +1 -1
  25. package/dist/{chunk-ZG6DNI7O.js → chunk-AGXO2H4E.js} +1 -1
  26. package/dist/{chunk-4DYSSDAA.js → chunk-EAC3J2Z4.js} +2 -2
  27. package/dist/{chunk-B7HIZN4V.js → chunk-FNGPOGDR.js} +2 -2
  28. package/dist/{chunk-CFBEBAQS.js → chunk-FWWPSH6V.js} +1 -1
  29. package/dist/{chunk-X4N7EMFO.js → chunk-FZHLRCBV.js} +2 -2
  30. package/dist/{chunk-X7E65HM2.js → chunk-HI6L7DXI.js} +1 -1
  31. package/dist/{chunk-3N7QXAMO.js → chunk-IER5BQNC.js} +1 -1
  32. package/dist/{chunk-GNWWL47L.js → chunk-JZBVDH6A.js} +1 -1
  33. package/dist/{chunk-YLK2WZU3.js → chunk-KNZ6ICKB.js} +2 -2
  34. package/dist/{chunk-LKW2KWJ4.js → chunk-LLHYICP5.js} +14 -2
  35. package/dist/{chunk-LVCIAKJI.js → chunk-LYCKVPWQ.js} +1 -1
  36. package/dist/{chunk-ESZN3ELN.js → chunk-M3YII6OB.js} +71 -18
  37. package/dist/{chunk-6AYGDFNE.js → chunk-MASXQMJY.js} +1 -1
  38. package/dist/{chunk-OA24YN34.js → chunk-N6R2WOJ7.js} +1 -1
  39. package/dist/{chunk-T53YX34K.js → chunk-NEZ35LWM.js} +3 -3
  40. package/dist/{chunk-AXVZ56UD.js → chunk-ORENI3LP.js} +2 -2
  41. package/dist/{chunk-UVYWKQJF.js → chunk-POSHDM4L.js} +1 -1
  42. package/dist/{chunk-GA4ZFAOV.js → chunk-PWFZCT6H.js} +1 -1
  43. package/dist/chunk-PZ27H46M.js +358 -0
  44. package/dist/{chunk-WHIYSLYW.js → chunk-QPLEFEOZ.js} +1 -1
  45. package/dist/{chunk-TH6W26RC.js → chunk-RWW3TAJQ.js} +4 -4
  46. package/dist/{chunk-YI7I7JFX.js → chunk-S6E7XAWX.js} +2 -2
  47. package/dist/{chunk-XKD67CD4.js → chunk-SJKLYS3R.js} +2 -2
  48. package/dist/{chunk-O62SUNK2.js → chunk-V3ATA433.js} +3 -3
  49. package/dist/{chunk-JWE2IW4R.js → chunk-WTPWO7KS.js} +7 -7
  50. package/dist/chunk-Y3RABQC4.js +33 -0
  51. package/dist/{chunk-OXONMLRP.js → chunk-ZLETFDWJ.js} +200 -105
  52. package/dist/{collection-add-products-4EZ6W4N6.js → collection-add-products-PBCIG33C.js} +11 -11
  53. package/dist/{collection-detail-X22ZIM5S.js → collection-detail-3OLBOV24.js} +12 -12
  54. package/dist/{collection-list-6CUEOLUU.js → collection-list-S4ICG5T6.js} +10 -10
  55. package/dist/{customer-detail-6MBW3FHO.js → customer-detail-MT2R7DFI.js} +10 -10
  56. package/dist/index.js +161 -153
  57. package/dist/{inventory-detail-ZWHSLLLI.js → inventory-detail-POKYZVLA.js} +7 -7
  58. package/dist/{location-detail-QS7HM2KG.js → location-detail-PHT367V5.js} +10 -10
  59. package/dist/{location-fulfillment-providers-6RUGYQ3W.js → location-fulfillment-providers-EZOVLJWL.js} +9 -9
  60. package/dist/{offers-WYAJB75N.js → offers-5LSNWJ6B.js} +8 -8
  61. package/dist/{order-detail-FZT74HMD.js → order-detail-Y6SFV44C.js} +12 -12
  62. package/dist/{order-edit-billing-address-OJZICMBN.js → order-edit-billing-address-IW6UIARN.js} +8 -8
  63. package/dist/{order-list-C5YOR6B5.js → order-list-KWHMMX2M.js} +2 -2
  64. package/dist/pages/index.d.ts +92 -0
  65. package/dist/pages/index.js +118 -115
  66. package/dist/{price-list-create-XQWV352E.js → price-list-create-LPJWSOBP.js} +13 -13
  67. package/dist/{price-list-detail-347UU3LU.js → price-list-detail-7AUDNRSM.js} +12 -12
  68. package/dist/{price-list-prices-add-R656I6QF.js → price-list-prices-add-5IOYBCXV.js} +12 -12
  69. package/dist/{product-add-existing-attributes-MNGWZFGD.js → product-add-existing-attributes-LNZK2LHX.js} +8 -8
  70. package/dist/{product-create-LMYR36NA.js → product-create-QYEZHBTC.js} +11 -11
  71. package/dist/{product-create-variant-XETT2WJC.js → product-create-variant-FQSREC66.js} +3 -3
  72. package/dist/{product-detail-WSL4PXKK.js → product-detail-Q6YF7IYX.js} +8 -8
  73. package/dist/{product-edit-attribute-XEYHQJ6D.js → product-edit-attribute-WW4LCYD7.js} +2 -2
  74. package/dist/{product-list-7YPGRGHX.js → product-list-IDRT4WUK.js} +12 -12
  75. package/dist/{product-media-H6SYBNLI.js → product-media-6H34CVXJ.js} +2 -2
  76. package/dist/{product-tag-detail-AUNKJJLP.js → product-tag-detail-WF34TUQR.js} +19 -19
  77. package/dist/{product-tag-list-IKL46JZT.js → product-tag-list-PK43EMMH.js} +19 -19
  78. package/dist/{product-type-detail-DKHKFADI.js → product-type-detail-J466AJUQ.js} +12 -12
  79. package/dist/{product-variant-edit-THZLEOGL.js → product-variant-edit-CYEISGII.js} +8 -8
  80. package/dist/{promotion-create-RB3AA5GE.js → promotion-create-KNK57JWD.js} +8 -8
  81. package/dist/{promotion-detail-PEDTLXZ4.js → promotion-detail-EUQ5LK2V.js} +9 -9
  82. package/dist/{promotion-list-MCYWN5TF.js → promotion-list-M5SAE7A3.js} +4 -4
  83. package/dist/{refund-reason-list-GPDRI2QM.js → refund-reason-list-FBH43XVP.js} +17 -17
  84. package/dist/region-list-2XXKCDDX.js +1 -1
  85. package/dist/{reservation-detail-WTYOR6IB.js → reservation-detail-T3VHDWP6.js} +7 -7
  86. package/dist/{reservation-list-3OKWSHWH.js → reservation-list-RGD6O4RY.js} +2 -2
  87. package/dist/{reset-password-2NVKH6QA.js → reset-password-RF5J4RIU.js} +1 -1
  88. package/dist/{return-reason-list-E6L7VJY7.js → return-reason-list-4JWWSFOS.js} +14 -14
  89. package/dist/{sales-channel-add-products-BKT3CFLY.js → sales-channel-add-products-FNJQKCQQ.js} +11 -11
  90. package/dist/{sales-channel-detail-MUBMJGQV.js → sales-channel-detail-HXJAR6M4.js} +12 -12
  91. package/dist/{store-bulk-edit-WML2DUA4.js → store-bulk-edit-JAOT5GY2.js} +1 -1
  92. package/dist/{store-details-3HWOCRYI.js → store-details-LSGSI4QU.js} +15 -15
  93. package/dist/{store-edit-5WWOOSHT.js → store-edit-TP5CQHV7.js} +3 -3
  94. package/dist/{store-list-YEEKX2AV.js → store-list-KQGPNQQ4.js} +10 -10
  95. package/dist/{store-member-invite-TULPI3N5.js → store-member-invite-MNRTPHUB.js} +1 -1
  96. package/dist/{tax-region-create-X2LAHX27.js → tax-region-create-JR7OHOJ5.js} +7 -7
  97. package/dist/{tax-region-detail-3X3TNFJA.js → tax-region-detail-2E56T5C2.js} +11 -11
  98. package/dist/{tax-region-province-detail-DIV5AAFQ.js → tax-region-province-detail-5Q5E5OP7.js} +10 -10
  99. package/dist/{tax-region-tax-override-create-BV4O3QCU.js → tax-region-tax-override-create-S5S5JZEJ.js} +19 -19
  100. package/dist/{tax-region-tax-override-edit-QUA77YTI.js → tax-region-tax-override-edit-JBG3MRNC.js} +20 -20
  101. package/package.json +1 -1
  102. package/dist/{adjust-inventory-F3OTF6O6.js → adjust-inventory-2LHBQAWK.js} +7 -7
  103. package/dist/{api-key-management-detail-JMWPGN6M.js → api-key-management-detail-R5QQPNOD.js} +6 -6
  104. package/dist/{attribute-list-EFU4DPB5.js → attribute-list-WRTXTFED.js} +6 -6
  105. package/dist/{categories-metadata-V37DXTVZ.js → categories-metadata-EPKUI3R4.js} +6 -6
  106. package/dist/{chunk-FYCIGKVG.js → chunk-3FN3YH2F.js} +3 -3
  107. package/dist/{chunk-D77BYNTQ.js → chunk-47TXYMFT.js} +3 -3
  108. package/dist/{chunk-3EUF5GRT.js → chunk-CKQPO2SN.js} +3 -3
  109. package/dist/{chunk-3KCXKGHX.js → chunk-KNB55WE4.js} +3 -3
  110. package/dist/{chunk-4IKESXD3.js → chunk-LTAQZW2L.js} +3 -3
  111. package/dist/{chunk-W6J4SJ3Y.js → chunk-SEY52XON.js} +6 -6
  112. package/dist/{chunk-BJQ4UBK7.js → chunk-WETV577Q.js} +18 -18
  113. package/dist/{chunk-EM5TF7YZ.js → chunk-Z3SUMFDT.js} +6 -6
  114. package/dist/{collection-metadata-AWJYPZKR.js → collection-metadata-VUOECEP4.js} +6 -6
  115. package/dist/{customer-group-detail-G53RB6EA.js → customer-group-detail-MCAEXZYM.js} +6 -6
  116. package/dist/{customer-group-list-XDNCZ4K6.js → customer-group-list-V4PW33M5.js} +6 -6
  117. package/dist/{customer-group-metadata-FWLKUHIZ.js → customer-group-metadata-J622TR4I.js} +6 -6
  118. package/dist/{customer-metadata-KU4YWD3R.js → customer-metadata-SFS5VRK5.js} +6 -6
  119. package/dist/{customers-add-customer-group-5Y5XPN7C.js → customers-add-customer-group-G6FIKKUP.js} +6 -6
  120. package/dist/{edit-inventory-item-MBLHBGBH.js → edit-inventory-item-OFPVTJ4I.js} +6 -6
  121. package/dist/{edit-inventory-item-attributes-GTTGNBO4.js → edit-inventory-item-attributes-Z37AFIYM.js} +6 -6
  122. package/dist/{edit-reservation-C3NXAKSE.js → edit-reservation-TBZL2REV.js} +3 -3
  123. package/dist/{edit-rules-UFGKSAJV.js → edit-rules-JG62MLUS.js} +6 -6
  124. package/dist/{inventory-create-4O4L6NXK.js → inventory-create-3IM54ZO3.js} +6 -6
  125. package/dist/{inventory-metadata-GZYYWU3S.js → inventory-metadata-XXYKRUNP.js} +6 -6
  126. package/dist/{inventory-stock-S5B6ZZQW.js → inventory-stock-CXPPGARO.js} +7 -7
  127. package/dist/{location-list-7RTDLHGR.js → location-list-HVSRDHOW.js} +6 -6
  128. package/dist/{location-service-zone-shipping-option-create-UKULBDGM.js → location-service-zone-shipping-option-create-VZBL7MK6.js} +6 -6
  129. package/dist/{location-service-zone-shipping-option-edit-O3B3H5OC.js → location-service-zone-shipping-option-edit-WRSLBO23.js} +3 -3
  130. package/dist/{login-SFGV4QGP.js → login-LJMTSRAG.js} +6 -6
  131. package/dist/{marketplace-detail-7VPTFUPB.js → marketplace-detail-WINAJJDB.js} +6 -6
  132. package/dist/{marketplace-metadata-E25VT5TH.js → marketplace-metadata-CCUK2B4Q.js} +6 -6
  133. package/dist/{order-create-claim-3AQK3FH2.js → order-create-claim-2MO3LM6J.js} +5 -5
  134. package/dist/{order-create-exchange-QCYD3DC4.js → order-create-exchange-6IQJFYUK.js} +12 -12
  135. package/dist/{order-create-refund-TR4XMHRY.js → order-create-refund-DUVGD54U.js} +7 -7
  136. package/dist/{order-edit-email-TH26N5HK.js → order-edit-email-D5XIYASI.js} +7 -7
  137. package/dist/{order-edit-shipping-address-GBOUGZPD.js → order-edit-shipping-address-4VJDVGKJ.js} +7 -7
  138. package/dist/{order-metadata-RT3BVTYZ.js → order-metadata-QSTGFW66.js} +7 -7
  139. package/dist/{order-request-transfer-3HTFPYFD.js → order-request-transfer-GYBTSHU4.js} +7 -7
  140. package/dist/{price-list-prices-edit-BOKBTLEI.js → price-list-prices-edit-DT2DLFTO.js} +6 -6
  141. package/dist/{product-metadata-MGLJJ7QG.js → product-metadata-VJMZL753.js} +6 -6
  142. package/dist/{product-tag-create-JCYAG42N.js → product-tag-create-4FYE46PE.js} +6 -6
  143. package/dist/{product-tag-edit-2FREKKVN.js → product-tag-edit-HRWMMCUC.js} +6 -6
  144. package/dist/{product-tag-metadata-UV3TBPXS.js → product-tag-metadata-ONSEQTEW.js} +6 -6
  145. package/dist/{product-type-metadata-22OACFMD.js → product-type-metadata-CXYKP2OF.js} +6 -6
  146. package/dist/{product-variant-detail-MNMJBYIP.js → product-variant-detail-FXQZLB7Q.js} +6 -6
  147. package/dist/{product-variant-metadata-7N7PL7WY.js → product-variant-metadata-YQ2GKWW7.js} +6 -6
  148. package/dist/{refund-reason-create-YWA5XP4J.js → refund-reason-create-ANAVZO2N.js} +6 -6
  149. package/dist/{refund-reason-edit-MBG5WL43.js → refund-reason-edit-HKEVJ6A5.js} +6 -6
  150. package/dist/{region-metadata-WDZ7DRGU.js → region-metadata-XHT3A6D7.js} +6 -6
  151. package/dist/{reservation-create-NPR2FMPA.js → reservation-create-F6YDCLCG.js} +3 -3
  152. package/dist/{reservation-metadata-PJVHEJRU.js → reservation-metadata-4LVLM4UW.js} +6 -6
  153. package/dist/{sales-channel-list-O5SFOGMA.js → sales-channel-list-YYIH254X.js} +6 -6
  154. package/dist/{sales-channel-metadata-67RGBA7X.js → sales-channel-metadata-YF5AV2XX.js} +6 -6
  155. package/dist/{shipping-option-type-create-OBF6GG5W.js → shipping-option-type-create-TOONS7EC.js} +6 -6
  156. package/dist/{shipping-option-type-detail-TJC2GBUA.js → shipping-option-type-detail-VXZ4UQQI.js} +6 -6
  157. package/dist/{shipping-option-type-edit-INKLJRSH.js → shipping-option-type-edit-6WO2XRLE.js} +6 -6
  158. package/dist/{shipping-option-type-list-WKA64NYE.js → shipping-option-type-list-S7TW7Q3R.js} +6 -6
  159. package/dist/{shipping-profile-metadata-RI6Y2N6V.js → shipping-profile-metadata-SVD3WK7H.js} +6 -6
  160. package/dist/{store-create-AGF2LZWR.js → store-create-7A5OSRIV.js} +6 -6
  161. package/dist/{tax-region-edit-7ECYGXEA.js → tax-region-edit-7SBQFGPY.js} +6 -6
  162. package/dist/{tax-region-metadata-FQLEYY2R.js → tax-region-metadata-4NUEQV3N.js} +6 -6
  163. package/dist/{user-metadata-64LX64QI.js → user-metadata-2D552EAR.js} +6 -6
@@ -0,0 +1,654 @@
1
+ import {
2
+ CATEGORY_IMAGE_FORMATS,
3
+ getCategoryGallery,
4
+ uploadCategoryImages
5
+ } from "./chunk-PZ27H46M.js";
6
+ import {
7
+ FileUpload
8
+ } from "./chunk-VSLHL2AZ.js";
9
+ import "./chunk-TKGWSUEI.js";
10
+ import {
11
+ KeyboundForm
12
+ } from "./chunk-SITRHMZZ.js";
13
+ import {
14
+ RouteFocusModal,
15
+ useRouteModal
16
+ } from "./chunk-FWJLS7XD.js";
17
+ import {
18
+ Form
19
+ } from "./chunk-3QSRE5LS.js";
20
+ import {
21
+ useProductCategory,
22
+ useUpdateProductCategory
23
+ } from "./chunk-KYFWVLWO.js";
24
+ import "./chunk-M2E3PKA4.js";
25
+ import "./chunk-RHKRREUU.js";
26
+ import "./chunk-ZA2KFUFR.js";
27
+ import "./chunk-ZBWL72TB.js";
28
+ import "./chunk-NBMM2TZK.js";
29
+
30
+ // src/pages/categories/category-media/category-media.tsx
31
+ import { useTranslation as useTranslation3 } from "react-i18next";
32
+ import { useParams } from "react-router-dom";
33
+
34
+ // src/pages/categories/category-media/components/category-media-view/category-media-view.tsx
35
+ import { useMemo } from "react";
36
+ import { useSearchParams } from "react-router-dom";
37
+
38
+ // src/pages/categories/category-media/components/edit-category-media-form/edit-category-media-form.tsx
39
+ import { Fragment, useCallback, useState } from "react";
40
+ import { FeaturedBadge, ThumbnailBadge } from "@medusajs/icons";
41
+ import {
42
+ Button,
43
+ Checkbox,
44
+ CommandBar,
45
+ Text,
46
+ Tooltip,
47
+ clx,
48
+ toast
49
+ } from "@medusajs/ui";
50
+ import {
51
+ DndContext,
52
+ DragOverlay,
53
+ KeyboardSensor,
54
+ PointerSensor,
55
+ defaultDropAnimationSideEffects,
56
+ useSensor,
57
+ useSensors
58
+ } from "@dnd-kit/core";
59
+ import {
60
+ SortableContext,
61
+ arrayMove,
62
+ rectSortingStrategy,
63
+ sortableKeyboardCoordinates,
64
+ useSortable
65
+ } from "@dnd-kit/sortable";
66
+ import { CSS } from "@dnd-kit/utilities";
67
+ import { zodResolver } from "@hookform/resolvers/zod";
68
+ import { useFieldArray, useForm } from "react-hook-form";
69
+ import { useTranslation } from "react-i18next";
70
+ import { Link } from "react-router-dom";
71
+ import { z } from "zod";
72
+ import { jsx, jsxs } from "react/jsx-runtime";
73
+ var MediaSchema = z.object({
74
+ id: z.string().optional(),
75
+ url: z.string(),
76
+ file: z.any().nullable(),
77
+ // File
78
+ is_thumbnail: z.boolean(),
79
+ is_banner: z.boolean()
80
+ });
81
+ var EditCategoryMediaSchema = z.object({
82
+ media: z.array(MediaSchema)
83
+ });
84
+ var EditCategoryMediaForm = ({
85
+ category
86
+ }) => {
87
+ const [selection, setSelection] = useState({});
88
+ const { t } = useTranslation();
89
+ const { handleSuccess } = useRouteModal();
90
+ const form = useForm({
91
+ defaultValues: {
92
+ media: getCategoryGallery(category.images).map((image) => ({
93
+ id: image.id,
94
+ url: image.url,
95
+ file: null,
96
+ is_thumbnail: image.is_thumbnail,
97
+ is_banner: image.is_banner
98
+ }))
99
+ },
100
+ resolver: zodResolver(EditCategoryMediaSchema)
101
+ });
102
+ const { fields, append, remove, update } = useFieldArray({
103
+ name: "media",
104
+ control: form.control,
105
+ keyName: "field_id"
106
+ });
107
+ const [activeId, setActiveId] = useState(null);
108
+ const sensors = useSensors(
109
+ useSensor(PointerSensor),
110
+ useSensor(KeyboardSensor, {
111
+ coordinateGetter: sortableKeyboardCoordinates
112
+ })
113
+ );
114
+ const handleDragEnd = (event) => {
115
+ setActiveId(null);
116
+ const { active, over } = event;
117
+ if (active.id !== over?.id) {
118
+ const oldIndex = fields.findIndex((item) => item.field_id === active.id);
119
+ const newIndex = fields.findIndex((item) => item.field_id === over?.id);
120
+ form.setValue("media", arrayMove(fields, oldIndex, newIndex), {
121
+ shouldDirty: true,
122
+ shouldTouch: true
123
+ });
124
+ }
125
+ };
126
+ const handleDragStart = (event) => setActiveId(event.active.id);
127
+ const handleDragCancel = () => setActiveId(null);
128
+ const { mutateAsync, isPending } = useUpdateProductCategory(category.id);
129
+ const handleSubmit = form.handleSubmit(async ({ media }) => {
130
+ const images = await uploadCategoryImages({
131
+ media: media.map((m) => ({
132
+ url: m.url,
133
+ file: m.file,
134
+ is_thumbnail: m.is_thumbnail,
135
+ is_banner: m.is_banner
136
+ }))
137
+ });
138
+ await mutateAsync(images, {
139
+ onSuccess: () => {
140
+ toast.success(t("categories.media.edit.successToast"));
141
+ handleSuccess();
142
+ },
143
+ onError: (error) => {
144
+ toast.error(error.message);
145
+ }
146
+ });
147
+ });
148
+ const handleCheckedChange = useCallback(
149
+ (id) => (val) => {
150
+ if (!val) {
151
+ const { [id]: _, ...rest } = selection;
152
+ setSelection(rest);
153
+ } else {
154
+ setSelection((prev) => ({ ...prev, [id]: true }));
155
+ }
156
+ },
157
+ [selection]
158
+ );
159
+ const handleDelete = () => {
160
+ const ids = Object.keys(selection);
161
+ const indices = ids.map((id) => fields.findIndex((m) => m.field_id === id));
162
+ remove(indices);
163
+ setSelection({});
164
+ };
165
+ const handlePromote = (role) => {
166
+ const ids = Object.keys(selection);
167
+ if (!ids.length) {
168
+ return;
169
+ }
170
+ const targetIndex = fields.findIndex((m) => m.field_id === ids[0]);
171
+ fields.forEach((field, i) => {
172
+ const shouldBe = i === targetIndex;
173
+ if (field[role] !== shouldBe) {
174
+ update(i, { ...field, [role]: shouldBe });
175
+ }
176
+ });
177
+ setSelection({});
178
+ };
179
+ const onUploaded = (files) => {
180
+ files.forEach(
181
+ (f) => append({
182
+ url: f.url,
183
+ file: f.file,
184
+ is_thumbnail: false,
185
+ is_banner: false
186
+ })
187
+ );
188
+ };
189
+ const selectionCount = Object.keys(selection).length;
190
+ return /* @__PURE__ */ jsx(RouteFocusModal.Form, { blockSearchParams: true, form, children: /* @__PURE__ */ jsxs(
191
+ KeyboundForm,
192
+ {
193
+ className: "flex size-full flex-col overflow-hidden",
194
+ onSubmit: handleSubmit,
195
+ children: [
196
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end gap-x-2", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsx(Link, { to: { pathname: ".", search: void 0 }, children: t("categories.media.galleryLabel") }) }) }) }),
197
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: /* @__PURE__ */ jsxs("div", { className: "flex size-full flex-col-reverse lg:grid lg:grid-cols-[1fr_560px]", children: [
198
+ /* @__PURE__ */ jsx(
199
+ DndContext,
200
+ {
201
+ sensors,
202
+ onDragEnd: handleDragEnd,
203
+ onDragStart: handleDragStart,
204
+ onDragCancel: handleDragCancel,
205
+ children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-subtle size-full overflow-auto", children: /* @__PURE__ */ jsxs("div", { className: "grid h-fit auto-rows-auto grid-cols-4 gap-6 p-6", children: [
206
+ /* @__PURE__ */ jsx(
207
+ SortableContext,
208
+ {
209
+ items: fields.map((m) => m.field_id),
210
+ strategy: rectSortingStrategy,
211
+ children: fields.map((m) => /* @__PURE__ */ jsx(
212
+ MediaGridItem,
213
+ {
214
+ media: m,
215
+ checked: !!selection[m.field_id],
216
+ onCheckedChange: handleCheckedChange(m.field_id)
217
+ },
218
+ m.field_id
219
+ ))
220
+ }
221
+ ),
222
+ /* @__PURE__ */ jsx(DragOverlay, { dropAnimation: dropAnimationConfig, children: activeId ? /* @__PURE__ */ jsx(
223
+ MediaGridItemOverlay,
224
+ {
225
+ media: fields.find((m) => m.field_id === activeId)
226
+ }
227
+ ) : null })
228
+ ] }) })
229
+ }
230
+ ),
231
+ /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-base overflow-auto border-b px-6 py-4 lg:border-b-0 lg:border-l", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-2", children: [
232
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-1", children: [
233
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: t("categories.media.label") }),
234
+ /* @__PURE__ */ jsx(Form.Hint, { children: t("categories.media.editHint") })
235
+ ] }),
236
+ /* @__PURE__ */ jsx(
237
+ FileUpload,
238
+ {
239
+ label: t("categories.media.upload.title"),
240
+ hint: t("categories.media.upload.hint"),
241
+ formats: CATEGORY_IMAGE_FORMATS,
242
+ onUploaded
243
+ }
244
+ )
245
+ ] }) })
246
+ ] }) }),
247
+ /* @__PURE__ */ jsx(CommandBar, { open: !!selectionCount, children: /* @__PURE__ */ jsxs(CommandBar.Bar, { children: [
248
+ /* @__PURE__ */ jsx(CommandBar.Value, { children: t("general.countSelected", { count: selectionCount }) }),
249
+ /* @__PURE__ */ jsx(CommandBar.Seperator, {}),
250
+ selectionCount === 1 && /* @__PURE__ */ jsxs(Fragment, { children: [
251
+ /* @__PURE__ */ jsx(
252
+ CommandBar.Command,
253
+ {
254
+ action: () => handlePromote("is_thumbnail"),
255
+ label: t("categories.media.actions.setThumbnail"),
256
+ shortcut: "t"
257
+ }
258
+ ),
259
+ /* @__PURE__ */ jsx(CommandBar.Seperator, {}),
260
+ /* @__PURE__ */ jsx(
261
+ CommandBar.Command,
262
+ {
263
+ action: () => handlePromote("is_banner"),
264
+ label: t("categories.media.actions.setBanner"),
265
+ shortcut: "b"
266
+ }
267
+ ),
268
+ /* @__PURE__ */ jsx(CommandBar.Seperator, {})
269
+ ] }),
270
+ /* @__PURE__ */ jsx(
271
+ CommandBar.Command,
272
+ {
273
+ action: handleDelete,
274
+ label: t("actions.delete"),
275
+ shortcut: "d"
276
+ }
277
+ )
278
+ ] }) }),
279
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
280
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: t("actions.cancel") }) }),
281
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: t("actions.save") })
282
+ ] }) })
283
+ ]
284
+ }
285
+ ) });
286
+ };
287
+ var dropAnimationConfig = {
288
+ sideEffects: defaultDropAnimationSideEffects({
289
+ styles: { active: { opacity: "0.4" } }
290
+ })
291
+ };
292
+ var RoleBadges = ({ media }) => {
293
+ const { t } = useTranslation();
294
+ if (!media.is_thumbnail && !media.is_banner) {
295
+ return null;
296
+ }
297
+ return /* @__PURE__ */ jsxs("div", { className: "absolute left-2 top-2 flex items-center gap-x-1", children: [
298
+ media.is_thumbnail && /* @__PURE__ */ jsx(Tooltip, { content: t("categories.media.thumbnail"), children: /* @__PURE__ */ jsx(ThumbnailBadge, {}) }),
299
+ media.is_banner && /* @__PURE__ */ jsx(Tooltip, { content: t("categories.media.banner"), children: /* @__PURE__ */ jsx(FeaturedBadge, { className: "text-ui-fg-interactive" }) })
300
+ ] });
301
+ };
302
+ var MediaGridItem = ({
303
+ media,
304
+ checked,
305
+ onCheckedChange
306
+ }) => {
307
+ const {
308
+ attributes,
309
+ listeners,
310
+ setNodeRef,
311
+ setActivatorNodeRef,
312
+ transform,
313
+ transition,
314
+ isDragging
315
+ } = useSortable({ id: media.field_id });
316
+ const style = {
317
+ opacity: isDragging ? 0.4 : void 0,
318
+ transform: CSS.Transform.toString(transform),
319
+ transition
320
+ };
321
+ return /* @__PURE__ */ jsxs(
322
+ "div",
323
+ {
324
+ className: "group bg-ui-bg-subtle-hover shadow-elevation-card-rest hover:shadow-elevation-card-hover focus-visible:shadow-borders-focus relative aspect-square h-auto max-w-full overflow-hidden rounded-lg outline-none",
325
+ style,
326
+ ref: setNodeRef,
327
+ children: [
328
+ /* @__PURE__ */ jsx(RoleBadges, { media }),
329
+ /* @__PURE__ */ jsx(
330
+ "div",
331
+ {
332
+ className: clx("absolute inset-0 cursor-grab touch-none outline-none", {
333
+ "cursor-grabbing": isDragging
334
+ }),
335
+ ref: setActivatorNodeRef,
336
+ ...attributes,
337
+ ...listeners
338
+ }
339
+ ),
340
+ /* @__PURE__ */ jsx(
341
+ "div",
342
+ {
343
+ className: clx("transition-fg absolute right-2 top-2 opacity-0", {
344
+ "group-focus-within:opacity-100 group-hover:opacity-100 group-focus:opacity-100": !isDragging && !checked,
345
+ "opacity-100": checked
346
+ }),
347
+ children: /* @__PURE__ */ jsx(
348
+ Checkbox,
349
+ {
350
+ onClick: (e) => e.stopPropagation(),
351
+ checked,
352
+ onCheckedChange
353
+ }
354
+ )
355
+ }
356
+ ),
357
+ /* @__PURE__ */ jsx(
358
+ "img",
359
+ {
360
+ src: media.url,
361
+ alt: "",
362
+ className: "size-full object-cover object-center"
363
+ }
364
+ )
365
+ ]
366
+ }
367
+ );
368
+ };
369
+ var MediaGridItemOverlay = ({ media }) => {
370
+ return /* @__PURE__ */ jsxs("div", { className: "group bg-ui-bg-subtle-hover shadow-elevation-card-rest relative aspect-square h-auto max-w-full cursor-grabbing overflow-hidden rounded-lg outline-none", children: [
371
+ /* @__PURE__ */ jsx(RoleBadges, { media }),
372
+ /* @__PURE__ */ jsx(
373
+ "img",
374
+ {
375
+ src: media.url,
376
+ alt: "",
377
+ className: "size-full object-cover object-center"
378
+ }
379
+ )
380
+ ] });
381
+ };
382
+
383
+ // src/pages/categories/category-media/components/category-media-gallery/category-media-gallery.tsx
384
+ import {
385
+ ArrowDownTray,
386
+ FeaturedBadge as FeaturedBadge2,
387
+ ThumbnailBadge as ThumbnailBadge2,
388
+ Trash,
389
+ TriangleLeftMini,
390
+ TriangleRightMini
391
+ } from "@medusajs/icons";
392
+ import { Button as Button2, IconButton, Text as Text2, Tooltip as Tooltip2, clx as clx2, usePrompt } from "@medusajs/ui";
393
+ import { useCallback as useCallback2, useEffect, useState as useState2 } from "react";
394
+ import { useTranslation as useTranslation2 } from "react-i18next";
395
+ import { Link as Link2, useLocation } from "react-router-dom";
396
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
397
+ var CategoryMediaGallery = ({
398
+ category
399
+ }) => {
400
+ const { state } = useLocation();
401
+ const [curr, setCurr] = useState2(state?.curr || 0);
402
+ const { t } = useTranslation2();
403
+ const prompt = usePrompt();
404
+ const { mutateAsync, isPending } = useUpdateProductCategory(category.id);
405
+ const media = getCategoryGallery(category.images);
406
+ const next = useCallback2(() => {
407
+ if (isPending) {
408
+ return;
409
+ }
410
+ setCurr((current) => (current + 1) % media.length);
411
+ }, [media, isPending]);
412
+ const prev = useCallback2(() => {
413
+ if (isPending) {
414
+ return;
415
+ }
416
+ setCurr((current) => (current - 1 + media.length) % media.length);
417
+ }, [media, isPending]);
418
+ const goTo = useCallback2(
419
+ (index) => {
420
+ if (isPending) {
421
+ return;
422
+ }
423
+ setCurr(index);
424
+ },
425
+ [isPending]
426
+ );
427
+ const handleDownloadCurrent = () => {
428
+ if (isPending) {
429
+ return;
430
+ }
431
+ const a = document.createElement("a");
432
+ a.href = media[curr].url;
433
+ a.download = "image";
434
+ a.target = "_blank";
435
+ a.click();
436
+ };
437
+ const handleDeleteCurrent = async () => {
438
+ const current = media[curr];
439
+ const res = await prompt({
440
+ title: t("general.areYouSure"),
441
+ description: t("categories.media.deleteWarning"),
442
+ confirmText: t("actions.delete"),
443
+ cancelText: t("actions.cancel")
444
+ });
445
+ if (!res) {
446
+ return;
447
+ }
448
+ const remaining = media.filter((image) => image.id !== current.id).map((image) => ({
449
+ url: image.url,
450
+ is_thumbnail: image.is_thumbnail,
451
+ is_banner: image.is_banner
452
+ }));
453
+ if (curr === media.length - 1) {
454
+ setCurr((index) => Math.max(0, index - 1));
455
+ }
456
+ await mutateAsync({ media: remaining });
457
+ };
458
+ useEffect(() => {
459
+ const handleKeyDown = (e) => {
460
+ if (e.key === "ArrowRight") {
461
+ next();
462
+ } else if (e.key === "ArrowLeft") {
463
+ prev();
464
+ }
465
+ };
466
+ document.addEventListener("keydown", handleKeyDown);
467
+ return () => document.removeEventListener("keydown", handleKeyDown);
468
+ }, [next, prev]);
469
+ const noMedia = !media.length;
470
+ return /* @__PURE__ */ jsxs2("div", { className: "flex size-full flex-col overflow-hidden", children: [
471
+ /* @__PURE__ */ jsx2(RouteFocusModal.Header, { children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-x-2", children: [
472
+ /* @__PURE__ */ jsx2(
473
+ IconButton,
474
+ {
475
+ size: "small",
476
+ type: "button",
477
+ onClick: handleDeleteCurrent,
478
+ disabled: noMedia,
479
+ children: /* @__PURE__ */ jsx2(Trash, {})
480
+ }
481
+ ),
482
+ /* @__PURE__ */ jsx2(
483
+ IconButton,
484
+ {
485
+ size: "small",
486
+ type: "button",
487
+ onClick: handleDownloadCurrent,
488
+ disabled: noMedia,
489
+ children: /* @__PURE__ */ jsx2(ArrowDownTray, {})
490
+ }
491
+ ),
492
+ /* @__PURE__ */ jsx2(Button2, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsx2(Link2, { to: { pathname: ".", search: "view=edit" }, children: t("actions.edit") }) })
493
+ ] }) }),
494
+ /* @__PURE__ */ jsxs2(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: [
495
+ /* @__PURE__ */ jsx2(Canvas, { curr, media }),
496
+ /* @__PURE__ */ jsx2(Preview, { curr, media, prev, next, goTo })
497
+ ] })
498
+ ] });
499
+ };
500
+ var Canvas = ({
501
+ media,
502
+ curr
503
+ }) => {
504
+ const { t } = useTranslation2();
505
+ if (media.length === 0) {
506
+ return /* @__PURE__ */ jsxs2("div", { className: "bg-ui-bg-subtle flex size-full flex-col items-center justify-center gap-y-4 pb-8 pt-6", children: [
507
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center", children: [
508
+ /* @__PURE__ */ jsx2(
509
+ Text2,
510
+ {
511
+ size: "small",
512
+ leading: "compact",
513
+ weight: "plus",
514
+ className: "text-ui-fg-subtle",
515
+ children: t("categories.media.empty.header")
516
+ }
517
+ ),
518
+ /* @__PURE__ */ jsx2(Text2, { size: "small", className: "text-ui-fg-muted", children: t("categories.media.empty.description") })
519
+ ] }),
520
+ /* @__PURE__ */ jsx2(Button2, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx2(Link2, { to: "?view=edit", children: t("categories.media.upload.title") }) })
521
+ ] });
522
+ }
523
+ return /* @__PURE__ */ jsx2("div", { className: "bg-ui-bg-subtle relative size-full overflow-hidden", children: /* @__PURE__ */ jsx2("div", { className: "flex size-full items-center justify-center p-6", children: /* @__PURE__ */ jsxs2("div", { className: "relative inline-block max-h-full max-w-full", children: [
524
+ /* @__PURE__ */ jsxs2("div", { className: "absolute left-2 top-2 flex items-center gap-x-1", children: [
525
+ media[curr].is_thumbnail && /* @__PURE__ */ jsx2(Tooltip2, { content: t("categories.media.thumbnail"), children: /* @__PURE__ */ jsx2(ThumbnailBadge2, {}) }),
526
+ media[curr].is_banner && /* @__PURE__ */ jsx2(Tooltip2, { content: t("categories.media.banner"), children: /* @__PURE__ */ jsx2(FeaturedBadge2, { className: "text-ui-fg-interactive" }) })
527
+ ] }),
528
+ /* @__PURE__ */ jsx2(
529
+ "img",
530
+ {
531
+ src: media[curr].url,
532
+ alt: "",
533
+ className: "object-fit shadow-elevation-card-rest max-h-[calc(100vh-200px)] w-auto rounded-xl object-contain"
534
+ }
535
+ )
536
+ ] }) }) });
537
+ };
538
+ var MAX_VISIBLE_ITEMS = 8;
539
+ var Preview = ({
540
+ media,
541
+ curr,
542
+ prev,
543
+ next,
544
+ goTo
545
+ }) => {
546
+ if (!media.length) {
547
+ return null;
548
+ }
549
+ const getVisibleItems = (items, index) => {
550
+ if (items.length <= MAX_VISIBLE_ITEMS) {
551
+ return items;
552
+ }
553
+ const half = Math.floor(MAX_VISIBLE_ITEMS / 2);
554
+ const start = (index - half + items.length) % items.length;
555
+ const end = (start + MAX_VISIBLE_ITEMS) % items.length;
556
+ if (end < start) {
557
+ return [...items.slice(start), ...items.slice(0, end)];
558
+ }
559
+ return items.slice(start, end);
560
+ };
561
+ const visibleItems = getVisibleItems(media, curr);
562
+ return /* @__PURE__ */ jsxs2("div", { className: "flex shrink-0 items-center justify-center gap-x-2 border-t p-3", children: [
563
+ /* @__PURE__ */ jsx2(
564
+ IconButton,
565
+ {
566
+ size: "small",
567
+ variant: "transparent",
568
+ className: "text-ui-fg-muted",
569
+ type: "button",
570
+ onClick: prev,
571
+ children: /* @__PURE__ */ jsx2(TriangleLeftMini, { className: "rtl:rotate-180" })
572
+ }
573
+ ),
574
+ /* @__PURE__ */ jsx2("div", { className: "flex items-center gap-x-2", children: visibleItems.map((item) => {
575
+ const isCurrentImage = item.id === media[curr].id;
576
+ const originalIndex = media.findIndex((i) => i.id === item.id);
577
+ return /* @__PURE__ */ jsx2(
578
+ "button",
579
+ {
580
+ type: "button",
581
+ "aria-label": "Media file input",
582
+ onClick: () => goTo(originalIndex),
583
+ className: clx2(
584
+ "transition-fg size-7 overflow-hidden rounded-[4px] outline-none",
585
+ {
586
+ "shadow-borders-focus": isCurrentImage
587
+ }
588
+ ),
589
+ children: /* @__PURE__ */ jsx2("img", { src: item.url, alt: "", className: "size-full object-cover" })
590
+ },
591
+ item.id
592
+ );
593
+ }) }),
594
+ /* @__PURE__ */ jsx2(
595
+ IconButton,
596
+ {
597
+ size: "small",
598
+ variant: "transparent",
599
+ className: "text-ui-fg-muted",
600
+ type: "button",
601
+ onClick: next,
602
+ children: /* @__PURE__ */ jsx2(TriangleRightMini, { className: "rtl:rotate-180" })
603
+ }
604
+ )
605
+ ] });
606
+ };
607
+
608
+ // src/pages/categories/category-media/components/category-media-view/category-media-view-context.tsx
609
+ import { createContext } from "react";
610
+ var CategoryMediaViewContext = createContext(null);
611
+
612
+ // src/pages/categories/category-media/components/category-media-view/category-media-view.tsx
613
+ import { jsx as jsx3 } from "react/jsx-runtime";
614
+ var getView = (searchParams) => {
615
+ const view = searchParams.get("view");
616
+ if (view === "edit" /* EDIT */) {
617
+ return "edit" /* EDIT */;
618
+ }
619
+ return "gallery" /* GALLERY */;
620
+ };
621
+ var CategoryMediaView = ({ category }) => {
622
+ const [searchParams, setSearchParams] = useSearchParams();
623
+ const view = getView(searchParams);
624
+ const contextValue = useMemo(
625
+ () => ({
626
+ goToGallery: () => setSearchParams({ view: "gallery" /* GALLERY */ }),
627
+ goToEdit: () => setSearchParams({ view: "edit" /* EDIT */ })
628
+ }),
629
+ [setSearchParams]
630
+ );
631
+ return /* @__PURE__ */ jsx3(CategoryMediaViewContext.Provider, { value: contextValue, children: view === "edit" /* EDIT */ ? /* @__PURE__ */ jsx3(EditCategoryMediaForm, { category }) : /* @__PURE__ */ jsx3(CategoryMediaGallery, { category }) });
632
+ };
633
+
634
+ // src/pages/categories/category-media/category-media.tsx
635
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
636
+ var CategoryMedia = () => {
637
+ const { t } = useTranslation3();
638
+ const { id } = useParams();
639
+ const { product_category, isLoading, isError, error } = useProductCategory(
640
+ id
641
+ );
642
+ const ready = !isLoading && !!product_category;
643
+ if (isError) {
644
+ throw error;
645
+ }
646
+ return /* @__PURE__ */ jsxs3(RouteFocusModal, { "data-testid": "category-media-modal", children: [
647
+ /* @__PURE__ */ jsx4(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx4("span", { className: "sr-only", children: t("categories.media.label") }) }),
648
+ /* @__PURE__ */ jsx4(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx4("span", { className: "sr-only", children: t("categories.media.edit.description") }) }),
649
+ ready && /* @__PURE__ */ jsx4(CategoryMediaView, { category: product_category })
650
+ ] });
651
+ };
652
+ export {
653
+ CategoryMedia as Component
654
+ };