PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 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 All 404 releases
gutenberg / build / scripts / compose / index.js

index.js in Gutenberg trunk, at build/scripts/compose/index.js

2,555 lines 84.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 "use strict";
3 var wp;
4 (wp ||= {}).compose = (() => {
5 var __create = Object.create;
6 var __defProp = Object.defineProperty;
7 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8 var __getOwnPropNames = Object.getOwnPropertyNames;
9 var __getProtoOf = Object.getPrototypeOf;
10 var __hasOwnProp = Object.prototype.hasOwnProperty;
11 var __commonJS = (cb, mod) => function __require() {
12 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13 };
14 var __export = (target, all) => {
15 for (var name in all)
16 __defProp(target, name, { get: all[name], enumerable: true });
17 };
18 var __copyProps = (to, from, except, desc) => {
19 if (from && typeof from === "object" || typeof from === "function") {
20 for (let key of __getOwnPropNames(from))
21 if (!__hasOwnProp.call(to, key) && key !== except)
22 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23 }
24 return to;
25 };
26 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27 // If the importer is in node compatibility mode or this is not an ESM
28 // file that has been converted to a CommonJS file using a Babel-
29 // compatible transform (i.e. "__esModule" has not been set), then set
30 // "default" to the CommonJS "module.exports" for node compatibility.
31 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32 mod
33 ));
34 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
36 // package-external:@wordpress/private-apis
37 var require_private_apis = __commonJS({
38 "package-external:@wordpress/private-apis"(exports, module) {
39 module.exports = window.wp.privateApis;
40 }
41 });
42
43 // vendor-external:react/jsx-runtime
44 var require_jsx_runtime = __commonJS({
45 "vendor-external:react/jsx-runtime"(exports, module) {
46 module.exports = window.ReactJSXRuntime;
47 }
48 });
49
50 // package-external:@wordpress/is-shallow-equal
51 var require_is_shallow_equal = __commonJS({
52 "package-external:@wordpress/is-shallow-equal"(exports, module) {
53 module.exports = window.wp.isShallowEqual;
54 }
55 });
56
57 // package-external:@wordpress/element
58 var require_element = __commonJS({
59 "package-external:@wordpress/element"(exports, module) {
60 module.exports = window.wp.element;
61 }
62 });
63
64 // package-external:@wordpress/deprecated
65 var require_deprecated = __commonJS({
66 "package-external:@wordpress/deprecated"(exports, module) {
67 module.exports = window.wp.deprecated;
68 }
69 });
70
71 // package-external:@wordpress/dom
72 var require_dom = __commonJS({
73 "package-external:@wordpress/dom"(exports, module) {
74 module.exports = window.wp.dom;
75 }
76 });
77
78 // node_modules/mousetrap/mousetrap.js
79 var require_mousetrap = __commonJS({
80 "node_modules/mousetrap/mousetrap.js"(exports, module) {
81 (function(window2, document2, undefined2) {
82 if (!window2) {
83 return;
84 }
85 var _MAP = {
86 8: "backspace",
87 9: "tab",
88 13: "enter",
89 16: "shift",
90 17: "ctrl",
91 18: "alt",
92 20: "capslock",
93 27: "esc",
94 32: "space",
95 33: "pageup",
96 34: "pagedown",
97 35: "end",
98 36: "home",
99 37: "left",
100 38: "up",
101 39: "right",
102 40: "down",
103 45: "ins",
104 46: "del",
105 91: "meta",
106 93: "meta",
107 224: "meta"
108 };
109 var _KEYCODE_MAP = {
110 106: "*",
111 107: "+",
112 109: "-",
113 110: ".",
114 111: "/",
115 186: ";",
116 187: "=",
117 188: ",",
118 189: "-",
119 190: ".",
120 191: "/",
121 192: "`",
122 219: "[",
123 220: "\\",
124 221: "]",
125 222: "'"
126 };
127 var _SHIFT_MAP = {
128 "~": "`",
129 "!": "1",
130 "@": "2",
131 "#": "3",
132 "$": "4",
133 "%": "5",
134 "^": "6",
135 "&": "7",
136 "*": "8",
137 "(": "9",
138 ")": "0",
139 "_": "-",
140 "+": "=",
141 ":": ";",
142 '"': "'",
143 "<": ",",
144 ">": ".",
145 "?": "/",
146 "|": "\\"
147 };
148 var _SPECIAL_ALIASES = {
149 "option": "alt",
150 "command": "meta",
151 "return": "enter",
152 "escape": "esc",
153 "plus": "+",
154 "mod": /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? "meta" : "ctrl"
155 };
156 var _REVERSE_MAP;
157 for (var i = 1; i < 20; ++i) {
158 _MAP[111 + i] = "f" + i;
159 }
160 for (i = 0; i <= 9; ++i) {
161 _MAP[i + 96] = i.toString();
162 }
163 function _addEvent(object, type, callback) {
164 if (object.addEventListener) {
165 object.addEventListener(type, callback, false);
166 return;
167 }
168 object.attachEvent("on" + type, callback);
169 }
170 function _characterFromEvent(e) {
171 if (e.type == "keypress") {
172 var character = String.fromCharCode(e.which);
173 if (!e.shiftKey) {
174 character = character.toLowerCase();
175 }
176 return character;
177 }
178 if (_MAP[e.which]) {
179 return _MAP[e.which];
180 }
181 if (_KEYCODE_MAP[e.which]) {
182 return _KEYCODE_MAP[e.which];
183 }
184 return String.fromCharCode(e.which).toLowerCase();
185 }
186 function _modifiersMatch(modifiers1, modifiers2) {
187 return modifiers1.sort().join(",") === modifiers2.sort().join(",");
188 }
189 function _eventModifiers(e) {
190 var modifiers = [];
191 if (e.shiftKey) {
192 modifiers.push("shift");
193 }
194 if (e.altKey) {
195 modifiers.push("alt");
196 }
197 if (e.ctrlKey) {
198 modifiers.push("ctrl");
199 }
200 if (e.metaKey) {
201 modifiers.push("meta");
202 }
203 return modifiers;
204 }
205 function _preventDefault(e) {
206 if (e.preventDefault) {
207 e.preventDefault();
208 return;
209 }
210 e.returnValue = false;
211 }
212 function _stopPropagation(e) {
213 if (e.stopPropagation) {
214 e.stopPropagation();
215 return;
216 }
217 e.cancelBubble = true;
218 }
219 function _isModifier(key) {
220 return key == "shift" || key == "ctrl" || key == "alt" || key == "meta";
221 }
222 function _getReverseMap() {
223 if (!_REVERSE_MAP) {
224 _REVERSE_MAP = {};
225 for (var key in _MAP) {
226 if (key > 95 && key < 112) {
227 continue;
228 }
229 if (_MAP.hasOwnProperty(key)) {
230 _REVERSE_MAP[_MAP[key]] = key;
231 }
232 }
233 }
234 return _REVERSE_MAP;
235 }
236 function _pickBestAction(key, modifiers, action) {
237 if (!action) {
238 action = _getReverseMap()[key] ? "keydown" : "keypress";
239 }
240 if (action == "keypress" && modifiers.length) {
241 action = "keydown";
242 }
243 return action;
244 }
245 function _keysFromString(combination) {
246 if (combination === "+") {
247 return ["+"];
248 }
249 combination = combination.replace(/\+{2}/g, "+plus");
250 return combination.split("+");
251 }
252 function _getKeyInfo(combination, action) {
253 var keys;
254 var key;
255 var i2;
256 var modifiers = [];
257 keys = _keysFromString(combination);
258 for (i2 = 0; i2 < keys.length; ++i2) {
259 key = keys[i2];
260 if (_SPECIAL_ALIASES[key]) {
261 key = _SPECIAL_ALIASES[key];
262 }
263 if (action && action != "keypress" && _SHIFT_MAP[key]) {
264 key = _SHIFT_MAP[key];
265 modifiers.push("shift");
266 }
267 if (_isModifier(key)) {
268 modifiers.push(key);
269 }
270 }
271 action = _pickBestAction(key, modifiers, action);
272 return {
273 key,
274 modifiers,
275 action
276 };
277 }
278 function _belongsTo(element, ancestor) {
279 if (element === null || element === document2) {
280 return false;
281 }
282 if (element === ancestor) {
283 return true;
284 }
285 return _belongsTo(element.parentNode, ancestor);
286 }
287 function Mousetrap3(targetElement) {
288 var self = this;
289 targetElement = targetElement || document2;
290 if (!(self instanceof Mousetrap3)) {
291 return new Mousetrap3(targetElement);
292 }
293 self.target = targetElement;
294 self._callbacks = {};
295 self._directMap = {};
296 var _sequenceLevels = {};
297 var _resetTimer;
298 var _ignoreNextKeyup = false;
299 var _ignoreNextKeypress = false;
300 var _nextExpectedAction = false;
301 function _resetSequences(doNotReset) {
302 doNotReset = doNotReset || {};
303 var activeSequences = false, key;
304 for (key in _sequenceLevels) {
305 if (doNotReset[key]) {
306 activeSequences = true;
307 continue;
308 }
309 _sequenceLevels[key] = 0;
310 }
311 if (!activeSequences) {
312 _nextExpectedAction = false;
313 }
314 }
315 function _getMatches(character, modifiers, e, sequenceName, combination, level) {
316 var i2;
317 var callback;
318 var matches = [];
319 var action = e.type;
320 if (!self._callbacks[character]) {
321 return [];
322 }
323 if (action == "keyup" && _isModifier(character)) {
324 modifiers = [character];
325 }
326 for (i2 = 0; i2 < self._callbacks[character].length; ++i2) {
327 callback = self._callbacks[character][i2];
328 if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) {
329 continue;
330 }
331 if (action != callback.action) {
332 continue;
333 }
334 if (action == "keypress" && !e.metaKey && !e.ctrlKey || _modifiersMatch(modifiers, callback.modifiers)) {
335 var deleteCombo = !sequenceName && callback.combo == combination;
336 var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level;
337 if (deleteCombo || deleteSequence) {
338 self._callbacks[character].splice(i2, 1);
339 }
340 matches.push(callback);
341 }
342 }
343 return matches;
344 }
345 function _fireCallback(callback, e, combo, sequence) {
346 if (self.stopCallback(e, e.target || e.srcElement, combo, sequence)) {
347 return;
348 }
349 if (callback(e, combo) === false) {
350 _preventDefault(e);
351 _stopPropagation(e);
352 }
353 }
354 self._handleKey = function(character, modifiers, e) {
355 var callbacks = _getMatches(character, modifiers, e);
356 var i2;
357 var doNotReset = {};
358 var maxLevel = 0;
359 var processedSequenceCallback = false;
360 for (i2 = 0; i2 < callbacks.length; ++i2) {
361 if (callbacks[i2].seq) {
362 maxLevel = Math.max(maxLevel, callbacks[i2].level);
363 }
364 }
365 for (i2 = 0; i2 < callbacks.length; ++i2) {
366 if (callbacks[i2].seq) {
367 if (callbacks[i2].level != maxLevel) {
368 continue;
369 }
370 processedSequenceCallback = true;
371 doNotReset[callbacks[i2].seq] = 1;
372 _fireCallback(callbacks[i2].callback, e, callbacks[i2].combo, callbacks[i2].seq);
373 continue;
374 }
375 if (!processedSequenceCallback) {
376 _fireCallback(callbacks[i2].callback, e, callbacks[i2].combo);
377 }
378 }
379 var ignoreThisKeypress = e.type == "keypress" && _ignoreNextKeypress;
380 if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) {
381 _resetSequences(doNotReset);
382 }
383 _ignoreNextKeypress = processedSequenceCallback && e.type == "keydown";
384 };
385 function _handleKeyEvent(e) {
386 if (typeof e.which !== "number") {
387 e.which = e.keyCode;
388 }
389 var character = _characterFromEvent(e);
390 if (!character) {
391 return;
392 }
393 if (e.type == "keyup" && _ignoreNextKeyup === character) {
394 _ignoreNextKeyup = false;
395 return;
396 }
397 self.handleKey(character, _eventModifiers(e), e);
398 }
399 function _resetSequenceTimer() {
400 clearTimeout(_resetTimer);
401 _resetTimer = setTimeout(_resetSequences, 1e3);
402 }
403 function _bindSequence(combo, keys, callback, action) {
404 _sequenceLevels[combo] = 0;
405 function _increaseSequence(nextAction) {
406 return function() {
407 _nextExpectedAction = nextAction;
408 ++_sequenceLevels[combo];
409 _resetSequenceTimer();
410 };
411 }
412 function _callbackAndReset(e) {
413 _fireCallback(callback, e, combo);
414 if (action !== "keyup") {
415 _ignoreNextKeyup = _characterFromEvent(e);
416 }
417 setTimeout(_resetSequences, 10);
418 }
419 for (var i2 = 0; i2 < keys.length; ++i2) {
420 var isFinal = i2 + 1 === keys.length;
421 var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i2 + 1]).action);
422 _bindSingle(keys[i2], wrappedCallback, action, combo, i2);
423 }
424 }
425 function _bindSingle(combination, callback, action, sequenceName, level) {
426 self._directMap[combination + ":" + action] = callback;
427 combination = combination.replace(/\s+/g, " ");
428 var sequence = combination.split(" ");
429 var info;
430 if (sequence.length > 1) {
431 _bindSequence(combination, sequence, callback, action);
432 return;
433 }
434 info = _getKeyInfo(combination, action);
435 self._callbacks[info.key] = self._callbacks[info.key] || [];
436 _getMatches(info.key, info.modifiers, { type: info.action }, sequenceName, combination, level);
437 self._callbacks[info.key][sequenceName ? "unshift" : "push"]({
438 callback,
439 modifiers: info.modifiers,
440 action: info.action,
441 seq: sequenceName,
442 level,
443 combo: combination
444 });
445 }
446 self._bindMultiple = function(combinations, callback, action) {
447 for (var i2 = 0; i2 < combinations.length; ++i2) {
448 _bindSingle(combinations[i2], callback, action);
449 }
450 };
451 _addEvent(targetElement, "keypress", _handleKeyEvent);
452 _addEvent(targetElement, "keydown", _handleKeyEvent);
453 _addEvent(targetElement, "keyup", _handleKeyEvent);
454 }
455 Mousetrap3.prototype.bind = function(keys, callback, action) {
456 var self = this;
457 keys = keys instanceof Array ? keys : [keys];
458 self._bindMultiple.call(self, keys, callback, action);
459 return self;
460 };
461 Mousetrap3.prototype.unbind = function(keys, action) {
462 var self = this;
463 return self.bind.call(self, keys, function() {
464 }, action);
465 };
466 Mousetrap3.prototype.trigger = function(keys, action) {
467 var self = this;
468 if (self._directMap[keys + ":" + action]) {
469 self._directMap[keys + ":" + action]({}, keys);
470 }
471 return self;
472 };
473 Mousetrap3.prototype.reset = function() {
474 var self = this;
475 self._callbacks = {};
476 self._directMap = {};
477 return self;
478 };
479 Mousetrap3.prototype.stopCallback = function(e, element) {
480 var self = this;
481 if ((" " + element.className + " ").indexOf(" mousetrap ") > -1) {
482 return false;
483 }
484 if (_belongsTo(element, self.target)) {
485 return false;
486 }
487 if ("composedPath" in e && typeof e.composedPath === "function") {
488 var initialEventTarget = e.composedPath()[0];
489 if (initialEventTarget !== e.target) {
490 element = initialEventTarget;
491 }
492 }
493 return element.tagName == "INPUT" || element.tagName == "SELECT" || element.tagName == "TEXTAREA" || element.isContentEditable;
494 };
495 Mousetrap3.prototype.handleKey = function() {
496 var self = this;
497 return self._handleKey.apply(self, arguments);
498 };
499 Mousetrap3.addKeycodes = function(object) {
500 for (var key in object) {
501 if (object.hasOwnProperty(key)) {
502 _MAP[key] = object[key];
503 }
504 }
505 _REVERSE_MAP = null;
506 };
507 Mousetrap3.init = function() {
508 var documentMousetrap = Mousetrap3(document2);
509 for (var method in documentMousetrap) {
510 if (method.charAt(0) !== "_") {
511 Mousetrap3[method] = /* @__PURE__ */ (function(method2) {
512 return function() {
513 return documentMousetrap[method2].apply(documentMousetrap, arguments);
514 };
515 })(method);
516 }
517 }
518 };
519 Mousetrap3.init();
520 window2.Mousetrap = Mousetrap3;
521 if (typeof module !== "undefined" && module.exports) {
522 module.exports = Mousetrap3;
523 }
524 if (typeof define === "function" && define.amd) {
525 define(function() {
526 return Mousetrap3;
527 });
528 }
529 })(typeof window !== "undefined" ? window : null, typeof window !== "undefined" ? document : null);
530 }
531 });
532
533 // package-external:@wordpress/keycodes
534 var require_keycodes = __commonJS({
535 "package-external:@wordpress/keycodes"(exports, module) {
536 module.exports = window.wp.keycodes;
537 }
538 });
539
540 // package-external:@wordpress/undo-manager
541 var require_undo_manager = __commonJS({
542 "package-external:@wordpress/undo-manager"(exports, module) {
543 module.exports = window.wp.undoManager;
544 }
545 });
546
547 // package-external:@wordpress/priority-queue
548 var require_priority_queue = __commonJS({
549 "package-external:@wordpress/priority-queue"(exports, module) {
550 module.exports = window.wp.priorityQueue;
551 }
552 });
553
554 // vendor-external:react
555 var require_react = __commonJS({
556 "vendor-external:react"(exports, module) {
557 module.exports = window.React;
558 }
559 });
560
561 // packages/compose/build-module/index.mjs
562 var index_exports = {};
563 __export(index_exports, {
564 __experimentalUseDialog: () => use_dialog_default,
565 __experimentalUseDragging: () => useDragging,
566 __experimentalUseDropZone: () => useDropZone,
567 __experimentalUseFixedWindowList: () => useFixedWindowList,
568 __experimentalUseFocusOutside: () => useFocusOutside,
569 compose: () => compose_default,
570 createHigherOrderComponent: () => createHigherOrderComponent,
571 debounce: () => debounce,
572 ifCondition: () => if_condition_default,
573 observableMap: () => observableMap,
574 pipe: () => pipe_default,
575 privateApis: () => privateApis,
576 pure: () => pure_default,
577 throttle: () => throttle,
578 useAsyncList: () => use_async_list_default,
579 useConstrainedTabbing: () => use_constrained_tabbing_default,
580 useCopyOnClick: () => useCopyOnClick,
581 useCopyToClipboard: () => useCopyToClipboard,
582 useDebounce: () => useDebounce,
583 useDebouncedInput: () => useDebouncedInput,
584 useDisabled: () => useDisabled,
585 useEvent: () => useEvent,
586 useFocusOnMount: () => useFocusOnMount,
587 useFocusReturn: () => use_focus_return_default,
588 useFocusableIframe: () => useFocusableIframe,
589 useInstanceId: () => use_instance_id_default,
590 useIsomorphicLayoutEffect: () => use_isomorphic_layout_effect_default,
591 useKeyboardShortcut: () => use_keyboard_shortcut_default,
592 useMediaQuery: () => useMediaQuery,
593 useMergeRefs: () => useMergeRefs,
594 useObservableValue: () => useObservableValue,
595 usePrevious: () => usePrevious,
596 useReducedMotion: () => use_reduced_motion_default,
597 useRefEffect: () => useRefEffect,
598 useResizeObserver: () => useResizeObserver2,
599 useStateWithHistory: () => useStateWithHistory,
600 useThrottle: () => useThrottle,
601 useViewportMatch: () => use_viewport_match_default,
602 useWarnOnChange: () => use_warn_on_change_default,
603 withGlobalEvents: () => withGlobalEvents,
604 withInstanceId: () => with_instance_id_default,
605 withSafeTimeout: () => with_safe_timeout_default,
606 withState: () => withState
607 });
608
609 // node_modules/tslib/tslib.es6.mjs
610 var __assign = function() {
611 __assign = Object.assign || function __assign2(t) {
612 for (var s, i = 1, n = arguments.length; i < n; i++) {
613 s = arguments[i];
614 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
615 }
616 return t;
617 };
618 return __assign.apply(this, arguments);
619 };
620
621 // node_modules/lower-case/dist.es2015/index.js
622 function lowerCase(str) {
623 return str.toLowerCase();
624 }
625
626 // node_modules/no-case/dist.es2015/index.js
627 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
628 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
629 function noCase(input, options) {
630 if (options === void 0) {
631 options = {};
632 }
633 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;
634 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
635 var start = 0;
636 var end = result.length;
637 while (result.charAt(start) === "\0")
638 start++;
639 while (result.charAt(end - 1) === "\0")
640 end--;
641 return result.slice(start, end).split("\0").map(transform).join(delimiter);
642 }
643 function replace(input, re, value) {
644 if (re instanceof RegExp)
645 return input.replace(re, value);
646 return re.reduce(function(input2, re2) {
647 return input2.replace(re2, value);
648 }, input);
649 }
650
651 // node_modules/pascal-case/dist.es2015/index.js
652 function pascalCaseTransform(input, index) {
653 var firstChar = input.charAt(0);
654 var lowerChars = input.substr(1).toLowerCase();
655 if (index > 0 && firstChar >= "0" && firstChar <= "9") {
656 return "_" + firstChar + lowerChars;
657 }
658 return "" + firstChar.toUpperCase() + lowerChars;
659 }
660 function pascalCase(input, options) {
661 if (options === void 0) {
662 options = {};
663 }
664 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
665 }
666
667 // packages/compose/build-module/utils/create-higher-order-component/index.mjs
668 function createHigherOrderComponent(mapComponent, modifierName) {
669 return (Inner) => {
670 const Outer = mapComponent(Inner);
671 Outer.displayName = hocName(modifierName, Inner);
672 return Outer;
673 };
674 }
675 var hocName = (name, Inner) => {
676 const inner = Inner.displayName || Inner.name || "Component";
677 const outer = pascalCase(name ?? "");
678 return `${outer}(${inner})`;
679 };
680
681 // packages/compose/build-module/utils/debounce/index.mjs
682 var debounce = (func, wait, options) => {
683 let lastArgs;
684 let lastThis;
685 let maxWait = 0;
686 let result;
687 let timerId;
688 let lastCallTime;
689 let lastInvokeTime = 0;
690 let leading = false;
691 let maxing = false;
692 let trailing = true;
693 if (options) {
694 leading = !!options.leading;
695 maxing = "maxWait" in options;
696 if (options.maxWait !== void 0) {
697 maxWait = Math.max(options.maxWait, wait);
698 }
699 trailing = "trailing" in options ? !!options.trailing : trailing;
700 }
701 function invokeFunc(time) {
702 const args = lastArgs;
703 const thisArg = lastThis;
704 lastArgs = void 0;
705 lastThis = void 0;
706 lastInvokeTime = time;
707 result = func.apply(thisArg, args);
708 return result;
709 }
710 function startTimer(pendingFunc, waitTime) {
711 timerId = setTimeout(pendingFunc, waitTime);
712 }
713 function cancelTimer() {
714 if (timerId !== void 0) {
715 clearTimeout(timerId);
716 }
717 }
718 function leadingEdge(time) {
719 lastInvokeTime = time;
720 startTimer(timerExpired, wait);
721 return leading ? invokeFunc(time) : result;
722 }
723 function getTimeSinceLastCall(time) {
724 return time - (lastCallTime || 0);
725 }
726 function remainingWait(time) {
727 const timeSinceLastCall = getTimeSinceLastCall(time);
728 const timeSinceLastInvoke = time - lastInvokeTime;
729 const timeWaiting = wait - timeSinceLastCall;
730 return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
731 }
732 function shouldInvoke(time) {
733 const timeSinceLastCall = getTimeSinceLastCall(time);
734 const timeSinceLastInvoke = time - lastInvokeTime;
735 return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
736 }
737 function timerExpired() {
738 const time = Date.now();
739 if (shouldInvoke(time)) {
740 return trailingEdge(time);
741 }
742 startTimer(timerExpired, remainingWait(time));
743 return void 0;
744 }
745 function clearTimer() {
746 timerId = void 0;
747 }
748 function trailingEdge(time) {
749 clearTimer();
750 if (trailing && lastArgs) {
751 return invokeFunc(time);
752 }
753 lastArgs = lastThis = void 0;
754 return result;
755 }
756 function cancel() {
757 cancelTimer();
758 lastInvokeTime = 0;
759 clearTimer();
760 lastArgs = lastCallTime = lastThis = void 0;
761 }
762 function flush() {
763 return pending() ? trailingEdge(Date.now()) : result;
764 }
765 function pending() {
766 return timerId !== void 0;
767 }
768 function debounced(...args) {
769 const time = Date.now();
770 const isInvoking = shouldInvoke(time);
771 lastArgs = args;
772 lastThis = this;
773 lastCallTime = time;
774 if (isInvoking) {
775 if (!pending()) {
776 return leadingEdge(lastCallTime);
777 }
778 if (maxing) {
779 startTimer(timerExpired, wait);
780 return invokeFunc(lastCallTime);
781 }
782 }
783 if (!pending()) {
784 startTimer(timerExpired, wait);
785 }
786 return result;
787 }
788 debounced.cancel = cancel;
789 debounced.flush = flush;
790 debounced.pending = pending;
791 return debounced;
792 };
793
794 // packages/compose/build-module/utils/throttle/index.mjs
795 var throttle = (func, wait, options) => {
796 let leading = true;
797 let trailing = true;
798 if (options) {
799 leading = "leading" in options ? !!options.leading : leading;
800 trailing = "trailing" in options ? !!options.trailing : trailing;
801 }
802 return debounce(func, wait, {
803 leading,
804 trailing,
805 maxWait: wait
806 });
807 };
808
809 // packages/compose/build-module/utils/observable-map/index.mjs
810 function observableMap() {
811 const map = /* @__PURE__ */ new Map();
812 const listeners = /* @__PURE__ */ new Map();
813 function callListeners(name) {
814 const list = listeners.get(name);
815 if (!list) {
816 return;
817 }
818 for (const listener2 of list) {
819 listener2();
820 }
821 }
822 return {
823 get(name) {
824 return map.get(name);
825 },
826 set(name, value) {
827 map.set(name, value);
828 callListeners(name);
829 },
830 delete(name) {
831 map.delete(name);
832 callListeners(name);
833 },
834 subscribe(name, listener2) {
835 let list = listeners.get(name);
836 if (!list) {
837 list = /* @__PURE__ */ new Set();
838 listeners.set(name, list);
839 }
840 list.add(listener2);
841 return () => {
842 list.delete(listener2);
843 if (list.size === 0) {
844 listeners.delete(name);
845 }
846 };
847 }
848 };
849 }
850
851 // packages/compose/build-module/lock-unlock.mjs
852 var import_private_apis = __toESM(require_private_apis(), 1);
853 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
854 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
855 "@wordpress/compose"
856 );
857
858 // packages/compose/build-module/utils/subscribe-delegated-listener/index.mjs
859 var registries = /* @__PURE__ */ new WeakMap();
860 function subscribeDelegatedListener(target, eventType, callback, capture = false) {
861 const ownerDoc = target.ownerDocument;
862 const root = ownerDoc ?? target;
863 const isWindow = ownerDoc === void 0;
864 let perRoot = registries.get(root);
865 if (!perRoot) {
866 perRoot = /* @__PURE__ */ new Map();
867 registries.set(root, perRoot);
868 }
869 const key = capture ? `${eventType}:capture` : eventType;
870 let perEvent = perRoot.get(key);
871 if (!perEvent) {
872 perEvent = /* @__PURE__ */ new WeakMap();
873 perRoot.set(key, perEvent);
874 const subscribers = perEvent;
875 root.addEventListener(
876 eventType,
877 (event) => {
878 if (isWindow) {
879 const set2 = subscribers.get(root);
880 if (set2) {
881 for (const cb of set2) {
882 cb(event);
883 }
884 }
885 return;
886 }
887 if (capture) {
888 const path = [];
889 let current = event.target;
890 while (current) {
891 path.push(current);
892 if (current === root) {
893 break;
894 }
895 current = current.parentNode;
896 }
897 for (let i = path.length - 1; i >= 0; i--) {
898 const set2 = subscribers.get(path[i]);
899 if (set2) {
900 for (const cb of set2) {
901 cb(event);
902 }
903 }
904 }
905 } else {
906 let current = event.target;
907 while (current) {
908 const set2 = subscribers.get(current);
909 if (set2) {
910 for (const cb of set2) {
911 cb(event);
912 }
913 }
914 if (current === root) {
915 break;
916 }
917 current = current.parentNode;
918 }
919 }
920 },
921 capture
922 );
923 }
924 let set = perEvent.get(target);
925 if (!set) {
926 set = /* @__PURE__ */ new Set();
927 perEvent.set(target, set);
928 }
929 set.add(callback);
930 return () => {
931 set.delete(callback);
932 };
933 }
934
935 // packages/compose/build-module/private-apis.mjs
936 var privateApis = {};
937 lock(privateApis, {
938 subscribeDelegatedListener
939 });
940
941 // packages/compose/build-module/higher-order/pipe.mjs
942 var basePipe = (reverse = false) => (...funcs) => (...args) => {
943 const functions = funcs.flat();
944 if (reverse) {
945 functions.reverse();
946 }
947 return functions.reduce(
948 (prev, func) => [func(...prev)],
949 args
950 )[0];
951 };
952 var pipe = basePipe();
953 var pipe_default = pipe;
954
955 // packages/compose/build-module/higher-order/compose.mjs
956 var compose = basePipe(true);
957 var compose_default = compose;
958
959 // packages/compose/build-module/higher-order/if-condition/index.mjs
960 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
961 function ifCondition(predicate) {
962 return createHigherOrderComponent(
963 (WrappedComponent) => (props) => {
964 if (!predicate(props)) {
965 return null;
966 }
967 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...props });
968 },
969 "ifCondition"
970 );
971 }
972 var if_condition_default = ifCondition;
973
974 // packages/compose/build-module/higher-order/pure/index.mjs
975 var import_is_shallow_equal = __toESM(require_is_shallow_equal(), 1);
976 var import_element = __toESM(require_element(), 1);
977 var import_deprecated = __toESM(require_deprecated(), 1);
978 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
979 var pure = createHigherOrderComponent(function(WrappedComponent) {
980 (0, import_deprecated.default)("wp.compose.pure", {
981 since: "7.1",
982 alternative: "Use `memo` or `PureComponent` instead"
983 });
984 if (WrappedComponent.prototype instanceof import_element.Component) {
985 return class extends WrappedComponent {
986 shouldComponentUpdate(nextProps, nextState) {
987 return !(0, import_is_shallow_equal.isShallowEqual)(nextProps, this.props) || !(0, import_is_shallow_equal.isShallowEqual)(nextState, this.state);
988 }
989 };
990 }
991 return class extends import_element.Component {
992 shouldComponentUpdate(nextProps) {
993 return !(0, import_is_shallow_equal.isShallowEqual)(nextProps, this.props);
994 }
995 render() {
996 return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WrappedComponent, { ...this.props });
997 }
998 };
999 }, "pure");
1000 var pure_default = pure;
1001
1002 // packages/compose/build-module/higher-order/with-global-events/index.mjs
1003 var import_element2 = __toESM(require_element(), 1);
1004 var import_deprecated2 = __toESM(require_deprecated(), 1);
1005
1006 // packages/compose/build-module/higher-order/with-global-events/listener.mjs
1007 var Listener = class {
1008 constructor() {
1009 this.listeners = {};
1010 this.handleEvent = this.handleEvent.bind(this);
1011 }
1012 add(eventType, instance) {
1013 if (!this.listeners[eventType]) {
1014 window.addEventListener(eventType, this.handleEvent);
1015 this.listeners[eventType] = [];
1016 }
1017 this.listeners[eventType].push(instance);
1018 }
1019 remove(eventType, instance) {
1020 if (!this.listeners[eventType]) {
1021 return;
1022 }
1023 this.listeners[eventType] = this.listeners[eventType].filter(
1024 (listener2) => listener2 !== instance
1025 );
1026 if (!this.listeners[eventType].length) {
1027 window.removeEventListener(eventType, this.handleEvent);
1028 delete this.listeners[eventType];
1029 }
1030 }
1031 handleEvent(event) {
1032 this.listeners[event.type]?.forEach(
1033 (instance) => {
1034 instance.handleEvent(event);
1035 }
1036 );
1037 }
1038 };
1039 var listener_default = Listener;
1040
1041 // packages/compose/build-module/higher-order/with-global-events/index.mjs
1042 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1043 var listener = new listener_default();
1044 function withGlobalEvents(eventTypesToHandlers) {
1045 (0, import_deprecated2.default)("wp.compose.withGlobalEvents", {
1046 since: "5.7",
1047 alternative: "useEffect"
1048 });
1049 return createHigherOrderComponent((WrappedComponent) => {
1050 class Wrapper extends import_element2.Component {
1051 constructor(props) {
1052 super(props);
1053 this.handleEvent = this.handleEvent.bind(this);
1054 this.handleRef = this.handleRef.bind(this);
1055 }
1056 componentDidMount() {
1057 Object.keys(eventTypesToHandlers).forEach((eventType) => {
1058 listener.add(eventType, this);
1059 });
1060 }
1061 componentWillUnmount() {
1062 Object.keys(eventTypesToHandlers).forEach((eventType) => {
1063 listener.remove(eventType, this);
1064 });
1065 }
1066 handleEvent(event) {
1067 const handler = eventTypesToHandlers[
1068 /** @type {keyof GlobalEventHandlersEventMap} */
1069 event.type
1070 ];
1071 if (typeof this.wrappedRef[handler] === "function") {
1072 this.wrappedRef[handler](event);
1073 }
1074 }
1075 handleRef(el) {
1076 this.wrappedRef = el;
1077 if (this.props.forwardedRef) {
1078 this.props.forwardedRef(el);
1079 }
1080 }
1081 render() {
1082 return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1083 WrappedComponent,
1084 {
1085 ...this.props.ownProps,
1086 ref: this.handleRef
1087 }
1088 );
1089 }
1090 }
1091 return (0, import_element2.forwardRef)((props, ref) => {
1092 return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Wrapper, { ownProps: props, forwardedRef: ref });
1093 });
1094 }, "withGlobalEvents");
1095 }
1096
1097 // packages/compose/build-module/hooks/use-instance-id/index.mjs
1098 var import_element3 = __toESM(require_element(), 1);
1099 var instanceMap = /* @__PURE__ */ new WeakMap();
1100 function createId(object) {
1101 const instances = instanceMap.get(object) || 0;
1102 instanceMap.set(object, instances + 1);
1103 return instances;
1104 }
1105 function useInstanceId(object, prefix, preferredId) {
1106 return (0, import_element3.useMemo)(() => {
1107 if (preferredId) {
1108 return preferredId;
1109 }
1110 const id = createId(object);
1111 return prefix ? `${prefix}-${id}` : id;
1112 }, [object, preferredId, prefix]);
1113 }
1114 var use_instance_id_default = useInstanceId;
1115
1116 // packages/compose/build-module/higher-order/with-instance-id/index.mjs
1117 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1118 var withInstanceId = createHigherOrderComponent(
1119 (WrappedComponent) => {
1120 return (props) => {
1121 const instanceId = use_instance_id_default(WrappedComponent);
1122 return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(WrappedComponent, { ...props, instanceId });
1123 };
1124 },
1125 "instanceId"
1126 );
1127 var with_instance_id_default = withInstanceId;
1128
1129 // packages/compose/build-module/higher-order/with-safe-timeout/index.mjs
1130 var import_element4 = __toESM(require_element(), 1);
1131 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1132 var withSafeTimeout = createHigherOrderComponent(
1133 (OriginalComponent) => {
1134 return class WrappedComponent extends import_element4.Component {
1135 timeouts;
1136 constructor(props) {
1137 super(props);
1138 this.timeouts = [];
1139 this.setTimeout = this.setTimeout.bind(this);
1140 this.clearTimeout = this.clearTimeout.bind(this);
1141 }
1142 componentWillUnmount() {
1143 this.timeouts.forEach(clearTimeout);
1144 }
1145 setTimeout(fn, delay) {
1146 const id = setTimeout(() => {
1147 fn();
1148 this.clearTimeout(id);
1149 }, delay);
1150 this.timeouts.push(id);
1151 return id;
1152 }
1153 clearTimeout(id) {
1154 clearTimeout(id);
1155 this.timeouts = this.timeouts.filter(
1156 (timeoutId) => timeoutId !== id
1157 );
1158 }
1159 render() {
1160 return (
1161 // @ts-expect-error `LibraryManagedAttributes` cannot see the injected timeout props.
1162 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1163 OriginalComponent,
1164 {
1165 ...this.props,
1166 setTimeout: this.setTimeout,
1167 clearTimeout: this.clearTimeout
1168 }
1169 )
1170 );
1171 }
1172 };
1173 },
1174 "withSafeTimeout"
1175 );
1176 var with_safe_timeout_default = withSafeTimeout;
1177
1178 // packages/compose/build-module/higher-order/with-state/index.mjs
1179 var import_element5 = __toESM(require_element(), 1);
1180 var import_deprecated3 = __toESM(require_deprecated(), 1);
1181 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1182 function withState(initialState = {}) {
1183 (0, import_deprecated3.default)("wp.compose.withState", {
1184 since: "5.8",
1185 alternative: "wp.element.useState"
1186 });
1187 return createHigherOrderComponent((OriginalComponent) => {
1188 return class WrappedComponent extends import_element5.Component {
1189 constructor(props) {
1190 super(props);
1191 this.setState = this.setState.bind(this);
1192 this.state = initialState;
1193 }
1194 render() {
1195 return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1196 OriginalComponent,
1197 {
1198 ...this.props,
1199 ...this.state,
1200 setState: this.setState
1201 }
1202 );
1203 }
1204 };
1205 }, "withState");
1206 }
1207
1208 // packages/compose/build-module/hooks/use-constrained-tabbing/index.mjs
1209 var import_dom = __toESM(require_dom(), 1);
1210
1211 // packages/compose/build-module/hooks/use-ref-effect/index.mjs
1212 var import_element6 = __toESM(require_element(), 1);
1213 function useRefEffect(callback, dependencies) {
1214 const cleanupRef = (0, import_element6.useRef)(void 0);
1215 return (0, import_element6.useCallback)((node) => {
1216 if (node) {
1217 cleanupRef.current = callback(node);
1218 } else if (cleanupRef.current) {
1219 cleanupRef.current();
1220 }
1221 }, dependencies);
1222 }
1223
1224 // packages/compose/build-module/hooks/use-constrained-tabbing/index.mjs
1225 function useConstrainedTabbing() {
1226 return useRefEffect((node) => {
1227 function onKeyDown(event) {
1228 const { key, shiftKey, target } = event;
1229 if (key !== "Tab") {
1230 return;
1231 }
1232 const action = shiftKey ? "findPrevious" : "findNext";
1233 const nextElement = import_dom.focus.tabbable[action](target) || null;
1234 if (target.contains(nextElement)) {
1235 event.preventDefault();
1236 nextElement?.focus();
1237 return;
1238 }
1239 if (node.contains(nextElement)) {
1240 return;
1241 }
1242 const domAction = shiftKey ? "append" : "prepend";
1243 const { ownerDocument } = node;
1244 const trap = ownerDocument.createElement("div");
1245 trap.tabIndex = -1;
1246 node[domAction](trap);
1247 trap.addEventListener("blur", () => node.removeChild(trap));
1248 trap.focus();
1249 }
1250 node.addEventListener("keydown", onKeyDown);
1251 return () => {
1252 node.removeEventListener("keydown", onKeyDown);
1253 };
1254 }, []);
1255 }
1256 var use_constrained_tabbing_default = useConstrainedTabbing;
1257
1258 // packages/compose/build-module/hooks/use-copy-on-click/index.mjs
1259 var import_element8 = __toESM(require_element(), 1);
1260 var import_deprecated4 = __toESM(require_deprecated(), 1);
1261
1262 // packages/compose/build-module/hooks/use-copy-to-clipboard/index.mjs
1263 var import_element7 = __toESM(require_element(), 1);
1264 async function copyToClipboard(text, trigger) {
1265 if (!trigger) {
1266 return false;
1267 }
1268 const { ownerDocument } = trigger;
1269 if (!ownerDocument) {
1270 return false;
1271 }
1272 const { defaultView } = ownerDocument;
1273 try {
1274 if (defaultView?.navigator?.clipboard?.writeText) {
1275 await defaultView.navigator.clipboard.writeText(text);
1276 return true;
1277 }
1278 const textarea = ownerDocument.createElement("textarea");
1279 textarea.value = text;
1280 textarea.setAttribute("readonly", "");
1281 textarea.style.position = "fixed";
1282 textarea.style.left = "-9999px";
1283 textarea.style.top = "-9999px";
1284 ownerDocument.body.appendChild(textarea);
1285 textarea.select();
1286 const success = ownerDocument.execCommand("copy");
1287 textarea.remove();
1288 return success;
1289 } catch {
1290 return false;
1291 }
1292 }
1293 function restoreFocus(trigger) {
1294 if ("focus" in trigger && typeof trigger.focus === "function") {
1295 trigger.focus();
1296 }
1297 }
1298 function useUpdatedRef(value) {
1299 const ref = (0, import_element7.useRef)(value);
1300 (0, import_element7.useLayoutEffect)(() => {
1301 ref.current = value;
1302 }, [value]);
1303 return ref;
1304 }
1305 function useCopyToClipboard(text, onSuccess) {
1306 const textRef = useUpdatedRef(text);
1307 const onSuccessRef = useUpdatedRef(onSuccess);
1308 return useRefEffect((node) => {
1309 let isActive = true;
1310 const handleClick = async () => {
1311 const textToCopy = typeof textRef.current === "function" ? textRef.current() : textRef.current || "";
1312 const success = await copyToClipboard(textToCopy, node);
1313 if (success) {
1314 if (isActive) {
1315 restoreFocus(node);
1316 }
1317 if (onSuccessRef.current) {
1318 onSuccessRef.current();
1319 }
1320 }
1321 };
1322 node.addEventListener("click", handleClick);
1323 return () => {
1324 isActive = false;
1325 node.removeEventListener("click", handleClick);
1326 };
1327 }, []);
1328 }
1329
1330 // packages/compose/build-module/hooks/use-copy-on-click/index.mjs
1331 function useCopyOnClick(ref, text, timeout = 4e3) {
1332 (0, import_deprecated4.default)("wp.compose.useCopyOnClick", {
1333 since: "5.8",
1334 alternative: "wp.compose.useCopyToClipboard"
1335 });
1336 const [hasCopied, setHasCopied] = (0, import_element8.useState)(false);
1337 (0, import_element8.useEffect)(() => {
1338 let isActive = true;
1339 let timeoutId;
1340 if (!ref.current) {
1341 return;
1342 }
1343 let targets;
1344 if (typeof ref.current === "string") {
1345 targets = typeof document !== "undefined" ? Array.from(document.querySelectorAll(ref.current)) : [];
1346 } else if ("length" in ref.current && typeof ref.current.length === "number") {
1347 targets = Array.from(ref.current);
1348 } else {
1349 targets = [ref.current];
1350 }
1351 if (targets.length === 0) {
1352 return;
1353 }
1354 const handleClick = async (event) => {
1355 const trigger = event.currentTarget;
1356 if (!trigger) {
1357 return;
1358 }
1359 const success = await copyToClipboard(
1360 typeof text === "function" ? text() : text || "",
1361 trigger
1362 );
1363 if (!isActive) {
1364 return;
1365 }
1366 if (success) {
1367 restoreFocus(trigger);
1368 if (timeout) {
1369 setHasCopied(true);
1370 clearTimeout(timeoutId);
1371 timeoutId = setTimeout(
1372 () => setHasCopied(false),
1373 timeout
1374 );
1375 }
1376 }
1377 };
1378 for (const target of targets) {
1379 target.addEventListener("click", handleClick);
1380 }
1381 return () => {
1382 isActive = false;
1383 for (const target of targets) {
1384 target.removeEventListener("click", handleClick);
1385 }
1386 clearTimeout(timeoutId);
1387 };
1388 }, [ref, text, timeout]);
1389 return hasCopied;
1390 }
1391
1392 // packages/compose/build-module/hooks/use-dialog/index.mjs
1393 var import_element13 = __toESM(require_element(), 1);
1394
1395 // packages/compose/build-module/hooks/use-focus-on-mount/index.mjs
1396 var import_dom2 = __toESM(require_dom(), 1);
1397 var import_element9 = __toESM(require_element(), 1);
1398 function useFocusOnMount(focusOnMount = "firstElement") {
1399 const focusOnMountRef = (0, import_element9.useRef)(focusOnMount);
1400 const setFocus = (target) => {
1401 target.focus({
1402 // When focusing newly mounted dialogs,
1403 // the position of the popover is often not right on the first render
1404 // This prevents the layout shifts when focusing the dialogs.
1405 preventScroll: true
1406 });
1407 };
1408 (0, import_element9.useEffect)(() => {
1409 focusOnMountRef.current = focusOnMount;
1410 }, [focusOnMount]);
1411 return useRefEffect((node) => {
1412 if (focusOnMountRef.current === false) {
1413 return;
1414 }
1415 if (node.contains(node.ownerDocument?.activeElement ?? null)) {
1416 return;
1417 }
1418 if (focusOnMountRef.current !== "firstElement" && focusOnMountRef.current !== "firstInputElement") {
1419 setFocus(node);
1420 return;
1421 }
1422 const timerId = setTimeout(() => {
1423 if (focusOnMountRef.current === "firstInputElement") {
1424 const formInput = node.querySelector(
1425 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
1426 );
1427 if (formInput) {
1428 setFocus(formInput);
1429 return;
1430 }
1431 }
1432 const firstTabbable = import_dom2.focus.tabbable.find(node)[0];
1433 if (firstTabbable) {
1434 setFocus(firstTabbable);
1435 }
1436 }, 0);
1437 return () => {
1438 clearTimeout(timerId);
1439 };
1440 }, []);
1441 }
1442
1443 // packages/compose/build-module/hooks/use-focus-return/index.mjs
1444 var import_element10 = __toESM(require_element(), 1);
1445 var origin = null;
1446 function useFocusReturn(onFocusReturn) {
1447 const ref = (0, import_element10.useRef)(null);
1448 const focusedBeforeMountRef = (0, import_element10.useRef)(null);
1449 const onFocusReturnRef = (0, import_element10.useRef)(
1450 onFocusReturn
1451 );
1452 (0, import_element10.useEffect)(() => {
1453 onFocusReturnRef.current = onFocusReturn;
1454 }, [onFocusReturn]);
1455 return (0, import_element10.useCallback)((node) => {
1456 if (node) {
1457 ref.current = node;
1458 if (focusedBeforeMountRef.current) {
1459 return;
1460 }
1461 const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument;
1462 focusedBeforeMountRef.current = activeDocument?.activeElement ?? null;
1463 } else if (focusedBeforeMountRef.current) {
1464 const isFocused = ref.current?.contains(
1465 ref.current?.ownerDocument.activeElement ?? null
1466 );
1467 if (ref.current?.isConnected && !isFocused) {
1468 origin ??= focusedBeforeMountRef.current;
1469 return;
1470 }
1471 if (onFocusReturnRef.current) {
1472 onFocusReturnRef.current();
1473 } else {
1474 const elementToFocus = !focusedBeforeMountRef.current.isConnected ? origin : focusedBeforeMountRef.current;
1475 elementToFocus?.focus();
1476 }
1477 origin = null;
1478 }
1479 }, []);
1480 }
1481 var use_focus_return_default = useFocusReturn;
1482
1483 // packages/compose/build-module/hooks/use-focus-outside/index.mjs
1484 var import_element11 = __toESM(require_element(), 1);
1485 var INPUT_BUTTON_TYPES = ["button", "submit"];
1486 function isFocusNormalizedButton(eventTarget) {
1487 if (!(eventTarget instanceof window.HTMLElement)) {
1488 return false;
1489 }
1490 switch (eventTarget.nodeName) {
1491 case "A":
1492 case "BUTTON":
1493 return true;
1494 case "INPUT":
1495 return INPUT_BUTTON_TYPES.includes(
1496 eventTarget.type
1497 );
1498 }
1499 return false;
1500 }
1501 function useFocusOutside(onFocusOutside) {
1502 const currentOnFocusOutsideRef = (0, import_element11.useRef)(onFocusOutside);
1503 (0, import_element11.useEffect)(() => {
1504 currentOnFocusOutsideRef.current = onFocusOutside;
1505 }, [onFocusOutside]);
1506 const preventBlurCheckRef = (0, import_element11.useRef)(false);
1507 const blurCheckTimeoutIdRef = (0, import_element11.useRef)(void 0);
1508 const cancelBlurCheck = (0, import_element11.useCallback)(() => {
1509 clearTimeout(blurCheckTimeoutIdRef.current);
1510 }, []);
1511 (0, import_element11.useEffect)(() => {
1512 if (!onFocusOutside) {
1513 cancelBlurCheck();
1514 }
1515 }, [onFocusOutside, cancelBlurCheck]);
1516 const normalizeButtonFocus = (0, import_element11.useCallback)((event) => {
1517 const { type, target } = event;
1518 const isInteractionEnd = ["mouseup", "touchend"].includes(type);
1519 if (isInteractionEnd) {
1520 preventBlurCheckRef.current = false;
1521 } else if (isFocusNormalizedButton(target)) {
1522 preventBlurCheckRef.current = true;
1523 }
1524 }, []);
1525 const queueBlurCheck = (0, import_element11.useCallback)((event) => {
1526 event.persist();
1527 if (preventBlurCheckRef.current) {
1528 return;
1529 }
1530 const ignoreForRelatedTarget = event.target.getAttribute(
1531 "data-unstable-ignore-focus-outside-for-relatedtarget"
1532 );
1533 if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) {
1534 return;
1535 }
1536 clearTimeout(blurCheckTimeoutIdRef.current);
1537 blurCheckTimeoutIdRef.current = setTimeout(() => {
1538 if (!document.hasFocus()) {
1539 event.preventDefault();
1540 return;
1541 }
1542 if ("function" === typeof currentOnFocusOutsideRef.current) {
1543 currentOnFocusOutsideRef.current(event);
1544 }
1545 }, 0);
1546 }, []);
1547 return {
1548 onFocus: cancelBlurCheck,
1549 onMouseDown: normalizeButtonFocus,
1550 onMouseUp: normalizeButtonFocus,
1551 onTouchStart: normalizeButtonFocus,
1552 onTouchEnd: normalizeButtonFocus,
1553 onBlur: queueBlurCheck
1554 };
1555 }
1556
1557 // packages/compose/build-module/hooks/use-merge-refs/index.mjs
1558 var import_element12 = __toESM(require_element(), 1);
1559 function assignRef(ref, value) {
1560 if (typeof ref === "function") {
1561 const returned = ref(value);
1562 return typeof returned === "function" ? returned : void 0;
1563 } else if (ref && ref.hasOwnProperty("current")) {
1564 ref.current = value;
1565 }
1566 return void 0;
1567 }
1568 function detachRef(ref, index, cleanups) {
1569 const cleanup = cleanups[index];
1570 if (cleanup) {
1571 cleanups[index] = void 0;
1572 cleanup();
1573 } else {
1574 assignRef(ref, null);
1575 }
1576 }
1577 function useMergeRefs(refs) {
1578 const elementRef = (0, import_element12.useRef)(null);
1579 const attachedRefsRef = (0, import_element12.useRef)([]);
1580 const currentRefsRef = (0, import_element12.useRef)(refs);
1581 const cleanupsRef = (0, import_element12.useRef)([]);
1582 currentRefsRef.current = refs;
1583 (0, import_element12.useLayoutEffect)(() => {
1584 const element = elementRef.current;
1585 if (element === null) {
1586 return;
1587 }
1588 refs.forEach((ref, index) => {
1589 const attachedRef = attachedRefsRef.current[index];
1590 if (ref !== attachedRef) {
1591 detachRef(attachedRef, index, cleanupsRef.current);
1592 cleanupsRef.current[index] = assignRef(ref, element);
1593 }
1594 });
1595 attachedRefsRef.current = refs;
1596 }, refs);
1597 return (0, import_element12.useCallback)((value) => {
1598 elementRef.current = value;
1599 if (value === null) {
1600 attachedRefsRef.current.forEach((ref, index) => {
1601 detachRef(ref, index, cleanupsRef.current);
1602 });
1603 attachedRefsRef.current = [];
1604 } else {
1605 attachedRefsRef.current = currentRefsRef.current;
1606 attachedRefsRef.current.forEach((ref, index) => {
1607 cleanupsRef.current[index] = assignRef(ref, value);
1608 });
1609 }
1610 }, []);
1611 }
1612
1613 // packages/compose/build-module/hooks/use-dialog/index.mjs
1614 function useDialog(options) {
1615 const currentOptions = (0, import_element13.useRef)(void 0);
1616 const { constrainTabbing = options.focusOnMount !== false } = options;
1617 (0, import_element13.useEffect)(() => {
1618 currentOptions.current = options;
1619 }, Object.values(options));
1620 const constrainedTabbingRef = use_constrained_tabbing_default();
1621 const focusOnMountRef = useFocusOnMount(options.focusOnMount);
1622 const focusReturnRef = use_focus_return_default();
1623 const focusOutsideProps = useFocusOutside((event) => {
1624 if (currentOptions.current?.__unstableOnClose) {
1625 currentOptions.current.__unstableOnClose("focus-outside", event);
1626 } else if (currentOptions.current?.onClose) {
1627 currentOptions.current.onClose();
1628 }
1629 });
1630 const onKeyDown = (0, import_element13.useCallback)((event) => {
1631 currentOptions.current?.onKeyDown?.(event);
1632 if (event.key === "Escape" && !event.defaultPrevented && currentOptions.current?.onClose) {
1633 event.preventDefault();
1634 event.stopPropagation();
1635 currentOptions.current.onClose();
1636 }
1637 }, []);
1638 return [
1639 useMergeRefs([
1640 constrainTabbing ? constrainedTabbingRef : null,
1641 options.focusOnMount !== false ? focusReturnRef : null,
1642 options.focusOnMount !== false ? focusOnMountRef : null
1643 ]),
1644 {
1645 ...focusOutsideProps,
1646 onKeyDown,
1647 tabIndex: -1
1648 }
1649 ];
1650 }
1651 var use_dialog_default = useDialog;
1652
1653 // packages/compose/build-module/hooks/use-disabled/index.mjs
1654 function useDisabled({
1655 isDisabled: isDisabledProp = false
1656 } = {}) {
1657 return useRefEffect(
1658 (node) => {
1659 if (isDisabledProp) {
1660 return;
1661 }
1662 const defaultView = node?.ownerDocument?.defaultView;
1663 if (!defaultView) {
1664 return;
1665 }
1666 const updates = [];
1667 const disable = () => {
1668 node.childNodes.forEach((child) => {
1669 if (!(child instanceof defaultView.HTMLElement)) {
1670 return;
1671 }
1672 if (!child.getAttribute("inert")) {
1673 child.setAttribute("inert", "true");
1674 updates.push(() => {
1675 child.removeAttribute("inert");
1676 });
1677 }
1678 });
1679 };
1680 const debouncedDisable = debounce(disable, 0, {
1681 leading: true
1682 });
1683 disable();
1684 const observer = new window.MutationObserver(debouncedDisable);
1685 observer.observe(node, {
1686 childList: true
1687 });
1688 return () => {
1689 if (observer) {
1690 observer.disconnect();
1691 }
1692 debouncedDisable.cancel();
1693 updates.forEach((update) => update());
1694 };
1695 },
1696 [isDisabledProp]
1697 );
1698 }
1699
1700 // packages/compose/build-module/hooks/use-event/index.mjs
1701 var import_element14 = __toESM(require_element(), 1);
1702 function useEvent(callback) {
1703 const ref = (0, import_element14.useRef)(() => {
1704 throw new Error(
1705 "Callbacks created with `useEvent` cannot be called during rendering."
1706 );
1707 });
1708 (0, import_element14.useInsertionEffect)(() => {
1709 ref.current = callback;
1710 });
1711 return (0, import_element14.useCallback)(
1712 (...args) => ref.current?.(...args),
1713 []
1714 );
1715 }
1716
1717 // packages/compose/build-module/hooks/use-dragging/index.mjs
1718 var import_element16 = __toESM(require_element(), 1);
1719
1720 // packages/compose/build-module/hooks/use-isomorphic-layout-effect/index.mjs
1721 var import_element15 = __toESM(require_element(), 1);
1722 var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_element15.useLayoutEffect : import_element15.useEffect;
1723 var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
1724
1725 // packages/compose/build-module/hooks/use-dragging/index.mjs
1726 function useDragging({
1727 onDragStart,
1728 onDragMove,
1729 onDragEnd
1730 }) {
1731 const [isDragging, setIsDragging] = (0, import_element16.useState)(false);
1732 const eventsRef = (0, import_element16.useRef)({
1733 onDragStart,
1734 onDragMove,
1735 onDragEnd
1736 });
1737 use_isomorphic_layout_effect_default(() => {
1738 eventsRef.current.onDragStart = onDragStart;
1739 eventsRef.current.onDragMove = onDragMove;
1740 eventsRef.current.onDragEnd = onDragEnd;
1741 }, [onDragStart, onDragMove, onDragEnd]);
1742 const onMouseMove = (0, import_element16.useCallback)((event) => {
1743 eventsRef.current.onDragMove?.(event);
1744 }, []);
1745 const endDrag = (0, import_element16.useCallback)(
1746 function endDrag2(event) {
1747 eventsRef.current.onDragEnd?.(event);
1748 document.removeEventListener("mousemove", onMouseMove);
1749 document.removeEventListener("mouseup", endDrag2);
1750 setIsDragging(false);
1751 },
1752 [onMouseMove]
1753 );
1754 const startDrag = (0, import_element16.useCallback)(
1755 (event) => {
1756 eventsRef.current.onDragStart?.(event);
1757 document.addEventListener("mousemove", onMouseMove);
1758 document.addEventListener("mouseup", endDrag);
1759 setIsDragging(true);
1760 },
1761 [onMouseMove, endDrag]
1762 );
1763 (0, import_element16.useEffect)(() => {
1764 return () => {
1765 if (isDragging) {
1766 document.removeEventListener("mousemove", onMouseMove);
1767 document.removeEventListener("mouseup", endDrag);
1768 }
1769 };
1770 }, [isDragging, onMouseMove, endDrag]);
1771 return {
1772 startDrag,
1773 endDrag,
1774 isDragging
1775 };
1776 }
1777
1778 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs
1779 var import_mousetrap = __toESM(require_mousetrap(), 1);
1780
1781 // node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
1782 (function(Mousetrap3) {
1783 if (!Mousetrap3) {
1784 return;
1785 }
1786 var _globalCallbacks = {};
1787 var _originalStopCallback = Mousetrap3.prototype.stopCallback;
1788 Mousetrap3.prototype.stopCallback = function(e, element, combo, sequence) {
1789 var self = this;
1790 if (self.paused) {
1791 return true;
1792 }
1793 if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
1794 return false;
1795 }
1796 return _originalStopCallback.call(self, e, element, combo);
1797 };
1798 Mousetrap3.prototype.bindGlobal = function(keys, callback, action) {
1799 var self = this;
1800 self.bind(keys, callback, action);
1801 if (keys instanceof Array) {
1802 for (var i = 0; i < keys.length; i++) {
1803 _globalCallbacks[keys[i]] = true;
1804 }
1805 return;
1806 }
1807 _globalCallbacks[keys] = true;
1808 };
1809 Mousetrap3.init();
1810 })(typeof Mousetrap !== "undefined" ? Mousetrap : void 0);
1811
1812 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs
1813 var import_element17 = __toESM(require_element(), 1);
1814 var import_keycodes = __toESM(require_keycodes(), 1);
1815 function useKeyboardShortcut(shortcuts, callback, {
1816 bindGlobal = false,
1817 eventName = "keydown",
1818 isDisabled = false,
1819 target
1820 } = {}) {
1821 const currentCallbackRef = (0, import_element17.useRef)(callback);
1822 (0, import_element17.useEffect)(() => {
1823 currentCallbackRef.current = callback;
1824 }, [callback]);
1825 (0, import_element17.useEffect)(() => {
1826 if (isDisabled) {
1827 return;
1828 }
1829 const mousetrap = new import_mousetrap.default(
1830 target && target.current ? target.current : (
1831 // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
1832 // 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
1833 // necessary to maintain the existing behavior.
1834 document
1835 )
1836 );
1837 const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
1838 shortcutsArray.forEach((shortcut) => {
1839 const keys = shortcut.split("+");
1840 const modifiers = new Set(
1841 keys.filter((value) => value.length > 1)
1842 );
1843 const hasAlt = modifiers.has("alt");
1844 const hasShift = modifiers.has("shift");
1845 if ((0, import_keycodes.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
1846 throw new Error(
1847 `Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`
1848 );
1849 }
1850 const bindFn = bindGlobal ? "bindGlobal" : "bind";
1851 mousetrap[bindFn](
1852 shortcut,
1853 (...args) => currentCallbackRef.current(...args),
1854 eventName
1855 );
1856 });
1857 return () => {
1858 mousetrap.reset();
1859 };
1860 }, [shortcuts, bindGlobal, eventName, target, isDisabled]);
1861 }
1862 var use_keyboard_shortcut_default = useKeyboardShortcut;
1863
1864 // packages/compose/build-module/hooks/use-media-query/index.mjs
1865 var import_element18 = __toESM(require_element(), 1);
1866 var perWindowCache = /* @__PURE__ */ new WeakMap();
1867 var EMPTY_SUBSCRIBER = {
1868 subscribe: () => () => {
1869 },
1870 getValue: () => false
1871 };
1872 function getMQLSubscriber(view, query) {
1873 if (!view || !query || typeof view.matchMedia !== "function") {
1874 return EMPTY_SUBSCRIBER;
1875 }
1876 let queryCache = perWindowCache.get(view);
1877 if (!queryCache) {
1878 queryCache = /* @__PURE__ */ new Map();
1879 perWindowCache.set(view, queryCache);
1880 }
1881 const cached = queryCache.get(query);
1882 if (cached) {
1883 return cached;
1884 }
1885 const mediaQueryList = view.matchMedia(query);
1886 const listeners = /* @__PURE__ */ new Set();
1887 const notify = () => {
1888 for (const listener2 of listeners) {
1889 listener2();
1890 }
1891 };
1892 const subscriber = {
1893 subscribe(onStoreChange) {
1894 if (listeners.size === 0) {
1895 mediaQueryList.addEventListener?.("change", notify);
1896 }
1897 listeners.add(onStoreChange);
1898 return () => {
1899 listeners.delete(onStoreChange);
1900 if (listeners.size === 0) {
1901 mediaQueryList.removeEventListener?.("change", notify);
1902 }
1903 };
1904 },
1905 getValue() {
1906 return mediaQueryList.matches;
1907 }
1908 };
1909 queryCache.set(query, subscriber);
1910 return subscriber;
1911 }
1912 function useMediaQuery(query, view = typeof window !== "undefined" ? window : void 0) {
1913 const source = getMQLSubscriber(view, query);
1914 return (0, import_element18.useSyncExternalStore)(
1915 source.subscribe,
1916 source.getValue,
1917 () => false
1918 );
1919 }
1920
1921 // packages/compose/build-module/hooks/use-previous/index.mjs
1922 var import_element19 = __toESM(require_element(), 1);
1923 function usePrevious(value) {
1924 const ref = (0, import_element19.useRef)(void 0);
1925 (0, import_element19.useEffect)(() => {
1926 ref.current = value;
1927 }, [value]);
1928 return ref.current;
1929 }
1930
1931 // packages/compose/build-module/hooks/use-reduced-motion/index.mjs
1932 var useReducedMotion = () => useMediaQuery("(prefers-reduced-motion: reduce)");
1933 var use_reduced_motion_default = useReducedMotion;
1934
1935 // packages/compose/build-module/hooks/use-state-with-history/index.mjs
1936 var import_undo_manager = __toESM(require_undo_manager(), 1);
1937 var import_element20 = __toESM(require_element(), 1);
1938 function undoRedoReducer(state, action) {
1939 switch (action.type) {
1940 case "UNDO": {
1941 const undoRecord = state.manager.undo();
1942 if (undoRecord) {
1943 return {
1944 ...state,
1945 value: undoRecord[0].changes.prop.from
1946 };
1947 }
1948 return state;
1949 }
1950 case "REDO": {
1951 const redoRecord = state.manager.redo();
1952 if (redoRecord) {
1953 return {
1954 ...state,
1955 value: redoRecord[0].changes.prop.to
1956 };
1957 }
1958 return state;
1959 }
1960 case "RECORD": {
1961 state.manager.addRecord(
1962 [
1963 {
1964 id: "object",
1965 changes: {
1966 prop: { from: state.value, to: action.value }
1967 }
1968 }
1969 ],
1970 action.isStaged
1971 );
1972 return {
1973 ...state,
1974 value: action.value
1975 };
1976 }
1977 }
1978 return state;
1979 }
1980 function initReducer(value) {
1981 return {
1982 manager: (0, import_undo_manager.createUndoManager)(),
1983 value
1984 };
1985 }
1986 function useStateWithHistory(initialValue) {
1987 const [state, dispatch] = (0, import_element20.useReducer)(
1988 undoRedoReducer,
1989 initialValue,
1990 initReducer
1991 );
1992 return {
1993 value: state.value,
1994 setValue: (0, import_element20.useCallback)((newValue, isStaged) => {
1995 dispatch({
1996 type: "RECORD",
1997 value: newValue,
1998 isStaged
1999 });
2000 }, []),
2001 hasUndo: state.manager.hasUndo(),
2002 hasRedo: state.manager.hasRedo(),
2003 undo: (0, import_element20.useCallback)(() => {
2004 dispatch({ type: "UNDO" });
2005 }, []),
2006 redo: (0, import_element20.useCallback)(() => {
2007 dispatch({ type: "REDO" });
2008 }, [])
2009 };
2010 }
2011
2012 // packages/compose/build-module/hooks/use-viewport-match/index.mjs
2013 var import_element21 = __toESM(require_element(), 1);
2014 var BREAKPOINTS = {
2015 xhuge: 1920,
2016 huge: 1440,
2017 wide: 1280,
2018 xlarge: 1080,
2019 large: 960,
2020 medium: 782,
2021 small: 600,
2022 mobile: 480
2023 };
2024 var CONDITIONS = {
2025 ">=": "min-width",
2026 "<": "max-width"
2027 };
2028 var OPERATOR_EVALUATORS = {
2029 ">=": (breakpointValue, width) => width >= breakpointValue,
2030 "<": (breakpointValue, width) => width < breakpointValue
2031 };
2032 var ViewportMatchWidthContext = (0, import_element21.createContext)(null);
2033 ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext";
2034 var useViewportMatch = (breakpoint, operator = ">=", view = typeof window !== "undefined" ? window : void 0) => {
2035 const simulatedWidth = (0, import_element21.useContext)(ViewportMatchWidthContext);
2036 const mediaQuery = !simulatedWidth && `screen and (${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
2037 const mediaQueryResult = useMediaQuery(mediaQuery || void 0, view);
2038 if (simulatedWidth) {
2039 return OPERATOR_EVALUATORS[operator](
2040 BREAKPOINTS[breakpoint],
2041 simulatedWidth
2042 );
2043 }
2044 return mediaQueryResult;
2045 };
2046 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
2047 var use_viewport_match_default = useViewportMatch;
2048
2049 // packages/compose/build-module/hooks/use-resize-observer/use-resize-observer.mjs
2050 var import_element22 = __toESM(require_element(), 1);
2051 function useResizeObserver(callback, resizeObserverOptions = {}) {
2052 const callbackEvent = useEvent(callback);
2053 const observedElementRef = (0, import_element22.useRef)(null);
2054 const resizeObserverRef = (0, import_element22.useRef)(void 0);
2055 (0, import_element22.useEffect)(() => {
2056 if (observedElementRef.current) {
2057 resizeObserverRef.current?.observe(
2058 observedElementRef.current,
2059 resizeObserverOptions
2060 );
2061 }
2062 return () => resizeObserverRef.current?.disconnect();
2063 }, []);
2064 return useEvent((element) => {
2065 if (element === observedElementRef.current) {
2066 return;
2067 }
2068 resizeObserverRef.current ??= new ResizeObserver(callbackEvent);
2069 const { current: resizeObserver } = resizeObserverRef;
2070 if (observedElementRef.current) {
2071 resizeObserver.unobserve(observedElementRef.current);
2072 }
2073 observedElementRef.current = element ?? null;
2074 if (element) {
2075 resizeObserver.observe(element, resizeObserverOptions);
2076 }
2077 });
2078 }
2079
2080 // packages/compose/build-module/hooks/use-resize-observer/legacy/index.mjs
2081 var import_element23 = __toESM(require_element(), 1);
2082 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
2083 var extractSize = (entry) => {
2084 let entrySize;
2085 if (!entry.contentBoxSize) {
2086 entrySize = [entry.contentRect.width, entry.contentRect.height];
2087 } else if (entry.contentBoxSize[0]) {
2088 const contentBoxSize = entry.contentBoxSize[0];
2089 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
2090 } else {
2091 const contentBoxSize = entry.contentBoxSize;
2092 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
2093 }
2094 const [width, height] = entrySize.map((d) => Math.round(d));
2095 return { width, height };
2096 };
2097 var RESIZE_ELEMENT_STYLES = {
2098 position: "absolute",
2099 top: 0,
2100 left: 0,
2101 right: 0,
2102 bottom: 0,
2103 pointerEvents: "none",
2104 opacity: 0,
2105 overflow: "hidden",
2106 zIndex: -1
2107 };
2108 function ResizeElement({ onResize }) {
2109 const resizeElementRef = useResizeObserver((entries) => {
2110 const newSize = extractSize(entries.at(-1));
2111 onResize(newSize);
2112 });
2113 return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2114 "div",
2115 {
2116 ref: resizeElementRef,
2117 style: RESIZE_ELEMENT_STYLES,
2118 "aria-hidden": "true"
2119 }
2120 );
2121 }
2122 function sizeEquals(a, b) {
2123 return a.width === b.width && a.height === b.height;
2124 }
2125 var NULL_SIZE = { width: null, height: null };
2126 function useLegacyResizeObserver() {
2127 const [size, setSize] = (0, import_element23.useState)(NULL_SIZE);
2128 const previousSizeRef = (0, import_element23.useRef)(NULL_SIZE);
2129 const handleResize = (0, import_element23.useCallback)((newSize) => {
2130 if (!sizeEquals(previousSizeRef.current, newSize)) {
2131 previousSizeRef.current = newSize;
2132 setSize(newSize);
2133 }
2134 }, []);
2135 const resizeElement = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ResizeElement, { onResize: handleResize });
2136 return [resizeElement, size];
2137 }
2138
2139 // packages/compose/build-module/hooks/use-resize-observer/index.mjs
2140 function useResizeObserver2(callback, options = {}) {
2141 return callback ? useResizeObserver(callback, options) : useLegacyResizeObserver();
2142 }
2143
2144 // packages/compose/build-module/hooks/use-async-list/index.mjs
2145 var import_element24 = __toESM(require_element(), 1);
2146 var import_priority_queue = __toESM(require_priority_queue(), 1);
2147 function getFirstItemsPresentInState(list, state) {
2148 const firstItems = [];
2149 for (let i = 0; i < list.length; i++) {
2150 const item = list[i];
2151 if (!state.includes(item)) {
2152 break;
2153 }
2154 firstItems.push(item);
2155 }
2156 return firstItems;
2157 }
2158 function useAsyncList(list, config = { step: 1 }) {
2159 const { step = 1 } = config;
2160 const [current, setCurrent] = (0, import_element24.useState)([]);
2161 (0, import_element24.useEffect)(() => {
2162 let firstItems = getFirstItemsPresentInState(list, current);
2163 if (firstItems.length < step) {
2164 firstItems = firstItems.concat(
2165 list.slice(firstItems.length, step)
2166 );
2167 }
2168 setCurrent(firstItems);
2169 const asyncQueue = (0, import_priority_queue.createQueue)();
2170 for (let i = firstItems.length; i < list.length; i += step) {
2171 asyncQueue.add({}, () => {
2172 (0, import_element24.flushSync)(() => {
2173 setCurrent((state) => [
2174 ...state,
2175 ...list.slice(i, i + step)
2176 ]);
2177 });
2178 });
2179 }
2180 return () => asyncQueue.reset();
2181 }, [list]);
2182 return current;
2183 }
2184 var use_async_list_default = useAsyncList;
2185
2186 // packages/compose/build-module/hooks/use-warn-on-change/index.mjs
2187 function useWarnOnChange(object, prefix = "Change detection") {
2188 const previousValues = usePrevious(object);
2189 Object.entries(previousValues ?? []).forEach(([key, value]) => {
2190 if (value !== object[key]) {
2191 console.warn(
2192 `${prefix}: ${key} key changed:`,
2193 value,
2194 object[key]
2195 );
2196 }
2197 });
2198 }
2199 var use_warn_on_change_default = useWarnOnChange;
2200
2201 // node_modules/use-memo-one/dist/use-memo-one.esm.js
2202 var import_react = __toESM(require_react());
2203 function areInputsEqual(newInputs, lastInputs) {
2204 if (newInputs.length !== lastInputs.length) {
2205 return false;
2206 }
2207 for (var i = 0; i < newInputs.length; i++) {
2208 if (newInputs[i] !== lastInputs[i]) {
2209 return false;
2210 }
2211 }
2212 return true;
2213 }
2214 function useMemoOne(getResult, inputs) {
2215 var initial = (0, import_react.useState)(function() {
2216 return {
2217 inputs,
2218 result: getResult()
2219 };
2220 })[0];
2221 var committed = (0, import_react.useRef)(initial);
2222 var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs));
2223 var cache = isInputMatch ? committed.current : {
2224 inputs,
2225 result: getResult()
2226 };
2227 (0, import_react.useEffect)(function() {
2228 committed.current = cache;
2229 }, [cache]);
2230 return cache.result;
2231 }
2232
2233 // packages/compose/build-module/hooks/use-debounce/index.mjs
2234 var import_element25 = __toESM(require_element(), 1);
2235 function useDebounce(fn, wait, options) {
2236 const debounced = useMemoOne(
2237 () => debounce(fn, wait ?? 0, options),
2238 [fn, wait, options?.leading, options?.trailing, options?.maxWait]
2239 );
2240 (0, import_element25.useEffect)(() => () => debounced.cancel(), [debounced]);
2241 return debounced;
2242 }
2243
2244 // packages/compose/build-module/hooks/use-debounced-input/index.mjs
2245 var import_element26 = __toESM(require_element(), 1);
2246 function useDebouncedInput(defaultValue = "") {
2247 const [input, setInput] = (0, import_element26.useState)(defaultValue);
2248 const [debouncedInput, setDebouncedState] = (0, import_element26.useState)(defaultValue);
2249 const setDebouncedInput = useDebounce(setDebouncedState, 250);
2250 (0, import_element26.useEffect)(() => {
2251 setDebouncedInput(input);
2252 }, [input, setDebouncedInput]);
2253 return [input, setInput, debouncedInput];
2254 }
2255
2256 // packages/compose/build-module/hooks/use-throttle/index.mjs
2257 var import_element27 = __toESM(require_element(), 1);
2258 function useThrottle(fn, wait, options) {
2259 const throttled = useMemoOne(
2260 () => throttle(fn, wait ?? 0, options),
2261 [fn, wait, options]
2262 );
2263 (0, import_element27.useEffect)(() => () => throttled.cancel(), [throttled]);
2264 return throttled;
2265 }
2266
2267 // packages/compose/build-module/hooks/use-drop-zone/index.mjs
2268 function useDropZone({
2269 dropZoneElement,
2270 isDisabled,
2271 onDrop: _onDrop,
2272 onDragStart: _onDragStart,
2273 onDragEnter: _onDragEnter,
2274 onDragLeave: _onDragLeave,
2275 onDragEnd: _onDragEnd,
2276 onDragOver: _onDragOver
2277 }) {
2278 const onDropEvent = useEvent(_onDrop);
2279 const onDragStartEvent = useEvent(_onDragStart);
2280 const onDragEnterEvent = useEvent(_onDragEnter);
2281 const onDragLeaveEvent = useEvent(_onDragLeave);
2282 const onDragEndEvent = useEvent(_onDragEnd);
2283 const onDragOverEvent = useEvent(_onDragOver);
2284 return useRefEffect(
2285 (elem) => {
2286 if (isDisabled) {
2287 return;
2288 }
2289 const element = dropZoneElement ?? elem;
2290 let isDragging = false;
2291 const { ownerDocument } = element;
2292 function isElementInZone(targetToCheck) {
2293 const { defaultView } = ownerDocument;
2294 if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) {
2295 return false;
2296 }
2297 let elementToCheck = targetToCheck;
2298 do {
2299 if (elementToCheck.dataset.isDropZone) {
2300 return elementToCheck === element;
2301 }
2302 } while (elementToCheck = elementToCheck.parentElement);
2303 return false;
2304 }
2305 function maybeDragStart(event) {
2306 if (isDragging) {
2307 return;
2308 }
2309 isDragging = true;
2310 ownerDocument.addEventListener("dragend", maybeDragEnd);
2311 ownerDocument.addEventListener("mousemove", maybeDragEnd);
2312 if (_onDragStart) {
2313 onDragStartEvent(event);
2314 }
2315 }
2316 function onDragEnter(event) {
2317 event.preventDefault();
2318 if (element.contains(event.relatedTarget)) {
2319 return;
2320 }
2321 if (_onDragEnter) {
2322 onDragEnterEvent(event);
2323 }
2324 }
2325 function onDragOver(event) {
2326 if (!event.defaultPrevented && _onDragOver) {
2327 onDragOverEvent(event);
2328 }
2329 event.preventDefault();
2330 }
2331 function onDragLeave(event) {
2332 if (isElementInZone(event.relatedTarget)) {
2333 return;
2334 }
2335 if (_onDragLeave) {
2336 onDragLeaveEvent(event);
2337 }
2338 }
2339 function onDrop(event) {
2340 if (event.defaultPrevented) {
2341 return;
2342 }
2343 event.preventDefault();
2344 event.dataTransfer && event.dataTransfer.files.length;
2345 if (_onDrop) {
2346 onDropEvent(event);
2347 }
2348 maybeDragEnd(event);
2349 }
2350 function maybeDragEnd(event) {
2351 if (!isDragging) {
2352 return;
2353 }
2354 isDragging = false;
2355 ownerDocument.removeEventListener("dragend", maybeDragEnd);
2356 ownerDocument.removeEventListener("mousemove", maybeDragEnd);
2357 if (_onDragEnd) {
2358 onDragEndEvent(event);
2359 }
2360 }
2361 element.setAttribute("data-is-drop-zone", "true");
2362 element.addEventListener("drop", onDrop);
2363 element.addEventListener("dragenter", onDragEnter);
2364 element.addEventListener("dragover", onDragOver);
2365 element.addEventListener("dragleave", onDragLeave);
2366 ownerDocument.addEventListener("dragenter", maybeDragStart);
2367 return () => {
2368 element.removeAttribute("data-is-drop-zone");
2369 element.removeEventListener("drop", onDrop);
2370 element.removeEventListener("dragenter", onDragEnter);
2371 element.removeEventListener("dragover", onDragOver);
2372 element.removeEventListener("dragleave", onDragLeave);
2373 ownerDocument.removeEventListener("dragend", maybeDragEnd);
2374 ownerDocument.removeEventListener("mousemove", maybeDragEnd);
2375 ownerDocument.removeEventListener(
2376 "dragenter",
2377 maybeDragStart
2378 );
2379 };
2380 },
2381 [isDisabled, dropZoneElement]
2382 // Refresh when the passed in dropZoneElement changes.
2383 );
2384 }
2385
2386 // packages/compose/build-module/hooks/use-focusable-iframe/index.mjs
2387 function useFocusableIframe() {
2388 return useRefEffect((element) => {
2389 const { ownerDocument } = element;
2390 if (!ownerDocument) {
2391 return;
2392 }
2393 const { defaultView } = ownerDocument;
2394 if (!defaultView) {
2395 return;
2396 }
2397 function checkFocus() {
2398 if (ownerDocument && ownerDocument.activeElement === element) {
2399 element.focus();
2400 }
2401 }
2402 defaultView.addEventListener("blur", checkFocus);
2403 return () => {
2404 defaultView.removeEventListener("blur", checkFocus);
2405 };
2406 }, []);
2407 }
2408
2409 // packages/compose/build-module/hooks/use-fixed-window-list/index.mjs
2410 var import_element28 = __toESM(require_element(), 1);
2411 var import_dom3 = __toESM(require_dom(), 1);
2412 var import_keycodes2 = __toESM(require_keycodes(), 1);
2413 var DEFAULT_INIT_WINDOW_SIZE = 30;
2414 function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
2415 const {
2416 windowOverscan,
2417 useWindowing = true,
2418 initWindowSize = DEFAULT_INIT_WINDOW_SIZE,
2419 expandedState
2420 } = options ?? {};
2421 const [fixedListWindow, setFixedListWindow] = (0, import_element28.useState)(
2422 {
2423 visibleItems: initWindowSize,
2424 start: 0,
2425 end: initWindowSize,
2426 itemInView: (index) => {
2427 return index >= 0 && index <= initWindowSize;
2428 }
2429 }
2430 );
2431 const visibleItemsRef = (0, import_element28.useRef)(initWindowSize);
2432 const isFirstMeasurementRef = (0, import_element28.useRef)(true);
2433 const measureWindow = useEvent((initRender) => {
2434 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current);
2435 if (!scrollContainer) {
2436 return;
2437 }
2438 const visibleItems = Math.ceil(
2439 scrollContainer.clientHeight / itemHeight
2440 );
2441 visibleItemsRef.current = visibleItems;
2442 const isFirstMeasurement = isFirstMeasurementRef.current;
2443 isFirstMeasurementRef.current = false;
2444 const overscan = initRender ? visibleItems : windowOverscan ?? visibleItems;
2445 const firstViewableIndex = Math.floor(
2446 scrollContainer.scrollTop / itemHeight
2447 );
2448 const start = Math.max(0, firstViewableIndex - overscan);
2449 const end = Math.min(
2450 totalItems - 1,
2451 firstViewableIndex + visibleItems + overscan
2452 );
2453 setFixedListWindow((lastWindow) => {
2454 if (lastWindow.start <= start && lastWindow.end >= end) {
2455 return lastWindow;
2456 }
2457 if (isFirstMeasurement && lastWindow.start <= firstViewableIndex && lastWindow.end >= firstViewableIndex + visibleItems) {
2458 return lastWindow;
2459 }
2460 return {
2461 visibleItems,
2462 start,
2463 end,
2464 itemInView: (index) => {
2465 return start <= index && index <= end;
2466 }
2467 };
2468 });
2469 });
2470 const handleKeyDown = useEvent(
2471 (event, scrollContainer) => {
2472 switch (event.keyCode) {
2473 case import_keycodes2.HOME: {
2474 return scrollContainer.scrollTo({ top: 0 });
2475 }
2476 case import_keycodes2.END: {
2477 return scrollContainer.scrollTo({
2478 top: totalItems * itemHeight
2479 });
2480 }
2481 case import_keycodes2.PAGEUP: {
2482 return scrollContainer.scrollTo({
2483 top: scrollContainer.scrollTop - visibleItemsRef.current * itemHeight
2484 });
2485 }
2486 case import_keycodes2.PAGEDOWN: {
2487 return scrollContainer.scrollTo({
2488 top: scrollContainer.scrollTop + visibleItemsRef.current * itemHeight
2489 });
2490 }
2491 }
2492 }
2493 );
2494 (0, import_element28.useLayoutEffect)(() => {
2495 if (!useWindowing) {
2496 return;
2497 }
2498 measureWindow(true);
2499 }, [
2500 useWindowing,
2501 measureWindow,
2502 itemHeight,
2503 totalItems,
2504 windowOverscan,
2505 expandedState
2506 ]);
2507 (0, import_element28.useLayoutEffect)(() => {
2508 if (!useWindowing) {
2509 return;
2510 }
2511 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current);
2512 if (!scrollContainer) {
2513 return;
2514 }
2515 const { defaultView } = scrollContainer.ownerDocument;
2516 const onMeasure = () => measureWindow();
2517 const onKeyDown = (event) => handleKeyDown(event, scrollContainer);
2518 scrollContainer.addEventListener("scroll", onMeasure);
2519 defaultView?.addEventListener("resize", onMeasure);
2520 defaultView?.addEventListener("keydown", onKeyDown);
2521 return () => {
2522 scrollContainer.removeEventListener("scroll", onMeasure);
2523 defaultView?.removeEventListener("resize", onMeasure);
2524 defaultView?.removeEventListener("keydown", onKeyDown);
2525 };
2526 }, [
2527 useWindowing,
2528 elementRef,
2529 itemHeight,
2530 totalItems,
2531 expandedState,
2532 measureWindow,
2533 handleKeyDown
2534 ]);
2535 return [fixedListWindow, setFixedListWindow];
2536 }
2537
2538 // packages/compose/build-module/hooks/use-observable-value/index.mjs
2539 var import_element29 = __toESM(require_element(), 1);
2540 function useObservableValue(map, name) {
2541 const [subscribe, getValue] = (0, import_element29.useMemo)(
2542 () => [
2543 (listener2) => map.subscribe(name, listener2),
2544 () => map.get(name)
2545 ],
2546 [map, name]
2547 );
2548 return (0, import_element29.useSyncExternalStore)(subscribe, getValue, getValue);
2549 }
2550 return __toCommonJS(index_exports);
2551 })();
2552 (window.wp ||= {}).compose = wp.compose;
2553 })();
2554 //# sourceMappingURL=index.js.map
2555