@wordpress/compose 6.27.0 → 6.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/higher-order/compose.js +1 -2
- package/build/higher-order/compose.js.map +1 -1
- package/build/higher-order/if-condition/index.js +1 -2
- package/build/higher-order/if-condition/index.js.map +1 -1
- package/build/higher-order/pipe.js +1 -2
- package/build/higher-order/pipe.js.map +1 -1
- package/build/higher-order/pure/index.js +1 -2
- package/build/higher-order/pure/index.js.map +1 -1
- package/build/higher-order/with-global-events/index.js +2 -3
- package/build/higher-order/with-global-events/index.js.map +1 -1
- package/build/higher-order/with-global-events/listener.js +1 -2
- package/build/higher-order/with-global-events/listener.js.map +1 -1
- package/build/higher-order/with-instance-id/index.js +1 -2
- package/build/higher-order/with-instance-id/index.js.map +1 -1
- package/build/higher-order/with-network-connectivity/index.native.js +1 -2
- package/build/higher-order/with-network-connectivity/index.native.js.map +1 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +1 -2
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build/higher-order/with-safe-timeout/index.js +1 -2
- package/build/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build/hooks/use-async-list/index.js +1 -2
- package/build/hooks/use-async-list/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.js +3 -5
- package/build/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.native.js +1 -2
- package/build/hooks/use-constrained-tabbing/index.native.js.map +1 -1
- package/build/hooks/use-dialog/index.js +5 -3
- package/build/hooks/use-dialog/index.js.map +1 -1
- package/build/hooks/use-focus-return/index.js +1 -2
- package/build/hooks/use-focus-return/index.js.map +1 -1
- package/build/hooks/use-instance-id/index.js +1 -2
- package/build/hooks/use-instance-id/index.js.map +1 -1
- package/build/hooks/use-isomorphic-layout-effect/index.js +1 -2
- package/build/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.js +1 -2
- package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.native.js +1 -2
- package/build/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.android.js +1 -2
- package/build/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.ios.js +1 -2
- package/build/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme-style/index.native.js +1 -2
- package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
- package/build/hooks/use-reduced-motion/index.js +1 -2
- package/build/hooks/use-reduced-motion/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.native.js +1 -2
- package/build/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build/hooks/use-viewport-match/index.js +1 -2
- package/build/hooks/use-viewport-match/index.js.map +1 -1
- package/build/hooks/use-warn-on-change/index.js +3 -4
- package/build/hooks/use-warn-on-change/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/index.js +2 -3
- package/build-module/higher-order/with-global-events/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.js +2 -3
- package/build-module/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build-module/hooks/use-dialog/index.js +4 -1
- package/build-module/hooks/use-dialog/index.js.map +1 -1
- package/build-module/hooks/use-warn-on-change/index.js +2 -3
- package/build-module/hooks/use-warn-on-change/index.js.map +1 -1
- package/build-types/hooks/use-constrained-tabbing/index.d.ts.map +1 -1
- package/build-types/hooks/use-dialog/index.d.ts +19 -0
- package/build-types/hooks/use-dialog/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/hooks/use-constrained-tabbing/index.js +2 -3
- package/src/hooks/use-dialog/index.ts +21 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -5,6 +5,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
const useKeyboardShortcut = () => null;
|
|
8
|
-
var _default = useKeyboardShortcut;
|
|
9
|
-
exports.default = _default;
|
|
8
|
+
var _default = exports.default = useKeyboardShortcut;
|
|
10
9
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useKeyboardShortcut","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-keyboard-shortcut/index.native.js"],"sourcesContent":["const useKeyboardShortcut = () => null;\nexport default useKeyboardShortcut;\n"],"mappings":";;;;;;AAAA,MAAMA,mBAAmB,GAAGA,CAAA,KAAM,IAAI;AAAC,IAAAC,QAAA,
|
|
1
|
+
{"version":3,"names":["useKeyboardShortcut","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-keyboard-shortcut/index.native.js"],"sourcesContent":["const useKeyboardShortcut = () => null;\nexport default useKeyboardShortcut;\n"],"mappings":";;;;;;AAAA,MAAMA,mBAAmB,GAAGA,CAAA,KAAM,IAAI;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACxBH,mBAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_reactNativeBridge","usePreferredColorScheme","currentColorScheme","setCurrentColorScheme","useState","isInitialColorSchemeDark","useEffect","subscribePreferredColorScheme","isPreferredColorSchemeDark","colorScheme","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.android.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tsubscribePreferredColorScheme,\n\tisInitialColorSchemeDark,\n} from '@wordpress/react-native-bridge';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nfunction usePreferredColorScheme() {\n\tconst [ currentColorScheme, setCurrentColorScheme ] = useState(\n\t\tisInitialColorSchemeDark ? 'dark' : 'light'\n\t);\n\tuseEffect( () => {\n\t\tsubscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {\n\t\t\tconst colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';\n\t\t\tif ( colorScheme !== currentColorScheme ) {\n\t\t\t\tsetCurrentColorScheme( colorScheme );\n\t\t\t}\n\t\t} );\n\t} );\n\treturn currentColorScheme;\n}\n\nexport default usePreferredColorScheme;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA,SAASE,uBAAuBA,CAAA,EAAG;EAClC,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAG,IAAAC,iBAAQ,EAC7DC,2CAAwB,GAAG,MAAM,GAAG,OACrC,CAAC;EACD,IAAAC,kBAAS,EAAE,MAAM;IAChB,IAAAC,gDAA6B,EAAE,CAAE;MAAEC;IAA2B,CAAC,KAAM;MACpE,MAAMC,WAAW,GAAGD,0BAA0B,GAAG,MAAM,GAAG,OAAO;MACjE,IAAKC,WAAW,KAAKP,kBAAkB,EAAG;QACzCC,qBAAqB,CAAEM,WAAY,CAAC;MACrC;IACD,CAAE,CAAC;EACJ,CAAE,CAAC;EACH,OAAOP,kBAAkB;AAC1B;AAAC,IAAAQ,QAAA,
|
|
1
|
+
{"version":3,"names":["_element","require","_reactNativeBridge","usePreferredColorScheme","currentColorScheme","setCurrentColorScheme","useState","isInitialColorSchemeDark","useEffect","subscribePreferredColorScheme","isPreferredColorSchemeDark","colorScheme","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.android.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tsubscribePreferredColorScheme,\n\tisInitialColorSchemeDark,\n} from '@wordpress/react-native-bridge';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nfunction usePreferredColorScheme() {\n\tconst [ currentColorScheme, setCurrentColorScheme ] = useState(\n\t\tisInitialColorSchemeDark ? 'dark' : 'light'\n\t);\n\tuseEffect( () => {\n\t\tsubscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {\n\t\t\tconst colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';\n\t\t\tif ( colorScheme !== currentColorScheme ) {\n\t\t\t\tsetCurrentColorScheme( colorScheme );\n\t\t\t}\n\t\t} );\n\t} );\n\treturn currentColorScheme;\n}\n\nexport default usePreferredColorScheme;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA,SAASE,uBAAuBA,CAAA,EAAG;EAClC,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAG,IAAAC,iBAAQ,EAC7DC,2CAAwB,GAAG,MAAM,GAAG,OACrC,CAAC;EACD,IAAAC,kBAAS,EAAE,MAAM;IAChB,IAAAC,gDAA6B,EAAE,CAAE;MAAEC;IAA2B,CAAC,KAAM;MACpE,MAAMC,WAAW,GAAGD,0BAA0B,GAAG,MAAM,GAAG,OAAO;MACjE,IAAKC,WAAW,KAAKP,kBAAkB,EAAG;QACzCC,qBAAqB,CAAEM,WAAY,CAAC;MACrC;IACD,CAAE,CAAC;EACJ,CAAE,CAAC;EACH,OAAOP,kBAAkB;AAC1B;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcX,uBAAuB"}
|
|
@@ -15,6 +15,5 @@ var _reactNative = require("react-native");
|
|
|
15
15
|
* @return {string} return current color scheme.
|
|
16
16
|
*/
|
|
17
17
|
const usePreferredColorScheme = _reactNative.useColorScheme;
|
|
18
|
-
var _default = usePreferredColorScheme;
|
|
19
|
-
exports.default = _default;
|
|
18
|
+
var _default = exports.default = usePreferredColorScheme;
|
|
20
19
|
//# sourceMappingURL=index.ios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","usePreferredColorScheme","useColorScheme","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.ios.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { useColorScheme } from 'react-native';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nconst usePreferredColorScheme = useColorScheme;\n\nexport default usePreferredColorScheme;\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAAGC,2BAAc;AAAC,IAAAC,QAAA,
|
|
1
|
+
{"version":3,"names":["_reactNative","require","usePreferredColorScheme","useColorScheme","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.ios.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { useColorScheme } from 'react-native';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nconst usePreferredColorScheme = useColorScheme;\n\nexport default usePreferredColorScheme;\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAAGC,2BAAc;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEhCJ,uBAAuB"}
|
|
@@ -38,6 +38,5 @@ const usePreferredColorSchemeStyle = (lightStyle, darkStyle) => {
|
|
|
38
38
|
...darkStyle
|
|
39
39
|
} : lightStyle;
|
|
40
40
|
};
|
|
41
|
-
var _default = usePreferredColorSchemeStyle;
|
|
42
|
-
exports.default = _default;
|
|
41
|
+
var _default = exports.default = usePreferredColorSchemeStyle;
|
|
43
42
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_usePreferredColorScheme","_interopRequireDefault","require","usePreferredColorSchemeStyle","lightStyle","darkStyle","colorScheme","usePreferredColorScheme","isDarkMode","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme-style/index.native.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport usePreferredColorScheme from '../use-preferred-color-scheme';\n\n/**\n * Selects which of the passed style objects should be applied depending on the\n * user's preferred color scheme.\n *\n * The \"light\" color schemed is assumed to be the default, and its styles are\n * always applied. The \"dark\" styles will always extend those defined for the\n * light case.\n *\n * @example\n * const light = { padding: 10, backgroundColor: 'white' };\n * const dark = { backgroundColor: 'black' };\n * usePreferredColorSchemeStyle( light, dark);\n * // On light mode:\n * // => { padding: 10, backgroundColor: 'white' }\n * // On dark mode:\n * // => { padding: 10, backgroundColor: 'black' }\n * @param {Object} lightStyle\n * @param {Object} darkStyle\n * @return {Object} the combined styles depending on the current color scheme\n */\nconst usePreferredColorSchemeStyle = ( lightStyle, darkStyle ) => {\n\tconst colorScheme = usePreferredColorScheme();\n\tconst isDarkMode = colorScheme === 'dark';\n\n\treturn isDarkMode ? { ...lightStyle, ...darkStyle } : lightStyle;\n};\n\nexport default usePreferredColorSchemeStyle;\n"],"mappings":";;;;;;;AAGA,IAAAA,wBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,4BAA4B,GAAGA,CAAEC,UAAU,EAAEC,SAAS,KAAM;EACjE,MAAMC,WAAW,GAAG,IAAAC,gCAAuB,EAAC,CAAC;EAC7C,MAAMC,UAAU,GAAGF,WAAW,KAAK,MAAM;EAEzC,OAAOE,UAAU,GAAG;IAAE,GAAGJ,UAAU;IAAE,GAAGC;EAAU,CAAC,GAAGD,UAAU;AACjE,CAAC;AAAC,IAAAK,QAAA,
|
|
1
|
+
{"version":3,"names":["_usePreferredColorScheme","_interopRequireDefault","require","usePreferredColorSchemeStyle","lightStyle","darkStyle","colorScheme","usePreferredColorScheme","isDarkMode","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme-style/index.native.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport usePreferredColorScheme from '../use-preferred-color-scheme';\n\n/**\n * Selects which of the passed style objects should be applied depending on the\n * user's preferred color scheme.\n *\n * The \"light\" color schemed is assumed to be the default, and its styles are\n * always applied. The \"dark\" styles will always extend those defined for the\n * light case.\n *\n * @example\n * const light = { padding: 10, backgroundColor: 'white' };\n * const dark = { backgroundColor: 'black' };\n * usePreferredColorSchemeStyle( light, dark);\n * // On light mode:\n * // => { padding: 10, backgroundColor: 'white' }\n * // On dark mode:\n * // => { padding: 10, backgroundColor: 'black' }\n * @param {Object} lightStyle\n * @param {Object} darkStyle\n * @return {Object} the combined styles depending on the current color scheme\n */\nconst usePreferredColorSchemeStyle = ( lightStyle, darkStyle ) => {\n\tconst colorScheme = usePreferredColorScheme();\n\tconst isDarkMode = colorScheme === 'dark';\n\n\treturn isDarkMode ? { ...lightStyle, ...darkStyle } : lightStyle;\n};\n\nexport default usePreferredColorSchemeStyle;\n"],"mappings":";;;;;;;AAGA,IAAAA,wBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,4BAA4B,GAAGA,CAAEC,UAAU,EAAEC,SAAS,KAAM;EACjE,MAAMC,WAAW,GAAG,IAAAC,gCAAuB,EAAC,CAAC;EAC7C,MAAMC,UAAU,GAAGF,WAAW,KAAK,MAAM;EAEzC,OAAOE,UAAU,GAAG;IAAE,GAAGJ,UAAU;IAAE,GAAGC;EAAU,CAAC,GAAGD,UAAU;AACjE,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaR,4BAA4B"}
|
|
@@ -16,6 +16,5 @@ var _useMediaQuery = _interopRequireDefault(require("../use-media-query"));
|
|
|
16
16
|
* @return {boolean} Reduced motion preference value.
|
|
17
17
|
*/
|
|
18
18
|
const useReducedMotion = () => (0, _useMediaQuery.default)('(prefers-reduced-motion: reduce)');
|
|
19
|
-
var _default = useReducedMotion;
|
|
20
|
-
exports.default = _default;
|
|
19
|
+
var _default = exports.default = useReducedMotion;
|
|
21
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_useMediaQuery","_interopRequireDefault","require","useReducedMotion","useMediaQuery","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-reduced-motion/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * Hook returning whether the user has a preference for reduced motion.\n *\n * @return {boolean} Reduced motion preference value.\n */\nconst useReducedMotion = () =>\n\tuseMediaQuery( '(prefers-reduced-motion: reduce)' );\n\nexport default useReducedMotion;\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAA,KACxB,IAAAC,sBAAa,EAAE,kCAAmC,CAAC;AAAC,IAAAC,QAAA,
|
|
1
|
+
{"version":3,"names":["_useMediaQuery","_interopRequireDefault","require","useReducedMotion","useMediaQuery","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-reduced-motion/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * Hook returning whether the user has a preference for reduced motion.\n *\n * @return {boolean} Reduced motion preference value.\n */\nconst useReducedMotion = () =>\n\tuseMediaQuery( '(prefers-reduced-motion: reduce)' );\n\nexport default useReducedMotion;\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAA,KACxB,IAAAC,sBAAa,EAAE,kCAAmC,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEtCJ,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_element","useResizeObserver","measurements","setMeasurements","useState","onLayout","useCallback","nativeEvent","width","height","layout","prevState","Math","floor","observer","_react","createElement","View","testID","style","StyleSheet","absoluteFill","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"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 */\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"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AAPA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,iBAAiB,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAAEC,YAAY,EAAEC,eAAe,CAAE,GAAG,IAAAC,iBAAQ,EAAE,IAAK,CAAC;EAE1D,MAAMC,QAAQ,GAAG,IAAAC,oBAAW,EAAE,CAAE;IAAEC;EAAY,CAAC,KAAM;IACpD,MAAM;MAAEC,KAAK;MAAEC;IAAO,CAAC,GAAGF,WAAW,CAACG,MAAM;IAC5CP,eAAe,CAAIQ,SAAS,IAAM;MACjC,IACC,CAAEA,SAAS,IACXA,SAAS,CAACH,KAAK,KAAKA,KAAK,IACzBG,SAAS,CAACF,MAAM,KAAKA,MAAM,EAC1B;QACD,OAAO;UACND,KAAK,EAAEI,IAAI,CAACC,KAAK,CAAEL,KAAM,CAAC;UAC1BC,MAAM,EAAEG,IAAI,CAACC,KAAK,CAAEJ,MAAO;QAC5B,CAAC;MACF;MACA,OAAOE,SAAS;IACjB,CAAE,CAAC;EACJ,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMG,QAAQ,GACb,IAAAC,MAAA,CAAAC,aAAA,EAAClB,YAAA,CAAAmB,IAAI;IACJC,MAAM,EAAC,iBAAiB;IACxBC,KAAK,EAAGC,uBAAU,CAACC,YAAc;IACjChB,QAAQ,EAAGA;EAAU,CACrB,CACD;EAED,OAAO,CAAES,QAAQ,EAAEZ,YAAY,CAAE;AAClC,CAAC;AAAC,IAAAoB,QAAA,
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_element","useResizeObserver","measurements","setMeasurements","useState","onLayout","useCallback","nativeEvent","width","height","layout","prevState","Math","floor","observer","_react","createElement","View","testID","style","StyleSheet","absoluteFill","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.native.js"],"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 */\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"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AAPA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,iBAAiB,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAAEC,YAAY,EAAEC,eAAe,CAAE,GAAG,IAAAC,iBAAQ,EAAE,IAAK,CAAC;EAE1D,MAAMC,QAAQ,GAAG,IAAAC,oBAAW,EAAE,CAAE;IAAEC;EAAY,CAAC,KAAM;IACpD,MAAM;MAAEC,KAAK;MAAEC;IAAO,CAAC,GAAGF,WAAW,CAACG,MAAM;IAC5CP,eAAe,CAAIQ,SAAS,IAAM;MACjC,IACC,CAAEA,SAAS,IACXA,SAAS,CAACH,KAAK,KAAKA,KAAK,IACzBG,SAAS,CAACF,MAAM,KAAKA,MAAM,EAC1B;QACD,OAAO;UACND,KAAK,EAAEI,IAAI,CAACC,KAAK,CAAEL,KAAM,CAAC;UAC1BC,MAAM,EAAEG,IAAI,CAACC,KAAK,CAAEJ,MAAO;QAC5B,CAAC;MACF;MACA,OAAOE,SAAS;IACjB,CAAE,CAAC;EACJ,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMG,QAAQ,GACb,IAAAC,MAAA,CAAAC,aAAA,EAAClB,YAAA,CAAAmB,IAAI;IACJC,MAAM,EAAC,iBAAiB;IACxBC,KAAK,EAAGC,uBAAU,CAACC,YAAc;IACjChB,QAAQ,EAAGA;EAAU,CACrB,CACD;EAED,OAAO,CAAES,QAAQ,EAAEZ,YAAY,CAAE;AAClC,CAAC;AAAC,IAAAoB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEavB,iBAAiB"}
|
|
@@ -85,6 +85,5 @@ const useViewportMatch = (breakpoint, operator = '>=') => {
|
|
|
85
85
|
return mediaQueryResult;
|
|
86
86
|
};
|
|
87
87
|
useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
|
|
88
|
-
var _default = useViewportMatch;
|
|
89
|
-
exports.default = _default;
|
|
88
|
+
var _default = exports.default = useViewportMatch;
|
|
90
89
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_useMediaQuery","_interopRequireDefault","BREAKPOINTS","huge","wide","large","medium","small","mobile","CONDITIONS","OPERATOR_EVALUATORS",">=","breakpointValue","width","<","ViewportMatchWidthContext","createContext","useViewportMatch","breakpoint","operator","simulatedWidth","useContext","mediaQuery","mediaQueryResult","useMediaQuery","undefined","__experimentalWidthProvider","Provider","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-viewport-match/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * @typedef {\"huge\" | \"wide\" | \"large\" | \"medium\" | \"small\" | \"mobile\"} WPBreakpoint\n */\n\n/**\n * Hash of breakpoint names with pixel width at which it becomes effective.\n *\n * @see _breakpoints.scss\n *\n * @type {Record<WPBreakpoint, number>}\n */\nconst BREAKPOINTS = {\n\thuge: 1440,\n\twide: 1280,\n\tlarge: 960,\n\tmedium: 782,\n\tsmall: 600,\n\tmobile: 480,\n};\n\n/**\n * @typedef {\">=\" | \"<\"} WPViewportOperator\n */\n\n/**\n * Object mapping media query operators to the condition to be used.\n *\n * @type {Record<WPViewportOperator, string>}\n */\nconst CONDITIONS = {\n\t'>=': 'min-width',\n\t'<': 'max-width',\n};\n\n/**\n * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.\n *\n * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}\n */\nconst OPERATOR_EVALUATORS = {\n\t'>=': ( breakpointValue, width ) => width >= breakpointValue,\n\t'<': ( breakpointValue, width ) => width < breakpointValue,\n};\n\nconst ViewportMatchWidthContext = createContext(\n\t/** @type {null | number} */ ( null )\n);\n\n/**\n * Returns true if the viewport matches the given query, or false otherwise.\n *\n * @param {WPBreakpoint} breakpoint Breakpoint size name.\n * @param {WPViewportOperator} [operator=\">=\"] Viewport operator.\n *\n * @example\n *\n * ```js\n * useViewportMatch( 'huge', '<' );\n * useViewportMatch( 'medium' );\n * ```\n *\n * @return {boolean} Whether viewport matches query.\n */\nconst useViewportMatch = ( breakpoint, operator = '>=' ) => {\n\tconst simulatedWidth = useContext( ViewportMatchWidthContext );\n\tconst mediaQuery =\n\t\t! simulatedWidth &&\n\t\t`(${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;\n\tconst mediaQueryResult = useMediaQuery( mediaQuery || undefined );\n\tif ( simulatedWidth ) {\n\t\treturn OPERATOR_EVALUATORS[ operator ](\n\t\t\tBREAKPOINTS[ breakpoint ],\n\t\t\tsimulatedWidth\n\t\t);\n\t}\n\treturn mediaQueryResult;\n};\n\nuseViewportMatch.__experimentalWidthProvider =\n\tViewportMatchWidthContext.Provider;\n\nexport default useViewportMatch;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,cAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,WAAW,GAAG;EACnBC,IAAI,EAAE,IAAI;EACVC,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE,GAAG;EACXC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE;AACT,CAAC;;AAED;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAG;EAClB,IAAI,EAAE,WAAW;EACjB,GAAG,EAAE;AACN,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG;EAC3B,IAAI,EAAEC,CAAEC,eAAe,EAAEC,KAAK,KAAMA,KAAK,IAAID,eAAe;EAC5D,GAAG,EAAEE,CAAEF,eAAe,EAAEC,KAAK,KAAMA,KAAK,GAAGD;AAC5C,CAAC;AAED,MAAMG,yBAAyB,GAAG,IAAAC,sBAAa,GAC9C,4BAA+B,IAChC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAEC,UAAU,EAAEC,QAAQ,GAAG,IAAI,KAAM;EAC3D,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAAEN,yBAA0B,CAAC;EAC9D,MAAMO,UAAU,GACf,CAAEF,cAAc,IACf,IAAIX,UAAU,CAAEU,QAAQ,CAAI,KAAKjB,WAAW,CAAEgB,UAAU,CAAI,KAAI;EAClE,MAAMK,gBAAgB,GAAG,IAAAC,sBAAa,EAAEF,UAAU,IAAIG,SAAU,CAAC;EACjE,IAAKL,cAAc,EAAG;IACrB,OAAOV,mBAAmB,CAAES,QAAQ,CAAE,CACrCjB,WAAW,CAAEgB,UAAU,CAAE,EACzBE,cACD,CAAC;EACF;EACA,OAAOG,gBAAgB;AACxB,CAAC;AAEDN,gBAAgB,CAACS,2BAA2B,GAC3CX,yBAAyB,CAACY,QAAQ;AAAC,IAAAC,QAAA,
|
|
1
|
+
{"version":3,"names":["_element","require","_useMediaQuery","_interopRequireDefault","BREAKPOINTS","huge","wide","large","medium","small","mobile","CONDITIONS","OPERATOR_EVALUATORS",">=","breakpointValue","width","<","ViewportMatchWidthContext","createContext","useViewportMatch","breakpoint","operator","simulatedWidth","useContext","mediaQuery","mediaQueryResult","useMediaQuery","undefined","__experimentalWidthProvider","Provider","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-viewport-match/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * @typedef {\"huge\" | \"wide\" | \"large\" | \"medium\" | \"small\" | \"mobile\"} WPBreakpoint\n */\n\n/**\n * Hash of breakpoint names with pixel width at which it becomes effective.\n *\n * @see _breakpoints.scss\n *\n * @type {Record<WPBreakpoint, number>}\n */\nconst BREAKPOINTS = {\n\thuge: 1440,\n\twide: 1280,\n\tlarge: 960,\n\tmedium: 782,\n\tsmall: 600,\n\tmobile: 480,\n};\n\n/**\n * @typedef {\">=\" | \"<\"} WPViewportOperator\n */\n\n/**\n * Object mapping media query operators to the condition to be used.\n *\n * @type {Record<WPViewportOperator, string>}\n */\nconst CONDITIONS = {\n\t'>=': 'min-width',\n\t'<': 'max-width',\n};\n\n/**\n * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.\n *\n * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}\n */\nconst OPERATOR_EVALUATORS = {\n\t'>=': ( breakpointValue, width ) => width >= breakpointValue,\n\t'<': ( breakpointValue, width ) => width < breakpointValue,\n};\n\nconst ViewportMatchWidthContext = createContext(\n\t/** @type {null | number} */ ( null )\n);\n\n/**\n * Returns true if the viewport matches the given query, or false otherwise.\n *\n * @param {WPBreakpoint} breakpoint Breakpoint size name.\n * @param {WPViewportOperator} [operator=\">=\"] Viewport operator.\n *\n * @example\n *\n * ```js\n * useViewportMatch( 'huge', '<' );\n * useViewportMatch( 'medium' );\n * ```\n *\n * @return {boolean} Whether viewport matches query.\n */\nconst useViewportMatch = ( breakpoint, operator = '>=' ) => {\n\tconst simulatedWidth = useContext( ViewportMatchWidthContext );\n\tconst mediaQuery =\n\t\t! simulatedWidth &&\n\t\t`(${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;\n\tconst mediaQueryResult = useMediaQuery( mediaQuery || undefined );\n\tif ( simulatedWidth ) {\n\t\treturn OPERATOR_EVALUATORS[ operator ](\n\t\t\tBREAKPOINTS[ breakpoint ],\n\t\t\tsimulatedWidth\n\t\t);\n\t}\n\treturn mediaQueryResult;\n};\n\nuseViewportMatch.__experimentalWidthProvider =\n\tViewportMatchWidthContext.Provider;\n\nexport default useViewportMatch;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,cAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,WAAW,GAAG;EACnBC,IAAI,EAAE,IAAI;EACVC,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE,GAAG;EACXC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE;AACT,CAAC;;AAED;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAG;EAClB,IAAI,EAAE,WAAW;EACjB,GAAG,EAAE;AACN,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG;EAC3B,IAAI,EAAEC,CAAEC,eAAe,EAAEC,KAAK,KAAMA,KAAK,IAAID,eAAe;EAC5D,GAAG,EAAEE,CAAEF,eAAe,EAAEC,KAAK,KAAMA,KAAK,GAAGD;AAC5C,CAAC;AAED,MAAMG,yBAAyB,GAAG,IAAAC,sBAAa,GAC9C,4BAA+B,IAChC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAEC,UAAU,EAAEC,QAAQ,GAAG,IAAI,KAAM;EAC3D,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAAEN,yBAA0B,CAAC;EAC9D,MAAMO,UAAU,GACf,CAAEF,cAAc,IACf,IAAIX,UAAU,CAAEU,QAAQ,CAAI,KAAKjB,WAAW,CAAEgB,UAAU,CAAI,KAAI;EAClE,MAAMK,gBAAgB,GAAG,IAAAC,sBAAa,EAAEF,UAAU,IAAIG,SAAU,CAAC;EACjE,IAAKL,cAAc,EAAG;IACrB,OAAOV,mBAAmB,CAAES,QAAQ,CAAE,CACrCjB,WAAW,CAAEgB,UAAU,CAAE,EACzBE,cACD,CAAC;EACF;EACA,OAAOG,gBAAgB;AACxB,CAAC;AAEDN,gBAAgB,CAACS,2BAA2B,GAC3CX,yBAAyB,CAACY,QAAQ;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAErBb,gBAAgB"}
|
|
@@ -34,13 +34,12 @@ var _usePrevious = _interopRequireDefault(require("../use-previous"));
|
|
|
34
34
|
function useWarnOnChange(object, prefix = 'Change detection') {
|
|
35
35
|
const previousValues = (0, _usePrevious.default)(object);
|
|
36
36
|
Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(([key, value]) => {
|
|
37
|
-
if (value !== object[/** @type {keyof typeof object} */key]) {
|
|
37
|
+
if (value !== object[( /** @type {keyof typeof object} */key)]) {
|
|
38
38
|
// eslint-disable-next-line no-console
|
|
39
|
-
console.warn(`${prefix}: ${key} key changed:`, value, object[/** @type {keyof typeof object} */key]
|
|
39
|
+
console.warn(`${prefix}: ${key} key changed:`, value, object[( /** @type {keyof typeof object} */key)]
|
|
40
40
|
/* eslint-enable jsdoc/check-types */);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
var _default = useWarnOnChange;
|
|
45
|
-
exports.default = _default;
|
|
44
|
+
var _default = exports.default = useWarnOnChange;
|
|
46
45
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_usePrevious","_interopRequireDefault","require","useWarnOnChange","object","prefix","previousValues","usePrevious","Object","entries","forEach","key","value","console","warn","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-warn-on-change/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case\n// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript\n/* eslint-disable jsdoc/check-types */\n/**\n * Hook that performs a shallow comparison between the preview value of an object\n * and the new one, if there's a difference, it prints it to the console.\n * this is useful in performance related work, to check why a component re-renders.\n *\n * @example\n *\n * ```jsx\n * function MyComponent(props) {\n * useWarnOnChange(props);\n *\n * return \"Something\";\n * }\n * ```\n *\n * @param {object} object Object which changes to compare.\n * @param {string} prefix Just a prefix to show when console logging.\n */\nfunction useWarnOnChange( object, prefix = 'Change detection' ) {\n\tconst previousValues = usePrevious( object );\n\n\tObject.entries( previousValues ?? [] ).forEach( ( [ key, value ] ) => {\n\t\tif ( value !== object[ /** @type {keyof typeof object} */ ( key ) ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`${ prefix }: ${ key } key changed:`,\n\t\t\t\tvalue,\n\t\t\t\tobject[ /** @type {keyof typeof object} */ ( key ) ]\n\t\t\t\t/* eslint-enable jsdoc/check-types */\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport default useWarnOnChange;\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAEC,MAAM,EAAEC,MAAM,GAAG,kBAAkB,EAAG;EAC/D,MAAMC,cAAc,GAAG,IAAAC,oBAAW,EAAEH,MAAO,CAAC;EAE5CI,MAAM,CAACC,OAAO,CAAEH,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAI,EAAG,CAAC,CAACI,OAAO,CAAE,CAAE,CAAEC,GAAG,EAAEC,KAAK,CAAE,KAAM;IACrE,IAAKA,KAAK,KAAKR,MAAM,
|
|
1
|
+
{"version":3,"names":["_usePrevious","_interopRequireDefault","require","useWarnOnChange","object","prefix","previousValues","usePrevious","Object","entries","forEach","key","value","console","warn","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-warn-on-change/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case\n// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript\n/* eslint-disable jsdoc/check-types */\n/**\n * Hook that performs a shallow comparison between the preview value of an object\n * and the new one, if there's a difference, it prints it to the console.\n * this is useful in performance related work, to check why a component re-renders.\n *\n * @example\n *\n * ```jsx\n * function MyComponent(props) {\n * useWarnOnChange(props);\n *\n * return \"Something\";\n * }\n * ```\n *\n * @param {object} object Object which changes to compare.\n * @param {string} prefix Just a prefix to show when console logging.\n */\nfunction useWarnOnChange( object, prefix = 'Change detection' ) {\n\tconst previousValues = usePrevious( object );\n\n\tObject.entries( previousValues ?? [] ).forEach( ( [ key, value ] ) => {\n\t\tif ( value !== object[ /** @type {keyof typeof object} */ ( key ) ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`${ prefix }: ${ key } key changed:`,\n\t\t\t\tvalue,\n\t\t\t\tobject[ /** @type {keyof typeof object} */ ( key ) ]\n\t\t\t\t/* eslint-enable jsdoc/check-types */\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport default useWarnOnChange;\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAEC,MAAM,EAAEC,MAAM,GAAG,kBAAkB,EAAG;EAC/D,MAAMC,cAAc,GAAG,IAAAC,oBAAW,EAAEH,MAAO,CAAC;EAE5CI,MAAM,CAACC,OAAO,CAAEH,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAI,EAAG,CAAC,CAACI,OAAO,CAAE,CAAE,CAAEC,GAAG,EAAEC,KAAK,CAAE,KAAM;IACrE,IAAKA,KAAK,KAAKR,MAAM,GAAE,kCAAqCO,GAAG,EAAI,EAAG;MACrE;MACAE,OAAO,CAACC,IAAI,CACV,GAAGT,MAAQ,KAAKM,GAAK,eAAc,EACpCC,KAAK,EACLR,MAAM,GAAE,kCAAqCO,GAAG;MAChD,qCACD,CAAC;IACF;EACD,CAAE,CAAC;AACJ;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcd,eAAe"}
|
|
@@ -61,11 +61,10 @@ export default function withGlobalEvents(eventTypesToHandlers) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
handleEvent( /** @type {any} */event) {
|
|
64
|
-
const handler = eventTypesToHandlers[/** @type {keyof GlobalEventHandlersEventMap} */
|
|
64
|
+
const handler = eventTypesToHandlers[( /** @type {keyof GlobalEventHandlersEventMap} */
|
|
65
65
|
event.type
|
|
66
66
|
|
|
67
|
-
/* eslint-enable jsdoc/no-undefined-types */];
|
|
68
|
-
|
|
67
|
+
/* eslint-enable jsdoc/no-undefined-types */)];
|
|
69
68
|
if (typeof this.wrappedRef[handler] === 'function') {
|
|
70
69
|
this.wrappedRef[handler](event);
|
|
71
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Component","forwardRef","deprecated","createHigherOrderComponent","Listener","listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","constructor","props","handleEvent","bind","handleRef","componentDidMount","Object","keys","forEach","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","createElement","ownProps","ref"],"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport Listener from './listener';\n\n/**\n * Listener instance responsible for managing document event handling.\n */\nconst listener = new Listener();\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Higher-order component creator which, given an object of DOM event types and\n * values corresponding to a callback function name on the component, will\n * create or update a window event handler to invoke the callback when an event\n * occurs. On behalf of the consuming developer, the higher-order component\n * manages unbinding when the component unmounts, and binding at most a single\n * event handler for the entire application.\n *\n * @deprecated\n *\n * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM\n * event type, the value a\n * name of the function on\n * the original component's\n * instance which handles\n * the event.\n *\n * @return {any} Higher-order component.\n */\nexport default function withGlobalEvents( eventTypesToHandlers ) {\n\tdeprecated( 'wp.compose.withGlobalEvents', {\n\t\tsince: '5.7',\n\t\talternative: 'useEffect',\n\t} );\n\n\t// @ts-ignore We don't need to fix the type-related issues because this is deprecated.\n\treturn createHigherOrderComponent( ( WrappedComponent ) => {\n\t\tclass Wrapper extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t\t\t\tthis.handleRef = this.handleRef.bind( this );\n\t\t\t}\n\n\t\t\tcomponentDidMount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.add( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.remove( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\thandleEvent( /** @type {any} */ event ) {\n\t\t\t\tconst handler =\n\t\t\t\t\teventTypesToHandlers[\n\t\t\t\t\t\t/** @type {keyof GlobalEventHandlersEventMap} */ (\n\t\t\t\t\t\t\tevent.type\n\t\t\t\t\t\t)\n\t\t\t\t\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t\t\t\t\t];\n\t\t\t\tif ( typeof this.wrappedRef[ handler ] === 'function' ) {\n\t\t\t\t\tthis.wrappedRef[ handler ]( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\thandleRef( /** @type {any} */ el ) {\n\t\t\t\tthis.wrappedRef = el;\n\t\t\t\t// Any component using `withGlobalEvents` that is not setting a `ref`\n\t\t\t\t// will cause `this.props.forwardedRef` to be `null`, so we need this\n\t\t\t\t// check.\n\t\t\t\tif ( this.props.forwardedRef ) {\n\t\t\t\t\tthis.props.forwardedRef( el );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...this.props.ownProps }\n\t\t\t\t\t\tref={ this.handleRef }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn forwardRef( ( props, ref ) => {\n\t\t\treturn <Wrapper ownProps={ props } forwardedRef={ ref } />;\n\t\t} );\n\t}, 'withGlobalEvents' );\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,UAAU,QAAQ,oBAAoB;AAC1D,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,SAASC,0BAA0B,QAAQ,2CAA2C;AACtF,OAAOC,QAAQ,MAAM,YAAY;;AAEjC;AACA;AACA;AACA,MAAMC,QAAQ,GAAG,IAAID,QAAQ,CAAC,CAAC;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASE,gBAAgBA,CAAEC,oBAAoB,EAAG;EAChEL,UAAU,CAAE,6BAA6B,EAAE;IAC1CM,KAAK,EAAE,KAAK;IACZC,WAAW,EAAE;EACd,CAAE,CAAC;;EAEH;EACA,OAAON,0BAA0B,CAAIO,gBAAgB,IAAM;IAC1D,MAAMC,OAAO,SAASX,SAAS,CAAC;MAC/BY,WAAWA,CAAA,CAAE,kBAAmBC,KAAK,EAAG;QACvC,KAAK,CAAEA,KAAM,CAAC;QAEd,IAAI,CAACC,WAAW,GAAG,IAAI,CAACA,WAAW,CAACC,IAAI,CAAE,IAAK,CAAC;QAChD,IAAI,CAACC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACD,IAAI,CAAE,IAAK,CAAC;MAC7C;MAEAE,iBAAiBA,CAAA,EAAG;QACnBC,MAAM,CAACC,IAAI,CAAEZ,oBAAqB,CAAC,CAACa,OAAO,CAAIC,SAAS,IAAM;UAC7DhB,QAAQ,CAACiB,GAAG,CAAED,SAAS,EAAE,IAAK,CAAC;QAChC,CAAE,CAAC;MACJ;MAEAE,oBAAoBA,CAAA,EAAG;QACtBL,MAAM,CAACC,IAAI,CAAEZ,oBAAqB,CAAC,CAACa,OAAO,CAAIC,SAAS,IAAM;UAC7DhB,QAAQ,CAACmB,MAAM,CAAEH,SAAS,EAAE,IAAK,CAAC;QACnC,CAAE,CAAC;MACJ;MAEAP,WAAWA,CAAA,CAAE,kBAAmBW,KAAK,EAAG;QACvC,MAAMC,OAAO,GACZnB,oBAAoB,
|
|
1
|
+
{"version":3,"names":["Component","forwardRef","deprecated","createHigherOrderComponent","Listener","listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","constructor","props","handleEvent","bind","handleRef","componentDidMount","Object","keys","forEach","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","createElement","ownProps","ref"],"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport Listener from './listener';\n\n/**\n * Listener instance responsible for managing document event handling.\n */\nconst listener = new Listener();\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Higher-order component creator which, given an object of DOM event types and\n * values corresponding to a callback function name on the component, will\n * create or update a window event handler to invoke the callback when an event\n * occurs. On behalf of the consuming developer, the higher-order component\n * manages unbinding when the component unmounts, and binding at most a single\n * event handler for the entire application.\n *\n * @deprecated\n *\n * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM\n * event type, the value a\n * name of the function on\n * the original component's\n * instance which handles\n * the event.\n *\n * @return {any} Higher-order component.\n */\nexport default function withGlobalEvents( eventTypesToHandlers ) {\n\tdeprecated( 'wp.compose.withGlobalEvents', {\n\t\tsince: '5.7',\n\t\talternative: 'useEffect',\n\t} );\n\n\t// @ts-ignore We don't need to fix the type-related issues because this is deprecated.\n\treturn createHigherOrderComponent( ( WrappedComponent ) => {\n\t\tclass Wrapper extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t\t\t\tthis.handleRef = this.handleRef.bind( this );\n\t\t\t}\n\n\t\t\tcomponentDidMount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.add( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.remove( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\thandleEvent( /** @type {any} */ event ) {\n\t\t\t\tconst handler =\n\t\t\t\t\teventTypesToHandlers[\n\t\t\t\t\t\t/** @type {keyof GlobalEventHandlersEventMap} */ (\n\t\t\t\t\t\t\tevent.type\n\t\t\t\t\t\t)\n\t\t\t\t\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t\t\t\t\t];\n\t\t\t\tif ( typeof this.wrappedRef[ handler ] === 'function' ) {\n\t\t\t\t\tthis.wrappedRef[ handler ]( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\thandleRef( /** @type {any} */ el ) {\n\t\t\t\tthis.wrappedRef = el;\n\t\t\t\t// Any component using `withGlobalEvents` that is not setting a `ref`\n\t\t\t\t// will cause `this.props.forwardedRef` to be `null`, so we need this\n\t\t\t\t// check.\n\t\t\t\tif ( this.props.forwardedRef ) {\n\t\t\t\t\tthis.props.forwardedRef( el );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...this.props.ownProps }\n\t\t\t\t\t\tref={ this.handleRef }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn forwardRef( ( props, ref ) => {\n\t\t\treturn <Wrapper ownProps={ props } forwardedRef={ ref } />;\n\t\t} );\n\t}, 'withGlobalEvents' );\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,UAAU,QAAQ,oBAAoB;AAC1D,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,SAASC,0BAA0B,QAAQ,2CAA2C;AACtF,OAAOC,QAAQ,MAAM,YAAY;;AAEjC;AACA;AACA;AACA,MAAMC,QAAQ,GAAG,IAAID,QAAQ,CAAC,CAAC;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASE,gBAAgBA,CAAEC,oBAAoB,EAAG;EAChEL,UAAU,CAAE,6BAA6B,EAAE;IAC1CM,KAAK,EAAE,KAAK;IACZC,WAAW,EAAE;EACd,CAAE,CAAC;;EAEH;EACA,OAAON,0BAA0B,CAAIO,gBAAgB,IAAM;IAC1D,MAAMC,OAAO,SAASX,SAAS,CAAC;MAC/BY,WAAWA,CAAA,CAAE,kBAAmBC,KAAK,EAAG;QACvC,KAAK,CAAEA,KAAM,CAAC;QAEd,IAAI,CAACC,WAAW,GAAG,IAAI,CAACA,WAAW,CAACC,IAAI,CAAE,IAAK,CAAC;QAChD,IAAI,CAACC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACD,IAAI,CAAE,IAAK,CAAC;MAC7C;MAEAE,iBAAiBA,CAAA,EAAG;QACnBC,MAAM,CAACC,IAAI,CAAEZ,oBAAqB,CAAC,CAACa,OAAO,CAAIC,SAAS,IAAM;UAC7DhB,QAAQ,CAACiB,GAAG,CAAED,SAAS,EAAE,IAAK,CAAC;QAChC,CAAE,CAAC;MACJ;MAEAE,oBAAoBA,CAAA,EAAG;QACtBL,MAAM,CAACC,IAAI,CAAEZ,oBAAqB,CAAC,CAACa,OAAO,CAAIC,SAAS,IAAM;UAC7DhB,QAAQ,CAACmB,MAAM,CAAEH,SAAS,EAAE,IAAK,CAAC;QACnC,CAAE,CAAC;MACJ;MAEAP,WAAWA,CAAA,CAAE,kBAAmBW,KAAK,EAAG;QACvC,MAAMC,OAAO,GACZnB,oBAAoB,GACnB;QACCkB,KAAK,CAACE;;QAEP,8CACA;QACF,IAAK,OAAO,IAAI,CAACC,UAAU,CAAEF,OAAO,CAAE,KAAK,UAAU,EAAG;UACvD,IAAI,CAACE,UAAU,CAAEF,OAAO,CAAE,CAAED,KAAM,CAAC;QACpC;MACD;MAEAT,SAASA,CAAA,CAAE,kBAAmBa,EAAE,EAAG;QAClC,IAAI,CAACD,UAAU,GAAGC,EAAE;QACpB;QACA;QACA;QACA,IAAK,IAAI,CAAChB,KAAK,CAACiB,YAAY,EAAG;UAC9B,IAAI,CAACjB,KAAK,CAACiB,YAAY,CAAED,EAAG,CAAC;QAC9B;MACD;MAEAE,MAAMA,CAAA,EAAG;QACR,OACCC,aAAA,CAACtB,gBAAgB;UAAA,GACX,IAAI,CAACG,KAAK,CAACoB,QAAQ;UACxBC,GAAG,EAAG,IAAI,CAAClB;QAAW,CACtB,CAAC;MAEJ;IACD;IAEA,OAAOf,UAAU,CAAE,CAAEY,KAAK,EAAEqB,GAAG,KAAM;MACpC,OAAOF,aAAA,CAACrB,OAAO;QAACsB,QAAQ,EAAGpB,KAAO;QAACiB,YAAY,EAAGI;MAAK,CAAE,CAAC;IAC3D,CAAE,CAAC;EACJ,CAAC,EAAE,kBAAmB,CAAC;AACxB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { TAB } from '@wordpress/keycodes';
|
|
5
4
|
import { focus } from '@wordpress/dom';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -34,11 +33,11 @@ function useConstrainedTabbing() {
|
|
|
34
33
|
return useRefEffect(( /** @type {HTMLElement} */node) => {
|
|
35
34
|
function onKeyDown( /** @type {KeyboardEvent} */event) {
|
|
36
35
|
const {
|
|
37
|
-
|
|
36
|
+
key,
|
|
38
37
|
shiftKey,
|
|
39
38
|
target
|
|
40
39
|
} = event;
|
|
41
|
-
if (
|
|
40
|
+
if (key !== 'Tab') {
|
|
42
41
|
return;
|
|
43
42
|
}
|
|
44
43
|
const action = shiftKey ? 'findPrevious' : 'findNext';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["focus","useRefEffect","useConstrainedTabbing","node","onKeyDown","event","key","shiftKey","target","action","nextElement","tabbable","contains","preventDefault","domAction","ownerDocument","trap","createElement","tabIndex","addEventListener","removeChild","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In Dialogs/modals, the tabbing must be constrained to the content of\n * the wrapper element. This hook adds the behavior to the returned ref.\n *\n * @return {import('react').RefCallback<Element>} Element Ref.\n *\n * @example\n * ```js\n * import { useConstrainedTabbing } from '@wordpress/compose';\n *\n * const ConstrainedTabbingExample = () => {\n * const constrainedTabbingRef = useConstrainedTabbing()\n * return (\n * <div ref={ constrainedTabbingRef }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useConstrainedTabbing() {\n\treturn useRefEffect( ( /** @type {HTMLElement} */ node ) => {\n\t\tfunction onKeyDown( /** @type {KeyboardEvent} */ event ) {\n\t\t\tconst { key, shiftKey, target } = event;\n\n\t\t\tif ( key !== 'Tab' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst action = shiftKey ? 'findPrevious' : 'findNext';\n\t\t\tconst nextElement =\n\t\t\t\tfocus.tabbable[ action ](\n\t\t\t\t\t/** @type {HTMLElement} */ ( target )\n\t\t\t\t) || null;\n\n\t\t\t// When the target element contains the element that is about to\n\t\t\t// receive focus, for example when the target is a tabbable\n\t\t\t// container, browsers may disagree on where to move focus next.\n\t\t\t// In this case we can't rely on native browsers behavior. We need\n\t\t\t// to manage focus instead.\n\t\t\t// See https://github.com/WordPress/gutenberg/issues/46041.\n\t\t\tif (\n\t\t\t\t/** @type {HTMLElement} */ ( target ).contains( nextElement )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\t/** @type {HTMLElement} */ ( nextElement )?.focus();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the element that is about to receive focus is inside the\n\t\t\t// area, rely on native browsers behavior and let tabbing follow\n\t\t\t// the native tab sequence.\n\t\t\tif ( node.contains( nextElement ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the element that is about to receive focus is outside the\n\t\t\t// area, move focus to a div and insert it at the start or end of\n\t\t\t// the area, depending on the direction. Without preventing default\n\t\t\t// behaviour, the browser will then move focus to the next element.\n\t\t\tconst domAction = shiftKey ? 'append' : 'prepend';\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst trap = ownerDocument.createElement( 'div' );\n\n\t\t\ttrap.tabIndex = -1;\n\t\t\tnode[ domAction ]( trap );\n\n\t\t\t// Remove itself when the trap loses focus.\n\t\t\ttrap.addEventListener( 'blur', () => node.removeChild( trap ) );\n\n\t\t\ttrap.focus();\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n\nexport default useConstrainedTabbing;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,gBAAgB;;AAEtC;AACA;AACA;AACA,OAAOC,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,qBAAqBA,CAAA,EAAG;EAChC,OAAOD,YAAY,CAAE,EAAE,0BAA2BE,IAAI,KAAM;IAC3D,SAASC,SAASA,CAAA,CAAE,4BAA6BC,KAAK,EAAG;MACxD,MAAM;QAAEC,GAAG;QAAEC,QAAQ;QAAEC;MAAO,CAAC,GAAGH,KAAK;MAEvC,IAAKC,GAAG,KAAK,KAAK,EAAG;QACpB;MACD;MAEA,MAAMG,MAAM,GAAGF,QAAQ,GAAG,cAAc,GAAG,UAAU;MACrD,MAAMG,WAAW,GAChBV,KAAK,CAACW,QAAQ,CAAEF,MAAM,CAAE,EACvB,0BAA6BD,MAC9B,CAAC,IAAI,IAAI;;MAEV;MACA;MACA;MACA;MACA;MACA;MACA,KACC,0BAA6BA,MAAM,CAAGI,QAAQ,CAAEF,WAAY,CAAC,EAC5D;QACDL,KAAK,CAACQ,cAAc,CAAC,CAAC;QACtB;QAA6BH,WAAW,EAAIV,KAAK,CAAC,CAAC;QACnD;MACD;;MAEA;MACA;MACA;MACA,IAAKG,IAAI,CAACS,QAAQ,CAAEF,WAAY,CAAC,EAAG;QACnC;MACD;;MAEA;MACA;MACA;MACA;MACA,MAAMI,SAAS,GAAGP,QAAQ,GAAG,QAAQ,GAAG,SAAS;MACjD,MAAM;QAAEQ;MAAc,CAAC,GAAGZ,IAAI;MAC9B,MAAMa,IAAI,GAAGD,aAAa,CAACE,aAAa,CAAE,KAAM,CAAC;MAEjDD,IAAI,CAACE,QAAQ,GAAG,CAAC,CAAC;MAClBf,IAAI,CAAEW,SAAS,CAAE,CAAEE,IAAK,CAAC;;MAEzB;MACAA,IAAI,CAACG,gBAAgB,CAAE,MAAM,EAAE,MAAMhB,IAAI,CAACiB,WAAW,CAAEJ,IAAK,CAAE,CAAC;MAE/DA,IAAI,CAAChB,KAAK,CAAC,CAAC;IACb;IAEAG,IAAI,CAACgB,gBAAgB,CAAE,SAAS,EAAEf,SAAU,CAAC;IAC7C,OAAO,MAAM;MACZD,IAAI,CAACkB,mBAAmB,CAAE,SAAS,EAAEjB,SAAU,CAAC;IACjD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR;AAEA,eAAeF,qBAAqB"}
|
|
@@ -27,6 +27,9 @@ import useMergeRefs from '../use-merge-refs';
|
|
|
27
27
|
*/
|
|
28
28
|
function useDialog(options) {
|
|
29
29
|
const currentOptions = useRef();
|
|
30
|
+
const {
|
|
31
|
+
constrainTabbing = options.focusOnMount !== false
|
|
32
|
+
} = options;
|
|
30
33
|
useEffect(() => {
|
|
31
34
|
currentOptions.current = options;
|
|
32
35
|
}, Object.values(options));
|
|
@@ -54,7 +57,7 @@ function useDialog(options) {
|
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
}, []);
|
|
57
|
-
return [useMergeRefs([
|
|
60
|
+
return [useMergeRefs([constrainTabbing ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), {
|
|
58
61
|
...focusOutsideProps,
|
|
59
62
|
tabIndex: -1
|
|
60
63
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useRef","useEffect","useCallback","ESCAPE","useConstrainedTabbing","useFocusOnMount","useFocusReturn","useFocusOutside","useMergeRefs","useDialog","options","currentOptions","current","Object","values","constrainedTabbingRef","focusOnMountRef","
|
|
1
|
+
{"version":3,"names":["useRef","useEffect","useCallback","ESCAPE","useConstrainedTabbing","useFocusOnMount","useFocusReturn","useFocusOutside","useMergeRefs","useDialog","options","currentOptions","constrainTabbing","focusOnMount","current","Object","values","constrainedTabbingRef","focusOnMountRef","focusReturnRef","focusOutsideProps","event","__unstableOnClose","onClose","closeOnEscapeRef","node","addEventListener","keyCode","defaultPrevented","preventDefault","tabIndex"],"sources":["@wordpress/compose/src/hooks/use-dialog/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback, SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport useConstrainedTabbing from '../use-constrained-tabbing';\nimport useFocusOnMount from '../use-focus-on-mount';\nimport useFocusReturn from '../use-focus-return';\nimport useFocusOutside from '../use-focus-outside';\nimport useMergeRefs from '../use-merge-refs';\n\ntype DialogOptions = {\n\t/**\n\t * Determines whether focus should be automatically moved to the popover\n\t * when it mounts. `false` causes no focus shift, `true` causes the popover\n\t * itself to gain focus, and `firstElement` focuses the first focusable\n\t * element within the popover.\n\t *\n\t * @default 'firstElement'\n\t */\n\tfocusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];\n\t/**\n\t * Determines whether tabbing is constrained to within the popover,\n\t * preventing keyboard focus from leaving the popover content without\n\t * explicit focus elsewhere, or whether the popover remains part of the\n\t * wider tab order.\n\t * If no value is passed, it will be derived from `focusOnMount`.\n\t *\n\t * @see focusOnMount\n\t * @default `focusOnMount` !== false\n\t */\n\tconstrainTabbing?: boolean;\n\tonClose?: () => void;\n\t/**\n\t * Use the `onClose` prop instead.\n\t *\n\t * @deprecated\n\t */\n\t__unstableOnClose?: (\n\t\ttype: string | undefined,\n\t\tevent: SyntheticEvent\n\t) => void;\n};\n\ntype useDialogReturn = [\n\tRefCallback< HTMLElement >,\n\tReturnType< typeof useFocusOutside > & Pick< HTMLElement, 'tabIndex' >,\n];\n\n/**\n * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:\n * - constrained tabbing.\n * - focus on mount.\n * - return focus on unmount.\n * - focus outside.\n *\n * @param options Dialog Options.\n */\nfunction useDialog( options: DialogOptions ): useDialogReturn {\n\tconst currentOptions = useRef< DialogOptions | undefined >();\n\tconst { constrainTabbing = options.focusOnMount !== false } = options;\n\tuseEffect( () => {\n\t\tcurrentOptions.current = options;\n\t}, Object.values( options ) );\n\tconst constrainedTabbingRef = useConstrainedTabbing();\n\tconst focusOnMountRef = useFocusOnMount( options.focusOnMount );\n\tconst focusReturnRef = useFocusReturn();\n\tconst focusOutsideProps = useFocusOutside( ( event ) => {\n\t\t// This unstable prop is here only to manage backward compatibility\n\t\t// for the Popover component otherwise, the onClose should be enough.\n\t\tif ( currentOptions.current?.__unstableOnClose ) {\n\t\t\tcurrentOptions.current.__unstableOnClose( 'focus-outside', event );\n\t\t} else if ( currentOptions.current?.onClose ) {\n\t\t\tcurrentOptions.current.onClose();\n\t\t}\n\t} );\n\tconst closeOnEscapeRef = useCallback( ( node: HTMLElement ) => {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', ( event: KeyboardEvent ) => {\n\t\t\t// Close on escape.\n\t\t\tif (\n\t\t\t\tevent.keyCode === ESCAPE &&\n\t\t\t\t! event.defaultPrevented &&\n\t\t\t\tcurrentOptions.current?.onClose\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcurrentOptions.current.onClose();\n\t\t\t}\n\t\t} );\n\t}, [] );\n\n\treturn [\n\t\tuseMergeRefs( [\n\t\t\tconstrainTabbing ? constrainedTabbingRef : null,\n\t\t\toptions.focusOnMount !== false ? focusReturnRef : null,\n\t\t\toptions.focusOnMount !== false ? focusOnMountRef : null,\n\t\t\tcloseOnEscapeRef,\n\t\t] ),\n\t\t{\n\t\t\t...focusOutsideProps,\n\t\t\ttabIndex: -1,\n\t\t},\n\t];\n}\n\nexport default useDialog;\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,SAAS,EAAEC,WAAW,QAAQ,oBAAoB;AACnE,SAASC,MAAM,QAAQ,qBAAqB;;AAE5C;AACA;AACA;AACA,OAAOC,qBAAqB,MAAM,4BAA4B;AAC9D,OAAOC,eAAe,MAAM,uBAAuB;AACnD,OAAOC,cAAc,MAAM,qBAAqB;AAChD,OAAOC,eAAe,MAAM,sBAAsB;AAClD,OAAOC,YAAY,MAAM,mBAAmB;AAwC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,OAAsB,EAAoB;EAC7D,MAAMC,cAAc,GAAGX,MAAM,CAA8B,CAAC;EAC5D,MAAM;IAAEY,gBAAgB,GAAGF,OAAO,CAACG,YAAY,KAAK;EAAM,CAAC,GAAGH,OAAO;EACrET,SAAS,CAAE,MAAM;IAChBU,cAAc,CAACG,OAAO,GAAGJ,OAAO;EACjC,CAAC,EAAEK,MAAM,CAACC,MAAM,CAAEN,OAAQ,CAAE,CAAC;EAC7B,MAAMO,qBAAqB,GAAGb,qBAAqB,CAAC,CAAC;EACrD,MAAMc,eAAe,GAAGb,eAAe,CAAEK,OAAO,CAACG,YAAa,CAAC;EAC/D,MAAMM,cAAc,GAAGb,cAAc,CAAC,CAAC;EACvC,MAAMc,iBAAiB,GAAGb,eAAe,CAAIc,KAAK,IAAM;IACvD;IACA;IACA,IAAKV,cAAc,CAACG,OAAO,EAAEQ,iBAAiB,EAAG;MAChDX,cAAc,CAACG,OAAO,CAACQ,iBAAiB,CAAE,eAAe,EAAED,KAAM,CAAC;IACnE,CAAC,MAAM,IAAKV,cAAc,CAACG,OAAO,EAAES,OAAO,EAAG;MAC7CZ,cAAc,CAACG,OAAO,CAACS,OAAO,CAAC,CAAC;IACjC;EACD,CAAE,CAAC;EACH,MAAMC,gBAAgB,GAAGtB,WAAW,CAAIuB,IAAiB,IAAM;IAC9D,IAAK,CAAEA,IAAI,EAAG;MACb;IACD;IAEAA,IAAI,CAACC,gBAAgB,CAAE,SAAS,EAAIL,KAAoB,IAAM;MAC7D;MACA,IACCA,KAAK,CAACM,OAAO,KAAKxB,MAAM,IACxB,CAAEkB,KAAK,CAACO,gBAAgB,IACxBjB,cAAc,CAACG,OAAO,EAAES,OAAO,EAC9B;QACDF,KAAK,CAACQ,cAAc,CAAC,CAAC;QACtBlB,cAAc,CAACG,OAAO,CAACS,OAAO,CAAC,CAAC;MACjC;IACD,CAAE,CAAC;EACJ,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO,CACNf,YAAY,CAAE,CACbI,gBAAgB,GAAGK,qBAAqB,GAAG,IAAI,EAC/CP,OAAO,CAACG,YAAY,KAAK,KAAK,GAAGM,cAAc,GAAG,IAAI,EACtDT,OAAO,CAACG,YAAY,KAAK,KAAK,GAAGK,eAAe,GAAG,IAAI,EACvDM,gBAAgB,CACf,CAAC,EACH;IACC,GAAGJ,iBAAiB;IACpBU,QAAQ,EAAE,CAAC;EACZ,CAAC,CACD;AACF;AAEA,eAAerB,SAAS"}
|
|
@@ -27,13 +27,12 @@ import usePrevious from '../use-previous';
|
|
|
27
27
|
function useWarnOnChange(object, prefix = 'Change detection') {
|
|
28
28
|
const previousValues = usePrevious(object);
|
|
29
29
|
Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(([key, value]) => {
|
|
30
|
-
if (value !== object[/** @type {keyof typeof object} */key]) {
|
|
30
|
+
if (value !== object[( /** @type {keyof typeof object} */key)]) {
|
|
31
31
|
// eslint-disable-next-line no-console
|
|
32
|
-
console.warn(`${prefix}: ${key} key changed:`, value, object[/** @type {keyof typeof object} */key]
|
|
32
|
+
console.warn(`${prefix}: ${key} key changed:`, value, object[( /** @type {keyof typeof object} */key)]
|
|
33
33
|
/* eslint-enable jsdoc/check-types */);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
export default useWarnOnChange;
|
|
39
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["usePrevious","useWarnOnChange","object","prefix","previousValues","Object","entries","forEach","key","value","console","warn"],"sources":["@wordpress/compose/src/hooks/use-warn-on-change/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case\n// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript\n/* eslint-disable jsdoc/check-types */\n/**\n * Hook that performs a shallow comparison between the preview value of an object\n * and the new one, if there's a difference, it prints it to the console.\n * this is useful in performance related work, to check why a component re-renders.\n *\n * @example\n *\n * ```jsx\n * function MyComponent(props) {\n * useWarnOnChange(props);\n *\n * return \"Something\";\n * }\n * ```\n *\n * @param {object} object Object which changes to compare.\n * @param {string} prefix Just a prefix to show when console logging.\n */\nfunction useWarnOnChange( object, prefix = 'Change detection' ) {\n\tconst previousValues = usePrevious( object );\n\n\tObject.entries( previousValues ?? [] ).forEach( ( [ key, value ] ) => {\n\t\tif ( value !== object[ /** @type {keyof typeof object} */ ( key ) ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`${ prefix }: ${ key } key changed:`,\n\t\t\t\tvalue,\n\t\t\t\tobject[ /** @type {keyof typeof object} */ ( key ) ]\n\t\t\t\t/* eslint-enable jsdoc/check-types */\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport default useWarnOnChange;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,iBAAiB;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAEC,MAAM,EAAEC,MAAM,GAAG,kBAAkB,EAAG;EAC/D,MAAMC,cAAc,GAAGJ,WAAW,CAAEE,MAAO,CAAC;EAE5CG,MAAM,CAACC,OAAO,CAAEF,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAI,EAAG,CAAC,CAACG,OAAO,CAAE,CAAE,CAAEC,GAAG,EAAEC,KAAK,CAAE,KAAM;IACrE,IAAKA,KAAK,KAAKP,MAAM,
|
|
1
|
+
{"version":3,"names":["usePrevious","useWarnOnChange","object","prefix","previousValues","Object","entries","forEach","key","value","console","warn"],"sources":["@wordpress/compose/src/hooks/use-warn-on-change/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case\n// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript\n/* eslint-disable jsdoc/check-types */\n/**\n * Hook that performs a shallow comparison between the preview value of an object\n * and the new one, if there's a difference, it prints it to the console.\n * this is useful in performance related work, to check why a component re-renders.\n *\n * @example\n *\n * ```jsx\n * function MyComponent(props) {\n * useWarnOnChange(props);\n *\n * return \"Something\";\n * }\n * ```\n *\n * @param {object} object Object which changes to compare.\n * @param {string} prefix Just a prefix to show when console logging.\n */\nfunction useWarnOnChange( object, prefix = 'Change detection' ) {\n\tconst previousValues = usePrevious( object );\n\n\tObject.entries( previousValues ?? [] ).forEach( ( [ key, value ] ) => {\n\t\tif ( value !== object[ /** @type {keyof typeof object} */ ( key ) ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`${ prefix }: ${ key } key changed:`,\n\t\t\t\tvalue,\n\t\t\t\tobject[ /** @type {keyof typeof object} */ ( key ) ]\n\t\t\t\t/* eslint-enable jsdoc/check-types */\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport default useWarnOnChange;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,iBAAiB;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAEC,MAAM,EAAEC,MAAM,GAAG,kBAAkB,EAAG;EAC/D,MAAMC,cAAc,GAAGJ,WAAW,CAAEE,MAAO,CAAC;EAE5CG,MAAM,CAACC,OAAO,CAAEF,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAI,EAAG,CAAC,CAACG,OAAO,CAAE,CAAE,CAAEC,GAAG,EAAEC,KAAK,CAAE,KAAM;IACrE,IAAKA,KAAK,KAAKP,MAAM,GAAE,kCAAqCM,GAAG,EAAI,EAAG;MACrE;MACAE,OAAO,CAACC,IAAI,CACV,GAAGR,MAAQ,KAAKK,GAAK,eAAc,EACpCC,KAAK,EACLP,MAAM,GAAE,kCAAqCM,GAAG;MAChD,qCACD,CAAC;IACF;EACD,CAAE,CAAC;AACJ;AAEA,eAAeP,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-constrained-tabbing/index.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-constrained-tabbing/index.js"],"names":[],"mappings":";AAUA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,0CAjBY,OAAO,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CA2E/C"}
|
|
@@ -5,7 +5,26 @@ import type { RefCallback, SyntheticEvent } from 'react';
|
|
|
5
5
|
import useFocusOnMount from '../use-focus-on-mount';
|
|
6
6
|
import useFocusOutside from '../use-focus-outside';
|
|
7
7
|
type DialogOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Determines whether focus should be automatically moved to the popover
|
|
10
|
+
* when it mounts. `false` causes no focus shift, `true` causes the popover
|
|
11
|
+
* itself to gain focus, and `firstElement` focuses the first focusable
|
|
12
|
+
* element within the popover.
|
|
13
|
+
*
|
|
14
|
+
* @default 'firstElement'
|
|
15
|
+
*/
|
|
8
16
|
focusOnMount?: Parameters<typeof useFocusOnMount>[0];
|
|
17
|
+
/**
|
|
18
|
+
* Determines whether tabbing is constrained to within the popover,
|
|
19
|
+
* preventing keyboard focus from leaving the popover content without
|
|
20
|
+
* explicit focus elsewhere, or whether the popover remains part of the
|
|
21
|
+
* wider tab order.
|
|
22
|
+
* If no value is passed, it will be derived from `focusOnMount`.
|
|
23
|
+
*
|
|
24
|
+
* @see focusOnMount
|
|
25
|
+
* @default `focusOnMount` !== false
|
|
26
|
+
*/
|
|
27
|
+
constrainTabbing?: boolean;
|
|
9
28
|
onClose?: () => void;
|
|
10
29
|
/**
|
|
11
30
|
* Use the `onClose` prop instead.
|
|
@@ -1 +1 @@
|
|
|
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,KAAK,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,KAAK,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,
|
|
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,KAAK,aAAa,GAAG;IACpB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,UAAU,CAAE,OAAO,eAAe,CAAE,CAAE,CAAC,CAAE,CAAC;IACzD;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,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,KAAK,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,CAgD5D;AAED,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.28.1",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,13 +31,13 @@
|
|
|
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": "^5.
|
|
37
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
38
|
-
"@wordpress/keycodes": "^3.
|
|
39
|
-
"@wordpress/priority-queue": "^2.
|
|
40
|
-
"@wordpress/undo-manager": "^0.
|
|
34
|
+
"@wordpress/deprecated": "^3.51.1",
|
|
35
|
+
"@wordpress/dom": "^3.51.1",
|
|
36
|
+
"@wordpress/element": "^5.28.1",
|
|
37
|
+
"@wordpress/is-shallow-equal": "^4.51.1",
|
|
38
|
+
"@wordpress/keycodes": "^3.51.1",
|
|
39
|
+
"@wordpress/priority-queue": "^2.51.1",
|
|
40
|
+
"@wordpress/undo-manager": "^0.11.1",
|
|
41
41
|
"change-case": "^4.1.2",
|
|
42
42
|
"clipboard": "^2.0.11",
|
|
43
43
|
"mousetrap": "^1.6.5",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "730beb7fd33d3382d6032c3f33e451625a0fcf36"
|
|
53
53
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { TAB } from '@wordpress/keycodes';
|
|
5
4
|
import { focus } from '@wordpress/dom';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -33,9 +32,9 @@ import useRefEffect from '../use-ref-effect';
|
|
|
33
32
|
function useConstrainedTabbing() {
|
|
34
33
|
return useRefEffect( ( /** @type {HTMLElement} */ node ) => {
|
|
35
34
|
function onKeyDown( /** @type {KeyboardEvent} */ event ) {
|
|
36
|
-
const {
|
|
35
|
+
const { key, shiftKey, target } = event;
|
|
37
36
|
|
|
38
|
-
if (
|
|
37
|
+
if ( key !== 'Tab' ) {
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -19,7 +19,26 @@ import useFocusOutside from '../use-focus-outside';
|
|
|
19
19
|
import useMergeRefs from '../use-merge-refs';
|
|
20
20
|
|
|
21
21
|
type DialogOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* Determines whether focus should be automatically moved to the popover
|
|
24
|
+
* when it mounts. `false` causes no focus shift, `true` causes the popover
|
|
25
|
+
* itself to gain focus, and `firstElement` focuses the first focusable
|
|
26
|
+
* element within the popover.
|
|
27
|
+
*
|
|
28
|
+
* @default 'firstElement'
|
|
29
|
+
*/
|
|
22
30
|
focusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];
|
|
31
|
+
/**
|
|
32
|
+
* Determines whether tabbing is constrained to within the popover,
|
|
33
|
+
* preventing keyboard focus from leaving the popover content without
|
|
34
|
+
* explicit focus elsewhere, or whether the popover remains part of the
|
|
35
|
+
* wider tab order.
|
|
36
|
+
* If no value is passed, it will be derived from `focusOnMount`.
|
|
37
|
+
*
|
|
38
|
+
* @see focusOnMount
|
|
39
|
+
* @default `focusOnMount` !== false
|
|
40
|
+
*/
|
|
41
|
+
constrainTabbing?: boolean;
|
|
23
42
|
onClose?: () => void;
|
|
24
43
|
/**
|
|
25
44
|
* Use the `onClose` prop instead.
|
|
@@ -48,6 +67,7 @@ type useDialogReturn = [
|
|
|
48
67
|
*/
|
|
49
68
|
function useDialog( options: DialogOptions ): useDialogReturn {
|
|
50
69
|
const currentOptions = useRef< DialogOptions | undefined >();
|
|
70
|
+
const { constrainTabbing = options.focusOnMount !== false } = options;
|
|
51
71
|
useEffect( () => {
|
|
52
72
|
currentOptions.current = options;
|
|
53
73
|
}, Object.values( options ) );
|
|
@@ -83,7 +103,7 @@ function useDialog( options: DialogOptions ): useDialogReturn {
|
|
|
83
103
|
|
|
84
104
|
return [
|
|
85
105
|
useMergeRefs( [
|
|
86
|
-
|
|
106
|
+
constrainTabbing ? constrainedTabbingRef : null,
|
|
87
107
|
options.focusOnMount !== false ? focusReturnRef : null,
|
|
88
108
|
options.focusOnMount !== false ? focusOnMountRef : null,
|
|
89
109
|
closeOnEscapeRef,
|