@btst/stack 1.5.2 → 1.7.0

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