@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,893 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RouteFocusModal
|
|
3
|
+
} from "./chunk-3CK6OINO.js";
|
|
4
|
+
import {
|
|
5
|
+
categoriesQueryKeys,
|
|
6
|
+
useProductCategories
|
|
7
|
+
} from "./chunk-ASVMGV2B.js";
|
|
8
|
+
import {
|
|
9
|
+
queryClient
|
|
10
|
+
} from "./chunk-RHKRREUU.js";
|
|
11
|
+
import {
|
|
12
|
+
fetchQuery
|
|
13
|
+
} from "./chunk-Y224F4UU.js";
|
|
14
|
+
|
|
15
|
+
// src/pages/categories/[id]/organize/organize-category-form/organize-category-form.tsx
|
|
16
|
+
import { useMutation } from "@tanstack/react-query";
|
|
17
|
+
import { Spinner } from "@medusajs/icons";
|
|
18
|
+
import { toast } from "@medusajs/ui";
|
|
19
|
+
import { useState as useState2 } from "react";
|
|
20
|
+
|
|
21
|
+
// src/components/common/sortable-tree/sortable-tree.tsx
|
|
22
|
+
import {
|
|
23
|
+
DndContext,
|
|
24
|
+
DragOverlay,
|
|
25
|
+
KeyboardSensor,
|
|
26
|
+
MeasuringStrategy,
|
|
27
|
+
PointerSensor,
|
|
28
|
+
closestCenter,
|
|
29
|
+
defaultDropAnimation,
|
|
30
|
+
useSensor,
|
|
31
|
+
useSensors
|
|
32
|
+
} from "@dnd-kit/core";
|
|
33
|
+
import {
|
|
34
|
+
SortableContext,
|
|
35
|
+
arrayMove as arrayMove2,
|
|
36
|
+
verticalListSortingStrategy
|
|
37
|
+
} from "@dnd-kit/sortable";
|
|
38
|
+
import { CSS as CSS2 } from "@dnd-kit/utilities";
|
|
39
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
40
|
+
import { createPortal } from "react-dom";
|
|
41
|
+
|
|
42
|
+
// src/components/common/sortable-tree/keyboard-coordinates.ts
|
|
43
|
+
import {
|
|
44
|
+
KeyboardCode,
|
|
45
|
+
closestCorners,
|
|
46
|
+
getFirstCollision
|
|
47
|
+
} from "@dnd-kit/core";
|
|
48
|
+
|
|
49
|
+
// src/components/common/sortable-tree/utils.ts
|
|
50
|
+
import { arrayMove } from "@dnd-kit/sortable";
|
|
51
|
+
var iOS = /iPad|iPhone|iPod/.test(navigator.platform);
|
|
52
|
+
function getDragDepth(offset, indentationWidth) {
|
|
53
|
+
return Math.round(offset / indentationWidth);
|
|
54
|
+
}
|
|
55
|
+
function getProjection(items, activeId, overId, dragOffset, indentationWidth) {
|
|
56
|
+
const overItemIndex = items.findIndex(({ id }) => id === overId);
|
|
57
|
+
const activeItemIndex = items.findIndex(({ id }) => id === activeId);
|
|
58
|
+
const activeItem = items[activeItemIndex];
|
|
59
|
+
const newItems = arrayMove(items, activeItemIndex, overItemIndex);
|
|
60
|
+
const previousItem = newItems[overItemIndex - 1];
|
|
61
|
+
const nextItem = newItems[overItemIndex + 1];
|
|
62
|
+
const dragDepth = getDragDepth(dragOffset, indentationWidth);
|
|
63
|
+
const projectedDepth = activeItem.depth + dragDepth;
|
|
64
|
+
const maxDepth = getMaxDepth({
|
|
65
|
+
previousItem
|
|
66
|
+
});
|
|
67
|
+
const minDepth = getMinDepth({ nextItem });
|
|
68
|
+
let depth = projectedDepth;
|
|
69
|
+
if (projectedDepth >= maxDepth) {
|
|
70
|
+
depth = maxDepth;
|
|
71
|
+
} else if (projectedDepth < minDepth) {
|
|
72
|
+
depth = minDepth;
|
|
73
|
+
}
|
|
74
|
+
return { depth, maxDepth, minDepth, parentId: getParentId() };
|
|
75
|
+
function getParentId() {
|
|
76
|
+
if (depth === 0 || !previousItem) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (depth === previousItem.depth) {
|
|
80
|
+
return previousItem.parentId;
|
|
81
|
+
}
|
|
82
|
+
if (depth > previousItem.depth) {
|
|
83
|
+
return previousItem.id;
|
|
84
|
+
}
|
|
85
|
+
const newParent = newItems.slice(0, overItemIndex).reverse().find((item) => item.depth === depth)?.parentId;
|
|
86
|
+
return newParent ?? null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function getMaxDepth({ previousItem }) {
|
|
90
|
+
if (previousItem) {
|
|
91
|
+
return previousItem.depth + 1;
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
function getMinDepth({ nextItem }) {
|
|
96
|
+
if (nextItem) {
|
|
97
|
+
return nextItem.depth;
|
|
98
|
+
}
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
function flatten(items, parentId = null, depth = 0, childrenProp) {
|
|
102
|
+
return items.reduce((acc, item, index) => {
|
|
103
|
+
const children = item[childrenProp] || [];
|
|
104
|
+
return [
|
|
105
|
+
...acc,
|
|
106
|
+
{ ...item, parentId, depth, index },
|
|
107
|
+
...flatten(children, item.id, depth + 1, childrenProp)
|
|
108
|
+
];
|
|
109
|
+
}, []);
|
|
110
|
+
}
|
|
111
|
+
function flattenTree(items, childrenProp) {
|
|
112
|
+
return flatten(items, void 0, void 0, childrenProp);
|
|
113
|
+
}
|
|
114
|
+
function buildTree(flattenedItems, newIndex, childrenProp) {
|
|
115
|
+
const root = { id: "root", [childrenProp]: [] };
|
|
116
|
+
const nodes = { [root.id]: root };
|
|
117
|
+
const items = flattenedItems.map((item) => ({ ...item, [childrenProp]: [] }));
|
|
118
|
+
let update = {
|
|
119
|
+
id: null,
|
|
120
|
+
parentId: null,
|
|
121
|
+
index: 0
|
|
122
|
+
};
|
|
123
|
+
items.forEach((item, index) => {
|
|
124
|
+
const {
|
|
125
|
+
id,
|
|
126
|
+
index: _index,
|
|
127
|
+
depth: _depth,
|
|
128
|
+
parentId: _parentId,
|
|
129
|
+
...rest
|
|
130
|
+
} = item;
|
|
131
|
+
const children = item[childrenProp] || [];
|
|
132
|
+
const parentId = _parentId ?? root.id;
|
|
133
|
+
const parent = nodes[parentId] ?? findItem(items, parentId);
|
|
134
|
+
nodes[id] = { id, [childrenProp]: children };
|
|
135
|
+
parent[childrenProp].push({
|
|
136
|
+
id,
|
|
137
|
+
...rest,
|
|
138
|
+
[childrenProp]: children
|
|
139
|
+
});
|
|
140
|
+
if (index === newIndex) {
|
|
141
|
+
const parentChildren = parent[childrenProp];
|
|
142
|
+
update = {
|
|
143
|
+
id: item.id,
|
|
144
|
+
parentId: parent.id === "root" ? null : parent.id,
|
|
145
|
+
index: parentChildren.length - 1
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
if (!update.id) {
|
|
150
|
+
throw new Error("Could not find item");
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
items: root[childrenProp],
|
|
154
|
+
update
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function findItem(items, itemId) {
|
|
158
|
+
return items.find(({ id }) => id === itemId);
|
|
159
|
+
}
|
|
160
|
+
function findItemDeep(items, itemId, childrenProp) {
|
|
161
|
+
for (const item of items) {
|
|
162
|
+
const { id } = item;
|
|
163
|
+
const children = item[childrenProp] || [];
|
|
164
|
+
if (id === itemId) {
|
|
165
|
+
return item;
|
|
166
|
+
}
|
|
167
|
+
if (children.length) {
|
|
168
|
+
const child = findItemDeep(children, itemId, childrenProp);
|
|
169
|
+
if (child) {
|
|
170
|
+
return child;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
function countChildren(items, count = 0, childrenProp) {
|
|
177
|
+
return items.reduce((acc, item) => {
|
|
178
|
+
const children = item[childrenProp] || [];
|
|
179
|
+
if (children.length) {
|
|
180
|
+
return countChildren(children, acc + 1, childrenProp);
|
|
181
|
+
}
|
|
182
|
+
return acc + 1;
|
|
183
|
+
}, count);
|
|
184
|
+
}
|
|
185
|
+
function getChildCount(items, id, childrenProp) {
|
|
186
|
+
const item = findItemDeep(items, id, childrenProp);
|
|
187
|
+
const children = item?.[childrenProp] || [];
|
|
188
|
+
return item ? countChildren(children, 0, childrenProp) : 0;
|
|
189
|
+
}
|
|
190
|
+
function removeChildrenOf(items, ids, childrenProp) {
|
|
191
|
+
const excludeParentIds = [...ids];
|
|
192
|
+
return items.filter((item) => {
|
|
193
|
+
if (item.parentId && excludeParentIds.includes(item.parentId)) {
|
|
194
|
+
const children = item[childrenProp] || [];
|
|
195
|
+
if (children.length) {
|
|
196
|
+
excludeParentIds.push(item.id);
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/components/common/sortable-tree/keyboard-coordinates.ts
|
|
205
|
+
var directions = [
|
|
206
|
+
KeyboardCode.Down,
|
|
207
|
+
KeyboardCode.Right,
|
|
208
|
+
KeyboardCode.Up,
|
|
209
|
+
KeyboardCode.Left
|
|
210
|
+
];
|
|
211
|
+
var horizontal = [KeyboardCode.Left, KeyboardCode.Right];
|
|
212
|
+
var sortableTreeKeyboardCoordinates = (context, indentationWidth) => (event, {
|
|
213
|
+
currentCoordinates,
|
|
214
|
+
context: {
|
|
215
|
+
active,
|
|
216
|
+
over,
|
|
217
|
+
collisionRect,
|
|
218
|
+
droppableRects,
|
|
219
|
+
droppableContainers
|
|
220
|
+
}
|
|
221
|
+
}) => {
|
|
222
|
+
if (directions.includes(event.code)) {
|
|
223
|
+
if (!active || !collisionRect) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
const {
|
|
228
|
+
current: { items, offset }
|
|
229
|
+
} = context;
|
|
230
|
+
if (horizontal.includes(event.code) && over?.id) {
|
|
231
|
+
const { depth, maxDepth, minDepth } = getProjection(
|
|
232
|
+
items,
|
|
233
|
+
active.id,
|
|
234
|
+
over.id,
|
|
235
|
+
offset,
|
|
236
|
+
indentationWidth
|
|
237
|
+
);
|
|
238
|
+
switch (event.code) {
|
|
239
|
+
case KeyboardCode.Left:
|
|
240
|
+
if (depth > minDepth) {
|
|
241
|
+
return {
|
|
242
|
+
...currentCoordinates,
|
|
243
|
+
x: currentCoordinates.x - indentationWidth
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case KeyboardCode.Right:
|
|
248
|
+
if (depth < maxDepth) {
|
|
249
|
+
return {
|
|
250
|
+
...currentCoordinates,
|
|
251
|
+
x: currentCoordinates.x + indentationWidth
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
return void 0;
|
|
257
|
+
}
|
|
258
|
+
const containers = [];
|
|
259
|
+
droppableContainers.forEach((container) => {
|
|
260
|
+
if (container?.disabled || container.id === over?.id) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const rect = droppableRects.get(container.id);
|
|
264
|
+
if (!rect) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
switch (event.code) {
|
|
268
|
+
case KeyboardCode.Down:
|
|
269
|
+
if (collisionRect.top < rect.top) {
|
|
270
|
+
containers.push(container);
|
|
271
|
+
}
|
|
272
|
+
break;
|
|
273
|
+
case KeyboardCode.Up:
|
|
274
|
+
if (collisionRect.top > rect.top) {
|
|
275
|
+
containers.push(container);
|
|
276
|
+
}
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
const collisions = closestCorners({
|
|
281
|
+
active,
|
|
282
|
+
collisionRect,
|
|
283
|
+
pointerCoordinates: null,
|
|
284
|
+
droppableRects,
|
|
285
|
+
droppableContainers: containers
|
|
286
|
+
});
|
|
287
|
+
let closestId = getFirstCollision(collisions, "id");
|
|
288
|
+
if (closestId === over?.id && collisions.length > 1) {
|
|
289
|
+
closestId = collisions[1].id;
|
|
290
|
+
}
|
|
291
|
+
if (closestId && over?.id) {
|
|
292
|
+
const activeRect = droppableRects.get(active.id);
|
|
293
|
+
const newRect = droppableRects.get(closestId);
|
|
294
|
+
const newDroppable = droppableContainers.get(closestId);
|
|
295
|
+
if (activeRect && newRect && newDroppable) {
|
|
296
|
+
const newIndex = items.findIndex(({ id }) => id === closestId);
|
|
297
|
+
const newItem = items[newIndex];
|
|
298
|
+
const activeIndex = items.findIndex(({ id }) => id === active.id);
|
|
299
|
+
const activeItem = items[activeIndex];
|
|
300
|
+
if (newItem && activeItem) {
|
|
301
|
+
const { depth } = getProjection(
|
|
302
|
+
items,
|
|
303
|
+
active.id,
|
|
304
|
+
closestId,
|
|
305
|
+
(newItem.depth - activeItem.depth) * indentationWidth,
|
|
306
|
+
indentationWidth
|
|
307
|
+
);
|
|
308
|
+
const isBelow = newIndex > activeIndex;
|
|
309
|
+
const modifier = isBelow ? 1 : -1;
|
|
310
|
+
const offset2 = 0;
|
|
311
|
+
const newCoordinates = {
|
|
312
|
+
x: newRect.left + depth * indentationWidth,
|
|
313
|
+
y: newRect.top + modifier * offset2
|
|
314
|
+
};
|
|
315
|
+
return newCoordinates;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return void 0;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// src/components/common/sortable-tree/sortable-tree-item.tsx
|
|
324
|
+
import { useSortable } from "@dnd-kit/sortable";
|
|
325
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
326
|
+
|
|
327
|
+
// src/components/common/sortable-tree/tree-item.tsx
|
|
328
|
+
import { forwardRef } from "react";
|
|
329
|
+
import {
|
|
330
|
+
DotsSix,
|
|
331
|
+
FolderIllustration,
|
|
332
|
+
FolderOpenIllustration,
|
|
333
|
+
TagIllustration,
|
|
334
|
+
TriangleRightMini
|
|
335
|
+
} from "@medusajs/icons";
|
|
336
|
+
import { Badge, clx, IconButton } from "@medusajs/ui";
|
|
337
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
338
|
+
var TreeItem = forwardRef(
|
|
339
|
+
({
|
|
340
|
+
childCount,
|
|
341
|
+
clone,
|
|
342
|
+
depth,
|
|
343
|
+
disableSelection,
|
|
344
|
+
disableInteraction,
|
|
345
|
+
ghost,
|
|
346
|
+
handleProps,
|
|
347
|
+
indentationWidth,
|
|
348
|
+
collapsed,
|
|
349
|
+
onCollapse,
|
|
350
|
+
style,
|
|
351
|
+
value,
|
|
352
|
+
disabled,
|
|
353
|
+
wrapperRef,
|
|
354
|
+
...props
|
|
355
|
+
}, ref) => {
|
|
356
|
+
return /* @__PURE__ */ jsx(
|
|
357
|
+
"li",
|
|
358
|
+
{
|
|
359
|
+
ref: wrapperRef,
|
|
360
|
+
style: {
|
|
361
|
+
paddingLeft: `${indentationWidth * depth}px`
|
|
362
|
+
},
|
|
363
|
+
className: clx("-mb-px list-none", {
|
|
364
|
+
"pointer-events-none": disableInteraction,
|
|
365
|
+
"select-none": disableSelection,
|
|
366
|
+
"[&:first-of-type>div]:border-t-0": !clone
|
|
367
|
+
}),
|
|
368
|
+
...props,
|
|
369
|
+
children: /* @__PURE__ */ jsxs(
|
|
370
|
+
"div",
|
|
371
|
+
{
|
|
372
|
+
ref,
|
|
373
|
+
style,
|
|
374
|
+
className: clx(
|
|
375
|
+
"bg-ui-bg-base transition-fg relative flex items-center gap-x-3 border-y px-6 py-2.5",
|
|
376
|
+
{
|
|
377
|
+
"border-l": depth > 0,
|
|
378
|
+
"shadow-elevation-flyout bg-ui-bg-base w-fit rounded-lg border-none pr-6 opacity-80": clone,
|
|
379
|
+
"bg-ui-bg-base-hover z-[1] opacity-50": ghost,
|
|
380
|
+
"bg-ui-bg-disabled": disabled
|
|
381
|
+
}
|
|
382
|
+
),
|
|
383
|
+
children: [
|
|
384
|
+
/* @__PURE__ */ jsx(Handle, { ...handleProps, disabled }),
|
|
385
|
+
/* @__PURE__ */ jsx(
|
|
386
|
+
Collapse,
|
|
387
|
+
{
|
|
388
|
+
collapsed,
|
|
389
|
+
onCollapse,
|
|
390
|
+
clone
|
|
391
|
+
}
|
|
392
|
+
),
|
|
393
|
+
/* @__PURE__ */ jsx(
|
|
394
|
+
Icon,
|
|
395
|
+
{
|
|
396
|
+
childrenCount: childCount,
|
|
397
|
+
collapsed,
|
|
398
|
+
clone
|
|
399
|
+
}
|
|
400
|
+
),
|
|
401
|
+
/* @__PURE__ */ jsx(Value, { value }),
|
|
402
|
+
/* @__PURE__ */ jsx(ChildrenCount, { clone, childrenCount: childCount })
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
);
|
|
410
|
+
TreeItem.displayName = "TreeItem";
|
|
411
|
+
var Handle = ({
|
|
412
|
+
listeners,
|
|
413
|
+
attributes,
|
|
414
|
+
disabled
|
|
415
|
+
}) => {
|
|
416
|
+
return /* @__PURE__ */ jsx(
|
|
417
|
+
IconButton,
|
|
418
|
+
{
|
|
419
|
+
size: "small",
|
|
420
|
+
variant: "transparent",
|
|
421
|
+
type: "button",
|
|
422
|
+
className: clx("cursor-grab", { "cursor-not-allowed": disabled }),
|
|
423
|
+
disabled,
|
|
424
|
+
...attributes,
|
|
425
|
+
...listeners,
|
|
426
|
+
children: /* @__PURE__ */ jsx(DotsSix, {})
|
|
427
|
+
}
|
|
428
|
+
);
|
|
429
|
+
};
|
|
430
|
+
var Icon = ({ childrenCount, collapsed, clone }) => {
|
|
431
|
+
const isBranch = clone ? childrenCount && childrenCount > 1 : childrenCount;
|
|
432
|
+
const isOpen = clone ? false : !collapsed;
|
|
433
|
+
return /* @__PURE__ */ jsx("div", { className: "flex size-7 items-center justify-center", children: isBranch ? isOpen ? /* @__PURE__ */ jsx(FolderOpenIllustration, {}) : /* @__PURE__ */ jsx(FolderIllustration, {}) : /* @__PURE__ */ jsx(TagIllustration, {}) });
|
|
434
|
+
};
|
|
435
|
+
var Collapse = ({ collapsed, onCollapse, clone }) => {
|
|
436
|
+
if (clone) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
if (!onCollapse) {
|
|
440
|
+
return /* @__PURE__ */ jsx("div", { className: "size-7", role: "presentation" });
|
|
441
|
+
}
|
|
442
|
+
return /* @__PURE__ */ jsx(
|
|
443
|
+
IconButton,
|
|
444
|
+
{
|
|
445
|
+
size: "small",
|
|
446
|
+
variant: "transparent",
|
|
447
|
+
onClick: onCollapse,
|
|
448
|
+
type: "button",
|
|
449
|
+
children: /* @__PURE__ */ jsx(
|
|
450
|
+
TriangleRightMini,
|
|
451
|
+
{
|
|
452
|
+
className: clx("text-ui-fg-subtle transition-transform", {
|
|
453
|
+
"rotate-90": !collapsed
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
)
|
|
457
|
+
}
|
|
458
|
+
);
|
|
459
|
+
};
|
|
460
|
+
var Value = ({ value }) => {
|
|
461
|
+
return /* @__PURE__ */ jsx("div", { className: "txt-compact-small text-ui-fg-subtle flex-grow truncate", children: value });
|
|
462
|
+
};
|
|
463
|
+
var ChildrenCount = ({ clone, childrenCount }) => {
|
|
464
|
+
if (!clone || !childrenCount) {
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
if (clone && childrenCount <= 1) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
return /* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: "blue", className: "absolute -right-2 -top-2", children: childrenCount });
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// src/components/common/sortable-tree/sortable-tree-item.tsx
|
|
474
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
475
|
+
var animateLayoutChanges = ({
|
|
476
|
+
isSorting,
|
|
477
|
+
wasDragging
|
|
478
|
+
}) => {
|
|
479
|
+
return isSorting || wasDragging ? false : true;
|
|
480
|
+
};
|
|
481
|
+
function SortableTreeItem({
|
|
482
|
+
id,
|
|
483
|
+
depth,
|
|
484
|
+
disabled,
|
|
485
|
+
...props
|
|
486
|
+
}) {
|
|
487
|
+
const {
|
|
488
|
+
attributes,
|
|
489
|
+
isDragging,
|
|
490
|
+
isSorting,
|
|
491
|
+
listeners,
|
|
492
|
+
setDraggableNodeRef,
|
|
493
|
+
setDroppableNodeRef,
|
|
494
|
+
transform,
|
|
495
|
+
transition
|
|
496
|
+
} = useSortable({
|
|
497
|
+
id,
|
|
498
|
+
animateLayoutChanges,
|
|
499
|
+
disabled
|
|
500
|
+
});
|
|
501
|
+
const style = {
|
|
502
|
+
transform: CSS.Translate.toString(transform),
|
|
503
|
+
transition
|
|
504
|
+
};
|
|
505
|
+
return /* @__PURE__ */ jsx2(
|
|
506
|
+
TreeItem,
|
|
507
|
+
{
|
|
508
|
+
ref: setDraggableNodeRef,
|
|
509
|
+
wrapperRef: setDroppableNodeRef,
|
|
510
|
+
style,
|
|
511
|
+
depth,
|
|
512
|
+
ghost: isDragging,
|
|
513
|
+
disableSelection: iOS,
|
|
514
|
+
disableInteraction: isSorting,
|
|
515
|
+
disabled,
|
|
516
|
+
handleProps: {
|
|
517
|
+
listeners,
|
|
518
|
+
attributes
|
|
519
|
+
},
|
|
520
|
+
...props
|
|
521
|
+
}
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// src/components/common/sortable-tree/sortable-tree.tsx
|
|
526
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
527
|
+
var measuring = {
|
|
528
|
+
droppable: {
|
|
529
|
+
strategy: MeasuringStrategy.Always
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
var dropAnimationConfig = {
|
|
533
|
+
keyframes({ transform }) {
|
|
534
|
+
return [
|
|
535
|
+
{ opacity: 1, transform: CSS2.Transform.toString(transform.initial) },
|
|
536
|
+
{
|
|
537
|
+
opacity: 0,
|
|
538
|
+
transform: CSS2.Transform.toString({
|
|
539
|
+
...transform.final,
|
|
540
|
+
x: transform.final.x + 5,
|
|
541
|
+
y: transform.final.y + 5
|
|
542
|
+
})
|
|
543
|
+
}
|
|
544
|
+
];
|
|
545
|
+
},
|
|
546
|
+
easing: "ease-out",
|
|
547
|
+
sideEffects({ active }) {
|
|
548
|
+
active.node.animate([{ opacity: 0 }, { opacity: 1 }], {
|
|
549
|
+
duration: defaultDropAnimation.duration,
|
|
550
|
+
easing: defaultDropAnimation.easing
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
function SortableTree({
|
|
555
|
+
collapsible = true,
|
|
556
|
+
childrenProp = "children",
|
|
557
|
+
// "children" is the default children prop name
|
|
558
|
+
enableDrag = true,
|
|
559
|
+
items = [],
|
|
560
|
+
indentationWidth = 40,
|
|
561
|
+
onChange,
|
|
562
|
+
renderValue
|
|
563
|
+
}) {
|
|
564
|
+
const [collapsedState, setCollapsedState] = useState({});
|
|
565
|
+
const [activeId, setActiveId] = useState(null);
|
|
566
|
+
const [overId, setOverId] = useState(null);
|
|
567
|
+
const [offsetLeft, setOffsetLeft] = useState(0);
|
|
568
|
+
const [currentPosition, setCurrentPosition] = useState(null);
|
|
569
|
+
const flattenedItems = useMemo(() => {
|
|
570
|
+
const flattenedTree = flattenTree(items, childrenProp);
|
|
571
|
+
const collapsedItems = flattenedTree.reduce(
|
|
572
|
+
(acc, item) => {
|
|
573
|
+
const { id } = item;
|
|
574
|
+
const children = item[childrenProp] || [];
|
|
575
|
+
const collapsed = collapsedState[id];
|
|
576
|
+
return collapsed && children.length ? [...acc, id] : acc;
|
|
577
|
+
},
|
|
578
|
+
[]
|
|
579
|
+
);
|
|
580
|
+
return removeChildrenOf(
|
|
581
|
+
flattenedTree,
|
|
582
|
+
activeId ? [activeId, ...collapsedItems] : collapsedItems,
|
|
583
|
+
childrenProp
|
|
584
|
+
);
|
|
585
|
+
}, [activeId, items, childrenProp, collapsedState]);
|
|
586
|
+
const projected = activeId && overId ? getProjection(
|
|
587
|
+
flattenedItems,
|
|
588
|
+
activeId,
|
|
589
|
+
overId,
|
|
590
|
+
offsetLeft,
|
|
591
|
+
indentationWidth
|
|
592
|
+
) : null;
|
|
593
|
+
const sensorContext = useRef({
|
|
594
|
+
items: flattenedItems,
|
|
595
|
+
offset: offsetLeft
|
|
596
|
+
});
|
|
597
|
+
const [coordinateGetter] = useState(
|
|
598
|
+
() => sortableTreeKeyboardCoordinates(sensorContext, indentationWidth)
|
|
599
|
+
);
|
|
600
|
+
const sensors = useSensors(
|
|
601
|
+
useSensor(PointerSensor),
|
|
602
|
+
useSensor(KeyboardSensor, {
|
|
603
|
+
coordinateGetter
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
const sortedIds = useMemo(
|
|
607
|
+
() => flattenedItems.map(({ id }) => id),
|
|
608
|
+
[flattenedItems]
|
|
609
|
+
);
|
|
610
|
+
const activeItem = activeId ? flattenedItems.find(({ id }) => id === activeId) : null;
|
|
611
|
+
useEffect(() => {
|
|
612
|
+
sensorContext.current = {
|
|
613
|
+
items: flattenedItems,
|
|
614
|
+
offset: offsetLeft
|
|
615
|
+
};
|
|
616
|
+
}, [flattenedItems, offsetLeft]);
|
|
617
|
+
function handleDragStart({ active: { id: activeId2 } }) {
|
|
618
|
+
setActiveId(activeId2);
|
|
619
|
+
setOverId(activeId2);
|
|
620
|
+
const activeItem2 = flattenedItems.find(({ id }) => id === activeId2);
|
|
621
|
+
if (activeItem2) {
|
|
622
|
+
setCurrentPosition({
|
|
623
|
+
parentId: activeItem2.parentId,
|
|
624
|
+
overId: activeId2
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
document.body.style.setProperty("cursor", "grabbing");
|
|
628
|
+
}
|
|
629
|
+
function handleDragMove({ delta }) {
|
|
630
|
+
setOffsetLeft(delta.x);
|
|
631
|
+
}
|
|
632
|
+
function handleDragOver({ over }) {
|
|
633
|
+
setOverId(over?.id ?? null);
|
|
634
|
+
}
|
|
635
|
+
function handleDragEnd({ active, over }) {
|
|
636
|
+
resetState();
|
|
637
|
+
if (projected && over) {
|
|
638
|
+
const { depth, parentId } = projected;
|
|
639
|
+
const clonedItems = JSON.parse(
|
|
640
|
+
JSON.stringify(flattenTree(items, childrenProp))
|
|
641
|
+
);
|
|
642
|
+
const overIndex = clonedItems.findIndex(({ id }) => id === over.id);
|
|
643
|
+
const activeIndex = clonedItems.findIndex(({ id }) => id === active.id);
|
|
644
|
+
const activeTreeItem = clonedItems[activeIndex];
|
|
645
|
+
clonedItems[activeIndex] = { ...activeTreeItem, depth, parentId };
|
|
646
|
+
const sortedItems = arrayMove2(clonedItems, activeIndex, overIndex);
|
|
647
|
+
const { items: newItems, update } = buildTree(
|
|
648
|
+
sortedItems,
|
|
649
|
+
overIndex,
|
|
650
|
+
childrenProp
|
|
651
|
+
);
|
|
652
|
+
onChange(update, newItems);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function handleDragCancel() {
|
|
656
|
+
resetState();
|
|
657
|
+
}
|
|
658
|
+
function resetState() {
|
|
659
|
+
setOverId(null);
|
|
660
|
+
setActiveId(null);
|
|
661
|
+
setOffsetLeft(0);
|
|
662
|
+
setCurrentPosition(null);
|
|
663
|
+
document.body.style.setProperty("cursor", "");
|
|
664
|
+
}
|
|
665
|
+
function handleCollapse(id) {
|
|
666
|
+
setCollapsedState((state) => ({
|
|
667
|
+
...state,
|
|
668
|
+
[id]: state[id] ? false : true
|
|
669
|
+
}));
|
|
670
|
+
}
|
|
671
|
+
function getMovementAnnouncement(eventName, activeId2, overId2) {
|
|
672
|
+
if (overId2 && projected) {
|
|
673
|
+
if (eventName !== "onDragEnd") {
|
|
674
|
+
if (currentPosition && projected.parentId === currentPosition.parentId && overId2 === currentPosition.overId) {
|
|
675
|
+
return;
|
|
676
|
+
} else {
|
|
677
|
+
setCurrentPosition({
|
|
678
|
+
parentId: projected.parentId,
|
|
679
|
+
overId: overId2
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
const clonedItems = JSON.parse(
|
|
684
|
+
JSON.stringify(flattenTree(items, childrenProp))
|
|
685
|
+
);
|
|
686
|
+
const overIndex = clonedItems.findIndex(({ id }) => id === overId2);
|
|
687
|
+
const activeIndex = clonedItems.findIndex(({ id }) => id === activeId2);
|
|
688
|
+
const sortedItems = arrayMove2(clonedItems, activeIndex, overIndex);
|
|
689
|
+
const previousItem = sortedItems[overIndex - 1];
|
|
690
|
+
let announcement;
|
|
691
|
+
const movedVerb = eventName === "onDragEnd" ? "dropped" : "moved";
|
|
692
|
+
const nestedVerb = eventName === "onDragEnd" ? "dropped" : "nested";
|
|
693
|
+
if (!previousItem) {
|
|
694
|
+
const nextItem = sortedItems[overIndex + 1];
|
|
695
|
+
announcement = `${activeId2} was ${movedVerb} before ${nextItem.id}.`;
|
|
696
|
+
} else {
|
|
697
|
+
if (projected.depth > previousItem.depth) {
|
|
698
|
+
announcement = `${activeId2} was ${nestedVerb} under ${previousItem.id}.`;
|
|
699
|
+
} else {
|
|
700
|
+
let previousSibling = previousItem;
|
|
701
|
+
while (previousSibling && projected.depth < previousSibling.depth) {
|
|
702
|
+
const parentId = previousSibling.parentId;
|
|
703
|
+
previousSibling = sortedItems.find(({ id }) => id === parentId);
|
|
704
|
+
}
|
|
705
|
+
if (previousSibling) {
|
|
706
|
+
announcement = `${activeId2} was ${movedVerb} after ${previousSibling.id}.`;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return announcement;
|
|
711
|
+
}
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const announcements = {
|
|
715
|
+
onDragStart({ active }) {
|
|
716
|
+
return `Picked up ${active.id}.`;
|
|
717
|
+
},
|
|
718
|
+
onDragMove({ active, over }) {
|
|
719
|
+
return getMovementAnnouncement("onDragMove", active.id, over?.id);
|
|
720
|
+
},
|
|
721
|
+
onDragOver({ active, over }) {
|
|
722
|
+
return getMovementAnnouncement("onDragOver", active.id, over?.id);
|
|
723
|
+
},
|
|
724
|
+
onDragEnd({ active, over }) {
|
|
725
|
+
return getMovementAnnouncement("onDragEnd", active.id, over?.id);
|
|
726
|
+
},
|
|
727
|
+
onDragCancel({ active }) {
|
|
728
|
+
return `Moving was cancelled. ${active.id} was dropped in its original position.`;
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
return /* @__PURE__ */ jsx3(
|
|
732
|
+
DndContext,
|
|
733
|
+
{
|
|
734
|
+
accessibility: { announcements },
|
|
735
|
+
sensors,
|
|
736
|
+
collisionDetection: closestCenter,
|
|
737
|
+
measuring,
|
|
738
|
+
onDragStart: handleDragStart,
|
|
739
|
+
onDragMove: handleDragMove,
|
|
740
|
+
onDragOver: handleDragOver,
|
|
741
|
+
onDragEnd: handleDragEnd,
|
|
742
|
+
onDragCancel: handleDragCancel,
|
|
743
|
+
children: /* @__PURE__ */ jsxs2(SortableContext, { items: sortedIds, strategy: verticalListSortingStrategy, children: [
|
|
744
|
+
flattenedItems.map((item) => {
|
|
745
|
+
const { id, depth } = item;
|
|
746
|
+
const children = item[childrenProp] || [];
|
|
747
|
+
const disabled = typeof enableDrag === "function" ? !enableDrag(item) : !enableDrag;
|
|
748
|
+
return /* @__PURE__ */ jsx3(
|
|
749
|
+
SortableTreeItem,
|
|
750
|
+
{
|
|
751
|
+
id,
|
|
752
|
+
value: renderValue(item),
|
|
753
|
+
disabled,
|
|
754
|
+
depth: id === activeId && projected ? projected.depth : depth,
|
|
755
|
+
indentationWidth,
|
|
756
|
+
collapsed: Boolean(collapsedState[id] && children.length),
|
|
757
|
+
childCount: children.length,
|
|
758
|
+
onCollapse: collapsible && children.length ? () => handleCollapse(id) : void 0
|
|
759
|
+
},
|
|
760
|
+
id
|
|
761
|
+
);
|
|
762
|
+
}),
|
|
763
|
+
createPortal(
|
|
764
|
+
/* @__PURE__ */ jsx3(DragOverlay, { dropAnimation: dropAnimationConfig, children: activeId && activeItem ? /* @__PURE__ */ jsx3(
|
|
765
|
+
SortableTreeItem,
|
|
766
|
+
{
|
|
767
|
+
id: activeId,
|
|
768
|
+
depth: activeItem.depth,
|
|
769
|
+
clone: true,
|
|
770
|
+
childCount: getChildCount(items, activeId, childrenProp) + 1,
|
|
771
|
+
value: renderValue(activeItem),
|
|
772
|
+
indentationWidth: 0
|
|
773
|
+
}
|
|
774
|
+
) : null }),
|
|
775
|
+
document.body
|
|
776
|
+
)
|
|
777
|
+
] })
|
|
778
|
+
}
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/pages/categories/common/components/category-tree/category-tree.tsx
|
|
783
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
784
|
+
var CategoryTree = ({
|
|
785
|
+
value,
|
|
786
|
+
onChange,
|
|
787
|
+
renderValue,
|
|
788
|
+
enableDrag = true,
|
|
789
|
+
isLoading = false
|
|
790
|
+
}) => {
|
|
791
|
+
if (isLoading) {
|
|
792
|
+
return /* @__PURE__ */ jsx4("div", { className: "txt-compact-small relative flex-1 overflow-y-auto", children: Array.from({ length: 10 }).map((_, i) => /* @__PURE__ */ jsx4(CategoryLeafPlaceholder, {}, i)) });
|
|
793
|
+
}
|
|
794
|
+
return /* @__PURE__ */ jsx4(
|
|
795
|
+
SortableTree,
|
|
796
|
+
{
|
|
797
|
+
items: value,
|
|
798
|
+
childrenProp: "category_children",
|
|
799
|
+
collapsible: true,
|
|
800
|
+
enableDrag,
|
|
801
|
+
onChange,
|
|
802
|
+
renderValue
|
|
803
|
+
}
|
|
804
|
+
);
|
|
805
|
+
};
|
|
806
|
+
var CategoryLeafPlaceholder = () => {
|
|
807
|
+
return /* @__PURE__ */ jsx4("div", { className: "bg-ui-bg-base -mb-px flex h-12 animate-pulse items-center border-y px-6 py-2.5" });
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
// src/pages/categories/[id]/organize/organize-category-form/organize-category-form.tsx
|
|
811
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
812
|
+
var QUERY = {
|
|
813
|
+
fields: "id,name,parent_category_id,rank,*category_children",
|
|
814
|
+
parent_category_id: "null",
|
|
815
|
+
include_descendants_tree: true,
|
|
816
|
+
limit: 9999
|
|
817
|
+
};
|
|
818
|
+
var OrganizeCategoryForm = () => {
|
|
819
|
+
const {
|
|
820
|
+
product_categories,
|
|
821
|
+
isPending,
|
|
822
|
+
isError,
|
|
823
|
+
error: fetchError
|
|
824
|
+
} = useProductCategories(QUERY);
|
|
825
|
+
const [snapshot, setSnapshot] = useState2([]);
|
|
826
|
+
const { mutateAsync, isPending: isMutating } = useMutation({
|
|
827
|
+
mutationFn: async ({
|
|
828
|
+
value
|
|
829
|
+
}) => {
|
|
830
|
+
await fetchQuery(`/vendor/product-categories/${value.id}`, {
|
|
831
|
+
method: "POST",
|
|
832
|
+
body: {
|
|
833
|
+
rank: value.rank ?? 0,
|
|
834
|
+
parent_category_id: value.parent_category_id
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
},
|
|
838
|
+
onMutate: async (update) => {
|
|
839
|
+
await queryClient.cancelQueries({
|
|
840
|
+
queryKey: categoriesQueryKeys.list(QUERY)
|
|
841
|
+
});
|
|
842
|
+
const previousValue = queryClient.getQueryData(categoriesQueryKeys.list(QUERY));
|
|
843
|
+
const nextValue = {
|
|
844
|
+
...previousValue,
|
|
845
|
+
product_categories: update.arr
|
|
846
|
+
};
|
|
847
|
+
queryClient.setQueryData(categoriesQueryKeys.list(QUERY), nextValue);
|
|
848
|
+
return {
|
|
849
|
+
previousValue
|
|
850
|
+
};
|
|
851
|
+
},
|
|
852
|
+
onError: (error, _newValue, context) => {
|
|
853
|
+
queryClient.setQueryData(
|
|
854
|
+
categoriesQueryKeys.list(QUERY),
|
|
855
|
+
context?.previousValue
|
|
856
|
+
);
|
|
857
|
+
toast.error(error.message);
|
|
858
|
+
},
|
|
859
|
+
onSettled: async () => {
|
|
860
|
+
await queryClient.invalidateQueries({
|
|
861
|
+
queryKey: categoriesQueryKeys.all
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
const handleRankChange = async (value, arr) => {
|
|
866
|
+
const val = {
|
|
867
|
+
id: value.id,
|
|
868
|
+
parent_category_id: value.parentId,
|
|
869
|
+
rank: value.index
|
|
870
|
+
};
|
|
871
|
+
setSnapshot(arr);
|
|
872
|
+
await mutateAsync({ value: val, arr });
|
|
873
|
+
};
|
|
874
|
+
const loading = isPending || isMutating;
|
|
875
|
+
if (isError) {
|
|
876
|
+
throw fetchError;
|
|
877
|
+
}
|
|
878
|
+
return /* @__PURE__ */ jsxs3("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
879
|
+
/* @__PURE__ */ jsx5(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx5("div", { className: "flex items-center justify-end", children: loading && /* @__PURE__ */ jsx5(Spinner, { className: "animate-spin" }) }) }),
|
|
880
|
+
/* @__PURE__ */ jsx5(RouteFocusModal.Body, { className: "bg-ui-bg-subtle flex flex-1 flex-col overflow-y-auto", children: /* @__PURE__ */ jsx5(
|
|
881
|
+
CategoryTree,
|
|
882
|
+
{
|
|
883
|
+
renderValue: (item) => item.name,
|
|
884
|
+
value: loading ? snapshot : product_categories || [],
|
|
885
|
+
onChange: handleRankChange
|
|
886
|
+
}
|
|
887
|
+
) })
|
|
888
|
+
] });
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
export {
|
|
892
|
+
OrganizeCategoryForm
|
|
893
|
+
};
|