@eightshift/ui-components 5.0.10 → 5.1.1

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 (85) hide show
  1. package/dist/{Collection-uTAXq9Br.js → Collection-BRJOMbOa.js} +12 -7
  2. package/dist/{Dialog-CmAxaSUv.js → Dialog-D6EdDPeu.js} +8 -8
  3. package/dist/{useFormValidation-Dy0PXJg5.js → Form-Bnyyv3Im.js} +6 -4
  4. package/dist/{Group-DDPhPPTQ.js → Group-LBogWgyp.js} +2 -2
  5. package/dist/{Input-BmDS8Juy.js → Input-DfSBLhDx.js} +1 -1
  6. package/dist/List-BLeHBkfx.js +590 -0
  7. package/dist/{ListBox-_nDFq8-H.js → ListBox-BY3gwI8c.js} +3 -3
  8. package/dist/Select-BebwUgKB.js +764 -0
  9. package/dist/Separator-CTQWg_HO.js +1111 -0
  10. package/dist/TextField-o2U-uBWv.js +133 -0
  11. package/dist/assets/style-admin.css +264 -150
  12. package/dist/assets/style-editor.css +264 -150
  13. package/dist/assets/style.css +264 -150
  14. package/dist/assets/wp-font-enhancements.css +1 -1
  15. package/dist/assets/wp-ui-enhancements.css +1 -1
  16. package/dist/components/base-control/base-control.js +1 -1
  17. package/dist/components/breakpoint-preview/breakpoint-preview.js +3 -4
  18. package/dist/components/button/button.js +3 -3
  19. package/dist/components/checkbox/checkbox.js +1 -2
  20. package/dist/components/color-pickers/color-picker.js +7 -9
  21. package/dist/components/color-pickers/color-swatch.js +1 -1
  22. package/dist/components/color-pickers/gradient-editor.js +19 -25
  23. package/dist/components/color-pickers/solid-color-picker.js +27 -27
  24. package/dist/components/component-toggle/component-toggle.js +1 -1
  25. package/dist/components/draggable/draggable-handle.js +2 -2
  26. package/dist/components/draggable/draggable.js +5 -5
  27. package/dist/components/draggable-list/draggable-list-item.js +2 -2
  28. package/dist/components/draggable-list/draggable-list.js +5 -5
  29. package/dist/components/expandable/expandable.js +1 -1
  30. package/dist/components/index.js +5 -5
  31. package/dist/components/input-field/input-field.js +14 -129
  32. package/dist/components/item-collection/item-collection.js +1 -1
  33. package/dist/components/link-input/link-input.js +1463 -17
  34. package/dist/components/matrix-align/matrix-align.js +11 -14
  35. package/dist/components/menu/menu.js +4 -8
  36. package/dist/components/modal/modal.js +30 -31
  37. package/dist/components/number-picker/number-picker.js +9 -10
  38. package/dist/components/option-select/option-select.js +140 -156
  39. package/dist/components/placeholders/file-placeholder.js +1 -1
  40. package/dist/components/placeholders/image-placeholder.js +3 -3
  41. package/dist/components/placeholders/media-placeholder.js +2 -2
  42. package/dist/components/popover/popover.js +10 -5
  43. package/dist/components/radio/radio.js +4 -5
  44. package/dist/components/repeater/repeater-item.js +1 -1
  45. package/dist/components/repeater/repeater.js +6 -6
  46. package/dist/components/responsive/mini-responsive.js +45 -47
  47. package/dist/components/responsive/responsive-legacy.js +51 -55
  48. package/dist/components/responsive/responsive.js +47 -49
  49. package/dist/components/responsive-preview/responsive-preview.js +12 -15
  50. package/dist/components/select/async-multi-select.js +4 -4
  51. package/dist/components/select/async-single-select.js +1 -1
  52. package/dist/components/select/multi-select-components.js +1 -1
  53. package/dist/components/select/multi-select.js +4 -4
  54. package/dist/components/select/shared.js +2 -2
  55. package/dist/components/select/single-select.js +1 -1
  56. package/dist/components/select/styles.js +3 -3
  57. package/dist/components/select/v2/async-select.js +216 -158
  58. package/dist/components/select/v2/shared.js +29 -20
  59. package/dist/components/select/v2/single-select.js +203 -851
  60. package/dist/components/slider/column-config-slider.js +2 -2
  61. package/dist/components/slider/slider.js +2 -2
  62. package/dist/components/slider/utils.js +1 -1
  63. package/dist/components/tabs/tabs.js +7 -8
  64. package/dist/components/toggle/switch.js +4 -3
  65. package/dist/components/toggle-button/toggle-button.js +1 -1
  66. package/dist/{default-i18n-CT_oS1Fy.js → default-i18n-OFa3zAyB.js} +5 -9
  67. package/dist/icons/icons.js +141 -141
  68. package/dist/icons/jsx-svg.js +3 -4
  69. package/dist/index.js +4 -4
  70. package/dist/{multi-select-components-Sp-JEFEX.js → multi-select-components-BcKzA24f.js} +3 -3
  71. package/dist/{react-jsx-parser.min-DZCiis5V.js → react-jsx-parser.min-LF707GK8.js} +312 -332
  72. package/dist/useAsyncList-fLtZMvJO.js +420 -0
  73. package/dist/useFilter-BR5z1A4Q.js +50 -0
  74. package/dist/{useListState-9Hq_FiRF.js → useListState-BrZ2XvDS.js} +1 -1
  75. package/dist/{useNumberField-D0u2bh8g.js → useNumberField-y0dLc_6m.js} +2 -2
  76. package/dist/{useSingleSelectListState-DqhemUIh.js → useSingleSelectListState-Bh46cRXs.js} +1 -1
  77. package/dist/utilities/array-helpers.js +4 -7
  78. package/dist/utilities/es-dash.js +21 -3
  79. package/dist/utilities/index.js +2 -1
  80. package/dist/utilities/text-helpers.js +3 -3
  81. package/package.json +9 -9
  82. package/dist/ComboBox-BANSEKnb.js +0 -1915
  83. package/dist/Form-Cq3fu75_.js +0 -5
  84. package/dist/List-CZMUbkFU.js +0 -593
  85. package/dist/Separator-BN3mjL6q.js +0 -332
