@geneui/components 3.0.0-next-9ffcb93-16102024 → 3.0.0-next-48d0ef7-31102024

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 (248) hide show
  1. package/Avatar.js +63 -0
  2. package/CHANGELOG.md +7 -0
  3. package/Divider.js +23 -0
  4. package/{GeneUIProvider/index.js → GeneUIProvider.js} +52 -65
  5. package/HelperText.js +69 -0
  6. package/Info.js +64 -0
  7. package/Label.js +38 -0
  8. package/Loader.js +21 -0
  9. package/Pill.js +64 -0
  10. package/TextLink.js +20 -0
  11. package/{index-65217440.js → Tooltip.js} +104 -80
  12. package/{lib → components}/atoms/Avatar/Avatar.d.ts +7 -6
  13. package/components/atoms/Avatar/index.d.ts +1 -0
  14. package/{lib → components}/atoms/Divider/Divider.d.ts +5 -5
  15. package/components/atoms/Divider/index.d.ts +1 -0
  16. package/{lib → components}/atoms/HelperText/HelperText.d.ts +6 -5
  17. package/components/atoms/HelperText/index.d.ts +1 -0
  18. package/{lib → components}/atoms/Info/Info.d.ts +5 -5
  19. package/components/atoms/Info/index.d.ts +1 -0
  20. package/{lib → components}/atoms/Label/Label.d.ts +3 -3
  21. package/components/atoms/Label/index.d.ts +1 -0
  22. package/{lib → components}/atoms/Loader/Loader.d.ts +5 -5
  23. package/components/atoms/Loader/index.d.ts +1 -0
  24. package/{lib → components}/atoms/Pill/Pill.d.ts +7 -6
  25. package/components/atoms/Pill/index.d.ts +1 -0
  26. package/{lib → components}/atoms/TextLink/TextLink.d.ts +5 -5
  27. package/components/atoms/TextLink/index.d.ts +1 -0
  28. package/{lib → components}/molecules/Tooltip/Tooltip.d.ts +26 -21
  29. package/components/molecules/Tooltip/index.d.ts +1 -0
  30. package/components/providers/GeneUIProvider/GeneUIProvider.d.ts +30 -0
  31. package/components/providers/GeneUIProvider/index.d.ts +1 -0
  32. package/hooks/index.d.ts +2 -20
  33. package/hooks/useDebounceCallback/index.d.ts +1 -0
  34. package/hooks/useDebounceCallback/useDebounceCallback.d.ts +2 -0
  35. package/hooks/useEllipsisDetection/index.d.ts +1 -1
  36. package/hooks/useEllipsisDetection/useEllipsisDetection.d.ts +2 -2
  37. package/{index-031ff73c.js → index-ce02421b.js} +4 -4
  38. package/index.d.ts +11 -121
  39. package/index.js +12 -159
  40. package/package.json +24 -43
  41. package/tokens-0abb4e1b.js +6 -0
  42. package/types/index.d.ts +0 -3
  43. package/useEllipsisDetection-46d712b6.js +34 -0
  44. package/ActionableList/index.js +0 -1694
  45. package/AdvancedSearch/index.js +0 -892
  46. package/Alert/index.js +0 -98
  47. package/Avatar/index.js +0 -58
  48. package/Badge/index.js +0 -29
  49. package/Breadcrumb/index.js +0 -130
  50. package/BusyLoader/index.js +0 -31
  51. package/Button/index.js +0 -30
  52. package/Card/index.js +0 -502
  53. package/CardList/index.js +0 -662
  54. package/CellMeasurerCache-80be385d.js +0 -229
  55. package/Charts/index.js +0 -17662
  56. package/Checkbox/index.js +0 -229
  57. package/CheckboxGroup/index.js +0 -203
  58. package/CheckboxGroupWithSearch/index.js +0 -280
  59. package/Collapse/index.js +0 -195
  60. package/ColorPicker/index.js +0 -210
  61. package/ComboBox/index.js +0 -524
  62. package/Copy/index.js +0 -56
  63. package/Counter/index.js +0 -312
  64. package/DateFilter/index.js +0 -183
  65. package/DatePicker/index.js +0 -1229
  66. package/DatePickerInput/index.js +0 -883
  67. package/Divider/index.js +0 -23
  68. package/Drawer/index.js +0 -261
  69. package/Dropdown/index.js +0 -43
  70. package/Editor/index.js +0 -22975
  71. package/Empty/index.js +0 -76
  72. package/ExtendedInput/index.js +0 -590
  73. package/Form/index.js +0 -85
  74. package/FormContainer/index.js +0 -189
  75. package/FormableCheckbox/index.js +0 -24
  76. package/FormableDatePicker/index.js +0 -43
  77. package/FormableDropdown/index.js +0 -50
  78. package/FormableEditor/index.js +0 -26
  79. package/FormableHOC-85f89a81.js +0 -83
  80. package/FormableMultiSelectDropdown/index.js +0 -50
  81. package/FormableNumberInput/index.js +0 -34
  82. package/FormableRadio/index.js +0 -22
  83. package/FormableSwitcher/index.js +0 -22
  84. package/FormableTextInput/index.js +0 -34
  85. package/FormableUploader/index.js +0 -44
  86. package/Grid/index.js +0 -167
  87. package/HelperText/index.js +0 -86
  88. package/Holder/index.js +0 -261
  89. package/Icon/index.js +0 -62
  90. package/Image/index.js +0 -45
  91. package/ImagePreview/index.js +0 -217
  92. package/Info/index.js +0 -41
  93. package/InfoOutline-dd2e89d9.js +0 -29
  94. package/InteractiveWidget/index.js +0 -78
  95. package/KeyValue/index.js +0 -22
  96. package/Label/index.js +0 -48
  97. package/LinkButton/index.js +0 -34
  98. package/Loader/index.js +0 -23
  99. package/Menu/index.js +0 -281
  100. package/MobileNavigation/index.js +0 -94
  101. package/MobilePopup/index.js +0 -182
  102. package/Modal/index.js +0 -251
  103. package/ModuleTitle/index.js +0 -141
  104. package/NavigationMenu/index.js +0 -222
  105. package/Notification/index.js +0 -120
  106. package/Option/index.js +0 -184
  107. package/Overlay/index.js +0 -187
  108. package/Overspread/index.js +0 -291
  109. package/Pagination/index.js +0 -261
  110. package/Paper/index.js +0 -96
  111. package/Pill/index.js +0 -67
  112. package/Popover/index.js +0 -725
  113. package/PopoverV2/index.js +0 -19
  114. package/Portal/index.js +0 -58
  115. package/Products/index.js +0 -115
  116. package/Profile/index.js +0 -589
  117. package/Progress/index.js +0 -200
  118. package/QRCode/index.js +0 -814
  119. package/Radio/index.js +0 -151
  120. package/RadioGroup/index.js +0 -104
  121. package/Range/index.js +0 -191
  122. package/Rating/index.js +0 -174
  123. package/RichEditor/index.js +0 -13
  124. package/RichEditor-78c2617e.js +0 -228
  125. package/Scrollbar/index.js +0 -1585
  126. package/Search/index.js +0 -75
  127. package/SearchWithDropdown/index.js +0 -140
  128. package/Section/index.js +0 -61
  129. package/SkeletonLoader/index.js +0 -81
  130. package/Slider/index.js +0 -261
  131. package/Status/index.js +0 -97
  132. package/Steps/index.js +0 -314
  133. package/SuggestionList/index.js +0 -385
  134. package/Switcher/index.js +0 -193
  135. package/Table/index.js +0 -57
  136. package/TableCompositions/index.js +0 -16995
  137. package/Tabs/index.js +0 -235
  138. package/Tag/index.js +0 -102
  139. package/TextLink/index.js +0 -20
  140. package/Textarea/index.js +0 -242
  141. package/Time/index.js +0 -62
  142. package/TimePicker/index.js +0 -575
  143. package/Timeline/index.js +0 -113
  144. package/Title/index.js +0 -65
  145. package/Toaster/index.js +0 -116
  146. package/Tooltip/index.js +0 -6
  147. package/TransferList/index.js +0 -493
  148. package/Uploader/index.js +0 -992
  149. package/ValidatableCheckbox/index.js +0 -123
  150. package/ValidatableDatePicker/index.js +0 -316
  151. package/ValidatableDropdown/index.js +0 -141
  152. package/ValidatableElements/index.js +0 -67
  153. package/ValidatableMultiSelectDropdown/index.js +0 -152
  154. package/ValidatableNumberInput/index.js +0 -204
  155. package/ValidatableRadio/index.js +0 -116
  156. package/ValidatableSwitcher/index.js +0 -93
  157. package/ValidatableTextInput/index.js +0 -167
  158. package/ValidatableTimeInput/index.js +0 -174
  159. package/ValidatableUploader/index.js +0 -98
  160. package/Widget/index.js +0 -225
  161. package/_commonjsHelpers-24198af3.js +0 -35
  162. package/_rollupPluginBabelHelpers-a83240e1.js +0 -11
  163. package/callAfterDelay-7272faca.js +0 -12
  164. package/checkTimeValidation-e56771be.js +0 -16
  165. package/checkboxRadioSwitcher-5b69d7bd.js +0 -4
  166. package/clsx.m-2bb6df4b.js +0 -3
  167. package/config-1053d64d.js +0 -20
  168. package/configs-00612ce0.js +0 -103
  169. package/configs.js +0 -111
  170. package/dateValidation-67caec66.js +0 -225
  171. package/debounce-4419bc2f.js +0 -17
  172. package/guid-8ddf77b3.js +0 -16
  173. package/hooks/useBodyScroll.js +0 -16
  174. package/hooks/useClick.js +0 -18
  175. package/hooks/useClickOutside.js +0 -25
  176. package/hooks/useDebounce.js +0 -28
  177. package/hooks/useDeviceType.js +0 -17
  178. package/hooks/useDidMount.js +0 -15
  179. package/hooks/useForceUpdate.js +0 -8
  180. package/hooks/useHover.js +0 -20
  181. package/hooks/useImgDownload.js +0 -18
  182. package/hooks/useKeyDown.js +0 -21
  183. package/hooks/useMount.js +0 -13
  184. package/hooks/useMutationObserver.js +0 -21
  185. package/hooks/usePrevious.js +0 -10
  186. package/hooks/useThrottle.js +0 -16
  187. package/hooks/useToggle.js +0 -11
  188. package/hooks/useUpdatableRef.js +0 -14
  189. package/hooks/useUpdate.js +0 -10
  190. package/hooks/useWidth.js +0 -16
  191. package/hooks/useWindowSize.js +0 -40
  192. package/index-122432cd.js +0 -270
  193. package/index-262edd7a.js +0 -77
  194. package/index-2f5aa51e.js +0 -6483
  195. package/index-370f9acd.js +0 -4
  196. package/index-45eafea6.js +0 -90
  197. package/index-480fd7d9.js +0 -10032
  198. package/index-5f37f281.js +0 -168
  199. package/index-73aaa093.js +0 -1940
  200. package/index.mobile.d.ts +0 -14
  201. package/lib/atoms/Avatar/index.d.ts +0 -1
  202. package/lib/atoms/Badge/Badge.d.ts +0 -36
  203. package/lib/atoms/Badge/index.d.ts +0 -1
  204. package/lib/atoms/BusyLoader/BusyLoader.d.ts +0 -32
  205. package/lib/atoms/BusyLoader/BusyLoaderHolderHOC.d.ts +0 -8
  206. package/lib/atoms/BusyLoader/index.d.ts +0 -1
  207. package/lib/atoms/Button/Button.d.ts +0 -70
  208. package/lib/atoms/Button/index.d.ts +0 -1
  209. package/lib/atoms/Divider/index.d.ts +0 -1
  210. package/lib/atoms/Empty/Empty.d.ts +0 -39
  211. package/lib/atoms/Empty/index.d.ts +0 -1
  212. package/lib/atoms/Empty/utils.d.ts +0 -9
  213. package/lib/atoms/HelperText/index.d.ts +0 -1
  214. package/lib/atoms/Image/Image.d.ts +0 -51
  215. package/lib/atoms/Image/index.d.ts +0 -1
  216. package/lib/atoms/ImagePreview/ImagePreview.d.ts +0 -56
  217. package/lib/atoms/ImagePreview/ImagePreviewHOC.d.ts +0 -4
  218. package/lib/atoms/ImagePreview/Magnifier.d.ts +0 -40
  219. package/lib/atoms/ImagePreview/index.d.ts +0 -1
  220. package/lib/atoms/Info/index.d.ts +0 -1
  221. package/lib/atoms/KeyValue/KeyValue.d.ts +0 -29
  222. package/lib/atoms/KeyValue/index.d.ts +0 -1
  223. package/lib/atoms/Label/index.d.ts +0 -1
  224. package/lib/atoms/LinkButton/LinkButton.d.ts +0 -46
  225. package/lib/atoms/LinkButton/index.d.ts +0 -1
  226. package/lib/atoms/Loader/index.d.ts +0 -1
  227. package/lib/atoms/Pill/index.d.ts +0 -1
  228. package/lib/atoms/Rating/DefaultSvg.d.ts +0 -3
  229. package/lib/atoms/Rating/Rating.d.ts +0 -49
  230. package/lib/atoms/Rating/index.d.ts +0 -1
  231. package/lib/atoms/TextLink/index.d.ts +0 -1
  232. package/lib/molecules/Copy/Copy.d.ts +0 -38
  233. package/lib/molecules/Copy/index.d.ts +0 -1
  234. package/lib/molecules/InteractiveWidget/InteractiveWidget.d.ts +0 -70
  235. package/lib/molecules/InteractiveWidget/InteractiveWidgetIcon.d.ts +0 -8
  236. package/lib/molecules/InteractiveWidget/index.d.ts +0 -1
  237. package/lib/molecules/Tooltip/index.d.ts +0 -1
  238. package/lib/providers/GeneUIProvider/GeneUIProvider.d.ts +0 -30
  239. package/lib/providers/GeneUIProvider/index.d.ts +0 -1
  240. package/localization-4ba17032.js +0 -46
  241. package/objectWithoutPropertiesLoose-e1596bdb.js +0 -62
  242. package/rangeAndSlider-693a3d41.js +0 -8684
  243. package/react-beautiful-dnd.esm-b637016a.js +0 -10116
  244. package/react-lifecycles-compat.es-6e1f3768.js +0 -158
  245. package/redux-e591c1b8.js +0 -536
  246. package/tokens-8ab1179c.js +0 -6
  247. package/tslib.es6-f211516f.js +0 -35
  248. package/useEllipsisDetection-c1c9ad94.js +0 -38
