@jobber/hooks 2.17.4 → 2.18.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.
- package/dist/index.cjs +49 -0
- package/dist/index.mjs +23 -0
- package/dist/isObjectLike-cjs.js +228 -0
- package/dist/isObjectLike-es.js +219 -0
- package/dist/useBool/index.cjs +8 -0
- package/dist/useBool/index.mjs +2 -0
- package/dist/useBool-cjs.js +13 -0
- package/dist/useBool-es.js +11 -0
- package/dist/useBreakpoints/index.cjs +11 -0
- package/dist/useBreakpoints/index.mjs +3 -0
- package/dist/useBreakpoints/mockViewportWidth/{mockViewportWidth.js → index.cjs} +5 -4
- package/dist/useBreakpoints/mockViewportWidth/index.mjs +66 -0
- package/dist/useBreakpoints-cjs.js +48 -0
- package/dist/useBreakpoints-es.js +45 -0
- package/dist/useCallbackRef/index.cjs +8 -0
- package/dist/useCallbackRef/index.mjs +2 -0
- package/dist/useCallbackRef-cjs.js +17 -0
- package/dist/useCallbackRef-es.js +15 -0
- package/dist/useCollectionQuery/index.cjs +13 -0
- package/dist/useCollectionQuery/index.mjs +7 -0
- package/dist/useCollectionQuery/useCollectionQuery.d.ts +1 -1
- package/dist/useCollectionQuery-cjs.js +2842 -0
- package/dist/useCollectionQuery-es.js +2821 -0
- package/dist/useDebounce/index.cjs +9 -0
- package/dist/useDebounce/index.mjs +3 -0
- package/dist/useDebounce-cjs.js +92 -0
- package/dist/useDebounce-es.js +90 -0
- package/dist/useFocusTrap/index.cjs +8 -0
- package/dist/useFocusTrap/index.mjs +2 -0
- package/dist/{useFocusTrap/useFocusTrap.js → useFocusTrap-cjs.js} +8 -6
- package/dist/useFocusTrap-es.js +68 -0
- package/dist/useFormState/index.cjs +8 -0
- package/dist/useFormState/index.mjs +2 -0
- package/dist/useFormState-cjs.js +13 -0
- package/dist/useFormState-es.js +11 -0
- package/dist/useInView/index.cjs +8 -0
- package/dist/useInView/index.mjs +2 -0
- package/dist/{useInView/useInView.js → useInView-cjs.js} +10 -8
- package/dist/useInView-es.js +19 -0
- package/dist/useIsMounted/index.cjs +9 -0
- package/dist/useIsMounted/index.mjs +3 -0
- package/dist/{useIsMounted/useIsMounted.js → useIsMounted-cjs.js} +9 -7
- package/dist/useIsMounted-es.js +34 -0
- package/dist/useLiveAnnounce/index.cjs +8 -0
- package/dist/useLiveAnnounce/index.mjs +2 -0
- package/dist/{useLiveAnnounce/useLiveAnnounce.js → useLiveAnnounce-cjs.js} +8 -6
- package/dist/useLiveAnnounce-es.js +41 -0
- package/dist/useOnKeyDown/index.cjs +8 -0
- package/dist/useOnKeyDown/index.mjs +2 -0
- package/dist/{useOnKeyDown/useOnKeyDown.js → useOnKeyDown-cjs.js} +7 -5
- package/dist/useOnKeyDown-es.js +34 -0
- package/dist/useOnMount/index.cjs +9 -0
- package/dist/useOnMount/index.mjs +3 -0
- package/dist/{useOnMount/useOnMount.js → useOnMount-cjs.js} +9 -8
- package/dist/useOnMount-es.js +19 -0
- package/dist/useRefocusOnActivator/index.cjs +8 -0
- package/dist/useRefocusOnActivator/index.mjs +2 -0
- package/dist/{useRefocusOnActivator/useRefocusOnActivator.js → useRefocusOnActivator-cjs.js} +7 -5
- package/dist/useRefocusOnActivator-es.js +26 -0
- package/dist/useResizeObserver/index.cjs +10 -0
- package/dist/useResizeObserver/index.mjs +3 -0
- package/dist/useResizeObserver-cjs.js +1519 -0
- package/dist/useResizeObserver-es.js +1516 -0
- package/dist/useSafeLayoutEffect/index.cjs +8 -0
- package/dist/useSafeLayoutEffect/index.mjs +2 -0
- package/dist/useSafeLayoutEffect-cjs.js +9 -0
- package/dist/useSafeLayoutEffect-es.js +7 -0
- package/dist/useShowClear/{useShowClear.js → index.cjs} +4 -3
- package/dist/useShowClear/index.mjs +17 -0
- package/dist/useStepper/index.cjs +8 -0
- package/dist/useStepper/index.mjs +2 -0
- package/dist/{useStepper/useStepper.js → useStepper-cjs.js} +26 -14
- package/dist/useStepper-es.js +51 -0
- package/dist/useWindowDimensions/index.cjs +8 -0
- package/dist/useWindowDimensions/index.mjs +2 -0
- package/dist/{useWindowDimensions/useWindowDimensions.js → useWindowDimensions-cjs.js} +8 -6
- package/dist/useWindowDimensions-es.js +28 -0
- package/package.json +109 -7
- package/dist/index.js +0 -34
- package/dist/useBool/index.js +0 -5
- package/dist/useBool/useBool.js +0 -11
- package/dist/useBool/useBool.test.d.ts +0 -1
- package/dist/useBool/useBool.test.js +0 -28
- package/dist/useBreakpoints/index.js +0 -20
- package/dist/useBreakpoints/mockViewportWidth/index.js +0 -17
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.d.ts +0 -1
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.js +0 -17
- package/dist/useBreakpoints/useBreakpoints.js +0 -28
- package/dist/useBreakpoints/useBreakpoints.test.d.ts +0 -1
- package/dist/useBreakpoints/useBreakpoints.test.js +0 -142
- package/dist/useBreakpoints/useMediaQuery.js +0 -22
- package/dist/useCallbackRef/index.js +0 -5
- package/dist/useCallbackRef/useCallbackRef.js +0 -15
- package/dist/useCallbackRef/useCallbackRef.test.d.ts +0 -1
- package/dist/useCallbackRef/useCallbackRef.test.js +0 -29
- package/dist/useCollectionQuery/index.js +0 -5
- package/dist/useCollectionQuery/mdxUtils.js +0 -152
- package/dist/useCollectionQuery/test-utilities/index.d.ts +0 -3
- package/dist/useCollectionQuery/test-utilities/index.js +0 -19
- package/dist/useCollectionQuery/test-utilities/mocks.d.ts +0 -106
- package/dist/useCollectionQuery/test-utilities/mocks.js +0 -131
- package/dist/useCollectionQuery/test-utilities/queries.d.ts +0 -37
- package/dist/useCollectionQuery/test-utilities/queries.js +0 -59
- package/dist/useCollectionQuery/test-utilities/utils.d.ts +0 -1
- package/dist/useCollectionQuery/test-utilities/utils.js +0 -17
- package/dist/useCollectionQuery/uniqueEdges.js +0 -18
- package/dist/useCollectionQuery/uniqueNodes.js +0 -10
- package/dist/useCollectionQuery/useCollectionQuery.js +0 -194
- package/dist/useCollectionQuery/useCollectionQuery.test.d.ts +0 -1
- package/dist/useCollectionQuery/useCollectionQuery.test.js +0 -357
- package/dist/useDebounce/index.js +0 -5
- package/dist/useDebounce/useDebounce.js +0 -29
- package/dist/useDebounce/useDebounce.test.d.ts +0 -1
- package/dist/useDebounce/useDebounce.test.js +0 -190
- package/dist/useFocusTrap/index.js +0 -5
- package/dist/useFocusTrap/useFocusTrap.test.d.ts +0 -1
- package/dist/useFocusTrap/useFocusTrap.test.js +0 -61
- package/dist/useFormState/index.js +0 -5
- package/dist/useFormState/useFormState.js +0 -11
- package/dist/useInView/index.js +0 -17
- package/dist/useInView/useInView.test.d.ts +0 -1
- package/dist/useInView/useInView.test.js +0 -29
- package/dist/useIsMounted/index.js +0 -5
- package/dist/useIsMounted/useIsMounted.test.d.ts +0 -1
- package/dist/useIsMounted/useIsMounted.test.js +0 -15
- package/dist/useLiveAnnounce/index.js +0 -5
- package/dist/useLiveAnnounce/useLiveAnnounce.test.d.ts +0 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +0 -60
- package/dist/useOnKeyDown/index.js +0 -5
- package/dist/useOnKeyDown/useOnKeyDown.test.d.ts +0 -1
- package/dist/useOnKeyDown/useOnKeyDown.test.js +0 -23
- package/dist/useOnMount/index.js +0 -5
- package/dist/useOnMount/useOnMount.test.d.ts +0 -1
- package/dist/useOnMount/useOnMount.test.js +0 -18
- package/dist/useRefocusOnActivator/index.js +0 -5
- package/dist/useResizeObserver/index.js +0 -17
- package/dist/useResizeObserver/useResizeObserver.js +0 -68
- package/dist/useSafeLayoutEffect/index.js +0 -5
- package/dist/useSafeLayoutEffect/useSafeLayoutEffect.js +0 -7
- package/dist/useShowClear/index.js +0 -5
- package/dist/useShowClear/useShowClear.test.d.ts +0 -1
- package/dist/useShowClear/useShowClear.test.js +0 -210
- package/dist/useStepper/index.js +0 -5
- package/dist/useStepper/useStepper.test.d.ts +0 -1
- package/dist/useStepper/useStepper.test.js +0 -79
- package/dist/useWindowDimensions/index.js +0 -5
- package/dist/useWindowDimensions/useWIndowDimensions.test.d.ts +0 -1
- package/dist/useWindowDimensions/useWIndowDimensions.test.js +0 -23
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$1 = require('react');
|
|
4
|
+
var useCallbackRef = require('./useCallbackRef-cjs.js');
|
|
5
|
+
|
|
6
|
+
function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
7
|
+
let pendingThis = undefined;
|
|
8
|
+
let pendingArgs = null;
|
|
9
|
+
const leading = edges != null && edges.includes('leading');
|
|
10
|
+
const trailing = edges == null || edges.includes('trailing');
|
|
11
|
+
const invoke = () => {
|
|
12
|
+
if (pendingArgs !== null) {
|
|
13
|
+
func.apply(pendingThis, pendingArgs);
|
|
14
|
+
pendingThis = undefined;
|
|
15
|
+
pendingArgs = null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const onTimerEnd = () => {
|
|
19
|
+
if (trailing) {
|
|
20
|
+
invoke();
|
|
21
|
+
}
|
|
22
|
+
cancel();
|
|
23
|
+
};
|
|
24
|
+
let timeoutId = null;
|
|
25
|
+
const schedule = () => {
|
|
26
|
+
if (timeoutId != null) {
|
|
27
|
+
clearTimeout(timeoutId);
|
|
28
|
+
}
|
|
29
|
+
timeoutId = setTimeout(() => {
|
|
30
|
+
timeoutId = null;
|
|
31
|
+
onTimerEnd();
|
|
32
|
+
}, debounceMs);
|
|
33
|
+
};
|
|
34
|
+
const cancelTimer = () => {
|
|
35
|
+
if (timeoutId !== null) {
|
|
36
|
+
clearTimeout(timeoutId);
|
|
37
|
+
timeoutId = null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const cancel = () => {
|
|
41
|
+
cancelTimer();
|
|
42
|
+
pendingThis = undefined;
|
|
43
|
+
pendingArgs = null;
|
|
44
|
+
};
|
|
45
|
+
const flush = () => {
|
|
46
|
+
cancelTimer();
|
|
47
|
+
invoke();
|
|
48
|
+
};
|
|
49
|
+
const debounced = function (...args) {
|
|
50
|
+
if (signal?.aborted) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
pendingThis = this;
|
|
54
|
+
pendingArgs = args;
|
|
55
|
+
const isFirstCall = timeoutId == null;
|
|
56
|
+
schedule();
|
|
57
|
+
if (leading && isFirstCall) {
|
|
58
|
+
invoke();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
debounced.schedule = schedule;
|
|
62
|
+
debounced.cancel = cancel;
|
|
63
|
+
debounced.flush = flush;
|
|
64
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
65
|
+
return debounced;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A hook to easily manage debounced functions, including their cleanup.
|
|
70
|
+
* @param func The function to debounce.
|
|
71
|
+
* @param wait The number of milliseconds to delay.
|
|
72
|
+
* @param options Optional debounce settings.
|
|
73
|
+
* @returns The debounced function.
|
|
74
|
+
*/
|
|
75
|
+
function useDebounce(func, wait, options) {
|
|
76
|
+
const funcRef = useCallbackRef.useCallbackRef(func);
|
|
77
|
+
// Note: do not add additional dependencies! There is currently no use case where we would change
|
|
78
|
+
// the wait delay or options between renders. By not tracking as dependencies, this allows
|
|
79
|
+
// consumers of useDebounce to provide a raw object for options rather than forcing them to
|
|
80
|
+
// memoize that param. Same with the func they provide, we're using a ref to keep that up
|
|
81
|
+
// to date and to avoid forcing the consumer to memoize it.
|
|
82
|
+
const debounced = require$$1.useMemo(() => {
|
|
83
|
+
return debounce((...args) => funcRef(...args), wait, options);
|
|
84
|
+
}, [funcRef]);
|
|
85
|
+
require$$1.useEffect(() => {
|
|
86
|
+
// If the debounced function is recreated (or unmounted), cancel the last call.
|
|
87
|
+
return () => debounced.cancel();
|
|
88
|
+
}, [debounced]);
|
|
89
|
+
return debounced;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.useDebounce = useDebounce;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useMemo, useEffect } from 'react';
|
|
2
|
+
import { u as useCallbackRef } from './useCallbackRef-es.js';
|
|
3
|
+
|
|
4
|
+
function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
5
|
+
let pendingThis = undefined;
|
|
6
|
+
let pendingArgs = null;
|
|
7
|
+
const leading = edges != null && edges.includes('leading');
|
|
8
|
+
const trailing = edges == null || edges.includes('trailing');
|
|
9
|
+
const invoke = () => {
|
|
10
|
+
if (pendingArgs !== null) {
|
|
11
|
+
func.apply(pendingThis, pendingArgs);
|
|
12
|
+
pendingThis = undefined;
|
|
13
|
+
pendingArgs = null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const onTimerEnd = () => {
|
|
17
|
+
if (trailing) {
|
|
18
|
+
invoke();
|
|
19
|
+
}
|
|
20
|
+
cancel();
|
|
21
|
+
};
|
|
22
|
+
let timeoutId = null;
|
|
23
|
+
const schedule = () => {
|
|
24
|
+
if (timeoutId != null) {
|
|
25
|
+
clearTimeout(timeoutId);
|
|
26
|
+
}
|
|
27
|
+
timeoutId = setTimeout(() => {
|
|
28
|
+
timeoutId = null;
|
|
29
|
+
onTimerEnd();
|
|
30
|
+
}, debounceMs);
|
|
31
|
+
};
|
|
32
|
+
const cancelTimer = () => {
|
|
33
|
+
if (timeoutId !== null) {
|
|
34
|
+
clearTimeout(timeoutId);
|
|
35
|
+
timeoutId = null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const cancel = () => {
|
|
39
|
+
cancelTimer();
|
|
40
|
+
pendingThis = undefined;
|
|
41
|
+
pendingArgs = null;
|
|
42
|
+
};
|
|
43
|
+
const flush = () => {
|
|
44
|
+
cancelTimer();
|
|
45
|
+
invoke();
|
|
46
|
+
};
|
|
47
|
+
const debounced = function (...args) {
|
|
48
|
+
if (signal?.aborted) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
pendingThis = this;
|
|
52
|
+
pendingArgs = args;
|
|
53
|
+
const isFirstCall = timeoutId == null;
|
|
54
|
+
schedule();
|
|
55
|
+
if (leading && isFirstCall) {
|
|
56
|
+
invoke();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
debounced.schedule = schedule;
|
|
60
|
+
debounced.cancel = cancel;
|
|
61
|
+
debounced.flush = flush;
|
|
62
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
63
|
+
return debounced;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A hook to easily manage debounced functions, including their cleanup.
|
|
68
|
+
* @param func The function to debounce.
|
|
69
|
+
* @param wait The number of milliseconds to delay.
|
|
70
|
+
* @param options Optional debounce settings.
|
|
71
|
+
* @returns The debounced function.
|
|
72
|
+
*/
|
|
73
|
+
function useDebounce(func, wait, options) {
|
|
74
|
+
const funcRef = useCallbackRef(func);
|
|
75
|
+
// Note: do not add additional dependencies! There is currently no use case where we would change
|
|
76
|
+
// the wait delay or options between renders. By not tracking as dependencies, this allows
|
|
77
|
+
// consumers of useDebounce to provide a raw object for options rather than forcing them to
|
|
78
|
+
// memoize that param. Same with the func they provide, we're using a ref to keep that up
|
|
79
|
+
// to date and to avoid forcing the consumer to memoize it.
|
|
80
|
+
const debounced = useMemo(() => {
|
|
81
|
+
return debounce((...args) => funcRef(...args), wait, options);
|
|
82
|
+
}, [funcRef]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
// If the debounced function is recreated (or unmounted), cancel the last call.
|
|
85
|
+
return () => debounced.cancel();
|
|
86
|
+
}, [debounced]);
|
|
87
|
+
return debounced;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { useDebounce as u };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$1 = require('react');
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* Traps the focus within the children of the ref element.
|
|
7
7
|
*
|
|
@@ -14,7 +14,7 @@ function useFocusTrap(active) {
|
|
|
14
14
|
// There's an ongoing issue with useRef return type clashing with an element's
|
|
15
15
|
// ref prop type. TLDR: Use null because useRef doesn't expect undefined.
|
|
16
16
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/35572
|
|
17
|
-
const ref =
|
|
17
|
+
const ref = require$$1.useRef(null);
|
|
18
18
|
function handleKeyDown(event) {
|
|
19
19
|
if (!(active && ref.current) || event.key !== "Tab") {
|
|
20
20
|
return;
|
|
@@ -33,7 +33,7 @@ function useFocusTrap(active) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
require$$1.useEffect(() => {
|
|
37
37
|
if (active && ref.current) {
|
|
38
38
|
const { firstElement } = getElements(ref.current);
|
|
39
39
|
firstElement.focus();
|
|
@@ -66,3 +66,5 @@ function getElements(ref) {
|
|
|
66
66
|
const lastElement = elements[elements.length - 1];
|
|
67
67
|
return { firstElement, lastElement };
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
exports.useFocusTrap = useFocusTrap;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Traps the focus within the children of the ref element.
|
|
5
|
+
*
|
|
6
|
+
* @param active - Turns the focus trapping on or off. Also adds aria-hidden on the
|
|
7
|
+
* body but not the dialog.
|
|
8
|
+
*
|
|
9
|
+
* @returns ref
|
|
10
|
+
*/
|
|
11
|
+
function useFocusTrap(active) {
|
|
12
|
+
// There's an ongoing issue with useRef return type clashing with an element's
|
|
13
|
+
// ref prop type. TLDR: Use null because useRef doesn't expect undefined.
|
|
14
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/35572
|
|
15
|
+
const ref = useRef(null);
|
|
16
|
+
function handleKeyDown(event) {
|
|
17
|
+
if (!(active && ref.current) || event.key !== "Tab") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { firstElement, lastElement } = getElements(ref.current);
|
|
21
|
+
if (event.shiftKey) {
|
|
22
|
+
if (document.activeElement === firstElement) {
|
|
23
|
+
lastElement.focus();
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
if (document.activeElement === lastElement) {
|
|
29
|
+
firstElement.focus();
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (active && ref.current) {
|
|
36
|
+
const { firstElement } = getElements(ref.current);
|
|
37
|
+
firstElement.focus();
|
|
38
|
+
ref.current.addEventListener("keydown", handleKeyDown);
|
|
39
|
+
}
|
|
40
|
+
return () => {
|
|
41
|
+
var _a;
|
|
42
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("keydown", handleKeyDown);
|
|
43
|
+
};
|
|
44
|
+
}, [active]);
|
|
45
|
+
return ref;
|
|
46
|
+
}
|
|
47
|
+
function getElements(ref) {
|
|
48
|
+
const focusables = [
|
|
49
|
+
"button",
|
|
50
|
+
"[href]",
|
|
51
|
+
"input",
|
|
52
|
+
"select",
|
|
53
|
+
"textarea",
|
|
54
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
55
|
+
];
|
|
56
|
+
const elements = [
|
|
57
|
+
...ref.querySelectorAll(focusables.join(", ")),
|
|
58
|
+
];
|
|
59
|
+
// If the ref is focusable, ensure it's the first element to be focused.
|
|
60
|
+
if (ref.getAttribute("tabindex") === "0") {
|
|
61
|
+
elements.unshift(ref);
|
|
62
|
+
}
|
|
63
|
+
const firstElement = elements[0];
|
|
64
|
+
const lastElement = elements[elements.length - 1];
|
|
65
|
+
return { firstElement, lastElement };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { useFocusTrap as u };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$1 = require('react');
|
|
4
|
+
|
|
5
|
+
function useFormState() {
|
|
6
|
+
const [formState, setFormState] = require$$1.useState({
|
|
7
|
+
isDirty: false,
|
|
8
|
+
isValid: false,
|
|
9
|
+
});
|
|
10
|
+
return [formState, setFormState];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useFormState = useFormState;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$1 = require('react');
|
|
4
|
+
|
|
5
5
|
function useInView() {
|
|
6
|
-
const ref =
|
|
7
|
-
const [isInView, setIsInView] =
|
|
8
|
-
const handleIntersection =
|
|
9
|
-
|
|
6
|
+
const ref = require$$1.useRef(null);
|
|
7
|
+
const [isInView, setIsInView] = require$$1.useState(false);
|
|
8
|
+
const handleIntersection = require$$1.useCallback(entries => setIsInView(entries[0].isIntersecting), [setIsInView]);
|
|
9
|
+
require$$1.useEffect(() => {
|
|
10
10
|
if (!window.IntersectionObserver)
|
|
11
11
|
return;
|
|
12
12
|
const observer = new IntersectionObserver(handleIntersection);
|
|
@@ -17,3 +17,5 @@ function useInView() {
|
|
|
17
17
|
}, [handleIntersection, ref.current]);
|
|
18
18
|
return [ref, isInView];
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
exports.useInView = useInView;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useRef, useState, useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
function useInView() {
|
|
4
|
+
const ref = useRef(null);
|
|
5
|
+
const [isInView, setIsInView] = useState(false);
|
|
6
|
+
const handleIntersection = useCallback(entries => setIsInView(entries[0].isIntersecting), [setIsInView]);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!window.IntersectionObserver)
|
|
9
|
+
return;
|
|
10
|
+
const observer = new IntersectionObserver(handleIntersection);
|
|
11
|
+
ref.current && observer.observe(ref.current);
|
|
12
|
+
return () => {
|
|
13
|
+
ref.current && observer.unobserve(ref.current);
|
|
14
|
+
};
|
|
15
|
+
}, [handleIntersection, ref.current]);
|
|
16
|
+
return [ref, isInView];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { useInView as u };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$1 = require('react');
|
|
4
|
+
var useSafeLayoutEffect = require('./useSafeLayoutEffect-cjs.js');
|
|
5
|
+
|
|
6
6
|
/**
|
|
7
7
|
* If you are using this hook in order to only perform an action once after mounting (for example sending
|
|
8
8
|
* analytics events), use `useOnMount` instead
|
|
@@ -23,8 +23,8 @@ const useSafeLayoutEffect_1 = require("../useSafeLayoutEffect");
|
|
|
23
23
|
* This `useLayoutEffect` hook will only be run once.
|
|
24
24
|
*/
|
|
25
25
|
function useIsMounted() {
|
|
26
|
-
const isMounted =
|
|
27
|
-
|
|
26
|
+
const isMounted = require$$1.useRef(false);
|
|
27
|
+
useSafeLayoutEffect.useSafeLayoutEffect(() => {
|
|
28
28
|
isMounted.current = true;
|
|
29
29
|
return () => {
|
|
30
30
|
isMounted.current = false;
|
|
@@ -32,3 +32,5 @@ function useIsMounted() {
|
|
|
32
32
|
}, []);
|
|
33
33
|
return isMounted;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
exports.useIsMounted = useIsMounted;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { u as useSafeLayoutEffect } from './useSafeLayoutEffect-es.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* If you are using this hook in order to only perform an action once after mounting (for example sending
|
|
6
|
+
* analytics events), use `useOnMount` instead
|
|
7
|
+
*
|
|
8
|
+
* Why does this work?
|
|
9
|
+
*
|
|
10
|
+
* The following is from the react docs:
|
|
11
|
+
* [The return function from `useLayoutEffect`] is the optional cleanup mechanism for effects.
|
|
12
|
+
* Every effect may return a function that cleans up after it.
|
|
13
|
+
*
|
|
14
|
+
* When exactly does React clean up an effect? React performs the cleanup when the component unmounts.
|
|
15
|
+
* The cleanup for useLayoutEffect is called after component unmounts and before before browser painting
|
|
16
|
+
* the screen
|
|
17
|
+
*
|
|
18
|
+
* What does that mean for us? When this hook is initially loaded, we then trigger a `useLayoutEffect` that
|
|
19
|
+
* sets the isMounted to true right after the component is mounted.
|
|
20
|
+
* When the component unmounts, it calls the cleanup function that sets `isMounted` to false.
|
|
21
|
+
* This `useLayoutEffect` hook will only be run once.
|
|
22
|
+
*/
|
|
23
|
+
function useIsMounted() {
|
|
24
|
+
const isMounted = useRef(false);
|
|
25
|
+
useSafeLayoutEffect(() => {
|
|
26
|
+
isMounted.current = true;
|
|
27
|
+
return () => {
|
|
28
|
+
isMounted.current = false;
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
return isMounted;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { useIsMounted as u };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$1 = require('react');
|
|
4
|
+
|
|
5
5
|
/**
|
|
6
6
|
* Announce a message on voice over whenever you do an action. This is
|
|
7
7
|
* especially helpful when you have an action that adds or deletes an element
|
|
8
8
|
* from the screen.
|
|
9
9
|
*/
|
|
10
10
|
function useLiveAnnounce() {
|
|
11
|
-
const [announcedMessage, setAnnouncedMessage] =
|
|
12
|
-
|
|
11
|
+
const [announcedMessage, setAnnouncedMessage] = require$$1.useState("");
|
|
12
|
+
require$$1.useEffect(() => {
|
|
13
13
|
let target;
|
|
14
14
|
if (announcedMessage) {
|
|
15
15
|
target = createAnnouncedElement();
|
|
@@ -39,3 +39,5 @@ function createAnnouncedElement() {
|
|
|
39
39
|
document.body.appendChild(el);
|
|
40
40
|
return el;
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
exports.useLiveAnnounce = useLiveAnnounce;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Announce a message on voice over whenever you do an action. This is
|
|
5
|
+
* especially helpful when you have an action that adds or deletes an element
|
|
6
|
+
* from the screen.
|
|
7
|
+
*/
|
|
8
|
+
function useLiveAnnounce() {
|
|
9
|
+
const [announcedMessage, setAnnouncedMessage] = useState("");
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
let target;
|
|
12
|
+
if (announcedMessage) {
|
|
13
|
+
target = createAnnouncedElement();
|
|
14
|
+
setTimeout(() => target.append(announcedMessage), 100);
|
|
15
|
+
}
|
|
16
|
+
return () => target === null || target === void 0 ? void 0 : target.remove();
|
|
17
|
+
}, [announcedMessage]);
|
|
18
|
+
return {
|
|
19
|
+
liveAnnounce: (message) => {
|
|
20
|
+
setAnnouncedMessage(message);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// eslint-disable-next-line max-statements
|
|
25
|
+
function createAnnouncedElement() {
|
|
26
|
+
const el = document.createElement("div");
|
|
27
|
+
el.style.position = "absolute";
|
|
28
|
+
el.style.width = "1px";
|
|
29
|
+
el.style.height = "1px";
|
|
30
|
+
el.style.overflow = "hidden";
|
|
31
|
+
el.style.clipPath = " inset(100%)";
|
|
32
|
+
el.style.whiteSpace = " nowrap";
|
|
33
|
+
el.style.top = "0";
|
|
34
|
+
el.setAttribute("role", "status");
|
|
35
|
+
el.setAttribute("aria-atomic", "true");
|
|
36
|
+
el.setAttribute("aria-live", "assertive");
|
|
37
|
+
document.body.appendChild(el);
|
|
38
|
+
return el;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { useLiveAnnounce as u };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var require$$1 = require('react');
|
|
4
|
+
|
|
5
5
|
function useOnKeyDown(callback, keys) {
|
|
6
|
-
|
|
6
|
+
require$$1.useEffect(() => {
|
|
7
7
|
window.addEventListener("keydown", handler);
|
|
8
8
|
return () => {
|
|
9
9
|
window.removeEventListener("keydown", handler);
|
|
@@ -32,3 +32,5 @@ function useOnKeyDown(callback, keys) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
exports.useOnKeyDown = useOnKeyDown;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
function useOnKeyDown(callback, keys) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
window.addEventListener("keydown", handler);
|
|
6
|
+
return () => {
|
|
7
|
+
window.removeEventListener("keydown", handler);
|
|
8
|
+
};
|
|
9
|
+
}, [handler]);
|
|
10
|
+
function handler(event) {
|
|
11
|
+
const keyboardEvent = event;
|
|
12
|
+
if (typeof keys === "string" && keyboardEvent.key === keys) {
|
|
13
|
+
callback(event);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(keys) &&
|
|
17
|
+
keys.some(item => {
|
|
18
|
+
if (typeof item === "string")
|
|
19
|
+
return keyboardEvent.key === item;
|
|
20
|
+
return Object.keys(item).every(index => keyboardEvent[index] === item[index]);
|
|
21
|
+
})) {
|
|
22
|
+
callback(event);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!Array.isArray(keys) &&
|
|
26
|
+
typeof keys !== "string" &&
|
|
27
|
+
Object.keys(keys).every(index => keyboardEvent[index] === keys[index])) {
|
|
28
|
+
callback(event);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { useOnKeyDown as u };
|