PluginProbe
Gutenberg / 23.6.2
Gutenberg v23.6.2
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.6.2, at build/scripts/compose/index.js

2,546 lines 83.7 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 attachedRefsRef = (0, import_element12.useRef)([]);
1578 const currentRefsRef = (0, import_element12.useRef)(refs);
1579 const cleanupsRef = (0, import_element12.useRef)([]);
1580 currentRefsRef.current = refs;
1581 (0, import_element12.useLayoutEffect)(() => {
1582 const element = elementRef.current;
1583 if (element === null) {
1584 return;
1585 }
1586 refs.forEach((ref, index) => {
1587 const attachedRef = attachedRefsRef.current[index];
1588 if (ref !== attachedRef) {
1589 detachRef(attachedRef, index, cleanupsRef.current);
1590 cleanupsRef.current[index] = assignRef(ref, element);
1591 }
1592 });
1593 attachedRefsRef.current = refs;
1594 }, refs);
1595 return (0, import_element12.useCallback)((value) => {
1596 elementRef.current = value;
1597 if (value === null) {
1598 attachedRefsRef.current.forEach((ref, index) => {
1599 detachRef(ref, index, cleanupsRef.current);
1600 });
1601 attachedRefsRef.current = [];
1602 } else {
1603 attachedRefsRef.current = currentRefsRef.current;
1604 attachedRefsRef.current.forEach((ref, index) => {
1605 cleanupsRef.current[index] = assignRef(ref, value);
1606 });
1607 }
1608 }, []);
1609 }
1610
1611 // packages/compose/build-module/hooks/use-dialog/index.mjs
1612 function useDialog(options) {
1613 const currentOptions = (0, import_element13.useRef)(void 0);
1614 const { constrainTabbing = options.focusOnMount !== false } = options;
1615 (0, import_element13.useEffect)(() => {
1616 currentOptions.current = options;
1617 }, Object.values(options));
1618 const constrainedTabbingRef = use_constrained_tabbing_default();
1619 const focusOnMountRef = useFocusOnMount(options.focusOnMount);
1620 const focusReturnRef = use_focus_return_default();
1621 const focusOutsideProps = useFocusOutside((event) => {
1622 if (currentOptions.current?.__unstableOnClose) {
1623 currentOptions.current.__unstableOnClose("focus-outside", event);
1624 } else if (currentOptions.current?.onClose) {
1625 currentOptions.current.onClose();
1626 }
1627 });
1628 const onKeyDown = (0, import_element13.useCallback)((event) => {
1629 currentOptions.current?.onKeyDown?.(event);
1630 if (event.key === "Escape" && !event.defaultPrevented && currentOptions.current?.onClose) {
1631 event.preventDefault();
1632 event.stopPropagation();
1633 currentOptions.current.onClose();
1634 }
1635 }, []);
1636 return [
1637 useMergeRefs([
1638 constrainTabbing ? constrainedTabbingRef : null,
1639 options.focusOnMount !== false ? focusReturnRef : null,
1640 options.focusOnMount !== false ? focusOnMountRef : null
1641 ]),
1642 {
1643 ...focusOutsideProps,
1644 onKeyDown,
1645 tabIndex: -1
1646 }
1647 ];
1648 }
1649 var use_dialog_default = useDialog;
1650
1651 // packages/compose/build-module/hooks/use-disabled/index.mjs
1652 function useDisabled({
1653 isDisabled: isDisabledProp = false
1654 } = {}) {
1655 return useRefEffect(
1656 (node) => {
1657 if (isDisabledProp) {
1658 return;
1659 }
1660 const defaultView = node?.ownerDocument?.defaultView;
1661 if (!defaultView) {
1662 return;
1663 }
1664 const updates = [];
1665 const disable = () => {
1666 node.childNodes.forEach((child) => {
1667 if (!(child instanceof defaultView.HTMLElement)) {
1668 return;
1669 }
1670 if (!child.getAttribute("inert")) {
1671 child.setAttribute("inert", "true");
1672 updates.push(() => {
1673 child.removeAttribute("inert");
1674 });
1675 }
1676 });
1677 };
1678 const debouncedDisable = debounce(disable, 0, {
1679 leading: true
1680 });
1681 disable();
1682 const observer = new window.MutationObserver(debouncedDisable);
1683 observer.observe(node, {
1684 childList: true
1685 });
1686 return () => {
1687 if (observer) {
1688 observer.disconnect();
1689 }
1690 debouncedDisable.cancel();
1691 updates.forEach((update) => update());
1692 };
1693 },
1694 [isDisabledProp]
1695 );
1696 }
1697
1698 // packages/compose/build-module/hooks/use-event/index.mjs
1699 var import_element14 = __toESM(require_element(), 1);
1700 function useEvent(callback) {
1701 const ref = (0, import_element14.useRef)(() => {
1702 throw new Error(
1703 "Callbacks created with `useEvent` cannot be called during rendering."
1704 );
1705 });
1706 (0, import_element14.useInsertionEffect)(() => {
1707 ref.current = callback;
1708 });
1709 return (0, import_element14.useCallback)(
1710 (...args) => ref.current?.(...args),
1711 []
1712 );
1713 }
1714
1715 // packages/compose/build-module/hooks/use-dragging/index.mjs
1716 var import_element16 = __toESM(require_element(), 1);
1717
1718 // packages/compose/build-module/hooks/use-isomorphic-layout-effect/index.mjs
1719 var import_element15 = __toESM(require_element(), 1);
1720 var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_element15.useLayoutEffect : import_element15.useEffect;
1721 var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
1722
1723 // packages/compose/build-module/hooks/use-dragging/index.mjs
1724 function useDragging({
1725 onDragStart,
1726 onDragMove,
1727 onDragEnd
1728 }) {
1729 const [isDragging, setIsDragging] = (0, import_element16.useState)(false);
1730 const eventsRef = (0, import_element16.useRef)({
1731 onDragStart,
1732 onDragMove,
1733 onDragEnd
1734 });
1735 use_isomorphic_layout_effect_default(() => {
1736 eventsRef.current.onDragStart = onDragStart;
1737 eventsRef.current.onDragMove = onDragMove;
1738 eventsRef.current.onDragEnd = onDragEnd;
1739 }, [onDragStart, onDragMove, onDragEnd]);
1740 const onMouseMove = (0, import_element16.useCallback)((event) => {
1741 eventsRef.current.onDragMove?.(event);
1742 }, []);
1743 const endDrag = (0, import_element16.useCallback)(
1744 function endDrag2(event) {
1745 eventsRef.current.onDragEnd?.(event);
1746 document.removeEventListener("mousemove", onMouseMove);
1747 document.removeEventListener("mouseup", endDrag2);
1748 setIsDragging(false);
1749 },
1750 [onMouseMove]
1751 );
1752 const startDrag = (0, import_element16.useCallback)(
1753 (event) => {
1754 eventsRef.current.onDragStart?.(event);
1755 document.addEventListener("mousemove", onMouseMove);
1756 document.addEventListener("mouseup", endDrag);
1757 setIsDragging(true);
1758 },
1759 [onMouseMove, endDrag]
1760 );
1761 (0, import_element16.useEffect)(() => {
1762 return () => {
1763 if (isDragging) {
1764 document.removeEventListener("mousemove", onMouseMove);
1765 document.removeEventListener("mouseup", endDrag);
1766 }
1767 };
1768 }, [isDragging, onMouseMove, endDrag]);
1769 return {
1770 startDrag,
1771 endDrag,
1772 isDragging
1773 };
1774 }
1775
1776 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs
1777 var import_mousetrap = __toESM(require_mousetrap(), 1);
1778
1779 // node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
1780 (function(Mousetrap3) {
1781 if (!Mousetrap3) {
1782 return;
1783 }
1784 var _globalCallbacks = {};
1785 var _originalStopCallback = Mousetrap3.prototype.stopCallback;
1786 Mousetrap3.prototype.stopCallback = function(e, element, combo, sequence) {
1787 var self = this;
1788 if (self.paused) {
1789 return true;
1790 }
1791 if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
1792 return false;
1793 }
1794 return _originalStopCallback.call(self, e, element, combo);
1795 };
1796 Mousetrap3.prototype.bindGlobal = function(keys, callback, action) {
1797 var self = this;
1798 self.bind(keys, callback, action);
1799 if (keys instanceof Array) {
1800 for (var i = 0; i < keys.length; i++) {
1801 _globalCallbacks[keys[i]] = true;
1802 }
1803 return;
1804 }
1805 _globalCallbacks[keys] = true;
1806 };
1807 Mousetrap3.init();
1808 })(typeof Mousetrap !== "undefined" ? Mousetrap : void 0);
1809
1810 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs
1811 var import_element17 = __toESM(require_element(), 1);
1812 var import_keycodes = __toESM(require_keycodes(), 1);
1813 function useKeyboardShortcut(shortcuts, callback, {
1814 bindGlobal = false,
1815 eventName = "keydown",
1816 isDisabled = false,
1817 target
1818 } = {}) {
1819 const currentCallbackRef = (0, import_element17.useRef)(callback);
1820 (0, import_element17.useEffect)(() => {
1821 currentCallbackRef.current = callback;
1822 }, [callback]);
1823 (0, import_element17.useEffect)(() => {
1824 if (isDisabled) {
1825 return;
1826 }
1827 const mousetrap = new import_mousetrap.default(
1828 target && target.current ? target.current : (
1829 // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
1830 // 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
1831 // necessary to maintain the existing behavior.
1832 document
1833 )
1834 );
1835 const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
1836 shortcutsArray.forEach((shortcut) => {
1837 const keys = shortcut.split("+");
1838 const modifiers = new Set(
1839 keys.filter((value) => value.length > 1)
1840 );
1841 const hasAlt = modifiers.has("alt");
1842 const hasShift = modifiers.has("shift");
1843 if ((0, import_keycodes.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
1844 throw new Error(
1845 `Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`
1846 );
1847 }
1848 const bindFn = bindGlobal ? "bindGlobal" : "bind";
1849 mousetrap[bindFn](
1850 shortcut,
1851 (...args) => currentCallbackRef.current(...args),
1852 eventName
1853 );
1854 });
1855 return () => {
1856 mousetrap.reset();
1857 };
1858 }, [shortcuts, bindGlobal, eventName, target, isDisabled]);
1859 }
1860 var use_keyboard_shortcut_default = useKeyboardShortcut;
1861
1862 // packages/compose/build-module/hooks/use-media-query/index.mjs
1863 var import_element18 = __toESM(require_element(), 1);
1864 var perWindowCache = /* @__PURE__ */ new WeakMap();
1865 var EMPTY_SUBSCRIBER = {
1866 subscribe: () => () => {
1867 },
1868 getValue: () => false
1869 };
1870 function getMQLSubscriber(view, query) {
1871 if (!view || !query || typeof view.matchMedia !== "function") {
1872 return EMPTY_SUBSCRIBER;
1873 }
1874 let queryCache = perWindowCache.get(view);
1875 if (!queryCache) {
1876 queryCache = /* @__PURE__ */ new Map();
1877 perWindowCache.set(view, queryCache);
1878 }
1879 const cached = queryCache.get(query);
1880 if (cached) {
1881 return cached;
1882 }
1883 const mediaQueryList = view.matchMedia(query);
1884 const listeners = /* @__PURE__ */ new Set();
1885 const notify = () => {
1886 for (const listener2 of listeners) {
1887 listener2();
1888 }
1889 };
1890 const subscriber = {
1891 subscribe(onStoreChange) {
1892 if (listeners.size === 0) {
1893 mediaQueryList.addEventListener?.("change", notify);
1894 }
1895 listeners.add(onStoreChange);
1896 return () => {
1897 listeners.delete(onStoreChange);
1898 if (listeners.size === 0) {
1899 mediaQueryList.removeEventListener?.("change", notify);
1900 }
1901 };
1902 },
1903 getValue() {
1904 return mediaQueryList.matches;
1905 }
1906 };
1907 queryCache.set(query, subscriber);
1908 return subscriber;
1909 }
1910 function useMediaQuery(query, view = typeof window !== "undefined" ? window : void 0) {
1911 const source = getMQLSubscriber(view, query);
1912 return (0, import_element18.useSyncExternalStore)(
1913 source.subscribe,
1914 source.getValue,
1915 () => false
1916 );
1917 }
1918
1919 // packages/compose/build-module/hooks/use-previous/index.mjs
1920 var import_element19 = __toESM(require_element(), 1);
1921 function usePrevious(value) {
1922 const ref = (0, import_element19.useRef)(void 0);
1923 (0, import_element19.useEffect)(() => {
1924 ref.current = value;
1925 }, [value]);
1926 return ref.current;
1927 }
1928
1929 // packages/compose/build-module/hooks/use-reduced-motion/index.mjs
1930 var useReducedMotion = () => useMediaQuery("(prefers-reduced-motion: reduce)");
1931 var use_reduced_motion_default = useReducedMotion;
1932
1933 // packages/compose/build-module/hooks/use-state-with-history/index.mjs
1934 var import_undo_manager = __toESM(require_undo_manager(), 1);
1935 var import_element20 = __toESM(require_element(), 1);
1936 function undoRedoReducer(state, action) {
1937 switch (action.type) {
1938 case "UNDO": {
1939 const undoRecord = state.manager.undo();
1940 if (undoRecord) {
1941 return {
1942 ...state,
1943 value: undoRecord[0].changes.prop.from
1944 };
1945 }
1946 return state;
1947 }
1948 case "REDO": {
1949 const redoRecord = state.manager.redo();
1950 if (redoRecord) {
1951 return {
1952 ...state,
1953 value: redoRecord[0].changes.prop.to
1954 };
1955 }
1956 return state;
1957 }
1958 case "RECORD": {
1959 state.manager.addRecord(
1960 [
1961 {
1962 id: "object",
1963 changes: {
1964 prop: { from: state.value, to: action.value }
1965 }
1966 }
1967 ],
1968 action.isStaged
1969 );
1970 return {
1971 ...state,
1972 value: action.value
1973 };
1974 }
1975 }
1976 return state;
1977 }
1978 function initReducer(value) {
1979 return {
1980 manager: (0, import_undo_manager.createUndoManager)(),
1981 value
1982 };
1983 }
1984 function useStateWithHistory(initialValue) {
1985 const [state, dispatch] = (0, import_element20.useReducer)(
1986 undoRedoReducer,
1987 initialValue,
1988 initReducer
1989 );
1990 return {
1991 value: state.value,
1992 setValue: (0, import_element20.useCallback)((newValue, isStaged) => {
1993 dispatch({
1994 type: "RECORD",
1995 value: newValue,
1996 isStaged
1997 });
1998 }, []),
1999 hasUndo: state.manager.hasUndo(),
2000 hasRedo: state.manager.hasRedo(),
2001 undo: (0, import_element20.useCallback)(() => {
2002 dispatch({ type: "UNDO" });
2003 }, []),
2004 redo: (0, import_element20.useCallback)(() => {
2005 dispatch({ type: "REDO" });
2006 }, [])
2007 };
2008 }
2009
2010 // packages/compose/build-module/hooks/use-viewport-match/index.mjs
2011 var import_element21 = __toESM(require_element(), 1);
2012 var BREAKPOINTS = {
2013 xhuge: 1920,
2014 huge: 1440,
2015 wide: 1280,
2016 xlarge: 1080,
2017 large: 960,
2018 medium: 782,
2019 small: 600,
2020 mobile: 480
2021 };
2022 var CONDITIONS = {
2023 ">=": "min-width",
2024 "<": "max-width"
2025 };
2026 var OPERATOR_EVALUATORS = {
2027 ">=": (breakpointValue, width) => width >= breakpointValue,
2028 "<": (breakpointValue, width) => width < breakpointValue
2029 };
2030 var ViewportMatchWidthContext = (0, import_element21.createContext)(null);
2031 ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext";
2032 var useViewportMatch = (breakpoint, operator = ">=", view = typeof window !== "undefined" ? window : void 0) => {
2033 const simulatedWidth = (0, import_element21.useContext)(ViewportMatchWidthContext);
2034 const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
2035 const mediaQueryResult = useMediaQuery(mediaQuery || void 0, view);
2036 if (simulatedWidth) {
2037 return OPERATOR_EVALUATORS[operator](
2038 BREAKPOINTS[breakpoint],
2039 simulatedWidth
2040 );
2041 }
2042 return mediaQueryResult;
2043 };
2044 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
2045 var use_viewport_match_default = useViewportMatch;
2046
2047 // packages/compose/build-module/hooks/use-resize-observer/use-resize-observer.mjs
2048 var import_element22 = __toESM(require_element(), 1);
2049 function useResizeObserver(callback, resizeObserverOptions = {}) {
2050 const callbackEvent = useEvent(callback);
2051 const observedElementRef = (0, import_element22.useRef)(null);
2052 const resizeObserverRef = (0, import_element22.useRef)(void 0);
2053 return useEvent((element) => {
2054 if (element === observedElementRef.current) {
2055 return;
2056 }
2057 resizeObserverRef.current ??= new ResizeObserver(callbackEvent);
2058 const { current: resizeObserver } = resizeObserverRef;
2059 if (observedElementRef.current) {
2060 resizeObserver.unobserve(observedElementRef.current);
2061 }
2062 observedElementRef.current = element ?? null;
2063 if (element) {
2064 resizeObserver.observe(element, resizeObserverOptions);
2065 }
2066 });
2067 }
2068
2069 // packages/compose/build-module/hooks/use-resize-observer/legacy/index.mjs
2070 var import_element23 = __toESM(require_element(), 1);
2071 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
2072 var extractSize = (entry) => {
2073 let entrySize;
2074 if (!entry.contentBoxSize) {
2075 entrySize = [entry.contentRect.width, entry.contentRect.height];
2076 } else if (entry.contentBoxSize[0]) {
2077 const contentBoxSize = entry.contentBoxSize[0];
2078 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
2079 } else {
2080 const contentBoxSize = entry.contentBoxSize;
2081 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
2082 }
2083 const [width, height] = entrySize.map((d) => Math.round(d));
2084 return { width, height };
2085 };
2086 var RESIZE_ELEMENT_STYLES = {
2087 position: "absolute",
2088 top: 0,
2089 left: 0,
2090 right: 0,
2091 bottom: 0,
2092 pointerEvents: "none",
2093 opacity: 0,
2094 overflow: "hidden",
2095 zIndex: -1
2096 };
2097 function ResizeElement({ onResize }) {
2098 const resizeElementRef = useResizeObserver((entries) => {
2099 const newSize = extractSize(entries.at(-1));
2100 onResize(newSize);
2101 });
2102 return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2103 "div",
2104 {
2105 ref: resizeElementRef,
2106 style: RESIZE_ELEMENT_STYLES,
2107 "aria-hidden": "true"
2108 }
2109 );
2110 }
2111 function sizeEquals(a, b) {
2112 return a.width === b.width && a.height === b.height;
2113 }
2114 var NULL_SIZE = { width: null, height: null };
2115 function useLegacyResizeObserver() {
2116 const [size, setSize] = (0, import_element23.useState)(NULL_SIZE);
2117 const previousSizeRef = (0, import_element23.useRef)(NULL_SIZE);
2118 const handleResize = (0, import_element23.useCallback)((newSize) => {
2119 if (!sizeEquals(previousSizeRef.current, newSize)) {
2120 previousSizeRef.current = newSize;
2121 setSize(newSize);
2122 }
2123 }, []);
2124 const resizeElement = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ResizeElement, { onResize: handleResize });
2125 return [resizeElement, size];
2126 }
2127
2128 // packages/compose/build-module/hooks/use-resize-observer/index.mjs
2129 function useResizeObserver2(callback, options = {}) {
2130 return callback ? useResizeObserver(callback, options) : useLegacyResizeObserver();
2131 }
2132
2133 // packages/compose/build-module/hooks/use-async-list/index.mjs
2134 var import_element24 = __toESM(require_element(), 1);
2135 var import_priority_queue = __toESM(require_priority_queue(), 1);
2136 function getFirstItemsPresentInState(list, state) {
2137 const firstItems = [];
2138 for (let i = 0; i < list.length; i++) {
2139 const item = list[i];
2140 if (!state.includes(item)) {
2141 break;
2142 }
2143 firstItems.push(item);
2144 }
2145 return firstItems;
2146 }
2147 function useAsyncList(list, config = { step: 1 }) {
2148 const { step = 1 } = config;
2149 const [current, setCurrent] = (0, import_element24.useState)([]);
2150 (0, import_element24.useEffect)(() => {
2151 let firstItems = getFirstItemsPresentInState(list, current);
2152 if (firstItems.length < step) {
2153 firstItems = firstItems.concat(
2154 list.slice(firstItems.length, step)
2155 );
2156 }
2157 setCurrent(firstItems);
2158 const asyncQueue = (0, import_priority_queue.createQueue)();
2159 for (let i = firstItems.length; i < list.length; i += step) {
2160 asyncQueue.add({}, () => {
2161 (0, import_element24.flushSync)(() => {
2162 setCurrent((state) => [
2163 ...state,
2164 ...list.slice(i, i + step)
2165 ]);
2166 });
2167 });
2168 }
2169 return () => asyncQueue.reset();
2170 }, [list]);
2171 return current;
2172 }
2173 var use_async_list_default = useAsyncList;
2174
2175 // packages/compose/build-module/hooks/use-warn-on-change/index.mjs
2176 function useWarnOnChange(object, prefix = "Change detection") {
2177 const previousValues = usePrevious(object);
2178 Object.entries(previousValues ?? []).forEach(([key, value]) => {
2179 if (value !== object[key]) {
2180 console.warn(
2181 `${prefix}: ${key} key changed:`,
2182 value,
2183 object[key]
2184 );
2185 }
2186 });
2187 }
2188 var use_warn_on_change_default = useWarnOnChange;
2189
2190 // node_modules/use-memo-one/dist/use-memo-one.esm.js
2191 var import_react = __toESM(require_react());
2192 function areInputsEqual(newInputs, lastInputs) {
2193 if (newInputs.length !== lastInputs.length) {
2194 return false;
2195 }
2196 for (var i = 0; i < newInputs.length; i++) {
2197 if (newInputs[i] !== lastInputs[i]) {
2198 return false;
2199 }
2200 }
2201 return true;
2202 }
2203 function useMemoOne(getResult, inputs) {
2204 var initial = (0, import_react.useState)(function() {
2205 return {
2206 inputs,
2207 result: getResult()
2208 };
2209 })[0];
2210 var committed = (0, import_react.useRef)(initial);
2211 var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs));
2212 var cache = isInputMatch ? committed.current : {
2213 inputs,
2214 result: getResult()
2215 };
2216 (0, import_react.useEffect)(function() {
2217 committed.current = cache;
2218 }, [cache]);
2219 return cache.result;
2220 }
2221
2222 // packages/compose/build-module/hooks/use-debounce/index.mjs
2223 var import_element25 = __toESM(require_element(), 1);
2224 function useDebounce(fn, wait, options) {
2225 const debounced = useMemoOne(
2226 () => debounce(fn, wait ?? 0, options),
2227 [fn, wait, options?.leading, options?.trailing, options?.maxWait]
2228 );
2229 (0, import_element25.useEffect)(() => () => debounced.cancel(), [debounced]);
2230 return debounced;
2231 }
2232
2233 // packages/compose/build-module/hooks/use-debounced-input/index.mjs
2234 var import_element26 = __toESM(require_element(), 1);
2235 function useDebouncedInput(defaultValue = "") {
2236 const [input, setInput] = (0, import_element26.useState)(defaultValue);
2237 const [debouncedInput, setDebouncedState] = (0, import_element26.useState)(defaultValue);
2238 const setDebouncedInput = useDebounce(setDebouncedState, 250);
2239 (0, import_element26.useEffect)(() => {
2240 setDebouncedInput(input);
2241 }, [input, setDebouncedInput]);
2242 return [input, setInput, debouncedInput];
2243 }
2244
2245 // packages/compose/build-module/hooks/use-throttle/index.mjs
2246 var import_element27 = __toESM(require_element(), 1);
2247 function useThrottle(fn, wait, options) {
2248 const throttled = useMemoOne(
2249 () => throttle(fn, wait ?? 0, options),
2250 [fn, wait, options]
2251 );
2252 (0, import_element27.useEffect)(() => () => throttled.cancel(), [throttled]);
2253 return throttled;
2254 }
2255
2256 // packages/compose/build-module/hooks/use-drop-zone/index.mjs
2257 function useDropZone({
2258 dropZoneElement,
2259 isDisabled,
2260 onDrop: _onDrop,
2261 onDragStart: _onDragStart,
2262 onDragEnter: _onDragEnter,
2263 onDragLeave: _onDragLeave,
2264 onDragEnd: _onDragEnd,
2265 onDragOver: _onDragOver
2266 }) {
2267 const onDropEvent = useEvent(_onDrop);
2268 const onDragStartEvent = useEvent(_onDragStart);
2269 const onDragEnterEvent = useEvent(_onDragEnter);
2270 const onDragLeaveEvent = useEvent(_onDragLeave);
2271 const onDragEndEvent = useEvent(_onDragEnd);
2272 const onDragOverEvent = useEvent(_onDragOver);
2273 return useRefEffect(
2274 (elem) => {
2275 if (isDisabled) {
2276 return;
2277 }
2278 const element = dropZoneElement ?? elem;
2279 let isDragging = false;
2280 const { ownerDocument } = element;
2281 function isElementInZone(targetToCheck) {
2282 const { defaultView } = ownerDocument;
2283 if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) {
2284 return false;
2285 }
2286 let elementToCheck = targetToCheck;
2287 do {
2288 if (elementToCheck.dataset.isDropZone) {
2289 return elementToCheck === element;
2290 }
2291 } while (elementToCheck = elementToCheck.parentElement);
2292 return false;
2293 }
2294 function maybeDragStart(event) {
2295 if (isDragging) {
2296 return;
2297 }
2298 isDragging = true;
2299 ownerDocument.addEventListener("dragend", maybeDragEnd);
2300 ownerDocument.addEventListener("mousemove", maybeDragEnd);
2301 if (_onDragStart) {
2302 onDragStartEvent(event);
2303 }
2304 }
2305 function onDragEnter(event) {
2306 event.preventDefault();
2307 if (element.contains(event.relatedTarget)) {
2308 return;
2309 }
2310 if (_onDragEnter) {
2311 onDragEnterEvent(event);
2312 }
2313 }
2314 function onDragOver(event) {
2315 if (!event.defaultPrevented && _onDragOver) {
2316 onDragOverEvent(event);
2317 }
2318 event.preventDefault();
2319 }
2320 function onDragLeave(event) {
2321 if (isElementInZone(event.relatedTarget)) {
2322 return;
2323 }
2324 if (_onDragLeave) {
2325 onDragLeaveEvent(event);
2326 }
2327 }
2328 function onDrop(event) {
2329 if (event.defaultPrevented) {
2330 return;
2331 }
2332 event.preventDefault();
2333 event.dataTransfer && event.dataTransfer.files.length;
2334 if (_onDrop) {
2335 onDropEvent(event);
2336 }
2337 maybeDragEnd(event);
2338 }
2339 function maybeDragEnd(event) {
2340 if (!isDragging) {
2341 return;
2342 }
2343 isDragging = false;
2344 ownerDocument.removeEventListener("dragend", maybeDragEnd);
2345 ownerDocument.removeEventListener("mousemove", maybeDragEnd);
2346 if (_onDragEnd) {
2347 onDragEndEvent(event);
2348 }
2349 }
2350 element.setAttribute("data-is-drop-zone", "true");
2351 element.addEventListener("drop", onDrop);
2352 element.addEventListener("dragenter", onDragEnter);
2353 element.addEventListener("dragover", onDragOver);
2354 element.addEventListener("dragleave", onDragLeave);
2355 ownerDocument.addEventListener("dragenter", maybeDragStart);
2356 return () => {
2357 element.removeAttribute("data-is-drop-zone");
2358 element.removeEventListener("drop", onDrop);
2359 element.removeEventListener("dragenter", onDragEnter);
2360 element.removeEventListener("dragover", onDragOver);
2361 element.removeEventListener("dragleave", onDragLeave);
2362 ownerDocument.removeEventListener("dragend", maybeDragEnd);
2363 ownerDocument.removeEventListener("mousemove", maybeDragEnd);
2364 ownerDocument.removeEventListener(
2365 "dragenter",
2366 maybeDragStart
2367 );
2368 };
2369 },
2370 [isDisabled, dropZoneElement]
2371 // Refresh when the passed in dropZoneElement changes.
2372 );
2373 }
2374
2375 // packages/compose/build-module/hooks/use-focusable-iframe/index.mjs
2376 function useFocusableIframe() {
2377 return useRefEffect((element) => {
2378 const { ownerDocument } = element;
2379 if (!ownerDocument) {
2380 return;
2381 }
2382 const { defaultView } = ownerDocument;
2383 if (!defaultView) {
2384 return;
2385 }
2386 function checkFocus() {
2387 if (ownerDocument && ownerDocument.activeElement === element) {
2388 element.focus();
2389 }
2390 }
2391 defaultView.addEventListener("blur", checkFocus);
2392 return () => {
2393 defaultView.removeEventListener("blur", checkFocus);
2394 };
2395 }, []);
2396 }
2397
2398 // packages/compose/build-module/hooks/use-fixed-window-list/index.mjs
2399 var import_element28 = __toESM(require_element(), 1);
2400 var import_dom3 = __toESM(require_dom(), 1);
2401 var import_keycodes2 = __toESM(require_keycodes(), 1);
2402 var DEFAULT_INIT_WINDOW_SIZE = 30;
2403 function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
2404 const initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;
2405 const useWindowing = options?.useWindowing ?? true;
2406 const [fixedListWindow, setFixedListWindow] = (0, import_element28.useState)(
2407 {
2408 visibleItems: initWindowSize,
2409 start: 0,
2410 end: initWindowSize,
2411 itemInView: (index) => {
2412 return index >= 0 && index <= initWindowSize;
2413 }
2414 }
2415 );
2416 (0, import_element28.useLayoutEffect)(() => {
2417 if (!useWindowing) {
2418 return;
2419 }
2420 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current);
2421 const measureWindow = (initRender) => {
2422 if (!scrollContainer) {
2423 return;
2424 }
2425 const visibleItems = Math.ceil(
2426 scrollContainer.clientHeight / itemHeight
2427 );
2428 const windowOverscan = initRender ? visibleItems : options?.windowOverscan ?? visibleItems;
2429 const firstViewableIndex = Math.floor(
2430 scrollContainer.scrollTop / itemHeight
2431 );
2432 const start = Math.max(0, firstViewableIndex - windowOverscan);
2433 const end = Math.min(
2434 totalItems - 1,
2435 firstViewableIndex + visibleItems + windowOverscan
2436 );
2437 setFixedListWindow((lastWindow) => {
2438 const nextWindow = {
2439 visibleItems,
2440 start,
2441 end,
2442 itemInView: (index) => {
2443 return start <= index && index <= end;
2444 }
2445 };
2446 if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) {
2447 return nextWindow;
2448 }
2449 return lastWindow;
2450 });
2451 };
2452 measureWindow(true);
2453 const debounceMeasureList = debounce(() => {
2454 measureWindow();
2455 }, 16);
2456 scrollContainer?.addEventListener("scroll", debounceMeasureList);
2457 scrollContainer?.ownerDocument?.defaultView?.addEventListener(
2458 "resize",
2459 debounceMeasureList
2460 );
2461 scrollContainer?.ownerDocument?.defaultView?.addEventListener(
2462 "resize",
2463 debounceMeasureList
2464 );
2465 return () => {
2466 scrollContainer?.removeEventListener(
2467 "scroll",
2468 debounceMeasureList
2469 );
2470 scrollContainer?.ownerDocument?.defaultView?.removeEventListener(
2471 "resize",
2472 debounceMeasureList
2473 );
2474 };
2475 }, [
2476 itemHeight,
2477 elementRef,
2478 totalItems,
2479 options?.expandedState,
2480 options?.windowOverscan,
2481 useWindowing
2482 ]);
2483 (0, import_element28.useLayoutEffect)(() => {
2484 if (!useWindowing) {
2485 return;
2486 }
2487 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current);
2488 const handleKeyDown = (event) => {
2489 switch (event.keyCode) {
2490 case import_keycodes2.HOME: {
2491 return scrollContainer?.scrollTo({ top: 0 });
2492 }
2493 case import_keycodes2.END: {
2494 return scrollContainer?.scrollTo({
2495 top: totalItems * itemHeight
2496 });
2497 }
2498 case import_keycodes2.PAGEUP: {
2499 return scrollContainer?.scrollTo({
2500 top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight
2501 });
2502 }
2503 case import_keycodes2.PAGEDOWN: {
2504 return scrollContainer?.scrollTo({
2505 top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight
2506 });
2507 }
2508 }
2509 };
2510 scrollContainer?.ownerDocument?.defaultView?.addEventListener(
2511 "keydown",
2512 handleKeyDown
2513 );
2514 return () => {
2515 scrollContainer?.ownerDocument?.defaultView?.removeEventListener(
2516 "keydown",
2517 handleKeyDown
2518 );
2519 };
2520 }, [
2521 totalItems,
2522 itemHeight,
2523 elementRef,
2524 fixedListWindow.visibleItems,
2525 useWindowing,
2526 options?.expandedState
2527 ]);
2528 return [fixedListWindow, setFixedListWindow];
2529 }
2530
2531 // packages/compose/build-module/hooks/use-observable-value/index.mjs
2532 var import_element29 = __toESM(require_element(), 1);
2533 function useObservableValue(map, name) {
2534 const [subscribe, getValue] = (0, import_element29.useMemo)(
2535 () => [
2536 (listener2) => map.subscribe(name, listener2),
2537 () => map.get(name)
2538 ],
2539 [map, name]
2540 );
2541 return (0, import_element29.useSyncExternalStore)(subscribe, getValue, getValue);
2542 }
2543 return __toCommonJS(index_exports);
2544 })();
2545 //# sourceMappingURL=index.js.map
2546