@mercurjs/vendor 2.0.0-canary.0
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/[id]-23D3HY3G.js +444 -0
- package/dist/[id]-2VBOAZM4.js +1215 -0
- package/dist/[id]-A4FSDRER.js +325 -0
- package/dist/[id]-E45G2SDA.js +213 -0
- package/dist/[id]-FXKSI52D.js +477 -0
- package/dist/[id]-HHZ3BSXV.js +1166 -0
- package/dist/[id]-MIV4U5UW.js +137 -0
- package/dist/[id]-QSRIPPIP.js +612 -0
- package/dist/[id]-RGDXOC7T.js +499 -0
- package/dist/[id]-TI2MOR2C.js +377 -0
- package/dist/[id]-U5DT2ZLS.js +301 -0
- package/dist/[id]-UMFGLDM2.js +354 -0
- package/dist/[id]-VTFOP3BF.js +97 -0
- package/dist/[id]-ZYF75L6G.js +479 -0
- package/dist/[location_id]-4UIEW5KM.js +685 -0
- package/dist/[province_id]-ZCHPXXQN.js +205 -0
- package/dist/add-KNDQL6YN.js +660 -0
- package/dist/add-customer-groups-JA346MTF.js +275 -0
- package/dist/add-products-2VB57KXV.js +273 -0
- package/dist/add-promotions-KVKEP6EO.js +260 -0
- package/dist/add-to-campaign-V6D7JKRS.js +44 -0
- package/dist/additional-attributes-E36EZX4V.js +219 -0
- package/dist/adjust-inventory-P7AB7VIB.js +228 -0
- package/dist/allocate-items-QAS5PZLR.js +529 -0
- package/dist/areas-Y7VDWH7G.js +151 -0
- package/dist/attributes-UEM2VJKV.js +277 -0
- package/dist/breadcrumb-3QTVWXZB.js +27 -0
- package/dist/breadcrumb-5OTOCYNL.js +38 -0
- package/dist/breadcrumb-6NAAOPIY.js +11 -0
- package/dist/breadcrumb-ASB2YCNV.js +25 -0
- package/dist/breadcrumb-CIGKLKKS.js +28 -0
- package/dist/breadcrumb-EOYLR3IQ.js +22 -0
- package/dist/breadcrumb-LENACUAA.js +22 -0
- package/dist/breadcrumb-LIXGWUQF.js +44 -0
- package/dist/breadcrumb-MOQ7GI3Z.js +27 -0
- package/dist/breadcrumb-NCBGPQML.js +23 -0
- package/dist/breadcrumb-OVMEC5OZ.js +33 -0
- package/dist/breadcrumb-RIXJ5QSX.js +45 -0
- package/dist/breadcrumb-TZB6EWNC.js +31 -0
- package/dist/breadcrumb-WP34OXGQ.js +23 -0
- package/dist/campaigns-PMVKUFEA.js +28 -0
- package/dist/categories-CKKIUMYG.js +27 -0
- package/dist/chunk-26OOAKQ6.js +18 -0
- package/dist/chunk-2C3HUJ3Z.js +222 -0
- package/dist/chunk-2F3H6ORE.js +36 -0
- package/dist/chunk-2ZFELO2L.js +13 -0
- package/dist/chunk-3CK6OINO.js +448 -0
- package/dist/chunk-3EF54XFY.js +64 -0
- package/dist/chunk-3LPVUPZZ.js +74 -0
- package/dist/chunk-3QSRE5LS.js +161 -0
- package/dist/chunk-3SIDRPKT.js +185 -0
- package/dist/chunk-4F5GP7J7.js +45 -0
- package/dist/chunk-4GPAS5GW.js +36 -0
- package/dist/chunk-4MFMCZEJ.js +70 -0
- package/dist/chunk-4TBDDMFP.js +425 -0
- package/dist/chunk-4TLP3TAA.js +34 -0
- package/dist/chunk-54TMLQH3.js +9 -0
- package/dist/chunk-5NF4OTVV.js +169 -0
- package/dist/chunk-66V3GFSW.js +138 -0
- package/dist/chunk-6EYGH3TB.js +26 -0
- package/dist/chunk-6IJMSVC6.js +16 -0
- package/dist/chunk-6YA3C4NB.js +55 -0
- package/dist/chunk-7AV5EJJ5.js +29 -0
- package/dist/chunk-7RPRNVBS.js +45 -0
- package/dist/chunk-A2SY5L5G.js +183 -0
- package/dist/chunk-A5DJIOHN.js +4 -0
- package/dist/chunk-AIFLEWO2.js +56 -0
- package/dist/chunk-ASVMGV2B.js +80 -0
- package/dist/chunk-AW77UWCZ.js +363 -0
- package/dist/chunk-AYUG34XF.js +84 -0
- package/dist/chunk-AYVH6Q5O.js +31 -0
- package/dist/chunk-B2RVONU7.js +160 -0
- package/dist/chunk-BCU3FKP2.js +18 -0
- package/dist/chunk-BDGZ4EQO.js +86 -0
- package/dist/chunk-BDZOSMAX.js +23 -0
- package/dist/chunk-C6SUTRP2.js +13 -0
- package/dist/chunk-CDIZEXFJ.js +145 -0
- package/dist/chunk-CFETU5BI.js +261 -0
- package/dist/chunk-CMHI2RPL.js +20 -0
- package/dist/chunk-CP5IL4P6.js +98 -0
- package/dist/chunk-CUO22GTM.js +96 -0
- package/dist/chunk-CVVYQI5F.js +41 -0
- package/dist/chunk-DARJTN4I.js +60 -0
- package/dist/chunk-DB6ANJBO.js +35 -0
- package/dist/chunk-DC2K6CFQ.js +86 -0
- package/dist/chunk-DDEIH66R.js +123 -0
- package/dist/chunk-DY3XQPHC.js +31 -0
- package/dist/chunk-DYUTYBAQ.js +67 -0
- package/dist/chunk-E3MNEQID.js +24 -0
- package/dist/chunk-FBZHM2QZ.js +247 -0
- package/dist/chunk-FDZC3TFZ.js +717 -0
- package/dist/chunk-FGCKXH45.js +263 -0
- package/dist/chunk-FMFVTERD.js +0 -0
- package/dist/chunk-FOMEBUX6.js +89 -0
- package/dist/chunk-FQERBIVS.js +0 -0
- package/dist/chunk-GC33DBKG.js +143 -0
- package/dist/chunk-GDMNHL7E.js +144 -0
- package/dist/chunk-GTUR4HSV.js +53 -0
- package/dist/chunk-H35HHFTB.js +225 -0
- package/dist/chunk-HB3BP55W.js +25 -0
- package/dist/chunk-HHD2VUED.js +29 -0
- package/dist/chunk-HUNGNEPY.js +312 -0
- package/dist/chunk-HUZG6A3X.js +127 -0
- package/dist/chunk-INNFZYX2.js +183 -0
- package/dist/chunk-IQPN4PZJ.js +749 -0
- package/dist/chunk-IZ5RG5XI.js +72 -0
- package/dist/chunk-J2XP7VRG.js +1080 -0
- package/dist/chunk-JHIMVLB2.js +42 -0
- package/dist/chunk-JKXAL7WR.js +92 -0
- package/dist/chunk-JRTZWK77.js +1764 -0
- package/dist/chunk-JVBLYMY2.js +268 -0
- package/dist/chunk-JXP5YZ77.js +86 -0
- package/dist/chunk-KAZ5BYTQ.js +132 -0
- package/dist/chunk-KHHY7EEM.js +267 -0
- package/dist/chunk-LAVHRER2.js +17 -0
- package/dist/chunk-LQSLDDPT.js +67 -0
- package/dist/chunk-LWVBKUUL.js +77 -0
- package/dist/chunk-LYUCDASZ.js +115 -0
- package/dist/chunk-LZ7QV42C.js +37 -0
- package/dist/chunk-MAEP2UCK.js +110 -0
- package/dist/chunk-MG4GKUJW.js +31 -0
- package/dist/chunk-N2TQXB44.js +1280 -0
- package/dist/chunk-N3T24SEK.js +32 -0
- package/dist/chunk-NANYVBFI.js +106 -0
- package/dist/chunk-NCMUZ6BQ.js +0 -0
- package/dist/chunk-NCYTM57J.js +160 -0
- package/dist/chunk-NX26QE2O.js +47 -0
- package/dist/chunk-NYDJTWRL.js +389 -0
- package/dist/chunk-O5LRZEG6.js +253 -0
- package/dist/chunk-O6PRBSFL.js +115 -0
- package/dist/chunk-OJCDB3N5.js +539 -0
- package/dist/chunk-OSFOX7MG.js +176 -0
- package/dist/chunk-OVPAOBZB.js +110 -0
- package/dist/chunk-PADOWAXM.js +118 -0
- package/dist/chunk-PHOCVOZ5.js +9 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/chunk-PLSJ74T2.js +298 -0
- package/dist/chunk-PVZBDWLK.js +41 -0
- package/dist/chunk-PWZKFTJS.js +247 -0
- package/dist/chunk-PXYDR7WQ.js +48 -0
- package/dist/chunk-PYQJ5N25.js +191 -0
- package/dist/chunk-Q4UVXS46.js +14 -0
- package/dist/chunk-QDPLZDMX.js +17 -0
- package/dist/chunk-QSGR43JM.js +30 -0
- package/dist/chunk-QUNDGPF7.js +92801 -0
- package/dist/chunk-R65A4P4H.js +136 -0
- package/dist/chunk-RE7YXVFG.js +128 -0
- package/dist/chunk-RETT6WME.js +37 -0
- package/dist/chunk-RHKRREUU.js +15 -0
- package/dist/chunk-RIILGKYR.js +32 -0
- package/dist/chunk-RM5RSDYP.js +353 -0
- package/dist/chunk-RNC4NFVK.js +170 -0
- package/dist/chunk-RSMZHZI2.js +2078 -0
- package/dist/chunk-RXM4B6HR.js +8 -0
- package/dist/chunk-S2WEYEQR.js +14 -0
- package/dist/chunk-S3PQKKNV.js +49 -0
- package/dist/chunk-S5GQ2SES.js +276 -0
- package/dist/chunk-SECZTXSU.js +31 -0
- package/dist/chunk-SI4ALL7W.js +180 -0
- package/dist/chunk-SID3COTK.js +21 -0
- package/dist/chunk-SMQT3ZNO.js +8 -0
- package/dist/chunk-SOZMJA7V.js +61 -0
- package/dist/chunk-TG3TCIL6.js +207 -0
- package/dist/chunk-THHRRYRS.js +16 -0
- package/dist/chunk-TKGWSUEI.js +0 -0
- package/dist/chunk-TTFCO5HU.js +173 -0
- package/dist/chunk-TXEPCJEQ.js +430 -0
- package/dist/chunk-U2EI2ZLM.js +32 -0
- package/dist/chunk-U2ZFCAPX.js +34 -0
- package/dist/chunk-U3X4DNV6.js +179 -0
- package/dist/chunk-UXKKD4AD.js +437 -0
- package/dist/chunk-UYJ65N46.js +261 -0
- package/dist/chunk-VDWGP2U6.js +71 -0
- package/dist/chunk-VGJTARSA.js +89 -0
- package/dist/chunk-VHMGJUYN.js +28 -0
- package/dist/chunk-VKC3XKFF.js +283 -0
- package/dist/chunk-VKOE5J66.js +31 -0
- package/dist/chunk-VOHEQ7B5.js +31 -0
- package/dist/chunk-VW56KWO2.js +9 -0
- package/dist/chunk-W4KHJ4D6.js +74 -0
- package/dist/chunk-W6Y3PPU5.js +73 -0
- package/dist/chunk-W6ZVQJYB.js +311 -0
- package/dist/chunk-WA3IVAUC.js +123 -0
- package/dist/chunk-WHTS4G5K.js +1551 -0
- package/dist/chunk-WIYFXWRI.js +30 -0
- package/dist/chunk-WPFTRRWV.js +455 -0
- package/dist/chunk-WQZ4ONQV.js +6 -0
- package/dist/chunk-WS652CCV.js +893 -0
- package/dist/chunk-XG4PTPRM.js +0 -0
- package/dist/chunk-XRNDVICA.js +85 -0
- package/dist/chunk-XXZJISPX.js +48 -0
- package/dist/chunk-Y224F4UU.js +81 -0
- package/dist/chunk-Y3FR5JC7.js +437 -0
- package/dist/chunk-Y4VBOHAP.js +111 -0
- package/dist/chunk-Y7QKP6QU.js +35 -0
- package/dist/chunk-YVCBMOJG.js +50 -0
- package/dist/chunk-Z2WPXJ6J.js +146 -0
- package/dist/chunk-ZA2KFUFR.js +19 -0
- package/dist/chunk-ZEKV7LGF.js +6 -0
- package/dist/chunk-ZFFA36DB.js +186 -0
- package/dist/chunk-ZPGWTLF2.js +499 -0
- package/dist/chunk-ZVT2QSWR.js +263 -0
- package/dist/chunk-ZZ7VKT2S.js +4113 -0
- package/dist/collections-TREF67TO.js +63 -0
- package/dist/configuration-KWAL2QZ5.js +152 -0
- package/dist/configuration-RNWBTRAH.js +205 -0
- package/dist/create-7UEEO5TM.js +125 -0
- package/dist/create-DTCDJMIT.js +634 -0
- package/dist/create-DYDRAY6V.js +622 -0
- package/dist/create-EJM5C2XP.js +27 -0
- package/dist/create-F7OMPGZV.js +853 -0
- package/dist/create-G4UJOJJ6.js +69 -0
- package/dist/create-IE6MYOIY.js +170 -0
- package/dist/create-L23TGTBH.js +225 -0
- package/dist/create-LOBCFTCT.js +583 -0
- package/dist/create-MKBBF2V3.js +150 -0
- package/dist/create-TFDUNJSI.js +163 -0
- package/dist/create-TMTZDKII.js +711 -0
- package/dist/create-XGF6DB5F.js +239 -0
- package/dist/create-YAAK7JQ3.js +1052 -0
- package/dist/create-YPCVTXAK.js +194 -0
- package/dist/create-ZU362U3B.js +310 -0
- package/dist/customers-4QWR5UOL.js +27 -0
- package/dist/edit-2QA5BVOY.js +735 -0
- package/dist/edit-47I7VVNB.js +167 -0
- package/dist/edit-5BUGSOTL.js +255 -0
- package/dist/edit-7LQATDUD.js +193 -0
- package/dist/edit-AQAPYMDY.js +260 -0
- package/dist/edit-BQLSTFTQ.js +138 -0
- package/dist/edit-BYXHU3IG.js +308 -0
- package/dist/edit-DG3MY3ZH.js +244 -0
- package/dist/edit-J3LD76JS.js +192 -0
- package/dist/edit-J6WCPHDS.js +205 -0
- package/dist/edit-KCZVZLSZ.js +131 -0
- package/dist/edit-LOKLQGM2.js +181 -0
- package/dist/edit-MDTTTB33.js +104 -0
- package/dist/edit-NFSU2K3O.js +413 -0
- package/dist/edit-RHNZWNXD.js +89 -0
- package/dist/edit-XU33IVZH.js +204 -0
- package/dist/edit-ZMINDMGM.js +116 -0
- package/dist/edit-budget-Z5USV462.js +145 -0
- package/dist/edit-inventory-item-YFW2AFRD.js +128 -0
- package/dist/edit-inventory-item-attributes-IYAMJDTB.js +278 -0
- package/dist/fulfillment-SKXAF3BZ.js +545 -0
- package/dist/fulfillment-providers-ACERVITQ.js +279 -0
- package/dist/home-PP7YYCSB.js +16 -0
- package/dist/index.css +6 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +3656 -0
- package/dist/inventory-AIRQ2KNS.js +26 -0
- package/dist/locations-SQKM7JWN.js +23 -0
- package/dist/login-LKFCRHXN.js +35 -0
- package/dist/manage-locations-4PQS4QY7.js +195 -0
- package/dist/media-PL477QJO.js +703 -0
- package/dist/metadata-42MU3H7T.js +60 -0
- package/dist/metadata-DIJTVDF7.js +45 -0
- package/dist/metadata-NX3LEEB3.js +64 -0
- package/dist/metadata-RBDSM567.js +65 -0
- package/dist/metadata-VZTWNZPG.js +66 -0
- package/dist/metadata-X3XGQ563.js +67 -0
- package/dist/no-match-BO2NNLCM.js +33 -0
- package/dist/orders-2KHCHNO5.js +59 -0
- package/dist/organization-VQXCKHCN.js +233 -0
- package/dist/organize-3F5ZUIGB.js +23 -0
- package/dist/organize-WPWEPCF7.js +23 -0
- package/dist/pages/index.d.ts +1153 -0
- package/dist/pages/index.js +198 -0
- package/dist/payouts-3BY73LZ3.js +27 -0
- package/dist/price-lists-G256JJN7.js +34 -0
- package/dist/prices-EW7KBY6R.js +269 -0
- package/dist/pricing-3PUJDOZN.js +313 -0
- package/dist/product-tags-PI3RENEX.js +80 -0
- package/dist/product-types-WJPLJI7H.js +32 -0
- package/dist/product-variant-detail-EYTE7PHL.js +377 -0
- package/dist/product-variant-edit-PW7W5J5E.js +402 -0
- package/dist/products-GSN4I7BT.js +272 -0
- package/dist/products-RFYNEY57.js +85 -0
- package/dist/promotions-CIZIDQ64.js +31 -0
- package/dist/reset-password-OFUSH363.js +299 -0
- package/dist/return-reasons-4V2KVSRI.js +52 -0
- package/dist/sales-channels-MBWVM3X2.js +184 -0
- package/dist/sales-channels-ZKA62EAW.js +156 -0
- package/dist/seller-ZFDLKF5Y.js +36 -0
- package/dist/settings-NP2IAID5.js +111 -0
- package/dist/shipping-profile-7FTHSPY2.js +145 -0
- package/dist/shipping-profiles-7R6L65WG.js +43 -0
- package/dist/stock-ENMBCZRY.js +502 -0
- package/dist/stock-VYDJY46S.js +278 -0
- package/dist/tax-regions-V6G6244H.js +87 -0
- package/package.json +87 -0
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UploadMediaFormItem
|
|
3
|
+
} from "./chunk-FOMEBUX6.js";
|
|
4
|
+
import {
|
|
5
|
+
EditProductMediaSchema
|
|
6
|
+
} from "./chunk-VKC3XKFF.js";
|
|
7
|
+
import "./chunk-IZ5RG5XI.js";
|
|
8
|
+
import "./chunk-SMQT3ZNO.js";
|
|
9
|
+
import "./chunk-QUNDGPF7.js";
|
|
10
|
+
import "./chunk-TKGWSUEI.js";
|
|
11
|
+
import {
|
|
12
|
+
KeyboundForm
|
|
13
|
+
} from "./chunk-U2ZFCAPX.js";
|
|
14
|
+
import {
|
|
15
|
+
RouteFocusModal,
|
|
16
|
+
useRouteModal
|
|
17
|
+
} from "./chunk-3CK6OINO.js";
|
|
18
|
+
import "./chunk-3QSRE5LS.js";
|
|
19
|
+
import {
|
|
20
|
+
useProduct,
|
|
21
|
+
useUpdateProduct
|
|
22
|
+
} from "./chunk-WPFTRRWV.js";
|
|
23
|
+
import "./chunk-A5DJIOHN.js";
|
|
24
|
+
import "./chunk-RHKRREUU.js";
|
|
25
|
+
import "./chunk-ZA2KFUFR.js";
|
|
26
|
+
import {
|
|
27
|
+
uploadFilesQuery
|
|
28
|
+
} from "./chunk-Y224F4UU.js";
|
|
29
|
+
import "./chunk-PKBMQBKP.js";
|
|
30
|
+
|
|
31
|
+
// src/pages/products/[id]/media/index.tsx
|
|
32
|
+
import { useTranslation as useTranslation3 } from "react-i18next";
|
|
33
|
+
import { useParams } from "react-router-dom";
|
|
34
|
+
|
|
35
|
+
// src/pages/products/[id]/media/product-media-view/product-media-view.tsx
|
|
36
|
+
import { useSearchParams } from "react-router-dom";
|
|
37
|
+
|
|
38
|
+
// src/pages/products/[id]/media/edit-product-media-form/edit-product-media-form.tsx
|
|
39
|
+
import {
|
|
40
|
+
defaultDropAnimationSideEffects,
|
|
41
|
+
DndContext,
|
|
42
|
+
DragOverlay,
|
|
43
|
+
KeyboardSensor,
|
|
44
|
+
PointerSensor,
|
|
45
|
+
useSensor,
|
|
46
|
+
useSensors
|
|
47
|
+
} from "@dnd-kit/core";
|
|
48
|
+
import {
|
|
49
|
+
arrayMove,
|
|
50
|
+
rectSortingStrategy,
|
|
51
|
+
SortableContext,
|
|
52
|
+
sortableKeyboardCoordinates,
|
|
53
|
+
useSortable
|
|
54
|
+
} from "@dnd-kit/sortable";
|
|
55
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
56
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
57
|
+
import { ThumbnailBadge } from "@medusajs/icons";
|
|
58
|
+
import { Button, Checkbox, clx, CommandBar, toast, Tooltip } from "@medusajs/ui";
|
|
59
|
+
import { Fragment, useCallback, useState } from "react";
|
|
60
|
+
import { useFieldArray, useForm } from "react-hook-form";
|
|
61
|
+
import { useTranslation } from "react-i18next";
|
|
62
|
+
import { Link } from "react-router-dom";
|
|
63
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
64
|
+
var EditProductMediaForm = ({ product }) => {
|
|
65
|
+
const [selection, setSelection] = useState({});
|
|
66
|
+
const { t } = useTranslation();
|
|
67
|
+
const { handleSuccess } = useRouteModal();
|
|
68
|
+
const form = useForm({
|
|
69
|
+
defaultValues: {
|
|
70
|
+
media: getDefaultValues(product.images, product.thumbnail)
|
|
71
|
+
},
|
|
72
|
+
resolver: zodResolver(EditProductMediaSchema)
|
|
73
|
+
});
|
|
74
|
+
const { fields, append, remove, update } = useFieldArray({
|
|
75
|
+
name: "media",
|
|
76
|
+
control: form.control,
|
|
77
|
+
keyName: "field_id"
|
|
78
|
+
});
|
|
79
|
+
const [activeId, setActiveId] = useState(null);
|
|
80
|
+
const sensors = useSensors(
|
|
81
|
+
useSensor(PointerSensor),
|
|
82
|
+
useSensor(KeyboardSensor, {
|
|
83
|
+
coordinateGetter: sortableKeyboardCoordinates
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
const handleDragStart = (event) => {
|
|
87
|
+
setActiveId(event.active.id);
|
|
88
|
+
};
|
|
89
|
+
const handleDragEnd = (event) => {
|
|
90
|
+
setActiveId(null);
|
|
91
|
+
const { active, over } = event;
|
|
92
|
+
if (active.id !== over?.id) {
|
|
93
|
+
const oldIndex = fields.findIndex((item) => item.field_id === active.id);
|
|
94
|
+
const newIndex = fields.findIndex((item) => item.field_id === over?.id);
|
|
95
|
+
form.setValue("media", arrayMove(fields, oldIndex, newIndex), {
|
|
96
|
+
shouldDirty: true,
|
|
97
|
+
shouldTouch: true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const handleDragCancel = () => {
|
|
102
|
+
setActiveId(null);
|
|
103
|
+
};
|
|
104
|
+
const { mutateAsync, isPending } = useUpdateProduct(product.id);
|
|
105
|
+
const handleSubmit = form.handleSubmit(async ({ media }) => {
|
|
106
|
+
const filesToUpload = media.map((m, i) => ({ file: m.file, index: i })).filter((m) => !!m.file);
|
|
107
|
+
let uploaded = [];
|
|
108
|
+
if (filesToUpload.length) {
|
|
109
|
+
const { files } = await uploadFilesQuery(filesToUpload).catch(() => {
|
|
110
|
+
form.setError("media", {
|
|
111
|
+
type: "invalid_file",
|
|
112
|
+
message: t("products.media.failedToUpload")
|
|
113
|
+
});
|
|
114
|
+
return { files: [] };
|
|
115
|
+
});
|
|
116
|
+
uploaded = files;
|
|
117
|
+
}
|
|
118
|
+
const withUpdatedUrls = media.map((entry, i) => {
|
|
119
|
+
const toUploadIndex = filesToUpload.findIndex((m) => m.index === i);
|
|
120
|
+
if (toUploadIndex > -1) {
|
|
121
|
+
return {
|
|
122
|
+
...entry,
|
|
123
|
+
url: uploaded[toUploadIndex]?.url
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return entry;
|
|
127
|
+
});
|
|
128
|
+
const thumbnail = withUpdatedUrls.find((m) => m.isThumbnail)?.url;
|
|
129
|
+
await mutateAsync(
|
|
130
|
+
{
|
|
131
|
+
images: withUpdatedUrls.map((file) => ({
|
|
132
|
+
url: file.url,
|
|
133
|
+
id: file.id
|
|
134
|
+
})),
|
|
135
|
+
thumbnail: thumbnail || null
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
onSuccess: () => {
|
|
139
|
+
toast.success(t("products.media.successToast"));
|
|
140
|
+
handleSuccess();
|
|
141
|
+
},
|
|
142
|
+
onError: (error) => {
|
|
143
|
+
toast.error(error.message);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
const handleCheckedChange = useCallback(
|
|
149
|
+
(id) => {
|
|
150
|
+
return (val) => {
|
|
151
|
+
if (!val) {
|
|
152
|
+
const { [id]: _, ...rest } = selection;
|
|
153
|
+
setSelection(rest);
|
|
154
|
+
} else {
|
|
155
|
+
setSelection((prev) => ({ ...prev, [id]: true }));
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
[selection]
|
|
160
|
+
);
|
|
161
|
+
const handleDelete = () => {
|
|
162
|
+
const ids = Object.keys(selection);
|
|
163
|
+
const indices = ids.map((id) => fields.findIndex((m) => m.id === id));
|
|
164
|
+
remove(indices);
|
|
165
|
+
setSelection({});
|
|
166
|
+
};
|
|
167
|
+
const handlePromoteToThumbnail = () => {
|
|
168
|
+
const ids = Object.keys(selection);
|
|
169
|
+
if (!ids.length) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const currentThumbnailIndex = fields.findIndex((m) => m.isThumbnail);
|
|
173
|
+
if (currentThumbnailIndex > -1) {
|
|
174
|
+
update(currentThumbnailIndex, {
|
|
175
|
+
...fields[currentThumbnailIndex],
|
|
176
|
+
isThumbnail: false
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const index = fields.findIndex((m) => m.id === ids[0]);
|
|
180
|
+
update(index, {
|
|
181
|
+
...fields[index],
|
|
182
|
+
isThumbnail: true
|
|
183
|
+
});
|
|
184
|
+
setSelection({});
|
|
185
|
+
};
|
|
186
|
+
const selectionCount = Object.keys(selection).length;
|
|
187
|
+
return /* @__PURE__ */ jsx(RouteFocusModal.Form, { blockSearchParams: true, form, children: /* @__PURE__ */ jsxs(
|
|
188
|
+
KeyboundForm,
|
|
189
|
+
{
|
|
190
|
+
className: "flex size-full flex-col overflow-hidden",
|
|
191
|
+
onSubmit: handleSubmit,
|
|
192
|
+
children: [
|
|
193
|
+
/* @__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("products.media.galleryLabel") }) }) }) }),
|
|
194
|
+
/* @__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: [
|
|
195
|
+
/* @__PURE__ */ jsx(
|
|
196
|
+
DndContext,
|
|
197
|
+
{
|
|
198
|
+
sensors,
|
|
199
|
+
onDragEnd: handleDragEnd,
|
|
200
|
+
onDragStart: handleDragStart,
|
|
201
|
+
onDragCancel: handleDragCancel,
|
|
202
|
+
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: [
|
|
203
|
+
/* @__PURE__ */ jsx(
|
|
204
|
+
SortableContext,
|
|
205
|
+
{
|
|
206
|
+
items: fields.map((m) => m.field_id),
|
|
207
|
+
strategy: rectSortingStrategy,
|
|
208
|
+
children: fields.map((m) => {
|
|
209
|
+
return /* @__PURE__ */ jsx(
|
|
210
|
+
MediaGridItem,
|
|
211
|
+
{
|
|
212
|
+
onCheckedChange: handleCheckedChange(m.id),
|
|
213
|
+
checked: !!selection[m.id],
|
|
214
|
+
media: m
|
|
215
|
+
},
|
|
216
|
+
m.field_id
|
|
217
|
+
);
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ jsx(DragOverlay, { dropAnimation: dropAnimationConfig, children: activeId ? /* @__PURE__ */ jsx(
|
|
222
|
+
MediaGridItemOverlay,
|
|
223
|
+
{
|
|
224
|
+
media: fields.find((m) => m.field_id === activeId),
|
|
225
|
+
checked: !!selection[fields.find((m) => m.field_id === activeId).id]
|
|
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__ */ jsx(UploadMediaFormItem, { form, append }) })
|
|
232
|
+
] }) }),
|
|
233
|
+
/* @__PURE__ */ jsx(CommandBar, { open: !!selectionCount, children: /* @__PURE__ */ jsxs(CommandBar.Bar, { children: [
|
|
234
|
+
/* @__PURE__ */ jsx(CommandBar.Value, { children: t("general.countSelected", {
|
|
235
|
+
count: selectionCount
|
|
236
|
+
}) }),
|
|
237
|
+
/* @__PURE__ */ jsx(CommandBar.Seperator, {}),
|
|
238
|
+
selectionCount === 1 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
239
|
+
/* @__PURE__ */ jsx(
|
|
240
|
+
CommandBar.Command,
|
|
241
|
+
{
|
|
242
|
+
action: handlePromoteToThumbnail,
|
|
243
|
+
label: t("products.media.makeThumbnail"),
|
|
244
|
+
shortcut: "t"
|
|
245
|
+
}
|
|
246
|
+
),
|
|
247
|
+
/* @__PURE__ */ jsx(CommandBar.Seperator, {})
|
|
248
|
+
] }),
|
|
249
|
+
/* @__PURE__ */ jsx(
|
|
250
|
+
CommandBar.Command,
|
|
251
|
+
{
|
|
252
|
+
action: handleDelete,
|
|
253
|
+
label: t("actions.delete"),
|
|
254
|
+
shortcut: "d"
|
|
255
|
+
}
|
|
256
|
+
)
|
|
257
|
+
] }) }),
|
|
258
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
259
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: t("actions.cancel") }) }),
|
|
260
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: t("actions.save") })
|
|
261
|
+
] }) })
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
) });
|
|
265
|
+
};
|
|
266
|
+
var getDefaultValues = (images, thumbnail) => {
|
|
267
|
+
const media = images?.map((image) => ({
|
|
268
|
+
id: image.id,
|
|
269
|
+
url: image.url,
|
|
270
|
+
isThumbnail: image.url === thumbnail,
|
|
271
|
+
file: null
|
|
272
|
+
})) || [];
|
|
273
|
+
if (thumbnail && !media.some((mediaItem) => mediaItem.url === thumbnail)) {
|
|
274
|
+
const id = Math.random().toString(36).substring(7);
|
|
275
|
+
media.unshift({
|
|
276
|
+
id,
|
|
277
|
+
url: thumbnail,
|
|
278
|
+
isThumbnail: true,
|
|
279
|
+
file: null
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return media;
|
|
283
|
+
};
|
|
284
|
+
var dropAnimationConfig = {
|
|
285
|
+
sideEffects: defaultDropAnimationSideEffects({
|
|
286
|
+
styles: {
|
|
287
|
+
active: {
|
|
288
|
+
opacity: "0.4"
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
};
|
|
293
|
+
var MediaGridItem = ({
|
|
294
|
+
media,
|
|
295
|
+
checked,
|
|
296
|
+
onCheckedChange
|
|
297
|
+
}) => {
|
|
298
|
+
const { t } = useTranslation();
|
|
299
|
+
const handleToggle = useCallback(
|
|
300
|
+
(value) => {
|
|
301
|
+
onCheckedChange(value);
|
|
302
|
+
},
|
|
303
|
+
[onCheckedChange]
|
|
304
|
+
);
|
|
305
|
+
const {
|
|
306
|
+
attributes,
|
|
307
|
+
listeners,
|
|
308
|
+
setNodeRef,
|
|
309
|
+
setActivatorNodeRef,
|
|
310
|
+
transform,
|
|
311
|
+
transition,
|
|
312
|
+
isDragging
|
|
313
|
+
} = useSortable({ id: media.field_id });
|
|
314
|
+
const style = {
|
|
315
|
+
opacity: isDragging ? 0.4 : void 0,
|
|
316
|
+
transform: CSS.Transform.toString(transform),
|
|
317
|
+
transition
|
|
318
|
+
};
|
|
319
|
+
return /* @__PURE__ */ jsxs(
|
|
320
|
+
"div",
|
|
321
|
+
{
|
|
322
|
+
className: clx(
|
|
323
|
+
"shadow-elevation-card-rest hover:shadow-elevation-card-hover focus-visible:shadow-borders-focus bg-ui-bg-subtle-hover group relative aspect-square h-auto max-w-full overflow-hidden rounded-lg outline-none"
|
|
324
|
+
),
|
|
325
|
+
style,
|
|
326
|
+
ref: setNodeRef,
|
|
327
|
+
children: [
|
|
328
|
+
media.isThumbnail && /* @__PURE__ */ jsx("div", { className: "absolute left-2 top-2", children: /* @__PURE__ */ jsx(Tooltip, { content: t("products.media.thumbnailTooltip"), children: /* @__PURE__ */ jsx(ThumbnailBadge, {}) }) }),
|
|
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) => {
|
|
351
|
+
e.stopPropagation();
|
|
352
|
+
},
|
|
353
|
+
checked,
|
|
354
|
+
onCheckedChange: handleToggle
|
|
355
|
+
}
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
),
|
|
359
|
+
/* @__PURE__ */ jsx(
|
|
360
|
+
"img",
|
|
361
|
+
{
|
|
362
|
+
src: media.url,
|
|
363
|
+
alt: "",
|
|
364
|
+
className: "size-full object-cover object-center"
|
|
365
|
+
}
|
|
366
|
+
)
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
};
|
|
371
|
+
var MediaGridItemOverlay = ({
|
|
372
|
+
media,
|
|
373
|
+
checked
|
|
374
|
+
}) => {
|
|
375
|
+
return /* @__PURE__ */ jsxs("div", { className: "shadow-elevation-card-rest hover:shadow-elevation-card-hover focus-visible:shadow-borders-focus bg-ui-bg-subtle-hover group relative aspect-square h-auto max-w-full cursor-grabbing overflow-hidden rounded-lg outline-none", children: [
|
|
376
|
+
media.isThumbnail && /* @__PURE__ */ jsx("div", { className: "absolute left-2 top-2", children: /* @__PURE__ */ jsx(ThumbnailBadge, {}) }),
|
|
377
|
+
/* @__PURE__ */ jsx(
|
|
378
|
+
"div",
|
|
379
|
+
{
|
|
380
|
+
className: clx("transition-fg absolute right-2 top-2 opacity-0", {
|
|
381
|
+
"opacity-100": checked
|
|
382
|
+
}),
|
|
383
|
+
children: /* @__PURE__ */ jsx(Checkbox, { checked })
|
|
384
|
+
}
|
|
385
|
+
),
|
|
386
|
+
/* @__PURE__ */ jsx(
|
|
387
|
+
"img",
|
|
388
|
+
{
|
|
389
|
+
src: media.url,
|
|
390
|
+
alt: "",
|
|
391
|
+
className: "size-full object-cover object-center"
|
|
392
|
+
}
|
|
393
|
+
)
|
|
394
|
+
] });
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// src/pages/products/[id]/media/product-media-gallery/product-media-gallery.tsx
|
|
398
|
+
import {
|
|
399
|
+
ArrowDownTray,
|
|
400
|
+
ThumbnailBadge as ThumbnailBadge2,
|
|
401
|
+
Trash,
|
|
402
|
+
TriangleLeftMini,
|
|
403
|
+
TriangleRightMini
|
|
404
|
+
} from "@medusajs/icons";
|
|
405
|
+
import { Button as Button2, IconButton, Text, Tooltip as Tooltip2, clx as clx2, usePrompt } from "@medusajs/ui";
|
|
406
|
+
import { useCallback as useCallback2, useEffect, useState as useState2 } from "react";
|
|
407
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
408
|
+
import { Link as Link2, useLocation } from "react-router-dom";
|
|
409
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
410
|
+
var ProductMediaGallery = ({ product }) => {
|
|
411
|
+
const { state } = useLocation();
|
|
412
|
+
const [curr, setCurr] = useState2(state?.curr || 0);
|
|
413
|
+
const { t } = useTranslation2();
|
|
414
|
+
const prompt = usePrompt();
|
|
415
|
+
const { mutateAsync, isPending } = useUpdateProduct(product.id);
|
|
416
|
+
const media = getMedia(product.images, product.thumbnail);
|
|
417
|
+
const next = useCallback2(() => {
|
|
418
|
+
if (isPending) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
setCurr((prev2) => (prev2 + 1) % media.length);
|
|
422
|
+
}, [media, isPending]);
|
|
423
|
+
const prev = useCallback2(() => {
|
|
424
|
+
if (isPending) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
setCurr((prev2) => (prev2 - 1 + media.length) % media.length);
|
|
428
|
+
}, [media, isPending]);
|
|
429
|
+
const goTo = useCallback2(
|
|
430
|
+
(index) => {
|
|
431
|
+
if (isPending) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
setCurr(index);
|
|
435
|
+
},
|
|
436
|
+
[isPending]
|
|
437
|
+
);
|
|
438
|
+
const handleDownloadCurrent = () => {
|
|
439
|
+
if (isPending) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const a = document.createElement("a");
|
|
443
|
+
a.href = media[curr].url;
|
|
444
|
+
a.download = "image";
|
|
445
|
+
a.target = "_blank";
|
|
446
|
+
a.click();
|
|
447
|
+
};
|
|
448
|
+
const handleDeleteCurrent = async () => {
|
|
449
|
+
const current = media[curr];
|
|
450
|
+
const res = await prompt({
|
|
451
|
+
title: t("general.areYouSure"),
|
|
452
|
+
description: current.isThumbnail ? t("products.media.deleteWarningWithThumbnail", { count: 1 }) : t("products.media.deleteWarning", { count: 1 }),
|
|
453
|
+
confirmText: t("actions.delete"),
|
|
454
|
+
cancelText: t("actions.cancel")
|
|
455
|
+
});
|
|
456
|
+
if (!res) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const mediaToKeep = product.images?.filter((i) => i.id !== current.id).map((i) => ({ url: i.url })) || [];
|
|
460
|
+
if (curr === media.length - 1) {
|
|
461
|
+
setCurr((prev2) => prev2 - 1);
|
|
462
|
+
}
|
|
463
|
+
await mutateAsync({
|
|
464
|
+
images: mediaToKeep,
|
|
465
|
+
thumbnail: current.isThumbnail ? "" : void 0
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
useEffect(() => {
|
|
469
|
+
const handleKeyDown = (e) => {
|
|
470
|
+
if (e.key === "ArrowRight") {
|
|
471
|
+
next();
|
|
472
|
+
} else if (e.key === "ArrowLeft") {
|
|
473
|
+
prev();
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
477
|
+
return () => {
|
|
478
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
479
|
+
};
|
|
480
|
+
}, [next, prev]);
|
|
481
|
+
const noMedia = !media.length;
|
|
482
|
+
return /* @__PURE__ */ jsxs2("div", { className: "flex size-full flex-col overflow-hidden", children: [
|
|
483
|
+
/* @__PURE__ */ jsx2(RouteFocusModal.Header, { children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
484
|
+
/* @__PURE__ */ jsxs2(
|
|
485
|
+
IconButton,
|
|
486
|
+
{
|
|
487
|
+
size: "small",
|
|
488
|
+
type: "button",
|
|
489
|
+
onClick: handleDeleteCurrent,
|
|
490
|
+
disabled: noMedia,
|
|
491
|
+
children: [
|
|
492
|
+
/* @__PURE__ */ jsx2(Trash, {}),
|
|
493
|
+
/* @__PURE__ */ jsx2("span", { className: "sr-only", children: t("products.media.deleteImageLabel") })
|
|
494
|
+
]
|
|
495
|
+
}
|
|
496
|
+
),
|
|
497
|
+
/* @__PURE__ */ jsxs2(
|
|
498
|
+
IconButton,
|
|
499
|
+
{
|
|
500
|
+
size: "small",
|
|
501
|
+
type: "button",
|
|
502
|
+
onClick: handleDownloadCurrent,
|
|
503
|
+
disabled: noMedia,
|
|
504
|
+
children: [
|
|
505
|
+
/* @__PURE__ */ jsx2(ArrowDownTray, {}),
|
|
506
|
+
/* @__PURE__ */ jsx2("span", { className: "sr-only", children: t("products.media.downloadImageLabel") })
|
|
507
|
+
]
|
|
508
|
+
}
|
|
509
|
+
),
|
|
510
|
+
/* @__PURE__ */ jsx2(Button2, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsx2(Link2, { to: { pathname: ".", search: "view=edit" }, children: t("actions.edit") }) })
|
|
511
|
+
] }) }),
|
|
512
|
+
/* @__PURE__ */ jsxs2(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: [
|
|
513
|
+
/* @__PURE__ */ jsx2(Canvas, { curr, media }),
|
|
514
|
+
/* @__PURE__ */ jsx2(
|
|
515
|
+
Preview,
|
|
516
|
+
{
|
|
517
|
+
curr,
|
|
518
|
+
media,
|
|
519
|
+
prev,
|
|
520
|
+
next,
|
|
521
|
+
goTo
|
|
522
|
+
}
|
|
523
|
+
)
|
|
524
|
+
] })
|
|
525
|
+
] });
|
|
526
|
+
};
|
|
527
|
+
var Canvas = ({ media, curr }) => {
|
|
528
|
+
const { t } = useTranslation2();
|
|
529
|
+
if (media.length === 0) {
|
|
530
|
+
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: [
|
|
531
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center", children: [
|
|
532
|
+
/* @__PURE__ */ jsx2(
|
|
533
|
+
Text,
|
|
534
|
+
{
|
|
535
|
+
size: "small",
|
|
536
|
+
leading: "compact",
|
|
537
|
+
weight: "plus",
|
|
538
|
+
className: "text-ui-fg-subtle",
|
|
539
|
+
children: t("products.media.emptyState.header")
|
|
540
|
+
}
|
|
541
|
+
),
|
|
542
|
+
/* @__PURE__ */ jsx2(Text, { size: "small", className: "text-ui-fg-muted", children: t("products.media.emptyState.description") })
|
|
543
|
+
] }),
|
|
544
|
+
/* @__PURE__ */ jsx2(Button2, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx2(Link2, { to: "?view=edit", children: t("products.media.emptyState.action") }) })
|
|
545
|
+
] });
|
|
546
|
+
}
|
|
547
|
+
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: [
|
|
548
|
+
media[curr].isThumbnail && /* @__PURE__ */ jsx2("div", { className: "absolute left-2 top-2", children: /* @__PURE__ */ jsx2(Tooltip2, { content: t("products.media.thumbnailTooltip"), children: /* @__PURE__ */ jsx2(ThumbnailBadge2, {}) }) }),
|
|
549
|
+
/* @__PURE__ */ jsx2(
|
|
550
|
+
"img",
|
|
551
|
+
{
|
|
552
|
+
src: media[curr].url,
|
|
553
|
+
alt: "",
|
|
554
|
+
className: "object-fit shadow-elevation-card-rest max-h-[calc(100vh-200px)] w-auto rounded-xl object-contain"
|
|
555
|
+
}
|
|
556
|
+
)
|
|
557
|
+
] }) }) });
|
|
558
|
+
};
|
|
559
|
+
var MAX_VISIBLE_ITEMS = 8;
|
|
560
|
+
var Preview = ({
|
|
561
|
+
media,
|
|
562
|
+
curr,
|
|
563
|
+
prev,
|
|
564
|
+
next,
|
|
565
|
+
goTo
|
|
566
|
+
}) => {
|
|
567
|
+
if (!media.length) {
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
const getVisibleItems = (media2, index) => {
|
|
571
|
+
if (media2.length <= MAX_VISIBLE_ITEMS) {
|
|
572
|
+
return media2;
|
|
573
|
+
}
|
|
574
|
+
const half = Math.floor(MAX_VISIBLE_ITEMS / 2);
|
|
575
|
+
const start = (index - half + media2.length) % media2.length;
|
|
576
|
+
const end = (start + MAX_VISIBLE_ITEMS) % media2.length;
|
|
577
|
+
if (end < start) {
|
|
578
|
+
return [...media2.slice(start), ...media2.slice(0, end)];
|
|
579
|
+
} else {
|
|
580
|
+
return media2.slice(start, end);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
const visibleItems = getVisibleItems(media, curr);
|
|
584
|
+
return /* @__PURE__ */ jsxs2("div", { className: "flex shrink-0 items-center justify-center gap-x-2 border-t p-3", children: [
|
|
585
|
+
/* @__PURE__ */ jsx2(
|
|
586
|
+
IconButton,
|
|
587
|
+
{
|
|
588
|
+
size: "small",
|
|
589
|
+
variant: "transparent",
|
|
590
|
+
className: "text-ui-fg-muted",
|
|
591
|
+
type: "button",
|
|
592
|
+
onClick: prev,
|
|
593
|
+
children: /* @__PURE__ */ jsx2(TriangleLeftMini, {})
|
|
594
|
+
}
|
|
595
|
+
),
|
|
596
|
+
/* @__PURE__ */ jsx2("div", { className: "flex items-center gap-x-2", children: visibleItems.map((item) => {
|
|
597
|
+
const isCurrentImage = item.id === media[curr].id;
|
|
598
|
+
const originalIndex = media.findIndex((i) => i.id === item.id);
|
|
599
|
+
return /* @__PURE__ */ jsx2(
|
|
600
|
+
"button",
|
|
601
|
+
{
|
|
602
|
+
type: "button",
|
|
603
|
+
onClick: () => goTo(originalIndex),
|
|
604
|
+
className: clx2(
|
|
605
|
+
"transition-fg size-7 overflow-hidden rounded-[4px] outline-none",
|
|
606
|
+
{
|
|
607
|
+
"shadow-borders-focus": isCurrentImage
|
|
608
|
+
}
|
|
609
|
+
),
|
|
610
|
+
children: /* @__PURE__ */ jsx2("img", { src: item.url, alt: "", className: "size-full object-cover" })
|
|
611
|
+
},
|
|
612
|
+
item.id
|
|
613
|
+
);
|
|
614
|
+
}) }),
|
|
615
|
+
/* @__PURE__ */ jsx2(
|
|
616
|
+
IconButton,
|
|
617
|
+
{
|
|
618
|
+
size: "small",
|
|
619
|
+
variant: "transparent",
|
|
620
|
+
className: "text-ui-fg-muted",
|
|
621
|
+
type: "button",
|
|
622
|
+
onClick: next,
|
|
623
|
+
children: /* @__PURE__ */ jsx2(TriangleRightMini, {})
|
|
624
|
+
}
|
|
625
|
+
)
|
|
626
|
+
] });
|
|
627
|
+
};
|
|
628
|
+
var getMedia = (images, thumbnail) => {
|
|
629
|
+
const media = images?.map((image) => ({
|
|
630
|
+
id: image.id,
|
|
631
|
+
url: image.url,
|
|
632
|
+
isThumbnail: image.url === thumbnail
|
|
633
|
+
})) || [];
|
|
634
|
+
if (thumbnail && !media.some((mediaItem) => mediaItem.isThumbnail)) {
|
|
635
|
+
media.unshift({
|
|
636
|
+
id: "thumbnail_only",
|
|
637
|
+
url: thumbnail,
|
|
638
|
+
isThumbnail: true
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
return media;
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// src/pages/products/[id]/media/product-media-view/product-media-view-context.tsx
|
|
645
|
+
import { createContext } from "react";
|
|
646
|
+
var ProductMediaViewContext = createContext(null);
|
|
647
|
+
|
|
648
|
+
// src/pages/products/[id]/media/product-media-view/product-media-view.tsx
|
|
649
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
650
|
+
var getView = (searchParams) => {
|
|
651
|
+
const view = searchParams.get("view");
|
|
652
|
+
if (view === "edit" /* EDIT */) {
|
|
653
|
+
return "edit" /* EDIT */;
|
|
654
|
+
}
|
|
655
|
+
return "gallery" /* GALLERY */;
|
|
656
|
+
};
|
|
657
|
+
var ProductMediaView = ({ product }) => {
|
|
658
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
659
|
+
const view = getView(searchParams);
|
|
660
|
+
const handleGoToView = (view2) => {
|
|
661
|
+
return () => {
|
|
662
|
+
setSearchParams({ view: view2 });
|
|
663
|
+
};
|
|
664
|
+
};
|
|
665
|
+
return /* @__PURE__ */ jsx3(
|
|
666
|
+
ProductMediaViewContext.Provider,
|
|
667
|
+
{
|
|
668
|
+
value: {
|
|
669
|
+
goToGallery: handleGoToView("gallery" /* GALLERY */),
|
|
670
|
+
goToEdit: handleGoToView("edit" /* EDIT */)
|
|
671
|
+
},
|
|
672
|
+
children: renderView(view, product)
|
|
673
|
+
}
|
|
674
|
+
);
|
|
675
|
+
};
|
|
676
|
+
var renderView = (view, product) => {
|
|
677
|
+
switch (view) {
|
|
678
|
+
case "gallery" /* GALLERY */:
|
|
679
|
+
return /* @__PURE__ */ jsx3(ProductMediaGallery, { product });
|
|
680
|
+
case "edit" /* EDIT */:
|
|
681
|
+
return /* @__PURE__ */ jsx3(EditProductMediaForm, { product });
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
// src/pages/products/[id]/media/index.tsx
|
|
686
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
687
|
+
var Component = () => {
|
|
688
|
+
const { t } = useTranslation3();
|
|
689
|
+
const { id } = useParams();
|
|
690
|
+
const { product, isLoading, isError, error } = useProduct(id);
|
|
691
|
+
const ready = !isLoading && product;
|
|
692
|
+
if (isError) {
|
|
693
|
+
throw error;
|
|
694
|
+
}
|
|
695
|
+
return /* @__PURE__ */ jsxs3(RouteFocusModal, { children: [
|
|
696
|
+
/* @__PURE__ */ jsx4(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx4("span", { className: "sr-only", children: t("products.media.label") }) }),
|
|
697
|
+
/* @__PURE__ */ jsx4(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx4("span", { className: "sr-only", children: t("products.media.editHint") }) }),
|
|
698
|
+
ready && /* @__PURE__ */ jsx4(ProductMediaView, { product })
|
|
699
|
+
] });
|
|
700
|
+
};
|
|
701
|
+
export {
|
|
702
|
+
Component
|
|
703
|
+
};
|