PluginProbe
Gutenberg / 13.5.1
Gutenberg v13.5.1
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / compose / index.js

index.js in Gutenberg 13.5.1, at build/compose/index.js

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