@wordpress/compose 6.15.0 → 6.17.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/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/build/higher-order/compose.js +0 -2
- package/build/higher-order/compose.js.map +1 -1
- package/build/higher-order/if-condition/index.js +2 -6
- package/build/higher-order/if-condition/index.js.map +1 -1
- package/build/higher-order/pipe.js +1 -5
- package/build/higher-order/pipe.js.map +1 -1
- package/build/higher-order/pure/index.js +2 -10
- package/build/higher-order/pure/index.js.map +1 -1
- package/build/higher-order/with-global-events/index.js +13 -32
- package/build/higher-order/with-global-events/index.js.map +1 -1
- package/build/higher-order/with-global-events/listener.js +5 -28
- package/build/higher-order/with-global-events/listener.js.map +1 -1
- package/build/higher-order/with-instance-id/index.js +4 -8
- package/build/higher-order/with-instance-id/index.js.map +1 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +3 -6
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build/higher-order/with-safe-timeout/index.js +4 -14
- package/build/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build/higher-order/with-state/index.js +3 -11
- package/build/higher-order/with-state/index.js.map +1 -1
- package/build/hooks/use-async-list/index.js +1 -14
- package/build/hooks/use-async-list/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.js +14 -30
- package/build/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.native.js +4 -4
- package/build/hooks/use-constrained-tabbing/index.native.js.map +1 -1
- package/build/hooks/use-copy-on-click/index.js +6 -15
- package/build/hooks/use-copy-on-click/index.js.map +1 -1
- package/build/hooks/use-copy-to-clipboard/index.js +3 -11
- package/build/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build/hooks/use-debounce/index.js +0 -4
- package/build/hooks/use-debounce/index.js.map +1 -1
- package/build/hooks/use-dialog/index.js +2 -12
- package/build/hooks/use-dialog/index.js.map +1 -1
- package/build/hooks/use-disabled/index.js +5 -15
- package/build/hooks/use-disabled/index.js.map +1 -1
- package/build/hooks/use-dragging/index.js +4 -11
- package/build/hooks/use-dragging/index.js.map +1 -1
- package/build/hooks/use-drop-zone/index.js +27 -66
- package/build/hooks/use-drop-zone/index.js.map +1 -1
- package/build/hooks/use-fixed-window-list/index.js +8 -34
- package/build/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build/hooks/use-focus-on-mount/index.js +3 -14
- package/build/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.js +13 -19
- package/build/hooks/use-focus-outside/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.native.js +13 -21
- package/build/hooks/use-focus-outside/index.native.js.map +1 -1
- package/build/hooks/use-focus-return/index.js +14 -16
- package/build/hooks/use-focus-return/index.js.map +1 -1
- package/build/hooks/use-focusable-iframe/index.js +1 -5
- package/build/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build/hooks/use-instance-id/index.js +3 -5
- package/build/hooks/use-instance-id/index.js.map +1 -1
- package/build/hooks/use-isomorphic-layout-effect/index.js +0 -2
- package/build/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.js +12 -28
- package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.native.js +0 -2
- package/build/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
- package/build/hooks/use-media-query/index.js +1 -9
- package/build/hooks/use-media-query/index.js.map +1 -1
- package/build/hooks/use-merge-refs/index.js +18 -24
- package/build/hooks/use-merge-refs/index.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.android.js +0 -5
- package/build/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.ios.js +0 -2
- package/build/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme-style/index.native.js +2 -5
- package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
- package/build/hooks/use-previous/index.js +3 -4
- package/build/hooks/use-previous/index.js.map +1 -1
- package/build/hooks/use-reduced-motion/index.js +0 -4
- package/build/hooks/use-reduced-motion/index.js.map +1 -1
- package/build/hooks/use-ref-effect/index.js +0 -2
- package/build/hooks/use-ref-effect/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.js +23 -30
- package/build/hooks/use-resize-observer/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.native.js +0 -6
- package/build/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build/hooks/use-throttle/index.js +0 -4
- package/build/hooks/use-throttle/index.js.map +1 -1
- package/build/hooks/use-viewport-match/index.js +4 -13
- package/build/hooks/use-viewport-match/index.js.map +1 -1
- package/build/hooks/use-warn-on-change/index.js +4 -14
- package/build/hooks/use-warn-on-change/index.js.map +1 -1
- package/build/index.js +0 -41
- package/build/index.js.map +1 -1
- package/build/index.native.js +0 -33
- package/build/index.native.js.map +1 -1
- package/build/utils/create-higher-order-component/index.js +1 -4
- package/build/utils/create-higher-order-component/index.js.map +1 -1
- package/build/utils/debounce/index.js +12 -37
- package/build/utils/debounce/index.js.map +1 -1
- package/build/utils/throttle/index.js +0 -5
- package/build/utils/throttle/index.js.map +1 -1
- package/build-module/higher-order/compose.js +1 -1
- package/build-module/higher-order/compose.js.map +1 -1
- package/build-module/higher-order/if-condition/index.js +3 -5
- package/build-module/higher-order/if-condition/index.js.map +1 -1
- package/build-module/higher-order/pipe.js +1 -4
- package/build-module/higher-order/pipe.js.map +1 -1
- package/build-module/higher-order/pure/index.js +4 -8
- package/build-module/higher-order/pure/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/index.js +15 -29
- package/build-module/higher-order/with-global-events/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/listener.js +5 -27
- package/build-module/higher-order/with-global-events/listener.js.map +1 -1
- package/build-module/higher-order/with-instance-id/index.js +5 -5
- package/build-module/higher-order/with-instance-id/index.js.map +1 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js +3 -3
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build-module/higher-order/with-safe-timeout/index.js +6 -8
- package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build-module/higher-order/with-state/index.js +5 -9
- package/build-module/higher-order/with-state/index.js.map +1 -1
- package/build-module/hooks/use-async-list/index.js +1 -12
- package/build-module/hooks/use-async-list/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.js +16 -27
- package/build-module/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.native.js +3 -3
- package/build-module/hooks/use-constrained-tabbing/index.native.js.map +1 -1
- package/build-module/hooks/use-copy-on-click/index.js +8 -12
- package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js +6 -9
- package/build-module/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build-module/hooks/use-debounce/index.js +3 -3
- package/build-module/hooks/use-debounce/index.js.map +1 -1
- package/build-module/hooks/use-dialog/index.js +3 -5
- package/build-module/hooks/use-dialog/index.js.map +1 -1
- package/build-module/hooks/use-disabled/index.js +6 -12
- package/build-module/hooks/use-disabled/index.js.map +1 -1
- package/build-module/hooks/use-dragging/index.js +6 -9
- package/build-module/hooks/use-dragging/index.js.map +1 -1
- package/build-module/hooks/use-drop-zone/index.js +29 -64
- package/build-module/hooks/use-drop-zone/index.js.map +1 -1
- package/build-module/hooks/use-fixed-window-list/index.js +8 -30
- package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build-module/hooks/use-focus-on-mount/index.js +4 -12
- package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.js +14 -18
- package/build-module/hooks/use-focus-outside/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.native.js +14 -20
- package/build-module/hooks/use-focus-outside/index.native.js.map +1 -1
- package/build-module/hooks/use-focus-return/index.js +15 -15
- package/build-module/hooks/use-focus-return/index.js.map +1 -1
- package/build-module/hooks/use-focusable-iframe/index.js +2 -3
- package/build-module/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build-module/hooks/use-instance-id/index.js +2 -3
- package/build-module/hooks/use-instance-id/index.js.map +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.js +14 -24
- package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
- package/build-module/hooks/use-media-query/index.js +2 -8
- package/build-module/hooks/use-media-query/index.js.map +1 -1
- package/build-module/hooks/use-merge-refs/index.js +19 -23
- package/build-module/hooks/use-merge-refs/index.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.android.js +1 -3
- package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +3 -3
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
- package/build-module/hooks/use-previous/index.js +4 -3
- package/build-module/hooks/use-previous/index.js.map +1 -1
- package/build-module/hooks/use-reduced-motion/index.js +1 -2
- package/build-module/hooks/use-reduced-motion/index.js.map +1 -1
- package/build-module/hooks/use-ref-effect/index.js +1 -1
- package/build-module/hooks/use-ref-effect/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.js +22 -30
- package/build-module/hooks/use-resize-observer/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.native.js +1 -6
- package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build-module/hooks/use-throttle/index.js +3 -3
- package/build-module/hooks/use-throttle/index.js.map +1 -1
- package/build-module/hooks/use-viewport-match/index.js +6 -11
- package/build-module/hooks/use-viewport-match/index.js.map +1 -1
- package/build-module/hooks/use-warn-on-change/index.js +6 -12
- package/build-module/hooks/use-warn-on-change/index.js.map +1 -1
- package/build-module/index.js +10 -7
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +10 -7
- package/build-module/index.native.js.map +1 -1
- package/build-module/utils/create-higher-order-component/index.js +1 -2
- package/build-module/utils/create-higher-order-component/index.js.map +1 -1
- package/build-module/utils/debounce/index.js +12 -35
- package/build-module/utils/debounce/index.js.map +1 -1
- package/build-module/utils/throttle/index.js +0 -3
- package/build-module/utils/throttle/index.js.map +1 -1
- package/build-types/higher-order/with-instance-id/index.d.ts +1 -1
- package/build-types/higher-order/with-instance-id/index.d.ts.map +1 -1
- package/build-types/higher-order/with-safe-timeout/index.d.ts +1 -1
- package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +1 -1
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-return/index.d.ts +2 -4
- package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
- package/build-types/hooks/use-viewport-match/index.d.ts +1 -1
- package/package.json +8 -8
- package/src/higher-order/with-instance-id/index.tsx +2 -2
- package/src/higher-order/with-safe-timeout/index.tsx +2 -2
- package/src/hooks/use-focus-return/index.js +11 -6
- package/src/hooks/use-resize-observer/index.native.js +0 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
8
8
|
import { useCallback, useEffect, useRef } from '@wordpress/element';
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
11
|
* Input types which are classified as button types, for use in considering
|
|
11
12
|
* whether element is a (focus-normalized) button.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
const INPUT_BUTTON_TYPES = ['button', 'submit'];
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* List of HTML button elements subject to focus normalization
|
|
17
18
|
*
|
|
@@ -32,19 +33,15 @@ function isFocusNormalizedButton(eventTarget) {
|
|
|
32
33
|
if (!(eventTarget instanceof window.HTMLElement)) {
|
|
33
34
|
return false;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
36
|
switch (eventTarget.nodeName) {
|
|
37
37
|
case 'A':
|
|
38
38
|
case 'BUTTON':
|
|
39
39
|
return true;
|
|
40
|
-
|
|
41
40
|
case 'INPUT':
|
|
42
41
|
return INPUT_BUTTON_TYPES.includes(eventTarget.type);
|
|
43
42
|
}
|
|
44
|
-
|
|
45
43
|
return false;
|
|
46
44
|
}
|
|
47
|
-
|
|
48
45
|
/**
|
|
49
46
|
* A react hook that can be used to check whether focus has moved outside the
|
|
50
47
|
* element the event handlers are bound to.
|
|
@@ -62,23 +59,26 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
62
59
|
}, [onFocusOutside]);
|
|
63
60
|
const preventBlurCheck = useRef(false);
|
|
64
61
|
const blurCheckTimeoutId = useRef();
|
|
62
|
+
|
|
65
63
|
/**
|
|
66
64
|
* Cancel a blur check timeout.
|
|
67
65
|
*/
|
|
68
|
-
|
|
69
66
|
const cancelBlurCheck = useCallback(() => {
|
|
70
67
|
clearTimeout(blurCheckTimeoutId.current);
|
|
71
|
-
}, []);
|
|
68
|
+
}, []);
|
|
72
69
|
|
|
70
|
+
// Cancel blur checks on unmount.
|
|
73
71
|
useEffect(() => {
|
|
74
72
|
return () => cancelBlurCheck();
|
|
75
|
-
}, []);
|
|
73
|
+
}, []);
|
|
76
74
|
|
|
75
|
+
// Cancel a blur check if the callback or ref is no longer provided.
|
|
77
76
|
useEffect(() => {
|
|
78
77
|
if (!onFocusOutside) {
|
|
79
78
|
cancelBlurCheck();
|
|
80
79
|
}
|
|
81
80
|
}, [onFocusOutside, cancelBlurCheck]);
|
|
81
|
+
|
|
82
82
|
/**
|
|
83
83
|
* Handles a mousedown or mouseup event to respectively assign and
|
|
84
84
|
* unassign a flag for preventing blur check on button elements. Some
|
|
@@ -89,20 +89,19 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
89
89
|
* @param event
|
|
90
90
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
|
|
91
91
|
*/
|
|
92
|
-
|
|
93
92
|
const normalizeButtonFocus = useCallback(event => {
|
|
94
93
|
const {
|
|
95
94
|
type,
|
|
96
95
|
target
|
|
97
96
|
} = event;
|
|
98
97
|
const isInteractionEnd = ['mouseup', 'touchend'].includes(type);
|
|
99
|
-
|
|
100
98
|
if (isInteractionEnd) {
|
|
101
99
|
preventBlurCheck.current = false;
|
|
102
100
|
} else if (isFocusNormalizedButton(target)) {
|
|
103
101
|
preventBlurCheck.current = true;
|
|
104
102
|
}
|
|
105
103
|
}, []);
|
|
104
|
+
|
|
106
105
|
/**
|
|
107
106
|
* A callback triggered when a blur event occurs on the element the handler
|
|
108
107
|
* is bound to.
|
|
@@ -110,29 +109,27 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
110
109
|
* Calls the `onFocusOutside` callback in an immediate timeout if focus has
|
|
111
110
|
* move outside the bound element and is still within the document.
|
|
112
111
|
*/
|
|
113
|
-
|
|
114
112
|
const queueBlurCheck = useCallback(event => {
|
|
115
113
|
// React does not allow using an event reference asynchronously
|
|
116
114
|
// due to recycling behavior, except when explicitly persisted.
|
|
117
|
-
event.persist();
|
|
115
|
+
event.persist();
|
|
118
116
|
|
|
117
|
+
// Skip blur check if clicking button. See `normalizeButtonFocus`.
|
|
119
118
|
if (preventBlurCheck.current) {
|
|
120
119
|
return;
|
|
121
|
-
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The usage of this attribute should be avoided. The only use case
|
|
122
123
|
// would be when we load modals that are not React components and
|
|
123
124
|
// therefore don't exist in the React tree. An example is opening
|
|
124
125
|
// the Media Library modal from another dialog.
|
|
125
126
|
// This attribute should contain a selector of the related target
|
|
126
127
|
// we want to ignore, because we still need to trigger the blur event
|
|
127
128
|
// on all other cases.
|
|
128
|
-
|
|
129
|
-
|
|
130
129
|
const ignoreForRelatedTarget = event.target.getAttribute('data-unstable-ignore-focus-outside-for-relatedtarget');
|
|
131
|
-
|
|
132
130
|
if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) {
|
|
133
131
|
return;
|
|
134
132
|
}
|
|
135
|
-
|
|
136
133
|
blurCheckTimeoutId.current = setTimeout(() => {
|
|
137
134
|
// If document is not focused then focus should remain
|
|
138
135
|
// inside the wrapped component and therefore we cancel
|
|
@@ -142,7 +139,6 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
142
139
|
event.preventDefault();
|
|
143
140
|
return;
|
|
144
141
|
}
|
|
145
|
-
|
|
146
142
|
if ('function' === typeof currentOnFocusOutside.current) {
|
|
147
143
|
currentOnFocusOutside.current(event);
|
|
148
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useRef","INPUT_BUTTON_TYPES","isFocusNormalizedButton","eventTarget","window","HTMLElement","nodeName","includes","type","useFocusOutside","onFocusOutside","currentOnFocusOutside","current","preventBlurCheck","blurCheckTimeoutId","cancelBlurCheck","clearTimeout","normalizeButtonFocus","event","target","isInteractionEnd","queueBlurCheck","persist","ignoreForRelatedTarget","getAttribute","relatedTarget","closest","setTimeout","document","hasFocus","preventDefault","onFocus","onMouseDown","onMouseUp","onTouchStart","onTouchEnd","onBlur"],"sources":["@wordpress/compose/src/hooks/use-focus-outside/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tFocusEventHandler,\n\tEventHandler,\n\tMouseEventHandler,\n\tTouchEventHandler,\n\tFocusEvent,\n\tMouseEvent,\n\tTouchEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Input types which are classified as button types, for use in considering\n * whether element is a (focus-normalized) button.\n */\nconst INPUT_BUTTON_TYPES = [ 'button', 'submit' ];\n\n/**\n * List of HTML button elements subject to focus normalization\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n */\ntype FocusNormalizedButton =\n\t| HTMLButtonElement\n\t| HTMLLinkElement\n\t| HTMLInputElement;\n\n/**\n * Returns true if the given element is a button element subject to focus\n * normalization, or false otherwise.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n *\n * @param eventTarget The target from a mouse or touch event.\n *\n * @return Whether the element is a button element subject to focus normalization.\n */\nfunction isFocusNormalizedButton(\n\teventTarget: EventTarget\n): eventTarget is FocusNormalizedButton {\n\tif ( ! ( eventTarget instanceof window.HTMLElement ) ) {\n\t\treturn false;\n\t}\n\tswitch ( eventTarget.nodeName ) {\n\t\tcase 'A':\n\t\tcase 'BUTTON':\n\t\t\treturn true;\n\n\t\tcase 'INPUT':\n\t\t\treturn INPUT_BUTTON_TYPES.includes(\n\t\t\t\t( eventTarget as HTMLInputElement ).type\n\t\t\t);\n\t}\n\n\treturn false;\n}\n\ntype UseFocusOutsideReturn = {\n\tonFocus: FocusEventHandler;\n\tonMouseDown: MouseEventHandler;\n\tonMouseUp: MouseEventHandler;\n\tonTouchStart: TouchEventHandler;\n\tonTouchEnd: TouchEventHandler;\n\tonBlur: FocusEventHandler;\n};\n\n/**\n * A react hook that can be used to check whether focus has moved outside the\n * element the event handlers are bound to.\n *\n * @param onFocusOutside A callback triggered when focus moves outside\n * the element the event handlers are bound to.\n *\n * @return An object containing event handlers. Bind the event handlers to a\n * wrapping element element to capture when focus moves outside that element.\n */\nexport default function useFocusOutside(\n\tonFocusOutside: ( event: FocusEvent ) => void\n): UseFocusOutsideReturn {\n\tconst currentOnFocusOutside = useRef( onFocusOutside );\n\tuseEffect( () => {\n\t\tcurrentOnFocusOutside.current = onFocusOutside;\n\t}, [ onFocusOutside ] );\n\n\tconst preventBlurCheck = useRef( false );\n\n\tconst blurCheckTimeoutId = useRef< number | undefined >();\n\n\t/**\n\t * Cancel a blur check timeout.\n\t */\n\tconst cancelBlurCheck = useCallback( () => {\n\t\tclearTimeout( blurCheckTimeoutId.current );\n\t}, [] );\n\n\t// Cancel blur checks on unmount.\n\tuseEffect( () => {\n\t\treturn () => cancelBlurCheck();\n\t}, [] );\n\n\t// Cancel a blur check if the callback or ref is no longer provided.\n\tuseEffect( () => {\n\t\tif ( ! onFocusOutside ) {\n\t\t\tcancelBlurCheck();\n\t\t}\n\t}, [ onFocusOutside, cancelBlurCheck ] );\n\n\t/**\n\t * Handles a mousedown or mouseup event to respectively assign and\n\t * unassign a flag for preventing blur check on button elements. Some\n\t * browsers, namely Firefox and Safari, do not emit a focus event on\n\t * button elements when clicked, while others do. The logic here\n\t * intends to normalize this as treating click on buttons as focus.\n\t *\n\t * @param event\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\t */\n\tconst normalizeButtonFocus: EventHandler< MouseEvent | TouchEvent > =\n\t\tuseCallback( ( event ) => {\n\t\t\tconst { type, target } = event;\n\t\t\tconst isInteractionEnd = [ 'mouseup', 'touchend' ].includes( type );\n\n\t\t\tif ( isInteractionEnd ) {\n\t\t\t\tpreventBlurCheck.current = false;\n\t\t\t} else if ( isFocusNormalizedButton( target ) ) {\n\t\t\t\tpreventBlurCheck.current = true;\n\t\t\t}\n\t\t}, [] );\n\n\t/**\n\t * A callback triggered when a blur event occurs on the element the handler\n\t * is bound to.\n\t *\n\t * Calls the `onFocusOutside` callback in an immediate timeout if focus has\n\t * move outside the bound element and is still within the document.\n\t */\n\tconst queueBlurCheck: FocusEventHandler = useCallback( ( event ) => {\n\t\t// React does not allow using an event reference asynchronously\n\t\t// due to recycling behavior, except when explicitly persisted.\n\t\tevent.persist();\n\n\t\t// Skip blur check if clicking button. See `normalizeButtonFocus`.\n\t\tif ( preventBlurCheck.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The usage of this attribute should be avoided. The only use case\n\t\t// would be when we load modals that are not React components and\n\t\t// therefore don't exist in the React tree. An example is opening\n\t\t// the Media Library modal from another dialog.\n\t\t// This attribute should contain a selector of the related target\n\t\t// we want to ignore, because we still need to trigger the blur event\n\t\t// on all other cases.\n\t\tconst ignoreForRelatedTarget = event.target.getAttribute(\n\t\t\t'data-unstable-ignore-focus-outside-for-relatedtarget'\n\t\t);\n\t\tif (\n\t\t\tignoreForRelatedTarget &&\n\t\t\tevent.relatedTarget?.closest( ignoreForRelatedTarget )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tblurCheckTimeoutId.current = setTimeout( () => {\n\t\t\t// If document is not focused then focus should remain\n\t\t\t// inside the wrapped component and therefore we cancel\n\t\t\t// this blur event thereby leaving focus in place.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.\n\t\t\tif ( ! document.hasFocus() ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( 'function' === typeof currentOnFocusOutside.current ) {\n\t\t\t\tcurrentOnFocusOutside.current( event );\n\t\t\t}\n\t\t}, 0 );\n\t}, [] );\n\n\treturn {\n\t\tonFocus: cancelBlurCheck,\n\t\tonMouseDown: normalizeButtonFocus,\n\t\tonMouseUp: normalizeButtonFocus,\n\t\tonTouchStart: normalizeButtonFocus,\n\t\tonTouchEnd: normalizeButtonFocus,\n\t\tonBlur: queueBlurCheck,\n\t};\n}\n"],"mappings":"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"}
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useCallback, useEffect, useRef } from '@wordpress/element';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Input types which are classified as button types, for use in considering
|
|
7
8
|
* whether element is a (focus-normalized) button.
|
|
8
9
|
*
|
|
9
10
|
* @type {string[]}
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
12
|
const INPUT_BUTTON_TYPES = ['button', 'submit'];
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* @typedef {HTMLButtonElement | HTMLLinkElement | HTMLInputElement} FocusNormalizedButton
|
|
15
16
|
*/
|
|
16
|
-
// Disable reason: Rule doesn't support predicate return types.
|
|
17
17
|
|
|
18
|
+
// Disable reason: Rule doesn't support predicate return types.
|
|
18
19
|
/* eslint-disable jsdoc/valid-types */
|
|
19
|
-
|
|
20
20
|
/**
|
|
21
21
|
* Returns true if the given element is a button element subject to focus
|
|
22
22
|
* normalization, or false otherwise.
|
|
@@ -27,19 +27,14 @@ const INPUT_BUTTON_TYPES = ['button', 'submit'];
|
|
|
27
27
|
*
|
|
28
28
|
* @return {eventTarget is FocusNormalizedButton} Whether element is a button.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
function isFocusNormalizedButton(eventTarget) {
|
|
32
31
|
switch (eventTarget.nodeName) {
|
|
33
32
|
case 'A':
|
|
34
33
|
case 'BUTTON':
|
|
35
34
|
return true;
|
|
36
|
-
|
|
37
35
|
case 'INPUT':
|
|
38
|
-
return INPUT_BUTTON_TYPES.includes(
|
|
39
|
-
/** @type {HTMLInputElement} */
|
|
40
|
-
eventTarget.type);
|
|
36
|
+
return INPUT_BUTTON_TYPES.includes( /** @type {HTMLInputElement} */eventTarget.type);
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
return false;
|
|
44
39
|
}
|
|
45
40
|
/* eslint-enable jsdoc/valid-types */
|
|
@@ -83,36 +78,37 @@ function isFocusNormalizedButton(eventTarget) {
|
|
|
83
78
|
* to a wrapping element element to capture when focus moves
|
|
84
79
|
* outside that element.
|
|
85
80
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
81
|
export default function useFocusOutside(onFocusOutside) {
|
|
89
82
|
const currentOnFocusOutside = useRef(onFocusOutside);
|
|
90
83
|
useEffect(() => {
|
|
91
84
|
currentOnFocusOutside.current = onFocusOutside;
|
|
92
85
|
}, [onFocusOutside]);
|
|
93
86
|
const preventBlurCheck = useRef(false);
|
|
87
|
+
|
|
94
88
|
/**
|
|
95
89
|
* @type {import('react').MutableRefObject<number | undefined>}
|
|
96
90
|
*/
|
|
97
|
-
|
|
98
91
|
const blurCheckTimeoutId = useRef();
|
|
92
|
+
|
|
99
93
|
/**
|
|
100
94
|
* Cancel a blur check timeout.
|
|
101
95
|
*/
|
|
102
|
-
|
|
103
96
|
const cancelBlurCheck = useCallback(() => {
|
|
104
97
|
clearTimeout(blurCheckTimeoutId.current);
|
|
105
|
-
}, []);
|
|
98
|
+
}, []);
|
|
106
99
|
|
|
100
|
+
// Cancel blur checks on unmount.
|
|
107
101
|
useEffect(() => {
|
|
108
102
|
return () => cancelBlurCheck();
|
|
109
|
-
}, []);
|
|
103
|
+
}, []);
|
|
110
104
|
|
|
105
|
+
// Cancel a blur check if the callback or ref is no longer provided.
|
|
111
106
|
useEffect(() => {
|
|
112
107
|
if (!onFocusOutside) {
|
|
113
108
|
cancelBlurCheck();
|
|
114
109
|
}
|
|
115
110
|
}, [onFocusOutside, cancelBlurCheck]);
|
|
111
|
+
|
|
116
112
|
/**
|
|
117
113
|
* Handles a mousedown or mouseup event to respectively assign and
|
|
118
114
|
* unassign a flag for preventing blur check on button elements. Some
|
|
@@ -124,20 +120,19 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
124
120
|
*
|
|
125
121
|
* @param {SyntheticEvent} event Event for mousedown or mouseup.
|
|
126
122
|
*/
|
|
127
|
-
|
|
128
123
|
const normalizeButtonFocus = useCallback(event => {
|
|
129
124
|
const {
|
|
130
125
|
type,
|
|
131
126
|
target
|
|
132
127
|
} = event;
|
|
133
128
|
const isInteractionEnd = ['mouseup', 'touchend'].includes(type);
|
|
134
|
-
|
|
135
129
|
if (isInteractionEnd) {
|
|
136
130
|
preventBlurCheck.current = false;
|
|
137
131
|
} else if (isFocusNormalizedButton(target)) {
|
|
138
132
|
preventBlurCheck.current = true;
|
|
139
133
|
}
|
|
140
134
|
}, []);
|
|
135
|
+
|
|
141
136
|
/**
|
|
142
137
|
* A callback triggered when a blur event occurs on the element the handler
|
|
143
138
|
* is bound to.
|
|
@@ -147,16 +142,15 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
147
142
|
*
|
|
148
143
|
* @param {SyntheticEvent} event Blur event.
|
|
149
144
|
*/
|
|
150
|
-
|
|
151
145
|
const queueBlurCheck = useCallback(event => {
|
|
152
146
|
// React does not allow using an event reference asynchronously
|
|
153
147
|
// due to recycling behavior, except when explicitly persisted.
|
|
154
|
-
event.persist();
|
|
148
|
+
event.persist();
|
|
155
149
|
|
|
150
|
+
// Skip blur check if clicking button. See `normalizeButtonFocus`.
|
|
156
151
|
if (preventBlurCheck.current) {
|
|
157
152
|
return;
|
|
158
153
|
}
|
|
159
|
-
|
|
160
154
|
blurCheckTimeoutId.current = setTimeout(() => {
|
|
161
155
|
if ('function' === typeof currentOnFocusOutside.current) {
|
|
162
156
|
currentOnFocusOutside.current(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useRef","INPUT_BUTTON_TYPES","isFocusNormalizedButton","eventTarget","nodeName","includes","type","useFocusOutside","onFocusOutside","currentOnFocusOutside","current","preventBlurCheck","blurCheckTimeoutId","cancelBlurCheck","clearTimeout","normalizeButtonFocus","event","target","isInteractionEnd","queueBlurCheck","persist","setTimeout","onFocus","onMouseDown","onMouseUp","onTouchStart","onTouchEnd","onBlur"],"sources":["@wordpress/compose/src/hooks/use-focus-outside/index.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Input types which are classified as button types, for use in considering\n * whether element is a (focus-normalized) button.\n *\n * @type {string[]}\n */\nconst INPUT_BUTTON_TYPES = [ 'button', 'submit' ];\n\n/**\n * @typedef {HTMLButtonElement | HTMLLinkElement | HTMLInputElement} FocusNormalizedButton\n */\n\n// Disable reason: Rule doesn't support predicate return types.\n/* eslint-disable jsdoc/valid-types */\n/**\n * Returns true if the given element is a button element subject to focus\n * normalization, or false otherwise.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n *\n * @param {EventTarget} eventTarget The target from a mouse or touch event.\n *\n * @return {eventTarget is FocusNormalizedButton} Whether element is a button.\n */\nfunction isFocusNormalizedButton( eventTarget ) {\n\tswitch ( eventTarget.nodeName ) {\n\t\tcase 'A':\n\t\tcase 'BUTTON':\n\t\t\treturn true;\n\n\t\tcase 'INPUT':\n\t\t\treturn INPUT_BUTTON_TYPES.includes(\n\t\t\t\t/** @type {HTMLInputElement} */ ( eventTarget ).type\n\t\t\t);\n\t}\n\n\treturn false;\n}\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * @typedef {import('react').SyntheticEvent} SyntheticEvent\n */\n\n/**\n * @callback EventCallback\n * @param {SyntheticEvent} event input related event.\n */\n\n/**\n * @typedef FocusOutsideReactElement\n * @property {EventCallback} handleFocusOutside callback for a focus outside event.\n */\n\n/**\n * @typedef {import('react').MutableRefObject<FocusOutsideReactElement | undefined>} FocusOutsideRef\n */\n\n/**\n * @typedef {Object} FocusOutsideReturnValue\n * @property {EventCallback} onFocus An event handler for focus events.\n * @property {EventCallback} onBlur An event handler for blur events.\n * @property {EventCallback} onMouseDown An event handler for mouse down events.\n * @property {EventCallback} onMouseUp An event handler for mouse up events.\n * @property {EventCallback} onTouchStart An event handler for touch start events.\n * @property {EventCallback} onTouchEnd An event handler for touch end events.\n */\n\n/**\n * A react hook that can be used to check whether focus has moved outside the\n * element the event handlers are bound to.\n *\n * @param {EventCallback} onFocusOutside A callback triggered when focus moves outside\n * the element the event handlers are bound to.\n *\n * @return {FocusOutsideReturnValue} An object containing event handlers. Bind the event handlers\n * to a wrapping element element to capture when focus moves\n * outside that element.\n */\nexport default function useFocusOutside( onFocusOutside ) {\n\tconst currentOnFocusOutside = useRef( onFocusOutside );\n\tuseEffect( () => {\n\t\tcurrentOnFocusOutside.current = onFocusOutside;\n\t}, [ onFocusOutside ] );\n\n\tconst preventBlurCheck = useRef( false );\n\n\t/**\n\t * @type {import('react').MutableRefObject<number | undefined>}\n\t */\n\tconst blurCheckTimeoutId = useRef();\n\n\t/**\n\t * Cancel a blur check timeout.\n\t */\n\tconst cancelBlurCheck = useCallback( () => {\n\t\tclearTimeout( blurCheckTimeoutId.current );\n\t}, [] );\n\n\t// Cancel blur checks on unmount.\n\tuseEffect( () => {\n\t\treturn () => cancelBlurCheck();\n\t}, [] );\n\n\t// Cancel a blur check if the callback or ref is no longer provided.\n\tuseEffect( () => {\n\t\tif ( ! onFocusOutside ) {\n\t\t\tcancelBlurCheck();\n\t\t}\n\t}, [ onFocusOutside, cancelBlurCheck ] );\n\n\t/**\n\t * Handles a mousedown or mouseup event to respectively assign and\n\t * unassign a flag for preventing blur check on button elements. Some\n\t * browsers, namely Firefox and Safari, do not emit a focus event on\n\t * button elements when clicked, while others do. The logic here\n\t * intends to normalize this as treating click on buttons as focus.\n\t *\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\t *\n\t * @param {SyntheticEvent} event Event for mousedown or mouseup.\n\t */\n\tconst normalizeButtonFocus = useCallback( ( event ) => {\n\t\tconst { type, target } = event;\n\t\tconst isInteractionEnd = [ 'mouseup', 'touchend' ].includes( type );\n\n\t\tif ( isInteractionEnd ) {\n\t\t\tpreventBlurCheck.current = false;\n\t\t} else if ( isFocusNormalizedButton( target ) ) {\n\t\t\tpreventBlurCheck.current = true;\n\t\t}\n\t}, [] );\n\n\t/**\n\t * A callback triggered when a blur event occurs on the element the handler\n\t * is bound to.\n\t *\n\t * Calls the `onFocusOutside` callback in an immediate timeout if focus has\n\t * move outside the bound element and is still within the document.\n\t *\n\t * @param {SyntheticEvent} event Blur event.\n\t */\n\tconst queueBlurCheck = useCallback( ( event ) => {\n\t\t// React does not allow using an event reference asynchronously\n\t\t// due to recycling behavior, except when explicitly persisted.\n\t\tevent.persist();\n\n\t\t// Skip blur check if clicking button. See `normalizeButtonFocus`.\n\t\tif ( preventBlurCheck.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tblurCheckTimeoutId.current = setTimeout( () => {\n\t\t\tif ( 'function' === typeof currentOnFocusOutside.current ) {\n\t\t\t\tcurrentOnFocusOutside.current( event );\n\t\t\t}\n\t\t}, 0 );\n\t}, [] );\n\n\treturn {\n\t\tonFocus: cancelBlurCheck,\n\t\tonMouseDown: normalizeButtonFocus,\n\t\tonMouseUp: normalizeButtonFocus,\n\t\tonTouchStart: normalizeButtonFocus,\n\t\tonTouchEnd: normalizeButtonFocus,\n\t\tonBlur: queueBlurCheck,\n\t};\n}\n"],"mappings":"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"}
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useRef, useEffect, useCallback } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/** @type {Element|null} */
|
|
7
|
+
let origin = null;
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* previously focused element when closed.
|
|
9
|
-
* The current hook implements the returning behavior.
|
|
10
|
+
* Adds the unmount behavior of returning focus to the element which had it
|
|
11
|
+
* previously as is expected for roles like menus or dialogs.
|
|
10
12
|
*
|
|
11
13
|
* @param {() => void} [onFocusReturn] Overrides the default return behavior.
|
|
12
14
|
* @return {import('react').RefCallback<HTMLElement>} Element Ref.
|
|
@@ -26,12 +28,10 @@ import { useRef, useEffect, useCallback } from '@wordpress/element';
|
|
|
26
28
|
* }
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
|
-
|
|
30
31
|
function useFocusReturn(onFocusReturn) {
|
|
31
32
|
/** @type {import('react').MutableRefObject<null | HTMLElement>} */
|
|
32
33
|
const ref = useRef(null);
|
|
33
34
|
/** @type {import('react').MutableRefObject<null | Element>} */
|
|
34
|
-
|
|
35
35
|
const focusedBeforeMount = useRef(null);
|
|
36
36
|
const onFocusReturnRef = useRef(onFocusReturn);
|
|
37
37
|
useEffect(() => {
|
|
@@ -40,33 +40,33 @@ function useFocusReturn(onFocusReturn) {
|
|
|
40
40
|
return useCallback(node => {
|
|
41
41
|
if (node) {
|
|
42
42
|
// Set ref to be used when unmounting.
|
|
43
|
-
ref.current = node;
|
|
43
|
+
ref.current = node;
|
|
44
44
|
|
|
45
|
+
// Only set when the node mounts.
|
|
45
46
|
if (focusedBeforeMount.current) {
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
|
-
|
|
49
49
|
focusedBeforeMount.current = node.ownerDocument.activeElement;
|
|
50
50
|
} else if (focusedBeforeMount.current) {
|
|
51
51
|
const isFocused = ref.current?.contains(ref.current?.ownerDocument.activeElement);
|
|
52
|
-
|
|
53
52
|
if (ref.current?.isConnected && !isFocused) {
|
|
53
|
+
var _origin;
|
|
54
|
+
(_origin = origin) !== null && _origin !== void 0 ? _origin : origin = focusedBeforeMount.current;
|
|
54
55
|
return;
|
|
55
|
-
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Defer to the component's own explicit focus return behavior, if
|
|
56
59
|
// specified. This allows for support that the `onFocusReturn`
|
|
57
60
|
// decides to allow the default behavior to occur under some
|
|
58
61
|
// conditions.
|
|
59
|
-
|
|
60
|
-
|
|
61
62
|
if (onFocusReturnRef.current) {
|
|
62
63
|
onFocusReturnRef.current();
|
|
63
64
|
} else {
|
|
64
|
-
/** @type {null
|
|
65
|
-
focusedBeforeMount.current?.focus();
|
|
65
|
+
/** @type {null|HTMLElement} */(!focusedBeforeMount.current.isConnected ? origin : focusedBeforeMount.current)?.focus();
|
|
66
66
|
}
|
|
67
|
+
origin = null;
|
|
67
68
|
}
|
|
68
69
|
}, []);
|
|
69
70
|
}
|
|
70
|
-
|
|
71
71
|
export default useFocusReturn;
|
|
72
72
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useRef","useEffect","useCallback","origin","useFocusReturn","onFocusReturn","ref","focusedBeforeMount","onFocusReturnRef","current","node","ownerDocument","activeElement","isFocused","contains","isConnected","_origin","focus"],"sources":["@wordpress/compose/src/hooks/use-focus-return/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\n/** @type {Element|null} */\nlet origin = null;\n\n/**\n * Adds the unmount behavior of returning focus to the element which had it\n * previously as is expected for roles like menus or dialogs.\n *\n * @param {() => void} [onFocusReturn] Overrides the default return behavior.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useFocusReturn } from '@wordpress/compose';\n *\n * const WithFocusReturn = () => {\n * const ref = useFocusReturn()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useFocusReturn( onFocusReturn ) {\n\t/** @type {import('react').MutableRefObject<null | HTMLElement>} */\n\tconst ref = useRef( null );\n\t/** @type {import('react').MutableRefObject<null | Element>} */\n\tconst focusedBeforeMount = useRef( null );\n\tconst onFocusReturnRef = useRef( onFocusReturn );\n\tuseEffect( () => {\n\t\tonFocusReturnRef.current = onFocusReturn;\n\t}, [ onFocusReturn ] );\n\n\treturn useCallback( ( node ) => {\n\t\tif ( node ) {\n\t\t\t// Set ref to be used when unmounting.\n\t\t\tref.current = node;\n\n\t\t\t// Only set when the node mounts.\n\t\t\tif ( focusedBeforeMount.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfocusedBeforeMount.current = node.ownerDocument.activeElement;\n\t\t} else if ( focusedBeforeMount.current ) {\n\t\t\tconst isFocused = ref.current?.contains(\n\t\t\t\tref.current?.ownerDocument.activeElement\n\t\t\t);\n\n\t\t\tif ( ref.current?.isConnected && ! isFocused ) {\n\t\t\t\torigin ??= focusedBeforeMount.current;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Defer to the component's own explicit focus return behavior, if\n\t\t\t// specified. This allows for support that the `onFocusReturn`\n\t\t\t// decides to allow the default behavior to occur under some\n\t\t\t// conditions.\n\t\t\tif ( onFocusReturnRef.current ) {\n\t\t\t\tonFocusReturnRef.current();\n\t\t\t} else {\n\t\t\t\t/** @type {null|HTMLElement} */ (\n\t\t\t\t\t! focusedBeforeMount.current.isConnected\n\t\t\t\t\t\t? origin\n\t\t\t\t\t\t: focusedBeforeMount.current\n\t\t\t\t)?.focus();\n\t\t\t}\n\t\t\torigin = null;\n\t\t}\n\t}, [] );\n}\n\nexport default useFocusReturn;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,SAAS,EAAEC,WAAW,QAAQ,oBAAoB;;AAEnE;AACA,IAAIC,MAAM,GAAG,IAAI;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAAEC,aAAa,EAAG;EACxC;EACA,MAAMC,GAAG,GAAGN,MAAM,CAAE,IAAK,CAAC;EAC1B;EACA,MAAMO,kBAAkB,GAAGP,MAAM,CAAE,IAAK,CAAC;EACzC,MAAMQ,gBAAgB,GAAGR,MAAM,CAAEK,aAAc,CAAC;EAChDJ,SAAS,CAAE,MAAM;IAChBO,gBAAgB,CAACC,OAAO,GAAGJ,aAAa;EACzC,CAAC,EAAE,CAAEA,aAAa,CAAG,CAAC;EAEtB,OAAOH,WAAW,CAAIQ,IAAI,IAAM;IAC/B,IAAKA,IAAI,EAAG;MACX;MACAJ,GAAG,CAACG,OAAO,GAAGC,IAAI;;MAElB;MACA,IAAKH,kBAAkB,CAACE,OAAO,EAAG;QACjC;MACD;MAEAF,kBAAkB,CAACE,OAAO,GAAGC,IAAI,CAACC,aAAa,CAACC,aAAa;IAC9D,CAAC,MAAM,IAAKL,kBAAkB,CAACE,OAAO,EAAG;MACxC,MAAMI,SAAS,GAAGP,GAAG,CAACG,OAAO,EAAEK,QAAQ,CACtCR,GAAG,CAACG,OAAO,EAAEE,aAAa,CAACC,aAC5B,CAAC;MAED,IAAKN,GAAG,CAACG,OAAO,EAAEM,WAAW,IAAI,CAAEF,SAAS,EAAG;QAAA,IAAAG,OAAA;QAC9C,CAAAA,OAAA,GAAAb,MAAM,cAAAa,OAAA,cAAAA,OAAA,GAANb,MAAM,GAAKI,kBAAkB,CAACE,OAAO;QACrC;MACD;;MAEA;MACA;MACA;MACA;MACA,IAAKD,gBAAgB,CAACC,OAAO,EAAG;QAC/BD,gBAAgB,CAACC,OAAO,CAAC,CAAC;MAC3B,CAAC,MAAM;QACN,+BAAgC,CAC/B,CAAEF,kBAAkB,CAACE,OAAO,CAACM,WAAW,GACrCZ,MAAM,GACNI,kBAAkB,CAACE,OAAO,GAC3BQ,KAAK,CAAC,CAAC;MACX;MACAd,MAAM,GAAG,IAAI;IACd;EACD,CAAC,EAAE,EAAG,CAAC;AACR;AAEA,eAAeC,cAAc"}
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
* Internal dependencies
|
|
7
7
|
*/
|
|
8
8
|
import useRefEffect from '../use-ref-effect';
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
11
|
* Dispatches a bubbling focus event when the iframe receives focus. Use
|
|
11
12
|
* `onFocus` as usual on the iframe or a parent element.
|
|
12
13
|
*
|
|
13
14
|
* @return Ref to pass to the iframe.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
16
|
export default function useFocusableIframe() {
|
|
17
17
|
return useRefEffect(element => {
|
|
18
18
|
const {
|
|
@@ -23,17 +23,16 @@ export default function useFocusableIframe() {
|
|
|
23
23
|
defaultView
|
|
24
24
|
} = ownerDocument;
|
|
25
25
|
if (!defaultView) return;
|
|
26
|
+
|
|
26
27
|
/**
|
|
27
28
|
* Checks whether the iframe is the activeElement, inferring that it has
|
|
28
29
|
* then received focus, and dispatches a focus event.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
31
|
function checkFocus() {
|
|
32
32
|
if (ownerDocument && ownerDocument.activeElement === element) {
|
|
33
33
|
element.focus();
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
37
36
|
defaultView.addEventListener('blur', checkFocus);
|
|
38
37
|
return () => {
|
|
39
38
|
defaultView.removeEventListener('blur', checkFocus);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useRefEffect","useFocusableIframe","element","ownerDocument","defaultView","checkFocus","activeElement","focus","addEventListener","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Dispatches a bubbling focus event when the iframe receives focus. Use\n * `onFocus` as usual on the iframe or a parent element.\n *\n * @return Ref to pass to the iframe.\n */\nexport default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {\n\treturn useRefEffect( ( element ) => {\n\t\tconst { ownerDocument } = element;\n\t\tif ( ! ownerDocument ) return;\n\t\tconst { defaultView } = ownerDocument;\n\t\tif ( ! defaultView ) return;\n\n\t\t/**\n\t\t * Checks whether the iframe is the activeElement, inferring that it has\n\t\t * then received focus, and dispatches a focus event.\n\t\t */\n\t\tfunction checkFocus() {\n\t\t\tif ( ownerDocument && ownerDocument.activeElement === element ) {\n\t\t\t\t( element as HTMLElement ).focus();\n\t\t\t}\n\t\t}\n\n\t\tdefaultView.addEventListener( 'blur', checkFocus );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'blur', checkFocus );\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAOA,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CAAA,EAAqC;EAC9E,OAAOD,YAAY,CAAIE,OAAO,IAAM;IACnC,MAAM;MAAEC;IAAc,CAAC,GAAGD,OAAO;IACjC,IAAK,CAAEC,aAAa,EAAG;IACvB,MAAM;MAAEC;IAAY,CAAC,GAAGD,aAAa;IACrC,IAAK,CAAEC,WAAW,EAAG;;IAErB;AACF;AACA;AACA;IACE,SAASC,UAAUA,CAAA,EAAG;MACrB,IAAKF,aAAa,IAAIA,aAAa,CAACG,aAAa,KAAKJ,OAAO,EAAG;QAC7DA,OAAO,CAAkBK,KAAK,CAAC,CAAC;MACnC;IACD;IAEAH,WAAW,CAACI,gBAAgB,CAAE,MAAM,EAAEH,UAAW,CAAC;IAClD,OAAO,MAAM;MACZD,WAAW,CAACK,mBAAmB,CAAE,MAAM,EAAEJ,UAAW,CAAC;IACtD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR"}
|
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useMemo } from '@wordpress/element';
|
|
5
5
|
const instanceMap = new WeakMap();
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Creates a new id for a given object.
|
|
8
9
|
*
|
|
9
10
|
* @param object Object reference to create an id for.
|
|
10
11
|
* @return The instance id (index).
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
13
|
function createId(object) {
|
|
14
14
|
const instances = instanceMap.get(object) || 0;
|
|
15
15
|
instanceMap.set(object, instances + 1);
|
|
16
16
|
return instances;
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* Specify the useInstanceId *function* signatures.
|
|
20
21
|
*
|
|
@@ -28,7 +29,6 @@ function createId(object) {
|
|
|
28
29
|
* @param object Object reference to create an id for.
|
|
29
30
|
*/
|
|
30
31
|
|
|
31
|
-
|
|
32
32
|
/**
|
|
33
33
|
* Provides a unique instance ID.
|
|
34
34
|
*
|
|
@@ -44,6 +44,5 @@ function useInstanceId(object, prefix, preferredId) {
|
|
|
44
44
|
return prefix ? `${prefix}-${id}` : id;
|
|
45
45
|
}, [object, preferredId, prefix]);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
47
|
export default useInstanceId;
|
|
49
48
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useMemo","instanceMap","WeakMap","createId","object","instances","get","set","useInstanceId","prefix","preferredId","id"],"sources":["@wordpress/compose/src/hooks/use-instance-id/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n *\n * @param object Object reference to create an id for.\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) return preferredId;\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object, preferredId, prefix ] );\n}\n\nexport default useInstanceId;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAE5C,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAmB,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,MAAc,EAAW;EAC3C,MAAMC,SAAS,GAAGJ,WAAW,CAACK,GAAG,CAAEF,MAAO,CAAC,IAAI,CAAC;EAChDH,WAAW,CAACM,GAAG,CAAEH,MAAM,EAAEC,SAAS,GAAG,CAAE,CAAC;EACxC,OAAOA,SAAS;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CACrBJ,MAAc,EACdK,MAAe,EACfC,WAA6B,EACX;EAClB,OAAOV,OAAO,CAAE,MAAM;IACrB,IAAKU,WAAW,EAAG,OAAOA,WAAW;IACrC,MAAMC,EAAE,GAAGR,QAAQ,CAAEC,MAAO,CAAC;IAE7B,OAAOK,MAAM,GAAI,GAAGA,MAAQ,IAAIE,EAAI,EAAC,GAAGA,EAAE;EAC3C,CAAC,EAAE,CAAEP,MAAM,EAAEM,WAAW,EAAED,MAAM,CAAG,CAAC;AACrC;AAEA,eAAeD,aAAa"}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useEffect, useLayoutEffect } from '@wordpress/element';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Preferred over direct usage of `useLayoutEffect` when supporting
|
|
7
8
|
* server rendered components (SSR) because currently React
|
|
8
9
|
* throws a warning when using useLayoutEffect in that environment.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
12
12
|
export default useIsomorphicLayoutEffect;
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-isomorphic-layout-effect/index.js"],"
|
|
1
|
+
{"version":3,"names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","window"],"sources":["@wordpress/compose/src/hooks/use-isomorphic-layout-effect/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useLayoutEffect } from '@wordpress/element';\n\n/**\n * Preferred over direct usage of `useLayoutEffect` when supporting\n * server rendered components (SSR) because currently React\n * throws a warning when using useLayoutEffect in that environment.\n */\nconst useIsomorphicLayoutEffect =\n\ttypeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,eAAe,QAAQ,oBAAoB;;AAE/D;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,GAC9B,OAAOC,MAAM,KAAK,WAAW,GAAGF,eAAe,GAAGD,SAAS;AAE5D,eAAeE,yBAAyB"}
|