ivt 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/dist/accordion/index.mjs +19 -1
  2. package/dist/accordion/index.mjs.map +1 -1
  3. package/dist/alert/index.mjs +43 -1
  4. package/dist/alert/index.mjs.map +1 -1
  5. package/dist/alert-dialog/index.mjs +260 -1
  6. package/dist/alert-dialog/index.mjs.map +1 -1
  7. package/dist/avatar/index.mjs +164 -1
  8. package/dist/avatar/index.mjs.map +1 -1
  9. package/dist/badge/index.mjs +6 -1
  10. package/dist/badge/index.mjs.map +1 -1
  11. package/dist/base/index.mjs +760 -1
  12. package/dist/base/index.mjs.map +1 -1
  13. package/dist/button/index.mjs +6 -1
  14. package/dist/button/index.mjs.map +1 -1
  15. package/dist/calendar/index.mjs +11 -1
  16. package/dist/calendar/index.mjs.map +1 -1
  17. package/dist/card/index.mjs +55 -1
  18. package/dist/card/index.mjs.map +1 -1
  19. package/dist/chart/index.mjs +17042 -1
  20. package/dist/chart/index.mjs.map +1 -1
  21. package/dist/checkbox/index.mjs +223 -1
  22. package/dist/checkbox/index.mjs.map +1 -1
  23. package/dist/chunks/_commonjsHelpers-DqEvkrE1.mjs +6 -0
  24. package/dist/chunks/_commonjsHelpers-DqEvkrE1.mjs.map +1 -0
  25. package/dist/chunks/accordion-BMP2PSSC.mjs +455 -0
  26. package/dist/chunks/{accordion-CdshDFZC.mjs.map → accordion-BMP2PSSC.mjs.map} +1 -1
  27. package/dist/chunks/badge-DxuZhgBF.mjs +57 -0
  28. package/dist/chunks/{badge-BYqshEmA.mjs.map → badge-DxuZhgBF.mjs.map} +1 -1
  29. package/dist/chunks/bundle-mjs-tFg__FnT.mjs +4491 -0
  30. package/dist/chunks/{bundle-mjs-9BXytT_r.mjs.map → bundle-mjs-tFg__FnT.mjs.map} +1 -1
  31. package/dist/chunks/button-CX0htulo.mjs +47 -0
  32. package/dist/chunks/{button-DrFZXJ7z.mjs.map → button-CX0htulo.mjs.map} +1 -1
  33. package/dist/chunks/calendar-B4IV5RyM.mjs +7106 -0
  34. package/dist/chunks/calendar-B4IV5RyM.mjs.map +1 -0
  35. package/dist/chunks/check-B7209s3e.mjs +15 -0
  36. package/dist/chunks/{check-CimnOyD7.mjs.map → check-B7209s3e.mjs.map} +1 -1
  37. package/dist/chunks/chevron-down-D84DRJBv.mjs +15 -0
  38. package/dist/chunks/{chevron-down-D3fvbjxE.mjs.map → chevron-down-D84DRJBv.mjs.map} +1 -1
  39. package/dist/chunks/chevron-left-DtL1t1DJ.mjs +15 -0
  40. package/dist/chunks/{chevron-left-CrN7DlXg.mjs.map → chevron-left-DtL1t1DJ.mjs.map} +1 -1
  41. package/dist/chunks/chevron-right-Cdxg1JSQ.mjs +15 -0
  42. package/dist/chunks/{chevron-right-BMSCuDGK.mjs.map → chevron-right-Cdxg1JSQ.mjs.map} +1 -1
  43. package/dist/chunks/chevrons-up-down-DtBUG1i8.mjs +22 -0
  44. package/dist/chunks/{chevrons-up-down-DBgvRkZm.mjs.map → chevrons-up-down-DtBUG1i8.mjs.map} +1 -1
  45. package/dist/chunks/circle-BLWMZ9yp.mjs +17 -0
  46. package/dist/chunks/{circle-CGqt18Bd.mjs.map → circle-BLWMZ9yp.mjs.map} +1 -1
  47. package/dist/chunks/command-C8cVzg-x.mjs +611 -0
  48. package/dist/chunks/command-C8cVzg-x.mjs.map +1 -0
  49. package/dist/chunks/createLucideIcon-Ba0IWqsz.mjs +60 -0
  50. package/dist/chunks/{createLucideIcon-L-tld2uc.mjs.map → createLucideIcon-Ba0IWqsz.mjs.map} +1 -1
  51. package/dist/chunks/dialog-D9vbxUuQ.mjs +80 -0
  52. package/dist/chunks/{dialog-36eqHzT3.mjs.map → dialog-D9vbxUuQ.mjs.map} +1 -1
  53. package/dist/chunks/hover-card-idvDPXrI.mjs +274 -0
  54. package/dist/chunks/{hover-card-Cnd58du6.mjs.map → hover-card-idvDPXrI.mjs.map} +1 -1
  55. package/dist/chunks/index-6JUj2Tld.mjs +18 -0
  56. package/dist/chunks/{index-CRxQlsb9.mjs.map → index-6JUj2Tld.mjs.map} +1 -1
  57. package/dist/chunks/index-B0IElWB4.mjs +51 -0
  58. package/dist/chunks/{index-vmPXTidH.mjs.map → index-B0IElWB4.mjs.map} +1 -1
  59. package/dist/chunks/index-B4VRyyD1.mjs +40 -0
  60. package/dist/chunks/index-B4VRyyD1.mjs.map +1 -0
  61. package/dist/chunks/index-BE-_q4IW.mjs +266 -0
  62. package/dist/chunks/index-BE-_q4IW.mjs.map +1 -0
  63. package/dist/chunks/index-BNxaLFA6.mjs +216 -0
  64. package/dist/chunks/{index-LvOFIVGz.mjs.map → index-BNxaLFA6.mjs.map} +1 -1
  65. package/dist/chunks/index-BZUrHhU8.mjs +7 -0
  66. package/dist/chunks/{index-CLtWFQL5.mjs.map → index-BZUrHhU8.mjs.map} +1 -1
  67. package/dist/chunks/index-B_FsTtnF.mjs +110 -0
  68. package/dist/chunks/{index-CCcl327A.mjs.map → index-B_FsTtnF.mjs.map} +1 -1
  69. package/dist/chunks/index-CAg47KJ6.mjs +13 -0
  70. package/dist/chunks/{index-CXszXOf_.mjs.map → index-CAg47KJ6.mjs.map} +1 -1
  71. package/dist/chunks/index-CXuEm8w1.mjs +12 -0
  72. package/dist/chunks/{index-CU_y1XAz.mjs.map → index-CXuEm8w1.mjs.map} +1 -1
  73. package/dist/chunks/index-C_jFwfR_.mjs +77 -0
  74. package/dist/chunks/{index-CybgQKpz.mjs.map → index-C_jFwfR_.mjs.map} +1 -1
  75. package/dist/chunks/index-CglX-DNW.mjs +21 -0
  76. package/dist/chunks/index-CglX-DNW.mjs.map +1 -0
  77. package/dist/chunks/index-CyMuypYR.mjs +324 -0
  78. package/dist/chunks/{index-DUNcuWJE.mjs.map → index-CyMuypYR.mjs.map} +1 -1
  79. package/dist/chunks/index-D0S6rRRE.mjs +50 -0
  80. package/dist/chunks/{index-w9bxia3O.mjs.map → index-D0S6rRRE.mjs.map} +1 -1
  81. package/dist/chunks/index-D23BhVQG.mjs +859 -0
  82. package/dist/chunks/{index-DZHMFdr0.mjs.map → index-D23BhVQG.mjs.map} +1 -1
  83. package/dist/chunks/index-D2wfJaZh.mjs +145 -0
  84. package/dist/chunks/index-D2wfJaZh.mjs.map +1 -0
  85. package/dist/chunks/index-DNvm9MP3.mjs +34 -0
  86. package/dist/chunks/{index-D2sZp5OP.mjs.map → index-DNvm9MP3.mjs.map} +1 -1
  87. package/dist/chunks/index-Dm4_czlz.mjs +12 -0
  88. package/dist/chunks/index-Dm4_czlz.mjs.map +1 -0
  89. package/dist/chunks/index-PaJVyocC.mjs +151 -0
  90. package/dist/chunks/index-PaJVyocC.mjs.map +1 -0
  91. package/dist/chunks/index-kr6_v_F8.mjs +2370 -0
  92. package/dist/chunks/index-kr6_v_F8.mjs.map +1 -0
  93. package/dist/chunks/index-sz_BcBbA.mjs +1210 -0
  94. package/dist/chunks/index-sz_BcBbA.mjs.map +1 -0
  95. package/dist/chunks/input-DK1slFF1.mjs +14 -0
  96. package/dist/chunks/{input-85UFztMJ.mjs.map → input-DK1slFF1.mjs.map} +1 -1
  97. package/dist/chunks/label-D7ONQdHc.mjs +32 -0
  98. package/dist/chunks/{label-CICFzZIt.mjs.map → label-D7ONQdHc.mjs.map} +1 -1
  99. package/dist/chunks/pagination-BM_IQ6Qk.mjs +106 -0
  100. package/dist/chunks/{pagination-CReDQes6.mjs.map → pagination-BM_IQ6Qk.mjs.map} +1 -1
  101. package/dist/chunks/popover-D3F326FR.mjs +308 -0
  102. package/dist/chunks/{popover-Cn2ZTvKd.mjs.map → popover-D3F326FR.mjs.map} +1 -1
  103. package/dist/chunks/progress-BCl5yD5Q.mjs +99 -0
  104. package/dist/chunks/{progress-CSxQH6-f.mjs.map → progress-BCl5yD5Q.mjs.map} +1 -1
  105. package/dist/chunks/scroll-area-DB3eUx8V.mjs +791 -0
  106. package/dist/chunks/scroll-area-DB3eUx8V.mjs.map +1 -0
  107. package/dist/chunks/select-Cw81y8pT.mjs +104 -0
  108. package/dist/chunks/{select-BR6_N_Yo.mjs.map → select-Cw81y8pT.mjs.map} +1 -1
  109. package/dist/chunks/separator-2k1C7RSn.mjs +48 -0
  110. package/dist/chunks/{separator-BB6-E9Z1.mjs.map → separator-2k1C7RSn.mjs.map} +1 -1
  111. package/dist/chunks/skeleton-qx8-vr62.mjs +13 -0
  112. package/dist/chunks/{skeleton-XPWWiaac.mjs.map → skeleton-qx8-vr62.mjs.map} +1 -1
  113. package/dist/chunks/sortable-D8ayoe_b.mjs +4221 -0
  114. package/dist/chunks/sortable-D8ayoe_b.mjs.map +1 -0
  115. package/dist/chunks/table-BDNUhtz-.mjs +62 -0
  116. package/dist/chunks/{table-LQIHzPHi.mjs.map → table-BDNUhtz-.mjs.map} +1 -1
  117. package/dist/chunks/toggle-CE2ycSdL.mjs +65 -0
  118. package/dist/chunks/{toggle-Co72WXGd.mjs.map → toggle-CE2ycSdL.mjs.map} +1 -1
  119. package/dist/chunks/tooltip-DLD0ycR4.mjs +596 -0
  120. package/dist/chunks/{tooltip-qX2HjdJP.mjs.map → tooltip-DLD0ycR4.mjs.map} +1 -1
  121. package/dist/chunks/tslib.es6-BgHLrbno.mjs +61 -0
  122. package/dist/chunks/{tslib.es6-cMGqxriw.mjs.map → tslib.es6-BgHLrbno.mjs.map} +1 -1
  123. package/dist/chunks/utils-BUelq9Ro.mjs +42 -0
  124. package/dist/chunks/utils-BUelq9Ro.mjs.map +1 -0
  125. package/dist/chunks/x-Bjz0Vo6R.mjs +22 -0
  126. package/dist/chunks/{x-BNLl0E-E.mjs.map → x-Bjz0Vo6R.mjs.map} +1 -1
  127. package/dist/combobox/index.mjs +65 -1
  128. package/dist/combobox/index.mjs.map +1 -1
  129. package/dist/command/index.mjs +23 -1
  130. package/dist/command/index.mjs.map +1 -1
  131. package/dist/data-table/index.mjs +673 -1
  132. package/dist/data-table/index.mjs.map +1 -1
  133. package/dist/dialog/index.mjs +22 -1
  134. package/dist/dialog/index.mjs.map +1 -1
  135. package/dist/dropdown-menu/index.mjs +438 -1
  136. package/dist/dropdown-menu/index.mjs.map +1 -1
  137. package/dist/dropzone/index.mjs +7839 -1
  138. package/dist/dropzone/index.mjs.map +1 -1
  139. package/dist/form/index.mjs +649 -1
  140. package/dist/form/index.mjs.map +1 -1
  141. package/dist/hover-card/index.mjs +18 -1
  142. package/dist/hover-card/index.mjs.map +1 -1
  143. package/dist/icon/index.mjs +317 -1
  144. package/dist/icon/index.mjs.map +1 -1
  145. package/dist/index.css +1 -1
  146. package/dist/input/index.mjs +4 -1
  147. package/dist/input/index.mjs.map +1 -1
  148. package/dist/ivt.css +1 -1
  149. package/dist/label/index.mjs +8 -1
  150. package/dist/label/index.mjs.map +1 -1
  151. package/dist/menubar/index.mjs +583 -1
  152. package/dist/menubar/index.mjs.map +1 -1
  153. package/dist/multi-select/index.mjs +297 -1
  154. package/dist/multi-select/index.mjs.map +1 -1
  155. package/dist/pagination/index.mjs +10 -1
  156. package/dist/pagination/index.mjs.map +1 -1
  157. package/dist/popover/index.mjs +21 -1
  158. package/dist/popover/index.mjs.map +1 -1
  159. package/dist/progress/index.mjs +9 -1
  160. package/dist/progress/index.mjs.map +1 -1
  161. package/dist/radio-group/index.mjs +267 -1
  162. package/dist/radio-group/index.mjs.map +1 -1
  163. package/dist/scroll-area/index.mjs +15 -1
  164. package/dist/scroll-area/index.mjs.map +1 -1
  165. package/dist/select/index.mjs +8 -1
  166. package/dist/select/index.mjs.map +1 -1
  167. package/dist/separator/index.mjs +8 -1
  168. package/dist/separator/index.mjs.map +1 -1
  169. package/dist/sheet/index.mjs +96 -1
  170. package/dist/sheet/index.mjs.map +1 -1
  171. package/dist/skeleton/index.mjs +4 -1
  172. package/dist/skeleton/index.mjs.map +1 -1
  173. package/dist/sonner/index.mjs +1140 -1
  174. package/dist/sonner/index.mjs.map +1 -1
  175. package/dist/sortable/index.mjs +8 -1
  176. package/dist/sortable/index.mjs.map +1 -1
  177. package/dist/table/index.mjs +4 -1
  178. package/dist/table/index.mjs.map +1 -1
  179. package/dist/tabs/index.mjs +193 -1
  180. package/dist/tabs/index.mjs.map +1 -1
  181. package/dist/textarea/index.mjs +13 -1
  182. package/dist/textarea/index.mjs.map +1 -1
  183. package/dist/toast/index.mjs +705 -1
  184. package/dist/toast/index.mjs.map +1 -1
  185. package/dist/toggle/index.mjs +12 -1
  186. package/dist/toggle/index.mjs.map +1 -1
  187. package/dist/toggle-group/index.mjs +219 -1
  188. package/dist/toggle-group/index.mjs.map +1 -1
  189. package/dist/tooltip/index.mjs +20 -1
  190. package/dist/tooltip/index.mjs.map +1 -1
  191. package/package.json +2 -2
  192. package/dist/chunks/_commonjsHelpers-6qLFzZa5.mjs +0 -2
  193. package/dist/chunks/_commonjsHelpers-6qLFzZa5.mjs.map +0 -1
  194. package/dist/chunks/accordion-CdshDFZC.mjs +0 -2
  195. package/dist/chunks/badge-BYqshEmA.mjs +0 -2
  196. package/dist/chunks/bundle-mjs-9BXytT_r.mjs +0 -2
  197. package/dist/chunks/button-DrFZXJ7z.mjs +0 -2
  198. package/dist/chunks/calendar-BY6t8wdJ.mjs +0 -2
  199. package/dist/chunks/calendar-BY6t8wdJ.mjs.map +0 -1
  200. package/dist/chunks/check-CimnOyD7.mjs +0 -2
  201. package/dist/chunks/chevron-down-D3fvbjxE.mjs +0 -2
  202. package/dist/chunks/chevron-left-CrN7DlXg.mjs +0 -2
  203. package/dist/chunks/chevron-right-BMSCuDGK.mjs +0 -2
  204. package/dist/chunks/chevrons-up-down-DBgvRkZm.mjs +0 -2
  205. package/dist/chunks/circle-CGqt18Bd.mjs +0 -2
  206. package/dist/chunks/command-C6ON-ciq.mjs +0 -2
  207. package/dist/chunks/command-C6ON-ciq.mjs.map +0 -1
  208. package/dist/chunks/createLucideIcon-L-tld2uc.mjs +0 -2
  209. package/dist/chunks/dialog-36eqHzT3.mjs +0 -2
  210. package/dist/chunks/hover-card-Cnd58du6.mjs +0 -2
  211. package/dist/chunks/index-B4QsDzeM.mjs +0 -2
  212. package/dist/chunks/index-B4QsDzeM.mjs.map +0 -1
  213. package/dist/chunks/index-BdpYc58_.mjs +0 -2
  214. package/dist/chunks/index-BdpYc58_.mjs.map +0 -1
  215. package/dist/chunks/index-CCcl327A.mjs +0 -2
  216. package/dist/chunks/index-CLtWFQL5.mjs +0 -2
  217. package/dist/chunks/index-COvW87ew.mjs +0 -2
  218. package/dist/chunks/index-COvW87ew.mjs.map +0 -1
  219. package/dist/chunks/index-CRxQlsb9.mjs +0 -2
  220. package/dist/chunks/index-CU_y1XAz.mjs +0 -2
  221. package/dist/chunks/index-CXszXOf_.mjs +0 -2
  222. package/dist/chunks/index-CdJCOoFA.mjs +0 -2
  223. package/dist/chunks/index-CdJCOoFA.mjs.map +0 -1
  224. package/dist/chunks/index-Cpq7N5Ej.mjs +0 -2
  225. package/dist/chunks/index-Cpq7N5Ej.mjs.map +0 -1
  226. package/dist/chunks/index-CybgQKpz.mjs +0 -2
  227. package/dist/chunks/index-D2sZp5OP.mjs +0 -2
  228. package/dist/chunks/index-DOyt-JEx.mjs +0 -2
  229. package/dist/chunks/index-DOyt-JEx.mjs.map +0 -1
  230. package/dist/chunks/index-DUNcuWJE.mjs +0 -2
  231. package/dist/chunks/index-DZHMFdr0.mjs +0 -2
  232. package/dist/chunks/index-LvOFIVGz.mjs +0 -2
  233. package/dist/chunks/index-lvPXnk5F.mjs +0 -2
  234. package/dist/chunks/index-lvPXnk5F.mjs.map +0 -1
  235. package/dist/chunks/index-vmPXTidH.mjs +0 -2
  236. package/dist/chunks/index-w9bxia3O.mjs +0 -2
  237. package/dist/chunks/index-xew3kygQ.mjs +0 -2
  238. package/dist/chunks/index-xew3kygQ.mjs.map +0 -1
  239. package/dist/chunks/input-85UFztMJ.mjs +0 -2
  240. package/dist/chunks/label-CICFzZIt.mjs +0 -2
  241. package/dist/chunks/pagination-CReDQes6.mjs +0 -2
  242. package/dist/chunks/popover-Cn2ZTvKd.mjs +0 -2
  243. package/dist/chunks/progress-CSxQH6-f.mjs +0 -2
  244. package/dist/chunks/scroll-area-CvCz7cL_.mjs +0 -2
  245. package/dist/chunks/scroll-area-CvCz7cL_.mjs.map +0 -1
  246. package/dist/chunks/select-BR6_N_Yo.mjs +0 -2
  247. package/dist/chunks/separator-BB6-E9Z1.mjs +0 -2
  248. package/dist/chunks/skeleton-XPWWiaac.mjs +0 -2
  249. package/dist/chunks/sortable-CqPFGn8Q.mjs +0 -2
  250. package/dist/chunks/sortable-CqPFGn8Q.mjs.map +0 -1
  251. package/dist/chunks/table-LQIHzPHi.mjs +0 -2
  252. package/dist/chunks/toggle-Co72WXGd.mjs +0 -2
  253. package/dist/chunks/tooltip-qX2HjdJP.mjs +0 -2
  254. package/dist/chunks/tslib.es6-cMGqxriw.mjs +0 -2
  255. package/dist/chunks/utils-BctauAA9.mjs +0 -2
  256. package/dist/chunks/utils-BctauAA9.mjs.map +0 -1
  257. package/dist/chunks/x-BNLl0E-E.mjs +0 -2
