@mercurjs/admin 2.0.0-canary.24
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/add-campaign-promotions-JDC36EOE.js +265 -0
- package/dist/adjust-inventory-2YLC4O4I.js +262 -0
- package/dist/api-key-management-create-KERROZ6Z.js +282 -0
- package/dist/api-key-management-detail-PXY2ZH4V.js +481 -0
- package/dist/api-key-management-edit-7IPPTW37.js +106 -0
- package/dist/api-key-management-list-QQHOCVV4.js +350 -0
- package/dist/api-key-management-sales-channels-AO6SRCAW.js +201 -0
- package/dist/campaign-budget-edit-C5PCVES3.js +147 -0
- package/dist/campaign-configuration-ONC2CL7Q.js +154 -0
- package/dist/campaign-create-J2PN77A6.js +29 -0
- package/dist/campaign-detail-2XJ7PXOQ.js +666 -0
- package/dist/campaign-edit-MU4TVOEC.js +206 -0
- package/dist/campaign-list-BWYHTJL2.js +187 -0
- package/dist/categories-metadata-UC3N6YSC.js +83 -0
- package/dist/category-create-DRJZI3EM.js +427 -0
- package/dist/category-detail-DEGYVUXB.js +544 -0
- package/dist/category-edit-PTYOK7VV.js +220 -0
- package/dist/category-list-T4GPTLOA.js +286 -0
- package/dist/category-organize-MLBY54BT.js +110 -0
- package/dist/category-products-W7U2VZTZ.js +281 -0
- package/dist/chunk-25LYVP3C.js +37 -0
- package/dist/chunk-26OOAKQ6.js +18 -0
- package/dist/chunk-2I3BDP2Z.js +61 -0
- package/dist/chunk-2KCF3ZIB.js +32 -0
- package/dist/chunk-2MKZ4HD4.js +175 -0
- package/dist/chunk-2PZGY332.js +88 -0
- package/dist/chunk-2QKPRGNK.js +107 -0
- package/dist/chunk-2Y3WMGN6.js +39 -0
- package/dist/chunk-2ZFELO2L.js +13 -0
- package/dist/chunk-33XUAKRP.js +6 -0
- package/dist/chunk-362QMJZM.js +77 -0
- package/dist/chunk-3CKTAFTR.js +143 -0
- package/dist/chunk-3EF54XFY.js +64 -0
- package/dist/chunk-3KOTDGC2.js +18 -0
- package/dist/chunk-3LDJURK5.js +296 -0
- package/dist/chunk-3QSRE5LS.js +161 -0
- package/dist/chunk-3XPXUIK3.js +34 -0
- package/dist/chunk-4F5GP7J7.js +45 -0
- package/dist/chunk-4GPAS5GW.js +36 -0
- package/dist/chunk-54EPH67T.js +34 -0
- package/dist/chunk-54RTJBYO.js +153 -0
- package/dist/chunk-54TMLQH3.js +9 -0
- package/dist/chunk-5LZ2G4ZX.js +422 -0
- package/dist/chunk-5S6J5PG5.js +182 -0
- package/dist/chunk-6IJMSVC6.js +16 -0
- package/dist/chunk-6KI3GDYH.js +46 -0
- package/dist/chunk-7AV5EJJ5.js +29 -0
- package/dist/chunk-7RPRNVBS.js +45 -0
- package/dist/chunk-7SVLKK6Q.js +31 -0
- package/dist/chunk-AW77UWCZ.js +363 -0
- package/dist/chunk-AWZFIP25.js +117 -0
- package/dist/chunk-AYVH6Q5O.js +31 -0
- package/dist/chunk-BDGZ4EQO.js +86 -0
- package/dist/chunk-BMNW3AEU.js +373 -0
- package/dist/chunk-BRUOBAPY.js +234 -0
- package/dist/chunk-BYZIWSBB.js +185 -0
- package/dist/chunk-C6SUTRP2.js +13 -0
- package/dist/chunk-CBRSGM3X.js +342 -0
- package/dist/chunk-CI5Z6FGV.js +87 -0
- package/dist/chunk-CMHI2RPL.js +20 -0
- package/dist/chunk-CP5IL4P6.js +98 -0
- package/dist/chunk-D3KDXELJ.js +110 -0
- package/dist/chunk-D6IERBVW.js +43 -0
- package/dist/chunk-DB6ANJBO.js +35 -0
- package/dist/chunk-DLKKSPFE.js +50 -0
- package/dist/chunk-DV73MHTN.js +457 -0
- package/dist/chunk-DXZOR4AG.js +69 -0
- package/dist/chunk-DY3XQPHC.js +31 -0
- package/dist/chunk-EOZUAYQL.js +6 -0
- package/dist/chunk-ERTSYQAI.js +121 -0
- package/dist/chunk-EZIB4NST.js +94 -0
- package/dist/chunk-FGZCSG7T.js +232 -0
- package/dist/chunk-FI474ADU.js +0 -0
- package/dist/chunk-FLCYR7E5.js +467 -0
- package/dist/chunk-FMFVTERD.js +0 -0
- package/dist/chunk-FODCCP6C.js +76 -0
- package/dist/chunk-FQERBIVS.js +0 -0
- package/dist/chunk-FWPGOIFA.js +22 -0
- package/dist/chunk-G5OVX555.js +26 -0
- package/dist/chunk-GUIDZSDY.js +41 -0
- package/dist/chunk-H22XDSXD.js +47 -0
- package/dist/chunk-HC25LNX7.js +45 -0
- package/dist/chunk-HINXQTCW.js +97 -0
- package/dist/chunk-HYUGYB23.js +161 -0
- package/dist/chunk-I43SCBL3.js +106 -0
- package/dist/chunk-IGTRIAUC.js +84 -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-JDGE23BZ.js +332 -0
- package/dist/chunk-JHIMVLB2.js +42 -0
- package/dist/chunk-JISYRXUS.js +389 -0
- package/dist/chunk-JJVGCTKT.js +243 -0
- package/dist/chunk-JQV7CXEC.js +37 -0
- package/dist/chunk-JRTZWK77.js +1764 -0
- package/dist/chunk-KAZ5BYTQ.js +132 -0
- package/dist/chunk-KBYZLKI4.js +1093 -0
- package/dist/chunk-KTKL7M34.js +90 -0
- package/dist/chunk-KUWNYCGL.js +4113 -0
- package/dist/chunk-KW56S7WF.js +67 -0
- package/dist/chunk-LAVHRER2.js +17 -0
- package/dist/chunk-LCZXAT4Q.js +58 -0
- package/dist/chunk-LFKTHNWI.js +83 -0
- package/dist/chunk-LGJWR5LX.js +164 -0
- package/dist/chunk-LLWK3OR6.js +169 -0
- package/dist/chunk-LQSLDDPT.js +67 -0
- package/dist/chunk-LR4ACD6E.js +86676 -0
- package/dist/chunk-LTBX54CI.js +11 -0
- package/dist/chunk-LXP7K6HL.js +817 -0
- package/dist/chunk-LXSBG6LK.js +18 -0
- package/dist/chunk-LZALOVO3.js +372 -0
- package/dist/chunk-M6SOYQJ6.js +39 -0
- package/dist/chunk-MAEP2UCK.js +110 -0
- package/dist/chunk-MG4GKUJW.js +31 -0
- package/dist/chunk-MWOKFNRO.js +446 -0
- package/dist/chunk-N2TQXB44.js +1280 -0
- package/dist/chunk-N5IUYCUZ.js +31 -0
- package/dist/chunk-NBMM2TZK.js +33 -0
- package/dist/chunk-NCMUZ6BQ.js +0 -0
- package/dist/chunk-NCYTM57J.js +160 -0
- package/dist/chunk-NIRWGTM3.js +1104 -0
- package/dist/chunk-NS5CHWOH.js +80 -0
- package/dist/chunk-NWQRHWE5.js +9461 -0
- package/dist/chunk-NXDFDEKP.js +0 -0
- package/dist/chunk-NZJGUN67.js +266 -0
- package/dist/chunk-NZN7PFPB.js +169 -0
- package/dist/chunk-O5HZRJPB.js +55 -0
- package/dist/chunk-O5VKW5FL.js +41 -0
- package/dist/chunk-O67KME6D.js +110 -0
- package/dist/chunk-ODBDAABQ.js +88 -0
- package/dist/chunk-OGYWOPHZ.js +96 -0
- package/dist/chunk-ORW4HNX5.js +357 -0
- package/dist/chunk-P3IZB24Y.js +109 -0
- package/dist/chunk-PHOCVOZ5.js +9 -0
- package/dist/chunk-PVZBDWLK.js +41 -0
- package/dist/chunk-PX675AEP.js +129 -0
- package/dist/chunk-PXYDR7WQ.js +48 -0
- package/dist/chunk-QDPLZDMX.js +17 -0
- package/dist/chunk-QG6PLWNH.js +106 -0
- package/dist/chunk-QSGR43JM.js +30 -0
- package/dist/chunk-RK5N3XIX.js +56 -0
- package/dist/chunk-RLMLYJDI.js +38 -0
- package/dist/chunk-RMXYSYK4.js +50 -0
- package/dist/chunk-RPIJY6TT.js +637 -0
- package/dist/chunk-RSBZREKG.js +144 -0
- package/dist/chunk-RXM4B6HR.js +8 -0
- package/dist/chunk-S2WEYEQR.js +14 -0
- package/dist/chunk-S4SVK5DE.js +39 -0
- package/dist/chunk-S6LPCNXQ.js +29 -0
- package/dist/chunk-SMQT3ZNO.js +8 -0
- package/dist/chunk-T435NFHC.js +490 -0
- package/dist/chunk-THHRRYRS.js +16 -0
- package/dist/chunk-TKGWSUEI.js +0 -0
- package/dist/chunk-TLE6YHGH.js +26 -0
- package/dist/chunk-TN4TIT7O.js +116 -0
- package/dist/chunk-TUJIAA5O.js +101 -0
- package/dist/chunk-U2EI2ZLM.js +32 -0
- package/dist/chunk-U2L77ZDR.js +17 -0
- package/dist/chunk-U2UCL2VG.js +369 -0
- package/dist/chunk-U2ZFCAPX.js +34 -0
- package/dist/chunk-U5MJIHLY.js +87 -0
- package/dist/chunk-U62GYN4A.js +227 -0
- package/dist/chunk-UM7ZR3VU.js +14 -0
- package/dist/chunk-UQITHKTH.js +342 -0
- package/dist/chunk-UZJ2NQSN.js +257 -0
- package/dist/chunk-UZWFZMOX.js +40 -0
- package/dist/chunk-V74Y5NIV.js +49 -0
- package/dist/chunk-VBMMWVB5.js +49 -0
- package/dist/chunk-VKOE5J66.js +31 -0
- package/dist/chunk-VOHEQ7B5.js +31 -0
- package/dist/chunk-VVTSF42Z.js +52 -0
- package/dist/chunk-VW56KWO2.js +9 -0
- package/dist/chunk-VWGKHDZ6.js +528 -0
- package/dist/chunk-W6Y3PPU5.js +73 -0
- package/dist/chunk-WCEMRNW4.js +6 -0
- package/dist/chunk-WDZFLCSQ.js +77 -0
- package/dist/chunk-WIYFXWRI.js +30 -0
- package/dist/chunk-WMA3WTCM.js +117 -0
- package/dist/chunk-WWANSDFM.js +175 -0
- package/dist/chunk-XBMLI2YI.js +85 -0
- package/dist/chunk-XBVIP2BA.js +609 -0
- package/dist/chunk-XCMR2HTV.js +102 -0
- package/dist/chunk-XFR5JLNF.js +44 -0
- package/dist/chunk-XL52SYWY.js +23 -0
- package/dist/chunk-XQNVC4Q7.js +212 -0
- package/dist/chunk-XSX255FK.js +12 -0
- package/dist/chunk-Y2M536WR.js +67 -0
- package/dist/chunk-Y456KVIN.js +116 -0
- package/dist/chunk-Y7QKP6QU.js +35 -0
- package/dist/chunk-YBZWO4ZV.js +57 -0
- package/dist/chunk-YGQUBTKR.js +81 -0
- package/dist/chunk-YGSM5PVN.js +170 -0
- package/dist/chunk-YVCBMOJG.js +50 -0
- package/dist/chunk-YWWUOGJA.js +62 -0
- package/dist/chunk-YXFG3M2D.js +792 -0
- package/dist/chunk-ZAUMHCIL.js +42 -0
- package/dist/chunk-ZDJWCSZ4.js +85 -0
- package/dist/chunk-ZQZHFMD7.js +19 -0
- package/dist/chunk-ZYNBKBY3.js +14 -0
- package/dist/collection-add-products-IUDEIUM5.js +284 -0
- package/dist/collection-create-AQ3GUG3G.js +133 -0
- package/dist/collection-detail-SDFALX6M.js +444 -0
- package/dist/collection-edit-AAHL2WFH.js +121 -0
- package/dist/collection-list-JGKC5EVM.js +228 -0
- package/dist/collection-metadata-YQWA2JTU.js +80 -0
- package/dist/customer-create-5VT2TB6S.js +183 -0
- package/dist/customer-create-address-ICEFEFD2.js +299 -0
- package/dist/customer-detail-CDELSJ77.js +695 -0
- package/dist/customer-edit-DZAD53JC.js +192 -0
- package/dist/customer-list-EIQP23FQ.js +152 -0
- package/dist/customer-metadata-ATAORBRN.js +81 -0
- package/dist/customers-add-customer-group-542PUCCT.js +308 -0
- package/dist/edit-inventory-item-P2HVULPA.js +152 -0
- package/dist/edit-inventory-item-attributes-V2HK3WTQ.js +323 -0
- package/dist/edit-reservation-LX2Z6KVD.js +246 -0
- package/dist/edit-rules-Q5UNWAUD.js +316 -0
- package/dist/home-I3OILW5Z.js +16 -0
- package/dist/index.css +6 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +4824 -0
- package/dist/inventory-create-FT7GL4RK.js +616 -0
- package/dist/inventory-detail-LNZ5QC67.js +771 -0
- package/dist/inventory-list-UXY7PU3N.js +432 -0
- package/dist/inventory-metadata-OYETRH5X.js +83 -0
- package/dist/inventory-stock-3MBERL3K.js +288 -0
- package/dist/invite-HJ7BRO6H.js +372 -0
- package/dist/location-create-ZVVQT2KP.js +238 -0
- package/dist/location-detail-A5SHPUQN.js +823 -0
- package/dist/location-edit-QSRHHDQ2.js +253 -0
- package/dist/location-fulfillment-providers-4HMT5L7L.js +289 -0
- package/dist/location-list-TC5FEN5R.js +346 -0
- package/dist/location-sales-channels-STDHWQSC.js +215 -0
- package/dist/location-service-zone-create-63LUYCJI.js +173 -0
- package/dist/location-service-zone-edit-UNXI5BQV.js +134 -0
- package/dist/location-service-zone-manage-areas-UMD6CZDZ.js +154 -0
- package/dist/location-service-zone-shipping-option-create-5L73SAGE.js +807 -0
- package/dist/location-service-zone-shipping-option-edit-2FEWQD6Y.js +362 -0
- package/dist/location-service-zone-shipping-option-pricing-QSB56QZD.js +362 -0
- package/dist/login-V4HZQTCQ.js +254 -0
- package/dist/manage-locations-NVHONEZE.js +249 -0
- package/dist/no-match-JLVLPCRH.js +33 -0
- package/dist/order-allocate-items-F7CXZQGX.js +558 -0
- package/dist/order-create-claim-GDVWGZJA.js +2203 -0
- package/dist/order-create-edit-6YYKYT66.js +936 -0
- package/dist/order-create-exchange-NLDIMGBG.js +2190 -0
- package/dist/order-create-fulfillment-EIYGSKXP.js +621 -0
- package/dist/order-create-refund-BBXEZNWA.js +403 -0
- package/dist/order-create-return-6TA5J3AW.js +1292 -0
- package/dist/order-create-shipment-T4C6UE2K.js +208 -0
- package/dist/order-detail-Y4EG3P5F.js +3846 -0
- package/dist/order-edit-billing-address-NNIFUC5C.js +400 -0
- package/dist/order-edit-email-VXOX62P6.js +171 -0
- package/dist/order-edit-shipping-address-WDKCQRRG.js +397 -0
- package/dist/order-list-XDOAXZXN.js +231 -0
- package/dist/order-metadata-S6N3GDOA.js +82 -0
- package/dist/order-receive-return-5VWUPWZJ.js +549 -0
- package/dist/order-request-transfer-VFSY5IFF.js +571 -0
- package/dist/price-list-configuration-GH67LL2N.js +356 -0
- package/dist/price-list-create-INX5HG7G.js +973 -0
- package/dist/price-list-detail-5LGPE67O.js +540 -0
- package/dist/price-list-edit-HRWPEIZI.js +227 -0
- package/dist/price-list-list-IXZVTXU5.js +228 -0
- package/dist/price-list-prices-add-QHE3TUTV.js +614 -0
- package/dist/price-list-prices-edit-TMVJ7S7J.js +326 -0
- package/dist/product-attributes-P7WFH4I2.js +358 -0
- package/dist/product-create-YC6MCJ2M.js +2305 -0
- package/dist/product-create-option-BNF2KKJM.js +144 -0
- package/dist/product-create-variant-SIJX7AE3.js +837 -0
- package/dist/product-detail-2GJ3PGHW.js +1638 -0
- package/dist/product-edit-YOGTWZ4I.js +397 -0
- package/dist/product-edit-option-4MUSMFS7.js +152 -0
- package/dist/product-export-5L4HNM3W.js +127 -0
- package/dist/product-import-Y54VG4AC.js +261 -0
- package/dist/product-list-EV2TS3Y4.js +313 -0
- package/dist/product-media-ZSMGHCNP.js +879 -0
- package/dist/product-metadata-572YVJH3.js +80 -0
- package/dist/product-organization-LVKRBJOQ.js +312 -0
- package/dist/product-prices-K5YM2TL6.js +266 -0
- package/dist/product-sales-channels-J3OH4NWX.js +157 -0
- package/dist/product-shipping-profile-NOOFEUBZ.js +146 -0
- package/dist/product-stock-J4LTIX64.js +540 -0
- package/dist/product-tag-create-5JJPPELP.js +122 -0
- package/dist/product-tag-detail-CGLCH3BJ.js +281 -0
- package/dist/product-tag-edit-OR7KSC7I.js +134 -0
- package/dist/product-tag-list-DY7GJUJQ.js +259 -0
- package/dist/product-tag-metadata-BFGPRMME.js +80 -0
- package/dist/product-type-create-FPVSGIKL.js +101 -0
- package/dist/product-type-detail-JYW2DAM4.js +242 -0
- package/dist/product-type-edit-FBT4Z4ZJ.js +113 -0
- package/dist/product-type-list-FK237DSQ.js +175 -0
- package/dist/product-type-metadata-SFJR5OQN.js +80 -0
- package/dist/product-variant-detail-6KPB3HL7.js +485 -0
- package/dist/product-variant-edit-QFHGNDW7.js +538 -0
- package/dist/product-variant-manage-inventory-items-ZEX2IW53.js +340 -0
- package/dist/product-variant-metadata-F45CSWU6.js +86 -0
- package/dist/profile-detail-LLXUNQOT.js +89 -0
- package/dist/profile-edit-UDYMDQLT.js +176 -0
- package/dist/promotion-add-campaign-U6X2FNWZ.js +43 -0
- package/dist/promotion-create-QB7E277L.js +1258 -0
- package/dist/promotion-detail-7D6D6PQ7.js +486 -0
- package/dist/promotion-edit-details-HYQJAZDF.js +512 -0
- package/dist/promotion-list-HTJ5GIWG.js +206 -0
- package/dist/refund-reason-create-LZCL6QJI.js +192 -0
- package/dist/refund-reason-edit-QNGFKZMN.js +192 -0
- package/dist/refund-reason-list-ZEKWYQ45.js +233 -0
- package/dist/region-add-countries-CWJ62VPK.js +226 -0
- package/dist/region-create-Z3JQFIKN.js +507 -0
- package/dist/region-detail-46R3HACJ.js +508 -0
- package/dist/region-edit-W5IVVP7Z.js +380 -0
- package/dist/region-list-DCU6NQFA.js +205 -0
- package/dist/region-metadata-VG5DLCOK.js +83 -0
- package/dist/reservation-create-VG5FSV3F.js +309 -0
- package/dist/reservation-detail-36BA3V2F.js +221 -0
- package/dist/reservation-list-R5UBPNI4.js +298 -0
- package/dist/reservation-metadata-KR4HOHTH.js +83 -0
- package/dist/reset-password-VZPICVMM.js +458 -0
- package/dist/return-reason-create-KTKI6NJE.js +165 -0
- package/dist/return-reason-edit-5KU7WKJF.js +168 -0
- package/dist/return-reason-list-HBSKNIMW.js +240 -0
- package/dist/sales-channel-add-products-6TUDLE4D.js +274 -0
- package/dist/sales-channel-create-2BTWSYIK.js +154 -0
- package/dist/sales-channel-detail-IQIQDN3L.js +437 -0
- package/dist/sales-channel-edit-YBNPALFT.js +163 -0
- package/dist/sales-channel-list-5KNN734B.js +193 -0
- package/dist/sales-channel-metadata-SVW6FYSV.js +88 -0
- package/dist/seller-details-HBVN4GGD.js +77 -0
- package/dist/seller-edit-OXDARXYJ.js +387 -0
- package/dist/seller-list-HG2VXA6V.js +192 -0
- package/dist/settings-D43GVDOO.js +19 -0
- package/dist/shipping-option-type-create-7KYU5NNF.js +195 -0
- package/dist/shipping-option-type-detail-4CNTT3MO.js +169 -0
- package/dist/shipping-option-type-edit-AN6IPVI6.js +191 -0
- package/dist/shipping-option-type-list-36ZS2QZO.js +266 -0
- package/dist/shipping-profile-create-3OWHNAOB.js +123 -0
- package/dist/shipping-profile-detail-WW7IVUVV.js +157 -0
- package/dist/shipping-profile-metadata-AD3DSZLR.js +84 -0
- package/dist/shipping-profiles-list-WOGGP7IT.js +241 -0
- package/dist/store-add-currencies-PIGEOZ4G.js +304 -0
- package/dist/store-detail-MFHPXBIN.js +525 -0
- package/dist/store-edit-WBF6EL5N.js +246 -0
- package/dist/store-metadata-LSK7UVSC.js +85 -0
- package/dist/tax-region-create-XTX4YWRA.js +300 -0
- package/dist/tax-region-detail-XUYJHBHI.js +320 -0
- package/dist/tax-region-edit-AC64YA64.js +162 -0
- package/dist/tax-region-list-XRAYDYK3.js +91 -0
- package/dist/tax-region-metadata-YDQX3Y4X.js +83 -0
- package/dist/tax-region-province-create-GDL65SQF.js +315 -0
- package/dist/tax-region-province-detail-QMPIKT7K.js +215 -0
- package/dist/tax-region-tax-override-create-X2QWOHSU.js +679 -0
- package/dist/tax-region-tax-override-edit-VZJ6EPSU.js +788 -0
- package/dist/tax-region-tax-rate-create-VC2WDVJJ.js +193 -0
- package/dist/tax-region-tax-rate-edit-SDW36H6I.js +192 -0
- package/dist/user-detail-IEIX24PZ.js +163 -0
- package/dist/user-edit-CJ7TNY3H.js +115 -0
- package/dist/user-invite-OTBYWV4L.js +389 -0
- package/dist/user-list-BJXFPTJ7.js +341 -0
- package/dist/user-metadata-ZLC6T6XH.js +83 -0
- package/package.json +87 -0
|
@@ -0,0 +1,4113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
currencies
|
|
3
|
+
} from "./chunk-IQPN4PZJ.js";
|
|
4
|
+
import {
|
|
5
|
+
Skeleton
|
|
6
|
+
} from "./chunk-INNFZYX2.js";
|
|
7
|
+
import {
|
|
8
|
+
ConditionalTooltip
|
|
9
|
+
} from "./chunk-LAVHRER2.js";
|
|
10
|
+
import {
|
|
11
|
+
useDocumentDirection
|
|
12
|
+
} from "./chunk-Y7QKP6QU.js";
|
|
13
|
+
import {
|
|
14
|
+
__publicField
|
|
15
|
+
} from "./chunk-NBMM2TZK.js";
|
|
16
|
+
|
|
17
|
+
// src/components/data-grid/components/data-grid-skeleton.tsx
|
|
18
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
var DataGridSkeleton = ({
|
|
20
|
+
columns,
|
|
21
|
+
rows: rowCount = 10
|
|
22
|
+
}) => {
|
|
23
|
+
const rows = Array.from({ length: rowCount }, (_, i) => i);
|
|
24
|
+
const colCount = columns.length;
|
|
25
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle size-full", children: [
|
|
26
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-bg-base border-b p-4", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-button-neutral h-7 w-[116px] animate-pulse rounded-md" }) }),
|
|
27
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle size-full overflow-auto", children: [
|
|
28
|
+
/* @__PURE__ */ jsx(
|
|
29
|
+
"div",
|
|
30
|
+
{
|
|
31
|
+
className: "grid",
|
|
32
|
+
style: {
|
|
33
|
+
gridTemplateColumns: `repeat(${colCount}, 1fr)`
|
|
34
|
+
},
|
|
35
|
+
children: columns.map((_col, i) => {
|
|
36
|
+
return /* @__PURE__ */ jsx(
|
|
37
|
+
"div",
|
|
38
|
+
{
|
|
39
|
+
className: "bg-ui-bg-base flex h-10 w-[200px] items-center border-b border-r px-4 py-2.5 last:border-r-0",
|
|
40
|
+
children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[14px] w-[164px]" })
|
|
41
|
+
},
|
|
42
|
+
i
|
|
43
|
+
);
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
/* @__PURE__ */ jsx("div", { children: rows.map((_, j) => /* @__PURE__ */ jsx(
|
|
48
|
+
"div",
|
|
49
|
+
{
|
|
50
|
+
className: "grid",
|
|
51
|
+
style: { gridTemplateColumns: `repeat(${colCount}, 1fr)` },
|
|
52
|
+
children: columns.map((_col, k) => {
|
|
53
|
+
return /* @__PURE__ */ jsx(
|
|
54
|
+
"div",
|
|
55
|
+
{
|
|
56
|
+
className: "bg-ui-bg-base flex h-10 w-[200px] items-center border-b border-r px-4 py-2.5 last:border-r-0",
|
|
57
|
+
children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[14px] w-[164px]" })
|
|
58
|
+
},
|
|
59
|
+
k
|
|
60
|
+
);
|
|
61
|
+
})
|
|
62
|
+
},
|
|
63
|
+
j
|
|
64
|
+
)) })
|
|
65
|
+
] })
|
|
66
|
+
] });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/components/data-grid/components/data-grid-boolean-cell.tsx
|
|
70
|
+
import { Checkbox } from "@medusajs/ui";
|
|
71
|
+
import { Controller } from "react-hook-form";
|
|
72
|
+
|
|
73
|
+
// src/hooks/use-combined-refs.tsx
|
|
74
|
+
function setRef(ref, value) {
|
|
75
|
+
if (typeof ref === "function") {
|
|
76
|
+
ref(value);
|
|
77
|
+
} else if (ref && "current" in ref) {
|
|
78
|
+
;
|
|
79
|
+
ref.current = value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
var useCombinedRefs = (...refs) => {
|
|
83
|
+
return (value) => {
|
|
84
|
+
refs.forEach((ref) => setRef(ref, value));
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/components/data-grid/hooks/use-data-grid-cell.tsx
|
|
89
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
90
|
+
|
|
91
|
+
// src/components/data-grid/context/data-grid-context.tsx
|
|
92
|
+
import { createContext } from "react";
|
|
93
|
+
var DataGridContext = createContext(
|
|
94
|
+
null
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// src/components/data-grid/context/use-data-grid-context.tsx
|
|
98
|
+
import { useContext } from "react";
|
|
99
|
+
var useDataGridContext = () => {
|
|
100
|
+
const context = useContext(DataGridContext);
|
|
101
|
+
if (!context) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
"useDataGridContext must be used within a DataGridContextProvider"
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return context;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/components/data-grid/utils.ts
|
|
110
|
+
function generateCellId(coords) {
|
|
111
|
+
return `${coords.row}:${coords.col}`;
|
|
112
|
+
}
|
|
113
|
+
function isCellMatch(cell, coords) {
|
|
114
|
+
if (!coords) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return cell.row === coords.row && cell.col === coords.col;
|
|
118
|
+
}
|
|
119
|
+
var SPECIAL_FOCUS_KEYS = [".", ","];
|
|
120
|
+
function isSpecialFocusKey(event) {
|
|
121
|
+
return SPECIAL_FOCUS_KEYS.includes(event.key) && event.ctrlKey && event.altKey;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/components/data-grid/hooks/use-data-grid-cell.tsx
|
|
125
|
+
var textCharacterRegex = /^.$/u;
|
|
126
|
+
var numberCharacterRegex = /^[0-9]$/u;
|
|
127
|
+
var useDataGridCell = ({
|
|
128
|
+
context
|
|
129
|
+
}) => {
|
|
130
|
+
const {
|
|
131
|
+
register,
|
|
132
|
+
control,
|
|
133
|
+
anchor,
|
|
134
|
+
setIsEditing,
|
|
135
|
+
setSingleRange,
|
|
136
|
+
setIsSelecting,
|
|
137
|
+
setRangeEnd,
|
|
138
|
+
getWrapperFocusHandler,
|
|
139
|
+
getWrapperMouseOverHandler,
|
|
140
|
+
getInputChangeHandler,
|
|
141
|
+
getIsCellSelected,
|
|
142
|
+
getIsCellDragSelected,
|
|
143
|
+
getCellMetadata
|
|
144
|
+
} = useDataGridContext();
|
|
145
|
+
const { rowIndex, columnIndex } = context;
|
|
146
|
+
const coords = useMemo(
|
|
147
|
+
() => ({ row: rowIndex, col: columnIndex }),
|
|
148
|
+
[rowIndex, columnIndex]
|
|
149
|
+
);
|
|
150
|
+
const { id, field, type, innerAttributes, inputAttributes } = useMemo(() => {
|
|
151
|
+
return getCellMetadata(coords);
|
|
152
|
+
}, [coords, getCellMetadata]);
|
|
153
|
+
const [showOverlay, setShowOverlay] = useState(true);
|
|
154
|
+
const containerRef = useRef(null);
|
|
155
|
+
const inputRef = useRef(null);
|
|
156
|
+
const handleOverlayMouseDown = useCallback(
|
|
157
|
+
(e) => {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
e.stopPropagation();
|
|
160
|
+
if (e.detail === 2) {
|
|
161
|
+
if (inputRef.current) {
|
|
162
|
+
setShowOverlay(false);
|
|
163
|
+
inputRef.current.focus();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (e.shiftKey) {
|
|
168
|
+
if (coords.col === anchor?.col) {
|
|
169
|
+
setRangeEnd(coords);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (containerRef.current) {
|
|
174
|
+
setSingleRange(coords);
|
|
175
|
+
setIsSelecting(true);
|
|
176
|
+
containerRef.current.focus();
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
[coords, anchor, setRangeEnd, setSingleRange, setIsSelecting]
|
|
180
|
+
);
|
|
181
|
+
const handleBooleanInnerMouseDown = useCallback(
|
|
182
|
+
(e) => {
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
e.stopPropagation();
|
|
185
|
+
if (e.detail === 2) {
|
|
186
|
+
inputRef.current?.focus();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (e.shiftKey) {
|
|
190
|
+
setRangeEnd(coords);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (containerRef.current) {
|
|
194
|
+
setSingleRange(coords);
|
|
195
|
+
setIsSelecting(true);
|
|
196
|
+
containerRef.current.focus();
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
[setIsSelecting, setSingleRange, setRangeEnd, coords]
|
|
200
|
+
);
|
|
201
|
+
const handleInputBlur = useCallback(() => {
|
|
202
|
+
setShowOverlay(true);
|
|
203
|
+
setIsEditing(false);
|
|
204
|
+
}, [setIsEditing]);
|
|
205
|
+
const handleInputFocus = useCallback(() => {
|
|
206
|
+
setShowOverlay(false);
|
|
207
|
+
setIsEditing(true);
|
|
208
|
+
}, [setIsEditing]);
|
|
209
|
+
const validateKeyStroke = useCallback(
|
|
210
|
+
(key) => {
|
|
211
|
+
switch (type) {
|
|
212
|
+
case "togglable-number":
|
|
213
|
+
case "number":
|
|
214
|
+
return numberCharacterRegex.test(key);
|
|
215
|
+
case "text":
|
|
216
|
+
case "multiline-text":
|
|
217
|
+
return textCharacterRegex.test(key);
|
|
218
|
+
default:
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[type]
|
|
223
|
+
);
|
|
224
|
+
const handleContainerKeyDown = useCallback(
|
|
225
|
+
(e) => {
|
|
226
|
+
if (!inputRef.current || !validateKeyStroke(e.key) || !showOverlay) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (e.key.toLowerCase() === "z" && (e.ctrlKey || e.metaKey)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (e.key.toLowerCase() === "c" && (e.ctrlKey || e.metaKey)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (e.key.toLowerCase() === "v" && (e.ctrlKey || e.metaKey)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (e.key === "Enter") {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (isSpecialFocusKey(e.nativeEvent)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
inputRef.current.focus();
|
|
245
|
+
setShowOverlay(false);
|
|
246
|
+
if (inputRef.current instanceof HTMLInputElement) {
|
|
247
|
+
inputRef.current.value = "";
|
|
248
|
+
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
|
249
|
+
window.HTMLInputElement.prototype,
|
|
250
|
+
"value"
|
|
251
|
+
)?.set;
|
|
252
|
+
nativeInputValueSetter?.call(inputRef.current, e.key);
|
|
253
|
+
const event = new Event("input", { bubbles: true });
|
|
254
|
+
inputRef.current.dispatchEvent(event);
|
|
255
|
+
} else if (inputRef.current instanceof HTMLTextAreaElement) {
|
|
256
|
+
inputRef.current.value = "";
|
|
257
|
+
const nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(
|
|
258
|
+
window.HTMLTextAreaElement.prototype,
|
|
259
|
+
"value"
|
|
260
|
+
)?.set;
|
|
261
|
+
nativeTextAreaValueSetter?.call(inputRef.current, e.key);
|
|
262
|
+
const event = new Event("input", { bubbles: true });
|
|
263
|
+
inputRef.current.dispatchEvent(event);
|
|
264
|
+
}
|
|
265
|
+
e.stopPropagation();
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
},
|
|
268
|
+
[showOverlay, validateKeyStroke]
|
|
269
|
+
);
|
|
270
|
+
const isAnchor = useMemo(() => {
|
|
271
|
+
return anchor ? isCellMatch(coords, anchor) : false;
|
|
272
|
+
}, [anchor, coords]);
|
|
273
|
+
const fieldWithoutOverlay = useMemo(() => {
|
|
274
|
+
return type === "boolean";
|
|
275
|
+
}, [type]);
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
if (isAnchor && !containerRef.current?.contains(document.activeElement)) {
|
|
278
|
+
containerRef.current?.focus({ preventScroll: true });
|
|
279
|
+
}
|
|
280
|
+
}, [isAnchor]);
|
|
281
|
+
const renderProps = {
|
|
282
|
+
container: {
|
|
283
|
+
field,
|
|
284
|
+
isAnchor,
|
|
285
|
+
isSelected: getIsCellSelected(coords),
|
|
286
|
+
isDragSelected: getIsCellDragSelected(coords),
|
|
287
|
+
showOverlay: fieldWithoutOverlay ? false : showOverlay,
|
|
288
|
+
innerProps: {
|
|
289
|
+
ref: containerRef,
|
|
290
|
+
onMouseOver: getWrapperMouseOverHandler(coords),
|
|
291
|
+
onMouseDown: type === "boolean" ? handleBooleanInnerMouseDown : void 0,
|
|
292
|
+
onKeyDown: handleContainerKeyDown,
|
|
293
|
+
onFocus: getWrapperFocusHandler(coords),
|
|
294
|
+
...innerAttributes
|
|
295
|
+
},
|
|
296
|
+
overlayProps: {
|
|
297
|
+
onMouseDown: handleOverlayMouseDown
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
input: {
|
|
301
|
+
ref: inputRef,
|
|
302
|
+
onBlur: handleInputBlur,
|
|
303
|
+
onFocus: handleInputFocus,
|
|
304
|
+
onChange: getInputChangeHandler(field),
|
|
305
|
+
...inputAttributes
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
return {
|
|
309
|
+
id,
|
|
310
|
+
field,
|
|
311
|
+
register,
|
|
312
|
+
control,
|
|
313
|
+
renderProps
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/components/data-grid/hooks/use-data-grid-cell-error.tsx
|
|
318
|
+
import { useMemo as useMemo2 } from "react";
|
|
319
|
+
import { get } from "react-hook-form";
|
|
320
|
+
var useDataGridCellError = ({
|
|
321
|
+
context
|
|
322
|
+
}) => {
|
|
323
|
+
const { errors, getCellErrorMetadata, navigateToField } = useDataGridContext();
|
|
324
|
+
const { rowIndex, columnIndex } = context;
|
|
325
|
+
const { accessor, field } = useMemo2(() => {
|
|
326
|
+
return getCellErrorMetadata({ row: rowIndex, col: columnIndex });
|
|
327
|
+
}, [rowIndex, columnIndex, getCellErrorMetadata]);
|
|
328
|
+
const rowErrorsObject = accessor && columnIndex === 0 ? get(errors, accessor) : void 0;
|
|
329
|
+
const rowErrors = [];
|
|
330
|
+
function collectErrors(errorObject, baseAccessor) {
|
|
331
|
+
if (!errorObject) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (isFieldError(errorObject)) {
|
|
335
|
+
const message = errorObject.message;
|
|
336
|
+
const to = () => navigateToField(baseAccessor);
|
|
337
|
+
if (message) {
|
|
338
|
+
rowErrors.push({ message, to });
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
Object.keys(errorObject).forEach((key) => {
|
|
342
|
+
const nestedError = errorObject[key];
|
|
343
|
+
const fieldAccessor = `${baseAccessor}.${key}`;
|
|
344
|
+
if (nestedError && typeof nestedError === "object") {
|
|
345
|
+
collectErrors(nestedError, fieldAccessor);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (rowErrorsObject && accessor) {
|
|
351
|
+
collectErrors(rowErrorsObject, accessor);
|
|
352
|
+
}
|
|
353
|
+
const cellError = field ? get(errors, field) : void 0;
|
|
354
|
+
return {
|
|
355
|
+
errors,
|
|
356
|
+
rowErrors,
|
|
357
|
+
cellError
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
function isFieldError(errors) {
|
|
361
|
+
return typeof errors === "object" && "message" in errors && "type" in errors;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// src/components/data-grid/hooks/use-data-grid-cell-handlers.tsx
|
|
365
|
+
import { useCallback as useCallback2 } from "react";
|
|
366
|
+
|
|
367
|
+
// src/components/data-grid/models/data-grid-bulk-update-command.ts
|
|
368
|
+
var DataGridBulkUpdateCommand = class {
|
|
369
|
+
constructor({ fields, prev, next, setter }) {
|
|
370
|
+
__publicField(this, "_fields");
|
|
371
|
+
__publicField(this, "_prev");
|
|
372
|
+
__publicField(this, "_next");
|
|
373
|
+
__publicField(this, "_setter");
|
|
374
|
+
this._fields = fields;
|
|
375
|
+
this._prev = prev;
|
|
376
|
+
this._next = next;
|
|
377
|
+
this._setter = setter;
|
|
378
|
+
}
|
|
379
|
+
execute(redo = false) {
|
|
380
|
+
this._setter(this._fields, this._next, redo);
|
|
381
|
+
}
|
|
382
|
+
undo() {
|
|
383
|
+
this._setter(this._fields, this._prev, true);
|
|
384
|
+
}
|
|
385
|
+
redo() {
|
|
386
|
+
this.execute(true);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// src/components/data-grid/models/data-grid-matrix.ts
|
|
391
|
+
var DataGridMatrix = class {
|
|
392
|
+
constructor(data, columns, multiColumnSelection = false) {
|
|
393
|
+
__publicField(this, "multiColumnSelection");
|
|
394
|
+
__publicField(this, "cells");
|
|
395
|
+
__publicField(this, "rowAccessors", []);
|
|
396
|
+
__publicField(this, "columnAccessors", []);
|
|
397
|
+
this.multiColumnSelection = multiColumnSelection;
|
|
398
|
+
this.cells = this._populateCells(data, columns);
|
|
399
|
+
this.rowAccessors = this._computeRowAccessors();
|
|
400
|
+
this.columnAccessors = this._computeColumnAccessors();
|
|
401
|
+
}
|
|
402
|
+
_computeRowAccessors() {
|
|
403
|
+
return this.cells.map((_, rowIndex) => this.getRowAccessor(rowIndex));
|
|
404
|
+
}
|
|
405
|
+
_computeColumnAccessors() {
|
|
406
|
+
if (this.cells.length === 0) {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
return this.cells[0].map((_, colIndex) => this.getColumnAccessor(colIndex));
|
|
410
|
+
}
|
|
411
|
+
getFirstNavigableCell() {
|
|
412
|
+
for (let row = 0; row < this.cells.length; row++) {
|
|
413
|
+
for (let col = 0; col < this.cells[0].length; col++) {
|
|
414
|
+
if (this.cells[row][col] !== null) {
|
|
415
|
+
return { row, col };
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
getFieldsInRow(row) {
|
|
422
|
+
const keys = [];
|
|
423
|
+
if (row < 0 || row >= this.cells.length) {
|
|
424
|
+
return keys;
|
|
425
|
+
}
|
|
426
|
+
this.cells[row].forEach((cell) => {
|
|
427
|
+
if (cell !== null) {
|
|
428
|
+
keys.push(cell.field);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
return keys;
|
|
432
|
+
}
|
|
433
|
+
getFieldsInSelection(start, end) {
|
|
434
|
+
const keys = [];
|
|
435
|
+
if (!start || !end) {
|
|
436
|
+
return keys;
|
|
437
|
+
}
|
|
438
|
+
if (!this.multiColumnSelection && start.col !== end.col) {
|
|
439
|
+
throw new Error(
|
|
440
|
+
"Selection must be in the same column when multiColumnSelection is disabled"
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
const startRow = Math.min(start.row, end.row);
|
|
444
|
+
const endRow = Math.max(start.row, end.row);
|
|
445
|
+
const startCol = this.multiColumnSelection ? Math.min(start.col, end.col) : start.col;
|
|
446
|
+
const endCol = this.multiColumnSelection ? Math.max(start.col, end.col) : start.col;
|
|
447
|
+
for (let row = startRow; row <= endRow; row++) {
|
|
448
|
+
for (let col = startCol; col <= endCol; col++) {
|
|
449
|
+
if (this._isValidPosition(row, col) && this.cells[row][col] !== null) {
|
|
450
|
+
keys.push(this.cells[row][col]?.field);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return keys;
|
|
455
|
+
}
|
|
456
|
+
getCellField(cell) {
|
|
457
|
+
if (this._isValidPosition(cell.row, cell.col)) {
|
|
458
|
+
return this.cells[cell.row][cell.col]?.field || null;
|
|
459
|
+
}
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
getCellType(cell) {
|
|
463
|
+
if (this._isValidPosition(cell.row, cell.col)) {
|
|
464
|
+
return this.cells[cell.row][cell.col]?.type || null;
|
|
465
|
+
}
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
getIsCellSelected(cell, start, end) {
|
|
469
|
+
if (!cell || !start || !end) {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
if (!this.multiColumnSelection && start.col !== end.col) {
|
|
473
|
+
throw new Error(
|
|
474
|
+
"Selection must be in the same column when multiColumnSelection is disabled"
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
const startRow = Math.min(start.row, end.row);
|
|
478
|
+
const endRow = Math.max(start.row, end.row);
|
|
479
|
+
const startCol = this.multiColumnSelection ? Math.min(start.col, end.col) : start.col;
|
|
480
|
+
const endCol = this.multiColumnSelection ? Math.max(start.col, end.col) : start.col;
|
|
481
|
+
return cell.row >= startRow && cell.row <= endRow && cell.col >= startCol && cell.col <= endCol;
|
|
482
|
+
}
|
|
483
|
+
toggleColumn(col, enabled) {
|
|
484
|
+
if (col < 0 || col >= this.cells[0].length) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
this.cells.forEach((row, index) => {
|
|
488
|
+
const cell = row[col];
|
|
489
|
+
if (cell) {
|
|
490
|
+
this.cells[index][col] = {
|
|
491
|
+
...cell,
|
|
492
|
+
enabled
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
toggleRow(row, enabled) {
|
|
498
|
+
if (row < 0 || row >= this.cells.length) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
this.cells[row].forEach((cell, index) => {
|
|
502
|
+
if (cell) {
|
|
503
|
+
this.cells[row][index] = {
|
|
504
|
+
...cell,
|
|
505
|
+
enabled
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
getCoordinatesByField(field) {
|
|
511
|
+
if (this.rowAccessors.length === 1) {
|
|
512
|
+
const col = this.columnAccessors.indexOf(field);
|
|
513
|
+
if (col === -1) {
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
return { row: 0, col };
|
|
517
|
+
}
|
|
518
|
+
for (let row = 0; row < this.rowAccessors.length; row++) {
|
|
519
|
+
const rowAccessor = this.rowAccessors[row];
|
|
520
|
+
if (rowAccessor === null) {
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
if (!field.startsWith(rowAccessor)) {
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
for (let column = 0; column < this.columnAccessors.length; column++) {
|
|
527
|
+
const columnAccessor = this.columnAccessors[column];
|
|
528
|
+
if (columnAccessor === null) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
const fullFieldPath = `${rowAccessor}.${columnAccessor}`;
|
|
532
|
+
if (fullFieldPath === field) {
|
|
533
|
+
return { row, col: column };
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
getRowAccessor(row) {
|
|
540
|
+
if (row < 0 || row >= this.cells.length) {
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
const cells = this.cells[row];
|
|
544
|
+
const nonNullFields = cells.filter((cell) => cell !== null).map((cell) => cell.field.split("."));
|
|
545
|
+
if (nonNullFields.length === 0) {
|
|
546
|
+
return null;
|
|
547
|
+
}
|
|
548
|
+
let commonParts = nonNullFields[0];
|
|
549
|
+
for (const segments of nonNullFields) {
|
|
550
|
+
commonParts = commonParts.filter(
|
|
551
|
+
(part, index) => segments[index] === part
|
|
552
|
+
);
|
|
553
|
+
if (commonParts.length === 0) {
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const accessor = commonParts.join(".");
|
|
558
|
+
if (!accessor) {
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
return accessor;
|
|
562
|
+
}
|
|
563
|
+
getColumnAccessor(column) {
|
|
564
|
+
if (column < 0 || column >= this.cells[0].length) {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
const uniqueParts = this.cells.map((row, rowIndex) => {
|
|
568
|
+
const cell = row[column];
|
|
569
|
+
if (!cell) {
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
const rowAccessor = this.getRowAccessor(rowIndex);
|
|
573
|
+
if (rowAccessor && cell.field.startsWith(rowAccessor + ".")) {
|
|
574
|
+
return cell.field.slice(rowAccessor.length + 1);
|
|
575
|
+
}
|
|
576
|
+
return null;
|
|
577
|
+
}).filter((part) => part !== null);
|
|
578
|
+
if (uniqueParts.length === 0) {
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
const firstPart = uniqueParts[0];
|
|
582
|
+
const isConsistent = uniqueParts.every((part) => part === firstPart);
|
|
583
|
+
return isConsistent ? firstPart : null;
|
|
584
|
+
}
|
|
585
|
+
getValidMovement(row, col, direction, metaKey = false) {
|
|
586
|
+
const [dRow, dCol] = this._getDirectionDeltas(direction);
|
|
587
|
+
if (metaKey) {
|
|
588
|
+
return this._getLastValidCellInDirection(row, col, dRow, dCol);
|
|
589
|
+
} else {
|
|
590
|
+
let newRow = row + dRow;
|
|
591
|
+
let newCol = col + dCol;
|
|
592
|
+
while (this._isValidPosition(newRow, newCol)) {
|
|
593
|
+
if (this.cells[newRow][newCol] !== null && this.cells[newRow][newCol]?.enabled !== false) {
|
|
594
|
+
return { row: newRow, col: newCol };
|
|
595
|
+
}
|
|
596
|
+
newRow += dRow;
|
|
597
|
+
newCol += dCol;
|
|
598
|
+
}
|
|
599
|
+
return { row, col };
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
_isValidPosition(row, col, cells) {
|
|
603
|
+
if (!cells) {
|
|
604
|
+
cells = this.cells;
|
|
605
|
+
}
|
|
606
|
+
return row >= 0 && row < cells.length && col >= 0 && col < cells[0].length;
|
|
607
|
+
}
|
|
608
|
+
_getDirectionDeltas(direction) {
|
|
609
|
+
switch (direction) {
|
|
610
|
+
case "ArrowUp":
|
|
611
|
+
return [-1, 0];
|
|
612
|
+
case "ArrowDown":
|
|
613
|
+
return [1, 0];
|
|
614
|
+
case "ArrowLeft":
|
|
615
|
+
return [0, -1];
|
|
616
|
+
case "ArrowRight":
|
|
617
|
+
return [0, 1];
|
|
618
|
+
default:
|
|
619
|
+
return [0, 0];
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
_getLastValidCellInDirection(row, col, dRow, dCol) {
|
|
623
|
+
let newRow = row;
|
|
624
|
+
let newCol = col;
|
|
625
|
+
let lastValidRow = row;
|
|
626
|
+
let lastValidCol = col;
|
|
627
|
+
while (this._isValidPosition(newRow + dRow, newCol + dCol)) {
|
|
628
|
+
newRow += dRow;
|
|
629
|
+
newCol += dCol;
|
|
630
|
+
if (this.cells[newRow][newCol] !== null) {
|
|
631
|
+
lastValidRow = newRow;
|
|
632
|
+
lastValidCol = newCol;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
row: lastValidRow,
|
|
637
|
+
col: lastValidCol
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
_populateCells(rows, columns) {
|
|
641
|
+
const cells = Array.from(
|
|
642
|
+
{ length: rows.length },
|
|
643
|
+
() => Array(columns.length).fill(null)
|
|
644
|
+
);
|
|
645
|
+
rows.forEach((row, rowIndex) => {
|
|
646
|
+
columns.forEach((column, colIndex) => {
|
|
647
|
+
if (!this._isValidPosition(rowIndex, colIndex, cells)) {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const {
|
|
651
|
+
name: _,
|
|
652
|
+
field,
|
|
653
|
+
type,
|
|
654
|
+
...rest
|
|
655
|
+
} = column.meta;
|
|
656
|
+
const context = {
|
|
657
|
+
row,
|
|
658
|
+
column: {
|
|
659
|
+
...column,
|
|
660
|
+
meta: rest
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
const fieldValue = field ? field(context) : null;
|
|
664
|
+
if (!fieldValue || !type) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
cells[rowIndex][colIndex] = {
|
|
668
|
+
field: fieldValue,
|
|
669
|
+
type,
|
|
670
|
+
enabled: true
|
|
671
|
+
};
|
|
672
|
+
});
|
|
673
|
+
});
|
|
674
|
+
return cells;
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
// src/components/data-grid/models/data-grid-query-tool.ts
|
|
679
|
+
var DataGridQueryTool = class {
|
|
680
|
+
constructor(container) {
|
|
681
|
+
__publicField(this, "container");
|
|
682
|
+
this.container = container;
|
|
683
|
+
}
|
|
684
|
+
getInput(cell) {
|
|
685
|
+
const id = this._getCellId(cell);
|
|
686
|
+
const input = this.container?.querySelector(`[data-cell-id="${id}"]`);
|
|
687
|
+
if (!input) {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
return input;
|
|
691
|
+
}
|
|
692
|
+
getInputByField(field) {
|
|
693
|
+
const input = this.container?.querySelector(`[data-field="${field}"]`);
|
|
694
|
+
if (!input) {
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
return input;
|
|
698
|
+
}
|
|
699
|
+
getCoordinatesByField(field) {
|
|
700
|
+
const cell = this.container?.querySelector(
|
|
701
|
+
`[data-field="${field}"][data-cell-id]`
|
|
702
|
+
);
|
|
703
|
+
if (!cell) {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
const cellId = cell.getAttribute("data-cell-id");
|
|
707
|
+
if (!cellId) {
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
const [row, col] = cellId.split(":").map((n) => parseInt(n, 10));
|
|
711
|
+
if (isNaN(row) || isNaN(col)) {
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
return { row, col };
|
|
715
|
+
}
|
|
716
|
+
getContainer(cell) {
|
|
717
|
+
const id = this._getCellId(cell);
|
|
718
|
+
const container = this.container?.querySelector(
|
|
719
|
+
`[data-container-id="${id}"]`
|
|
720
|
+
);
|
|
721
|
+
if (!container) {
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
return container;
|
|
725
|
+
}
|
|
726
|
+
_getCellId(cell) {
|
|
727
|
+
return generateCellId(cell);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
// src/components/data-grid/models/data-grid-update-command.ts
|
|
732
|
+
var DataGridUpdateCommand = class {
|
|
733
|
+
constructor({ prev, next, setter }) {
|
|
734
|
+
__publicField(this, "_prev");
|
|
735
|
+
__publicField(this, "_next");
|
|
736
|
+
__publicField(this, "_setter");
|
|
737
|
+
this._prev = prev;
|
|
738
|
+
this._next = next;
|
|
739
|
+
this._setter = setter;
|
|
740
|
+
}
|
|
741
|
+
execute() {
|
|
742
|
+
this._setter(this._next);
|
|
743
|
+
}
|
|
744
|
+
undo() {
|
|
745
|
+
this._setter(this._prev);
|
|
746
|
+
}
|
|
747
|
+
redo() {
|
|
748
|
+
this.execute();
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
// src/components/data-grid/hooks/use-data-grid-cell-handlers.tsx
|
|
753
|
+
var useDataGridCellHandlers = ({
|
|
754
|
+
matrix,
|
|
755
|
+
anchor,
|
|
756
|
+
rangeEnd,
|
|
757
|
+
setRangeEnd,
|
|
758
|
+
isDragging,
|
|
759
|
+
setIsDragging,
|
|
760
|
+
isSelecting,
|
|
761
|
+
setIsSelecting,
|
|
762
|
+
setSingleRange,
|
|
763
|
+
dragEnd,
|
|
764
|
+
setDragEnd,
|
|
765
|
+
setValue: setValue2,
|
|
766
|
+
execute,
|
|
767
|
+
multiColumnSelection
|
|
768
|
+
}) => {
|
|
769
|
+
const getWrapperFocusHandler = useCallback2(
|
|
770
|
+
(coords) => {
|
|
771
|
+
return (_e) => {
|
|
772
|
+
setSingleRange(coords);
|
|
773
|
+
};
|
|
774
|
+
},
|
|
775
|
+
[setSingleRange]
|
|
776
|
+
);
|
|
777
|
+
const getOverlayMouseDownHandler = useCallback2(
|
|
778
|
+
(coords) => {
|
|
779
|
+
return (e) => {
|
|
780
|
+
e.stopPropagation();
|
|
781
|
+
e.preventDefault();
|
|
782
|
+
if (e.shiftKey) {
|
|
783
|
+
setRangeEnd(coords);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
setIsSelecting(true);
|
|
787
|
+
setSingleRange(coords);
|
|
788
|
+
};
|
|
789
|
+
},
|
|
790
|
+
[setIsSelecting, setRangeEnd, setSingleRange]
|
|
791
|
+
);
|
|
792
|
+
const getWrapperMouseOverHandler = useCallback2(
|
|
793
|
+
(coords) => {
|
|
794
|
+
if (!isDragging && !isSelecting) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
return (_e) => {
|
|
798
|
+
if (anchor?.col !== coords.col && !multiColumnSelection) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
if (isSelecting) {
|
|
802
|
+
setRangeEnd(coords);
|
|
803
|
+
} else {
|
|
804
|
+
setDragEnd(coords);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
},
|
|
808
|
+
[
|
|
809
|
+
anchor?.col,
|
|
810
|
+
isDragging,
|
|
811
|
+
isSelecting,
|
|
812
|
+
setDragEnd,
|
|
813
|
+
setRangeEnd,
|
|
814
|
+
multiColumnSelection
|
|
815
|
+
]
|
|
816
|
+
);
|
|
817
|
+
const getInputChangeHandler = useCallback2(
|
|
818
|
+
// Using `any` here as the generic type of Path<TFieldValues> will
|
|
819
|
+
// not be inferred correctly.
|
|
820
|
+
(field) => {
|
|
821
|
+
return (next, prev) => {
|
|
822
|
+
const command = new DataGridUpdateCommand({
|
|
823
|
+
next,
|
|
824
|
+
prev,
|
|
825
|
+
setter: (value) => {
|
|
826
|
+
setValue2(field, value, {
|
|
827
|
+
shouldDirty: true,
|
|
828
|
+
shouldTouch: true
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
execute(command);
|
|
833
|
+
};
|
|
834
|
+
},
|
|
835
|
+
[setValue2, execute]
|
|
836
|
+
);
|
|
837
|
+
const onDragToFillStart = useCallback2(
|
|
838
|
+
(_e) => {
|
|
839
|
+
setIsDragging(true);
|
|
840
|
+
},
|
|
841
|
+
[setIsDragging]
|
|
842
|
+
);
|
|
843
|
+
const getIsCellSelected = useCallback2(
|
|
844
|
+
(cell) => {
|
|
845
|
+
if (!cell || !anchor || !rangeEnd) {
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
return matrix.getIsCellSelected(cell, anchor, rangeEnd);
|
|
849
|
+
},
|
|
850
|
+
[anchor, rangeEnd, matrix]
|
|
851
|
+
);
|
|
852
|
+
const getIsCellDragSelected = useCallback2(
|
|
853
|
+
(cell) => {
|
|
854
|
+
if (!cell || !anchor || !dragEnd) {
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
return matrix.getIsCellSelected(cell, anchor, dragEnd);
|
|
858
|
+
},
|
|
859
|
+
[anchor, dragEnd, matrix]
|
|
860
|
+
);
|
|
861
|
+
return {
|
|
862
|
+
getWrapperFocusHandler,
|
|
863
|
+
getOverlayMouseDownHandler,
|
|
864
|
+
getWrapperMouseOverHandler,
|
|
865
|
+
getInputChangeHandler,
|
|
866
|
+
getIsCellSelected,
|
|
867
|
+
getIsCellDragSelected,
|
|
868
|
+
onDragToFillStart
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
// src/components/data-grid/hooks/use-data-grid-cell-metadata.tsx
|
|
873
|
+
import { useCallback as useCallback3 } from "react";
|
|
874
|
+
var useDataGridCellMetadata = ({
|
|
875
|
+
matrix
|
|
876
|
+
}) => {
|
|
877
|
+
const getCellMetadata = useCallback3(
|
|
878
|
+
(coords) => {
|
|
879
|
+
const { row, col } = coords;
|
|
880
|
+
const id = generateCellId(coords);
|
|
881
|
+
const field = matrix.getCellField(coords);
|
|
882
|
+
const type = matrix.getCellType(coords);
|
|
883
|
+
if (!field || !type) {
|
|
884
|
+
throw new Error(`'field' or 'type' is null for cell ${id}`);
|
|
885
|
+
}
|
|
886
|
+
const inputAttributes = {
|
|
887
|
+
"data-row": row,
|
|
888
|
+
"data-col": col,
|
|
889
|
+
"data-cell-id": id,
|
|
890
|
+
"data-field": field
|
|
891
|
+
};
|
|
892
|
+
const innerAttributes = {
|
|
893
|
+
"data-container-id": id
|
|
894
|
+
};
|
|
895
|
+
return {
|
|
896
|
+
id,
|
|
897
|
+
field,
|
|
898
|
+
type,
|
|
899
|
+
inputAttributes,
|
|
900
|
+
innerAttributes
|
|
901
|
+
};
|
|
902
|
+
},
|
|
903
|
+
[matrix]
|
|
904
|
+
);
|
|
905
|
+
const getCellErrorMetadata = useCallback3(
|
|
906
|
+
(coords) => {
|
|
907
|
+
const accessor = matrix.getRowAccessor(coords.row);
|
|
908
|
+
const field = matrix.getCellField(coords);
|
|
909
|
+
return {
|
|
910
|
+
accessor,
|
|
911
|
+
field
|
|
912
|
+
};
|
|
913
|
+
},
|
|
914
|
+
[matrix]
|
|
915
|
+
);
|
|
916
|
+
return {
|
|
917
|
+
getCellMetadata,
|
|
918
|
+
getCellErrorMetadata
|
|
919
|
+
};
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
// src/components/data-grid/hooks/use-data-grid-cell-snapshot.tsx
|
|
923
|
+
import { useCallback as useCallback4, useState as useState2 } from "react";
|
|
924
|
+
var useDataGridCellSnapshot = ({
|
|
925
|
+
matrix,
|
|
926
|
+
form
|
|
927
|
+
}) => {
|
|
928
|
+
const [snapshot, setSnapshot] = useState2(null);
|
|
929
|
+
const { getValues, setValue: setValue2 } = form;
|
|
930
|
+
const createSnapshot = useCallback4(
|
|
931
|
+
(cell) => {
|
|
932
|
+
if (!cell) {
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
const field = matrix.getCellField(cell);
|
|
936
|
+
if (!field) {
|
|
937
|
+
return null;
|
|
938
|
+
}
|
|
939
|
+
const value = getValues(field);
|
|
940
|
+
setSnapshot((curr) => {
|
|
941
|
+
if (curr?.field === field) {
|
|
942
|
+
return curr;
|
|
943
|
+
}
|
|
944
|
+
return { field, value };
|
|
945
|
+
});
|
|
946
|
+
},
|
|
947
|
+
[getValues, matrix]
|
|
948
|
+
);
|
|
949
|
+
const restoreSnapshot = useCallback4(() => {
|
|
950
|
+
if (!snapshot) {
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
const { field, value } = snapshot;
|
|
954
|
+
requestAnimationFrame(() => {
|
|
955
|
+
setValue2(field, value);
|
|
956
|
+
});
|
|
957
|
+
}, [setValue2, snapshot]);
|
|
958
|
+
return {
|
|
959
|
+
createSnapshot,
|
|
960
|
+
restoreSnapshot
|
|
961
|
+
};
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
// src/components/data-grid/hooks/use-data-grid-clipboard-events.tsx
|
|
965
|
+
import { useCallback as useCallback5 } from "react";
|
|
966
|
+
var useDataGridClipboardEvents = ({
|
|
967
|
+
matrix,
|
|
968
|
+
anchor,
|
|
969
|
+
rangeEnd,
|
|
970
|
+
isEditing,
|
|
971
|
+
getSelectionValues,
|
|
972
|
+
setSelectionValues,
|
|
973
|
+
execute
|
|
974
|
+
}) => {
|
|
975
|
+
const handleCopyEvent = useCallback5(
|
|
976
|
+
(e) => {
|
|
977
|
+
if (isEditing || !anchor || !rangeEnd) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
e.preventDefault();
|
|
981
|
+
const fields = matrix.getFieldsInSelection(anchor, rangeEnd);
|
|
982
|
+
const values = getSelectionValues(fields);
|
|
983
|
+
const text = values.map((value) => {
|
|
984
|
+
if (typeof value === "object" && value !== null) {
|
|
985
|
+
return JSON.stringify(value);
|
|
986
|
+
}
|
|
987
|
+
return `${value}` ?? "";
|
|
988
|
+
}).join(" ");
|
|
989
|
+
e.clipboardData?.setData("text/plain", text);
|
|
990
|
+
},
|
|
991
|
+
[isEditing, anchor, rangeEnd, matrix, getSelectionValues]
|
|
992
|
+
);
|
|
993
|
+
const handlePasteEvent = useCallback5(
|
|
994
|
+
(e) => {
|
|
995
|
+
if (isEditing || !anchor || !rangeEnd) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
e.preventDefault();
|
|
999
|
+
const text = e.clipboardData?.getData("text/plain");
|
|
1000
|
+
if (!text) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const next = text.split(" ");
|
|
1004
|
+
const fields = matrix.getFieldsInSelection(anchor, rangeEnd);
|
|
1005
|
+
const prev = getSelectionValues(fields);
|
|
1006
|
+
const command = new DataGridBulkUpdateCommand({
|
|
1007
|
+
fields,
|
|
1008
|
+
next,
|
|
1009
|
+
prev,
|
|
1010
|
+
setter: setSelectionValues
|
|
1011
|
+
});
|
|
1012
|
+
execute(command);
|
|
1013
|
+
},
|
|
1014
|
+
[
|
|
1015
|
+
isEditing,
|
|
1016
|
+
anchor,
|
|
1017
|
+
rangeEnd,
|
|
1018
|
+
matrix,
|
|
1019
|
+
getSelectionValues,
|
|
1020
|
+
setSelectionValues,
|
|
1021
|
+
execute
|
|
1022
|
+
]
|
|
1023
|
+
);
|
|
1024
|
+
return {
|
|
1025
|
+
handleCopyEvent,
|
|
1026
|
+
handlePasteEvent
|
|
1027
|
+
};
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// src/components/data-grid/hooks/use-data-grid-column-visibility.tsx
|
|
1031
|
+
import { useCallback as useCallback6 } from "react";
|
|
1032
|
+
function useDataGridColumnVisibility(grid, matrix) {
|
|
1033
|
+
const columns = grid.getAllLeafColumns();
|
|
1034
|
+
const columnOptions = columns.map((column) => ({
|
|
1035
|
+
id: column.id,
|
|
1036
|
+
name: getColumnName(column),
|
|
1037
|
+
checked: column.getIsVisible(),
|
|
1038
|
+
disabled: !column.getCanHide()
|
|
1039
|
+
}));
|
|
1040
|
+
const handleToggleColumn = useCallback6(
|
|
1041
|
+
(index) => (value) => {
|
|
1042
|
+
const column = columns[index];
|
|
1043
|
+
if (!column.getCanHide()) {
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
matrix.toggleColumn(index, value);
|
|
1047
|
+
column.toggleVisibility(value);
|
|
1048
|
+
},
|
|
1049
|
+
[columns, matrix]
|
|
1050
|
+
);
|
|
1051
|
+
const handleResetColumns = useCallback6(() => {
|
|
1052
|
+
grid.setColumnVisibility({});
|
|
1053
|
+
}, [grid]);
|
|
1054
|
+
const optionCount = columnOptions.filter((c) => !c.disabled).length;
|
|
1055
|
+
const isDisabled = optionCount === 0;
|
|
1056
|
+
return {
|
|
1057
|
+
columnOptions,
|
|
1058
|
+
handleToggleColumn,
|
|
1059
|
+
handleResetColumns,
|
|
1060
|
+
isDisabled
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
function getColumnName(column) {
|
|
1064
|
+
const id = column.columnDef.id;
|
|
1065
|
+
const enableHiding = column.columnDef.enableHiding;
|
|
1066
|
+
const meta = column?.columnDef.meta;
|
|
1067
|
+
if (!id) {
|
|
1068
|
+
throw new Error(
|
|
1069
|
+
"Column is missing an id, which is a required field. Please provide an id for the column."
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
if (process.env.NODE_ENV === "development" && !meta?.name && enableHiding) {
|
|
1073
|
+
console.warn(
|
|
1074
|
+
`Column "${id}" does not have a name. You should add a name to the column definition. Falling back to the column id.`
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
return meta?.name || id;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// src/components/data-grid/hooks/use-data-grid-duplicate-cell.tsx
|
|
1081
|
+
import { useWatch } from "react-hook-form";
|
|
1082
|
+
var useDataGridDuplicateCell = ({
|
|
1083
|
+
duplicateOf
|
|
1084
|
+
}) => {
|
|
1085
|
+
const { control } = useDataGridContext();
|
|
1086
|
+
const watchedValue = useWatch({ control, name: duplicateOf });
|
|
1087
|
+
return {
|
|
1088
|
+
watchedValue
|
|
1089
|
+
};
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
// src/components/data-grid/hooks/use-data-grid-error-highlighting.tsx
|
|
1093
|
+
import { useCallback as useCallback7, useMemo as useMemo3, useState as useState3 } from "react";
|
|
1094
|
+
var useDataGridErrorHighlighting = (matrix, grid, errors) => {
|
|
1095
|
+
const [isHighlighted, setIsHighlighted] = useState3(false);
|
|
1096
|
+
const [visibilitySnapshot, setVisibilitySnapshot] = useState3(null);
|
|
1097
|
+
const { flatRows } = grid.getRowModel();
|
|
1098
|
+
const flatColumns = grid.getAllFlatColumns();
|
|
1099
|
+
const errorPaths = findErrorPaths(errors);
|
|
1100
|
+
const errorCount = errorPaths.length;
|
|
1101
|
+
const { rowsWithErrors, columnsWithErrors } = useMemo3(() => {
|
|
1102
|
+
const rowsWithErrors2 = /* @__PURE__ */ new Set();
|
|
1103
|
+
const columnsWithErrors2 = /* @__PURE__ */ new Set();
|
|
1104
|
+
errorPaths.forEach((errorPath) => {
|
|
1105
|
+
const rowIndex = matrix.rowAccessors.findIndex(
|
|
1106
|
+
(accessor) => accessor && (errorPath === accessor || errorPath.startsWith(`${accessor}.`))
|
|
1107
|
+
);
|
|
1108
|
+
if (rowIndex !== -1) {
|
|
1109
|
+
rowsWithErrors2.add(rowIndex);
|
|
1110
|
+
}
|
|
1111
|
+
const columnIndex = matrix.columnAccessors.findIndex(
|
|
1112
|
+
(accessor) => accessor && (errorPath === accessor || errorPath.endsWith(`.${accessor}`))
|
|
1113
|
+
);
|
|
1114
|
+
if (columnIndex !== -1) {
|
|
1115
|
+
columnsWithErrors2.add(columnIndex);
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
return { rowsWithErrors: rowsWithErrors2, columnsWithErrors: columnsWithErrors2 };
|
|
1119
|
+
}, [errorPaths, matrix.rowAccessors, matrix.columnAccessors]);
|
|
1120
|
+
const toggleErrorHighlighting = useCallback7(
|
|
1121
|
+
(currentRowVisibility, currentColumnVisibility, setRowVisibility, setColumnVisibility) => {
|
|
1122
|
+
if (isHighlighted) {
|
|
1123
|
+
if (visibilitySnapshot) {
|
|
1124
|
+
setRowVisibility(visibilitySnapshot.rows);
|
|
1125
|
+
setColumnVisibility(visibilitySnapshot.columns);
|
|
1126
|
+
}
|
|
1127
|
+
} else {
|
|
1128
|
+
setVisibilitySnapshot({
|
|
1129
|
+
rows: { ...currentRowVisibility },
|
|
1130
|
+
columns: { ...currentColumnVisibility }
|
|
1131
|
+
});
|
|
1132
|
+
const rowsToHide = flatRows.map((_, index) => {
|
|
1133
|
+
return !rowsWithErrors.has(index) ? index : void 0;
|
|
1134
|
+
}).filter((index) => index !== void 0);
|
|
1135
|
+
const columnsToHide = flatColumns.map((column, index) => {
|
|
1136
|
+
return !columnsWithErrors.has(index) && index !== 0 ? column.id : void 0;
|
|
1137
|
+
}).filter((id) => id !== void 0);
|
|
1138
|
+
setRowVisibility(
|
|
1139
|
+
rowsToHide.reduce((acc, row) => ({ ...acc, [row]: false }), {})
|
|
1140
|
+
);
|
|
1141
|
+
setColumnVisibility(
|
|
1142
|
+
columnsToHide.reduce(
|
|
1143
|
+
(acc, column) => ({ ...acc, [column]: false }),
|
|
1144
|
+
{}
|
|
1145
|
+
)
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
setIsHighlighted((prev) => !prev);
|
|
1149
|
+
},
|
|
1150
|
+
[
|
|
1151
|
+
isHighlighted,
|
|
1152
|
+
visibilitySnapshot,
|
|
1153
|
+
flatRows,
|
|
1154
|
+
flatColumns,
|
|
1155
|
+
rowsWithErrors,
|
|
1156
|
+
columnsWithErrors
|
|
1157
|
+
]
|
|
1158
|
+
);
|
|
1159
|
+
return {
|
|
1160
|
+
errorCount,
|
|
1161
|
+
isHighlighted,
|
|
1162
|
+
toggleErrorHighlighting
|
|
1163
|
+
};
|
|
1164
|
+
};
|
|
1165
|
+
function findErrorPaths(obj, path = []) {
|
|
1166
|
+
if (typeof obj !== "object" || obj === null) {
|
|
1167
|
+
return [];
|
|
1168
|
+
}
|
|
1169
|
+
if ("message" in obj && "type" in obj) {
|
|
1170
|
+
return [path.join(".")];
|
|
1171
|
+
}
|
|
1172
|
+
return Object.entries(obj).flatMap(
|
|
1173
|
+
([key, value]) => findErrorPaths(value, [...path, key])
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// src/components/data-grid/hooks/use-data-grid-form-handlers.tsx
|
|
1178
|
+
import { useCallback as useCallback8 } from "react";
|
|
1179
|
+
var useDataGridFormHandlers = ({
|
|
1180
|
+
matrix,
|
|
1181
|
+
form,
|
|
1182
|
+
anchor
|
|
1183
|
+
}) => {
|
|
1184
|
+
const { getValues, reset } = form;
|
|
1185
|
+
const getSelectionValues = useCallback8(
|
|
1186
|
+
(fields) => {
|
|
1187
|
+
if (!fields.length) {
|
|
1188
|
+
return [];
|
|
1189
|
+
}
|
|
1190
|
+
const allValues = getValues();
|
|
1191
|
+
return fields.map((field) => {
|
|
1192
|
+
return field.split(".").reduce((obj, key) => obj?.[key], allValues);
|
|
1193
|
+
});
|
|
1194
|
+
},
|
|
1195
|
+
[getValues]
|
|
1196
|
+
);
|
|
1197
|
+
const setSelectionValues = useCallback8(
|
|
1198
|
+
async (fields, values, isHistory) => {
|
|
1199
|
+
if (!fields.length || !anchor) {
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
const type = matrix.getCellType(anchor);
|
|
1203
|
+
if (!type) {
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
const convertedValues = convertArrayToPrimitive(values, type);
|
|
1207
|
+
const currentValues = getValues();
|
|
1208
|
+
fields.forEach((field, index) => {
|
|
1209
|
+
if (!field) {
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
const valueIndex = index % values.length;
|
|
1213
|
+
const newValue = convertedValues[valueIndex];
|
|
1214
|
+
setValue(currentValues, field, newValue, type, isHistory);
|
|
1215
|
+
});
|
|
1216
|
+
reset(currentValues, {
|
|
1217
|
+
keepDirty: true,
|
|
1218
|
+
keepTouched: true,
|
|
1219
|
+
keepDefaultValues: true
|
|
1220
|
+
});
|
|
1221
|
+
},
|
|
1222
|
+
[matrix, anchor, getValues, reset]
|
|
1223
|
+
);
|
|
1224
|
+
return {
|
|
1225
|
+
getSelectionValues,
|
|
1226
|
+
setSelectionValues
|
|
1227
|
+
};
|
|
1228
|
+
};
|
|
1229
|
+
function convertToNumber(value) {
|
|
1230
|
+
if (typeof value === "number") {
|
|
1231
|
+
return value;
|
|
1232
|
+
}
|
|
1233
|
+
const converted = Number(value);
|
|
1234
|
+
if (isNaN(converted)) {
|
|
1235
|
+
throw new Error(`String "${value}" cannot be converted to number.`);
|
|
1236
|
+
}
|
|
1237
|
+
return converted;
|
|
1238
|
+
}
|
|
1239
|
+
function convertToBoolean(value) {
|
|
1240
|
+
if (typeof value === "boolean") {
|
|
1241
|
+
return value;
|
|
1242
|
+
}
|
|
1243
|
+
if (typeof value === "undefined" || value === null) {
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
const lowerValue = value.toLowerCase();
|
|
1247
|
+
if (lowerValue === "true" || lowerValue === "false") {
|
|
1248
|
+
return lowerValue === "true";
|
|
1249
|
+
}
|
|
1250
|
+
throw new Error(`String "${value}" cannot be converted to boolean.`);
|
|
1251
|
+
}
|
|
1252
|
+
function covertToString(value) {
|
|
1253
|
+
if (typeof value === "undefined" || value === null) {
|
|
1254
|
+
return "";
|
|
1255
|
+
}
|
|
1256
|
+
return String(value);
|
|
1257
|
+
}
|
|
1258
|
+
function convertToggleableNumber(value) {
|
|
1259
|
+
let obj = value;
|
|
1260
|
+
if (typeof obj === "string") {
|
|
1261
|
+
try {
|
|
1262
|
+
obj = JSON.parse(obj);
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
throw new Error(`String "${value}" cannot be converted to object.`);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return obj;
|
|
1268
|
+
}
|
|
1269
|
+
function setValue(currentValues, field, newValue, type, isHistory) {
|
|
1270
|
+
if (type !== "togglable-number") {
|
|
1271
|
+
field.split(".").reduce((curr, key, index) => {
|
|
1272
|
+
if (index === field.split(".").length - 1) {
|
|
1273
|
+
curr[key] = newValue;
|
|
1274
|
+
}
|
|
1275
|
+
curr[key] ?? (curr[key] = {});
|
|
1276
|
+
return curr[key];
|
|
1277
|
+
}, currentValues);
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
setValueToggleableNumber(currentValues, field, newValue, isHistory);
|
|
1281
|
+
}
|
|
1282
|
+
function setValueToggleableNumber(currentValues = {}, field, newValue, isHistory) {
|
|
1283
|
+
const currentValue = field.split(".").reduce((obj, key) => obj?.[key], currentValues);
|
|
1284
|
+
const { disabledToggle } = currentValue || {};
|
|
1285
|
+
const normalizeQuantity = (value) => {
|
|
1286
|
+
if (disabledToggle && value === "") {
|
|
1287
|
+
return 0;
|
|
1288
|
+
}
|
|
1289
|
+
return value;
|
|
1290
|
+
};
|
|
1291
|
+
const determineChecked = (quantity2) => {
|
|
1292
|
+
if (disabledToggle) {
|
|
1293
|
+
return true;
|
|
1294
|
+
}
|
|
1295
|
+
return quantity2 !== "" && quantity2 != null;
|
|
1296
|
+
};
|
|
1297
|
+
const quantity = normalizeQuantity(newValue.quantity);
|
|
1298
|
+
const checked = isHistory ? disabledToggle ? true : newValue.checked : determineChecked(quantity);
|
|
1299
|
+
const fieldParts = field.split(".");
|
|
1300
|
+
fieldParts.reduce((curr, key, index) => {
|
|
1301
|
+
if (index === fieldParts.length - 1) {
|
|
1302
|
+
curr[key] = {
|
|
1303
|
+
...currentValue || {},
|
|
1304
|
+
quantity,
|
|
1305
|
+
checked,
|
|
1306
|
+
disabledToggle: disabledToggle ?? false
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
curr[key] ?? (curr[key] = {});
|
|
1310
|
+
return curr[key];
|
|
1311
|
+
}, currentValues);
|
|
1312
|
+
}
|
|
1313
|
+
function convertArrayToPrimitive(values, type) {
|
|
1314
|
+
switch (type) {
|
|
1315
|
+
case "number":
|
|
1316
|
+
return values.map((v) => {
|
|
1317
|
+
if (v === "") {
|
|
1318
|
+
return v;
|
|
1319
|
+
}
|
|
1320
|
+
if (v == null) {
|
|
1321
|
+
return "";
|
|
1322
|
+
}
|
|
1323
|
+
return convertToNumber(v);
|
|
1324
|
+
});
|
|
1325
|
+
case "togglable-number":
|
|
1326
|
+
return values.map(convertToggleableNumber);
|
|
1327
|
+
case "boolean":
|
|
1328
|
+
return values.map(convertToBoolean);
|
|
1329
|
+
case "text":
|
|
1330
|
+
case "multiline-text":
|
|
1331
|
+
return values.map(covertToString);
|
|
1332
|
+
default:
|
|
1333
|
+
throw new Error(`Unsupported target type "${type}".`);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// src/components/data-grid/hooks/use-data-grid-keydown-event.tsx
|
|
1338
|
+
import { useCallback as useCallback9 } from "react";
|
|
1339
|
+
var ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
1340
|
+
var VERTICAL_KEYS = ["ArrowUp", "ArrowDown"];
|
|
1341
|
+
var useDataGridKeydownEvent = ({
|
|
1342
|
+
containerRef,
|
|
1343
|
+
matrix,
|
|
1344
|
+
anchor,
|
|
1345
|
+
rangeEnd,
|
|
1346
|
+
isEditing,
|
|
1347
|
+
setTrapActive,
|
|
1348
|
+
scrollToCoordinates,
|
|
1349
|
+
setSingleRange,
|
|
1350
|
+
setRangeEnd,
|
|
1351
|
+
onEditingChangeHandler,
|
|
1352
|
+
getValues,
|
|
1353
|
+
setValue: setValue2,
|
|
1354
|
+
execute,
|
|
1355
|
+
undo,
|
|
1356
|
+
redo,
|
|
1357
|
+
queryTool,
|
|
1358
|
+
getSelectionValues,
|
|
1359
|
+
setSelectionValues,
|
|
1360
|
+
restoreSnapshot,
|
|
1361
|
+
createSnapshot
|
|
1362
|
+
}) => {
|
|
1363
|
+
const handleKeyboardNavigation = useCallback9(
|
|
1364
|
+
(e) => {
|
|
1365
|
+
if (!anchor) {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
const type = matrix.getCellType(anchor);
|
|
1369
|
+
if (isEditing && type !== "boolean") {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
const direction = VERTICAL_KEYS.includes(e.key) ? "vertical" : "horizontal";
|
|
1373
|
+
const basis = direction === "horizontal" ? anchor : e.shiftKey ? rangeEnd : anchor;
|
|
1374
|
+
const updater = direction === "horizontal" ? setSingleRange : e.shiftKey ? setRangeEnd : setSingleRange;
|
|
1375
|
+
if (!basis) {
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
const { row, col } = basis;
|
|
1379
|
+
const handleNavigation = (coords) => {
|
|
1380
|
+
e.preventDefault();
|
|
1381
|
+
e.stopPropagation();
|
|
1382
|
+
scrollToCoordinates(coords, direction);
|
|
1383
|
+
updater(coords);
|
|
1384
|
+
};
|
|
1385
|
+
const next = matrix.getValidMovement(
|
|
1386
|
+
row,
|
|
1387
|
+
col,
|
|
1388
|
+
e.key,
|
|
1389
|
+
e.metaKey || e.ctrlKey
|
|
1390
|
+
);
|
|
1391
|
+
handleNavigation(next);
|
|
1392
|
+
},
|
|
1393
|
+
[
|
|
1394
|
+
isEditing,
|
|
1395
|
+
anchor,
|
|
1396
|
+
rangeEnd,
|
|
1397
|
+
scrollToCoordinates,
|
|
1398
|
+
setSingleRange,
|
|
1399
|
+
setRangeEnd,
|
|
1400
|
+
matrix
|
|
1401
|
+
]
|
|
1402
|
+
);
|
|
1403
|
+
const handleTabKey = useCallback9(
|
|
1404
|
+
(e) => {
|
|
1405
|
+
if (!anchor) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
e.preventDefault();
|
|
1409
|
+
e.stopPropagation();
|
|
1410
|
+
const { row, col } = anchor;
|
|
1411
|
+
const key = e.shiftKey ? "ArrowLeft" : "ArrowRight";
|
|
1412
|
+
const direction = "horizontal";
|
|
1413
|
+
const next = matrix.getValidMovement(
|
|
1414
|
+
row,
|
|
1415
|
+
col,
|
|
1416
|
+
key,
|
|
1417
|
+
e.metaKey || e.ctrlKey
|
|
1418
|
+
);
|
|
1419
|
+
scrollToCoordinates(next, direction);
|
|
1420
|
+
setSingleRange(next);
|
|
1421
|
+
},
|
|
1422
|
+
[anchor, scrollToCoordinates, setSingleRange, matrix]
|
|
1423
|
+
);
|
|
1424
|
+
const handleUndo = useCallback9(
|
|
1425
|
+
(e) => {
|
|
1426
|
+
e.preventDefault();
|
|
1427
|
+
if (e.shiftKey) {
|
|
1428
|
+
redo();
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
undo();
|
|
1432
|
+
},
|
|
1433
|
+
[redo, undo]
|
|
1434
|
+
);
|
|
1435
|
+
const handleSpaceKeyBoolean = useCallback9(
|
|
1436
|
+
(anchor2) => {
|
|
1437
|
+
const end = rangeEnd ?? anchor2;
|
|
1438
|
+
const fields = matrix.getFieldsInSelection(anchor2, end);
|
|
1439
|
+
const prev = getSelectionValues(fields);
|
|
1440
|
+
const allChecked = prev.every((value) => value === true);
|
|
1441
|
+
const next = Array.from({ length: prev.length }, () => !allChecked);
|
|
1442
|
+
const command = new DataGridBulkUpdateCommand({
|
|
1443
|
+
fields,
|
|
1444
|
+
next,
|
|
1445
|
+
prev,
|
|
1446
|
+
setter: setSelectionValues
|
|
1447
|
+
});
|
|
1448
|
+
execute(command);
|
|
1449
|
+
},
|
|
1450
|
+
[rangeEnd, matrix, getSelectionValues, setSelectionValues, execute]
|
|
1451
|
+
);
|
|
1452
|
+
const handleSpaceKeyText = useCallback9(
|
|
1453
|
+
(anchor2) => {
|
|
1454
|
+
const field = matrix.getCellField(anchor2);
|
|
1455
|
+
const input = queryTool?.getInput(anchor2);
|
|
1456
|
+
if (!field || !input) {
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
createSnapshot(anchor2);
|
|
1460
|
+
input.focus();
|
|
1461
|
+
},
|
|
1462
|
+
[matrix, queryTool, createSnapshot]
|
|
1463
|
+
);
|
|
1464
|
+
const handleSpaceKeyNumber = useCallback9(
|
|
1465
|
+
(anchor2) => {
|
|
1466
|
+
const field = matrix.getCellField(anchor2);
|
|
1467
|
+
const input = queryTool?.getInput(anchor2);
|
|
1468
|
+
if (!field || !input) {
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
createSnapshot(anchor2);
|
|
1472
|
+
const current = getValues(field);
|
|
1473
|
+
const next = "";
|
|
1474
|
+
const command = new DataGridUpdateCommand({
|
|
1475
|
+
next,
|
|
1476
|
+
prev: current,
|
|
1477
|
+
setter: (value) => {
|
|
1478
|
+
setValue2(field, value, {
|
|
1479
|
+
shouldDirty: true,
|
|
1480
|
+
shouldTouch: true
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
execute(command);
|
|
1485
|
+
input.focus();
|
|
1486
|
+
},
|
|
1487
|
+
[matrix, queryTool, getValues, execute, setValue2, createSnapshot]
|
|
1488
|
+
);
|
|
1489
|
+
const handleSpaceKeyTogglableNumber = useCallback9(
|
|
1490
|
+
(anchor2) => {
|
|
1491
|
+
const field = matrix.getCellField(anchor2);
|
|
1492
|
+
const input = queryTool?.getInput(anchor2);
|
|
1493
|
+
if (!field || !input) {
|
|
1494
|
+
return;
|
|
1495
|
+
}
|
|
1496
|
+
createSnapshot(anchor2);
|
|
1497
|
+
const current = getValues(field);
|
|
1498
|
+
let checked = current.checked;
|
|
1499
|
+
if (!current.disabledToggle) {
|
|
1500
|
+
checked = false;
|
|
1501
|
+
}
|
|
1502
|
+
const next = { ...current, quantity: "", checked };
|
|
1503
|
+
const command = new DataGridUpdateCommand({
|
|
1504
|
+
next,
|
|
1505
|
+
prev: current,
|
|
1506
|
+
setter: (value) => {
|
|
1507
|
+
setValue2(field, value, {
|
|
1508
|
+
shouldDirty: true,
|
|
1509
|
+
shouldTouch: true
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
execute(command);
|
|
1514
|
+
input.focus();
|
|
1515
|
+
},
|
|
1516
|
+
[matrix, queryTool, getValues, execute, setValue2, createSnapshot]
|
|
1517
|
+
);
|
|
1518
|
+
const handleSpaceKey = useCallback9(
|
|
1519
|
+
(e) => {
|
|
1520
|
+
if (!anchor || isEditing) {
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
e.preventDefault();
|
|
1524
|
+
const type = matrix.getCellType(anchor);
|
|
1525
|
+
if (!type) {
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
switch (type) {
|
|
1529
|
+
case "boolean":
|
|
1530
|
+
handleSpaceKeyBoolean(anchor);
|
|
1531
|
+
break;
|
|
1532
|
+
case "togglable-number":
|
|
1533
|
+
handleSpaceKeyTogglableNumber(anchor);
|
|
1534
|
+
break;
|
|
1535
|
+
case "text":
|
|
1536
|
+
case "multiline-text":
|
|
1537
|
+
handleSpaceKeyText(anchor);
|
|
1538
|
+
break;
|
|
1539
|
+
case "number":
|
|
1540
|
+
handleSpaceKeyNumber(anchor);
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1544
|
+
[
|
|
1545
|
+
anchor,
|
|
1546
|
+
isEditing,
|
|
1547
|
+
matrix,
|
|
1548
|
+
handleSpaceKeyBoolean,
|
|
1549
|
+
handleSpaceKeyText,
|
|
1550
|
+
handleSpaceKeyNumber,
|
|
1551
|
+
handleSpaceKeyTogglableNumber
|
|
1552
|
+
]
|
|
1553
|
+
);
|
|
1554
|
+
const handleMoveOnEnter = useCallback9(
|
|
1555
|
+
(e, anchor2) => {
|
|
1556
|
+
const direction = e.shiftKey ? "ArrowUp" : "ArrowDown";
|
|
1557
|
+
const pos = matrix.getValidMovement(
|
|
1558
|
+
anchor2.row,
|
|
1559
|
+
anchor2.col,
|
|
1560
|
+
direction,
|
|
1561
|
+
false
|
|
1562
|
+
);
|
|
1563
|
+
if (anchor2.row !== pos.row || anchor2.col !== pos.col) {
|
|
1564
|
+
setSingleRange(pos);
|
|
1565
|
+
scrollToCoordinates(pos, "vertical");
|
|
1566
|
+
} else {
|
|
1567
|
+
const container = queryTool?.getContainer(anchor2);
|
|
1568
|
+
container?.focus();
|
|
1569
|
+
}
|
|
1570
|
+
onEditingChangeHandler(false);
|
|
1571
|
+
},
|
|
1572
|
+
[
|
|
1573
|
+
queryTool,
|
|
1574
|
+
matrix,
|
|
1575
|
+
scrollToCoordinates,
|
|
1576
|
+
setSingleRange,
|
|
1577
|
+
onEditingChangeHandler
|
|
1578
|
+
]
|
|
1579
|
+
);
|
|
1580
|
+
const handleEditOnEnter = useCallback9(
|
|
1581
|
+
(anchor2) => {
|
|
1582
|
+
const input = queryTool?.getInput(anchor2);
|
|
1583
|
+
if (!input) {
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
input.focus();
|
|
1587
|
+
onEditingChangeHandler(true);
|
|
1588
|
+
},
|
|
1589
|
+
[queryTool, onEditingChangeHandler]
|
|
1590
|
+
);
|
|
1591
|
+
const handleEnterKeyTextOrNumber = useCallback9(
|
|
1592
|
+
(e, anchor2) => {
|
|
1593
|
+
if (isEditing) {
|
|
1594
|
+
handleMoveOnEnter(e, anchor2);
|
|
1595
|
+
return;
|
|
1596
|
+
}
|
|
1597
|
+
handleEditOnEnter(anchor2);
|
|
1598
|
+
},
|
|
1599
|
+
[handleMoveOnEnter, handleEditOnEnter, isEditing]
|
|
1600
|
+
);
|
|
1601
|
+
const handleEnterKeyMultilineText = useCallback9(
|
|
1602
|
+
(e, anchor2) => {
|
|
1603
|
+
if (isEditing) {
|
|
1604
|
+
if (e.shiftKey) {
|
|
1605
|
+
return;
|
|
1606
|
+
}
|
|
1607
|
+
handleMoveOnEnter(e, anchor2);
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
handleEditOnEnter(anchor2);
|
|
1611
|
+
},
|
|
1612
|
+
[handleMoveOnEnter, handleEditOnEnter, isEditing]
|
|
1613
|
+
);
|
|
1614
|
+
const handleEnterKeyBoolean = useCallback9(
|
|
1615
|
+
(e, anchor2) => {
|
|
1616
|
+
const field = matrix.getCellField(anchor2);
|
|
1617
|
+
if (!field) {
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
const current = getValues(field);
|
|
1621
|
+
let next;
|
|
1622
|
+
if (typeof current === "boolean") {
|
|
1623
|
+
next = !current;
|
|
1624
|
+
} else {
|
|
1625
|
+
next = true;
|
|
1626
|
+
}
|
|
1627
|
+
const command = new DataGridUpdateCommand({
|
|
1628
|
+
next,
|
|
1629
|
+
prev: current,
|
|
1630
|
+
setter: (value) => {
|
|
1631
|
+
setValue2(field, value, {
|
|
1632
|
+
shouldDirty: true,
|
|
1633
|
+
shouldTouch: true
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
execute(command);
|
|
1638
|
+
handleMoveOnEnter(e, anchor2);
|
|
1639
|
+
},
|
|
1640
|
+
[execute, getValues, handleMoveOnEnter, matrix, setValue2]
|
|
1641
|
+
);
|
|
1642
|
+
const handleEnterKey = useCallback9(
|
|
1643
|
+
(e) => {
|
|
1644
|
+
if (!anchor) {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
const type = matrix.getCellType(anchor);
|
|
1648
|
+
if (type === "multiline-text" && isEditing && e.shiftKey) {
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
e.preventDefault();
|
|
1652
|
+
switch (type) {
|
|
1653
|
+
case "multiline-text":
|
|
1654
|
+
handleEnterKeyMultilineText(e, anchor);
|
|
1655
|
+
break;
|
|
1656
|
+
case "togglable-number":
|
|
1657
|
+
case "text":
|
|
1658
|
+
case "number":
|
|
1659
|
+
handleEnterKeyTextOrNumber(e, anchor);
|
|
1660
|
+
break;
|
|
1661
|
+
case "boolean": {
|
|
1662
|
+
handleEnterKeyBoolean(e, anchor);
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
[
|
|
1668
|
+
anchor,
|
|
1669
|
+
matrix,
|
|
1670
|
+
isEditing,
|
|
1671
|
+
handleEnterKeyTextOrNumber,
|
|
1672
|
+
handleEnterKeyBoolean,
|
|
1673
|
+
handleEnterKeyMultilineText
|
|
1674
|
+
]
|
|
1675
|
+
);
|
|
1676
|
+
const handleDeleteKeyTogglableNumber = useCallback9(
|
|
1677
|
+
(anchor2, rangeEnd2) => {
|
|
1678
|
+
const fields = matrix.getFieldsInSelection(anchor2, rangeEnd2);
|
|
1679
|
+
const prev = getSelectionValues(fields);
|
|
1680
|
+
const next = prev.map((value) => ({
|
|
1681
|
+
...value,
|
|
1682
|
+
quantity: "",
|
|
1683
|
+
checked: value.disableToggle ? value.checked : false
|
|
1684
|
+
}));
|
|
1685
|
+
const command = new DataGridBulkUpdateCommand({
|
|
1686
|
+
fields,
|
|
1687
|
+
next,
|
|
1688
|
+
prev,
|
|
1689
|
+
setter: setSelectionValues
|
|
1690
|
+
});
|
|
1691
|
+
execute(command);
|
|
1692
|
+
},
|
|
1693
|
+
[matrix, getSelectionValues, setSelectionValues, execute]
|
|
1694
|
+
);
|
|
1695
|
+
const handleDeleteKeyTextOrNumber = useCallback9(
|
|
1696
|
+
(anchor2, rangeEnd2) => {
|
|
1697
|
+
const fields = matrix.getFieldsInSelection(anchor2, rangeEnd2);
|
|
1698
|
+
const prev = getSelectionValues(fields);
|
|
1699
|
+
const next = Array.from({ length: prev.length }, () => "");
|
|
1700
|
+
const command = new DataGridBulkUpdateCommand({
|
|
1701
|
+
fields,
|
|
1702
|
+
next,
|
|
1703
|
+
prev,
|
|
1704
|
+
setter: setSelectionValues
|
|
1705
|
+
});
|
|
1706
|
+
execute(command);
|
|
1707
|
+
},
|
|
1708
|
+
[matrix, getSelectionValues, setSelectionValues, execute]
|
|
1709
|
+
);
|
|
1710
|
+
const handleDeleteKeyBoolean = useCallback9(
|
|
1711
|
+
(anchor2, rangeEnd2) => {
|
|
1712
|
+
const fields = matrix.getFieldsInSelection(anchor2, rangeEnd2);
|
|
1713
|
+
const prev = getSelectionValues(fields);
|
|
1714
|
+
const next = Array.from({ length: prev.length }, () => false);
|
|
1715
|
+
const command = new DataGridBulkUpdateCommand({
|
|
1716
|
+
fields,
|
|
1717
|
+
next,
|
|
1718
|
+
prev,
|
|
1719
|
+
setter: setSelectionValues
|
|
1720
|
+
});
|
|
1721
|
+
execute(command);
|
|
1722
|
+
},
|
|
1723
|
+
[execute, getSelectionValues, matrix, setSelectionValues]
|
|
1724
|
+
);
|
|
1725
|
+
const handleDeleteKey = useCallback9(
|
|
1726
|
+
(e) => {
|
|
1727
|
+
if (!anchor || !rangeEnd || isEditing) {
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
e.preventDefault();
|
|
1731
|
+
const type = matrix.getCellType(anchor);
|
|
1732
|
+
if (!type) {
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
switch (type) {
|
|
1736
|
+
case "text":
|
|
1737
|
+
case "multiline-text":
|
|
1738
|
+
case "number":
|
|
1739
|
+
handleDeleteKeyTextOrNumber(anchor, rangeEnd);
|
|
1740
|
+
break;
|
|
1741
|
+
case "boolean":
|
|
1742
|
+
handleDeleteKeyBoolean(anchor, rangeEnd);
|
|
1743
|
+
break;
|
|
1744
|
+
case "togglable-number":
|
|
1745
|
+
handleDeleteKeyTogglableNumber(anchor, rangeEnd);
|
|
1746
|
+
break;
|
|
1747
|
+
}
|
|
1748
|
+
},
|
|
1749
|
+
[
|
|
1750
|
+
anchor,
|
|
1751
|
+
rangeEnd,
|
|
1752
|
+
isEditing,
|
|
1753
|
+
matrix,
|
|
1754
|
+
handleDeleteKeyTextOrNumber,
|
|
1755
|
+
handleDeleteKeyBoolean,
|
|
1756
|
+
handleDeleteKeyTogglableNumber
|
|
1757
|
+
]
|
|
1758
|
+
);
|
|
1759
|
+
const handleEscapeKey = useCallback9(
|
|
1760
|
+
(e) => {
|
|
1761
|
+
if (!anchor || !isEditing) {
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
e.preventDefault();
|
|
1765
|
+
e.stopPropagation();
|
|
1766
|
+
restoreSnapshot();
|
|
1767
|
+
const container = queryTool?.getContainer(anchor);
|
|
1768
|
+
container?.focus();
|
|
1769
|
+
},
|
|
1770
|
+
[queryTool, isEditing, anchor, restoreSnapshot]
|
|
1771
|
+
);
|
|
1772
|
+
const handleSpecialFocusKeys = useCallback9(
|
|
1773
|
+
(e) => {
|
|
1774
|
+
if (!containerRef || isEditing) {
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
const focusableElements = getFocusableElements(containerRef);
|
|
1778
|
+
const focusElement = (element) => {
|
|
1779
|
+
if (element) {
|
|
1780
|
+
setTrapActive(false);
|
|
1781
|
+
element.focus();
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
switch (e.key) {
|
|
1785
|
+
case ".":
|
|
1786
|
+
focusElement(focusableElements.cancel);
|
|
1787
|
+
break;
|
|
1788
|
+
case ",":
|
|
1789
|
+
focusElement(focusableElements.shortcuts);
|
|
1790
|
+
break;
|
|
1791
|
+
default:
|
|
1792
|
+
break;
|
|
1793
|
+
}
|
|
1794
|
+
},
|
|
1795
|
+
[isEditing, setTrapActive, containerRef]
|
|
1796
|
+
);
|
|
1797
|
+
const handleKeyDownEvent = useCallback9(
|
|
1798
|
+
(e) => {
|
|
1799
|
+
if (ARROW_KEYS.includes(e.key)) {
|
|
1800
|
+
handleKeyboardNavigation(e);
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
if (e.key === "z" && (e.metaKey || e.ctrlKey)) {
|
|
1804
|
+
handleUndo(e);
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
if (e.key === " ") {
|
|
1808
|
+
handleSpaceKey(e);
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
1812
|
+
handleDeleteKey(e);
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
if (e.key === "Enter") {
|
|
1816
|
+
handleEnterKey(e);
|
|
1817
|
+
return;
|
|
1818
|
+
}
|
|
1819
|
+
if (e.key === "Escape") {
|
|
1820
|
+
handleEscapeKey(e);
|
|
1821
|
+
return;
|
|
1822
|
+
}
|
|
1823
|
+
if (e.key === "Tab") {
|
|
1824
|
+
handleTabKey(e);
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1827
|
+
},
|
|
1828
|
+
[
|
|
1829
|
+
handleEscapeKey,
|
|
1830
|
+
handleKeyboardNavigation,
|
|
1831
|
+
handleUndo,
|
|
1832
|
+
handleSpaceKey,
|
|
1833
|
+
handleEnterKey,
|
|
1834
|
+
handleDeleteKey,
|
|
1835
|
+
handleTabKey
|
|
1836
|
+
]
|
|
1837
|
+
);
|
|
1838
|
+
return {
|
|
1839
|
+
handleKeyDownEvent,
|
|
1840
|
+
handleSpecialFocusKeys
|
|
1841
|
+
};
|
|
1842
|
+
};
|
|
1843
|
+
function getFocusableElements(ref) {
|
|
1844
|
+
const focusableElements = Array.from(
|
|
1845
|
+
document.querySelectorAll(
|
|
1846
|
+
"[tabindex], a, button, input, select, textarea"
|
|
1847
|
+
)
|
|
1848
|
+
);
|
|
1849
|
+
const currentElementIndex = focusableElements.indexOf(ref.current);
|
|
1850
|
+
const shortcuts = currentElementIndex > 0 ? focusableElements[currentElementIndex - 1] : null;
|
|
1851
|
+
let cancel = null;
|
|
1852
|
+
for (let i = currentElementIndex + 1; i < focusableElements.length; i++) {
|
|
1853
|
+
if (!ref.current.contains(focusableElements[i])) {
|
|
1854
|
+
cancel = focusableElements[i];
|
|
1855
|
+
break;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
return { shortcuts, cancel };
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// src/components/data-grid/hooks/use-data-grid-mouse-up-event.tsx
|
|
1862
|
+
import { useCallback as useCallback10 } from "react";
|
|
1863
|
+
var useDataGridMouseUpEvent = ({
|
|
1864
|
+
matrix,
|
|
1865
|
+
anchor,
|
|
1866
|
+
dragEnd,
|
|
1867
|
+
setDragEnd,
|
|
1868
|
+
isDragging,
|
|
1869
|
+
setIsDragging,
|
|
1870
|
+
setRangeEnd,
|
|
1871
|
+
setIsSelecting,
|
|
1872
|
+
getSelectionValues,
|
|
1873
|
+
setSelectionValues,
|
|
1874
|
+
execute
|
|
1875
|
+
}) => {
|
|
1876
|
+
const handleDragEnd = useCallback10(() => {
|
|
1877
|
+
if (!isDragging) {
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
if (!anchor || !dragEnd) {
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
const dragSelection = matrix.getFieldsInSelection(anchor, dragEnd);
|
|
1884
|
+
const anchorField = matrix.getCellField(anchor);
|
|
1885
|
+
if (!anchorField || !dragSelection.length) {
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
const anchorValue = getSelectionValues([anchorField]);
|
|
1889
|
+
const fields = dragSelection.filter((field) => field !== anchorField);
|
|
1890
|
+
const prev = getSelectionValues(fields);
|
|
1891
|
+
const next = Array.from({ length: prev.length }, () => anchorValue[0]);
|
|
1892
|
+
const command = new DataGridBulkUpdateCommand({
|
|
1893
|
+
fields,
|
|
1894
|
+
prev,
|
|
1895
|
+
next,
|
|
1896
|
+
setter: setSelectionValues
|
|
1897
|
+
});
|
|
1898
|
+
execute(command);
|
|
1899
|
+
setIsDragging(false);
|
|
1900
|
+
setDragEnd(null);
|
|
1901
|
+
setRangeEnd(dragEnd);
|
|
1902
|
+
}, [
|
|
1903
|
+
isDragging,
|
|
1904
|
+
anchor,
|
|
1905
|
+
dragEnd,
|
|
1906
|
+
matrix,
|
|
1907
|
+
getSelectionValues,
|
|
1908
|
+
setSelectionValues,
|
|
1909
|
+
execute,
|
|
1910
|
+
setIsDragging,
|
|
1911
|
+
setDragEnd,
|
|
1912
|
+
setRangeEnd
|
|
1913
|
+
]);
|
|
1914
|
+
const handleMouseUpEvent = useCallback10(() => {
|
|
1915
|
+
handleDragEnd();
|
|
1916
|
+
setIsSelecting(false);
|
|
1917
|
+
}, [handleDragEnd, setIsSelecting]);
|
|
1918
|
+
return {
|
|
1919
|
+
handleMouseUpEvent
|
|
1920
|
+
};
|
|
1921
|
+
};
|
|
1922
|
+
|
|
1923
|
+
// src/components/data-grid/hooks/use-data-grid-navigation.tsx
|
|
1924
|
+
import { useCallback as useCallback11 } from "react";
|
|
1925
|
+
var useDataGridNavigation = ({
|
|
1926
|
+
matrix,
|
|
1927
|
+
anchor,
|
|
1928
|
+
visibleColumns,
|
|
1929
|
+
visibleRows,
|
|
1930
|
+
columnVirtualizer,
|
|
1931
|
+
rowVirtualizer,
|
|
1932
|
+
setColumnVisibility,
|
|
1933
|
+
flatColumns,
|
|
1934
|
+
queryTool,
|
|
1935
|
+
setSingleRange
|
|
1936
|
+
}) => {
|
|
1937
|
+
const scrollToCoordinates = useCallback11(
|
|
1938
|
+
(coords, direction) => {
|
|
1939
|
+
if (!anchor) {
|
|
1940
|
+
return;
|
|
1941
|
+
}
|
|
1942
|
+
const { row, col } = coords;
|
|
1943
|
+
const { row: anchorRow, col: anchorCol } = anchor;
|
|
1944
|
+
const rowDirection = row >= anchorRow ? "down" : "up";
|
|
1945
|
+
const colDirection = col >= anchorCol ? "right" : "left";
|
|
1946
|
+
let toRow = rowDirection === "down" ? row + 1 : row - 1;
|
|
1947
|
+
if (visibleRows[toRow] === void 0) {
|
|
1948
|
+
toRow = row;
|
|
1949
|
+
}
|
|
1950
|
+
let toCol = colDirection === "right" ? col + 1 : col - 1;
|
|
1951
|
+
if (visibleColumns[toCol] === void 0) {
|
|
1952
|
+
toCol = col;
|
|
1953
|
+
}
|
|
1954
|
+
const scrollOptions = { align: "auto", behavior: "auto" };
|
|
1955
|
+
if (direction === "horizontal" || direction === "both") {
|
|
1956
|
+
columnVirtualizer.scrollToIndex(toCol, scrollOptions);
|
|
1957
|
+
}
|
|
1958
|
+
if (direction === "vertical" || direction === "both") {
|
|
1959
|
+
rowVirtualizer.scrollToIndex(toRow, scrollOptions);
|
|
1960
|
+
}
|
|
1961
|
+
},
|
|
1962
|
+
[anchor, columnVirtualizer, visibleRows, rowVirtualizer, visibleColumns]
|
|
1963
|
+
);
|
|
1964
|
+
const navigateToField = useCallback11(
|
|
1965
|
+
(field) => {
|
|
1966
|
+
const coords = matrix.getCoordinatesByField(field);
|
|
1967
|
+
if (!coords) {
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
const column = flatColumns[coords.col];
|
|
1971
|
+
setColumnVisibility((prev) => {
|
|
1972
|
+
return {
|
|
1973
|
+
...prev,
|
|
1974
|
+
[column.id]: true
|
|
1975
|
+
};
|
|
1976
|
+
});
|
|
1977
|
+
requestAnimationFrame(() => {
|
|
1978
|
+
scrollToCoordinates(coords, "both");
|
|
1979
|
+
setSingleRange(coords);
|
|
1980
|
+
});
|
|
1981
|
+
requestAnimationFrame(() => {
|
|
1982
|
+
const input = queryTool?.getInput(coords);
|
|
1983
|
+
if (input) {
|
|
1984
|
+
input.focus();
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
},
|
|
1988
|
+
[
|
|
1989
|
+
matrix,
|
|
1990
|
+
flatColumns,
|
|
1991
|
+
setColumnVisibility,
|
|
1992
|
+
scrollToCoordinates,
|
|
1993
|
+
setSingleRange,
|
|
1994
|
+
queryTool
|
|
1995
|
+
]
|
|
1996
|
+
);
|
|
1997
|
+
return {
|
|
1998
|
+
scrollToCoordinates,
|
|
1999
|
+
navigateToField
|
|
2000
|
+
};
|
|
2001
|
+
};
|
|
2002
|
+
|
|
2003
|
+
// src/components/data-grid/hooks/use-data-grid-query-tool.tsx
|
|
2004
|
+
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
2005
|
+
var useDataGridQueryTool = (containerRef) => {
|
|
2006
|
+
const queryToolRef = useRef2(null);
|
|
2007
|
+
useEffect2(() => {
|
|
2008
|
+
if (containerRef.current) {
|
|
2009
|
+
queryToolRef.current = new DataGridQueryTool(containerRef.current);
|
|
2010
|
+
}
|
|
2011
|
+
}, [containerRef]);
|
|
2012
|
+
return queryToolRef.current;
|
|
2013
|
+
};
|
|
2014
|
+
|
|
2015
|
+
// src/components/data-grid/components/data-grid-cell-container.tsx
|
|
2016
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
2017
|
+
import { ExclamationCircle } from "@medusajs/icons";
|
|
2018
|
+
import { Tooltip as Tooltip2, clx } from "@medusajs/ui";
|
|
2019
|
+
import { get as get2 } from "react-hook-form";
|
|
2020
|
+
|
|
2021
|
+
// src/components/data-grid/components/data-grid-row-error-indicator.tsx
|
|
2022
|
+
import { Badge, Tooltip } from "@medusajs/ui";
|
|
2023
|
+
import { useTranslation } from "react-i18next";
|
|
2024
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2025
|
+
var DataGridRowErrorIndicator = ({
|
|
2026
|
+
rowErrors
|
|
2027
|
+
}) => {
|
|
2028
|
+
const rowErrorCount = rowErrors ? rowErrors.length : 0;
|
|
2029
|
+
if (!rowErrors || rowErrorCount <= 0) {
|
|
2030
|
+
return null;
|
|
2031
|
+
}
|
|
2032
|
+
return /* @__PURE__ */ jsx2(
|
|
2033
|
+
Tooltip,
|
|
2034
|
+
{
|
|
2035
|
+
content: /* @__PURE__ */ jsx2("ul", { className: "flex flex-col gap-y-3", children: rowErrors.map((error, index) => /* @__PURE__ */ jsx2(DataGridRowErrorLine, { error }, index)) }),
|
|
2036
|
+
delayDuration: 0,
|
|
2037
|
+
children: /* @__PURE__ */ jsx2(Badge, { color: "red", size: "2xsmall", className: "cursor-default", children: rowErrorCount })
|
|
2038
|
+
}
|
|
2039
|
+
);
|
|
2040
|
+
};
|
|
2041
|
+
var DataGridRowErrorLine = ({
|
|
2042
|
+
error
|
|
2043
|
+
}) => {
|
|
2044
|
+
const { t } = useTranslation();
|
|
2045
|
+
return /* @__PURE__ */ jsxs2("li", { className: "txt-compact-small flex flex-col items-start", children: [
|
|
2046
|
+
error.message,
|
|
2047
|
+
/* @__PURE__ */ jsx2(
|
|
2048
|
+
"button",
|
|
2049
|
+
{
|
|
2050
|
+
type: "button",
|
|
2051
|
+
onClick: error.to,
|
|
2052
|
+
className: "text-ui-fg-interactive hover:text-ui-fg-interactive-hover transition-fg",
|
|
2053
|
+
children: t("dataGrid.errors.fixError")
|
|
2054
|
+
}
|
|
2055
|
+
)
|
|
2056
|
+
] });
|
|
2057
|
+
};
|
|
2058
|
+
|
|
2059
|
+
// src/components/data-grid/components/data-grid-cell-container.tsx
|
|
2060
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2061
|
+
var DataGridCellContainer = ({
|
|
2062
|
+
isAnchor,
|
|
2063
|
+
isSelected,
|
|
2064
|
+
isDragSelected,
|
|
2065
|
+
field,
|
|
2066
|
+
showOverlay,
|
|
2067
|
+
placeholder,
|
|
2068
|
+
innerProps,
|
|
2069
|
+
overlayProps,
|
|
2070
|
+
children,
|
|
2071
|
+
errors,
|
|
2072
|
+
rowErrors,
|
|
2073
|
+
outerComponent,
|
|
2074
|
+
isMultiLine
|
|
2075
|
+
}) => {
|
|
2076
|
+
const error = get2(errors, field);
|
|
2077
|
+
const hasError = !!error;
|
|
2078
|
+
return /* @__PURE__ */ jsxs3("div", { className: clx("group/container relative h-full w-full"), children: [
|
|
2079
|
+
/* @__PURE__ */ jsxs3(
|
|
2080
|
+
"div",
|
|
2081
|
+
{
|
|
2082
|
+
className: clx(
|
|
2083
|
+
"bg-ui-bg-base group/cell relative flex h-full w-full gap-x-2 px-4 py-2.5 outline-none",
|
|
2084
|
+
{
|
|
2085
|
+
"items-center": !isMultiLine,
|
|
2086
|
+
"items-start": isMultiLine,
|
|
2087
|
+
"bg-ui-tag-red-bg text-ui-tag-red-text": hasError && !isAnchor && !isSelected && !isDragSelected,
|
|
2088
|
+
"ring-ui-bg-interactive ring-2 ring-inset": isAnchor,
|
|
2089
|
+
"bg-ui-bg-highlight [&:has([data-field]:focus)]:bg-ui-bg-base": isSelected || isAnchor,
|
|
2090
|
+
"bg-ui-bg-subtle": isDragSelected && !isAnchor
|
|
2091
|
+
}
|
|
2092
|
+
),
|
|
2093
|
+
tabIndex: -1,
|
|
2094
|
+
...innerProps,
|
|
2095
|
+
children: [
|
|
2096
|
+
/* @__PURE__ */ jsx3(
|
|
2097
|
+
ErrorMessage,
|
|
2098
|
+
{
|
|
2099
|
+
name: field,
|
|
2100
|
+
errors,
|
|
2101
|
+
render: ({ message }) => {
|
|
2102
|
+
return /* @__PURE__ */ jsx3("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ jsx3(Tooltip2, { content: message, delayDuration: 0, children: /* @__PURE__ */ jsx3(ExclamationCircle, { className: "text-ui-tag-red-icon z-[3]" }) }) });
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
),
|
|
2106
|
+
/* @__PURE__ */ jsx3(
|
|
2107
|
+
"div",
|
|
2108
|
+
{
|
|
2109
|
+
className: clx("relative z-[1] flex h-full w-full", {
|
|
2110
|
+
"items-center justify-center": !isMultiLine,
|
|
2111
|
+
"items-start": isMultiLine
|
|
2112
|
+
}),
|
|
2113
|
+
children: /* @__PURE__ */ jsx3(RenderChildren, { isAnchor, placeholder, children })
|
|
2114
|
+
}
|
|
2115
|
+
),
|
|
2116
|
+
/* @__PURE__ */ jsx3(DataGridRowErrorIndicator, { rowErrors }),
|
|
2117
|
+
showOverlay && /* @__PURE__ */ jsx3(
|
|
2118
|
+
"div",
|
|
2119
|
+
{
|
|
2120
|
+
...overlayProps,
|
|
2121
|
+
"data-cell-overlay": "true",
|
|
2122
|
+
className: "absolute inset-0 z-[2]"
|
|
2123
|
+
}
|
|
2124
|
+
)
|
|
2125
|
+
]
|
|
2126
|
+
}
|
|
2127
|
+
),
|
|
2128
|
+
outerComponent
|
|
2129
|
+
] });
|
|
2130
|
+
};
|
|
2131
|
+
var RenderChildren = ({
|
|
2132
|
+
isAnchor,
|
|
2133
|
+
placeholder,
|
|
2134
|
+
children
|
|
2135
|
+
}) => {
|
|
2136
|
+
if (!isAnchor && placeholder) {
|
|
2137
|
+
return placeholder;
|
|
2138
|
+
}
|
|
2139
|
+
return children;
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
// src/components/data-grid/components/data-grid-boolean-cell.tsx
|
|
2143
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
2144
|
+
var DataGridBooleanCell = ({
|
|
2145
|
+
context,
|
|
2146
|
+
disabled
|
|
2147
|
+
}) => {
|
|
2148
|
+
const { field, control, renderProps } = useDataGridCell({
|
|
2149
|
+
context
|
|
2150
|
+
});
|
|
2151
|
+
const errorProps = useDataGridCellError({ context });
|
|
2152
|
+
const { container, input } = renderProps;
|
|
2153
|
+
return /* @__PURE__ */ jsx4(
|
|
2154
|
+
Controller,
|
|
2155
|
+
{
|
|
2156
|
+
control,
|
|
2157
|
+
name: field,
|
|
2158
|
+
render: ({ field: field2 }) => {
|
|
2159
|
+
return /* @__PURE__ */ jsx4(DataGridCellContainer, { ...container, ...errorProps, children: /* @__PURE__ */ jsx4(Inner, { field: field2, inputProps: input, disabled }) });
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
);
|
|
2163
|
+
};
|
|
2164
|
+
var Inner = ({
|
|
2165
|
+
field,
|
|
2166
|
+
inputProps,
|
|
2167
|
+
disabled
|
|
2168
|
+
}) => {
|
|
2169
|
+
const { ref, value, onBlur, name, disabled: fieldDisabled } = field;
|
|
2170
|
+
const {
|
|
2171
|
+
ref: inputRef,
|
|
2172
|
+
onBlur: onInputBlur,
|
|
2173
|
+
onChange,
|
|
2174
|
+
onFocus,
|
|
2175
|
+
...attributes
|
|
2176
|
+
} = inputProps;
|
|
2177
|
+
const combinedRefs = useCombinedRefs(ref, inputRef);
|
|
2178
|
+
return /* @__PURE__ */ jsx4(
|
|
2179
|
+
Checkbox,
|
|
2180
|
+
{
|
|
2181
|
+
disabled: disabled || fieldDisabled,
|
|
2182
|
+
name,
|
|
2183
|
+
checked: value,
|
|
2184
|
+
onCheckedChange: (newValue) => onChange(newValue === true, value),
|
|
2185
|
+
onFocus,
|
|
2186
|
+
onBlur: () => {
|
|
2187
|
+
onBlur();
|
|
2188
|
+
onInputBlur();
|
|
2189
|
+
},
|
|
2190
|
+
ref: combinedRefs,
|
|
2191
|
+
tabIndex: -1,
|
|
2192
|
+
...attributes
|
|
2193
|
+
}
|
|
2194
|
+
);
|
|
2195
|
+
};
|
|
2196
|
+
|
|
2197
|
+
// src/components/data-grid/components/data-grid-currency-cell.tsx
|
|
2198
|
+
import CurrencyInput, {
|
|
2199
|
+
formatValue
|
|
2200
|
+
} from "react-currency-input-field";
|
|
2201
|
+
import { Controller as Controller2 } from "react-hook-form";
|
|
2202
|
+
import { useCallback as useCallback12, useEffect as useEffect3, useState as useState4 } from "react";
|
|
2203
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
2204
|
+
var DataGridCurrencyCell = ({
|
|
2205
|
+
context,
|
|
2206
|
+
code
|
|
2207
|
+
}) => {
|
|
2208
|
+
const { field, control, renderProps } = useDataGridCell({
|
|
2209
|
+
context
|
|
2210
|
+
});
|
|
2211
|
+
const errorProps = useDataGridCellError({ context });
|
|
2212
|
+
const { container, input } = renderProps;
|
|
2213
|
+
const currency = currencies[code.toUpperCase()];
|
|
2214
|
+
return /* @__PURE__ */ jsx5(
|
|
2215
|
+
Controller2,
|
|
2216
|
+
{
|
|
2217
|
+
control,
|
|
2218
|
+
name: field,
|
|
2219
|
+
render: ({ field: field2 }) => {
|
|
2220
|
+
return /* @__PURE__ */ jsx5(DataGridCellContainer, { ...container, ...errorProps, children: /* @__PURE__ */ jsx5(Inner2, { field: field2, inputProps: input, currencyInfo: currency }) });
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
);
|
|
2224
|
+
};
|
|
2225
|
+
var Inner2 = ({
|
|
2226
|
+
field,
|
|
2227
|
+
inputProps,
|
|
2228
|
+
currencyInfo
|
|
2229
|
+
}) => {
|
|
2230
|
+
const { value, onChange: _, onBlur, ref, ...rest } = field;
|
|
2231
|
+
const {
|
|
2232
|
+
ref: inputRef,
|
|
2233
|
+
onBlur: onInputBlur,
|
|
2234
|
+
onFocus,
|
|
2235
|
+
onChange,
|
|
2236
|
+
...attributes
|
|
2237
|
+
} = inputProps;
|
|
2238
|
+
const formatter = useCallback12(
|
|
2239
|
+
(value2) => {
|
|
2240
|
+
const ensuredValue = typeof value2 === "number" ? value2.toString() : value2 || "";
|
|
2241
|
+
return formatValue({
|
|
2242
|
+
value: ensuredValue,
|
|
2243
|
+
decimalScale: currencyInfo.decimal_digits,
|
|
2244
|
+
disableGroupSeparators: true,
|
|
2245
|
+
decimalSeparator: "."
|
|
2246
|
+
});
|
|
2247
|
+
},
|
|
2248
|
+
[currencyInfo]
|
|
2249
|
+
);
|
|
2250
|
+
const [localValue, setLocalValue] = useState4(value || "");
|
|
2251
|
+
const handleValueChange = (value2, _name, _values) => {
|
|
2252
|
+
if (!value2) {
|
|
2253
|
+
setLocalValue("");
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
setLocalValue(value2);
|
|
2257
|
+
};
|
|
2258
|
+
useEffect3(() => {
|
|
2259
|
+
let update = value;
|
|
2260
|
+
if (!isNaN(Number(value))) {
|
|
2261
|
+
update = formatter(update);
|
|
2262
|
+
}
|
|
2263
|
+
setLocalValue(update);
|
|
2264
|
+
}, [value, formatter]);
|
|
2265
|
+
const combinedRed = useCombinedRefs(inputRef, ref);
|
|
2266
|
+
return /* @__PURE__ */ jsxs4("div", { className: "relative flex size-full items-center", children: [
|
|
2267
|
+
/* @__PURE__ */ jsx5(
|
|
2268
|
+
"span",
|
|
2269
|
+
{
|
|
2270
|
+
className: "txt-compact-small text-ui-fg-muted pointer-events-none absolute left-0 w-fit min-w-4",
|
|
2271
|
+
"aria-hidden": true,
|
|
2272
|
+
children: currencyInfo.symbol_native
|
|
2273
|
+
}
|
|
2274
|
+
),
|
|
2275
|
+
/* @__PURE__ */ jsx5(
|
|
2276
|
+
CurrencyInput,
|
|
2277
|
+
{
|
|
2278
|
+
...rest,
|
|
2279
|
+
...attributes,
|
|
2280
|
+
ref: combinedRed,
|
|
2281
|
+
className: "txt-compact-small w-full flex-1 cursor-default appearance-none bg-transparent pl-8 text-right outline-none",
|
|
2282
|
+
value: localValue || void 0,
|
|
2283
|
+
onValueChange: handleValueChange,
|
|
2284
|
+
formatValueOnBlur: true,
|
|
2285
|
+
onBlur: () => {
|
|
2286
|
+
onBlur();
|
|
2287
|
+
onInputBlur();
|
|
2288
|
+
onChange(localValue, value);
|
|
2289
|
+
},
|
|
2290
|
+
onFocus,
|
|
2291
|
+
decimalScale: currencyInfo.decimal_digits,
|
|
2292
|
+
decimalsLimit: currencyInfo.decimal_digits,
|
|
2293
|
+
autoComplete: "off",
|
|
2294
|
+
tabIndex: -1
|
|
2295
|
+
}
|
|
2296
|
+
)
|
|
2297
|
+
] });
|
|
2298
|
+
};
|
|
2299
|
+
|
|
2300
|
+
// src/components/data-grid/components/data-grid-multiline-cell.tsx
|
|
2301
|
+
import { clx as clx2 } from "@medusajs/ui";
|
|
2302
|
+
import { useCallback as useCallback13, useEffect as useEffect4, useRef as useRef3, useState as useState5 } from "react";
|
|
2303
|
+
import { Controller as Controller3 } from "react-hook-form";
|
|
2304
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
2305
|
+
var DataGridMultilineCell = ({
|
|
2306
|
+
context
|
|
2307
|
+
}) => {
|
|
2308
|
+
const { field, control, renderProps } = useDataGridCell({
|
|
2309
|
+
context
|
|
2310
|
+
});
|
|
2311
|
+
const errorProps = useDataGridCellError({ context });
|
|
2312
|
+
const { container, input } = renderProps;
|
|
2313
|
+
return /* @__PURE__ */ jsx6(
|
|
2314
|
+
Controller3,
|
|
2315
|
+
{
|
|
2316
|
+
control,
|
|
2317
|
+
name: field,
|
|
2318
|
+
render: ({ field: field2 }) => {
|
|
2319
|
+
return /* @__PURE__ */ jsx6(DataGridCellContainer, { ...container, ...errorProps, isMultiLine: true, children: /* @__PURE__ */ jsx6(Inner3, { field: field2, inputProps: input }) });
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
);
|
|
2323
|
+
};
|
|
2324
|
+
var Inner3 = ({
|
|
2325
|
+
field,
|
|
2326
|
+
inputProps
|
|
2327
|
+
}) => {
|
|
2328
|
+
const { onChange: _, onBlur, ref, value, ...rest } = field;
|
|
2329
|
+
const { ref: inputRef, onBlur: onInputBlur, onChange, ...input } = inputProps;
|
|
2330
|
+
const [localValue, setLocalValue] = useState5(value);
|
|
2331
|
+
const textareaRef = useRef3(null);
|
|
2332
|
+
useEffect4(() => {
|
|
2333
|
+
setLocalValue(value);
|
|
2334
|
+
}, [value]);
|
|
2335
|
+
const combinedRefs = useCombinedRefs(inputRef, ref, textareaRef);
|
|
2336
|
+
const adjustTextareaHeight = useCallback13(() => {
|
|
2337
|
+
const textarea = textareaRef.current;
|
|
2338
|
+
if (textarea) {
|
|
2339
|
+
textarea.style.height = "0px";
|
|
2340
|
+
const newHeight = Math.max(textarea.scrollHeight, 24);
|
|
2341
|
+
textarea.style.height = `${newHeight}px`;
|
|
2342
|
+
}
|
|
2343
|
+
}, []);
|
|
2344
|
+
useEffect4(() => {
|
|
2345
|
+
adjustTextareaHeight();
|
|
2346
|
+
}, [localValue, adjustTextareaHeight]);
|
|
2347
|
+
useEffect4(() => {
|
|
2348
|
+
adjustTextareaHeight();
|
|
2349
|
+
const timeoutId = setTimeout(adjustTextareaHeight, 50);
|
|
2350
|
+
return () => clearTimeout(timeoutId);
|
|
2351
|
+
}, [adjustTextareaHeight]);
|
|
2352
|
+
return /* @__PURE__ */ jsx6(
|
|
2353
|
+
"textarea",
|
|
2354
|
+
{
|
|
2355
|
+
className: clx2(
|
|
2356
|
+
"txt-compact-small text-ui-fg-subtle flex w-full cursor-pointer bg-transparent outline-none",
|
|
2357
|
+
"focus:cursor-text",
|
|
2358
|
+
"resize-none overflow-hidden py-2"
|
|
2359
|
+
),
|
|
2360
|
+
autoComplete: "off",
|
|
2361
|
+
tabIndex: -1,
|
|
2362
|
+
value: localValue ?? "",
|
|
2363
|
+
onChange: (e) => {
|
|
2364
|
+
setLocalValue(e.target.value);
|
|
2365
|
+
adjustTextareaHeight();
|
|
2366
|
+
},
|
|
2367
|
+
ref: combinedRefs,
|
|
2368
|
+
onBlur: () => {
|
|
2369
|
+
onBlur();
|
|
2370
|
+
onInputBlur();
|
|
2371
|
+
onChange(localValue, value);
|
|
2372
|
+
},
|
|
2373
|
+
...input,
|
|
2374
|
+
...rest
|
|
2375
|
+
}
|
|
2376
|
+
);
|
|
2377
|
+
};
|
|
2378
|
+
|
|
2379
|
+
// src/components/data-grid/components/data-grid-number-cell.tsx
|
|
2380
|
+
import { clx as clx3 } from "@medusajs/ui";
|
|
2381
|
+
import { useEffect as useEffect5, useState as useState6 } from "react";
|
|
2382
|
+
import { Controller as Controller4 } from "react-hook-form";
|
|
2383
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
2384
|
+
var DataGridNumberCell = ({
|
|
2385
|
+
context,
|
|
2386
|
+
...rest
|
|
2387
|
+
}) => {
|
|
2388
|
+
const { field, control, renderProps } = useDataGridCell({
|
|
2389
|
+
context
|
|
2390
|
+
});
|
|
2391
|
+
const errorProps = useDataGridCellError({ context });
|
|
2392
|
+
const { container, input } = renderProps;
|
|
2393
|
+
return /* @__PURE__ */ jsx7(
|
|
2394
|
+
Controller4,
|
|
2395
|
+
{
|
|
2396
|
+
control,
|
|
2397
|
+
name: field,
|
|
2398
|
+
render: ({ field: field2 }) => {
|
|
2399
|
+
return /* @__PURE__ */ jsx7(DataGridCellContainer, { ...container, ...errorProps, children: /* @__PURE__ */ jsx7(Inner4, { field: field2, inputProps: input, ...rest }) });
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
);
|
|
2403
|
+
};
|
|
2404
|
+
var Inner4 = ({
|
|
2405
|
+
field,
|
|
2406
|
+
inputProps,
|
|
2407
|
+
...props
|
|
2408
|
+
}) => {
|
|
2409
|
+
const { ref, value, onChange: _, onBlur, ...fieldProps } = field;
|
|
2410
|
+
const {
|
|
2411
|
+
ref: inputRef,
|
|
2412
|
+
onChange,
|
|
2413
|
+
onBlur: onInputBlur,
|
|
2414
|
+
onFocus,
|
|
2415
|
+
...attributes
|
|
2416
|
+
} = inputProps;
|
|
2417
|
+
const [localValue, setLocalValue] = useState6(value);
|
|
2418
|
+
useEffect5(() => {
|
|
2419
|
+
setLocalValue(value);
|
|
2420
|
+
}, [value]);
|
|
2421
|
+
const combinedRefs = useCombinedRefs(inputRef, ref);
|
|
2422
|
+
return /* @__PURE__ */ jsx7("div", { className: "size-full", children: /* @__PURE__ */ jsx7(
|
|
2423
|
+
"input",
|
|
2424
|
+
{
|
|
2425
|
+
ref: combinedRefs,
|
|
2426
|
+
value: localValue,
|
|
2427
|
+
onChange: (e) => setLocalValue(e.target.value),
|
|
2428
|
+
onBlur: () => {
|
|
2429
|
+
onBlur();
|
|
2430
|
+
onInputBlur();
|
|
2431
|
+
onChange(localValue, value);
|
|
2432
|
+
},
|
|
2433
|
+
onFocus,
|
|
2434
|
+
type: "number",
|
|
2435
|
+
inputMode: "decimal",
|
|
2436
|
+
className: clx3(
|
|
2437
|
+
"txt-compact-small size-full bg-transparent outline-none",
|
|
2438
|
+
"placeholder:text-ui-fg-muted"
|
|
2439
|
+
),
|
|
2440
|
+
tabIndex: -1,
|
|
2441
|
+
...props,
|
|
2442
|
+
...fieldProps,
|
|
2443
|
+
...attributes
|
|
2444
|
+
}
|
|
2445
|
+
) });
|
|
2446
|
+
};
|
|
2447
|
+
|
|
2448
|
+
// src/components/data-grid/components/data-grid-readonly-cell.tsx
|
|
2449
|
+
import { clx as clx4 } from "@medusajs/ui";
|
|
2450
|
+
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2451
|
+
var DataGridReadonlyCell = ({
|
|
2452
|
+
context,
|
|
2453
|
+
color = "muted",
|
|
2454
|
+
children,
|
|
2455
|
+
isMultiLine = false
|
|
2456
|
+
}) => {
|
|
2457
|
+
const { rowErrors } = useDataGridCellError({ context });
|
|
2458
|
+
return /* @__PURE__ */ jsxs5(
|
|
2459
|
+
"div",
|
|
2460
|
+
{
|
|
2461
|
+
className: clx4(
|
|
2462
|
+
"txt-compact-small text-ui-fg-subtle flex w-full cursor-not-allowed justify-between overflow-hidden px-4 py-2.5 outline-none",
|
|
2463
|
+
color === "muted" && "bg-ui-bg-subtle",
|
|
2464
|
+
color === "normal" && "bg-ui-bg-base",
|
|
2465
|
+
"h-full items-center"
|
|
2466
|
+
),
|
|
2467
|
+
children: [
|
|
2468
|
+
/* @__PURE__ */ jsx8(
|
|
2469
|
+
"div",
|
|
2470
|
+
{
|
|
2471
|
+
className: clx4("flex-1", {
|
|
2472
|
+
truncate: !isMultiLine,
|
|
2473
|
+
"whitespace-pre-wrap break-words": isMultiLine
|
|
2474
|
+
}),
|
|
2475
|
+
children
|
|
2476
|
+
}
|
|
2477
|
+
),
|
|
2478
|
+
/* @__PURE__ */ jsx8(DataGridRowErrorIndicator, { rowErrors })
|
|
2479
|
+
]
|
|
2480
|
+
}
|
|
2481
|
+
);
|
|
2482
|
+
};
|
|
2483
|
+
|
|
2484
|
+
// src/components/data-grid/components/data-grid-root.tsx
|
|
2485
|
+
import {
|
|
2486
|
+
Adjustments,
|
|
2487
|
+
AdjustmentsDone,
|
|
2488
|
+
ExclamationCircle as ExclamationCircle2
|
|
2489
|
+
} from "@medusajs/icons";
|
|
2490
|
+
import { Button as Button2, DropdownMenu, clx as clx6 } from "@medusajs/ui";
|
|
2491
|
+
import {
|
|
2492
|
+
flexRender,
|
|
2493
|
+
getCoreRowModel,
|
|
2494
|
+
useReactTable
|
|
2495
|
+
} from "@tanstack/react-table";
|
|
2496
|
+
import {
|
|
2497
|
+
useVirtualizer
|
|
2498
|
+
} from "@tanstack/react-virtual";
|
|
2499
|
+
import {
|
|
2500
|
+
useCallback as useCallback15,
|
|
2501
|
+
useEffect as useEffect6,
|
|
2502
|
+
useMemo as useMemo5,
|
|
2503
|
+
useRef as useRef4,
|
|
2504
|
+
useState as useState9
|
|
2505
|
+
} from "react";
|
|
2506
|
+
import { useTranslation as useTranslation3 } from "react-i18next";
|
|
2507
|
+
|
|
2508
|
+
// src/hooks/use-command-history.tsx
|
|
2509
|
+
import { useCallback as useCallback14, useState as useState7 } from "react";
|
|
2510
|
+
var useCommandHistory = (maxHistory = 20) => {
|
|
2511
|
+
const [past, setPast] = useState7([]);
|
|
2512
|
+
const [future, setFuture] = useState7([]);
|
|
2513
|
+
const canUndo = past.length > 0;
|
|
2514
|
+
const canRedo = future.length > 0;
|
|
2515
|
+
const undo = useCallback14(() => {
|
|
2516
|
+
if (!canUndo) {
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
const previous = past[past.length - 1];
|
|
2520
|
+
const newPast = past.slice(0, past.length - 1);
|
|
2521
|
+
previous.undo();
|
|
2522
|
+
setPast(newPast);
|
|
2523
|
+
setFuture([previous, ...future.slice(0, maxHistory - 1)]);
|
|
2524
|
+
}, [canUndo, future, past, maxHistory]);
|
|
2525
|
+
const redo = useCallback14(() => {
|
|
2526
|
+
if (!canRedo) {
|
|
2527
|
+
return;
|
|
2528
|
+
}
|
|
2529
|
+
const next = future[0];
|
|
2530
|
+
const newFuture = future.slice(1);
|
|
2531
|
+
next.redo();
|
|
2532
|
+
setPast([...past, next].slice(0, maxHistory - 1));
|
|
2533
|
+
setFuture(newFuture);
|
|
2534
|
+
}, [canRedo, future, past, maxHistory]);
|
|
2535
|
+
const execute = useCallback14(
|
|
2536
|
+
(command) => {
|
|
2537
|
+
command.execute();
|
|
2538
|
+
setPast((past2) => [...past2, command].slice(0, maxHistory - 1));
|
|
2539
|
+
setFuture([]);
|
|
2540
|
+
},
|
|
2541
|
+
[maxHistory]
|
|
2542
|
+
);
|
|
2543
|
+
return {
|
|
2544
|
+
undo,
|
|
2545
|
+
redo,
|
|
2546
|
+
execute,
|
|
2547
|
+
canUndo,
|
|
2548
|
+
canRedo
|
|
2549
|
+
};
|
|
2550
|
+
};
|
|
2551
|
+
|
|
2552
|
+
// src/components/data-grid/components/data-grid-keyboard-shortcut-modal.tsx
|
|
2553
|
+
import { XMark } from "@medusajs/icons";
|
|
2554
|
+
import {
|
|
2555
|
+
Button,
|
|
2556
|
+
clx as clx5,
|
|
2557
|
+
Heading,
|
|
2558
|
+
IconButton,
|
|
2559
|
+
Input,
|
|
2560
|
+
Kbd,
|
|
2561
|
+
Text
|
|
2562
|
+
} from "@medusajs/ui";
|
|
2563
|
+
import { Dialog as RadixDialog } from "radix-ui";
|
|
2564
|
+
import { useMemo as useMemo4, useState as useState8 } from "react";
|
|
2565
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
2566
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2567
|
+
var useDataGridShortcuts = () => {
|
|
2568
|
+
const { t } = useTranslation2();
|
|
2569
|
+
const shortcuts = useMemo4(
|
|
2570
|
+
() => [
|
|
2571
|
+
{
|
|
2572
|
+
label: t("dataGrid.shortcuts.commands.undo"),
|
|
2573
|
+
keys: {
|
|
2574
|
+
Mac: ["\u2318", "Z"],
|
|
2575
|
+
Windows: ["Ctrl", "Z"]
|
|
2576
|
+
}
|
|
2577
|
+
},
|
|
2578
|
+
{
|
|
2579
|
+
label: t("dataGrid.shortcuts.commands.redo"),
|
|
2580
|
+
keys: {
|
|
2581
|
+
Mac: ["\u21E7", "\u2318", "Z"],
|
|
2582
|
+
Windows: ["Shift", "Ctrl", "Z"]
|
|
2583
|
+
}
|
|
2584
|
+
},
|
|
2585
|
+
{
|
|
2586
|
+
label: t("dataGrid.shortcuts.commands.copy"),
|
|
2587
|
+
keys: {
|
|
2588
|
+
Mac: ["\u2318", "C"],
|
|
2589
|
+
Windows: ["Ctrl", "C"]
|
|
2590
|
+
}
|
|
2591
|
+
},
|
|
2592
|
+
{
|
|
2593
|
+
label: t("dataGrid.shortcuts.commands.paste"),
|
|
2594
|
+
keys: {
|
|
2595
|
+
Mac: ["\u2318", "V"],
|
|
2596
|
+
Windows: ["Ctrl", "V"]
|
|
2597
|
+
}
|
|
2598
|
+
},
|
|
2599
|
+
{
|
|
2600
|
+
label: t("dataGrid.shortcuts.commands.edit"),
|
|
2601
|
+
keys: {
|
|
2602
|
+
Mac: ["\u21B5"],
|
|
2603
|
+
Windows: ["Enter"]
|
|
2604
|
+
}
|
|
2605
|
+
},
|
|
2606
|
+
{
|
|
2607
|
+
label: t("dataGrid.shortcuts.commands.delete"),
|
|
2608
|
+
keys: {
|
|
2609
|
+
Mac: ["\u232B"],
|
|
2610
|
+
Windows: ["Backspace"]
|
|
2611
|
+
}
|
|
2612
|
+
},
|
|
2613
|
+
{
|
|
2614
|
+
label: t("dataGrid.shortcuts.commands.clear"),
|
|
2615
|
+
keys: {
|
|
2616
|
+
Mac: ["Space"],
|
|
2617
|
+
Windows: ["Space"]
|
|
2618
|
+
}
|
|
2619
|
+
},
|
|
2620
|
+
{
|
|
2621
|
+
label: t("dataGrid.shortcuts.commands.moveUp"),
|
|
2622
|
+
keys: {
|
|
2623
|
+
Mac: ["\u2191"],
|
|
2624
|
+
Windows: ["\u2191"]
|
|
2625
|
+
}
|
|
2626
|
+
},
|
|
2627
|
+
{
|
|
2628
|
+
label: t("dataGrid.shortcuts.commands.moveDown"),
|
|
2629
|
+
keys: {
|
|
2630
|
+
Mac: ["\u2193"],
|
|
2631
|
+
Windows: ["\u2193"]
|
|
2632
|
+
}
|
|
2633
|
+
},
|
|
2634
|
+
{
|
|
2635
|
+
label: t("dataGrid.shortcuts.commands.moveLeft"),
|
|
2636
|
+
keys: {
|
|
2637
|
+
Mac: ["\u2190"],
|
|
2638
|
+
Windows: ["\u2190"]
|
|
2639
|
+
}
|
|
2640
|
+
},
|
|
2641
|
+
{
|
|
2642
|
+
label: t("dataGrid.shortcuts.commands.moveRight"),
|
|
2643
|
+
keys: {
|
|
2644
|
+
Mac: ["\u2192"],
|
|
2645
|
+
Windows: ["\u2192"]
|
|
2646
|
+
}
|
|
2647
|
+
},
|
|
2648
|
+
{
|
|
2649
|
+
label: t("dataGrid.shortcuts.commands.moveTop"),
|
|
2650
|
+
keys: {
|
|
2651
|
+
Mac: ["\u2318", "\u2191"],
|
|
2652
|
+
Windows: ["Ctrl", "\u2191"]
|
|
2653
|
+
}
|
|
2654
|
+
},
|
|
2655
|
+
{
|
|
2656
|
+
label: t("dataGrid.shortcuts.commands.moveBottom"),
|
|
2657
|
+
keys: {
|
|
2658
|
+
Mac: ["\u2318", "\u2193"],
|
|
2659
|
+
Windows: ["Ctrl", "\u2193"]
|
|
2660
|
+
}
|
|
2661
|
+
},
|
|
2662
|
+
{
|
|
2663
|
+
label: t("dataGrid.shortcuts.commands.selectDown"),
|
|
2664
|
+
keys: {
|
|
2665
|
+
Mac: ["\u21E7", "\u2193"],
|
|
2666
|
+
Windows: ["Shift", "\u2193"]
|
|
2667
|
+
}
|
|
2668
|
+
},
|
|
2669
|
+
{
|
|
2670
|
+
label: t("dataGrid.shortcuts.commands.selectUp"),
|
|
2671
|
+
keys: {
|
|
2672
|
+
Mac: ["\u21E7", "\u2191"],
|
|
2673
|
+
Windows: ["Shift", "\u2191"]
|
|
2674
|
+
}
|
|
2675
|
+
},
|
|
2676
|
+
{
|
|
2677
|
+
label: t("dataGrid.shortcuts.commands.selectColumnDown"),
|
|
2678
|
+
keys: {
|
|
2679
|
+
Mac: ["\u21E7", "\u2318", "\u2193"],
|
|
2680
|
+
Windows: ["Shift", "Ctrl", "\u2193"]
|
|
2681
|
+
}
|
|
2682
|
+
},
|
|
2683
|
+
{
|
|
2684
|
+
label: t("dataGrid.shortcuts.commands.selectColumnUp"),
|
|
2685
|
+
keys: {
|
|
2686
|
+
Mac: ["\u21E7", "\u2318", "\u2191"],
|
|
2687
|
+
Windows: ["Shift", "Ctrl", "\u2191"]
|
|
2688
|
+
}
|
|
2689
|
+
},
|
|
2690
|
+
{
|
|
2691
|
+
label: t("dataGrid.shortcuts.commands.focusToolbar"),
|
|
2692
|
+
keys: {
|
|
2693
|
+
Mac: ["\u2303", "\u2325", ","],
|
|
2694
|
+
Windows: ["Ctrl", "Alt", ","]
|
|
2695
|
+
}
|
|
2696
|
+
},
|
|
2697
|
+
{
|
|
2698
|
+
label: t("dataGrid.shortcuts.commands.focusCancel"),
|
|
2699
|
+
keys: {
|
|
2700
|
+
Mac: ["\u2303", "\u2325", "."],
|
|
2701
|
+
Windows: ["Ctrl", "Alt", "."]
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
],
|
|
2705
|
+
[t]
|
|
2706
|
+
);
|
|
2707
|
+
return shortcuts;
|
|
2708
|
+
};
|
|
2709
|
+
var DataGridKeyboardShortcutModal = ({
|
|
2710
|
+
open,
|
|
2711
|
+
onOpenChange
|
|
2712
|
+
}) => {
|
|
2713
|
+
const { t } = useTranslation2();
|
|
2714
|
+
const [searchValue, onSearchValueChange] = useState8("");
|
|
2715
|
+
const shortcuts = useDataGridShortcuts();
|
|
2716
|
+
const searchResults = useMemo4(() => {
|
|
2717
|
+
return shortcuts.filter(
|
|
2718
|
+
(shortcut) => shortcut.label.toLowerCase().includes(searchValue.toLowerCase())
|
|
2719
|
+
);
|
|
2720
|
+
}, [searchValue, shortcuts]);
|
|
2721
|
+
return /* @__PURE__ */ jsxs6(RadixDialog.Root, { open, onOpenChange, children: [
|
|
2722
|
+
/* @__PURE__ */ jsx9(RadixDialog.Trigger, { asChild: true, children: /* @__PURE__ */ jsx9(Button, { size: "small", variant: "secondary", children: t("dataGrid.shortcuts.label") }) }),
|
|
2723
|
+
/* @__PURE__ */ jsxs6(RadixDialog.Portal, { children: [
|
|
2724
|
+
/* @__PURE__ */ jsx9(
|
|
2725
|
+
RadixDialog.Overlay,
|
|
2726
|
+
{
|
|
2727
|
+
className: clx5(
|
|
2728
|
+
"bg-ui-bg-overlay fixed inset-0",
|
|
2729
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
|
|
2730
|
+
)
|
|
2731
|
+
}
|
|
2732
|
+
),
|
|
2733
|
+
/* @__PURE__ */ jsxs6(RadixDialog.Content, { className: "bg-ui-bg-subtle shadow-elevation-modal fixed left-[50%] top-[50%] flex h-full max-h-[612px] w-full max-w-[560px] translate-x-[-50%] translate-y-[-50%] flex-col divide-y overflow-hidden rounded-lg outline-none", children: [
|
|
2734
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-y-3 px-6 py-4", children: [
|
|
2735
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between", children: [
|
|
2736
|
+
/* @__PURE__ */ jsxs6("div", { children: [
|
|
2737
|
+
/* @__PURE__ */ jsx9(RadixDialog.Title, { asChild: true, children: /* @__PURE__ */ jsx9(Heading, { children: t("app.menus.user.shortcuts") }) }),
|
|
2738
|
+
/* @__PURE__ */ jsx9(RadixDialog.Description, { className: "sr-only" })
|
|
2739
|
+
] }),
|
|
2740
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-x-2", children: [
|
|
2741
|
+
/* @__PURE__ */ jsx9(Kbd, { children: "esc" }),
|
|
2742
|
+
/* @__PURE__ */ jsx9(RadixDialog.Close, { asChild: true, children: /* @__PURE__ */ jsx9(IconButton, { variant: "transparent", size: "small", children: /* @__PURE__ */ jsx9(XMark, {}) }) })
|
|
2743
|
+
] })
|
|
2744
|
+
] }),
|
|
2745
|
+
/* @__PURE__ */ jsx9("div", { children: /* @__PURE__ */ jsx9(
|
|
2746
|
+
Input,
|
|
2747
|
+
{
|
|
2748
|
+
type: "search",
|
|
2749
|
+
value: searchValue,
|
|
2750
|
+
autoFocus: true,
|
|
2751
|
+
onChange: (e) => onSearchValueChange(e.target.value)
|
|
2752
|
+
}
|
|
2753
|
+
) })
|
|
2754
|
+
] }),
|
|
2755
|
+
/* @__PURE__ */ jsx9("div", { className: "flex flex-col divide-y overflow-y-auto", children: searchResults.map((shortcut, index) => {
|
|
2756
|
+
return /* @__PURE__ */ jsxs6(
|
|
2757
|
+
"div",
|
|
2758
|
+
{
|
|
2759
|
+
className: "text-ui-fg-subtle flex items-center justify-between px-6 py-3",
|
|
2760
|
+
children: [
|
|
2761
|
+
/* @__PURE__ */ jsx9(Text, { size: "small", children: shortcut.label }),
|
|
2762
|
+
/* @__PURE__ */ jsx9("div", { className: "flex items-center gap-x-1", children: shortcut.keys.Mac?.map((key, index2) => {
|
|
2763
|
+
return /* @__PURE__ */ jsx9("div", { className: "flex items-center gap-x-1", children: /* @__PURE__ */ jsx9(Kbd, { children: key }) }, index2);
|
|
2764
|
+
}) })
|
|
2765
|
+
]
|
|
2766
|
+
},
|
|
2767
|
+
index
|
|
2768
|
+
);
|
|
2769
|
+
}) })
|
|
2770
|
+
] })
|
|
2771
|
+
] })
|
|
2772
|
+
] });
|
|
2773
|
+
};
|
|
2774
|
+
|
|
2775
|
+
// src/components/data-grid/components/data-grid-root.tsx
|
|
2776
|
+
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2777
|
+
var ROW_HEIGHT = 40;
|
|
2778
|
+
var getCommonPinningStyles = (column) => {
|
|
2779
|
+
const isPinned = column.getIsPinned();
|
|
2780
|
+
const isDarkMode = document.documentElement.classList.contains("dark");
|
|
2781
|
+
const BORDER_COLOR = isDarkMode ? "rgb(50,50,53)" : "rgb(228,228,231)";
|
|
2782
|
+
return {
|
|
2783
|
+
position: isPinned ? "sticky" : "relative",
|
|
2784
|
+
width: column.getSize(),
|
|
2785
|
+
zIndex: isPinned ? 1 : 0,
|
|
2786
|
+
borderBottom: isPinned ? `1px solid ${BORDER_COLOR}` : void 0,
|
|
2787
|
+
borderRight: isPinned ? `1px solid ${BORDER_COLOR}` : void 0,
|
|
2788
|
+
left: isPinned === "left" ? `${column.getStart("left")}px` : void 0,
|
|
2789
|
+
right: isPinned === "right" ? `${column.getAfter("right")}px` : void 0
|
|
2790
|
+
};
|
|
2791
|
+
};
|
|
2792
|
+
var DataGridRoot = ({
|
|
2793
|
+
data = [],
|
|
2794
|
+
columns,
|
|
2795
|
+
state,
|
|
2796
|
+
getSubRows,
|
|
2797
|
+
onEditingChange,
|
|
2798
|
+
disableInteractions,
|
|
2799
|
+
multiColumnSelection = false,
|
|
2800
|
+
showColumnsDropdown = true,
|
|
2801
|
+
totalRowCount,
|
|
2802
|
+
onFetchMore,
|
|
2803
|
+
isFetchingMore,
|
|
2804
|
+
hasNextPage,
|
|
2805
|
+
headerContent
|
|
2806
|
+
}) => {
|
|
2807
|
+
const isLazyMode = totalRowCount !== void 0;
|
|
2808
|
+
const containerRef = useRef4(null);
|
|
2809
|
+
const { redo, undo, execute } = useCommandHistory();
|
|
2810
|
+
const {
|
|
2811
|
+
register,
|
|
2812
|
+
control,
|
|
2813
|
+
getValues,
|
|
2814
|
+
setValue: setValue2,
|
|
2815
|
+
formState: { errors }
|
|
2816
|
+
} = state;
|
|
2817
|
+
const [internalTrapActive, setTrapActive] = useState9(true);
|
|
2818
|
+
const trapActive = !disableInteractions && internalTrapActive;
|
|
2819
|
+
const [anchor, setAnchor] = useState9(null);
|
|
2820
|
+
const [rangeEnd, setRangeEnd] = useState9(null);
|
|
2821
|
+
const [dragEnd, setDragEnd] = useState9(null);
|
|
2822
|
+
const [isSelecting, setIsSelecting] = useState9(false);
|
|
2823
|
+
const [isDragging, setIsDragging] = useState9(false);
|
|
2824
|
+
const [isEditing, setIsEditing] = useState9(false);
|
|
2825
|
+
const [columnVisibility, setColumnVisibility] = useState9({});
|
|
2826
|
+
const [rowVisibility, setRowVisibility] = useState9({});
|
|
2827
|
+
const grid = useReactTable({
|
|
2828
|
+
data,
|
|
2829
|
+
columns,
|
|
2830
|
+
initialState: {
|
|
2831
|
+
columnPinning: {
|
|
2832
|
+
left: [columns[0].id]
|
|
2833
|
+
}
|
|
2834
|
+
},
|
|
2835
|
+
state: {
|
|
2836
|
+
columnVisibility
|
|
2837
|
+
},
|
|
2838
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
2839
|
+
getSubRows,
|
|
2840
|
+
getCoreRowModel: getCoreRowModel(),
|
|
2841
|
+
defaultColumn: {
|
|
2842
|
+
size: 200,
|
|
2843
|
+
maxSize: 400
|
|
2844
|
+
}
|
|
2845
|
+
});
|
|
2846
|
+
const { flatRows } = grid.getRowModel();
|
|
2847
|
+
const flatColumns = grid.getAllFlatColumns();
|
|
2848
|
+
const visibleRows = useMemo5(
|
|
2849
|
+
() => flatRows.filter((_, index) => rowVisibility?.[index] !== false),
|
|
2850
|
+
[flatRows, rowVisibility]
|
|
2851
|
+
);
|
|
2852
|
+
const visibleColumns = grid.getVisibleLeafColumns();
|
|
2853
|
+
const effectiveRowCount = isLazyMode ? totalRowCount : visibleRows.length;
|
|
2854
|
+
const rowVirtualizer = useVirtualizer({
|
|
2855
|
+
count: effectiveRowCount,
|
|
2856
|
+
estimateSize: () => ROW_HEIGHT,
|
|
2857
|
+
getScrollElement: () => containerRef.current,
|
|
2858
|
+
// Measure actual row heights for dynamic sizing (disabled in Firefox due to measurement issues). Taken from Tanstack
|
|
2859
|
+
measureElement: typeof window !== "undefined" && navigator.userAgent.indexOf("Firefox") === -1 ? (element) => element?.getBoundingClientRect().height : void 0,
|
|
2860
|
+
overscan: 5,
|
|
2861
|
+
rangeExtractor: (range) => {
|
|
2862
|
+
const toRender = new Set(
|
|
2863
|
+
Array.from(
|
|
2864
|
+
{ length: range.endIndex - range.startIndex + 1 },
|
|
2865
|
+
(_, i) => range.startIndex + i
|
|
2866
|
+
)
|
|
2867
|
+
);
|
|
2868
|
+
if (anchor && visibleRows[anchor.row]) {
|
|
2869
|
+
toRender.add(anchor.row);
|
|
2870
|
+
}
|
|
2871
|
+
if (rangeEnd && visibleRows[rangeEnd.row]) {
|
|
2872
|
+
toRender.add(rangeEnd.row);
|
|
2873
|
+
}
|
|
2874
|
+
return Array.from(toRender).sort((a, b) => a - b);
|
|
2875
|
+
}
|
|
2876
|
+
});
|
|
2877
|
+
const virtualRows = rowVirtualizer.getVirtualItems();
|
|
2878
|
+
const lazyLoadingRefs = useRef4({
|
|
2879
|
+
onFetchMore,
|
|
2880
|
+
hasNextPage,
|
|
2881
|
+
isFetchingMore,
|
|
2882
|
+
loadedRowCount: visibleRows.length
|
|
2883
|
+
});
|
|
2884
|
+
useEffect6(() => {
|
|
2885
|
+
lazyLoadingRefs.current = {
|
|
2886
|
+
onFetchMore,
|
|
2887
|
+
hasNextPage,
|
|
2888
|
+
isFetchingMore,
|
|
2889
|
+
loadedRowCount: visibleRows.length
|
|
2890
|
+
};
|
|
2891
|
+
}, [onFetchMore, hasNextPage, isFetchingMore, visibleRows.length]);
|
|
2892
|
+
const hasData = visibleRows.length > 0;
|
|
2893
|
+
const handleScroll = useCallback15(() => {
|
|
2894
|
+
const { onFetchMore: onFetchMore2, hasNextPage: hasNextPage2, isFetchingMore: isFetchingMore2, loadedRowCount } = lazyLoadingRefs.current;
|
|
2895
|
+
if (!onFetchMore2 || !hasNextPage2 || isFetchingMore2) {
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
const scrollElement = containerRef.current;
|
|
2899
|
+
const { scrollTop, clientHeight } = scrollElement;
|
|
2900
|
+
const loadedHeight = loadedRowCount * ROW_HEIGHT;
|
|
2901
|
+
const viewportBottom = scrollTop + clientHeight;
|
|
2902
|
+
const fetchThreshold = loadedHeight - ROW_HEIGHT * 10;
|
|
2903
|
+
if (viewportBottom >= fetchThreshold) {
|
|
2904
|
+
onFetchMore2();
|
|
2905
|
+
}
|
|
2906
|
+
}, [lazyLoadingRefs, containerRef]);
|
|
2907
|
+
useEffect6(() => {
|
|
2908
|
+
if (!isLazyMode || !hasData) {
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2911
|
+
const container = containerRef.current;
|
|
2912
|
+
if (!container) {
|
|
2913
|
+
return;
|
|
2914
|
+
}
|
|
2915
|
+
const timeoutId = setTimeout(() => {
|
|
2916
|
+
const scrollElement = containerRef.current;
|
|
2917
|
+
if (!scrollElement) {
|
|
2918
|
+
return;
|
|
2919
|
+
}
|
|
2920
|
+
scrollElement.addEventListener("scroll", handleScroll);
|
|
2921
|
+
}, 100);
|
|
2922
|
+
return () => {
|
|
2923
|
+
clearTimeout(timeoutId);
|
|
2924
|
+
const scrollElement = containerRef.current;
|
|
2925
|
+
scrollElement?.removeEventListener("scroll", handleScroll);
|
|
2926
|
+
};
|
|
2927
|
+
}, [isLazyMode, hasData]);
|
|
2928
|
+
const columnVirtualizer = useVirtualizer({
|
|
2929
|
+
count: visibleColumns.length,
|
|
2930
|
+
estimateSize: (index) => visibleColumns[index].getSize(),
|
|
2931
|
+
getScrollElement: () => containerRef.current,
|
|
2932
|
+
horizontal: true,
|
|
2933
|
+
overscan: 3,
|
|
2934
|
+
rangeExtractor: (range) => {
|
|
2935
|
+
const startIndex = range.startIndex;
|
|
2936
|
+
const endIndex = range.endIndex;
|
|
2937
|
+
const toRender = new Set(
|
|
2938
|
+
Array.from(
|
|
2939
|
+
{ length: endIndex - startIndex + 1 },
|
|
2940
|
+
(_, i) => startIndex + i
|
|
2941
|
+
)
|
|
2942
|
+
);
|
|
2943
|
+
if (anchor && visibleColumns[anchor.col]) {
|
|
2944
|
+
toRender.add(anchor.col);
|
|
2945
|
+
}
|
|
2946
|
+
if (rangeEnd && visibleColumns[rangeEnd.col]) {
|
|
2947
|
+
toRender.add(rangeEnd.col);
|
|
2948
|
+
}
|
|
2949
|
+
toRender.add(0);
|
|
2950
|
+
return Array.from(toRender).sort((a, b) => a - b);
|
|
2951
|
+
}
|
|
2952
|
+
});
|
|
2953
|
+
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
2954
|
+
let virtualPaddingLeft;
|
|
2955
|
+
let virtualPaddingRight;
|
|
2956
|
+
if (columnVirtualizer && virtualColumns?.length) {
|
|
2957
|
+
virtualPaddingLeft = virtualColumns[0]?.start ?? 0;
|
|
2958
|
+
virtualPaddingRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0);
|
|
2959
|
+
}
|
|
2960
|
+
const matrix = useMemo5(
|
|
2961
|
+
() => new DataGridMatrix(
|
|
2962
|
+
flatRows,
|
|
2963
|
+
columns,
|
|
2964
|
+
multiColumnSelection
|
|
2965
|
+
),
|
|
2966
|
+
[flatRows, columns, multiColumnSelection]
|
|
2967
|
+
);
|
|
2968
|
+
const queryTool = useDataGridQueryTool(containerRef);
|
|
2969
|
+
const setSingleRange = useCallback15(
|
|
2970
|
+
(coordinates) => {
|
|
2971
|
+
setAnchor(coordinates);
|
|
2972
|
+
setRangeEnd(coordinates);
|
|
2973
|
+
},
|
|
2974
|
+
[]
|
|
2975
|
+
);
|
|
2976
|
+
const { errorCount, isHighlighted, toggleErrorHighlighting } = useDataGridErrorHighlighting(matrix, grid, errors);
|
|
2977
|
+
const handleToggleErrorHighlighting = useCallback15(() => {
|
|
2978
|
+
toggleErrorHighlighting(
|
|
2979
|
+
rowVisibility,
|
|
2980
|
+
columnVisibility,
|
|
2981
|
+
setRowVisibility,
|
|
2982
|
+
setColumnVisibility
|
|
2983
|
+
);
|
|
2984
|
+
}, [toggleErrorHighlighting, rowVisibility, columnVisibility]);
|
|
2985
|
+
const {
|
|
2986
|
+
columnOptions,
|
|
2987
|
+
handleToggleColumn,
|
|
2988
|
+
handleResetColumns,
|
|
2989
|
+
isDisabled: isColumsDisabled
|
|
2990
|
+
} = useDataGridColumnVisibility(grid, matrix);
|
|
2991
|
+
const handleToggleColumnVisibility = useCallback15(
|
|
2992
|
+
(index) => {
|
|
2993
|
+
return handleToggleColumn(index);
|
|
2994
|
+
},
|
|
2995
|
+
[handleToggleColumn]
|
|
2996
|
+
);
|
|
2997
|
+
const { navigateToField, scrollToCoordinates } = useDataGridNavigation({
|
|
2998
|
+
matrix,
|
|
2999
|
+
queryTool,
|
|
3000
|
+
anchor,
|
|
3001
|
+
columnVirtualizer,
|
|
3002
|
+
rowVirtualizer,
|
|
3003
|
+
flatColumns,
|
|
3004
|
+
setColumnVisibility,
|
|
3005
|
+
setSingleRange,
|
|
3006
|
+
visibleColumns,
|
|
3007
|
+
visibleRows
|
|
3008
|
+
});
|
|
3009
|
+
const { createSnapshot, restoreSnapshot } = useDataGridCellSnapshot({
|
|
3010
|
+
matrix,
|
|
3011
|
+
form: state
|
|
3012
|
+
});
|
|
3013
|
+
const onEditingChangeHandler = useCallback15(
|
|
3014
|
+
(value) => {
|
|
3015
|
+
if (onEditingChange) {
|
|
3016
|
+
onEditingChange(value);
|
|
3017
|
+
}
|
|
3018
|
+
if (value) {
|
|
3019
|
+
createSnapshot(anchor);
|
|
3020
|
+
}
|
|
3021
|
+
setIsEditing(value);
|
|
3022
|
+
},
|
|
3023
|
+
[anchor, createSnapshot, onEditingChange]
|
|
3024
|
+
);
|
|
3025
|
+
const { getSelectionValues, setSelectionValues } = useDataGridFormHandlers({
|
|
3026
|
+
matrix,
|
|
3027
|
+
form: state,
|
|
3028
|
+
anchor
|
|
3029
|
+
});
|
|
3030
|
+
const { handleKeyDownEvent, handleSpecialFocusKeys } = useDataGridKeydownEvent({
|
|
3031
|
+
containerRef,
|
|
3032
|
+
matrix,
|
|
3033
|
+
queryTool,
|
|
3034
|
+
anchor,
|
|
3035
|
+
rangeEnd,
|
|
3036
|
+
isEditing,
|
|
3037
|
+
setTrapActive,
|
|
3038
|
+
setRangeEnd,
|
|
3039
|
+
getSelectionValues,
|
|
3040
|
+
getValues,
|
|
3041
|
+
setSelectionValues,
|
|
3042
|
+
onEditingChangeHandler,
|
|
3043
|
+
restoreSnapshot,
|
|
3044
|
+
createSnapshot,
|
|
3045
|
+
setSingleRange,
|
|
3046
|
+
scrollToCoordinates,
|
|
3047
|
+
execute,
|
|
3048
|
+
undo,
|
|
3049
|
+
redo,
|
|
3050
|
+
setValue: setValue2
|
|
3051
|
+
});
|
|
3052
|
+
const { handleMouseUpEvent } = useDataGridMouseUpEvent({
|
|
3053
|
+
matrix,
|
|
3054
|
+
anchor,
|
|
3055
|
+
dragEnd,
|
|
3056
|
+
setDragEnd,
|
|
3057
|
+
isDragging,
|
|
3058
|
+
setIsDragging,
|
|
3059
|
+
setRangeEnd,
|
|
3060
|
+
setIsSelecting,
|
|
3061
|
+
getSelectionValues,
|
|
3062
|
+
setSelectionValues,
|
|
3063
|
+
execute
|
|
3064
|
+
});
|
|
3065
|
+
const { handleCopyEvent, handlePasteEvent } = useDataGridClipboardEvents({
|
|
3066
|
+
matrix,
|
|
3067
|
+
isEditing,
|
|
3068
|
+
anchor,
|
|
3069
|
+
rangeEnd,
|
|
3070
|
+
getSelectionValues,
|
|
3071
|
+
setSelectionValues,
|
|
3072
|
+
execute
|
|
3073
|
+
});
|
|
3074
|
+
const {
|
|
3075
|
+
getWrapperFocusHandler,
|
|
3076
|
+
getInputChangeHandler,
|
|
3077
|
+
getOverlayMouseDownHandler,
|
|
3078
|
+
getWrapperMouseOverHandler,
|
|
3079
|
+
getIsCellDragSelected,
|
|
3080
|
+
getIsCellSelected,
|
|
3081
|
+
onDragToFillStart
|
|
3082
|
+
} = useDataGridCellHandlers({
|
|
3083
|
+
matrix,
|
|
3084
|
+
anchor,
|
|
3085
|
+
rangeEnd,
|
|
3086
|
+
setRangeEnd,
|
|
3087
|
+
isDragging,
|
|
3088
|
+
setIsDragging,
|
|
3089
|
+
isSelecting,
|
|
3090
|
+
setIsSelecting,
|
|
3091
|
+
setSingleRange,
|
|
3092
|
+
dragEnd,
|
|
3093
|
+
setDragEnd,
|
|
3094
|
+
setValue: setValue2,
|
|
3095
|
+
execute,
|
|
3096
|
+
multiColumnSelection
|
|
3097
|
+
});
|
|
3098
|
+
const { getCellErrorMetadata, getCellMetadata } = useDataGridCellMetadata({
|
|
3099
|
+
matrix
|
|
3100
|
+
});
|
|
3101
|
+
useEffect6(() => {
|
|
3102
|
+
if (!trapActive) {
|
|
3103
|
+
return;
|
|
3104
|
+
}
|
|
3105
|
+
window.addEventListener("keydown", handleKeyDownEvent);
|
|
3106
|
+
window.addEventListener("mouseup", handleMouseUpEvent);
|
|
3107
|
+
window.addEventListener("copy", handleCopyEvent);
|
|
3108
|
+
window.addEventListener("paste", handlePasteEvent);
|
|
3109
|
+
return () => {
|
|
3110
|
+
window.removeEventListener("keydown", handleKeyDownEvent);
|
|
3111
|
+
window.removeEventListener("mouseup", handleMouseUpEvent);
|
|
3112
|
+
window.removeEventListener("copy", handleCopyEvent);
|
|
3113
|
+
window.removeEventListener("paste", handlePasteEvent);
|
|
3114
|
+
};
|
|
3115
|
+
}, [
|
|
3116
|
+
trapActive,
|
|
3117
|
+
handleKeyDownEvent,
|
|
3118
|
+
handleMouseUpEvent,
|
|
3119
|
+
handleCopyEvent,
|
|
3120
|
+
handlePasteEvent
|
|
3121
|
+
]);
|
|
3122
|
+
useEffect6(() => {
|
|
3123
|
+
const specialFocusHandler = (e) => {
|
|
3124
|
+
if (isSpecialFocusKey(e)) {
|
|
3125
|
+
handleSpecialFocusKeys(e);
|
|
3126
|
+
return;
|
|
3127
|
+
}
|
|
3128
|
+
};
|
|
3129
|
+
window.addEventListener("keydown", specialFocusHandler);
|
|
3130
|
+
return () => {
|
|
3131
|
+
window.removeEventListener("keydown", specialFocusHandler);
|
|
3132
|
+
};
|
|
3133
|
+
}, [handleSpecialFocusKeys]);
|
|
3134
|
+
const handleHeaderInteractionChange = useCallback15((isActive) => {
|
|
3135
|
+
if (isActive) {
|
|
3136
|
+
setTrapActive(false);
|
|
3137
|
+
}
|
|
3138
|
+
}, []);
|
|
3139
|
+
useEffect6(() => {
|
|
3140
|
+
if (!anchor) {
|
|
3141
|
+
return;
|
|
3142
|
+
}
|
|
3143
|
+
if (rangeEnd) {
|
|
3144
|
+
return;
|
|
3145
|
+
}
|
|
3146
|
+
setRangeEnd(anchor);
|
|
3147
|
+
}, [anchor, rangeEnd]);
|
|
3148
|
+
useEffect6(() => {
|
|
3149
|
+
if (!anchor && matrix) {
|
|
3150
|
+
const coords = matrix.getFirstNavigableCell();
|
|
3151
|
+
if (coords) {
|
|
3152
|
+
setSingleRange(coords);
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
}, [anchor, matrix, setSingleRange]);
|
|
3156
|
+
const values = useMemo5(
|
|
3157
|
+
() => ({
|
|
3158
|
+
anchor,
|
|
3159
|
+
control,
|
|
3160
|
+
trapActive,
|
|
3161
|
+
errors,
|
|
3162
|
+
setTrapActive,
|
|
3163
|
+
setIsSelecting,
|
|
3164
|
+
setIsEditing: onEditingChangeHandler,
|
|
3165
|
+
setSingleRange,
|
|
3166
|
+
setRangeEnd,
|
|
3167
|
+
getWrapperFocusHandler,
|
|
3168
|
+
getInputChangeHandler,
|
|
3169
|
+
getOverlayMouseDownHandler,
|
|
3170
|
+
getWrapperMouseOverHandler,
|
|
3171
|
+
register,
|
|
3172
|
+
getIsCellSelected,
|
|
3173
|
+
getIsCellDragSelected,
|
|
3174
|
+
getCellMetadata,
|
|
3175
|
+
getCellErrorMetadata,
|
|
3176
|
+
navigateToField
|
|
3177
|
+
}),
|
|
3178
|
+
[
|
|
3179
|
+
anchor,
|
|
3180
|
+
control,
|
|
3181
|
+
trapActive,
|
|
3182
|
+
errors,
|
|
3183
|
+
setTrapActive,
|
|
3184
|
+
setIsSelecting,
|
|
3185
|
+
onEditingChangeHandler,
|
|
3186
|
+
setSingleRange,
|
|
3187
|
+
setRangeEnd,
|
|
3188
|
+
getWrapperFocusHandler,
|
|
3189
|
+
getInputChangeHandler,
|
|
3190
|
+
getOverlayMouseDownHandler,
|
|
3191
|
+
getWrapperMouseOverHandler,
|
|
3192
|
+
register,
|
|
3193
|
+
getIsCellSelected,
|
|
3194
|
+
getIsCellDragSelected,
|
|
3195
|
+
getCellMetadata,
|
|
3196
|
+
getCellErrorMetadata,
|
|
3197
|
+
navigateToField
|
|
3198
|
+
]
|
|
3199
|
+
);
|
|
3200
|
+
const handleRestoreGridFocus = useCallback15(() => {
|
|
3201
|
+
if (anchor && !trapActive) {
|
|
3202
|
+
setTrapActive(true);
|
|
3203
|
+
setSingleRange(anchor);
|
|
3204
|
+
scrollToCoordinates(anchor, "both");
|
|
3205
|
+
requestAnimationFrame(() => {
|
|
3206
|
+
queryTool?.getContainer(anchor)?.focus();
|
|
3207
|
+
});
|
|
3208
|
+
}
|
|
3209
|
+
}, [anchor, trapActive, setSingleRange, scrollToCoordinates, queryTool]);
|
|
3210
|
+
return /* @__PURE__ */ jsx10(DataGridContext.Provider, { value: values, children: /* @__PURE__ */ jsxs7("div", { className: "bg-ui-bg-subtle flex size-full flex-col", children: [
|
|
3211
|
+
/* @__PURE__ */ jsx10(
|
|
3212
|
+
DataGridHeader,
|
|
3213
|
+
{
|
|
3214
|
+
showColumnsDropdown,
|
|
3215
|
+
columnOptions,
|
|
3216
|
+
isDisabled: isColumsDisabled,
|
|
3217
|
+
onToggleColumn: handleToggleColumnVisibility,
|
|
3218
|
+
errorCount,
|
|
3219
|
+
onToggleErrorHighlighting: handleToggleErrorHighlighting,
|
|
3220
|
+
onResetColumns: handleResetColumns,
|
|
3221
|
+
isHighlighted,
|
|
3222
|
+
onHeaderInteractionChange: handleHeaderInteractionChange,
|
|
3223
|
+
headerContent
|
|
3224
|
+
}
|
|
3225
|
+
),
|
|
3226
|
+
/* @__PURE__ */ jsx10("div", { className: "size-full overflow-hidden", children: /* @__PURE__ */ jsx10(
|
|
3227
|
+
"div",
|
|
3228
|
+
{
|
|
3229
|
+
ref: containerRef,
|
|
3230
|
+
autoFocus: true,
|
|
3231
|
+
tabIndex: 0,
|
|
3232
|
+
className: "relative h-full select-none overflow-auto outline-none",
|
|
3233
|
+
onFocus: handleRestoreGridFocus,
|
|
3234
|
+
onClick: handleRestoreGridFocus,
|
|
3235
|
+
"data-container": true,
|
|
3236
|
+
role: "application",
|
|
3237
|
+
children: /* @__PURE__ */ jsxs7("div", { role: "grid", className: "text-ui-fg-subtle grid", children: [
|
|
3238
|
+
/* @__PURE__ */ jsx10(
|
|
3239
|
+
"div",
|
|
3240
|
+
{
|
|
3241
|
+
role: "rowgroup",
|
|
3242
|
+
className: "txt-compact-small-plus bg-ui-bg-subtle sticky top-0 z-[1] grid",
|
|
3243
|
+
children: grid.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs7(
|
|
3244
|
+
"div",
|
|
3245
|
+
{
|
|
3246
|
+
role: "row",
|
|
3247
|
+
className: "flex h-10 w-full",
|
|
3248
|
+
children: [
|
|
3249
|
+
virtualPaddingLeft ? /* @__PURE__ */ jsx10(
|
|
3250
|
+
"div",
|
|
3251
|
+
{
|
|
3252
|
+
role: "presentation",
|
|
3253
|
+
style: { display: "flex", width: virtualPaddingLeft }
|
|
3254
|
+
}
|
|
3255
|
+
) : null,
|
|
3256
|
+
virtualColumns.reduce((acc, vc, index, array) => {
|
|
3257
|
+
const header = headerGroup.headers[vc.index];
|
|
3258
|
+
const previousVC = array[index - 1];
|
|
3259
|
+
if (previousVC && vc.index !== previousVC.index + 1) {
|
|
3260
|
+
acc.push(
|
|
3261
|
+
/* @__PURE__ */ jsx10(
|
|
3262
|
+
"div",
|
|
3263
|
+
{
|
|
3264
|
+
role: "presentation",
|
|
3265
|
+
style: {
|
|
3266
|
+
display: "flex",
|
|
3267
|
+
width: `${vc.start - previousVC.end}px`
|
|
3268
|
+
}
|
|
3269
|
+
},
|
|
3270
|
+
`padding-${previousVC.index}-${vc.index}`
|
|
3271
|
+
)
|
|
3272
|
+
);
|
|
3273
|
+
}
|
|
3274
|
+
acc.push(
|
|
3275
|
+
/* @__PURE__ */ jsx10(
|
|
3276
|
+
"div",
|
|
3277
|
+
{
|
|
3278
|
+
role: "columnheader",
|
|
3279
|
+
"data-column-index": vc.index,
|
|
3280
|
+
style: {
|
|
3281
|
+
width: header.getSize(),
|
|
3282
|
+
...getCommonPinningStyles(header.column)
|
|
3283
|
+
},
|
|
3284
|
+
className: "bg-ui-bg-base txt-compact-small-plus flex items-center border-b border-r px-4 py-2.5",
|
|
3285
|
+
children: header.isPlaceholder ? null : flexRender(
|
|
3286
|
+
header.column.columnDef.header,
|
|
3287
|
+
header.getContext()
|
|
3288
|
+
)
|
|
3289
|
+
},
|
|
3290
|
+
header.id
|
|
3291
|
+
)
|
|
3292
|
+
);
|
|
3293
|
+
return acc;
|
|
3294
|
+
}, []),
|
|
3295
|
+
virtualPaddingRight ? /* @__PURE__ */ jsx10(
|
|
3296
|
+
"div",
|
|
3297
|
+
{
|
|
3298
|
+
role: "presentation",
|
|
3299
|
+
style: {
|
|
3300
|
+
display: "flex",
|
|
3301
|
+
width: virtualPaddingRight
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
) : null
|
|
3305
|
+
]
|
|
3306
|
+
},
|
|
3307
|
+
headerGroup.id
|
|
3308
|
+
))
|
|
3309
|
+
}
|
|
3310
|
+
),
|
|
3311
|
+
/* @__PURE__ */ jsx10(
|
|
3312
|
+
"div",
|
|
3313
|
+
{
|
|
3314
|
+
role: "rowgroup",
|
|
3315
|
+
className: "relative grid",
|
|
3316
|
+
style: {
|
|
3317
|
+
height: `${rowVirtualizer.getTotalSize()}px`
|
|
3318
|
+
},
|
|
3319
|
+
children: virtualRows.map((virtualRow) => {
|
|
3320
|
+
const row = visibleRows[virtualRow.index];
|
|
3321
|
+
if (!row) {
|
|
3322
|
+
return /* @__PURE__ */ jsx10(
|
|
3323
|
+
DataGridRowSkeleton,
|
|
3324
|
+
{
|
|
3325
|
+
virtualRow,
|
|
3326
|
+
virtualColumns,
|
|
3327
|
+
virtualPaddingLeft,
|
|
3328
|
+
virtualPaddingRight
|
|
3329
|
+
},
|
|
3330
|
+
`skeleton-${virtualRow.index}`
|
|
3331
|
+
);
|
|
3332
|
+
}
|
|
3333
|
+
const rowIndex = flatRows.findIndex((r) => r.id === row.id);
|
|
3334
|
+
return /* @__PURE__ */ jsx10(
|
|
3335
|
+
DataGridRow,
|
|
3336
|
+
{
|
|
3337
|
+
row,
|
|
3338
|
+
rowIndex,
|
|
3339
|
+
virtualRow,
|
|
3340
|
+
rowVirtualizer,
|
|
3341
|
+
flatColumns,
|
|
3342
|
+
virtualColumns,
|
|
3343
|
+
anchor,
|
|
3344
|
+
virtualPaddingLeft,
|
|
3345
|
+
virtualPaddingRight,
|
|
3346
|
+
onDragToFillStart,
|
|
3347
|
+
multiColumnSelection
|
|
3348
|
+
},
|
|
3349
|
+
row.id
|
|
3350
|
+
);
|
|
3351
|
+
})
|
|
3352
|
+
}
|
|
3353
|
+
)
|
|
3354
|
+
] })
|
|
3355
|
+
}
|
|
3356
|
+
) })
|
|
3357
|
+
] }) });
|
|
3358
|
+
};
|
|
3359
|
+
var DataGridHeader = ({
|
|
3360
|
+
columnOptions,
|
|
3361
|
+
isDisabled,
|
|
3362
|
+
onToggleColumn,
|
|
3363
|
+
onResetColumns,
|
|
3364
|
+
isHighlighted,
|
|
3365
|
+
errorCount,
|
|
3366
|
+
onToggleErrorHighlighting,
|
|
3367
|
+
onHeaderInteractionChange,
|
|
3368
|
+
showColumnsDropdown,
|
|
3369
|
+
headerContent
|
|
3370
|
+
}) => {
|
|
3371
|
+
const [shortcutsOpen, setShortcutsOpen] = useState9(false);
|
|
3372
|
+
const [columnsOpen, setColumnsOpen] = useState9(false);
|
|
3373
|
+
const { t } = useTranslation3();
|
|
3374
|
+
const direction = useDocumentDirection();
|
|
3375
|
+
const hasChanged = columnOptions.some((column) => !column.checked);
|
|
3376
|
+
const handleShortcutsOpenChange = (value) => {
|
|
3377
|
+
onHeaderInteractionChange(value);
|
|
3378
|
+
setShortcutsOpen(value);
|
|
3379
|
+
};
|
|
3380
|
+
const handleColumnsOpenChange = (value) => {
|
|
3381
|
+
onHeaderInteractionChange(value);
|
|
3382
|
+
setColumnsOpen(value);
|
|
3383
|
+
};
|
|
3384
|
+
return /* @__PURE__ */ jsxs7("div", { className: "bg-ui-bg-base flex items-center justify-between border-b p-4", children: [
|
|
3385
|
+
showColumnsDropdown && /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-x-2", children: [
|
|
3386
|
+
/* @__PURE__ */ jsxs7(
|
|
3387
|
+
DropdownMenu,
|
|
3388
|
+
{
|
|
3389
|
+
dir: direction,
|
|
3390
|
+
open: columnsOpen,
|
|
3391
|
+
onOpenChange: handleColumnsOpenChange,
|
|
3392
|
+
children: [
|
|
3393
|
+
/* @__PURE__ */ jsx10(
|
|
3394
|
+
ConditionalTooltip,
|
|
3395
|
+
{
|
|
3396
|
+
showTooltip: isDisabled,
|
|
3397
|
+
content: t("dataGrid.columns.disabled"),
|
|
3398
|
+
children: /* @__PURE__ */ jsx10(DropdownMenu.Trigger, { asChild: true, disabled: isDisabled, children: /* @__PURE__ */ jsxs7(Button2, { size: "small", variant: "secondary", children: [
|
|
3399
|
+
hasChanged ? /* @__PURE__ */ jsx10(AdjustmentsDone, {}) : /* @__PURE__ */ jsx10(Adjustments, {}),
|
|
3400
|
+
t("dataGrid.columns.view")
|
|
3401
|
+
] }) })
|
|
3402
|
+
}
|
|
3403
|
+
),
|
|
3404
|
+
/* @__PURE__ */ jsx10(DropdownMenu.Content, { children: columnOptions.map((column, index) => {
|
|
3405
|
+
const { checked, disabled, id, name } = column;
|
|
3406
|
+
if (disabled) {
|
|
3407
|
+
return null;
|
|
3408
|
+
}
|
|
3409
|
+
return /* @__PURE__ */ jsx10(
|
|
3410
|
+
DropdownMenu.CheckboxItem,
|
|
3411
|
+
{
|
|
3412
|
+
checked,
|
|
3413
|
+
onCheckedChange: onToggleColumn(index),
|
|
3414
|
+
onSelect: (e) => e.preventDefault(),
|
|
3415
|
+
children: name
|
|
3416
|
+
},
|
|
3417
|
+
id
|
|
3418
|
+
);
|
|
3419
|
+
}) })
|
|
3420
|
+
]
|
|
3421
|
+
}
|
|
3422
|
+
),
|
|
3423
|
+
hasChanged && /* @__PURE__ */ jsx10(
|
|
3424
|
+
Button2,
|
|
3425
|
+
{
|
|
3426
|
+
size: "small",
|
|
3427
|
+
variant: "transparent",
|
|
3428
|
+
type: "button",
|
|
3429
|
+
onClick: onResetColumns,
|
|
3430
|
+
className: "text-ui-fg-muted hover:text-ui-fg-subtle",
|
|
3431
|
+
"data-id": "reset-columns",
|
|
3432
|
+
children: t("dataGrid.columns.resetToDefault")
|
|
3433
|
+
}
|
|
3434
|
+
)
|
|
3435
|
+
] }),
|
|
3436
|
+
headerContent,
|
|
3437
|
+
/* @__PURE__ */ jsxs7("div", { className: "ml-auto flex items-center gap-x-2", children: [
|
|
3438
|
+
errorCount > 0 && /* @__PURE__ */ jsxs7(
|
|
3439
|
+
Button2,
|
|
3440
|
+
{
|
|
3441
|
+
size: "small",
|
|
3442
|
+
variant: "secondary",
|
|
3443
|
+
type: "button",
|
|
3444
|
+
onClick: onToggleErrorHighlighting,
|
|
3445
|
+
className: clx6({
|
|
3446
|
+
"bg-ui-button-neutral-pressed": isHighlighted
|
|
3447
|
+
}),
|
|
3448
|
+
children: [
|
|
3449
|
+
/* @__PURE__ */ jsx10(ExclamationCircle2, { className: "text-ui-fg-subtle" }),
|
|
3450
|
+
/* @__PURE__ */ jsx10("span", { children: t("dataGrid.errors.count", {
|
|
3451
|
+
count: errorCount
|
|
3452
|
+
}) })
|
|
3453
|
+
]
|
|
3454
|
+
}
|
|
3455
|
+
),
|
|
3456
|
+
/* @__PURE__ */ jsx10(
|
|
3457
|
+
DataGridKeyboardShortcutModal,
|
|
3458
|
+
{
|
|
3459
|
+
open: shortcutsOpen,
|
|
3460
|
+
onOpenChange: handleShortcutsOpenChange
|
|
3461
|
+
}
|
|
3462
|
+
)
|
|
3463
|
+
] })
|
|
3464
|
+
] });
|
|
3465
|
+
};
|
|
3466
|
+
var DataGridCell = ({
|
|
3467
|
+
cell,
|
|
3468
|
+
columnIndex,
|
|
3469
|
+
rowIndex,
|
|
3470
|
+
anchor,
|
|
3471
|
+
onDragToFillStart,
|
|
3472
|
+
multiColumnSelection
|
|
3473
|
+
}) => {
|
|
3474
|
+
const coords = {
|
|
3475
|
+
row: rowIndex,
|
|
3476
|
+
col: columnIndex
|
|
3477
|
+
};
|
|
3478
|
+
const isAnchor = isCellMatch(coords, anchor);
|
|
3479
|
+
return /* @__PURE__ */ jsx10(
|
|
3480
|
+
"div",
|
|
3481
|
+
{
|
|
3482
|
+
role: "gridcell",
|
|
3483
|
+
"aria-rowindex": rowIndex,
|
|
3484
|
+
"aria-colindex": columnIndex,
|
|
3485
|
+
style: {
|
|
3486
|
+
width: cell.column.getSize(),
|
|
3487
|
+
...getCommonPinningStyles(cell.column)
|
|
3488
|
+
},
|
|
3489
|
+
"data-row-index": rowIndex,
|
|
3490
|
+
"data-column-index": columnIndex,
|
|
3491
|
+
className: clx6(
|
|
3492
|
+
"relative flex items-stretch border-b border-r p-0 outline-none"
|
|
3493
|
+
),
|
|
3494
|
+
tabIndex: -1,
|
|
3495
|
+
children: /* @__PURE__ */ jsxs7("div", { className: "relative w-full", children: [
|
|
3496
|
+
flexRender(cell.column.columnDef.cell, {
|
|
3497
|
+
...cell.getContext(),
|
|
3498
|
+
columnIndex,
|
|
3499
|
+
rowIndex
|
|
3500
|
+
}),
|
|
3501
|
+
isAnchor && /* @__PURE__ */ jsx10(
|
|
3502
|
+
"div",
|
|
3503
|
+
{
|
|
3504
|
+
onMouseDown: onDragToFillStart,
|
|
3505
|
+
className: clx6(
|
|
3506
|
+
"bg-ui-fg-interactive absolute bottom-0 right-0 z-[3] size-1.5 cursor-ns-resize",
|
|
3507
|
+
{
|
|
3508
|
+
"cursor-nwse-resize": multiColumnSelection
|
|
3509
|
+
}
|
|
3510
|
+
)
|
|
3511
|
+
}
|
|
3512
|
+
)
|
|
3513
|
+
] })
|
|
3514
|
+
}
|
|
3515
|
+
);
|
|
3516
|
+
};
|
|
3517
|
+
var DataGridRow = ({
|
|
3518
|
+
row,
|
|
3519
|
+
rowIndex,
|
|
3520
|
+
virtualRow,
|
|
3521
|
+
rowVirtualizer,
|
|
3522
|
+
virtualPaddingLeft,
|
|
3523
|
+
virtualPaddingRight,
|
|
3524
|
+
virtualColumns,
|
|
3525
|
+
flatColumns,
|
|
3526
|
+
anchor,
|
|
3527
|
+
onDragToFillStart,
|
|
3528
|
+
multiColumnSelection
|
|
3529
|
+
}) => {
|
|
3530
|
+
const visibleCells = row.getVisibleCells();
|
|
3531
|
+
return /* @__PURE__ */ jsxs7(
|
|
3532
|
+
"div",
|
|
3533
|
+
{
|
|
3534
|
+
role: "row",
|
|
3535
|
+
"aria-rowindex": virtualRow.index,
|
|
3536
|
+
"data-index": virtualRow.index,
|
|
3537
|
+
ref: (node) => rowVirtualizer.measureElement(node),
|
|
3538
|
+
style: {
|
|
3539
|
+
transform: `translateY(${virtualRow.start}px)`
|
|
3540
|
+
},
|
|
3541
|
+
className: "bg-ui-bg-subtle txt-compact-small absolute flex min-h-10 w-full",
|
|
3542
|
+
children: [
|
|
3543
|
+
virtualPaddingLeft ? /* @__PURE__ */ jsx10(
|
|
3544
|
+
"div",
|
|
3545
|
+
{
|
|
3546
|
+
role: "presentation",
|
|
3547
|
+
style: { display: "flex", width: virtualPaddingLeft }
|
|
3548
|
+
}
|
|
3549
|
+
) : null,
|
|
3550
|
+
virtualColumns.reduce((acc, vc, index, array) => {
|
|
3551
|
+
const cell = visibleCells[vc.index];
|
|
3552
|
+
const column = cell.column;
|
|
3553
|
+
const columnIndex = flatColumns.findIndex((c) => c.id === column.id);
|
|
3554
|
+
const previousVC = array[index - 1];
|
|
3555
|
+
if (previousVC && vc.index !== previousVC.index + 1) {
|
|
3556
|
+
acc.push(
|
|
3557
|
+
/* @__PURE__ */ jsx10(
|
|
3558
|
+
"div",
|
|
3559
|
+
{
|
|
3560
|
+
role: "presentation",
|
|
3561
|
+
style: {
|
|
3562
|
+
display: "flex",
|
|
3563
|
+
width: `${vc.start - previousVC.end}px`
|
|
3564
|
+
}
|
|
3565
|
+
},
|
|
3566
|
+
`padding-${previousVC.index}-${vc.index}`
|
|
3567
|
+
)
|
|
3568
|
+
);
|
|
3569
|
+
}
|
|
3570
|
+
acc.push(
|
|
3571
|
+
/* @__PURE__ */ jsx10(
|
|
3572
|
+
DataGridCell,
|
|
3573
|
+
{
|
|
3574
|
+
cell,
|
|
3575
|
+
columnIndex,
|
|
3576
|
+
rowIndex,
|
|
3577
|
+
anchor,
|
|
3578
|
+
onDragToFillStart,
|
|
3579
|
+
multiColumnSelection
|
|
3580
|
+
},
|
|
3581
|
+
cell.id
|
|
3582
|
+
)
|
|
3583
|
+
);
|
|
3584
|
+
return acc;
|
|
3585
|
+
}, []),
|
|
3586
|
+
virtualPaddingRight ? /* @__PURE__ */ jsx10(
|
|
3587
|
+
"div",
|
|
3588
|
+
{
|
|
3589
|
+
role: "presentation",
|
|
3590
|
+
style: { display: "flex", width: virtualPaddingRight }
|
|
3591
|
+
}
|
|
3592
|
+
) : null
|
|
3593
|
+
]
|
|
3594
|
+
}
|
|
3595
|
+
);
|
|
3596
|
+
};
|
|
3597
|
+
var DataGridRowSkeleton = ({
|
|
3598
|
+
virtualRow,
|
|
3599
|
+
virtualPaddingLeft,
|
|
3600
|
+
virtualPaddingRight,
|
|
3601
|
+
virtualColumns
|
|
3602
|
+
}) => {
|
|
3603
|
+
return /* @__PURE__ */ jsxs7(
|
|
3604
|
+
"div",
|
|
3605
|
+
{
|
|
3606
|
+
role: "row",
|
|
3607
|
+
"aria-rowindex": virtualRow.index,
|
|
3608
|
+
style: {
|
|
3609
|
+
transform: `translateY(${virtualRow.start}px)`
|
|
3610
|
+
},
|
|
3611
|
+
className: "bg-ui-bg-subtle txt-compact-small absolute flex h-10 w-full",
|
|
3612
|
+
children: [
|
|
3613
|
+
virtualPaddingLeft ? /* @__PURE__ */ jsx10(
|
|
3614
|
+
"div",
|
|
3615
|
+
{
|
|
3616
|
+
role: "presentation",
|
|
3617
|
+
style: { display: "flex", width: virtualPaddingLeft }
|
|
3618
|
+
}
|
|
3619
|
+
) : null,
|
|
3620
|
+
virtualColumns.map((vc, index, array) => {
|
|
3621
|
+
const previousVC = array[index - 1];
|
|
3622
|
+
const elements = [];
|
|
3623
|
+
if (previousVC && vc.index !== previousVC.index + 1) {
|
|
3624
|
+
elements.push(
|
|
3625
|
+
/* @__PURE__ */ jsx10(
|
|
3626
|
+
"div",
|
|
3627
|
+
{
|
|
3628
|
+
role: "presentation",
|
|
3629
|
+
style: {
|
|
3630
|
+
display: "flex",
|
|
3631
|
+
width: `${vc.start - previousVC.end}px`
|
|
3632
|
+
}
|
|
3633
|
+
},
|
|
3634
|
+
`padding-${previousVC.index}-${vc.index}`
|
|
3635
|
+
)
|
|
3636
|
+
);
|
|
3637
|
+
}
|
|
3638
|
+
elements.push(
|
|
3639
|
+
/* @__PURE__ */ jsx10(
|
|
3640
|
+
"div",
|
|
3641
|
+
{
|
|
3642
|
+
role: "gridcell",
|
|
3643
|
+
style: { width: vc.size },
|
|
3644
|
+
className: "relative flex items-center border-b border-r p-0 outline-none",
|
|
3645
|
+
children: /* @__PURE__ */ jsx10("div", { className: "flex h-full w-full items-center px-4", children: /* @__PURE__ */ jsx10("div", { className: "bg-ui-bg-component h-4 w-3/4 animate-pulse rounded" }) })
|
|
3646
|
+
},
|
|
3647
|
+
`skeleton-cell-${vc.index}`
|
|
3648
|
+
)
|
|
3649
|
+
);
|
|
3650
|
+
return elements;
|
|
3651
|
+
}),
|
|
3652
|
+
virtualPaddingRight ? /* @__PURE__ */ jsx10(
|
|
3653
|
+
"div",
|
|
3654
|
+
{
|
|
3655
|
+
role: "presentation",
|
|
3656
|
+
style: { display: "flex", width: virtualPaddingRight }
|
|
3657
|
+
}
|
|
3658
|
+
) : null
|
|
3659
|
+
]
|
|
3660
|
+
}
|
|
3661
|
+
);
|
|
3662
|
+
};
|
|
3663
|
+
|
|
3664
|
+
// src/components/data-grid/components/data-grid-text-cell.tsx
|
|
3665
|
+
import { clx as clx7 } from "@medusajs/ui";
|
|
3666
|
+
import { useEffect as useEffect7, useRef as useRef5, useState as useState10 } from "react";
|
|
3667
|
+
import { Controller as Controller5 } from "react-hook-form";
|
|
3668
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
3669
|
+
var DataGridTextCell = ({
|
|
3670
|
+
context
|
|
3671
|
+
}) => {
|
|
3672
|
+
const { field, control, renderProps } = useDataGridCell({
|
|
3673
|
+
context
|
|
3674
|
+
});
|
|
3675
|
+
const errorProps = useDataGridCellError({ context });
|
|
3676
|
+
const { container, input } = renderProps;
|
|
3677
|
+
return /* @__PURE__ */ jsx11(
|
|
3678
|
+
Controller5,
|
|
3679
|
+
{
|
|
3680
|
+
control,
|
|
3681
|
+
name: field,
|
|
3682
|
+
render: ({ field: field2 }) => {
|
|
3683
|
+
return /* @__PURE__ */ jsx11(DataGridCellContainer, { ...container, ...errorProps, children: /* @__PURE__ */ jsx11(Inner5, { field: field2, inputProps: input }) });
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
);
|
|
3687
|
+
};
|
|
3688
|
+
var Inner5 = ({
|
|
3689
|
+
field,
|
|
3690
|
+
inputProps
|
|
3691
|
+
}) => {
|
|
3692
|
+
const { onChange: _, onBlur, ref, value, ...rest } = field;
|
|
3693
|
+
const { ref: inputRef, onBlur: onInputBlur, onChange, ...input } = inputProps;
|
|
3694
|
+
const [localValue, setLocalValue] = useState10(value);
|
|
3695
|
+
const inputElRef = useRef5(null);
|
|
3696
|
+
useEffect7(() => {
|
|
3697
|
+
setLocalValue(value);
|
|
3698
|
+
}, [value]);
|
|
3699
|
+
const combinedRefs = useCombinedRefs(inputRef, ref, inputElRef);
|
|
3700
|
+
return /* @__PURE__ */ jsx11(
|
|
3701
|
+
"input",
|
|
3702
|
+
{
|
|
3703
|
+
className: clx7(
|
|
3704
|
+
"txt-compact-small text-ui-fg-subtle flex size-full cursor-pointer bg-transparent outline-none",
|
|
3705
|
+
"focus:cursor-text",
|
|
3706
|
+
"items-center justify-center"
|
|
3707
|
+
),
|
|
3708
|
+
autoComplete: "off",
|
|
3709
|
+
tabIndex: -1,
|
|
3710
|
+
value: localValue ?? "",
|
|
3711
|
+
onChange: (e) => setLocalValue(e.target.value),
|
|
3712
|
+
ref: combinedRefs,
|
|
3713
|
+
onBlur: () => {
|
|
3714
|
+
onBlur();
|
|
3715
|
+
onInputBlur();
|
|
3716
|
+
onChange(localValue, value);
|
|
3717
|
+
},
|
|
3718
|
+
...input,
|
|
3719
|
+
...rest
|
|
3720
|
+
}
|
|
3721
|
+
);
|
|
3722
|
+
};
|
|
3723
|
+
|
|
3724
|
+
// src/components/data-grid/components/data-grid-textarea-modal-cell.tsx
|
|
3725
|
+
import { clx as clx8, Textarea } from "@medusajs/ui";
|
|
3726
|
+
import { Popover as RadixPopover } from "radix-ui";
|
|
3727
|
+
import { useCallback as useCallback16, useEffect as useEffect8, useRef as useRef6, useState as useState11 } from "react";
|
|
3728
|
+
import { Controller as Controller6 } from "react-hook-form";
|
|
3729
|
+
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
3730
|
+
var DataGridExpandableTextCell = ({
|
|
3731
|
+
context,
|
|
3732
|
+
fieldLabel
|
|
3733
|
+
}) => {
|
|
3734
|
+
const { field, control, renderProps } = useDataGridCell({
|
|
3735
|
+
context
|
|
3736
|
+
});
|
|
3737
|
+
const errorProps = useDataGridCellError({ context });
|
|
3738
|
+
const { container, input } = renderProps;
|
|
3739
|
+
return /* @__PURE__ */ jsx12(
|
|
3740
|
+
Controller6,
|
|
3741
|
+
{
|
|
3742
|
+
control,
|
|
3743
|
+
name: field,
|
|
3744
|
+
render: ({ field: field2 }) => {
|
|
3745
|
+
return /* @__PURE__ */ jsx12(
|
|
3746
|
+
Inner6,
|
|
3747
|
+
{
|
|
3748
|
+
field: field2,
|
|
3749
|
+
inputProps: input,
|
|
3750
|
+
fieldLabel,
|
|
3751
|
+
container,
|
|
3752
|
+
errorProps
|
|
3753
|
+
}
|
|
3754
|
+
);
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
);
|
|
3758
|
+
};
|
|
3759
|
+
var Inner6 = ({
|
|
3760
|
+
field,
|
|
3761
|
+
inputProps,
|
|
3762
|
+
fieldLabel: _fieldLabel,
|
|
3763
|
+
container,
|
|
3764
|
+
errorProps
|
|
3765
|
+
}) => {
|
|
3766
|
+
const { onChange: _, onBlur, ref, value, ...rest } = field;
|
|
3767
|
+
const { ref: inputRef, onBlur: onInputBlur, onChange, ...input } = inputProps;
|
|
3768
|
+
const { setSingleRange, anchor } = useDataGridContext();
|
|
3769
|
+
const { row, col } = anchor || { row: 0, col: 0 };
|
|
3770
|
+
const [localValue, setLocalValue] = useState11(value || "");
|
|
3771
|
+
const [isPopoverOpen, setIsPopoverOpen] = useState11(false);
|
|
3772
|
+
const [popoverValue, setPopoverValue] = useState11(value || "");
|
|
3773
|
+
const popoverContentRef = useRef6(null);
|
|
3774
|
+
useEffect8(() => {
|
|
3775
|
+
setLocalValue(value || "");
|
|
3776
|
+
}, [value]);
|
|
3777
|
+
useEffect8(() => {
|
|
3778
|
+
if (isPopoverOpen) {
|
|
3779
|
+
setPopoverValue(value || "");
|
|
3780
|
+
}
|
|
3781
|
+
}, [isPopoverOpen, value]);
|
|
3782
|
+
useEffect8(() => {
|
|
3783
|
+
if (!isPopoverOpen || !popoverContentRef.current) {
|
|
3784
|
+
return;
|
|
3785
|
+
}
|
|
3786
|
+
const handleKeyDownCapture = (e) => {
|
|
3787
|
+
const target = e.target;
|
|
3788
|
+
const isTextarea = target.tagName === "TEXTAREA";
|
|
3789
|
+
const isInPopover = popoverContentRef.current && popoverContentRef.current.contains(target);
|
|
3790
|
+
if (isTextarea || isInPopover) {
|
|
3791
|
+
const dataGridKeys = [
|
|
3792
|
+
"Enter",
|
|
3793
|
+
"Delete",
|
|
3794
|
+
"Backspace",
|
|
3795
|
+
"ArrowUp",
|
|
3796
|
+
"ArrowDown",
|
|
3797
|
+
"ArrowLeft",
|
|
3798
|
+
"ArrowRight",
|
|
3799
|
+
"Tab",
|
|
3800
|
+
" "
|
|
3801
|
+
];
|
|
3802
|
+
if (dataGridKeys.includes(e.key) && e.key !== "Escape") {
|
|
3803
|
+
e.stopImmediatePropagation();
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
};
|
|
3807
|
+
window.addEventListener("keydown", handleKeyDownCapture, true);
|
|
3808
|
+
return () => {
|
|
3809
|
+
window.removeEventListener("keydown", handleKeyDownCapture, true);
|
|
3810
|
+
};
|
|
3811
|
+
}, [isPopoverOpen]);
|
|
3812
|
+
const combinedRefs = useCombinedRefs(inputRef, ref);
|
|
3813
|
+
const handleOverlayMouseDown = useCallback16(
|
|
3814
|
+
(e) => {
|
|
3815
|
+
if (e.detail === 2) {
|
|
3816
|
+
e.preventDefault();
|
|
3817
|
+
e.stopPropagation();
|
|
3818
|
+
setSingleRange({ row, col });
|
|
3819
|
+
setIsPopoverOpen(true);
|
|
3820
|
+
return;
|
|
3821
|
+
}
|
|
3822
|
+
container.overlayProps.onMouseDown?.(e);
|
|
3823
|
+
},
|
|
3824
|
+
[container.overlayProps, setSingleRange, row, col]
|
|
3825
|
+
);
|
|
3826
|
+
const customContainer = {
|
|
3827
|
+
...container,
|
|
3828
|
+
overlayProps: {
|
|
3829
|
+
...container.overlayProps,
|
|
3830
|
+
onMouseDown: handleOverlayMouseDown
|
|
3831
|
+
}
|
|
3832
|
+
};
|
|
3833
|
+
const handlePopoverSave = () => {
|
|
3834
|
+
onChange(popoverValue, value);
|
|
3835
|
+
setLocalValue(popoverValue);
|
|
3836
|
+
setIsPopoverOpen(false);
|
|
3837
|
+
onBlur();
|
|
3838
|
+
onInputBlur();
|
|
3839
|
+
};
|
|
3840
|
+
const handlePopoverKeyDown = useCallback16((e) => {
|
|
3841
|
+
if (e.key !== "Escape") {
|
|
3842
|
+
e.stopPropagation();
|
|
3843
|
+
}
|
|
3844
|
+
}, []);
|
|
3845
|
+
const displayValue = localValue || "";
|
|
3846
|
+
const truncatedValue = displayValue.length > 50 ? `${displayValue.substring(0, 50)}...` : displayValue;
|
|
3847
|
+
return /* @__PURE__ */ jsxs8(
|
|
3848
|
+
RadixPopover.Root,
|
|
3849
|
+
{
|
|
3850
|
+
open: isPopoverOpen,
|
|
3851
|
+
onOpenChange: (open) => {
|
|
3852
|
+
if (!open) {
|
|
3853
|
+
handlePopoverSave();
|
|
3854
|
+
} else {
|
|
3855
|
+
setIsPopoverOpen(true);
|
|
3856
|
+
}
|
|
3857
|
+
},
|
|
3858
|
+
children: [
|
|
3859
|
+
/* @__PURE__ */ jsxs8(DataGridCellContainer, { ...customContainer, ...errorProps, children: [
|
|
3860
|
+
/* @__PURE__ */ jsx12(RadixPopover.Anchor, { asChild: true, children: /* @__PURE__ */ jsx12(
|
|
3861
|
+
"div",
|
|
3862
|
+
{
|
|
3863
|
+
className: clx8(
|
|
3864
|
+
"txt-compact-small text-ui-fg-subtle flex size-full cursor-pointer items-center justify-center bg-transparent outline-none",
|
|
3865
|
+
"focus:cursor-text"
|
|
3866
|
+
),
|
|
3867
|
+
children: /* @__PURE__ */ jsx12("span", { className: "w-full truncate text-center", children: truncatedValue })
|
|
3868
|
+
}
|
|
3869
|
+
) }),
|
|
3870
|
+
/* @__PURE__ */ jsx12(
|
|
3871
|
+
"input",
|
|
3872
|
+
{
|
|
3873
|
+
className: "sr-only",
|
|
3874
|
+
autoComplete: "off",
|
|
3875
|
+
tabIndex: -1,
|
|
3876
|
+
value: localValue,
|
|
3877
|
+
onChange: (e) => setLocalValue(e.target.value),
|
|
3878
|
+
ref: combinedRefs,
|
|
3879
|
+
onBlur: () => {
|
|
3880
|
+
onBlur();
|
|
3881
|
+
onInputBlur();
|
|
3882
|
+
onChange(localValue, value);
|
|
3883
|
+
},
|
|
3884
|
+
...input,
|
|
3885
|
+
...rest
|
|
3886
|
+
}
|
|
3887
|
+
)
|
|
3888
|
+
] }),
|
|
3889
|
+
/* @__PURE__ */ jsx12(RadixPopover.Portal, { children: /* @__PURE__ */ jsx12(
|
|
3890
|
+
RadixPopover.Content,
|
|
3891
|
+
{
|
|
3892
|
+
className: clx8(
|
|
3893
|
+
"bg-ui-bg-base shadow-elevation-flyout flex max-h-[80vh] w-[600px] overflow-hidden p-0 outline-none"
|
|
3894
|
+
),
|
|
3895
|
+
align: "start",
|
|
3896
|
+
side: "bottom",
|
|
3897
|
+
sideOffset: -29,
|
|
3898
|
+
alignOffset: -16,
|
|
3899
|
+
collisionPadding: 24,
|
|
3900
|
+
onEscapeKeyDown: handlePopoverSave,
|
|
3901
|
+
onKeyDown: handlePopoverKeyDown,
|
|
3902
|
+
children: /* @__PURE__ */ jsx12("div", { ref: popoverContentRef, className: "h-full w-full", children: /* @__PURE__ */ jsx12(
|
|
3903
|
+
Textarea,
|
|
3904
|
+
{
|
|
3905
|
+
value: popoverValue,
|
|
3906
|
+
onChange: (e) => setPopoverValue(e.target.value),
|
|
3907
|
+
onKeyDown: (e) => {
|
|
3908
|
+
e.stopPropagation();
|
|
3909
|
+
},
|
|
3910
|
+
className: "!bg-ui-bg-base h-full min-h-[300px] w-full resize-none border-0 p-4 !shadow-none focus-visible:!shadow-none"
|
|
3911
|
+
}
|
|
3912
|
+
) })
|
|
3913
|
+
}
|
|
3914
|
+
) })
|
|
3915
|
+
]
|
|
3916
|
+
}
|
|
3917
|
+
);
|
|
3918
|
+
};
|
|
3919
|
+
|
|
3920
|
+
// src/components/data-grid/data-grid.tsx
|
|
3921
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
3922
|
+
var _DataGrid = ({
|
|
3923
|
+
isLoading,
|
|
3924
|
+
// Lazy loading props - passed through to DataGridRoot
|
|
3925
|
+
totalRowCount,
|
|
3926
|
+
onFetchMore,
|
|
3927
|
+
isFetchingMore,
|
|
3928
|
+
hasNextPage,
|
|
3929
|
+
...props
|
|
3930
|
+
}) => {
|
|
3931
|
+
return isLoading ? /* @__PURE__ */ jsx13(
|
|
3932
|
+
DataGridSkeleton,
|
|
3933
|
+
{
|
|
3934
|
+
columns: props.columns,
|
|
3935
|
+
rows: props.data?.length && props.data.length > 0 ? props.data.length : 10
|
|
3936
|
+
}
|
|
3937
|
+
) : /* @__PURE__ */ jsx13(
|
|
3938
|
+
DataGridRoot,
|
|
3939
|
+
{
|
|
3940
|
+
...props,
|
|
3941
|
+
totalRowCount,
|
|
3942
|
+
onFetchMore,
|
|
3943
|
+
isFetchingMore,
|
|
3944
|
+
hasNextPage
|
|
3945
|
+
}
|
|
3946
|
+
);
|
|
3947
|
+
};
|
|
3948
|
+
var DataGrid = Object.assign(_DataGrid, {
|
|
3949
|
+
BooleanCell: DataGridBooleanCell,
|
|
3950
|
+
TextCell: DataGridTextCell,
|
|
3951
|
+
MultilineCell: DataGridMultilineCell,
|
|
3952
|
+
ExpandableTextCell: DataGridExpandableTextCell,
|
|
3953
|
+
NumberCell: DataGridNumberCell,
|
|
3954
|
+
CurrencyCell: DataGridCurrencyCell,
|
|
3955
|
+
ReadonlyCell: DataGridReadonlyCell
|
|
3956
|
+
});
|
|
3957
|
+
|
|
3958
|
+
// src/components/data-grid/helpers/create-data-grid-column-helper.ts
|
|
3959
|
+
import {
|
|
3960
|
+
createColumnHelper
|
|
3961
|
+
} from "@tanstack/react-table";
|
|
3962
|
+
function createDataGridHelper() {
|
|
3963
|
+
const columnHelper = createColumnHelper();
|
|
3964
|
+
return {
|
|
3965
|
+
column: ({
|
|
3966
|
+
id,
|
|
3967
|
+
name,
|
|
3968
|
+
header,
|
|
3969
|
+
cell,
|
|
3970
|
+
disableHiding = false,
|
|
3971
|
+
field,
|
|
3972
|
+
type,
|
|
3973
|
+
size,
|
|
3974
|
+
minSize,
|
|
3975
|
+
maxSize
|
|
3976
|
+
}) => columnHelper.display({
|
|
3977
|
+
id,
|
|
3978
|
+
header,
|
|
3979
|
+
cell,
|
|
3980
|
+
enableHiding: !disableHiding,
|
|
3981
|
+
size,
|
|
3982
|
+
minSize,
|
|
3983
|
+
maxSize,
|
|
3984
|
+
meta: {
|
|
3985
|
+
name,
|
|
3986
|
+
field,
|
|
3987
|
+
type
|
|
3988
|
+
}
|
|
3989
|
+
})
|
|
3990
|
+
};
|
|
3991
|
+
}
|
|
3992
|
+
|
|
3993
|
+
// src/components/common/tax-badge/tax-badge.tsx
|
|
3994
|
+
import { TaxExclusive, TaxInclusive } from "@medusajs/icons";
|
|
3995
|
+
import { Tooltip as Tooltip3 } from "@medusajs/ui";
|
|
3996
|
+
import { useTranslation as useTranslation4 } from "react-i18next";
|
|
3997
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
3998
|
+
var IncludesTaxTooltip = ({
|
|
3999
|
+
includesTax
|
|
4000
|
+
}) => {
|
|
4001
|
+
const { t } = useTranslation4();
|
|
4002
|
+
return /* @__PURE__ */ jsx14(
|
|
4003
|
+
Tooltip3,
|
|
4004
|
+
{
|
|
4005
|
+
maxWidth: 999,
|
|
4006
|
+
content: includesTax ? t("general.includesTaxTooltip") : t("general.excludesTaxTooltip"),
|
|
4007
|
+
children: includesTax ? /* @__PURE__ */ jsx14(TaxInclusive, { className: "text-ui-fg-muted shrink-0" }) : /* @__PURE__ */ jsx14(TaxExclusive, { className: "text-ui-fg-muted shrink-0" })
|
|
4008
|
+
}
|
|
4009
|
+
);
|
|
4010
|
+
};
|
|
4011
|
+
|
|
4012
|
+
// src/components/data-grid/helpers/create-data-grid-price-columns.tsx
|
|
4013
|
+
import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
4014
|
+
var createDataGridPriceColumns = ({
|
|
4015
|
+
currencies: currencies2,
|
|
4016
|
+
regions,
|
|
4017
|
+
pricePreferences,
|
|
4018
|
+
isReadyOnly,
|
|
4019
|
+
getFieldName,
|
|
4020
|
+
t
|
|
4021
|
+
}) => {
|
|
4022
|
+
const columnHelper = createDataGridHelper();
|
|
4023
|
+
return [
|
|
4024
|
+
...currencies2?.map((currency) => {
|
|
4025
|
+
const preference = pricePreferences?.find(
|
|
4026
|
+
(p) => p.attribute === "currency_code" && p.value === currency
|
|
4027
|
+
);
|
|
4028
|
+
const translatedCurrencyName = t("fields.priceTemplate", {
|
|
4029
|
+
regionOrCurrency: currency.toUpperCase()
|
|
4030
|
+
});
|
|
4031
|
+
return columnHelper.column({
|
|
4032
|
+
id: `currency_prices.${currency}`,
|
|
4033
|
+
name: t("fields.priceTemplate", {
|
|
4034
|
+
regionOrCurrency: currency.toUpperCase()
|
|
4035
|
+
}),
|
|
4036
|
+
field: (context) => {
|
|
4037
|
+
const isReadyOnlyValue = isReadyOnly?.(context);
|
|
4038
|
+
if (isReadyOnlyValue) {
|
|
4039
|
+
return null;
|
|
4040
|
+
}
|
|
4041
|
+
return getFieldName(context, currency);
|
|
4042
|
+
},
|
|
4043
|
+
type: "number",
|
|
4044
|
+
header: () => /* @__PURE__ */ jsxs9("div", { className: "flex w-full items-center justify-between gap-3", children: [
|
|
4045
|
+
/* @__PURE__ */ jsx15("span", { className: "truncate", title: translatedCurrencyName, children: translatedCurrencyName }),
|
|
4046
|
+
/* @__PURE__ */ jsx15(IncludesTaxTooltip, { includesTax: preference?.is_tax_inclusive })
|
|
4047
|
+
] }),
|
|
4048
|
+
cell: (context) => {
|
|
4049
|
+
if (isReadyOnly?.(context)) {
|
|
4050
|
+
return /* @__PURE__ */ jsx15(DataGridReadonlyCell, { context });
|
|
4051
|
+
}
|
|
4052
|
+
return /* @__PURE__ */ jsx15(DataGridCurrencyCell, { code: currency, context });
|
|
4053
|
+
}
|
|
4054
|
+
});
|
|
4055
|
+
}) ?? [],
|
|
4056
|
+
...regions?.map((region) => {
|
|
4057
|
+
const preference = pricePreferences?.find(
|
|
4058
|
+
(p) => p.attribute === "region_id" && p.value === region.id
|
|
4059
|
+
);
|
|
4060
|
+
const translatedRegionName = t("fields.priceTemplate", {
|
|
4061
|
+
regionOrCurrency: region.name
|
|
4062
|
+
});
|
|
4063
|
+
return columnHelper.column({
|
|
4064
|
+
id: `region_prices.${region.id}`,
|
|
4065
|
+
name: t("fields.priceTemplate", {
|
|
4066
|
+
regionOrCurrency: region.name
|
|
4067
|
+
}),
|
|
4068
|
+
field: (context) => {
|
|
4069
|
+
const isReadyOnlyValue = isReadyOnly?.(context);
|
|
4070
|
+
if (isReadyOnlyValue) {
|
|
4071
|
+
return null;
|
|
4072
|
+
}
|
|
4073
|
+
return getFieldName(context, region.id);
|
|
4074
|
+
},
|
|
4075
|
+
type: "number",
|
|
4076
|
+
header: () => /* @__PURE__ */ jsxs9("div", { className: "flex w-full items-center justify-between gap-3", children: [
|
|
4077
|
+
/* @__PURE__ */ jsx15("span", { className: "truncate", title: translatedRegionName, children: translatedRegionName }),
|
|
4078
|
+
/* @__PURE__ */ jsx15(IncludesTaxTooltip, { includesTax: preference?.is_tax_inclusive })
|
|
4079
|
+
] }),
|
|
4080
|
+
cell: (context) => {
|
|
4081
|
+
if (isReadyOnly?.(context)) {
|
|
4082
|
+
return /* @__PURE__ */ jsx15(DataGridReadonlyCell, { context });
|
|
4083
|
+
}
|
|
4084
|
+
const currency = currencies2?.find((c) => c === region.currency_code);
|
|
4085
|
+
if (!currency) {
|
|
4086
|
+
return null;
|
|
4087
|
+
}
|
|
4088
|
+
return /* @__PURE__ */ jsx15(
|
|
4089
|
+
DataGridCurrencyCell,
|
|
4090
|
+
{
|
|
4091
|
+
code: region.currency_code,
|
|
4092
|
+
context
|
|
4093
|
+
}
|
|
4094
|
+
);
|
|
4095
|
+
}
|
|
4096
|
+
});
|
|
4097
|
+
}) ?? []
|
|
4098
|
+
];
|
|
4099
|
+
};
|
|
4100
|
+
|
|
4101
|
+
export {
|
|
4102
|
+
useCombinedRefs,
|
|
4103
|
+
useDataGridCell,
|
|
4104
|
+
useDataGridCellError,
|
|
4105
|
+
useDataGridDuplicateCell,
|
|
4106
|
+
DataGridCellContainer,
|
|
4107
|
+
DataGridReadonlyCell,
|
|
4108
|
+
DataGridSkeleton,
|
|
4109
|
+
DataGrid,
|
|
4110
|
+
createDataGridHelper,
|
|
4111
|
+
IncludesTaxTooltip,
|
|
4112
|
+
createDataGridPriceColumns
|
|
4113
|
+
};
|