@@ -1,25 +0,0 @@
1
- import { useRef, useCallback, useEffect } from 'react';
2
-
3
- function useClickOutside(callback, relativeElements) {
4
- const ref = useRef();
5
- const handleClickOutside = useCallback(e => {
6
- var _ref$current;
7
- const {
8
- target
9
- } = e;
10
- const isNotRelativeTarget = Array.isArray(relativeElements) && relativeElements.length ? relativeElements === null || relativeElements === void 0 ? void 0 : relativeElements.find(relativeRef => {
11
- var _relativeRef$current;
12
- return !((_relativeRef$current = relativeRef.current) !== null && _relativeRef$current !== void 0 && _relativeRef$current.contains(target));
13
- }) : true;
14
- if (ref.current && !((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contains(target)) && isNotRelativeTarget) {
15
- callback && callback(e);
16
- }
17
- }, [ref.current, callback, relativeElements]);
18
- useEffect(() => {
19
- document.addEventListener('mousedown', handleClickOutside);
20
- return () => document.removeEventListener('mousedown', handleClickOutside);
21
- }, [handleClickOutside]);
22
- return node => ref.current = node;
23
- }
24
-
25
- export { useClickOutside as default };
@@ -1,28 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- const useDebounce = (value, delay) => {
4
- if (value === undefined) {
5
- let timeoutId;
6
- const debounceCallback = (value, delay) => {
7
- clearTimeout(timeoutId);
8
- timeoutId = setTimeout(value, delay);
9
- };
10
- const clearDebounce = () => clearTimeout(timeoutId);
11
- return {
12
- debounceCallback,
13
- clearDebounce
14
- };
15
- }
16
- const [debouncedValue, setDebouncedValue] = useState(value);
17
- useEffect(() => {
18
- const handler = setTimeout(() => {
19
- setDebouncedValue(value);
20
- }, delay);
21
- return () => {
22
- clearTimeout(handler);
23
- };
24
- }, [delay, value]);
25
- return debouncedValue;
26
- };
27
-
28
- export { useDebounce as default };
@@ -1,17 +0,0 @@
1
- import { a as clientConfigs, m as mobileScreenSize } from '../configs-00612ce0.js';
2
- import useWindowSize from './useWindowSize.js';
3
- import 'react';
4
- import './useDebounce.js';
5
-
6
- function useDeviceType(screenType) {
7
- const {
8
- width
9
- } = useWindowSize();
10
- const type = screenType || (clientConfigs.isMobile ? clientConfigs.isMobile() ? 'mobile' : 'desktop' : width < mobileScreenSize ? 'mobile' : 'desktop');
11
- return {
12
- type,
13
- isMobile: type === 'mobile'
14
- };
15
- }
16
-
17
- export { useDeviceType as default };
@@ -1,15 +0,0 @@
1
- import { useRef, useEffect } from 'react';
2
-
3
- const useDidMount = function () {
4
- let callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : () => {};
5
- let deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
6
- const _isFirstUpdate = useRef(true);
7
- useEffect(() => {
8
- if (!_isFirstUpdate.current) {
9
- callback();
10
- }
11
- _isFirstUpdate.current = false;
12
- }, deps);
13
- };
14
-
15
- export { useDidMount as default };
@@ -1,8 +0,0 @@
1
- import { useReducer } from 'react';
2
-
3
- const useForceUpdate = () => {
4
- const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
5
- return forceUpdate;
6
- };
7
-
8
- export { useForceUpdate as default };
package/hooks/useHover.js DELETED
@@ -1,20 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- const useHover = ref => {
4
- const [isHovered, setIsHovered] = useState(false);
5
- const handleMouseEnter = () => setIsHovered(true);
6
- const handleMouseLeave = () => setIsHovered(false);
7
- useEffect(() => {
8
- const node = ref.current;
9
- if (!node) return;
10
- node.addEventListener('mouseenter', handleMouseEnter);
11
- node.addEventListener('mouseleave', handleMouseLeave);
12
- return () => {
13
- node.removeEventListener('mouseenter', handleMouseEnter);
14
- node.removeEventListener('mouseleave', handleMouseLeave);
15
- };
16
- }, [ref]);
17
- return isHovered;
18
- };
19
-
20
- export { useHover as default };
@@ -1,18 +0,0 @@
1
- import { useCallback } from 'react';
2
-
3
- const useImgDownload = () => useCallback(function (url, name) {
4
- let customHeaders = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5
- fetch(url, {
6
- headers: {
7
- ...customHeaders
8
- }
9
- }).then(response => response.blob()).then(blob => {
10
- const blobURL = URL.createObjectURL(blob);
11
- const a = document.createElement('a');
12
- a.href = blobURL;
13
- a.download = name && name.length ? name : 'download';
14
- a.click();
15
- }).catch(error => console.log(error));
16
- }, []);
17
-
18
- export { useImgDownload as default };
@@ -1,21 +0,0 @@
1
- import { useCallback, useEffect } from 'react';
2
-
3
- const useKeyDown = function (callback, deps, ref) {
4
- let keys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
5
- const handleKeyDown = useCallback(e => {
6
- if (!keys.length || keys.includes(e.key)) {
7
- callback(e);
8
- }
9
- }, [...keys, ...deps]);
10
- useEffect(() => {
11
- if (ref && ref.current) {
12
- ref.current.addEventListener('keydown', handleKeyDown);
13
- return () => {
14
- var _ref$current;
15
- return ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.removeEventListener('keydown', handleKeyDown);
16
- };
17
- }
18
- }, [handleKeyDown, ref.current]);
19
- };
20
-
21
- export { useKeyDown as default };
package/hooks/useMount.js DELETED
@@ -1,13 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { n as noop } from '../index-5f37f281.js';
3
- import 'prop-types';
4
- import '../dateValidation-67caec66.js';
5
- import '../_commonjsHelpers-24198af3.js';
6
- import 'react-dom';
7
-
8
- const useMount = function () {
9
- let onMount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop;
10
- return useEffect(onMount, []);
11
- };
12
-
13
- export { useMount as default };
@@ -1,21 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- const defaultOptions = {
4
- attributes: true,
5
- childList: true,
6
- subtree: true
7
- };
8
- const useMutationObserver = function (ref, callback) {
9
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultOptions;
10
- useEffect(() => {
11
- if (ref.current) {
12
- const observer = new MutationObserver(callback);
13
- observer.observe(ref.current, options);
14
- return () => {
15
- observer.disconnect();
16
- };
17
- }
18
- }, [callback, options]);
19
- };
20
-
21
- export { useMutationObserver as default };
@@ -1,10 +0,0 @@
1
- import { useRef, useMemo } from 'react';
2
-
3
- const usePrevious = (callback, deps) => {
4
- const previous = useRef();
5
- const value = useMemo(() => callback(previous.current), deps);
6
- previous.current = value;
7
- return value;
8
- };
9
-
10
- export { usePrevious as default };
@@ -1,16 +0,0 @@
1
- import { useRef, useCallback } from 'react';
2
-
3
- const useThrottle = (callback, delay) => {
4
- const ref = useRef(null);
5
- return useCallback(function () {
6
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7
- args[_key] = arguments[_key];
8
- }
9
- clearTimeout(ref.current);
10
- ref.current = setTimeout(() => {
11
- callback(...args);
12
- }, delay);
13
- }, [callback, delay]);
14
- };
15
-
16
- export { useThrottle as default };
@@ -1,11 +0,0 @@
1
- import { useState, useCallback } from 'react';
2
-
3
- function useToggle(defaultValue) {
4
- const [state, setState] = useState(!!defaultValue);
5
- const toggle = useCallback(value => {
6
- setState(prev => typeof value === 'undefined' ? !prev : !!value);
7
- }, []);
8
- return [state, toggle];
9
- }
10
-
11
- export { useToggle as default };
@@ -1,14 +0,0 @@
1
- import { useRef, useCallback } from 'react';
2
- import useForceUpdate from './useForceUpdate.js';
3
-
4
- const useUpdatableRef = initial => {
5
- const ref = useRef(initial);
6
- const forceUpdate = useForceUpdate();
7
- const update = useCallback(value => {
8
- if (ref.current !== value) forceUpdate();
9
- ref.current = value;
10
- }, []);
11
- return [ref, update];
12
- };
13
-
14
- export { useUpdatableRef as default };
@@ -1,10 +0,0 @@
1
- import { useRef, useEffect } from 'react';
2
-
3
- function useUpdate(callback, dependencies) {
4
- const initial = useRef(true);
5
- useEffect(initial.current ? () => {
6
- initial.current = false;
7
- } : callback, dependencies);
8
- }
9
-
10
- export { useUpdate as default };
package/hooks/useWidth.js DELETED
@@ -1,16 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import useWindowSize from './useWindowSize.js';
3
- import './useDebounce.js';
4
-
5
- function useWidth(ref) {
6
- const [width, setWidth] = useState(null);
7
- const {
8
- width: windowWidth
9
- } = useWindowSize();
10
- useEffect(() => {
11
- setWidth(ref.current.clientWidth);
12
- }, [ref.current, windowWidth]);
13
- return width;
14
- }
15
-
16
- export { useWidth as default };
@@ -1,40 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import useDebounce from './useDebounce.js';
3
-
4
- function useWindowSize() {
5
- const w = window;
6
- const {
7
- innerHeight,
8
- innerWidth
9
- } = w;
10
- const [width, setWindowWidth] = useState(innerWidth);
11
- const [height, setWindowHeight] = useState(innerHeight);
12
- const {
13
- debounceCallback,
14
- clearDebounce
15
- } = useDebounce();
16
- const handleResize = () => {
17
- const {
18
- innerHeight,
19
- innerWidth
20
- } = w;
21
- setWindowWidth(innerWidth);
22
- setWindowHeight(innerHeight);
23
- };
24
- const debounce = () => debounceCallback(handleResize, 100);
25
- useEffect(() => {
26
- w.addEventListener('resize', debounce);
27
- w.addEventListener('orientationChange', debounce);
28
- return () => {
29
- w.removeEventListener('resize', debounce);
30
- w.removeEventListener('orientationChange', debounce);
31
- clearDebounce();
32
- };
33
- }, []);
34
- return {
35
- width,
36
- height
37
- };
38
- }
39
-
40
- export { useWindowSize as default };
package/index-122432cd.js DELETED
@@ -1,270 +0,0 @@
1
- import * as React from 'react';
2
-
3
- const LEFT = "Left";
4
- const RIGHT = "Right";
5
- const UP = "Up";
6
- const DOWN = "Down";
7
-
8
- /* global document */
9
- const defaultProps = {
10
- delta: 10,
11
- preventScrollOnSwipe: false,
12
- rotationAngle: 0,
13
- trackMouse: false,
14
- trackTouch: true,
15
- swipeDuration: Infinity,
16
- touchEventOptions: { passive: true },
17
- };
18
- const initialState = {
19
- first: true,
20
- initial: [0, 0],
21
- start: 0,
22
- swiping: false,
23
- xy: [0, 0],
24
- };
25
- const mouseMove = "mousemove";
26
- const mouseUp = "mouseup";
27
- const touchEnd = "touchend";
28
- const touchMove = "touchmove";
29
- const touchStart = "touchstart";
30
- function getDirection(absX, absY, deltaX, deltaY) {
31
- if (absX > absY) {
32
- if (deltaX > 0) {
33
- return RIGHT;
34
- }
35
- return LEFT;
36
- }
37
- else if (deltaY > 0) {
38
- return DOWN;
39
- }
40
- return UP;
41
- }
42
- function rotateXYByAngle(pos, angle) {
43
- if (angle === 0)
44
- return pos;
45
- const angleInRadians = (Math.PI / 180) * angle;
46
- const x = pos[0] * Math.cos(angleInRadians) + pos[1] * Math.sin(angleInRadians);
47
- const y = pos[1] * Math.cos(angleInRadians) - pos[0] * Math.sin(angleInRadians);
48
- return [x, y];
49
- }
50
- function getHandlers(set, handlerProps) {
51
- const onStart = (event) => {
52
- const isTouch = "touches" in event;
53
- // if more than a single touch don't track, for now...
54
- if (isTouch && event.touches.length > 1)
55
- return;
56
- set((state, props) => {
57
- // setup mouse listeners on document to track swipe since swipe can leave container
58
- if (props.trackMouse && !isTouch) {
59
- document.addEventListener(mouseMove, onMove);
60
- document.addEventListener(mouseUp, onUp);
61
- }
62
- const { clientX, clientY } = isTouch ? event.touches[0] : event;
63
- const xy = rotateXYByAngle([clientX, clientY], props.rotationAngle);
64
- props.onTouchStartOrOnMouseDown &&
65
- props.onTouchStartOrOnMouseDown({ event });
66
- return Object.assign(Object.assign(Object.assign({}, state), initialState), { initial: xy.slice(), xy, start: event.timeStamp || 0 });
67
- });
68
- };
69
- const onMove = (event) => {
70
- set((state, props) => {
71
- const isTouch = "touches" in event;
72
- // Discount a swipe if additional touches are present after
73
- // a swipe has started.
74
- if (isTouch && event.touches.length > 1) {
75
- return state;
76
- }
77
- // if swipe has exceeded duration stop tracking
78
- if (event.timeStamp - state.start > props.swipeDuration) {
79
- return state.swiping ? Object.assign(Object.assign({}, state), { swiping: false }) : state;
80
- }
81
- const { clientX, clientY } = isTouch ? event.touches[0] : event;
82
- const [x, y] = rotateXYByAngle([clientX, clientY], props.rotationAngle);
83
- const deltaX = x - state.xy[0];
84
- const deltaY = y - state.xy[1];
85
- const absX = Math.abs(deltaX);
86
- const absY = Math.abs(deltaY);
87
- const time = (event.timeStamp || 0) - state.start;
88
- const velocity = Math.sqrt(absX * absX + absY * absY) / (time || 1);
89
- const vxvy = [deltaX / (time || 1), deltaY / (time || 1)];
90
- const dir = getDirection(absX, absY, deltaX, deltaY);
91
- // if swipe is under delta and we have not started to track a swipe: skip update
92
- const delta = typeof props.delta === "number"
93
- ? props.delta
94
- : props.delta[dir.toLowerCase()] ||
95
- defaultProps.delta;
96
- if (absX < delta && absY < delta && !state.swiping)
97
- return state;
98
- const eventData = {
99
- absX,
100
- absY,
101
- deltaX,
102
- deltaY,
103
- dir,
104
- event,
105
- first: state.first,
106
- initial: state.initial,
107
- velocity,
108
- vxvy,
109
- };
110
- // call onSwipeStart if present and is first swipe event
111
- eventData.first && props.onSwipeStart && props.onSwipeStart(eventData);
112
- // call onSwiping if present
113
- props.onSwiping && props.onSwiping(eventData);
114
- // track if a swipe is cancelable (handler for swiping or swiped(dir) exists)
115
- // so we can call preventDefault if needed
116
- let cancelablePageSwipe = false;
117
- if (props.onSwiping ||
118
- props.onSwiped ||
119
- props[`onSwiped${dir}`]) {
120
- cancelablePageSwipe = true;
121
- }
122
- if (cancelablePageSwipe &&
123
- props.preventScrollOnSwipe &&
124
- props.trackTouch &&
125
- event.cancelable) {
126
- event.preventDefault();
127
- }
128
- return Object.assign(Object.assign({}, state), {
129
- // first is now always false
130
- first: false, eventData, swiping: true });
131
- });
132
- };
133
- const onEnd = (event) => {
134
- set((state, props) => {
135
- let eventData;
136
- if (state.swiping && state.eventData) {
137
- // if swipe is less than duration fire swiped callbacks
138
- if (event.timeStamp - state.start < props.swipeDuration) {
139
- eventData = Object.assign(Object.assign({}, state.eventData), { event });
140
- props.onSwiped && props.onSwiped(eventData);
141
- const onSwipedDir = props[`onSwiped${eventData.dir}`];
142
- onSwipedDir && onSwipedDir(eventData);
143
- }
144
- }
145
- else {
146
- props.onTap && props.onTap({ event });
147
- }
148
- props.onTouchEndOrOnMouseUp && props.onTouchEndOrOnMouseUp({ event });
149
- return Object.assign(Object.assign(Object.assign({}, state), initialState), { eventData });
150
- });
151
- };
152
- const cleanUpMouse = () => {
153
- // safe to just call removeEventListener
154
- document.removeEventListener(mouseMove, onMove);
155
- document.removeEventListener(mouseUp, onUp);
156
- };
157
- const onUp = (e) => {
158
- cleanUpMouse();
159
- onEnd(e);
160
- };
161
- /**
162
- * The value of passive on touchMove depends on `preventScrollOnSwipe`:
163
- * - true => { passive: false }
164
- * - false => { passive: true } // Default
165
- *
166
- * NOTE: When preventScrollOnSwipe is true, we attempt to call preventDefault to prevent scroll.
167
- *
168
- * props.touchEventOptions can also be set for all touch event listeners,
169
- * but for `touchmove` specifically when `preventScrollOnSwipe` it will
170
- * supersede and force passive to false.
171
- *
172
- */
173
- const attachTouch = (el, props) => {
174
- let cleanup = () => { };
175
- if (el && el.addEventListener) {
176
- const baseOptions = Object.assign(Object.assign({}, defaultProps.touchEventOptions), props.touchEventOptions);
177
- // attach touch event listeners and handlers
178
- const tls = [
179
- [touchStart, onStart, baseOptions],
180
- // preventScrollOnSwipe option supersedes touchEventOptions.passive
181
- [
182
- touchMove,
183
- onMove,
184
- Object.assign(Object.assign({}, baseOptions), (props.preventScrollOnSwipe ? { passive: false } : {})),
185
- ],
186
- [touchEnd, onEnd, baseOptions],
187
- ];
188
- tls.forEach(([e, h, o]) => el.addEventListener(e, h, o));
189
- // return properly scoped cleanup method for removing listeners, options not required
190
- cleanup = () => tls.forEach(([e, h]) => el.removeEventListener(e, h));
191
- }
192
- return cleanup;
193
- };
194
- const onRef = (el) => {
195
- // "inline" ref functions are called twice on render, once with null then again with DOM element
196
- // ignore null here
197
- if (el === null)
198
- return;
199
- set((state, props) => {
200
- // if the same DOM el as previous just return state
201
- if (state.el === el)
202
- return state;
203
- const addState = {};
204
- // if new DOM el clean up old DOM and reset cleanUpTouch
205
- if (state.el && state.el !== el && state.cleanUpTouch) {
206
- state.cleanUpTouch();
207
- addState.cleanUpTouch = void 0;
208
- }
209
- // only attach if we want to track touch
210
- if (props.trackTouch && el) {
211
- addState.cleanUpTouch = attachTouch(el, props);
212
- }
213
- // store event attached DOM el for comparison, clean up, and re-attachment
214
- return Object.assign(Object.assign(Object.assign({}, state), { el }), addState);
215
- });
216
- };
217
- // set ref callback to attach touch event listeners
218
- const output = {
219
- ref: onRef,
220
- };
221
- // if track mouse attach mouse down listener
222
- if (handlerProps.trackMouse) {
223
- output.onMouseDown = onStart;
224
- }
225
- return [output, attachTouch];
226
- }
227
- function updateTransientState(state, props, previousProps, attachTouch) {
228
- // if trackTouch is off or there is no el, then remove handlers if necessary and exit
229
- if (!props.trackTouch || !state.el) {
230
- if (state.cleanUpTouch) {
231
- state.cleanUpTouch();
232
- }
233
- return Object.assign(Object.assign({}, state), { cleanUpTouch: undefined });
234
- }
235
- // trackTouch is on, so if there are no handlers attached, attach them and exit
236
- if (!state.cleanUpTouch) {
237
- return Object.assign(Object.assign({}, state), { cleanUpTouch: attachTouch(state.el, props) });
238
- }
239
- // trackTouch is on and handlers are already attached, so if preventScrollOnSwipe changes value,
240
- // remove and reattach handlers (this is required to update the passive option when attaching
241
- // the handlers)
242
- if (props.preventScrollOnSwipe !== previousProps.preventScrollOnSwipe ||
243
- props.touchEventOptions.passive !== previousProps.touchEventOptions.passive) {
244
- state.cleanUpTouch();
245
- return Object.assign(Object.assign({}, state), { cleanUpTouch: attachTouch(state.el, props) });
246
- }
247
- return state;
248
- }
249
- function useSwipeable(options) {
250
- const { trackMouse } = options;
251
- const transientState = React.useRef(Object.assign({}, initialState));
252
- const transientProps = React.useRef(Object.assign({}, defaultProps));
253
- // track previous rendered props
254
- const previousProps = React.useRef(Object.assign({}, transientProps.current));
255
- previousProps.current = Object.assign({}, transientProps.current);
256
- // update current render props & defaults
257
- transientProps.current = Object.assign(Object.assign({}, defaultProps), options);
258
- // Force defaults for config properties
259
- let defaultKey;
260
- for (defaultKey in defaultProps) {
261
- if (transientProps.current[defaultKey] === void 0) {
262
- transientProps.current[defaultKey] = defaultProps[defaultKey];
263
- }
264
- }
265
- const [handlers, attachTouch] = React.useMemo(() => getHandlers((stateSetter) => (transientState.current = stateSetter(transientState.current, transientProps.current)), { trackMouse }), [trackMouse]);
266
- transientState.current = updateTransientState(transientState.current, transientProps.current, previousProps.current, attachTouch);
267
- return handlers;
268
- }
269
-
270
- export { useSwipeable as u };
package/index-262edd7a.js DELETED
@@ -1,77 +0,0 @@
1
- import React__default, { useContext, useReducer, useState, useCallback, useMemo, createContext } from 'react';
2
-
3
- const Context = /*#__PURE__*/createContext();
4
- const useFormContext = () => useContext(Context);
5
- const reducer = (state, _ref) => {
6
- let {
7
- type,
8
- field
9
- } = _ref;
10
- switch (type) {
11
- case 'add':
12
- return [...state, field];
13
- case 'validation':
14
- return state.map(item => ({
15
- ...item,
16
- isValid: field.name === item.name ? field.isValid : item.isValid
17
- }));
18
- case 'change':
19
- return state.map(item => ({
20
- ...item,
21
- isChanged: field.name === item.name ? field.isChanged : item.isChanged
22
- }));
23
- case 'unmount':
24
- return state.filter(item => field.name !== item.name);
25
- default:
26
- return state;
27
- }
28
- };
29
- function FormProvider(_ref2) {
30
- let {
31
- value,
32
- children
33
- } = _ref2;
34
- const [fields, dispatch] = useReducer(reducer, []);
35
- const [readOnlyState, setReadOnly] = useState(value.readOnly);
36
- const [allowValidation, setAllowValidation] = useState(false);
37
-
38
- // handle field `isChanged` prop when value changes
39
- const handleFieldChange = useCallback(field => dispatch({
40
- type: 'change',
41
- field
42
- }), []);
43
-
44
- // add field to store when mounted
45
- const handleFieldMount = useCallback(field => dispatch({
46
- type: 'add',
47
- field
48
- }), []);
49
-
50
- // remove field when unmounted
51
- const handleFieldUnMount = useCallback(field => dispatch({
52
- type: 'unmount',
53
- field
54
- }), []);
55
-
56
- // handle field `isValid` prop when validation changes
57
- const handleValidationChange = useCallback(field => dispatch({
58
- type: 'validation',
59
- field
60
- }), []);
61
- const contextProps = useMemo(() => ({
62
- fields,
63
- setReadOnly,
64
- readOnlyState,
65
- allowValidation,
66
- handleFieldMount,
67
- handleFieldUnMount,
68
- handleFieldChange,
69
- setAllowValidation,
70
- handleValidationChange
71
- }), [fields, readOnlyState, allowValidation]);
72
- return /*#__PURE__*/React__default.createElement(Context.Provider, {
73
- value: contextProps
74
- }, children);
75
- }
76
-
77
- export { FormProvider as F, useFormContext as u };