@@ -2388,11 +2388,16 @@ export {
2388
2388
  $ae20dd8cbca75726$export$d6daf82dcd84e87c as i,
2389
2389
  $7135fc7d473fd974$export$a164736487e3f0ae as j,
2390
2390
  $7135fc7d473fd974$export$90e00781bc59d8f9 as k,
2391
- $cc38e7bd3fc7b213$export$2bb74740c4e19def as l,
2392
- $feb5ffebff200149$export$c3d8340acf92597f as m,
2393
- $c5a24bc478652b5f$export$1005530eda016c13 as n,
2394
- $fb3050f43d946246$export$e32c88dfddc6e1d8 as o,
2395
- $55f9b1ae81f22853$export$2b35b76d2e30e129 as p,
2396
- $8a26561d2877236e$export$c24ed0104d07eab9 as q,
2397
- $e1995378a142960e$export$e953bb1cd0f19726 as r
2391
+ $fb3050f43d946246$export$e32c88dfddc6e1d8 as l,
2392
+ $c5a24bc478652b5f$export$1005530eda016c13 as m,
2393
+ $55f9b1ae81f22853$export$2b35b76d2e30e129 as n,
2394
+ $cc38e7bd3fc7b213$export$2bb74740c4e19def as o,
2395
+ $feb5ffebff200149$export$c3d8340acf92597f as p,
2396
+ $5671b20cf9b562b2$export$831c820ad60f9d12 as q,
2397
+ $55f9b1ae81f22853$export$76e4e37e5339496d as r,
2398
+ $5671b20cf9b562b2$export$447a38995de2c711 as s,
2399
+ $55f9b1ae81f22853$export$6c5dc7e81d2cc29a as t,
2400
+ $21f1aa98acb08317$export$16792effe837dba3 as u,
2401
+ $8a26561d2877236e$export$c24ed0104d07eab9 as v,
2402
+ $e1995378a142960e$export$e953bb1cd0f19726 as w
2398
2403
  };
@@ -2,8 +2,8 @@ import { a as $d2b4bc8c273e7be6$export$24d547caef80ccd1 } from "./Button-DH22t_S
2
2
  import { l as $df56164dff5785e2$export$4338b53315abf666, d as $3ef42575df84b30b$export$9d1611c77c2fe928, f as $8ae05eaa5c114e9c$export$7f54fc3180508a52, e as $bdb11010cef70236$export$f680877a34711e37, k as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c, p as $ff5963eb1fccf552$export$e08e3b67e392101e, n as $b5e257d569688ac6$export$535bd6ca7f90a273, j as $bdb11010cef70236$export$b4cc09c592e8fdb8, a as $64fa3d84918910a7$export$29f1550f4b0d4415, b as $64fa3d84918910a7$export$4d86445c2cf5e3, i as $64fa3d84918910a7$export$2881499e37b75b9a, $ as $64fa3d84918910a7$export$fabf2dc03a41866e, o as $64fa3d84918910a7$export$c62b8e45d58ddad9, m as $5dc95899b306f630$export$c9058316764c140e, g as $64fa3d84918910a7$export$9d4c57ee4c6ffdd8 } from "./utils-CZt7LCbO.js";
3
3
  import { $ as $4e85f108e88277b8$export$d688439359537581 } from "./RSPContexts-2lR5GG9p.js";
4
4
  import { g as $dd149f63282afbbf$export$f6211563215e3b37, c as $2a41e45df1593e64$export$d39e1813b3bdd0e1, f as $9daab02d461809db$export$683480f191c0e3ea, $ as $fc909762b330b746$export$61c6a8c84e605fb6, a as $d3f049242431219c$export$45fda7c47f93fd48, b as $d3f049242431219c$export$6d3443f2c48bfc20, d as $44f671af83e7d9e0$export$2de4954e8ae13b9f } from "./OverlayArrow-BUfV-5P3.js";
