abrplus-ui-kit 0.2.9

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