PluginProbe
Gutenberg / 14.7.3
Gutenberg v14.7.3
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 14.7.3, at build/compose/index.js

5,689 lines 185.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 /******/ var __webpack_modules__ = ({
3
4 /***/ 8294:
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 /***/ (function(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 /***/ (function() {
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 /******/ !function() {
2107 /******/ // getDefaultExport function for compatibility with non-harmony modules
2108 /******/ __webpack_require__.n = function(module) {
2109 /******/ var getter = module && module.__esModule ?
2110 /******/ function() { return module['default']; } :
2111 /******/ function() { return module; };
2112 /******/ __webpack_require__.d(getter, { a: getter });
2113 /******/ return getter;
2114 /******/ };
2115 /******/ }();
2116 /******/
2117 /******/ /* webpack/runtime/define property getters */
2118 /******/ !function() {
2119 /******/ // define getter functions for harmony exports
2120 /******/ __webpack_require__.d = function(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 /******/ !function() {
2131 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
2132 /******/ }();
2133 /******/
2134 /******/ /* webpack/runtime/make namespace object */
2135 /******/ !function() {
2136 /******/ // define __esModule on exports
2137 /******/ __webpack_require__.r = function(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 !function() {
2149 "use strict";
2150 // ESM COMPAT FLAG
2151 __webpack_require__.r(__webpack_exports__);
2152
2153 // EXPORTS
2154 __webpack_require__.d(__webpack_exports__, {
2155 "__experimentalUseDialog": function() { return /* reexport */ use_dialog; },
2156 "__experimentalUseDragging": function() { return /* reexport */ useDragging; },
2157 "__experimentalUseDropZone": function() { return /* reexport */ useDropZone; },
2158 "__experimentalUseFixedWindowList": function() { return /* reexport */ useFixedWindowList; },
2159 "__experimentalUseFocusOutside": function() { return /* reexport */ useFocusOutside; },
2160 "compose": function() { return /* reexport */ higher_order_compose; },
2161 "createHigherOrderComponent": function() { return /* reexport */ createHigherOrderComponent; },
2162 "debounce": function() { return /* reexport */ debounce; },
2163 "ifCondition": function() { return /* reexport */ if_condition; },
2164 "pipe": function() { return /* reexport */ higher_order_pipe; },
2165 "pure": function() { return /* reexport */ higher_order_pure; },
2166 "throttle": function() { return /* reexport */ throttle; },
2167 "useAsyncList": function() { return /* reexport */ use_async_list; },
2168 "useConstrainedTabbing": function() { return /* reexport */ use_constrained_tabbing; },
2169 "useCopyOnClick": function() { return /* reexport */ useCopyOnClick; },
2170 "useCopyToClipboard": function() { return /* reexport */ useCopyToClipboard; },
2171 "useDebounce": function() { return /* reexport */ useDebounce; },
2172 "useDisabled": function() { return /* reexport */ useDisabled; },
2173 "useFocusOnMount": function() { return /* reexport */ useFocusOnMount; },
2174 "useFocusReturn": function() { return /* reexport */ use_focus_return; },
2175 "useFocusableIframe": function() { return /* reexport */ useFocusableIframe; },
2176 "useInstanceId": function() { return /* reexport */ use_instance_id; },
2177 "useIsomorphicLayoutEffect": function() { return /* reexport */ use_isomorphic_layout_effect; },
2178 "useKeyboardShortcut": function() { return /* reexport */ use_keyboard_shortcut; },
2179 "useMediaQuery": function() { return /* reexport */ useMediaQuery; },
2180 "useMergeRefs": function() { return /* reexport */ useMergeRefs; },
2181 "usePrevious": function() { return /* reexport */ usePrevious; },
2182 "useReducedMotion": function() { return /* reexport */ use_reduced_motion; },
2183 "useRefEffect": function() { return /* reexport */ useRefEffect; },
2184 "useResizeObserver": function() { return /* reexport */ useResizeAware; },
2185 "useThrottle": function() { return /* reexport */ useThrottle; },
2186 "useViewportMatch": function() { return /* reexport */ use_viewport_match; },
2187 "useWarnOnChange": function() { return /* reexport */ use_warn_on_change; },
2188 "withGlobalEvents": function() { return /* reexport */ withGlobalEvents; },
2189 "withInstanceId": function() { return /* reexport */ with_instance_id; },
2190 "withSafeTimeout": function() { return /* reexport */ with_safe_timeout; },
2191 "withState": function() { return /* reexport */ withState; }
2192 });
2193
2194 ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
2195 /*! *****************************************************************************
2196 Copyright (c) Microsoft Corporation.
2197
2198 Permission to use, copy, modify, and/or distribute this software for any
2199 purpose with or without fee is hereby granted.
2200
2201 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2202 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2203 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2204 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2205 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2206 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2207 PERFORMANCE OF THIS SOFTWARE.
2208 ***************************************************************************** */
2209 /* global Reflect, Promise */
2210
2211 var extendStatics = function(d, b) {
2212 extendStatics = Object.setPrototypeOf ||
2213 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
2214 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
2215 return extendStatics(d, b);
2216 };
2217
2218 function __extends(d, b) {
2219 if (typeof b !== "function" && b !== null)
2220 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
2221 extendStatics(d, b);
2222 function __() { this.constructor = d; }
2223 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2224 }
2225
2226 var __assign = function() {
2227 __assign = Object.assign || function __assign(t) {
2228 for (var s, i = 1, n = arguments.length; i < n; i++) {
2229 s = arguments[i];
2230 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
2231 }
2232 return t;
2233 }
2234 return __assign.apply(this, arguments);
2235 }
2236
2237 function __rest(s, e) {
2238 var t = {};
2239 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2240 t[p] = s[p];
2241 if (s != null && typeof Object.getOwnPropertySymbols === "function")
2242 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
2243 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
2244 t[p[i]] = s[p[i]];
2245 }
2246 return t;
2247 }
2248
2249 function __decorate(decorators, target, key, desc) {
2250 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2251 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2252 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2253 return c > 3 && r && Object.defineProperty(target, key, r), r;
2254 }
2255
2256 function __param(paramIndex, decorator) {
2257 return function (target, key) { decorator(target, key, paramIndex); }
2258 }
2259
2260 function __metadata(metadataKey, metadataValue) {
2261 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
2262 }
2263
2264 function __awaiter(thisArg, _arguments, P, generator) {
2265 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2266 return new (P || (P = Promise))(function (resolve, reject) {
2267 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2268 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2269 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2270 step((generator = generator.apply(thisArg, _arguments || [])).next());
2271 });
2272 }
2273
2274 function __generator(thisArg, body) {
2275 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
2276 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2277 function verb(n) { return function (v) { return step([n, v]); }; }
2278 function step(op) {
2279 if (f) throw new TypeError("Generator is already executing.");
2280 while (_) try {
2281 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
2282 if (y = 0, t) op = [op[0] & 2, t.value];
2283 switch (op[0]) {
2284 case 0: case 1: t = op; break;
2285 case 4: _.label++; return { value: op[1], done: false };
2286 case 5: _.label++; y = op[1]; op = [0]; continue;
2287 case 7: op = _.ops.pop(); _.trys.pop(); continue;
2288 default:
2289 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2290 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2291 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2292 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2293 if (t[2]) _.ops.pop();
2294 _.trys.pop(); continue;
2295 }
2296 op = body.call(thisArg, _);
2297 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2298 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2299 }
2300 }
2301
2302 var __createBinding = Object.create ? (function(o, m, k, k2) {
2303 if (k2 === undefined) k2 = k;
2304 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
2305 }) : (function(o, m, k, k2) {
2306 if (k2 === undefined) k2 = k;
2307 o[k2] = m[k];
2308 });
2309
2310 function __exportStar(m, o) {
2311 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
2312 }
2313
2314 function __values(o) {
2315 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
2316 if (m) return m.call(o);
2317 if (o && typeof o.length === "number") return {
2318 next: function () {
2319 if (o && i >= o.length) o = void 0;
2320 return { value: o && o[i++], done: !o };
2321 }
2322 };
2323 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
2324 }
2325
2326 function __read(o, n) {
2327 var m = typeof Symbol === "function" && o[Symbol.iterator];
2328 if (!m) return o;
2329 var i = m.call(o), r, ar = [], e;
2330 try {
2331 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
2332 }
2333 catch (error) { e = { error: error }; }
2334 finally {
2335 try {
2336 if (r && !r.done && (m = i["return"])) m.call(i);
2337 }
2338 finally { if (e) throw e.error; }
2339 }
2340 return ar;
2341 }
2342
2343 /** @deprecated */
2344 function __spread() {
2345 for (var ar = [], i = 0; i < arguments.length; i++)
2346 ar = ar.concat(__read(arguments[i]));
2347 return ar;
2348 }
2349
2350 /** @deprecated */
2351 function __spreadArrays() {
2352 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
2353 for (var r = Array(s), k = 0, i = 0; i < il; i++)
2354 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
2355 r[k] = a[j];
2356 return r;
2357 }
2358
2359 function __spreadArray(to, from, pack) {
2360 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
2361 if (ar || !(i in from)) {
2362 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
2363 ar[i] = from[i];
2364 }
2365 }
2366 return to.concat(ar || from);
2367 }
2368
2369 function __await(v) {
2370 return this instanceof __await ? (this.v = v, this) : new __await(v);
2371 }
2372
2373 function __asyncGenerator(thisArg, _arguments, generator) {
2374 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2375 var g = generator.apply(thisArg, _arguments || []), i, q = [];
2376 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
2377 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
2378 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
2379 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
2380 function fulfill(value) { resume("next", value); }
2381 function reject(value) { resume("throw", value); }
2382 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
2383 }
2384
2385 function __asyncDelegator(o) {
2386 var i, p;
2387 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
2388 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
2389 }
2390
2391 function __asyncValues(o) {
2392 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2393 var m = o[Symbol.asyncIterator], i;
2394 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
2395 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
2396 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
2397 }
2398
2399 function __makeTemplateObject(cooked, raw) {
2400 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
2401 return cooked;
2402 };
2403
2404 var __setModuleDefault = Object.create ? (function(o, v) {
2405 Object.defineProperty(o, "default", { enumerable: true, value: v });
2406 }) : function(o, v) {
2407 o["default"] = v;
2408 };
2409
2410 function __importStar(mod) {
2411 if (mod && mod.__esModule) return mod;
2412 var result = {};
2413 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2414 __setModuleDefault(result, mod);
2415 return result;
2416 }
2417
2418 function __importDefault(mod) {
2419 return (mod && mod.__esModule) ? mod : { default: mod };
2420 }
2421
2422 function __classPrivateFieldGet(receiver, state, kind, f) {
2423 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
2424 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
2425 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
2426 }
2427
2428 function __classPrivateFieldSet(receiver, state, value, kind, f) {
2429 if (kind === "m") throw new TypeError("Private method is not writable");
2430 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
2431 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
2432 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
2433 }
2434
2435 ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js
2436 /**
2437 * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
2438 */
2439 var SUPPORTED_LOCALE = {
2440 tr: {
2441 regexp: /\u0130|\u0049|\u0049\u0307/g,
2442 map: {
2443 İ: "\u0069",
2444 I: "\u0131",
2445 İ: "\u0069",
2446 },
2447 },
2448 az: {
2449 regexp: /\u0130/g,
2450 map: {
2451 İ: "\u0069",
2452 I: "\u0131",
2453 İ: "\u0069",
2454 },
2455 },
2456 lt: {
2457 regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
2458 map: {
2459 I: "\u0069\u0307",
2460 J: "\u006A\u0307",
2461 Į: "\u012F\u0307",
2462 Ì: "\u0069\u0307\u0300",
2463 Í: "\u0069\u0307\u0301",
2464 Ĩ: "\u0069\u0307\u0303",
2465 },
2466 },
2467 };
2468 /**
2469 * Localized lower case.
2470 */
2471 function localeLowerCase(str, locale) {
2472 var lang = SUPPORTED_LOCALE[locale.toLowerCase()];
2473 if (lang)
2474 return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));
2475 return lowerCase(str);
2476 }
2477 /**
2478 * Lower case as a function.
2479 */
2480 function lowerCase(str) {
2481 return str.toLowerCase();
2482 }
2483
2484 ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js
2485
2486 // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
2487 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
2488 // Remove all non-word characters.
2489 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
2490 /**
2491 * Normalize the string into something other libraries can manipulate easier.
2492 */
2493 function noCase(input, options) {
2494 if (options === void 0) { options = {}; }
2495 var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
2496 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
2497 var start = 0;
2498 var end = result.length;
2499 // Trim the delimiter from around the output string.
2500 while (result.charAt(start) === "\0")
2501 start++;
2502 while (result.charAt(end - 1) === "\0")
2503 end--;
2504 // Transform each token independently.
2505 return result.slice(start, end).split("\0").map(transform).join(delimiter);
2506 }
2507 /**
2508 * Replace `re` in the input string with the replacement value.
2509 */
2510 function replace(input, re, value) {
2511 if (re instanceof RegExp)
2512 return input.replace(re, value);
2513 return re.reduce(function (input, re) { return input.replace(re, value); }, input);
2514 }
2515
2516 ;// CONCATENATED MODULE: ./node_modules/pascal-case/dist.es2015/index.js
2517
2518
2519 function pascalCaseTransform(input, index) {
2520 var firstChar = input.charAt(0);
2521 var lowerChars = input.substr(1).toLowerCase();
2522 if (index > 0 && firstChar >= "0" && firstChar <= "9") {
2523 return "_" + firstChar + lowerChars;
2524 }
2525 return "" + firstChar.toUpperCase() + lowerChars;
2526 }
2527 function pascalCaseTransformMerge(input) {
2528 return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
2529 }
2530 function pascalCase(input, options) {
2531 if (options === void 0) { options = {}; }
2532 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
2533 }
2534
2535 ;// CONCATENATED MODULE: ./packages/compose/build-module/utils/create-higher-order-component/index.js
2536 /**
2537 * External dependencies
2538 */
2539
2540
2541 /**
2542 * Given a function mapping a component to an enhanced component and modifier
2543 * name, returns the enhanced component augmented with a generated displayName.
2544 *
2545 * @param mapComponent Function mapping component to enhanced component.
2546 * @param modifierName Seed name from which to generated display name.
2547 *
2548 * @return Component class with generated display name assigned.
2549 */
2550 function createHigherOrderComponent(mapComponent, modifierName) {
2551 return Inner => {
2552 const Outer = mapComponent(Inner);
2553 Outer.displayName = hocName(modifierName, Inner);
2554 return Outer;
2555 };
2556 }
2557 /**
2558 * Returns a displayName for a higher-order component, given a wrapper name.
2559 *
2560 * @example
2561 * hocName( 'MyMemo', Widget ) === 'MyMemo(Widget)';
2562 * hocName( 'MyMemo', <div /> ) === 'MyMemo(Component)';
2563 *
2564 * @param name Name assigned to higher-order component's wrapper component.
2565 * @param Inner Wrapped component inside higher-order component.
2566 * @return Wrapped name of higher-order component.
2567 */
2568
2569 const hocName = (name, Inner) => {
2570 const inner = Inner.displayName || Inner.name || 'Component';
2571 const outer = pascalCase(name !== null && name !== void 0 ? name : '');
2572 return `${outer}(${inner})`;
2573 };
2574
2575 ;// CONCATENATED MODULE: ./packages/compose/build-module/utils/debounce/index.js
2576 /**
2577 * Parts of this source were derived and modified from lodash,
2578 * released under the MIT license.
2579 *
2580 * https://github.com/lodash/lodash
2581 *
2582 * Copyright JS Foundation and other contributors <https://js.foundation/>
2583 *
2584 * Based on Underscore.js, copyright Jeremy Ashkenas,
2585 * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
2586 *
2587 * This software consists of voluntary contributions made by many
2588 * individuals. For exact contribution history, see the revision history
2589 * available at https://github.com/lodash/lodash
2590 *
2591 * The following license applies to all parts of this software except as
2592 * documented below:
2593 *
2594 * ====
2595 *
2596 * Permission is hereby granted, free of charge, to any person obtaining
2597 * a copy of this software and associated documentation files (the
2598 * "Software"), to deal in the Software without restriction, including
2599 * without limitation the rights to use, copy, modify, merge, publish,
2600 * distribute, sublicense, and/or sell copies of the Software, and to
2601 * permit persons to whom the Software is furnished to do so, subject to
2602 * the following conditions:
2603 *
2604 * The above copyright notice and this permission notice shall be
2605 * included in all copies or substantial portions of the Software.
2606 *
2607 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2608 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2609 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2610 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2611 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2612 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2613 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2614 */
2615
2616 /**
2617 * A simplified and properly typed version of lodash's `debounce`, that
2618 * always uses timers instead of sometimes using rAF.
2619 *
2620 * Creates a debounced function that delays invoking `func` until after `wait`
2621 * milliseconds have elapsed since the last time the debounced function was
2622 * invoked. The debounced function comes with a `cancel` method to cancel delayed
2623 * `func` invocations and a `flush` method to immediately invoke them. Provide
2624 * `options` to indicate whether `func` should be invoked on the leading and/or
2625 * trailing edge of the `wait` timeout. The `func` is invoked with the last
2626 * arguments provided to the debounced function. Subsequent calls to the debounced
2627 * function return the result of the last `func` invocation.
2628 *
2629 * **Note:** If `leading` and `trailing` options are `true`, `func` is
2630 * invoked on the trailing edge of the timeout only if the debounced function
2631 * is invoked more than once during the `wait` timeout.
2632 *
2633 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
2634 * until the next tick, similar to `setTimeout` with a timeout of `0`.
2635 *
2636 * @param {Function} func The function to debounce.
2637 * @param {number} wait The number of milliseconds to delay.
2638 * @param {Partial< DebounceOptions >} options The options object.
2639 * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
2640 * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.
2641 * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
2642 *
2643 * @return Returns the new debounced function.
2644 */
2645 const debounce = (func, wait, options) => {
2646 let lastArgs;
2647 let lastThis;
2648 let maxWait = 0;
2649 let result;
2650 let timerId;
2651 let lastCallTime;
2652 let lastInvokeTime = 0;
2653 let leading = false;
2654 let maxing = false;
2655 let trailing = true;
2656
2657 if (options) {
2658 leading = !!options.leading;
2659 maxing = 'maxWait' in options;
2660
2661 if (options.maxWait !== undefined) {
2662 maxWait = Math.max(options.maxWait, wait);
2663 }
2664
2665 trailing = 'trailing' in options ? !!options.trailing : trailing;
2666 }
2667
2668 function invokeFunc(time) {
2669 const args = lastArgs;
2670 const thisArg = lastThis;
2671 lastArgs = undefined;
2672 lastThis = undefined;
2673 lastInvokeTime = time;
2674 result = func.apply(thisArg, args);
2675 return result;
2676 }
2677
2678 function startTimer(pendingFunc, waitTime) {
2679 timerId = setTimeout(pendingFunc, waitTime);
2680 }
2681
2682 function cancelTimer() {
2683 if (timerId !== undefined) {
2684 clearTimeout(timerId);
2685 }
2686 }
2687
2688 function leadingEdge(time) {
2689 // Reset any `maxWait` timer.
2690 lastInvokeTime = time; // Start the timer for the trailing edge.
2691
2692 startTimer(timerExpired, wait); // Invoke the leading edge.
2693
2694 return leading ? invokeFunc(time) : result;
2695 }
2696
2697 function getTimeSinceLastCall(time) {
2698 return time - (lastCallTime || 0);
2699 }
2700
2701 function remainingWait(time) {
2702 const timeSinceLastCall = getTimeSinceLastCall(time);
2703 const timeSinceLastInvoke = time - lastInvokeTime;
2704 const timeWaiting = wait - timeSinceLastCall;
2705 return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
2706 }
2707
2708 function shouldInvoke(time) {
2709 const timeSinceLastCall = getTimeSinceLastCall(time);
2710 const timeSinceLastInvoke = time - lastInvokeTime; // Either this is the first call, activity has stopped and we're at the
2711 // trailing edge, the system time has gone backwards and we're treating
2712 // it as the trailing edge, or we've hit the `maxWait` limit.
2713
2714 return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
2715 }
2716
2717 function timerExpired() {
2718 const time = Date.now();
2719
2720 if (shouldInvoke(time)) {
2721 return trailingEdge(time);
2722 } // Restart the timer.
2723
2724
2725 startTimer(timerExpired, remainingWait(time));
2726 return undefined;
2727 }
2728
2729 function clearTimer() {
2730 timerId = undefined;
2731 }
2732
2733 function trailingEdge(time) {
2734 clearTimer(); // Only invoke if we have `lastArgs` which means `func` has been
2735 // debounced at least once.
2736
2737 if (trailing && lastArgs) {
2738 return invokeFunc(time);
2739 }
2740
2741 lastArgs = lastThis = undefined;
2742 return result;
2743 }
2744
2745 function cancel() {
2746 cancelTimer();
2747 lastInvokeTime = 0;
2748 clearTimer();
2749 lastArgs = lastCallTime = lastThis = undefined;
2750 }
2751
2752 function flush() {
2753 return pending() ? trailingEdge(Date.now()) : result;
2754 }
2755
2756 function pending() {
2757 return timerId !== undefined;
2758 }
2759
2760 function debounced() {
2761 const time = Date.now();
2762 const isInvoking = shouldInvoke(time);
2763
2764 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2765 args[_key] = arguments[_key];
2766 }
2767
2768 lastArgs = args;
2769 lastThis = this;
2770 lastCallTime = time;
2771
2772 if (isInvoking) {
2773 if (!pending()) {
2774 return leadingEdge(lastCallTime);
2775 }
2776
2777 if (maxing) {
2778 // Handle invocations in a tight loop.
2779 startTimer(timerExpired, wait);
2780 return invokeFunc(lastCallTime);
2781 }
2782 }
2783
2784 if (!pending()) {
2785 startTimer(timerExpired, wait);
2786 }
2787
2788 return result;
2789 }
2790
2791 debounced.cancel = cancel;
2792 debounced.flush = flush;
2793 debounced.pending = pending;
2794 return debounced;
2795 };
2796
2797 ;// CONCATENATED MODULE: ./packages/compose/build-module/utils/throttle/index.js
2798 /**
2799 * Parts of this source were derived and modified from lodash,
2800 * released under the MIT license.
2801 *
2802 * https://github.com/lodash/lodash
2803 *
2804 * Copyright JS Foundation and other contributors <https://js.foundation/>
2805 *
2806 * Based on Underscore.js, copyright Jeremy Ashkenas,
2807 * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
2808 *
2809 * This software consists of voluntary contributions made by many
2810 * individuals. For exact contribution history, see the revision history
2811 * available at https://github.com/lodash/lodash
2812 *
2813 * The following license applies to all parts of this software except as
2814 * documented below:
2815 *
2816 * ====
2817 *
2818 * Permission is hereby granted, free of charge, to any person obtaining
2819 * a copy of this software and associated documentation files (the
2820 * "Software"), to deal in the Software without restriction, including
2821 * without limitation the rights to use, copy, modify, merge, publish,
2822 * distribute, sublicense, and/or sell copies of the Software, and to
2823 * permit persons to whom the Software is furnished to do so, subject to
2824 * the following conditions:
2825 *
2826 * The above copyright notice and this permission notice shall be
2827 * included in all copies or substantial portions of the Software.
2828 *
2829 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2830 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2831 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2832 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2833 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2834 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2835 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2836 */
2837
2838 /**
2839 * Internal dependencies
2840 */
2841
2842
2843 /**
2844 * A simplified and properly typed version of lodash's `throttle`, that
2845 * always uses timers instead of sometimes using rAF.
2846 *
2847 * Creates a throttled function that only invokes `func` at most once per
2848 * every `wait` milliseconds. The throttled function comes with a `cancel`
2849 * method to cancel delayed `func` invocations and a `flush` method to
2850 * immediately invoke them. Provide `options` to indicate whether `func`
2851 * should be invoked on the leading and/or trailing edge of the `wait`
2852 * timeout. The `func` is invoked with the last arguments provided to the
2853 * throttled function. Subsequent calls to the throttled function return
2854 * the result of the last `func` invocation.
2855 *
2856 * **Note:** If `leading` and `trailing` options are `true`, `func` is
2857 * invoked on the trailing edge of the timeout only if the throttled function
2858 * is invoked more than once during the `wait` timeout.
2859 *
2860 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
2861 * until the next tick, similar to `setTimeout` with a timeout of `0`.
2862 *
2863 * @param {Function} func The function to throttle.
2864 * @param {number} wait The number of milliseconds to throttle invocations to.
2865 * @param {Partial< ThrottleOptions >} options The options object.
2866 * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
2867 * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
2868 * @return Returns the new throttled function.
2869 */
2870 const throttle = (func, wait, options) => {
2871 let leading = true;
2872 let trailing = true;
2873
2874 if (options) {
2875 leading = 'leading' in options ? !!options.leading : leading;
2876 trailing = 'trailing' in options ? !!options.trailing : trailing;
2877 }
2878
2879 return debounce(func, wait, {
2880 leading,
2881 trailing,
2882 maxWait: wait
2883 });
2884 };
2885
2886 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/pipe.js
2887 /**
2888 * Parts of this source were derived and modified from lodash,
2889 * released under the MIT license.
2890 *
2891 * https://github.com/lodash/lodash
2892 *
2893 * Copyright JS Foundation and other contributors <https://js.foundation/>
2894 *
2895 * Based on Underscore.js, copyright Jeremy Ashkenas,
2896 * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
2897 *
2898 * This software consists of voluntary contributions made by many
2899 * individuals. For exact contribution history, see the revision history
2900 * available at https://github.com/lodash/lodash
2901 *
2902 * The following license applies to all parts of this software except as
2903 * documented below:
2904 *
2905 * ====
2906 *
2907 * Permission is hereby granted, free of charge, to any person obtaining
2908 * a copy of this software and associated documentation files (the
2909 * "Software"), to deal in the Software without restriction, including
2910 * without limitation the rights to use, copy, modify, merge, publish,
2911 * distribute, sublicense, and/or sell copies of the Software, and to
2912 * permit persons to whom the Software is furnished to do so, subject to
2913 * the following conditions:
2914 *
2915 * The above copyright notice and this permission notice shall be
2916 * included in all copies or substantial portions of the Software.
2917 *
2918 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2919 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2920 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2921 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2922 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2923 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2924 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2925 */
2926
2927 /**
2928 * Creates a pipe function.
2929 *
2930 * Allows to choose whether to perform left-to-right or right-to-left composition.
2931 *
2932 * @see https://docs-lodash.com/v4/flow/
2933 *
2934 * @param {boolean} reverse True if right-to-left, false for left-to-right composition.
2935 */
2936 const basePipe = function () {
2937 let reverse = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2938 return function () {
2939 for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
2940 funcs[_key] = arguments[_key];
2941 }
2942
2943 return function () {
2944 const functions = funcs.flat();
2945
2946 if (reverse) {
2947 functions.reverse();
2948 }
2949
2950 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2951 args[_key2] = arguments[_key2];
2952 }
2953
2954 return functions.reduce((prev, func) => [func(...prev)], args)[0];
2955 };
2956 };
2957 };
2958 /**
2959 * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
2960 * composition, where each successive invocation is supplied the return value of the previous.
2961 *
2962 * This is inspired by `lodash`'s `flow` function.
2963 *
2964 * @see https://docs-lodash.com/v4/flow/
2965 */
2966
2967
2968 const pipe = basePipe();
2969
2970 /* harmony default export */ var higher_order_pipe = (pipe);
2971
2972 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/compose.js
2973 /**
2974 * Internal dependencies
2975 */
2976
2977 /**
2978 * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
2979 * composition, where each successive invocation is supplied the return value of the previous.
2980 *
2981 * This is inspired by `lodash`'s `flowRight` function.
2982 *
2983 * @see https://docs-lodash.com/v4/flow-right/
2984 */
2985
2986 const compose = basePipe(true);
2987 /* harmony default export */ var higher_order_compose = (compose);
2988
2989 ;// CONCATENATED MODULE: external ["wp","element"]
2990 var external_wp_element_namespaceObject = window["wp"]["element"];
2991 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/if-condition/index.js
2992
2993
2994 /**
2995 * External dependencies
2996 */
2997
2998 /**
2999 * Internal dependencies
3000 */
3001
3002 /**
3003 * Higher-order component creator, creating a new component which renders if
3004 * the given condition is satisfied or with the given optional prop name.
3005 *
3006 * @example
3007 * ```ts
3008 * type Props = { foo: string };
3009 * const Component = ( props: Props ) => <div>{ props.foo }</div>;
3010 * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );
3011 * <ConditionalComponent foo="" />; // => null
3012 * <ConditionalComponent foo="bar" />; // => <div>bar</div>;
3013 * ```
3014 *
3015 * @param predicate Function to test condition.
3016 *
3017 * @return Higher-order component.
3018 */
3019
3020 function ifCondition(predicate) {
3021 return createHigherOrderComponent(WrappedComponent => props => {
3022 if (!predicate(props)) {
3023 return null;
3024 }
3025
3026 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, props);
3027 }, 'ifCondition');
3028 }
3029
3030 /* harmony default export */ var if_condition = (ifCondition);
3031
3032 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"]
3033 var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
3034 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
3035 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/pure/index.js
3036
3037
3038 /**
3039 * External dependencies
3040 */
3041
3042 /**
3043 * WordPress dependencies
3044 */
3045
3046
3047 /**
3048 * Internal dependencies
3049 */
3050
3051
3052 /**
3053 * Given a component returns the enhanced component augmented with a component
3054 * only re-rendering when its props/state change
3055 */
3056
3057 const pure = createHigherOrderComponent(function (WrappedComponent) {
3058 if (WrappedComponent.prototype instanceof external_wp_element_namespaceObject.Component) {
3059 return class extends WrappedComponent {
3060 shouldComponentUpdate(nextProps, nextState) {
3061 return !external_wp_isShallowEqual_default()(nextProps, this.props) || !external_wp_isShallowEqual_default()(nextState, this.state);
3062 }
3063
3064 };
3065 }
3066
3067 return class extends external_wp_element_namespaceObject.Component {
3068 shouldComponentUpdate(nextProps) {
3069 return !external_wp_isShallowEqual_default()(nextProps, this.props);
3070 }
3071
3072 render() {
3073 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, this.props);
3074 }
3075
3076 };
3077 }, 'pure');
3078 /* harmony default export */ var higher_order_pure = (pure);
3079
3080 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
3081 function _extends() {
3082 _extends = Object.assign || function (target) {
3083 for (var i = 1; i < arguments.length; i++) {
3084 var source = arguments[i];
3085
3086 for (var key in source) {
3087 if (Object.prototype.hasOwnProperty.call(source, key)) {
3088 target[key] = source[key];
3089 }
3090 }
3091 }
3092
3093 return target;
3094 };
3095
3096 return _extends.apply(this, arguments);
3097 }
3098 ;// CONCATENATED MODULE: external ["wp","deprecated"]
3099 var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
3100 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
3101 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/with-global-events/listener.js
3102 /**
3103 * Class responsible for orchestrating event handling on the global window,
3104 * binding a single event to be shared across all handling instances, and
3105 * removing the handler when no instances are listening for the event.
3106 */
3107 class Listener {
3108 constructor() {
3109 /** @type {any} */
3110 this.listeners = {};
3111 this.handleEvent = this.handleEvent.bind(this);
3112 }
3113
3114 add(
3115 /** @type {any} */
3116 eventType,
3117 /** @type {any} */
3118 instance) {
3119 if (!this.listeners[eventType]) {
3120 // Adding first listener for this type, so bind event.
3121 window.addEventListener(eventType, this.handleEvent);
3122 this.listeners[eventType] = [];
3123 }
3124
3125 this.listeners[eventType].push(instance);
3126 }
3127
3128 remove(
3129 /** @type {any} */
3130 eventType,
3131 /** @type {any} */
3132 instance) {
3133 if (!this.listeners[eventType]) {
3134 return;
3135 }
3136
3137 this.listeners[eventType] = this.listeners[eventType].filter((
3138 /** @type {any} */
3139 listener) => listener !== instance);
3140
3141 if (!this.listeners[eventType].length) {
3142 // Removing last listener for this type, so unbind event.
3143 window.removeEventListener(eventType, this.handleEvent);
3144 delete this.listeners[eventType];
3145 }
3146 }
3147
3148 handleEvent(
3149 /** @type {any} */
3150 event) {
3151 var _this$listeners$event;
3152
3153 (_this$listeners$event = this.listeners[event.type]) === null || _this$listeners$event === void 0 ? void 0 : _this$listeners$event.forEach((
3154 /** @type {any} */
3155 instance) => {
3156 instance.handleEvent(event);
3157 });
3158 }
3159
3160 }
3161
3162 /* harmony default export */ var listener = (Listener);
3163
3164 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/with-global-events/index.js
3165
3166
3167
3168 /**
3169 * WordPress dependencies
3170 */
3171
3172
3173 /**
3174 * Internal dependencies
3175 */
3176
3177
3178
3179 /**
3180 * Listener instance responsible for managing document event handling.
3181 */
3182
3183 const with_global_events_listener = new listener();
3184 /* eslint-disable jsdoc/no-undefined-types */
3185
3186 /**
3187 * Higher-order component creator which, given an object of DOM event types and
3188 * values corresponding to a callback function name on the component, will
3189 * create or update a window event handler to invoke the callback when an event
3190 * occurs. On behalf of the consuming developer, the higher-order component
3191 * manages unbinding when the component unmounts, and binding at most a single
3192 * event handler for the entire application.
3193 *
3194 * @deprecated
3195 *
3196 * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM
3197 * event type, the value a
3198 * name of the function on
3199 * the original component's
3200 * instance which handles
3201 * the event.
3202 *
3203 * @return {any} Higher-order component.
3204 */
3205
3206 function withGlobalEvents(eventTypesToHandlers) {
3207 external_wp_deprecated_default()('wp.compose.withGlobalEvents', {
3208 since: '5.7',
3209 alternative: 'useEffect'
3210 }); // @ts-ignore We don't need to fix the type-related issues because this is deprecated.
3211
3212 return createHigherOrderComponent(WrappedComponent => {
3213 class Wrapper extends external_wp_element_namespaceObject.Component {
3214 constructor(
3215 /** @type {any} */
3216 props) {
3217 super(props);
3218 this.handleEvent = this.handleEvent.bind(this);
3219 this.handleRef = this.handleRef.bind(this);
3220 }
3221
3222 componentDidMount() {
3223 Object.keys(eventTypesToHandlers).forEach(eventType => {
3224 with_global_events_listener.add(eventType, this);
3225 });
3226 }
3227
3228 componentWillUnmount() {
3229 Object.keys(eventTypesToHandlers).forEach(eventType => {
3230 with_global_events_listener.remove(eventType, this);
3231 });
3232 }
3233
3234 handleEvent(
3235 /** @type {any} */
3236 event) {
3237 const handler = eventTypesToHandlers[
3238 /** @type {keyof GlobalEventHandlersEventMap} */
3239 event.type
3240 /* eslint-enable jsdoc/no-undefined-types */
3241 ];
3242
3243 if (typeof this.wrappedRef[handler] === 'function') {
3244 this.wrappedRef[handler](event);
3245 }
3246 }
3247
3248 handleRef(
3249 /** @type {any} */
3250 el) {
3251 this.wrappedRef = el; // Any component using `withGlobalEvents` that is not setting a `ref`
3252 // will cause `this.props.forwardedRef` to be `null`, so we need this
3253 // check.
3254
3255 if (this.props.forwardedRef) {
3256 this.props.forwardedRef(el);
3257 }
3258 }
3259
3260 render() {
3261 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, this.props.ownProps, {
3262 ref: this.handleRef
3263 }));
3264 }
3265
3266 }
3267
3268 return (0,external_wp_element_namespaceObject.forwardRef)((props, ref) => {
3269 return (0,external_wp_element_namespaceObject.createElement)(Wrapper, {
3270 ownProps: props,
3271 forwardedRef: ref
3272 });
3273 });
3274 }, 'withGlobalEvents');
3275 }
3276
3277 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-instance-id/index.js
3278 /**
3279 * WordPress dependencies
3280 */
3281
3282 const instanceMap = new WeakMap();
3283 /**
3284 * Creates a new id for a given object.
3285 *
3286 * @param object Object reference to create an id for.
3287 * @return The instance id (index).
3288 */
3289
3290 function createId(object) {
3291 const instances = instanceMap.get(object) || 0;
3292 instanceMap.set(object, instances + 1);
3293 return instances;
3294 }
3295 /**
3296 * Specify the useInstanceId *function* signatures.
3297 *
3298 * More accurately, useInstanceId distinguishes between three different
3299 * signatures:
3300 *
3301 * 1. When only object is given, the returned value is a number
3302 * 2. When object and prefix is given, the returned value is a string
3303 * 3. When preferredId is given, the returned value is the type of preferredId
3304 */
3305
3306
3307 /**
3308 * Provides a unique instance ID.
3309 *
3310 * @param object Object reference to create an id for.
3311 * @param [prefix] Prefix for the unique id.
3312 * @param [preferredId] Default ID to use.
3313 * @return The unique instance id.
3314 */
3315 function useInstanceId(object, prefix, preferredId) {
3316 return (0,external_wp_element_namespaceObject.useMemo)(() => {
3317 if (preferredId) return preferredId;
3318 const id = createId(object);
3319 return prefix ? `${prefix}-${id}` : id;
3320 }, [object]);
3321 }
3322
3323 /* harmony default export */ var use_instance_id = (useInstanceId);
3324
3325 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/with-instance-id/index.js
3326
3327
3328
3329 /**
3330 * Internal dependencies
3331 */
3332
3333
3334
3335 /**
3336 * A Higher Order Component used to be provide a unique instance ID by
3337 * component.
3338 */
3339 const withInstanceId = createHigherOrderComponent(WrappedComponent => {
3340 return props => {
3341 const instanceId = use_instance_id(WrappedComponent); // @ts-ignore
3342
3343 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, props, {
3344 instanceId: instanceId
3345 }));
3346 };
3347 }, 'instanceId');
3348 /* harmony default export */ var with_instance_id = (withInstanceId);
3349
3350 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/with-safe-timeout/index.js
3351
3352
3353
3354 /**
3355 * WordPress dependencies
3356 */
3357
3358 /**
3359 * Internal dependencies
3360 */
3361
3362
3363 /**
3364 * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
3365 * types here because those functions include functionality that is not handled
3366 * by this component, like the ability to pass extra arguments.
3367 *
3368 * In the case of this component, we only handle the simplest case where
3369 * `setTimeout` only accepts a function (not a string) and an optional delay.
3370 */
3371
3372 /**
3373 * A higher-order component used to provide and manage delayed function calls
3374 * that ought to be bound to a component's lifecycle.
3375 */
3376 const withSafeTimeout = createHigherOrderComponent(OriginalComponent => {
3377 return class WrappedComponent extends external_wp_element_namespaceObject.Component {
3378 constructor(props) {
3379 super(props);
3380 this.timeouts = [];
3381 this.setTimeout = this.setTimeout.bind(this);
3382 this.clearTimeout = this.clearTimeout.bind(this);
3383 }
3384
3385 componentWillUnmount() {
3386 this.timeouts.forEach(clearTimeout);
3387 }
3388
3389 setTimeout(fn, delay) {
3390 const id = setTimeout(() => {
3391 fn();
3392 this.clearTimeout(id);
3393 }, delay);
3394 this.timeouts.push(id);
3395 return id;
3396 }
3397
3398 clearTimeout(id) {
3399 clearTimeout(id);
3400 this.timeouts.filter(timeoutId => timeoutId !== id);
3401 }
3402
3403 render() {
3404 return (// @ts-ignore
3405 (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, this.props, {
3406 setTimeout: this.setTimeout,
3407 clearTimeout: this.clearTimeout
3408 }))
3409 );
3410 }
3411
3412 };
3413 }, 'withSafeTimeout');
3414 /* harmony default export */ var with_safe_timeout = (withSafeTimeout);
3415
3416 ;// CONCATENATED MODULE: ./packages/compose/build-module/higher-order/with-state/index.js
3417
3418
3419
3420 /**
3421 * WordPress dependencies
3422 */
3423
3424
3425 /**
3426 * Internal dependencies
3427 */
3428
3429
3430 /**
3431 * A Higher Order Component used to provide and manage internal component state
3432 * via props.
3433 *
3434 * @deprecated Use `useState` instead.
3435 *
3436 * @param {any} initialState Optional initial state of the component.
3437 *
3438 * @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.
3439 */
3440
3441 function withState() {
3442 let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3443 external_wp_deprecated_default()('wp.compose.withState', {
3444 since: '5.8',
3445 alternative: 'wp.element.useState'
3446 });
3447 return createHigherOrderComponent(OriginalComponent => {
3448 return class WrappedComponent extends external_wp_element_namespaceObject.Component {
3449 constructor(
3450 /** @type {any} */
3451 props) {
3452 super(props);
3453 this.setState = this.setState.bind(this);
3454 this.state = initialState;
3455 }
3456
3457 render() {
3458 return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, this.props, this.state, {
3459 setState: this.setState
3460 }));
3461 }
3462
3463 };
3464 }, 'withState');
3465 }
3466
3467 ;// CONCATENATED MODULE: external ["wp","keycodes"]
3468 var external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
3469 ;// CONCATENATED MODULE: external ["wp","dom"]
3470 var external_wp_dom_namespaceObject = window["wp"]["dom"];
3471 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-ref-effect/index.js
3472 /**
3473 * External dependencies
3474 */
3475
3476 /**
3477 * WordPress dependencies
3478 */
3479
3480 /**
3481 * Effect-like ref callback. Just like with `useEffect`, this allows you to
3482 * return a cleanup function to be run if the ref changes or one of the
3483 * dependencies changes. The ref is provided as an argument to the callback
3484 * functions. The main difference between this and `useEffect` is that
3485 * the `useEffect` callback is not called when the ref changes, but this is.
3486 * Pass the returned ref callback as the component's ref and merge multiple refs
3487 * with `useMergeRefs`.
3488 *
3489 * It's worth noting that if the dependencies array is empty, there's not
3490 * strictly a need to clean up event handlers for example, because the node is
3491 * to be removed. It *is* necessary if you add dependencies because the ref
3492 * callback will be called multiple times for the same node.
3493 *
3494 * @param callback Callback with ref as argument.
3495 * @param dependencies Dependencies of the callback.
3496 *
3497 * @return Ref callback.
3498 */
3499
3500 function useRefEffect(callback, dependencies) {
3501 const cleanup = (0,external_wp_element_namespaceObject.useRef)();
3502 return (0,external_wp_element_namespaceObject.useCallback)(node => {
3503 if (node) {
3504 cleanup.current = callback(node);
3505 } else if (cleanup.current) {
3506 cleanup.current();
3507 }
3508 }, dependencies);
3509 }
3510
3511 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-constrained-tabbing/index.js
3512 /**
3513 * WordPress dependencies
3514 */
3515
3516
3517 /**
3518 * Internal dependencies
3519 */
3520
3521
3522 /**
3523 * In Dialogs/modals, the tabbing must be constrained to the content of
3524 * the wrapper element. This hook adds the behavior to the returned ref.
3525 *
3526 * @return {import('react').RefCallback<Element>} Element Ref.
3527 *
3528 * @example
3529 * ```js
3530 * import { useConstrainedTabbing } from '@wordpress/compose';
3531 *
3532 * const ConstrainedTabbingExample = () => {
3533 * const constrainedTabbingRef = useConstrainedTabbing()
3534 * return (
3535 * <div ref={ constrainedTabbingRef }>
3536 * <Button />
3537 * <Button />
3538 * </div>
3539 * );
3540 * }
3541 * ```
3542 */
3543
3544 function useConstrainedTabbing() {
3545 return useRefEffect((
3546 /** @type {HTMLElement} */
3547 node) => {
3548 function onKeyDown(
3549 /** @type {KeyboardEvent} */
3550 event) {
3551 const {
3552 keyCode,
3553 shiftKey,
3554 target
3555 } = event;
3556
3557 if (keyCode !== external_wp_keycodes_namespaceObject.TAB) {
3558 return;
3559 }
3560
3561 const action = shiftKey ? 'findPrevious' : 'findNext';
3562 const nextElement = external_wp_dom_namespaceObject.focus.tabbable[action](
3563 /** @type {HTMLElement} */
3564 target) || null; // If the element that is about to receive focus is outside the
3565 // area, move focus to a div and insert it at the start or end of
3566 // the area, depending on the direction. Without preventing default
3567 // behaviour, the browser will then move focus to the next element.
3568
3569 if (node.contains(nextElement)) {
3570 return;
3571 }
3572
3573 const domAction = shiftKey ? 'append' : 'prepend';
3574 const {
3575 ownerDocument
3576 } = node;
3577 const trap = ownerDocument.createElement('div');
3578 trap.tabIndex = -1;
3579 node[domAction](trap); // Remove itself when the trap loses focus.
3580
3581 trap.addEventListener('blur', () => node.removeChild(trap));
3582 trap.focus();
3583 }
3584
3585 node.addEventListener('keydown', onKeyDown);
3586 return () => {
3587 node.removeEventListener('keydown', onKeyDown);
3588 };
3589 }, []);
3590 }
3591
3592 /* harmony default export */ var use_constrained_tabbing = (useConstrainedTabbing);
3593
3594 // EXTERNAL MODULE: ./node_modules/clipboard/dist/clipboard.js
3595 var dist_clipboard = __webpack_require__(8294);
3596 var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard);
3597 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-copy-on-click/index.js
3598 /**
3599 * External dependencies
3600 */
3601
3602 /**
3603 * WordPress dependencies
3604 */
3605
3606
3607
3608 /* eslint-disable jsdoc/no-undefined-types */
3609
3610 /**
3611 * Copies the text to the clipboard when the element is clicked.
3612 *
3613 * @deprecated
3614 *
3615 * @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.
3616 * @param {string|Function} text The text to copy.
3617 * @param {number} [timeout] Optional timeout to reset the returned
3618 * state. 4 seconds by default.
3619 *
3620 * @return {boolean} Whether or not the text has been copied. Resets after the
3621 * timeout.
3622 */
3623
3624 function useCopyOnClick(ref, text) {
3625 let timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4000;
3626
3627 /* eslint-enable jsdoc/no-undefined-types */
3628 external_wp_deprecated_default()('wp.compose.useCopyOnClick', {
3629 since: '5.8',
3630 alternative: 'wp.compose.useCopyToClipboard'
3631 });
3632 /** @type {import('react').MutableRefObject<Clipboard | undefined>} */
3633
3634 const clipboard = (0,external_wp_element_namespaceObject.useRef)();
3635 const [hasCopied, setHasCopied] = (0,external_wp_element_namespaceObject.useState)(false);
3636 (0,external_wp_element_namespaceObject.useEffect)(() => {
3637 /** @type {number | undefined} */
3638 let timeoutId;
3639
3640 if (!ref.current) {
3641 return;
3642 } // Clipboard listens to click events.
3643
3644
3645 clipboard.current = new (clipboard_default())(ref.current, {
3646 text: () => typeof text === 'function' ? text() : text
3647 });
3648 clipboard.current.on('success', _ref => {
3649 let {
3650 clearSelection,
3651 trigger
3652 } = _ref;
3653 // Clearing selection will move focus back to the triggering button,
3654 // ensuring that it is not reset to the body, and further that it is
3655 // kept within the rendered node.
3656 clearSelection(); // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
3657
3658 if (trigger) {
3659 /** @type {HTMLElement} */
3660 trigger.focus();
3661 }
3662
3663 if (timeout) {
3664 setHasCopied(true);
3665 clearTimeout(timeoutId);
3666 timeoutId = setTimeout(() => setHasCopied(false), timeout);
3667 }
3668 });
3669 return () => {
3670 if (clipboard.current) {
3671 clipboard.current.destroy();
3672 }
3673
3674 clearTimeout(timeoutId);
3675 };
3676 }, [text, timeout, setHasCopied]);
3677 return hasCopied;
3678 }
3679
3680 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-copy-to-clipboard/index.js
3681 /**
3682 * External dependencies
3683 */
3684
3685 /**
3686 * WordPress dependencies
3687 */
3688
3689
3690 /**
3691 * Internal dependencies
3692 */
3693
3694
3695 /**
3696 * @template T
3697 * @param {T} value
3698 * @return {import('react').RefObject<T>} The updated ref
3699 */
3700
3701 function useUpdatedRef(value) {
3702 const ref = (0,external_wp_element_namespaceObject.useRef)(value);
3703 ref.current = value;
3704 return ref;
3705 }
3706 /**
3707 * Copies the given text to the clipboard when the element is clicked.
3708 *
3709 * @template {HTMLElement} TElementType
3710 * @param {string | (() => string)} text The text to copy. Use a function if not
3711 * already available and expensive to compute.
3712 * @param {Function} onSuccess Called when to text is copied.
3713 *
3714 * @return {import('react').Ref<TElementType>} A ref to assign to the target element.
3715 */
3716
3717
3718 function useCopyToClipboard(text, onSuccess) {
3719 // Store the dependencies as refs and continuously update them so they're
3720 // fresh when the callback is called.
3721 const textRef = useUpdatedRef(text);
3722 const onSuccessRef = useUpdatedRef(onSuccess);
3723 return useRefEffect(node => {
3724 // Clipboard listens to click events.
3725 const clipboard = new (clipboard_default())(node, {
3726 text() {
3727 return typeof textRef.current === 'function' ? textRef.current() : textRef.current || '';
3728 }
3729
3730 });
3731 clipboard.on('success', _ref => {
3732 let {
3733 clearSelection
3734 } = _ref;
3735 // Clearing selection will move focus back to the triggering
3736 // button, ensuring that it is not reset to the body, and
3737 // further that it is kept within the rendered node.
3738 clearSelection(); // Handle ClipboardJS focus bug, see
3739 // https://github.com/zenorocha/clipboard.js/issues/680
3740
3741 node.focus();
3742
3743 if (onSuccessRef.current) {
3744 onSuccessRef.current();
3745 }
3746 });
3747 return () => {
3748 clipboard.destroy();
3749 };
3750 }, []);
3751 }
3752
3753 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-focus-on-mount/index.js
3754 /**
3755 * WordPress dependencies
3756 */
3757
3758
3759 /**
3760 * Hook used to focus the first tabbable element on mount.
3761 *
3762 * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode.
3763 * @return {import('react').RefCallback<HTMLElement>} Ref callback.
3764 *
3765 * @example
3766 * ```js
3767 * import { useFocusOnMount } from '@wordpress/compose';
3768 *
3769 * const WithFocusOnMount = () => {
3770 * const ref = useFocusOnMount()
3771 * return (
3772 * <div ref={ ref }>
3773 * <Button />
3774 * <Button />
3775 * </div>
3776 * );
3777 * }
3778 * ```
3779 */
3780
3781 function useFocusOnMount() {
3782 let focusOnMount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'firstElement';
3783 const focusOnMountRef = (0,external_wp_element_namespaceObject.useRef)(focusOnMount);
3784 (0,external_wp_element_namespaceObject.useEffect)(() => {
3785 focusOnMountRef.current = focusOnMount;
3786 }, [focusOnMount]);
3787 return (0,external_wp_element_namespaceObject.useCallback)(node => {
3788 var _node$ownerDocument$a, _node$ownerDocument;
3789
3790 if (!node || focusOnMountRef.current === false) {
3791 return;
3792 }
3793
3794 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)) {
3795 return;
3796 }
3797
3798 let target = node;
3799
3800 if (focusOnMountRef.current === 'firstElement') {
3801 const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0];
3802
3803 if (firstTabbable) {
3804 target =
3805 /** @type {HTMLElement} */
3806 firstTabbable;
3807 }
3808 }
3809
3810 target.focus({
3811 // When focusing newly mounted dialogs,
3812 // the position of the popover is often not right on the first render
3813 // This prevents the layout shifts when focusing the dialogs.
3814 preventScroll: true
3815 });
3816 }, []);
3817 }
3818
3819 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-focus-return/index.js
3820 /**
3821 * WordPress dependencies
3822 */
3823
3824 /**
3825 * When opening modals/sidebars/dialogs, the focus
3826 * must move to the opened area and return to the
3827 * previously focused element when closed.
3828 * The current hook implements the returning behavior.
3829 *
3830 * @param {() => void} [onFocusReturn] Overrides the default return behavior.
3831 * @return {import('react').RefCallback<HTMLElement>} Element Ref.
3832 *
3833 * @example
3834 * ```js
3835 * import { useFocusReturn } from '@wordpress/compose';
3836 *
3837 * const WithFocusReturn = () => {
3838 * const ref = useFocusReturn()
3839 * return (
3840 * <div ref={ ref }>
3841 * <Button />
3842 * <Button />
3843 * </div>
3844 * );
3845 * }
3846 * ```
3847 */
3848
3849 function useFocusReturn(onFocusReturn) {
3850 /** @type {import('react').MutableRefObject<null | HTMLElement>} */
3851 const ref = (0,external_wp_element_namespaceObject.useRef)(null);
3852 /** @type {import('react').MutableRefObject<null | Element>} */
3853
3854 const focusedBeforeMount = (0,external_wp_element_namespaceObject.useRef)(null);
3855 const onFocusReturnRef = (0,external_wp_element_namespaceObject.useRef)(onFocusReturn);
3856 (0,external_wp_element_namespaceObject.useEffect)(() => {
3857 onFocusReturnRef.current = onFocusReturn;
3858 }, [onFocusReturn]);
3859 return (0,external_wp_element_namespaceObject.useCallback)(node => {
3860 if (node) {
3861 // Set ref to be used when unmounting.
3862 ref.current = node; // Only set when the node mounts.
3863
3864 if (focusedBeforeMount.current) {
3865 return;
3866 }
3867
3868 focusedBeforeMount.current = node.ownerDocument.activeElement;
3869 } else if (focusedBeforeMount.current) {
3870 var _ref$current, _ref$current2, _ref$current3;
3871
3872 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);
3873
3874 if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.isConnected && !isFocused) {
3875 return;
3876 } // Defer to the component's own explicit focus return behavior, if
3877 // specified. This allows for support that the `onFocusReturn`
3878 // decides to allow the default behavior to occur under some
3879 // conditions.
3880
3881
3882 if (onFocusReturnRef.current) {
3883 onFocusReturnRef.current();
3884 } else {
3885 var _focusedBeforeMount$c;
3886
3887 /** @type {null | HTMLElement} */
3888 (_focusedBeforeMount$c = focusedBeforeMount.current) === null || _focusedBeforeMount$c === void 0 ? void 0 : _focusedBeforeMount$c.focus();
3889 }
3890 }
3891 }, []);
3892 }
3893
3894 /* harmony default export */ var use_focus_return = (useFocusReturn);
3895
3896 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-focus-outside/index.js
3897 /**
3898 * External dependencies
3899 */
3900
3901 /**
3902 * WordPress dependencies
3903 */
3904
3905 /**
3906 * Input types which are classified as button types, for use in considering
3907 * whether element is a (focus-normalized) button.
3908 */
3909
3910 const INPUT_BUTTON_TYPES = ['button', 'submit'];
3911 /**
3912 * List of HTML button elements subject to focus normalization
3913 *
3914 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
3915 */
3916
3917 /**
3918 * Returns true if the given element is a button element subject to focus
3919 * normalization, or false otherwise.
3920 *
3921 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
3922 *
3923 * @param eventTarget The target from a mouse or touch event.
3924 *
3925 * @return Whether the element is a button element subject to focus normalization.
3926 */
3927 function isFocusNormalizedButton(eventTarget) {
3928 if (!(eventTarget instanceof window.HTMLElement)) {
3929 return false;
3930 }
3931
3932 switch (eventTarget.nodeName) {
3933 case 'A':
3934 case 'BUTTON':
3935 return true;
3936
3937 case 'INPUT':
3938 return INPUT_BUTTON_TYPES.includes(eventTarget.type);
3939 }
3940
3941 return false;
3942 }
3943
3944 /**
3945 * A react hook that can be used to check whether focus has moved outside the
3946 * element the event handlers are bound to.
3947 *
3948 * @param onFocusOutside A callback triggered when focus moves outside
3949 * the element the event handlers are bound to.
3950 *
3951 * @return An object containing event handlers. Bind the event handlers to a
3952 * wrapping element element to capture when focus moves outside that element.
3953 */
3954 function useFocusOutside(onFocusOutside) {
3955 const currentOnFocusOutside = (0,external_wp_element_namespaceObject.useRef)(onFocusOutside);
3956 (0,external_wp_element_namespaceObject.useEffect)(() => {
3957 currentOnFocusOutside.current = onFocusOutside;
3958 }, [onFocusOutside]);
3959 const preventBlurCheck = (0,external_wp_element_namespaceObject.useRef)(false);
3960 const blurCheckTimeoutId = (0,external_wp_element_namespaceObject.useRef)();
3961 /**
3962 * Cancel a blur check timeout.
3963 */
3964
3965 const cancelBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(() => {
3966 clearTimeout(blurCheckTimeoutId.current);
3967 }, []); // Cancel blur checks on unmount.
3968
3969 (0,external_wp_element_namespaceObject.useEffect)(() => {
3970 return () => cancelBlurCheck();
3971 }, []); // Cancel a blur check if the callback or ref is no longer provided.
3972
3973 (0,external_wp_element_namespaceObject.useEffect)(() => {
3974 if (!onFocusOutside) {
3975 cancelBlurCheck();
3976 }
3977 }, [onFocusOutside, cancelBlurCheck]);
3978 /**
3979 * Handles a mousedown or mouseup event to respectively assign and
3980 * unassign a flag for preventing blur check on button elements. Some
3981 * browsers, namely Firefox and Safari, do not emit a focus event on
3982 * button elements when clicked, while others do. The logic here
3983 * intends to normalize this as treating click on buttons as focus.
3984 *
3985 * @param event
3986 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
3987 */
3988
3989 const normalizeButtonFocus = (0,external_wp_element_namespaceObject.useCallback)(event => {
3990 const {
3991 type,
3992 target
3993 } = event;
3994 const isInteractionEnd = ['mouseup', 'touchend'].includes(type);
3995
3996 if (isInteractionEnd) {
3997 preventBlurCheck.current = false;
3998 } else if (isFocusNormalizedButton(target)) {
3999 preventBlurCheck.current = true;
4000 }
4001 }, []);
4002 /**
4003 * A callback triggered when a blur event occurs on the element the handler
4004 * is bound to.
4005 *
4006 * Calls the `onFocusOutside` callback in an immediate timeout if focus has
4007 * move outside the bound element and is still within the document.
4008 */
4009
4010 const queueBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(event => {
4011 var _event$relatedTarget;
4012
4013 // React does not allow using an event reference asynchronously
4014 // due to recycling behavior, except when explicitly persisted.
4015 event.persist(); // Skip blur check if clicking button. See `normalizeButtonFocus`.
4016
4017 if (preventBlurCheck.current) {
4018 return;
4019 } // The usage of this attribute should be avoided. The only use case
4020 // would be when we load modals that are not React components and
4021 // therefore don't exist in the React tree. An example is opening
4022 // the Media Library modal from another dialog.
4023 // This attribute should contain a selector of the related target
4024 // we want to ignore, because we still need to trigger the blur event
4025 // on all other cases.
4026
4027
4028 const ignoreForRelatedTarget = event.target.getAttribute('data-unstable-ignore-focus-outside-for-relatedtarget');
4029
4030 if (ignoreForRelatedTarget && (_event$relatedTarget = event.relatedTarget) !== null && _event$relatedTarget !== void 0 && _event$relatedTarget.closest(ignoreForRelatedTarget)) {
4031 return;
4032 }
4033
4034 blurCheckTimeoutId.current = setTimeout(() => {
4035 // If document is not focused then focus should remain
4036 // inside the wrapped component and therefore we cancel
4037 // this blur event thereby leaving focus in place.
4038 // https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.
4039 if (!document.hasFocus()) {
4040 event.preventDefault();
4041 return;
4042 }
4043
4044 if ('function' === typeof currentOnFocusOutside.current) {
4045 currentOnFocusOutside.current(event);
4046 }
4047 }, 0);
4048 }, []);
4049 return {
4050 onFocus: cancelBlurCheck,
4051 onMouseDown: normalizeButtonFocus,
4052 onMouseUp: normalizeButtonFocus,
4053 onTouchStart: normalizeButtonFocus,
4054 onTouchEnd: normalizeButtonFocus,
4055 onBlur: queueBlurCheck
4056 };
4057 }
4058
4059 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-merge-refs/index.js
4060 /**
4061 * WordPress dependencies
4062 */
4063
4064 /* eslint-disable jsdoc/valid-types */
4065
4066 /**
4067 * @template T
4068 * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef
4069 */
4070
4071 /* eslint-enable jsdoc/valid-types */
4072
4073 /**
4074 * @template T
4075 * @param {import('react').Ref<T>} ref
4076 * @param {T} value
4077 */
4078
4079 function assignRef(ref, value) {
4080 if (typeof ref === 'function') {
4081 ref(value);
4082 } else if (ref && ref.hasOwnProperty('current')) {
4083 /* eslint-disable jsdoc/no-undefined-types */
4084
4085 /** @type {import('react').MutableRefObject<T>} */
4086 ref.current = value;
4087 /* eslint-enable jsdoc/no-undefined-types */
4088 }
4089 }
4090 /**
4091 * Merges refs into one ref callback.
4092 *
4093 * It also ensures that the merged ref callbacks are only called when they
4094 * change (as a result of a `useCallback` dependency update) OR when the ref
4095 * value changes, just as React does when passing a single ref callback to the
4096 * component.
4097 *
4098 * As expected, if you pass a new function on every render, the ref callback
4099 * will be called after every render.
4100 *
4101 * If you don't wish a ref callback to be called after every render, wrap it
4102 * with `useCallback( callback, dependencies )`. When a dependency changes, the
4103 * old ref callback will be called with `null` and the new ref callback will be
4104 * called with the same value.
4105 *
4106 * To make ref callbacks easier to use, you can also pass the result of
4107 * `useRefEffect`, which makes cleanup easier by allowing you to return a
4108 * cleanup function instead of handling `null`.
4109 *
4110 * It's also possible to _disable_ a ref (and its behaviour) by simply not
4111 * passing the ref.
4112 *
4113 * ```jsx
4114 * const ref = useRefEffect( ( node ) => {
4115 * node.addEventListener( ... );
4116 * return () => {
4117 * node.removeEventListener( ... );
4118 * };
4119 * }, [ ...dependencies ] );
4120 * const otherRef = useRef();
4121 * const mergedRefs useMergeRefs( [
4122 * enabled && ref,
4123 * otherRef,
4124 * ] );
4125 * return <div ref={ mergedRefs } />;
4126 * ```
4127 *
4128 * @template {import('react').Ref<any>} TRef
4129 * @param {Array<TRef>} refs The refs to be merged.
4130 *
4131 * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.
4132 */
4133
4134
4135 function useMergeRefs(refs) {
4136 const element = (0,external_wp_element_namespaceObject.useRef)();
4137 const isAttached = (0,external_wp_element_namespaceObject.useRef)(false);
4138 const didElementChange = (0,external_wp_element_namespaceObject.useRef)(false);
4139 /* eslint-disable jsdoc/no-undefined-types */
4140
4141 /** @type {import('react').MutableRefObject<TRef[]>} */
4142
4143 /* eslint-enable jsdoc/no-undefined-types */
4144
4145 const previousRefs = (0,external_wp_element_namespaceObject.useRef)([]);
4146 const currentRefs = (0,external_wp_element_namespaceObject.useRef)(refs); // Update on render before the ref callback is called, so the ref callback
4147 // always has access to the current refs.
4148
4149 currentRefs.current = refs; // If any of the refs change, call the previous ref with `null` and the new
4150 // ref with the node, except when the element changes in the same cycle, in
4151 // which case the ref callbacks will already have been called.
4152
4153 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
4154 if (didElementChange.current === false && isAttached.current === true) {
4155 refs.forEach((ref, index) => {
4156 const previousRef = previousRefs.current[index];
4157
4158 if (ref !== previousRef) {
4159 assignRef(previousRef, null);
4160 assignRef(ref, element.current);
4161 }
4162 });
4163 }
4164
4165 previousRefs.current = refs;
4166 }, refs); // No dependencies, must be reset after every render so ref callbacks are
4167 // correctly called after a ref change.
4168
4169 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
4170 didElementChange.current = false;
4171 }); // There should be no dependencies so that `callback` is only called when
4172 // the node changes.
4173
4174 return (0,external_wp_element_namespaceObject.useCallback)(value => {
4175 // Update the element so it can be used when calling ref callbacks on a
4176 // dependency change.
4177 assignRef(element, value);
4178 didElementChange.current = true;
4179 isAttached.current = value !== null; // When an element changes, the current ref callback should be called
4180 // with the new element and the previous one with `null`.
4181
4182 const refsToAssign = value ? currentRefs.current : previousRefs.current; // Update the latest refs.
4183
4184 for (const ref of refsToAssign) {
4185 assignRef(ref, value);
4186 }
4187 }, []);
4188 }
4189
4190 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-dialog/index.js
4191 /**
4192 * External dependencies
4193 */
4194
4195 /**
4196 * WordPress dependencies
4197 */
4198
4199
4200 /**
4201 * Internal dependencies
4202 */
4203
4204
4205
4206
4207
4208
4209
4210 /**
4211 * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:
4212 * - constrained tabbing.
4213 * - focus on mount.
4214 * - return focus on unmount.
4215 * - focus outside.
4216 *
4217 * @param options Dialog Options.
4218 */
4219 function useDialog(options) {
4220 const currentOptions = (0,external_wp_element_namespaceObject.useRef)();
4221 (0,external_wp_element_namespaceObject.useEffect)(() => {
4222 currentOptions.current = options;
4223 }, Object.values(options));
4224 const constrainedTabbingRef = use_constrained_tabbing();
4225 const focusOnMountRef = useFocusOnMount(options.focusOnMount);
4226 const focusReturnRef = use_focus_return();
4227 const focusOutsideProps = useFocusOutside(event => {
4228 var _currentOptions$curre, _currentOptions$curre2;
4229
4230 // This unstable prop is here only to manage backward compatibility
4231 // for the Popover component otherwise, the onClose should be enough.
4232 if ((_currentOptions$curre = currentOptions.current) !== null && _currentOptions$curre !== void 0 && _currentOptions$curre.__unstableOnClose) {
4233 currentOptions.current.__unstableOnClose('focus-outside', event);
4234 } else if ((_currentOptions$curre2 = currentOptions.current) !== null && _currentOptions$curre2 !== void 0 && _currentOptions$curre2.onClose) {
4235 currentOptions.current.onClose();
4236 }
4237 });
4238 const closeOnEscapeRef = (0,external_wp_element_namespaceObject.useCallback)(node => {
4239 if (!node) {
4240 return;
4241 }
4242
4243 node.addEventListener('keydown', event => {
4244 var _currentOptions$curre3;
4245
4246 // Close on escape.
4247 if (event.keyCode === external_wp_keycodes_namespaceObject.ESCAPE && !event.defaultPrevented && (_currentOptions$curre3 = currentOptions.current) !== null && _currentOptions$curre3 !== void 0 && _currentOptions$curre3.onClose) {
4248 event.preventDefault();
4249 currentOptions.current.onClose();
4250 }
4251 });
4252 }, []);
4253 return [useMergeRefs([options.focusOnMount !== false ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), { ...focusOutsideProps,
4254 tabIndex: -1
4255 }];
4256 }
4257
4258 /* harmony default export */ var use_dialog = (useDialog);
4259
4260 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-disabled/index.js
4261 /**
4262 * Internal dependencies
4263 */
4264
4265
4266 /**
4267 * In some circumstances, such as block previews, all focusable DOM elements
4268 * (input fields, links, buttons, etc.) need to be disabled. This hook adds the
4269 * behavior to disable nested DOM elements to the returned ref.
4270 *
4271 * If you can, prefer the use of the inert HTML attribute.
4272 *
4273 * @param {Object} config Configuration object.
4274 * @param {boolean=} config.isDisabled Whether the element should be disabled.
4275 * @return {import('react').RefCallback<HTMLElement>} Element Ref.
4276 *
4277 * @example
4278 * ```js
4279 * import { useDisabled } from '@wordpress/compose';
4280 *
4281 * const DisabledExample = () => {
4282 * const disabledRef = useDisabled();
4283 * return (
4284 * <div ref={ disabledRef }>
4285 * <a href="#">This link will have tabindex set to -1</a>
4286 * <input placeholder="This input will have the disabled attribute added to it." type="text" />
4287 * </div>
4288 * );
4289 * };
4290 * ```
4291 */
4292
4293 function useDisabled() {
4294 let {
4295 isDisabled: isDisabledProp = false
4296 } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4297 return useRefEffect(node => {
4298 if (isDisabledProp) {
4299 return;
4300 }
4301 /** A variable keeping track of the previous updates in order to restore them. */
4302
4303
4304 const updates = [];
4305
4306 const disable = () => {
4307 node.childNodes.forEach(child => {
4308 if (!(child instanceof HTMLElement)) {
4309 return;
4310 }
4311
4312 if (!child.getAttribute('inert')) {
4313 child.setAttribute('inert', 'true');
4314 updates.push(() => {
4315 child.removeAttribute('inert');
4316 });
4317 }
4318 });
4319 }; // Debounce re-disable since disabling process itself will incur
4320 // additional mutations which should be ignored.
4321
4322
4323 const debouncedDisable = debounce(disable, 0, {
4324 leading: true
4325 });
4326 disable();
4327 /** @type {MutationObserver | undefined} */
4328
4329 const observer = new window.MutationObserver(debouncedDisable);
4330 observer.observe(node, {
4331 childList: true
4332 });
4333 return () => {
4334 if (observer) {
4335 observer.disconnect();
4336 }
4337
4338 debouncedDisable.cancel();
4339 updates.forEach(update => update());
4340 };
4341 }, [isDisabledProp]);
4342 }
4343
4344 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-isomorphic-layout-effect/index.js
4345 /**
4346 * WordPress dependencies
4347 */
4348
4349 /**
4350 * Preferred over direct usage of `useLayoutEffect` when supporting
4351 * server rendered components (SSR) because currently React
4352 * throws a warning when using useLayoutEffect in that environment.
4353 */
4354
4355 const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_namespaceObject.useLayoutEffect : external_wp_element_namespaceObject.useEffect;
4356 /* harmony default export */ var use_isomorphic_layout_effect = (useIsomorphicLayoutEffect);
4357
4358 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-dragging/index.js
4359 /**
4360 * WordPress dependencies
4361 */
4362
4363 /**
4364 * Internal dependencies
4365 */
4366
4367 // Event handlers that are triggered from `document` listeners accept a MouseEvent,
4368 // while those triggered from React listeners accept a React.MouseEvent.
4369
4370 /**
4371 * @param {Object} props
4372 * @param {(e: import('react').MouseEvent) => void} props.onDragStart
4373 * @param {(e: MouseEvent) => void} props.onDragMove
4374 * @param {(e?: MouseEvent) => void} props.onDragEnd
4375 */
4376
4377 function useDragging(_ref) {
4378 let {
4379 onDragStart,
4380 onDragMove,
4381 onDragEnd
4382 } = _ref;
4383 const [isDragging, setIsDragging] = (0,external_wp_element_namespaceObject.useState)(false);
4384 const eventsRef = (0,external_wp_element_namespaceObject.useRef)({
4385 onDragStart,
4386 onDragMove,
4387 onDragEnd
4388 });
4389 use_isomorphic_layout_effect(() => {
4390 eventsRef.current.onDragStart = onDragStart;
4391 eventsRef.current.onDragMove = onDragMove;
4392 eventsRef.current.onDragEnd = onDragEnd;
4393 }, [onDragStart, onDragMove, onDragEnd]);
4394 /** @type {(e: MouseEvent) => void} */
4395
4396 const onMouseMove = (0,external_wp_element_namespaceObject.useCallback)(event => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), []);
4397 /** @type {(e?: MouseEvent) => void} */
4398
4399 const endDrag = (0,external_wp_element_namespaceObject.useCallback)(event => {
4400 if (eventsRef.current.onDragEnd) {
4401 eventsRef.current.onDragEnd(event);
4402 }
4403
4404 document.removeEventListener('mousemove', onMouseMove);
4405 document.removeEventListener('mouseup', endDrag);
4406 setIsDragging(false);
4407 }, []);
4408 /** @type {(e: import('react').MouseEvent) => void} */
4409
4410 const startDrag = (0,external_wp_element_namespaceObject.useCallback)(event => {
4411 if (eventsRef.current.onDragStart) {
4412 eventsRef.current.onDragStart(event);
4413 }
4414
4415 document.addEventListener('mousemove', onMouseMove);
4416 document.addEventListener('mouseup', endDrag);
4417 setIsDragging(true);
4418 }, []); // Remove the global events when unmounting if needed.
4419
4420 (0,external_wp_element_namespaceObject.useEffect)(() => {
4421 return () => {
4422 if (isDragging) {
4423 document.removeEventListener('mousemove', onMouseMove);
4424 document.removeEventListener('mouseup', endDrag);
4425 }
4426 };
4427 }, [isDragging]);
4428 return {
4429 startDrag,
4430 endDrag,
4431 isDragging
4432 };
4433 }
4434
4435 // EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js
4436 var mousetrap_mousetrap = __webpack_require__(7973);
4437 var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap);
4438 // EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
4439 var mousetrap_global_bind = __webpack_require__(5538);
4440 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-keyboard-shortcut/index.js
4441 /**
4442 * External dependencies
4443 */
4444
4445
4446 /**
4447 * WordPress dependencies
4448 */
4449
4450
4451
4452 /**
4453 * A block selection object.
4454 *
4455 * @typedef {Object} WPKeyboardShortcutConfig
4456 *
4457 * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.
4458 * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.
4459 * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.
4460 * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.
4461 */
4462
4463 /* eslint-disable jsdoc/valid-types */
4464
4465 /**
4466 * Attach a keyboard shortcut handler.
4467 *
4468 * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.
4469 *
4470 * @param {string[]|string} shortcuts Keyboard Shortcuts.
4471 * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.
4472 * @param {WPKeyboardShortcutConfig} options Shortcut options.
4473 */
4474
4475 function useKeyboardShortcut(
4476 /* eslint-enable jsdoc/valid-types */
4477 shortcuts, callback) {
4478 let {
4479 bindGlobal = false,
4480 eventName = 'keydown',
4481 isDisabled = false,
4482 // This is important for performance considerations.
4483 target
4484 } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4485 const currentCallback = (0,external_wp_element_namespaceObject.useRef)(callback);
4486 (0,external_wp_element_namespaceObject.useEffect)(() => {
4487 currentCallback.current = callback;
4488 }, [callback]);
4489 (0,external_wp_element_namespaceObject.useEffect)(() => {
4490 if (isDisabled) {
4491 return;
4492 }
4493
4494 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`.
4495 // 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
4496 // necessary to maintain the existing behavior.
4497
4498 /** @type {Element} */
4499
4500 /** @type {unknown} */
4501 document);
4502 const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
4503 shortcutsArray.forEach(shortcut => {
4504 const keys = shortcut.split('+'); // Determines whether a key is a modifier by the length of the string.
4505 // E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that
4506 // the modifiers are Shift and Cmd because they're not a single character.
4507
4508 const modifiers = new Set(keys.filter(value => value.length > 1));
4509 const hasAlt = modifiers.has('alt');
4510 const hasShift = modifiers.has('shift'); // This should be better moved to the shortcut registration instead.
4511
4512 if ((0,external_wp_keycodes_namespaceObject.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
4513 throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`);
4514 }
4515
4516 const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; // @ts-ignore `bindGlobal` is an undocumented property
4517
4518 mousetrap[bindFn](shortcut, function () {
4519 return (
4520 /* eslint-enable jsdoc/valid-types */
4521 currentCallback.current(...arguments)
4522 );
4523 }, eventName);
4524 });
4525 return () => {
4526 mousetrap.reset();
4527 };
4528 }, [shortcuts, bindGlobal, eventName, target, isDisabled]);
4529 }
4530
4531 /* harmony default export */ var use_keyboard_shortcut = (useKeyboardShortcut);
4532
4533 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-media-query/index.js
4534 /**
4535 * WordPress dependencies
4536 */
4537
4538 /**
4539 * Runs a media query and returns its value when it changes.
4540 *
4541 * @param {string} [query] Media Query.
4542 * @return {boolean} return value of the media query.
4543 */
4544
4545 function useMediaQuery(query) {
4546 const [match, setMatch] = (0,external_wp_element_namespaceObject.useState)(() => !!(query && typeof window !== 'undefined' && window.matchMedia(query).matches));
4547 (0,external_wp_element_namespaceObject.useEffect)(() => {
4548 if (!query) {
4549 return;
4550 }
4551
4552 const updateMatch = () => setMatch(window.matchMedia(query).matches);
4553
4554 updateMatch();
4555 const list = window.matchMedia(query);
4556 list.addListener(updateMatch);
4557 return () => {
4558 list.removeListener(updateMatch);
4559 };
4560 }, [query]);
4561 return !!query && match;
4562 }
4563
4564 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-previous/index.js
4565 /**
4566 * WordPress dependencies
4567 */
4568
4569 /**
4570 * Use something's value from the previous render.
4571 * Based on https://usehooks.com/usePrevious/.
4572 *
4573 * @param value The value to track.
4574 *
4575 * @return The value from the previous render.
4576 */
4577
4578 function usePrevious(value) {
4579 const ref = (0,external_wp_element_namespaceObject.useRef)(); // Store current value in ref.
4580
4581 (0,external_wp_element_namespaceObject.useEffect)(() => {
4582 ref.current = value;
4583 }, [value]); // Re-run when value changes.
4584 // Return previous value (happens before update in useEffect above).
4585
4586 return ref.current;
4587 }
4588
4589 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-reduced-motion/index.js
4590 /**
4591 * Internal dependencies
4592 */
4593
4594 /**
4595 * Hook returning whether the user has a preference for reduced motion.
4596 *
4597 * @return {boolean} Reduced motion preference value.
4598 */
4599
4600 const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)');
4601
4602 /* harmony default export */ var use_reduced_motion = (useReducedMotion);
4603
4604 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-viewport-match/index.js
4605 /**
4606 * WordPress dependencies
4607 */
4608
4609 /**
4610 * Internal dependencies
4611 */
4612
4613
4614 /**
4615 * @typedef {"huge" | "wide" | "large" | "medium" | "small" | "mobile"} WPBreakpoint
4616 */
4617
4618 /**
4619 * Hash of breakpoint names with pixel width at which it becomes effective.
4620 *
4621 * @see _breakpoints.scss
4622 *
4623 * @type {Record<WPBreakpoint, number>}
4624 */
4625
4626 const BREAKPOINTS = {
4627 huge: 1440,
4628 wide: 1280,
4629 large: 960,
4630 medium: 782,
4631 small: 600,
4632 mobile: 480
4633 };
4634 /**
4635 * @typedef {">=" | "<"} WPViewportOperator
4636 */
4637
4638 /**
4639 * Object mapping media query operators to the condition to be used.
4640 *
4641 * @type {Record<WPViewportOperator, string>}
4642 */
4643
4644 const CONDITIONS = {
4645 '>=': 'min-width',
4646 '<': 'max-width'
4647 };
4648 /**
4649 * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.
4650 *
4651 * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}
4652 */
4653
4654 const OPERATOR_EVALUATORS = {
4655 '>=': (breakpointValue, width) => width >= breakpointValue,
4656 '<': (breakpointValue, width) => width < breakpointValue
4657 };
4658 const ViewportMatchWidthContext = (0,external_wp_element_namespaceObject.createContext)(
4659 /** @type {null | number} */
4660 null);
4661 /**
4662 * Returns true if the viewport matches the given query, or false otherwise.
4663 *
4664 * @param {WPBreakpoint} breakpoint Breakpoint size name.
4665 * @param {WPViewportOperator} [operator=">="] Viewport operator.
4666 *
4667 * @example
4668 *
4669 * ```js
4670 * useViewportMatch( 'huge', '<' );
4671 * useViewportMatch( 'medium' );
4672 * ```
4673 *
4674 * @return {boolean} Whether viewport matches query.
4675 */
4676
4677 const useViewportMatch = function (breakpoint) {
4678 let operator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '>=';
4679 const simulatedWidth = (0,external_wp_element_namespaceObject.useContext)(ViewportMatchWidthContext);
4680 const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
4681 const mediaQueryResult = useMediaQuery(mediaQuery || undefined);
4682
4683 if (simulatedWidth) {
4684 return OPERATOR_EVALUATORS[operator](BREAKPOINTS[breakpoint], simulatedWidth);
4685 }
4686
4687 return mediaQueryResult;
4688 };
4689
4690 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
4691 /* harmony default export */ var use_viewport_match = (useViewportMatch);
4692
4693 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-resize-observer/index.js
4694
4695
4696 /**
4697 * External dependencies
4698 */
4699
4700 /**
4701 * WordPress dependencies
4702 */
4703
4704
4705 // This of course could've been more streamlined with internal state instead of
4706 // refs, but then host hooks / components could not opt out of renders.
4707 // This could've been exported to its own module, but the current build doesn't
4708 // seem to work with module imports and I had no more time to spend on this...
4709 function useResolvedElement(subscriber, refOrElement) {
4710 const callbackRefElement = (0,external_wp_element_namespaceObject.useRef)(null);
4711 const lastReportRef = (0,external_wp_element_namespaceObject.useRef)(null);
4712 const cleanupRef = (0,external_wp_element_namespaceObject.useRef)();
4713 const callSubscriber = (0,external_wp_element_namespaceObject.useCallback)(() => {
4714 let element = null;
4715
4716 if (callbackRefElement.current) {
4717 element = callbackRefElement.current;
4718 } else if (refOrElement) {
4719 if (refOrElement instanceof HTMLElement) {
4720 element = refOrElement;
4721 } else {
4722 element = refOrElement.current;
4723 }
4724 }
4725
4726 if (lastReportRef.current && lastReportRef.current.element === element && lastReportRef.current.reporter === callSubscriber) {
4727 return;
4728 }
4729
4730 if (cleanupRef.current) {
4731 cleanupRef.current(); // Making sure the cleanup is not called accidentally multiple times.
4732
4733 cleanupRef.current = null;
4734 }
4735
4736 lastReportRef.current = {
4737 reporter: callSubscriber,
4738 element
4739 }; // Only calling the subscriber, if there's an actual element to report.
4740
4741 if (element) {
4742 cleanupRef.current = subscriber(element);
4743 }
4744 }, [refOrElement, subscriber]); // On each render, we check whether a ref changed, or if we got a new raw
4745 // element.
4746
4747 (0,external_wp_element_namespaceObject.useEffect)(() => {
4748 // With this we're *technically* supporting cases where ref objects' current value changes, but only if there's a
4749 // render accompanying that change as well.
4750 // To guarantee we always have the right element, one must use the ref callback provided instead, but we support
4751 // RefObjects to make the hook API more convenient in certain cases.
4752 callSubscriber();
4753 }, [callSubscriber]);
4754 return (0,external_wp_element_namespaceObject.useCallback)(element => {
4755 callbackRefElement.current = element;
4756 callSubscriber();
4757 }, [callSubscriber]);
4758 }
4759
4760 // We're only using the first element of the size sequences, until future versions of the spec solidify on how
4761 // exactly it'll be used for fragments in multi-column scenarios:
4762 // From the spec:
4763 // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,
4764 // > which occur in multi-column scenarios. However the current definitions of content rect and border box do not
4765 // > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single
4766 // > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.
4767 // > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.
4768 // (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)
4769 //
4770 // Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,
4771 // regardless of the "box" option.
4772 // The spec states the following on this:
4773 // > This does not have any impact on which box dimensions are returned to the defined callback when the event
4774 // > is fired, it solely defines which box the author wishes to observe layout changes on.
4775 // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
4776 // I'm not exactly clear on what this means, especially when you consider a later section stating the following:
4777 // > This section is non-normative. An author may desire to observe more than one CSS box.
4778 // > In this case, author will need to use multiple ResizeObservers.
4779 // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
4780 // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.
4781 // For this reason I decided to only return the requested size,
4782 // even though it seems we have access to results for all box types.
4783 // This also means that we get to keep the current api, being able to return a simple { width, height } pair,
4784 // regardless of box option.
4785 const extractSize = (entry, boxProp, sizeType) => {
4786 if (!entry[boxProp]) {
4787 if (boxProp === 'contentBoxSize') {
4788 // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.
4789 // See the 6th step in the description for the RO algorithm:
4790 // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h
4791 // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box".
4792 // In real browser implementations of course these objects differ, but the width/height values should be equivalent.
4793 return entry.contentRect[sizeType === 'inlineSize' ? 'width' : 'height'];
4794 }
4795
4796 return undefined;
4797 } // A couple bytes smaller than calling Array.isArray() and just as effective here.
4798
4799
4800 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
4801 // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.
4802 // @ts-ignore
4803 entry[boxProp][sizeType];
4804 };
4805
4806 function useResizeObserver() {
4807 let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4808 // Saving the callback as a ref. With this, I don't need to put onResize in the
4809 // effect dep array, and just passing in an anonymous function without memoising
4810 // will not reinstantiate the hook's ResizeObserver.
4811 const onResize = opts.onResize;
4812 const onResizeRef = (0,external_wp_element_namespaceObject.useRef)(undefined);
4813 onResizeRef.current = onResize;
4814 const round = opts.round || Math.round; // Using a single instance throughout the hook's lifetime
4815
4816 const resizeObserverRef = (0,external_wp_element_namespaceObject.useRef)();
4817 const [size, setSize] = (0,external_wp_element_namespaceObject.useState)({
4818 width: undefined,
4819 height: undefined
4820 }); // In certain edge cases the RO might want to report a size change just after
4821 // the component unmounted.
4822
4823 const didUnmount = (0,external_wp_element_namespaceObject.useRef)(false);
4824 (0,external_wp_element_namespaceObject.useEffect)(() => {
4825 return () => {
4826 didUnmount.current = true;
4827 };
4828 }, []); // Using a ref to track the previous width / height to avoid unnecessary renders.
4829
4830 const previous = (0,external_wp_element_namespaceObject.useRef)({
4831 width: undefined,
4832 height: undefined
4833 }); // This block is kinda like a useEffect, only it's called whenever a new
4834 // element could be resolved based on the ref option. It also has a cleanup
4835 // function.
4836
4837 const refCallback = useResolvedElement((0,external_wp_element_namespaceObject.useCallback)(element => {
4838 // We only use a single Resize Observer instance, and we're instantiating it on demand, only once there's something to observe.
4839 // 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.
4840 if (!resizeObserverRef.current || resizeObserverRef.current.box !== opts.box || resizeObserverRef.current.round !== round) {
4841 resizeObserverRef.current = {
4842 box: opts.box,
4843 round,
4844 instance: new ResizeObserver(entries => {
4845 const entry = entries[0];
4846 let boxProp = 'borderBoxSize';
4847
4848 if (opts.box === 'border-box') {
4849 boxProp = 'borderBoxSize';
4850 } else {
4851 boxProp = opts.box === 'device-pixel-content-box' ? 'devicePixelContentBoxSize' : 'contentBoxSize';
4852 }
4853
4854 const reportedWidth = extractSize(entry, boxProp, 'inlineSize');
4855 const reportedHeight = extractSize(entry, boxProp, 'blockSize');
4856 const newWidth = reportedWidth ? round(reportedWidth) : undefined;
4857 const newHeight = reportedHeight ? round(reportedHeight) : undefined;
4858
4859 if (previous.current.width !== newWidth || previous.current.height !== newHeight) {
4860 const newSize = {
4861 width: newWidth,
4862 height: newHeight
4863 };
4864 previous.current.width = newWidth;
4865 previous.current.height = newHeight;
4866
4867 if (onResizeRef.current) {
4868 onResizeRef.current(newSize);
4869 } else if (!didUnmount.current) {
4870 setSize(newSize);
4871 }
4872 }
4873 })
4874 };
4875 }
4876
4877 resizeObserverRef.current.instance.observe(element, {
4878 box: opts.box
4879 });
4880 return () => {
4881 if (resizeObserverRef.current) {
4882 resizeObserverRef.current.instance.unobserve(element);
4883 }
4884 };
4885 }, [opts.box, round]), opts.ref);
4886 return (0,external_wp_element_namespaceObject.useMemo)(() => ({
4887 ref: refCallback,
4888 width: size.width,
4889 height: size.height
4890 }), [refCallback, size ? size.width : null, size ? size.height : null]);
4891 }
4892 /**
4893 * Hook which allows to listen the resize event of any target element when it changes sizes.
4894 * _Note: `useResizeObserver` will report `null` until after first render.
4895 *
4896 * @example
4897 *
4898 * ```js
4899 * const App = () => {
4900 * const [ resizeListener, sizes ] = useResizeObserver();
4901 *
4902 * return (
4903 * <div>
4904 * { resizeListener }
4905 * Your content here
4906 * </div>
4907 * );
4908 * };
4909 * ```
4910 */
4911
4912
4913 function useResizeAware() {
4914 const {
4915 ref,
4916 width,
4917 height
4918 } = useResizeObserver();
4919 const sizes = (0,external_wp_element_namespaceObject.useMemo)(() => {
4920 return {
4921 width: width !== null && width !== void 0 ? width : null,
4922 height: height !== null && height !== void 0 ? height : null
4923 };
4924 }, [width, height]);
4925 const resizeListener = (0,external_wp_element_namespaceObject.createElement)("div", {
4926 style: {
4927 position: 'absolute',
4928 top: 0,
4929 left: 0,
4930 right: 0,
4931 bottom: 0,
4932 pointerEvents: 'none',
4933 opacity: 0,
4934 overflow: 'hidden',
4935 zIndex: -1
4936 },
4937 "aria-hidden": "true",
4938 ref: ref
4939 });
4940 return [resizeListener, sizes];
4941 }
4942
4943 ;// CONCATENATED MODULE: external ["wp","priorityQueue"]
4944 var external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"];
4945 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-async-list/index.js
4946 /**
4947 * WordPress dependencies
4948 */
4949
4950
4951
4952 /**
4953 * Returns the first items from list that are present on state.
4954 *
4955 * @param list New array.
4956 * @param state Current state.
4957 * @return First items present iin state.
4958 */
4959 function getFirstItemsPresentInState(list, state) {
4960 const firstItems = [];
4961
4962 for (let i = 0; i < list.length; i++) {
4963 const item = list[i];
4964
4965 if (!state.includes(item)) {
4966 break;
4967 }
4968
4969 firstItems.push(item);
4970 }
4971
4972 return firstItems;
4973 }
4974 /**
4975 * React hook returns an array which items get asynchronously appended from a source array.
4976 * This behavior is useful if we want to render a list of items asynchronously for performance reasons.
4977 *
4978 * @param list Source array.
4979 * @param config Configuration object.
4980 *
4981 * @return Async array.
4982 */
4983
4984
4985 function useAsyncList(list) {
4986 let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
4987 step: 1
4988 };
4989 const {
4990 step = 1
4991 } = config;
4992 const [current, setCurrent] = (0,external_wp_element_namespaceObject.useState)([]);
4993 (0,external_wp_element_namespaceObject.useEffect)(() => {
4994 // On reset, we keep the first items that were previously rendered.
4995 let firstItems = getFirstItemsPresentInState(list, current);
4996
4997 if (firstItems.length < step) {
4998 firstItems = firstItems.concat(list.slice(firstItems.length, step));
4999 }
5000
5001 setCurrent(firstItems);
5002 let nextIndex = firstItems.length;
5003 const asyncQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)();
5004
5005 const append = () => {
5006 if (list.length <= nextIndex) {
5007 return;
5008 }
5009
5010 setCurrent(state => [...state, ...list.slice(nextIndex, nextIndex + step)]);
5011 nextIndex += step;
5012 asyncQueue.add({}, append);
5013 };
5014
5015 asyncQueue.add({}, append);
5016 return () => asyncQueue.reset();
5017 }, [list]);
5018 return current;
5019 }
5020
5021 /* harmony default export */ var use_async_list = (useAsyncList);
5022
5023 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-warn-on-change/index.js
5024 /**
5025 * Internal dependencies
5026 */
5027 // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case
5028 // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript
5029
5030 /* eslint-disable jsdoc/check-types */
5031
5032 /**
5033 * Hook that performs a shallow comparison between the preview value of an object
5034 * and the new one, if there's a difference, it prints it to the console.
5035 * this is useful in performance related work, to check why a component re-renders.
5036 *
5037 * @example
5038 *
5039 * ```jsx
5040 * function MyComponent(props) {
5041 * useWarnOnChange(props);
5042 *
5043 * return "Something";
5044 * }
5045 * ```
5046 *
5047 * @param {object} object Object which changes to compare.
5048 * @param {string} prefix Just a prefix to show when console logging.
5049 */
5050
5051 function useWarnOnChange(object) {
5052 let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Change detection';
5053 const previousValues = usePrevious(object);
5054 Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(_ref => {
5055 let [key, value] = _ref;
5056
5057 if (value !== object[
5058 /** @type {keyof typeof object} */
5059 key]) {
5060 // eslint-disable-next-line no-console
5061 console.warn(`${prefix}: ${key} key changed:`, value, object[
5062 /** @type {keyof typeof object} */
5063 key]
5064 /* eslint-enable jsdoc/check-types */
5065 );
5066 }
5067 });
5068 }
5069
5070 /* harmony default export */ var use_warn_on_change = (useWarnOnChange);
5071
5072 ;// CONCATENATED MODULE: external "React"
5073 var external_React_namespaceObject = window["React"];
5074 ;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js
5075
5076
5077 function areInputsEqual(newInputs, lastInputs) {
5078 if (newInputs.length !== lastInputs.length) {
5079 return false;
5080 }
5081
5082 for (var i = 0; i < newInputs.length; i++) {
5083 if (newInputs[i] !== lastInputs[i]) {
5084 return false;
5085 }
5086 }
5087
5088 return true;
5089 }
5090
5091 function useMemoOne(getResult, inputs) {
5092 var initial = (0,external_React_namespaceObject.useState)(function () {
5093 return {
5094 inputs: inputs,
5095 result: getResult()
5096 };
5097 })[0];
5098 var committed = (0,external_React_namespaceObject.useRef)(initial);
5099 var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs));
5100 var cache = isInputMatch ? committed.current : {
5101 inputs: inputs,
5102 result: getResult()
5103 };
5104 (0,external_React_namespaceObject.useEffect)(function () {
5105 committed.current = cache;
5106 }, [cache]);
5107 return cache.result;
5108 }
5109 function useCallbackOne(callback, inputs) {
5110 return useMemoOne(function () {
5111 return callback;
5112 }, inputs);
5113 }
5114 var useMemo = (/* unused pure expression or super */ null && (useMemoOne));
5115 var useCallback = (/* unused pure expression or super */ null && (useCallbackOne));
5116
5117
5118
5119 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-debounce/index.js
5120 /**
5121 * External dependencies
5122 */
5123
5124 /**
5125 * WordPress dependencies
5126 */
5127
5128
5129 /**
5130 * Internal dependencies
5131 */
5132
5133
5134 /**
5135 * Debounces a function similar to Lodash's `debounce`. A new debounced function will
5136 * be returned and any scheduled calls cancelled if any of the arguments change,
5137 * including the function to debounce, so please wrap functions created on
5138 * render in components in `useCallback`.
5139 *
5140 * @see https://docs-lodash.com/v4/debounce/
5141 *
5142 * @template {(...args: any[]) => void} TFunc
5143 *
5144 * @param {TFunc} fn The function to debounce.
5145 * @param {number} [wait] The number of milliseconds to delay.
5146 * @param {import('../../utils/debounce').DebounceOptions} [options] The options object.
5147 * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function.
5148 */
5149
5150 function useDebounce(fn, wait, options) {
5151 const debounced = useMemoOne(() => debounce(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]);
5152 (0,external_wp_element_namespaceObject.useEffect)(() => () => debounced.cancel(), [debounced]);
5153 return debounced;
5154 }
5155
5156 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-throttle/index.js
5157 /**
5158 * External dependencies
5159 */
5160
5161 /**
5162 * WordPress dependencies
5163 */
5164
5165
5166 /**
5167 * Internal dependencies
5168 */
5169
5170
5171 /**
5172 * Throttles a function similar to Lodash's `throttle`. A new throttled function will
5173 * be returned and any scheduled calls cancelled if any of the arguments change,
5174 * including the function to throttle, so please wrap functions created on
5175 * render in components in `useCallback`.
5176 *
5177 * @see https://docs-lodash.com/v4/throttle/
5178 *
5179 * @template {(...args: any[]) => void} TFunc
5180 *
5181 * @param {TFunc} fn The function to throttle.
5182 * @param {number} [wait] The number of milliseconds to throttle invocations to.
5183 * @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.
5184 * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.
5185 */
5186
5187 function useThrottle(fn, wait, options) {
5188 const throttled = useMemoOne(() => throttle(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]);
5189 (0,external_wp_element_namespaceObject.useEffect)(() => () => throttled.cancel(), [throttled]);
5190 return throttled;
5191 }
5192
5193 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-drop-zone/index.js
5194 /**
5195 * WordPress dependencies
5196 */
5197
5198 /**
5199 * Internal dependencies
5200 */
5201
5202
5203 /* eslint-disable jsdoc/valid-types */
5204
5205 /**
5206 * @template T
5207 * @param {T} value
5208 * @return {import('react').MutableRefObject<T|null>} A ref with the value.
5209 */
5210
5211 function useFreshRef(value) {
5212 /* eslint-enable jsdoc/valid-types */
5213
5214 /* eslint-disable jsdoc/no-undefined-types */
5215
5216 /** @type {import('react').MutableRefObject<T>} */
5217
5218 /* eslint-enable jsdoc/no-undefined-types */
5219 // Disable reason: We're doing something pretty JavaScript-y here where the
5220 // ref will always have a current value that is not null or undefined but it
5221 // needs to start as undefined. We don't want to change the return type so
5222 // it's easier to just ts-ignore this specific line that's complaining about
5223 // undefined not being part of T.
5224 // @ts-ignore
5225 const ref = (0,external_wp_element_namespaceObject.useRef)();
5226 ref.current = value;
5227 return ref;
5228 }
5229 /**
5230 * A hook to facilitate drag and drop handling.
5231 *
5232 * @param {Object} props Named parameters.
5233 * @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.
5234 * @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.
5235 * @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.
5236 * @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.
5237 * @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.
5238 * @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.
5239 * @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.
5240 *
5241 * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.
5242 */
5243
5244
5245 function useDropZone(_ref) {
5246 let {
5247 isDisabled,
5248 onDrop: _onDrop,
5249 onDragStart: _onDragStart,
5250 onDragEnter: _onDragEnter,
5251 onDragLeave: _onDragLeave,
5252 onDragEnd: _onDragEnd,
5253 onDragOver: _onDragOver
5254 } = _ref;
5255 const onDropRef = useFreshRef(_onDrop);
5256 const onDragStartRef = useFreshRef(_onDragStart);
5257 const onDragEnterRef = useFreshRef(_onDragEnter);
5258 const onDragLeaveRef = useFreshRef(_onDragLeave);
5259 const onDragEndRef = useFreshRef(_onDragEnd);
5260 const onDragOverRef = useFreshRef(_onDragOver);
5261 return useRefEffect(element => {
5262 if (isDisabled) {
5263 return;
5264 }
5265
5266 let isDragging = false;
5267 const {
5268 ownerDocument
5269 } = element;
5270 /**
5271 * Checks if an element is in the drop zone.
5272 *
5273 * @param {EventTarget|null} targetToCheck
5274 *
5275 * @return {boolean} True if in drop zone, false if not.
5276 */
5277
5278 function isElementInZone(targetToCheck) {
5279 const {
5280 defaultView
5281 } = ownerDocument;
5282
5283 if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) {
5284 return false;
5285 }
5286 /** @type {HTMLElement|null} */
5287
5288
5289 let elementToCheck = targetToCheck;
5290
5291 do {
5292 if (elementToCheck.dataset.isDropZone) {
5293 return elementToCheck === element;
5294 }
5295 } while (elementToCheck = elementToCheck.parentElement);
5296
5297 return false;
5298 }
5299
5300 function maybeDragStart(
5301 /** @type {DragEvent} */
5302 event) {
5303 if (isDragging) {
5304 return;
5305 }
5306
5307 isDragging = true; // Note that `dragend` doesn't fire consistently for file and
5308 // HTML drag events where the drag origin is outside the browser
5309 // window. In Firefox it may also not fire if the originating
5310 // node is removed.
5311
5312 ownerDocument.addEventListener('dragend', maybeDragEnd);
5313 ownerDocument.addEventListener('mousemove', maybeDragEnd);
5314
5315 if (onDragStartRef.current) {
5316 onDragStartRef.current(event);
5317 }
5318 }
5319
5320 function onDragEnter(
5321 /** @type {DragEvent} */
5322 event) {
5323 event.preventDefault(); // The `dragenter` event will also fire when entering child
5324 // elements, but we only want to call `onDragEnter` when
5325 // entering the drop zone, which means the `relatedTarget`
5326 // (element that has been left) should be outside the drop zone.
5327
5328 if (element.contains(
5329 /** @type {Node} */
5330 event.relatedTarget)) {
5331 return;
5332 }
5333
5334 if (onDragEnterRef.current) {
5335 onDragEnterRef.current(event);
5336 }
5337 }
5338
5339 function onDragOver(
5340 /** @type {DragEvent} */
5341 event) {
5342 // Only call onDragOver for the innermost hovered drop zones.
5343 if (!event.defaultPrevented && onDragOverRef.current) {
5344 onDragOverRef.current(event);
5345 } // Prevent the browser default while also signalling to parent
5346 // drop zones that `onDragOver` is already handled.
5347
5348
5349 event.preventDefault();
5350 }
5351
5352 function onDragLeave(
5353 /** @type {DragEvent} */
5354 event) {
5355 // The `dragleave` event will also fire when leaving child
5356 // elements, but we only want to call `onDragLeave` when
5357 // leaving the drop zone, which means the `relatedTarget`
5358 // (element that has been entered) should be outside the drop
5359 // zone.
5360 // Note: This is not entirely reliable in Safari due to this bug
5361 // https://bugs.webkit.org/show_bug.cgi?id=66547
5362 if (isElementInZone(event.relatedTarget)) {
5363 return;
5364 }
5365
5366 if (onDragLeaveRef.current) {
5367 onDragLeaveRef.current(event);
5368 }
5369 }
5370
5371 function onDrop(
5372 /** @type {DragEvent} */
5373 event) {
5374 // Don't handle drop if an inner drop zone already handled it.
5375 if (event.defaultPrevented) {
5376 return;
5377 } // Prevent the browser default while also signalling to parent
5378 // drop zones that `onDrop` is already handled.
5379
5380
5381 event.preventDefault(); // This seemingly useless line has been shown to resolve a
5382 // Safari issue where files dragged directly from the dock are
5383 // not recognized.
5384 // eslint-disable-next-line no-unused-expressions
5385
5386 event.dataTransfer && event.dataTransfer.files.length;
5387
5388 if (onDropRef.current) {
5389 onDropRef.current(event);
5390 }
5391
5392 maybeDragEnd(event);
5393 }
5394
5395 function maybeDragEnd(
5396 /** @type {MouseEvent} */
5397 event) {
5398 if (!isDragging) {
5399 return;
5400 }
5401
5402 isDragging = false;
5403 ownerDocument.removeEventListener('dragend', maybeDragEnd);
5404 ownerDocument.removeEventListener('mousemove', maybeDragEnd);
5405
5406 if (onDragEndRef.current) {
5407 onDragEndRef.current(event);
5408 }
5409 }
5410
5411 element.dataset.isDropZone = 'true';
5412 element.addEventListener('drop', onDrop);
5413 element.addEventListener('dragenter', onDragEnter);
5414 element.addEventListener('dragover', onDragOver);
5415 element.addEventListener('dragleave', onDragLeave); // The `dragstart` event doesn't fire if the drag started outside
5416 // the document.
5417
5418 ownerDocument.addEventListener('dragenter', maybeDragStart);
5419 return () => {
5420 delete element.dataset.isDropZone;
5421 element.removeEventListener('drop', onDrop);
5422 element.removeEventListener('dragenter', onDragEnter);
5423 element.removeEventListener('dragover', onDragOver);
5424 element.removeEventListener('dragleave', onDragLeave);
5425 ownerDocument.removeEventListener('dragend', maybeDragEnd);
5426 ownerDocument.removeEventListener('mousemove', maybeDragEnd);
5427 ownerDocument.removeEventListener('dragenter', maybeDragStart);
5428 };
5429 }, [isDisabled]);
5430 }
5431
5432 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-focusable-iframe/index.js
5433 /**
5434 * External dependencies
5435 */
5436
5437 /**
5438 * Internal dependencies
5439 */
5440
5441 /**
5442 * Dispatches a bubbling focus event when the iframe receives focus. Use
5443 * `onFocus` as usual on the iframe or a parent element.
5444 *
5445 * @return Ref to pass to the iframe.
5446 */
5447
5448 function useFocusableIframe() {
5449 return useRefEffect(element => {
5450 const {
5451 ownerDocument
5452 } = element;
5453 if (!ownerDocument) return;
5454 const {
5455 defaultView
5456 } = ownerDocument;
5457 if (!defaultView) return;
5458 /**
5459 * Checks whether the iframe is the activeElement, inferring that it has
5460 * then received focus, and dispatches a focus event.
5461 */
5462
5463 function checkFocus() {
5464 if (ownerDocument && ownerDocument.activeElement === element) {
5465 element.focus();
5466 }
5467 }
5468
5469 defaultView.addEventListener('blur', checkFocus);
5470 return () => {
5471 defaultView.removeEventListener('blur', checkFocus);
5472 };
5473 }, []);
5474 }
5475
5476 ;// CONCATENATED MODULE: ./packages/compose/build-module/hooks/use-fixed-window-list/index.js
5477 /**
5478 * WordPress dependencies
5479 */
5480
5481
5482
5483 /**
5484 * Internal dependencies
5485 */
5486
5487
5488 const DEFAULT_INIT_WINDOW_SIZE = 30;
5489 /**
5490 * @typedef {Object} WPFixedWindowList
5491 *
5492 * @property {number} visibleItems Items visible in the current viewport
5493 * @property {number} start Start index of the window
5494 * @property {number} end End index of the window
5495 * @property {(index:number)=>boolean} itemInView Returns true if item is in the window
5496 */
5497
5498 /**
5499 * @typedef {Object} WPFixedWindowListOptions
5500 *
5501 * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.
5502 * @property {boolean} [useWindowing] When false avoids calculating the window size
5503 * @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.
5504 */
5505
5506 /**
5507 *
5508 * @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.
5509 * @param { number } itemHeight Fixed item height in pixels
5510 * @param { number } totalItems Total items in list
5511 * @param { WPFixedWindowListOptions } [options] Options object
5512 * @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter
5513 */
5514
5515 function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
5516 var _options$initWindowSi, _options$useWindowing;
5517
5518 const initWindowSize = (_options$initWindowSi = options === null || options === void 0 ? void 0 : options.initWindowSize) !== null && _options$initWindowSi !== void 0 ? _options$initWindowSi : DEFAULT_INIT_WINDOW_SIZE;
5519 const useWindowing = (_options$useWindowing = options === null || options === void 0 ? void 0 : options.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true;
5520 const [fixedListWindow, setFixedListWindow] = (0,external_wp_element_namespaceObject.useState)({
5521 visibleItems: initWindowSize,
5522 start: 0,
5523 end: initWindowSize,
5524 itemInView: (
5525 /** @type {number} */
5526 index) => {
5527 return index >= 0 && index <= initWindowSize;
5528 }
5529 });
5530 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
5531 var _scrollContainer$owne, _scrollContainer$owne2, _scrollContainer$owne3, _scrollContainer$owne4;
5532
5533 if (!useWindowing) {
5534 return;
5535 }
5536
5537 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current);
5538
5539 const measureWindow = (
5540 /** @type {boolean | undefined} */
5541 initRender) => {
5542 var _options$windowOversc;
5543
5544 if (!scrollContainer) {
5545 return;
5546 }
5547
5548 const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); // Aim to keep opening list view fast, afterward we can optimize for scrolling.
5549
5550 const windowOverscan = initRender ? visibleItems : (_options$windowOversc = options === null || options === void 0 ? void 0 : options.windowOverscan) !== null && _options$windowOversc !== void 0 ? _options$windowOversc : visibleItems;
5551 const firstViewableIndex = Math.floor(scrollContainer.scrollTop / itemHeight);
5552 const start = Math.max(0, firstViewableIndex - windowOverscan);
5553 const end = Math.min(totalItems - 1, firstViewableIndex + visibleItems + windowOverscan);
5554 setFixedListWindow(lastWindow => {
5555 const nextWindow = {
5556 visibleItems,
5557 start,
5558 end,
5559 itemInView: (
5560 /** @type {number} */
5561 index) => {
5562 return start <= index && index <= end;
5563 }
5564 };
5565
5566 if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) {
5567 return nextWindow;
5568 }
5569
5570 return lastWindow;
5571 });
5572 };
5573
5574 measureWindow(true);
5575 const debounceMeasureList = debounce(() => {
5576 measureWindow();
5577 }, 16);
5578 scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.addEventListener('scroll', debounceMeasureList);
5579 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);
5580 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);
5581 return () => {
5582 var _scrollContainer$owne5, _scrollContainer$owne6;
5583
5584 scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener('scroll', debounceMeasureList);
5585 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);
5586 };
5587 }, [itemHeight, elementRef, totalItems]);
5588 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
5589 var _scrollContainer$owne7, _scrollContainer$owne8;
5590
5591 if (!useWindowing) {
5592 return;
5593 }
5594
5595 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current);
5596
5597 const handleKeyDown = (
5598 /** @type {KeyboardEvent} */
5599 event) => {
5600 switch (event.keyCode) {
5601 case external_wp_keycodes_namespaceObject.HOME:
5602 {
5603 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
5604 top: 0
5605 });
5606 }
5607
5608 case external_wp_keycodes_namespaceObject.END:
5609 {
5610 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
5611 top: totalItems * itemHeight
5612 });
5613 }
5614
5615 case external_wp_keycodes_namespaceObject.PAGEUP:
5616 {
5617 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
5618 top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight
5619 });
5620 }
5621
5622 case external_wp_keycodes_namespaceObject.PAGEDOWN:
5623 {
5624 return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
5625 top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight
5626 });
5627 }
5628 }
5629 };
5630
5631 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);
5632 return () => {
5633 var _scrollContainer$owne9, _scrollContainer$owne10;
5634
5635 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);
5636 };
5637 }, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems]);
5638 return [fixedListWindow, setFixedListWindow];
5639 }
5640
5641 ;// CONCATENATED MODULE: ./packages/compose/build-module/index.js
5642 // The `createHigherOrderComponent` helper and helper types.
5643 // The `debounce` helper and its types.
5644
5645 // The `throttle` helper and its types.
5646
5647 // The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).
5648
5649
5650 // Higher-order components.
5651
5652
5653
5654
5655
5656
5657 // Hooks.
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686 }();
5687 (window.wp = window.wp || {}).compose = __webpack_exports__;
5688 /******/ })()
5689 ;