1 this["wp"] = this["wp"] || {}; this["wp"]["compose"] = |
1 /******/ (function() { // webpackBootstrap |
2 /******/ (function(modules) { // webpackBootstrap |
2 /******/ var __webpack_modules__ = ({ |
|
3 |
|
4 /***/ 8294: |
|
5 /***/ (function(module) { |
|
6 |
|
7 /*! |
|
8 * clipboard.js v2.0.10 |
|
9 * https://clipboardjs.com/ |
|
10 * |
|
11 * Licensed MIT © Zeno Rocha |
|
12 */ |
|
13 (function webpackUniversalModuleDefinition(root, factory) { |
|
14 if(true) |
|
15 module.exports = factory(); |
|
16 else {} |
|
17 })(this, function() { |
|
18 return /******/ (function() { // webpackBootstrap |
|
19 /******/ var __webpack_modules__ = ({ |
|
20 |
|
21 /***/ 686: |
|
22 /***/ (function(__unused_webpack_module, __webpack_exports__, __nested_webpack_require_623__) { |
|
23 |
|
24 "use strict"; |
|
25 |
|
26 // EXPORTS |
|
27 __nested_webpack_require_623__.d(__webpack_exports__, { |
|
28 "default": function() { return /* binding */ clipboard; } |
|
29 }); |
|
30 |
|
31 // EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js |
|
32 var tiny_emitter = __nested_webpack_require_623__(279); |
|
33 var tiny_emitter_default = /*#__PURE__*/__nested_webpack_require_623__.n(tiny_emitter); |
|
34 // EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js |
|
35 var listen = __nested_webpack_require_623__(370); |
|
36 var listen_default = /*#__PURE__*/__nested_webpack_require_623__.n(listen); |
|
37 // EXTERNAL MODULE: ./node_modules/select/src/select.js |
|
38 var src_select = __nested_webpack_require_623__(817); |
|
39 var select_default = /*#__PURE__*/__nested_webpack_require_623__.n(src_select); |
|
40 ;// CONCATENATED MODULE: ./src/common/command.js |
|
41 /** |
|
42 * Executes a given operation type. |
|
43 * @param {String} type |
|
44 * @return {Boolean} |
|
45 */ |
|
46 function command(type) { |
|
47 try { |
|
48 return document.execCommand(type); |
|
49 } catch (err) { |
|
50 return false; |
|
51 } |
|
52 } |
|
53 ;// CONCATENATED MODULE: ./src/actions/cut.js |
|
54 |
|
55 |
|
56 /** |
|
57 * Cut action wrapper. |
|
58 * @param {String|HTMLElement} target |
|
59 * @return {String} |
|
60 */ |
|
61 |
|
62 var ClipboardActionCut = function ClipboardActionCut(target) { |
|
63 var selectedText = select_default()(target); |
|
64 command('cut'); |
|
65 return selectedText; |
|
66 }; |
|
67 |
|
68 /* harmony default export */ var actions_cut = (ClipboardActionCut); |
|
69 ;// CONCATENATED MODULE: ./src/common/create-fake-element.js |
|
70 /** |
|
71 * Creates a fake textarea element with a value. |
|
72 * @param {String} value |
|
73 * @return {HTMLElement} |
|
74 */ |
|
75 function createFakeElement(value) { |
|
76 var isRTL = document.documentElement.getAttribute('dir') === 'rtl'; |
|
77 var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS |
|
78 |
|
79 fakeElement.style.fontSize = '12pt'; // Reset box model |
|
80 |
|
81 fakeElement.style.border = '0'; |
|
82 fakeElement.style.padding = '0'; |
|
83 fakeElement.style.margin = '0'; // Move element out of screen horizontally |
|
84 |
|
85 fakeElement.style.position = 'absolute'; |
|
86 fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically |
|
87 |
|
88 var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
|
89 fakeElement.style.top = "".concat(yPosition, "px"); |
|
90 fakeElement.setAttribute('readonly', ''); |
|
91 fakeElement.value = value; |
|
92 return fakeElement; |
|
93 } |
|
94 ;// CONCATENATED MODULE: ./src/actions/copy.js |
|
95 |
|
96 |
|
97 |
|
98 /** |
|
99 * Copy action wrapper. |
|
100 * @param {String|HTMLElement} target |
|
101 * @param {Object} options |
|
102 * @return {String} |
|
103 */ |
|
104 |
|
105 var ClipboardActionCopy = function ClipboardActionCopy(target) { |
|
106 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
|
107 container: document.body |
|
108 }; |
|
109 var selectedText = ''; |
|
110 |
|
111 if (typeof target === 'string') { |
|
112 var fakeElement = createFakeElement(target); |
|
113 options.container.appendChild(fakeElement); |
|
114 selectedText = select_default()(fakeElement); |
|
115 command('copy'); |
|
116 fakeElement.remove(); |
|
117 } else { |
|
118 selectedText = select_default()(target); |
|
119 command('copy'); |
|
120 } |
|
121 |
|
122 return selectedText; |
|
123 }; |
|
124 |
|
125 /* harmony default export */ var actions_copy = (ClipboardActionCopy); |
|
126 ;// CONCATENATED MODULE: ./src/actions/default.js |
|
127 function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
128 |
|
129 |
|
130 |
|
131 /** |
|
132 * Inner function which performs selection from either `text` or `target` |
|
133 * properties and then executes copy or cut operations. |
|
134 * @param {Object} options |
|
135 */ |
|
136 |
|
137 var ClipboardActionDefault = function ClipboardActionDefault() { |
|
138 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
139 // Defines base properties passed from constructor. |
|
140 var _options$action = options.action, |
|
141 action = _options$action === void 0 ? 'copy' : _options$action, |
|
142 container = options.container, |
|
143 target = options.target, |
|
144 text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'. |
|
145 |
|
146 if (action !== 'copy' && action !== 'cut') { |
|
147 throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
|
148 } // Sets the `target` property using an element that will be have its content copied. |
|
149 |
|
150 |
|
151 if (target !== undefined) { |
|
152 if (target && _typeof(target) === 'object' && target.nodeType === 1) { |
|
153 if (action === 'copy' && target.hasAttribute('disabled')) { |
|
154 throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
|
155 } |
|
156 |
|
157 if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
|
158 throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
|
159 } |
|
160 } else { |
|
161 throw new Error('Invalid "target" value, use a valid Element'); |
|
162 } |
|
163 } // Define selection strategy based on `text` property. |
|
164 |
|
165 |
|
166 if (text) { |
|
167 return actions_copy(text, { |
|
168 container: container |
|
169 }); |
|
170 } // Defines which selection strategy based on `target` property. |
|
171 |
|
172 |
|
173 if (target) { |
|
174 return action === 'cut' ? actions_cut(target) : actions_copy(target, { |
|
175 container: container |
|
176 }); |
|
177 } |
|
178 }; |
|
179 |
|
180 /* harmony default export */ var actions_default = (ClipboardActionDefault); |
|
181 ;// CONCATENATED MODULE: ./src/clipboard.js |
|
182 function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); } |
|
183 |
|
184 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
185 |
|
186 function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } |
|
187 |
|
188 function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
|
189 |
|
190 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } |
|
191 |
|
192 function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } |
|
193 |
|
194 function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } |
|
195 |
|
196 function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } |
|
197 |
|
198 function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } |
|
199 |
|
200 function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } |
|
201 |
|
202 function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 /** |
|
210 * Helper function to retrieve attribute value. |
|
211 * @param {String} suffix |
|
212 * @param {Element} element |
|
213 */ |
|
214 |
|
215 function getAttributeValue(suffix, element) { |
|
216 var attribute = "data-clipboard-".concat(suffix); |
|
217 |
|
218 if (!element.hasAttribute(attribute)) { |
|
219 return; |
|
220 } |
|
221 |
|
222 return element.getAttribute(attribute); |
|
223 } |
|
224 /** |
|
225 * Base class which takes one or more elements, adds event listeners to them, |
|
226 * and instantiates a new `ClipboardAction` on each click. |
|
227 */ |
|
228 |
|
229 |
|
230 var Clipboard = /*#__PURE__*/function (_Emitter) { |
|
231 _inherits(Clipboard, _Emitter); |
|
232 |
|
233 var _super = _createSuper(Clipboard); |
|
234 |
|
235 /** |
|
236 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
|
237 * @param {Object} options |
|
238 */ |
|
239 function Clipboard(trigger, options) { |
|
240 var _this; |
|
241 |
|
242 _classCallCheck(this, Clipboard); |
|
243 |
|
244 _this = _super.call(this); |
|
245 |
|
246 _this.resolveOptions(options); |
|
247 |
|
248 _this.listenClick(trigger); |
|
249 |
|
250 return _this; |
|
251 } |
|
252 /** |
|
253 * Defines if attributes would be resolved using internal setter functions |
|
254 * or custom functions that were passed in the constructor. |
|
255 * @param {Object} options |
|
256 */ |
|
257 |
|
258 |
|
259 _createClass(Clipboard, [{ |
|
260 key: "resolveOptions", |
|
261 value: function resolveOptions() { |
|
262 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
263 this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
|
264 this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
|
265 this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
|
266 this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body; |
|
267 } |
|
268 /** |
|
269 * Adds a click event listener to the passed trigger. |
|
270 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
|
271 */ |
|
272 |
|
273 }, { |
|
274 key: "listenClick", |
|
275 value: function listenClick(trigger) { |
|
276 var _this2 = this; |
|
277 |
|
278 this.listener = listen_default()(trigger, 'click', function (e) { |
|
279 return _this2.onClick(e); |
|
280 }); |
|
281 } |
|
282 /** |
|
283 * Defines a new `ClipboardAction` on each click event. |
|
284 * @param {Event} e |
|
285 */ |
|
286 |
|
287 }, { |
|
288 key: "onClick", |
|
289 value: function onClick(e) { |
|
290 var trigger = e.delegateTarget || e.currentTarget; |
|
291 var action = this.action(trigger) || 'copy'; |
|
292 var text = actions_default({ |
|
293 action: action, |
|
294 container: this.container, |
|
295 target: this.target(trigger), |
|
296 text: this.text(trigger) |
|
297 }); // Fires an event based on the copy operation result. |
|
298 |
|
299 this.emit(text ? 'success' : 'error', { |
|
300 action: action, |
|
301 text: text, |
|
302 trigger: trigger, |
|
303 clearSelection: function clearSelection() { |
|
304 if (trigger) { |
|
305 trigger.focus(); |
|
306 } |
|
307 |
|
308 document.activeElement.blur(); |
|
309 window.getSelection().removeAllRanges(); |
|
310 } |
|
311 }); |
|
312 } |
|
313 /** |
|
314 * Default `action` lookup function. |
|
315 * @param {Element} trigger |
|
316 */ |
|
317 |
|
318 }, { |
|
319 key: "defaultAction", |
|
320 value: function defaultAction(trigger) { |
|
321 return getAttributeValue('action', trigger); |
|
322 } |
|
323 /** |
|
324 * Default `target` lookup function. |
|
325 * @param {Element} trigger |
|
326 */ |
|
327 |
|
328 }, { |
|
329 key: "defaultTarget", |
|
330 value: function defaultTarget(trigger) { |
|
331 var selector = getAttributeValue('target', trigger); |
|
332 |
|
333 if (selector) { |
|
334 return document.querySelector(selector); |
|
335 } |
|
336 } |
|
337 /** |
|
338 * Allow fire programmatically a copy action |
|
339 * @param {String|HTMLElement} target |
|
340 * @param {Object} options |
|
341 * @returns Text copied. |
|
342 */ |
|
343 |
|
344 }, { |
|
345 key: "defaultText", |
|
346 |
|
347 /** |
|
348 * Default `text` lookup function. |
|
349 * @param {Element} trigger |
|
350 */ |
|
351 value: function defaultText(trigger) { |
|
352 return getAttributeValue('text', trigger); |
|
353 } |
|
354 /** |
|
355 * Destroy lifecycle. |
|
356 */ |
|
357 |
|
358 }, { |
|
359 key: "destroy", |
|
360 value: function destroy() { |
|
361 this.listener.destroy(); |
|
362 } |
|
363 }], [{ |
|
364 key: "copy", |
|
365 value: function copy(target) { |
|
366 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
|
367 container: document.body |
|
368 }; |
|
369 return actions_copy(target, options); |
|
370 } |
|
371 /** |
|
372 * Allow fire programmatically a cut action |
|
373 * @param {String|HTMLElement} target |
|
374 * @returns Text cutted. |
|
375 */ |
|
376 |
|
377 }, { |
|
378 key: "cut", |
|
379 value: function cut(target) { |
|
380 return actions_cut(target); |
|
381 } |
|
382 /** |
|
383 * Returns the support of the given action, or all actions if no action is |
|
384 * given. |
|
385 * @param {String} [action] |
|
386 */ |
|
387 |
|
388 }, { |
|
389 key: "isSupported", |
|
390 value: function isSupported() { |
|
391 var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
|
392 var actions = typeof action === 'string' ? [action] : action; |
|
393 var support = !!document.queryCommandSupported; |
|
394 actions.forEach(function (action) { |
|
395 support = support && !!document.queryCommandSupported(action); |
|
396 }); |
|
397 return support; |
|
398 } |
|
399 }]); |
|
400 |
|
401 return Clipboard; |
|
402 }((tiny_emitter_default())); |
|
403 |
|
404 /* harmony default export */ var clipboard = (Clipboard); |
|
405 |
|
406 /***/ }), |
|
407 |
|
408 /***/ 828: |
|
409 /***/ (function(module) { |
|
410 |
|
411 var DOCUMENT_NODE_TYPE = 9; |
|
412 |
|
413 /** |
|
414 * A polyfill for Element.matches() |
|
415 */ |
|
416 if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
|
417 var proto = Element.prototype; |
|
418 |
|
419 proto.matches = proto.matchesSelector || |
|
420 proto.mozMatchesSelector || |
|
421 proto.msMatchesSelector || |
|
422 proto.oMatchesSelector || |
|
423 proto.webkitMatchesSelector; |
|
424 } |
|
425 |
|
426 /** |
|
427 * Finds the closest parent that matches a selector. |
|
428 * |
|
429 * @param {Element} element |
|
430 * @param {String} selector |
|
431 * @return {Function} |
|
432 */ |
|
433 function closest (element, selector) { |
|
434 while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
|
435 if (typeof element.matches === 'function' && |
|
436 element.matches(selector)) { |
|
437 return element; |
|
438 } |
|
439 element = element.parentNode; |
|
440 } |
|
441 } |
|
442 |
|
443 module.exports = closest; |
|
444 |
|
445 |
|
446 /***/ }), |
|
447 |
|
448 /***/ 438: |
|
449 /***/ (function(module, __unused_webpack_exports, __nested_webpack_require_15133__) { |
|
450 |
|
451 var closest = __nested_webpack_require_15133__(828); |
|
452 |
|
453 /** |
|
454 * Delegates event to a selector. |
|
455 * |
|
456 * @param {Element} element |
|
457 * @param {String} selector |
|
458 * @param {String} type |
|
459 * @param {Function} callback |
|
460 * @param {Boolean} useCapture |
|
461 * @return {Object} |
|
462 */ |
|
463 function _delegate(element, selector, type, callback, useCapture) { |
|
464 var listenerFn = listener.apply(this, arguments); |
|
465 |
|
466 element.addEventListener(type, listenerFn, useCapture); |
|
467 |
|
468 return { |
|
469 destroy: function() { |
|
470 element.removeEventListener(type, listenerFn, useCapture); |
|
471 } |
|
472 } |
|
473 } |
|
474 |
|
475 /** |
|
476 * Delegates event to a selector. |
|
477 * |
|
478 * @param {Element|String|Array} [elements] |
|
479 * @param {String} selector |
|
480 * @param {String} type |
|
481 * @param {Function} callback |
|
482 * @param {Boolean} useCapture |
|
483 * @return {Object} |
|
484 */ |
|
485 function delegate(elements, selector, type, callback, useCapture) { |
|
486 // Handle the regular Element usage |
|
487 if (typeof elements.addEventListener === 'function') { |
|
488 return _delegate.apply(null, arguments); |
|
489 } |
|
490 |
|
491 // Handle Element-less usage, it defaults to global delegation |
|
492 if (typeof type === 'function') { |
|
493 // Use `document` as the first parameter, then apply arguments |
|
494 // This is a short way to .unshift `arguments` without running into deoptimizations |
|
495 return _delegate.bind(null, document).apply(null, arguments); |
|
496 } |
|
497 |
|
498 // Handle Selector-based usage |
|
499 if (typeof elements === 'string') { |
|
500 elements = document.querySelectorAll(elements); |
|
501 } |
|
502 |
|
503 // Handle Array-like based usage |
|
504 return Array.prototype.map.call(elements, function (element) { |
|
505 return _delegate(element, selector, type, callback, useCapture); |
|
506 }); |
|
507 } |
|
508 |
|
509 /** |
|
510 * Finds closest match and invokes callback. |
|
511 * |
|
512 * @param {Element} element |
|
513 * @param {String} selector |
|
514 * @param {String} type |
|
515 * @param {Function} callback |
|
516 * @return {Function} |
|
517 */ |
|
518 function listener(element, selector, type, callback) { |
|
519 return function(e) { |
|
520 e.delegateTarget = closest(e.target, selector); |
|
521 |
|
522 if (e.delegateTarget) { |
|
523 callback.call(element, e); |
|
524 } |
|
525 } |
|
526 } |
|
527 |
|
528 module.exports = delegate; |
|
529 |
|
530 |
|
531 /***/ }), |
|
532 |
|
533 /***/ 879: |
|
534 /***/ (function(__unused_webpack_module, exports) { |
|
535 |
|
536 /** |
|
537 * Check if argument is a HTML element. |
|
538 * |
|
539 * @param {Object} value |
|
540 * @return {Boolean} |
|
541 */ |
|
542 exports.node = function(value) { |
|
543 return value !== undefined |
|
544 && value instanceof HTMLElement |
|
545 && value.nodeType === 1; |
|
546 }; |
|
547 |
|
548 /** |
|
549 * Check if argument is a list of HTML elements. |
|
550 * |
|
551 * @param {Object} value |
|
552 * @return {Boolean} |
|
553 */ |
|
554 exports.nodeList = function(value) { |
|
555 var type = Object.prototype.toString.call(value); |
|
556 |
|
557 return value !== undefined |
|
558 && (type === '[object NodeList]' || type === '[object HTMLCollection]') |
|
559 && ('length' in value) |
|
560 && (value.length === 0 || exports.node(value[0])); |
|
561 }; |
|
562 |
|
563 /** |
|
564 * Check if argument is a string. |
|
565 * |
|
566 * @param {Object} value |
|
567 * @return {Boolean} |
|
568 */ |
|
569 exports.string = function(value) { |
|
570 return typeof value === 'string' |
|
571 || value instanceof String; |
|
572 }; |
|
573 |
|
574 /** |
|
575 * Check if argument is a function. |
|
576 * |
|
577 * @param {Object} value |
|
578 * @return {Boolean} |
|
579 */ |
|
580 exports.fn = function(value) { |
|
581 var type = Object.prototype.toString.call(value); |
|
582 |
|
583 return type === '[object Function]'; |
|
584 }; |
|
585 |
|
586 |
|
587 /***/ }), |
|
588 |
|
589 /***/ 370: |
|
590 /***/ (function(module, __unused_webpack_exports, __nested_webpack_require_18497__) { |
|
591 |
|
592 var is = __nested_webpack_require_18497__(879); |
|
593 var delegate = __nested_webpack_require_18497__(438); |
|
594 |
|
595 /** |
|
596 * Validates all params and calls the right |
|
597 * listener function based on its target type. |
|
598 * |
|
599 * @param {String|HTMLElement|HTMLCollection|NodeList} target |
|
600 * @param {String} type |
|
601 * @param {Function} callback |
|
602 * @return {Object} |
|
603 */ |
|
604 function listen(target, type, callback) { |
|
605 if (!target && !type && !callback) { |
|
606 throw new Error('Missing required arguments'); |
|
607 } |
|
608 |
|
609 if (!is.string(type)) { |
|
610 throw new TypeError('Second argument must be a String'); |
|
611 } |
|
612 |
|
613 if (!is.fn(callback)) { |
|
614 throw new TypeError('Third argument must be a Function'); |
|
615 } |
|
616 |
|
617 if (is.node(target)) { |
|
618 return listenNode(target, type, callback); |
|
619 } |
|
620 else if (is.nodeList(target)) { |
|
621 return listenNodeList(target, type, callback); |
|
622 } |
|
623 else if (is.string(target)) { |
|
624 return listenSelector(target, type, callback); |
|
625 } |
|
626 else { |
|
627 throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
|
628 } |
|
629 } |
|
630 |
|
631 /** |
|
632 * Adds an event listener to a HTML element |
|
633 * and returns a remove listener function. |
|
634 * |
|
635 * @param {HTMLElement} node |
|
636 * @param {String} type |
|
637 * @param {Function} callback |
|
638 * @return {Object} |
|
639 */ |
|
640 function listenNode(node, type, callback) { |
|
641 node.addEventListener(type, callback); |
|
642 |
|
643 return { |
|
644 destroy: function() { |
|
645 node.removeEventListener(type, callback); |
|
646 } |
|
647 } |
|
648 } |
|
649 |
|
650 /** |
|
651 * Add an event listener to a list of HTML elements |
|
652 * and returns a remove listener function. |
|
653 * |
|
654 * @param {NodeList|HTMLCollection} nodeList |
|
655 * @param {String} type |
|
656 * @param {Function} callback |
|
657 * @return {Object} |
|
658 */ |
|
659 function listenNodeList(nodeList, type, callback) { |
|
660 Array.prototype.forEach.call(nodeList, function(node) { |
|
661 node.addEventListener(type, callback); |
|
662 }); |
|
663 |
|
664 return { |
|
665 destroy: function() { |
|
666 Array.prototype.forEach.call(nodeList, function(node) { |
|
667 node.removeEventListener(type, callback); |
|
668 }); |
|
669 } |
|
670 } |
|
671 } |
|
672 |
|
673 /** |
|
674 * Add an event listener to a selector |
|
675 * and returns a remove listener function. |
|
676 * |
|
677 * @param {String} selector |
|
678 * @param {String} type |
|
679 * @param {Function} callback |
|
680 * @return {Object} |
|
681 */ |
|
682 function listenSelector(selector, type, callback) { |
|
683 return delegate(document.body, selector, type, callback); |
|
684 } |
|
685 |
|
686 module.exports = listen; |
|
687 |
|
688 |
|
689 /***/ }), |
|
690 |
|
691 /***/ 817: |
|
692 /***/ (function(module) { |
|
693 |
|
694 function select(element) { |
|
695 var selectedText; |
|
696 |
|
697 if (element.nodeName === 'SELECT') { |
|
698 element.focus(); |
|
699 |
|
700 selectedText = element.value; |
|
701 } |
|
702 else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
|
703 var isReadOnly = element.hasAttribute('readonly'); |
|
704 |
|
705 if (!isReadOnly) { |
|
706 element.setAttribute('readonly', ''); |
|
707 } |
|
708 |
|
709 element.select(); |
|
710 element.setSelectionRange(0, element.value.length); |
|
711 |
|
712 if (!isReadOnly) { |
|
713 element.removeAttribute('readonly'); |
|
714 } |
|
715 |
|
716 selectedText = element.value; |
|
717 } |
|
718 else { |
|
719 if (element.hasAttribute('contenteditable')) { |
|
720 element.focus(); |
|
721 } |
|
722 |
|
723 var selection = window.getSelection(); |
|
724 var range = document.createRange(); |
|
725 |
|
726 range.selectNodeContents(element); |
|
727 selection.removeAllRanges(); |
|
728 selection.addRange(range); |
|
729 |
|
730 selectedText = selection.toString(); |
|
731 } |
|
732 |
|
733 return selectedText; |
|
734 } |
|
735 |
|
736 module.exports = select; |
|
737 |
|
738 |
|
739 /***/ }), |
|
740 |
|
741 /***/ 279: |
|
742 /***/ (function(module) { |
|
743 |
|
744 function E () { |
|
745 // Keep this empty so it's easier to inherit from |
|
746 // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
|
747 } |
|
748 |
|
749 E.prototype = { |
|
750 on: function (name, callback, ctx) { |
|
751 var e = this.e || (this.e = {}); |
|
752 |
|
753 (e[name] || (e[name] = [])).push({ |
|
754 fn: callback, |
|
755 ctx: ctx |
|
756 }); |
|
757 |
|
758 return this; |
|
759 }, |
|
760 |
|
761 once: function (name, callback, ctx) { |
|
762 var self = this; |
|
763 function listener () { |
|
764 self.off(name, listener); |
|
765 callback.apply(ctx, arguments); |
|
766 }; |
|
767 |
|
768 listener._ = callback |
|
769 return this.on(name, listener, ctx); |
|
770 }, |
|
771 |
|
772 emit: function (name) { |
|
773 var data = [].slice.call(arguments, 1); |
|
774 var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
|
775 var i = 0; |
|
776 var len = evtArr.length; |
|
777 |
|
778 for (i; i < len; i++) { |
|
779 evtArr[i].fn.apply(evtArr[i].ctx, data); |
|
780 } |
|
781 |
|
782 return this; |
|
783 }, |
|
784 |
|
785 off: function (name, callback) { |
|
786 var e = this.e || (this.e = {}); |
|
787 var evts = e[name]; |
|
788 var liveEvents = []; |
|
789 |
|
790 if (evts && callback) { |
|
791 for (var i = 0, len = evts.length; i < len; i++) { |
|
792 if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
|
793 liveEvents.push(evts[i]); |
|
794 } |
|
795 } |
|
796 |
|
797 // Remove event from queue to prevent memory leak |
|
798 // Suggested by https://github.com/lazd |
|
799 // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
|
800 |
|
801 (liveEvents.length) |
|
802 ? e[name] = liveEvents |
|
803 : delete e[name]; |
|
804 |
|
805 return this; |
|
806 } |
|
807 }; |
|
808 |
|
809 module.exports = E; |
|
810 module.exports.TinyEmitter = E; |
|
811 |
|
812 |
|
813 /***/ }) |
|
814 |
|
815 /******/ }); |
|
816 /************************************************************************/ |
3 /******/ // The module cache |
817 /******/ // The module cache |
4 /******/ var installedModules = {}; |
818 /******/ var __webpack_module_cache__ = {}; |
5 /******/ |
819 /******/ |
6 /******/ // The require function |
820 /******/ // The require function |
7 /******/ function __webpack_require__(moduleId) { |
821 /******/ function __nested_webpack_require_23879__(moduleId) { |
8 /******/ |
|
9 /******/ // Check if module is in cache |
822 /******/ // Check if module is in cache |
10 /******/ if(installedModules[moduleId]) { |
823 /******/ if(__webpack_module_cache__[moduleId]) { |
11 /******/ return installedModules[moduleId].exports; |
824 /******/ return __webpack_module_cache__[moduleId].exports; |
12 /******/ } |
825 /******/ } |
13 /******/ // Create a new module (and put it into the cache) |
826 /******/ // Create a new module (and put it into the cache) |
14 /******/ var module = installedModules[moduleId] = { |
827 /******/ var module = __webpack_module_cache__[moduleId] = { |
15 /******/ i: moduleId, |
828 /******/ // no module.id needed |
16 /******/ l: false, |
829 /******/ // no module.loaded needed |
17 /******/ exports: {} |
830 /******/ exports: {} |
18 /******/ }; |
831 /******/ }; |
19 /******/ |
832 /******/ |
20 /******/ // Execute the module function |
833 /******/ // Execute the module function |
21 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
834 /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_23879__); |
22 /******/ |
835 /******/ |
23 /******/ // Flag the module as loaded |
|
24 /******/ module.l = true; |
|
25 /******/ |
|
26 /******/ // Return the exports of the module |
836 /******/ // Return the exports of the module |
27 /******/ return module.exports; |
837 /******/ return module.exports; |
28 /******/ } |
838 /******/ } |
29 /******/ |
839 /******/ |
30 /******/ |
840 /************************************************************************/ |
31 /******/ // expose the modules object (__webpack_modules__) |
841 /******/ /* webpack/runtime/compat get default export */ |
32 /******/ __webpack_require__.m = modules; |
842 /******/ !function() { |
33 /******/ |
843 /******/ // getDefaultExport function for compatibility with non-harmony modules |
34 /******/ // expose the module cache |
844 /******/ __nested_webpack_require_23879__.n = function(module) { |
35 /******/ __webpack_require__.c = installedModules; |
845 /******/ var getter = module && module.__esModule ? |
36 /******/ |
846 /******/ function() { return module['default']; } : |
37 /******/ // define getter function for harmony exports |
847 /******/ function() { return module; }; |
38 /******/ __webpack_require__.d = function(exports, name, getter) { |
848 /******/ __nested_webpack_require_23879__.d(getter, { a: getter }); |
39 /******/ if(!__webpack_require__.o(exports, name)) { |
849 /******/ return getter; |
40 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); |
850 /******/ }; |
41 /******/ } |
851 /******/ }(); |
42 /******/ }; |
852 /******/ |
43 /******/ |
853 /******/ /* webpack/runtime/define property getters */ |
44 /******/ // define __esModule on exports |
854 /******/ !function() { |
45 /******/ __webpack_require__.r = function(exports) { |
855 /******/ // define getter functions for harmony exports |
46 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
856 /******/ __nested_webpack_require_23879__.d = function(exports, definition) { |
47 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
857 /******/ for(var key in definition) { |
48 /******/ } |
858 /******/ if(__nested_webpack_require_23879__.o(definition, key) && !__nested_webpack_require_23879__.o(exports, key)) { |
49 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
859 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
50 /******/ }; |
860 /******/ } |
51 /******/ |
861 /******/ } |
52 /******/ // create a fake namespace object |
862 /******/ }; |
53 /******/ // mode & 1: value is a module id, require it |
863 /******/ }(); |
54 /******/ // mode & 2: merge all properties of value into the ns |
864 /******/ |
55 /******/ // mode & 4: return value when already ns object |
865 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
56 /******/ // mode & 8|1: behave like require |
866 /******/ !function() { |
57 /******/ __webpack_require__.t = function(value, mode) { |
867 /******/ __nested_webpack_require_23879__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
58 /******/ if(mode & 1) value = __webpack_require__(value); |
868 /******/ }(); |
59 /******/ if(mode & 8) return value; |
869 /******/ |
60 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; |
870 /************************************************************************/ |
61 /******/ var ns = Object.create(null); |
871 /******/ // module exports must be returned from runtime so entry inlining is disabled |
62 /******/ __webpack_require__.r(ns); |
872 /******/ // startup |
63 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); |
|
64 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); |
|
65 /******/ return ns; |
|
66 /******/ }; |
|
67 /******/ |
|
68 /******/ // getDefaultExport function for compatibility with non-harmony modules |
|
69 /******/ __webpack_require__.n = function(module) { |
|
70 /******/ var getter = module && module.__esModule ? |
|
71 /******/ function getDefault() { return module['default']; } : |
|
72 /******/ function getModuleExports() { return module; }; |
|
73 /******/ __webpack_require__.d(getter, 'a', getter); |
|
74 /******/ return getter; |
|
75 /******/ }; |
|
76 /******/ |
|
77 /******/ // Object.prototype.hasOwnProperty.call |
|
78 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
|
79 /******/ |
|
80 /******/ // __webpack_public_path__ |
|
81 /******/ __webpack_require__.p = ""; |
|
82 /******/ |
|
83 /******/ |
|
84 /******/ // Load entry module and return exports |
873 /******/ // Load entry module and return exports |
85 /******/ return __webpack_require__(__webpack_require__.s = "PD33"); |
874 /******/ return __nested_webpack_require_23879__(686); |
86 /******/ }) |
875 /******/ })() |
87 /************************************************************************/ |
876 .default; |
88 /******/ ({ |
877 }); |
89 |
|
90 /***/ "1CF3": |
|
91 /***/ (function(module, exports) { |
|
92 |
|
93 (function() { module.exports = window["wp"]["dom"]; }()); |
|
94 |
878 |
95 /***/ }), |
879 /***/ }), |
96 |
880 |
97 /***/ "GRId": |
881 /***/ 7973: |
98 /***/ (function(module, exports) { |
|
99 |
|
100 (function() { module.exports = window["wp"]["element"]; }()); |
|
101 |
|
102 /***/ }), |
|
103 |
|
104 /***/ "NMb1": |
|
105 /***/ (function(module, exports) { |
|
106 |
|
107 (function() { module.exports = window["wp"]["deprecated"]; }()); |
|
108 |
|
109 /***/ }), |
|
110 |
|
111 /***/ "PD33": |
|
112 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
113 |
|
114 "use strict"; |
|
115 // ESM COMPAT FLAG |
|
116 __webpack_require__.r(__webpack_exports__); |
|
117 |
|
118 // EXPORTS |
|
119 __webpack_require__.d(__webpack_exports__, "createHigherOrderComponent", function() { return /* reexport */ create_higher_order_component; }); |
|
120 __webpack_require__.d(__webpack_exports__, "compose", function() { return /* reexport */ compose; }); |
|
121 __webpack_require__.d(__webpack_exports__, "ifCondition", function() { return /* reexport */ if_condition; }); |
|
122 __webpack_require__.d(__webpack_exports__, "pure", function() { return /* reexport */ higher_order_pure; }); |
|
123 __webpack_require__.d(__webpack_exports__, "withGlobalEvents", function() { return /* reexport */ withGlobalEvents; }); |
|
124 __webpack_require__.d(__webpack_exports__, "withInstanceId", function() { return /* reexport */ with_instance_id; }); |
|
125 __webpack_require__.d(__webpack_exports__, "withSafeTimeout", function() { return /* reexport */ with_safe_timeout; }); |
|
126 __webpack_require__.d(__webpack_exports__, "withState", function() { return /* reexport */ withState; }); |
|
127 __webpack_require__.d(__webpack_exports__, "useConstrainedTabbing", function() { return /* reexport */ use_constrained_tabbing; }); |
|
128 __webpack_require__.d(__webpack_exports__, "useCopyOnClick", function() { return /* reexport */ useCopyOnClick; }); |
|
129 __webpack_require__.d(__webpack_exports__, "useCopyToClipboard", function() { return /* reexport */ useCopyToClipboard; }); |
|
130 __webpack_require__.d(__webpack_exports__, "__experimentalUseDialog", function() { return /* reexport */ use_dialog; }); |
|
131 __webpack_require__.d(__webpack_exports__, "__experimentalUseDragging", function() { return /* reexport */ useDragging; }); |
|
132 __webpack_require__.d(__webpack_exports__, "useFocusOnMount", function() { return /* reexport */ useFocusOnMount; }); |
|
133 __webpack_require__.d(__webpack_exports__, "__experimentalUseFocusOutside", function() { return /* reexport */ useFocusOutside; }); |
|
134 __webpack_require__.d(__webpack_exports__, "useFocusReturn", function() { return /* reexport */ use_focus_return; }); |
|
135 __webpack_require__.d(__webpack_exports__, "useInstanceId", function() { return /* reexport */ useInstanceId; }); |
|
136 __webpack_require__.d(__webpack_exports__, "useIsomorphicLayoutEffect", function() { return /* reexport */ use_isomorphic_layout_effect; }); |
|
137 __webpack_require__.d(__webpack_exports__, "useKeyboardShortcut", function() { return /* reexport */ use_keyboard_shortcut; }); |
|
138 __webpack_require__.d(__webpack_exports__, "useMediaQuery", function() { return /* reexport */ useMediaQuery; }); |
|
139 __webpack_require__.d(__webpack_exports__, "usePrevious", function() { return /* reexport */ usePrevious; }); |
|
140 __webpack_require__.d(__webpack_exports__, "useReducedMotion", function() { return /* reexport */ use_reduced_motion; }); |
|
141 __webpack_require__.d(__webpack_exports__, "useViewportMatch", function() { return /* reexport */ use_viewport_match; }); |
|
142 __webpack_require__.d(__webpack_exports__, "useResizeObserver", function() { return /* reexport */ use_resize_observer; }); |
|
143 __webpack_require__.d(__webpack_exports__, "useAsyncList", function() { return /* reexport */ use_async_list; }); |
|
144 __webpack_require__.d(__webpack_exports__, "useWarnOnChange", function() { return /* reexport */ use_warn_on_change; }); |
|
145 __webpack_require__.d(__webpack_exports__, "useDebounce", function() { return /* reexport */ useDebounce; }); |
|
146 __webpack_require__.d(__webpack_exports__, "useThrottle", function() { return /* reexport */ useThrottle; }); |
|
147 __webpack_require__.d(__webpack_exports__, "useMergeRefs", function() { return /* reexport */ useMergeRefs; }); |
|
148 __webpack_require__.d(__webpack_exports__, "useRefEffect", function() { return /* reexport */ useRefEffect; }); |
|
149 __webpack_require__.d(__webpack_exports__, "__experimentalUseDropZone", function() { return /* reexport */ useDropZone; }); |
|
150 |
|
151 // EXTERNAL MODULE: external "lodash" |
|
152 var external_lodash_ = __webpack_require__("YLtl"); |
|
153 |
|
154 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/create-higher-order-component/index.js |
|
155 /** |
|
156 * External dependencies |
|
157 */ |
|
158 // eslint-disable-next-line no-restricted-imports |
|
159 |
|
160 /** |
|
161 * Given a function mapping a component to an enhanced component and modifier |
|
162 * name, returns the enhanced component augmented with a generated displayName. |
|
163 * |
|
164 * @param mapComponentToEnhancedComponent Function mapping component to enhanced component. |
|
165 * @param modifierName Seed name from which to generated display name. |
|
166 * |
|
167 * @return Component class with generated display name assigned. |
|
168 */ |
|
169 function createHigherOrderComponent(mapComponent, modifierName) { |
|
170 return Inner => { |
|
171 const Outer = mapComponent(Inner); |
|
172 const displayName = Inner.displayName || Inner.name || 'Component'; |
|
173 Outer.displayName = `${Object(external_lodash_["upperFirst"])(Object(external_lodash_["camelCase"])(modifierName))}(${displayName})`; |
|
174 return Outer; |
|
175 }; |
|
176 } |
|
177 |
|
178 /* harmony default export */ var create_higher_order_component = (createHigherOrderComponent); |
|
179 |
|
180 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/compose.js |
|
181 /** |
|
182 * External dependencies |
|
183 */ |
|
184 |
|
185 /** |
|
186 * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function |
|
187 * composition, where each successive invocation is supplied the return value of the previous. |
|
188 * |
|
189 * @param {...Function} hocs The HOC functions to invoke. |
|
190 * |
|
191 * @return {Function} Returns the new composite function. |
|
192 */ |
|
193 |
|
194 /* harmony default export */ var compose = (external_lodash_["flowRight"]); |
|
195 |
|
196 // EXTERNAL MODULE: external ["wp","element"] |
|
197 var external_wp_element_ = __webpack_require__("GRId"); |
|
198 |
|
199 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/if-condition/index.js |
|
200 |
|
201 |
|
202 /** |
|
203 * Internal dependencies |
|
204 */ |
|
205 // eslint-disable-next-line no-duplicate-imports |
|
206 |
|
207 /** |
|
208 * Higher-order component creator, creating a new component which renders if |
|
209 * the given condition is satisfied or with the given optional prop name. |
|
210 * |
|
211 * @example |
|
212 * ```ts |
|
213 * type Props = { foo: string }; |
|
214 * const Component = ( props: Props ) => <div>{ props.foo }</div>; |
|
215 * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component ); |
|
216 * <ConditionalComponent foo="" />; // => null |
|
217 * <ConditionalComponent foo="bar" />; // => <div>bar</div>; |
|
218 * ``` |
|
219 * |
|
220 * @param predicate Function to test condition. |
|
221 * |
|
222 * @return Higher-order component. |
|
223 */ |
|
224 const ifCondition = predicate => create_higher_order_component(WrappedComponent => props => { |
|
225 if (!predicate(props)) { |
|
226 return null; |
|
227 } |
|
228 |
|
229 return Object(external_wp_element_["createElement"])(WrappedComponent, props); |
|
230 }, 'ifCondition'); |
|
231 |
|
232 /* harmony default export */ var if_condition = (ifCondition); |
|
233 |
|
234 // EXTERNAL MODULE: external ["wp","isShallowEqual"] |
|
235 var external_wp_isShallowEqual_ = __webpack_require__("rl8x"); |
|
236 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_); |
|
237 |
|
238 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/pure/index.js |
|
239 |
|
240 |
|
241 /** |
|
242 * WordPress dependencies |
|
243 */ |
|
244 |
|
245 |
|
246 /** |
|
247 * Internal dependencies |
|
248 */ |
|
249 |
|
250 // eslint-disable-next-line no-duplicate-imports |
|
251 |
|
252 /** |
|
253 * Given a component returns the enhanced component augmented with a component |
|
254 * only rerendering when its props/state change |
|
255 */ |
|
256 const pure = create_higher_order_component(Wrapped => { |
|
257 if (Wrapped.prototype instanceof external_wp_element_["Component"]) { |
|
258 return class extends Wrapped { |
|
259 shouldComponentUpdate(nextProps, nextState) { |
|
260 return !external_wp_isShallowEqual_default()(nextProps, this.props) || !external_wp_isShallowEqual_default()(nextState, this.state); |
|
261 } |
|
262 |
|
263 }; |
|
264 } |
|
265 |
|
266 return class extends external_wp_element_["Component"] { |
|
267 shouldComponentUpdate(nextProps) { |
|
268 return !external_wp_isShallowEqual_default()(nextProps, this.props); |
|
269 } |
|
270 |
|
271 render() { |
|
272 return Object(external_wp_element_["createElement"])(Wrapped, this.props); |
|
273 } |
|
274 |
|
275 }; |
|
276 }, 'pure'); |
|
277 /* harmony default export */ var higher_order_pure = (pure); |
|
278 |
|
279 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js |
|
280 var esm_extends = __webpack_require__("wx14"); |
|
281 |
|
282 // EXTERNAL MODULE: external ["wp","deprecated"] |
|
283 var external_wp_deprecated_ = __webpack_require__("NMb1"); |
|
284 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_); |
|
285 |
|
286 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/listener.js |
|
287 /** |
|
288 * External dependencies |
|
289 */ |
|
290 |
|
291 /** |
|
292 * Class responsible for orchestrating event handling on the global window, |
|
293 * binding a single event to be shared across all handling instances, and |
|
294 * removing the handler when no instances are listening for the event. |
|
295 */ |
|
296 |
|
297 class listener_Listener { |
|
298 constructor() { |
|
299 this.listeners = {}; |
|
300 this.handleEvent = this.handleEvent.bind(this); |
|
301 } |
|
302 |
|
303 add(eventType, instance) { |
|
304 if (!this.listeners[eventType]) { |
|
305 // Adding first listener for this type, so bind event. |
|
306 window.addEventListener(eventType, this.handleEvent); |
|
307 this.listeners[eventType] = []; |
|
308 } |
|
309 |
|
310 this.listeners[eventType].push(instance); |
|
311 } |
|
312 |
|
313 remove(eventType, instance) { |
|
314 this.listeners[eventType] = Object(external_lodash_["without"])(this.listeners[eventType], instance); |
|
315 |
|
316 if (!this.listeners[eventType].length) { |
|
317 // Removing last listener for this type, so unbind event. |
|
318 window.removeEventListener(eventType, this.handleEvent); |
|
319 delete this.listeners[eventType]; |
|
320 } |
|
321 } |
|
322 |
|
323 handleEvent(event) { |
|
324 Object(external_lodash_["forEach"])(this.listeners[event.type], instance => { |
|
325 instance.handleEvent(event); |
|
326 }); |
|
327 } |
|
328 |
|
329 } |
|
330 |
|
331 /* harmony default export */ var listener = (listener_Listener); |
|
332 |
|
333 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/index.js |
|
334 |
|
335 |
|
336 |
|
337 /** |
|
338 * External dependencies |
|
339 */ |
|
340 |
|
341 /** |
|
342 * WordPress dependencies |
|
343 */ |
|
344 |
|
345 |
|
346 |
|
347 /** |
|
348 * Internal dependencies |
|
349 */ |
|
350 |
|
351 |
|
352 |
|
353 /** |
|
354 * Listener instance responsible for managing document event handling. |
|
355 * |
|
356 * @type {Listener} |
|
357 */ |
|
358 |
|
359 const with_global_events_listener = new listener(); |
|
360 /** |
|
361 * Higher-order component creator which, given an object of DOM event types and |
|
362 * values corresponding to a callback function name on the component, will |
|
363 * create or update a window event handler to invoke the callback when an event |
|
364 * occurs. On behalf of the consuming developer, the higher-order component |
|
365 * manages unbinding when the component unmounts, and binding at most a single |
|
366 * event handler for the entire application. |
|
367 * |
|
368 * @deprecated |
|
369 * |
|
370 * @param {Object<string,string>} eventTypesToHandlers Object with keys of DOM |
|
371 * event type, the value a |
|
372 * name of the function on |
|
373 * the original component's |
|
374 * instance which handles |
|
375 * the event. |
|
376 * |
|
377 * @return {Function} Higher-order component. |
|
378 */ |
|
379 |
|
380 function withGlobalEvents(eventTypesToHandlers) { |
|
381 external_wp_deprecated_default()('wp.compose.withGlobalEvents', { |
|
382 since: '5.7', |
|
383 alternative: 'useEffect' |
|
384 }); |
|
385 return create_higher_order_component(WrappedComponent => { |
|
386 class Wrapper extends external_wp_element_["Component"] { |
|
387 constructor() { |
|
388 super(...arguments); |
|
389 this.handleEvent = this.handleEvent.bind(this); |
|
390 this.handleRef = this.handleRef.bind(this); |
|
391 } |
|
392 |
|
393 componentDidMount() { |
|
394 Object(external_lodash_["forEach"])(eventTypesToHandlers, (handler, eventType) => { |
|
395 with_global_events_listener.add(eventType, this); |
|
396 }); |
|
397 } |
|
398 |
|
399 componentWillUnmount() { |
|
400 Object(external_lodash_["forEach"])(eventTypesToHandlers, (handler, eventType) => { |
|
401 with_global_events_listener.remove(eventType, this); |
|
402 }); |
|
403 } |
|
404 |
|
405 handleEvent(event) { |
|
406 const handler = eventTypesToHandlers[event.type]; |
|
407 |
|
408 if (typeof this.wrappedRef[handler] === 'function') { |
|
409 this.wrappedRef[handler](event); |
|
410 } |
|
411 } |
|
412 |
|
413 handleRef(el) { |
|
414 this.wrappedRef = el; // Any component using `withGlobalEvents` that is not setting a `ref` |
|
415 // will cause `this.props.forwardedRef` to be `null`, so we need this |
|
416 // check. |
|
417 |
|
418 if (this.props.forwardedRef) { |
|
419 this.props.forwardedRef(el); |
|
420 } |
|
421 } |
|
422 |
|
423 render() { |
|
424 return Object(external_wp_element_["createElement"])(WrappedComponent, Object(esm_extends["a" /* default */])({}, this.props.ownProps, { |
|
425 ref: this.handleRef |
|
426 })); |
|
427 } |
|
428 |
|
429 } |
|
430 |
|
431 return Object(external_wp_element_["forwardRef"])((props, ref) => { |
|
432 return Object(external_wp_element_["createElement"])(Wrapper, { |
|
433 ownProps: props, |
|
434 forwardedRef: ref |
|
435 }); |
|
436 }); |
|
437 }, 'withGlobalEvents'); |
|
438 } |
|
439 |
|
440 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-instance-id/index.js |
|
441 // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case |
|
442 // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript |
|
443 |
|
444 /* eslint-disable jsdoc/check-types */ |
|
445 |
|
446 /** |
|
447 * WordPress dependencies |
|
448 */ |
|
449 |
|
450 /** |
|
451 * @type {WeakMap<object, number>} |
|
452 */ |
|
453 |
|
454 const instanceMap = new WeakMap(); |
|
455 /** |
|
456 * Creates a new id for a given object. |
|
457 * |
|
458 * @param {object} object Object reference to create an id for. |
|
459 * @return {number} The instance id (index). |
|
460 */ |
|
461 |
|
462 function createId(object) { |
|
463 const instances = instanceMap.get(object) || 0; |
|
464 instanceMap.set(object, instances + 1); |
|
465 return instances; |
|
466 } |
|
467 /** |
|
468 * Provides a unique instance ID. |
|
469 * |
|
470 * @param {object} object Object reference to create an id for. |
|
471 * @param {string} [prefix] Prefix for the unique id. |
|
472 * @param {string} [preferredId=''] Default ID to use. |
|
473 * @return {string | number} The unique instance id. |
|
474 */ |
|
475 |
|
476 |
|
477 function useInstanceId(object, prefix, preferredId = '') { |
|
478 return Object(external_wp_element_["useMemo"])(() => { |
|
479 if (preferredId) return preferredId; |
|
480 const id = createId(object); |
|
481 return prefix ? `${prefix}-${id}` : id; |
|
482 }, [object]); |
|
483 } |
|
484 /* eslint-enable jsdoc/check-types */ |
|
485 |
|
486 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-instance-id/index.js |
|
487 |
|
488 |
|
489 |
|
490 /** |
|
491 * External dependencies |
|
492 */ |
|
493 // eslint-disable-next-line no-restricted-imports |
|
494 |
|
495 /** |
|
496 * Internal dependencies |
|
497 */ |
|
498 // eslint-disable-next-line no-duplicate-imports |
|
499 |
|
500 |
|
501 /** |
|
502 * A Higher Order Component used to be provide a unique instance ID by |
|
503 * component. |
|
504 */ |
|
505 |
|
506 const withInstanceId = create_higher_order_component(WrappedComponent => { |
|
507 return props => { |
|
508 const instanceId = useInstanceId(WrappedComponent); |
|
509 return Object(external_wp_element_["createElement"])(WrappedComponent, Object(esm_extends["a" /* default */])({}, props, { |
|
510 instanceId: instanceId |
|
511 })); |
|
512 }; |
|
513 }, 'withInstanceId'); |
|
514 /* harmony default export */ var with_instance_id = (withInstanceId); |
|
515 |
|
516 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-safe-timeout/index.js |
|
517 |
|
518 |
|
519 |
|
520 /** |
|
521 * External dependencies |
|
522 */ |
|
523 |
|
524 /** |
|
525 * WordPress dependencies |
|
526 */ |
|
527 |
|
528 |
|
529 /** |
|
530 * Internal dependencies |
|
531 */ |
|
532 |
|
533 |
|
534 /** |
|
535 * A higher-order component used to provide and manage delayed function calls |
|
536 * that ought to be bound to a component's lifecycle. |
|
537 * |
|
538 * @param {WPComponent} OriginalComponent Component requiring setTimeout |
|
539 * |
|
540 * @return {WPComponent} Wrapped component. |
|
541 */ |
|
542 |
|
543 const withSafeTimeout = create_higher_order_component(OriginalComponent => { |
|
544 return class WrappedComponent extends external_wp_element_["Component"] { |
|
545 constructor() { |
|
546 super(...arguments); |
|
547 this.timeouts = []; |
|
548 this.setTimeout = this.setTimeout.bind(this); |
|
549 this.clearTimeout = this.clearTimeout.bind(this); |
|
550 } |
|
551 |
|
552 componentWillUnmount() { |
|
553 this.timeouts.forEach(clearTimeout); |
|
554 } |
|
555 |
|
556 setTimeout(fn, delay) { |
|
557 const id = setTimeout(() => { |
|
558 fn(); |
|
559 this.clearTimeout(id); |
|
560 }, delay); |
|
561 this.timeouts.push(id); |
|
562 return id; |
|
563 } |
|
564 |
|
565 clearTimeout(id) { |
|
566 clearTimeout(id); |
|
567 this.timeouts = Object(external_lodash_["without"])(this.timeouts, id); |
|
568 } |
|
569 |
|
570 render() { |
|
571 return Object(external_wp_element_["createElement"])(OriginalComponent, Object(esm_extends["a" /* default */])({}, this.props, { |
|
572 setTimeout: this.setTimeout, |
|
573 clearTimeout: this.clearTimeout |
|
574 })); |
|
575 } |
|
576 |
|
577 }; |
|
578 }, 'withSafeTimeout'); |
|
579 /* harmony default export */ var with_safe_timeout = (withSafeTimeout); |
|
580 |
|
581 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-state/index.js |
|
582 |
|
583 |
|
584 |
|
585 /** |
|
586 * WordPress dependencies |
|
587 */ |
|
588 |
|
589 /** |
|
590 * Internal dependencies |
|
591 */ |
|
592 |
|
593 |
|
594 /** |
|
595 * A Higher Order Component used to provide and manage internal component state |
|
596 * via props. |
|
597 * |
|
598 * @param {?Object} initialState Optional initial state of the component. |
|
599 * |
|
600 * @return {WPComponent} Wrapped component. |
|
601 */ |
|
602 |
|
603 function withState(initialState = {}) { |
|
604 return create_higher_order_component(OriginalComponent => { |
|
605 return class WrappedComponent extends external_wp_element_["Component"] { |
|
606 constructor() { |
|
607 super(...arguments); |
|
608 this.setState = this.setState.bind(this); |
|
609 this.state = initialState; |
|
610 } |
|
611 |
|
612 render() { |
|
613 return Object(external_wp_element_["createElement"])(OriginalComponent, Object(esm_extends["a" /* default */])({}, this.props, this.state, { |
|
614 setState: this.setState |
|
615 })); |
|
616 } |
|
617 |
|
618 }; |
|
619 }, 'withState'); |
|
620 } |
|
621 |
|
622 // EXTERNAL MODULE: external ["wp","keycodes"] |
|
623 var external_wp_keycodes_ = __webpack_require__("RxS6"); |
|
624 |
|
625 // EXTERNAL MODULE: external ["wp","dom"] |
|
626 var external_wp_dom_ = __webpack_require__("1CF3"); |
|
627 |
|
628 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-constrained-tabbing/index.js |
|
629 /** |
|
630 * WordPress dependencies |
|
631 */ |
|
632 |
|
633 |
|
634 |
|
635 /** |
|
636 * In Dialogs/modals, the tabbing must be constrained to the content of |
|
637 * the wrapper element. This hook adds the behavior to the returned ref. |
|
638 * |
|
639 * @return {Object|Function} Element Ref. |
|
640 * |
|
641 * @example |
|
642 * ```js |
|
643 * import { useConstrainedTabbing } from '@wordpress/compose'; |
|
644 * |
|
645 * const ConstrainedTabbingExample = () => { |
|
646 * const constrainedTabbingRef = useConstrainedTabbing() |
|
647 * return ( |
|
648 * <div ref={ constrainedTabbingRef }> |
|
649 * <Button /> |
|
650 * <Button /> |
|
651 * </div> |
|
652 * ); |
|
653 * } |
|
654 * ``` |
|
655 */ |
|
656 |
|
657 function useConstrainedTabbing() { |
|
658 const ref = Object(external_wp_element_["useCallback"])( |
|
659 /** @type {Element} */ |
|
660 node => { |
|
661 if (!node) { |
|
662 return; |
|
663 } |
|
664 |
|
665 node.addEventListener('keydown', |
|
666 /** @type {Event} */ |
|
667 event => { |
|
668 if (!(event instanceof window.KeyboardEvent)) { |
|
669 return; |
|
670 } |
|
671 |
|
672 if (event.keyCode !== external_wp_keycodes_["TAB"]) { |
|
673 return; |
|
674 } |
|
675 |
|
676 const tabbables = external_wp_dom_["focus"].tabbable.find(node); |
|
677 |
|
678 if (!tabbables.length) { |
|
679 return; |
|
680 } |
|
681 |
|
682 const firstTabbable = tabbables[0]; |
|
683 const lastTabbable = tabbables[tabbables.length - 1]; |
|
684 |
|
685 if (event.shiftKey && event.target === firstTabbable) { |
|
686 event.preventDefault(); |
|
687 /** @type {HTMLElement} */ |
|
688 |
|
689 lastTabbable.focus(); |
|
690 } else if (!event.shiftKey && event.target === lastTabbable) { |
|
691 event.preventDefault(); |
|
692 /** @type {HTMLElement} */ |
|
693 |
|
694 firstTabbable.focus(); |
|
695 /* |
|
696 * When pressing Tab and none of the tabbables has focus, the keydown |
|
697 * event happens on the wrapper div: move focus on the first tabbable. |
|
698 */ |
|
699 } else if (!tabbables.includes( |
|
700 /** @type {Element} */ |
|
701 event.target)) { |
|
702 event.preventDefault(); |
|
703 /** @type {HTMLElement} */ |
|
704 |
|
705 firstTabbable.focus(); |
|
706 } |
|
707 }); |
|
708 }, []); |
|
709 return ref; |
|
710 } |
|
711 |
|
712 /* harmony default export */ var use_constrained_tabbing = (useConstrainedTabbing); |
|
713 |
|
714 // EXTERNAL MODULE: ./node_modules/clipboard/dist/clipboard.js |
|
715 var dist_clipboard = __webpack_require__("sxGJ"); |
|
716 var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard); |
|
717 |
|
718 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-on-click/index.js |
|
719 /** |
|
720 * External dependencies |
|
721 */ |
|
722 |
|
723 /** |
|
724 * WordPress dependencies |
|
725 */ |
|
726 |
|
727 |
|
728 |
|
729 /** |
|
730 * Copies the text to the clipboard when the element is clicked. |
|
731 * |
|
732 * @deprecated |
|
733 * |
|
734 * @param {Object} ref Reference with the element. |
|
735 * @param {string|Function} text The text to copy. |
|
736 * @param {number} timeout Optional timeout to reset the returned |
|
737 * state. 4 seconds by default. |
|
738 * |
|
739 * @return {boolean} Whether or not the text has been copied. Resets after the |
|
740 * timeout. |
|
741 */ |
|
742 |
|
743 function useCopyOnClick(ref, text, timeout = 4000) { |
|
744 external_wp_deprecated_default()('wp.compose.useCopyOnClick', { |
|
745 since: '10.3', |
|
746 plugin: 'Gutenberg', |
|
747 alternative: 'wp.compose.useCopyToClipboard' |
|
748 }); |
|
749 const clipboard = Object(external_wp_element_["useRef"])(); |
|
750 const [hasCopied, setHasCopied] = Object(external_wp_element_["useState"])(false); |
|
751 Object(external_wp_element_["useEffect"])(() => { |
|
752 let timeoutId; // Clipboard listens to click events. |
|
753 |
|
754 clipboard.current = new clipboard_default.a(ref.current, { |
|
755 text: () => typeof text === 'function' ? text() : text |
|
756 }); |
|
757 clipboard.current.on('success', ({ |
|
758 clearSelection, |
|
759 trigger |
|
760 }) => { |
|
761 // Clearing selection will move focus back to the triggering button, |
|
762 // ensuring that it is not reset to the body, and further that it is |
|
763 // kept within the rendered node. |
|
764 clearSelection(); // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680 |
|
765 |
|
766 if (trigger) { |
|
767 trigger.focus(); |
|
768 } |
|
769 |
|
770 if (timeout) { |
|
771 setHasCopied(true); |
|
772 clearTimeout(timeoutId); |
|
773 timeoutId = setTimeout(() => setHasCopied(false), timeout); |
|
774 } |
|
775 }); |
|
776 return () => { |
|
777 clipboard.current.destroy(); |
|
778 clearTimeout(timeoutId); |
|
779 }; |
|
780 }, [text, timeout, setHasCopied]); |
|
781 return hasCopied; |
|
782 } |
|
783 |
|
784 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-ref-effect/index.js |
|
785 /** |
|
786 * WordPress dependencies |
|
787 */ |
|
788 |
|
789 /** |
|
790 * Effect-like ref callback. Just like with `useEffect`, this allows you to |
|
791 * return a cleanup function to be run if the ref changes or one of the |
|
792 * dependencies changes. The ref is provided as an argument to the callback |
|
793 * functions. The main difference between this and `useEffect` is that |
|
794 * the `useEffect` callback is not called when the ref changes, but this is. |
|
795 * Pass the returned ref callback as the component's ref and merge multiple refs |
|
796 * with `useMergeRefs`. |
|
797 * |
|
798 * It's worth noting that if the dependencies array is empty, there's not |
|
799 * strictly a need to clean up event handlers for example, because the node is |
|
800 * to be removed. It *is* necessary if you add dependencies because the ref |
|
801 * callback will be called multiple times for the same node. |
|
802 * |
|
803 * @param {Function} callback Callback with ref as argument. |
|
804 * @param {Array} dependencies Dependencies of the callback. |
|
805 * |
|
806 * @return {Function} Ref callback. |
|
807 */ |
|
808 |
|
809 function useRefEffect(callback, dependencies) { |
|
810 const cleanup = Object(external_wp_element_["useRef"])(); |
|
811 return Object(external_wp_element_["useCallback"])(node => { |
|
812 if (node) { |
|
813 cleanup.current = callback(node); |
|
814 } else if (cleanup.current) { |
|
815 cleanup.current(); |
|
816 } |
|
817 }, dependencies); |
|
818 } |
|
819 |
|
820 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-to-clipboard/index.js |
|
821 /** |
|
822 * External dependencies |
|
823 */ |
|
824 |
|
825 /** |
|
826 * WordPress dependencies |
|
827 */ |
|
828 |
|
829 |
|
830 /** |
|
831 * Internal dependencies |
|
832 */ |
|
833 |
|
834 |
|
835 /** @typedef {import('@wordpress/element').RefObject} RefObject */ |
|
836 |
|
837 function useUpdatedRef(value) { |
|
838 const ref = Object(external_wp_element_["useRef"])(value); |
|
839 ref.current = value; |
|
840 return ref; |
|
841 } |
|
842 /** |
|
843 * Copies the given text to the clipboard when the element is clicked. |
|
844 * |
|
845 * @param {text|Function} text The text to copy. Use a function if not |
|
846 * already available and expensive to compute. |
|
847 * @param {Function} onSuccess Called when to text is copied. |
|
848 * |
|
849 * @return {RefObject} A ref to assign to the target element. |
|
850 */ |
|
851 |
|
852 |
|
853 function useCopyToClipboard(text, onSuccess) { |
|
854 // Store the dependencies as refs and continuesly update them so they're |
|
855 // fresh when the callback is called. |
|
856 const textRef = useUpdatedRef(text); |
|
857 const onSuccesRef = useUpdatedRef(onSuccess); |
|
858 return useRefEffect(node => { |
|
859 // Clipboard listens to click events. |
|
860 const clipboard = new clipboard_default.a(node, { |
|
861 text() { |
|
862 return typeof textRef.current === 'function' ? textRef.current() : textRef.current; |
|
863 } |
|
864 |
|
865 }); |
|
866 clipboard.on('success', ({ |
|
867 clearSelection |
|
868 }) => { |
|
869 // Clearing selection will move focus back to the triggering |
|
870 // button, ensuring that it is not reset to the body, and |
|
871 // further that it is kept within the rendered node. |
|
872 clearSelection(); // Handle ClipboardJS focus bug, see |
|
873 // https://github.com/zenorocha/clipboard.js/issues/680 |
|
874 |
|
875 node.focus(); |
|
876 |
|
877 if (onSuccesRef.current) { |
|
878 onSuccesRef.current(); |
|
879 } |
|
880 }); |
|
881 return () => { |
|
882 clipboard.destroy(); |
|
883 }; |
|
884 }, []); |
|
885 } |
|
886 |
|
887 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-on-mount/index.js |
|
888 /** |
|
889 * WordPress dependencies |
|
890 */ |
|
891 |
|
892 |
|
893 /** |
|
894 * Hook used to focus the first tabbable element on mount. |
|
895 * |
|
896 * @param {boolean|string} focusOnMount Focus on mount mode. |
|
897 * @return {Function} Ref callback. |
|
898 * |
|
899 * @example |
|
900 * ```js |
|
901 * import { useFocusOnMount } from '@wordpress/compose'; |
|
902 * |
|
903 * const WithFocusOnMount = () => { |
|
904 * const ref = useFocusOnMount() |
|
905 * return ( |
|
906 * <div ref={ ref }> |
|
907 * <Button /> |
|
908 * <Button /> |
|
909 * </div> |
|
910 * ); |
|
911 * } |
|
912 * ``` |
|
913 */ |
|
914 |
|
915 function useFocusOnMount(focusOnMount = 'firstElement') { |
|
916 const focusOnMountRef = Object(external_wp_element_["useRef"])(focusOnMount); |
|
917 Object(external_wp_element_["useEffect"])(() => { |
|
918 focusOnMountRef.current = focusOnMount; |
|
919 }, [focusOnMount]); |
|
920 return Object(external_wp_element_["useCallback"])(node => { |
|
921 if (!node || focusOnMountRef.current === false) { |
|
922 return; |
|
923 } |
|
924 |
|
925 if (node.contains(node.ownerDocument.activeElement)) { |
|
926 return; |
|
927 } |
|
928 |
|
929 let target = node; |
|
930 |
|
931 if (focusOnMountRef.current === 'firstElement') { |
|
932 const firstTabbable = external_wp_dom_["focus"].tabbable.find(node)[0]; |
|
933 |
|
934 if (firstTabbable) { |
|
935 target = firstTabbable; |
|
936 } |
|
937 } |
|
938 |
|
939 target.focus(); |
|
940 }, []); |
|
941 } |
|
942 |
|
943 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-return/index.js |
|
944 /** |
|
945 * WordPress dependencies |
|
946 */ |
|
947 |
|
948 /** |
|
949 * When opening modals/sidebars/dialogs, the focus |
|
950 * must move to the opened area and return to the |
|
951 * previously focused element when closed. |
|
952 * The current hook implements the returning behavior. |
|
953 * |
|
954 * @param {Function?} onFocusReturn Overrides the default return behavior. |
|
955 * @return {Function} Element Ref. |
|
956 * |
|
957 * @example |
|
958 * ```js |
|
959 * import { useFocusReturn } from '@wordpress/compose'; |
|
960 * |
|
961 * const WithFocusReturn = () => { |
|
962 * const ref = useFocusReturn() |
|
963 * return ( |
|
964 * <div ref={ ref }> |
|
965 * <Button /> |
|
966 * <Button /> |
|
967 * </div> |
|
968 * ); |
|
969 * } |
|
970 * ``` |
|
971 */ |
|
972 |
|
973 function useFocusReturn(onFocusReturn) { |
|
974 const ref = Object(external_wp_element_["useRef"])(); |
|
975 const focusedBeforeMount = Object(external_wp_element_["useRef"])(); |
|
976 const onFocusReturnRef = Object(external_wp_element_["useRef"])(onFocusReturn); |
|
977 Object(external_wp_element_["useEffect"])(() => { |
|
978 onFocusReturnRef.current = onFocusReturn; |
|
979 }, [onFocusReturn]); |
|
980 return Object(external_wp_element_["useCallback"])(node => { |
|
981 if (node) { |
|
982 // Set ref to be used when unmounting. |
|
983 ref.current = node; // Only set when the node mounts. |
|
984 |
|
985 if (focusedBeforeMount.current) { |
|
986 return; |
|
987 } |
|
988 |
|
989 focusedBeforeMount.current = node.ownerDocument.activeElement; |
|
990 } else if (focusedBeforeMount.current) { |
|
991 const isFocused = ref.current.contains(ref.current.ownerDocument.activeElement); |
|
992 |
|
993 if (ref.current.isConnected && !isFocused) { |
|
994 return; |
|
995 } // Defer to the component's own explicit focus return behavior, if |
|
996 // specified. This allows for support that the `onFocusReturn` |
|
997 // decides to allow the default behavior to occur under some |
|
998 // conditions. |
|
999 |
|
1000 |
|
1001 if (onFocusReturnRef.current) { |
|
1002 onFocusReturnRef.current(); |
|
1003 } else { |
|
1004 focusedBeforeMount.current.focus(); |
|
1005 } |
|
1006 } |
|
1007 }, []); |
|
1008 } |
|
1009 |
|
1010 /* harmony default export */ var use_focus_return = (useFocusReturn); |
|
1011 |
|
1012 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-outside/index.js |
|
1013 /** |
|
1014 * External dependencies |
|
1015 */ |
|
1016 |
|
1017 /** |
|
1018 * WordPress dependencies |
|
1019 */ |
|
1020 |
|
1021 |
|
1022 /** |
|
1023 * Input types which are classified as button types, for use in considering |
|
1024 * whether element is a (focus-normalized) button. |
|
1025 * |
|
1026 * @type {string[]} |
|
1027 */ |
|
1028 |
|
1029 const INPUT_BUTTON_TYPES = ['button', 'submit']; |
|
1030 /** |
|
1031 * @typedef {HTMLButtonElement | HTMLLinkElement | HTMLInputElement} FocusNormalizedButton |
|
1032 */ |
|
1033 // Disable reason: Rule doesn't support predicate return types |
|
1034 |
|
1035 /* eslint-disable jsdoc/valid-types */ |
|
1036 |
|
1037 /** |
|
1038 * Returns true if the given element is a button element subject to focus |
|
1039 * normalization, or false otherwise. |
|
1040 * |
|
1041 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus |
|
1042 * |
|
1043 * @param {EventTarget} eventTarget The target from a mouse or touch event. |
|
1044 * |
|
1045 * @return {eventTarget is FocusNormalizedButton} Whether element is a button. |
|
1046 */ |
|
1047 |
|
1048 function isFocusNormalizedButton(eventTarget) { |
|
1049 if (!(eventTarget instanceof window.HTMLElement)) { |
|
1050 return false; |
|
1051 } |
|
1052 |
|
1053 switch (eventTarget.nodeName) { |
|
1054 case 'A': |
|
1055 case 'BUTTON': |
|
1056 return true; |
|
1057 |
|
1058 case 'INPUT': |
|
1059 return Object(external_lodash_["includes"])(INPUT_BUTTON_TYPES, |
|
1060 /** @type {HTMLInputElement} */ |
|
1061 eventTarget.type); |
|
1062 } |
|
1063 |
|
1064 return false; |
|
1065 } |
|
1066 /* eslint-enable jsdoc/valid-types */ |
|
1067 |
|
1068 /** |
|
1069 * @typedef {import('react').SyntheticEvent} SyntheticEvent |
|
1070 */ |
|
1071 |
|
1072 /** |
|
1073 * @callback EventCallback |
|
1074 * @param {SyntheticEvent} event input related event. |
|
1075 */ |
|
1076 |
|
1077 /** |
|
1078 * @typedef FocusOutsideReactElement |
|
1079 * @property {EventCallback} handleFocusOutside callback for a focus outside event. |
|
1080 */ |
|
1081 |
|
1082 /** |
|
1083 * @typedef {import('react').MutableRefObject<FocusOutsideReactElement | undefined>} FocusOutsideRef |
|
1084 */ |
|
1085 |
|
1086 /** |
|
1087 * @typedef {Object} FocusOutsideReturnValue |
|
1088 * @property {EventCallback} onFocus An event handler for focus events. |
|
1089 * @property {EventCallback} onBlur An event handler for blur events. |
|
1090 * @property {EventCallback} onMouseDown An event handler for mouse down events. |
|
1091 * @property {EventCallback} onMouseUp An event handler for mouse up events. |
|
1092 * @property {EventCallback} onTouchStart An event handler for touch start events. |
|
1093 * @property {EventCallback} onTouchEnd An event handler for touch end events. |
|
1094 */ |
|
1095 |
|
1096 /** |
|
1097 * A react hook that can be used to check whether focus has moved outside the |
|
1098 * element the event handlers are bound to. |
|
1099 * |
|
1100 * @param {EventCallback} onFocusOutside A callback triggered when focus moves outside |
|
1101 * the element the event handlers are bound to. |
|
1102 * |
|
1103 * @return {FocusOutsideReturnValue} An object containing event handlers. Bind the event handlers |
|
1104 * to a wrapping element element to capture when focus moves |
|
1105 * outside that element. |
|
1106 */ |
|
1107 |
|
1108 |
|
1109 function useFocusOutside(onFocusOutside) { |
|
1110 const currentOnFocusOutside = Object(external_wp_element_["useRef"])(onFocusOutside); |
|
1111 Object(external_wp_element_["useEffect"])(() => { |
|
1112 currentOnFocusOutside.current = onFocusOutside; |
|
1113 }, [onFocusOutside]); |
|
1114 const preventBlurCheck = Object(external_wp_element_["useRef"])(false); |
|
1115 /** |
|
1116 * @type {import('react').MutableRefObject<number | undefined>} |
|
1117 */ |
|
1118 |
|
1119 const blurCheckTimeoutId = Object(external_wp_element_["useRef"])(); |
|
1120 /** |
|
1121 * Cancel a blur check timeout. |
|
1122 */ |
|
1123 |
|
1124 const cancelBlurCheck = Object(external_wp_element_["useCallback"])(() => { |
|
1125 clearTimeout(blurCheckTimeoutId.current); |
|
1126 }, []); // Cancel blur checks on unmount. |
|
1127 |
|
1128 Object(external_wp_element_["useEffect"])(() => { |
|
1129 return () => cancelBlurCheck(); |
|
1130 }, []); // Cancel a blur check if the callback or ref is no longer provided. |
|
1131 |
|
1132 Object(external_wp_element_["useEffect"])(() => { |
|
1133 if (!onFocusOutside) { |
|
1134 cancelBlurCheck(); |
|
1135 } |
|
1136 }, [onFocusOutside, cancelBlurCheck]); |
|
1137 /** |
|
1138 * Handles a mousedown or mouseup event to respectively assign and |
|
1139 * unassign a flag for preventing blur check on button elements. Some |
|
1140 * browsers, namely Firefox and Safari, do not emit a focus event on |
|
1141 * button elements when clicked, while others do. The logic here |
|
1142 * intends to normalize this as treating click on buttons as focus. |
|
1143 * |
|
1144 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus |
|
1145 * |
|
1146 * @param {SyntheticEvent} event Event for mousedown or mouseup. |
|
1147 */ |
|
1148 |
|
1149 const normalizeButtonFocus = Object(external_wp_element_["useCallback"])(event => { |
|
1150 const { |
|
1151 type, |
|
1152 target |
|
1153 } = event; |
|
1154 const isInteractionEnd = Object(external_lodash_["includes"])(['mouseup', 'touchend'], type); |
|
1155 |
|
1156 if (isInteractionEnd) { |
|
1157 preventBlurCheck.current = false; |
|
1158 } else if (isFocusNormalizedButton(target)) { |
|
1159 preventBlurCheck.current = true; |
|
1160 } |
|
1161 }, []); |
|
1162 /** |
|
1163 * A callback triggered when a blur event occurs on the element the handler |
|
1164 * is bound to. |
|
1165 * |
|
1166 * Calls the `onFocusOutside` callback in an immediate timeout if focus has |
|
1167 * move outside the bound element and is still within the document. |
|
1168 * |
|
1169 * @param {SyntheticEvent} event Blur event. |
|
1170 */ |
|
1171 |
|
1172 const queueBlurCheck = Object(external_wp_element_["useCallback"])(event => { |
|
1173 // React does not allow using an event reference asynchronously |
|
1174 // due to recycling behavior, except when explicitly persisted. |
|
1175 event.persist(); // Skip blur check if clicking button. See `normalizeButtonFocus`. |
|
1176 |
|
1177 if (preventBlurCheck.current) { |
|
1178 return; |
|
1179 } |
|
1180 |
|
1181 blurCheckTimeoutId.current = setTimeout(() => { |
|
1182 // If document is not focused then focus should remain |
|
1183 // inside the wrapped component and therefore we cancel |
|
1184 // this blur event thereby leaving focus in place. |
|
1185 // https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus. |
|
1186 if (!document.hasFocus()) { |
|
1187 event.preventDefault(); |
|
1188 return; |
|
1189 } |
|
1190 |
|
1191 if ('function' === typeof currentOnFocusOutside.current) { |
|
1192 currentOnFocusOutside.current(event); |
|
1193 } |
|
1194 }, 0); |
|
1195 }, []); |
|
1196 return { |
|
1197 onFocus: cancelBlurCheck, |
|
1198 onMouseDown: normalizeButtonFocus, |
|
1199 onMouseUp: normalizeButtonFocus, |
|
1200 onTouchStart: normalizeButtonFocus, |
|
1201 onTouchEnd: normalizeButtonFocus, |
|
1202 onBlur: queueBlurCheck |
|
1203 }; |
|
1204 } |
|
1205 |
|
1206 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-merge-refs/index.js |
|
1207 /** |
|
1208 * WordPress dependencies |
|
1209 */ |
|
1210 |
|
1211 /** @typedef {import('@wordpress/element').RefObject} RefObject */ |
|
1212 |
|
1213 /** @typedef {import('@wordpress/element').RefCallback} RefCallback */ |
|
1214 |
|
1215 function assignRef(ref, value) { |
|
1216 if (typeof ref === 'function') { |
|
1217 ref(value); |
|
1218 } else if (ref && ref.hasOwnProperty('current')) { |
|
1219 ref.current = value; |
|
1220 } |
|
1221 } |
|
1222 /** |
|
1223 * Merges refs into one ref callback. Ensures the merged ref callbacks are only |
|
1224 * called when it changes (as a result of a `useCallback` dependency update) or |
|
1225 * when the ref value changes. If you don't wish a ref callback to be called on |
|
1226 * every render, wrap it with `useCallback( ref, [] )`. |
|
1227 * Dependencies can be added, but when a dependency changes, the old ref |
|
1228 * callback will be called with `null` and the new ref callback will be called |
|
1229 * with the same node. |
|
1230 * |
|
1231 * @param {Array<RefObject|RefCallback>} refs The refs to be merged. |
|
1232 * |
|
1233 * @return {RefCallback} The merged ref callback. |
|
1234 */ |
|
1235 |
|
1236 |
|
1237 function useMergeRefs(refs) { |
|
1238 const element = Object(external_wp_element_["useRef"])(); |
|
1239 const didElementChange = Object(external_wp_element_["useRef"])(false); |
|
1240 const previousRefs = Object(external_wp_element_["useRef"])([]); |
|
1241 const currentRefs = Object(external_wp_element_["useRef"])(refs); // Update on render before the ref callback is called, so the ref callback |
|
1242 // always has access to the current refs. |
|
1243 |
|
1244 currentRefs.current = refs; // If any of the refs change, call the previous ref with `null` and the new |
|
1245 // ref with the node, except when the element changes in the same cycle, in |
|
1246 // which case the ref callbacks will already have been called. |
|
1247 |
|
1248 Object(external_wp_element_["useLayoutEffect"])(() => { |
|
1249 if (didElementChange.current === false) { |
|
1250 refs.forEach((ref, index) => { |
|
1251 const previousRef = previousRefs.current[index]; |
|
1252 |
|
1253 if (ref !== previousRef) { |
|
1254 assignRef(previousRef, null); |
|
1255 assignRef(ref, element.current); |
|
1256 } |
|
1257 }); |
|
1258 } |
|
1259 |
|
1260 previousRefs.current = refs; |
|
1261 }, refs); // No dependencies, must be reset after every render so ref callbacks are |
|
1262 // correctly called after a ref change. |
|
1263 |
|
1264 Object(external_wp_element_["useLayoutEffect"])(() => { |
|
1265 didElementChange.current = false; |
|
1266 }); // There should be no dependencies so that `callback` is only called when |
|
1267 // the node changes. |
|
1268 |
|
1269 return Object(external_wp_element_["useCallback"])(value => { |
|
1270 // Update the element so it can be used when calling ref callbacks on a |
|
1271 // dependency change. |
|
1272 assignRef(element, value); |
|
1273 didElementChange.current = true; // When an element changes, the current ref callback should be called |
|
1274 // with the new element and the previous one with `null`. |
|
1275 |
|
1276 const refsToAssign = value ? currentRefs.current : previousRefs.current; // Update the latest refs. |
|
1277 |
|
1278 for (const ref of refsToAssign) { |
|
1279 assignRef(ref, value); |
|
1280 } |
|
1281 }, []); |
|
1282 } |
|
1283 |
|
1284 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dialog/index.js |
|
1285 /** |
|
1286 * WordPress dependencies |
|
1287 */ |
|
1288 |
|
1289 |
|
1290 /** |
|
1291 * Internal dependencies |
|
1292 */ |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 /** |
|
1300 * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors: |
|
1301 * - constrained tabbing. |
|
1302 * - focus on mount. |
|
1303 * - return focus on unmount. |
|
1304 * - focus outside. |
|
1305 * |
|
1306 * @param {Object} options Dialog Options. |
|
1307 */ |
|
1308 |
|
1309 function useDialog(options) { |
|
1310 const onClose = Object(external_wp_element_["useRef"])(); |
|
1311 Object(external_wp_element_["useEffect"])(() => { |
|
1312 onClose.current = options.onClose; |
|
1313 }, [options.onClose]); |
|
1314 const constrainedTabbingRef = use_constrained_tabbing(); |
|
1315 const focusOnMountRef = useFocusOnMount(); |
|
1316 const focusReturnRef = use_focus_return(); |
|
1317 const focusOutsideProps = useFocusOutside(options.onClose); |
|
1318 const closeOnEscapeRef = Object(external_wp_element_["useCallback"])(node => { |
|
1319 if (!node) { |
|
1320 return; |
|
1321 } |
|
1322 |
|
1323 node.addEventListener('keydown', event => { |
|
1324 // Close on escape |
|
1325 if (event.keyCode === external_wp_keycodes_["ESCAPE"] && onClose.current) { |
|
1326 event.stopPropagation(); |
|
1327 onClose.current(); |
|
1328 } |
|
1329 }); |
|
1330 }, []); |
|
1331 return [useMergeRefs([constrainedTabbingRef, focusReturnRef, focusOnMountRef, closeOnEscapeRef]), { ...focusOutsideProps, |
|
1332 tabIndex: '-1' |
|
1333 }]; |
|
1334 } |
|
1335 |
|
1336 /* harmony default export */ var use_dialog = (useDialog); |
|
1337 |
|
1338 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-isomorphic-layout-effect/index.js |
|
1339 /** |
|
1340 * WordPress dependencies |
|
1341 */ |
|
1342 |
|
1343 /** |
|
1344 * Preferred over direct usage of `useLayoutEffect` when supporting |
|
1345 * server rendered components (SSR) because currently React |
|
1346 * throws a warning when using useLayoutEffect in that environment. |
|
1347 */ |
|
1348 |
|
1349 const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_["useLayoutEffect"] : external_wp_element_["useEffect"]; |
|
1350 /* harmony default export */ var use_isomorphic_layout_effect = (useIsomorphicLayoutEffect); |
|
1351 |
|
1352 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dragging/index.js |
|
1353 /** |
|
1354 * WordPress dependencies |
|
1355 */ |
|
1356 |
|
1357 /** |
|
1358 * Internal dependencies |
|
1359 */ |
|
1360 |
|
1361 |
|
1362 function useDragging({ |
|
1363 onDragStart, |
|
1364 onDragMove, |
|
1365 onDragEnd |
|
1366 }) { |
|
1367 const [isDragging, setIsDragging] = Object(external_wp_element_["useState"])(false); |
|
1368 const eventsRef = Object(external_wp_element_["useRef"])({ |
|
1369 onDragStart, |
|
1370 onDragMove, |
|
1371 onDragEnd |
|
1372 }); |
|
1373 use_isomorphic_layout_effect(() => { |
|
1374 eventsRef.current.onDragStart = onDragStart; |
|
1375 eventsRef.current.onDragMove = onDragMove; |
|
1376 eventsRef.current.onDragEnd = onDragEnd; |
|
1377 }, [onDragStart, onDragMove, onDragEnd]); |
|
1378 const onMouseMove = Object(external_wp_element_["useCallback"])((...args) => eventsRef.current.onDragMove && eventsRef.current.onDragMove(...args), []); |
|
1379 const endDrag = Object(external_wp_element_["useCallback"])((...args) => { |
|
1380 if (eventsRef.current.onDragEnd) { |
|
1381 eventsRef.current.onDragEnd(...args); |
|
1382 } |
|
1383 |
|
1384 document.removeEventListener('mousemove', onMouseMove); |
|
1385 document.removeEventListener('mouseup', endDrag); |
|
1386 setIsDragging(false); |
|
1387 }, []); |
|
1388 const startDrag = Object(external_wp_element_["useCallback"])((...args) => { |
|
1389 if (eventsRef.current.onDragStart) { |
|
1390 eventsRef.current.onDragStart(...args); |
|
1391 } |
|
1392 |
|
1393 document.addEventListener('mousemove', onMouseMove); |
|
1394 document.addEventListener('mouseup', endDrag); |
|
1395 setIsDragging(true); |
|
1396 }, []); // Remove the global events when unmounting if needed. |
|
1397 |
|
1398 Object(external_wp_element_["useEffect"])(() => { |
|
1399 return () => { |
|
1400 if (isDragging) { |
|
1401 document.removeEventListener('mousemove', onMouseMove); |
|
1402 document.removeEventListener('mouseup', endDrag); |
|
1403 } |
|
1404 }; |
|
1405 }, [isDragging]); |
|
1406 return { |
|
1407 startDrag, |
|
1408 endDrag, |
|
1409 isDragging |
|
1410 }; |
|
1411 } |
|
1412 |
|
1413 // EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js |
|
1414 var mousetrap_mousetrap = __webpack_require__("imBb"); |
|
1415 var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap); |
|
1416 |
|
1417 // EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js |
|
1418 var mousetrap_global_bind = __webpack_require__("VcSt"); |
|
1419 |
|
1420 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-keyboard-shortcut/index.js |
|
1421 /** |
|
1422 * External dependencies |
|
1423 */ |
|
1424 |
|
1425 |
|
1426 |
|
1427 /** |
|
1428 * WordPress dependencies |
|
1429 */ |
|
1430 |
|
1431 |
|
1432 /** |
|
1433 * A block selection object. |
|
1434 * |
|
1435 * @typedef {Object} WPKeyboardShortcutConfig |
|
1436 * |
|
1437 * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields. |
|
1438 * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown. |
|
1439 * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true. |
|
1440 * @property {Object} [target] React reference to the DOM element used to catch the keyboard event. |
|
1441 */ |
|
1442 |
|
1443 /** |
|
1444 * Return true if platform is MacOS. |
|
1445 * |
|
1446 * @param {Object} _window window object by default; used for DI testing. |
|
1447 * |
|
1448 * @return {boolean} True if MacOS; false otherwise. |
|
1449 */ |
|
1450 |
|
1451 function isAppleOS(_window = window) { |
|
1452 const { |
|
1453 platform |
|
1454 } = _window.navigator; |
|
1455 return platform.indexOf('Mac') !== -1 || Object(external_lodash_["includes"])(['iPad', 'iPhone'], platform); |
|
1456 } |
|
1457 /** |
|
1458 * Attach a keyboard shortcut handler. |
|
1459 * |
|
1460 * @param {string[]|string} shortcuts Keyboard Shortcuts. |
|
1461 * @param {Function} callback Shortcut callback. |
|
1462 * @param {WPKeyboardShortcutConfig} options Shortcut options. |
|
1463 */ |
|
1464 |
|
1465 |
|
1466 function useKeyboardShortcut(shortcuts, callback, { |
|
1467 bindGlobal = false, |
|
1468 eventName = 'keydown', |
|
1469 isDisabled = false, |
|
1470 // This is important for performance considerations. |
|
1471 target |
|
1472 } = {}) { |
|
1473 const currentCallback = Object(external_wp_element_["useRef"])(callback); |
|
1474 Object(external_wp_element_["useEffect"])(() => { |
|
1475 currentCallback.current = callback; |
|
1476 }, [callback]); |
|
1477 Object(external_wp_element_["useEffect"])(() => { |
|
1478 if (isDisabled) { |
|
1479 return; |
|
1480 } |
|
1481 |
|
1482 const mousetrap = new mousetrap_default.a(target ? target.current : document); |
|
1483 Object(external_lodash_["castArray"])(shortcuts).forEach(shortcut => { |
|
1484 const keys = shortcut.split('+'); // Determines whether a key is a modifier by the length of the string. |
|
1485 // E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that |
|
1486 // the modifiers are Shift and Cmd because they're not a single character. |
|
1487 |
|
1488 const modifiers = new Set(keys.filter(value => value.length > 1)); |
|
1489 const hasAlt = modifiers.has('alt'); |
|
1490 const hasShift = modifiers.has('shift'); // This should be better moved to the shortcut registration instead. |
|
1491 |
|
1492 if (isAppleOS() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) { |
|
1493 throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`); |
|
1494 } |
|
1495 |
|
1496 const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; |
|
1497 mousetrap[bindFn](shortcut, (...args) => currentCallback.current(...args), eventName); |
|
1498 }); |
|
1499 return () => { |
|
1500 mousetrap.reset(); |
|
1501 }; |
|
1502 }, [shortcuts, bindGlobal, eventName, target, isDisabled]); |
|
1503 } |
|
1504 |
|
1505 /* harmony default export */ var use_keyboard_shortcut = (useKeyboardShortcut); |
|
1506 |
|
1507 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-media-query/index.js |
|
1508 /** |
|
1509 * WordPress dependencies |
|
1510 */ |
|
1511 |
|
1512 /** |
|
1513 * Runs a media query and returns its value when it changes. |
|
1514 * |
|
1515 * @param {string} [query] Media Query. |
|
1516 * @return {boolean} return value of the media query. |
|
1517 */ |
|
1518 |
|
1519 function useMediaQuery(query) { |
|
1520 const [match, setMatch] = Object(external_wp_element_["useState"])(() => !!(query && typeof window !== 'undefined' && window.matchMedia(query).matches)); |
|
1521 Object(external_wp_element_["useEffect"])(() => { |
|
1522 if (!query) { |
|
1523 return; |
|
1524 } |
|
1525 |
|
1526 const updateMatch = () => setMatch(window.matchMedia(query).matches); |
|
1527 |
|
1528 updateMatch(); |
|
1529 const list = window.matchMedia(query); |
|
1530 list.addListener(updateMatch); |
|
1531 return () => { |
|
1532 list.removeListener(updateMatch); |
|
1533 }; |
|
1534 }, [query]); |
|
1535 return query && match; |
|
1536 } |
|
1537 |
|
1538 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-previous/index.js |
|
1539 /** |
|
1540 * WordPress dependencies |
|
1541 */ |
|
1542 |
|
1543 /** |
|
1544 * Use something's value from the previous render. |
|
1545 * Based on https://usehooks.com/usePrevious/. |
|
1546 * |
|
1547 * @template T |
|
1548 * |
|
1549 * @param {T} value The value to track. |
|
1550 * |
|
1551 * @return {T|undefined} The value from the previous render. |
|
1552 */ |
|
1553 |
|
1554 function usePrevious(value) { |
|
1555 // Disable reason: without an explicit type detail, the type of ref will be |
|
1556 // inferred based on the initial useRef argument, which is undefined. |
|
1557 // https://github.com/WordPress/gutenberg/pull/22597#issuecomment-633588366 |
|
1558 |
|
1559 /* eslint-disable jsdoc/no-undefined-types */ |
|
1560 const ref = Object(external_wp_element_["useRef"])( |
|
1561 /** @type {T|undefined} */ |
|
1562 undefined); |
|
1563 /* eslint-enable jsdoc/no-undefined-types */ |
|
1564 // Store current value in ref. |
|
1565 |
|
1566 Object(external_wp_element_["useEffect"])(() => { |
|
1567 ref.current = value; |
|
1568 }, [value]); // Re-run when value changes. |
|
1569 // Return previous value (happens before update in useEffect above). |
|
1570 |
|
1571 return ref.current; |
|
1572 } |
|
1573 |
|
1574 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-reduced-motion/index.js |
|
1575 /** |
|
1576 * Internal dependencies |
|
1577 */ |
|
1578 |
|
1579 /** |
|
1580 * Whether or not the user agent is Internet Explorer. |
|
1581 * |
|
1582 * @type {boolean} |
|
1583 */ |
|
1584 |
|
1585 const IS_IE = typeof window !== 'undefined' && window.navigator.userAgent.indexOf('Trident') >= 0; |
|
1586 /** |
|
1587 * Hook returning whether the user has a preference for reduced motion. |
|
1588 * |
|
1589 * @return {boolean} Reduced motion preference value. |
|
1590 */ |
|
1591 |
|
1592 const useReducedMotion = undefined || IS_IE ? () => true : () => useMediaQuery('(prefers-reduced-motion: reduce)'); |
|
1593 /* harmony default export */ var use_reduced_motion = (useReducedMotion); |
|
1594 |
|
1595 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-viewport-match/index.js |
|
1596 /** |
|
1597 * WordPress dependencies |
|
1598 */ |
|
1599 |
|
1600 /** |
|
1601 * Internal dependencies |
|
1602 */ |
|
1603 |
|
1604 |
|
1605 /** |
|
1606 * @typedef {"huge"|"wide"|"large"|"medium"|"small"|"mobile"} WPBreakpoint |
|
1607 */ |
|
1608 |
|
1609 /** |
|
1610 * Hash of breakpoint names with pixel width at which it becomes effective. |
|
1611 * |
|
1612 * @see _breakpoints.scss |
|
1613 * |
|
1614 * @type {Object<WPBreakpoint,number>} |
|
1615 */ |
|
1616 |
|
1617 const BREAKPOINTS = { |
|
1618 huge: 1440, |
|
1619 wide: 1280, |
|
1620 large: 960, |
|
1621 medium: 782, |
|
1622 small: 600, |
|
1623 mobile: 480 |
|
1624 }; |
|
1625 /** |
|
1626 * @typedef {">="|"<"} WPViewportOperator |
|
1627 */ |
|
1628 |
|
1629 /** |
|
1630 * Object mapping media query operators to the condition to be used. |
|
1631 * |
|
1632 * @type {Object<WPViewportOperator,string>} |
|
1633 */ |
|
1634 |
|
1635 const CONDITIONS = { |
|
1636 '>=': 'min-width', |
|
1637 '<': 'max-width' |
|
1638 }; |
|
1639 /** |
|
1640 * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values. |
|
1641 * |
|
1642 * @type {Object<WPViewportOperator,Function>} |
|
1643 */ |
|
1644 |
|
1645 const OPERATOR_EVALUATORS = { |
|
1646 '>=': (breakpointValue, width) => width >= breakpointValue, |
|
1647 '<': (breakpointValue, width) => width < breakpointValue |
|
1648 }; |
|
1649 const ViewportMatchWidthContext = Object(external_wp_element_["createContext"])(null); |
|
1650 /** |
|
1651 * Returns true if the viewport matches the given query, or false otherwise. |
|
1652 * |
|
1653 * @param {WPBreakpoint} breakpoint Breakpoint size name. |
|
1654 * @param {WPViewportOperator} [operator=">="] Viewport operator. |
|
1655 * |
|
1656 * @example |
|
1657 * |
|
1658 * ```js |
|
1659 * useViewportMatch( 'huge', '<' ); |
|
1660 * useViewportMatch( 'medium' ); |
|
1661 * ``` |
|
1662 * |
|
1663 * @return {boolean} Whether viewport matches query. |
|
1664 */ |
|
1665 |
|
1666 const useViewportMatch = (breakpoint, operator = '>=') => { |
|
1667 const simulatedWidth = Object(external_wp_element_["useContext"])(ViewportMatchWidthContext); |
|
1668 const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`; |
|
1669 const mediaQueryResult = useMediaQuery(mediaQuery); |
|
1670 |
|
1671 if (simulatedWidth) { |
|
1672 return OPERATOR_EVALUATORS[operator](BREAKPOINTS[breakpoint], simulatedWidth); |
|
1673 } |
|
1674 |
|
1675 return mediaQueryResult; |
|
1676 }; |
|
1677 |
|
1678 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider; |
|
1679 /* harmony default export */ var use_viewport_match = (useViewportMatch); |
|
1680 |
|
1681 // EXTERNAL MODULE: ./node_modules/react-resize-aware/dist/index.js |
|
1682 var dist = __webpack_require__("SSiF"); |
|
1683 var dist_default = /*#__PURE__*/__webpack_require__.n(dist); |
|
1684 |
|
1685 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/index.js |
|
1686 /** |
|
1687 * External dependencies |
|
1688 */ |
|
1689 |
|
1690 /** |
|
1691 * Hook which allows to listen the resize event of any target element when it changes sizes. |
|
1692 * _Note: `useResizeObserver` will report `null` until after first render_ |
|
1693 * |
|
1694 * @return {Array} An array of {Element} `resizeListener` and {?Object} `sizes` with properties `width` and `height` |
|
1695 * |
|
1696 * @example |
|
1697 * |
|
1698 * ```js |
|
1699 * const App = () => { |
|
1700 * const [ resizeListener, sizes ] = useResizeObserver(); |
|
1701 * |
|
1702 * return ( |
|
1703 * <div> |
|
1704 * { resizeListener } |
|
1705 * Your content here |
|
1706 * </div> |
|
1707 * ); |
|
1708 * }; |
|
1709 * ``` |
|
1710 * |
|
1711 */ |
|
1712 |
|
1713 /* harmony default export */ var use_resize_observer = (dist_default.a); |
|
1714 |
|
1715 // EXTERNAL MODULE: external ["wp","priorityQueue"] |
|
1716 var external_wp_priorityQueue_ = __webpack_require__("XI5e"); |
|
1717 |
|
1718 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-async-list/index.js |
|
1719 /** |
|
1720 * WordPress dependencies |
|
1721 */ |
|
1722 |
|
1723 |
|
1724 /** |
|
1725 * Returns the first items from list that are present on state. |
|
1726 * |
|
1727 * @param list New array. |
|
1728 * @param state Current state. |
|
1729 * @return First items present iin state. |
|
1730 */ |
|
1731 |
|
1732 function getFirstItemsPresentInState(list, state) { |
|
1733 const firstItems = []; |
|
1734 |
|
1735 for (let i = 0; i < list.length; i++) { |
|
1736 const item = list[i]; |
|
1737 |
|
1738 if (!state.includes(item)) { |
|
1739 break; |
|
1740 } |
|
1741 |
|
1742 firstItems.push(item); |
|
1743 } |
|
1744 |
|
1745 return firstItems; |
|
1746 } |
|
1747 /** |
|
1748 * React hook returns an array which items get asynchronously appended from a source array. |
|
1749 * This behavior is useful if we want to render a list of items asynchronously for performance reasons. |
|
1750 * |
|
1751 * @param list Source array. |
|
1752 * @return Async array. |
|
1753 */ |
|
1754 |
|
1755 |
|
1756 function useAsyncList(list) { |
|
1757 const [current, setCurrent] = Object(external_wp_element_["useState"])([]); |
|
1758 Object(external_wp_element_["useEffect"])(() => { |
|
1759 // On reset, we keep the first items that were previously rendered. |
|
1760 const firstItems = getFirstItemsPresentInState(list, current); |
|
1761 setCurrent(firstItems); |
|
1762 const asyncQueue = Object(external_wp_priorityQueue_["createQueue"])(); |
|
1763 |
|
1764 const append = index => () => { |
|
1765 if (list.length <= index) { |
|
1766 return; |
|
1767 } |
|
1768 |
|
1769 setCurrent(state => [...state, list[index]]); |
|
1770 asyncQueue.add({}, append(index + 1)); |
|
1771 }; |
|
1772 |
|
1773 asyncQueue.add({}, append(firstItems.length)); |
|
1774 return () => asyncQueue.reset(); |
|
1775 }, [list]); |
|
1776 return current; |
|
1777 } |
|
1778 |
|
1779 /* harmony default export */ var use_async_list = (useAsyncList); |
|
1780 |
|
1781 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-warn-on-change/index.js |
|
1782 /** |
|
1783 * Internal dependencies |
|
1784 */ |
|
1785 |
|
1786 /** |
|
1787 * Hook that performs a shallow comparison between the preview value of an object |
|
1788 * and the new one, if there's a difference, it prints it to the console. |
|
1789 * this is useful in performance related work, to check why a component re-renders. |
|
1790 * |
|
1791 * @example |
|
1792 * |
|
1793 * ```jsx |
|
1794 * function MyComponent(props) { |
|
1795 * useWarnOnChange(props); |
|
1796 * |
|
1797 * return "Something"; |
|
1798 * } |
|
1799 * ``` |
|
1800 * |
|
1801 * @param {Object} object Object which changes to compare. |
|
1802 * @param {string} prefix Just a prefix to show when console logging. |
|
1803 */ |
|
1804 |
|
1805 function useWarnOnChange(object, prefix = 'Change detection') { |
|
1806 const previousValues = usePrevious(object); |
|
1807 Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(([key, value]) => { |
|
1808 if (value !== object[key]) { |
|
1809 // eslint-disable-next-line no-console |
|
1810 console.warn(`${prefix}: ${key} key changed:`, value, object[key]); |
|
1811 } |
|
1812 }); |
|
1813 } |
|
1814 |
|
1815 /* harmony default export */ var use_warn_on_change = (useWarnOnChange); |
|
1816 |
|
1817 // EXTERNAL MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
|
1818 var use_memo_one_esm = __webpack_require__("mHlH"); |
|
1819 |
|
1820 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-debounce/index.js |
|
1821 /** |
|
1822 * External dependencies |
|
1823 */ |
|
1824 |
|
1825 |
|
1826 /** |
|
1827 * WordPress dependencies |
|
1828 */ |
|
1829 |
|
1830 |
|
1831 /** |
|
1832 * Debounces a function with Lodash's `debounce`. A new debounced function will |
|
1833 * be returned and any scheduled calls cancelled if any of the arguments change, |
|
1834 * including the function to debounce, so please wrap functions created on |
|
1835 * render in components in `useCallback`. |
|
1836 * |
|
1837 * @param {...any} args Arguments passed to Lodash's `debounce`. |
|
1838 * |
|
1839 * @return {Function} Debounced function. |
|
1840 */ |
|
1841 |
|
1842 function useDebounce(...args) { |
|
1843 const debounced = Object(use_memo_one_esm["a" /* useMemoOne */])(() => Object(external_lodash_["debounce"])(...args), args); |
|
1844 Object(external_wp_element_["useEffect"])(() => () => debounced.cancel(), [debounced]); |
|
1845 return debounced; |
|
1846 } |
|
1847 |
|
1848 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-throttle/index.js |
|
1849 /** |
|
1850 * External dependencies |
|
1851 */ |
|
1852 |
|
1853 |
|
1854 /** |
|
1855 * WordPress dependencies |
|
1856 */ |
|
1857 |
|
1858 |
|
1859 /** |
|
1860 * Throttles a function with Lodash's `throttle`. A new throttled function will |
|
1861 * be returned and any scheduled calls cancelled if any of the arguments change, |
|
1862 * including the function to throttle, so please wrap functions created on |
|
1863 * render in components in `useCallback`. |
|
1864 * |
|
1865 * @param {...any} args Arguments passed to Lodash's `throttle`. |
|
1866 * |
|
1867 * @return {Function} Throttled function. |
|
1868 */ |
|
1869 |
|
1870 function useThrottle(...args) { |
|
1871 const throttled = Object(use_memo_one_esm["a" /* useMemoOne */])(() => Object(external_lodash_["throttle"])(...args), args); |
|
1872 Object(external_wp_element_["useEffect"])(() => () => throttled.cancel(), [throttled]); |
|
1873 return throttled; |
|
1874 } |
|
1875 |
|
1876 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-drop-zone/index.js |
|
1877 /** |
|
1878 * WordPress dependencies |
|
1879 */ |
|
1880 |
|
1881 /** |
|
1882 * Internal dependencies |
|
1883 */ |
|
1884 |
|
1885 |
|
1886 /** @typedef {import('@wordpress/element').RefCallback} RefCallback */ |
|
1887 |
|
1888 function useFreshRef(value) { |
|
1889 const ref = Object(external_wp_element_["useRef"])(); |
|
1890 ref.current = value; |
|
1891 return ref; |
|
1892 } |
|
1893 /** |
|
1894 * A hook to facilitate drag and drop handling. |
|
1895 * |
|
1896 * @param {Object} $1 Named parameters. |
|
1897 * @param {boolean} $1.isDisabled Whether or not to disable the drop zone. |
|
1898 * @param {DragEvent} $1.onDragStart Called when dragging has started. |
|
1899 * @param {DragEvent} $1.onDragEnter Called when the zone is entered. |
|
1900 * @param {DragEvent} $1.onDragOver Called when the zone is moved within. |
|
1901 * @param {DragEvent} $1.onDragLeave Called when the zone is left. |
|
1902 * @param {MouseEvent} $1.onDragEnd Called when dragging has ended. |
|
1903 * @param {DragEvent} $1.onDrop Called when dropping in the zone. |
|
1904 * |
|
1905 * @return {RefCallback} Ref callback to be passed to the drop zone element. |
|
1906 */ |
|
1907 |
|
1908 |
|
1909 function useDropZone({ |
|
1910 isDisabled, |
|
1911 onDrop: _onDrop, |
|
1912 onDragStart: _onDragStart, |
|
1913 onDragEnter: _onDragEnter, |
|
1914 onDragLeave: _onDragLeave, |
|
1915 onDragEnd: _onDragEnd, |
|
1916 onDragOver: _onDragOver |
|
1917 }) { |
|
1918 const onDropRef = useFreshRef(_onDrop); |
|
1919 const onDragStartRef = useFreshRef(_onDragStart); |
|
1920 const onDragEnterRef = useFreshRef(_onDragEnter); |
|
1921 const onDragLeaveRef = useFreshRef(_onDragLeave); |
|
1922 const onDragEndRef = useFreshRef(_onDragEnd); |
|
1923 const onDragOverRef = useFreshRef(_onDragOver); |
|
1924 return useRefEffect(element => { |
|
1925 if (isDisabled) { |
|
1926 return; |
|
1927 } |
|
1928 |
|
1929 let isDragging = false; |
|
1930 const { |
|
1931 ownerDocument |
|
1932 } = element; |
|
1933 /** |
|
1934 * Checks if an element is in the drop zone. |
|
1935 * |
|
1936 * @param {HTMLElement|null} elementToCheck |
|
1937 * |
|
1938 * @return {boolean} True if in drop zone, false if not. |
|
1939 */ |
|
1940 |
|
1941 function isElementInZone(elementToCheck) { |
|
1942 if (!elementToCheck || !element.contains(elementToCheck)) { |
|
1943 return false; |
|
1944 } |
|
1945 |
|
1946 do { |
|
1947 if (elementToCheck.dataset.isDropZone) { |
|
1948 return elementToCheck === element; |
|
1949 } |
|
1950 } while (elementToCheck = elementToCheck.parentElement); |
|
1951 |
|
1952 return false; |
|
1953 } |
|
1954 |
|
1955 function maybeDragStart( |
|
1956 /** @type {DragEvent} */ |
|
1957 event) { |
|
1958 if (isDragging) { |
|
1959 return; |
|
1960 } |
|
1961 |
|
1962 isDragging = true; |
|
1963 ownerDocument.removeEventListener('dragenter', maybeDragStart); // Note that `dragend` doesn't fire consistently for file and |
|
1964 // HTML drag events where the drag origin is outside the browser |
|
1965 // window. In Firefox it may also not fire if the originating |
|
1966 // node is removed. |
|
1967 |
|
1968 ownerDocument.addEventListener('dragend', maybeDragEnd); |
|
1969 ownerDocument.addEventListener('mousemove', maybeDragEnd); |
|
1970 |
|
1971 if (onDragStartRef.current) { |
|
1972 onDragStartRef.current(event); |
|
1973 } |
|
1974 } |
|
1975 |
|
1976 function onDragEnter(event) { |
|
1977 event.preventDefault(); // The `dragenter` event will also fire when entering child |
|
1978 // elements, but we only want to call `onDragEnter` when |
|
1979 // entering the drop zone, which means the `relatedTarget` |
|
1980 // (element that has been left) should be outside the drop zone. |
|
1981 |
|
1982 if (element.contains(event.relatedTarget)) { |
|
1983 return; |
|
1984 } |
|
1985 |
|
1986 if (onDragEnterRef.current) { |
|
1987 onDragEnterRef.current(event); |
|
1988 } |
|
1989 } |
|
1990 |
|
1991 function onDragOver(event) { |
|
1992 // Only call onDragOver for the innermost hovered drop zones. |
|
1993 if (!event.defaultPrevented && onDragOverRef.current) { |
|
1994 onDragOverRef.current(event); |
|
1995 } // Prevent the browser default while also signalling to parent |
|
1996 // drop zones that `onDragOver` is already handled. |
|
1997 |
|
1998 |
|
1999 event.preventDefault(); |
|
2000 } |
|
2001 |
|
2002 function onDragLeave(event) { |
|
2003 // The `dragleave` event will also fire when leaving child |
|
2004 // elements, but we only want to call `onDragLeave` when |
|
2005 // leaving the drop zone, which means the `relatedTarget` |
|
2006 // (element that has been entered) should be outside the drop |
|
2007 // zone. |
|
2008 if (isElementInZone(event.relatedTarget)) { |
|
2009 return; |
|
2010 } |
|
2011 |
|
2012 if (onDragLeaveRef.current) { |
|
2013 onDragLeaveRef.current(event); |
|
2014 } |
|
2015 } |
|
2016 |
|
2017 function onDrop(event) { |
|
2018 // Don't handle drop if an inner drop zone already handled it. |
|
2019 if (event.defaultPrevented) { |
|
2020 return; |
|
2021 } // Prevent the browser default while also signalling to parent |
|
2022 // drop zones that `onDrop` is already handled. |
|
2023 |
|
2024 |
|
2025 event.preventDefault(); // This seemingly useless line has been shown to resolve a |
|
2026 // Safari issue where files dragged directly from the dock are |
|
2027 // not recognized. |
|
2028 // eslint-disable-next-line no-unused-expressions |
|
2029 |
|
2030 event.dataTransfer && event.dataTransfer.files.length; |
|
2031 |
|
2032 if (onDropRef.current) { |
|
2033 onDropRef.current(event); |
|
2034 } |
|
2035 |
|
2036 maybeDragEnd(event); |
|
2037 } |
|
2038 |
|
2039 function maybeDragEnd(event) { |
|
2040 if (!isDragging) { |
|
2041 return; |
|
2042 } |
|
2043 |
|
2044 isDragging = false; |
|
2045 ownerDocument.addEventListener('dragenter', maybeDragStart); |
|
2046 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
|
2047 ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
|
2048 |
|
2049 if (onDragEndRef.current) { |
|
2050 onDragEndRef.current(event); |
|
2051 } |
|
2052 } |
|
2053 |
|
2054 element.dataset.isDropZone = 'true'; |
|
2055 element.addEventListener('drop', onDrop); |
|
2056 element.addEventListener('dragenter', onDragEnter); |
|
2057 element.addEventListener('dragover', onDragOver); |
|
2058 element.addEventListener('dragleave', onDragLeave); // The `dragstart` event doesn't fire if the drag started outside |
|
2059 // the document. |
|
2060 |
|
2061 ownerDocument.addEventListener('dragenter', maybeDragStart); |
|
2062 return () => { |
|
2063 delete element.dataset.isDropZone; |
|
2064 element.removeEventListener('drop', onDrop); |
|
2065 element.removeEventListener('dragenter', onDragEnter); |
|
2066 element.removeEventListener('dragover', onDragOver); |
|
2067 element.removeEventListener('dragleave', onDragLeave); |
|
2068 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
|
2069 ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
|
2070 ownerDocument.addEventListener('dragenter', maybeDragStart); |
|
2071 }; |
|
2072 }, [isDisabled]); |
|
2073 } |
|
2074 |
|
2075 // CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/index.js |
|
2076 // Utils |
|
2077 // Compose helper (aliased flowRight from Lodash) |
|
2078 |
|
2079 // Higher-order components |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 |
|
2086 // Hooks |
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 |
|
2113 /***/ }), |
|
2114 |
|
2115 /***/ "RxS6": |
|
2116 /***/ (function(module, exports) { |
|
2117 |
|
2118 (function() { module.exports = window["wp"]["keycodes"]; }()); |
|
2119 |
|
2120 /***/ }), |
|
2121 |
|
2122 /***/ "SSiF": |
|
2123 /***/ (function(module, exports, __webpack_require__) { |
|
2124 |
|
2125 var e=__webpack_require__("cDcd"),n={display:"block",opacity:0,position:"absolute",top:0,left:0,height:"100%",width:"100%",overflow:"hidden",pointerEvents:"none",zIndex:-1},t=function(t){var r=t.onResize,u=e.useRef();return function(n,t){var r=function(){return n.current&&n.current.contentDocument&&n.current.contentDocument.defaultView};function u(){t();var e=r();e&&e.addEventListener("resize",t)}e.useEffect((function(){return r()?u():n.current&&n.current.addEventListener&&n.current.addEventListener("load",u),function(){var e=r();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("resize",t)}}),[])}(u,(function(){return r(u)})),e.createElement("iframe",{style:n,src:"about:blank",ref:u,"aria-hidden":!0,tabIndex:-1,frameBorder:0})},r=function(e){return{width:null!=e?e.offsetWidth:null,height:null!=e?e.offsetHeight:null}};module.exports=function(n){void 0===n&&(n=r);var u=e.useState(n(null)),o=u[0],i=u[1],c=e.useCallback((function(e){return i(n(e.current))}),[n]);return[e.useMemo((function(){return e.createElement(t,{onResize:c})}),[c]),o]}; |
|
2126 |
|
2127 |
|
2128 /***/ }), |
|
2129 |
|
2130 /***/ "VcSt": |
|
2131 /***/ (function(module, exports) { |
|
2132 |
|
2133 /** |
|
2134 * adds a bindGlobal method to Mousetrap that allows you to |
|
2135 * bind specific keyboard shortcuts that will still work |
|
2136 * inside a text input field |
|
2137 * |
|
2138 * usage: |
|
2139 * Mousetrap.bindGlobal('ctrl+s', _saveChanges); |
|
2140 */ |
|
2141 /* global Mousetrap:true */ |
|
2142 (function(Mousetrap) { |
|
2143 if (! Mousetrap) { |
|
2144 return; |
|
2145 } |
|
2146 var _globalCallbacks = {}; |
|
2147 var _originalStopCallback = Mousetrap.prototype.stopCallback; |
|
2148 |
|
2149 Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) { |
|
2150 var self = this; |
|
2151 |
|
2152 if (self.paused) { |
|
2153 return true; |
|
2154 } |
|
2155 |
|
2156 if (_globalCallbacks[combo] || _globalCallbacks[sequence]) { |
|
2157 return false; |
|
2158 } |
|
2159 |
|
2160 return _originalStopCallback.call(self, e, element, combo); |
|
2161 }; |
|
2162 |
|
2163 Mousetrap.prototype.bindGlobal = function(keys, callback, action) { |
|
2164 var self = this; |
|
2165 self.bind(keys, callback, action); |
|
2166 |
|
2167 if (keys instanceof Array) { |
|
2168 for (var i = 0; i < keys.length; i++) { |
|
2169 _globalCallbacks[keys[i]] = true; |
|
2170 } |
|
2171 return; |
|
2172 } |
|
2173 |
|
2174 _globalCallbacks[keys] = true; |
|
2175 }; |
|
2176 |
|
2177 Mousetrap.init(); |
|
2178 }) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined); |
|
2179 |
|
2180 |
|
2181 /***/ }), |
|
2182 |
|
2183 /***/ "XI5e": |
|
2184 /***/ (function(module, exports) { |
|
2185 |
|
2186 (function() { module.exports = window["wp"]["priorityQueue"]; }()); |
|
2187 |
|
2188 /***/ }), |
|
2189 |
|
2190 /***/ "YLtl": |
|
2191 /***/ (function(module, exports) { |
|
2192 |
|
2193 (function() { module.exports = window["lodash"]; }()); |
|
2194 |
|
2195 /***/ }), |
|
2196 |
|
2197 /***/ "cDcd": |
|
2198 /***/ (function(module, exports) { |
|
2199 |
|
2200 (function() { module.exports = window["React"]; }()); |
|
2201 |
|
2202 /***/ }), |
|
2203 |
|
2204 /***/ "imBb": |
|
2205 /***/ (function(module, exports, __webpack_require__) { |
882 /***/ (function(module, exports, __webpack_require__) { |
2206 |
883 |
2207 var __WEBPACK_AMD_DEFINE_RESULT__;/*global define:false */ |
884 var __WEBPACK_AMD_DEFINE_RESULT__;/*global define:false */ |
2208 /** |
885 /** |
2209 * Copyright 2012-2017 Craig Campbell |
886 * Copyright 2012-2017 Craig Campbell |
3258 // expose mousetrap as an AMD module |
1935 // expose mousetrap as an AMD module |
3259 if (true) { |
1936 if (true) { |
3260 !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() { |
1937 !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() { |
3261 return Mousetrap; |
1938 return Mousetrap; |
3262 }).call(exports, __webpack_require__, exports, module), |
1939 }).call(exports, __webpack_require__, exports, module), |
3263 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
1940 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
3264 } |
1941 } |
3265 }) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null); |
1942 }) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null); |
3266 |
1943 |
3267 |
1944 |
3268 /***/ }), |
1945 /***/ }), |
3269 |
1946 |
3270 /***/ "mHlH": |
1947 /***/ 5538: |
3271 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
1948 /***/ (function() { |
|
1949 |
|
1950 /** |
|
1951 * adds a bindGlobal method to Mousetrap that allows you to |
|
1952 * bind specific keyboard shortcuts that will still work |
|
1953 * inside a text input field |
|
1954 * |
|
1955 * usage: |
|
1956 * Mousetrap.bindGlobal('ctrl+s', _saveChanges); |
|
1957 */ |
|
1958 /* global Mousetrap:true */ |
|
1959 (function(Mousetrap) { |
|
1960 if (! Mousetrap) { |
|
1961 return; |
|
1962 } |
|
1963 var _globalCallbacks = {}; |
|
1964 var _originalStopCallback = Mousetrap.prototype.stopCallback; |
|
1965 |
|
1966 Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) { |
|
1967 var self = this; |
|
1968 |
|
1969 if (self.paused) { |
|
1970 return true; |
|
1971 } |
|
1972 |
|
1973 if (_globalCallbacks[combo] || _globalCallbacks[sequence]) { |
|
1974 return false; |
|
1975 } |
|
1976 |
|
1977 return _originalStopCallback.call(self, e, element, combo); |
|
1978 }; |
|
1979 |
|
1980 Mousetrap.prototype.bindGlobal = function(keys, callback, action) { |
|
1981 var self = this; |
|
1982 self.bind(keys, callback, action); |
|
1983 |
|
1984 if (keys instanceof Array) { |
|
1985 for (var i = 0; i < keys.length; i++) { |
|
1986 _globalCallbacks[keys[i]] = true; |
|
1987 } |
|
1988 return; |
|
1989 } |
|
1990 |
|
1991 _globalCallbacks[keys] = true; |
|
1992 }; |
|
1993 |
|
1994 Mousetrap.init(); |
|
1995 }) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined); |
|
1996 |
|
1997 |
|
1998 /***/ }), |
|
1999 |
|
2000 /***/ 235: |
|
2001 /***/ (function(module, __unused_webpack_exports, __webpack_require__) { |
|
2002 |
|
2003 var e=__webpack_require__(9196),n={display:"block",opacity:0,position:"absolute",top:0,left:0,height:"100%",width:"100%",overflow:"hidden",pointerEvents:"none",zIndex:-1},t=function(t){var r=t.onResize,u=e.useRef();return function(n,t){var r=function(){return n.current&&n.current.contentDocument&&n.current.contentDocument.defaultView};function u(){t();var e=r();e&&e.addEventListener("resize",t)}e.useEffect((function(){return r()?u():n.current&&n.current.addEventListener&&n.current.addEventListener("load",u),function(){var e=r();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("resize",t)}}),[])}(u,(function(){return r(u)})),e.createElement("iframe",{style:n,src:"about:blank",ref:u,"aria-hidden":!0,tabIndex:-1,frameBorder:0})},r=function(e){return{width:null!=e?e.offsetWidth:null,height:null!=e?e.offsetHeight:null}};module.exports=function(n){void 0===n&&(n=r);var u=e.useState(n(null)),o=u[0],i=u[1],c=e.useCallback((function(e){return i(n(e.current))}),[n]);return[e.useMemo((function(){return e.createElement(t,{onResize:c})}),[c]),o]}; |
|
2004 |
|
2005 |
|
2006 /***/ }), |
|
2007 |
|
2008 /***/ 9196: |
|
2009 /***/ (function(module) { |
3272 |
2010 |
3273 "use strict"; |
2011 "use strict"; |
3274 /* unused harmony export useCallback */ |
2012 module.exports = window["React"]; |
3275 /* unused harmony export useCallbackOne */ |
|
3276 /* unused harmony export useMemo */ |
|
3277 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useMemoOne; }); |
|
3278 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("cDcd"); |
|
3279 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
|
3280 |
|
3281 |
|
3282 function areInputsEqual(newInputs, lastInputs) { |
|
3283 if (newInputs.length !== lastInputs.length) { |
|
3284 return false; |
|
3285 } |
|
3286 |
|
3287 for (var i = 0; i < newInputs.length; i++) { |
|
3288 if (newInputs[i] !== lastInputs[i]) { |
|
3289 return false; |
|
3290 } |
|
3291 } |
|
3292 |
|
3293 return true; |
|
3294 } |
|
3295 |
|
3296 function useMemoOne(getResult, inputs) { |
|
3297 var initial = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(function () { |
|
3298 return { |
|
3299 inputs: inputs, |
|
3300 result: getResult() |
|
3301 }; |
|
3302 })[0]; |
|
3303 var isFirstRun = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(true); |
|
3304 var committed = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(initial); |
|
3305 var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); |
|
3306 var cache = useCache ? committed.current : { |
|
3307 inputs: inputs, |
|
3308 result: getResult() |
|
3309 }; |
|
3310 Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(function () { |
|
3311 isFirstRun.current = false; |
|
3312 committed.current = cache; |
|
3313 }, [cache]); |
|
3314 return cache.result; |
|
3315 } |
|
3316 function useCallbackOne(callback, inputs) { |
|
3317 return useMemoOne(function () { |
|
3318 return callback; |
|
3319 }, inputs); |
|
3320 } |
|
3321 var useMemo = useMemoOne; |
|
3322 var useCallback = useCallbackOne; |
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 /***/ }), |
|
3328 |
|
3329 /***/ "rl8x": |
|
3330 /***/ (function(module, exports) { |
|
3331 |
|
3332 (function() { module.exports = window["wp"]["isShallowEqual"]; }()); |
|
3333 |
|
3334 /***/ }), |
|
3335 |
|
3336 /***/ "sxGJ": |
|
3337 /***/ (function(module, exports, __webpack_require__) { |
|
3338 |
|
3339 /*! |
|
3340 * clipboard.js v2.0.8 |
|
3341 * https://clipboardjs.com/ |
|
3342 * |
|
3343 * Licensed MIT © Zeno Rocha |
|
3344 */ |
|
3345 (function webpackUniversalModuleDefinition(root, factory) { |
|
3346 if(true) |
|
3347 module.exports = factory(); |
|
3348 else {} |
|
3349 })(this, function() { |
|
3350 return /******/ (function() { // webpackBootstrap |
|
3351 /******/ var __webpack_modules__ = ({ |
|
3352 |
|
3353 /***/ 134: |
|
3354 /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
|
3355 |
|
3356 "use strict"; |
|
3357 |
|
3358 // EXPORTS |
|
3359 __webpack_require__.d(__webpack_exports__, { |
|
3360 "default": function() { return /* binding */ clipboard; } |
|
3361 }); |
|
3362 |
|
3363 // EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js |
|
3364 var tiny_emitter = __webpack_require__(279); |
|
3365 var tiny_emitter_default = /*#__PURE__*/__webpack_require__.n(tiny_emitter); |
|
3366 // EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js |
|
3367 var listen = __webpack_require__(370); |
|
3368 var listen_default = /*#__PURE__*/__webpack_require__.n(listen); |
|
3369 // EXTERNAL MODULE: ./node_modules/select/src/select.js |
|
3370 var src_select = __webpack_require__(817); |
|
3371 var select_default = /*#__PURE__*/__webpack_require__.n(src_select); |
|
3372 ;// CONCATENATED MODULE: ./src/clipboard-action.js |
|
3373 function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
3374 |
|
3375 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
3376 |
|
3377 function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } |
|
3378 |
|
3379 function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
|
3380 |
|
3381 |
|
3382 /** |
|
3383 * Inner class which performs selection from either `text` or `target` |
|
3384 * properties and then executes copy or cut operations. |
|
3385 */ |
|
3386 |
|
3387 var ClipboardAction = /*#__PURE__*/function () { |
|
3388 /** |
|
3389 * @param {Object} options |
|
3390 */ |
|
3391 function ClipboardAction(options) { |
|
3392 _classCallCheck(this, ClipboardAction); |
|
3393 |
|
3394 this.resolveOptions(options); |
|
3395 this.initSelection(); |
|
3396 } |
|
3397 /** |
|
3398 * Defines base properties passed from constructor. |
|
3399 * @param {Object} options |
|
3400 */ |
|
3401 |
|
3402 |
|
3403 _createClass(ClipboardAction, [{ |
|
3404 key: "resolveOptions", |
|
3405 value: function resolveOptions() { |
|
3406 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3407 this.action = options.action; |
|
3408 this.container = options.container; |
|
3409 this.emitter = options.emitter; |
|
3410 this.target = options.target; |
|
3411 this.text = options.text; |
|
3412 this.trigger = options.trigger; |
|
3413 this.selectedText = ''; |
|
3414 } |
|
3415 /** |
|
3416 * Decides which selection strategy is going to be applied based |
|
3417 * on the existence of `text` and `target` properties. |
|
3418 */ |
|
3419 |
|
3420 }, { |
|
3421 key: "initSelection", |
|
3422 value: function initSelection() { |
|
3423 if (this.text) { |
|
3424 this.selectFake(); |
|
3425 } else if (this.target) { |
|
3426 this.selectTarget(); |
|
3427 } |
|
3428 } |
|
3429 /** |
|
3430 * Creates a fake textarea element, sets its value from `text` property, |
|
3431 */ |
|
3432 |
|
3433 }, { |
|
3434 key: "createFakeElement", |
|
3435 value: function createFakeElement() { |
|
3436 var isRTL = document.documentElement.getAttribute('dir') === 'rtl'; |
|
3437 this.fakeElem = document.createElement('textarea'); // Prevent zooming on iOS |
|
3438 |
|
3439 this.fakeElem.style.fontSize = '12pt'; // Reset box model |
|
3440 |
|
3441 this.fakeElem.style.border = '0'; |
|
3442 this.fakeElem.style.padding = '0'; |
|
3443 this.fakeElem.style.margin = '0'; // Move element out of screen horizontally |
|
3444 |
|
3445 this.fakeElem.style.position = 'absolute'; |
|
3446 this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically |
|
3447 |
|
3448 var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
|
3449 this.fakeElem.style.top = "".concat(yPosition, "px"); |
|
3450 this.fakeElem.setAttribute('readonly', ''); |
|
3451 this.fakeElem.value = this.text; |
|
3452 return this.fakeElem; |
|
3453 } |
|
3454 /** |
|
3455 * Get's the value of fakeElem, |
|
3456 * and makes a selection on it. |
|
3457 */ |
|
3458 |
|
3459 }, { |
|
3460 key: "selectFake", |
|
3461 value: function selectFake() { |
|
3462 var _this = this; |
|
3463 |
|
3464 var fakeElem = this.createFakeElement(); |
|
3465 |
|
3466 this.fakeHandlerCallback = function () { |
|
3467 return _this.removeFake(); |
|
3468 }; |
|
3469 |
|
3470 this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true; |
|
3471 this.container.appendChild(fakeElem); |
|
3472 this.selectedText = select_default()(fakeElem); |
|
3473 this.copyText(); |
|
3474 this.removeFake(); |
|
3475 } |
|
3476 /** |
|
3477 * Only removes the fake element after another click event, that way |
|
3478 * a user can hit `Ctrl+C` to copy because selection still exists. |
|
3479 */ |
|
3480 |
|
3481 }, { |
|
3482 key: "removeFake", |
|
3483 value: function removeFake() { |
|
3484 if (this.fakeHandler) { |
|
3485 this.container.removeEventListener('click', this.fakeHandlerCallback); |
|
3486 this.fakeHandler = null; |
|
3487 this.fakeHandlerCallback = null; |
|
3488 } |
|
3489 |
|
3490 if (this.fakeElem) { |
|
3491 this.container.removeChild(this.fakeElem); |
|
3492 this.fakeElem = null; |
|
3493 } |
|
3494 } |
|
3495 /** |
|
3496 * Selects the content from element passed on `target` property. |
|
3497 */ |
|
3498 |
|
3499 }, { |
|
3500 key: "selectTarget", |
|
3501 value: function selectTarget() { |
|
3502 this.selectedText = select_default()(this.target); |
|
3503 this.copyText(); |
|
3504 } |
|
3505 /** |
|
3506 * Executes the copy operation based on the current selection. |
|
3507 */ |
|
3508 |
|
3509 }, { |
|
3510 key: "copyText", |
|
3511 value: function copyText() { |
|
3512 var succeeded; |
|
3513 |
|
3514 try { |
|
3515 succeeded = document.execCommand(this.action); |
|
3516 } catch (err) { |
|
3517 succeeded = false; |
|
3518 } |
|
3519 |
|
3520 this.handleResult(succeeded); |
|
3521 } |
|
3522 /** |
|
3523 * Fires an event based on the copy operation result. |
|
3524 * @param {Boolean} succeeded |
|
3525 */ |
|
3526 |
|
3527 }, { |
|
3528 key: "handleResult", |
|
3529 value: function handleResult(succeeded) { |
|
3530 this.emitter.emit(succeeded ? 'success' : 'error', { |
|
3531 action: this.action, |
|
3532 text: this.selectedText, |
|
3533 trigger: this.trigger, |
|
3534 clearSelection: this.clearSelection.bind(this) |
|
3535 }); |
|
3536 } |
|
3537 /** |
|
3538 * Moves focus away from `target` and back to the trigger, removes current selection. |
|
3539 */ |
|
3540 |
|
3541 }, { |
|
3542 key: "clearSelection", |
|
3543 value: function clearSelection() { |
|
3544 if (this.trigger) { |
|
3545 this.trigger.focus(); |
|
3546 } |
|
3547 |
|
3548 document.activeElement.blur(); |
|
3549 window.getSelection().removeAllRanges(); |
|
3550 } |
|
3551 /** |
|
3552 * Sets the `action` to be performed which can be either 'copy' or 'cut'. |
|
3553 * @param {String} action |
|
3554 */ |
|
3555 |
|
3556 }, { |
|
3557 key: "destroy", |
|
3558 |
|
3559 /** |
|
3560 * Destroy lifecycle. |
|
3561 */ |
|
3562 value: function destroy() { |
|
3563 this.removeFake(); |
|
3564 } |
|
3565 }, { |
|
3566 key: "action", |
|
3567 set: function set() { |
|
3568 var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy'; |
|
3569 this._action = action; |
|
3570 |
|
3571 if (this._action !== 'copy' && this._action !== 'cut') { |
|
3572 throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
|
3573 } |
|
3574 } |
|
3575 /** |
|
3576 * Gets the `action` property. |
|
3577 * @return {String} |
|
3578 */ |
|
3579 , |
|
3580 get: function get() { |
|
3581 return this._action; |
|
3582 } |
|
3583 /** |
|
3584 * Sets the `target` property using an element |
|
3585 * that will be have its content copied. |
|
3586 * @param {Element} target |
|
3587 */ |
|
3588 |
|
3589 }, { |
|
3590 key: "target", |
|
3591 set: function set(target) { |
|
3592 if (target !== undefined) { |
|
3593 if (target && _typeof(target) === 'object' && target.nodeType === 1) { |
|
3594 if (this.action === 'copy' && target.hasAttribute('disabled')) { |
|
3595 throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
|
3596 } |
|
3597 |
|
3598 if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
|
3599 throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
|
3600 } |
|
3601 |
|
3602 this._target = target; |
|
3603 } else { |
|
3604 throw new Error('Invalid "target" value, use a valid Element'); |
|
3605 } |
|
3606 } |
|
3607 } |
|
3608 /** |
|
3609 * Gets the `target` property. |
|
3610 * @return {String|HTMLElement} |
|
3611 */ |
|
3612 , |
|
3613 get: function get() { |
|
3614 return this._target; |
|
3615 } |
|
3616 }]); |
|
3617 |
|
3618 return ClipboardAction; |
|
3619 }(); |
|
3620 |
|
3621 /* harmony default export */ var clipboard_action = (ClipboardAction); |
|
3622 ;// CONCATENATED MODULE: ./src/clipboard.js |
|
3623 function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); } |
|
3624 |
|
3625 function clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
3626 |
|
3627 function clipboard_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } |
|
3628 |
|
3629 function clipboard_createClass(Constructor, protoProps, staticProps) { if (protoProps) clipboard_defineProperties(Constructor.prototype, protoProps); if (staticProps) clipboard_defineProperties(Constructor, staticProps); return Constructor; } |
|
3630 |
|
3631 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } |
|
3632 |
|
3633 function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } |
|
3634 |
|
3635 function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } |
|
3636 |
|
3637 function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } |
|
3638 |
|
3639 function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } |
|
3640 |
|
3641 function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } |
|
3642 |
|
3643 function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } |
|
3644 |
|
3645 |
|
3646 |
|
3647 |
|
3648 /** |
|
3649 * Helper function to retrieve attribute value. |
|
3650 * @param {String} suffix |
|
3651 * @param {Element} element |
|
3652 */ |
|
3653 |
|
3654 function getAttributeValue(suffix, element) { |
|
3655 var attribute = "data-clipboard-".concat(suffix); |
|
3656 |
|
3657 if (!element.hasAttribute(attribute)) { |
|
3658 return; |
|
3659 } |
|
3660 |
|
3661 return element.getAttribute(attribute); |
|
3662 } |
|
3663 /** |
|
3664 * Base class which takes one or more elements, adds event listeners to them, |
|
3665 * and instantiates a new `ClipboardAction` on each click. |
|
3666 */ |
|
3667 |
|
3668 |
|
3669 var Clipboard = /*#__PURE__*/function (_Emitter) { |
|
3670 _inherits(Clipboard, _Emitter); |
|
3671 |
|
3672 var _super = _createSuper(Clipboard); |
|
3673 |
|
3674 /** |
|
3675 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
|
3676 * @param {Object} options |
|
3677 */ |
|
3678 function Clipboard(trigger, options) { |
|
3679 var _this; |
|
3680 |
|
3681 clipboard_classCallCheck(this, Clipboard); |
|
3682 |
|
3683 _this = _super.call(this); |
|
3684 |
|
3685 _this.resolveOptions(options); |
|
3686 |
|
3687 _this.listenClick(trigger); |
|
3688 |
|
3689 return _this; |
|
3690 } |
|
3691 /** |
|
3692 * Defines if attributes would be resolved using internal setter functions |
|
3693 * or custom functions that were passed in the constructor. |
|
3694 * @param {Object} options |
|
3695 */ |
|
3696 |
|
3697 |
|
3698 clipboard_createClass(Clipboard, [{ |
|
3699 key: "resolveOptions", |
|
3700 value: function resolveOptions() { |
|
3701 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3702 this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
|
3703 this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
|
3704 this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
|
3705 this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body; |
|
3706 } |
|
3707 /** |
|
3708 * Adds a click event listener to the passed trigger. |
|
3709 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
|
3710 */ |
|
3711 |
|
3712 }, { |
|
3713 key: "listenClick", |
|
3714 value: function listenClick(trigger) { |
|
3715 var _this2 = this; |
|
3716 |
|
3717 this.listener = listen_default()(trigger, 'click', function (e) { |
|
3718 return _this2.onClick(e); |
|
3719 }); |
|
3720 } |
|
3721 /** |
|
3722 * Defines a new `ClipboardAction` on each click event. |
|
3723 * @param {Event} e |
|
3724 */ |
|
3725 |
|
3726 }, { |
|
3727 key: "onClick", |
|
3728 value: function onClick(e) { |
|
3729 var trigger = e.delegateTarget || e.currentTarget; |
|
3730 |
|
3731 if (this.clipboardAction) { |
|
3732 this.clipboardAction = null; |
|
3733 } |
|
3734 |
|
3735 this.clipboardAction = new clipboard_action({ |
|
3736 action: this.action(trigger), |
|
3737 target: this.target(trigger), |
|
3738 text: this.text(trigger), |
|
3739 container: this.container, |
|
3740 trigger: trigger, |
|
3741 emitter: this |
|
3742 }); |
|
3743 } |
|
3744 /** |
|
3745 * Default `action` lookup function. |
|
3746 * @param {Element} trigger |
|
3747 */ |
|
3748 |
|
3749 }, { |
|
3750 key: "defaultAction", |
|
3751 value: function defaultAction(trigger) { |
|
3752 return getAttributeValue('action', trigger); |
|
3753 } |
|
3754 /** |
|
3755 * Default `target` lookup function. |
|
3756 * @param {Element} trigger |
|
3757 */ |
|
3758 |
|
3759 }, { |
|
3760 key: "defaultTarget", |
|
3761 value: function defaultTarget(trigger) { |
|
3762 var selector = getAttributeValue('target', trigger); |
|
3763 |
|
3764 if (selector) { |
|
3765 return document.querySelector(selector); |
|
3766 } |
|
3767 } |
|
3768 /** |
|
3769 * Returns the support of the given action, or all actions if no action is |
|
3770 * given. |
|
3771 * @param {String} [action] |
|
3772 */ |
|
3773 |
|
3774 }, { |
|
3775 key: "defaultText", |
|
3776 |
|
3777 /** |
|
3778 * Default `text` lookup function. |
|
3779 * @param {Element} trigger |
|
3780 */ |
|
3781 value: function defaultText(trigger) { |
|
3782 return getAttributeValue('text', trigger); |
|
3783 } |
|
3784 /** |
|
3785 * Destroy lifecycle. |
|
3786 */ |
|
3787 |
|
3788 }, { |
|
3789 key: "destroy", |
|
3790 value: function destroy() { |
|
3791 this.listener.destroy(); |
|
3792 |
|
3793 if (this.clipboardAction) { |
|
3794 this.clipboardAction.destroy(); |
|
3795 this.clipboardAction = null; |
|
3796 } |
|
3797 } |
|
3798 }], [{ |
|
3799 key: "isSupported", |
|
3800 value: function isSupported() { |
|
3801 var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
|
3802 var actions = typeof action === 'string' ? [action] : action; |
|
3803 var support = !!document.queryCommandSupported; |
|
3804 actions.forEach(function (action) { |
|
3805 support = support && !!document.queryCommandSupported(action); |
|
3806 }); |
|
3807 return support; |
|
3808 } |
|
3809 }]); |
|
3810 |
|
3811 return Clipboard; |
|
3812 }((tiny_emitter_default())); |
|
3813 |
|
3814 /* harmony default export */ var clipboard = (Clipboard); |
|
3815 |
|
3816 /***/ }), |
|
3817 |
|
3818 /***/ 828: |
|
3819 /***/ (function(module) { |
|
3820 |
|
3821 var DOCUMENT_NODE_TYPE = 9; |
|
3822 |
|
3823 /** |
|
3824 * A polyfill for Element.matches() |
|
3825 */ |
|
3826 if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
|
3827 var proto = Element.prototype; |
|
3828 |
|
3829 proto.matches = proto.matchesSelector || |
|
3830 proto.mozMatchesSelector || |
|
3831 proto.msMatchesSelector || |
|
3832 proto.oMatchesSelector || |
|
3833 proto.webkitMatchesSelector; |
|
3834 } |
|
3835 |
|
3836 /** |
|
3837 * Finds the closest parent that matches a selector. |
|
3838 * |
|
3839 * @param {Element} element |
|
3840 * @param {String} selector |
|
3841 * @return {Function} |
|
3842 */ |
|
3843 function closest (element, selector) { |
|
3844 while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
|
3845 if (typeof element.matches === 'function' && |
|
3846 element.matches(selector)) { |
|
3847 return element; |
|
3848 } |
|
3849 element = element.parentNode; |
|
3850 } |
|
3851 } |
|
3852 |
|
3853 module.exports = closest; |
|
3854 |
|
3855 |
|
3856 /***/ }), |
|
3857 |
|
3858 /***/ 438: |
|
3859 /***/ (function(module, __unused_webpack_exports, __webpack_require__) { |
|
3860 |
|
3861 var closest = __webpack_require__(828); |
|
3862 |
|
3863 /** |
|
3864 * Delegates event to a selector. |
|
3865 * |
|
3866 * @param {Element} element |
|
3867 * @param {String} selector |
|
3868 * @param {String} type |
|
3869 * @param {Function} callback |
|
3870 * @param {Boolean} useCapture |
|
3871 * @return {Object} |
|
3872 */ |
|
3873 function _delegate(element, selector, type, callback, useCapture) { |
|
3874 var listenerFn = listener.apply(this, arguments); |
|
3875 |
|
3876 element.addEventListener(type, listenerFn, useCapture); |
|
3877 |
|
3878 return { |
|
3879 destroy: function() { |
|
3880 element.removeEventListener(type, listenerFn, useCapture); |
|
3881 } |
|
3882 } |
|
3883 } |
|
3884 |
|
3885 /** |
|
3886 * Delegates event to a selector. |
|
3887 * |
|
3888 * @param {Element|String|Array} [elements] |
|
3889 * @param {String} selector |
|
3890 * @param {String} type |
|
3891 * @param {Function} callback |
|
3892 * @param {Boolean} useCapture |
|
3893 * @return {Object} |
|
3894 */ |
|
3895 function delegate(elements, selector, type, callback, useCapture) { |
|
3896 // Handle the regular Element usage |
|
3897 if (typeof elements.addEventListener === 'function') { |
|
3898 return _delegate.apply(null, arguments); |
|
3899 } |
|
3900 |
|
3901 // Handle Element-less usage, it defaults to global delegation |
|
3902 if (typeof type === 'function') { |
|
3903 // Use `document` as the first parameter, then apply arguments |
|
3904 // This is a short way to .unshift `arguments` without running into deoptimizations |
|
3905 return _delegate.bind(null, document).apply(null, arguments); |
|
3906 } |
|
3907 |
|
3908 // Handle Selector-based usage |
|
3909 if (typeof elements === 'string') { |
|
3910 elements = document.querySelectorAll(elements); |
|
3911 } |
|
3912 |
|
3913 // Handle Array-like based usage |
|
3914 return Array.prototype.map.call(elements, function (element) { |
|
3915 return _delegate(element, selector, type, callback, useCapture); |
|
3916 }); |
|
3917 } |
|
3918 |
|
3919 /** |
|
3920 * Finds closest match and invokes callback. |
|
3921 * |
|
3922 * @param {Element} element |
|
3923 * @param {String} selector |
|
3924 * @param {String} type |
|
3925 * @param {Function} callback |
|
3926 * @return {Function} |
|
3927 */ |
|
3928 function listener(element, selector, type, callback) { |
|
3929 return function(e) { |
|
3930 e.delegateTarget = closest(e.target, selector); |
|
3931 |
|
3932 if (e.delegateTarget) { |
|
3933 callback.call(element, e); |
|
3934 } |
|
3935 } |
|
3936 } |
|
3937 |
|
3938 module.exports = delegate; |
|
3939 |
|
3940 |
|
3941 /***/ }), |
|
3942 |
|
3943 /***/ 879: |
|
3944 /***/ (function(__unused_webpack_module, exports) { |
|
3945 |
|
3946 /** |
|
3947 * Check if argument is a HTML element. |
|
3948 * |
|
3949 * @param {Object} value |
|
3950 * @return {Boolean} |
|
3951 */ |
|
3952 exports.node = function(value) { |
|
3953 return value !== undefined |
|
3954 && value instanceof HTMLElement |
|
3955 && value.nodeType === 1; |
|
3956 }; |
|
3957 |
|
3958 /** |
|
3959 * Check if argument is a list of HTML elements. |
|
3960 * |
|
3961 * @param {Object} value |
|
3962 * @return {Boolean} |
|
3963 */ |
|
3964 exports.nodeList = function(value) { |
|
3965 var type = Object.prototype.toString.call(value); |
|
3966 |
|
3967 return value !== undefined |
|
3968 && (type === '[object NodeList]' || type === '[object HTMLCollection]') |
|
3969 && ('length' in value) |
|
3970 && (value.length === 0 || exports.node(value[0])); |
|
3971 }; |
|
3972 |
|
3973 /** |
|
3974 * Check if argument is a string. |
|
3975 * |
|
3976 * @param {Object} value |
|
3977 * @return {Boolean} |
|
3978 */ |
|
3979 exports.string = function(value) { |
|
3980 return typeof value === 'string' |
|
3981 || value instanceof String; |
|
3982 }; |
|
3983 |
|
3984 /** |
|
3985 * Check if argument is a function. |
|
3986 * |
|
3987 * @param {Object} value |
|
3988 * @return {Boolean} |
|
3989 */ |
|
3990 exports.fn = function(value) { |
|
3991 var type = Object.prototype.toString.call(value); |
|
3992 |
|
3993 return type === '[object Function]'; |
|
3994 }; |
|
3995 |
|
3996 |
|
3997 /***/ }), |
|
3998 |
|
3999 /***/ 370: |
|
4000 /***/ (function(module, __unused_webpack_exports, __webpack_require__) { |
|
4001 |
|
4002 var is = __webpack_require__(879); |
|
4003 var delegate = __webpack_require__(438); |
|
4004 |
|
4005 /** |
|
4006 * Validates all params and calls the right |
|
4007 * listener function based on its target type. |
|
4008 * |
|
4009 * @param {String|HTMLElement|HTMLCollection|NodeList} target |
|
4010 * @param {String} type |
|
4011 * @param {Function} callback |
|
4012 * @return {Object} |
|
4013 */ |
|
4014 function listen(target, type, callback) { |
|
4015 if (!target && !type && !callback) { |
|
4016 throw new Error('Missing required arguments'); |
|
4017 } |
|
4018 |
|
4019 if (!is.string(type)) { |
|
4020 throw new TypeError('Second argument must be a String'); |
|
4021 } |
|
4022 |
|
4023 if (!is.fn(callback)) { |
|
4024 throw new TypeError('Third argument must be a Function'); |
|
4025 } |
|
4026 |
|
4027 if (is.node(target)) { |
|
4028 return listenNode(target, type, callback); |
|
4029 } |
|
4030 else if (is.nodeList(target)) { |
|
4031 return listenNodeList(target, type, callback); |
|
4032 } |
|
4033 else if (is.string(target)) { |
|
4034 return listenSelector(target, type, callback); |
|
4035 } |
|
4036 else { |
|
4037 throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
|
4038 } |
|
4039 } |
|
4040 |
|
4041 /** |
|
4042 * Adds an event listener to a HTML element |
|
4043 * and returns a remove listener function. |
|
4044 * |
|
4045 * @param {HTMLElement} node |
|
4046 * @param {String} type |
|
4047 * @param {Function} callback |
|
4048 * @return {Object} |
|
4049 */ |
|
4050 function listenNode(node, type, callback) { |
|
4051 node.addEventListener(type, callback); |
|
4052 |
|
4053 return { |
|
4054 destroy: function() { |
|
4055 node.removeEventListener(type, callback); |
|
4056 } |
|
4057 } |
|
4058 } |
|
4059 |
|
4060 /** |
|
4061 * Add an event listener to a list of HTML elements |
|
4062 * and returns a remove listener function. |
|
4063 * |
|
4064 * @param {NodeList|HTMLCollection} nodeList |
|
4065 * @param {String} type |
|
4066 * @param {Function} callback |
|
4067 * @return {Object} |
|
4068 */ |
|
4069 function listenNodeList(nodeList, type, callback) { |
|
4070 Array.prototype.forEach.call(nodeList, function(node) { |
|
4071 node.addEventListener(type, callback); |
|
4072 }); |
|
4073 |
|
4074 return { |
|
4075 destroy: function() { |
|
4076 Array.prototype.forEach.call(nodeList, function(node) { |
|
4077 node.removeEventListener(type, callback); |
|
4078 }); |
|
4079 } |
|
4080 } |
|
4081 } |
|
4082 |
|
4083 /** |
|
4084 * Add an event listener to a selector |
|
4085 * and returns a remove listener function. |
|
4086 * |
|
4087 * @param {String} selector |
|
4088 * @param {String} type |
|
4089 * @param {Function} callback |
|
4090 * @return {Object} |
|
4091 */ |
|
4092 function listenSelector(selector, type, callback) { |
|
4093 return delegate(document.body, selector, type, callback); |
|
4094 } |
|
4095 |
|
4096 module.exports = listen; |
|
4097 |
|
4098 |
|
4099 /***/ }), |
|
4100 |
|
4101 /***/ 817: |
|
4102 /***/ (function(module) { |
|
4103 |
|
4104 function select(element) { |
|
4105 var selectedText; |
|
4106 |
|
4107 if (element.nodeName === 'SELECT') { |
|
4108 element.focus(); |
|
4109 |
|
4110 selectedText = element.value; |
|
4111 } |
|
4112 else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
|
4113 var isReadOnly = element.hasAttribute('readonly'); |
|
4114 |
|
4115 if (!isReadOnly) { |
|
4116 element.setAttribute('readonly', ''); |
|
4117 } |
|
4118 |
|
4119 element.select(); |
|
4120 element.setSelectionRange(0, element.value.length); |
|
4121 |
|
4122 if (!isReadOnly) { |
|
4123 element.removeAttribute('readonly'); |
|
4124 } |
|
4125 |
|
4126 selectedText = element.value; |
|
4127 } |
|
4128 else { |
|
4129 if (element.hasAttribute('contenteditable')) { |
|
4130 element.focus(); |
|
4131 } |
|
4132 |
|
4133 var selection = window.getSelection(); |
|
4134 var range = document.createRange(); |
|
4135 |
|
4136 range.selectNodeContents(element); |
|
4137 selection.removeAllRanges(); |
|
4138 selection.addRange(range); |
|
4139 |
|
4140 selectedText = selection.toString(); |
|
4141 } |
|
4142 |
|
4143 return selectedText; |
|
4144 } |
|
4145 |
|
4146 module.exports = select; |
|
4147 |
|
4148 |
|
4149 /***/ }), |
|
4150 |
|
4151 /***/ 279: |
|
4152 /***/ (function(module) { |
|
4153 |
|
4154 function E () { |
|
4155 // Keep this empty so it's easier to inherit from |
|
4156 // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
|
4157 } |
|
4158 |
|
4159 E.prototype = { |
|
4160 on: function (name, callback, ctx) { |
|
4161 var e = this.e || (this.e = {}); |
|
4162 |
|
4163 (e[name] || (e[name] = [])).push({ |
|
4164 fn: callback, |
|
4165 ctx: ctx |
|
4166 }); |
|
4167 |
|
4168 return this; |
|
4169 }, |
|
4170 |
|
4171 once: function (name, callback, ctx) { |
|
4172 var self = this; |
|
4173 function listener () { |
|
4174 self.off(name, listener); |
|
4175 callback.apply(ctx, arguments); |
|
4176 }; |
|
4177 |
|
4178 listener._ = callback |
|
4179 return this.on(name, listener, ctx); |
|
4180 }, |
|
4181 |
|
4182 emit: function (name) { |
|
4183 var data = [].slice.call(arguments, 1); |
|
4184 var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
|
4185 var i = 0; |
|
4186 var len = evtArr.length; |
|
4187 |
|
4188 for (i; i < len; i++) { |
|
4189 evtArr[i].fn.apply(evtArr[i].ctx, data); |
|
4190 } |
|
4191 |
|
4192 return this; |
|
4193 }, |
|
4194 |
|
4195 off: function (name, callback) { |
|
4196 var e = this.e || (this.e = {}); |
|
4197 var evts = e[name]; |
|
4198 var liveEvents = []; |
|
4199 |
|
4200 if (evts && callback) { |
|
4201 for (var i = 0, len = evts.length; i < len; i++) { |
|
4202 if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
|
4203 liveEvents.push(evts[i]); |
|
4204 } |
|
4205 } |
|
4206 |
|
4207 // Remove event from queue to prevent memory leak |
|
4208 // Suggested by https://github.com/lazd |
|
4209 // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
|
4210 |
|
4211 (liveEvents.length) |
|
4212 ? e[name] = liveEvents |
|
4213 : delete e[name]; |
|
4214 |
|
4215 return this; |
|
4216 } |
|
4217 }; |
|
4218 |
|
4219 module.exports = E; |
|
4220 module.exports.TinyEmitter = E; |
|
4221 |
|
4222 |
2013 |
4223 /***/ }) |
2014 /***/ }) |
4224 |
2015 |
4225 /******/ }); |
2016 /******/ }); |
4226 /************************************************************************/ |
2017 /************************************************************************/ |
4305 } |
2267 } |
4306 } |
2268 } |
4307 |
2269 |
4308 return target; |
2270 return target; |
4309 }; |
2271 }; |
4310 |
|
4311 return _extends.apply(this, arguments); |
2272 return _extends.apply(this, arguments); |
4312 } |
2273 } |
4313 |
2274 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
4314 /***/ }) |
2275 var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
4315 |
2276 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
4316 /******/ }); |
2277 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/listener.js |
|
2278 /** |
|
2279 * External dependencies |
|
2280 */ |
|
2281 |
|
2282 /** |
|
2283 * Class responsible for orchestrating event handling on the global window, |
|
2284 * binding a single event to be shared across all handling instances, and |
|
2285 * removing the handler when no instances are listening for the event. |
|
2286 */ |
|
2287 |
|
2288 class Listener { |
|
2289 constructor() { |
|
2290 /** @type {any} */ |
|
2291 this.listeners = {}; |
|
2292 this.handleEvent = this.handleEvent.bind(this); |
|
2293 } |
|
2294 |
|
2295 add( |
|
2296 /** @type {any} */ |
|
2297 eventType, |
|
2298 /** @type {any} */ |
|
2299 instance) { |
|
2300 if (!this.listeners[eventType]) { |
|
2301 // Adding first listener for this type, so bind event. |
|
2302 window.addEventListener(eventType, this.handleEvent); |
|
2303 this.listeners[eventType] = []; |
|
2304 } |
|
2305 |
|
2306 this.listeners[eventType].push(instance); |
|
2307 } |
|
2308 |
|
2309 remove( |
|
2310 /** @type {any} */ |
|
2311 eventType, |
|
2312 /** @type {any} */ |
|
2313 instance) { |
|
2314 this.listeners[eventType] = (0,external_lodash_namespaceObject.without)(this.listeners[eventType], instance); |
|
2315 |
|
2316 if (!this.listeners[eventType].length) { |
|
2317 // Removing last listener for this type, so unbind event. |
|
2318 window.removeEventListener(eventType, this.handleEvent); |
|
2319 delete this.listeners[eventType]; |
|
2320 } |
|
2321 } |
|
2322 |
|
2323 handleEvent( |
|
2324 /** @type {any} */ |
|
2325 event) { |
|
2326 (0,external_lodash_namespaceObject.forEach)(this.listeners[event.type], instance => { |
|
2327 instance.handleEvent(event); |
|
2328 }); |
|
2329 } |
|
2330 |
|
2331 } |
|
2332 |
|
2333 /* harmony default export */ var listener = (Listener); |
|
2334 |
|
2335 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/index.js |
|
2336 |
|
2337 |
|
2338 |
|
2339 /** |
|
2340 * External dependencies |
|
2341 */ |
|
2342 |
|
2343 /** |
|
2344 * WordPress dependencies |
|
2345 */ |
|
2346 |
|
2347 |
|
2348 |
|
2349 /** |
|
2350 * Internal dependencies |
|
2351 */ |
|
2352 |
|
2353 |
|
2354 |
|
2355 /** |
|
2356 * Listener instance responsible for managing document event handling. |
|
2357 */ |
|
2358 |
|
2359 const with_global_events_listener = new listener(); |
|
2360 /* eslint-disable jsdoc/no-undefined-types */ |
|
2361 |
|
2362 /** |
|
2363 * Higher-order component creator which, given an object of DOM event types and |
|
2364 * values corresponding to a callback function name on the component, will |
|
2365 * create or update a window event handler to invoke the callback when an event |
|
2366 * occurs. On behalf of the consuming developer, the higher-order component |
|
2367 * manages unbinding when the component unmounts, and binding at most a single |
|
2368 * event handler for the entire application. |
|
2369 * |
|
2370 * @deprecated |
|
2371 * |
|
2372 * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM |
|
2373 * event type, the value a |
|
2374 * name of the function on |
|
2375 * the original component's |
|
2376 * instance which handles |
|
2377 * the event. |
|
2378 * |
|
2379 * @return {any} Higher-order component. |
|
2380 */ |
|
2381 |
|
2382 function withGlobalEvents(eventTypesToHandlers) { |
|
2383 external_wp_deprecated_default()('wp.compose.withGlobalEvents', { |
|
2384 since: '5.7', |
|
2385 alternative: 'useEffect' |
|
2386 }); // @ts-ignore We don't need to fix the type-related issues because this is deprecated. |
|
2387 |
|
2388 return create_higher_order_component(WrappedComponent => { |
|
2389 class Wrapper extends external_wp_element_namespaceObject.Component { |
|
2390 constructor( |
|
2391 /** @type {any} */ |
|
2392 props) { |
|
2393 super(props); |
|
2394 this.handleEvent = this.handleEvent.bind(this); |
|
2395 this.handleRef = this.handleRef.bind(this); |
|
2396 } |
|
2397 |
|
2398 componentDidMount() { |
|
2399 (0,external_lodash_namespaceObject.forEach)(eventTypesToHandlers, (_, eventType) => { |
|
2400 with_global_events_listener.add(eventType, this); |
|
2401 }); |
|
2402 } |
|
2403 |
|
2404 componentWillUnmount() { |
|
2405 (0,external_lodash_namespaceObject.forEach)(eventTypesToHandlers, (_, eventType) => { |
|
2406 with_global_events_listener.remove(eventType, this); |
|
2407 }); |
|
2408 } |
|
2409 |
|
2410 handleEvent( |
|
2411 /** @type {any} */ |
|
2412 event) { |
|
2413 const handler = eventTypesToHandlers[ |
|
2414 /** @type {keyof GlobalEventHandlersEventMap} */ |
|
2415 event.type |
|
2416 /* eslint-enable jsdoc/no-undefined-types */ |
|
2417 ]; |
|
2418 |
|
2419 if (typeof this.wrappedRef[handler] === 'function') { |
|
2420 this.wrappedRef[handler](event); |
|
2421 } |
|
2422 } |
|
2423 |
|
2424 handleRef( |
|
2425 /** @type {any} */ |
|
2426 el) { |
|
2427 this.wrappedRef = el; // Any component using `withGlobalEvents` that is not setting a `ref` |
|
2428 // will cause `this.props.forwardedRef` to be `null`, so we need this |
|
2429 // check. |
|
2430 |
|
2431 if (this.props.forwardedRef) { |
|
2432 this.props.forwardedRef(el); |
|
2433 } |
|
2434 } |
|
2435 |
|
2436 render() { |
|
2437 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, this.props.ownProps, { |
|
2438 ref: this.handleRef |
|
2439 })); |
|
2440 } |
|
2441 |
|
2442 } |
|
2443 |
|
2444 return (0,external_wp_element_namespaceObject.forwardRef)((props, ref) => { |
|
2445 return (0,external_wp_element_namespaceObject.createElement)(Wrapper, { |
|
2446 ownProps: props, |
|
2447 forwardedRef: ref |
|
2448 }); |
|
2449 }); |
|
2450 }, 'withGlobalEvents'); |
|
2451 } |
|
2452 |
|
2453 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-instance-id/index.js |
|
2454 // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case |
|
2455 // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript |
|
2456 |
|
2457 /* eslint-disable jsdoc/check-types */ |
|
2458 |
|
2459 /** |
|
2460 * WordPress dependencies |
|
2461 */ |
|
2462 |
|
2463 /** |
|
2464 * @type {WeakMap<object, number>} |
|
2465 */ |
|
2466 |
|
2467 const instanceMap = new WeakMap(); |
|
2468 /** |
|
2469 * Creates a new id for a given object. |
|
2470 * |
|
2471 * @param {object} object Object reference to create an id for. |
|
2472 * @return {number} The instance id (index). |
|
2473 */ |
|
2474 |
|
2475 function createId(object) { |
|
2476 const instances = instanceMap.get(object) || 0; |
|
2477 instanceMap.set(object, instances + 1); |
|
2478 return instances; |
|
2479 } |
|
2480 /** |
|
2481 * Provides a unique instance ID. |
|
2482 * |
|
2483 * @param {object} object Object reference to create an id for. |
|
2484 * @param {string} [prefix] Prefix for the unique id. |
|
2485 * @param {string | number} [preferredId=''] Default ID to use. |
|
2486 * @return {string | number} The unique instance id. |
|
2487 */ |
|
2488 |
|
2489 |
|
2490 function useInstanceId(object, prefix) { |
|
2491 let preferredId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; |
|
2492 return (0,external_wp_element_namespaceObject.useMemo)(() => { |
|
2493 if (preferredId) return preferredId; |
|
2494 const id = createId(object); |
|
2495 return prefix ? `${prefix}-${id}` : id; |
|
2496 }, [object]); |
|
2497 } |
|
2498 /* eslint-enable jsdoc/check-types */ |
|
2499 |
|
2500 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-instance-id/index.js |
|
2501 |
|
2502 |
|
2503 |
|
2504 /** |
|
2505 * Internal dependencies |
|
2506 */ |
|
2507 |
|
2508 |
|
2509 /** |
|
2510 * A Higher Order Component used to be provide a unique instance ID by |
|
2511 * component. |
|
2512 */ |
|
2513 |
|
2514 const withInstanceId = create_higher_order_component(WrappedComponent => { |
|
2515 return props => { |
|
2516 const instanceId = useInstanceId(WrappedComponent); // @ts-ignore |
|
2517 |
|
2518 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, props, { |
|
2519 instanceId: instanceId |
|
2520 })); |
|
2521 }; |
|
2522 }, 'withInstanceId'); |
|
2523 /* harmony default export */ var with_instance_id = (withInstanceId); |
|
2524 |
|
2525 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-safe-timeout/index.js |
|
2526 |
|
2527 |
|
2528 /** |
|
2529 * External dependencies |
|
2530 */ |
|
2531 |
|
2532 |
|
2533 /** |
|
2534 * WordPress dependencies |
|
2535 */ |
|
2536 |
|
2537 /** |
|
2538 * Internal dependencies |
|
2539 */ |
|
2540 |
|
2541 |
|
2542 /** |
|
2543 * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']` |
|
2544 * types here because those functions include functionality that is not handled |
|
2545 * by this component, like the ability to pass extra arguments. |
|
2546 * |
|
2547 * In the case of this component, we only handle the simplest case where |
|
2548 * `setTimeout` only accepts a function (not a string) and an optional delay. |
|
2549 */ |
|
2550 |
|
2551 /** |
|
2552 * A higher-order component used to provide and manage delayed function calls |
|
2553 * that ought to be bound to a component's lifecycle. |
|
2554 */ |
|
2555 const withSafeTimeout = create_higher_order_component(OriginalComponent => { |
|
2556 return class WrappedComponent extends external_wp_element_namespaceObject.Component { |
|
2557 constructor(props) { |
|
2558 super(props); |
|
2559 this.timeouts = []; |
|
2560 this.setTimeout = this.setTimeout.bind(this); |
|
2561 this.clearTimeout = this.clearTimeout.bind(this); |
|
2562 } |
|
2563 |
|
2564 componentWillUnmount() { |
|
2565 this.timeouts.forEach(clearTimeout); |
|
2566 } |
|
2567 |
|
2568 setTimeout(fn, delay) { |
|
2569 const id = setTimeout(() => { |
|
2570 fn(); |
|
2571 this.clearTimeout(id); |
|
2572 }, delay); |
|
2573 this.timeouts.push(id); |
|
2574 return id; |
|
2575 } |
|
2576 |
|
2577 clearTimeout(id) { |
|
2578 clearTimeout(id); |
|
2579 this.timeouts = (0,external_lodash_namespaceObject.without)(this.timeouts, id); |
|
2580 } |
|
2581 |
|
2582 render() { |
|
2583 const props = { ...this.props, |
|
2584 setTimeout: this.setTimeout, |
|
2585 clearTimeout: this.clearTimeout |
|
2586 }; |
|
2587 return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, props); |
|
2588 } |
|
2589 |
|
2590 }; |
|
2591 }, 'withSafeTimeout'); |
|
2592 /* harmony default export */ var with_safe_timeout = (withSafeTimeout); |
|
2593 |
|
2594 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-state/index.js |
|
2595 |
|
2596 |
|
2597 |
|
2598 /** |
|
2599 * WordPress dependencies |
|
2600 */ |
|
2601 |
|
2602 |
|
2603 /** |
|
2604 * Internal dependencies |
|
2605 */ |
|
2606 |
|
2607 |
|
2608 /** |
|
2609 * A Higher Order Component used to provide and manage internal component state |
|
2610 * via props. |
|
2611 * |
|
2612 * @deprecated Use `useState` instead. |
|
2613 * |
|
2614 * @param {any} initialState Optional initial state of the component. |
|
2615 * |
|
2616 * @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. |
|
2617 */ |
|
2618 |
|
2619 function withState() { |
|
2620 let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2621 external_wp_deprecated_default()('wp.compose.withState', { |
|
2622 since: '5.8', |
|
2623 alternative: 'wp.element.useState' |
|
2624 }); |
|
2625 return create_higher_order_component(OriginalComponent => { |
|
2626 return class WrappedComponent extends external_wp_element_namespaceObject.Component { |
|
2627 constructor( |
|
2628 /** @type {any} */ |
|
2629 props) { |
|
2630 super(props); |
|
2631 this.setState = this.setState.bind(this); |
|
2632 this.state = initialState; |
|
2633 } |
|
2634 |
|
2635 render() { |
|
2636 return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, this.props, this.state, { |
|
2637 setState: this.setState |
|
2638 })); |
|
2639 } |
|
2640 |
|
2641 }; |
|
2642 }, 'withState'); |
|
2643 } |
|
2644 |
|
2645 ;// CONCATENATED MODULE: external ["wp","keycodes"] |
|
2646 var external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; |
|
2647 ;// CONCATENATED MODULE: external ["wp","dom"] |
|
2648 var external_wp_dom_namespaceObject = window["wp"]["dom"]; |
|
2649 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-ref-effect/index.js |
|
2650 /** |
|
2651 * External dependencies |
|
2652 */ |
|
2653 |
|
2654 /** |
|
2655 * WordPress dependencies |
|
2656 */ |
|
2657 |
|
2658 /** |
|
2659 * Effect-like ref callback. Just like with `useEffect`, this allows you to |
|
2660 * return a cleanup function to be run if the ref changes or one of the |
|
2661 * dependencies changes. The ref is provided as an argument to the callback |
|
2662 * functions. The main difference between this and `useEffect` is that |
|
2663 * the `useEffect` callback is not called when the ref changes, but this is. |
|
2664 * Pass the returned ref callback as the component's ref and merge multiple refs |
|
2665 * with `useMergeRefs`. |
|
2666 * |
|
2667 * It's worth noting that if the dependencies array is empty, there's not |
|
2668 * strictly a need to clean up event handlers for example, because the node is |
|
2669 * to be removed. It *is* necessary if you add dependencies because the ref |
|
2670 * callback will be called multiple times for the same node. |
|
2671 * |
|
2672 * @param callback Callback with ref as argument. |
|
2673 * @param dependencies Dependencies of the callback. |
|
2674 * |
|
2675 * @return Ref callback. |
|
2676 */ |
|
2677 |
|
2678 function useRefEffect(callback, dependencies) { |
|
2679 const cleanup = (0,external_wp_element_namespaceObject.useRef)(); |
|
2680 return (0,external_wp_element_namespaceObject.useCallback)(node => { |
|
2681 if (node) { |
|
2682 cleanup.current = callback(node); |
|
2683 } else if (cleanup.current) { |
|
2684 cleanup.current(); |
|
2685 } |
|
2686 }, dependencies); |
|
2687 } |
|
2688 |
|
2689 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-constrained-tabbing/index.js |
|
2690 /** |
|
2691 * WordPress dependencies |
|
2692 */ |
|
2693 |
|
2694 |
|
2695 /** |
|
2696 * Internal dependencies |
|
2697 */ |
|
2698 |
|
2699 |
|
2700 /** |
|
2701 * In Dialogs/modals, the tabbing must be constrained to the content of |
|
2702 * the wrapper element. This hook adds the behavior to the returned ref. |
|
2703 * |
|
2704 * @return {import('react').RefCallback<Element>} Element Ref. |
|
2705 * |
|
2706 * @example |
|
2707 * ```js |
|
2708 * import { useConstrainedTabbing } from '@wordpress/compose'; |
|
2709 * |
|
2710 * const ConstrainedTabbingExample = () => { |
|
2711 * const constrainedTabbingRef = useConstrainedTabbing() |
|
2712 * return ( |
|
2713 * <div ref={ constrainedTabbingRef }> |
|
2714 * <Button /> |
|
2715 * <Button /> |
|
2716 * </div> |
|
2717 * ); |
|
2718 * } |
|
2719 * ``` |
|
2720 */ |
|
2721 |
|
2722 function useConstrainedTabbing() { |
|
2723 return useRefEffect(( |
|
2724 /** @type {HTMLElement} */ |
|
2725 node) => { |
|
2726 /** @type {number|undefined} */ |
|
2727 let timeoutId; |
|
2728 |
|
2729 function onKeyDown( |
|
2730 /** @type {KeyboardEvent} */ |
|
2731 event) { |
|
2732 const { |
|
2733 keyCode, |
|
2734 shiftKey, |
|
2735 target |
|
2736 } = event; |
|
2737 |
|
2738 if (keyCode !== external_wp_keycodes_namespaceObject.TAB) { |
|
2739 return; |
|
2740 } |
|
2741 |
|
2742 const action = shiftKey ? 'findPrevious' : 'findNext'; |
|
2743 const nextElement = external_wp_dom_namespaceObject.focus.tabbable[action]( |
|
2744 /** @type {HTMLElement} */ |
|
2745 target) || null; // If the element that is about to receive focus is outside the |
|
2746 // area, move focus to a div and insert it at the start or end of |
|
2747 // the area, depending on the direction. Without preventing default |
|
2748 // behaviour, the browser will then move focus to the next element. |
|
2749 |
|
2750 if (node.contains(nextElement)) { |
|
2751 return; |
|
2752 } |
|
2753 |
|
2754 const domAction = shiftKey ? 'append' : 'prepend'; |
|
2755 const { |
|
2756 ownerDocument |
|
2757 } = node; |
|
2758 const trap = ownerDocument.createElement('div'); |
|
2759 trap.tabIndex = -1; |
|
2760 node[domAction](trap); |
|
2761 trap.focus(); // Remove after the browser moves focus to the next element. |
|
2762 |
|
2763 timeoutId = setTimeout(() => node.removeChild(trap)); |
|
2764 } |
|
2765 |
|
2766 node.addEventListener('keydown', onKeyDown); |
|
2767 return () => { |
|
2768 node.removeEventListener('keydown', onKeyDown); |
|
2769 clearTimeout(timeoutId); |
|
2770 }; |
|
2771 }, []); |
|
2772 } |
|
2773 |
|
2774 /* harmony default export */ var use_constrained_tabbing = (useConstrainedTabbing); |
|
2775 |
|
2776 // EXTERNAL MODULE: ./node_modules/clipboard/dist/clipboard.js |
|
2777 var dist_clipboard = __webpack_require__(8294); |
|
2778 var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard); |
|
2779 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-on-click/index.js |
|
2780 /** |
|
2781 * External dependencies |
|
2782 */ |
|
2783 |
|
2784 /** |
|
2785 * WordPress dependencies |
|
2786 */ |
|
2787 |
|
2788 |
|
2789 |
|
2790 /* eslint-disable jsdoc/no-undefined-types */ |
|
2791 |
|
2792 /** |
|
2793 * Copies the text to the clipboard when the element is clicked. |
|
2794 * |
|
2795 * @deprecated |
|
2796 * |
|
2797 * @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element. |
|
2798 * @param {string|Function} text The text to copy. |
|
2799 * @param {number} [timeout] Optional timeout to reset the returned |
|
2800 * state. 4 seconds by default. |
|
2801 * |
|
2802 * @return {boolean} Whether or not the text has been copied. Resets after the |
|
2803 * timeout. |
|
2804 */ |
|
2805 |
|
2806 function useCopyOnClick(ref, text) { |
|
2807 let timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4000; |
|
2808 |
|
2809 /* eslint-enable jsdoc/no-undefined-types */ |
|
2810 external_wp_deprecated_default()('wp.compose.useCopyOnClick', { |
|
2811 since: '5.8', |
|
2812 alternative: 'wp.compose.useCopyToClipboard' |
|
2813 }); |
|
2814 /** @type {import('react').MutableRefObject<Clipboard | undefined>} */ |
|
2815 |
|
2816 const clipboard = (0,external_wp_element_namespaceObject.useRef)(); |
|
2817 const [hasCopied, setHasCopied] = (0,external_wp_element_namespaceObject.useState)(false); |
|
2818 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
2819 /** @type {number | undefined} */ |
|
2820 let timeoutId; |
|
2821 |
|
2822 if (!ref.current) { |
|
2823 return; |
|
2824 } // Clipboard listens to click events. |
|
2825 |
|
2826 |
|
2827 clipboard.current = new (clipboard_default())(ref.current, { |
|
2828 text: () => typeof text === 'function' ? text() : text |
|
2829 }); |
|
2830 clipboard.current.on('success', _ref => { |
|
2831 let { |
|
2832 clearSelection, |
|
2833 trigger |
|
2834 } = _ref; |
|
2835 // Clearing selection will move focus back to the triggering button, |
|
2836 // ensuring that it is not reset to the body, and further that it is |
|
2837 // kept within the rendered node. |
|
2838 clearSelection(); // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680 |
|
2839 |
|
2840 if (trigger) { |
|
2841 /** @type {HTMLElement} */ |
|
2842 trigger.focus(); |
|
2843 } |
|
2844 |
|
2845 if (timeout) { |
|
2846 setHasCopied(true); |
|
2847 clearTimeout(timeoutId); |
|
2848 timeoutId = setTimeout(() => setHasCopied(false), timeout); |
|
2849 } |
|
2850 }); |
|
2851 return () => { |
|
2852 if (clipboard.current) { |
|
2853 clipboard.current.destroy(); |
|
2854 } |
|
2855 |
|
2856 clearTimeout(timeoutId); |
|
2857 }; |
|
2858 }, [text, timeout, setHasCopied]); |
|
2859 return hasCopied; |
|
2860 } |
|
2861 |
|
2862 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-to-clipboard/index.js |
|
2863 /** |
|
2864 * External dependencies |
|
2865 */ |
|
2866 |
|
2867 /** |
|
2868 * WordPress dependencies |
|
2869 */ |
|
2870 |
|
2871 |
|
2872 /** |
|
2873 * Internal dependencies |
|
2874 */ |
|
2875 |
|
2876 |
|
2877 /** |
|
2878 * @template T |
|
2879 * @param {T} value |
|
2880 * @return {import('react').RefObject<T>} The updated ref |
|
2881 */ |
|
2882 |
|
2883 function useUpdatedRef(value) { |
|
2884 const ref = (0,external_wp_element_namespaceObject.useRef)(value); |
|
2885 ref.current = value; |
|
2886 return ref; |
|
2887 } |
|
2888 /** |
|
2889 * Copies the given text to the clipboard when the element is clicked. |
|
2890 * |
|
2891 * @template {HTMLElement} TElementType |
|
2892 * @param {string | (() => string)} text The text to copy. Use a function if not |
|
2893 * already available and expensive to compute. |
|
2894 * @param {Function} onSuccess Called when to text is copied. |
|
2895 * |
|
2896 * @return {import('react').Ref<TElementType>} A ref to assign to the target element. |
|
2897 */ |
|
2898 |
|
2899 |
|
2900 function useCopyToClipboard(text, onSuccess) { |
|
2901 // Store the dependencies as refs and continuesly update them so they're |
|
2902 // fresh when the callback is called. |
|
2903 const textRef = useUpdatedRef(text); |
|
2904 const onSuccessRef = useUpdatedRef(onSuccess); |
|
2905 return useRefEffect(node => { |
|
2906 // Clipboard listens to click events. |
|
2907 const clipboard = new (clipboard_default())(node, { |
|
2908 text() { |
|
2909 return typeof textRef.current === 'function' ? textRef.current() : textRef.current || ''; |
|
2910 } |
|
2911 |
|
2912 }); |
|
2913 clipboard.on('success', _ref => { |
|
2914 let { |
|
2915 clearSelection |
|
2916 } = _ref; |
|
2917 // Clearing selection will move focus back to the triggering |
|
2918 // button, ensuring that it is not reset to the body, and |
|
2919 // further that it is kept within the rendered node. |
|
2920 clearSelection(); // Handle ClipboardJS focus bug, see |
|
2921 // https://github.com/zenorocha/clipboard.js/issues/680 |
|
2922 |
|
2923 node.focus(); |
|
2924 |
|
2925 if (onSuccessRef.current) { |
|
2926 onSuccessRef.current(); |
|
2927 } |
|
2928 }); |
|
2929 return () => { |
|
2930 clipboard.destroy(); |
|
2931 }; |
|
2932 }, []); |
|
2933 } |
|
2934 |
|
2935 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-on-mount/index.js |
|
2936 /** |
|
2937 * WordPress dependencies |
|
2938 */ |
|
2939 |
|
2940 |
|
2941 /** |
|
2942 * Hook used to focus the first tabbable element on mount. |
|
2943 * |
|
2944 * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode. |
|
2945 * @return {import('react').RefCallback<HTMLElement>} Ref callback. |
|
2946 * |
|
2947 * @example |
|
2948 * ```js |
|
2949 * import { useFocusOnMount } from '@wordpress/compose'; |
|
2950 * |
|
2951 * const WithFocusOnMount = () => { |
|
2952 * const ref = useFocusOnMount() |
|
2953 * return ( |
|
2954 * <div ref={ ref }> |
|
2955 * <Button /> |
|
2956 * <Button /> |
|
2957 * </div> |
|
2958 * ); |
|
2959 * } |
|
2960 * ``` |
|
2961 */ |
|
2962 |
|
2963 function useFocusOnMount() { |
|
2964 let focusOnMount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'firstElement'; |
|
2965 const focusOnMountRef = (0,external_wp_element_namespaceObject.useRef)(focusOnMount); |
|
2966 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
2967 focusOnMountRef.current = focusOnMount; |
|
2968 }, [focusOnMount]); |
|
2969 return (0,external_wp_element_namespaceObject.useCallback)(node => { |
|
2970 var _node$ownerDocument$a, _node$ownerDocument; |
|
2971 |
|
2972 if (!node || focusOnMountRef.current === false) { |
|
2973 return; |
|
2974 } |
|
2975 |
|
2976 if (node.contains((_node$ownerDocument$a = (_node$ownerDocument = node.ownerDocument) === null || _node$ownerDocument === void 0 ? void 0 : _node$ownerDocument.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) { |
|
2977 return; |
|
2978 } |
|
2979 |
|
2980 let target = node; |
|
2981 |
|
2982 if (focusOnMountRef.current === 'firstElement') { |
|
2983 const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0]; |
|
2984 |
|
2985 if (firstTabbable) { |
|
2986 target = |
|
2987 /** @type {HTMLElement} */ |
|
2988 firstTabbable; |
|
2989 } |
|
2990 } |
|
2991 |
|
2992 target.focus(); |
|
2993 }, []); |
|
2994 } |
|
2995 |
|
2996 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-return/index.js |
|
2997 /** |
|
2998 * WordPress dependencies |
|
2999 */ |
|
3000 |
|
3001 /** |
|
3002 * When opening modals/sidebars/dialogs, the focus |
|
3003 * must move to the opened area and return to the |
|
3004 * previously focused element when closed. |
|
3005 * The current hook implements the returning behavior. |
|
3006 * |
|
3007 * @param {() => void} [onFocusReturn] Overrides the default return behavior. |
|
3008 * @return {import('react').RefCallback<HTMLElement>} Element Ref. |
|
3009 * |
|
3010 * @example |
|
3011 * ```js |
|
3012 * import { useFocusReturn } from '@wordpress/compose'; |
|
3013 * |
|
3014 * const WithFocusReturn = () => { |
|
3015 * const ref = useFocusReturn() |
|
3016 * return ( |
|
3017 * <div ref={ ref }> |
|
3018 * <Button /> |
|
3019 * <Button /> |
|
3020 * </div> |
|
3021 * ); |
|
3022 * } |
|
3023 * ``` |
|
3024 */ |
|
3025 |
|
3026 function useFocusReturn(onFocusReturn) { |
|
3027 /** @type {import('react').MutableRefObject<null | HTMLElement>} */ |
|
3028 const ref = (0,external_wp_element_namespaceObject.useRef)(null); |
|
3029 /** @type {import('react').MutableRefObject<null | Element>} */ |
|
3030 |
|
3031 const focusedBeforeMount = (0,external_wp_element_namespaceObject.useRef)(null); |
|
3032 const onFocusReturnRef = (0,external_wp_element_namespaceObject.useRef)(onFocusReturn); |
|
3033 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3034 onFocusReturnRef.current = onFocusReturn; |
|
3035 }, [onFocusReturn]); |
|
3036 return (0,external_wp_element_namespaceObject.useCallback)(node => { |
|
3037 if (node) { |
|
3038 // Set ref to be used when unmounting. |
|
3039 ref.current = node; // Only set when the node mounts. |
|
3040 |
|
3041 if (focusedBeforeMount.current) { |
|
3042 return; |
|
3043 } |
|
3044 |
|
3045 focusedBeforeMount.current = node.ownerDocument.activeElement; |
|
3046 } else if (focusedBeforeMount.current) { |
|
3047 var _ref$current, _ref$current2, _ref$current3; |
|
3048 |
|
3049 const isFocused = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.contains((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.ownerDocument.activeElement); |
|
3050 |
|
3051 if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.isConnected && !isFocused) { |
|
3052 return; |
|
3053 } // Defer to the component's own explicit focus return behavior, if |
|
3054 // specified. This allows for support that the `onFocusReturn` |
|
3055 // decides to allow the default behavior to occur under some |
|
3056 // conditions. |
|
3057 |
|
3058 |
|
3059 if (onFocusReturnRef.current) { |
|
3060 onFocusReturnRef.current(); |
|
3061 } else { |
|
3062 var _focusedBeforeMount$c; |
|
3063 |
|
3064 /** @type {null | HTMLElement} */ |
|
3065 (_focusedBeforeMount$c = focusedBeforeMount.current) === null || _focusedBeforeMount$c === void 0 ? void 0 : _focusedBeforeMount$c.focus(); |
|
3066 } |
|
3067 } |
|
3068 }, []); |
|
3069 } |
|
3070 |
|
3071 /* harmony default export */ var use_focus_return = (useFocusReturn); |
|
3072 |
|
3073 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-outside/index.js |
|
3074 /** |
|
3075 * External dependencies |
|
3076 */ |
|
3077 |
|
3078 /** |
|
3079 * WordPress dependencies |
|
3080 */ |
|
3081 |
|
3082 |
|
3083 /** |
|
3084 * Input types which are classified as button types, for use in considering |
|
3085 * whether element is a (focus-normalized) button. |
|
3086 * |
|
3087 * @type {string[]} |
|
3088 */ |
|
3089 |
|
3090 const INPUT_BUTTON_TYPES = ['button', 'submit']; |
|
3091 /** |
|
3092 * @typedef {HTMLButtonElement | HTMLLinkElement | HTMLInputElement} FocusNormalizedButton |
|
3093 */ |
|
3094 // Disable reason: Rule doesn't support predicate return types. |
|
3095 |
|
3096 /* eslint-disable jsdoc/valid-types */ |
|
3097 |
|
3098 /** |
|
3099 * Returns true if the given element is a button element subject to focus |
|
3100 * normalization, or false otherwise. |
|
3101 * |
|
3102 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus |
|
3103 * |
|
3104 * @param {EventTarget} eventTarget The target from a mouse or touch event. |
|
3105 * |
|
3106 * @return {eventTarget is FocusNormalizedButton} Whether element is a button. |
|
3107 */ |
|
3108 |
|
3109 function isFocusNormalizedButton(eventTarget) { |
|
3110 if (!(eventTarget instanceof window.HTMLElement)) { |
|
3111 return false; |
|
3112 } |
|
3113 |
|
3114 switch (eventTarget.nodeName) { |
|
3115 case 'A': |
|
3116 case 'BUTTON': |
|
3117 return true; |
|
3118 |
|
3119 case 'INPUT': |
|
3120 return (0,external_lodash_namespaceObject.includes)(INPUT_BUTTON_TYPES, |
|
3121 /** @type {HTMLInputElement} */ |
|
3122 eventTarget.type); |
|
3123 } |
|
3124 |
|
3125 return false; |
|
3126 } |
|
3127 /* eslint-enable jsdoc/valid-types */ |
|
3128 |
|
3129 /** |
|
3130 * @typedef {import('react').SyntheticEvent} SyntheticEvent |
|
3131 */ |
|
3132 |
|
3133 /** |
|
3134 * @callback EventCallback |
|
3135 * @param {SyntheticEvent} event input related event. |
|
3136 */ |
|
3137 |
|
3138 /** |
|
3139 * @typedef FocusOutsideReactElement |
|
3140 * @property {EventCallback} handleFocusOutside callback for a focus outside event. |
|
3141 */ |
|
3142 |
|
3143 /** |
|
3144 * @typedef {import('react').MutableRefObject<FocusOutsideReactElement | undefined>} FocusOutsideRef |
|
3145 */ |
|
3146 |
|
3147 /** |
|
3148 * @typedef {Object} FocusOutsideReturnValue |
|
3149 * @property {EventCallback} onFocus An event handler for focus events. |
|
3150 * @property {EventCallback} onBlur An event handler for blur events. |
|
3151 * @property {EventCallback} onMouseDown An event handler for mouse down events. |
|
3152 * @property {EventCallback} onMouseUp An event handler for mouse up events. |
|
3153 * @property {EventCallback} onTouchStart An event handler for touch start events. |
|
3154 * @property {EventCallback} onTouchEnd An event handler for touch end events. |
|
3155 */ |
|
3156 |
|
3157 /** |
|
3158 * A react hook that can be used to check whether focus has moved outside the |
|
3159 * element the event handlers are bound to. |
|
3160 * |
|
3161 * @param {EventCallback} onFocusOutside A callback triggered when focus moves outside |
|
3162 * the element the event handlers are bound to. |
|
3163 * |
|
3164 * @return {FocusOutsideReturnValue} An object containing event handlers. Bind the event handlers |
|
3165 * to a wrapping element element to capture when focus moves |
|
3166 * outside that element. |
|
3167 */ |
|
3168 |
|
3169 |
|
3170 function useFocusOutside(onFocusOutside) { |
|
3171 const currentOnFocusOutside = (0,external_wp_element_namespaceObject.useRef)(onFocusOutside); |
|
3172 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3173 currentOnFocusOutside.current = onFocusOutside; |
|
3174 }, [onFocusOutside]); |
|
3175 const preventBlurCheck = (0,external_wp_element_namespaceObject.useRef)(false); |
|
3176 /** |
|
3177 * @type {import('react').MutableRefObject<number | undefined>} |
|
3178 */ |
|
3179 |
|
3180 const blurCheckTimeoutId = (0,external_wp_element_namespaceObject.useRef)(); |
|
3181 /** |
|
3182 * Cancel a blur check timeout. |
|
3183 */ |
|
3184 |
|
3185 const cancelBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(() => { |
|
3186 clearTimeout(blurCheckTimeoutId.current); |
|
3187 }, []); // Cancel blur checks on unmount. |
|
3188 |
|
3189 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3190 return () => cancelBlurCheck(); |
|
3191 }, []); // Cancel a blur check if the callback or ref is no longer provided. |
|
3192 |
|
3193 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3194 if (!onFocusOutside) { |
|
3195 cancelBlurCheck(); |
|
3196 } |
|
3197 }, [onFocusOutside, cancelBlurCheck]); |
|
3198 /** |
|
3199 * Handles a mousedown or mouseup event to respectively assign and |
|
3200 * unassign a flag for preventing blur check on button elements. Some |
|
3201 * browsers, namely Firefox and Safari, do not emit a focus event on |
|
3202 * button elements when clicked, while others do. The logic here |
|
3203 * intends to normalize this as treating click on buttons as focus. |
|
3204 * |
|
3205 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus |
|
3206 * |
|
3207 * @param {SyntheticEvent} event Event for mousedown or mouseup. |
|
3208 */ |
|
3209 |
|
3210 const normalizeButtonFocus = (0,external_wp_element_namespaceObject.useCallback)(event => { |
|
3211 const { |
|
3212 type, |
|
3213 target |
|
3214 } = event; |
|
3215 const isInteractionEnd = (0,external_lodash_namespaceObject.includes)(['mouseup', 'touchend'], type); |
|
3216 |
|
3217 if (isInteractionEnd) { |
|
3218 preventBlurCheck.current = false; |
|
3219 } else if (isFocusNormalizedButton(target)) { |
|
3220 preventBlurCheck.current = true; |
|
3221 } |
|
3222 }, []); |
|
3223 /** |
|
3224 * A callback triggered when a blur event occurs on the element the handler |
|
3225 * is bound to. |
|
3226 * |
|
3227 * Calls the `onFocusOutside` callback in an immediate timeout if focus has |
|
3228 * move outside the bound element and is still within the document. |
|
3229 * |
|
3230 * @param {SyntheticEvent} event Blur event. |
|
3231 */ |
|
3232 |
|
3233 const queueBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(event => { |
|
3234 // React does not allow using an event reference asynchronously |
|
3235 // due to recycling behavior, except when explicitly persisted. |
|
3236 event.persist(); // Skip blur check if clicking button. See `normalizeButtonFocus`. |
|
3237 |
|
3238 if (preventBlurCheck.current) { |
|
3239 return; |
|
3240 } |
|
3241 |
|
3242 blurCheckTimeoutId.current = setTimeout(() => { |
|
3243 // If document is not focused then focus should remain |
|
3244 // inside the wrapped component and therefore we cancel |
|
3245 // this blur event thereby leaving focus in place. |
|
3246 // https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus. |
|
3247 if (!document.hasFocus()) { |
|
3248 event.preventDefault(); |
|
3249 return; |
|
3250 } |
|
3251 |
|
3252 if ('function' === typeof currentOnFocusOutside.current) { |
|
3253 currentOnFocusOutside.current(event); |
|
3254 } |
|
3255 }, 0); |
|
3256 }, []); |
|
3257 return { |
|
3258 onFocus: cancelBlurCheck, |
|
3259 onMouseDown: normalizeButtonFocus, |
|
3260 onMouseUp: normalizeButtonFocus, |
|
3261 onTouchStart: normalizeButtonFocus, |
|
3262 onTouchEnd: normalizeButtonFocus, |
|
3263 onBlur: queueBlurCheck |
|
3264 }; |
|
3265 } |
|
3266 |
|
3267 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-merge-refs/index.js |
|
3268 /** |
|
3269 * WordPress dependencies |
|
3270 */ |
|
3271 |
|
3272 /* eslint-disable jsdoc/valid-types */ |
|
3273 |
|
3274 /** |
|
3275 * @template T |
|
3276 * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef |
|
3277 */ |
|
3278 |
|
3279 /* eslint-enable jsdoc/valid-types */ |
|
3280 |
|
3281 /** |
|
3282 * @template T |
|
3283 * @param {import('react').Ref<T>} ref |
|
3284 * @param {T} value |
|
3285 */ |
|
3286 |
|
3287 function assignRef(ref, value) { |
|
3288 if (typeof ref === 'function') { |
|
3289 ref(value); |
|
3290 } else if (ref && ref.hasOwnProperty('current')) { |
|
3291 /* eslint-disable jsdoc/no-undefined-types */ |
|
3292 |
|
3293 /** @type {import('react').MutableRefObject<T>} */ |
|
3294 ref.current = value; |
|
3295 /* eslint-enable jsdoc/no-undefined-types */ |
|
3296 } |
|
3297 } |
|
3298 /** |
|
3299 * Merges refs into one ref callback. |
|
3300 * |
|
3301 * It also ensures that the merged ref callbacks are only called when they |
|
3302 * change (as a result of a `useCallback` dependency update) OR when the ref |
|
3303 * value changes, just as React does when passing a single ref callback to the |
|
3304 * component. |
|
3305 * |
|
3306 * As expected, if you pass a new function on every render, the ref callback |
|
3307 * will be called after every render. |
|
3308 * |
|
3309 * If you don't wish a ref callback to be called after every render, wrap it |
|
3310 * with `useCallback( callback, dependencies )`. When a dependency changes, the |
|
3311 * old ref callback will be called with `null` and the new ref callback will be |
|
3312 * called with the same value. |
|
3313 * |
|
3314 * To make ref callbacks easier to use, you can also pass the result of |
|
3315 * `useRefEffect`, which makes cleanup easier by allowing you to return a |
|
3316 * cleanup function instead of handling `null`. |
|
3317 * |
|
3318 * It's also possible to _disable_ a ref (and its behaviour) by simply not |
|
3319 * passing the ref. |
|
3320 * |
|
3321 * ```jsx |
|
3322 * const ref = useRefEffect( ( node ) => { |
|
3323 * node.addEventListener( ... ); |
|
3324 * return () => { |
|
3325 * node.removeEventListener( ... ); |
|
3326 * }; |
|
3327 * }, [ ...dependencies ] ); |
|
3328 * const otherRef = useRef(); |
|
3329 * const mergedRefs useMergeRefs( [ |
|
3330 * enabled && ref, |
|
3331 * otherRef, |
|
3332 * ] ); |
|
3333 * return <div ref={ mergedRefs } />; |
|
3334 * ``` |
|
3335 * |
|
3336 * @template {import('react').Ref<any>} TRef |
|
3337 * @param {Array<TRef>} refs The refs to be merged. |
|
3338 * |
|
3339 * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback. |
|
3340 */ |
|
3341 |
|
3342 |
|
3343 function useMergeRefs(refs) { |
|
3344 const element = (0,external_wp_element_namespaceObject.useRef)(); |
|
3345 const didElementChange = (0,external_wp_element_namespaceObject.useRef)(false); |
|
3346 /* eslint-disable jsdoc/no-undefined-types */ |
|
3347 |
|
3348 /** @type {import('react').MutableRefObject<TRef[]>} */ |
|
3349 |
|
3350 /* eslint-enable jsdoc/no-undefined-types */ |
|
3351 |
|
3352 const previousRefs = (0,external_wp_element_namespaceObject.useRef)([]); |
|
3353 const currentRefs = (0,external_wp_element_namespaceObject.useRef)(refs); // Update on render before the ref callback is called, so the ref callback |
|
3354 // always has access to the current refs. |
|
3355 |
|
3356 currentRefs.current = refs; // If any of the refs change, call the previous ref with `null` and the new |
|
3357 // ref with the node, except when the element changes in the same cycle, in |
|
3358 // which case the ref callbacks will already have been called. |
|
3359 |
|
3360 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
|
3361 if (didElementChange.current === false) { |
|
3362 refs.forEach((ref, index) => { |
|
3363 const previousRef = previousRefs.current[index]; |
|
3364 |
|
3365 if (ref !== previousRef) { |
|
3366 assignRef(previousRef, null); |
|
3367 assignRef(ref, element.current); |
|
3368 } |
|
3369 }); |
|
3370 } |
|
3371 |
|
3372 previousRefs.current = refs; |
|
3373 }, refs); // No dependencies, must be reset after every render so ref callbacks are |
|
3374 // correctly called after a ref change. |
|
3375 |
|
3376 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
|
3377 didElementChange.current = false; |
|
3378 }); // There should be no dependencies so that `callback` is only called when |
|
3379 // the node changes. |
|
3380 |
|
3381 return (0,external_wp_element_namespaceObject.useCallback)(value => { |
|
3382 // Update the element so it can be used when calling ref callbacks on a |
|
3383 // dependency change. |
|
3384 assignRef(element, value); |
|
3385 didElementChange.current = true; // When an element changes, the current ref callback should be called |
|
3386 // with the new element and the previous one with `null`. |
|
3387 |
|
3388 const refsToAssign = value ? currentRefs.current : previousRefs.current; // Update the latest refs. |
|
3389 |
|
3390 for (const ref of refsToAssign) { |
|
3391 assignRef(ref, value); |
|
3392 } |
|
3393 }, []); |
|
3394 } |
|
3395 |
|
3396 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dialog/index.js |
|
3397 /** |
|
3398 * WordPress dependencies |
|
3399 */ |
|
3400 |
|
3401 |
|
3402 /** |
|
3403 * Internal dependencies |
|
3404 */ |
|
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 /* eslint-disable jsdoc/valid-types */ |
|
3412 |
|
3413 /** |
|
3414 * @typedef DialogOptions |
|
3415 * @property {Parameters<useFocusOnMount>[0]} focusOnMount Focus on mount arguments. |
|
3416 * @property {() => void} onClose Function to call when the dialog is closed. |
|
3417 */ |
|
3418 |
|
3419 /* eslint-enable jsdoc/valid-types */ |
|
3420 |
|
3421 /** |
|
3422 * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors: |
|
3423 * - constrained tabbing. |
|
3424 * - focus on mount. |
|
3425 * - return focus on unmount. |
|
3426 * - focus outside. |
|
3427 * |
|
3428 * @param {DialogOptions} options Dialog Options. |
|
3429 */ |
|
3430 |
|
3431 function useDialog(options) { |
|
3432 /** |
|
3433 * @type {import('react').MutableRefObject<DialogOptions | undefined>} |
|
3434 */ |
|
3435 const currentOptions = (0,external_wp_element_namespaceObject.useRef)(); |
|
3436 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3437 currentOptions.current = options; |
|
3438 }, Object.values(options)); |
|
3439 const constrainedTabbingRef = use_constrained_tabbing(); |
|
3440 const focusOnMountRef = useFocusOnMount(options.focusOnMount); |
|
3441 const focusReturnRef = use_focus_return(); |
|
3442 const focusOutsideProps = useFocusOutside(event => { |
|
3443 var _currentOptions$curre, _currentOptions$curre2; |
|
3444 |
|
3445 // This unstable prop is here only to manage backward compatibility |
|
3446 // for the Popover component otherwise, the onClose should be enough. |
|
3447 // @ts-ignore unstable property |
|
3448 if ((_currentOptions$curre = currentOptions.current) !== null && _currentOptions$curre !== void 0 && _currentOptions$curre.__unstableOnClose) { |
|
3449 // @ts-ignore unstable property |
|
3450 currentOptions.current.__unstableOnClose('focus-outside', event); |
|
3451 } else if ((_currentOptions$curre2 = currentOptions.current) !== null && _currentOptions$curre2 !== void 0 && _currentOptions$curre2.onClose) { |
|
3452 currentOptions.current.onClose(); |
|
3453 } |
|
3454 }); |
|
3455 const closeOnEscapeRef = (0,external_wp_element_namespaceObject.useCallback)(node => { |
|
3456 if (!node) { |
|
3457 return; |
|
3458 } |
|
3459 |
|
3460 node.addEventListener('keydown', ( |
|
3461 /** @type {KeyboardEvent} */ |
|
3462 event) => { |
|
3463 var _currentOptions$curre3; |
|
3464 |
|
3465 // Close on escape. |
|
3466 if (event.keyCode === external_wp_keycodes_namespaceObject.ESCAPE && !event.defaultPrevented && (_currentOptions$curre3 = currentOptions.current) !== null && _currentOptions$curre3 !== void 0 && _currentOptions$curre3.onClose) { |
|
3467 event.preventDefault(); |
|
3468 currentOptions.current.onClose(); |
|
3469 } |
|
3470 }); |
|
3471 }, []); |
|
3472 return [useMergeRefs([options.focusOnMount !== false ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), { ...focusOutsideProps, |
|
3473 tabIndex: '-1' |
|
3474 }]; |
|
3475 } |
|
3476 |
|
3477 /* harmony default export */ var use_dialog = (useDialog); |
|
3478 |
|
3479 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-disabled/index.js |
|
3480 /** |
|
3481 * External dependencies |
|
3482 */ |
|
3483 |
|
3484 /** |
|
3485 * WordPress dependencies |
|
3486 */ |
|
3487 |
|
3488 |
|
3489 |
|
3490 /** |
|
3491 * Names of control nodes which qualify for disabled behavior. |
|
3492 * |
|
3493 * See WHATWG HTML Standard: 4.10.18.5: "Enabling and disabling form controls: the disabled attribute". |
|
3494 * |
|
3495 * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute |
|
3496 * |
|
3497 * @type {string[]} |
|
3498 */ |
|
3499 |
|
3500 const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP', 'OPTION', 'SELECT', 'TEXTAREA']; |
|
3501 /** |
|
3502 * In some circumstances, such as block previews, all focusable DOM elements |
|
3503 * (input fields, links, buttons, etc.) need to be disabled. This hook adds the |
|
3504 * behavior to disable nested DOM elements to the returned ref. |
|
3505 * |
|
3506 * @return {import('react').RefObject<HTMLElement>} Element Ref. |
|
3507 * |
|
3508 * @example |
|
3509 * ```js |
|
3510 * import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose'; |
|
3511 * const DisabledExample = () => { |
|
3512 * const disabledRef = useDisabled(); |
|
3513 * return ( |
|
3514 * <div ref={ disabledRef }> |
|
3515 * <a href="#">This link will have tabindex set to -1</a> |
|
3516 * <input placeholder="This input will have the disabled attribute added to it." type="text" /> |
|
3517 * </div> |
|
3518 * ); |
|
3519 * }; |
|
3520 * ``` |
|
3521 */ |
|
3522 |
|
3523 function useDisabled() { |
|
3524 /** @type {import('react').RefObject<HTMLElement>} */ |
|
3525 const node = (0,external_wp_element_namespaceObject.useRef)(null); |
|
3526 |
|
3527 const disable = () => { |
|
3528 if (!node.current) { |
|
3529 return; |
|
3530 } |
|
3531 |
|
3532 external_wp_dom_namespaceObject.focus.focusable.find(node.current).forEach(focusable => { |
|
3533 if ((0,external_lodash_namespaceObject.includes)(DISABLED_ELIGIBLE_NODE_NAMES, focusable.nodeName)) { |
|
3534 focusable.setAttribute('disabled', ''); |
|
3535 } |
|
3536 |
|
3537 if (focusable.nodeName === 'A') { |
|
3538 focusable.setAttribute('tabindex', '-1'); |
|
3539 } |
|
3540 |
|
3541 const tabIndex = focusable.getAttribute('tabindex'); |
|
3542 |
|
3543 if (tabIndex !== null && tabIndex !== '-1') { |
|
3544 focusable.removeAttribute('tabindex'); |
|
3545 } |
|
3546 |
|
3547 if (focusable.hasAttribute('contenteditable')) { |
|
3548 focusable.setAttribute('contenteditable', 'false'); |
|
3549 } |
|
3550 }); |
|
3551 }; // Debounce re-disable since disabling process itself will incur |
|
3552 // additional mutations which should be ignored. |
|
3553 |
|
3554 |
|
3555 const debouncedDisable = (0,external_wp_element_namespaceObject.useCallback)((0,external_lodash_namespaceObject.debounce)(disable, undefined, { |
|
3556 leading: true |
|
3557 }), []); |
|
3558 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
|
3559 disable(); |
|
3560 /** @type {MutationObserver | undefined} */ |
|
3561 |
|
3562 let observer; |
|
3563 |
|
3564 if (node.current) { |
|
3565 observer = new window.MutationObserver(debouncedDisable); |
|
3566 observer.observe(node.current, { |
|
3567 childList: true, |
|
3568 attributes: true, |
|
3569 subtree: true |
|
3570 }); |
|
3571 } |
|
3572 |
|
3573 return () => { |
|
3574 if (observer) { |
|
3575 observer.disconnect(); |
|
3576 } |
|
3577 |
|
3578 debouncedDisable.cancel(); |
|
3579 }; |
|
3580 }, []); |
|
3581 return node; |
|
3582 } |
|
3583 |
|
3584 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-isomorphic-layout-effect/index.js |
|
3585 /** |
|
3586 * WordPress dependencies |
|
3587 */ |
|
3588 |
|
3589 /** |
|
3590 * Preferred over direct usage of `useLayoutEffect` when supporting |
|
3591 * server rendered components (SSR) because currently React |
|
3592 * throws a warning when using useLayoutEffect in that environment. |
|
3593 */ |
|
3594 |
|
3595 const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_namespaceObject.useLayoutEffect : external_wp_element_namespaceObject.useEffect; |
|
3596 /* harmony default export */ var use_isomorphic_layout_effect = (useIsomorphicLayoutEffect); |
|
3597 |
|
3598 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dragging/index.js |
|
3599 /** |
|
3600 * WordPress dependencies |
|
3601 */ |
|
3602 |
|
3603 /** |
|
3604 * Internal dependencies |
|
3605 */ |
|
3606 |
|
3607 |
|
3608 /** |
|
3609 * @param {Object} props |
|
3610 * @param {(e: MouseEvent) => void} props.onDragStart |
|
3611 * @param {(e: MouseEvent) => void} props.onDragMove |
|
3612 * @param {(e: MouseEvent) => void} props.onDragEnd |
|
3613 */ |
|
3614 |
|
3615 function useDragging(_ref) { |
|
3616 let { |
|
3617 onDragStart, |
|
3618 onDragMove, |
|
3619 onDragEnd |
|
3620 } = _ref; |
|
3621 const [isDragging, setIsDragging] = (0,external_wp_element_namespaceObject.useState)(false); |
|
3622 const eventsRef = (0,external_wp_element_namespaceObject.useRef)({ |
|
3623 onDragStart, |
|
3624 onDragMove, |
|
3625 onDragEnd |
|
3626 }); |
|
3627 use_isomorphic_layout_effect(() => { |
|
3628 eventsRef.current.onDragStart = onDragStart; |
|
3629 eventsRef.current.onDragMove = onDragMove; |
|
3630 eventsRef.current.onDragEnd = onDragEnd; |
|
3631 }, [onDragStart, onDragMove, onDragEnd]); |
|
3632 const onMouseMove = (0,external_wp_element_namespaceObject.useCallback)(( |
|
3633 /** @type {MouseEvent} */ |
|
3634 event) => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), []); |
|
3635 const endDrag = (0,external_wp_element_namespaceObject.useCallback)(( |
|
3636 /** @type {MouseEvent} */ |
|
3637 event) => { |
|
3638 if (eventsRef.current.onDragEnd) { |
|
3639 eventsRef.current.onDragEnd(event); |
|
3640 } |
|
3641 |
|
3642 document.removeEventListener('mousemove', onMouseMove); |
|
3643 document.removeEventListener('mouseup', endDrag); |
|
3644 setIsDragging(false); |
|
3645 }, []); |
|
3646 const startDrag = (0,external_wp_element_namespaceObject.useCallback)(( |
|
3647 /** @type {MouseEvent} */ |
|
3648 event) => { |
|
3649 if (eventsRef.current.onDragStart) { |
|
3650 eventsRef.current.onDragStart(event); |
|
3651 } |
|
3652 |
|
3653 document.addEventListener('mousemove', onMouseMove); |
|
3654 document.addEventListener('mouseup', endDrag); |
|
3655 setIsDragging(true); |
|
3656 }, []); // Remove the global events when unmounting if needed. |
|
3657 |
|
3658 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3659 return () => { |
|
3660 if (isDragging) { |
|
3661 document.removeEventListener('mousemove', onMouseMove); |
|
3662 document.removeEventListener('mouseup', endDrag); |
|
3663 } |
|
3664 }; |
|
3665 }, [isDragging]); |
|
3666 return { |
|
3667 startDrag, |
|
3668 endDrag, |
|
3669 isDragging |
|
3670 }; |
|
3671 } |
|
3672 |
|
3673 // EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js |
|
3674 var mousetrap_mousetrap = __webpack_require__(7973); |
|
3675 var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap); |
|
3676 // EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js |
|
3677 var mousetrap_global_bind = __webpack_require__(5538); |
|
3678 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-keyboard-shortcut/index.js |
|
3679 /** |
|
3680 * External dependencies |
|
3681 */ |
|
3682 |
|
3683 |
|
3684 |
|
3685 /** |
|
3686 * WordPress dependencies |
|
3687 */ |
|
3688 |
|
3689 |
|
3690 /** |
|
3691 * A block selection object. |
|
3692 * |
|
3693 * @typedef {Object} WPKeyboardShortcutConfig |
|
3694 * |
|
3695 * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields. |
|
3696 * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown. |
|
3697 * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true. |
|
3698 * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event. |
|
3699 */ |
|
3700 |
|
3701 /** |
|
3702 * Return true if platform is MacOS. |
|
3703 * |
|
3704 * @param {Window} [_window] window object by default; used for DI testing. |
|
3705 * |
|
3706 * @return {boolean} True if MacOS; false otherwise. |
|
3707 */ |
|
3708 |
|
3709 function isAppleOS() { |
|
3710 let _window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window; |
|
3711 |
|
3712 const { |
|
3713 platform |
|
3714 } = _window.navigator; |
|
3715 return platform.indexOf('Mac') !== -1 || (0,external_lodash_namespaceObject.includes)(['iPad', 'iPhone'], platform); |
|
3716 } |
|
3717 /* eslint-disable jsdoc/valid-types */ |
|
3718 |
|
3719 /** |
|
3720 * Attach a keyboard shortcut handler. |
|
3721 * |
|
3722 * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter. |
|
3723 * |
|
3724 * @param {string[]|string} shortcuts Keyboard Shortcuts. |
|
3725 * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback. |
|
3726 * @param {WPKeyboardShortcutConfig} options Shortcut options. |
|
3727 */ |
|
3728 |
|
3729 |
|
3730 function useKeyboardShortcut( |
|
3731 /* eslint-enable jsdoc/valid-types */ |
|
3732 shortcuts, callback) { |
|
3733 let { |
|
3734 bindGlobal = false, |
|
3735 eventName = 'keydown', |
|
3736 isDisabled = false, |
|
3737 // This is important for performance considerations. |
|
3738 target |
|
3739 } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
|
3740 const currentCallback = (0,external_wp_element_namespaceObject.useRef)(callback); |
|
3741 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3742 currentCallback.current = callback; |
|
3743 }, [callback]); |
|
3744 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3745 if (isDisabled) { |
|
3746 return; |
|
3747 } |
|
3748 |
|
3749 const mousetrap = new (mousetrap_default())(target && target.current ? target.current : // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`. |
|
3750 // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's |
|
3751 // necessary to maintain the existing behavior. |
|
3752 |
|
3753 /** @type {Element} */ |
|
3754 |
|
3755 /** @type {unknown} */ |
|
3756 document); |
|
3757 (0,external_lodash_namespaceObject.castArray)(shortcuts).forEach(shortcut => { |
|
3758 const keys = shortcut.split('+'); // Determines whether a key is a modifier by the length of the string. |
|
3759 // E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that |
|
3760 // the modifiers are Shift and Cmd because they're not a single character. |
|
3761 |
|
3762 const modifiers = new Set(keys.filter(value => value.length > 1)); |
|
3763 const hasAlt = modifiers.has('alt'); |
|
3764 const hasShift = modifiers.has('shift'); // This should be better moved to the shortcut registration instead. |
|
3765 |
|
3766 if (isAppleOS() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) { |
|
3767 throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`); |
|
3768 } |
|
3769 |
|
3770 const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; // @ts-ignore `bindGlobal` is an undocumented property |
|
3771 |
|
3772 mousetrap[bindFn](shortcut, function () { |
|
3773 return ( |
|
3774 /* eslint-enable jsdoc/valid-types */ |
|
3775 currentCallback.current(...arguments) |
|
3776 ); |
|
3777 }, eventName); |
|
3778 }); |
|
3779 return () => { |
|
3780 mousetrap.reset(); |
|
3781 }; |
|
3782 }, [shortcuts, bindGlobal, eventName, target, isDisabled]); |
|
3783 } |
|
3784 |
|
3785 /* harmony default export */ var use_keyboard_shortcut = (useKeyboardShortcut); |
|
3786 |
|
3787 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-media-query/index.js |
|
3788 /** |
|
3789 * WordPress dependencies |
|
3790 */ |
|
3791 |
|
3792 /** |
|
3793 * Runs a media query and returns its value when it changes. |
|
3794 * |
|
3795 * @param {string} [query] Media Query. |
|
3796 * @return {boolean} return value of the media query. |
|
3797 */ |
|
3798 |
|
3799 function useMediaQuery(query) { |
|
3800 const [match, setMatch] = (0,external_wp_element_namespaceObject.useState)(() => !!(query && typeof window !== 'undefined' && window.matchMedia(query).matches)); |
|
3801 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3802 if (!query) { |
|
3803 return; |
|
3804 } |
|
3805 |
|
3806 const updateMatch = () => setMatch(window.matchMedia(query).matches); |
|
3807 |
|
3808 updateMatch(); |
|
3809 const list = window.matchMedia(query); |
|
3810 list.addListener(updateMatch); |
|
3811 return () => { |
|
3812 list.removeListener(updateMatch); |
|
3813 }; |
|
3814 }, [query]); |
|
3815 return !!query && match; |
|
3816 } |
|
3817 |
|
3818 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-previous/index.js |
|
3819 /** |
|
3820 * WordPress dependencies |
|
3821 */ |
|
3822 |
|
3823 /** |
|
3824 * Use something's value from the previous render. |
|
3825 * Based on https://usehooks.com/usePrevious/. |
|
3826 * |
|
3827 * @param value The value to track. |
|
3828 * |
|
3829 * @return The value from the previous render. |
|
3830 */ |
|
3831 |
|
3832 function usePrevious(value) { |
|
3833 const ref = (0,external_wp_element_namespaceObject.useRef)(); // Store current value in ref. |
|
3834 |
|
3835 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
3836 ref.current = value; |
|
3837 }, [value]); // Re-run when value changes. |
|
3838 // Return previous value (happens before update in useEffect above). |
|
3839 |
|
3840 return ref.current; |
|
3841 } |
|
3842 |
|
3843 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-reduced-motion/index.js |
|
3844 /** |
|
3845 * Internal dependencies |
|
3846 */ |
|
3847 |
|
3848 /** |
|
3849 * Hook returning whether the user has a preference for reduced motion. |
|
3850 * |
|
3851 * @return {boolean} Reduced motion preference value. |
|
3852 */ |
|
3853 |
|
3854 const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)'); |
|
3855 |
|
3856 /* harmony default export */ var use_reduced_motion = (useReducedMotion); |
|
3857 |
|
3858 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-viewport-match/index.js |
|
3859 /** |
|
3860 * WordPress dependencies |
|
3861 */ |
|
3862 |
|
3863 /** |
|
3864 * Internal dependencies |
|
3865 */ |
|
3866 |
|
3867 |
|
3868 /** |
|
3869 * @typedef {"huge" | "wide" | "large" | "medium" | "small" | "mobile"} WPBreakpoint |
|
3870 */ |
|
3871 |
|
3872 /** |
|
3873 * Hash of breakpoint names with pixel width at which it becomes effective. |
|
3874 * |
|
3875 * @see _breakpoints.scss |
|
3876 * |
|
3877 * @type {Record<WPBreakpoint, number>} |
|
3878 */ |
|
3879 |
|
3880 const BREAKPOINTS = { |
|
3881 huge: 1440, |
|
3882 wide: 1280, |
|
3883 large: 960, |
|
3884 medium: 782, |
|
3885 small: 600, |
|
3886 mobile: 480 |
|
3887 }; |
|
3888 /** |
|
3889 * @typedef {">=" | "<"} WPViewportOperator |
|
3890 */ |
|
3891 |
|
3892 /** |
|
3893 * Object mapping media query operators to the condition to be used. |
|
3894 * |
|
3895 * @type {Record<WPViewportOperator, string>} |
|
3896 */ |
|
3897 |
|
3898 const CONDITIONS = { |
|
3899 '>=': 'min-width', |
|
3900 '<': 'max-width' |
|
3901 }; |
|
3902 /** |
|
3903 * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values. |
|
3904 * |
|
3905 * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>} |
|
3906 */ |
|
3907 |
|
3908 const OPERATOR_EVALUATORS = { |
|
3909 '>=': (breakpointValue, width) => width >= breakpointValue, |
|
3910 '<': (breakpointValue, width) => width < breakpointValue |
|
3911 }; |
|
3912 const ViewportMatchWidthContext = (0,external_wp_element_namespaceObject.createContext)( |
|
3913 /** @type {null | number} */ |
|
3914 null); |
|
3915 /** |
|
3916 * Returns true if the viewport matches the given query, or false otherwise. |
|
3917 * |
|
3918 * @param {WPBreakpoint} breakpoint Breakpoint size name. |
|
3919 * @param {WPViewportOperator} [operator=">="] Viewport operator. |
|
3920 * |
|
3921 * @example |
|
3922 * |
|
3923 * ```js |
|
3924 * useViewportMatch( 'huge', '<' ); |
|
3925 * useViewportMatch( 'medium' ); |
|
3926 * ``` |
|
3927 * |
|
3928 * @return {boolean} Whether viewport matches query. |
|
3929 */ |
|
3930 |
|
3931 const useViewportMatch = function (breakpoint) { |
|
3932 let operator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '>='; |
|
3933 const simulatedWidth = (0,external_wp_element_namespaceObject.useContext)(ViewportMatchWidthContext); |
|
3934 const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`; |
|
3935 const mediaQueryResult = useMediaQuery(mediaQuery || undefined); |
|
3936 |
|
3937 if (simulatedWidth) { |
|
3938 return OPERATOR_EVALUATORS[operator](BREAKPOINTS[breakpoint], simulatedWidth); |
|
3939 } |
|
3940 |
|
3941 return mediaQueryResult; |
|
3942 }; |
|
3943 |
|
3944 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider; |
|
3945 /* harmony default export */ var use_viewport_match = (useViewportMatch); |
|
3946 |
|
3947 // EXTERNAL MODULE: ./node_modules/react-resize-aware/dist/index.js |
|
3948 var dist = __webpack_require__(235); |
|
3949 var dist_default = /*#__PURE__*/__webpack_require__.n(dist); |
|
3950 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/index.js |
|
3951 /** |
|
3952 * External dependencies |
|
3953 */ |
|
3954 |
|
3955 /** |
|
3956 * Hook which allows to listen the resize event of any target element when it changes sizes. |
|
3957 * _Note: `useResizeObserver` will report `null` until after first render_ |
|
3958 * |
|
3959 * Simply a re-export of `react-resize-aware` so refer to its documentation <https://github.com/FezVrasta/react-resize-aware> |
|
3960 * for more details. |
|
3961 * |
|
3962 * @see https://github.com/FezVrasta/react-resize-aware |
|
3963 * |
|
3964 * @example |
|
3965 * |
|
3966 * ```js |
|
3967 * const App = () => { |
|
3968 * const [ resizeListener, sizes ] = useResizeObserver(); |
|
3969 * |
|
3970 * return ( |
|
3971 * <div> |
|
3972 * { resizeListener } |
|
3973 * Your content here |
|
3974 * </div> |
|
3975 * ); |
|
3976 * }; |
|
3977 * ``` |
|
3978 * |
|
3979 */ |
|
3980 |
|
3981 /* harmony default export */ var use_resize_observer = ((dist_default())); |
|
3982 |
|
3983 ;// CONCATENATED MODULE: external ["wp","priorityQueue"] |
|
3984 var external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; |
|
3985 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-async-list/index.js |
|
3986 /** |
|
3987 * WordPress dependencies |
|
3988 */ |
|
3989 |
|
3990 |
|
3991 |
|
3992 /** |
|
3993 * Returns the first items from list that are present on state. |
|
3994 * |
|
3995 * @param list New array. |
|
3996 * @param state Current state. |
|
3997 * @return First items present iin state. |
|
3998 */ |
|
3999 function getFirstItemsPresentInState(list, state) { |
|
4000 const firstItems = []; |
|
4001 |
|
4002 for (let i = 0; i < list.length; i++) { |
|
4003 const item = list[i]; |
|
4004 |
|
4005 if (!state.includes(item)) { |
|
4006 break; |
|
4007 } |
|
4008 |
|
4009 firstItems.push(item); |
|
4010 } |
|
4011 |
|
4012 return firstItems; |
|
4013 } |
|
4014 /** |
|
4015 * React hook returns an array which items get asynchronously appended from a source array. |
|
4016 * This behavior is useful if we want to render a list of items asynchronously for performance reasons. |
|
4017 * |
|
4018 * @param list Source array. |
|
4019 * @param config Configuration object. |
|
4020 * |
|
4021 * @return Async array. |
|
4022 */ |
|
4023 |
|
4024 |
|
4025 function useAsyncList(list) { |
|
4026 let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
|
4027 step: 1 |
|
4028 }; |
|
4029 const { |
|
4030 step = 1 |
|
4031 } = config; |
|
4032 const [current, setCurrent] = (0,external_wp_element_namespaceObject.useState)([]); |
|
4033 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
4034 // On reset, we keep the first items that were previously rendered. |
|
4035 let firstItems = getFirstItemsPresentInState(list, current); |
|
4036 |
|
4037 if (firstItems.length < step) { |
|
4038 firstItems = firstItems.concat(list.slice(firstItems.length, step)); |
|
4039 } |
|
4040 |
|
4041 setCurrent(firstItems); |
|
4042 let nextIndex = firstItems.length; |
|
4043 const asyncQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)(); |
|
4044 |
|
4045 const append = () => { |
|
4046 if (list.length <= nextIndex) { |
|
4047 return; |
|
4048 } |
|
4049 |
|
4050 setCurrent(state => [...state, ...list.slice(nextIndex, nextIndex + step)]); |
|
4051 nextIndex += step; |
|
4052 asyncQueue.add({}, append); |
|
4053 }; |
|
4054 |
|
4055 asyncQueue.add({}, append); |
|
4056 return () => asyncQueue.reset(); |
|
4057 }, [list]); |
|
4058 return current; |
|
4059 } |
|
4060 |
|
4061 /* harmony default export */ var use_async_list = (useAsyncList); |
|
4062 |
|
4063 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-warn-on-change/index.js |
|
4064 /** |
|
4065 * Internal dependencies |
|
4066 */ |
|
4067 // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case |
|
4068 // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript |
|
4069 |
|
4070 /* eslint-disable jsdoc/check-types */ |
|
4071 |
|
4072 /** |
|
4073 * Hook that performs a shallow comparison between the preview value of an object |
|
4074 * and the new one, if there's a difference, it prints it to the console. |
|
4075 * this is useful in performance related work, to check why a component re-renders. |
|
4076 * |
|
4077 * @example |
|
4078 * |
|
4079 * ```jsx |
|
4080 * function MyComponent(props) { |
|
4081 * useWarnOnChange(props); |
|
4082 * |
|
4083 * return "Something"; |
|
4084 * } |
|
4085 * ``` |
|
4086 * |
|
4087 * @param {object} object Object which changes to compare. |
|
4088 * @param {string} prefix Just a prefix to show when console logging. |
|
4089 */ |
|
4090 |
|
4091 function useWarnOnChange(object) { |
|
4092 let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Change detection'; |
|
4093 const previousValues = usePrevious(object); |
|
4094 Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(_ref => { |
|
4095 let [key, value] = _ref; |
|
4096 |
|
4097 if (value !== object[ |
|
4098 /** @type {keyof typeof object} */ |
|
4099 key]) { |
|
4100 // eslint-disable-next-line no-console |
|
4101 console.warn(`${prefix}: ${key} key changed:`, value, object[ |
|
4102 /** @type {keyof typeof object} */ |
|
4103 key] |
|
4104 /* eslint-enable jsdoc/check-types */ |
|
4105 ); |
|
4106 } |
|
4107 }); |
|
4108 } |
|
4109 |
|
4110 /* harmony default export */ var use_warn_on_change = (useWarnOnChange); |
|
4111 |
|
4112 // EXTERNAL MODULE: external "React" |
|
4113 var external_React_ = __webpack_require__(9196); |
|
4114 ;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
|
4115 |
|
4116 |
|
4117 function areInputsEqual(newInputs, lastInputs) { |
|
4118 if (newInputs.length !== lastInputs.length) { |
|
4119 return false; |
|
4120 } |
|
4121 |
|
4122 for (var i = 0; i < newInputs.length; i++) { |
|
4123 if (newInputs[i] !== lastInputs[i]) { |
|
4124 return false; |
|
4125 } |
|
4126 } |
|
4127 |
|
4128 return true; |
|
4129 } |
|
4130 |
|
4131 function useMemoOne(getResult, inputs) { |
|
4132 var initial = (0,external_React_.useState)(function () { |
|
4133 return { |
|
4134 inputs: inputs, |
|
4135 result: getResult() |
|
4136 }; |
|
4137 })[0]; |
|
4138 var isFirstRun = (0,external_React_.useRef)(true); |
|
4139 var committed = (0,external_React_.useRef)(initial); |
|
4140 var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); |
|
4141 var cache = useCache ? committed.current : { |
|
4142 inputs: inputs, |
|
4143 result: getResult() |
|
4144 }; |
|
4145 (0,external_React_.useEffect)(function () { |
|
4146 isFirstRun.current = false; |
|
4147 committed.current = cache; |
|
4148 }, [cache]); |
|
4149 return cache.result; |
|
4150 } |
|
4151 function useCallbackOne(callback, inputs) { |
|
4152 return useMemoOne(function () { |
|
4153 return callback; |
|
4154 }, inputs); |
|
4155 } |
|
4156 var useMemo = (/* unused pure expression or super */ null && (useMemoOne)); |
|
4157 var useCallback = (/* unused pure expression or super */ null && (useCallbackOne)); |
|
4158 |
|
4159 |
|
4160 |
|
4161 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-debounce/index.js |
|
4162 /** |
|
4163 * External dependencies |
|
4164 */ |
|
4165 |
|
4166 |
|
4167 /** |
|
4168 * WordPress dependencies |
|
4169 */ |
|
4170 |
|
4171 |
|
4172 /* eslint-disable jsdoc/valid-types */ |
|
4173 |
|
4174 /** |
|
4175 * Debounces a function with Lodash's `debounce`. A new debounced function will |
|
4176 * be returned and any scheduled calls cancelled if any of the arguments change, |
|
4177 * including the function to debounce, so please wrap functions created on |
|
4178 * render in components in `useCallback`. |
|
4179 * |
|
4180 * @see https://docs-lodash.com/v4/debounce/ |
|
4181 * |
|
4182 * @template {(...args: any[]) => void} TFunc |
|
4183 * |
|
4184 * @param {TFunc} fn The function to debounce. |
|
4185 * @param {number} [wait] The number of milliseconds to delay. |
|
4186 * @param {import('lodash').DebounceSettings} [options] The options object. |
|
4187 * @return {import('lodash').DebouncedFunc<TFunc>} Debounced function. |
|
4188 */ |
|
4189 |
|
4190 function useDebounce(fn, wait, options) { |
|
4191 /* eslint-enable jsdoc/valid-types */ |
|
4192 const debounced = useMemoOne(() => (0,external_lodash_namespaceObject.debounce)(fn, wait, options), [fn, wait, options]); |
|
4193 (0,external_wp_element_namespaceObject.useEffect)(() => () => debounced.cancel(), [debounced]); |
|
4194 return debounced; |
|
4195 } |
|
4196 |
|
4197 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-throttle/index.js |
|
4198 /** |
|
4199 * External dependencies |
|
4200 */ |
|
4201 |
|
4202 |
|
4203 /** |
|
4204 * WordPress dependencies |
|
4205 */ |
|
4206 |
|
4207 |
|
4208 /** |
|
4209 * Throttles a function with Lodash's `throttle`. A new throttled function will |
|
4210 * be returned and any scheduled calls cancelled if any of the arguments change, |
|
4211 * including the function to throttle, so please wrap functions created on |
|
4212 * render in components in `useCallback`. |
|
4213 * |
|
4214 * @see https://docs-lodash.com/v4/throttle/ |
|
4215 * |
|
4216 * @template {(...args: any[]) => void} TFunc |
|
4217 * |
|
4218 * @param {TFunc} fn The function to throttle. |
|
4219 * @param {number} [wait] The number of milliseconds to throttle invocations to. |
|
4220 * @param {import('lodash').ThrottleSettings} [options] The options object. See linked documentation for details. |
|
4221 * @return {import('lodash').DebouncedFunc<TFunc>} Throttled function. |
|
4222 */ |
|
4223 |
|
4224 function useThrottle(fn, wait, options) { |
|
4225 const throttled = useMemoOne(() => (0,external_lodash_namespaceObject.throttle)(fn, wait, options), [fn, wait, options]); |
|
4226 (0,external_wp_element_namespaceObject.useEffect)(() => () => throttled.cancel(), [throttled]); |
|
4227 return throttled; |
|
4228 } |
|
4229 |
|
4230 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-drop-zone/index.js |
|
4231 /** |
|
4232 * WordPress dependencies |
|
4233 */ |
|
4234 |
|
4235 /** |
|
4236 * Internal dependencies |
|
4237 */ |
|
4238 |
|
4239 |
|
4240 /* eslint-disable jsdoc/valid-types */ |
|
4241 |
|
4242 /** |
|
4243 * @template T |
|
4244 * @param {T} value |
|
4245 * @return {import('react').MutableRefObject<T|null>} A ref with the value. |
|
4246 */ |
|
4247 |
|
4248 function useFreshRef(value) { |
|
4249 /* eslint-enable jsdoc/valid-types */ |
|
4250 |
|
4251 /* eslint-disable jsdoc/no-undefined-types */ |
|
4252 |
|
4253 /** @type {import('react').MutableRefObject<T>} */ |
|
4254 |
|
4255 /* eslint-enable jsdoc/no-undefined-types */ |
|
4256 // Disable reason: We're doing something pretty JavaScript-y here where the |
|
4257 // ref will always have a current value that is not null or undefined but it |
|
4258 // needs to start as undefined. We don't want to change the return type so |
|
4259 // it's easier to just ts-ignore this specific line that's complaining about |
|
4260 // undefined not being part of T. |
|
4261 // @ts-ignore |
|
4262 const ref = (0,external_wp_element_namespaceObject.useRef)(); |
|
4263 ref.current = value; |
|
4264 return ref; |
|
4265 } |
|
4266 /** |
|
4267 * A hook to facilitate drag and drop handling. |
|
4268 * |
|
4269 * @param {Object} props Named parameters. |
|
4270 * @param {boolean} props.isDisabled Whether or not to disable the drop zone. |
|
4271 * @param {(e: DragEvent) => void} props.onDragStart Called when dragging has started. |
|
4272 * @param {(e: DragEvent) => void} props.onDragEnter Called when the zone is entered. |
|
4273 * @param {(e: DragEvent) => void} props.onDragOver Called when the zone is moved within. |
|
4274 * @param {(e: DragEvent) => void} props.onDragLeave Called when the zone is left. |
|
4275 * @param {(e: MouseEvent) => void} props.onDragEnd Called when dragging has ended. |
|
4276 * @param {(e: DragEvent) => void} props.onDrop Called when dropping in the zone. |
|
4277 * |
|
4278 * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element. |
|
4279 */ |
|
4280 |
|
4281 |
|
4282 function useDropZone(_ref) { |
|
4283 let { |
|
4284 isDisabled, |
|
4285 onDrop: _onDrop, |
|
4286 onDragStart: _onDragStart, |
|
4287 onDragEnter: _onDragEnter, |
|
4288 onDragLeave: _onDragLeave, |
|
4289 onDragEnd: _onDragEnd, |
|
4290 onDragOver: _onDragOver |
|
4291 } = _ref; |
|
4292 const onDropRef = useFreshRef(_onDrop); |
|
4293 const onDragStartRef = useFreshRef(_onDragStart); |
|
4294 const onDragEnterRef = useFreshRef(_onDragEnter); |
|
4295 const onDragLeaveRef = useFreshRef(_onDragLeave); |
|
4296 const onDragEndRef = useFreshRef(_onDragEnd); |
|
4297 const onDragOverRef = useFreshRef(_onDragOver); |
|
4298 return useRefEffect(element => { |
|
4299 if (isDisabled) { |
|
4300 return; |
|
4301 } |
|
4302 |
|
4303 let isDragging = false; |
|
4304 const { |
|
4305 ownerDocument |
|
4306 } = element; |
|
4307 /** |
|
4308 * Checks if an element is in the drop zone. |
|
4309 * |
|
4310 * @param {EventTarget|null} targetToCheck |
|
4311 * |
|
4312 * @return {boolean} True if in drop zone, false if not. |
|
4313 */ |
|
4314 |
|
4315 function isElementInZone(targetToCheck) { |
|
4316 const { |
|
4317 defaultView |
|
4318 } = ownerDocument; |
|
4319 |
|
4320 if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) { |
|
4321 return false; |
|
4322 } |
|
4323 /** @type {HTMLElement|null} */ |
|
4324 |
|
4325 |
|
4326 let elementToCheck = targetToCheck; |
|
4327 |
|
4328 do { |
|
4329 if (elementToCheck.dataset.isDropZone) { |
|
4330 return elementToCheck === element; |
|
4331 } |
|
4332 } while (elementToCheck = elementToCheck.parentElement); |
|
4333 |
|
4334 return false; |
|
4335 } |
|
4336 |
|
4337 function maybeDragStart( |
|
4338 /** @type {DragEvent} */ |
|
4339 event) { |
|
4340 if (isDragging) { |
|
4341 return; |
|
4342 } |
|
4343 |
|
4344 isDragging = true; |
|
4345 ownerDocument.removeEventListener('dragenter', maybeDragStart); // Note that `dragend` doesn't fire consistently for file and |
|
4346 // HTML drag events where the drag origin is outside the browser |
|
4347 // window. In Firefox it may also not fire if the originating |
|
4348 // node is removed. |
|
4349 |
|
4350 ownerDocument.addEventListener('dragend', maybeDragEnd); |
|
4351 ownerDocument.addEventListener('mousemove', maybeDragEnd); |
|
4352 |
|
4353 if (onDragStartRef.current) { |
|
4354 onDragStartRef.current(event); |
|
4355 } |
|
4356 } |
|
4357 |
|
4358 function onDragEnter( |
|
4359 /** @type {DragEvent} */ |
|
4360 event) { |
|
4361 event.preventDefault(); // The `dragenter` event will also fire when entering child |
|
4362 // elements, but we only want to call `onDragEnter` when |
|
4363 // entering the drop zone, which means the `relatedTarget` |
|
4364 // (element that has been left) should be outside the drop zone. |
|
4365 |
|
4366 if (element.contains( |
|
4367 /** @type {Node} */ |
|
4368 event.relatedTarget)) { |
|
4369 return; |
|
4370 } |
|
4371 |
|
4372 if (onDragEnterRef.current) { |
|
4373 onDragEnterRef.current(event); |
|
4374 } |
|
4375 } |
|
4376 |
|
4377 function onDragOver( |
|
4378 /** @type {DragEvent} */ |
|
4379 event) { |
|
4380 // Only call onDragOver for the innermost hovered drop zones. |
|
4381 if (!event.defaultPrevented && onDragOverRef.current) { |
|
4382 onDragOverRef.current(event); |
|
4383 } // Prevent the browser default while also signalling to parent |
|
4384 // drop zones that `onDragOver` is already handled. |
|
4385 |
|
4386 |
|
4387 event.preventDefault(); |
|
4388 } |
|
4389 |
|
4390 function onDragLeave( |
|
4391 /** @type {DragEvent} */ |
|
4392 event) { |
|
4393 // The `dragleave` event will also fire when leaving child |
|
4394 // elements, but we only want to call `onDragLeave` when |
|
4395 // leaving the drop zone, which means the `relatedTarget` |
|
4396 // (element that has been entered) should be outside the drop |
|
4397 // zone. |
|
4398 if (isElementInZone(event.relatedTarget)) { |
|
4399 return; |
|
4400 } |
|
4401 |
|
4402 if (onDragLeaveRef.current) { |
|
4403 onDragLeaveRef.current(event); |
|
4404 } |
|
4405 } |
|
4406 |
|
4407 function onDrop( |
|
4408 /** @type {DragEvent} */ |
|
4409 event) { |
|
4410 // Don't handle drop if an inner drop zone already handled it. |
|
4411 if (event.defaultPrevented) { |
|
4412 return; |
|
4413 } // Prevent the browser default while also signalling to parent |
|
4414 // drop zones that `onDrop` is already handled. |
|
4415 |
|
4416 |
|
4417 event.preventDefault(); // This seemingly useless line has been shown to resolve a |
|
4418 // Safari issue where files dragged directly from the dock are |
|
4419 // not recognized. |
|
4420 // eslint-disable-next-line no-unused-expressions |
|
4421 |
|
4422 event.dataTransfer && event.dataTransfer.files.length; |
|
4423 |
|
4424 if (onDropRef.current) { |
|
4425 onDropRef.current(event); |
|
4426 } |
|
4427 |
|
4428 maybeDragEnd(event); |
|
4429 } |
|
4430 |
|
4431 function maybeDragEnd( |
|
4432 /** @type {MouseEvent} */ |
|
4433 event) { |
|
4434 if (!isDragging) { |
|
4435 return; |
|
4436 } |
|
4437 |
|
4438 isDragging = false; |
|
4439 ownerDocument.addEventListener('dragenter', maybeDragStart); |
|
4440 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
|
4441 ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
|
4442 |
|
4443 if (onDragEndRef.current) { |
|
4444 onDragEndRef.current(event); |
|
4445 } |
|
4446 } |
|
4447 |
|
4448 element.dataset.isDropZone = 'true'; |
|
4449 element.addEventListener('drop', onDrop); |
|
4450 element.addEventListener('dragenter', onDragEnter); |
|
4451 element.addEventListener('dragover', onDragOver); |
|
4452 element.addEventListener('dragleave', onDragLeave); // The `dragstart` event doesn't fire if the drag started outside |
|
4453 // the document. |
|
4454 |
|
4455 ownerDocument.addEventListener('dragenter', maybeDragStart); |
|
4456 return () => { |
|
4457 onDropRef.current = null; |
|
4458 onDragStartRef.current = null; |
|
4459 onDragEnterRef.current = null; |
|
4460 onDragLeaveRef.current = null; |
|
4461 onDragEndRef.current = null; |
|
4462 onDragOverRef.current = null; |
|
4463 delete element.dataset.isDropZone; |
|
4464 element.removeEventListener('drop', onDrop); |
|
4465 element.removeEventListener('dragenter', onDragEnter); |
|
4466 element.removeEventListener('dragover', onDragOver); |
|
4467 element.removeEventListener('dragleave', onDragLeave); |
|
4468 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
|
4469 ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
|
4470 ownerDocument.addEventListener('dragenter', maybeDragStart); |
|
4471 }; |
|
4472 }, [isDisabled]); |
|
4473 } |
|
4474 |
|
4475 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focusable-iframe/index.js |
|
4476 /** |
|
4477 * Internal dependencies |
|
4478 */ |
|
4479 |
|
4480 /** |
|
4481 * Dispatches a bubbling focus event when the iframe receives focus. Use |
|
4482 * `onFocus` as usual on the iframe or a parent element. |
|
4483 * |
|
4484 * @return {Object} Ref to pass to the iframe. |
|
4485 */ |
|
4486 |
|
4487 function useFocusableIframe() { |
|
4488 return useRefEffect(element => { |
|
4489 const { |
|
4490 ownerDocument |
|
4491 } = element; |
|
4492 if (!ownerDocument) return; |
|
4493 const { |
|
4494 defaultView |
|
4495 } = ownerDocument; |
|
4496 if (!defaultView) return; |
|
4497 /** |
|
4498 * Checks whether the iframe is the activeElement, inferring that it has |
|
4499 * then received focus, and dispatches a focus event. |
|
4500 */ |
|
4501 |
|
4502 function checkFocus() { |
|
4503 if (ownerDocument && ownerDocument.activeElement === element) { |
|
4504 /** @type {HTMLElement} */ |
|
4505 element.focus(); |
|
4506 } |
|
4507 } |
|
4508 |
|
4509 defaultView.addEventListener('blur', checkFocus); |
|
4510 return () => { |
|
4511 defaultView.removeEventListener('blur', checkFocus); |
|
4512 }; |
|
4513 }, []); |
|
4514 } |
|
4515 |
|
4516 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-fixed-window-list/index.js |
|
4517 /** |
|
4518 * External dependencies |
|
4519 */ |
|
4520 |
|
4521 /** |
|
4522 * WordPress dependencies |
|
4523 */ |
|
4524 |
|
4525 |
|
4526 |
|
4527 |
|
4528 const DEFAULT_INIT_WINDOW_SIZE = 30; |
|
4529 /** |
|
4530 * @typedef {Object} WPFixedWindowList |
|
4531 * |
|
4532 * @property {number} visibleItems Items visible in the current viewport |
|
4533 * @property {number} start Start index of the window |
|
4534 * @property {number} end End index of the window |
|
4535 * @property {(index:number)=>boolean} itemInView Returns true if item is in the window |
|
4536 */ |
|
4537 |
|
4538 /** |
|
4539 * @typedef {Object} WPFixedWindowListOptions |
|
4540 * |
|
4541 * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window. |
|
4542 * @property {boolean} [useWindowing] When false avoids calculating the window size |
|
4543 * @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size. |
|
4544 */ |
|
4545 |
|
4546 /** |
|
4547 * |
|
4548 * @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element. |
|
4549 * @param { number } itemHeight Fixed item height in pixels |
|
4550 * @param { number } totalItems Total items in list |
|
4551 * @param { WPFixedWindowListOptions } [options] Options object |
|
4552 * @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter |
|
4553 */ |
|
4554 |
|
4555 function useFixedWindowList(elementRef, itemHeight, totalItems, options) { |
|
4556 var _options$initWindowSi, _options$useWindowing; |
|
4557 |
|
4558 const initWindowSize = (_options$initWindowSi = options === null || options === void 0 ? void 0 : options.initWindowSize) !== null && _options$initWindowSi !== void 0 ? _options$initWindowSi : DEFAULT_INIT_WINDOW_SIZE; |
|
4559 const useWindowing = (_options$useWindowing = options === null || options === void 0 ? void 0 : options.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true; |
|
4560 const [fixedListWindow, setFixedListWindow] = (0,external_wp_element_namespaceObject.useState)({ |
|
4561 visibleItems: initWindowSize, |
|
4562 start: 0, |
|
4563 end: initWindowSize, |
|
4564 itemInView: ( |
|
4565 /** @type {number} */ |
|
4566 index) => { |
|
4567 return index >= 0 && index <= initWindowSize; |
|
4568 } |
|
4569 }); |
|
4570 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
|
4571 var _scrollContainer$owne, _scrollContainer$owne2, _scrollContainer$owne3, _scrollContainer$owne4; |
|
4572 |
|
4573 if (!useWindowing) { |
|
4574 return; |
|
4575 } |
|
4576 |
|
4577 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
|
4578 |
|
4579 const measureWindow = ( |
|
4580 /** @type {boolean | undefined} */ |
|
4581 initRender) => { |
|
4582 var _options$windowOversc; |
|
4583 |
|
4584 if (!scrollContainer) { |
|
4585 return; |
|
4586 } |
|
4587 |
|
4588 const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); // Aim to keep opening list view fast, afterward we can optimize for scrolling. |
|
4589 |
|
4590 const windowOverscan = initRender ? visibleItems : (_options$windowOversc = options === null || options === void 0 ? void 0 : options.windowOverscan) !== null && _options$windowOversc !== void 0 ? _options$windowOversc : visibleItems; |
|
4591 const firstViewableIndex = Math.floor(scrollContainer.scrollTop / itemHeight); |
|
4592 const start = Math.max(0, firstViewableIndex - windowOverscan); |
|
4593 const end = Math.min(totalItems - 1, firstViewableIndex + visibleItems + windowOverscan); |
|
4594 setFixedListWindow(lastWindow => { |
|
4595 const nextWindow = { |
|
4596 visibleItems, |
|
4597 start, |
|
4598 end, |
|
4599 itemInView: ( |
|
4600 /** @type {number} */ |
|
4601 index) => { |
|
4602 return start <= index && index <= end; |
|
4603 } |
|
4604 }; |
|
4605 |
|
4606 if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) { |
|
4607 return nextWindow; |
|
4608 } |
|
4609 |
|
4610 return lastWindow; |
|
4611 }); |
|
4612 }; |
|
4613 |
|
4614 measureWindow(true); |
|
4615 const debounceMeasureList = (0,external_lodash_namespaceObject.debounce)(() => { |
|
4616 measureWindow(); |
|
4617 }, 16); |
|
4618 scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.addEventListener('scroll', debounceMeasureList); |
|
4619 scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne = scrollContainer.ownerDocument) === null || _scrollContainer$owne === void 0 ? void 0 : (_scrollContainer$owne2 = _scrollContainer$owne.defaultView) === null || _scrollContainer$owne2 === void 0 ? void 0 : _scrollContainer$owne2.addEventListener('resize', debounceMeasureList); |
|
4620 scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne3 = scrollContainer.ownerDocument) === null || _scrollContainer$owne3 === void 0 ? void 0 : (_scrollContainer$owne4 = _scrollContainer$owne3.defaultView) === null || _scrollContainer$owne4 === void 0 ? void 0 : _scrollContainer$owne4.addEventListener('resize', debounceMeasureList); |
|
4621 return () => { |
|
4622 var _scrollContainer$owne5, _scrollContainer$owne6; |
|
4623 |
|
4624 scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener('scroll', debounceMeasureList); |
|
4625 scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne5 = scrollContainer.ownerDocument) === null || _scrollContainer$owne5 === void 0 ? void 0 : (_scrollContainer$owne6 = _scrollContainer$owne5.defaultView) === null || _scrollContainer$owne6 === void 0 ? void 0 : _scrollContainer$owne6.removeEventListener('resize', debounceMeasureList); |
|
4626 }; |
|
4627 }, [itemHeight, elementRef, totalItems]); |
|
4628 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
|
4629 var _scrollContainer$owne7, _scrollContainer$owne8; |
|
4630 |
|
4631 if (!useWindowing) { |
|
4632 return; |
|
4633 } |
|
4634 |
|
4635 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
|
4636 |
|
4637 const handleKeyDown = ( |
|
4638 /** @type {KeyboardEvent} */ |
|
4639 event) => { |
|
4640 switch (event.keyCode) { |
|
4641 case external_wp_keycodes_namespaceObject.HOME: |
|
4642 { |
|
4643 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({ |
|
4644 top: 0 |
|
4645 }); |
|
4646 } |
|
4647 |
|
4648 case external_wp_keycodes_namespaceObject.END: |
|
4649 { |
|
4650 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({ |
|
4651 top: totalItems * itemHeight |
|
4652 }); |
|
4653 } |
|
4654 |
|
4655 case external_wp_keycodes_namespaceObject.PAGEUP: |
|
4656 { |
|
4657 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({ |
|
4658 top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight |
|
4659 }); |
|
4660 } |
|
4661 |
|
4662 case external_wp_keycodes_namespaceObject.PAGEDOWN: |
|
4663 { |
|
4664 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({ |
|
4665 top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight |
|
4666 }); |
|
4667 } |
|
4668 } |
|
4669 }; |
|
4670 |
|
4671 scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne7 = scrollContainer.ownerDocument) === null || _scrollContainer$owne7 === void 0 ? void 0 : (_scrollContainer$owne8 = _scrollContainer$owne7.defaultView) === null || _scrollContainer$owne8 === void 0 ? void 0 : _scrollContainer$owne8.addEventListener('keydown', handleKeyDown); |
|
4672 return () => { |
|
4673 var _scrollContainer$owne9, _scrollContainer$owne10; |
|
4674 |
|
4675 scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne9 = scrollContainer.ownerDocument) === null || _scrollContainer$owne9 === void 0 ? void 0 : (_scrollContainer$owne10 = _scrollContainer$owne9.defaultView) === null || _scrollContainer$owne10 === void 0 ? void 0 : _scrollContainer$owne10.removeEventListener('keydown', handleKeyDown); |
|
4676 }; |
|
4677 }, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems]); |
|
4678 return [fixedListWindow, setFixedListWindow]; |
|
4679 } |
|
4680 |
|
4681 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/index.js |
|
4682 // Utils. |
|
4683 // Compose helper (aliased flowRight from Lodash) |
|
4684 |
|
4685 // Higher-order components. |
|
4686 |
|
4687 |
|
4688 |
|
4689 |
|
4690 |
|
4691 |
|
4692 // Hooks. |
|
4693 |
|
4694 |
|
4695 |
|
4696 |
|
4697 |
|
4698 |
|
4699 |
|
4700 |
|
4701 |
|
4702 |
|
4703 |
|
4704 |
|
4705 |
|
4706 |
|
4707 |
|
4708 |
|
4709 |
|
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 }(); |
|
4722 (window.wp = window.wp || {}).compose = __webpack_exports__; |
|
4723 /******/ })() |
|
4724 ; |