@mantine/hooks 7.0.0-alpha.9 → 7.0.0-beta.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.
- package/cjs/use-callback-ref/use-callback-ref.js +8 -5
- package/cjs/use-callback-ref/use-callback-ref.js.map +1 -1
- package/cjs/use-click-outside/use-click-outside.js +19 -21
- package/cjs/use-click-outside/use-click-outside.js.map +1 -1
- package/cjs/use-clipboard/use-clipboard.js +22 -26
- package/cjs/use-clipboard/use-clipboard.js.map +1 -1
- package/cjs/use-color-scheme/use-color-scheme.js +1 -3
- package/cjs/use-color-scheme/use-color-scheme.js.map +1 -1
- package/cjs/use-counter/use-counter.js +25 -9
- package/cjs/use-counter/use-counter.js.map +1 -1
- package/cjs/use-debounced-callback/use-debounced-callback.js +7 -7
- package/cjs/use-debounced-callback/use-debounced-callback.js.map +1 -1
- package/cjs/use-debounced-state/use-debounced-state.js +18 -19
- package/cjs/use-debounced-state/use-debounced-state.js.map +1 -1
- package/cjs/use-debounced-value/use-debounced-value.js +24 -25
- package/cjs/use-debounced-value/use-debounced-value.js.map +1 -1
- package/cjs/use-did-update/use-did-update.js +14 -11
- package/cjs/use-did-update/use-did-update.js.map +1 -1
- package/cjs/use-disclosure/use-disclosure.js +24 -24
- package/cjs/use-disclosure/use-disclosure.js.map +1 -1
- package/cjs/use-document-title/use-document-title.js +5 -5
- package/cjs/use-document-title/use-document-title.js.map +1 -1
- package/cjs/use-document-visibility/use-document-visibility.js +7 -7
- package/cjs/use-document-visibility/use-document-visibility.js.map +1 -1
- package/cjs/use-event-listener/use-event-listener.js +12 -9
- package/cjs/use-event-listener/use-event-listener.js.map +1 -1
- package/cjs/use-eye-dropper/use-eye-dropper.js +15 -12
- package/cjs/use-eye-dropper/use-eye-dropper.js.map +1 -1
- package/cjs/use-favicon/use-favicon.js +25 -23
- package/cjs/use-favicon/use-favicon.js.map +1 -1
- package/cjs/use-focus-return/use-focus-return.js +25 -29
- package/cjs/use-focus-return/use-focus-return.js.map +1 -1
- package/cjs/use-focus-trap/create-aria-hider.js +36 -36
- package/cjs/use-focus-trap/create-aria-hider.js.map +1 -1
- package/cjs/use-focus-trap/scope-tab.js +15 -15
- package/cjs/use-focus-trap/scope-tab.js.map +1 -1
- package/cjs/use-focus-trap/tabbable.js +33 -35
- package/cjs/use-focus-trap/tabbable.js.map +1 -1
- package/cjs/use-focus-trap/use-focus-trap.js +67 -67
- package/cjs/use-focus-trap/use-focus-trap.js.map +1 -1
- package/cjs/use-focus-within/use-focus-within.js +40 -37
- package/cjs/use-focus-within/use-focus-within.js.map +1 -1
- package/cjs/use-force-update/use-force-update.js +3 -3
- package/cjs/use-force-update/use-force-update.js.map +1 -1
- package/cjs/use-fullscreen/use-fullscreen.js +79 -83
- package/cjs/use-fullscreen/use-fullscreen.js.map +1 -1
- package/cjs/use-hash/use-hash.js +16 -16
- package/cjs/use-hash/use-hash.js.map +1 -1
- package/cjs/use-headroom/use-headroom.js +23 -23
- package/cjs/use-headroom/use-headroom.js.map +1 -1
- package/cjs/use-hotkeys/parse-hotkey.js +64 -49
- package/cjs/use-hotkeys/parse-hotkey.js.map +1 -1
- package/cjs/use-hotkeys/use-hotkeys.js +21 -22
- package/cjs/use-hotkeys/use-hotkeys.js.map +1 -1
- package/cjs/use-hover/use-hover.js +17 -17
- package/cjs/use-hover/use-hover.js.map +1 -1
- package/cjs/use-id/use-id.js +12 -12
- package/cjs/use-id/use-id.js.map +1 -1
- package/cjs/use-id/use-react-id.js +3 -3
- package/cjs/use-id/use-react-id.js.map +1 -1
- package/cjs/use-idle/use-idle.js +42 -26
- package/cjs/use-idle/use-idle.js.map +1 -1
- package/cjs/use-input-state/use-input-state.js +18 -22
- package/cjs/use-input-state/use-input-state.js.map +1 -1
- package/cjs/use-intersection/use-intersection.js +20 -17
- package/cjs/use-intersection/use-intersection.js.map +1 -1
- package/cjs/use-interval/use-interval.js +27 -28
- package/cjs/use-interval/use-interval.js.map +1 -1
- package/cjs/use-isomorphic-effect/use-isomorphic-effect.js +1 -3
- package/cjs/use-isomorphic-effect/use-isomorphic-effect.js.map +1 -1
- package/cjs/use-list-state/use-list-state.js +76 -55
- package/cjs/use-list-state/use-list-state.js.map +1 -1
- package/cjs/use-local-storage/create-storage.js +79 -71
- package/cjs/use-local-storage/create-storage.js.map +1 -1
- package/cjs/use-local-storage/use-local-storage.js +1 -1
- package/cjs/use-local-storage/use-local-storage.js.map +1 -1
- package/cjs/use-logger/use-logger.js +8 -9
- package/cjs/use-logger/use-logger.js.map +1 -1
- package/cjs/use-media-query/use-media-query.js +28 -31
- package/cjs/use-media-query/use-media-query.js.map +1 -1
- package/cjs/use-merged-ref/use-merged-ref.js +9 -11
- package/cjs/use-merged-ref/use-merged-ref.js.map +1 -1
- package/cjs/use-mouse/use-mouse.js +46 -25
- package/cjs/use-mouse/use-mouse.js.map +1 -1
- package/cjs/use-move/use-move.js +87 -88
- package/cjs/use-move/use-move.js.map +1 -1
- package/cjs/use-network/use-network.js +51 -32
- package/cjs/use-network/use-network.js.map +1 -1
- package/cjs/use-os/use-os.js +30 -30
- package/cjs/use-os/use-os.js.map +1 -1
- package/cjs/use-page-leave/use-page-leave.js +4 -4
- package/cjs/use-page-leave/use-page-leave.js.map +1 -1
- package/cjs/use-pagination/use-pagination.js +63 -58
- package/cjs/use-pagination/use-pagination.js.map +1 -1
- package/cjs/use-previous/use-previous.js +5 -5
- package/cjs/use-previous/use-previous.js.map +1 -1
- package/cjs/use-queue/use-queue.js +24 -24
- package/cjs/use-queue/use-queue.js.map +1 -1
- package/cjs/use-reduced-motion/use-reduced-motion.js +1 -1
- package/cjs/use-reduced-motion/use-reduced-motion.js.map +1 -1
- package/cjs/use-resize-observer/use-resize-observer.js +39 -38
- package/cjs/use-resize-observer/use-resize-observer.js.map +1 -1
- package/cjs/use-scroll-into-view/use-scroll-into-view.js +78 -75
- package/cjs/use-scroll-into-view/use-scroll-into-view.js.map +1 -1
- package/cjs/use-scroll-into-view/utils/ease-in-out-quad.js +1 -1
- package/cjs/use-scroll-into-view/utils/ease-in-out-quad.js.map +1 -1
- package/cjs/use-scroll-into-view/utils/get-relative-position.js +53 -46
- package/cjs/use-scroll-into-view/utils/get-relative-position.js.map +1 -1
- package/cjs/use-scroll-into-view/utils/get-scroll-start.js +9 -10
- package/cjs/use-scroll-into-view/utils/get-scroll-start.js.map +1 -1
- package/cjs/use-scroll-into-view/utils/set-scroll-param.js +11 -14
- package/cjs/use-scroll-into-view/utils/set-scroll-param.js.map +1 -1
- package/cjs/use-session-storage/use-session-storage.js +1 -1
- package/cjs/use-session-storage/use-session-storage.js.map +1 -1
- package/cjs/use-set-state/use-set-state.js +22 -3
- package/cjs/use-set-state/use-set-state.js.map +1 -1
- package/cjs/use-shallow-effect/use-shallow-effect.js +22 -22
- package/cjs/use-shallow-effect/use-shallow-effect.js.map +1 -1
- package/cjs/use-text-selection/use-text-selection.js +12 -12
- package/cjs/use-text-selection/use-text-selection.js.map +1 -1
- package/cjs/use-timeout/use-timeout.js +22 -22
- package/cjs/use-timeout/use-timeout.js.map +1 -1
- package/cjs/use-toggle/use-toggle.js +6 -6
- package/cjs/use-toggle/use-toggle.js.map +1 -1
- package/cjs/use-uncontrolled/use-uncontrolled.js +18 -10
- package/cjs/use-uncontrolled/use-uncontrolled.js.map +1 -1
- package/cjs/use-validated-state/use-validated-state.js +17 -14
- package/cjs/use-validated-state/use-validated-state.js.map +1 -1
- package/cjs/use-viewport-size/use-viewport-size.js +12 -12
- package/cjs/use-viewport-size/use-viewport-size.js.map +1 -1
- package/cjs/use-window-event/use-window-event.js +4 -4
- package/cjs/use-window-event/use-window-event.js.map +1 -1
- package/cjs/use-window-scroll/use-window-scroll.js +17 -19
- package/cjs/use-window-scroll/use-window-scroll.js.map +1 -1
- package/cjs/utils/clamp/clamp.js +10 -1
- package/cjs/utils/clamp/clamp.js.map +1 -1
- package/cjs/utils/lower-first/lower-first.js +1 -1
- package/cjs/utils/lower-first/lower-first.js.map +1 -1
- package/cjs/utils/random-id/random-id.js +1 -1
- package/cjs/utils/random-id/random-id.js.map +1 -1
- package/cjs/utils/range/range.js +2 -2
- package/cjs/utils/range/range.js.map +1 -1
- package/cjs/utils/shallow-equal/shallow-equal.js +19 -19
- package/cjs/utils/shallow-equal/shallow-equal.js.map +1 -1
- package/cjs/utils/upper-first/upper-first.js +1 -1
- package/cjs/utils/upper-first/upper-first.js.map +1 -1
- package/esm/use-callback-ref/use-callback-ref.js +8 -5
- package/esm/use-callback-ref/use-callback-ref.js.map +1 -1
- package/esm/use-click-outside/use-click-outside.js +19 -21
- package/esm/use-click-outside/use-click-outside.js.map +1 -1
- package/esm/use-clipboard/use-clipboard.js +22 -26
- package/esm/use-clipboard/use-clipboard.js.map +1 -1
- package/esm/use-color-scheme/use-color-scheme.js +1 -3
- package/esm/use-color-scheme/use-color-scheme.js.map +1 -1
- package/esm/use-counter/use-counter.js +25 -9
- package/esm/use-counter/use-counter.js.map +1 -1
- package/esm/use-debounced-callback/use-debounced-callback.js +7 -7
- package/esm/use-debounced-callback/use-debounced-callback.js.map +1 -1
- package/esm/use-debounced-state/use-debounced-state.js +18 -19
- package/esm/use-debounced-state/use-debounced-state.js.map +1 -1
- package/esm/use-debounced-value/use-debounced-value.js +24 -25
- package/esm/use-debounced-value/use-debounced-value.js.map +1 -1
- package/esm/use-did-update/use-did-update.js +14 -11
- package/esm/use-did-update/use-did-update.js.map +1 -1
- package/esm/use-disclosure/use-disclosure.js +24 -24
- package/esm/use-disclosure/use-disclosure.js.map +1 -1
- package/esm/use-document-title/use-document-title.js +5 -5
- package/esm/use-document-title/use-document-title.js.map +1 -1
- package/esm/use-document-visibility/use-document-visibility.js +7 -7
- package/esm/use-document-visibility/use-document-visibility.js.map +1 -1
- package/esm/use-event-listener/use-event-listener.js +12 -9
- package/esm/use-event-listener/use-event-listener.js.map +1 -1
- package/esm/use-eye-dropper/use-eye-dropper.js +15 -12
- package/esm/use-eye-dropper/use-eye-dropper.js.map +1 -1
- package/esm/use-favicon/use-favicon.js +25 -23
- package/esm/use-favicon/use-favicon.js.map +1 -1
- package/esm/use-focus-return/use-focus-return.js +25 -29
- package/esm/use-focus-return/use-focus-return.js.map +1 -1
- package/esm/use-focus-trap/create-aria-hider.js +36 -36
- package/esm/use-focus-trap/create-aria-hider.js.map +1 -1
- package/esm/use-focus-trap/scope-tab.js +15 -15
- package/esm/use-focus-trap/scope-tab.js.map +1 -1
- package/esm/use-focus-trap/tabbable.js +33 -35
- package/esm/use-focus-trap/tabbable.js.map +1 -1
- package/esm/use-focus-trap/use-focus-trap.js +67 -67
- package/esm/use-focus-trap/use-focus-trap.js.map +1 -1
- package/esm/use-focus-within/use-focus-within.js +40 -37
- package/esm/use-focus-within/use-focus-within.js.map +1 -1
- package/esm/use-force-update/use-force-update.js +3 -3
- package/esm/use-force-update/use-force-update.js.map +1 -1
- package/esm/use-fullscreen/use-fullscreen.js +79 -83
- package/esm/use-fullscreen/use-fullscreen.js.map +1 -1
- package/esm/use-hash/use-hash.js +16 -16
- package/esm/use-hash/use-hash.js.map +1 -1
- package/esm/use-headroom/use-headroom.js +23 -23
- package/esm/use-headroom/use-headroom.js.map +1 -1
- package/esm/use-hotkeys/parse-hotkey.js +64 -49
- package/esm/use-hotkeys/parse-hotkey.js.map +1 -1
- package/esm/use-hotkeys/use-hotkeys.js +21 -22
- package/esm/use-hotkeys/use-hotkeys.js.map +1 -1
- package/esm/use-hover/use-hover.js +17 -17
- package/esm/use-hover/use-hover.js.map +1 -1
- package/esm/use-id/use-id.js +12 -12
- package/esm/use-id/use-id.js.map +1 -1
- package/esm/use-id/use-react-id.js +3 -3
- package/esm/use-id/use-react-id.js.map +1 -1
- package/esm/use-idle/use-idle.js +42 -26
- package/esm/use-idle/use-idle.js.map +1 -1
- package/esm/use-input-state/use-input-state.js +18 -22
- package/esm/use-input-state/use-input-state.js.map +1 -1
- package/esm/use-intersection/use-intersection.js +20 -17
- package/esm/use-intersection/use-intersection.js.map +1 -1
- package/esm/use-interval/use-interval.js +27 -28
- package/esm/use-interval/use-interval.js.map +1 -1
- package/esm/use-isomorphic-effect/use-isomorphic-effect.js +1 -3
- package/esm/use-isomorphic-effect/use-isomorphic-effect.js.map +1 -1
- package/esm/use-list-state/use-list-state.js +76 -55
- package/esm/use-list-state/use-list-state.js.map +1 -1
- package/esm/use-local-storage/create-storage.js +79 -71
- package/esm/use-local-storage/create-storage.js.map +1 -1
- package/esm/use-local-storage/use-local-storage.js +1 -1
- package/esm/use-local-storage/use-local-storage.js.map +1 -1
- package/esm/use-logger/use-logger.js +8 -9
- package/esm/use-logger/use-logger.js.map +1 -1
- package/esm/use-media-query/use-media-query.js +28 -31
- package/esm/use-media-query/use-media-query.js.map +1 -1
- package/esm/use-merged-ref/use-merged-ref.js +9 -11
- package/esm/use-merged-ref/use-merged-ref.js.map +1 -1
- package/esm/use-mouse/use-mouse.js +46 -25
- package/esm/use-mouse/use-mouse.js.map +1 -1
- package/esm/use-move/use-move.js +87 -88
- package/esm/use-move/use-move.js.map +1 -1
- package/esm/use-network/use-network.js +51 -32
- package/esm/use-network/use-network.js.map +1 -1
- package/esm/use-os/use-os.js +30 -30
- package/esm/use-os/use-os.js.map +1 -1
- package/esm/use-page-leave/use-page-leave.js +4 -4
- package/esm/use-page-leave/use-page-leave.js.map +1 -1
- package/esm/use-pagination/use-pagination.js +63 -58
- package/esm/use-pagination/use-pagination.js.map +1 -1
- package/esm/use-previous/use-previous.js +5 -5
- package/esm/use-previous/use-previous.js.map +1 -1
- package/esm/use-queue/use-queue.js +24 -24
- package/esm/use-queue/use-queue.js.map +1 -1
- package/esm/use-reduced-motion/use-reduced-motion.js +1 -1
- package/esm/use-reduced-motion/use-reduced-motion.js.map +1 -1
- package/esm/use-resize-observer/use-resize-observer.js +39 -38
- package/esm/use-resize-observer/use-resize-observer.js.map +1 -1
- package/esm/use-scroll-into-view/use-scroll-into-view.js +78 -75
- package/esm/use-scroll-into-view/use-scroll-into-view.js.map +1 -1
- package/esm/use-scroll-into-view/utils/ease-in-out-quad.js +1 -1
- package/esm/use-scroll-into-view/utils/ease-in-out-quad.js.map +1 -1
- package/esm/use-scroll-into-view/utils/get-relative-position.js +53 -46
- package/esm/use-scroll-into-view/utils/get-relative-position.js.map +1 -1
- package/esm/use-scroll-into-view/utils/get-scroll-start.js +9 -10
- package/esm/use-scroll-into-view/utils/get-scroll-start.js.map +1 -1
- package/esm/use-scroll-into-view/utils/set-scroll-param.js +11 -14
- package/esm/use-scroll-into-view/utils/set-scroll-param.js.map +1 -1
- package/esm/use-session-storage/use-session-storage.js +1 -1
- package/esm/use-session-storage/use-session-storage.js.map +1 -1
- package/esm/use-set-state/use-set-state.js +22 -3
- package/esm/use-set-state/use-set-state.js.map +1 -1
- package/esm/use-shallow-effect/use-shallow-effect.js +22 -22
- package/esm/use-shallow-effect/use-shallow-effect.js.map +1 -1
- package/esm/use-text-selection/use-text-selection.js +12 -12
- package/esm/use-text-selection/use-text-selection.js.map +1 -1
- package/esm/use-timeout/use-timeout.js +22 -22
- package/esm/use-timeout/use-timeout.js.map +1 -1
- package/esm/use-toggle/use-toggle.js +6 -6
- package/esm/use-toggle/use-toggle.js.map +1 -1
- package/esm/use-uncontrolled/use-uncontrolled.js +18 -10
- package/esm/use-uncontrolled/use-uncontrolled.js.map +1 -1
- package/esm/use-validated-state/use-validated-state.js +17 -14
- package/esm/use-validated-state/use-validated-state.js.map +1 -1
- package/esm/use-viewport-size/use-viewport-size.js +12 -12
- package/esm/use-viewport-size/use-viewport-size.js.map +1 -1
- package/esm/use-window-event/use-window-event.js +4 -4
- package/esm/use-window-event/use-window-event.js.map +1 -1
- package/esm/use-window-scroll/use-window-scroll.js +17 -19
- package/esm/use-window-scroll/use-window-scroll.js.map +1 -1
- package/esm/utils/clamp/clamp.js +10 -1
- package/esm/utils/clamp/clamp.js.map +1 -1
- package/esm/utils/lower-first/lower-first.js +1 -1
- package/esm/utils/lower-first/lower-first.js.map +1 -1
- package/esm/utils/random-id/random-id.js +1 -1
- package/esm/utils/random-id/random-id.js.map +1 -1
- package/esm/utils/range/range.js +2 -2
- package/esm/utils/range/range.js.map +1 -1
- package/esm/utils/shallow-equal/shallow-equal.js +19 -19
- package/esm/utils/shallow-equal/shallow-equal.js.map +1 -1
- package/esm/utils/upper-first/upper-first.js +1 -1
- package/esm/utils/upper-first/upper-first.js.map +1 -1
- package/lib/use-hover/use-hover.d.ts +1 -0
- package/lib/use-mouse/use-mouse.d.ts +1 -0
- package/lib/use-move/use-move.d.ts +2 -1
- package/lib/use-scroll-into-view/use-scroll-into-view.d.ts +1 -0
- package/lib/utils/clamp/clamp.d.ts +1 -1
- package/package.json +5 -4
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
import { useState, useRef, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
function useDebouncedValue(value, wait, options = { leading: false }) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return [_value, cancel];
|
|
4
|
+
const [_value, setValue] = useState(value);
|
|
5
|
+
const mountedRef = useRef(false);
|
|
6
|
+
const timeoutRef = useRef(null);
|
|
7
|
+
const cooldownRef = useRef(false);
|
|
8
|
+
const cancel = () => window.clearTimeout(timeoutRef.current);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (mountedRef.current) {
|
|
11
|
+
if (!cooldownRef.current && options.leading) {
|
|
12
|
+
cooldownRef.current = true;
|
|
13
|
+
setValue(value);
|
|
14
|
+
} else {
|
|
15
|
+
cancel();
|
|
16
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
17
|
+
cooldownRef.current = false;
|
|
18
|
+
setValue(value);
|
|
19
|
+
}, wait);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}, [value, options.leading, wait]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
mountedRef.current = true;
|
|
25
|
+
return cancel;
|
|
26
|
+
}, []);
|
|
27
|
+
return [_value, cancel];
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
export { useDebouncedValue };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-debounced-value.js","sources":["../../src/use-debounced-value/use-debounced-value.ts"],"sourcesContent":["import { useEffect, useState, useRef } from 'react';\n\nexport function useDebouncedValue<T = any>(value: T, wait: number, options = { leading: false }) {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number | null>(null);\n const cooldownRef = useRef(false);\n\n const cancel = () => window.clearTimeout(timeoutRef.current!);\n\n useEffect(() => {\n if (mountedRef.current) {\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n } else {\n cancel();\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading, wait]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel] as const;\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-debounced-value.js","sources":["../../src/use-debounced-value/use-debounced-value.ts"],"sourcesContent":["import { useEffect, useState, useRef } from 'react';\n\nexport function useDebouncedValue<T = any>(value: T, wait: number, options = { leading: false }) {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number | null>(null);\n const cooldownRef = useRef(false);\n\n const cancel = () => window.clearTimeout(timeoutRef.current!);\n\n useEffect(() => {\n if (mountedRef.current) {\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n } else {\n cancel();\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading, wait]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;AAC7E,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACnC,EAAE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACpC,EAAE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC/D,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE;AAC5B,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;AACnD,QAAQ,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;AACnC,QAAQ,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,OAAO,MAAM;AACb,QAAQ,MAAM,EAAE,CAAC;AACjB,QAAQ,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACrD,UAAU,WAAW,CAAC,OAAO,GAAG,KAAK,CAAC;AACtC,UAAU,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1B,SAAS,EAAE,IAAI,CAAC,CAAC;AACjB,OAAO;AACP,KAAK;AACL,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;AACrC,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AAC9B,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1B;;;;"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
function useDidUpdate(fn, dependencies) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
4
|
+
const mounted = useRef(false);
|
|
5
|
+
useEffect(
|
|
6
|
+
() => () => {
|
|
7
|
+
mounted.current = false;
|
|
8
|
+
},
|
|
9
|
+
[]
|
|
10
|
+
);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (mounted.current) {
|
|
13
|
+
return fn();
|
|
14
|
+
}
|
|
15
|
+
mounted.current = true;
|
|
16
|
+
return void 0;
|
|
17
|
+
}, dependencies);
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export { useDidUpdate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-did-update.js","sources":["../../src/use-did-update/use-did-update.ts"],"sourcesContent":["import { useEffect, useRef, EffectCallback, DependencyList } from 'react';\n\nexport function useDidUpdate(fn: EffectCallback, dependencies?: DependencyList) {\n const mounted = useRef(false);\n\n useEffect(\n () => () => {\n mounted.current = false;\n },\n []\n );\n\n useEffect(() => {\n if (mounted.current) {\n return fn();\n }\n\n mounted.current = true;\n return undefined;\n }, dependencies);\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-did-update.js","sources":["../../src/use-did-update/use-did-update.ts"],"sourcesContent":["import { useEffect, useRef, EffectCallback, DependencyList } from 'react';\n\nexport function useDidUpdate(fn: EffectCallback, dependencies?: DependencyList) {\n const mounted = useRef(false);\n\n useEffect(\n () => () => {\n mounted.current = false;\n },\n []\n );\n\n useEffect(() => {\n if (mounted.current) {\n return fn();\n }\n\n mounted.current = true;\n return undefined;\n }, dependencies);\n}\n"],"names":[],"mappings":";;AACO,SAAS,YAAY,CAAC,EAAE,EAAE,YAAY,EAAE;AAC/C,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAChC,EAAE,SAAS;AACX,IAAI,MAAM,MAAM;AAChB,MAAM,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;AAC9B,KAAK;AACL,IAAI,EAAE;AACN,GAAG,CAAC;AACJ,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE;AACzB,MAAM,OAAO,EAAE,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;AAC3B,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,YAAY,CAAC,CAAC;AACnB;;;;"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { useState, useCallback } from 'react';
|
|
2
2
|
|
|
3
3
|
function useDisclosure(initialState = false, callbacks) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
const { onOpen, onClose } = callbacks || {};
|
|
5
|
+
const [opened, setOpened] = useState(initialState);
|
|
6
|
+
const open = useCallback(() => {
|
|
7
|
+
setOpened((isOpened) => {
|
|
8
|
+
if (!isOpened) {
|
|
9
|
+
onOpen == null ? void 0 : onOpen();
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return isOpened;
|
|
13
|
+
});
|
|
14
|
+
}, [onOpen]);
|
|
15
|
+
const close = useCallback(() => {
|
|
16
|
+
setOpened((isOpened) => {
|
|
17
|
+
if (isOpened) {
|
|
18
|
+
onClose == null ? void 0 : onClose();
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return isOpened;
|
|
22
|
+
});
|
|
23
|
+
}, [onClose]);
|
|
24
|
+
const toggle = useCallback(() => {
|
|
25
|
+
opened ? close() : open();
|
|
26
|
+
}, [close, open, opened]);
|
|
27
|
+
return [opened, { open, close, toggle }];
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export { useDisclosure };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-disclosure.js","sources":["../../src/use-disclosure/use-disclosure.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\n\nexport function useDisclosure(\n initialState = false,\n callbacks?: { onOpen?(): void; onClose?(): void }\n) {\n const { onOpen, onClose } = callbacks || {};\n const [opened, setOpened] = useState(initialState);\n\n const open = useCallback(() => {\n setOpened((isOpened) => {\n if (!isOpened) {\n onOpen?.();\n return true;\n }\n return isOpened;\n });\n }, [onOpen]);\n\n const close = useCallback(() => {\n setOpened((isOpened) => {\n if (isOpened) {\n onClose?.();\n return false;\n }\n return isOpened;\n });\n }, [onClose]);\n\n const toggle = useCallback(() => {\n opened ? close() : open();\n }, [close, open, opened]);\n\n return [opened, { open, close, toggle }] as const;\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-disclosure.js","sources":["../../src/use-disclosure/use-disclosure.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\n\nexport function useDisclosure(\n initialState = false,\n callbacks?: { onOpen?(): void; onClose?(): void }\n) {\n const { onOpen, onClose } = callbacks || {};\n const [opened, setOpened] = useState(initialState);\n\n const open = useCallback(() => {\n setOpened((isOpened) => {\n if (!isOpened) {\n onOpen?.();\n return true;\n }\n return isOpened;\n });\n }, [onOpen]);\n\n const close = useCallback(() => {\n setOpened((isOpened) => {\n if (isOpened) {\n onClose?.();\n return false;\n }\n return isOpened;\n });\n }, [onClose]);\n\n const toggle = useCallback(() => {\n opened ? close() : open();\n }, [close, open, opened]);\n\n return [opened, { open, close, toggle }] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,aAAa,CAAC,YAAY,GAAG,KAAK,EAAE,SAAS,EAAE;AAC/D,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,IAAI,EAAE,CAAC;AAC9C,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AACrD,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM;AACjC,IAAI,SAAS,CAAC,CAAC,QAAQ,KAAK;AAC5B,MAAM,IAAI,CAAC,QAAQ,EAAE;AACrB,QAAQ,MAAM,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,MAAM,EAAE,CAAC;AAC3C,QAAQ,OAAO,IAAI,CAAC;AACpB,OAAO;AACP,MAAM,OAAO,QAAQ,CAAC;AACtB,KAAK,CAAC,CAAC;AACP,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACf,EAAE,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM;AAClC,IAAI,SAAS,CAAC,CAAC,QAAQ,KAAK;AAC5B,MAAM,IAAI,QAAQ,EAAE;AACpB,QAAQ,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,EAAE,CAAC;AAC7C,QAAQ,OAAO,KAAK,CAAC;AACrB,OAAO;AACP,MAAM,OAAO,QAAQ,CAAC;AACtB,KAAK,CAAC,CAAC;AACP,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,EAAE,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM;AACnC,IAAI,MAAM,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC;AAC9B,GAAG,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC5B,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3C;;;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.js';
|
|
2
2
|
|
|
3
3
|
function useDocumentTitle(title) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
useIsomorphicEffect(() => {
|
|
5
|
+
if (typeof title === "string" && title.trim().length > 0) {
|
|
6
|
+
document.title = title.trim();
|
|
7
|
+
}
|
|
8
|
+
}, [title]);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export { useDocumentTitle };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-document-title.js","sources":["../../src/use-document-title/use-document-title.ts"],"sourcesContent":["import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nexport function useDocumentTitle(title: string) {\n useIsomorphicEffect(() => {\n if (typeof title === 'string' && title.trim().length > 0) {\n document.title = title.trim();\n }\n }, [title]);\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-document-title.js","sources":["../../src/use-document-title/use-document-title.ts"],"sourcesContent":["import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nexport function useDocumentTitle(title: string) {\n useIsomorphicEffect(() => {\n if (typeof title === 'string' && title.trim().length > 0) {\n document.title = title.trim();\n }\n }, [title]);\n}\n"],"names":[],"mappings":";;AACO,SAAS,gBAAgB,CAAC,KAAK,EAAE;AACxC,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE;AAC9D,MAAM,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;AACpC,KAAK;AACL,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd;;;;"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
function useDocumentVisibility() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const [documentVisibility, setDocumentVisibility] = useState("visible");
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const listener = () => setDocumentVisibility(document.visibilityState);
|
|
7
|
+
document.addEventListener("visibilitychange", listener);
|
|
8
|
+
return () => document.removeEventListener("visibilitychange", listener);
|
|
9
|
+
}, []);
|
|
10
|
+
return documentVisibility;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export { useDocumentVisibility };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-document-visibility.js","sources":["../../src/use-document-visibility/use-document-visibility.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport function useDocumentVisibility(): DocumentVisibilityState {\n const [documentVisibility, setDocumentVisibility] = useState<DocumentVisibilityState>('visible');\n\n useEffect(() => {\n const listener = () => setDocumentVisibility(document.visibilityState);\n document.addEventListener('visibilitychange', listener);\n return () => document.removeEventListener('visibilitychange', listener);\n }, []);\n\n return documentVisibility;\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-document-visibility.js","sources":["../../src/use-document-visibility/use-document-visibility.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport function useDocumentVisibility(): DocumentVisibilityState {\n const [documentVisibility, setDocumentVisibility] = useState<DocumentVisibilityState>('visible');\n\n useEffect(() => {\n const listener = () => setDocumentVisibility(document.visibilityState);\n document.addEventListener('visibilitychange', listener);\n return () => document.removeEventListener('visibilitychange', listener);\n }, []);\n\n return documentVisibility;\n}\n"],"names":[],"mappings":";;AACO,SAAS,qBAAqB,GAAG;AACxC,EAAE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC1E,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC3E,IAAI,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC5D,IAAI,OAAO,MAAM,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC5E,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,kBAAkB,CAAC;AAC5B;;;;"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
function useEventListener(type, listener, options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const ref = useRef();
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (ref.current) {
|
|
7
|
+
ref.current.addEventListener(type, listener, options);
|
|
8
|
+
return () => {
|
|
9
|
+
var _a;
|
|
10
|
+
return (_a = ref.current) == null ? void 0 : _a.removeEventListener(type, listener, options);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return void 0;
|
|
14
|
+
}, [listener, options]);
|
|
15
|
+
return ref;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export { useEventListener };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-event-listener.js","sources":["../../src/use-event-listener/use-event-listener.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\nexport function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = any>(\n type: K,\n listener: (this: HTMLDivElement, ev: HTMLElementEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n const ref = useRef<T>();\n\n useEffect(() => {\n if (ref.current) {\n ref.current.addEventListener(type, listener as any, options);\n return () => ref.current?.removeEventListener(type, listener as any, options);\n }\n return undefined;\n }, [listener, options]);\n\n return ref;\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"use-event-listener.js","sources":["../../src/use-event-listener/use-event-listener.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\nexport function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = any>(\n type: K,\n listener: (this: HTMLDivElement, ev: HTMLElementEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n const ref = useRef<T>();\n\n useEffect(() => {\n if (ref.current) {\n ref.current.addEventListener(type, listener as any, options);\n return () => ref.current?.removeEventListener(type, listener as any, options);\n }\n return undefined;\n }, [listener, options]);\n\n return ref;\n}\n"],"names":[],"mappings":";;AACO,SAAS,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE;AAC1D,EAAE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;AACvB,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE;AACrB,MAAM,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC5D,MAAM,OAAO,MAAM;AACnB,QAAQ,IAAI,EAAE,CAAC;AACf,QAAQ,OAAO,CAAC,EAAE,GAAG,GAAG,CAAC,OAAO,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACrG,OAAO,CAAC;AACR,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1B,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
|
|
@@ -2,18 +2,21 @@ import { useState, useCallback } from 'react';
|
|
|
2
2
|
import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.js';
|
|
3
3
|
|
|
4
4
|
function useEyeDropper() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
const [supported, setSupported] = useState(false);
|
|
6
|
+
useIsomorphicEffect(() => {
|
|
7
|
+
setSupported(typeof window !== "undefined" && "EyeDropper" in window);
|
|
8
|
+
}, []);
|
|
9
|
+
const open = useCallback(
|
|
10
|
+
(options = {}) => {
|
|
11
|
+
if (supported) {
|
|
12
|
+
const eyeDropper = new window.EyeDropper();
|
|
13
|
+
return eyeDropper.open(options);
|
|
14
|
+
}
|
|
15
|
+
return Promise.resolve(void 0);
|
|
16
|
+
},
|
|
17
|
+
[supported]
|
|
18
|
+
);
|
|
19
|
+
return { supported, open };
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export { useEyeDropper };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-eye-dropper.js","sources":["../../src/use-eye-dropper/use-eye-dropper.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\ninterface EyeDropperOpenOptions {\n signal?: AbortSignal;\n}\n\nexport interface EyeDropperOpenReturnType {\n sRGBHex: string;\n}\n\nexport function useEyeDropper() {\n const [supported, setSupported] = useState(false);\n\n useIsomorphicEffect(() => {\n setSupported(typeof window !== 'undefined' && 'EyeDropper' in window);\n }, []);\n\n const open = useCallback(\n (options: EyeDropperOpenOptions = {}): Promise<EyeDropperOpenReturnType | undefined> => {\n if (supported) {\n const eyeDropper = new (window as any).EyeDropper();\n return eyeDropper.open(options);\n }\n\n return Promise.resolve(undefined);\n },\n [supported]\n );\n\n return { supported, open };\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-eye-dropper.js","sources":["../../src/use-eye-dropper/use-eye-dropper.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\ninterface EyeDropperOpenOptions {\n signal?: AbortSignal;\n}\n\nexport interface EyeDropperOpenReturnType {\n sRGBHex: string;\n}\n\nexport function useEyeDropper() {\n const [supported, setSupported] = useState(false);\n\n useIsomorphicEffect(() => {\n setSupported(typeof window !== 'undefined' && 'EyeDropper' in window);\n }, []);\n\n const open = useCallback(\n (options: EyeDropperOpenOptions = {}): Promise<EyeDropperOpenReturnType | undefined> => {\n if (supported) {\n const eyeDropper = new (window as any).EyeDropper();\n return eyeDropper.open(options);\n }\n\n return Promise.resolve(undefined);\n },\n [supported]\n );\n\n return { supported, open };\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,aAAa,GAAG;AAChC,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpD,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,YAAY,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,YAAY,IAAI,MAAM,CAAC,CAAC;AAC1E,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,MAAM,IAAI,GAAG,WAAW;AAC1B,IAAI,CAAC,OAAO,GAAG,EAAE,KAAK;AACtB,MAAM,IAAI,SAAS,EAAE;AACrB,QAAQ,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;AACnD,QAAQ,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxC,OAAO;AACP,MAAM,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACrC,KAAK;AACL,IAAI,CAAC,SAAS,CAAC;AACf,GAAG,CAAC;AACJ,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC7B;;;;"}
|
|
@@ -2,31 +2,33 @@ import { useRef } from 'react';
|
|
|
2
2
|
import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.js';
|
|
3
3
|
|
|
4
4
|
const MIME_TYPES = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
ico: "image/x-icon",
|
|
6
|
+
png: "image/png",
|
|
7
|
+
svg: "image/svg+xml",
|
|
8
|
+
gif: "image/gif"
|
|
9
9
|
};
|
|
10
10
|
function useFavicon(url) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
const link = useRef();
|
|
12
|
+
useIsomorphicEffect(() => {
|
|
13
|
+
if (!url) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!link.current) {
|
|
17
|
+
const existingElements = document.querySelectorAll('link[rel*="icon"]');
|
|
18
|
+
existingElements.forEach((element2) => document.head.removeChild(element2));
|
|
19
|
+
const element = document.createElement("link");
|
|
20
|
+
element.rel = "shortcut icon";
|
|
21
|
+
link.current = element;
|
|
22
|
+
document.querySelector("head").appendChild(element);
|
|
23
|
+
}
|
|
24
|
+
const splittedUrl = url.split(".");
|
|
25
|
+
link.current.setAttribute(
|
|
26
|
+
"type",
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
MIME_TYPES[splittedUrl[splittedUrl.length - 1].toLowerCase()]
|
|
29
|
+
);
|
|
30
|
+
link.current.setAttribute("href", url);
|
|
31
|
+
}, [url]);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export { useFavicon };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-favicon.js","sources":["../../src/use-favicon/use-favicon.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nconst MIME_TYPES = {\n ico: 'image/x-icon',\n png: 'image/png',\n svg: 'image/svg+xml',\n gif: 'image/gif',\n};\n\nexport function useFavicon(url: string) {\n const link = useRef<HTMLLinkElement>();\n\n useIsomorphicEffect(() => {\n if (!url) {\n return;\n }\n\n if (!link.current) {\n const existingElements = document.querySelectorAll<HTMLLinkElement>('link[rel*=\"icon\"]');\n existingElements.forEach((element) => document.head.removeChild(element));\n\n const element = document.createElement('link');\n element.rel = 'shortcut icon';\n link.current = element;\n document.querySelector('head')!.appendChild(element);\n }\n\n const splittedUrl = url.split('.');\n link.current.setAttribute(\n 'type',\n // @ts-ignore\n MIME_TYPES[splittedUrl[splittedUrl.length - 1].toLowerCase()]\n );\n link.current.setAttribute('href', url);\n }, [url]);\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-favicon.js","sources":["../../src/use-favicon/use-favicon.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\nconst MIME_TYPES = {\n ico: 'image/x-icon',\n png: 'image/png',\n svg: 'image/svg+xml',\n gif: 'image/gif',\n};\n\nexport function useFavicon(url: string) {\n const link = useRef<HTMLLinkElement>();\n\n useIsomorphicEffect(() => {\n if (!url) {\n return;\n }\n\n if (!link.current) {\n const existingElements = document.querySelectorAll<HTMLLinkElement>('link[rel*=\"icon\"]');\n existingElements.forEach((element) => document.head.removeChild(element));\n\n const element = document.createElement('link');\n element.rel = 'shortcut icon';\n link.current = element;\n document.querySelector('head')!.appendChild(element);\n }\n\n const splittedUrl = url.split('.');\n link.current.setAttribute(\n 'type',\n // @ts-ignore\n MIME_TYPES[splittedUrl[splittedUrl.length - 1].toLowerCase()]\n );\n link.current.setAttribute('href', url);\n }, [url]);\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG;AACnB,EAAE,GAAG,EAAE,cAAc;AACrB,EAAE,GAAG,EAAE,WAAW;AAClB,EAAE,GAAG,EAAE,eAAe;AACtB,EAAE,GAAG,EAAE,WAAW;AAClB,CAAC,CAAC;AACK,SAAS,UAAU,CAAC,GAAG,EAAE;AAChC,EAAE,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC;AACxB,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,MAAM,OAAO;AACb,KAAK;AACL,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACvB,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;AAC9E,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;AAClF,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,OAAO,CAAC,GAAG,GAAG,eAAe,CAAC;AACpC,MAAM,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AAC7B,MAAM,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AAC1D,KAAK;AACL,IAAI,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACvC,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY;AAC7B,MAAM,MAAM;AACZ;AACA,MAAM,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACnE,KAAK,CAAC;AACN,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC3C,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AACZ;;;;"}
|
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
import { useDidUpdate } from '../use-did-update/use-did-update.js';
|
|
3
3
|
|
|
4
|
-
/** Returns focus to last active element, used in Modal and Drawer */
|
|
5
4
|
function useFocusReturn({ opened, shouldReturnFocus = true }) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const lastActiveElement = useRef();
|
|
6
|
+
const returnFocus = () => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (lastActiveElement.current && "focus" in lastActiveElement.current && typeof lastActiveElement.current.focus === "function") {
|
|
9
|
+
(_a = lastActiveElement.current) == null ? void 0 : _a.focus({ preventScroll: true });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
useDidUpdate(() => {
|
|
13
|
+
let timeout = -1;
|
|
14
|
+
const clearFocusTimeout = (event) => {
|
|
15
|
+
if (event.key === "Tab") {
|
|
16
|
+
window.clearTimeout(timeout);
|
|
17
|
+
}
|
|
14
18
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
timeout = window.setTimeout(returnFocus, 10);
|
|
28
|
-
}
|
|
29
|
-
return () => {
|
|
30
|
-
window.clearTimeout(timeout);
|
|
31
|
-
document.removeEventListener('keydown', clearFocusTimeout);
|
|
32
|
-
};
|
|
33
|
-
}, [opened, shouldReturnFocus]);
|
|
34
|
-
return returnFocus;
|
|
19
|
+
document.addEventListener("keydown", clearFocusTimeout);
|
|
20
|
+
if (opened) {
|
|
21
|
+
lastActiveElement.current = document.activeElement;
|
|
22
|
+
} else if (shouldReturnFocus) {
|
|
23
|
+
timeout = window.setTimeout(returnFocus, 10);
|
|
24
|
+
}
|
|
25
|
+
return () => {
|
|
26
|
+
window.clearTimeout(timeout);
|
|
27
|
+
document.removeEventListener("keydown", clearFocusTimeout);
|
|
28
|
+
};
|
|
29
|
+
}, [opened, shouldReturnFocus]);
|
|
30
|
+
return returnFocus;
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
export { useFocusReturn };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-focus-return.js","sources":["../../src/use-focus-return/use-focus-return.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { useDidUpdate } from '../use-did-update/use-did-update';\n\ninterface UseFocusReturn {\n opened: boolean;\n shouldReturnFocus?: boolean;\n}\n\n/** Returns focus to last active element, used in Modal and Drawer */\nexport function useFocusReturn({ opened, shouldReturnFocus = true }: UseFocusReturn) {\n const lastActiveElement = useRef<HTMLElement>();\n const returnFocus = () => {\n if (\n lastActiveElement.current &&\n 'focus' in lastActiveElement.current &&\n typeof lastActiveElement.current.focus === 'function'\n ) {\n lastActiveElement.current?.focus({ preventScroll: true });\n }\n };\n\n useDidUpdate(() => {\n let timeout = -1;\n\n const clearFocusTimeout = (event: KeyboardEvent) => {\n if (event.key === 'Tab') {\n window.clearTimeout(timeout);\n }\n };\n\n document.addEventListener('keydown', clearFocusTimeout);\n\n if (opened) {\n lastActiveElement.current = document.activeElement as HTMLElement;\n } else if (shouldReturnFocus) {\n timeout = window.setTimeout(returnFocus, 10);\n }\n\n return () => {\n window.clearTimeout(timeout);\n document.removeEventListener('keydown', clearFocusTimeout);\n };\n }, [opened, shouldReturnFocus]);\n\n return returnFocus;\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"use-focus-return.js","sources":["../../src/use-focus-return/use-focus-return.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { useDidUpdate } from '../use-did-update/use-did-update';\n\ninterface UseFocusReturn {\n opened: boolean;\n shouldReturnFocus?: boolean;\n}\n\n/** Returns focus to last active element, used in Modal and Drawer */\nexport function useFocusReturn({ opened, shouldReturnFocus = true }: UseFocusReturn) {\n const lastActiveElement = useRef<HTMLElement>();\n const returnFocus = () => {\n if (\n lastActiveElement.current &&\n 'focus' in lastActiveElement.current &&\n typeof lastActiveElement.current.focus === 'function'\n ) {\n lastActiveElement.current?.focus({ preventScroll: true });\n }\n };\n\n useDidUpdate(() => {\n let timeout = -1;\n\n const clearFocusTimeout = (event: KeyboardEvent) => {\n if (event.key === 'Tab') {\n window.clearTimeout(timeout);\n }\n };\n\n document.addEventListener('keydown', clearFocusTimeout);\n\n if (opened) {\n lastActiveElement.current = document.activeElement as HTMLElement;\n } else if (shouldReturnFocus) {\n timeout = window.setTimeout(returnFocus, 10);\n }\n\n return () => {\n window.clearTimeout(timeout);\n document.removeEventListener('keydown', clearFocusTimeout);\n };\n }, [opened, shouldReturnFocus]);\n\n return returnFocus;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,cAAc,CAAC,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI,EAAE,EAAE;AACrE,EAAE,MAAM,iBAAiB,GAAG,MAAM,EAAE,CAAC;AACrC,EAAE,MAAM,WAAW,GAAG,MAAM;AAC5B,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,IAAI,iBAAiB,CAAC,OAAO,IAAI,OAAO,IAAI,iBAAiB,CAAC,OAAO,IAAI,OAAO,iBAAiB,CAAC,OAAO,CAAC,KAAK,KAAK,UAAU,EAAE;AACpI,MAAM,CAAC,EAAE,GAAG,iBAAiB,CAAC,OAAO,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AAC5F,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,YAAY,CAAC,MAAM;AACrB,IAAI,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC;AACrB,IAAI,MAAM,iBAAiB,GAAG,CAAC,KAAK,KAAK;AACzC,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,EAAE;AAC/B,QAAQ,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;AACrC,OAAO;AACP,KAAK,CAAC;AACN,IAAI,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAC5D,IAAI,IAAI,MAAM,EAAE;AAChB,MAAM,iBAAiB,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;AACzD,KAAK,MAAM,IAAI,iBAAiB,EAAE;AAClC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,OAAO,MAAM;AACjB,MAAM,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;AACnC,MAAM,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AACjE,KAAK,CAAC;AACN,GAAG,EAAE,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAClC,EAAE,OAAO,WAAW,CAAC;AACrB;;;;"}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
import { randomId } from '../utils/random-id/random-id.js';
|
|
2
2
|
|
|
3
|
-
function createAriaHider(containerNode, selector =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
return () => {
|
|
26
|
-
rootNodes.forEach((item) => {
|
|
27
|
-
if (!item || id !== item.node.getAttribute('data-focus-id')) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (item.ariaHidden === null) {
|
|
31
|
-
item.node.removeAttribute('aria-hidden');
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
item.node.setAttribute('aria-hidden', item.ariaHidden);
|
|
35
|
-
}
|
|
36
|
-
item.node.removeAttribute('data-focus-id');
|
|
37
|
-
item.node.removeAttribute('data-hidden');
|
|
38
|
-
});
|
|
3
|
+
function createAriaHider(containerNode, selector = "body > :not(script)") {
|
|
4
|
+
const id = randomId();
|
|
5
|
+
const rootNodes = Array.from(
|
|
6
|
+
document.querySelectorAll(selector)
|
|
7
|
+
).map((node) => {
|
|
8
|
+
var _a;
|
|
9
|
+
if (((_a = node == null ? void 0 : node.shadowRoot) == null ? void 0 : _a.contains(containerNode)) || node.contains(containerNode)) {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
const ariaHidden = node.getAttribute("aria-hidden");
|
|
13
|
+
const prevAriaHidden = node.getAttribute("data-hidden");
|
|
14
|
+
const prevFocusId = node.getAttribute("data-focus-id");
|
|
15
|
+
node.setAttribute("data-focus-id", id);
|
|
16
|
+
if (ariaHidden === null || ariaHidden === "false") {
|
|
17
|
+
node.setAttribute("aria-hidden", "true");
|
|
18
|
+
} else if (!prevAriaHidden && !prevFocusId) {
|
|
19
|
+
node.setAttribute("data-hidden", ariaHidden);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
node,
|
|
23
|
+
ariaHidden: prevAriaHidden || null
|
|
39
24
|
};
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
rootNodes.forEach((item) => {
|
|
28
|
+
if (!item || id !== item.node.getAttribute("data-focus-id")) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (item.ariaHidden === null) {
|
|
32
|
+
item.node.removeAttribute("aria-hidden");
|
|
33
|
+
} else {
|
|
34
|
+
item.node.setAttribute("aria-hidden", item.ariaHidden);
|
|
35
|
+
}
|
|
36
|
+
item.node.removeAttribute("data-focus-id");
|
|
37
|
+
item.node.removeAttribute("data-hidden");
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export { createAriaHider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-aria-hider.js","sources":["../../src/use-focus-trap/create-aria-hider.ts"],"sourcesContent":["import { randomId } from '../utils';\n\ninterface Value {\n node: HTMLElement;\n ariaHidden: string | null;\n}\n\nexport function createAriaHider(\n containerNode: HTMLElement,\n selector: string = 'body > :not(script)'\n) {\n const id = randomId();\n\n const rootNodes: (Value | undefined)[] = Array.from<HTMLElement>(\n document.querySelectorAll(selector)\n ).map((node) => {\n if (node?.shadowRoot?.contains(containerNode) || node.contains(containerNode)) {\n return undefined;\n }\n\n const ariaHidden = node.getAttribute('aria-hidden');\n const prevAriaHidden = node.getAttribute('data-hidden');\n const prevFocusId = node.getAttribute('data-focus-id');\n\n node.setAttribute('data-focus-id', id);\n\n if (ariaHidden === null || ariaHidden === 'false') {\n node.setAttribute('aria-hidden', 'true');\n } else if (!prevAriaHidden && !prevFocusId) {\n node.setAttribute('data-hidden', ariaHidden);\n }\n\n return {\n node,\n ariaHidden: prevAriaHidden || null,\n };\n });\n\n return () => {\n rootNodes.forEach((item) => {\n if (!item || id !== item.node.getAttribute('data-focus-id')) {\n return;\n }\n\n if (item.ariaHidden === null) {\n item.node.removeAttribute('aria-hidden');\n } else {\n item.node.setAttribute('aria-hidden', item.ariaHidden);\n }\n\n item.node.removeAttribute('data-focus-id');\n item.node.removeAttribute('data-hidden');\n });\n };\n}\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"create-aria-hider.js","sources":["../../src/use-focus-trap/create-aria-hider.ts"],"sourcesContent":["import { randomId } from '../utils';\n\ninterface Value {\n node: HTMLElement;\n ariaHidden: string | null;\n}\n\nexport function createAriaHider(\n containerNode: HTMLElement,\n selector: string = 'body > :not(script)'\n) {\n const id = randomId();\n\n const rootNodes: (Value | undefined)[] = Array.from<HTMLElement>(\n document.querySelectorAll(selector)\n ).map((node) => {\n if (node?.shadowRoot?.contains(containerNode) || node.contains(containerNode)) {\n return undefined;\n }\n\n const ariaHidden = node.getAttribute('aria-hidden');\n const prevAriaHidden = node.getAttribute('data-hidden');\n const prevFocusId = node.getAttribute('data-focus-id');\n\n node.setAttribute('data-focus-id', id);\n\n if (ariaHidden === null || ariaHidden === 'false') {\n node.setAttribute('aria-hidden', 'true');\n } else if (!prevAriaHidden && !prevFocusId) {\n node.setAttribute('data-hidden', ariaHidden);\n }\n\n return {\n node,\n ariaHidden: prevAriaHidden || null,\n };\n });\n\n return () => {\n rootNodes.forEach((item) => {\n if (!item || id !== item.node.getAttribute('data-focus-id')) {\n return;\n }\n\n if (item.ariaHidden === null) {\n item.node.removeAttribute('aria-hidden');\n } else {\n item.node.setAttribute('aria-hidden', item.ariaHidden);\n }\n\n item.node.removeAttribute('data-focus-id');\n item.node.removeAttribute('data-hidden');\n });\n };\n}\n"],"names":[],"mappings":";;AACO,SAAS,eAAe,CAAC,aAAa,EAAE,QAAQ,GAAG,qBAAqB,EAAE;AACjF,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;AACxB,EAAE,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI;AAC9B,IAAI,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC;AACvC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK;AAClB,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,UAAU,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;AACxI,MAAM,OAAO,KAAK,CAAC,CAAC;AACpB,KAAK;AACL,IAAI,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;AACxD,IAAI,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;AAC5D,IAAI,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;AAC3D,IAAI,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;AAC3C,IAAI,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,OAAO,EAAE;AACvD,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAC/C,KAAK,MAAM,IAAI,CAAC,cAAc,IAAI,CAAC,WAAW,EAAE;AAChD,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,OAAO;AACX,MAAM,IAAI;AACV,MAAM,UAAU,EAAE,cAAc,IAAI,IAAI;AACxC,KAAK,CAAC;AACN,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,MAAM;AACf,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK;AAChC,MAAM,IAAI,CAAC,IAAI,IAAI,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE;AACnE,QAAQ,OAAO;AACf,OAAO;AACP,MAAM,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE;AACpC,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AACjD,OAAO,MAAM;AACb,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAC/D,OAAO;AACP,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;AACjD,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAC/C,KAAK,CAAC,CAAC;AACP,GAAG,CAAC;AACJ;;;;"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { findTabbableDescendants } from './tabbable.js';
|
|
2
2
|
|
|
3
3
|
function scopeTab(node, event) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
event.preventDefault();
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
|
|
10
|
-
const root = node.getRootNode();
|
|
11
|
-
const leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement;
|
|
12
|
-
if (!leavingFinalTabbable) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
4
|
+
const tabbable = findTabbableDescendants(node);
|
|
5
|
+
if (!tabbable.length) {
|
|
15
6
|
event.preventDefault();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
|
|
10
|
+
const root = node.getRootNode();
|
|
11
|
+
const leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement;
|
|
12
|
+
if (!leavingFinalTabbable) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
event.preventDefault();
|
|
16
|
+
const target = tabbable[event.shiftKey ? tabbable.length - 1 : 0];
|
|
17
|
+
if (target) {
|
|
18
|
+
target.focus();
|
|
19
|
+
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export { scopeTab };
|