5
- import { q as $8a26561d2877236e$export$c24ed0104d07eab9, c as $880e95eb8b93ba9a$export$ecf600387e221c37, $ as $7af3f5b51489e0b5$export$253fe78d46329472, a as $7613b1592d41b092$export$6cd28814d92fa9c9, b as $d496c0a20b6e58ec$export$6c8a5aaad13c9852, d as $e1995378a142960e$export$18af5c7a9e9b3664, r as $e1995378a142960e$export$e953bb1cd0f19726, e as $e1995378a142960e$export$bf788dd355e3a401, f as $e1995378a142960e$export$fb8073518f34e6ec, g as $7135fc7d473fd974$export$4feb769f8ddf26c5, h as $7135fc7d473fd974$export$d40e14dec8b060a8, k as $7135fc7d473fd974$export$90e00781bc59d8f9 } from "./Collection-uTAXq9Br.js";
6
- import { b as $62d8ded9296f3872$export$cfa2225e87938781, c as $982254629710d113$export$b95089534ab7c1fd, d as $453cc9f0df89c0a5$export$77d5aafae4e095b2, e as $d2f53cda644affe3$export$65d2a03b8800d6e3, h as $431f98aba6844401$export$6615d83f6de245ce, i as $72a5793c14baf454$export$e0e4026c12a8bdbb } from "./Separator-BN3mjL6q.js";
5
+ import { v as $8a26561d2877236e$export$c24ed0104d07eab9, c as $880e95eb8b93ba9a$export$ecf600387e221c37, $ as $7af3f5b51489e0b5$export$253fe78d46329472, a as $7613b1592d41b092$export$6cd28814d92fa9c9, b as $d496c0a20b6e58ec$export$6c8a5aaad13c9852, d as $e1995378a142960e$export$18af5c7a9e9b3664, w as $e1995378a142960e$export$e953bb1cd0f19726, e as $e1995378a142960e$export$bf788dd355e3a401, f as $e1995378a142960e$export$fb8073518f34e6ec, g as $7135fc7d473fd974$export$4feb769f8ddf26c5, h as $7135fc7d473fd974$export$d40e14dec8b060a8, k as $7135fc7d473fd974$export$90e00781bc59d8f9 } from "./Collection-BRJOMbOa.js";
6
+ import { e as $62d8ded9296f3872$export$cfa2225e87938781, f as $982254629710d113$export$b95089534ab7c1fd, g as $453cc9f0df89c0a5$export$77d5aafae4e095b2, h as $d2f53cda644affe3$export$65d2a03b8800d6e3, j as $431f98aba6844401$export$6615d83f6de245ce, k as $72a5793c14baf454$export$e0e4026c12a8bdbb } from "./Separator-CTQWg_HO.js";
7
7
  import React__default, { useRef, useContext, useEffect, useMemo, useState, useCallback, forwardRef, createContext } from "react";
8
8
  import { a as $514c0188e459b4c0$export$9afb8bc826b033ea } from "./Text-BuJgePCv.js";
9
9
  import { $ as $65484d02dcb7eb3e$export$457c3d6518dd4c6f } from "./filterDOMProps-EDDcM64A.js";
@@ -2298,12 +2298,12 @@ const $de32f1b87079253c$export$3ddf2d174ce01153 = /* @__PURE__ */ forwardRef(fun
2298
2298
  }, renderProps.children));
2299
2299
  });
2300
2300
  export {
2301
- $07b14b47974efb58$export$5b6b19405a83ff9d as $,
2302
- $3674c52c6b3c5bce$export$27d2ad3c5815583e as a,
2303
- $3674c52c6b3c5bce$export$d9b273488cd8ce6f as b,
2304
- $3674c52c6b3c5bce$export$2ce376c2cc3355c8 as c,
2305
- $3674c52c6b3c5bce$export$4b1545b4f2016d26 as d,
2306
- $3674c52c6b3c5bce$export$ecabc99eeffab7ca as e,
2301
+ $3674c52c6b3c5bce$export$27d2ad3c5815583e as $,
2302
+ $3674c52c6b3c5bce$export$d9b273488cd8ce6f as a,
2303
+ $3674c52c6b3c5bce$export$2ce376c2cc3355c8 as b,
2304
+ $3674c52c6b3c5bce$export$4b1545b4f2016d26 as c,
2305
+ $3674c52c6b3c5bce$export$ecabc99eeffab7ca as d,
2306
+ $07b14b47974efb58$export$5b6b19405a83ff9d as e,
2307
2307
  $de32f1b87079253c$export$3ddf2d174ce01153 as f,
2308
2308
  $de32f1b87079253c$export$2e1e1122cf0cba88 as g,
2309
2309
  $a11501f3d1d39e6c$export$ea8f71083e90600f as h,
@@ -216,9 +216,11 @@ function $e93e671b31057976$var$getFirstInvalidInput(form) {
216
216
  }
217
217
  return null;
218
218
  }
219
+ const $d3e0e05bdfcf66bd$export$c24727297075ec6a = /* @__PURE__ */ createContext(null);
219
220
  export {
220
- $e5be200c675c3b3a$export$fc1a364ae1f3ff10 as $,
221
- $e93e671b31057976$export$b8473d3665f3a75a as a,
222
- $e5be200c675c3b3a$export$a763b9476acd3eb as b,
223
- $e5be200c675c3b3a$export$dad6ae84456c676a as c
221
+ $d3e0e05bdfcf66bd$export$c24727297075ec6a as $,
222
+ $e5be200c675c3b3a$export$fc1a364ae1f3ff10 as a,
223
+ $e93e671b31057976$export$b8473d3665f3a75a as b,
224
+ $e5be200c675c3b3a$export$a763b9476acd3eb as c,
225
+ $e5be200c675c3b3a$export$dad6ae84456c676a as d
224
226
  };
@@ -43,6 +43,6 @@ const $a049562f99e7db0e$export$eb2fcfdbd7ba97d4 = /* @__PURE__ */ forwardRef(fun
43
43
  }, renderProps.children);
44
44
  });
45
45
  export {
46
- $a049562f99e7db0e$export$eb2fcfdbd7ba97d4 as $,
47
- $a049562f99e7db0e$export$f9c6924e160136d1 as a
46
+ $a049562f99e7db0e$export$f9c6924e160136d1 as $,
47
+ $a049562f99e7db0e$export$eb2fcfdbd7ba97d4 as a
48
48
  };
@@ -4,7 +4,7 @@ import { $ as $65484d02dcb7eb3e$export$457c3d6518dd4c6f } from "./filterDOMProps
4
4
  import { $ as $99facab73266f662$export$5add1d006293d136 } from "./useFormReset-D2YaWRIA.js";
5
5
  import React__default, { useEffect, createContext } from "react";
