@wordpress/compose 5.17.0 → 5.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +3 -0
- package/build/hooks/use-disabled/index.js +10 -98
- package/build/hooks/use-disabled/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-disabled/index.js +10 -97
- package/build-module/hooks/use-disabled/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-disabled/index.d.ts +4 -1
- package/build-types/hooks/use-disabled/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-disabled/index.ts +81 -0
- package/src/hooks/use-disabled/test/index.js +4 -36
- package/src/hooks/use-focus-outside/test/index.js +44 -45
- 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
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -289,10 +289,13 @@ In some circumstances, such as block previews, all focusable DOM elements
|
|
|
289
289
|
(input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
290
290
|
behavior to disable nested DOM elements to the returned ref.
|
|
291
291
|
|
|
292
|
+
If you can, prefer the use of the inert HTML attribute.
|
|
293
|
+
|
|
292
294
|
_Usage_
|
|
293
295
|
|
|
294
296
|
```js
|
|
295
297
|
import { useDisabled } from '@wordpress/compose';
|
|
298
|
+
|
|
296
299
|
const DisabledExample = () => {
|
|
297
300
|
const disabledRef = useDisabled();
|
|
298
301
|
return (
|
|
@@ -7,35 +7,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = useDisabled;
|
|
9
9
|
|
|
10
|
-
var _dom = require("@wordpress/dom");
|
|
11
|
-
|
|
12
10
|
var _debounce = require("../../utils/debounce");
|
|
13
11
|
|
|
14
12
|
var _useRefEffect = _interopRequireDefault(require("../use-ref-effect"));
|
|
15
13
|
|
|
16
|
-
/**
|
|
17
|
-
* WordPress dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
14
|
/**
|
|
21
15
|
* Internal dependencies
|
|
22
16
|
*/
|
|
23
17
|
|
|
24
|
-
/**
|
|
25
|
-
* Names of control nodes which qualify for disabled behavior.
|
|
26
|
-
*
|
|
27
|
-
* See WHATWG HTML Standard: 4.10.18.5: "Enabling and disabling form controls: the disabled attribute".
|
|
28
|
-
*
|
|
29
|
-
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute
|
|
30
|
-
*
|
|
31
|
-
* @type {string[]}
|
|
32
|
-
*/
|
|
33
|
-
const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP', 'OPTION', 'SELECT', 'TEXTAREA'];
|
|
34
18
|
/**
|
|
35
19
|
* In some circumstances, such as block previews, all focusable DOM elements
|
|
36
20
|
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
37
21
|
* behavior to disable nested DOM elements to the returned ref.
|
|
38
22
|
*
|
|
23
|
+
* If you can, prefer the use of the inert HTML attribute.
|
|
24
|
+
*
|
|
39
25
|
* @param {Object} config Configuration object.
|
|
40
26
|
* @param {boolean=} config.isDisabled Whether the element should be disabled.
|
|
41
27
|
* @return {import('react').RefCallback<HTMLElement>} Element Ref.
|
|
@@ -43,6 +29,7 @@ const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP',
|
|
|
43
29
|
* @example
|
|
44
30
|
* ```js
|
|
45
31
|
* import { useDisabled } from '@wordpress/compose';
|
|
32
|
+
*
|
|
46
33
|
* const DisabledExample = () => {
|
|
47
34
|
* const disabledRef = useDisabled();
|
|
48
35
|
* return (
|
|
@@ -54,7 +41,6 @@ const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP',
|
|
|
54
41
|
* };
|
|
55
42
|
* ```
|
|
56
43
|
*/
|
|
57
|
-
|
|
58
44
|
function useDisabled() {
|
|
59
45
|
let {
|
|
60
46
|
isDisabled: isDisabledProp = false
|
|
@@ -65,91 +51,19 @@ function useDisabled() {
|
|
|
65
51
|
}
|
|
66
52
|
/** A variable keeping track of the previous updates in order to restore them. */
|
|
67
53
|
|
|
68
|
-
/** @type {Function[]} */
|
|
69
|
-
|
|
70
54
|
|
|
71
55
|
const updates = [];
|
|
72
56
|
|
|
73
57
|
const disable = () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
node.style.setProperty('-webkit-user-select', 'none');
|
|
78
|
-
updates.push(() => {
|
|
79
|
-
if (!node.isConnected) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
node.style.setProperty('user-select', previousValue);
|
|
84
|
-
node.style.setProperty('-webkit-user-select', previousValue);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_dom.focus.focusable.find(node).forEach(focusable => {
|
|
89
|
-
var _node$ownerDocument$d;
|
|
90
|
-
|
|
91
|
-
if (DISABLED_ELIGIBLE_NODE_NAMES.includes(focusable.nodeName) && // @ts-ignore
|
|
92
|
-
!focusable.disabled) {
|
|
93
|
-
focusable.setAttribute('disabled', '');
|
|
94
|
-
updates.push(() => {
|
|
95
|
-
if (!focusable.isConnected) {
|
|
96
|
-
return;
|
|
97
|
-
} // @ts-ignore
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
focusable.disabled = false;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (focusable.nodeName === 'A' && focusable.getAttribute('tabindex') !== '-1') {
|
|
105
|
-
const previousValue = focusable.getAttribute('tabindex');
|
|
106
|
-
focusable.setAttribute('tabindex', '-1');
|
|
107
|
-
updates.push(() => {
|
|
108
|
-
if (!focusable.isConnected) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!previousValue) {
|
|
113
|
-
focusable.removeAttribute('tabindex');
|
|
114
|
-
} else {
|
|
115
|
-
focusable.setAttribute('tabindex', previousValue);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
58
|
+
node.childNodes.forEach(child => {
|
|
59
|
+
if (!(child instanceof HTMLElement)) {
|
|
60
|
+
return;
|
|
118
61
|
}
|
|
119
62
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (tabIndex !== null && tabIndex !== '-1') {
|
|
123
|
-
focusable.removeAttribute('tabindex');
|
|
63
|
+
if (!child.getAttribute('inert')) {
|
|
64
|
+
child.setAttribute('inert', 'true');
|
|
124
65
|
updates.push(() => {
|
|
125
|
-
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
focusable.setAttribute('tabindex', tabIndex);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (focusable.hasAttribute('contenteditable') && focusable.getAttribute('contenteditable') !== 'false') {
|
|
134
|
-
focusable.setAttribute('contenteditable', 'false');
|
|
135
|
-
updates.push(() => {
|
|
136
|
-
if (!focusable.isConnected) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
focusable.setAttribute('contenteditable', 'true');
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if ((_node$ownerDocument$d = node.ownerDocument.defaultView) !== null && _node$ownerDocument$d !== void 0 && _node$ownerDocument$d.HTMLElement && focusable instanceof node.ownerDocument.defaultView.HTMLElement) {
|
|
145
|
-
const previousValue = focusable.style.getPropertyValue('pointer-events');
|
|
146
|
-
focusable.style.setProperty('pointer-events', 'none');
|
|
147
|
-
updates.push(() => {
|
|
148
|
-
if (!focusable.isConnected) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
focusable.style.setProperty('pointer-events', previousValue);
|
|
66
|
+
child.removeAttribute('inert');
|
|
153
67
|
});
|
|
154
68
|
}
|
|
155
69
|
});
|
|
@@ -165,9 +79,7 @@ function useDisabled() {
|
|
|
165
79
|
|
|
166
80
|
const observer = new window.MutationObserver(debouncedDisable);
|
|
167
81
|
observer.observe(node, {
|
|
168
|
-
childList: true
|
|
169
|
-
attributes: true,
|
|
170
|
-
subtree: true
|
|
82
|
+
childList: true
|
|
171
83
|
});
|
|
172
84
|
return () => {
|
|
173
85
|
if (observer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-disabled/index.js"],"names":["DISABLED_ELIGIBLE_NODE_NAMES","useDisabled","isDisabled","isDisabledProp","node","updates","disable","style","getPropertyValue","previousValue","setProperty","push","isConnected","focus","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":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,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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encies\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":["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":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;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;AACe,SAASA,WAAT,GAEN;AAAA,MAF4B;AACpCC,IAAAA,UAAU,EAAEC,cAAc,GAAG;AADO,GAE5B,uEAAL,EAAK;AACR,SAAO,2BACJC,IAAF,IAAY;AACX,QAAKD,cAAL,EAAsB;AACrB;AACA;AAED;;;AACA,UAAME,OAAmB,GAAG,EAA5B;;AACA,UAAMC,OAAO,GAAG,MAAM;AACrBF,MAAAA,IAAI,CAACG,UAAL,CAAgBC,OAAhB,CAA2BC,KAAF,IAAa;AACrC,YAAK,EAAIA,KAAK,YAAYC,WAArB,CAAL,EAA0C;AACzC;AACA;;AACD,YAAK,CAAED,KAAK,CAACE,YAAN,CAAoB,OAApB,CAAP,EAAuC;AACtCF,UAAAA,KAAK,CAACG,YAAN,CAAoB,OAApB,EAA6B,MAA7B;AACAP,UAAAA,OAAO,CAACQ,IAAR,CAAc,MAAM;AACnBJ,YAAAA,KAAK,CAACK,eAAN,CAAuB,OAAvB;AACA,WAFD;AAGA;AACD,OAVD;AAWA,KAZD,CAPW,CAqBX;AACA;;;AACA,UAAMC,gBAAgB,GAAG,wBAAUT,OAAV,EAAmB,CAAnB,EAAsB;AAC9CU,MAAAA,OAAO,EAAE;AADqC,KAAtB,CAAzB;AAGAV,IAAAA,OAAO;AAEP;;AACA,UAAMW,QAAQ,GAAG,IAAIC,MAAM,CAACC,gBAAX,CAA6BJ,gBAA7B,CAAjB;AACAE,IAAAA,QAAQ,CAACG,OAAT,CAAkBhB,IAAlB,EAAwB;AACvBiB,MAAAA,SAAS,EAAE;AADY,KAAxB;AAIA,WAAO,MAAM;AACZ,UAAKJ,QAAL,EAAgB;AACfA,QAAAA,QAAQ,CAACK,UAAT;AACA;;AACDP,MAAAA,gBAAgB,CAACQ,MAAjB;AACAlB,MAAAA,OAAO,CAACG,OAAR,CAAmBgB,MAAF,IAAcA,MAAM,EAArC;AACA,KAND;AAOA,GA1CK,EA2CN,CAAErB,cAAF,CA3CM,CAAP;AA6CA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { debounce } from '../../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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"names":["useResizeObserver","measurements","setMeasurements","onLayout","nativeEvent","width","height","layout","prevState","Math","floor","observer","StyleSheet","absoluteFill"],"mappings":";;;;;;;AAOA;;AAJA;;AAHA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG,MAAM;AAC/B,QAAM,CAAEC,YAAF,EAAgBC,eAAhB,IAAoC,uBAAU,IAAV,CAA1C;AAEA,QAAMC,QAAQ,GAAG,0BAAa,QAAuB;AAAA,QAArB;AAAEC,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,GAfgB,EAed,EAfc,CAAjB;AAiBA,QAAMG,QAAQ,GACb,4BAAC,iBAAD;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"names":["useResizeObserver","measurements","setMeasurements","onLayout","nativeEvent","width","height","layout","prevState","Math","floor","observer","StyleSheet","absoluteFill"],"mappings":";;;;;;;AAOA;;AAJA;;AAHA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG,MAAM;AAC/B,QAAM,CAAEC,YAAF,EAAgBC,eAAhB,IAAoC,uBAAU,IAAV,CAA1C;AAEA,QAAMC,QAAQ,GAAG,0BAAa,QAAuB;AAAA,QAArB;AAAEC,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,GAfgB,EAed,EAfc,CAAjB;AAiBA,QAAMG,QAAQ,GACb,4BAAC,iBAAD;AACC,IAAA,MAAM,EAAC,iBADR;AAEC,IAAA,KAAK,EAAGC,wBAAWC,YAFpB;AAGC,IAAA,QAAQ,EAAGV;AAHZ,IADD;AAQA,SAAO,CAAEQ,QAAF,EAAYV,YAAZ,CAAP;AACA,CA7BD;;eA+BeD,iB","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"]}
|
|
@@ -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,QAAs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ACvB6B,MAAAA,SAAS,EAAE,IADY;AAEvBC,MAAAA,UAAU,EAAE,IAFW;AAGvBC,MAAAA,OAAO,EAAE;AAHc,KAAxB;AAMA,WAAO,MAAM;AACZ,UAAKN,QAAL,EAAgB;AACfA,QAAAA,QAAQ,CAACO,UAAT;AACA;;AACDT,MAAAA,gBAAgB,CAACU,MAAjB;AACAhC,MAAAA,OAAO,CAACU,OAAR,CAAmBuB,MAAF,IAAcA,MAAM,EAArC;AACA,KAND;AAOA,GAzIiB,EA0IlB,CAAEnC,cAAF,CA1IkB,CAAnB;AA4IA","sourcesContent":["/**\n * WordPress dependencies\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,MAF4B;AACpCC,IAAAA,UAAU,EAAEC,cAAc,GAAG;AADO,GAE5B,uEAAL,EAAK;AACR,SAAOH,YAAY,CAChBI,IAAF,IAAY;AACX,QAAKD,cAAL,EAAsB;AACrB;AACA;AAED;;;AACA,UAAME,OAAmB,GAAG,EAA5B;;AACA,UAAMC,OAAO,GAAG,MAAM;AACrBF,MAAAA,IAAI,CAACG,UAAL,CAAgBC,OAAhB,CAA2BC,KAAF,IAAa;AACrC,YAAK,EAAIA,KAAK,YAAYC,WAArB,CAAL,EAA0C;AACzC;AACA;;AACD,YAAK,CAAED,KAAK,CAACE,YAAN,CAAoB,OAApB,CAAP,EAAuC;AACtCF,UAAAA,KAAK,CAACG,YAAN,CAAoB,OAApB,EAA6B,MAA7B;AACAP,UAAAA,OAAO,CAACQ,IAAR,CAAc,MAAM;AACnBJ,YAAAA,KAAK,CAACK,eAAN,CAAuB,OAAvB;AACA,WAFD;AAGA;AACD,OAVD;AAWA,KAZD,CAPW,CAqBX;AACA;;;AACA,UAAMC,gBAAgB,GAAGhB,QAAQ,CAAEO,OAAF,EAAW,CAAX,EAAc;AAC9CU,MAAAA,OAAO,EAAE;AADqC,KAAd,CAAjC;AAGAV,IAAAA,OAAO;AAEP;;AACA,UAAMW,QAAQ,GAAG,IAAIC,MAAM,CAACC,gBAAX,CAA6BJ,gBAA7B,CAAjB;AACAE,IAAAA,QAAQ,CAACG,OAAT,CAAkBhB,IAAlB,EAAwB;AACvBiB,MAAAA,SAAS,EAAE;AADY,KAAxB;AAIA,WAAO,MAAM;AACZ,UAAKJ,QAAL,EAAgB;AACfA,QAAAA,QAAQ,CAACK,UAAT;AACA;;AACDP,MAAAA,gBAAgB,CAACQ,MAAjB;AACAlB,MAAAA,OAAO,CAACG,OAAR,CAAmBgB,MAAF,IAAcA,MAAM,EAArC;AACA,KAND;AAOA,GA1CiB,EA2ClB,CAAErB,cAAF,CA3CkB,CAAnB;AA6CA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { debounce } from '../../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 +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,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.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.20.0",
|
|
35
|
+
"@wordpress/dom": "^3.20.0",
|
|
36
|
+
"@wordpress/element": "^4.18.0",
|
|
37
|
+
"@wordpress/is-shallow-equal": "^4.20.0",
|
|
38
|
+
"@wordpress/keycodes": "^3.20.0",
|
|
39
|
+
"@wordpress/priority-queue": "^2.20.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": "a2ff0e6471c88436dad0287beb88d1729aa6f5dd"
|
|
52
52
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -30,8 +30,6 @@ jest.mock( '../listener', () => {
|
|
|
30
30
|
} );
|
|
31
31
|
|
|
32
32
|
describe( 'withGlobalEvents', () => {
|
|
33
|
-
let wrapper;
|
|
34
|
-
|
|
35
33
|
class OriginalComponent extends Component {
|
|
36
34
|
handleResize( event ) {
|
|
37
35
|
this.props.onResize( event );
|
|
@@ -50,51 +48,42 @@ describe( 'withGlobalEvents', () => {
|
|
|
50
48
|
jest.clearAllMocks();
|
|
51
49
|
} );
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
if ( wrapper ) {
|
|
55
|
-
wrapper.unmount();
|
|
56
|
-
wrapper = null;
|
|
57
|
-
}
|
|
58
|
-
} );
|
|
59
|
-
|
|
60
|
-
function mountEnhancedComponent( props = {} ) {
|
|
51
|
+
it( 'renders with original component', () => {
|
|
61
52
|
const EnhancedComponent = withGlobalEvents( {
|
|
62
53
|
resize: 'handleResize',
|
|
63
54
|
} )( OriginalComponent );
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
wrapper = TestRenderer.create(
|
|
68
|
-
<EnhancedComponent { ...props }>Hello</EnhancedComponent>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
it( 'renders with original component', () => {
|
|
73
|
-
mountEnhancedComponent();
|
|
56
|
+
render( <EnhancedComponent ref={ () => {} }>Hello</EnhancedComponent> );
|
|
74
57
|
|
|
75
58
|
expect( console ).toHaveWarned();
|
|
76
|
-
expect(
|
|
77
|
-
'Hello'
|
|
78
|
-
);
|
|
59
|
+
expect( screen.getByText( 'Hello' ) ).toBeVisible();
|
|
79
60
|
} );
|
|
80
61
|
|
|
81
62
|
it( 'binds events from passed object', () => {
|
|
82
|
-
|
|
63
|
+
const EnhancedComponent = withGlobalEvents( {
|
|
64
|
+
resize: 'handleResize',
|
|
65
|
+
} )( OriginalComponent );
|
|
83
66
|
|
|
84
|
-
|
|
85
|
-
const hocInstance =
|
|
86
|
-
wrapper.root.findByType( OriginalComponent ).parent.instance;
|
|
67
|
+
render( <EnhancedComponent ref={ () => {} }>Hello</EnhancedComponent> );
|
|
87
68
|
|
|
88
69
|
expect( Listener._instance.add ).toHaveBeenCalledWith(
|
|
89
70
|
'resize',
|
|
90
|
-
|
|
71
|
+
// If not `undefined`, then we consider handlers were properly bound to the wrapper component.
|
|
72
|
+
expect.any( Object )
|
|
91
73
|
);
|
|
92
74
|
} );
|
|
93
75
|
|
|
94
76
|
it( 'handles events', () => {
|
|
77
|
+
const EnhancedComponent = withGlobalEvents( {
|
|
78
|
+
resize: 'handleResize',
|
|
79
|
+
} )( OriginalComponent );
|
|
95
80
|
const onResize = jest.fn();
|
|
96
81
|
|
|
97
|
-
|
|
82
|
+
render(
|
|
83
|
+
<EnhancedComponent ref={ () => {} } onResize={ onResize }>
|
|
84
|
+
Hello
|
|
85
|
+
</EnhancedComponent>
|
|
86
|
+
);
|
|
98
87
|
|
|
99
88
|
const event = { type: 'resize' };
|
|
100
89
|
|