@@ -0,0 +1,4221 @@
1
+ import * as React from 'react';
2
+ import React__default, { useLayoutEffect, useEffect, useRef, useMemo, useCallback, useState, memo, useReducer, createContext, useContext, forwardRef, cloneElement } from 'react';
3
+ import { unstable_batchedUpdates, createPortal } from 'react-dom';
4
+ import { Slot } from '@radix-ui/react-slot';
5
+ import { c as cn } from './utils-BUelq9Ro.mjs';
6
+ import { B as Button } from './button-CX0htulo.mjs';
7
+
8
+ function useCombinedRefs() {
9
+ for(var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++){
10
+ refs[_key] = arguments[_key];
11
+ }
12
+ return useMemo(()=>(node)=>{
13
+ refs.forEach((ref)=>ref(node));
14
+ }, refs);
15
+ }
16
+ // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
17
+ const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
18
+ function isWindow(element) {
19
+ const elementString = Object.prototype.toString.call(element);
20
+ return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
21
+ elementString === '[object global]';
22
+ }
23
+ function isNode(node) {
24
+ return 'nodeType' in node;
25
+ }
26
+ function getWindow(target) {
27
+ var _target$ownerDocument, _target$ownerDocument2;
28
+ if (!target) {
29
+ return window;
30
+ }
31
+ if (isWindow(target)) {
32
+ return target;
33
+ }
34
+ if (!isNode(target)) {
35
+ return window;
36
+ }
37
+ return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
38
+ }
39
+ function isDocument(node) {
40
+ const { Document } = getWindow(node);
41
+ return node instanceof Document;
42
+ }
43
+ function isHTMLElement(node) {
44
+ if (isWindow(node)) {
45
+ return false;
46
+ }
47
+ return node instanceof getWindow(node).HTMLElement;
48
+ }
49
+ function isSVGElement(node) {
50
+ return node instanceof getWindow(node).SVGElement;
51
+ }
52
+ function getOwnerDocument(target) {
53
+ if (!target) {
54
+ return document;
55
+ }
56
+ if (isWindow(target)) {
57
+ return target.document;
58
+ }
59
+ if (!isNode(target)) {
60
+ return document;
61
+ }
62
+ if (isDocument(target)) {
63
+ return target;
64
+ }
65
+ if (isHTMLElement(target) || isSVGElement(target)) {
66
+ return target.ownerDocument;
67
+ }
68
+ return document;
69
+ }
70
+ /**
71
+ * A hook that resolves to useEffect on the server and useLayoutEffect on the client
72
+ * @param callback {function} Callback function that is invoked when the dependencies of the hook change
73
+ */ const useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
74
+ function useEvent(handler) {
75
+ const handlerRef = useRef(handler);
76
+ useIsomorphicLayoutEffect(()=>{
77
+ handlerRef.current = handler;
78
+ });
79
+ return useCallback(function() {
80
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
81
+ args[_key] = arguments[_key];
82
+ }
83
+ return handlerRef.current == null ? void 0 : handlerRef.current(...args);
84
+ }, []);
85
+ }
86
+ function useInterval() {
87
+ const intervalRef = useRef(null);
88
+ const set = useCallback((listener, duration)=>{
89
+ intervalRef.current = setInterval(listener, duration);
90
+ }, []);
91
+ const clear = useCallback(()=>{
92
+ if (intervalRef.current !== null) {
93
+ clearInterval(intervalRef.current);
94
+ intervalRef.current = null;
95
+ }
96
+ }, []);
97
+ return [
98
+ set,
99
+ clear
100
+ ];
101
+ }
102
+ function useLatestValue(value, dependencies) {
103
+ if (dependencies === void 0) {
104
+ dependencies = [
105
+ value
106
+ ];
107
+ }
108
+ const valueRef = useRef(value);
109
+ useIsomorphicLayoutEffect(()=>{
110
+ if (valueRef.current !== value) {
111
+ valueRef.current = value;
112
+ }
113
+ }, dependencies);
114
+ return valueRef;
115
+ }
116
+ function useLazyMemo(callback, dependencies) {
117
+ const valueRef = useRef();
118
+ return useMemo(()=>{
119
+ const newValue = callback(valueRef.current);
120
+ valueRef.current = newValue;
121
+ return newValue;
122
+ }, [
123
+ ...dependencies
124
+ ]);
125
+ }
126
+ function useNodeRef(onChange) {
127
+ const onChangeHandler = useEvent(onChange);
128
+ const node = useRef(null);
129
+ const setNodeRef = useCallback((element)=>{
130
+ if (element !== node.current) {
131
+ onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
132
+ }
133
+ node.current = element;
134
+ }, []);
135
+ return [
136
+ node,
137
+ setNodeRef
138
+ ];
139
+ }
140
+ function usePrevious(value) {
141
+ const ref = useRef();
142
+ useEffect(()=>{
143
+ ref.current = value;
144
+ }, [
145
+ value
146
+ ]);
147
+ return ref.current;
148
+ }
149
+ let ids = {};
150
+ function useUniqueId(prefix, value) {
151
+ return useMemo(()=>{
152
+ if (value) {
153
+ return value;
154
+ }
155
+ const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
156
+ ids[prefix] = id;
157
+ return prefix + "-" + id;
158
+ }, [
159
+ prefix,
160
+ value
161
+ ]);
162
+ }
163
+ function createAdjustmentFn(modifier) {
164
+ return function(object) {
165
+ for(var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
166
+ adjustments[_key - 1] = arguments[_key];
167
+ }
168
+ return adjustments.reduce((accumulator, adjustment)=>{
169
+ const entries = Object.entries(adjustment);
170
+ for (const [key, valueAdjustment] of entries){
171
+ const value = accumulator[key];
172
+ if (value != null) {
173
+ accumulator[key] = value + modifier * valueAdjustment;
174
+ }
175
+ }
176
+ return accumulator;
177
+ }, {
178
+ ...object
179
+ });
180
+ };
181
+ }
182
+ const add = /*#__PURE__*/ createAdjustmentFn(1);
183
+ const subtract = /*#__PURE__*/ createAdjustmentFn(-1);
184
+ function hasViewportRelativeCoordinates(event) {
185
+ return 'clientX' in event && 'clientY' in event;
186
+ }
187
+ function isKeyboardEvent(event) {
188
+ if (!event) {
189
+ return false;
190
+ }
191
+ const { KeyboardEvent } = getWindow(event.target);
192
+ return KeyboardEvent && event instanceof KeyboardEvent;
193
+ }
194
+ function isTouchEvent(event) {
195
+ if (!event) {
196
+ return false;
197
+ }
198
+ const { TouchEvent } = getWindow(event.target);
199
+ return TouchEvent && event instanceof TouchEvent;
200
+ }
201
+ /**
202
+ * Returns the normalized x and y coordinates for mouse and touch events.
203
+ */ function getEventCoordinates(event) {
204
+ if (isTouchEvent(event)) {
205
+ if (event.touches && event.touches.length) {
206
+ const { clientX: x, clientY: y } = event.touches[0];
207
+ return {
208
+ x,
209
+ y
210
+ };
211
+ } else if (event.changedTouches && event.changedTouches.length) {
212
+ const { clientX: x, clientY: y } = event.changedTouches[0];
213
+ return {
214
+ x,
215
+ y
216
+ };
217
+ }
218
+ }
219
+ if (hasViewportRelativeCoordinates(event)) {
220
+ return {
221
+ x: event.clientX,
222
+ y: event.clientY
223
+ };
224
+ }
225
+ return null;
226
+ }
227
+ const CSS = /*#__PURE__*/ Object.freeze({
228
+ Translate: {
229
+ toString (transform) {
230
+ if (!transform) {
231
+ return;
232
+ }
233
+ const { x, y } = transform;
234
+ return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
235
+ }
236
+ },
237
+ Scale: {
238
+ toString (transform) {
239
+ if (!transform) {
240
+ return;
241
+ }
242
+ const { scaleX, scaleY } = transform;
243
+ return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
244
+ }
245
+ },
246
+ Transform: {
247
+ toString (transform) {
248
+ if (!transform) {
249
+ return;
250
+ }
251
+ return [
252
+ CSS.Translate.toString(transform),
253
+ CSS.Scale.toString(transform)
254
+ ].join(' ');
255
+ }
256
+ },
257
+ Transition: {
258
+ toString (_ref) {
259
+ let { property, duration, easing } = _ref;
260
+ return property + " " + duration + "ms " + easing;
261
+ }
262
+ }
263
+ });
264
+ const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
265
+ function findFirstFocusableNode(element) {
266
+ if (element.matches(SELECTOR)) {
267
+ return element;
268
+ }
269
+ return element.querySelector(SELECTOR);
270
+ }
271
+
272
+ const hiddenStyles = {
273
+ display: 'none'
274
+ };
275
+ function HiddenText(_ref) {
276
+ let { id, value } = _ref;
277
+ return React__default.createElement("div", {
278
+ id: id,
279
+ style: hiddenStyles
280
+ }, value);
281
+ }
282
+ function LiveRegion(_ref) {
283
+ let { id, announcement, ariaLiveType = "assertive" } = _ref;
284
+ // Hide element visually but keep it readable by screen readers
285
+ const visuallyHidden = {
286
+ position: 'fixed',
287
+ top: 0,
288
+ left: 0,
289
+ width: 1,
290
+ height: 1,
291
+ margin: -1,
292
+ border: 0,
293
+ padding: 0,
294
+ overflow: 'hidden',
295
+ clip: 'rect(0 0 0 0)',
296
+ clipPath: 'inset(100%)',
297
+ whiteSpace: 'nowrap'
298
+ };
299
+ return React__default.createElement("div", {
300
+ id: id,
301
+ style: visuallyHidden,
302
+ role: "status",
303
+ "aria-live": ariaLiveType,
304
+ "aria-atomic": true
305
+ }, announcement);
306
+ }
307
+ function useAnnouncement() {
308
+ const [announcement, setAnnouncement] = useState('');
309
+ const announce = useCallback((value)=>{
310
+ if (value != null) {
311
+ setAnnouncement(value);
312
+ }
313
+ }, []);
314
+ return {
315
+ announce,
316
+ announcement
317
+ };
318
+ }
319
+
320
+ const DndMonitorContext = /*#__PURE__*/ createContext(null);
321
+ function useDndMonitor(listener) {
322
+ const registerListener = useContext(DndMonitorContext);
323
+ useEffect(()=>{
324
+ if (!registerListener) {
325
+ throw new Error('useDndMonitor must be used within a children of <DndContext>');
326
+ }
327
+ const unsubscribe = registerListener(listener);
328
+ return unsubscribe;
329
+ }, [
330
+ listener,
331
+ registerListener
332
+ ]);
333
+ }
334
+ function useDndMonitorProvider() {
335
+ const [listeners] = useState(()=>new Set());
336
+ const registerListener = useCallback((listener)=>{
337
+ listeners.add(listener);
338
+ return ()=>listeners.delete(listener);
339
+ }, [
340
+ listeners
341
+ ]);
342
+ const dispatch = useCallback((_ref)=>{
343
+ let { type, event } = _ref;
344
+ listeners.forEach((listener)=>{
345
+ var _listener$type;
346
+ return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
347
+ });
348
+ }, [
349
+ listeners
350
+ ]);
351
+ return [
352
+ dispatch,
353
+ registerListener
354
+ ];
355
+ }
356
+ const defaultScreenReaderInstructions = {
357
+ draggable: "\n To pick up a draggable item, press the space bar.\n While dragging, use the arrow keys to move the item.\n Press space again to drop the item in its new position, or press escape to cancel.\n "
358
+ };
359
+ const defaultAnnouncements = {
360
+ onDragStart (_ref) {
361
+ let { active } = _ref;
362
+ return "Picked up draggable item " + active.id + ".";
363
+ },
364
+ onDragOver (_ref2) {
365
+ let { active, over } = _ref2;
366
+ if (over) {
367
+ return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
368
+ }
369
+ return "Draggable item " + active.id + " is no longer over a droppable area.";
370
+ },
371
+ onDragEnd (_ref3) {
372
+ let { active, over } = _ref3;
373
+ if (over) {
374
+ return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
375
+ }
376
+ return "Draggable item " + active.id + " was dropped.";
377
+ },
378
+ onDragCancel (_ref4) {
379
+ let { active } = _ref4;
380
+ return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
381
+ }
382
+ };
383
+ function Accessibility(_ref) {
384
+ let { announcements = defaultAnnouncements, container, hiddenTextDescribedById, screenReaderInstructions = defaultScreenReaderInstructions } = _ref;
385
+ const { announce, announcement } = useAnnouncement();
386
+ const liveRegionId = useUniqueId("DndLiveRegion");
387
+ const [mounted, setMounted] = useState(false);
388
+ useEffect(()=>{
389
+ setMounted(true);
390
+ }, []);
391
+ useDndMonitor(useMemo(()=>({
392
+ onDragStart (_ref2) {
393
+ let { active } = _ref2;
394
+ announce(announcements.onDragStart({
395
+ active
396
+ }));
397
+ },
398
+ onDragMove (_ref3) {
399
+ let { active, over } = _ref3;
400
+ if (announcements.onDragMove) {
401
+ announce(announcements.onDragMove({
402
+ active,
403
+ over
404
+ }));
405
+ }
406
+ },
407
+ onDragOver (_ref4) {
408
+ let { active, over } = _ref4;
409
+ announce(announcements.onDragOver({
410
+ active,
411
+ over
412
+ }));
413
+ },
414
+ onDragEnd (_ref5) {
415
+ let { active, over } = _ref5;
416
+ announce(announcements.onDragEnd({
417
+ active,
418
+ over
419
+ }));
420
+ },
421
+ onDragCancel (_ref6) {
422
+ let { active, over } = _ref6;
423
+ announce(announcements.onDragCancel({
424
+ active,
425
+ over
426
+ }));
427
+ }
428
+ }), [
429
+ announce,
430
+ announcements
431
+ ]));
432
+ if (!mounted) {
433
+ return null;
434
+ }
435
+ const markup = React__default.createElement(React__default.Fragment, null, React__default.createElement(HiddenText, {
436
+ id: hiddenTextDescribedById,
437
+ value: screenReaderInstructions.draggable
438
+ }), React__default.createElement(LiveRegion, {
439
+ id: liveRegionId,
440
+ announcement: announcement
441
+ }));
442
+ return container ? createPortal(markup, container) : markup;
443
+ }
444
+ var Action;
445
+ (function(Action) {
446
+ Action["DragStart"] = "dragStart";
447
+ Action["DragMove"] = "dragMove";
448
+ Action["DragEnd"] = "dragEnd";
449
+ Action["DragCancel"] = "dragCancel";
450
+ Action["DragOver"] = "dragOver";
451
+ Action["RegisterDroppable"] = "registerDroppable";
452
+ Action["SetDroppableDisabled"] = "setDroppableDisabled";
453
+ Action["UnregisterDroppable"] = "unregisterDroppable";
454
+ })(Action || (Action = {}));
455
+ function noop() {}
456
+ function useSensor(sensor, options) {
457
+ return useMemo(()=>({
458
+ sensor,
459
+ options: {}
460
+ }), [
461
+ sensor,
462
+ options
463
+ ]);
464
+ }
465
+ function useSensors() {
466
+ for(var _len = arguments.length, sensors = new Array(_len), _key = 0; _key < _len; _key++){
467
+ sensors[_key] = arguments[_key];
468
+ }
469
+ return useMemo(()=>[
470
+ ...sensors
471
+ ].filter((sensor)=>sensor != null), [
472
+ ...sensors
473
+ ]);
474
+ }
475
+ const defaultCoordinates = /*#__PURE__*/ Object.freeze({
476
+ x: 0,
477
+ y: 0
478
+ });
479
+ /**
480
+ * Returns the distance between two points
481
+ */ function distanceBetween(p1, p2) {
482
+ return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
483
+ }
484
+ function getRelativeTransformOrigin(event, rect) {
485
+ const eventCoordinates = getEventCoordinates(event);
486
+ if (!eventCoordinates) {
487
+ return '0 0';
488
+ }
489
+ const transformOrigin = {
490
+ x: (eventCoordinates.x - rect.left) / rect.width * 100,
491
+ y: (eventCoordinates.y - rect.top) / rect.height * 100
492
+ };
493
+ return transformOrigin.x + "% " + transformOrigin.y + "%";
494
+ }
495
+ /**
496
+ * Sort collisions from smallest to greatest value
497
+ */ function sortCollisionsAsc(_ref, _ref2) {
498
+ let { data: { value: a } } = _ref;
499
+ let { data: { value: b } } = _ref2;
500
+ return a - b;
501
+ }
502
+ /**
503
+ * Sort collisions from greatest to smallest value
504
+ */ function sortCollisionsDesc(_ref3, _ref4) {
505
+ let { data: { value: a } } = _ref3;
506
+ let { data: { value: b } } = _ref4;
507
+ return b - a;
508
+ }
509
+ function getFirstCollision(collisions, property) {
510
+ if (!collisions || collisions.length === 0) {
511
+ return null;
512
+ }
513
+ const [firstCollision] = collisions;
514
+ return firstCollision[property] ;
515
+ }
516
+ /**
517
+ * Returns the coordinates of the center of a given ClientRect
518
+ */ function centerOfRectangle(rect, left, top) {
519
+ if (left === void 0) {
520
+ left = rect.left;
521
+ }
522
+ if (top === void 0) {
523
+ top = rect.top;
524
+ }
525
+ return {
526
+ x: left + rect.width * 0.5,
527
+ y: top + rect.height * 0.5
528
+ };
529
+ }
530
+ /**
531
+ * Returns the closest rectangles from an array of rectangles to the center of a given
532
+ * rectangle.
533
+ */ const closestCenter = (_ref)=>{
534
+ let { collisionRect, droppableRects, droppableContainers } = _ref;
535
+ const centerRect = centerOfRectangle(collisionRect, collisionRect.left, collisionRect.top);
536
+ const collisions = [];
537
+ for (const droppableContainer of droppableContainers){
538
+ const { id } = droppableContainer;
539
+ const rect = droppableRects.get(id);
540
+ if (rect) {
541
+ const distBetween = distanceBetween(centerOfRectangle(rect), centerRect);
542
+ collisions.push({
543
+ id,
544
+ data: {
545
+ droppableContainer,
546
+ value: distBetween
547
+ }
548
+ });
549
+ }
550
+ }
551
+ return collisions.sort(sortCollisionsAsc);
552
+ };
553
+ /**
554
+ * Returns the intersecting rectangle area between two rectangles
555
+ */ function getIntersectionRatio(entry, target) {
556
+ const top = Math.max(target.top, entry.top);
557
+ const left = Math.max(target.left, entry.left);
558
+ const right = Math.min(target.left + target.width, entry.left + entry.width);
559
+ const bottom = Math.min(target.top + target.height, entry.top + entry.height);
560
+ const width = right - left;
561
+ const height = bottom - top;
562
+ if (left < right && top < bottom) {
563
+ const targetArea = target.width * target.height;
564
+ const entryArea = entry.width * entry.height;
565
+ const intersectionArea = width * height;
566
+ const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
567
+ return Number(intersectionRatio.toFixed(4));
568
+ } // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
569
+ return 0;
570
+ }
571
+ /**
572
+ * Returns the rectangles that has the greatest intersection area with a given
573
+ * rectangle in an array of rectangles.
574
+ */ const rectIntersection = (_ref)=>{
575
+ let { collisionRect, droppableRects, droppableContainers } = _ref;
576
+ const collisions = [];
577
+ for (const droppableContainer of droppableContainers){
578
+ const { id } = droppableContainer;
579
+ const rect = droppableRects.get(id);
580
+ if (rect) {
581
+ const intersectionRatio = getIntersectionRatio(rect, collisionRect);
582
+ if (intersectionRatio > 0) {
583
+ collisions.push({
584
+ id,
585
+ data: {
586
+ droppableContainer,
587
+ value: intersectionRatio
588
+ }
589
+ });
590
+ }
591
+ }
592
+ }
593
+ return collisions.sort(sortCollisionsDesc);
594
+ };
595
+ function adjustScale(transform, rect1, rect2) {
596
+ return {
597
+ ...transform,
598
+ scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
599
+ scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
600
+ };
601
+ }
602
+ function getRectDelta(rect1, rect2) {
603
+ return rect1 && rect2 ? {
604
+ x: rect1.left - rect2.left,
605
+ y: rect1.top - rect2.top
606
+ } : defaultCoordinates;
607
+ }
608
+ function createRectAdjustmentFn(modifier) {
609
+ return function adjustClientRect(rect) {
610
+ for(var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
611
+ adjustments[_key - 1] = arguments[_key];
612
+ }
613
+ return adjustments.reduce((acc, adjustment)=>({
614
+ ...acc,
615
+ top: acc.top + modifier * adjustment.y,
616
+ bottom: acc.bottom + modifier * adjustment.y,
617
+ left: acc.left + modifier * adjustment.x,
618
+ right: acc.right + modifier * adjustment.x
619
+ }), {
620
+ ...rect
621
+ });
622
+ };
623
+ }
624
+ const getAdjustedRect = /*#__PURE__*/ createRectAdjustmentFn(1);
625
+ function parseTransform(transform) {
626
+ if (transform.startsWith('matrix3d(')) {
627
+ const transformArray = transform.slice(9, -1).split(/, /);
628
+ return {
629
+ x: +transformArray[12],
630
+ y: +transformArray[13],
631
+ scaleX: +transformArray[0],
632
+ scaleY: +transformArray[5]
633
+ };
634
+ } else if (transform.startsWith('matrix(')) {
635
+ const transformArray = transform.slice(7, -1).split(/, /);
636
+ return {
637
+ x: +transformArray[4],
638
+ y: +transformArray[5],
639
+ scaleX: +transformArray[0],
640
+ scaleY: +transformArray[3]
641
+ };
642
+ }
643
+ return null;
644
+ }
645
+ function inverseTransform(rect, transform, transformOrigin) {
646
+ const parsedTransform = parseTransform(transform);
647
+ if (!parsedTransform) {
648
+ return rect;
649
+ }
650
+ const { scaleX, scaleY, x: translateX, y: translateY } = parsedTransform;
651
+ const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
652
+ const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(' ') + 1));
653
+ const w = scaleX ? rect.width / scaleX : rect.width;
654
+ const h = scaleY ? rect.height / scaleY : rect.height;
655
+ return {
656
+ width: w,
657
+ height: h,
658
+ top: y,
659
+ right: x + w,
660
+ bottom: y + h,
661
+ left: x
662
+ };
663
+ }
664
+ const defaultOptions = {
665
+ ignoreTransform: false
666
+ };
667
+ /**
668
+ * Returns the bounding client rect of an element relative to the viewport.
669
+ */ function getClientRect(element, options) {
670
+ if (options === void 0) {
671
+ options = defaultOptions;
672
+ }
673
+ let rect = element.getBoundingClientRect();
674
+ if (options.ignoreTransform) {
675
+ const { transform, transformOrigin } = getWindow(element).getComputedStyle(element);
676
+ if (transform) {
677
+ rect = inverseTransform(rect, transform, transformOrigin);
678
+ }
679
+ }
680
+ const { top, left, width, height, bottom, right } = rect;
681
+ return {
682
+ top,
683
+ left,
684
+ width,
685
+ height,
686
+ bottom,
687
+ right
688
+ };
689
+ }
690
+ /**
691
+ * Returns the bounding client rect of an element relative to the viewport.
692
+ *
693
+ * @remarks
694
+ * The ClientRect returned by this method does not take into account transforms
695
+ * applied to the element it measures.
696
+ *
697
+ */ function getTransformAgnosticClientRect(element) {
698
+ return getClientRect(element, {
699
+ ignoreTransform: true
700
+ });
701
+ }
702
+ function getWindowClientRect(element) {
703
+ const width = element.innerWidth;
704
+ const height = element.innerHeight;
705
+ return {
706
+ top: 0,
707
+ left: 0,
708
+ right: width,
709
+ bottom: height,
710
+ width,
711
+ height
712
+ };
713
+ }
714
+ function isFixed(node, computedStyle) {
715
+ if (computedStyle === void 0) {
716
+ computedStyle = getWindow(node).getComputedStyle(node);
717
+ }
718
+ return computedStyle.position === 'fixed';
719
+ }
720
+ function isScrollable(element, computedStyle) {
721
+ if (computedStyle === void 0) {
722
+ computedStyle = getWindow(element).getComputedStyle(element);
723
+ }
724
+ const overflowRegex = /(auto|scroll|overlay)/;
725
+ const properties = [
726
+ 'overflow',
727
+ 'overflowX',
728
+ 'overflowY'
729
+ ];
730
+ return properties.some((property)=>{
731
+ const value = computedStyle[property];
732
+ return typeof value === 'string' ? overflowRegex.test(value) : false;
733
+ });
734
+ }
735
+ function getScrollableAncestors(element, limit) {
736
+ const scrollParents = [];
737
+ function findScrollableAncestors(node) {
738
+ if (limit != null && scrollParents.length >= limit) {
739
+ return scrollParents;
740
+ }
741
+ if (!node) {
742
+ return scrollParents;
743
+ }
744
+ if (isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
745
+ scrollParents.push(node.scrollingElement);
746
+ return scrollParents;
747
+ }
748
+ if (!isHTMLElement(node) || isSVGElement(node)) {
749
+ return scrollParents;
750
+ }
751
+ if (scrollParents.includes(node)) {
752
+ return scrollParents;
753
+ }
754
+ const computedStyle = getWindow(element).getComputedStyle(node);
755
+ if (node !== element) {
756
+ if (isScrollable(node, computedStyle)) {
757
+ scrollParents.push(node);
758
+ }
759
+ }
760
+ if (isFixed(node, computedStyle)) {
761
+ return scrollParents;
762
+ }
763
+ return findScrollableAncestors(node.parentNode);
764
+ }
765
+ if (!element) {
766
+ return scrollParents;
767
+ }
768
+ return findScrollableAncestors(element);
769
+ }
770
+ function getFirstScrollableAncestor(node) {
771
+ const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
772
+ return firstScrollableAncestor != null ? firstScrollableAncestor : null;
773
+ }
774
+ function getScrollableElement(element) {
775
+ if (!canUseDOM || !element) {
776
+ return null;
777
+ }
778
+ if (isWindow(element)) {
779
+ return element;
780
+ }
781
+ if (!isNode(element)) {
782
+ return null;
783
+ }
784
+ if (isDocument(element) || element === getOwnerDocument(element).scrollingElement) {
785
+ return window;
786
+ }
787
+ if (isHTMLElement(element)) {
788
+ return element;
789
+ }
790
+ return null;
791
+ }
792
+ function getScrollXCoordinate(element) {
793
+ if (isWindow(element)) {
794
+ return element.scrollX;
795
+ }
796
+ return element.scrollLeft;
797
+ }
798
+ function getScrollYCoordinate(element) {
799
+ if (isWindow(element)) {
800
+ return element.scrollY;
801
+ }
802
+ return element.scrollTop;
803
+ }
804
+ function getScrollCoordinates(element) {
805
+ return {
806
+ x: getScrollXCoordinate(element),
807
+ y: getScrollYCoordinate(element)
808
+ };
809
+ }
810
+ var Direction;
811
+ (function(Direction) {
812
+ Direction[Direction["Forward"] = 1] = "Forward";
813
+ Direction[Direction["Backward"] = -1] = "Backward";
814
+ })(Direction || (Direction = {}));
815
+ function isDocumentScrollingElement(element) {
816
+ if (!canUseDOM || !element) {
817
+ return false;
818
+ }
819
+ return element === document.scrollingElement;
820
+ }
821
+ function getScrollPosition(scrollingContainer) {
822
+ const minScroll = {
823
+ x: 0,
824
+ y: 0
825
+ };
826
+ const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
827
+ height: window.innerHeight,
828
+ width: window.innerWidth
829
+ } : {
830
+ height: scrollingContainer.clientHeight,
831
+ width: scrollingContainer.clientWidth
832
+ };
833
+ const maxScroll = {
834
+ x: scrollingContainer.scrollWidth - dimensions.width,
835
+ y: scrollingContainer.scrollHeight - dimensions.height
836
+ };
837
+ const isTop = scrollingContainer.scrollTop <= minScroll.y;
838
+ const isLeft = scrollingContainer.scrollLeft <= minScroll.x;
839
+ const isBottom = scrollingContainer.scrollTop >= maxScroll.y;
840
+ const isRight = scrollingContainer.scrollLeft >= maxScroll.x;
841
+ return {
842
+ isTop,
843
+ isLeft,
844
+ isBottom,
845
+ isRight,
846
+ maxScroll,
847
+ minScroll
848
+ };
849
+ }
850
+ const defaultThreshold = {
851
+ x: 0.2,
852
+ y: 0.2
853
+ };
854
+ function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
855
+ let { top, left, right, bottom } = _ref;
856
+ if (acceleration === void 0) {
857
+ acceleration = 10;
858
+ }
859
+ if (thresholdPercentage === void 0) {
860
+ thresholdPercentage = defaultThreshold;
861
+ }
862
+ const { isTop, isBottom, isLeft, isRight } = getScrollPosition(scrollContainer);
863
+ const direction = {
864
+ x: 0,
865
+ y: 0
866
+ };
867
+ const speed = {
868
+ x: 0,
869
+ y: 0
870
+ };
871
+ const threshold = {
872
+ height: scrollContainerRect.height * thresholdPercentage.y,
873
+ width: scrollContainerRect.width * thresholdPercentage.x
874
+ };
875
+ if (!isTop && top <= scrollContainerRect.top + threshold.height) {
876
+ // Scroll Up
877
+ direction.y = Direction.Backward;
878
+ speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
879
+ } else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
880
+ // Scroll Down
881
+ direction.y = Direction.Forward;
882
+ speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
883
+ }
884
+ if (!isRight && right >= scrollContainerRect.right - threshold.width) {
885
+ // Scroll Right
886
+ direction.x = Direction.Forward;
887
+ speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
888
+ } else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
889
+ // Scroll Left
890
+ direction.x = Direction.Backward;
891
+ speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
892
+ }
893
+ return {
894
+ direction,
895
+ speed
896
+ };
897
+ }
898
+ function getScrollElementRect(element) {
899
+ if (element === document.scrollingElement) {
900
+ const { innerWidth, innerHeight } = window;
901
+ return {
902
+ top: 0,
903
+ left: 0,
904
+ right: innerWidth,
905
+ bottom: innerHeight,
906
+ width: innerWidth,
907
+ height: innerHeight
908
+ };
909
+ }
910
+ const { top, left, right, bottom } = element.getBoundingClientRect();
911
+ return {
912
+ top,
913
+ left,
914
+ right,
915
+ bottom,
916
+ width: element.clientWidth,
917
+ height: element.clientHeight
918
+ };
919
+ }
920
+ function getScrollOffsets(scrollableAncestors) {
921
+ return scrollableAncestors.reduce((acc, node)=>{
922
+ return add(acc, getScrollCoordinates(node));
923
+ }, defaultCoordinates);
924
+ }
925
+ function getScrollXOffset(scrollableAncestors) {
926
+ return scrollableAncestors.reduce((acc, node)=>{
927
+ return acc + getScrollXCoordinate(node);
928
+ }, 0);
929
+ }
930
+ function getScrollYOffset(scrollableAncestors) {
931
+ return scrollableAncestors.reduce((acc, node)=>{
932
+ return acc + getScrollYCoordinate(node);
933
+ }, 0);
934
+ }
935
+ function scrollIntoViewIfNeeded(element, measure) {
936
+ if (measure === void 0) {
937
+ measure = getClientRect;
938
+ }
939
+ if (!element) {
940
+ return;
941
+ }
942
+ const { top, left, bottom, right } = measure(element);
943
+ const firstScrollableAncestor = getFirstScrollableAncestor(element);
944
+ if (!firstScrollableAncestor) {
945
+ return;
946
+ }
947
+ if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) {
948
+ element.scrollIntoView({
949
+ block: 'center',
950
+ inline: 'center'
951
+ });
952
+ }
953
+ }
954
+ const properties = [
955
+ [
956
+ 'x',
957
+ [
958
+ 'left',
959
+ 'right'
960
+ ],
961
+ getScrollXOffset
962
+ ],
963
+ [
964
+ 'y',
965
+ [
966
+ 'top',
967
+ 'bottom'
968
+ ],
969
+ getScrollYOffset
970
+ ]
971
+ ];
972
+ class Rect {
973
+ constructor(rect, element){
974
+ this.rect = void 0;
975
+ this.width = void 0;
976
+ this.height = void 0;
977
+ this.top = void 0;
978
+ this.bottom = void 0;
979
+ this.right = void 0;
980
+ this.left = void 0;
981
+ const scrollableAncestors = getScrollableAncestors(element);
982
+ const scrollOffsets = getScrollOffsets(scrollableAncestors);
983
+ this.rect = {
984
+ ...rect
985
+ };
986
+ this.width = rect.width;
987
+ this.height = rect.height;
988
+ for (const [axis, keys, getScrollOffset] of properties){
989
+ for (const key of keys){
990
+ Object.defineProperty(this, key, {
991
+ get: ()=>{
992
+ const currentOffsets = getScrollOffset(scrollableAncestors);
993
+ const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
994
+ return this.rect[key] + scrollOffsetsDeltla;
995
+ },
996
+ enumerable: true
997
+ });
998
+ }
999
+ }
1000
+ Object.defineProperty(this, 'rect', {
1001
+ enumerable: false
1002
+ });
1003
+ }
1004
+ }
1005
+ class Listeners {
1006
+ add(eventName, handler, options) {
1007
+ var _this$target2;
1008
+ (_this$target2 = this.target) == null ? void 0 : _this$target2.addEventListener(eventName, handler, options);
1009
+ this.listeners.push([
1010
+ eventName,
1011
+ handler,
1012
+ options
1013
+ ]);
1014
+ }
1015
+ constructor(target){
1016
+ this.target = void 0;
1017
+ this.listeners = [];
1018
+ this.removeAll = ()=>{
1019
+ this.listeners.forEach((listener)=>{
1020
+ var _this$target;
1021
+ return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
1022
+ });
1023
+ };
1024
+ this.target = target;
1025
+ }
1026
+ }
1027
+ function getEventListenerTarget(target) {
1028
+ // If the `event.target` element is removed from the document events will still be targeted
1029
+ // at it, and hence won't always bubble up to the window or document anymore.
1030
+ // If there is any risk of an element being removed while it is being dragged,
1031
+ // the best practice is to attach the event listeners directly to the target.
1032
+ // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
1033
+ const { EventTarget } = getWindow(target);
1034
+ return target instanceof EventTarget ? target : getOwnerDocument(target);
1035
+ }
1036
+ function hasExceededDistance(delta, measurement) {
1037
+ const dx = Math.abs(delta.x);
1038
+ const dy = Math.abs(delta.y);
1039
+ if (typeof measurement === 'number') {
1040
+ return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
1041
+ }
1042
+ if ('x' in measurement && 'y' in measurement) {
1043
+ return dx > measurement.x && dy > measurement.y;
1044
+ }
1045
+ if ('x' in measurement) {
1046
+ return dx > measurement.x;
1047
+ }
1048
+ if ('y' in measurement) {
1049
+ return dy > measurement.y;
1050
+ }
1051
+ return false;
1052
+ }
1053
+ var EventName;
1054
+ (function(EventName) {
1055
+ EventName["Click"] = "click";
1056
+ EventName["DragStart"] = "dragstart";
1057
+ EventName["Keydown"] = "keydown";
1058
+ EventName["ContextMenu"] = "contextmenu";
1059
+ EventName["Resize"] = "resize";
1060
+ EventName["SelectionChange"] = "selectionchange";
1061
+ EventName["VisibilityChange"] = "visibilitychange";
1062
+ })(EventName || (EventName = {}));
1063
+ function preventDefault(event) {
1064
+ event.preventDefault();
1065
+ }
1066
+ function stopPropagation(event) {
1067
+ event.stopPropagation();
1068
+ }
1069
+ var KeyboardCode;
1070
+ (function(KeyboardCode) {
1071
+ KeyboardCode["Space"] = "Space";
1072
+ KeyboardCode["Down"] = "ArrowDown";
1073
+ KeyboardCode["Right"] = "ArrowRight";
1074
+ KeyboardCode["Left"] = "ArrowLeft";
1075
+ KeyboardCode["Up"] = "ArrowUp";
1076
+ KeyboardCode["Esc"] = "Escape";
1077
+ KeyboardCode["Enter"] = "Enter";
1078
+ KeyboardCode["Tab"] = "Tab";
1079
+ })(KeyboardCode || (KeyboardCode = {}));
1080
+ const defaultKeyboardCodes = {
1081
+ start: [
1082
+ KeyboardCode.Space,
1083
+ KeyboardCode.Enter
1084
+ ],
1085
+ cancel: [
1086
+ KeyboardCode.Esc
1087
+ ],
1088
+ end: [
1089
+ KeyboardCode.Space,
1090
+ KeyboardCode.Enter,
1091
+ KeyboardCode.Tab
1092
+ ]
1093
+ };
1094
+ const defaultKeyboardCoordinateGetter = (event, _ref)=>{
1095
+ let { currentCoordinates } = _ref;
1096
+ switch(event.code){
1097
+ case KeyboardCode.Right:
1098
+ return {
1099
+ ...currentCoordinates,
1100
+ x: currentCoordinates.x + 25
1101
+ };
1102
+ case KeyboardCode.Left:
1103
+ return {
1104
+ ...currentCoordinates,
1105
+ x: currentCoordinates.x - 25
1106
+ };
1107
+ case KeyboardCode.Down:
1108
+ return {
1109
+ ...currentCoordinates,
1110
+ y: currentCoordinates.y + 25
1111
+ };
1112
+ case KeyboardCode.Up:
1113
+ return {
1114
+ ...currentCoordinates,
1115
+ y: currentCoordinates.y - 25
1116
+ };
1117
+ }
1118
+ return undefined;
1119
+ };
1120
+ class KeyboardSensor {
1121
+ attach() {
1122
+ this.handleStart();
1123
+ this.windowListeners.add(EventName.Resize, this.handleCancel);
1124
+ this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
1125
+ setTimeout(()=>this.listeners.add(EventName.Keydown, this.handleKeyDown));
1126
+ }
1127
+ handleStart() {
1128
+ const { activeNode, onStart } = this.props;
1129
+ const node = activeNode.node.current;
1130
+ if (node) {
1131
+ scrollIntoViewIfNeeded(node);
1132
+ }
1133
+ onStart(defaultCoordinates);
1134
+ }
1135
+ handleKeyDown(event) {
1136
+ if (isKeyboardEvent(event)) {
1137
+ const { active, context, options } = this.props;
1138
+ const { keyboardCodes = defaultKeyboardCodes, coordinateGetter = defaultKeyboardCoordinateGetter, scrollBehavior = 'smooth' } = options;
1139
+ const { code } = event;
1140
+ if (keyboardCodes.end.includes(code)) {
1141
+ this.handleEnd(event);
1142
+ return;
1143
+ }
1144
+ if (keyboardCodes.cancel.includes(code)) {
1145
+ this.handleCancel(event);
1146
+ return;
1147
+ }
1148
+ const { collisionRect } = context.current;
1149
+ const currentCoordinates = collisionRect ? {
1150
+ x: collisionRect.left,
1151
+ y: collisionRect.top
1152
+ } : defaultCoordinates;
1153
+ if (!this.referenceCoordinates) {
1154
+ this.referenceCoordinates = currentCoordinates;
1155
+ }
1156
+ const newCoordinates = coordinateGetter(event, {
1157
+ active,
1158
+ context: context.current,
1159
+ currentCoordinates
1160
+ });
1161
+ if (newCoordinates) {
1162
+ const coordinatesDelta = subtract(newCoordinates, currentCoordinates);
1163
+ const scrollDelta = {
1164
+ x: 0,
1165
+ y: 0
1166
+ };
1167
+ const { scrollableAncestors } = context.current;
1168
+ for (const scrollContainer of scrollableAncestors){
1169
+ const direction = event.code;
1170
+ const { isTop, isRight, isLeft, isBottom, maxScroll, minScroll } = getScrollPosition(scrollContainer);
1171
+ const scrollElementRect = getScrollElementRect(scrollContainer);
1172
+ const clampedCoordinates = {
1173
+ x: Math.min(direction === KeyboardCode.Right ? scrollElementRect.right - scrollElementRect.width / 2 : scrollElementRect.right, Math.max(direction === KeyboardCode.Right ? scrollElementRect.left : scrollElementRect.left + scrollElementRect.width / 2, newCoordinates.x)),
1174
+ y: Math.min(direction === KeyboardCode.Down ? scrollElementRect.bottom - scrollElementRect.height / 2 : scrollElementRect.bottom, Math.max(direction === KeyboardCode.Down ? scrollElementRect.top : scrollElementRect.top + scrollElementRect.height / 2, newCoordinates.y))
1175
+ };
1176
+ const canScrollX = direction === KeyboardCode.Right && !isRight || direction === KeyboardCode.Left && !isLeft;
1177
+ const canScrollY = direction === KeyboardCode.Down && !isBottom || direction === KeyboardCode.Up && !isTop;
1178
+ if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
1179
+ const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
1180
+ const canScrollToNewCoordinates = direction === KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
1181
+ if (canScrollToNewCoordinates && !coordinatesDelta.y) {
1182
+ // We don't need to update coordinates, the scroll adjustment alone will trigger
1183
+ // logic to auto-detect the new container we are over
1184
+ scrollContainer.scrollTo({
1185
+ left: newScrollCoordinates,
1186
+ behavior: scrollBehavior
1187
+ });
1188
+ return;
1189
+ }
1190
+ if (canScrollToNewCoordinates) {
1191
+ scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
1192
+ } else {
1193
+ scrollDelta.x = direction === KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
1194
+ }
1195
+ if (scrollDelta.x) {
1196
+ scrollContainer.scrollBy({
1197
+ left: -scrollDelta.x,
1198
+ behavior: scrollBehavior
1199
+ });
1200
+ }
1201
+ break;
1202
+ } else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
1203
+ const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
1204
+ const canScrollToNewCoordinates = direction === KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
1205
+ if (canScrollToNewCoordinates && !coordinatesDelta.x) {
1206
+ // We don't need to update coordinates, the scroll adjustment alone will trigger
1207
+ // logic to auto-detect the new container we are over
1208
+ scrollContainer.scrollTo({
1209
+ top: newScrollCoordinates,
1210
+ behavior: scrollBehavior
1211
+ });
1212
+ return;
1213
+ }
1214
+ if (canScrollToNewCoordinates) {
1215
+ scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
1216
+ } else {
1217
+ scrollDelta.y = direction === KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
1218
+ }
1219
+ if (scrollDelta.y) {
1220
+ scrollContainer.scrollBy({
1221
+ top: -scrollDelta.y,
1222
+ behavior: scrollBehavior
1223
+ });
1224
+ }
1225
+ break;
1226
+ }
1227
+ }
1228
+ this.handleMove(event, add(subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
1229
+ }
1230
+ }
1231
+ }
1232
+ handleMove(event, coordinates) {
1233
+ const { onMove } = this.props;
1234
+ event.preventDefault();
1235
+ onMove(coordinates);
1236
+ }
1237
+ handleEnd(event) {
1238
+ const { onEnd } = this.props;
1239
+ event.preventDefault();
1240
+ this.detach();
1241
+ onEnd();
1242
+ }
1243
+ handleCancel(event) {
1244
+ const { onCancel } = this.props;
1245
+ event.preventDefault();
1246
+ this.detach();
1247
+ onCancel();
1248
+ }
1249
+ detach() {
1250
+ this.listeners.removeAll();
1251
+ this.windowListeners.removeAll();
1252
+ }
1253
+ constructor(props){
1254
+ this.props = void 0;
1255
+ this.autoScrollEnabled = false;
1256
+ this.referenceCoordinates = void 0;
1257
+ this.listeners = void 0;
1258
+ this.windowListeners = void 0;
1259
+ this.props = props;
1260
+ const { event: { target } } = props;
1261
+ this.props = props;
1262
+ this.listeners = new Listeners(getOwnerDocument(target));
1263
+ this.windowListeners = new Listeners(getWindow(target));
1264
+ this.handleKeyDown = this.handleKeyDown.bind(this);
1265
+ this.handleCancel = this.handleCancel.bind(this);
1266
+ this.attach();
1267
+ }
1268
+ }
1269
+ KeyboardSensor.activators = [
1270
+ {
1271
+ eventName: 'onKeyDown',
1272
+ handler: (event, _ref, _ref2)=>{
1273
+ let { keyboardCodes = defaultKeyboardCodes, onActivation } = _ref;
1274
+ let { active } = _ref2;
1275
+ const { code } = event.nativeEvent;
1276
+ if (keyboardCodes.start.includes(code)) {
1277
+ const activator = active.activatorNode.current;
1278
+ if (activator && event.target !== activator) {
1279
+ return false;
1280
+ }
1281
+ event.preventDefault();
1282
+ onActivation == null ? void 0 : onActivation({
1283
+ event: event.nativeEvent
1284
+ });
1285
+ return true;
1286
+ }
1287
+ return false;
1288
+ }
1289
+ }
1290
+ ];
1291
+ function isDistanceConstraint(constraint) {
1292
+ return Boolean(constraint && 'distance' in constraint);
1293
+ }
1294
+ function isDelayConstraint(constraint) {
1295
+ return Boolean(constraint && 'delay' in constraint);
1296
+ }
1297
+ class AbstractPointerSensor {
1298
+ attach() {
1299
+ const { events, props: { options: { activationConstraint, bypassActivationConstraint } } } = this;
1300
+ this.listeners.add(events.move.name, this.handleMove, {
1301
+ passive: false
1302
+ });
1303
+ this.listeners.add(events.end.name, this.handleEnd);
1304
+ if (events.cancel) {
1305
+ this.listeners.add(events.cancel.name, this.handleCancel);
1306
+ }
1307
+ this.windowListeners.add(EventName.Resize, this.handleCancel);
1308
+ this.windowListeners.add(EventName.DragStart, preventDefault);
1309
+ this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
1310
+ this.windowListeners.add(EventName.ContextMenu, preventDefault);
1311
+ this.documentListeners.add(EventName.Keydown, this.handleKeydown);
1312
+ if (activationConstraint) {
1313
+ if (bypassActivationConstraint != null && bypassActivationConstraint({
1314
+ event: this.props.event,
1315
+ activeNode: this.props.activeNode,
1316
+ options: this.props.options
1317
+ })) {
1318
+ return this.handleStart();
1319
+ }
1320
+ if (isDelayConstraint(activationConstraint)) {
1321
+ this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
1322
+ this.handlePending(activationConstraint);
1323
+ return;
1324
+ }
1325
+ if (isDistanceConstraint(activationConstraint)) {
1326
+ this.handlePending(activationConstraint);
1327
+ return;
1328
+ }
1329
+ }
1330
+ this.handleStart();
1331
+ }
1332
+ detach() {
1333
+ this.listeners.removeAll();
1334
+ this.windowListeners.removeAll(); // Wait until the next event loop before removing document listeners
1335
+ // This is necessary because we listen for `click` and `selection` events on the document
1336
+ setTimeout(this.documentListeners.removeAll, 50);
1337
+ if (this.timeoutId !== null) {
1338
+ clearTimeout(this.timeoutId);
1339
+ this.timeoutId = null;
1340
+ }
1341
+ }
1342
+ handlePending(constraint, offset) {
1343
+ const { active, onPending } = this.props;
1344
+ onPending(active, constraint, this.initialCoordinates, offset);
1345
+ }
1346
+ handleStart() {
1347
+ const { initialCoordinates } = this;
1348
+ const { onStart } = this.props;
1349
+ if (initialCoordinates) {
1350
+ this.activated = true; // Stop propagation of click events once activation constraints are met
1351
+ this.documentListeners.add(EventName.Click, stopPropagation, {
1352
+ capture: true
1353
+ }); // Remove any text selection from the document
1354
+ this.removeTextSelection(); // Prevent further text selection while dragging
1355
+ this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
1356
+ onStart(initialCoordinates);
1357
+ }
1358
+ }
1359
+ handleMove(event) {
1360
+ var _getEventCoordinates2;
1361
+ const { activated, initialCoordinates, props } = this;
1362
+ const { onMove, options: { activationConstraint } } = props;
1363
+ if (!initialCoordinates) {
1364
+ return;
1365
+ }
1366
+ const coordinates = (_getEventCoordinates2 = getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
1367
+ const delta = subtract(initialCoordinates, coordinates); // Constraint validation
1368
+ if (!activated && activationConstraint) {
1369
+ if (isDistanceConstraint(activationConstraint)) {
1370
+ if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) {
1371
+ return this.handleCancel();
1372
+ }
1373
+ if (hasExceededDistance(delta, activationConstraint.distance)) {
1374
+ return this.handleStart();
1375
+ }
1376
+ }
1377
+ if (isDelayConstraint(activationConstraint)) {
1378
+ if (hasExceededDistance(delta, activationConstraint.tolerance)) {
1379
+ return this.handleCancel();
1380
+ }
1381
+ }
1382
+ this.handlePending(activationConstraint, delta);
1383
+ return;
1384
+ }
1385
+ if (event.cancelable) {
1386
+ event.preventDefault();
1387
+ }
1388
+ onMove(coordinates);
1389
+ }
1390
+ handleEnd() {
1391
+ const { onAbort, onEnd } = this.props;
1392
+ this.detach();
1393
+ if (!this.activated) {
1394
+ onAbort(this.props.active);
1395
+ }
1396
+ onEnd();
1397
+ }
1398
+ handleCancel() {
1399
+ const { onAbort, onCancel } = this.props;
1400
+ this.detach();
1401
+ if (!this.activated) {
1402
+ onAbort(this.props.active);
1403
+ }
1404
+ onCancel();
1405
+ }
1406
+ handleKeydown(event) {
1407
+ if (event.code === KeyboardCode.Esc) {
1408
+ this.handleCancel();
1409
+ }
1410
+ }
1411
+ removeTextSelection() {
1412
+ var _this$document$getSel;
1413
+ (_this$document$getSel = this.document.getSelection()) == null ? void 0 : _this$document$getSel.removeAllRanges();
1414
+ }
1415
+ constructor(props, events, listenerTarget){
1416
+ var _getEventCoordinates;
1417
+ if (listenerTarget === void 0) {
1418
+ listenerTarget = getEventListenerTarget(props.event.target);
1419
+ }
1420
+ this.props = void 0;
1421
+ this.events = void 0;
1422
+ this.autoScrollEnabled = true;
1423
+ this.document = void 0;
1424
+ this.activated = false;
1425
+ this.initialCoordinates = void 0;
1426
+ this.timeoutId = null;
1427
+ this.listeners = void 0;
1428
+ this.documentListeners = void 0;
1429
+ this.windowListeners = void 0;
1430
+ this.props = props;
1431
+ this.events = events;
1432
+ const { event } = props;
1433
+ const { target } = event;
1434
+ this.props = props;
1435
+ this.events = events;
1436
+ this.document = getOwnerDocument(target);
1437
+ this.documentListeners = new Listeners(this.document);
1438
+ this.listeners = new Listeners(listenerTarget);
1439
+ this.windowListeners = new Listeners(getWindow(target));
1440
+ this.initialCoordinates = (_getEventCoordinates = getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
1441
+ this.handleStart = this.handleStart.bind(this);
1442
+ this.handleMove = this.handleMove.bind(this);
1443
+ this.handleEnd = this.handleEnd.bind(this);
1444
+ this.handleCancel = this.handleCancel.bind(this);
1445
+ this.handleKeydown = this.handleKeydown.bind(this);
1446
+ this.removeTextSelection = this.removeTextSelection.bind(this);
1447
+ this.attach();
1448
+ }
1449
+ }
1450
+ const events = {
1451
+ cancel: {
1452
+ name: 'pointercancel'
1453
+ },
1454
+ move: {
1455
+ name: 'pointermove'
1456
+ },
1457
+ end: {
1458
+ name: 'pointerup'
1459
+ }
1460
+ };
1461
+ class PointerSensor extends AbstractPointerSensor {
1462
+ constructor(props){
1463
+ const { event } = props; // Pointer events stop firing if the target is unmounted while dragging
1464
+ // Therefore we attach listeners to the owner document instead
1465
+ const listenerTarget = getOwnerDocument(event.target);
1466
+ super(props, events, listenerTarget);
1467
+ }
1468
+ }
1469
+ PointerSensor.activators = [
1470
+ {
1471
+ eventName: 'onPointerDown',
1472
+ handler: (_ref, _ref2)=>{
1473
+ let { nativeEvent: event } = _ref;
1474
+ let { onActivation } = _ref2;
1475
+ if (!event.isPrimary || event.button !== 0) {
1476
+ return false;
1477
+ }
1478
+ onActivation == null ? void 0 : onActivation({
1479
+ event
1480
+ });
1481
+ return true;
1482
+ }
1483
+ }
1484
+ ];
1485
+ const events$1 = {
1486
+ move: {
1487
+ name: 'mousemove'
1488
+ },
1489
+ end: {
1490
+ name: 'mouseup'
1491
+ }
1492
+ };
1493
+ var MouseButton;
1494
+ (function(MouseButton) {
1495
+ MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
1496
+ })(MouseButton || (MouseButton = {}));
1497
+ class MouseSensor extends AbstractPointerSensor {
1498
+ constructor(props){
1499
+ super(props, events$1, getOwnerDocument(props.event.target));
1500
+ }
1501
+ }
1502
+ MouseSensor.activators = [
1503
+ {
1504
+ eventName: 'onMouseDown',
1505
+ handler: (_ref, _ref2)=>{
1506
+ let { nativeEvent: event } = _ref;
1507
+ let { onActivation } = _ref2;
1508
+ if (event.button === MouseButton.RightClick) {
1509
+ return false;
1510
+ }
1511
+ onActivation == null ? void 0 : onActivation({
1512
+ event
1513
+ });
1514
+ return true;
1515
+ }
1516
+ }
1517
+ ];
1518
+ const events$2 = {
1519
+ cancel: {
1520
+ name: 'touchcancel'
1521
+ },
1522
+ move: {
1523
+ name: 'touchmove'
1524
+ },
1525
+ end: {
1526
+ name: 'touchend'
1527
+ }
1528
+ };
1529
+ class TouchSensor extends AbstractPointerSensor {
1530
+ static setup() {
1531
+ // Adding a non-capture and non-passive `touchmove` listener in order
1532
+ // to force `event.preventDefault()` calls to work in dynamically added
1533
+ // touchmove event handlers. This is required for iOS Safari.
1534
+ window.addEventListener(events$2.move.name, noop, {
1535
+ capture: false,
1536
+ passive: false
1537
+ });
1538
+ return function teardown() {
1539
+ window.removeEventListener(events$2.move.name, noop);
1540
+ }; // We create a new handler because the teardown function of another sensor
1541
+ // could remove our event listener if we use a referentially equal listener.
1542
+ function noop() {}
1543
+ }
1544
+ constructor(props){
1545
+ super(props, events$2);
1546
+ }
1547
+ }
1548
+ TouchSensor.activators = [
1549
+ {
1550
+ eventName: 'onTouchStart',
1551
+ handler: (_ref, _ref2)=>{
1552
+ let { nativeEvent: event } = _ref;
1553
+ let { onActivation } = _ref2;
1554
+ const { touches } = event;
1555
+ if (touches.length > 1) {
1556
+ return false;
1557
+ }
1558
+ onActivation == null ? void 0 : onActivation({
1559
+ event
1560
+ });
1561
+ return true;
1562
+ }
1563
+ }
1564
+ ];
1565
+ var AutoScrollActivator;
1566
+ (function(AutoScrollActivator) {
1567
+ AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
1568
+ AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
1569
+ })(AutoScrollActivator || (AutoScrollActivator = {}));
1570
+ var TraversalOrder;
1571
+ (function(TraversalOrder) {
1572
+ TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
1573
+ TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
1574
+ })(TraversalOrder || (TraversalOrder = {}));
1575
+ function useAutoScroller(_ref) {
1576
+ let { acceleration, activator = AutoScrollActivator.Pointer, canScroll, draggingRect, enabled, interval = 5, order = TraversalOrder.TreeOrder, pointerCoordinates, scrollableAncestors, scrollableAncestorRects, delta, threshold } = _ref;
1577
+ const scrollIntent = useScrollIntent({
1578
+ delta,
1579
+ disabled: !enabled
1580
+ });
1581
+ const [setAutoScrollInterval, clearAutoScrollInterval] = useInterval();
1582
+ const scrollSpeed = useRef({
1583
+ x: 0,
1584
+ y: 0
1585
+ });
1586
+ const scrollDirection = useRef({
1587
+ x: 0,
1588
+ y: 0
1589
+ });
1590
+ const rect = useMemo(()=>{
1591
+ switch(activator){
1592
+ case AutoScrollActivator.Pointer:
1593
+ return pointerCoordinates ? {
1594
+ top: pointerCoordinates.y,
1595
+ bottom: pointerCoordinates.y,
1596
+ left: pointerCoordinates.x,
1597
+ right: pointerCoordinates.x
1598
+ } : null;
1599
+ case AutoScrollActivator.DraggableRect:
1600
+ return draggingRect;
1601
+ }
1602
+ }, [
1603
+ activator,
1604
+ draggingRect,
1605
+ pointerCoordinates
1606
+ ]);
1607
+ const scrollContainerRef = useRef(null);
1608
+ const autoScroll = useCallback(()=>{
1609
+ const scrollContainer = scrollContainerRef.current;
1610
+ if (!scrollContainer) {
1611
+ return;
1612
+ }
1613
+ const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
1614
+ const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
1615
+ scrollContainer.scrollBy(scrollLeft, scrollTop);
1616
+ }, []);
1617
+ const sortedScrollableAncestors = useMemo(()=>order === TraversalOrder.TreeOrder ? [
1618
+ ...scrollableAncestors
1619
+ ].reverse() : scrollableAncestors, [
1620
+ order,
1621
+ scrollableAncestors
1622
+ ]);
1623
+ useEffect(()=>{
1624
+ if (!enabled || !scrollableAncestors.length || !rect) {
1625
+ clearAutoScrollInterval();
1626
+ return;
1627
+ }
1628
+ for (const scrollContainer of sortedScrollableAncestors){
1629
+ if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) {
1630
+ continue;
1631
+ }
1632
+ const index = scrollableAncestors.indexOf(scrollContainer);
1633
+ const scrollContainerRect = scrollableAncestorRects[index];
1634
+ if (!scrollContainerRect) {
1635
+ continue;
1636
+ }
1637
+ const { direction, speed } = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
1638
+ for (const axis of [
1639
+ 'x',
1640
+ 'y'
1641
+ ]){
1642
+ if (!scrollIntent[axis][direction[axis]]) {
1643
+ speed[axis] = 0;
1644
+ direction[axis] = 0;
1645
+ }
1646
+ }
1647
+ if (speed.x > 0 || speed.y > 0) {
1648
+ clearAutoScrollInterval();
1649
+ scrollContainerRef.current = scrollContainer;
1650
+ setAutoScrollInterval(autoScroll, interval);
1651
+ scrollSpeed.current = speed;
1652
+ scrollDirection.current = direction;
1653
+ return;
1654
+ }
1655
+ }
1656
+ scrollSpeed.current = {
1657
+ x: 0,
1658
+ y: 0
1659
+ };
1660
+ scrollDirection.current = {
1661
+ x: 0,
1662
+ y: 0
1663
+ };
1664
+ clearAutoScrollInterval();
1665
+ }, [
1666
+ acceleration,
1667
+ autoScroll,
1668
+ canScroll,
1669
+ clearAutoScrollInterval,
1670
+ enabled,
1671
+ interval,
1672
+ JSON.stringify(rect),
1673
+ JSON.stringify(scrollIntent),
1674
+ setAutoScrollInterval,
1675
+ scrollableAncestors,
1676
+ sortedScrollableAncestors,
1677
+ scrollableAncestorRects,
1678
+ JSON.stringify(threshold)
1679
+ ]);
1680
+ }
1681
+ const defaultScrollIntent = {
1682
+ x: {
1683
+ [Direction.Backward]: false,
1684
+ [Direction.Forward]: false
1685
+ },
1686
+ y: {
1687
+ [Direction.Backward]: false,
1688
+ [Direction.Forward]: false
1689
+ }
1690
+ };
1691
+ function useScrollIntent(_ref2) {
1692
+ let { delta, disabled } = _ref2;
1693
+ const previousDelta = usePrevious(delta);
1694
+ return useLazyMemo((previousIntent)=>{
1695
+ if (disabled || !previousDelta || !previousIntent) {
1696
+ // Reset scroll intent tracking when auto-scrolling is disabled
1697
+ return defaultScrollIntent;
1698
+ }
1699
+ const direction = {
1700
+ x: Math.sign(delta.x - previousDelta.x),
1701
+ y: Math.sign(delta.y - previousDelta.y)
1702
+ }; // Keep track of the user intent to scroll in each direction for both axis
1703
+ return {
1704
+ x: {
1705
+ [Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
1706
+ [Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
1707
+ },
1708
+ y: {
1709
+ [Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
1710
+ [Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
1711
+ }
1712
+ };
1713
+ }, [
1714
+ disabled,
1715
+ delta,
1716
+ previousDelta
1717
+ ]);
1718
+ }
1719
+ function useCachedNode(draggableNodes, id) {
1720
+ const draggableNode = id != null ? draggableNodes.get(id) : undefined;
1721
+ const node = draggableNode ? draggableNode.node.current : null;
1722
+ return useLazyMemo((cachedNode)=>{
1723
+ var _ref;
1724
+ if (id == null) {
1725
+ return null;
1726
+ } // In some cases, the draggable node can unmount while dragging
1727
+ // This is the case for virtualized lists. In those situations,
1728
+ // we fall back to the last known value for that node.
1729
+ return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
1730
+ }, [
1731
+ node,
1732
+ id
1733
+ ]);
1734
+ }
1735
+ function useCombineActivators(sensors, getSyntheticHandler) {
1736
+ return useMemo(()=>sensors.reduce((accumulator, sensor)=>{
1737
+ const { sensor: Sensor } = sensor;
1738
+ const sensorActivators = Sensor.activators.map((activator)=>({
1739
+ eventName: activator.eventName,
1740
+ handler: getSyntheticHandler(activator.handler, sensor)
1741
+ }));
1742
+ return [
1743
+ ...accumulator,
1744
+ ...sensorActivators
1745
+ ];
1746
+ }, []), [
1747
+ sensors,
1748
+ getSyntheticHandler
1749
+ ]);
1750
+ }
1751
+ var MeasuringStrategy;
1752
+ (function(MeasuringStrategy) {
1753
+ MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
1754
+ MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
1755
+ MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
1756
+ })(MeasuringStrategy || (MeasuringStrategy = {}));
1757
+ var MeasuringFrequency;
1758
+ (function(MeasuringFrequency) {
1759
+ MeasuringFrequency["Optimized"] = "optimized";
1760
+ })(MeasuringFrequency || (MeasuringFrequency = {}));
1761
+ const defaultValue = /*#__PURE__*/ new Map();
1762
+ function useDroppableMeasuring(containers, _ref) {
1763
+ let { dragging, dependencies, config } = _ref;
1764
+ const [queue, setQueue] = useState(null);
1765
+ const { frequency, measure, strategy } = config;
1766
+ const containersRef = useRef(containers);
1767
+ const disabled = isDisabled();
1768
+ const disabledRef = useLatestValue(disabled);
1769
+ const measureDroppableContainers = useCallback(function(ids) {
1770
+ if (ids === void 0) {
1771
+ ids = [];
1772
+ }
1773
+ if (disabledRef.current) {
1774
+ return;
1775
+ }
1776
+ setQueue((value)=>{
1777
+ if (value === null) {
1778
+ return ids;
1779
+ }
1780
+ return value.concat(ids.filter((id)=>!value.includes(id)));
1781
+ });
1782
+ }, [
1783
+ disabledRef
1784
+ ]);
1785
+ const timeoutId = useRef(null);
1786
+ const droppableRects = useLazyMemo((previousValue)=>{
1787
+ if (disabled && !dragging) {
1788
+ return defaultValue;
1789
+ }
1790
+ if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
1791
+ const map = new Map();
1792
+ for (let container of containers){
1793
+ if (!container) {
1794
+ continue;
1795
+ }
1796
+ if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
1797
+ // This container does not need to be re-measured
1798
+ map.set(container.id, container.rect.current);
1799
+ continue;
1800
+ }
1801
+ const node = container.node.current;
1802
+ const rect = node ? new Rect(measure(node), node) : null;
1803
+ container.rect.current = rect;
1804
+ if (rect) {
1805
+ map.set(container.id, rect);
1806
+ }
1807
+ }
1808
+ return map;
1809
+ }
1810
+ return previousValue;
1811
+ }, [
1812
+ containers,
1813
+ queue,
1814
+ dragging,
1815
+ disabled,
1816
+ measure
1817
+ ]);
1818
+ useEffect(()=>{
1819
+ containersRef.current = containers;
1820
+ }, [
1821
+ containers
1822
+ ]);
1823
+ useEffect(()=>{
1824
+ if (disabled) {
1825
+ return;
1826
+ }
1827
+ measureDroppableContainers();
1828
+ }, [
1829
+ dragging,
1830
+ disabled
1831
+ ]);
1832
+ useEffect(()=>{
1833
+ if (queue && queue.length > 0) {
1834
+ setQueue(null);
1835
+ }
1836
+ }, [
1837
+ JSON.stringify(queue)
1838
+ ]);
1839
+ useEffect(()=>{
1840
+ if (disabled || typeof frequency !== 'number' || timeoutId.current !== null) {
1841
+ return;
1842
+ }
1843
+ timeoutId.current = setTimeout(()=>{
1844
+ measureDroppableContainers();
1845
+ timeoutId.current = null;
1846
+ }, frequency);
1847
+ }, [
1848
+ frequency,
1849
+ disabled,
1850
+ measureDroppableContainers,
1851
+ ...dependencies
1852
+ ]);
1853
+ return {
1854
+ droppableRects,
1855
+ measureDroppableContainers,
1856
+ measuringScheduled: queue != null
1857
+ };
1858
+ function isDisabled() {
1859
+ switch(strategy){
1860
+ case MeasuringStrategy.Always:
1861
+ return false;
1862
+ case MeasuringStrategy.BeforeDragging:
1863
+ return dragging;
1864
+ default:
1865
+ return !dragging;
1866
+ }
1867
+ }
1868
+ }
1869
+ function useInitialValue(value, computeFn) {
1870
+ return useLazyMemo((previousValue)=>{
1871
+ if (!value) {
1872
+ return null;
1873
+ }
1874
+ if (previousValue) {
1875
+ return previousValue;
1876
+ }
1877
+ return typeof computeFn === 'function' ? computeFn(value) : value;
1878
+ }, [
1879
+ computeFn,
1880
+ value
1881
+ ]);
1882
+ }
1883
+ function useInitialRect(node, measure) {
1884
+ return useInitialValue(node, measure);
1885
+ }
1886
+ /**
1887
+ * Returns a new MutationObserver instance.
1888
+ * If `MutationObserver` is undefined in the execution environment, returns `undefined`.
1889
+ */ function useMutationObserver(_ref) {
1890
+ let { callback, disabled } = _ref;
1891
+ const handleMutations = useEvent(callback);
1892
+ const mutationObserver = useMemo(()=>{
1893
+ if (disabled || typeof window === 'undefined' || typeof window.MutationObserver === 'undefined') {
1894
+ return undefined;
1895
+ }
1896
+ const { MutationObserver } = window;
1897
+ return new MutationObserver(handleMutations);
1898
+ }, [
1899
+ handleMutations,
1900
+ disabled
1901
+ ]);
1902
+ useEffect(()=>{
1903
+ return ()=>mutationObserver == null ? void 0 : mutationObserver.disconnect();
1904
+ }, [
1905
+ mutationObserver
1906
+ ]);
1907
+ return mutationObserver;
1908
+ }
1909
+ /**
1910
+ * Returns a new ResizeObserver instance bound to the `onResize` callback.
1911
+ * If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
1912
+ */ function useResizeObserver(_ref) {
1913
+ let { callback, disabled } = _ref;
1914
+ const handleResize = useEvent(callback);
1915
+ const resizeObserver = useMemo(()=>{
1916
+ if (disabled || typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
1917
+ return undefined;
1918
+ }
1919
+ const { ResizeObserver } = window;
1920
+ return new ResizeObserver(handleResize);
1921
+ }, [
1922
+ disabled
1923
+ ]);
1924
+ useEffect(()=>{
1925
+ return ()=>resizeObserver == null ? void 0 : resizeObserver.disconnect();
1926
+ }, [
1927
+ resizeObserver
1928
+ ]);
1929
+ return resizeObserver;
1930
+ }
1931
+ function defaultMeasure(element) {
1932
+ return new Rect(getClientRect(element), element);
1933
+ }
1934
+ function useRect(element, measure, fallbackRect) {
1935
+ if (measure === void 0) {
1936
+ measure = defaultMeasure;
1937
+ }
1938
+ const [rect, setRect] = useState(null);
1939
+ function measureRect() {
1940
+ setRect((currentRect)=>{
1941
+ if (!element) {
1942
+ return null;
1943
+ }
1944
+ if (element.isConnected === false) {
1945
+ var _ref;
1946
+ // Fall back to last rect we measured if the element is
1947
+ // no longer connected to the DOM.
1948
+ return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
1949
+ }
1950
+ const newRect = measure(element);
1951
+ if (JSON.stringify(currentRect) === JSON.stringify(newRect)) {
1952
+ return currentRect;
1953
+ }
1954
+ return newRect;
1955
+ });
1956
+ }
1957
+ const mutationObserver = useMutationObserver({
1958
+ callback (records) {
1959
+ if (!element) {
1960
+ return;
1961
+ }
1962
+ for (const record of records){
1963
+ const { type, target } = record;
1964
+ if (type === 'childList' && target instanceof HTMLElement && target.contains(element)) {
1965
+ measureRect();
1966
+ break;
1967
+ }
1968
+ }
1969
+ }
1970
+ });
1971
+ const resizeObserver = useResizeObserver({
1972
+ callback: measureRect
1973
+ });
1974
+ useIsomorphicLayoutEffect(()=>{
1975
+ measureRect();
1976
+ if (element) {
1977
+ resizeObserver == null ? void 0 : resizeObserver.observe(element);
1978
+ mutationObserver == null ? void 0 : mutationObserver.observe(document.body, {
1979
+ childList: true,
1980
+ subtree: true
1981
+ });
1982
+ } else {
1983
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
1984
+ mutationObserver == null ? void 0 : mutationObserver.disconnect();
1985
+ }
1986
+ }, [
1987
+ element
1988
+ ]);
1989
+ return rect;
1990
+ }
1991
+ function useRectDelta(rect) {
1992
+ const initialRect = useInitialValue(rect);
1993
+ return getRectDelta(rect, initialRect);
1994
+ }
1995
+ const defaultValue$1 = [];
1996
+ function useScrollableAncestors(node) {
1997
+ const previousNode = useRef(node);
1998
+ const ancestors = useLazyMemo((previousValue)=>{
1999
+ if (!node) {
2000
+ return defaultValue$1;
2001
+ }
2002
+ if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) {
2003
+ return previousValue;
2004
+ }
2005
+ return getScrollableAncestors(node);
2006
+ }, [
2007
+ node
2008
+ ]);
2009
+ useEffect(()=>{
2010
+ previousNode.current = node;
2011
+ }, [
2012
+ node
2013
+ ]);
2014
+ return ancestors;
2015
+ }
2016
+ function useScrollOffsets(elements) {
2017
+ const [scrollCoordinates, setScrollCoordinates] = useState(null);
2018
+ const prevElements = useRef(elements); // To-do: Throttle the handleScroll callback
2019
+ const handleScroll = useCallback((event)=>{
2020
+ const scrollingElement = getScrollableElement(event.target);
2021
+ if (!scrollingElement) {
2022
+ return;
2023
+ }
2024
+ setScrollCoordinates((scrollCoordinates)=>{
2025
+ if (!scrollCoordinates) {
2026
+ return null;
2027
+ }
2028
+ scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
2029
+ return new Map(scrollCoordinates);
2030
+ });
2031
+ }, []);
2032
+ useEffect(()=>{
2033
+ const previousElements = prevElements.current;
2034
+ if (elements !== previousElements) {
2035
+ cleanup(previousElements);
2036
+ const entries = elements.map((element)=>{
2037
+ const scrollableElement = getScrollableElement(element);
2038
+ if (scrollableElement) {
2039
+ scrollableElement.addEventListener('scroll', handleScroll, {
2040
+ passive: true
2041
+ });
2042
+ return [
2043
+ scrollableElement,
2044
+ getScrollCoordinates(scrollableElement)
2045
+ ];
2046
+ }
2047
+ return null;
2048
+ }).filter((entry)=>entry != null);
2049
+ setScrollCoordinates(entries.length ? new Map(entries) : null);
2050
+ prevElements.current = elements;
2051
+ }
2052
+ return ()=>{
2053
+ cleanup(elements);
2054
+ cleanup(previousElements);
2055
+ };
2056
+ function cleanup(elements) {
2057
+ elements.forEach((element)=>{
2058
+ const scrollableElement = getScrollableElement(element);
2059
+ scrollableElement == null ? void 0 : scrollableElement.removeEventListener('scroll', handleScroll);
2060
+ });
2061
+ }
2062
+ }, [
2063
+ handleScroll,
2064
+ elements
2065
+ ]);
2066
+ return useMemo(()=>{
2067
+ if (elements.length) {
2068
+ return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates)=>add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
2069
+ }
2070
+ return defaultCoordinates;
2071
+ }, [
2072
+ elements,
2073
+ scrollCoordinates
2074
+ ]);
2075
+ }
2076
+ function useScrollOffsetsDelta(scrollOffsets, dependencies) {
2077
+ if (dependencies === void 0) {
2078
+ dependencies = [];
2079
+ }
2080
+ const initialScrollOffsets = useRef(null);
2081
+ useEffect(()=>{
2082
+ initialScrollOffsets.current = null;
2083
+ }, dependencies);
2084
+ useEffect(()=>{
2085
+ const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
2086
+ if (hasScrollOffsets && !initialScrollOffsets.current) {
2087
+ initialScrollOffsets.current = scrollOffsets;
2088
+ }
2089
+ if (!hasScrollOffsets && initialScrollOffsets.current) {
2090
+ initialScrollOffsets.current = null;
2091
+ }
2092
+ }, [
2093
+ scrollOffsets
2094
+ ]);
2095
+ return initialScrollOffsets.current ? subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
2096
+ }
2097
+ function useSensorSetup(sensors) {
2098
+ useEffect(()=>{
2099
+ if (!canUseDOM) {
2100
+ return;
2101
+ }
2102
+ const teardownFns = sensors.map((_ref)=>{
2103
+ let { sensor } = _ref;
2104
+ return sensor.setup == null ? void 0 : sensor.setup();
2105
+ });
2106
+ return ()=>{
2107
+ for (const teardown of teardownFns){
2108
+ teardown == null ? void 0 : teardown();
2109
+ }
2110
+ };
2111
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
2112
+ sensors.map((_ref2)=>{
2113
+ let { sensor } = _ref2;
2114
+ return sensor;
2115
+ }));
2116
+ }
2117
+ function useSyntheticListeners(listeners, id) {
2118
+ return useMemo(()=>{
2119
+ return listeners.reduce((acc, _ref)=>{
2120
+ let { eventName, handler } = _ref;
2121
+ acc[eventName] = (event)=>{
2122
+ handler(event, id);
2123
+ };
2124
+ return acc;
2125
+ }, {});
2126
+ }, [
2127
+ listeners,
2128
+ id
2129
+ ]);
2130
+ }
2131
+ function useWindowRect(element) {
2132
+ return useMemo(()=>element ? getWindowClientRect(element) : null, [
2133
+ element
2134
+ ]);
2135
+ }
2136
+ const defaultValue$2 = [];
2137
+ function useRects(elements, measure) {
2138
+ if (measure === void 0) {
2139
+ measure = getClientRect;
2140
+ }
2141
+ const [firstElement] = elements;
2142
+ const windowRect = useWindowRect(firstElement ? getWindow(firstElement) : null);
2143
+ const [rects, setRects] = useState(defaultValue$2);
2144
+ function measureRects() {
2145
+ setRects(()=>{
2146
+ if (!elements.length) {
2147
+ return defaultValue$2;
2148
+ }
2149
+ return elements.map((element)=>isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
2150
+ });
2151
+ }
2152
+ const resizeObserver = useResizeObserver({
2153
+ callback: measureRects
2154
+ });
2155
+ useIsomorphicLayoutEffect(()=>{
2156
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
2157
+ measureRects();
2158
+ elements.forEach((element)=>resizeObserver == null ? void 0 : resizeObserver.observe(element));
2159
+ }, [
2160
+ elements
2161
+ ]);
2162
+ return rects;
2163
+ }
2164
+ function getMeasurableNode(node) {
2165
+ if (!node) {
2166
+ return null;
2167
+ }
2168
+ if (node.children.length > 1) {
2169
+ return node;
2170
+ }
2171
+ const firstChild = node.children[0];
2172
+ return isHTMLElement(firstChild) ? firstChild : node;
2173
+ }
2174
+ function useDragOverlayMeasuring(_ref) {
2175
+ let { measure } = _ref;
2176
+ const [rect, setRect] = useState(null);
2177
+ const handleResize = useCallback((entries)=>{
2178
+ for (const { target } of entries){
2179
+ if (isHTMLElement(target)) {
2180
+ setRect((rect)=>{
2181
+ const newRect = measure(target);
2182
+ return rect ? {
2183
+ ...rect,
2184
+ width: newRect.width,
2185
+ height: newRect.height
2186
+ } : newRect;
2187
+ });
2188
+ break;
2189
+ }
2190
+ }
2191
+ }, [
2192
+ measure
2193
+ ]);
2194
+ const resizeObserver = useResizeObserver({
2195
+ callback: handleResize
2196
+ });
2197
+ const handleNodeChange = useCallback((element)=>{
2198
+ const node = getMeasurableNode(element);
2199
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
2200
+ if (node) {
2201
+ resizeObserver == null ? void 0 : resizeObserver.observe(node);
2202
+ }
2203
+ setRect(node ? measure(node) : null);
2204
+ }, [
2205
+ measure,
2206
+ resizeObserver
2207
+ ]);
2208
+ const [nodeRef, setRef] = useNodeRef(handleNodeChange);
2209
+ return useMemo(()=>({
2210
+ nodeRef,
2211
+ rect,
2212
+ setRef
2213
+ }), [
2214
+ rect,
2215
+ nodeRef,
2216
+ setRef
2217
+ ]);
2218
+ }
2219
+ const defaultSensors = [
2220
+ {
2221
+ sensor: PointerSensor,
2222
+ options: {}
2223
+ },
2224
+ {
2225
+ sensor: KeyboardSensor,
2226
+ options: {}
2227
+ }
2228
+ ];
2229
+ const defaultData = {
2230
+ current: {}
2231
+ };
2232
+ const defaultMeasuringConfiguration = {
2233
+ draggable: {
2234
+ measure: getTransformAgnosticClientRect
2235
+ },
2236
+ droppable: {
2237
+ measure: getTransformAgnosticClientRect,
2238
+ strategy: MeasuringStrategy.WhileDragging,
2239
+ frequency: MeasuringFrequency.Optimized
2240
+ },
2241
+ dragOverlay: {
2242
+ measure: getClientRect
2243
+ }
2244
+ };
2245
+ class DroppableContainersMap extends Map {
2246
+ get(id) {
2247
+ var _super$get;
2248
+ return id != null ? (_super$get = super.get(id)) != null ? _super$get : undefined : undefined;
2249
+ }
2250
+ toArray() {
2251
+ return Array.from(this.values());
2252
+ }
2253
+ getEnabled() {
2254
+ return this.toArray().filter((_ref)=>{
2255
+ let { disabled } = _ref;
2256
+ return !disabled;
2257
+ });
2258
+ }
2259
+ getNodeFor(id) {
2260
+ var _this$get$node$curren, _this$get;
2261
+ return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : undefined;
2262
+ }
2263
+ }
2264
+ const defaultPublicContext = {
2265
+ activatorEvent: null,
2266
+ active: null,
2267
+ activeNode: null,
2268
+ activeNodeRect: null,
2269
+ collisions: null,
2270
+ containerNodeRect: null,
2271
+ draggableNodes: /*#__PURE__*/ new Map(),
2272
+ droppableRects: /*#__PURE__*/ new Map(),
2273
+ droppableContainers: /*#__PURE__*/ new DroppableContainersMap(),
2274
+ over: null,
2275
+ dragOverlay: {
2276
+ nodeRef: {
2277
+ current: null
2278
+ },
2279
+ rect: null,
2280
+ setRef: noop
2281
+ },
2282
+ scrollableAncestors: [],
2283
+ scrollableAncestorRects: [],
2284
+ measuringConfiguration: defaultMeasuringConfiguration,
2285
+ measureDroppableContainers: noop,
2286
+ windowRect: null,
2287
+ measuringScheduled: false
2288
+ };
2289
+ const defaultInternalContext = {
2290
+ activatorEvent: null,
2291
+ activators: [],
2292
+ active: null,
2293
+ activeNodeRect: null,
2294
+ ariaDescribedById: {
2295
+ draggable: ''
2296
+ },
2297
+ dispatch: noop,
2298
+ draggableNodes: /*#__PURE__*/ new Map(),
2299
+ over: null,
2300
+ measureDroppableContainers: noop
2301
+ };
2302
+ const InternalContext = /*#__PURE__*/ createContext(defaultInternalContext);
2303
+ const PublicContext = /*#__PURE__*/ createContext(defaultPublicContext);
2304
+ function getInitialState() {
2305
+ return {
2306
+ draggable: {
2307
+ active: null,
2308
+ initialCoordinates: {
2309
+ x: 0,
2310
+ y: 0
2311
+ },
2312
+ nodes: new Map(),
2313
+ translate: {
2314
+ x: 0,
2315
+ y: 0
2316
+ }
2317
+ },
2318
+ droppable: {
2319
+ containers: new DroppableContainersMap()
2320
+ }
2321
+ };
2322
+ }
2323
+ function reducer(state, action) {
2324
+ switch(action.type){
2325
+ case Action.DragStart:
2326
+ return {
2327
+ ...state,
2328
+ draggable: {
2329
+ ...state.draggable,
2330
+ initialCoordinates: action.initialCoordinates,
2331
+ active: action.active
2332
+ }
2333
+ };
2334
+ case Action.DragMove:
2335
+ if (state.draggable.active == null) {
2336
+ return state;
2337
+ }
2338
+ return {
2339
+ ...state,
2340
+ draggable: {
2341
+ ...state.draggable,
2342
+ translate: {
2343
+ x: action.coordinates.x - state.draggable.initialCoordinates.x,
2344
+ y: action.coordinates.y - state.draggable.initialCoordinates.y
2345
+ }
2346
+ }
2347
+ };
2348
+ case Action.DragEnd:
2349
+ case Action.DragCancel:
2350
+ return {
2351
+ ...state,
2352
+ draggable: {
2353
+ ...state.draggable,
2354
+ active: null,
2355
+ initialCoordinates: {
2356
+ x: 0,
2357
+ y: 0
2358
+ },
2359
+ translate: {
2360
+ x: 0,
2361
+ y: 0
2362
+ }
2363
+ }
2364
+ };
2365
+ case Action.RegisterDroppable:
2366
+ {
2367
+ const { element } = action;
2368
+ const { id } = element;
2369
+ const containers = new DroppableContainersMap(state.droppable.containers);
2370
+ containers.set(id, element);
2371
+ return {
2372
+ ...state,
2373
+ droppable: {
2374
+ ...state.droppable,
2375
+ containers
2376
+ }
2377
+ };
2378
+ }
2379
+ case Action.SetDroppableDisabled:
2380
+ {
2381
+ const { id, key, disabled } = action;
2382
+ const element = state.droppable.containers.get(id);
2383
+ if (!element || key !== element.key) {
2384
+ return state;
2385
+ }
2386
+ const containers = new DroppableContainersMap(state.droppable.containers);
2387
+ containers.set(id, {
2388
+ ...element,
2389
+ disabled
2390
+ });
2391
+ return {
2392
+ ...state,
2393
+ droppable: {
2394
+ ...state.droppable,
2395
+ containers
2396
+ }
2397
+ };
2398
+ }
2399
+ case Action.UnregisterDroppable:
2400
+ {
2401
+ const { id, key } = action;
2402
+ const element = state.droppable.containers.get(id);
2403
+ if (!element || key !== element.key) {
2404
+ return state;
2405
+ }
2406
+ const containers = new DroppableContainersMap(state.droppable.containers);
2407
+ containers.delete(id);
2408
+ return {
2409
+ ...state,
2410
+ droppable: {
2411
+ ...state.droppable,
2412
+ containers
2413
+ }
2414
+ };
2415
+ }
2416
+ default:
2417
+ {
2418
+ return state;
2419
+ }
2420
+ }
2421
+ }
2422
+ function RestoreFocus(_ref) {
2423
+ let { disabled } = _ref;
2424
+ const { active, activatorEvent, draggableNodes } = useContext(InternalContext);
2425
+ const previousActivatorEvent = usePrevious(activatorEvent);
2426
+ const previousActiveId = usePrevious(active == null ? void 0 : active.id); // Restore keyboard focus on the activator node
2427
+ useEffect(()=>{
2428
+ if (disabled) {
2429
+ return;
2430
+ }
2431
+ if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
2432
+ if (!isKeyboardEvent(previousActivatorEvent)) {
2433
+ return;
2434
+ }
2435
+ if (document.activeElement === previousActivatorEvent.target) {
2436
+ // No need to restore focus
2437
+ return;
2438
+ }
2439
+ const draggableNode = draggableNodes.get(previousActiveId);
2440
+ if (!draggableNode) {
2441
+ return;
2442
+ }
2443
+ const { activatorNode, node } = draggableNode;
2444
+ if (!activatorNode.current && !node.current) {
2445
+ return;
2446
+ }
2447
+ requestAnimationFrame(()=>{
2448
+ for (const element of [
2449
+ activatorNode.current,
2450
+ node.current
2451
+ ]){
2452
+ if (!element) {
2453
+ continue;
2454
+ }
2455
+ const focusableNode = findFirstFocusableNode(element);
2456
+ if (focusableNode) {
2457
+ focusableNode.focus();
2458
+ break;
2459
+ }
2460
+ }
2461
+ });
2462
+ }
2463
+ }, [
2464
+ activatorEvent,
2465
+ disabled,
2466
+ draggableNodes,
2467
+ previousActiveId,
2468
+ previousActivatorEvent
2469
+ ]);
2470
+ return null;
2471
+ }
2472
+ function applyModifiers(modifiers, _ref) {
2473
+ let { transform, ...args } = _ref;
2474
+ return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier)=>{
2475
+ return modifier({
2476
+ transform: accumulator,
2477
+ ...args
2478
+ });
2479
+ }, transform) : transform;
2480
+ }
2481
+ function useMeasuringConfiguration(config) {
2482
+ return useMemo(()=>({
2483
+ draggable: {
2484
+ ...defaultMeasuringConfiguration.draggable,
2485
+ ...config == null ? void 0 : config.draggable
2486
+ },
2487
+ droppable: {
2488
+ ...defaultMeasuringConfiguration.droppable,
2489
+ ...config == null ? void 0 : config.droppable
2490
+ },
2491
+ dragOverlay: {
2492
+ ...defaultMeasuringConfiguration.dragOverlay,
2493
+ ...config == null ? void 0 : config.dragOverlay
2494
+ }
2495
+ }), [
2496
+ config == null ? void 0 : config.draggable,
2497
+ config == null ? void 0 : config.droppable,
2498
+ config == null ? void 0 : config.dragOverlay
2499
+ ]);
2500
+ }
2501
+ function useLayoutShiftScrollCompensation(_ref) {
2502
+ let { activeNode, measure, initialRect, config = true } = _ref;
2503
+ const initialized = useRef(false);
2504
+ const { x, y } = typeof config === 'boolean' ? {
2505
+ x: config,
2506
+ y: config
2507
+ } : config;
2508
+ useIsomorphicLayoutEffect(()=>{
2509
+ const disabled = !x && !y;
2510
+ if (disabled || !activeNode) {
2511
+ initialized.current = false;
2512
+ return;
2513
+ }
2514
+ if (initialized.current || !initialRect) {
2515
+ // Return early if layout shift scroll compensation was already attempted
2516
+ // or if there is no initialRect to compare to.
2517
+ return;
2518
+ } // Get the most up to date node ref for the active draggable
2519
+ const node = activeNode == null ? void 0 : activeNode.node.current;
2520
+ if (!node || node.isConnected === false) {
2521
+ // Return early if there is no attached node ref or if the node is
2522
+ // disconnected from the document.
2523
+ return;
2524
+ }
2525
+ const rect = measure(node);
2526
+ const rectDelta = getRectDelta(rect, initialRect);
2527
+ if (!x) {
2528
+ rectDelta.x = 0;
2529
+ }
2530
+ if (!y) {
2531
+ rectDelta.y = 0;
2532
+ } // Only perform layout shift scroll compensation once
2533
+ initialized.current = true;
2534
+ if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
2535
+ const firstScrollableAncestor = getFirstScrollableAncestor(node);
2536
+ if (firstScrollableAncestor) {
2537
+ firstScrollableAncestor.scrollBy({
2538
+ top: rectDelta.y,
2539
+ left: rectDelta.x
2540
+ });
2541
+ }
2542
+ }
2543
+ }, [
2544
+ activeNode,
2545
+ x,
2546
+ y,
2547
+ initialRect,
2548
+ measure
2549
+ ]);
2550
+ }
2551
+ const ActiveDraggableContext = /*#__PURE__*/ createContext({
2552
+ ...defaultCoordinates,
2553
+ scaleX: 1,
2554
+ scaleY: 1
2555
+ });
2556
+ var Status;
2557
+ (function(Status) {
2558
+ Status[Status["Uninitialized"] = 0] = "Uninitialized";
2559
+ Status[Status["Initializing"] = 1] = "Initializing";
2560
+ Status[Status["Initialized"] = 2] = "Initialized";
2561
+ })(Status || (Status = {}));
2562
+ const DndContext = /*#__PURE__*/ memo(function DndContext(_ref) {
2563
+ var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
2564
+ let { id, accessibility, autoScroll = true, children, sensors = defaultSensors, collisionDetection = rectIntersection, measuring, modifiers, ...props } = _ref;
2565
+ const store = useReducer(reducer, undefined, getInitialState);
2566
+ const [state, dispatch] = store;
2567
+ const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
2568
+ const [status, setStatus] = useState(Status.Uninitialized);
2569
+ const isInitialized = status === Status.Initialized;
2570
+ const { draggable: { active: activeId, nodes: draggableNodes, translate }, droppable: { containers: droppableContainers } } = state;
2571
+ const node = activeId != null ? draggableNodes.get(activeId) : null;
2572
+ const activeRects = useRef({
2573
+ initial: null,
2574
+ translated: null
2575
+ });
2576
+ const active = useMemo(()=>{
2577
+ var _node$data;
2578
+ return activeId != null ? {
2579
+ id: activeId,
2580
+ // It's possible for the active node to unmount while dragging
2581
+ data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
2582
+ rect: activeRects
2583
+ } : null;
2584
+ }, [
2585
+ activeId,
2586
+ node
2587
+ ]);
2588
+ const activeRef = useRef(null);
2589
+ const [activeSensor, setActiveSensor] = useState(null);
2590
+ const [activatorEvent, setActivatorEvent] = useState(null);
2591
+ const latestProps = useLatestValue(props, Object.values(props));
2592
+ const draggableDescribedById = useUniqueId("DndDescribedBy", id);
2593
+ const enabledDroppableContainers = useMemo(()=>droppableContainers.getEnabled(), [
2594
+ droppableContainers
2595
+ ]);
2596
+ const measuringConfiguration = useMeasuringConfiguration(measuring);
2597
+ const { droppableRects, measureDroppableContainers, measuringScheduled } = useDroppableMeasuring(enabledDroppableContainers, {
2598
+ dragging: isInitialized,
2599
+ dependencies: [
2600
+ translate.x,
2601
+ translate.y
2602
+ ],
2603
+ config: measuringConfiguration.droppable
2604
+ });
2605
+ const activeNode = useCachedNode(draggableNodes, activeId);
2606
+ const activationCoordinates = useMemo(()=>activatorEvent ? getEventCoordinates(activatorEvent) : null, [
2607
+ activatorEvent
2608
+ ]);
2609
+ const autoScrollOptions = getAutoScrollerOptions();
2610
+ const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
2611
+ useLayoutShiftScrollCompensation({
2612
+ activeNode: activeId != null ? draggableNodes.get(activeId) : null,
2613
+ config: autoScrollOptions.layoutShiftCompensation,
2614
+ initialRect: initialActiveNodeRect,
2615
+ measure: measuringConfiguration.draggable.measure
2616
+ });
2617
+ const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
2618
+ const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
2619
+ const sensorContext = useRef({
2620
+ activatorEvent: null,
2621
+ active: null,
2622
+ activeNode,
2623
+ collisionRect: null,
2624
+ collisions: null,
2625
+ droppableRects,
2626
+ draggableNodes,
2627
+ draggingNode: null,
2628
+ draggingNodeRect: null,
2629
+ droppableContainers,
2630
+ over: null,
2631
+ scrollableAncestors: [],
2632
+ scrollAdjustedTranslate: null
2633
+ });
2634
+ const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
2635
+ const dragOverlay = useDragOverlayMeasuring({
2636
+ measure: measuringConfiguration.dragOverlay.measure
2637
+ }); // Use the rect of the drag overlay if it is mounted
2638
+ const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
2639
+ const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
2640
+ const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect); // The delta between the previous and new position of the draggable node
2641
+ // is only relevant when there is no drag overlay
2642
+ const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect); // Get the window rect of the dragging node
2643
+ const windowRect = useWindowRect(draggingNode ? getWindow(draggingNode) : null); // Get scrollable ancestors of the dragging node
2644
+ const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
2645
+ const scrollableAncestorRects = useRects(scrollableAncestors); // Apply modifiers
2646
+ const modifiedTranslate = applyModifiers(modifiers, {
2647
+ transform: {
2648
+ x: translate.x - nodeRectDelta.x,
2649
+ y: translate.y - nodeRectDelta.y,
2650
+ scaleX: 1,
2651
+ scaleY: 1
2652
+ },
2653
+ activatorEvent,
2654
+ active,
2655
+ activeNodeRect,
2656
+ containerNodeRect,
2657
+ draggingNodeRect,
2658
+ over: sensorContext.current.over,
2659
+ overlayNodeRect: dragOverlay.rect,
2660
+ scrollableAncestors,
2661
+ scrollableAncestorRects,
2662
+ windowRect
2663
+ });
2664
+ const pointerCoordinates = activationCoordinates ? add(activationCoordinates, translate) : null;
2665
+ const scrollOffsets = useScrollOffsets(scrollableAncestors); // Represents the scroll delta since dragging was initiated
2666
+ const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets); // Represents the scroll delta since the last time the active node rect was measured
2667
+ const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [
2668
+ activeNodeRect
2669
+ ]);
2670
+ const scrollAdjustedTranslate = add(modifiedTranslate, scrollAdjustment);
2671
+ const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
2672
+ const collisions = active && collisionRect ? collisionDetection({
2673
+ active,
2674
+ collisionRect,
2675
+ droppableRects,
2676
+ droppableContainers: enabledDroppableContainers,
2677
+ pointerCoordinates
2678
+ }) : null;
2679
+ const overId = getFirstCollision(collisions, 'id');
2680
+ const [over, setOver] = useState(null); // When there is no drag overlay used, we need to account for the
2681
+ // window scroll delta
2682
+ const appliedTranslate = usesDragOverlay ? modifiedTranslate : add(modifiedTranslate, activeNodeScrollDelta);
2683
+ const transform = adjustScale(appliedTranslate, (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
2684
+ const activeSensorRef = useRef(null);
2685
+ const instantiateSensor = useCallback((event, _ref2)=>{
2686
+ let { sensor: Sensor, options } = _ref2;
2687
+ if (activeRef.current == null) {
2688
+ return;
2689
+ }
2690
+ const activeNode = draggableNodes.get(activeRef.current);
2691
+ if (!activeNode) {
2692
+ return;
2693
+ }
2694
+ const activatorEvent = event.nativeEvent;
2695
+ const sensorInstance = new Sensor({
2696
+ active: activeRef.current,
2697
+ activeNode,
2698
+ event: activatorEvent,
2699
+ options,
2700
+ // Sensors need to be instantiated with refs for arguments that change over time
2701
+ // otherwise they are frozen in time with the stale arguments
2702
+ context: sensorContext,
2703
+ onAbort (id) {
2704
+ const draggableNode = draggableNodes.get(id);
2705
+ if (!draggableNode) {
2706
+ return;
2707
+ }
2708
+ const { onDragAbort } = latestProps.current;
2709
+ const event = {
2710
+ id
2711
+ };
2712
+ onDragAbort == null ? void 0 : onDragAbort(event);
2713
+ dispatchMonitorEvent({
2714
+ type: 'onDragAbort',
2715
+ event
2716
+ });
2717
+ },
2718
+ onPending (id, constraint, initialCoordinates, offset) {
2719
+ const draggableNode = draggableNodes.get(id);
2720
+ if (!draggableNode) {
2721
+ return;
2722
+ }
2723
+ const { onDragPending } = latestProps.current;
2724
+ const event = {
2725
+ id,
2726
+ constraint,
2727
+ initialCoordinates,
2728
+ offset
2729
+ };
2730
+ onDragPending == null ? void 0 : onDragPending(event);
2731
+ dispatchMonitorEvent({
2732
+ type: 'onDragPending',
2733
+ event
2734
+ });
2735
+ },
2736
+ onStart (initialCoordinates) {
2737
+ const id = activeRef.current;
2738
+ if (id == null) {
2739
+ return;
2740
+ }
2741
+ const draggableNode = draggableNodes.get(id);
2742
+ if (!draggableNode) {
2743
+ return;
2744
+ }
2745
+ const { onDragStart } = latestProps.current;
2746
+ const event = {
2747
+ activatorEvent,
2748
+ active: {
2749
+ id,
2750
+ data: draggableNode.data,
2751
+ rect: activeRects
2752
+ }
2753
+ };
2754
+ unstable_batchedUpdates(()=>{
2755
+ onDragStart == null ? void 0 : onDragStart(event);
2756
+ setStatus(Status.Initializing);
2757
+ dispatch({
2758
+ type: Action.DragStart,
2759
+ initialCoordinates,
2760
+ active: id
2761
+ });
2762
+ dispatchMonitorEvent({
2763
+ type: 'onDragStart',
2764
+ event
2765
+ });
2766
+ setActiveSensor(activeSensorRef.current);
2767
+ setActivatorEvent(activatorEvent);
2768
+ });
2769
+ },
2770
+ onMove (coordinates) {
2771
+ dispatch({
2772
+ type: Action.DragMove,
2773
+ coordinates
2774
+ });
2775
+ },
2776
+ onEnd: createHandler(Action.DragEnd),
2777
+ onCancel: createHandler(Action.DragCancel)
2778
+ });
2779
+ activeSensorRef.current = sensorInstance;
2780
+ function createHandler(type) {
2781
+ return async function handler() {
2782
+ const { active, collisions, over, scrollAdjustedTranslate } = sensorContext.current;
2783
+ let event = null;
2784
+ if (active && scrollAdjustedTranslate) {
2785
+ const { cancelDrop } = latestProps.current;
2786
+ event = {
2787
+ activatorEvent,
2788
+ active: active,
2789
+ collisions,
2790
+ delta: scrollAdjustedTranslate,
2791
+ over
2792
+ };
2793
+ if (type === Action.DragEnd && typeof cancelDrop === 'function') {
2794
+ const shouldCancel = await Promise.resolve(cancelDrop(event));
2795
+ if (shouldCancel) {
2796
+ type = Action.DragCancel;
2797
+ }
2798
+ }
2799
+ }
2800
+ activeRef.current = null;
2801
+ unstable_batchedUpdates(()=>{
2802
+ dispatch({
2803
+ type
2804
+ });
2805
+ setStatus(Status.Uninitialized);
2806
+ setOver(null);
2807
+ setActiveSensor(null);
2808
+ setActivatorEvent(null);
2809
+ activeSensorRef.current = null;
2810
+ const eventName = type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
2811
+ if (event) {
2812
+ const handler = latestProps.current[eventName];
2813
+ handler == null ? void 0 : handler(event);
2814
+ dispatchMonitorEvent({
2815
+ type: eventName,
2816
+ event
2817
+ });
2818
+ }
2819
+ });
2820
+ };
2821
+ }
2822
+ }, [
2823
+ draggableNodes
2824
+ ]);
2825
+ const bindActivatorToSensorInstantiator = useCallback((handler, sensor)=>{
2826
+ return (event, active)=>{
2827
+ const nativeEvent = event.nativeEvent;
2828
+ const activeDraggableNode = draggableNodes.get(active);
2829
+ if (activeRef.current !== null || // No active draggable
2830
+ !activeDraggableNode || // Event has already been captured
2831
+ nativeEvent.dndKit || nativeEvent.defaultPrevented) {
2832
+ return;
2833
+ }
2834
+ const activationContext = {
2835
+ active: activeDraggableNode
2836
+ };
2837
+ const shouldActivate = handler(event, sensor.options, activationContext);
2838
+ if (shouldActivate === true) {
2839
+ nativeEvent.dndKit = {
2840
+ capturedBy: sensor.sensor
2841
+ };
2842
+ activeRef.current = active;
2843
+ instantiateSensor(event, sensor);
2844
+ }
2845
+ };
2846
+ }, [
2847
+ draggableNodes,
2848
+ instantiateSensor
2849
+ ]);
2850
+ const activators = useCombineActivators(sensors, bindActivatorToSensorInstantiator);
2851
+ useSensorSetup(sensors);
2852
+ useIsomorphicLayoutEffect(()=>{
2853
+ if (activeNodeRect && status === Status.Initializing) {
2854
+ setStatus(Status.Initialized);
2855
+ }
2856
+ }, [
2857
+ activeNodeRect,
2858
+ status
2859
+ ]);
2860
+ useEffect(()=>{
2861
+ const { onDragMove } = latestProps.current;
2862
+ const { active, activatorEvent, collisions, over } = sensorContext.current;
2863
+ if (!active || !activatorEvent) {
2864
+ return;
2865
+ }
2866
+ const event = {
2867
+ active,
2868
+ activatorEvent,
2869
+ collisions,
2870
+ delta: {
2871
+ x: scrollAdjustedTranslate.x,
2872
+ y: scrollAdjustedTranslate.y
2873
+ },
2874
+ over
2875
+ };
2876
+ unstable_batchedUpdates(()=>{
2877
+ onDragMove == null ? void 0 : onDragMove(event);
2878
+ dispatchMonitorEvent({
2879
+ type: 'onDragMove',
2880
+ event
2881
+ });
2882
+ });
2883
+ }, [
2884
+ scrollAdjustedTranslate.x,
2885
+ scrollAdjustedTranslate.y
2886
+ ]);
2887
+ useEffect(()=>{
2888
+ const { active, activatorEvent, collisions, droppableContainers, scrollAdjustedTranslate } = sensorContext.current;
2889
+ if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) {
2890
+ return;
2891
+ }
2892
+ const { onDragOver } = latestProps.current;
2893
+ const overContainer = droppableContainers.get(overId);
2894
+ const over = overContainer && overContainer.rect.current ? {
2895
+ id: overContainer.id,
2896
+ rect: overContainer.rect.current,
2897
+ data: overContainer.data,
2898
+ disabled: overContainer.disabled
2899
+ } : null;
2900
+ const event = {
2901
+ active,
2902
+ activatorEvent,
2903
+ collisions,
2904
+ delta: {
2905
+ x: scrollAdjustedTranslate.x,
2906
+ y: scrollAdjustedTranslate.y
2907
+ },
2908
+ over
2909
+ };
2910
+ unstable_batchedUpdates(()=>{
2911
+ setOver(over);
2912
+ onDragOver == null ? void 0 : onDragOver(event);
2913
+ dispatchMonitorEvent({
2914
+ type: 'onDragOver',
2915
+ event
2916
+ });
2917
+ });
2918
+ }, [
2919
+ overId
2920
+ ]);
2921
+ useIsomorphicLayoutEffect(()=>{
2922
+ sensorContext.current = {
2923
+ activatorEvent,
2924
+ active,
2925
+ activeNode,
2926
+ collisionRect,
2927
+ collisions,
2928
+ droppableRects,
2929
+ draggableNodes,
2930
+ draggingNode,
2931
+ draggingNodeRect,
2932
+ droppableContainers,
2933
+ over,
2934
+ scrollableAncestors,
2935
+ scrollAdjustedTranslate
2936
+ };
2937
+ activeRects.current = {
2938
+ initial: draggingNodeRect,
2939
+ translated: collisionRect
2940
+ };
2941
+ }, [
2942
+ active,
2943
+ activeNode,
2944
+ collisions,
2945
+ collisionRect,
2946
+ draggableNodes,
2947
+ draggingNode,
2948
+ draggingNodeRect,
2949
+ droppableRects,
2950
+ droppableContainers,
2951
+ over,
2952
+ scrollableAncestors,
2953
+ scrollAdjustedTranslate
2954
+ ]);
2955
+ useAutoScroller({
2956
+ ...autoScrollOptions,
2957
+ delta: translate,
2958
+ draggingRect: collisionRect,
2959
+ pointerCoordinates,
2960
+ scrollableAncestors,
2961
+ scrollableAncestorRects
2962
+ });
2963
+ const publicContext = useMemo(()=>{
2964
+ const context = {
2965
+ active,
2966
+ activeNode,
2967
+ activeNodeRect,
2968
+ activatorEvent,
2969
+ collisions,
2970
+ containerNodeRect,
2971
+ dragOverlay,
2972
+ draggableNodes,
2973
+ droppableContainers,
2974
+ droppableRects,
2975
+ over,
2976
+ measureDroppableContainers,
2977
+ scrollableAncestors,
2978
+ scrollableAncestorRects,
2979
+ measuringConfiguration,
2980
+ measuringScheduled,
2981
+ windowRect
2982
+ };
2983
+ return context;
2984
+ }, [
2985
+ active,
2986
+ activeNode,
2987
+ activeNodeRect,
2988
+ activatorEvent,
2989
+ collisions,
2990
+ containerNodeRect,
2991
+ dragOverlay,
2992
+ draggableNodes,
2993
+ droppableContainers,
2994
+ droppableRects,
2995
+ over,
2996
+ measureDroppableContainers,
2997
+ scrollableAncestors,
2998
+ scrollableAncestorRects,
2999
+ measuringConfiguration,
3000
+ measuringScheduled,
3001
+ windowRect
3002
+ ]);
3003
+ const internalContext = useMemo(()=>{
3004
+ const context = {
3005
+ activatorEvent,
3006
+ activators,
3007
+ active,
3008
+ activeNodeRect,
3009
+ ariaDescribedById: {
3010
+ draggable: draggableDescribedById
3011
+ },
3012
+ dispatch,
3013
+ draggableNodes,
3014
+ over,
3015
+ measureDroppableContainers
3016
+ };
3017
+ return context;
3018
+ }, [
3019
+ activatorEvent,
3020
+ activators,
3021
+ active,
3022
+ activeNodeRect,
3023
+ dispatch,
3024
+ draggableDescribedById,
3025
+ draggableNodes,
3026
+ over,
3027
+ measureDroppableContainers
3028
+ ]);
3029
+ return React__default.createElement(DndMonitorContext.Provider, {
3030
+ value: registerMonitorListener
3031
+ }, React__default.createElement(InternalContext.Provider, {
3032
+ value: internalContext
3033
+ }, React__default.createElement(PublicContext.Provider, {
3034
+ value: publicContext
3035
+ }, React__default.createElement(ActiveDraggableContext.Provider, {
3036
+ value: transform
3037
+ }, children)), React__default.createElement(RestoreFocus, {
3038
+ disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false
3039
+ })), React__default.createElement(Accessibility, {
3040
+ ...accessibility,
3041
+ hiddenTextDescribedById: draggableDescribedById
3042
+ }));
3043
+ function getAutoScrollerOptions() {
3044
+ const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
3045
+ const autoScrollGloballyDisabled = typeof autoScroll === 'object' ? autoScroll.enabled === false : autoScroll === false;
3046
+ const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
3047
+ if (typeof autoScroll === 'object') {
3048
+ return {
3049
+ ...autoScroll,
3050
+ enabled
3051
+ };
3052
+ }
3053
+ return {
3054
+ enabled
3055
+ };
3056
+ }
3057
+ });
3058
+ const NullContext = /*#__PURE__*/ createContext(null);
3059
+ const defaultRole = 'button';
3060
+ const ID_PREFIX$1 = 'Draggable';
3061
+ function useDraggable(_ref) {
3062
+ let { id, data, disabled = false, attributes } = _ref;
3063
+ const key = useUniqueId(ID_PREFIX$1);
3064
+ const { activators, activatorEvent, active, activeNodeRect, ariaDescribedById, draggableNodes, over } = useContext(InternalContext);
3065
+ const { role = defaultRole, roleDescription = 'draggable', tabIndex = 0 } = attributes != null ? attributes : {};
3066
+ const isDragging = (active == null ? void 0 : active.id) === id;
3067
+ const transform = useContext(isDragging ? ActiveDraggableContext : NullContext);
3068
+ const [node, setNodeRef] = useNodeRef();
3069
+ const [activatorNode, setActivatorNodeRef] = useNodeRef();
3070
+ const listeners = useSyntheticListeners(activators, id);
3071
+ const dataRef = useLatestValue(data);
3072
+ useIsomorphicLayoutEffect(()=>{
3073
+ draggableNodes.set(id, {
3074
+ id,
3075
+ key,
3076
+ node,
3077
+ activatorNode,
3078
+ data: dataRef
3079
+ });
3080
+ return ()=>{
3081
+ const node = draggableNodes.get(id);
3082
+ if (node && node.key === key) {
3083
+ draggableNodes.delete(id);
3084
+ }
3085
+ };
3086
+ }, [
3087
+ draggableNodes,
3088
+ id
3089
+ ]);
3090
+ const memoizedAttributes = useMemo(()=>({
3091
+ role,
3092
+ tabIndex,
3093
+ 'aria-disabled': disabled,
3094
+ 'aria-pressed': isDragging && role === defaultRole ? true : undefined,
3095
+ 'aria-roledescription': roleDescription,
3096
+ 'aria-describedby': ariaDescribedById.draggable
3097
+ }), [
3098
+ disabled,
3099
+ role,
3100
+ tabIndex,
3101
+ isDragging,
3102
+ roleDescription,
3103
+ ariaDescribedById.draggable
3104
+ ]);
3105
+ return {
3106
+ active,
3107
+ activatorEvent,
3108
+ activeNodeRect,
3109
+ attributes: memoizedAttributes,
3110
+ isDragging,
3111
+ listeners: disabled ? undefined : listeners,
3112
+ node,
3113
+ over,
3114
+ setNodeRef,
3115
+ setActivatorNodeRef,
3116
+ transform
3117
+ };
3118
+ }
3119
+ function useDndContext() {
3120
+ return useContext(PublicContext);
3121
+ }
3122
+ const ID_PREFIX$1$1 = 'Droppable';
3123
+ const defaultResizeObserverConfig = {
3124
+ timeout: 25
3125
+ };
3126
+ function useDroppable(_ref) {
3127
+ let { data, disabled = false, id, resizeObserverConfig } = _ref;
3128
+ const key = useUniqueId(ID_PREFIX$1$1);
3129
+ const { active, dispatch, over, measureDroppableContainers } = useContext(InternalContext);
3130
+ const previous = useRef({
3131
+ disabled
3132
+ });
3133
+ const resizeObserverConnected = useRef(false);
3134
+ const rect = useRef(null);
3135
+ const callbackId = useRef(null);
3136
+ const { disabled: resizeObserverDisabled, updateMeasurementsFor, timeout: resizeObserverTimeout } = {
3137
+ ...defaultResizeObserverConfig,
3138
+ ...resizeObserverConfig
3139
+ };
3140
+ const ids = useLatestValue(updateMeasurementsFor != null ? updateMeasurementsFor : id);
3141
+ const handleResize = useCallback(()=>{
3142
+ if (!resizeObserverConnected.current) {
3143
+ // ResizeObserver invokes the `handleResize` callback as soon as `observe` is called,
3144
+ // assuming the element is rendered and displayed.
3145
+ resizeObserverConnected.current = true;
3146
+ return;
3147
+ }
3148
+ if (callbackId.current != null) {
3149
+ clearTimeout(callbackId.current);
3150
+ }
3151
+ callbackId.current = setTimeout(()=>{
3152
+ measureDroppableContainers(Array.isArray(ids.current) ? ids.current : [
3153
+ ids.current
3154
+ ]);
3155
+ callbackId.current = null;
3156
+ }, resizeObserverTimeout);
3157
+ }, [
3158
+ resizeObserverTimeout
3159
+ ]);
3160
+ const resizeObserver = useResizeObserver({
3161
+ callback: handleResize,
3162
+ disabled: resizeObserverDisabled || !active
3163
+ });
3164
+ const handleNodeChange = useCallback((newElement, previousElement)=>{
3165
+ if (!resizeObserver) {
3166
+ return;
3167
+ }
3168
+ if (previousElement) {
3169
+ resizeObserver.unobserve(previousElement);
3170
+ resizeObserverConnected.current = false;
3171
+ }
3172
+ if (newElement) {
3173
+ resizeObserver.observe(newElement);
3174
+ }
3175
+ }, [
3176
+ resizeObserver
3177
+ ]);
3178
+ const [nodeRef, setNodeRef] = useNodeRef(handleNodeChange);
3179
+ const dataRef = useLatestValue(data);
3180
+ useEffect(()=>{
3181
+ if (!resizeObserver || !nodeRef.current) {
3182
+ return;
3183
+ }
3184
+ resizeObserver.disconnect();
3185
+ resizeObserverConnected.current = false;
3186
+ resizeObserver.observe(nodeRef.current);
3187
+ }, [
3188
+ nodeRef,
3189
+ resizeObserver
3190
+ ]);
3191
+ useEffect(()=>{
3192
+ dispatch({
3193
+ type: Action.RegisterDroppable,
3194
+ element: {
3195
+ id,
3196
+ key,
3197
+ disabled,
3198
+ node: nodeRef,
3199
+ rect,
3200
+ data: dataRef
3201
+ }
3202
+ });
3203
+ return ()=>dispatch({
3204
+ type: Action.UnregisterDroppable,
3205
+ key,
3206
+ id
3207
+ });
3208
+ }, [
3209
+ id
3210
+ ]);
3211
+ useEffect(()=>{
3212
+ if (disabled !== previous.current.disabled) {
3213
+ dispatch({
3214
+ type: Action.SetDroppableDisabled,
3215
+ id,
3216
+ key,
3217
+ disabled
3218
+ });
3219
+ previous.current.disabled = disabled;
3220
+ }
3221
+ }, [
3222
+ id,
3223
+ key,
3224
+ disabled,
3225
+ dispatch
3226
+ ]);
3227
+ return {
3228
+ active,
3229
+ rect,
3230
+ isOver: (over == null ? void 0 : over.id) === id,
3231
+ node: nodeRef,
3232
+ over,
3233
+ setNodeRef
3234
+ };
3235
+ }
3236
+ function AnimationManager(_ref) {
3237
+ let { animation, children } = _ref;
3238
+ const [clonedChildren, setClonedChildren] = useState(null);
3239
+ const [element, setElement] = useState(null);
3240
+ const previousChildren = usePrevious(children);
3241
+ if (!children && !clonedChildren && previousChildren) {
3242
+ setClonedChildren(previousChildren);
3243
+ }
3244
+ useIsomorphicLayoutEffect(()=>{
3245
+ if (!element) {
3246
+ return;
3247
+ }
3248
+ const key = clonedChildren == null ? void 0 : clonedChildren.key;
3249
+ const id = clonedChildren == null ? void 0 : clonedChildren.props.id;
3250
+ if (key == null || id == null) {
3251
+ setClonedChildren(null);
3252
+ return;
3253
+ }
3254
+ Promise.resolve(animation(id, element)).then(()=>{
3255
+ setClonedChildren(null);
3256
+ });
3257
+ }, [
3258
+ animation,
3259
+ clonedChildren,
3260
+ element
3261
+ ]);
3262
+ return React__default.createElement(React__default.Fragment, null, children, clonedChildren ? cloneElement(clonedChildren, {
3263
+ ref: setElement
3264
+ }) : null);
3265
+ }
3266
+ const defaultTransform = {
3267
+ x: 0,
3268
+ y: 0,
3269
+ scaleX: 1,
3270
+ scaleY: 1
3271
+ };
3272
+ function NullifiedContextProvider(_ref) {
3273
+ let { children } = _ref;
3274
+ return React__default.createElement(InternalContext.Provider, {
3275
+ value: defaultInternalContext
3276
+ }, React__default.createElement(ActiveDraggableContext.Provider, {
3277
+ value: defaultTransform
3278
+ }, children));
3279
+ }
3280
+ const baseStyles = {
3281
+ position: 'fixed',
3282
+ touchAction: 'none'
3283
+ };
3284
+ const defaultTransition$1 = (activatorEvent)=>{
3285
+ const isKeyboardActivator = isKeyboardEvent(activatorEvent);
3286
+ return isKeyboardActivator ? 'transform 250ms ease' : undefined;
3287
+ };
3288
+ const PositionedOverlay = /*#__PURE__*/ forwardRef((_ref, ref)=>{
3289
+ let { as, activatorEvent, adjustScale, children, className, rect, style, transform, transition = defaultTransition$1 } = _ref;
3290
+ if (!rect) {
3291
+ return null;
3292
+ }
3293
+ const scaleAdjustedTransform = adjustScale ? transform : {
3294
+ ...transform,
3295
+ scaleX: 1,
3296
+ scaleY: 1
3297
+ };
3298
+ const styles = {
3299
+ ...baseStyles,
3300
+ width: rect.width,
3301
+ height: rect.height,
3302
+ top: rect.top,
3303
+ left: rect.left,
3304
+ transform: CSS.Transform.toString(scaleAdjustedTransform),
3305
+ transformOrigin: adjustScale && activatorEvent ? getRelativeTransformOrigin(activatorEvent, rect) : undefined,
3306
+ transition: typeof transition === 'function' ? transition(activatorEvent) : transition,
3307
+ ...style
3308
+ };
3309
+ return React__default.createElement(as, {
3310
+ className,
3311
+ style: styles,
3312
+ ref
3313
+ }, children);
3314
+ });
3315
+ const defaultDropAnimationSideEffects = (options)=>(_ref)=>{
3316
+ let { active, dragOverlay } = _ref;
3317
+ const originalStyles = {};
3318
+ const { styles, className } = options;
3319
+ if (styles != null && styles.active) {
3320
+ for (const [key, value] of Object.entries(styles.active)){
3321
+ if (value === undefined) {
3322
+ continue;
3323
+ }
3324
+ originalStyles[key] = active.node.style.getPropertyValue(key);
3325
+ active.node.style.setProperty(key, value);
3326
+ }
3327
+ }
3328
+ if (styles != null && styles.dragOverlay) {
3329
+ for (const [key, value] of Object.entries(styles.dragOverlay)){
3330
+ if (value === undefined) {
3331
+ continue;
3332
+ }
3333
+ dragOverlay.node.style.setProperty(key, value);
3334
+ }
3335
+ }
3336
+ if (className != null && className.active) {
3337
+ active.node.classList.add(className.active);
3338
+ }
3339
+ if (className != null && className.dragOverlay) {
3340
+ dragOverlay.node.classList.add(className.dragOverlay);
3341
+ }
3342
+ return function cleanup() {
3343
+ for (const [key, value] of Object.entries(originalStyles)){
3344
+ active.node.style.setProperty(key, value);
3345
+ }
3346
+ if (className != null && className.active) {
3347
+ active.node.classList.remove(className.active);
3348
+ }
3349
+ };
3350
+ };
3351
+ const defaultKeyframeResolver = (_ref2)=>{
3352
+ let { transform: { initial, final } } = _ref2;
3353
+ return [
3354
+ {
3355
+ transform: CSS.Transform.toString(initial)
3356
+ },
3357
+ {
3358
+ transform: CSS.Transform.toString(final)
3359
+ }
3360
+ ];
3361
+ };
3362
+ const defaultDropAnimationConfiguration = {
3363
+ duration: 250,
3364
+ easing: 'ease',
3365
+ keyframes: defaultKeyframeResolver,
3366
+ sideEffects: /*#__PURE__*/ defaultDropAnimationSideEffects({
3367
+ styles: {
3368
+ active: {
3369
+ opacity: '0'
3370
+ }
3371
+ }
3372
+ })
3373
+ };
3374
+ function useDropAnimation(_ref3) {
3375
+ let { config, draggableNodes, droppableContainers, measuringConfiguration } = _ref3;
3376
+ return useEvent((id, node)=>{
3377
+ if (config === null) {
3378
+ return;
3379
+ }
3380
+ const activeDraggable = draggableNodes.get(id);
3381
+ if (!activeDraggable) {
3382
+ return;
3383
+ }
3384
+ const activeNode = activeDraggable.node.current;
3385
+ if (!activeNode) {
3386
+ return;
3387
+ }
3388
+ const measurableNode = getMeasurableNode(node);
3389
+ if (!measurableNode) {
3390
+ return;
3391
+ }
3392
+ const { transform } = getWindow(node).getComputedStyle(node);
3393
+ const parsedTransform = parseTransform(transform);
3394
+ if (!parsedTransform) {
3395
+ return;
3396
+ }
3397
+ const animation = typeof config === 'function' ? config : createDefaultDropAnimation(config);
3398
+ scrollIntoViewIfNeeded(activeNode, measuringConfiguration.draggable.measure);
3399
+ return animation({
3400
+ active: {
3401
+ id,
3402
+ data: activeDraggable.data,
3403
+ node: activeNode,
3404
+ rect: measuringConfiguration.draggable.measure(activeNode)
3405
+ },
3406
+ draggableNodes,
3407
+ dragOverlay: {
3408
+ node,
3409
+ rect: measuringConfiguration.dragOverlay.measure(measurableNode)
3410
+ },
3411
+ droppableContainers,
3412
+ measuringConfiguration,
3413
+ transform: parsedTransform
3414
+ });
3415
+ });
3416
+ }
3417
+ function createDefaultDropAnimation(options) {
3418
+ const { duration, easing, sideEffects, keyframes } = {
3419
+ ...defaultDropAnimationConfiguration,
3420
+ ...options
3421
+ };
3422
+ return (_ref4)=>{
3423
+ let { active, dragOverlay, transform, ...rest } = _ref4;
3424
+ if (!duration) {
3425
+ // Do not animate if animation duration is zero.
3426
+ return;
3427
+ }
3428
+ const delta = {
3429
+ x: dragOverlay.rect.left - active.rect.left,
3430
+ y: dragOverlay.rect.top - active.rect.top
3431
+ };
3432
+ const scale = {
3433
+ scaleX: transform.scaleX !== 1 ? active.rect.width * transform.scaleX / dragOverlay.rect.width : 1,
3434
+ scaleY: transform.scaleY !== 1 ? active.rect.height * transform.scaleY / dragOverlay.rect.height : 1
3435
+ };
3436
+ const finalTransform = {
3437
+ x: transform.x - delta.x,
3438
+ y: transform.y - delta.y,
3439
+ ...scale
3440
+ };
3441
+ const animationKeyframes = keyframes({
3442
+ ...rest,
3443
+ active,
3444
+ dragOverlay,
3445
+ transform: {
3446
+ initial: transform,
3447
+ final: finalTransform
3448
+ }
3449
+ });
3450
+ const [firstKeyframe] = animationKeyframes;
3451
+ const lastKeyframe = animationKeyframes[animationKeyframes.length - 1];
3452
+ if (JSON.stringify(firstKeyframe) === JSON.stringify(lastKeyframe)) {
3453
+ // The start and end keyframes are the same, infer that there is no animation needed.
3454
+ return;
3455
+ }
3456
+ const cleanup = sideEffects == null ? void 0 : sideEffects({
3457
+ active,
3458
+ dragOverlay,
3459
+ ...rest
3460
+ });
3461
+ const animation = dragOverlay.node.animate(animationKeyframes, {
3462
+ duration,
3463
+ easing,
3464
+ fill: 'forwards'
3465
+ });
3466
+ return new Promise((resolve)=>{
3467
+ animation.onfinish = ()=>{
3468
+ cleanup == null ? void 0 : cleanup();
3469
+ resolve();
3470
+ };
3471
+ });
3472
+ };
3473
+ }
3474
+ let key = 0;
3475
+ function useKey(id) {
3476
+ return useMemo(()=>{
3477
+ if (id == null) {
3478
+ return;
3479
+ }
3480
+ key++;
3481
+ return key;
3482
+ }, [
3483
+ id
3484
+ ]);
3485
+ }
3486
+ const DragOverlay = /*#__PURE__*/ React__default.memo((_ref)=>{
3487
+ let { adjustScale = false, children, dropAnimation: dropAnimationConfig, style, transition, modifiers, wrapperElement = 'div', className, zIndex = 999 } = _ref;
3488
+ const { activatorEvent, active, activeNodeRect, containerNodeRect, draggableNodes, droppableContainers, dragOverlay, over, measuringConfiguration, scrollableAncestors, scrollableAncestorRects, windowRect } = useDndContext();
3489
+ const transform = useContext(ActiveDraggableContext);
3490
+ const key = useKey(active == null ? void 0 : active.id);
3491
+ const modifiedTransform = applyModifiers(modifiers, {
3492
+ activatorEvent,
3493
+ active,
3494
+ activeNodeRect,
3495
+ containerNodeRect,
3496
+ draggingNodeRect: dragOverlay.rect,
3497
+ over,
3498
+ overlayNodeRect: dragOverlay.rect,
3499
+ scrollableAncestors,
3500
+ scrollableAncestorRects,
3501
+ transform,
3502
+ windowRect
3503
+ });
3504
+ const initialRect = useInitialValue(activeNodeRect);
3505
+ const dropAnimation = useDropAnimation({
3506
+ config: dropAnimationConfig,
3507
+ draggableNodes,
3508
+ droppableContainers,
3509
+ measuringConfiguration
3510
+ }); // We need to wait for the active node to be measured before connecting the drag overlay ref
3511
+ // otherwise collisions can be computed against a mispositioned drag overlay
3512
+ const ref = initialRect ? dragOverlay.setRef : undefined;
3513
+ return React__default.createElement(NullifiedContextProvider, null, React__default.createElement(AnimationManager, {
3514
+ animation: dropAnimation
3515
+ }, active && key ? React__default.createElement(PositionedOverlay, {
3516
+ key: key,
3517
+ id: active.id,
3518
+ ref: ref,
3519
+ as: wrapperElement,
3520
+ activatorEvent: activatorEvent,
3521
+ adjustScale: adjustScale,
3522
+ className: className,
3523
+ transition: transition,
3524
+ rect: initialRect,
3525
+ style: {
3526
+ zIndex,
3527
+ ...style
3528
+ },
3529
+ transform: modifiedTransform
3530
+ }, children) : null));
3531
+ });
3532
+
3533
+ const restrictToHorizontalAxis = (_ref)=>{
3534
+ let { transform } = _ref;
3535
+ return {
3536
+ ...transform,
3537
+ y: 0
3538
+ };
3539
+ };
3540
+ function restrictToBoundingRect(transform, rect, boundingRect) {
3541
+ const value = {
3542
+ ...transform
3543
+ };
3544
+ if (rect.top + transform.y <= boundingRect.top) {
3545
+ value.y = boundingRect.top - rect.top;
3546
+ } else if (rect.bottom + transform.y >= boundingRect.top + boundingRect.height) {
3547
+ value.y = boundingRect.top + boundingRect.height - rect.bottom;
3548
+ }
3549
+ if (rect.left + transform.x <= boundingRect.left) {
3550
+ value.x = boundingRect.left - rect.left;
3551
+ } else if (rect.right + transform.x >= boundingRect.left + boundingRect.width) {
3552
+ value.x = boundingRect.left + boundingRect.width - rect.right;
3553
+ }
3554
+ return value;
3555
+ }
3556
+ const restrictToParentElement = (_ref)=>{
3557
+ let { containerNodeRect, draggingNodeRect, transform } = _ref;
3558
+ if (!draggingNodeRect || !containerNodeRect) {
3559
+ return transform;
3560
+ }
3561
+ return restrictToBoundingRect(transform, draggingNodeRect, containerNodeRect);
3562
+ };
3563
+ const restrictToVerticalAxis = (_ref)=>{
3564
+ let { transform } = _ref;
3565
+ return {
3566
+ ...transform,
3567
+ x: 0
3568
+ };
3569
+ };
3570
+
3571
+ /**
3572
+ * Move an array item to a different position. Returns a new array with the item moved to the new position.
3573
+ */ function arrayMove(array, from, to) {
3574
+ const newArray = array.slice();
3575
+ newArray.splice(to < 0 ? newArray.length + to : to, 0, newArray.splice(from, 1)[0]);
3576
+ return newArray;
3577
+ }
3578
+ function getSortedRects(items, rects) {
3579
+ return items.reduce((accumulator, id, index)=>{
3580
+ const rect = rects.get(id);
3581
+ if (rect) {
3582
+ accumulator[index] = rect;
3583
+ }
3584
+ return accumulator;
3585
+ }, Array(items.length));
3586
+ }
3587
+ function isValidIndex(index) {
3588
+ return index !== null && index >= 0;
3589
+ }
3590
+ function itemsEqual(a, b) {
3591
+ if (a === b) {
3592
+ return true;
3593
+ }
3594
+ if (a.length !== b.length) {
3595
+ return false;
3596
+ }
3597
+ for(let i = 0; i < a.length; i++){
3598
+ if (a[i] !== b[i]) {
3599
+ return false;
3600
+ }
3601
+ }
3602
+ return true;
3603
+ }
3604
+ function normalizeDisabled(disabled) {
3605
+ if (typeof disabled === 'boolean') {
3606
+ return {
3607
+ draggable: disabled,
3608
+ droppable: disabled
3609
+ };
3610
+ }
3611
+ return disabled;
3612
+ }
3613
+ // To-do: We should be calculating scale transformation
3614
+ const defaultScale = {
3615
+ scaleX: 1,
3616
+ scaleY: 1
3617
+ };
3618
+ const horizontalListSortingStrategy = (_ref)=>{
3619
+ var _rects$activeIndex;
3620
+ let { rects, activeNodeRect: fallbackActiveRect, activeIndex, overIndex, index } = _ref;
3621
+ const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
3622
+ if (!activeNodeRect) {
3623
+ return null;
3624
+ }
3625
+ const itemGap = getItemGap(rects, index, activeIndex);
3626
+ if (index === activeIndex) {
3627
+ const newIndexRect = rects[overIndex];
3628
+ if (!newIndexRect) {
3629
+ return null;
3630
+ }
3631
+ return {
3632
+ x: activeIndex < overIndex ? newIndexRect.left + newIndexRect.width - (activeNodeRect.left + activeNodeRect.width) : newIndexRect.left - activeNodeRect.left,
3633
+ y: 0,
3634
+ ...defaultScale
3635
+ };
3636
+ }
3637
+ if (index > activeIndex && index <= overIndex) {
3638
+ return {
3639
+ x: -activeNodeRect.width - itemGap,
3640
+ y: 0,
3641
+ ...defaultScale
3642
+ };
3643
+ }
3644
+ if (index < activeIndex && index >= overIndex) {
3645
+ return {
3646
+ x: activeNodeRect.width + itemGap,
3647
+ y: 0,
3648
+ ...defaultScale
3649
+ };
3650
+ }
3651
+ return {
3652
+ x: 0,
3653
+ y: 0,
3654
+ ...defaultScale
3655
+ };
3656
+ };
3657
+ function getItemGap(rects, index, activeIndex) {
3658
+ const currentRect = rects[index];
3659
+ const previousRect = rects[index - 1];
3660
+ const nextRect = rects[index + 1];
3661
+ if (!currentRect || !previousRect && !nextRect) {
3662
+ return 0;
3663
+ }
3664
+ if (activeIndex < index) {
3665
+ return previousRect ? currentRect.left - (previousRect.left + previousRect.width) : nextRect.left - (currentRect.left + currentRect.width);
3666
+ }
3667
+ return nextRect ? nextRect.left - (currentRect.left + currentRect.width) : currentRect.left - (previousRect.left + previousRect.width);
3668
+ }
3669
+ const rectSortingStrategy = (_ref)=>{
3670
+ let { rects, activeIndex, overIndex, index } = _ref;
3671
+ const newRects = arrayMove(rects, overIndex, activeIndex);
3672
+ const oldRect = rects[index];
3673
+ const newRect = newRects[index];
3674
+ if (!newRect || !oldRect) {
3675
+ return null;
3676
+ }
3677
+ return {
3678
+ x: newRect.left - oldRect.left,
3679
+ y: newRect.top - oldRect.top,
3680
+ scaleX: newRect.width / oldRect.width,
3681
+ scaleY: newRect.height / oldRect.height
3682
+ };
3683
+ };
3684
+ // To-do: We should be calculating scale transformation
3685
+ const defaultScale$1 = {
3686
+ scaleX: 1,
3687
+ scaleY: 1
3688
+ };
3689
+ const verticalListSortingStrategy = (_ref)=>{
3690
+ var _rects$activeIndex;
3691
+ let { activeIndex, activeNodeRect: fallbackActiveRect, index, rects, overIndex } = _ref;
3692
+ const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
3693
+ if (!activeNodeRect) {
3694
+ return null;
3695
+ }
3696
+ if (index === activeIndex) {
3697
+ const overIndexRect = rects[overIndex];
3698
+ if (!overIndexRect) {
3699
+ return null;
3700
+ }
3701
+ return {
3702
+ x: 0,
3703
+ y: activeIndex < overIndex ? overIndexRect.top + overIndexRect.height - (activeNodeRect.top + activeNodeRect.height) : overIndexRect.top - activeNodeRect.top,
3704
+ ...defaultScale$1
3705
+ };
3706
+ }
3707
+ const itemGap = getItemGap$1(rects, index, activeIndex);
3708
+ if (index > activeIndex && index <= overIndex) {
3709
+ return {
3710
+ x: 0,
3711
+ y: -activeNodeRect.height - itemGap,
3712
+ ...defaultScale$1
3713
+ };
3714
+ }
3715
+ if (index < activeIndex && index >= overIndex) {
3716
+ return {
3717
+ x: 0,
3718
+ y: activeNodeRect.height + itemGap,
3719
+ ...defaultScale$1
3720
+ };
3721
+ }
3722
+ return {
3723
+ x: 0,
3724
+ y: 0,
3725
+ ...defaultScale$1
3726
+ };
3727
+ };
3728
+ function getItemGap$1(clientRects, index, activeIndex) {
3729
+ const currentRect = clientRects[index];
3730
+ const previousRect = clientRects[index - 1];
3731
+ const nextRect = clientRects[index + 1];
3732
+ if (!currentRect) {
3733
+ return 0;
3734
+ }
3735
+ if (activeIndex < index) {
3736
+ return previousRect ? currentRect.top - (previousRect.top + previousRect.height) : nextRect ? nextRect.top - (currentRect.top + currentRect.height) : 0;
3737
+ }
3738
+ return nextRect ? nextRect.top - (currentRect.top + currentRect.height) : previousRect ? currentRect.top - (previousRect.top + previousRect.height) : 0;
3739
+ }
3740
+ const ID_PREFIX = 'Sortable';
3741
+ const Context = /*#__PURE__*/ React__default.createContext({
3742
+ activeIndex: -1,
3743
+ containerId: ID_PREFIX,
3744
+ disableTransforms: false,
3745
+ items: [],
3746
+ overIndex: -1,
3747
+ useDragOverlay: false,
3748
+ sortedRects: [],
3749
+ strategy: rectSortingStrategy,
3750
+ disabled: {
3751
+ draggable: false,
3752
+ droppable: false
3753
+ }
3754
+ });
3755
+ function SortableContext(_ref) {
3756
+ let { children, id, items: userDefinedItems, strategy = rectSortingStrategy, disabled: disabledProp = false } = _ref;
3757
+ const { active, dragOverlay, droppableRects, over, measureDroppableContainers } = useDndContext();
3758
+ const containerId = useUniqueId(ID_PREFIX, id);
3759
+ const useDragOverlay = Boolean(dragOverlay.rect !== null);
3760
+ const items = useMemo(()=>userDefinedItems.map((item)=>typeof item === 'object' && 'id' in item ? item.id : item), [
3761
+ userDefinedItems
3762
+ ]);
3763
+ const isDragging = active != null;
3764
+ const activeIndex = active ? items.indexOf(active.id) : -1;
3765
+ const overIndex = over ? items.indexOf(over.id) : -1;
3766
+ const previousItemsRef = useRef(items);
3767
+ const itemsHaveChanged = !itemsEqual(items, previousItemsRef.current);
3768
+ const disableTransforms = overIndex !== -1 && activeIndex === -1 || itemsHaveChanged;
3769
+ const disabled = normalizeDisabled(disabledProp);
3770
+ useIsomorphicLayoutEffect(()=>{
3771
+ if (itemsHaveChanged && isDragging) {
3772
+ measureDroppableContainers(items);
3773
+ }
3774
+ }, [
3775
+ itemsHaveChanged,
3776
+ items,
3777
+ isDragging,
3778
+ measureDroppableContainers
3779
+ ]);
3780
+ useEffect(()=>{
3781
+ previousItemsRef.current = items;
3782
+ }, [
3783
+ items
3784
+ ]);
3785
+ const contextValue = useMemo(()=>({
3786
+ activeIndex,
3787
+ containerId,
3788
+ disabled,
3789
+ disableTransforms,
3790
+ items,
3791
+ overIndex,
3792
+ useDragOverlay,
3793
+ sortedRects: getSortedRects(items, droppableRects),
3794
+ strategy
3795
+ }), [
3796
+ activeIndex,
3797
+ containerId,
3798
+ disabled.draggable,
3799
+ disabled.droppable,
3800
+ disableTransforms,
3801
+ items,
3802
+ overIndex,
3803
+ droppableRects,
3804
+ useDragOverlay,
3805
+ strategy
3806
+ ]);
3807
+ return React__default.createElement(Context.Provider, {
3808
+ value: contextValue
3809
+ }, children);
3810
+ }
3811
+ const defaultNewIndexGetter = (_ref)=>{
3812
+ let { id, items, activeIndex, overIndex } = _ref;
3813
+ return arrayMove(items, activeIndex, overIndex).indexOf(id);
3814
+ };
3815
+ const defaultAnimateLayoutChanges = (_ref2)=>{
3816
+ let { containerId, isSorting, wasDragging, index, items, newIndex, previousItems, previousContainerId, transition } = _ref2;
3817
+ if (!transition || !wasDragging) {
3818
+ return false;
3819
+ }
3820
+ if (previousItems !== items && index === newIndex) {
3821
+ return false;
3822
+ }
3823
+ if (isSorting) {
3824
+ return true;
3825
+ }
3826
+ return newIndex !== index && containerId === previousContainerId;
3827
+ };
3828
+ const defaultTransition = {
3829
+ duration: 200,
3830
+ easing: 'ease'
3831
+ };
3832
+ const transitionProperty = 'transform';
3833
+ const disabledTransition = /*#__PURE__*/ CSS.Transition.toString({
3834
+ property: transitionProperty,
3835
+ duration: 0,
3836
+ easing: 'linear'
3837
+ });
3838
+ const defaultAttributes = {
3839
+ roleDescription: 'sortable'
3840
+ };
3841
+ /*
3842
+ * When the index of an item changes while sorting,
3843
+ * we need to temporarily disable the transforms
3844
+ */ function useDerivedTransform(_ref) {
3845
+ let { disabled, index, node, rect } = _ref;
3846
+ const [derivedTransform, setDerivedtransform] = useState(null);
3847
+ const previousIndex = useRef(index);
3848
+ useIsomorphicLayoutEffect(()=>{
3849
+ if (!disabled && index !== previousIndex.current && node.current) {
3850
+ const initial = rect.current;
3851
+ if (initial) {
3852
+ const current = getClientRect(node.current, {
3853
+ ignoreTransform: true
3854
+ });
3855
+ const delta = {
3856
+ x: initial.left - current.left,
3857
+ y: initial.top - current.top,
3858
+ scaleX: initial.width / current.width,
3859
+ scaleY: initial.height / current.height
3860
+ };
3861
+ if (delta.x || delta.y) {
3862
+ setDerivedtransform(delta);
3863
+ }
3864
+ }
3865
+ }
3866
+ if (index !== previousIndex.current) {
3867
+ previousIndex.current = index;
3868
+ }
3869
+ }, [
3870
+ disabled,
3871
+ index,
3872
+ node,
3873
+ rect
3874
+ ]);
3875
+ useEffect(()=>{
3876
+ if (derivedTransform) {
3877
+ setDerivedtransform(null);
3878
+ }
3879
+ }, [
3880
+ derivedTransform
3881
+ ]);
3882
+ return derivedTransform;
3883
+ }
3884
+ function useSortable(_ref) {
3885
+ let { animateLayoutChanges = defaultAnimateLayoutChanges, attributes: userDefinedAttributes, disabled: localDisabled, data: customData, getNewIndex = defaultNewIndexGetter, id, strategy: localStrategy, resizeObserverConfig, transition = defaultTransition } = _ref;
3886
+ const { items, containerId, activeIndex, disabled: globalDisabled, disableTransforms, sortedRects, overIndex, useDragOverlay, strategy: globalStrategy } = useContext(Context);
3887
+ const disabled = normalizeLocalDisabled(localDisabled, globalDisabled);
3888
+ const index = items.indexOf(id);
3889
+ const data = useMemo(()=>({
3890
+ sortable: {
3891
+ containerId,
3892
+ index,
3893
+ items
3894
+ },
3895
+ ...customData
3896
+ }), [
3897
+ containerId,
3898
+ customData,
3899
+ index,
3900
+ items
3901
+ ]);
3902
+ const itemsAfterCurrentSortable = useMemo(()=>items.slice(items.indexOf(id)), [
3903
+ items,
3904
+ id
3905
+ ]);
3906
+ const { rect, node, isOver, setNodeRef: setDroppableNodeRef } = useDroppable({
3907
+ id,
3908
+ data,
3909
+ disabled: disabled.droppable,
3910
+ resizeObserverConfig: {
3911
+ updateMeasurementsFor: itemsAfterCurrentSortable,
3912
+ ...resizeObserverConfig
3913
+ }
3914
+ });
3915
+ const { active, activatorEvent, activeNodeRect, attributes, setNodeRef: setDraggableNodeRef, listeners, isDragging, over, setActivatorNodeRef, transform } = useDraggable({
3916
+ id,
3917
+ data,
3918
+ attributes: {
3919
+ ...defaultAttributes,
3920
+ ...userDefinedAttributes
3921
+ },
3922
+ disabled: disabled.draggable
3923
+ });
3924
+ const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
3925
+ const isSorting = Boolean(active);
3926
+ const displaceItem = isSorting && !disableTransforms && isValidIndex(activeIndex) && isValidIndex(overIndex);
3927
+ const shouldDisplaceDragSource = !useDragOverlay && isDragging;
3928
+ const dragSourceDisplacement = shouldDisplaceDragSource && displaceItem ? transform : null;
3929
+ const strategy = localStrategy != null ? localStrategy : globalStrategy;
3930
+ const finalTransform = displaceItem ? dragSourceDisplacement != null ? dragSourceDisplacement : strategy({
3931
+ rects: sortedRects,
3932
+ activeNodeRect,
3933
+ activeIndex,
3934
+ overIndex,
3935
+ index
3936
+ }) : null;
3937
+ const newIndex = isValidIndex(activeIndex) && isValidIndex(overIndex) ? getNewIndex({
3938
+ id,
3939
+ items,
3940
+ activeIndex,
3941
+ overIndex
3942
+ }) : index;
3943
+ const activeId = active == null ? void 0 : active.id;
3944
+ const previous = useRef({
3945
+ activeId,
3946
+ items,
3947
+ newIndex,
3948
+ containerId
3949
+ });
3950
+ const itemsHaveChanged = items !== previous.current.items;
3951
+ const shouldAnimateLayoutChanges = animateLayoutChanges({
3952
+ active,
3953
+ containerId,
3954
+ isDragging,
3955
+ isSorting,
3956
+ id,
3957
+ index,
3958
+ items,
3959
+ newIndex: previous.current.newIndex,
3960
+ previousItems: previous.current.items,
3961
+ previousContainerId: previous.current.containerId,
3962
+ transition,
3963
+ wasDragging: previous.current.activeId != null
3964
+ });
3965
+ const derivedTransform = useDerivedTransform({
3966
+ disabled: !shouldAnimateLayoutChanges,
3967
+ index,
3968
+ node,
3969
+ rect
3970
+ });
3971
+ useEffect(()=>{
3972
+ if (isSorting && previous.current.newIndex !== newIndex) {
3973
+ previous.current.newIndex = newIndex;
3974
+ }
3975
+ if (containerId !== previous.current.containerId) {
3976
+ previous.current.containerId = containerId;
3977
+ }
3978
+ if (items !== previous.current.items) {
3979
+ previous.current.items = items;
3980
+ }
3981
+ }, [
3982
+ isSorting,
3983
+ newIndex,
3984
+ containerId,
3985
+ items
3986
+ ]);
3987
+ useEffect(()=>{
3988
+ if (activeId === previous.current.activeId) {
3989
+ return;
3990
+ }
3991
+ if (activeId != null && previous.current.activeId == null) {
3992
+ previous.current.activeId = activeId;
3993
+ return;
3994
+ }
3995
+ const timeoutId = setTimeout(()=>{
3996
+ previous.current.activeId = activeId;
3997
+ }, 50);
3998
+ return ()=>clearTimeout(timeoutId);
3999
+ }, [
4000
+ activeId
4001
+ ]);
4002
+ return {
4003
+ active,
4004
+ activeIndex,
4005
+ attributes,
4006
+ data,
4007
+ rect,
4008
+ index,
4009
+ newIndex,
4010
+ items,
4011
+ isOver,
4012
+ isSorting,
4013
+ isDragging,
4014
+ listeners,
4015
+ node,
4016
+ overIndex,
4017
+ over,
4018
+ setNodeRef,
4019
+ setActivatorNodeRef,
4020
+ setDroppableNodeRef,
4021
+ setDraggableNodeRef,
4022
+ transform: derivedTransform != null ? derivedTransform : finalTransform,
4023
+ transition: getTransition()
4024
+ };
4025
+ function getTransition() {
4026
+ if (derivedTransform || // Or to prevent items jumping to back to their "new" position when items change
4027
+ itemsHaveChanged && previous.current.newIndex === index) {
4028
+ return disabledTransition;
4029
+ }
4030
+ if (shouldDisplaceDragSource && !isKeyboardEvent(activatorEvent) || !transition) {
4031
+ return undefined;
4032
+ }
4033
+ if (isSorting || shouldAnimateLayoutChanges) {
4034
+ return CSS.Transition.toString({
4035
+ ...transition,
4036
+ property: transitionProperty
4037
+ });
4038
+ }
4039
+ return undefined;
4040
+ }
4041
+ }
4042
+ function normalizeLocalDisabled(localDisabled, globalDisabled) {
4043
+ var _localDisabled$dragga, _localDisabled$droppa;
4044
+ if (typeof localDisabled === 'boolean') {
4045
+ return {
4046
+ draggable: localDisabled,
4047
+ // Backwards compatibility
4048
+ droppable: false
4049
+ };
4050
+ }
4051
+ return {
4052
+ draggable: (_localDisabled$dragga = localDisabled == null ? void 0 : localDisabled.draggable) != null ? _localDisabled$dragga : globalDisabled.draggable,
4053
+ droppable: (_localDisabled$droppa = localDisabled == null ? void 0 : localDisabled.droppable) != null ? _localDisabled$droppa : globalDisabled.droppable
4054
+ };
4055
+ }
4056
+ [
4057
+ KeyboardCode.Down,
4058
+ KeyboardCode.Right,
4059
+ KeyboardCode.Up,
4060
+ KeyboardCode.Left
4061
+ ];
4062
+
4063
+ // @see https://github.com/radix-ui/primitives/blob/main/packages/react/compose-refs/src/composeRefs.tsx
4064
+ /**
4065
+ * Set a given ref to a given value
4066
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
4067
+ */ function setRef(ref, value) {
4068
+ if (typeof ref === "function") {
4069
+ ref(value);
4070
+ } else if (ref !== null && ref !== undefined) {
4071
+ ref.current = value;
4072
+ }
4073
+ }
4074
+ /**
4075
+ * A utility to compose multiple refs together
4076
+ * Accepts callback refs and RefObject(s)
4077
+ */ function composeRefs(...refs) {
4078
+ return (node)=>{
4079
+ for (const ref of refs){
4080
+ setRef(ref, node);
4081
+ }
4082
+ };
4083
+ }
4084
+
4085
+ const orientationConfig = {
4086
+ vertical: {
4087
+ modifiers: [
4088
+ restrictToVerticalAxis,
4089
+ restrictToParentElement
4090
+ ],
4091
+ strategy: verticalListSortingStrategy
4092
+ },
4093
+ horizontal: {
4094
+ modifiers: [
4095
+ restrictToHorizontalAxis,
4096
+ restrictToParentElement
4097
+ ],
4098
+ strategy: horizontalListSortingStrategy
4099
+ },
4100
+ mixed: {
4101
+ modifiers: [
4102
+ restrictToParentElement
4103
+ ],
4104
+ strategy: undefined
4105
+ }
4106
+ };
4107
+ function Sortable({ value, onValueChange, collisionDetection = closestCenter, modifiers, strategy, onMove, orientation = "vertical", overlay, children, ...props }) {
4108
+ const [activeId, setActiveId] = React.useState(null);
4109
+ const sensors = useSensors(useSensor(MouseSensor), useSensor(TouchSensor), useSensor(KeyboardSensor));
4110
+ const config = orientationConfig[orientation];
4111
+ return /*#__PURE__*/ React.createElement(DndContext, {
4112
+ modifiers: modifiers ?? config.modifiers,
4113
+ sensors: sensors,
4114
+ onDragStart: ({ active })=>setActiveId(active.id),
4115
+ onDragEnd: ({ active, over })=>{
4116
+ if (over && active.id !== over?.id) {
4117
+ const activeIndex = value.findIndex((item)=>item.id === active.id);
4118
+ const overIndex = value.findIndex((item)=>item.id === over.id);
4119
+ if (onMove) {
4120
+ onMove({
4121
+ activeIndex,
4122
+ overIndex
4123
+ });
4124
+ } else {
4125
+ onValueChange?.(arrayMove(value, activeIndex, overIndex));
4126
+ }
4127
+ }
4128
+ setActiveId(null);
4129
+ },
4130
+ onDragCancel: ()=>setActiveId(null),
4131
+ collisionDetection: collisionDetection,
4132
+ ...props
4133
+ }, /*#__PURE__*/ React.createElement(SortableContext, {
4134
+ items: value,
4135
+ strategy: strategy ?? config.strategy
4136
+ }, children), overlay ? /*#__PURE__*/ React.createElement(SortableOverlay, {
4137
+ activeId: activeId
4138
+ }, overlay) : null);
4139
+ }
4140
+ const dropAnimationOpts = {
4141
+ sideEffects: defaultDropAnimationSideEffects({
4142
+ styles: {
4143
+ active: {
4144
+ opacity: "0.4"
4145
+ }
4146
+ }
4147
+ })
4148
+ };
4149
+ const SortableOverlay = /*#__PURE__*/ React.forwardRef(({ activeId, dropAnimation = dropAnimationOpts, children, ...props }, ref)=>{
4150
+ return /*#__PURE__*/ React.createElement(DragOverlay, {
4151
+ dropAnimation: dropAnimation,
4152
+ ...props
4153
+ }, activeId ? /*#__PURE__*/ React.createElement(SortableItem, {
4154
+ ref: ref,
4155
+ value: activeId,
4156
+ className: "cursor-grabbing",
4157
+ asChild: true
4158
+ }, children) : null);
4159
+ });
4160
+ SortableOverlay.displayName = "SortableOverlay";
4161
+ const SortableItemContext = /*#__PURE__*/ React.createContext({
4162
+ attributes: {},
4163
+ listeners: undefined,
4164
+ isDragging: false
4165
+ });
4166
+ function useSortableItem() {
4167
+ const context = React.useContext(SortableItemContext);
4168
+ if (!context) {
4169
+ throw new Error("useSortableItem must be used within a SortableItem");
4170
+ }
4171
+ return context;
4172
+ }
4173
+ const SortableItem = /*#__PURE__*/ React.forwardRef(({ value, asTrigger, asChild, className, ...props }, ref)=>{
4174
+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
4175
+ id: value
4176
+ });
4177
+ const context = React.useMemo(()=>({
4178
+ attributes,
4179
+ listeners,
4180
+ isDragging
4181
+ }), [
4182
+ attributes,
4183
+ listeners,
4184
+ isDragging
4185
+ ]);
4186
+ const style = {
4187
+ opacity: isDragging ? 0.5 : 1,
4188
+ transform: CSS.Translate.toString(transform),
4189
+ transition
4190
+ };
4191
+ const Comp = asChild ? Slot : "div";
4192
+ return /*#__PURE__*/ React.createElement(SortableItemContext.Provider, {
4193
+ value: context
4194
+ }, /*#__PURE__*/ React.createElement(Comp, {
4195
+ "data-state": isDragging ? "dragging" : undefined,
4196
+ className: cn("data-[state=dragging]:cursor-grabbing", {
4197
+ "cursor-grab": !isDragging && asTrigger
4198
+ }, className),
4199
+ ref: composeRefs(ref, setNodeRef),
4200
+ style: style,
4201
+ ...asTrigger ? attributes : {},
4202
+ ...asTrigger ? listeners : {},
4203
+ ...props
4204
+ }));
4205
+ });
4206
+ SortableItem.displayName = "SortableItem";
4207
+ const SortableDragHandle = /*#__PURE__*/ React.forwardRef(({ className, ...props }, ref)=>{
4208
+ const { attributes, listeners, isDragging } = useSortableItem();
4209
+ return /*#__PURE__*/ React.createElement(Button, {
4210
+ ref: composeRefs(ref),
4211
+ "data-state": isDragging ? "dragging" : undefined,
4212
+ className: cn("cursor-grab data-[state=dragging]:cursor-grabbing", className),
4213
+ ...attributes,
4214
+ ...listeners,
4215
+ ...props
4216
+ });
4217
+ });
4218
+ SortableDragHandle.displayName = "SortableDragHandle";
4219
+
4220
+ export { Sortable as S, SortableDragHandle as a, SortableItem as b, SortableOverlay as c };
4221
+ //# sourceMappingURL=sortable-D8ayoe_b.mjs.map