6
6
  import { a as $2baaea4c71418dea$export$294aa081a6c6f55d } from "./FieldError-DHrSdE_Q.js";
7
- import { $ as $e5be200c675c3b3a$export$fc1a364ae1f3ff10, a as $e93e671b31057976$export$b8473d3665f3a75a } from "./useFormValidation-Dy0PXJg5.js";
7
+ import { a as $e5be200c675c3b3a$export$fc1a364ae1f3ff10, b as $e93e671b31057976$export$b8473d3665f3a75a } from "./Form-Bnyyv3Im.js";
8
8
  import { $ as $f39a9eba43920ace$export$86427a43e3e48ebb } from "./Hidden-rE6uR-lr.js";
9
9
  import { $ as $f7dceffc5ad7768b$export$4e328f61c538687f } from "./useFocusRing-Bv0UJQl8.js";
10
10
  function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
@@ -0,0 +1,590 @@
1
+ import * as React from "react";
2
+ import { r as reactDomExports } from "./index-CFozsmNS.js";
3
+ function arrayMove(array, from, to) {
4
+ array = array.slice();
5
+ array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
6
+ return array;
7
+ }
8
+ function arrayRemove(array, index) {
9
+ array = array.slice();
10
+ array.splice(index, 1);
11
+ return array;
12
+ }
13
+ function getTranslateOffset(element) {
14
+ const style = window.getComputedStyle(element);
15
+ return Math.max(parseInt(style["margin-top"], 10), parseInt(style["margin-bottom"], 10)) + element.getBoundingClientRect().height;
16
+ }
17
+ function isTouchEvent(event) {
18
+ return event.touches && event.touches.length || event.changedTouches && event.changedTouches.length;
19
+ }
20
+ function transformItem(element, offsetY = 0, offsetX = 0) {
21
+ if (!element)
22
+ return;
23
+ if (offsetY === null || offsetX === null) {
24
+ element.style.removeProperty("transform");
25
+ return;
26
+ }
27
+ element.style.transform = `translate(${offsetX}px, ${offsetY}px)`;
28
+ }
29
+ function setItemTransition(element, duration, timing) {
30
+ if (element) {
31
+ element.style["transition"] = `transform ${duration}ms${timing ? ` ${timing}` : ""}`;
32
+ }
33
+ }
34
+ function binarySearch(array, targetValue) {
35
+ let min = 0;
36
+ let max = array.length - 1;
37
+ let guess;
38
+ while (min <= max) {
39
+ guess = Math.floor((max + min) / 2);
40
+ if (!array[guess + 1] || array[guess] <= targetValue && array[guess + 1] >= targetValue) {
41
+ return guess;
42
+ } else if (array[guess] < targetValue && array[guess + 1] < targetValue) {
43
+ min = guess + 1;
44
+ } else {
45
+ max = guess - 1;
46
+ }
47
+ }
48
+ return -1;
49
+ }
50
+ const schd = (fn) => {
51
+ let lastArgs = [];
52
+ let frameId = null;
53
+ const wrapperFn = (...args) => {
54
+ lastArgs = args;
55
+ if (frameId) {
56
+ return;
57
+ }
58
+ frameId = requestAnimationFrame(() => {
59
+ frameId = null;
60
+ fn(...lastArgs);
61
+ });
62
+ };
63
+ wrapperFn.cancel = () => {
64
+ if (frameId) {
65
+ cancelAnimationFrame(frameId);
66
+ }
67
+ };
68
+ return wrapperFn;
69
+ };
70
+ function checkIfInteractive(target, rootElement) {
71
+ const DISABLED_ELEMENTS = [
72
+ "input",
73
+ "textarea",
74
+ "select",
75
+ "option",
76
+ "optgroup",
77
+ "video",
78
+ "audio",
79
+ "button",
80
+ "a"
81
+ ];
82
+ const DISABLED_ROLES = [
83
+ "button",
84
+ "link",
85
+ "checkbox",
86
+ "radio",
87
+ "switch",
88
+ "tab"
89
+ ];
90
+ if (!target || !rootElement)
91
+ return false;
92
+ while (target !== rootElement) {
93
+ if (target.getAttribute("data-movable-handle")) {
94
+ return false;
95
+ }
96
+ if (DISABLED_ELEMENTS.includes(target.tagName.toLowerCase())) {
97
+ return true;
98
+ }
99
+ const role = target.getAttribute("role");
100
+ if (role && DISABLED_ROLES.includes(role.toLowerCase())) {
101
+ return true;
102
+ }
103
+ if (target.tagName.toLowerCase() === "label" && target.hasAttribute("for")) {
104
+ return true;
105
+ }
106
+ if (target.tagName)
107
+ target = target.parentElement;
108
+ }
109
+ return false;
110
+ }
111
+ const AUTOSCROLL_ACTIVE_OFFSET = 200;
112
+ const AUTOSCROLL_SPEED_RATIO = 10;
113
+ const AUTOSCROLL_DELTA_THRESHOLD = 10;
114
+ class List extends React.Component {
115
+ listRef = React.createRef();
116
+ ghostRef = React.createRef();
117
+ topOffsets = [];
118
+ itemTranslateOffsets = [];
119
+ initialYOffset = 0;
120
+ lastScroll = 0;
121
+ lastYOffset = 0;
122
+ lastListYOffset = 0;
123
+ dropTimeout;
124
+ needle = -1;
125
+ afterIndex = -2;
126
+ state = {
127
+ itemDragged: -1,
128
+ itemDraggedOutOfBounds: -1,
129
+ selectedItem: -1,
130
+ initialX: 0,
131
+ initialY: 0,
132
+ targetX: 0,
133
+ targetY: 0,
134
+ targetHeight: 0,
135
+ targetWidth: 0,
136
+ liveText: "",
137
+ scrollingSpeed: 0,
138
+ scrollWindow: false
139
+ };
140
+ schdOnMouseMove;
141
+ schdOnTouchMove;
142
+ schdOnEnd;
143
+ constructor(props) {
144
+ super(props);
145
+ this.schdOnMouseMove = schd(this.onMouseMove);
146
+ this.schdOnTouchMove = schd(this.onTouchMove);
147
+ this.schdOnEnd = schd(this.onEnd);
148
+ }
149
+ componentDidMount() {
150
+ this.calculateOffsets();
151
+ document.addEventListener("touchstart", this.onMouseOrTouchStart, {
152
+ passive: false,
153
+ capture: false
154
+ });
155
+ document.addEventListener("mousedown", this.onMouseOrTouchStart);
156
+ }
157
+ componentDidUpdate(_prevProps, prevState) {
158
+ if (prevState.scrollingSpeed !== this.state.scrollingSpeed && prevState.scrollingSpeed === 0) {
159
+ this.doScrolling();
160
+ }
161
+ }
162
+ componentWillUnmount() {
163
+ document.removeEventListener("touchstart", this.onMouseOrTouchStart);
164
+ document.removeEventListener("mousedown", this.onMouseOrTouchStart);
165
+ if (this.dropTimeout) {
166
+ window.clearTimeout(this.dropTimeout);
167
+ }
168
+ this.schdOnMouseMove.cancel();
169
+ this.schdOnTouchMove.cancel();
170
+ this.schdOnEnd.cancel();
171
+ }
172
+ doScrolling = () => {
173
+ const { scrollingSpeed, scrollWindow } = this.state;
174
+ const listEl = this.listRef.current;
175
+ window.requestAnimationFrame(() => {
176
+ if (scrollWindow) {
177
+ window.scrollTo(window.pageXOffset, window.pageYOffset + scrollingSpeed * 1.5);
178
+ } else {
179
+ listEl.scrollTop += scrollingSpeed;
180
+ }
181
+ if (scrollingSpeed !== 0) {
182
+ this.doScrolling();
183
+ }
184
+ });
185
+ };
186
+ getChildren = () => {
187
+ if (this.listRef && this.listRef.current) {
188
+ return Array.from(this.listRef.current.children);
189
+ }
190
+ console.warn("No items found in the List container. Did you forget to pass & spread the `props` param in renderList?");
191
+ return [];
192
+ };
193
+ static defaultProps = {
194
+ transitionDuration: 300,
195
+ lockVertically: false,
196
+ removableByMove: false,
197
+ voiceover: {
198
+ item: (position) => `You are currently at a draggable item at position ${position}. Press space bar to lift.`,
199
+ lifted: (position) => `You have lifted item at position ${position}. Press j to move down, k to move up, space bar to drop and escape to cancel.`,
200
+ moved: (position, up) => `You have moved the lifted item ${up ? "up" : "down"} to position ${position}. Press j to move down, k to move up, space bar to drop and escape to cancel.`,
201
+ dropped: (from, to) => `You have dropped the item. It has moved from position ${from} to ${to}.`,
202
+ canceled: (position) => `You have cancelled the movement. The item has returned to its starting position of ${position}.`
203
+ }
204
+ };
205
+ calculateOffsets = () => {
206
+ this.topOffsets = this.getChildren().map((item) => item.getBoundingClientRect().top);
207
+ this.itemTranslateOffsets = this.getChildren().map((item) => getTranslateOffset(item));
208
+ };
209
+ getTargetIndex = (e) => {
210
+ return this.getChildren().findIndex((child) => child === e.target || child.contains(e.target));
211
+ };
212
+ onMouseOrTouchStart = (e) => {
213
+ if (this.dropTimeout && this.state.itemDragged > -1) {
214
+ window.clearTimeout(this.dropTimeout);
215
+ this.finishDrop();
216
+ }
217
+ const isTouch = isTouchEvent(e);
218
+ if (!isTouch && e.button !== 0)
219
+ return;
220
+ const index = this.getTargetIndex(e);
221
+ if (index === -1 || this.props.disabled || // @ts-ignore
222
+ this.props.values[index] && this.props.values[index].disabled) {
223
+ if (this.state.selectedItem !== -1) {
224
+ this.setState({ selectedItem: -1 });
225
+ this.finishDrop();
226
+ }
227
+ return;
228
+ }
229
+ const listItemTouched = this.getChildren()[index];
230
+ const handle = listItemTouched.querySelector("[data-movable-handle]");
231
+ if (handle && !handle.contains(e.target)) {
232
+ return;
233
+ }
234
+ if (checkIfInteractive(e.target, listItemTouched)) {
235
+ return;
236
+ }
237
+ e.preventDefault();
238
+ this.props.beforeDrag && this.props.beforeDrag({
239
+ elements: this.getChildren(),
240
+ index
241
+ });
242
+ if (isTouch) {
243
+ const opts = { passive: false };
244
+ listItemTouched.style.touchAction = "none";
245
+ document.addEventListener("touchend", this.schdOnEnd, opts);
246
+ document.addEventListener("touchmove", this.schdOnTouchMove, opts);
247
+ document.addEventListener("touchcancel", this.schdOnEnd, opts);
248
+ } else {
249
+ document.addEventListener("mousemove", this.schdOnMouseMove);
250
+ document.addEventListener("mouseup", this.schdOnEnd);
251
+ const listItemDragged = this.getChildren()[this.state.itemDragged];
252
+ if (listItemDragged && listItemDragged.style) {
253
+ listItemDragged.style.touchAction = "";
254
+ }
255
+ }
256
+ this.onStart(listItemTouched, isTouch ? e.touches[0].clientX : e.clientX, isTouch ? e.touches[0].clientY : e.clientY, index);
257
+ };
258
+ getYOffset = () => {
259
+ const listScroll = this.listRef.current ? this.listRef.current.scrollTop : 0;
260
+ return window.pageYOffset + listScroll;
261
+ };
262
+ onStart = (target, clientX, clientY, index) => {
263
+ if (this.state.selectedItem > -1) {
264
+ this.setState({ selectedItem: -1 });
265
+ this.needle = -1;
266
+ }
267
+ const targetRect = target.getBoundingClientRect();
268
+ const targetStyles = window.getComputedStyle(target);
269
+ this.calculateOffsets();
270
+ this.initialYOffset = this.getYOffset();
271
+ this.lastYOffset = window.pageYOffset;
272
+ this.lastListYOffset = this.listRef.current.scrollTop;
273
+ this.setState({
274
+ itemDragged: index,
275
+ targetX: targetRect.left - parseInt(targetStyles["margin-left"], 10),
276
+ targetY: targetRect.top - parseInt(targetStyles["margin-top"], 10),
277
+ targetHeight: targetRect.height,
278
+ targetWidth: targetRect.width,
279
+ initialX: clientX,
280
+ initialY: clientY
281
+ });
282
+ };
283
+ onMouseMove = (e) => {
284
+ e.cancelable && e.preventDefault();
285
+ this.onMove(e.clientX, e.clientY);
286
+ };
287
+ onTouchMove = (e) => {
288
+ e.cancelable && e.preventDefault();
289
+ this.onMove(e.touches[0].clientX, e.touches[0].clientY);
290
+ };
291
+ onWheel = (e) => {
292
+ if (this.state.itemDragged < 0)
293
+ return;
294
+ this.lastScroll = this.listRef.current.scrollTop += e.deltaY;
295
+ this.moveOtherItems();
296
+ };
297
+ onMove = (clientX, clientY) => {
298
+ if (this.state.itemDragged === -1)
299
+ return null;
300
+ transformItem(this.ghostRef.current, clientY - this.state.initialY, this.props.lockVertically ? 0 : clientX - this.state.initialX);
301
+ this.autoScrolling(clientY, clientY - this.state.initialY);
302
+ this.moveOtherItems();
303
+ };
304
+ moveOtherItems = () => {
305
+ const targetRect = this.ghostRef.current.getBoundingClientRect();
306
+ const itemVerticalCenter = targetRect.top + targetRect.height / 2;
307
+ const offset = getTranslateOffset(this.getChildren()[this.state.itemDragged]);
308
+ const currentYOffset = this.getYOffset();
309
+ if (this.initialYOffset !== currentYOffset) {
310
+ this.topOffsets = this.topOffsets.map((offset2) => offset2 - (currentYOffset - this.initialYOffset));
311
+ this.initialYOffset = currentYOffset;
312
+ }
313
+ if (this.isDraggedItemOutOfBounds() && this.props.removableByMove) {
314
+ this.afterIndex = this.topOffsets.length + 1;
315
+ } else {
316
+ this.afterIndex = binarySearch(this.topOffsets, itemVerticalCenter);
317
+ }
318
+ this.animateItems(this.afterIndex === -1 ? 0 : this.afterIndex, this.state.itemDragged, offset);
319
+ };
320
+ autoScrolling = (clientY, delta) => {
321
+ const { top, bottom, height } = this.listRef.current.getBoundingClientRect();
322
+ const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
323
+ if (bottom > viewportHeight && viewportHeight - clientY < AUTOSCROLL_ACTIVE_OFFSET && delta > AUTOSCROLL_DELTA_THRESHOLD) {
324
+ this.setState({
325
+ scrollingSpeed: Math.min(Math.round((AUTOSCROLL_ACTIVE_OFFSET - (viewportHeight - clientY)) / AUTOSCROLL_SPEED_RATIO), Math.round((delta - AUTOSCROLL_DELTA_THRESHOLD) / AUTOSCROLL_SPEED_RATIO)),
326
+ scrollWindow: true
327
+ });
328
+ } else if (top < 0 && clientY < AUTOSCROLL_ACTIVE_OFFSET && delta < -10) {
329
+ this.setState({
330
+ scrollingSpeed: Math.max(Math.round((AUTOSCROLL_ACTIVE_OFFSET - clientY) / -10), Math.round((delta + AUTOSCROLL_DELTA_THRESHOLD) / AUTOSCROLL_SPEED_RATIO)),
331
+ scrollWindow: true
332
+ });
333
+ } else {
334
+ if (this.state.scrollWindow && this.state.scrollingSpeed !== 0) {
335
+ this.setState({ scrollingSpeed: 0, scrollWindow: false });
336
+ }
337
+ if (height + 20 < this.listRef.current.scrollHeight) {
338
+ let scrollingSpeed = 0;
339
+ if (clientY - top < AUTOSCROLL_ACTIVE_OFFSET && delta < -10) {
340
+ scrollingSpeed = Math.max(Math.round((AUTOSCROLL_ACTIVE_OFFSET - (clientY - top)) / -10), Math.round((delta + AUTOSCROLL_DELTA_THRESHOLD) / AUTOSCROLL_SPEED_RATIO));
341
+ } else if (bottom - clientY < AUTOSCROLL_ACTIVE_OFFSET && delta > AUTOSCROLL_DELTA_THRESHOLD) {
342
+ scrollingSpeed = Math.min(Math.round((AUTOSCROLL_ACTIVE_OFFSET - (bottom - clientY)) / AUTOSCROLL_SPEED_RATIO), Math.round((delta - AUTOSCROLL_DELTA_THRESHOLD) / AUTOSCROLL_SPEED_RATIO));
343
+ }
344
+ if (this.state.scrollingSpeed !== scrollingSpeed) {
345
+ this.setState({ scrollingSpeed });
346
+ }
347
+ }
348
+ }
349
+ };
350
+ animateItems = (needle, movedItem, offset, animateMovedItem = false) => {
351
+ this.getChildren().forEach((item, i) => {
352
+ setItemTransition(item, this.props.transitionDuration);
353
+ if (movedItem === i && animateMovedItem) {
354
+ if (movedItem === needle) {
355
+ return transformItem(item, null);
356
+ }
357
+ transformItem(item, movedItem < needle ? this.itemTranslateOffsets.slice(movedItem + 1, needle + 1).reduce((a, b) => a + b, 0) : this.itemTranslateOffsets.slice(needle, movedItem).reduce((a, b) => a + b, 0) * -1);
358
+ } else if (movedItem < needle && i > movedItem && i <= needle) {
359
+ transformItem(item, -offset);
360
+ } else if (i < movedItem && movedItem > needle && i >= needle) {
361
+ transformItem(item, offset);
362
+ } else {
363
+ transformItem(item, null);
364
+ }
365
+ });
366
+ };
367
+ isDraggedItemOutOfBounds = () => {
368
+ const initialRect = this.getChildren()[this.state.itemDragged].getBoundingClientRect();
369
+ const targetRect = this.ghostRef.current.getBoundingClientRect();
370
+ if (Math.abs(initialRect.left - targetRect.left) > targetRect.width) {
371
+ if (this.state.itemDraggedOutOfBounds === -1) {
372
+ this.setState({ itemDraggedOutOfBounds: this.state.itemDragged });
373
+ }
374
+ return true;
375
+ }
376
+ if (this.state.itemDraggedOutOfBounds > -1) {
377
+ this.setState({ itemDraggedOutOfBounds: -1 });
378
+ }
379
+ return false;
380
+ };
381
+ onEnd = (e) => {
382
+ e.cancelable && e.preventDefault();
383
+ document.removeEventListener("mousemove", this.schdOnMouseMove);
384
+ document.removeEventListener("touchmove", this.schdOnTouchMove);
385
+ document.removeEventListener("mouseup", this.schdOnEnd);
386
+ document.removeEventListener("touchup", this.schdOnEnd);
387
+ document.removeEventListener("touchcancel", this.schdOnEnd);
388
+ const removeItem = this.props.removableByMove && this.isDraggedItemOutOfBounds();
389
+ if (!removeItem && this.props.transitionDuration > 0 && this.afterIndex !== -2) {
390
+ schd(() => {
391
+ setItemTransition(this.ghostRef.current, this.props.transitionDuration, "cubic-bezier(.2,1,.1,1)");
392
+ if (this.afterIndex < 1 && this.state.itemDragged === 0) {
393
+ transformItem(this.ghostRef.current, 0, 0);
394
+ } else {
395
+ transformItem(
396
+ this.ghostRef.current,
397
+ // compensate window scroll
398
+ -(window.pageYOffset - this.lastYOffset) + // compensate container scroll
399
+ -(this.listRef.current.scrollTop - this.lastListYOffset) + (this.state.itemDragged < this.afterIndex ? this.itemTranslateOffsets.slice(this.state.itemDragged + 1, this.afterIndex + 1).reduce((a, b) => a + b, 0) : this.itemTranslateOffsets.slice(this.afterIndex < 0 ? 0 : this.afterIndex, this.state.itemDragged).reduce((a, b) => a + b, 0) * -1),
400
+ 0
401
+ );
402
+ }
403
+ })();
404
+ }
405
+ this.dropTimeout = window.setTimeout(this.finishDrop, removeItem || this.afterIndex === -2 ? 0 : this.props.transitionDuration);
406
+ };
407
+ finishDrop = () => {
408
+ const removeItem = this.props.removableByMove && this.isDraggedItemOutOfBounds();
409
+ const oldIndex = this.state.itemDragged;
410
+ const hasChanged = this.afterIndex > -2 && oldIndex !== this.afterIndex;
411
+ const newIndex = hasChanged ? removeItem ? -1 : Math.max(this.afterIndex, 0) : oldIndex;
412
+ if (removeItem || hasChanged) {
413
+ this.props.onChange({
414
+ oldIndex,
415
+ newIndex,
416
+ targetRect: this.ghostRef.current.getBoundingClientRect()
417
+ });
418
+ }
419
+ this.props.afterDrag && this.props.afterDrag({
420
+ elements: this.getChildren(),
421
+ oldIndex,
422
+ newIndex
423
+ });
424
+ this.getChildren().forEach((item) => {
425
+ setItemTransition(item, 0);
426
+ transformItem(item, null);
427
+ item.style.touchAction = "";
428
+ });
429
+ this.setState({ itemDragged: -1, scrollingSpeed: 0 });
430
+ this.afterIndex = -2;
431
+ if (this.lastScroll > 0) {
432
+ this.listRef.current.scrollTop = this.lastScroll;
433
+ this.lastScroll = 0;
434
+ }
435
+ };
436
+ onKeyDown = (e) => {
437
+ const selectedItem = this.state.selectedItem;
438
+ const index = this.getTargetIndex(e);
439
+ if (checkIfInteractive(e.target, e.currentTarget)) {
440
+ return;
441
+ }
442
+ if (index === -1)
443
+ return;
444
+ if (e.key === " ") {
445
+ e.preventDefault();
446
+ if (selectedItem === index) {
447
+ if (selectedItem !== this.needle) {
448
+ this.getChildren().forEach((item) => {
449
+ setItemTransition(item, 0);
450
+ transformItem(item, null);
451
+ });
452
+ this.props.onChange({
453
+ oldIndex: selectedItem,
454
+ newIndex: this.needle,
455
+ targetRect: this.getChildren()[this.needle].getBoundingClientRect()
456
+ });
457
+ this.getChildren()[this.needle].focus();
458
+ }
459
+ this.setState({
460
+ selectedItem: -1,
461
+ liveText: this.props.voiceover.dropped(selectedItem + 1, this.needle + 1)
462
+ });
463
+ this.needle = -1;
464
+ } else {
465
+ this.setState({
466
+ selectedItem: index,
467
+ liveText: this.props.voiceover.lifted(index + 1)
468
+ });
469
+ this.needle = index;
470
+ this.calculateOffsets();
471
+ }
472
+ }
473
+ if ((e.key === "ArrowDown" || e.key === "j") && selectedItem > -1 && this.needle < this.props.values.length - 1) {
474
+ e.preventDefault();
475
+ const offset = getTranslateOffset(this.getChildren()[selectedItem]);
476
+ this.needle++;
477
+ this.animateItems(this.needle, selectedItem, offset, true);
478
+ this.setState({
479
+ liveText: this.props.voiceover.moved(this.needle + 1, false)
480
+ });
481
+ }
482
+ if ((e.key === "ArrowUp" || e.key === "k") && selectedItem > -1 && this.needle > 0) {
483
+ e.preventDefault();
484
+ const offset = getTranslateOffset(this.getChildren()[selectedItem]);
485
+ this.needle--;
486
+ this.animateItems(this.needle, selectedItem, offset, true);
487
+ this.setState({
488
+ liveText: this.props.voiceover.moved(this.needle + 1, true)
489
+ });
490
+ }
491
+ if (e.key === "Escape" && selectedItem > -1) {
492
+ this.getChildren().forEach((item) => {
493
+ setItemTransition(item, 0);
494
+ transformItem(item, null);
495
+ });
496
+ this.setState({
497
+ selectedItem: -1,
498
+ liveText: this.props.voiceover.canceled(selectedItem + 1)
499
+ });
500
+ this.needle = -1;
501
+ }
502
+ if ((e.key === "Tab" || e.key === "Enter") && selectedItem > -1) {
503
+ e.preventDefault();
504
+ }
505
+ };
506
+ render() {
507
+ const baseStyle = {
508
+ userSelect: "none",
509
+ WebkitUserSelect: "none",
510
+ MozUserSelect: "none",
511
+ msUserSelect: "none",
512
+ boxSizing: "border-box",
513
+ position: "relative"
514
+ };
515
+ const ghostStyle = {
516
+ ...baseStyle,
517
+ top: this.state.targetY,
518
+ left: this.state.targetX,
519
+ width: this.state.targetWidth,
520
+ height: this.state.targetHeight,
521
+ position: "fixed",
522
+ marginTop: 0
523
+ };
524
+ return React.createElement(
525
+ React.Fragment,
526
+ null,
527
+ this.props.renderList({
528
+ children: this.props.values.map((value, index) => {
529
+ const isHidden = index === this.state.itemDragged;
530
+ const isSelected = index === this.state.selectedItem;
531
+ const isDisabled = Boolean(this.props.disabled || this.props.values[index] && typeof this.props.values[index] === "object" && // @ts-expect-error value doesn't necessarily have a `disabled` property
532
+ this.props.values[index].disabled);
533
+ const props = {
534
+ key: index,
535
+ tabIndex: isDisabled ? -1 : 0,
536
+ "aria-roledescription": this.props.voiceover.item(index + 1),
537
+ onKeyDown: this.onKeyDown,
538
+ style: {
539
+ ...baseStyle,
540
+ visibility: isHidden ? "hidden" : void 0,
541
+ zIndex: isSelected ? 5e3 : 0
542
+ }
543
+ };
544
+ return this.props.renderItem({
545
+ value,
546
+ props,
547
+ index,
548
+ isDragged: false,
549
+ isSelected,
550
+ isOutOfBounds: false,
551
+ isDisabled
552
+ });
553
+ }),
554
+ isDragged: this.state.itemDragged > -1,
555
+ props: {
556
+ ref: this.listRef
557
+ }
558
+ }),
559
+ this.state.itemDragged > -1 && reactDomExports.createPortal(this.props.renderItem({
560
+ value: this.props.values[this.state.itemDragged],
561
+ props: {
562
+ ref: this.ghostRef,
563
+ style: ghostStyle,
564
+ onWheel: this.onWheel
565
+ },
566
+ index: this.state.itemDragged,
567
+ isDragged: true,
568
+ isSelected: false,
569
+ isDisabled: false,
570
+ isOutOfBounds: this.state.itemDraggedOutOfBounds > -1
571
+ }), this.props.container || document.body),
572
+ React.createElement("div", { "aria-live": "assertive", role: "log", "aria-atomic": "true", style: {
573
+ position: "absolute",
574
+ width: "1px",
575
+ height: "1px",
576
+ margin: "-1px",
577
+ border: "0px",
578
+ padding: "0px",
579
+ overflow: "hidden",
580
+ clip: "rect(0px, 0px, 0px, 0px)",
581
+ clipPath: "inset(100%)"
582
+ } }, this.state.liveText)
583
+ );
584
+ }
585
+ }
586
+ export {
587
+ List as L,
588
+ arrayRemove as a,
589
+ arrayMove as b
590
+ };