@wordpress/compose 6.11.0 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/higher-order/pipe.js +6 -19
- package/build/higher-order/pipe.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-state/index.js +1 -2
- 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/pipe.js +6 -19
- package/build-module/higher-order/pipe.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-state/index.js +1 -2
- 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
|
@@ -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"]}
|
|
@@ -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,W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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"]}
|
|
@@ -33,8 +33,7 @@ var _createHigherOrderComponent = require("../../utils/create-higher-order-compo
|
|
|
33
33
|
*
|
|
34
34
|
* @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
35
|
*/
|
|
36
|
-
function withState() {
|
|
37
|
-
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
36
|
+
function withState(initialState = {}) {
|
|
38
37
|
(0, _deprecated.default)('wp.compose.withState', {
|
|
39
38
|
since: '5.8',
|
|
40
39
|
alternative: 'wp.element.useState'
|
|
@@ -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;;;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,
|
|
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,6BACM,KAAKJ,KADX,EAEM,KAAKG,KAFX;AAGC,UAAA,QAAQ,EAAG,KAAKF;AAHjB,WADD;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;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AEAA,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"]}
|
|
@@ -41,18 +41,15 @@ var _useRefEffect = _interopRequireDefault(require("../use-ref-effect"));
|
|
|
41
41
|
* };
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
function useDisabled(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
44
|
+
function useDisabled({
|
|
45
|
+
isDisabled: isDisabledProp = false
|
|
46
|
+
} = {}) {
|
|
48
47
|
return (0, _useRefEffect.default)(node => {
|
|
49
|
-
var _node$ownerDocument;
|
|
50
|
-
|
|
51
48
|
if (isDisabledProp) {
|
|
52
49
|
return;
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
const defaultView = node
|
|
52
|
+
const defaultView = node?.ownerDocument?.defaultView;
|
|
56
53
|
|
|
57
54
|
if (!defaultView) {
|
|
58
55
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-disabled/index.ts"],"names":["useDisabled","isDisabled","isDisabledProp","node","defaultView","ownerDocument","updates","disable","childNodes","forEach","child","HTMLElement","getAttribute","setAttribute","push","removeAttribute","debouncedDisable","leading","observer","window","MutationObserver","observe","childList","disconnect","cancel","update"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-disabled/index.ts"],"names":["useDisabled","isDisabled","isDisabledProp","node","defaultView","ownerDocument","updates","disable","childNodes","forEach","child","HTMLElement","getAttribute","setAttribute","push","removeAttribute","debouncedDisable","leading","observer","window","MutationObserver","observe","childList","disconnect","cancel","update"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,CAAsB;AACpCC,EAAAA,UAAU,EAAEC,cAAc,GAAG;AADO,IAEjC,EAFW,EAEN;AACR,SAAO,2BACJC,IAAF,IAAY;AACX,QAAKD,cAAL,EAAsB;AACrB;AACA;;AAED,UAAME,WAAW,GAAGD,IAAI,EAAEE,aAAN,EAAqBD,WAAzC;;AACA,QAAK,CAAEA,WAAP,EAAqB;AACpB;AACA;AAED;;;AACA,UAAME,OAAmB,GAAG,EAA5B;;AACA,UAAMC,OAAO,GAAG,MAAM;AACrBJ,MAAAA,IAAI,CAACK,UAAL,CAAgBC,OAAhB,CAA2BC,KAAF,IAAa;AACrC,YAAK,EAAIA,KAAK,YAAYN,WAAW,CAACO,WAAjC,CAAL,EAAsD;AACrD;AACA;;AACD,YAAK,CAAED,KAAK,CAACE,YAAN,CAAoB,OAApB,CAAP,EAAuC;AACtCF,UAAAA,KAAK,CAACG,YAAN,CAAoB,OAApB,EAA6B,MAA7B;AACAP,UAAAA,OAAO,CAACQ,IAAR,CAAc,MAAM;AACnBJ,YAAAA,KAAK,CAACK,eAAN,CAAuB,OAAvB;AACA,WAFD;AAGA;AACD,OAVD;AAWA,KAZD,CAZW,CA0BX;AACA;;;AACA,UAAMC,gBAAgB,GAAG,wBAAUT,OAAV,EAAmB,CAAnB,EAAsB;AAC9CU,MAAAA,OAAO,EAAE;AADqC,KAAtB,CAAzB;AAGAV,IAAAA,OAAO;AAEP;;AACA,UAAMW,QAAQ,GAAG,IAAIC,MAAM,CAACC,gBAAX,CAA6BJ,gBAA7B,CAAjB;AACAE,IAAAA,QAAQ,CAACG,OAAT,CAAkBlB,IAAlB,EAAwB;AACvBmB,MAAAA,SAAS,EAAE;AADY,KAAxB;AAIA,WAAO,MAAM;AACZ,UAAKJ,QAAL,EAAgB;AACfA,QAAAA,QAAQ,CAACK,UAAT;AACA;;AACDP,MAAAA,gBAAgB,CAACQ,MAAjB;AACAlB,MAAAA,OAAO,CAACG,OAAR,CAAmBgB,MAAF,IAAcA,MAAM,EAArC;AACA,KAND;AAOA,GA/CK,EAgDN,CAAEvB,cAAF,CAhDM,CAAP;AAkDA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * If you can, prefer the use of the inert HTML attribute.\n *\n * @param {Object} config Configuration object.\n * @param {boolean=} config.isDisabled Whether the element should be disabled.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useDisabled } from '@wordpress/compose';\n *\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled( {\n\tisDisabled: isDisabledProp = false,\n} = {} ) {\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isDisabledProp ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultView = node?.ownerDocument?.defaultView;\n\t\t\tif ( ! defaultView ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/** A variable keeping track of the previous updates in order to restore them. */\n\t\t\tconst updates: Function[] = [];\n\t\t\tconst disable = () => {\n\t\t\t\tnode.childNodes.forEach( ( child ) => {\n\t\t\t\t\tif ( ! ( child instanceof defaultView.HTMLElement ) ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif ( ! child.getAttribute( 'inert' ) ) {\n\t\t\t\t\t\tchild.setAttribute( 'inert', 'true' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tchild.removeAttribute( 'inert' );\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Debounce re-disable since disabling process itself will incur\n\t\t\t// additional mutations which should be ignored.\n\t\t\tconst debouncedDisable = debounce( disable, 0, {\n\t\t\t\tleading: true,\n\t\t\t} );\n\t\t\tdisable();\n\n\t\t\t/** @type {MutationObserver | undefined} */\n\t\t\tconst observer = new window.MutationObserver( debouncedDisable );\n\t\t\tobserver.observe( node, {\n\t\t\t\tchildList: true,\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tif ( observer ) {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t}\n\t\t\t\tdebouncedDisable.cancel();\n\t\t\t\tupdates.forEach( ( update ) => update() );\n\t\t\t};\n\t\t},\n\t\t[ isDisabledProp ]\n\t);\n}\n"]}
|
|
@@ -27,12 +27,11 @@ var _useIsomorphicLayoutEffect = _interopRequireDefault(require("../use-isomorph
|
|
|
27
27
|
* @param {(e: MouseEvent) => void} props.onDragMove
|
|
28
28
|
* @param {(e?: MouseEvent) => void} props.onDragEnd
|
|
29
29
|
*/
|
|
30
|
-
function useDragging(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} = _ref;
|
|
30
|
+
function useDragging({
|
|
31
|
+
onDragStart,
|
|
32
|
+
onDragMove,
|
|
33
|
+
onDragEnd
|
|
34
|
+
}) {
|
|
36
35
|
const [isDragging, setIsDragging] = (0, _element.useState)(false);
|
|
37
36
|
const eventsRef = (0, _element.useRef)({
|
|
38
37
|
onDragStart,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-dragging/index.js"],"names":["useDragging","onDragStart","onDragMove","onDragEnd","isDragging","setIsDragging","eventsRef","current","onMouseMove","event","endDrag","document","removeEventListener","startDrag","addEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAGA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-dragging/index.js"],"names":["useDragging","onDragStart","onDragMove","onDragEnd","isDragging","setIsDragging","eventsRef","current","onMouseMove","event","endDrag","document","removeEventListener","startDrag","addEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAGA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,CAAsB;AAAEC,EAAAA,WAAF;AAAeC,EAAAA,UAAf;AAA2BC,EAAAA;AAA3B,CAAtB,EAA+D;AAC7E,QAAM,CAAEC,UAAF,EAAcC,aAAd,IAAgC,uBAAU,KAAV,CAAtC;AAEA,QAAMC,SAAS,GAAG,qBAAQ;AACzBL,IAAAA,WADyB;AAEzBC,IAAAA,UAFyB;AAGzBC,IAAAA;AAHyB,GAAR,CAAlB;AAKA,0CAA2B,MAAM;AAChCG,IAAAA,SAAS,CAACC,OAAV,CA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A,QAAQ,CAACC,mBAAT,CAA8B,WAA9B,EAA2CJ,WAA3C;AACAG,QAAAA,QAAQ,CAACC,mBAAT,CAA8B,SAA9B,EAAyCF,OAAzC;AACA;AACD,KALD;AAMA,GAPD,EAOG,CAAEN,UAAF,CAPH;AASA,SAAO;AACNS,IAAAA,SADM;AAENH,IAAAA,OAFM;AAGNN,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';\n\n// Event handlers that are triggered from `document` listeners accept a MouseEvent,\n// while those triggered from React listeners accept a React.MouseEvent.\n/**\n * @param {Object} props\n * @param {(e: import('react').MouseEvent) => void} props.onDragStart\n * @param {(e: MouseEvent) => void} props.onDragMove\n * @param {(e?: MouseEvent) => void} props.onDragEnd\n */\nexport default function useDragging( { onDragStart, onDragMove, onDragEnd } ) {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\n\tconst eventsRef = useRef( {\n\t\tonDragStart,\n\t\tonDragMove,\n\t\tonDragEnd,\n\t} );\n\tuseIsomorphicLayoutEffect( () => {\n\t\teventsRef.current.onDragStart = onDragStart;\n\t\teventsRef.current.onDragMove = onDragMove;\n\t\teventsRef.current.onDragEnd = onDragEnd;\n\t}, [ onDragStart, onDragMove, onDragEnd ] );\n\n\t/** @type {(e: MouseEvent) => void} */\n\tconst onMouseMove = useCallback(\n\t\t( event ) =>\n\t\t\teventsRef.current.onDragMove &&\n\t\t\teventsRef.current.onDragMove( event ),\n\t\t[]\n\t);\n\t/** @type {(e?: MouseEvent) => void} */\n\tconst endDrag = useCallback( ( event ) => {\n\t\tif ( eventsRef.current.onDragEnd ) {\n\t\t\teventsRef.current.onDragEnd( event );\n\t\t}\n\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\tsetIsDragging( false );\n\t}, [] );\n\t/** @type {(e: import('react').MouseEvent) => void} */\n\tconst startDrag = useCallback( ( event ) => {\n\t\tif ( eventsRef.current.onDragStart ) {\n\t\t\teventsRef.current.onDragStart( event );\n\t\t}\n\t\tdocument.addEventListener( 'mousemove', onMouseMove );\n\t\tdocument.addEventListener( 'mouseup', endDrag );\n\t\tsetIsDragging( true );\n\t}, [] );\n\n\t// Remove the global events when unmounting if needed.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( isDragging ) {\n\t\t\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\t\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\t\t}\n\t\t};\n\t}, [ isDragging ] );\n\n\treturn {\n\t\tstartDrag,\n\t\tendDrag,\n\t\tisDragging,\n\t};\n}\n"]}
|
|
@@ -47,40 +47,45 @@ function useFreshRef(value) {
|
|
|
47
47
|
/**
|
|
48
48
|
* A hook to facilitate drag and drop handling.
|
|
49
49
|
*
|
|
50
|
-
* @param {Object} props
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
53
|
-
* @param {(e: DragEvent) => void} [props.
|
|
54
|
-
* @param {(e: DragEvent) => void} [props.
|
|
55
|
-
* @param {(e: DragEvent) => void} [props.
|
|
56
|
-
* @param {(e:
|
|
57
|
-
* @param {(e:
|
|
50
|
+
* @param {Object} props Named parameters.
|
|
51
|
+
* @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone.
|
|
52
|
+
* @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.
|
|
53
|
+
* @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.
|
|
54
|
+
* @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.
|
|
55
|
+
* @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.
|
|
56
|
+
* @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.
|
|
57
|
+
* @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.
|
|
58
|
+
* @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.
|
|
58
59
|
*
|
|
59
60
|
* @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.
|
|
60
61
|
*/
|
|
61
62
|
|
|
62
63
|
|
|
63
|
-
function useDropZone(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
function useDropZone({
|
|
65
|
+
dropZoneElement,
|
|
66
|
+
isDisabled,
|
|
67
|
+
onDrop: _onDrop,
|
|
68
|
+
onDragStart: _onDragStart,
|
|
69
|
+
onDragEnter: _onDragEnter,
|
|
70
|
+
onDragLeave: _onDragLeave,
|
|
71
|
+
onDragEnd: _onDragEnd,
|
|
72
|
+
onDragOver: _onDragOver
|
|
73
|
+
}) {
|
|
73
74
|
const onDropRef = useFreshRef(_onDrop);
|
|
74
75
|
const onDragStartRef = useFreshRef(_onDragStart);
|
|
75
76
|
const onDragEnterRef = useFreshRef(_onDragEnter);
|
|
76
77
|
const onDragLeaveRef = useFreshRef(_onDragLeave);
|
|
77
78
|
const onDragEndRef = useFreshRef(_onDragEnd);
|
|
78
79
|
const onDragOverRef = useFreshRef(_onDragOver);
|
|
79
|
-
return (0, _useRefEffect.default)(
|
|
80
|
+
return (0, _useRefEffect.default)(elem => {
|
|
80
81
|
if (isDisabled) {
|
|
81
82
|
return;
|
|
82
|
-
}
|
|
83
|
+
} // If a custom dropZoneRef is passed, use that instead of the element.
|
|
84
|
+
// This allows the dropzone to cover an expanded area, rather than
|
|
85
|
+
// be restricted to the area of the ref returned by this hook.
|
|
86
|
+
|
|
83
87
|
|
|
88
|
+
const element = dropZoneElement !== null && dropZoneElement !== void 0 ? dropZoneElement : elem;
|
|
84
89
|
let isDragging = false;
|
|
85
90
|
const {
|
|
86
91
|
ownerDocument
|
|
@@ -244,6 +249,7 @@ function useDropZone(_ref) {
|
|
|
244
249
|
ownerDocument.removeEventListener('mousemove', maybeDragEnd);
|
|
245
250
|
ownerDocument.removeEventListener('dragenter', maybeDragStart);
|
|
246
251
|
};
|
|
247
|
-
}, [isDisabled]
|
|
252
|
+
}, [isDisabled, dropZoneElement] // Refresh when the passed in dropZoneElement changes.
|
|
253
|
+
);
|
|
248
254
|
}
|
|
249
255
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-drop-zone/index.js"],"names":["useFreshRef","value","ref","current","useDropZone","isDisabled","onDrop","_onDrop","onDragStart","_onDragStart","onDragEnter","_onDragEnter","onDragLeave","_onDragLeave","onDragEnd","_onDragEnd","onDragOver","_onDragOver","onDropRef","onDragStartRef","onDragEnterRef","onDragLeaveRef","onDragEndRef","onDragOverRef","element","isDragging","ownerDocument","isElementInZone","targetToCheck","defaultView","HTMLElement","contains","elementToCheck","dataset","isDropZone","parentElement","maybeDragStart","event","addEventListener","maybeDragEnd","preventDefault","relatedTarget","defaultPrevented","dataTransfer","files","length","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAMC,GAAG,GAAG,sBAAZ;AACAA,EAAAA,GAAG,CAACC,OAAJ,GAAcF,KAAd;AACA,SAAOC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASE,WAAT,OAQX;AAAA,MARiC;AACpCC,IAAAA,UADoC;AAEpCC,IAAAA,MAAM,EAAEC,OAF4B;AAGpCC,IAAAA,WAAW,EAAEC,YAHuB;AAIpCC,IAAAA,WAAW,EAAEC,YAJuB;AAKpCC,IAAAA,WAAW,EAA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A,OAAO,CAACsB,mBAAR,CAA6B,UAA7B,EAAyC9B,UAAzC;AACAQ,MAAAA,OAAO,CAACsB,mBAAR,CAA6B,WAA7B,EAA0ClC,WAA1C;AACAc,MAAAA,aAAa,CAACoB,mBAAd,CAAmC,SAAnC,EAA8CP,YAA9C;AACAb,MAAAA,aAAa,CAACoB,mBAAd,CAAmC,WAAnC,EAAgDP,YAAhD;AACAb,MAAAA,aAAa,CAACoB,mBAAd,CACC,WADD,EAECV,cAFD;AAIA,KAZD;AAaA,GAvKK,EAwKN,CAAE/B,UAAF,CAxKM,CAAP;AA0KA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @param {T} value\n * @return {import('react').MutableRefObject<T|null>} A ref with the value.\n */\nfunction useFreshRef( value ) {\n\t/* eslint-enable jsdoc/valid-types */\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<T>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\t// Disable reason: We're doing something pretty JavaScript-y here where the\n\t// ref will always have a current value that is not null or undefined but it\n\t// needs to start as undefined. We don't want to change the return type so\n\t// it's easier to just ts-ignore this specific line that's complaining about\n\t// undefined not being part of T.\n\t// @ts-ignore\n\tconst ref = useRef();\n\tref.current = value;\n\treturn ref;\n}\n\n/**\n * A hook to facilitate drag and drop handling.\n *\n * @param {Object} props Named parameters.\n * @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.\n * @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.\n * @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.\n * @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.\n * @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.\n * @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.\n * @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.\n *\n * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.\n */\nexport default function useDropZone( {\n\tisDisabled,\n\tonDrop: _onDrop,\n\tonDragStart: _onDragStart,\n\tonDragEnter: _onDragEnter,\n\tonDragLeave: _onDragLeave,\n\tonDragEnd: _onDragEnd,\n\tonDragOver: _onDragOver,\n} ) {\n\tconst onDropRef = useFreshRef( _onDrop );\n\tconst onDragStartRef = useFreshRef( _onDragStart );\n\tconst onDragEnterRef = useFreshRef( _onDragEnter );\n\tconst onDragLeaveRef = useFreshRef( _onDragLeave );\n\tconst onDragEndRef = useFreshRef( _onDragEnd );\n\tconst onDragOverRef = useFreshRef( _onDragOver );\n\n\treturn useRefEffect(\n\t\t( element ) => {\n\t\t\tif ( isDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet isDragging = false;\n\n\t\t\tconst { ownerDocument } = element;\n\n\t\t\t/**\n\t\t\t * Checks if an element is in the drop zone.\n\t\t\t *\n\t\t\t * @param {EventTarget|null} targetToCheck\n\t\t\t *\n\t\t\t * @return {boolean} True if in drop zone, false if not.\n\t\t\t */\n\t\t\tfunction isElementInZone( targetToCheck ) {\n\t\t\t\tconst { defaultView } = ownerDocument;\n\t\t\t\tif (\n\t\t\t\t\t! targetToCheck ||\n\t\t\t\t\t! defaultView ||\n\t\t\t\t\t! ( targetToCheck instanceof defaultView.HTMLElement ) ||\n\t\t\t\t\t! element.contains( targetToCheck )\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t/** @type {HTMLElement|null} */\n\t\t\t\tlet elementToCheck = targetToCheck;\n\n\t\t\t\tdo {\n\t\t\t\t\tif ( elementToCheck.dataset.isDropZone ) {\n\t\t\t\t\t\treturn elementToCheck === element;\n\t\t\t\t\t}\n\t\t\t\t} while ( ( elementToCheck = elementToCheck.parentElement ) );\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfunction maybeDragStart( /** @type {DragEvent} */ event ) {\n\t\t\t\tif ( isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = true;\n\n\t\t\t\t// Note that `dragend` doesn't fire consistently for file and\n\t\t\t\t// HTML drag events where the drag origin is outside the browser\n\t\t\t\t// window. In Firefox it may also not fire if the originating\n\t\t\t\t// node is removed.\n\t\t\t\townerDocument.addEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.addEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragStartRef.current ) {\n\t\t\t\t\tonDragStartRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragEnter( /** @type {DragEvent} */ event ) {\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// The `dragenter` event will also fire when entering child\n\t\t\t\t// elements, but we only want to call `onDragEnter` when\n\t\t\t\t// entering the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been left) should be outside the drop zone.\n\t\t\t\tif (\n\t\t\t\t\telement.contains(\n\t\t\t\t\t\t/** @type {Node} */ ( event.relatedTarget )\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragEnterRef.current ) {\n\t\t\t\t\tonDragEnterRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragOver( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Only call onDragOver for the innermost hovered drop zones.\n\t\t\t\tif ( ! event.defaultPrevented && onDragOverRef.current ) {\n\t\t\t\t\tonDragOverRef.current( event );\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDragOver` is already handled.\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\tfunction onDragLeave( /** @type {DragEvent} */ event ) {\n\t\t\t\t// The `dragleave` event will also fire when leaving child\n\t\t\t\t// elements, but we only want to call `onDragLeave` when\n\t\t\t\t// leaving the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been entered) should be outside the drop\n\t\t\t\t// zone.\n\t\t\t\t// Note: This is not entirely reliable in Safari due to this bug\n\t\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=66547\n\t\t\t\tif ( isElementInZone( event.relatedTarget ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragLeaveRef.current ) {\n\t\t\t\t\tonDragLeaveRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDrop( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Don't handle drop if an inner drop zone already handled it.\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDrop` is already handled.\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// This seemingly useless line has been shown to resolve a\n\t\t\t\t// Safari issue where files dragged directly from the dock are\n\t\t\t\t// not recognized.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tevent.dataTransfer && event.dataTransfer.files.length;\n\n\t\t\t\tif ( onDropRef.current ) {\n\t\t\t\t\tonDropRef.current( event );\n\t\t\t\t}\n\n\t\t\t\tmaybeDragEnd( event );\n\t\t\t}\n\n\t\t\tfunction maybeDragEnd( /** @type {MouseEvent} */ event ) {\n\t\t\t\tif ( ! isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = false;\n\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragEndRef.current ) {\n\t\t\t\t\tonDragEndRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telement.dataset.isDropZone = 'true';\n\t\t\telement.addEventListener( 'drop', onDrop );\n\t\t\telement.addEventListener( 'dragenter', onDragEnter );\n\t\t\telement.addEventListener( 'dragover', onDragOver );\n\t\t\telement.addEventListener( 'dragleave', onDragLeave );\n\t\t\t// The `dragstart` event doesn't fire if the drag started outside\n\t\t\t// the document.\n\t\t\townerDocument.addEventListener( 'dragenter', maybeDragStart );\n\n\t\t\treturn () => {\n\t\t\t\tdelete element.dataset.isDropZone;\n\t\t\t\telement.removeEventListener( 'drop', onDrop );\n\t\t\t\telement.removeEventListener( 'dragenter', onDragEnter );\n\t\t\t\telement.removeEventListener( 'dragover', onDragOver );\n\t\t\t\telement.removeEventListener( 'dragleave', onDragLeave );\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'dragenter',\n\t\t\t\t\tmaybeDragStart\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t\t[ isDisabled ]\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-drop-zone/index.js"],"names":["useFreshRef","value","ref","current","useDropZone","dropZoneElement","isDisabled","onDrop","_onDrop","onDragStart","_onDragStart","onDragEnter","_onDragEnter","onDragLeave","_onDragLeave","onDragEnd","_onDragEnd","onDragOver","_onDragOver","onDropRef","onDragStartRef","onDragEnterRef","onDragLeaveRef","onDragEndRef","onDragOverRef","elem","element","isDragging","ownerDocument","isElementInZone","targetToCheck","defaultView","HTMLElement","contains","elementToCheck","dataset","isDropZone","parentElement","maybeDragStart","event","addEventListener","maybeDragEnd","preventDefault","relatedTarget","defaultPrevented","dataTransfer","files","length","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAMC,GAAG,GAAG,sB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CAACc,gBAAR,CAA0B,WAA1B,EAAuC7B,WAAvC;AACAe,IAAAA,OAAO,CAACc,gBAAR,CAA0B,UAA1B,EAAsCvB,UAAtC;AACAS,IAAAA,OAAO,CAACc,gBAAR,CAA0B,WAA1B,EAAuC3B,WAAvC,EAzJW,CA0JX;AACA;;AACAe,IAAAA,aAAa,CAACY,gBAAd,CAAgC,WAAhC,EAA6CF,cAA7C;AAEA,WAAO,MAAM;AACZ,aAAOZ,OAAO,CAACS,OAAR,CAAgBC,UAAvB;AACAV,MAAAA,OAAO,CAACsB,mBAAR,CAA6B,MAA7B,EAAqCzC,MAArC;AACAmB,MAAAA,OAAO,CAACsB,mBAAR,CAA6B,WAA7B,EAA0CrC,WAA1C;AACAe,MAAAA,OAAO,CAACsB,mBAAR,CAA6B,UAA7B,EAAyC/B,UAAzC;AACAS,MAAAA,OAAO,CAACsB,mBAAR,CAA6B,WAA7B,EAA0CnC,WAA1C;AACAe,MAAAA,aAAa,CAACoB,mBAAd,CAAmC,SAAnC,EAA8CP,YAA9C;AACAb,MAAAA,aAAa,CAACoB,mBAAd,CAAmC,WAAnC,EAAgDP,YAAhD;AACAb,MAAAA,aAAa,CAACoB,mBAAd,CACC,WADD,EAECV,cAFD;AAIA,KAZD;AAaA,GA5KK,EA6KN,CAAEhC,UAAF,EAAcD,eAAd,CA7KM,CA6K0B;AA7K1B,GAAP;AA+KA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @param {T} value\n * @return {import('react').MutableRefObject<T|null>} A ref with the value.\n */\nfunction useFreshRef( value ) {\n\t/* eslint-enable jsdoc/valid-types */\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<T>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\t// Disable reason: We're doing something pretty JavaScript-y here where the\n\t// ref will always have a current value that is not null or undefined but it\n\t// needs to start as undefined. We don't want to change the return type so\n\t// it's easier to just ts-ignore this specific line that's complaining about\n\t// undefined not being part of T.\n\t// @ts-ignore\n\tconst ref = useRef();\n\tref.current = value;\n\treturn ref;\n}\n\n/**\n * A hook to facilitate drag and drop handling.\n *\n * @param {Object} props Named parameters.\n * @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone.\n * @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.\n * @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.\n * @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.\n * @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.\n * @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.\n * @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.\n * @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.\n *\n * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.\n */\nexport default function useDropZone( {\n\tdropZoneElement,\n\tisDisabled,\n\tonDrop: _onDrop,\n\tonDragStart: _onDragStart,\n\tonDragEnter: _onDragEnter,\n\tonDragLeave: _onDragLeave,\n\tonDragEnd: _onDragEnd,\n\tonDragOver: _onDragOver,\n} ) {\n\tconst onDropRef = useFreshRef( _onDrop );\n\tconst onDragStartRef = useFreshRef( _onDragStart );\n\tconst onDragEnterRef = useFreshRef( _onDragEnter );\n\tconst onDragLeaveRef = useFreshRef( _onDragLeave );\n\tconst onDragEndRef = useFreshRef( _onDragEnd );\n\tconst onDragOverRef = useFreshRef( _onDragOver );\n\n\treturn useRefEffect(\n\t\t( elem ) => {\n\t\t\tif ( isDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If a custom dropZoneRef is passed, use that instead of the element.\n\t\t\t// This allows the dropzone to cover an expanded area, rather than\n\t\t\t// be restricted to the area of the ref returned by this hook.\n\t\t\tconst element = dropZoneElement ?? elem;\n\n\t\t\tlet isDragging = false;\n\n\t\t\tconst { ownerDocument } = element;\n\n\t\t\t/**\n\t\t\t * Checks if an element is in the drop zone.\n\t\t\t *\n\t\t\t * @param {EventTarget|null} targetToCheck\n\t\t\t *\n\t\t\t * @return {boolean} True if in drop zone, false if not.\n\t\t\t */\n\t\t\tfunction isElementInZone( targetToCheck ) {\n\t\t\t\tconst { defaultView } = ownerDocument;\n\t\t\t\tif (\n\t\t\t\t\t! targetToCheck ||\n\t\t\t\t\t! defaultView ||\n\t\t\t\t\t! ( targetToCheck instanceof defaultView.HTMLElement ) ||\n\t\t\t\t\t! element.contains( targetToCheck )\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t/** @type {HTMLElement|null} */\n\t\t\t\tlet elementToCheck = targetToCheck;\n\n\t\t\t\tdo {\n\t\t\t\t\tif ( elementToCheck.dataset.isDropZone ) {\n\t\t\t\t\t\treturn elementToCheck === element;\n\t\t\t\t\t}\n\t\t\t\t} while ( ( elementToCheck = elementToCheck.parentElement ) );\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfunction maybeDragStart( /** @type {DragEvent} */ event ) {\n\t\t\t\tif ( isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = true;\n\n\t\t\t\t// Note that `dragend` doesn't fire consistently for file and\n\t\t\t\t// HTML drag events where the drag origin is outside the browser\n\t\t\t\t// window. In Firefox it may also not fire if the originating\n\t\t\t\t// node is removed.\n\t\t\t\townerDocument.addEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.addEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragStartRef.current ) {\n\t\t\t\t\tonDragStartRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragEnter( /** @type {DragEvent} */ event ) {\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// The `dragenter` event will also fire when entering child\n\t\t\t\t// elements, but we only want to call `onDragEnter` when\n\t\t\t\t// entering the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been left) should be outside the drop zone.\n\t\t\t\tif (\n\t\t\t\t\telement.contains(\n\t\t\t\t\t\t/** @type {Node} */ ( event.relatedTarget )\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragEnterRef.current ) {\n\t\t\t\t\tonDragEnterRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragOver( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Only call onDragOver for the innermost hovered drop zones.\n\t\t\t\tif ( ! event.defaultPrevented && onDragOverRef.current ) {\n\t\t\t\t\tonDragOverRef.current( event );\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDragOver` is already handled.\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\tfunction onDragLeave( /** @type {DragEvent} */ event ) {\n\t\t\t\t// The `dragleave` event will also fire when leaving child\n\t\t\t\t// elements, but we only want to call `onDragLeave` when\n\t\t\t\t// leaving the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been entered) should be outside the drop\n\t\t\t\t// zone.\n\t\t\t\t// Note: This is not entirely reliable in Safari due to this bug\n\t\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=66547\n\t\t\t\tif ( isElementInZone( event.relatedTarget ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragLeaveRef.current ) {\n\t\t\t\t\tonDragLeaveRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDrop( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Don't handle drop if an inner drop zone already handled it.\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDrop` is already handled.\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// This seemingly useless line has been shown to resolve a\n\t\t\t\t// Safari issue where files dragged directly from the dock are\n\t\t\t\t// not recognized.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tevent.dataTransfer && event.dataTransfer.files.length;\n\n\t\t\t\tif ( onDropRef.current ) {\n\t\t\t\t\tonDropRef.current( event );\n\t\t\t\t}\n\n\t\t\t\tmaybeDragEnd( event );\n\t\t\t}\n\n\t\t\tfunction maybeDragEnd( /** @type {MouseEvent} */ event ) {\n\t\t\t\tif ( ! isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = false;\n\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragEndRef.current ) {\n\t\t\t\t\tonDragEndRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telement.dataset.isDropZone = 'true';\n\t\t\telement.addEventListener( 'drop', onDrop );\n\t\t\telement.addEventListener( 'dragenter', onDragEnter );\n\t\t\telement.addEventListener( 'dragover', onDragOver );\n\t\t\telement.addEventListener( 'dragleave', onDragLeave );\n\t\t\t// The `dragstart` event doesn't fire if the drag started outside\n\t\t\t// the document.\n\t\t\townerDocument.addEventListener( 'dragenter', maybeDragStart );\n\n\t\t\treturn () => {\n\t\t\t\tdelete element.dataset.isDropZone;\n\t\t\t\telement.removeEventListener( 'drop', onDrop );\n\t\t\t\telement.removeEventListener( 'dragenter', onDragEnter );\n\t\t\t\telement.removeEventListener( 'dragover', onDragOver );\n\t\t\t\telement.removeEventListener( 'dragleave', onDragLeave );\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'dragenter',\n\t\t\t\t\tmaybeDragStart\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t\t[ isDisabled, dropZoneElement ] // Refresh when the passed in dropZoneElement changes.\n\t);\n}\n"]}
|