@wordpress/compose 5.17.0 → 5.19.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 +10 -0
- package/README.md +4 -1
- package/build/hooks/use-dialog/index.js.map +1 -1
- package/build/hooks/use-disabled/index.js +10 -98
- package/build/hooks/use-disabled/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.js +15 -56
- package/build/hooks/use-focus-outside/index.js.map +1 -1
- package/build/hooks/use-focusable-iframe/index.js +5 -2
- package/build/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.native.js +1 -0
- package/build/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build-module/hooks/use-dialog/index.js.map +1 -1
- package/build-module/hooks/use-disabled/index.js +10 -97
- package/build-module/hooks/use-disabled/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.js +15 -56
- package/build-module/hooks/use-focus-outside/index.js.map +1 -1
- package/build-module/hooks/use-focusable-iframe/index.js +5 -2
- package/build-module/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.native.js +1 -0
- package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build-types/hooks/use-dialog/index.d.ts +2 -2
- package/build-types/hooks/use-dialog/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +4 -1
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-outside/index.d.ts +16 -63
- package/build-types/hooks/use-focus-outside/index.d.ts.map +1 -1
- package/build-types/hooks/use-focusable-iframe/index.d.ts +6 -2
- package/build-types/hooks/use-focusable-iframe/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/higher-order/with-global-events/test/index.js +18 -29
- package/src/higher-order/with-state/test/index.js +13 -26
- package/src/hooks/use-dialog/index.ts +3 -4
- package/src/hooks/use-disabled/index.ts +81 -0
- package/src/hooks/use-disabled/test/index.js +4 -36
- package/src/hooks/use-focus-outside/{index.js → index.ts} +55 -62
- package/src/hooks/use-focus-outside/test/index.js +112 -84
- package/src/hooks/use-focusable-iframe/{index.js → index.ts} +8 -3
- package/src/hooks/use-instance-id/test/index.js +9 -16
- package/src/hooks/use-media-query/test/index.js +33 -53
- package/src/hooks/use-resize-observer/index.native.js +5 -1
- package/src/hooks/use-resize-observer/test/index.native.js +18 -22
- package/src/hooks/use-viewport-match/test/index.js +78 -78
- package/tsconfig.tsbuildinfo +1 -1
- package/src/hooks/use-disabled/index.js +0 -197
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { focus } from '@wordpress/dom';
|
|
5
1
|
/**
|
|
6
2
|
* Internal dependencies
|
|
7
3
|
*/
|
|
8
|
-
|
|
9
4
|
import { debounce } from '../../utils/debounce';
|
|
10
5
|
import useRefEffect from '../use-ref-effect';
|
|
11
|
-
/**
|
|
12
|
-
* Names of control nodes which qualify for disabled behavior.
|
|
13
|
-
*
|
|
14
|
-
* See WHATWG HTML Standard: 4.10.18.5: "Enabling and disabling form controls: the disabled attribute".
|
|
15
|
-
*
|
|
16
|
-
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute
|
|
17
|
-
*
|
|
18
|
-
* @type {string[]}
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP', 'OPTION', 'SELECT', 'TEXTAREA'];
|
|
22
6
|
/**
|
|
23
7
|
* In some circumstances, such as block previews, all focusable DOM elements
|
|
24
8
|
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
25
9
|
* behavior to disable nested DOM elements to the returned ref.
|
|
26
10
|
*
|
|
11
|
+
* If you can, prefer the use of the inert HTML attribute.
|
|
12
|
+
*
|
|
27
13
|
* @param {Object} config Configuration object.
|
|
28
14
|
* @param {boolean=} config.isDisabled Whether the element should be disabled.
|
|
29
15
|
* @return {import('react').RefCallback<HTMLElement>} Element Ref.
|
|
@@ -31,6 +17,7 @@ const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP',
|
|
|
31
17
|
* @example
|
|
32
18
|
* ```js
|
|
33
19
|
* import { useDisabled } from '@wordpress/compose';
|
|
20
|
+
*
|
|
34
21
|
* const DisabledExample = () => {
|
|
35
22
|
* const disabledRef = useDisabled();
|
|
36
23
|
* return (
|
|
@@ -53,91 +40,19 @@ export default function useDisabled() {
|
|
|
53
40
|
}
|
|
54
41
|
/** A variable keeping track of the previous updates in order to restore them. */
|
|
55
42
|
|
|
56
|
-
/** @type {Function[]} */
|
|
57
|
-
|
|
58
43
|
|
|
59
44
|
const updates = [];
|
|
60
45
|
|
|
61
46
|
const disable = () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
node.style.setProperty('-webkit-user-select', 'none');
|
|
66
|
-
updates.push(() => {
|
|
67
|
-
if (!node.isConnected) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
node.style.setProperty('user-select', previousValue);
|
|
72
|
-
node.style.setProperty('-webkit-user-select', previousValue);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
focus.focusable.find(node).forEach(focusable => {
|
|
77
|
-
var _node$ownerDocument$d;
|
|
78
|
-
|
|
79
|
-
if (DISABLED_ELIGIBLE_NODE_NAMES.includes(focusable.nodeName) && // @ts-ignore
|
|
80
|
-
!focusable.disabled) {
|
|
81
|
-
focusable.setAttribute('disabled', '');
|
|
82
|
-
updates.push(() => {
|
|
83
|
-
if (!focusable.isConnected) {
|
|
84
|
-
return;
|
|
85
|
-
} // @ts-ignore
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
focusable.disabled = false;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (focusable.nodeName === 'A' && focusable.getAttribute('tabindex') !== '-1') {
|
|
93
|
-
const previousValue = focusable.getAttribute('tabindex');
|
|
94
|
-
focusable.setAttribute('tabindex', '-1');
|
|
95
|
-
updates.push(() => {
|
|
96
|
-
if (!focusable.isConnected) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!previousValue) {
|
|
101
|
-
focusable.removeAttribute('tabindex');
|
|
102
|
-
} else {
|
|
103
|
-
focusable.setAttribute('tabindex', previousValue);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const tabIndex = focusable.getAttribute('tabindex');
|
|
109
|
-
|
|
110
|
-
if (tabIndex !== null && tabIndex !== '-1') {
|
|
111
|
-
focusable.removeAttribute('tabindex');
|
|
112
|
-
updates.push(() => {
|
|
113
|
-
if (!focusable.isConnected) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
focusable.setAttribute('tabindex', tabIndex);
|
|
118
|
-
});
|
|
47
|
+
node.childNodes.forEach(child => {
|
|
48
|
+
if (!(child instanceof HTMLElement)) {
|
|
49
|
+
return;
|
|
119
50
|
}
|
|
120
51
|
|
|
121
|
-
if (
|
|
122
|
-
|
|
52
|
+
if (!child.getAttribute('inert')) {
|
|
53
|
+
child.setAttribute('inert', 'true');
|
|
123
54
|
updates.push(() => {
|
|
124
|
-
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
focusable.setAttribute('contenteditable', 'true');
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if ((_node$ownerDocument$d = node.ownerDocument.defaultView) !== null && _node$ownerDocument$d !== void 0 && _node$ownerDocument$d.HTMLElement && focusable instanceof node.ownerDocument.defaultView.HTMLElement) {
|
|
133
|
-
const previousValue = focusable.style.getPropertyValue('pointer-events');
|
|
134
|
-
focusable.style.setProperty('pointer-events', 'none');
|
|
135
|
-
updates.push(() => {
|
|
136
|
-
if (!focusable.isConnected) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
focusable.style.setProperty('pointer-events', previousValue);
|
|
55
|
+
child.removeAttribute('inert');
|
|
141
56
|
});
|
|
142
57
|
}
|
|
143
58
|
});
|
|
@@ -153,9 +68,7 @@ export default function useDisabled() {
|
|
|
153
68
|
|
|
154
69
|
const observer = new window.MutationObserver(debouncedDisable);
|
|
155
70
|
observer.observe(node, {
|
|
156
|
-
childList: true
|
|
157
|
-
attributes: true,
|
|
158
|
-
subtree: true
|
|
71
|
+
childList: true
|
|
159
72
|
});
|
|
160
73
|
return () => {
|
|
161
74
|
if (observer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-disabled/index.js"],"names":["focus","debounce","useRefEffect","DISABLED_ELIGIBLE_NODE_NAMES","useDisabled","isDisabled","isDisabledProp","node","updates","disable","style","getPropertyValue","previousValue","setProperty","push","isConnected","focusable","find","forEach","includes","nodeName","disabled","setAttribute","getAttribute","removeAttribute","tabIndex","hasAttribute","ownerDocument","defaultView","HTMLElement","debouncedDisable","leading","observer","window","MutationObserver","observe","childList","attributes","subtree","disconnect","cancel","update"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,QAAsB,gBAAtB;AAEA;AACA;AACA;;AACA,SAASC,QAAT,QAAyB,sBAAzB;AACA,OAAOC,YAAP,MAAyB,mBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,4BAA4B,GAAG,CACpC,QADoC,EAEpC,UAFoC,EAGpC,OAHoC,EAIpC,UAJoC,EAKpC,QALoC,EAMpC,QANoC,EAOpC,UAPoC,CAArC;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,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\n */\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Names of control nodes which qualify for disabled behavior.\n *\n * See WHATWG HTML Standard: 4.10.18.5: \"Enabling and disabling form controls: the disabled attribute\".\n *\n * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute\n *\n * @type {string[]}\n */\nconst DISABLED_ELIGIBLE_NODE_NAMES = [\n\t'BUTTON',\n\t'FIELDSET',\n\t'INPUT',\n\t'OPTGROUP',\n\t'OPTION',\n\t'SELECT',\n\t'TEXTAREA',\n];\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * @param {Object} config Configuration object.\n * @param {boolean=} config.isDisabled Whether the element should be disabled.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useDisabled } from '@wordpress/compose';\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled( {\n\tisDisabled: isDisabledProp = false,\n} = {} ) {\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isDisabledProp ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/** A variable keeping track of the previous updates in order to restore them. */\n\t\t\t/** @type {Function[]} */\n\t\t\tconst updates = [];\n\n\t\t\tconst disable = () => {\n\t\t\t\tif ( node.style.getPropertyValue( 'user-select' ) !== 'none' ) {\n\t\t\t\t\tconst previousValue =\n\t\t\t\t\t\tnode.style.getPropertyValue( 'user-select' );\n\t\t\t\t\tnode.style.setProperty( 'user-select', 'none' );\n\t\t\t\t\tnode.style.setProperty( '-webkit-user-select', 'none' );\n\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\tif ( ! node.isConnected ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnode.style.setProperty( 'user-select', previousValue );\n\t\t\t\t\t\tnode.style.setProperty(\n\t\t\t\t\t\t\t'-webkit-user-select',\n\t\t\t\t\t\t\tpreviousValue\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tfocus.focusable.find( node ).forEach( ( focusable ) => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tDISABLED_ELIGIBLE_NODE_NAMES.includes(\n\t\t\t\t\t\t\tfocusable.nodeName\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t! focusable.disabled\n\t\t\t\t\t) {\n\t\t\t\t\t\tfocusable.setAttribute( 'disabled', '' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tif ( ! focusable.isConnected ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\tfocusable.disabled = false;\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tfocusable.nodeName === 'A' &&\n\t\t\t\t\t\tfocusable.getAttribute( 'tabindex' ) !== '-1'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst previousValue =\n\t\t\t\t\t\t\tfocusable.getAttribute( 'tabindex' );\n\t\t\t\t\t\tfocusable.setAttribute( 'tabindex', '-1' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tif ( ! focusable.isConnected ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( ! previousValue ) {\n\t\t\t\t\t\t\t\tfocusable.removeAttribute( 'tabindex' );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tfocusable.setAttribute(\n\t\t\t\t\t\t\t\t\t'tabindex',\n\t\t\t\t\t\t\t\t\tpreviousValue\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\tconst tabIndex = focusable.getAttribute( 'tabindex' );\n\t\t\t\t\tif ( tabIndex !== null && tabIndex !== '-1' ) {\n\t\t\t\t\t\tfocusable.removeAttribute( 'tabindex' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tif ( ! focusable.isConnected ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfocusable.setAttribute( 'tabindex', tabIndex );\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tfocusable.hasAttribute( 'contenteditable' ) &&\n\t\t\t\t\t\tfocusable.getAttribute( 'contenteditable' ) !== 'false'\n\t\t\t\t\t) {\n\t\t\t\t\t\tfocusable.setAttribute( 'contenteditable', 'false' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tif ( ! focusable.isConnected ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfocusable.setAttribute( 'contenteditable', 'true' );\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tnode.ownerDocument.defaultView?.HTMLElement &&\n\t\t\t\t\t\tfocusable instanceof\n\t\t\t\t\t\t\tnode.ownerDocument.defaultView.HTMLElement\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst previousValue =\n\t\t\t\t\t\t\tfocusable.style.getPropertyValue(\n\t\t\t\t\t\t\t\t'pointer-events'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\tfocusable.style.setProperty( 'pointer-events', 'none' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tif ( ! focusable.isConnected ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfocusable.style.setProperty(\n\t\t\t\t\t\t\t\t'pointer-events',\n\t\t\t\t\t\t\t\tpreviousValue\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Debounce re-disable since disabling process itself will incur\n\t\t\t// additional mutations which should be ignored.\n\t\t\tconst debouncedDisable = debounce( disable, 0, {\n\t\t\t\tleading: true,\n\t\t\t} );\n\t\t\tdisable();\n\n\t\t\t/** @type {MutationObserver | undefined} */\n\t\t\tconst observer = new window.MutationObserver( debouncedDisable );\n\t\t\tobserver.observe( node, {\n\t\t\t\tchildList: true,\n\t\t\t\tattributes: true,\n\t\t\t\tsubtree: true,\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tif ( observer ) {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t}\n\t\t\t\tdebouncedDisable.cancel();\n\t\t\t\tupdates.forEach( ( update ) => update() );\n\t\t\t};\n\t\t},\n\t\t[ isDisabledProp ]\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-disabled/index.ts"],"names":["debounce","useRefEffect","useDisabled","isDisabled","isDisabledProp","node","updates","disable","childNodes","forEach","child","HTMLElement","getAttribute","setAttribute","push","removeAttribute","debouncedDisable","leading","observer","window","MutationObserver","observe","childList","disconnect","cancel","update"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,QAAyB,sBAAzB;AACA,OAAOC,YAAP,MAAyB,mBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,WAAT,GAEN;AAAA,M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'../../utils/debounce';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * If you can, prefer the use of the inert HTML attribute.\n *\n * @param {Object} config Configuration object.\n * @param {boolean=} config.isDisabled Whether the element should be disabled.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useDisabled } from '@wordpress/compose';\n *\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled( {\n\tisDisabled: isDisabledProp = false,\n} = {} ) {\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isDisabledProp ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/** A variable keeping track of the previous updates in order to restore them. */\n\t\t\tconst updates: Function[] = [];\n\t\t\tconst disable = () => {\n\t\t\t\tnode.childNodes.forEach( ( child ) => {\n\t\t\t\t\tif ( ! ( child instanceof HTMLElement ) ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif ( ! child.getAttribute( 'inert' ) ) {\n\t\t\t\t\t\tchild.setAttribute( 'inert', 'true' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tchild.removeAttribute( 'inert' );\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Debounce re-disable since disabling process itself will incur\n\t\t\t// additional mutations which should be ignored.\n\t\t\tconst debouncedDisable = debounce( disable, 0, {\n\t\t\t\tleading: true,\n\t\t\t} );\n\t\t\tdisable();\n\n\t\t\t/** @type {MutationObserver | undefined} */\n\t\t\tconst observer = new window.MutationObserver( debouncedDisable );\n\t\t\tobserver.observe( node, {\n\t\t\t\tchildList: true,\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tif ( observer ) {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t}\n\t\t\t\tdebouncedDisable.cancel();\n\t\t\t\tupdates.forEach( ( update ) => update() );\n\t\t\t};\n\t\t},\n\t\t[ isDisabledProp ]\n\t);\n}\n"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* WordPress dependencies
|
|
3
7
|
*/
|
|
@@ -5,17 +9,14 @@ import { useCallback, useEffect, useRef } from '@wordpress/element';
|
|
|
5
9
|
/**
|
|
6
10
|
* Input types which are classified as button types, for use in considering
|
|
7
11
|
* whether element is a (focus-normalized) button.
|
|
8
|
-
*
|
|
9
|
-
* @type {string[]}
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
14
|
const INPUT_BUTTON_TYPES = ['button', 'submit'];
|
|
13
15
|
/**
|
|
14
|
-
*
|
|
16
|
+
* List of HTML button elements subject to focus normalization
|
|
17
|
+
*
|
|
18
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
|
|
15
19
|
*/
|
|
16
|
-
// Disable reason: Rule doesn't support predicate return types.
|
|
17
|
-
|
|
18
|
-
/* eslint-disable jsdoc/valid-types */
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Returns true if the given element is a button element subject to focus
|
|
@@ -23,11 +24,10 @@ const INPUT_BUTTON_TYPES = ['button', 'submit'];
|
|
|
23
24
|
*
|
|
24
25
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
|
|
25
26
|
*
|
|
26
|
-
* @param
|
|
27
|
+
* @param eventTarget The target from a mouse or touch event.
|
|
27
28
|
*
|
|
28
|
-
* @return
|
|
29
|
+
* @return Whether the element is a button element subject to focus normalization.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
31
|
function isFocusNormalizedButton(eventTarget) {
|
|
32
32
|
if (!(eventTarget instanceof window.HTMLElement)) {
|
|
33
33
|
return false;
|
|
@@ -39,66 +39,28 @@ function isFocusNormalizedButton(eventTarget) {
|
|
|
39
39
|
return true;
|
|
40
40
|
|
|
41
41
|
case 'INPUT':
|
|
42
|
-
return INPUT_BUTTON_TYPES.includes(
|
|
43
|
-
/** @type {HTMLInputElement} */
|
|
44
|
-
eventTarget.type);
|
|
42
|
+
return INPUT_BUTTON_TYPES.includes(eventTarget.type);
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
return false;
|
|
48
46
|
}
|
|
49
|
-
/* eslint-enable jsdoc/valid-types */
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @typedef {import('react').SyntheticEvent} SyntheticEvent
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @callback EventCallback
|
|
57
|
-
* @param {SyntheticEvent} event input related event.
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @typedef FocusOutsideReactElement
|
|
62
|
-
* @property {EventCallback} handleFocusOutside callback for a focus outside event.
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @typedef {import('react').MutableRefObject<FocusOutsideReactElement | undefined>} FocusOutsideRef
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @typedef {Object} FocusOutsideReturnValue
|
|
71
|
-
* @property {EventCallback} onFocus An event handler for focus events.
|
|
72
|
-
* @property {EventCallback} onBlur An event handler for blur events.
|
|
73
|
-
* @property {EventCallback} onMouseDown An event handler for mouse down events.
|
|
74
|
-
* @property {EventCallback} onMouseUp An event handler for mouse up events.
|
|
75
|
-
* @property {EventCallback} onTouchStart An event handler for touch start events.
|
|
76
|
-
* @property {EventCallback} onTouchEnd An event handler for touch end events.
|
|
77
|
-
*/
|
|
78
47
|
|
|
79
48
|
/**
|
|
80
49
|
* A react hook that can be used to check whether focus has moved outside the
|
|
81
50
|
* element the event handlers are bound to.
|
|
82
51
|
*
|
|
83
|
-
* @param
|
|
84
|
-
*
|
|
52
|
+
* @param onFocusOutside A callback triggered when focus moves outside
|
|
53
|
+
* the element the event handlers are bound to.
|
|
85
54
|
*
|
|
86
|
-
* @return
|
|
87
|
-
*
|
|
88
|
-
* outside that element.
|
|
55
|
+
* @return An object containing event handlers. Bind the event handlers to a
|
|
56
|
+
* wrapping element element to capture when focus moves outside that element.
|
|
89
57
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
58
|
export default function useFocusOutside(onFocusOutside) {
|
|
93
59
|
const currentOnFocusOutside = useRef(onFocusOutside);
|
|
94
60
|
useEffect(() => {
|
|
95
61
|
currentOnFocusOutside.current = onFocusOutside;
|
|
96
62
|
}, [onFocusOutside]);
|
|
97
63
|
const preventBlurCheck = useRef(false);
|
|
98
|
-
/**
|
|
99
|
-
* @type {import('react').MutableRefObject<number | undefined>}
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
64
|
const blurCheckTimeoutId = useRef();
|
|
103
65
|
/**
|
|
104
66
|
* Cancel a blur check timeout.
|
|
@@ -124,9 +86,8 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
124
86
|
* button elements when clicked, while others do. The logic here
|
|
125
87
|
* intends to normalize this as treating click on buttons as focus.
|
|
126
88
|
*
|
|
89
|
+
* @param event
|
|
127
90
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
|
|
128
|
-
*
|
|
129
|
-
* @param {SyntheticEvent} event Event for mousedown or mouseup.
|
|
130
91
|
*/
|
|
131
92
|
|
|
132
93
|
const normalizeButtonFocus = useCallback(event => {
|
|
@@ -148,8 +109,6 @@ export default function useFocusOutside(onFocusOutside) {
|
|
|
148
109
|
*
|
|
149
110
|
* Calls the `onFocusOutside` callback in an immediate timeout if focus has
|
|
150
111
|
* move outside the bound element and is still within the document.
|
|
151
|
-
*
|
|
152
|
-
* @param {SyntheticEvent} event Blur event.
|
|
153
112
|
*/
|
|
154
113
|
|
|
155
114
|
const queueBlurCheck = useCallback(event => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-outside/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-focus-outside/index.ts"],"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","setTimeout","document","hasFocus","preventDefault","onFocus","onMouseDown","onMouseUp","onTouchStart","onTouchEnd","onBlur"],"mappings":"AAAA;AACA;AACA;;AAWA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,QAA+C,oBAA/C;AAEA;AACA;AACA;AACA;;AACA,MAAMC,kBAAkB,GAAG,CAAE,QAAF,EAAY,QAAZ,CAA3B;AAEA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAT,CACCC,WADD,EAEwC;AACvC,MAAK,EAAIA,WAAW,YAAYC,MAAM,CAACC,WAAlC,CAAL,EAAuD;AACtD,WAAO,KAAP;AACA;;AACD,UAASF,WAAW,CAACG,QAArB;AACC,SAAK,GAAL;AACA,SAAK,QAAL;AACC,aAAO,IAAP;;AAED,SAAK,OAAL;AACC,aAAOL,kBAAkB,CAACM,QAAnB,CACJJ,WAAF,CAAoCK,IAD9B,CAAP;AANF;;AAWA,SAAO,KAAP;AACA;;AAWD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAT,CACdC,cADc,EA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;AACC,QAAMS,cAAiC,GAAGvB,WAAW,CAAIoB,KAAF,IAAa;AACnE;AACA;AACAA,IAAAA,KAAK,CAACI,OAAN,GAHmE,CAKnE;;AACA,QAAKT,gBAAgB,CAACD,OAAtB,EAAgC;AAC/B;AACA;;AAEDE,IAAAA,kBAAkB,CAACF,OAAnB,GAA6BW,UAAU,CAAE,MAAM;AAC9C;AACA;AACA;AACA;AACA,UAAK,CAAEC,QAAQ,CAACC,QAAT,EAAP,EAA6B;AAC5BP,QAAAA,KAAK,CAACQ,cAAN;AACA;AACA;;AAED,UAAK,eAAe,OAAOf,qBAAqB,CAACC,OAAjD,EAA2D;AAC1DD,QAAAA,qBAAqB,CAACC,OAAtB,CAA+BM,KAA/B;AACA;AACD,KAbsC,EAapC,CAboC,CAAvC;AAcA,GAxBoD,EAwBlD,EAxBkD,CAArD;AA0BA,SAAO;AACNS,IAAAA,OAAO,EAAEZ,eADH;AAENa,IAAAA,WAAW,EAAEX,oBAFP;AAGNY,IAAAA,SAAS,EAAEZ,oBAHL;AAINa,IAAAA,YAAY,EAAEb,oBAJR;AAKNc,IAAAA,UAAU,EAAEd,oBALN;AAMNe,IAAAA,MAAM,EAAEX;AANF,GAAP;AAQA","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\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"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Internal dependencies
|
|
3
7
|
*/
|
|
@@ -6,7 +10,7 @@ import useRefEffect from '../use-ref-effect';
|
|
|
6
10
|
* Dispatches a bubbling focus event when the iframe receives focus. Use
|
|
7
11
|
* `onFocus` as usual on the iframe or a parent element.
|
|
8
12
|
*
|
|
9
|
-
* @return
|
|
13
|
+
* @return Ref to pass to the iframe.
|
|
10
14
|
*/
|
|
11
15
|
|
|
12
16
|
export default function useFocusableIframe() {
|
|
@@ -26,7 +30,6 @@ export default function useFocusableIframe() {
|
|
|
26
30
|
|
|
27
31
|
function checkFocus() {
|
|
28
32
|
if (ownerDocument && ownerDocument.activeElement === element) {
|
|
29
|
-
/** @type {HTMLElement} */
|
|
30
33
|
element.focus();
|
|
31
34
|
}
|
|
32
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.ts"],"names":["useRefEffect","useFocusableIframe","element","ownerDocument","defaultView","checkFocus","activeElement","focus","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAOA,YAAP,MAAyB,mBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,kBAAT,GAAgE;AAC9E,SAAOD,YAAY,CAAIE,OAAF,IAAe;AACnC,UAAM;AAAEC,MAAAA;AAAF,QAAoBD,OAA1B;AACA,QAAK,CAAEC,aAAP,EAAuB;AACvB,UAAM;AAAEC,MAAAA;AAAF,QAAkBD,aAAxB;AACA,QAAK,CAAEC,WAAP,EAAqB;AAErB;AACF;AACA;AACA;;AACE,aAASC,UAAT,GAAsB;AACrB,UAAKF,aAAa,IAAIA,aAAa,CAACG,aAAd,KAAgCJ,OAAtD,EAAgE;AAC7DA,QAAAA,OAAF,CAA2BK,KAA3B;AACA;AACD;;AAEDH,IAAAA,WAAW,CAACI,gBAAZ,CAA8B,MAA9B,EAAsCH,UAAtC;AACA,WAAO,MAAM;AACZD,MAAAA,WAAW,CAACK,mBAAZ,CAAiC,MAAjC,EAAyCJ,UAAzC;AACA,KAFD;AAGA,GApBkB,EAoBhB,EApBgB,CAAnB;AAqBA","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"names":["View","StyleSheet","useState","useCallback","useResizeObserver","measurements","setMeasurements","onLayout","nativeEvent","width","height","layout","prevState","Math","floor","observer","absoluteFill"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,UAAf,QAAiC,cAAjC;AACA;AACA;AACA;;AACA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,oBAAtC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,iBAAiB,GAAG,MAAM;AAC/B,QAAM,CAAEC,YAAF,EAAgBC,eAAhB,IAAoCJ,QAAQ,CAAE,IAAF,CAAlD;AAEA,QAAMK,QAAQ,GAAGJ,WAAW,CAAE,QAAuB;AAAA,QAArB;AAAEK,MAAAA;AAAF,KAAqB;AACpD,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAoBF,WAAW,CAACG,MAAtC;AACAL,IAAAA,eAAe,CAAIM,SAAF,IAAiB;AACjC,UACC,CAAEA,SAAF,IACAA,SAAS,CAACH,KAAV,KAAoBA,KADpB,IAEAG,SAAS,CAACF,MAAV,KAAqBA,MAHtB,EAIE;AACD,eAAO;AACND,UAAAA,KAAK,EAAEI,IAAI,CAACC,KAAL,CAAYL,KAAZ,CADD;AAENC,UAAAA,MAAM,EAAEG,IAAI,CAACC,KAAL,CAAYJ,MAAZ;AAFF,SAAP;AAIA;;AACD,aAAOE,SAAP;AACA,KAZc,CAAf;AAaA,GAf2B,EAezB,EAfyB,CAA5B;AAiBA,QAAMG,QAAQ,GACb,cAAC,IAAD;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"names":["View","StyleSheet","useState","useCallback","useResizeObserver","measurements","setMeasurements","onLayout","nativeEvent","width","height","layout","prevState","Math","floor","observer","absoluteFill"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,UAAf,QAAiC,cAAjC;AACA;AACA;AACA;;AACA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,oBAAtC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,iBAAiB,GAAG,MAAM;AAC/B,QAAM,CAAEC,YAAF,EAAgBC,eAAhB,IAAoCJ,QAAQ,CAAE,IAAF,CAAlD;AAEA,QAAMK,QAAQ,GAAGJ,WAAW,CAAE,QAAuB;AAAA,QAArB;AAAEK,MAAAA;AAAF,KAAqB;AACpD,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA;AAAT,QAAoBF,WAAW,CAACG,MAAtC;AACAL,IAAAA,eAAe,CAAIM,SAAF,IAAiB;AACjC,UACC,CAAEA,SAAF,IACAA,SAAS,CAACH,KAAV,KAAoBA,KADpB,IAEAG,SAAS,CAACF,MAAV,KAAqBA,MAHtB,EAIE;AACD,eAAO;AACND,UAAAA,KAAK,EAAEI,IAAI,CAACC,KAAL,CAAYL,KAAZ,CADD;AAENC,UAAAA,MAAM,EAAEG,IAAI,CAACC,KAAL,CAAYJ,MAAZ;AAFF,SAAP;AAIA;;AACD,aAAOE,SAAP;AACA,KAZc,CAAf;AAaA,GAf2B,EAezB,EAfyB,CAA5B;AAiBA,QAAMG,QAAQ,GACb,cAAC,IAAD;AACC,IAAA,MAAM,EAAC,iBADR;AAEC,IAAA,KAAK,EAAGd,UAAU,CAACe,YAFpB;AAGC,IAAA,QAAQ,EAAGT;AAHZ,IADD;AAQA,SAAO,CAAEQ,QAAF,EAAYV,YAAZ,CAAP;AACA,CA7BD;;AA+BA,eAAeD,iBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { View, StyleSheet } from 'react-native';\n/**\n * WordPress dependencies\n */\nimport { useState, useCallback } from '@wordpress/element';\n\n/**\n * Hook which allows to listen the resize event of any target element when it changes sizes.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<View>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</View>\n * \t);\n * };\n * ```\n *\n */\nconst useResizeObserver = () => {\n\tconst [ measurements, setMeasurements ] = useState( null );\n\n\tconst onLayout = useCallback( ( { nativeEvent } ) => {\n\t\tconst { width, height } = nativeEvent.layout;\n\t\tsetMeasurements( ( prevState ) => {\n\t\t\tif (\n\t\t\t\t! prevState ||\n\t\t\t\tprevState.width !== width ||\n\t\t\t\tprevState.height !== height\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\twidth: Math.floor( width ),\n\t\t\t\t\theight: Math.floor( height ),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn prevState;\n\t\t} );\n\t}, [] );\n\n\tconst observer = (\n\t\t<View\n\t\t\ttestID=\"resize-observer\"\n\t\t\tstyle={ StyleSheet.absoluteFill }\n\t\t\tonLayout={ onLayout }\n\t\t/>\n\t);\n\n\treturn [ observer, measurements ];\n};\n\nexport default useResizeObserver;\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { RefCallback, SyntheticEvent } from 'react';
|
|
5
5
|
import useFocusOnMount from '../use-focus-on-mount';
|
|
6
|
-
import
|
|
6
|
+
import useFocusOutside from '../use-focus-outside';
|
|
7
7
|
declare type DialogOptions = {
|
|
8
8
|
focusOnMount?: Parameters<typeof useFocusOnMount>[0];
|
|
9
9
|
onClose?: () => void;
|
|
@@ -16,7 +16,7 @@ declare type DialogOptions = {
|
|
|
16
16
|
};
|
|
17
17
|
declare type useDialogReturn = [
|
|
18
18
|
RefCallback<HTMLElement>,
|
|
19
|
-
|
|
19
|
+
ReturnType<typeof useFocusOutside> & Pick<HTMLElement, 'tabIndex'>
|
|
20
20
|
];
|
|
21
21
|
/**
|
|
22
22
|
* Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAYzD,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAGnD,aAAK,aAAa,GAAG;IACpB,YAAY,CAAC,EAAE,UAAU,CAAE,OAAO,eAAe,CAAE,CAAE,CAAC,CAAE,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CACnB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,KAAK,EAAE,cAAc,KACjB,IAAI,CAAC;CACV,CAAC;AAEF,aAAK,eAAe,GAAG;IACtB,WAAW,CAAE,WAAW,CAAE;IAC1B,UAAU,CAAE,OAAO,eAAe,CAAE,GAAG,IAAI,CAAE,WAAW,EAAE,UAAU,CAAE;CACtE,CAAC;AAEF;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAE,OAAO,EAAE,aAAa,GAAI,eAAe,CA+C5D;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
4
4
|
* behavior to disable nested DOM elements to the returned ref.
|
|
5
5
|
*
|
|
6
|
+
* If you can, prefer the use of the inert HTML attribute.
|
|
7
|
+
*
|
|
6
8
|
* @param {Object} config Configuration object.
|
|
7
9
|
* @param {boolean=} config.isDisabled Whether the element should be disabled.
|
|
8
10
|
* @return {import('react').RefCallback<HTMLElement>} Element Ref.
|
|
@@ -10,6 +12,7 @@
|
|
|
10
12
|
* @example
|
|
11
13
|
* ```js
|
|
12
14
|
* import { useDisabled } from '@wordpress/compose';
|
|
15
|
+
*
|
|
13
16
|
* const DisabledExample = () => {
|
|
14
17
|
* const disabledRef = useDisabled();
|
|
15
18
|
* return (
|
|
@@ -23,5 +26,5 @@
|
|
|
23
26
|
*/
|
|
24
27
|
export default function useDisabled({ isDisabled: isDisabledProp, }?: {
|
|
25
28
|
isDisabled?: boolean | undefined;
|
|
26
|
-
}):
|
|
29
|
+
}): (instance: Node | null) => void;
|
|
27
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAE,EACpC,UAAU,EAAE,cAAsB,GAClC;;CAAK,mCA8CL"}
|
|
@@ -1,72 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* @callback EventCallback
|
|
6
|
-
* @param {SyntheticEvent} event input related event.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* @typedef FocusOutsideReactElement
|
|
10
|
-
* @property {EventCallback} handleFocusOutside callback for a focus outside event.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {import('react').MutableRefObject<FocusOutsideReactElement | undefined>} FocusOutsideRef
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {Object} FocusOutsideReturnValue
|
|
17
|
-
* @property {EventCallback} onFocus An event handler for focus events.
|
|
18
|
-
* @property {EventCallback} onBlur An event handler for blur events.
|
|
19
|
-
* @property {EventCallback} onMouseDown An event handler for mouse down events.
|
|
20
|
-
* @property {EventCallback} onMouseUp An event handler for mouse up events.
|
|
21
|
-
* @property {EventCallback} onTouchStart An event handler for touch start events.
|
|
22
|
-
* @property {EventCallback} onTouchEnd An event handler for touch end events.
|
|
2
|
+
* External dependencies
|
|
23
3
|
*/
|
|
4
|
+
import type { FocusEventHandler, MouseEventHandler, TouchEventHandler, FocusEvent } from 'react';
|
|
5
|
+
declare type UseFocusOutsideReturn = {
|
|
6
|
+
onFocus: FocusEventHandler;
|
|
7
|
+
onMouseDown: MouseEventHandler;
|
|
8
|
+
onMouseUp: MouseEventHandler;
|
|
9
|
+
onTouchStart: TouchEventHandler;
|
|
10
|
+
onTouchEnd: TouchEventHandler;
|
|
11
|
+
onBlur: FocusEventHandler;
|
|
12
|
+
};
|
|
24
13
|
/**
|
|
25
14
|
* A react hook that can be used to check whether focus has moved outside the
|
|
26
15
|
* element the event handlers are bound to.
|
|
27
16
|
*
|
|
28
|
-
* @param
|
|
29
|
-
*
|
|
17
|
+
* @param onFocusOutside A callback triggered when focus moves outside
|
|
18
|
+
* the element the event handlers are bound to.
|
|
30
19
|
*
|
|
31
|
-
* @return
|
|
32
|
-
*
|
|
33
|
-
* outside that element.
|
|
20
|
+
* @return An object containing event handlers. Bind the event handlers to a
|
|
21
|
+
* wrapping element element to capture when focus moves outside that element.
|
|
34
22
|
*/
|
|
35
|
-
export default function useFocusOutside(onFocusOutside:
|
|
36
|
-
export
|
|
37
|
-
export type SyntheticEvent = import('react').SyntheticEvent;
|
|
38
|
-
export type EventCallback = (event: SyntheticEvent) => any;
|
|
39
|
-
export type FocusOutsideReactElement = {
|
|
40
|
-
/**
|
|
41
|
-
* callback for a focus outside event.
|
|
42
|
-
*/
|
|
43
|
-
handleFocusOutside: EventCallback;
|
|
44
|
-
};
|
|
45
|
-
export type FocusOutsideRef = import('react').MutableRefObject<FocusOutsideReactElement | undefined>;
|
|
46
|
-
export type FocusOutsideReturnValue = {
|
|
47
|
-
/**
|
|
48
|
-
* An event handler for focus events.
|
|
49
|
-
*/
|
|
50
|
-
onFocus: EventCallback;
|
|
51
|
-
/**
|
|
52
|
-
* An event handler for blur events.
|
|
53
|
-
*/
|
|
54
|
-
onBlur: EventCallback;
|
|
55
|
-
/**
|
|
56
|
-
* An event handler for mouse down events.
|
|
57
|
-
*/
|
|
58
|
-
onMouseDown: EventCallback;
|
|
59
|
-
/**
|
|
60
|
-
* An event handler for mouse up events.
|
|
61
|
-
*/
|
|
62
|
-
onMouseUp: EventCallback;
|
|
63
|
-
/**
|
|
64
|
-
* An event handler for touch start events.
|
|
65
|
-
*/
|
|
66
|
-
onTouchStart: EventCallback;
|
|
67
|
-
/**
|
|
68
|
-
* An event handler for touch end events.
|
|
69
|
-
*/
|
|
70
|
-
onTouchEnd: EventCallback;
|
|
71
|
-
};
|
|
23
|
+
export default function useFocusOutside(onFocusOutside: (event: FocusEvent) => void): UseFocusOutsideReturn;
|
|
24
|
+
export {};
|
|
72
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-outside/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-outside/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACX,iBAAiB,EAEjB,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAGV,MAAM,OAAO,CAAC;AAqDf,aAAK,qBAAqB,GAAG;IAC5B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,WAAW,EAAE,iBAAiB,CAAC;IAC/B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,YAAY,EAAE,iBAAiB,CAAC;IAChC,UAAU,EAAE,iBAAiB,CAAC;IAC9B,MAAM,EAAE,iBAAiB,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACtC,cAAc,EAAE,CAAE,KAAK,EAAE,UAAU,KAAM,IAAI,GAC3C,qBAAqB,CA4FvB"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { RefCallback } from 'react';
|
|
1
5
|
/**
|
|
2
6
|
* Dispatches a bubbling focus event when the iframe receives focus. Use
|
|
3
7
|
* `onFocus` as usual on the iframe or a parent element.
|
|
4
8
|
*
|
|
5
|
-
* @return
|
|
9
|
+
* @return Ref to pass to the iframe.
|
|
6
10
|
*/
|
|
7
|
-
export default function useFocusableIframe():
|
|
11
|
+
export default function useFocusableIframe(): RefCallback<HTMLIFrameElement>;
|
|
8
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focusable-iframe/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focusable-iframe/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAOzC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,IAAI,WAAW,CAAE,iBAAiB,CAAE,CAsB7E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.19.0",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
33
|
"@types/mousetrap": "^1.6.8",
|
|
34
|
-
"@wordpress/deprecated": "^3.
|
|
35
|
-
"@wordpress/dom": "^3.
|
|
36
|
-
"@wordpress/element": "^4.
|
|
37
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
38
|
-
"@wordpress/keycodes": "^3.
|
|
39
|
-
"@wordpress/priority-queue": "^2.
|
|
34
|
+
"@wordpress/deprecated": "^3.21.0",
|
|
35
|
+
"@wordpress/dom": "^3.21.0",
|
|
36
|
+
"@wordpress/element": "^4.19.0",
|
|
37
|
+
"@wordpress/is-shallow-equal": "^4.21.0",
|
|
38
|
+
"@wordpress/keycodes": "^3.21.0",
|
|
39
|
+
"@wordpress/priority-queue": "^2.21.0",
|
|
40
40
|
"change-case": "^4.1.2",
|
|
41
41
|
"clipboard": "^2.0.8",
|
|
42
42
|
"mousetrap": "^1.6.5",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "511f4cc1f0138641bc4394bc1cf36e833109c791"
|
|
52
52
|
}
|