PluginProbe
Gutenberg / 23.5.3
Gutenberg v23.5.3
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 7.4.0 All 402 releases
gutenberg / build / scripts / compose / index.js

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

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