@wordpress/compose 6.11.0 → 6.12.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/if-condition/index.js +2 -1
- package/build/higher-order/if-condition/index.js.map +1 -1
- package/build/higher-order/pipe.js +6 -19
- package/build/higher-order/pipe.js.map +1 -1
- package/build/higher-order/pure/index.js +2 -1
- package/build/higher-order/pure/index.js.map +1 -1
- package/build/higher-order/with-global-events/index.js +2 -4
- package/build/higher-order/with-global-events/index.js.map +1 -1
- package/build/higher-order/with-global-events/listener.js +1 -3
- package/build/higher-order/with-global-events/listener.js.map +1 -1
- package/build/higher-order/with-instance-id/index.js +2 -4
- package/build/higher-order/with-instance-id/index.js.map +1 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +4 -5
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build/higher-order/with-safe-timeout/index.js +2 -6
- package/build/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build/higher-order/with-state/index.js +4 -6
- package/build/higher-order/with-state/index.js.map +1 -1
- package/build/hooks/use-async-list/index.js +3 -4
- package/build/hooks/use-async-list/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.js +1 -1
- package/build/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build/hooks/use-copy-on-click/index.js +5 -8
- package/build/hooks/use-copy-on-click/index.js.map +1 -1
- package/build/hooks/use-copy-to-clipboard/index.js +3 -4
- package/build/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build/hooks/use-dialog/index.js +3 -7
- package/build/hooks/use-dialog/index.js.map +1 -1
- package/build/hooks/use-disabled/index.js +4 -7
- package/build/hooks/use-disabled/index.js.map +1 -1
- package/build/hooks/use-dragging/index.js +5 -6
- package/build/hooks/use-dragging/index.js.map +1 -1
- package/build/hooks/use-drop-zone/index.js +27 -21
- package/build/hooks/use-drop-zone/index.js.map +1 -1
- package/build/hooks/use-fixed-window-list/index.js +14 -22
- package/build/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build/hooks/use-focus-on-mount/index.js +3 -4
- package/build/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.js +1 -3
- package/build/hooks/use-focus-outside/index.js.map +1 -1
- package/build/hooks/use-focus-return/index.js +3 -7
- package/build/hooks/use-focus-return/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.js +14 -14
- package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build/hooks/use-media-query/index.js +1 -1
- package/build/hooks/use-media-query/index.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.android.js +3 -4
- package/build/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build/hooks/use-resize-observer/index.js +1 -2
- package/build/hooks/use-resize-observer/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.native.js +3 -4
- 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 +2 -5
- package/build/hooks/use-warn-on-change/index.js.map +1 -1
- package/build/utils/debounce/index.js +1 -6
- package/build/utils/debounce/index.js.map +1 -1
- package/build-module/higher-order/if-condition/index.js +2 -1
- package/build-module/higher-order/if-condition/index.js.map +1 -1
- package/build-module/higher-order/pipe.js +6 -19
- package/build-module/higher-order/pipe.js.map +1 -1
- package/build-module/higher-order/pure/index.js +2 -1
- package/build-module/higher-order/pure/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/higher-order/with-global-events/listener.js +1 -3
- package/build-module/higher-order/with-global-events/listener.js.map +1 -1
- package/build-module/higher-order/with-instance-id/index.js +2 -3
- package/build-module/higher-order/with-instance-id/index.js.map +1 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js +4 -4
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build-module/higher-order/with-safe-timeout/index.js +2 -3
- package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build-module/higher-order/with-state/index.js +4 -5
- package/build-module/higher-order/with-state/index.js.map +1 -1
- package/build-module/hooks/use-async-list/index.js +3 -4
- package/build-module/hooks/use-async-list/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.js +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build-module/hooks/use-copy-on-click/index.js +5 -8
- package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js +3 -4
- package/build-module/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build-module/hooks/use-dialog/index.js +3 -7
- package/build-module/hooks/use-dialog/index.js.map +1 -1
- package/build-module/hooks/use-disabled/index.js +4 -7
- package/build-module/hooks/use-disabled/index.js.map +1 -1
- package/build-module/hooks/use-dragging/index.js +5 -6
- package/build-module/hooks/use-dragging/index.js.map +1 -1
- package/build-module/hooks/use-drop-zone/index.js +27 -21
- package/build-module/hooks/use-drop-zone/index.js.map +1 -1
- package/build-module/hooks/use-fixed-window-list/index.js +14 -22
- package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build-module/hooks/use-focus-on-mount/index.js +3 -4
- package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.js +1 -3
- package/build-module/hooks/use-focus-outside/index.js.map +1 -1
- package/build-module/hooks/use-focus-return/index.js +3 -7
- package/build-module/hooks/use-focus-return/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.js +14 -14
- package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build-module/hooks/use-media-query/index.js +1 -1
- package/build-module/hooks/use-media-query/index.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.android.js +3 -4
- package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.js +1 -2
- package/build-module/hooks/use-resize-observer/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.native.js +3 -4
- package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build-module/hooks/use-viewport-match/index.js +1 -2
- package/build-module/hooks/use-viewport-match/index.js.map +1 -1
- package/build-module/hooks/use-warn-on-change/index.js +2 -5
- package/build-module/hooks/use-warn-on-change/index.js.map +1 -1
- package/build-module/utils/debounce/index.js +1 -6
- package/build-module/utils/debounce/index.js.map +1 -1
- package/build-types/hooks/use-drop-zone/index.d.ts +11 -9
- package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/hooks/use-drop-zone/README.md +71 -0
- package/src/hooks/use-drop-zone/index.js +17 -10
- package/src/hooks/use-drop-zone/test/index.js +63 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/if-condition/index.tsx"],"names":["ifCondition","predicate","WrappedComponent","props"],"mappings":";;;;;;;;;AAQA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CACCC,SADD,EAEE;AACD,SAAO,4DACJC,gBAAF,IAAkDC,KAAF,IAAoB;AACnE,QAAK,CAAEF,SAAS,CAAEE,KAAF,CAAhB,EAA4B;AAC3B,aAAO,IAAP;AACA;;AAED,WAAO,4BAAC,gBAAD,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/if-condition/index.tsx"],"names":["ifCondition","predicate","WrappedComponent","props"],"mappings":";;;;;;;;;AAQA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CACCC,SADD,EAEE;AACD,SAAO,4DACJC,gBAAF,IAAkDC,KAAF,IAAoB;AACnE,QAAK,CAAEF,SAAS,CAAEE,KAAF,CAAhB,EAA4B;AAC3B,aAAO,IAAP;AACA;;AAED,WAAO,4BAAC,gBAAD,OAAuBA;AAAvB,MAAP;AACA,GAPK,EAQN,aARM,CAAP;AAUA;;eAEcH,W","sourcesContent":["/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * Higher-order component creator, creating a new component which renders if\n * the given condition is satisfied or with the given optional prop name.\n *\n * @example\n * ```ts\n * type Props = { foo: string };\n * const Component = ( props: Props ) => <div>{ props.foo }</div>;\n * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );\n * <ConditionalComponent foo=\"\" />; // => null\n * <ConditionalComponent foo=\"bar\" />; // => <div>bar</div>;\n * ```\n *\n * @param predicate Function to test condition.\n *\n * @return Higher-order component.\n */\nfunction ifCondition< Props extends {} >(\n\tpredicate: ( props: Props ) => boolean\n) {\n\treturn createHigherOrderComponent(\n\t\t( WrappedComponent: ComponentType< Props > ) => ( props: Props ) => {\n\t\t\tif ( ! predicate( props ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn <WrappedComponent { ...props } />;\n\t\t},\n\t\t'ifCondition'\n\t);\n}\n\nexport default ifCondition;\n"]}
|
|
@@ -54,27 +54,14 @@ exports.default = exports.basePipe = void 0;
|
|
|
54
54
|
*
|
|
55
55
|
* @param {boolean} reverse True if right-to-left, false for left-to-right composition.
|
|
56
56
|
*/
|
|
57
|
-
const basePipe =
|
|
58
|
-
|
|
59
|
-
return function () {
|
|
60
|
-
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
61
|
-
funcs[_key] = arguments[_key];
|
|
62
|
-
}
|
|
57
|
+
const basePipe = (reverse = false) => (...funcs) => (...args) => {
|
|
58
|
+
const functions = funcs.flat();
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
if (reverse) {
|
|
61
|
+
functions.reverse();
|
|
62
|
+
}
|
|
66
63
|
|
|
67
|
-
|
|
68
|
-
functions.reverse();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
72
|
-
args[_key2] = arguments[_key2];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return functions.reduce((prev, func) => [func(...prev)], args)[0];
|
|
76
|
-
};
|
|
77
|
-
};
|
|
64
|
+
return functions.reduce((prev, func) => [func(...prev)], args)[0];
|
|
78
65
|
};
|
|
79
66
|
/**
|
|
80
67
|
* Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/pipe.ts"],"names":["basePipe","reverse","funcs","
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/pipe.ts"],"names":["basePipe","reverse","funcs","args","functions","flat","reduce","prev","func","pipe"],"mappings":";;;;;;;AAAA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAQ,GACb,CAAEC,OAAgB,GAAG,KAArB,KACA,CAAE,GAAGC,KAAL,KACA,CAAE,GAAGC,IAAL,KAA0B;AACzB,QAAMC,SAAS,GAAGF,KAAK,CAACG,IAAN,EAAlB;;AACA,MAAKJ,OAAL,EAAe;AACdG,IAAAA,SAAS,CAACH,OAAV;AACA;;AACD,SAAOG,SAAS,CAACE,MAAV,CACN,CAAEC,IAAF,EAAQC,IAAR,KAAkB,CAAEA,IAAI,CAAE,GAAGD,IAAL,CAAN,CADZ,EAENJ,IAFM,EAGJ,CAHI,CAAP;AAIA,CAZF;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,MAAMM,IAAI,GAAGT,QAAQ,EAArB;eAIeS,I","sourcesContent":["/**\n * Parts of this source were derived and modified from lodash,\n * released under the MIT license.\n *\n * https://github.com/lodash/lodash\n *\n * Copyright JS Foundation and other contributors <https://js.foundation/>\n *\n * Based on Underscore.js, copyright Jeremy Ashkenas,\n * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>\n *\n * This software consists of voluntary contributions made by many\n * individuals. For exact contribution history, see the revision history\n * available at https://github.com/lodash/lodash\n *\n * The following license applies to all parts of this software except as\n * documented below:\n *\n * ====\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * Creates a pipe function.\n *\n * Allows to choose whether to perform left-to-right or right-to-left composition.\n *\n * @see https://docs-lodash.com/v4/flow/\n *\n * @param {boolean} reverse True if right-to-left, false for left-to-right composition.\n */\nconst basePipe =\n\t( reverse: boolean = false ) =>\n\t( ...funcs: Function[] ) =>\n\t( ...args: unknown[] ) => {\n\t\tconst functions = funcs.flat();\n\t\tif ( reverse ) {\n\t\t\tfunctions.reverse();\n\t\t}\n\t\treturn functions.reduce(\n\t\t\t( prev, func ) => [ func( ...prev ) ],\n\t\t\targs\n\t\t)[ 0 ];\n\t};\n\n/**\n * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function\n * composition, where each successive invocation is supplied the return value of the previous.\n *\n * This is inspired by `lodash`'s `flow` function.\n *\n * @see https://docs-lodash.com/v4/flow/\n */\nconst pipe = basePipe();\n\nexport { basePipe };\n\nexport default pipe;\n"]}
|
|
@@ -45,7 +45,8 @@ const pure = (0, _createHigherOrderComponent.createHigherOrderComponent)(functio
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
render() {
|
|
48
|
-
return (0, _element.createElement)(WrappedComponent, this.props
|
|
48
|
+
return (0, _element.createElement)(WrappedComponent, { ...this.props
|
|
49
|
+
});
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/pure/index.tsx"],"names":["pure","WrappedComponent","prototype","Component","shouldComponentUpdate","nextProps","nextState","props","state","render"],"mappings":";;;;;;;;;AASA;;AADA;;AAMA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,MAAMA,IAAI,GAAG,4DAA4B,UACxCC,gBADwC,EAEf;AACzB,MAAKA,gBAAgB,CAACC,SAAjB,YAAsCC,kBAA3C,EAAuD;AACtD,WAAO,cAAgBF,gBAAhB,CAA8D;AACpEG,MAAAA,qBAAqB,CAAEC,SAAF,EAAoBC,SAApB,EAAqC;AACzD,eACC,CAAE,6BAAgBD,SAAhB,EAA2B,KAAKE,KAAhC,CAAF,IACA,CAAE,6BAAgBD,SAAhB,EAA2B,KAAKE,KAAhC,CAFH;AAIA;;AANmE,KAArE;AAQA;;AAED,SAAO,cAAcL,kBAAd,CAAiC;AACvCC,IAAAA,qBAAqB,CAAEC,SAAF,EAAqB;AACzC,aAAO,CAAE,6BAAgBA,SAAhB,EAA2B,KAAKE,KAAhC,CAAT;AACA;;AAEDE,IAAAA,MAAM,GAAG;AACR,aAAO,4BAAC,gBAAD,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/pure/index.tsx"],"names":["pure","WrappedComponent","prototype","Component","shouldComponentUpdate","nextProps","nextState","props","state","render"],"mappings":";;;;;;;;;AASA;;AADA;;AAMA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,MAAMA,IAAI,GAAG,4DAA4B,UACxCC,gBADwC,EAEf;AACzB,MAAKA,gBAAgB,CAACC,SAAjB,YAAsCC,kBAA3C,EAAuD;AACtD,WAAO,cAAgBF,gBAAhB,CAA8D;AACpEG,MAAAA,qBAAqB,CAAEC,SAAF,EAAoBC,SAApB,EAAqC;AACzD,eACC,CAAE,6BAAgBD,SAAhB,EAA2B,KAAKE,KAAhC,CAAF,IACA,CAAE,6BAAgBD,SAAhB,EAA2B,KAAKE,KAAhC,CAFH;AAIA;;AANmE,KAArE;AAQA;;AAED,SAAO,cAAcL,kBAAd,CAAiC;AACvCC,IAAAA,qBAAqB,CAAEC,SAAF,EAAqB;AACzC,aAAO,CAAE,6BAAgBA,SAAhB,EAA2B,KAAKE,KAAhC,CAAT;AACA;;AAEDE,IAAAA,MAAM,GAAG;AACR,aAAO,4BAAC,gBAAD,OAAuB,KAAKF;AAA5B,QAAP;AACA;;AAPsC,GAAxC;AASA,CAvBY,EAwBb,MAxBa,CAAb;eA0BeP,I","sourcesContent":["/**\n * External dependencies\n */\nimport type { ComponentType, ComponentClass } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * Given a component returns the enhanced component augmented with a component\n * only re-rendering when its props/state change\n */\nconst pure = createHigherOrderComponent( function < Props extends {} >(\n\tWrappedComponent: ComponentType< Props >\n): ComponentType< Props > {\n\tif ( WrappedComponent.prototype instanceof Component ) {\n\t\treturn class extends ( WrappedComponent as ComponentClass< Props > ) {\n\t\t\tshouldComponentUpdate( nextProps: Props, nextState: any ) {\n\t\t\t\treturn (\n\t\t\t\t\t! isShallowEqual( nextProps, this.props ) ||\n\t\t\t\t\t! isShallowEqual( nextState, this.state )\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}\n\n\treturn class extends Component< Props > {\n\t\tshouldComponentUpdate( nextProps: Props ) {\n\t\t\treturn ! isShallowEqual( nextProps, this.props );\n\t\t}\n\n\t\trender() {\n\t\t\treturn <WrappedComponent { ...this.props } />;\n\t\t}\n\t};\n},\n'pure' );\n\nexport default pure;\n"]}
|
|
@@ -9,8 +9,6 @@ exports.default = withGlobalEvents;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
12
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
15
13
|
|
|
16
14
|
var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
|
|
@@ -106,9 +104,9 @@ function withGlobalEvents(eventTypesToHandlers) {
|
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
render() {
|
|
109
|
-
return (0, _element.createElement)(WrappedComponent,
|
|
107
|
+
return (0, _element.createElement)(WrappedComponent, { ...this.props.ownProps,
|
|
110
108
|
ref: this.handleRef
|
|
111
|
-
})
|
|
109
|
+
});
|
|
112
110
|
}
|
|
113
111
|
|
|
114
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"names":["listener","Listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","Component","constructor","props","handleEvent","bind","handleRef","componentDidMount","Object","keys","forEach","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","ownProps","ref"],"mappings":";;;;;;;;;AAGA
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"names":["listener","Listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","Component","constructor","props","handleEvent","bind","handleRef","componentDidMount","Object","keys","forEach","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","ownProps","ref"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA,MAAMA,QAAQ,GAAG,IAAIC,iBAAJ,EAAjB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,gBAAT,CAA2BC,oBAA3B,EAAkD;AAChE,2BAAY,6BAAZ,EAA2C;AAC1CC,IAAAA,KAAK,EAAE,KADmC;AAE1CC,IAAAA,WAAW,EAAE;AAF6B,GAA3C,EADgE,CAMhE;;AACA,SAAO,4DAA8BC,gBAAF,IAAwB;AAC1D,UAAMC,OAAN,SAAsBC,kBAAtB,CAAgC;AAC/BC,MAAAA,WAAW;AAAE;AAAmBC,MAAAA,KAArB,EAA6B;AACvC,cAAOA,KAAP;AAEA,aAAKC,WAAL,GAAmB,KAAKA,WAAL,CAAiBC,IAAjB,CAAuB,IAAvB,CAAnB;AACA,aAAKC,SAAL,GAAiB,KAAKA,SAAL,CAAeD,IAAf,CAAqB,IAArB,CAAjB;AACA;;AAEDE,MAAAA,iBAAiB,GAAG;AACnBC,QAAAA,MAAM,CAACC,IAAP,CAAab,oBAAb,EAAoCc,OAApC,CAA+CC,SAAF,IAAiB;AAC7DlB,UAAAA,QAAQ,CAACmB,GAAT,CAAcD,SAAd,EAAyB,IAAzB;AACA,SAFD;AAGA;;AAEDE,MAAAA,oBAAoB,GAAG;AACtBL,QAAAA,MAAM,CAACC,IAAP,CAAab,oBAAb,EAAoCc,OAApC,CAA+CC,SAAF,IAAiB;AAC7DlB,UAAAA,QAAQ,CAACqB,MAAT,CAAiBH,SAAjB,EAA4B,IAA5B;AACA,SAFD;AAGA;;AAEDP,MAAAA,WAAW;AAAE;AAAmBW,MAAAA,KAArB,EAA6B;AACvC,cAAMC,OAAO,GACZpB,oBAAoB;AACnB;AACCmB,QAAAA,KAAK,CAACE;AAEP;AAJmB,SADrB;;AAOA,YAAK,OAAO,KAAKC,UAAL,CAAiBF,OAAjB,CAAP,KAAsC,UAA3C,EAAwD;AACvD,eAAKE,UAAL,CAAiBF,OAAjB,EAA4BD,KAA5B;AACA;AACD;;AAEDT,MAAAA,SAAS;AAAE;AAAmBa,MAAAA,EAArB,EAA0B;AAClC,aAAKD,UAAL,GAAkBC,EAAlB,CADkC,CAElC;AACA;AACA;;AACA,YAAK,KAAKhB,KAAL,CAAWiB,YAAhB,EAA+B;AAC9B,eAAKjB,KAAL,CAAWiB,YAAX,CAAyBD,EAAzB;AACA;AACD;;AAEDE,MAAAA,MAAM,GAAG;AACR,eACC,4BAAC,gBAAD,OACM,KAAKlB,KAAL,CAAWmB,QADjB;AAEC,UAAA,GAAG,EAAG,KAAKhB;AAFZ,UADD;AAMA;;AAlD8B;;AAqDhC,WAAO,yBAAY,CAAEH,KAAF,EAASoB,GAAT,KAAkB;AACpC,aAAO,4BAAC,OAAD;AAAS,QAAA,QAAQ,EAAGpB,KAApB;AAA4B,QAAA,YAAY,EAAGoB;AAA3C,QAAP;AACA,KAFM,CAAP;AAGA,GAzDM,EAyDJ,kBAzDI,CAAP;AA0DA","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"]}
|
|
@@ -54,9 +54,7 @@ class Listener {
|
|
|
54
54
|
handleEvent(
|
|
55
55
|
/** @type {any} */
|
|
56
56
|
event) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(_this$listeners$event = this.listeners[event.type]) === null || _this$listeners$event === void 0 ? void 0 : _this$listeners$event.forEach((
|
|
57
|
+
this.listeners[event.type]?.forEach((
|
|
60
58
|
/** @type {any} */
|
|
61
59
|
instance) => {
|
|
62
60
|
instance.handleEvent(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/listener.js"],"names":["Listener","constructor","listeners","handleEvent","bind","add","eventType","instance","window","addEventListener","push","remove","filter","listener","length","removeEventListener","event","type","forEach"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAN,CAAe;AACdC,EAAAA,WAAW,GAAG;AACb;AACA,SAAKC,SAAL,GAAiB,EAAjB;AAEA,SAAKC,WAAL,GAAmB,KAAKA,WAAL,CAAiBC,IAAjB,CAAuB,IAAvB,CAAnB;AACA;;AAEDC,EAAAA,GAAG;AAAE;AAAmBC,EAAAA,SAArB;AAAgC;AAAmBC,EAAAA,QAAnD,EAA8D;AAChE,QAAK,CAAE,KAAKL,SAAL,CAAgBI,SAAhB,CAAP,EAAqC;AACpC;AACAE,MAAAA,MAAM,CAACC,gBAAP,CAAyBH,SAAzB,EAAoC,KAAKH,WAAzC;AACA,WAAKD,SAAL,CAAgBI,SAAhB,IAA8B,EAA9B;AACA;;AAED,SAAKJ,SAAL,CAAgBI,SAAhB,EAA4BI,IAA5B,CAAkCH,QAAlC;AACA;;AAEDI,EAAAA,MAAM;AAAE;AAAmBL,EAAAA,SAArB;AAAgC;AAAmBC,EAAAA,QAAnD,EAA8D;AACnE,QAAK,CAAE,KAAKL,SAAL,CAAgBI,SAAhB,CAAP,EAAqC;AACpC;AACA;;AAED,SAAKJ,SAAL,CAAgBI,SAAhB,IAA8B,KAAKJ,SAAL,CAAgBI,SAAhB,EAA4BM,MAA5B,CAC7B;AAAE;AAAmBC,IAAAA,QAArB,KAAmCA,QAAQ,KAAKN,QADnB,CAA9B;;AAIA,QAAK,CAAE,KAAKL,SAAL,CAAgBI,SAAhB,EAA4BQ,MAAnC,EAA4C;AAC3C;AACAN,MAAAA,MAAM,CAACO,mBAAP,CAA4BT,SAA5B,EAAuC,KAAKH,WAA5C;AACA,aAAO,KAAKD,SAAL,CAAgBI,SAAhB,CAAP;AACA;AACD;;AAEDH,EAAAA,WAAW;AAAE;AAAmBa,EAAAA,KAArB,EAA6B;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/listener.js"],"names":["Listener","constructor","listeners","handleEvent","bind","add","eventType","instance","window","addEventListener","push","remove","filter","listener","length","removeEventListener","event","type","forEach"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAN,CAAe;AACdC,EAAAA,WAAW,GAAG;AACb;AACA,SAAKC,SAAL,GAAiB,EAAjB;AAEA,SAAKC,WAAL,GAAmB,KAAKA,WAAL,CAAiBC,IAAjB,CAAuB,IAAvB,CAAnB;AACA;;AAEDC,EAAAA,GAAG;AAAE;AAAmBC,EAAAA,SAArB;AAAgC;AAAmBC,EAAAA,QAAnD,EAA8D;AAChE,QAAK,CAAE,KAAKL,SAAL,CAAgBI,SAAhB,CAAP,EAAqC;AACpC;AACAE,MAAAA,MAAM,CAACC,gBAAP,CAAyBH,SAAzB,EAAoC,KAAKH,WAAzC;AACA,WAAKD,SAAL,CAAgBI,SAAhB,IAA8B,EAA9B;AACA;;AAED,SAAKJ,SAAL,CAAgBI,SAAhB,EAA4BI,IAA5B,CAAkCH,QAAlC;AACA;;AAEDI,EAAAA,MAAM;AAAE;AAAmBL,EAAAA,SAArB;AAAgC;AAAmBC,EAAAA,QAAnD,EAA8D;AACnE,QAAK,CAAE,KAAKL,SAAL,CAAgBI,SAAhB,CAAP,EAAqC;AACpC;AACA;;AAED,SAAKJ,SAAL,CAAgBI,SAAhB,IAA8B,KAAKJ,SAAL,CAAgBI,SAAhB,EAA4BM,MAA5B,CAC7B;AAAE;AAAmBC,IAAAA,QAArB,KAAmCA,QAAQ,KAAKN,QADnB,CAA9B;;AAIA,QAAK,CAAE,KAAKL,SAAL,CAAgBI,SAAhB,EAA4BQ,MAAnC,EAA4C;AAC3C;AACAN,MAAAA,MAAM,CAACO,mBAAP,CAA4BT,SAA5B,EAAuC,KAAKH,WAA5C;AACA,aAAO,KAAKD,SAAL,CAAgBI,SAAhB,CAAP;AACA;AACD;;AAEDH,EAAAA,WAAW;AAAE;AAAmBa,EAAAA,KAArB,EAA6B;AACvC,SAAKd,SAAL,CAAgBc,KAAK,CAACC,IAAtB,GAA8BC,OAA9B,CACC;AAAE;AAAmBX,IAAAA,QAArB,KAAmC;AAClCA,MAAAA,QAAQ,CAACJ,WAAT,CAAsBa,KAAtB;AACA,KAHF;AAKA;;AAxCa;;eA2CAhB,Q","sourcesContent":["/**\n * Class responsible for orchestrating event handling on the global window,\n * binding a single event to be shared across all handling instances, and\n * removing the handler when no instances are listening for the event.\n */\nclass Listener {\n\tconstructor() {\n\t\t/** @type {any} */\n\t\tthis.listeners = {};\n\n\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t}\n\n\tadd( /** @type {any} */ eventType, /** @type {any} */ instance ) {\n\t\tif ( ! this.listeners[ eventType ] ) {\n\t\t\t// Adding first listener for this type, so bind event.\n\t\t\twindow.addEventListener( eventType, this.handleEvent );\n\t\t\tthis.listeners[ eventType ] = [];\n\t\t}\n\n\t\tthis.listeners[ eventType ].push( instance );\n\t}\n\n\tremove( /** @type {any} */ eventType, /** @type {any} */ instance ) {\n\t\tif ( ! this.listeners[ eventType ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.listeners[ eventType ] = this.listeners[ eventType ].filter(\n\t\t\t( /** @type {any} */ listener ) => listener !== instance\n\t\t);\n\n\t\tif ( ! this.listeners[ eventType ].length ) {\n\t\t\t// Removing last listener for this type, so unbind event.\n\t\t\twindow.removeEventListener( eventType, this.handleEvent );\n\t\t\tdelete this.listeners[ eventType ];\n\t\t}\n\t}\n\n\thandleEvent( /** @type {any} */ event ) {\n\t\tthis.listeners[ event.type ]?.forEach(\n\t\t\t( /** @type {any} */ instance ) => {\n\t\t\t\tinstance.handleEvent( event );\n\t\t\t}\n\t\t);\n\t}\n}\n\nexport default Listener;\n"]}
|
|
@@ -9,8 +9,6 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
12
|
var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
|
|
15
13
|
|
|
16
14
|
var _useInstanceId = _interopRequireDefault(require("../../hooks/use-instance-id"));
|
|
@@ -27,9 +25,9 @@ const withInstanceId = (0, _createHigherOrderComponent.createHigherOrderComponen
|
|
|
27
25
|
return props => {
|
|
28
26
|
const instanceId = (0, _useInstanceId.default)(WrappedComponent); // @ts-ignore
|
|
29
27
|
|
|
30
|
-
return (0, _element.createElement)(WrappedComponent,
|
|
28
|
+
return (0, _element.createElement)(WrappedComponent, { ...props,
|
|
31
29
|
instanceId: instanceId
|
|
32
|
-
})
|
|
30
|
+
});
|
|
33
31
|
};
|
|
34
32
|
}, 'instanceId');
|
|
35
33
|
var _default = withInstanceId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-instance-id/index.tsx"],"names":["withInstanceId","WrappedComponent","props","instanceId"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-instance-id/index.tsx"],"names":["withInstanceId","WrappedComponent","props","instanceId"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA,MAAMA,cAAc,GAAG,4DAErBC,gBADD,IAEK;AACJ,SAASC,KAAF,IAAyD;AAC/D,UAAMC,UAAU,GAAG,4BAAeF,gBAAf,CAAnB,CAD+D,CAE/D;;AACA,WAAO,4BAAC,gBAAD,OAAuBC,KAAvB;AAA+B,MAAA,UAAU,EAAGC;AAA5C,MAAP;AACA,GAJD;AAKA,CATqB,EAUtB,YAVsB,CAAvB;eAaeH,c","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateHigherOrderComponent,\n\tWithInjectedProps,\n\tWithoutInjectedProps,\n} from '../../utils/create-higher-order-component';\nimport useInstanceId from '../../hooks/use-instance-id';\n\ntype InstanceIdProps = { instanceId: string | number };\n\n/**\n * A Higher Order Component used to be provide a unique instance ID by\n * component.\n */\nconst withInstanceId = createHigherOrderComponent(\n\t< C extends WithInjectedProps< C, InstanceIdProps > >(\n\t\tWrappedComponent: C\n\t) => {\n\t\treturn ( props: WithoutInjectedProps< C, InstanceIdProps > ) => {\n\t\t\tconst instanceId = useInstanceId( WrappedComponent );\n\t\t\t// @ts-ignore\n\t\t\treturn <WrappedComponent { ...props } instanceId={ instanceId } />;\n\t\t};\n\t},\n\t'instanceId'\n);\n\nexport default withInstanceId;\n"]}
|
|
@@ -9,8 +9,6 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
12
|
var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
|
|
15
13
|
|
|
16
14
|
var _usePreferredColorScheme = _interopRequireDefault(require("../../hooks/use-preferred-color-scheme"));
|
|
@@ -31,10 +29,11 @@ const withPreferredColorScheme = (0, _createHigherOrderComponent.createHigherOrd
|
|
|
31
29
|
};
|
|
32
30
|
return isDarkMode ? finalDarkStyles : lightStyles;
|
|
33
31
|
}, [isDarkMode]);
|
|
34
|
-
return (0, _element.createElement)(WrappedComponent,
|
|
32
|
+
return (0, _element.createElement)(WrappedComponent, {
|
|
35
33
|
preferredColorScheme: colorScheme,
|
|
36
|
-
getStylesFromColorScheme: getStyles
|
|
37
|
-
|
|
34
|
+
getStylesFromColorScheme: getStyles,
|
|
35
|
+
...props
|
|
36
|
+
});
|
|
38
37
|
}, 'withPreferredColorScheme');
|
|
39
38
|
var _default = withPreferredColorScheme;
|
|
40
39
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-preferred-color-scheme/index.native.js"],"names":["withPreferredColorScheme","WrappedComponent","props","colorScheme","isDarkMode","getStyles","lightStyles","darkStyles","finalDarkStyles"],"mappings":";;;;;;;;;AASA
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-preferred-color-scheme/index.native.js"],"names":["withPreferredColorScheme","WrappedComponent","props","colorScheme","isDarkMode","getStyles","lightStyles","darkStyles","finalDarkStyles"],"mappings":";;;;;;;;;AASA;;AANA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AAGA,MAAMA,wBAAwB,GAAG,4DAC9BC,gBAAF,IAA0BC,KAAF,IAAa;AACpC,QAAMC,WAAW,GAAG,uCAApB;AACA,QAAMC,UAAU,GAAGD,WAAW,KAAK,MAAnC;AAEA,QAAME,SAAS,GAAG,0BACjB,CAAEC,WAAF,EAAeC,UAAf,KAA+B;AAC9B,UAAMC,eAAe,GAAG,EACvB,GAAGF,WADoB;AAEvB,SAAGC;AAFoB,KAAxB;AAKA,WAAOH,UAAU,GAAGI,eAAH,GAAqBF,WAAtC;AACA,GARgB,EASjB,CAAEF,UAAF,CATiB,CAAlB;AAYA,SACC,4BAAC,gBAAD;AACC,IAAA,oBAAoB,EAAGD,WADxB;AAEC,IAAA,wBAAwB,EAAGE,SAF5B;AAAA,OAGMH;AAHN,IADD;AAOA,CAxB+B,EAyBhC,0BAzBgC,CAAjC;eA4BeF,wB","sourcesContent":["/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport usePreferredColorScheme from '../../hooks/use-preferred-color-scheme';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\n\nconst withPreferredColorScheme = createHigherOrderComponent(\n\t( WrappedComponent ) => ( props ) => {\n\t\tconst colorScheme = usePreferredColorScheme();\n\t\tconst isDarkMode = colorScheme === 'dark';\n\n\t\tconst getStyles = useCallback(\n\t\t\t( lightStyles, darkStyles ) => {\n\t\t\t\tconst finalDarkStyles = {\n\t\t\t\t\t...lightStyles,\n\t\t\t\t\t...darkStyles,\n\t\t\t\t};\n\n\t\t\t\treturn isDarkMode ? finalDarkStyles : lightStyles;\n\t\t\t},\n\t\t\t[ isDarkMode ]\n\t\t);\n\n\t\treturn (\n\t\t\t<WrappedComponent\n\t\t\t\tpreferredColorScheme={ colorScheme }\n\t\t\t\tgetStylesFromColorScheme={ getStyles }\n\t\t\t\t{ ...props }\n\t\t\t/>\n\t\t);\n\t},\n\t'withPreferredColorScheme'\n);\n\nexport default withPreferredColorScheme;\n"]}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -9,8 +7,6 @@ exports.default = void 0;
|
|
|
9
7
|
|
|
10
8
|
var _element = require("@wordpress/element");
|
|
11
9
|
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
10
|
var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
|
|
15
11
|
|
|
16
12
|
/**
|
|
@@ -54,10 +50,10 @@ const withSafeTimeout = (0, _createHigherOrderComponent.createHigherOrderCompone
|
|
|
54
50
|
|
|
55
51
|
render() {
|
|
56
52
|
return (// @ts-ignore
|
|
57
|
-
(0, _element.createElement)(OriginalComponent,
|
|
53
|
+
(0, _element.createElement)(OriginalComponent, { ...this.props,
|
|
58
54
|
setTimeout: this.setTimeout,
|
|
59
55
|
clearTimeout: this.clearTimeout
|
|
60
|
-
})
|
|
56
|
+
})
|
|
61
57
|
);
|
|
62
58
|
}
|
|
63
59
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-safe-timeout/index.tsx"],"names":["withSafeTimeout","OriginalComponent","WrappedComponent","Component","constructor","props","timeouts","setTimeout","bind","clearTimeout","componentWillUnmount","forEach","fn","delay","id","push","filter","timeoutId","render"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-safe-timeout/index.tsx"],"names":["withSafeTimeout","OriginalComponent","WrappedComponent","Component","constructor","props","timeouts","setTimeout","bind","clearTimeout","componentWillUnmount","forEach","fn","delay","id","push","filter","timeoutId","render"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAoBA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,4DAEtBC,iBADD,IAEK;AAEJ,SAAO,MAAMC,gBAAN,SAA+BC,kBAA/B,CAAyD;AAG/DC,IAAAA,WAAW,CAAEC,KAAF,EAAwB;AAClC,YAAOA,KAAP;AACA,WAAKC,QAAL,GAAgB,EAAhB;AACA,WAAKC,UAAL,GAAkB,KAAKA,UAAL,CAAgBC,IAAhB,CAAsB,IAAtB,CAAlB;AACA,WAAKC,YAAL,GAAoB,KAAKA,YAAL,CAAkBD,IAAlB,CAAwB,IAAxB,CAApB;AACA;;AAEDE,IAAAA,oBAAoB,GAAG;AACtB,WAAKJ,QAAL,CAAcK,OAAd,CAAuBF,YAAvB;AACA;;AAEDF,IAAAA,UAAU,CAAEK,EAAF,EAAkBC,KAAlB,EAAkC;AAC3C,YAAMC,EAAE,GAAGP,UAAU,CAAE,MAAM;AAC5BK,QAAAA,EAAE;AACF,aAAKH,YAAL,CAAmBK,EAAnB;AACA,OAHoB,EAGlBD,KAHkB,CAArB;AAIA,WAAKP,QAAL,CAAcS,IAAd,CAAoBD,EAApB;AACA,aAAOA,EAAP;AACA;;AAEDL,IAAAA,YAAY,CAAEK,EAAF,EAAe;AAC1BL,MAAAA,YAAY,CAAEK,EAAF,CAAZ;AACA,WAAKR,QAAL,GAAgB,KAAKA,QAAL,CAAcU,MAAd,CACbC,SAAF,IAAiBA,SAAS,KAAKH,EADhB,CAAhB;AAGA;;AAEDI,IAAAA,MAAM,GAAG;AACR,aACC;AACA,oCAAC,iBAAD,OACM,KAAKb,KADX;AAEC,UAAA,UAAU,EAAG,KAAKE,UAFnB;AAGC,UAAA,YAAY,EAAG,KAAKE;AAHrB;AAFD;AAQA;;AAvC8D,GAAhE;AAyCA,CA9CsB,EA+CvB,iBA/CuB,CAAxB;eAkDeT,e","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcreateHigherOrderComponent,\n\tWithInjectedProps,\n\tWithoutInjectedProps,\n} from '../../utils/create-higher-order-component';\n\n/**\n * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`\n * types here because those functions include functionality that is not handled\n * by this component, like the ability to pass extra arguments.\n *\n * In the case of this component, we only handle the simplest case where\n * `setTimeout` only accepts a function (not a string) and an optional delay.\n */\ninterface TimeoutProps {\n\tsetTimeout: ( fn: () => void, delay: number ) => number;\n\tclearTimeout: ( id: number ) => void;\n}\n\n/**\n * A higher-order component used to provide and manage delayed function calls\n * that ought to be bound to a component's lifecycle.\n */\nconst withSafeTimeout = createHigherOrderComponent(\n\t< C extends WithInjectedProps< C, TimeoutProps > >(\n\t\tOriginalComponent: C\n\t) => {\n\t\ttype WrappedProps = WithoutInjectedProps< C, TimeoutProps >;\n\t\treturn class WrappedComponent extends Component< WrappedProps > {\n\t\t\ttimeouts: number[];\n\n\t\t\tconstructor( props: WrappedProps ) {\n\t\t\t\tsuper( props );\n\t\t\t\tthis.timeouts = [];\n\t\t\t\tthis.setTimeout = this.setTimeout.bind( this );\n\t\t\t\tthis.clearTimeout = this.clearTimeout.bind( this );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tthis.timeouts.forEach( clearTimeout );\n\t\t\t}\n\n\t\t\tsetTimeout( fn: () => void, delay: number ) {\n\t\t\t\tconst id = setTimeout( () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tthis.clearTimeout( id );\n\t\t\t\t}, delay );\n\t\t\t\tthis.timeouts.push( id );\n\t\t\t\treturn id;\n\t\t\t}\n\n\t\t\tclearTimeout( id: number ) {\n\t\t\t\tclearTimeout( id );\n\t\t\t\tthis.timeouts = this.timeouts.filter(\n\t\t\t\t\t( timeoutId ) => timeoutId !== id\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// @ts-ignore\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\tsetTimeout={ this.setTimeout }\n\t\t\t\t\t\tclearTimeout={ this.clearTimeout }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t},\n\t'withSafeTimeout'\n);\n\nexport default withSafeTimeout;\n"]}
|
|
@@ -9,8 +9,6 @@ exports.default = withState;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
12
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
15
13
|
|
|
16
14
|
var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
|
|
@@ -33,8 +31,7 @@ var _createHigherOrderComponent = require("../../utils/create-higher-order-compo
|
|
|
33
31
|
*
|
|
34
32
|
* @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.
|
|
35
33
|
*/
|
|
36
|
-
function withState() {
|
|
37
|
-
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
|
+
function withState(initialState = {}) {
|
|
38
35
|
(0, _deprecated.default)('wp.compose.withState', {
|
|
39
36
|
since: '5.8',
|
|
40
37
|
alternative: 'wp.element.useState'
|
|
@@ -50,9 +47,10 @@ function withState() {
|
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
render() {
|
|
53
|
-
return (0, _element.createElement)(OriginalComponent,
|
|
50
|
+
return (0, _element.createElement)(OriginalComponent, { ...this.props,
|
|
51
|
+
...this.state,
|
|
54
52
|
setState: this.setState
|
|
55
|
-
})
|
|
53
|
+
});
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"names":["withState","initialState","since","alternative","OriginalComponent","WrappedComponent","Component","constructor","props","setState","bind","state","render"],"mappings":";;;;;;;;;AAGA
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"names":["withState","initialState","since","alternative","OriginalComponent","WrappedComponent","Component","constructor","props","setState","bind","state","render"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,CAAoBC,YAAY,GAAG,EAAnC,EAAwC;AACtD,2BAAY,sBAAZ,EAAoC;AACnCC,IAAAA,KAAK,EAAE,KAD4B;AAEnCC,IAAAA,WAAW,EAAE;AAFsB,GAApC;AAKA,SAAO,4DAA8BC,iBAAF,IAAyB;AAC3D,WAAO,MAAMC,gBAAN,SAA+BC,kBAA/B,CAAyC;AAC/CC,MAAAA,WAAW;AAAE;AAAmBC,MAAAA,KAArB,EAA6B;AACvC,cAAOA,KAAP;AAEA,aAAKC,QAAL,GAAgB,KAAKA,QAAL,CAAcC,IAAd,CAAoB,IAApB,CAAhB;AAEA,aAAKC,KAAL,GAAaV,YAAb;AACA;;AAEDW,MAAAA,MAAM,GAAG;AACR,eACC,4BAAC,iBAAD,OACM,KAAKJ,KADX;AAAA,aAEM,KAAKG,KAFX;AAGC,UAAA,QAAQ,EAAG,KAAKF;AAHjB,UADD;AAOA;;AAjB8C,KAAhD;AAmBA,GApBM,EAoBJ,WApBI,CAAP;AAqBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * A Higher Order Component used to provide and manage internal component state\n * via props.\n *\n * @deprecated Use `useState` instead.\n *\n * @param {any} initialState Optional initial state of the component.\n *\n * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.\n */\nexport default function withState( initialState = {} ) {\n\tdeprecated( 'wp.compose.withState', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.element.useState',\n\t} );\n\n\treturn createHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn class WrappedComponent extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.setState = this.setState.bind( this );\n\n\t\t\t\tthis.state = initialState;\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state }\n\t\t\t\t\t\tsetState={ this.setState }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withState' );\n}\n"]}
|
|
@@ -46,10 +46,9 @@ function getFirstItemsPresentInState(list, state) {
|
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
function useAsyncList(list
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
49
|
+
function useAsyncList(list, config = {
|
|
50
|
+
step: 1
|
|
51
|
+
}) {
|
|
53
52
|
const {
|
|
54
53
|
step = 1
|
|
55
54
|
} = config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-async-list/index.ts"],"names":["getFirstItemsPresentInState","list","state","firstItems","i","length","item","includes","push","useAsyncList","config","step","current","setCurrent","concat","slice","asyncQueue","add","reset"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,2BAAT,CAA2CC,IAA3C,EAAsDC,KAAtD,EAAwE;AACvE,QAAMC,UAAU,GAAG,EAAnB;;AAEA,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGH,IAAI,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAwC;AACvC,UAAME,IAAI,GAAGL,IAAI,CAAEG,CAAF,CAAjB;;AACA,QAAK,CAAEF,KAAK,CAACK,QAAN,CAAgBD,IAAhB,CAAP,EAAgC;AAC/B;AACA;;AAEDH,IAAAA,UAAU,CAACK,IAAX,CAAiBF,IAAjB;AACA;;AAED,SAAOH,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,YAAT,CACCR,IADD,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-async-list/index.ts"],"names":["getFirstItemsPresentInState","list","state","firstItems","i","length","item","includes","push","useAsyncList","config","step","current","setCurrent","concat","slice","asyncQueue","add","reset"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,2BAAT,CAA2CC,IAA3C,EAAsDC,KAAtD,EAAwE;AACvE,QAAMC,UAAU,GAAG,EAAnB;;AAEA,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGH,IAAI,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAwC;AACvC,UAAME,IAAI,GAAGL,IAAI,CAAEG,CAAF,CAAjB;;AACA,QAAK,CAAEF,KAAK,CAACK,QAAN,CAAgBD,IAAhB,CAAP,EAAgC;AAC/B;AACA;;AAEDH,IAAAA,UAAU,CAACK,IAAX,CAAiBF,IAAjB;AACA;;AAED,SAAOH,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,YAAT,CACCR,IADD,EAECS,MAAuB,GAAG;AAAEC,EAAAA,IAAI,EAAE;AAAR,CAF3B,EAGO;AACN,QAAM;AAAEA,IAAAA,IAAI,GAAG;AAAT,MAAeD,MAArB;AACA,QAAM,CAAEE,OAAF,EAAWC,UAAX,IAA0B,uBAAiB,EAAjB,CAAhC;AAEA,0BAAW,MAAM;AAChB;AACA,QAAIV,UAAU,GAAGH,2BAA2B,CAAEC,IAAF,EAAQW,OAAR,CAA5C;;AACA,QAAKT,UAAU,CAACE,MAAX,GAAoBM,IAAzB,EAAgC;AAC/BR,MAAAA,UAAU,GAAGA,UAAU,CAACW,MAAX,CACZb,IAAI,CAACc,KAAL,CAAYZ,UAAU,CAACE,MAAvB,EAA+BM,IAA/B,CADY,CAAb;AAGA;;AACDE,IAAAA,UAAU,CAAEV,UAAF,CAAV;AAEA,UAAMa,UAAU,GAAG,iCAAnB;;AACA,SAAM,IAAIZ,CAAC,GAAGD,UAAU,CAACE,MAAzB,EAAiCD,CAAC,GAAGH,IAAI,CAACI,MAA1C,EAAkDD,CAAC,IAAIO,IAAvD,EAA8D;AAC7DK,MAAAA,UAAU,CAACC,GAAX,CAAgB,EAAhB,EAAoB,MAAM;AACzB,gCAAW,MAAM;AAChBJ,UAAAA,UAAU,CAAIX,KAAF,IAAa,CACxB,GAAGA,KADqB,EAExB,GAAGD,IAAI,CAACc,KAAL,CAAYX,CAAZ,EAAeA,CAAC,GAAGO,IAAnB,CAFqB,CAAf,CAAV;AAIA,SALD;AAMA,OAPD;AAQA;;AAED,WAAO,MAAMK,UAAU,CAACE,KAAX,EAAb;AACA,GAvBD,EAuBG,CAAEjB,IAAF,CAvBH;AAyBA,SAAOW,OAAP;AACA;;eAEcH,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { flushSync, useEffect, useState } from '@wordpress/element';\nimport { createQueue } from '@wordpress/priority-queue';\n\ntype AsyncListConfig = {\n\tstep: number;\n};\n\n/**\n * Returns the first items from list that are present on state.\n *\n * @param list New array.\n * @param state Current state.\n * @return First items present iin state.\n */\nfunction getFirstItemsPresentInState< T >( list: T[], state: T[] ): T[] {\n\tconst firstItems = [];\n\n\tfor ( let i = 0; i < list.length; i++ ) {\n\t\tconst item = list[ i ];\n\t\tif ( ! state.includes( item ) ) {\n\t\t\tbreak;\n\t\t}\n\n\t\tfirstItems.push( item );\n\t}\n\n\treturn firstItems;\n}\n\n/**\n * React hook returns an array which items get asynchronously appended from a source array.\n * This behavior is useful if we want to render a list of items asynchronously for performance reasons.\n *\n * @param list Source array.\n * @param config Configuration object.\n *\n * @return Async array.\n */\nfunction useAsyncList< T >(\n\tlist: T[],\n\tconfig: AsyncListConfig = { step: 1 }\n): T[] {\n\tconst { step = 1 } = config;\n\tconst [ current, setCurrent ] = useState< T[] >( [] );\n\n\tuseEffect( () => {\n\t\t// On reset, we keep the first items that were previously rendered.\n\t\tlet firstItems = getFirstItemsPresentInState( list, current );\n\t\tif ( firstItems.length < step ) {\n\t\t\tfirstItems = firstItems.concat(\n\t\t\t\tlist.slice( firstItems.length, step )\n\t\t\t);\n\t\t}\n\t\tsetCurrent( firstItems );\n\n\t\tconst asyncQueue = createQueue();\n\t\tfor ( let i = firstItems.length; i < list.length; i += step ) {\n\t\t\tasyncQueue.add( {}, () => {\n\t\t\t\tflushSync( () => {\n\t\t\t\t\tsetCurrent( ( state ) => [\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\t...list.slice( i, i + step ),\n\t\t\t\t\t] );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\treturn () => asyncQueue.reset();\n\t}, [ list ] );\n\n\treturn current;\n}\n\nexport default useAsyncList;\n"]}
|
|
@@ -75,7 +75,7 @@ function useConstrainedTabbing() {
|
|
|
75
75
|
event.preventDefault();
|
|
76
76
|
/** @type {HTMLElement} */
|
|
77
77
|
|
|
78
|
-
nextElement
|
|
78
|
+
nextElement?.focus();
|
|
79
79
|
return;
|
|
80
80
|
} // If the element that is about to receive focus is inside the
|
|
81
81
|
// area, rely on native browsers behavior and let tabbing follow
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.js"],"names":["useConstrainedTabbing","node","onKeyDown","event","keyCode","shiftKey","target","TAB","action","nextElement","focus","tabbable","contains","preventDefault","domAction","ownerDocument","trap","createElement","tabIndex","addEventListener","removeChild","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,qBAAT,GAAiC;AAChC,SAAO,2BAAc;AAAE;AAA2BC,EAAAA,IAA7B,KAAuC;AAC3D,aAASC,SAAT;AAAoB;AAA6BC,IAAAA,KAAjD,EAAyD;AACxD,YAAM;AAAEC,QAAAA,OAAF;AAAWC,QAAAA,QAAX;AAAqBC,QAAAA;AAArB,UAAgCH,KAAtC;;AAEA,UAAKC,OAAO,KAAKG,aAAjB,EAAuB;AACtB;AACA;;AAED,YAAMC,MAAM,GAAGH,QAAQ,GAAG,cAAH,GAAoB,UAA3C;AACA,YAAMI,WAAW,GAChBC,WAAMC,QAAN,CAAgBH,MAAhB;AACC;AAA6BF,MAAAA,MAD9B,KAEK,IAHN,CARwD,CAaxD;AACA;AACA;AACA;AACA;AACA;;AACA;AACC;AAA6BA,MAAAA,MAAF,CAAWM,QAAX,CAAqBH,WAArB,CAD5B,EAEE;AACDN,QAAAA,KAAK,CAACU,cAAN;AACA;;AAA6BJ,QAAAA,WAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.js"],"names":["useConstrainedTabbing","node","onKeyDown","event","keyCode","shiftKey","target","TAB","action","nextElement","focus","tabbable","contains","preventDefault","domAction","ownerDocument","trap","createElement","tabIndex","addEventListener","removeChild","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,qBAAT,GAAiC;AAChC,SAAO,2BAAc;AAAE;AAA2BC,EAAAA,IAA7B,KAAuC;AAC3D,aAASC,SAAT;AAAoB;AAA6BC,IAAAA,KAAjD,EAAyD;AACxD,YAAM;AAAEC,QAAAA,OAAF;AAAWC,QAAAA,QAAX;AAAqBC,QAAAA;AAArB,UAAgCH,KAAtC;;AAEA,UAAKC,OAAO,KAAKG,aAAjB,EAAuB;AACtB;AACA;;AAED,YAAMC,MAAM,GAAGH,QAAQ,GAAG,cAAH,GAAoB,UAA3C;AACA,YAAMI,WAAW,GAChBC,WAAMC,QAAN,CAAgBH,MAAhB;AACC;AAA6BF,MAAAA,MAD9B,KAEK,IAHN,CARwD,CAaxD;AACA;AACA;AACA;AACA;AACA;;AACA;AACC;AAA6BA,MAAAA,MAAF,CAAWM,QAAX,CAAqBH,WAArB,CAD5B,EAEE;AACDN,QAAAA,KAAK,CAACU,cAAN;AACA;;AAA6BJ,QAAAA,WAAF,EAAiBC,KAAjB;AAC3B;AACA,OAzBuD,CA2BxD;AACA;AACA;;;AACA,UAAKT,IAAI,CAACW,QAAL,CAAeH,WAAf,CAAL,EAAoC;AACnC;AACA,OAhCuD,CAkCxD;AACA;AACA;AACA;;;AACA,YAAMK,SAAS,GAAGT,QAAQ,GAAG,QAAH,GAAc,SAAxC;AACA,YAAM;AAAEU,QAAAA;AAAF,UAAoBd,IAA1B;AACA,YAAMe,IAAI,GAAGD,aAAa,CAACE,aAAd,CAA6B,KAA7B,CAAb;AAEAD,MAAAA,IAAI,CAACE,QAAL,GAAgB,CAAC,CAAjB;AACAjB,MAAAA,IAAI,CAAEa,SAAF,CAAJ,CAAmBE,IAAnB,EA3CwD,CA6CxD;;AACAA,MAAAA,IAAI,CAACG,gBAAL,CAAuB,MAAvB,EAA+B,MAAMlB,IAAI,CAACmB,WAAL,CAAkBJ,IAAlB,CAArC;AAEAA,MAAAA,IAAI,CAACN,KAAL;AACA;;AAEDT,IAAAA,IAAI,CAACkB,gBAAL,CAAuB,SAAvB,EAAkCjB,SAAlC;AACA,WAAO,MAAM;AACZD,MAAAA,IAAI,CAACoB,mBAAL,CAA0B,SAA1B,EAAqCnB,SAArC;AACA,KAFD;AAGA,GAxDM,EAwDJ,EAxDI,CAAP;AAyDA;;eAEcF,qB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { TAB } from '@wordpress/keycodes';\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 { keyCode, shiftKey, target } = event;\n\n\t\t\tif ( keyCode !== 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"]}
|
|
@@ -36,9 +36,7 @@ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
|
36
36
|
* @return {boolean} Whether or not the text has been copied. Resets after the
|
|
37
37
|
* timeout.
|
|
38
38
|
*/
|
|
39
|
-
function useCopyOnClick(ref, text) {
|
|
40
|
-
let timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4000;
|
|
41
|
-
|
|
39
|
+
function useCopyOnClick(ref, text, timeout = 4000) {
|
|
42
40
|
/* eslint-enable jsdoc/no-undefined-types */
|
|
43
41
|
(0, _deprecated.default)('wp.compose.useCopyOnClick', {
|
|
44
42
|
since: '5.8',
|
|
@@ -60,11 +58,10 @@ function useCopyOnClick(ref, text) {
|
|
|
60
58
|
clipboard.current = new _clipboard.default(ref.current, {
|
|
61
59
|
text: () => typeof text === 'function' ? text() : text
|
|
62
60
|
});
|
|
63
|
-
clipboard.current.on('success',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} = _ref;
|
|
61
|
+
clipboard.current.on('success', ({
|
|
62
|
+
clearSelection,
|
|
63
|
+
trigger
|
|
64
|
+
}) => {
|
|
68
65
|
// Clearing selection will move focus back to the triggering button,
|
|
69
66
|
// ensuring that it is not reset to the body, and further that it is
|
|
70
67
|
// kept within the rendered node.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"names":["useCopyOnClick","ref","text","timeout","since","alternative","clipboard","hasCopied","setHasCopied","timeoutId","current","Clipboard","on","clearSelection","trigger","focus","clearTimeout","setTimeout","destroy"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAyBC,GAAzB,EAA8BC,IAA9B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"names":["useCopyOnClick","ref","text","timeout","since","alternative","clipboard","hasCopied","setHasCopied","timeoutId","current","Clipboard","on","clearSelection","trigger","focus","clearTimeout","setTimeout","destroy"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAyBC,GAAzB,EAA8BC,IAA9B,EAAoCC,OAAO,GAAG,IAA9C,EAAqD;AACnE;AACA,2BAAY,2BAAZ,EAAyC;AACxCC,IAAAA,KAAK,EAAE,KADiC;AAExCC,IAAAA,WAAW,EAAE;AAF2B,GAAzC;AAKA;;AACA,QAAMC,SAAS,GAAG,sBAAlB;AACA,QAAM,CAAEC,SAAF,EAAaC,YAAb,IAA8B,uBAAU,KAAV,CAApC;AAEA,0BAAW,MAAM;AAChB;AACA,QAAIC,SAAJ;;AAEA,QAAK,CAAER,GAAG,CAACS,OAAX,EAAqB;AACpB;AACA,KANe,CAQhB;;;AACAJ,IAAAA,SAAS,CAACI,OAAV,GAAoB,IAAIC,kBAAJ,CAAeV,GAAG,CAACS,OAAnB,EAA4B;AAC/CR,MAAAA,IAAI,EAAE,MAAQ,OAAOA,IAAP,KAAgB,UAAhB,GAA6BA,IAAI,EAAjC,GAAsCA;AADL,KAA5B,CAApB;AAIAI,IAAAA,SAAS,CAACI,OAAV,CAAkBE,EAAlB,CAAsB,SAAtB,EAAiC,CAAE;AAAEC,MAAAA,cAAF;AAAkBC,MAAAA;AAAlB,KAAF,KAAmC;AACnE;AACA;AACA;AACAD,MAAAA,cAAc,GAJqD,CAMnE;;AACA,UAAKC,OAAL,EAAe;AACd;AAA6BA,QAAAA,OAAF,CAAYC,KAAZ;AAC3B;;AAED,UAAKZ,OAAL,EAAe;AACdK,QAAAA,YAAY,CAAE,IAAF,CAAZ;AACAQ,QAAAA,YAAY,CAAEP,SAAF,CAAZ;AACAA,QAAAA,SAAS,GAAGQ,UAAU,CAAE,MAAMT,YAAY,CAAE,KAAF,CAApB,EAA+BL,OAA/B,CAAtB;AACA;AACD,KAhBD;AAkBA,WAAO,MAAM;AACZ,UAAKG,SAAS,CAACI,OAAf,EAAyB;AACxBJ,QAAAA,SAAS,CAACI,OAAV,CAAkBQ,OAAlB;AACA;;AACDF,MAAAA,YAAY,CAAEP,SAAF,CAAZ;AACA,KALD;AAMA,GArCD,EAqCG,CAAEP,IAAF,EAAQC,OAAR,EAAiBK,YAAjB,CArCH;AAuCA,SAAOD,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useState } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Copies the text to the clipboard when the element is clicked.\n *\n * @deprecated\n *\n * @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.\n * @param {string|Function} text The text to copy.\n * @param {number} [timeout] Optional timeout to reset the returned\n * state. 4 seconds by default.\n *\n * @return {boolean} Whether or not the text has been copied. Resets after the\n * timeout.\n */\nexport default function useCopyOnClick( ref, text, timeout = 4000 ) {\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tdeprecated( 'wp.compose.useCopyOnClick', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.compose.useCopyToClipboard',\n\t} );\n\n\t/** @type {import('react').MutableRefObject<Clipboard | undefined>} */\n\tconst clipboard = useRef();\n\tconst [ hasCopied, setHasCopied ] = useState( false );\n\n\tuseEffect( () => {\n\t\t/** @type {number | undefined} */\n\t\tlet timeoutId;\n\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Clipboard listens to click events.\n\t\tclipboard.current = new Clipboard( ref.current, {\n\t\t\ttext: () => ( typeof text === 'function' ? text() : text ),\n\t\t} );\n\n\t\tclipboard.current.on( 'success', ( { clearSelection, trigger } ) => {\n\t\t\t// Clearing selection will move focus back to the triggering button,\n\t\t\t// ensuring that it is not reset to the body, and further that it is\n\t\t\t// kept within the rendered node.\n\t\t\tclearSelection();\n\n\t\t\t// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680\n\t\t\tif ( trigger ) {\n\t\t\t\t/** @type {HTMLElement} */ ( trigger ).focus();\n\t\t\t}\n\n\t\t\tif ( timeout ) {\n\t\t\t\tsetHasCopied( true );\n\t\t\t\tclearTimeout( timeoutId );\n\t\t\t\ttimeoutId = setTimeout( () => setHasCopied( false ), timeout );\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tif ( clipboard.current ) {\n\t\t\t\tclipboard.current.destroy();\n\t\t\t}\n\t\t\tclearTimeout( timeoutId );\n\t\t};\n\t}, [ text, timeout, setHasCopied ] );\n\n\treturn hasCopied;\n}\n"]}
|
|
@@ -60,10 +60,9 @@ function useCopyToClipboard(text, onSuccess) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
});
|
|
63
|
-
clipboard.on('success',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} = _ref;
|
|
63
|
+
clipboard.on('success', ({
|
|
64
|
+
clearSelection
|
|
65
|
+
}) => {
|
|
67
66
|
// Clearing selection will move focus back to the triggering
|
|
68
67
|
// button, ensuring that it is not reset to the body, and
|
|
69
68
|
// further that it is kept within the rendered node.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-to-clipboard/index.js"],"names":["useUpdatedRef","value","ref","current","useCopyToClipboard","text","onSuccess","textRef","onSuccessRef","node","clipboard","Clipboard","on","clearSelection","focus","destroy"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,KAAxB,EAAgC;AAC/B,QAAMC,GAAG,GAAG,qBAAQD,KAAR,CAAZ;AACAC,EAAAA,GAAG,CAACC,OAAJ,GAAcF,KAAd;AACA,SAAOC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASE,kBAAT,CAA6BC,IAA7B,EAAmCC,SAAnC,EAA+C;AAC7D;AACA;AACA,QAAMC,OAAO,GAAGP,aAAa,CAAEK,IAAF,CAA7B;AACA,QAAMG,YAAY,GAAGR,aAAa,CAAEM,SAAF,CAAlC;AACA,SAAO,2BAAgBG,IAAF,IAAY;AAChC;AACA,UAAMC,SAAS,GAAG,IAAIC,kBAAJ,CAAeF,IAAf,EAAqB;AACtCJ,MAAAA,IAAI,GAAG;AACN,eAAO,OAAOE,OAAO,CAACJ,OAAf,KAA2B,UAA3B,GACJI,OAAO,CAACJ,OAAR,EADI,GAEJI,OAAO,CAACJ,OAAR,IAAmB,EAFtB;AAGA;;AALqC,KAArB,CAAlB;AAQAO,IAAAA,SAAS,CAACE,EAAV,CAAc,SAAd,EAAyB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-to-clipboard/index.js"],"names":["useUpdatedRef","value","ref","current","useCopyToClipboard","text","onSuccess","textRef","onSuccessRef","node","clipboard","Clipboard","on","clearSelection","focus","destroy"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,KAAxB,EAAgC;AAC/B,QAAMC,GAAG,GAAG,qBAAQD,KAAR,CAAZ;AACAC,EAAAA,GAAG,CAACC,OAAJ,GAAcF,KAAd;AACA,SAAOC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASE,kBAAT,CAA6BC,IAA7B,EAAmCC,SAAnC,EAA+C;AAC7D;AACA;AACA,QAAMC,OAAO,GAAGP,aAAa,CAAEK,IAAF,CAA7B;AACA,QAAMG,YAAY,GAAGR,aAAa,CAAEM,SAAF,CAAlC;AACA,SAAO,2BAAgBG,IAAF,IAAY;AAChC;AACA,UAAMC,SAAS,GAAG,IAAIC,kBAAJ,CAAeF,IAAf,EAAqB;AACtCJ,MAAAA,IAAI,GAAG;AACN,eAAO,OAAOE,OAAO,CAACJ,OAAf,KAA2B,UAA3B,GACJI,OAAO,CAACJ,OAAR,EADI,GAEJI,OAAO,CAACJ,OAAR,IAAmB,EAFtB;AAGA;;AALqC,KAArB,CAAlB;AAQAO,IAAAA,SAAS,CAACE,EAAV,CAAc,SAAd,EAAyB,CAAE;AAAEC,MAAAA;AAAF,KAAF,KAA0B;AAClD;AACA;AACA;AACAA,MAAAA,cAAc,GAJoC,CAKlD;AACA;;AACAJ,MAAAA,IAAI,CAACK,KAAL;;AAEA,UAAKN,YAAY,CAACL,OAAlB,EAA4B;AAC3BK,QAAAA,YAAY,CAACL,OAAb;AACA;AACD,KAZD;AAcA,WAAO,MAAM;AACZO,MAAAA,SAAS,CAACK,OAAV;AACA,KAFD;AAGA,GA3BM,EA2BJ,EA3BI,CAAP;AA4BA","sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * @template T\n * @param {T} value\n * @return {import('react').RefObject<T>} The updated ref\n */\nfunction useUpdatedRef( value ) {\n\tconst ref = useRef( value );\n\tref.current = value;\n\treturn ref;\n}\n\n/**\n * Copies the given text to the clipboard when the element is clicked.\n *\n * @template {HTMLElement} TElementType\n * @param {string | (() => string)} text The text to copy. Use a function if not\n * already available and expensive to compute.\n * @param {Function} onSuccess Called when to text is copied.\n *\n * @return {import('react').Ref<TElementType>} A ref to assign to the target element.\n */\nexport default function useCopyToClipboard( text, onSuccess ) {\n\t// Store the dependencies as refs and continuously update them so they're\n\t// fresh when the callback is called.\n\tconst textRef = useUpdatedRef( text );\n\tconst onSuccessRef = useUpdatedRef( onSuccess );\n\treturn useRefEffect( ( node ) => {\n\t\t// Clipboard listens to click events.\n\t\tconst clipboard = new Clipboard( node, {\n\t\t\ttext() {\n\t\t\t\treturn typeof textRef.current === 'function'\n\t\t\t\t\t? textRef.current()\n\t\t\t\t\t: textRef.current || '';\n\t\t\t},\n\t\t} );\n\n\t\tclipboard.on( 'success', ( { clearSelection } ) => {\n\t\t\t// Clearing selection will move focus back to the triggering\n\t\t\t// button, ensuring that it is not reset to the body, and\n\t\t\t// further that it is kept within the rendered node.\n\t\t\tclearSelection();\n\t\t\t// Handle ClipboardJS focus bug, see\n\t\t\t// https://github.com/zenorocha/clipboard.js/issues/680\n\t\t\tnode.focus();\n\n\t\t\tif ( onSuccessRef.current ) {\n\t\t\t\tonSuccessRef.current();\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tclipboard.destroy();\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -51,13 +51,11 @@ function useDialog(options) {
|
|
|
51
51
|
const focusOnMountRef = (0, _useFocusOnMount.default)(options.focusOnMount);
|
|
52
52
|
const focusReturnRef = (0, _useFocusReturn.default)();
|
|
53
53
|
const focusOutsideProps = (0, _useFocusOutside.default)(event => {
|
|
54
|
-
var _currentOptions$curre, _currentOptions$curre2;
|
|
55
|
-
|
|
56
54
|
// This unstable prop is here only to manage backward compatibility
|
|
57
55
|
// for the Popover component otherwise, the onClose should be enough.
|
|
58
|
-
if (
|
|
56
|
+
if (currentOptions.current?.__unstableOnClose) {
|
|
59
57
|
currentOptions.current.__unstableOnClose('focus-outside', event);
|
|
60
|
-
} else if (
|
|
58
|
+
} else if (currentOptions.current?.onClose) {
|
|
61
59
|
currentOptions.current.onClose();
|
|
62
60
|
}
|
|
63
61
|
});
|
|
@@ -67,10 +65,8 @@ function useDialog(options) {
|
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
node.addEventListener('keydown', event => {
|
|
70
|
-
var _currentOptions$curre3;
|
|
71
|
-
|
|
72
68
|
// Close on escape.
|
|
73
|
-
if (event.keyCode === _keycodes.ESCAPE && !event.defaultPrevented &&
|
|
69
|
+
if (event.keyCode === _keycodes.ESCAPE && !event.defaultPrevented && currentOptions.current?.onClose) {
|
|
74
70
|
event.preventDefault();
|
|
75
71
|
currentOptions.current.onClose();
|
|
76
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-dialog/index.ts"],"names":["useDialog","options","currentOptions","current","Object","values","constrainedTabbingRef","focusOnMountRef","focusOnMount","focusReturnRef","focusOutsideProps","event","__unstableOnClose","onClose","closeOnEscapeRef","node","addEventListener","keyCode","ESCAPE","defaultPrevented","preventDefault","tabIndex"],"mappings":";;;;;;;;;AAQA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,SAAT,CAAoBC,OAApB,EAA8D;AAC7D,QAAMC,cAAc,GAAG,sBAAvB;AACA,0BAAW,MAAM;AAChBA,IAAAA,cAAc,CAACC,OAAf,GAAyBF,OAAzB;AACA,GAFD,EAEGG,MAAM,CAACC,MAAP,CAAeJ,OAAf,CAFH;AAGA,QAAMK,qBAAqB,GAAG,qCAA9B;AACA,QAAMC,eAAe,GAAG,8BAAiBN,OAAO,CAACO,YAAzB,CAAxB;AACA,QAAMC,cAAc,GAAG,8BAAvB;AACA,QAAMC,iBAAiB,GAAG,8BAAmBC,KAAF,IAAa;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-dialog/index.ts"],"names":["useDialog","options","currentOptions","current","Object","values","constrainedTabbingRef","focusOnMountRef","focusOnMount","focusReturnRef","focusOutsideProps","event","__unstableOnClose","onClose","closeOnEscapeRef","node","addEventListener","keyCode","ESCAPE","defaultPrevented","preventDefault","tabIndex"],"mappings":";;;;;;;;;AAQA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,SAAT,CAAoBC,OAApB,EAA8D;AAC7D,QAAMC,cAAc,GAAG,sBAAvB;AACA,0BAAW,MAAM;AAChBA,IAAAA,cAAc,CAACC,OAAf,GAAyBF,OAAzB;AACA,GAFD,EAEGG,MAAM,CAACC,MAAP,CAAeJ,OAAf,CAFH;AAGA,QAAMK,qBAAqB,GAAG,qCAA9B;AACA,QAAMC,eAAe,GAAG,8BAAiBN,OAAO,CAACO,YAAzB,CAAxB;AACA,QAAMC,cAAc,GAAG,8BAAvB;AACA,QAAMC,iBAAiB,GAAG,8BAAmBC,KAAF,IAAa;AACvD;AACA;AACA,QAAKT,cAAc,CAACC,OAAf,EAAwBS,iBAA7B,EAAiD;AAChDV,MAAAA,cAAc,CAACC,OAAf,CAAuBS,iBAAvB,CAA0C,eAA1C,EAA2DD,KAA3D;AACA,KAFD,MAEO,IAAKT,cAAc,CAACC,OAAf,EAAwBU,OAA7B,EAAuC;AAC7CX,MAAAA,cAAc,CAACC,OAAf,CAAuBU,OAAvB;AACA;AACD,GARyB,CAA1B;AASA,QAAMC,gBAAgB,GAAG,0BAAeC,IAAF,IAAyB;AAC9D,QAAK,CAAEA,IAAP,EAAc;AACb;AACA;;AAEDA,IAAAA,IAAI,CAACC,gBAAL,CAAuB,SAAvB,EAAoCL,KAAF,IAA4B;AAC7D;AACA,UACCA,KAAK,CAACM,OAAN,KAAkBC,gBAAlB,IACA,CAAEP,KAAK,CAACQ,gBADR,IAEAjB,cAAc,CAACC,OAAf,EAAwBU,OAHzB,EAIE;AACDF,QAAAA,KAAK,CAACS,cAAN;AACAlB,QAAAA,cAAc,CAACC,OAAf,CAAuBU,OAAvB;AACA;AACD,KAVD;AAWA,GAhBwB,EAgBtB,EAhBsB,CAAzB;AAkBA,SAAO,CACN,2BAAc,CACbZ,OAAO,CAACO,YAAR,KAAyB,KAAzB,GAAiCF,qBAAjC,GAAyD,IAD5C,EAEbL,OAAO,CAACO,YAAR,KAAyB,KAAzB,GAAiCC,cAAjC,GAAkD,IAFrC,EAGbR,OAAO,CAACO,YAAR,KAAyB,KAAzB,GAAiCD,eAAjC,GAAmD,IAHtC,EAIbO,gBAJa,CAAd,CADM,EAON,EACC,GAAGJ,iBADJ;AAECW,IAAAA,QAAQ,EAAE,CAAC;AAFZ,GAPM,CAAP;AAYA;;eAEcrB,S","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\tfocusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];\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\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\toptions.focusOnMount !== false ? 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"]}
|