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

2,539 lines 83.5 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_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
977 var pure = createHigherOrderComponent(function(WrappedComponent) {
978 if (WrappedComponent.prototype instanceof import_element.Component) {
979 return class extends WrappedComponent {
980 shouldComponentUpdate(nextProps, nextState) {
981 return !(0, import_is_shallow_equal.isShallowEqual)(nextProps, this.props) || !(0, import_is_shallow_equal.isShallowEqual)(nextState, this.state);
982 }
983 };
984 }
985 return class extends import_element.Component {
986 shouldComponentUpdate(nextProps) {
987 return !(0, import_is_shallow_equal.isShallowEqual)(nextProps, this.props);
988 }
989 render() {
990 return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WrappedComponent, { ...this.props });
991 }
992 };
993 }, "pure");
994 var pure_default = pure;
995
996 // packages/compose/build-module/higher-order/with-global-events/index.mjs
997 var import_element2 = __toESM(require_element(), 1);
998 var import_deprecated = __toESM(require_deprecated(), 1);
999
1000 // packages/compose/build-module/higher-order/with-global-events/listener.mjs
1001 var Listener = class {
1002 constructor() {
1003 this.listeners = {};
1004 this.handleEvent = this.handleEvent.bind(this);
1005 }
1006 add(eventType, instance) {
1007 if (!this.listeners[eventType]) {
1008 window.addEventListener(eventType, this.handleEvent);
1009 this.listeners[eventType] = [];
1010 }
1011 this.listeners[eventType].push(instance);
1012 }
1013 remove(eventType, instance) {
1014 if (!this.listeners[eventType]) {
1015 return;
1016 }
1017 this.listeners[eventType] = this.listeners[eventType].filter(
1018 (listener2) => listener2 !== instance
1019 );
1020 if (!this.listeners[eventType].length) {
1021 window.removeEventListener(eventType, this.handleEvent);
1022 delete this.listeners[eventType];
1023 }
1024 }
1025 handleEvent(event) {
1026 this.listeners[event.type]?.forEach(
1027 (instance) => {
1028 instance.handleEvent(event);
1029 }
1030 );
1031 }
1032 };
1033 var listener_default = Listener;
1034
1035 // packages/compose/build-module/higher-order/with-global-events/index.mjs
1036 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1037 var listener = new listener_default();
1038 function withGlobalEvents(eventTypesToHandlers) {
1039 (0, import_deprecated.default)("wp.compose.withGlobalEvents", {
1040 since: "5.7",
1041 alternative: "useEffect"
1042 });
1043 return createHigherOrderComponent((WrappedComponent) => {
1044 class Wrapper extends import_element2.Component {
1045 constructor(props) {
1046 super(props);
1047 this.handleEvent = this.handleEvent.bind(this);
1048 this.handleRef = this.handleRef.bind(this);
1049 }
1050 componentDidMount() {
1051 Object.keys(eventTypesToHandlers).forEach((eventType) => {
1052 listener.add(eventType, this);
1053 });
1054 }
1055 componentWillUnmount() {
1056 Object.keys(eventTypesToHandlers).forEach((eventType) => {
1057 listener.remove(eventType, this);
1058 });
1059 }
1060 handleEvent(event) {
1061 const handler = eventTypesToHandlers[
1062 /** @type {keyof GlobalEventHandlersEventMap} */
1063 event.type
1064 ];
1065 if (typeof this.wrappedRef[handler] === "function") {
1066 this.wrappedRef[handler](event);
1067 }
1068 }
1069 handleRef(el) {
1070 this.wrappedRef = el;
1071 if (this.props.forwardedRef) {
1072 this.props.forwardedRef(el);
1073 }
1074 }
1075 render() {
1076 return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1077 WrappedComponent,
1078 {
1079 ...this.props.ownProps,
1080 ref: this.handleRef
1081 }
1082 );
1083 }
1084 }
1085 return (0, import_element2.forwardRef)((props, ref) => {
1086 return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Wrapper, { ownProps: props, forwardedRef: ref });
1087 });
1088 }, "withGlobalEvents");
1089 }
1090
1091 // packages/compose/build-module/hooks/use-instance-id/index.mjs
1092 var import_element3 = __toESM(require_element(), 1);
1093 var instanceMap = /* @__PURE__ */ new WeakMap();
1094 function createId(object) {
1095 const instances = instanceMap.get(object) || 0;
1096 instanceMap.set(object, instances + 1);
1097 return instances;
1098 }
1099 function useInstanceId(object, prefix, preferredId) {
1100 return (0, import_element3.useMemo)(() => {
1101 if (preferredId) {
1102 return preferredId;
1103 }
1104 const id = createId(object);
1105 return prefix ? `${prefix}-${id}` : id;
1106 }, [object, preferredId, prefix]);
1107 }
1108 var use_instance_id_default = useInstanceId;
1109
1110 // packages/compose/build-module/higher-order/with-instance-id/index.mjs
1111 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1112 var withInstanceId = createHigherOrderComponent(
1113 (WrappedComponent) => {
1114 return (props) => {
1115 const instanceId = use_instance_id_default(WrappedComponent);
1116 return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(WrappedComponent, { ...props, instanceId });
1117 };
1118 },
1119 "instanceId"
1120 );
1121 var with_instance_id_default = withInstanceId;
1122
1123 // packages/compose/build-module/higher-order/with-safe-timeout/index.mjs
1124 var import_element4 = __toESM(require_element(), 1);
1125 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1126 var withSafeTimeout = createHigherOrderComponent(
1127 (OriginalComponent) => {
1128 return class WrappedComponent extends import_element4.Component {
1129 timeouts;
1130 constructor(props) {
1131 super(props);
1132 this.timeouts = [];
1133 this.setTimeout = this.setTimeout.bind(this);
1134 this.clearTimeout = this.clearTimeout.bind(this);
1135 }
1136 componentWillUnmount() {
1137 this.timeouts.forEach(clearTimeout);
1138 }
1139 setTimeout(fn, delay) {
1140 const id = setTimeout(() => {
1141 fn();
1142 this.clearTimeout(id);
1143 }, delay);
1144 this.timeouts.push(id);
1145 return id;
1146 }
1147 clearTimeout(id) {
1148 clearTimeout(id);
1149 this.timeouts = this.timeouts.filter(
1150 (timeoutId) => timeoutId !== id
1151 );
1152 }
1153 render() {
1154 return (
1155 // @ts-ignore
1156 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1157 OriginalComponent,
1158 {
1159 ...this.props,
1160 setTimeout: this.setTimeout,
1161 clearTimeout: this.clearTimeout
1162 }
1163 )
1164 );
1165 }
1166 };
1167 },
1168 "withSafeTimeout"
1169 );
1170 var with_safe_timeout_default = withSafeTimeout;
1171
1172 // packages/compose/build-module/higher-order/with-state/index.mjs
1173 var import_element5 = __toESM(require_element(), 1);
1174 var import_deprecated2 = __toESM(require_deprecated(), 1);
1175 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1176 function withState(initialState = {}) {
1177 (0, import_deprecated2.default)("wp.compose.withState", {
1178 since: "5.8",
1179 alternative: "wp.element.useState"
1180 });
1181 return createHigherOrderComponent((OriginalComponent) => {
1182 return class WrappedComponent extends import_element5.Component {
1183 constructor(props) {
1184 super(props);
1185 this.setState = this.setState.bind(this);
1186 this.state = initialState;
1187 }
1188 render() {
1189 return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1190 OriginalComponent,
1191 {
1192 ...this.props,
1193 ...this.state,
1194 setState: this.setState
1195 }
1196 );
1197 }
1198 };
1199 }, "withState");
1200 }
1201
1202 // packages/compose/build-module/hooks/use-constrained-tabbing/index.mjs
1203 var import_dom = __toESM(require_dom(), 1);
1204
1205 // packages/compose/build-module/hooks/use-ref-effect/index.mjs
1206 var import_element6 = __toESM(require_element(), 1);
1207 function useRefEffect(callback, dependencies) {
1208 const cleanupRef = (0, import_element6.useRef)(void 0);
1209 return (0, import_element6.useCallback)((node) => {
1210 if (node) {
1211 cleanupRef.current = callback(node);
1212 } else if (cleanupRef.current) {
1213 cleanupRef.current();
1214 }
1215 }, dependencies);
1216 }
1217
1218 // packages/compose/build-module/hooks/use-constrained-tabbing/index.mjs
1219 function useConstrainedTabbing() {
1220 return useRefEffect((node) => {
1221 function onKeyDown(event) {
1222 const { key, shiftKey, target } = event;
1223 if (key !== "Tab") {
1224 return;
1225 }
1226 const action = shiftKey ? "findPrevious" : "findNext";
1227 const nextElement = import_dom.focus.tabbable[action](
1228 /** @type {HTMLElement} */
1229 target
1230 ) || null;
1231 if (
1232 /** @type {HTMLElement} */
1233 target.contains(nextElement)
1234 ) {
1235 event.preventDefault();
1236 nextElement?.focus();
1237 return;
1238 }
1239 if (node.contains(nextElement)) {
1240 return;
1241 }
1242 const domAction = shiftKey ? "append" : "prepend";
1243 const { ownerDocument } = node;
1244 const trap = ownerDocument.createElement("div");
1245 trap.tabIndex = -1;
1246 node[domAction](trap);
1247 trap.addEventListener("blur", () => node.removeChild(trap));
1248 trap.focus();
1249 }
1250 node.addEventListener("keydown", onKeyDown);
1251 return () => {
1252 node.removeEventListener("keydown", onKeyDown);
1253 };
1254 }, []);
1255 }
1256 var use_constrained_tabbing_default = useConstrainedTabbing;
1257
1258 // packages/compose/build-module/hooks/use-copy-on-click/index.mjs
1259 var import_element8 = __toESM(require_element(), 1);
1260 var import_deprecated3 = __toESM(require_deprecated(), 1);
1261
1262 // packages/compose/build-module/hooks/use-copy-to-clipboard/index.mjs
1263 var import_element7 = __toESM(require_element(), 1);
1264 async function copyToClipboard(text, trigger) {
1265 if (!trigger) {
1266 return false;
1267 }
1268 const { ownerDocument } = trigger;
1269 if (!ownerDocument) {
1270 return false;
1271 }
1272 const { defaultView } = ownerDocument;
1273 try {
1274 if (defaultView?.navigator?.clipboard?.writeText) {
1275 await defaultView.navigator.clipboard.writeText(text);
1276 return true;
1277 }
1278 const textarea = ownerDocument.createElement("textarea");
1279 textarea.value = text;
1280 textarea.setAttribute("readonly", "");
1281 textarea.style.position = "fixed";
1282 textarea.style.left = "-9999px";
1283 textarea.style.top = "-9999px";
1284 ownerDocument.body.appendChild(textarea);
1285 textarea.select();
1286 const success = ownerDocument.execCommand("copy");
1287 textarea.remove();
1288 return success;
1289 } catch {
1290 return false;
1291 }
1292 }
1293 function restoreFocus(trigger) {
1294 if ("focus" in trigger && typeof trigger.focus === "function") {
1295 trigger.focus();
1296 }
1297 }
1298 function useUpdatedRef(value) {
1299 const ref = (0, import_element7.useRef)(value);
1300 (0, import_element7.useLayoutEffect)(() => {
1301 ref.current = value;
1302 }, [value]);
1303 return ref;
1304 }
1305 function useCopyToClipboard(text, onSuccess) {
1306 const textRef = useUpdatedRef(text);
1307 const onSuccessRef = useUpdatedRef(onSuccess);
1308 return useRefEffect((node) => {
1309 let isActive = true;
1310 const handleClick = async () => {
1311 const textToCopy = typeof textRef.current === "function" ? textRef.current() : textRef.current || "";
1312 const success = await copyToClipboard(textToCopy, node);
1313 if (success) {
1314 if (isActive) {
1315 restoreFocus(node);
1316 }
1317 if (onSuccessRef.current) {
1318 onSuccessRef.current();
1319 }
1320 }
1321 };
1322 node.addEventListener("click", handleClick);
1323 return () => {
1324 isActive = false;
1325 node.removeEventListener("click", handleClick);
1326 };
1327 }, []);
1328 }
1329
1330 // packages/compose/build-module/hooks/use-copy-on-click/index.mjs
1331 function useCopyOnClick(ref, text, timeout = 4e3) {
1332 (0, import_deprecated3.default)("wp.compose.useCopyOnClick", {
1333 since: "5.8",
1334 alternative: "wp.compose.useCopyToClipboard"
1335 });
1336 const [hasCopied, setHasCopied] = (0, import_element8.useState)(false);
1337 (0, import_element8.useEffect)(() => {
1338 let isActive = true;
1339 let timeoutId;
1340 if (!ref.current) {
1341 return;
1342 }
1343 let targets;
1344 if (typeof ref.current === "string") {
1345 targets = typeof document !== "undefined" ? Array.from(document.querySelectorAll(ref.current)) : [];
1346 } else if ("length" in ref.current && typeof ref.current.length === "number") {
1347 targets = Array.from(ref.current);
1348 } else {
1349 targets = [ref.current];
1350 }
1351 if (targets.length === 0) {
1352 return;
1353 }
1354 const handleClick = async (event) => {
1355 const trigger = event.currentTarget;
1356 if (!trigger) {
1357 return;
1358 }
1359 const success = await copyToClipboard(
1360 typeof text === "function" ? text() : text || "",
1361 trigger
1362 );
1363 if (!isActive) {
1364 return;
1365 }
1366 if (success) {
1367 restoreFocus(trigger);
1368 if (timeout) {
1369 setHasCopied(true);
1370 clearTimeout(timeoutId);
1371 timeoutId = setTimeout(
1372 () => setHasCopied(false),
1373 timeout
1374 );
1375 }
1376 }
1377 };
1378 for (const target of targets) {
1379 target.addEventListener("click", handleClick);
1380 }
1381 return () => {
1382 isActive = false;
1383 for (const target of targets) {
1384 target.removeEventListener("click", handleClick);
1385 }
1386 clearTimeout(timeoutId);
1387 };
1388 }, [ref, text, timeout]);
1389 return hasCopied;
1390 }
1391
1392 // packages/compose/build-module/hooks/use-dialog/index.mjs
1393 var import_element13 = __toESM(require_element(), 1);
1394
1395 // packages/compose/build-module/hooks/use-focus-on-mount/index.mjs
1396 var import_dom2 = __toESM(require_dom(), 1);
1397 var import_element9 = __toESM(require_element(), 1);
1398 function useFocusOnMount(focusOnMount = "firstElement") {
1399 const focusOnMountRef = (0, import_element9.useRef)(focusOnMount);
1400 const setFocus = (target) => {
1401 target.focus({
1402 // When focusing newly mounted dialogs,
1403 // the position of the popover is often not right on the first render
1404 // This prevents the layout shifts when focusing the dialogs.
1405 preventScroll: true
1406 });
1407 };
1408 (0, import_element9.useEffect)(() => {
1409 focusOnMountRef.current = focusOnMount;
1410 }, [focusOnMount]);
1411 return useRefEffect((node) => {
1412 if (focusOnMountRef.current === false) {
1413 return;
1414 }
1415 if (node.contains(node.ownerDocument?.activeElement ?? null)) {
1416 return;
1417 }
1418 if (focusOnMountRef.current !== "firstElement" && focusOnMountRef.current !== "firstInputElement") {
1419 setFocus(node);
1420 return;
1421 }
1422 const timerId = setTimeout(() => {
1423 if (focusOnMountRef.current === "firstInputElement") {
1424 const formInput = node.querySelector(
1425 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
1426 );
1427 if (formInput) {
1428 setFocus(formInput);
1429 return;
1430 }
1431 }
1432 const firstTabbable = import_dom2.focus.tabbable.find(node)[0];
1433 if (firstTabbable) {
1434 setFocus(firstTabbable);
1435 }
1436 }, 0);
1437 return () => {
1438 clearTimeout(timerId);
1439 };
1440 }, []);
1441 }
1442
1443 // packages/compose/build-module/hooks/use-focus-return/index.mjs
1444 var import_element10 = __toESM(require_element(), 1);
1445 var origin = null;
1446 function useFocusReturn(onFocusReturn) {
1447 const ref = (0, import_element10.useRef)(null);
1448 const focusedBeforeMount = (0, import_element10.useRef)(null);
1449 const onFocusReturnRef = (0, import_element10.useRef)(onFocusReturn);
1450 (0, import_element10.useEffect)(() => {
1451 onFocusReturnRef.current = onFocusReturn;
1452 }, [onFocusReturn]);
1453 return (0, import_element10.useCallback)((node) => {
1454 if (node) {
1455 ref.current = node;
1456 if (focusedBeforeMount.current) {
1457 return;
1458 }
1459 const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument;
1460 focusedBeforeMount.current = activeDocument?.activeElement ?? null;
1461 } else if (focusedBeforeMount.current) {
1462 const isFocused = ref.current?.contains(
1463 ref.current?.ownerDocument.activeElement
1464 );
1465 if (ref.current?.isConnected && !isFocused) {
1466 origin ??= focusedBeforeMount.current;
1467 return;
1468 }
1469 if (onFocusReturnRef.current) {
1470 onFocusReturnRef.current();
1471 } else {
1472 (!focusedBeforeMount.current.isConnected ? origin : focusedBeforeMount.current)?.focus();
1473 }
1474 origin = null;
1475 }
1476 }, []);
1477 }
1478 var use_focus_return_default = useFocusReturn;
1479
1480 // packages/compose/build-module/hooks/use-focus-outside/index.mjs
1481 var import_element11 = __toESM(require_element(), 1);
1482 var INPUT_BUTTON_TYPES = ["button", "submit"];
1483 function isFocusNormalizedButton(eventTarget) {
1484 if (!(eventTarget instanceof window.HTMLElement)) {
1485 return false;
1486 }
1487 switch (eventTarget.nodeName) {
1488 case "A":
1489 case "BUTTON":
1490 return true;
1491 case "INPUT":
1492 return INPUT_BUTTON_TYPES.includes(
1493 eventTarget.type
1494 );
1495 }
1496 return false;
1497 }
1498 function useFocusOutside(onFocusOutside) {
1499 const currentOnFocusOutsideRef = (0, import_element11.useRef)(onFocusOutside);
1500 (0, import_element11.useEffect)(() => {
1501 currentOnFocusOutsideRef.current = onFocusOutside;
1502 }, [onFocusOutside]);
1503 const preventBlurCheckRef = (0, import_element11.useRef)(false);
1504 const blurCheckTimeoutIdRef = (0, import_element11.useRef)(void 0);
1505 const cancelBlurCheck = (0, import_element11.useCallback)(() => {
1506 clearTimeout(blurCheckTimeoutIdRef.current);
1507 }, []);
1508 (0, import_element11.useEffect)(() => {
1509 if (!onFocusOutside) {
1510 cancelBlurCheck();
1511 }
1512 }, [onFocusOutside, cancelBlurCheck]);
1513 const normalizeButtonFocus = (0, import_element11.useCallback)((event) => {
1514 const { type, target } = event;
1515 const isInteractionEnd = ["mouseup", "touchend"].includes(type);
1516 if (isInteractionEnd) {
1517 preventBlurCheckRef.current = false;
1518 } else if (isFocusNormalizedButton(target)) {
1519 preventBlurCheckRef.current = true;
1520 }
1521 }, []);
1522 const queueBlurCheck = (0, import_element11.useCallback)((event) => {
1523 event.persist();
1524 if (preventBlurCheckRef.current) {
1525 return;
1526 }
1527 const ignoreForRelatedTarget = event.target.getAttribute(
1528 "data-unstable-ignore-focus-outside-for-relatedtarget"
1529 );
1530 if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) {
1531 return;
1532 }
1533 blurCheckTimeoutIdRef.current = setTimeout(() => {
1534 if (!document.hasFocus()) {
1535 event.preventDefault();
1536 return;
1537 }
1538 if ("function" === typeof currentOnFocusOutsideRef.current) {
1539 currentOnFocusOutsideRef.current(event);
1540 }
1541 }, 0);
1542 }, []);
1543 return {
1544 onFocus: cancelBlurCheck,
1545 onMouseDown: normalizeButtonFocus,
1546 onMouseUp: normalizeButtonFocus,
1547 onTouchStart: normalizeButtonFocus,
1548 onTouchEnd: normalizeButtonFocus,
1549 onBlur: queueBlurCheck
1550 };
1551 }
1552
1553 // packages/compose/build-module/hooks/use-merge-refs/index.mjs
1554 var import_element12 = __toESM(require_element(), 1);
1555 function assignRef(ref, value) {
1556 if (typeof ref === "function") {
1557 ref(value);
1558 } else if (ref && ref.hasOwnProperty("current")) {
1559 ref.current = value;
1560 }
1561 }
1562 function useMergeRefs(refs) {
1563 const element = (0, import_element12.useRef)(null);
1564 const isAttachedRef = (0, import_element12.useRef)(false);
1565 const didElementChangeRef = (0, import_element12.useRef)(false);
1566 const previousRefsRef = (0, import_element12.useRef)([]);
1567 const currentRefsRef = (0, import_element12.useRef)(refs);
1568 currentRefsRef.current = refs;
1569 (0, import_element12.useLayoutEffect)(() => {
1570 if (didElementChangeRef.current === false && isAttachedRef.current === true) {
1571 refs.forEach((ref, index) => {
1572 const previousRef = previousRefsRef.current[index];
1573 if (ref !== previousRef) {
1574 assignRef(previousRef, null);
1575 assignRef(ref, element.current);
1576 }
1577 });
1578 }
1579 previousRefsRef.current = refs;
1580 }, refs);
1581 (0, import_element12.useLayoutEffect)(() => {
1582 didElementChangeRef.current = false;
1583 });
1584 return (0, import_element12.useCallback)((value) => {
1585 assignRef(element, value);
1586 didElementChangeRef.current = true;
1587 isAttachedRef.current = value !== null;
1588 const refsToAssign = value ? currentRefsRef.current : previousRefsRef.current;
1589 for (const ref of refsToAssign) {
1590 assignRef(ref, value);
1591 }
1592 }, []);
1593 }
1594
1595 // packages/compose/build-module/hooks/use-dialog/index.mjs
1596 function useDialog(options) {
1597 const currentOptions = (0, import_element13.useRef)(void 0);
1598 const { constrainTabbing = options.focusOnMount !== false } = options;
1599 (0, import_element13.useEffect)(() => {
1600 currentOptions.current = options;
1601 }, Object.values(options));
1602 const constrainedTabbingRef = use_constrained_tabbing_default();
1603 const focusOnMountRef = useFocusOnMount(options.focusOnMount);
1604 const focusReturnRef = use_focus_return_default();
1605 const focusOutsideProps = useFocusOutside((event) => {
1606 if (currentOptions.current?.__unstableOnClose) {
1607 currentOptions.current.__unstableOnClose("focus-outside", event);
1608 } else if (currentOptions.current?.onClose) {
1609 currentOptions.current.onClose();
1610 }
1611 });
1612 const onKeyDown = (0, import_element13.useCallback)((event) => {
1613 currentOptions.current?.onKeyDown?.(event);
1614 if (event.key === "Escape" && !event.defaultPrevented && currentOptions.current?.onClose) {
1615 event.preventDefault();
1616 event.stopPropagation();
1617 currentOptions.current.onClose();
1618 }
1619 }, []);
1620 return [
1621 useMergeRefs([
1622 constrainTabbing ? constrainedTabbingRef : null,
1623 options.focusOnMount !== false ? focusReturnRef : null,
1624 options.focusOnMount !== false ? focusOnMountRef : null
1625 ]),
1626 {
1627 ...focusOutsideProps,
1628 onKeyDown,
1629 tabIndex: -1
1630 }
1631 ];
1632 }
1633 var use_dialog_default = useDialog;
1634
1635 // packages/compose/build-module/hooks/use-disabled/index.mjs
1636 function useDisabled({
1637 isDisabled: isDisabledProp = false
1638 } = {}) {
1639 return useRefEffect(
1640 (node) => {
1641 if (isDisabledProp) {
1642 return;
1643 }
1644 const defaultView = node?.ownerDocument?.defaultView;
1645 if (!defaultView) {
1646 return;
1647 }
1648 const updates = [];
1649 const disable = () => {
1650 node.childNodes.forEach((child) => {
1651 if (!(child instanceof defaultView.HTMLElement)) {
1652 return;
1653 }
1654 if (!child.hasAttribute("inert")) {
1655 child.setAttribute("inert", "");
1656 updates.push(() => {
1657 child.removeAttribute("inert");
1658 });
1659 }
1660 });
1661 };
1662 const debouncedDisable = debounce(disable, 0, {
1663 leading: true
1664 });
1665 disable();
1666 const observer = new window.MutationObserver(debouncedDisable);
1667 observer.observe(node, {
1668 childList: true
1669 });
1670 return () => {
1671 if (observer) {
1672 observer.disconnect();
1673 }
1674 debouncedDisable.cancel();
1675 updates.forEach((update) => update());
1676 };
1677 },
1678 [isDisabledProp]
1679 );
1680 }
1681
1682 // packages/compose/build-module/hooks/use-event/index.mjs
1683 var import_element14 = __toESM(require_element(), 1);
1684 function useEvent(callback) {
1685 const ref = (0, import_element14.useRef)(() => {
1686 throw new Error(
1687 "Callbacks created with `useEvent` cannot be called during rendering."
1688 );
1689 });
1690 (0, import_element14.useInsertionEffect)(() => {
1691 ref.current = callback;
1692 });
1693 return (0, import_element14.useCallback)(
1694 (...args) => ref.current?.(...args),
1695 []
1696 );
1697 }
1698
1699 // packages/compose/build-module/hooks/use-dragging/index.mjs
1700 var import_element16 = __toESM(require_element(), 1);
1701
1702 // packages/compose/build-module/hooks/use-isomorphic-layout-effect/index.mjs
1703 var import_element15 = __toESM(require_element(), 1);
1704 var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_element15.useLayoutEffect : import_element15.useEffect;
1705 var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
1706
1707 // packages/compose/build-module/hooks/use-dragging/index.mjs
1708 function useDragging({ onDragStart, onDragMove, onDragEnd }) {
1709 const [isDragging, setIsDragging] = (0, import_element16.useState)(false);
1710 const eventsRef = (0, import_element16.useRef)({
1711 onDragStart,
1712 onDragMove,
1713 onDragEnd
1714 });
1715 use_isomorphic_layout_effect_default(() => {
1716 eventsRef.current.onDragStart = onDragStart;
1717 eventsRef.current.onDragMove = onDragMove;
1718 eventsRef.current.onDragEnd = onDragEnd;
1719 }, [onDragStart, onDragMove, onDragEnd]);
1720 const onMouseMove = (0, import_element16.useCallback)(
1721 (event) => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event),
1722 []
1723 );
1724 const endDrag = (0, import_element16.useCallback)((event) => {
1725 if (eventsRef.current.onDragEnd) {
1726 eventsRef.current.onDragEnd(event);
1727 }
1728 document.removeEventListener("mousemove", onMouseMove);
1729 document.removeEventListener("mouseup", endDrag);
1730 setIsDragging(false);
1731 }, []);
1732 const startDrag = (0, import_element16.useCallback)((event) => {
1733 if (eventsRef.current.onDragStart) {
1734 eventsRef.current.onDragStart(event);
1735 }
1736 document.addEventListener("mousemove", onMouseMove);
1737 document.addEventListener("mouseup", endDrag);
1738 setIsDragging(true);
1739 }, []);
1740 (0, import_element16.useEffect)(() => {
1741 return () => {
1742 if (isDragging) {
1743 document.removeEventListener("mousemove", onMouseMove);
1744 document.removeEventListener("mouseup", endDrag);
1745 }
1746 };
1747 }, [isDragging]);
1748 return {
1749 startDrag,
1750 endDrag,
1751 isDragging
1752 };
1753 }
1754
1755 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs
1756 var import_mousetrap = __toESM(require_mousetrap(), 1);
1757
1758 // node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
1759 (function(Mousetrap3) {
1760 if (!Mousetrap3) {
1761 return;
1762 }
1763 var _globalCallbacks = {};
1764 var _originalStopCallback = Mousetrap3.prototype.stopCallback;
1765 Mousetrap3.prototype.stopCallback = function(e, element, combo, sequence) {
1766 var self = this;
1767 if (self.paused) {
1768 return true;
1769 }
1770 if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
1771 return false;
1772 }
1773 return _originalStopCallback.call(self, e, element, combo);
1774 };
1775 Mousetrap3.prototype.bindGlobal = function(keys, callback, action) {
1776 var self = this;
1777 self.bind(keys, callback, action);
1778 if (keys instanceof Array) {
1779 for (var i = 0; i < keys.length; i++) {
1780 _globalCallbacks[keys[i]] = true;
1781 }
1782 return;
1783 }
1784 _globalCallbacks[keys] = true;
1785 };
1786 Mousetrap3.init();
1787 })(typeof Mousetrap !== "undefined" ? Mousetrap : void 0);
1788
1789 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs
1790 var import_element17 = __toESM(require_element(), 1);
1791 var import_keycodes = __toESM(require_keycodes(), 1);
1792 function useKeyboardShortcut(shortcuts, callback, {
1793 bindGlobal = false,
1794 eventName = "keydown",
1795 isDisabled = false,
1796 // This is important for performance considerations.
1797 target
1798 } = {}) {
1799 const currentCallbackRef = (0, import_element17.useRef)(callback);
1800 (0, import_element17.useEffect)(() => {
1801 currentCallbackRef.current = callback;
1802 }, [callback]);
1803 (0, import_element17.useEffect)(() => {
1804 if (isDisabled) {
1805 return;
1806 }
1807 const mousetrap = new import_mousetrap.default(
1808 target && target.current ? target.current : (
1809 // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
1810 // 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
1811 // necessary to maintain the existing behavior.
1812 /** @type {Element} */
1813 /** @type {unknown} */
1814 document
1815 )
1816 );
1817 const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
1818 shortcutsArray.forEach((shortcut) => {
1819 const keys = shortcut.split("+");
1820 const modifiers = new Set(
1821 keys.filter((value) => value.length > 1)
1822 );
1823 const hasAlt = modifiers.has("alt");
1824 const hasShift = modifiers.has("shift");
1825 if ((0, import_keycodes.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
1826 throw new Error(
1827 `Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`
1828 );
1829 }
1830 const bindFn = bindGlobal ? "bindGlobal" : "bind";
1831 mousetrap[bindFn](
1832 shortcut,
1833 (...args) => currentCallbackRef.current(...args),
1834 eventName
1835 );
1836 });
1837 return () => {
1838 mousetrap.reset();
1839 };
1840 }, [shortcuts, bindGlobal, eventName, target, isDisabled]);
1841 }
1842 var use_keyboard_shortcut_default = useKeyboardShortcut;
1843
1844 // packages/compose/build-module/hooks/use-media-query/index.mjs
1845 var import_element18 = __toESM(require_element(), 1);
1846 var perWindowCache = /* @__PURE__ */ new WeakMap();
1847 var EMPTY_SUBSCRIBER = {
1848 subscribe: () => () => {
1849 },
1850 getValue: () => false
1851 };
1852 function getMQLSubscriber(view, query) {
1853 if (!query || typeof view?.matchMedia !== "function") {
1854 return EMPTY_SUBSCRIBER;
1855 }
1856 let queryCache = perWindowCache.get(view);
1857 if (!queryCache) {
1858 queryCache = /* @__PURE__ */ new Map();
1859 perWindowCache.set(view, queryCache);
1860 }
1861 const cached = queryCache.get(query);
1862 if (cached) {
1863 return cached;
1864 }
1865 const mediaQueryList = view.matchMedia(query);
1866 const listeners = /* @__PURE__ */ new Set();
1867 const notify = () => {
1868 for (const listener2 of listeners) {
1869 listener2();
1870 }
1871 };
1872 const subscriber = {
1873 subscribe(onStoreChange) {
1874 if (listeners.size === 0) {
1875 mediaQueryList.addEventListener?.("change", notify);
1876 }
1877 listeners.add(onStoreChange);
1878 return () => {
1879 listeners.delete(onStoreChange);
1880 if (listeners.size === 0) {
1881 mediaQueryList.removeEventListener?.("change", notify);
1882 }
1883 };
1884 },
1885 getValue() {
1886 return mediaQueryList.matches;
1887 }
1888 };
1889 queryCache.set(query, subscriber);
1890 return subscriber;
1891 }
1892 function useMediaQuery(query, view = window) {
1893 const source = getMQLSubscriber(view, query);
1894 return (0, import_element18.useSyncExternalStore)(
1895 source.subscribe,
1896 source.getValue,
1897 () => false
1898 );
1899 }
1900
1901 // packages/compose/build-module/hooks/use-previous/index.mjs
1902 var import_element19 = __toESM(require_element(), 1);
1903 function usePrevious(value) {
1904 const ref = (0, import_element19.useRef)(void 0);
1905 (0, import_element19.useEffect)(() => {
1906 ref.current = value;
1907 }, [value]);
1908 return ref.current;
1909 }
1910
1911 // packages/compose/build-module/hooks/use-reduced-motion/index.mjs
1912 var useReducedMotion = () => useMediaQuery("(prefers-reduced-motion: reduce)");
1913 var use_reduced_motion_default = useReducedMotion;
1914
1915 // packages/compose/build-module/hooks/use-state-with-history/index.mjs
1916 var import_undo_manager = __toESM(require_undo_manager(), 1);
1917 var import_element20 = __toESM(require_element(), 1);
1918 function undoRedoReducer(state, action) {
1919 switch (action.type) {
1920 case "UNDO": {
1921 const undoRecord = state.manager.undo();
1922 if (undoRecord) {
1923 return {
1924 ...state,
1925 value: undoRecord[0].changes.prop.from
1926 };
1927 }
1928 return state;
1929 }
1930 case "REDO": {
1931 const redoRecord = state.manager.redo();
1932 if (redoRecord) {
1933 return {
1934 ...state,
1935 value: redoRecord[0].changes.prop.to
1936 };
1937 }
1938 return state;
1939 }
1940 case "RECORD": {
1941 state.manager.addRecord(
1942 [
1943 {
1944 id: "object",
1945 changes: {
1946 prop: { from: state.value, to: action.value }
1947 }
1948 }
1949 ],
1950 action.isStaged
1951 );
1952 return {
1953 ...state,
1954 value: action.value
1955 };
1956 }
1957 }
1958 return state;
1959 }
1960 function initReducer(value) {
1961 return {
1962 manager: (0, import_undo_manager.createUndoManager)(),
1963 value
1964 };
1965 }
1966 function useStateWithHistory(initialValue) {
1967 const [state, dispatch] = (0, import_element20.useReducer)(
1968 undoRedoReducer,
1969 initialValue,
1970 initReducer
1971 );
1972 return {
1973 value: state.value,
1974 setValue: (0, import_element20.useCallback)((newValue, isStaged) => {
1975 dispatch({
1976 type: "RECORD",
1977 value: newValue,
1978 isStaged
1979 });
1980 }, []),
1981 hasUndo: state.manager.hasUndo(),
1982 hasRedo: state.manager.hasRedo(),
1983 undo: (0, import_element20.useCallback)(() => {
1984 dispatch({ type: "UNDO" });
1985 }, []),
1986 redo: (0, import_element20.useCallback)(() => {
1987 dispatch({ type: "REDO" });
1988 }, [])
1989 };
1990 }
1991
1992 // packages/compose/build-module/hooks/use-viewport-match/index.mjs
1993 var import_element21 = __toESM(require_element(), 1);
1994 var BREAKPOINTS = {
1995 xhuge: 1920,
1996 huge: 1440,
1997 wide: 1280,
1998 xlarge: 1080,
1999 large: 960,
2000 medium: 782,
2001 small: 600,
2002 mobile: 480
2003 };
2004 var CONDITIONS = {
2005 ">=": "min-width",
2006 "<": "max-width"
2007 };
2008 var OPERATOR_EVALUATORS = {
2009 ">=": (breakpointValue, width) => width >= breakpointValue,
2010 "<": (breakpointValue, width) => width < breakpointValue
2011 };
2012 var ViewportMatchWidthContext = (0, import_element21.createContext)(
2013 /** @type {null | number} */
2014 null
2015 );
2016 ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext";
2017 var useViewportMatch = (breakpoint, operator = ">=", view = window) => {
2018 const simulatedWidth = (0, import_element21.useContext)(ViewportMatchWidthContext);
2019 const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
2020 const mediaQueryResult = useMediaQuery(mediaQuery || void 0, view);
2021 if (simulatedWidth) {
2022 return OPERATOR_EVALUATORS[operator](
2023 BREAKPOINTS[breakpoint],
2024 simulatedWidth
2025 );
2026 }
2027 return mediaQueryResult;
2028 };
2029 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
2030 var use_viewport_match_default = useViewportMatch;
2031
2032 // packages/compose/build-module/hooks/use-resize-observer/use-resize-observer.mjs
2033 var import_element22 = __toESM(require_element(), 1);
2034 function useResizeObserver(callback, resizeObserverOptions = {}) {
2035 const callbackEvent = useEvent(callback);
2036 const observedElementRef = (0, import_element22.useRef)(null);
2037 const resizeObserverRef = (0, import_element22.useRef)(void 0);
2038 return useEvent((element) => {
2039 if (element === observedElementRef.current) {
2040 return;
2041 }
2042 resizeObserverRef.current ??= new ResizeObserver(callbackEvent);
2043 const { current: resizeObserver } = resizeObserverRef;
2044 if (observedElementRef.current) {
2045 resizeObserver.unobserve(observedElementRef.current);
2046 }
2047 observedElementRef.current = element ?? null;
2048 if (element) {
2049 resizeObserver.observe(element, resizeObserverOptions);
2050 }
2051 });
2052 }
2053
2054 // packages/compose/build-module/hooks/use-resize-observer/legacy/index.mjs
2055 var import_element23 = __toESM(require_element(), 1);
2056 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
2057 var extractSize = (entry) => {
2058 let entrySize;
2059 if (!entry.contentBoxSize) {
2060 entrySize = [entry.contentRect.width, entry.contentRect.height];
2061 } else if (entry.contentBoxSize[0]) {
2062 const contentBoxSize = entry.contentBoxSize[0];
2063 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
2064 } else {
2065 const contentBoxSize = entry.contentBoxSize;
2066 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
2067 }
2068 const [width, height] = entrySize.map((d) => Math.round(d));
2069 return { width, height };
2070 };
2071 var RESIZE_ELEMENT_STYLES = {
2072 position: "absolute",
2073 top: 0,
2074 left: 0,
2075 right: 0,
2076 bottom: 0,
2077 pointerEvents: "none",
2078 opacity: 0,
2079 overflow: "hidden",
2080 zIndex: -1
2081 };
2082 function ResizeElement({ onResize }) {
2083 const resizeElementRef = useResizeObserver((entries) => {
2084 const newSize = extractSize(entries.at(-1));
2085 onResize(newSize);
2086 });
2087 return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2088 "div",
2089 {
2090 ref: resizeElementRef,
2091 style: RESIZE_ELEMENT_STYLES,
2092 "aria-hidden": "true"
2093 }
2094 );
2095 }
2096 function sizeEquals(a, b) {
2097 return a.width === b.width && a.height === b.height;
2098 }
2099 var NULL_SIZE = { width: null, height: null };
2100 function useLegacyResizeObserver() {
2101 const [size, setSize] = (0, import_element23.useState)(NULL_SIZE);
2102 const previousSizeRef = (0, import_element23.useRef)(NULL_SIZE);
2103 const handleResize = (0, import_element23.useCallback)((newSize) => {
2104 if (!sizeEquals(previousSizeRef.current, newSize)) {
2105 previousSizeRef.current = newSize;
2106 setSize(newSize);
2107 }
2108 }, []);
2109 const resizeElement = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ResizeElement, { onResize: handleResize });
2110 return [resizeElement, size];
2111 }
2112
2113 // packages/compose/build-module/hooks/use-resize-observer/index.mjs
2114 function useResizeObserver2(callback, options = {}) {
2115 return callback ? useResizeObserver(callback, options) : useLegacyResizeObserver();
2116 }
2117
2118 // packages/compose/build-module/hooks/use-async-list/index.mjs
2119 var import_element24 = __toESM(require_element(), 1);
2120 var import_priority_queue = __toESM(require_priority_queue(), 1);
2121 function getFirstItemsPresentInState(list, state) {
2122 const firstItems = [];
2123 for (let i = 0; i < list.length; i++) {
2124 const item = list[i];
2125 if (!state.includes(item)) {
2126 break;
2127 }
2128 firstItems.push(item);
2129 }
2130 return firstItems;
2131 }
2132 function useAsyncList(list, config = { step: 1 }) {
2133 const { step = 1 } = config;
2134 const [current, setCurrent] = (0, import_element24.useState)([]);
2135 (0, import_element24.useEffect)(() => {
2136 let firstItems = getFirstItemsPresentInState(list, current);
2137 if (firstItems.length < step) {
2138 firstItems = firstItems.concat(
2139 list.slice(firstItems.length, step)
2140 );
2141 }
2142 setCurrent(firstItems);
2143 const asyncQueue = (0, import_priority_queue.createQueue)();
2144 for (let i = firstItems.length; i < list.length; i += step) {
2145 asyncQueue.add({}, () => {
2146 (0, import_element24.flushSync)(() => {
2147 setCurrent((state) => [
2148 ...state,
2149 ...list.slice(i, i + step)
2150 ]);
2151 });
2152 });
2153 }
2154 return () => asyncQueue.reset();
2155 }, [list]);
2156 return current;
2157 }
2158 var use_async_list_default = useAsyncList;
2159
2160 // packages/compose/build-module/hooks/use-warn-on-change/index.mjs
2161 function useWarnOnChange(object, prefix = "Change detection") {
2162 const previousValues = usePrevious(object);
2163 Object.entries(previousValues ?? []).forEach(([key, value]) => {
2164 if (value !== object[
2165 /** @type {keyof typeof object} */
2166 key
2167 ]) {
2168 console.warn(
2169 `${prefix}: ${key} key changed:`,
2170 value,
2171 object[
2172 /** @type {keyof typeof object} */
2173 key
2174 ]
2175 /* eslint-enable jsdoc/check-types */
2176 );
2177 }
2178 });
2179 }
2180 var use_warn_on_change_default = useWarnOnChange;
2181
2182 // node_modules/use-memo-one/dist/use-memo-one.esm.js
2183 var import_react = __toESM(require_react());
2184 function areInputsEqual(newInputs, lastInputs) {
2185 if (newInputs.length !== lastInputs.length) {
2186 return false;
2187 }
2188 for (var i = 0; i < newInputs.length; i++) {
2189 if (newInputs[i] !== lastInputs[i]) {
2190 return false;
2191 }
2192 }
2193 return true;
2194 }
2195 function useMemoOne(getResult, inputs) {
2196 var initial = (0, import_react.useState)(function() {
2197 return {
2198 inputs,
2199 result: getResult()
2200 };
2201 })[0];
2202 var committed = (0, import_react.useRef)(initial);
2203 var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs));
2204 var cache = isInputMatch ? committed.current : {
2205 inputs,
2206 result: getResult()
2207 };
2208 (0, import_react.useEffect)(function() {
2209 committed.current = cache;
2210 }, [cache]);
2211 return cache.result;
2212 }
2213
2214 // packages/compose/build-module/hooks/use-debounce/index.mjs
2215 var import_element25 = __toESM(require_element(), 1);
2216 function useDebounce(fn, wait, options) {
2217 const debounced = useMemoOne(
2218 () => debounce(fn, wait ?? 0, options),
2219 [fn, wait, options?.leading, options?.trailing, options?.maxWait]
2220 );
2221 (0, import_element25.useEffect)(() => () => debounced.cancel(), [debounced]);
2222 return debounced;
2223 }
2224
2225 // packages/compose/build-module/hooks/use-debounced-input/index.mjs
2226 var import_element26 = __toESM(require_element(), 1);
2227 function useDebouncedInput(defaultValue = "") {
2228 const [input, setInput] = (0, import_element26.useState)(defaultValue);
2229 const [debouncedInput, setDebouncedState] = (0, import_element26.useState)(defaultValue);
2230 const setDebouncedInput = useDebounce(setDebouncedState, 250);
2231 (0, import_element26.useEffect)(() => {
2232 setDebouncedInput(input);
2233 }, [input, setDebouncedInput]);
2234 return [input, setInput, debouncedInput];
2235 }
2236
2237 // packages/compose/build-module/hooks/use-throttle/index.mjs
2238 var import_element27 = __toESM(require_element(), 1);
2239 function useThrottle(fn, wait, options) {
2240 const throttled = useMemoOne(
2241 () => throttle(fn, wait ?? 0, options),
2242 [fn, wait, options]
2243 );
2244 (0, import_element27.useEffect)(() => () => throttled.cancel(), [throttled]);
2245 return throttled;
2246 }
2247
2248 // packages/compose/build-module/hooks/use-drop-zone/index.mjs
2249 function useDropZone({
2250 dropZoneElement,
2251 isDisabled,
2252 onDrop: _onDrop,
2253 onDragStart: _onDragStart,
2254 onDragEnter: _onDragEnter,
2255 onDragLeave: _onDragLeave,
2256 onDragEnd: _onDragEnd,
2257 onDragOver: _onDragOver
2258 }) {
2259 const onDropEvent = useEvent(_onDrop);
2260 const onDragStartEvent = useEvent(_onDragStart);
2261 const onDragEnterEvent = useEvent(_onDragEnter);
2262 const onDragLeaveEvent = useEvent(_onDragLeave);
2263 const onDragEndEvent = useEvent(_onDragEnd);
2264 const onDragOverEvent = useEvent(_onDragOver);
2265 return useRefEffect(
2266 (elem) => {
2267 if (isDisabled) {
2268 return;
2269 }
2270 const element = dropZoneElement ?? elem;
2271 let isDragging = false;
2272 const { ownerDocument } = element;
2273 function isElementInZone(targetToCheck) {
2274 const { defaultView } = ownerDocument;
2275 if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) {
2276 return false;
2277 }
2278 let elementToCheck = targetToCheck;
2279 do {
2280 if (elementToCheck.dataset.isDropZone) {
2281 return elementToCheck === element;
2282 }
2283 } while (elementToCheck = elementToCheck.parentElement);
2284 return false;
2285 }
2286 function maybeDragStart(event) {
2287 if (isDragging) {
2288 return;
2289 }
2290 isDragging = true;
2291 ownerDocument.addEventListener("dragend", maybeDragEnd);
2292 ownerDocument.addEventListener("mousemove", maybeDragEnd);
2293 if (_onDragStart) {
2294 onDragStartEvent(event);
2295 }
2296 }
2297 function onDragEnter(event) {
2298 event.preventDefault();
2299 if (element.contains(
2300 /** @type {Node} */
2301 event.relatedTarget
2302 )) {
2303 return;
2304 }
2305 if (_onDragEnter) {
2306 onDragEnterEvent(event);
2307 }
2308 }
2309 function onDragOver(event) {
2310 if (!event.defaultPrevented && _onDragOver) {
2311 onDragOverEvent(event);
2312 }
2313 event.preventDefault();
2314 }
2315 function onDragLeave(event) {
2316 if (isElementInZone(event.relatedTarget)) {
2317 return;
2318 }
2319 if (_onDragLeave) {
2320 onDragLeaveEvent(event);
2321 }
2322 }
2323 function onDrop(event) {
2324 if (event.defaultPrevented) {
2325 return;
2326 }
2327 event.preventDefault();
2328 event.dataTransfer && event.dataTransfer.files.length;
2329 if (_onDrop) {
2330 onDropEvent(event);
2331 }
2332 maybeDragEnd(event);
2333 }
2334 function maybeDragEnd(event) {
2335 if (!isDragging) {
2336 return;
2337 }
2338 isDragging = false;
2339 ownerDocument.removeEventListener("dragend", maybeDragEnd);
2340 ownerDocument.removeEventListener("mousemove", maybeDragEnd);
2341 if (_onDragEnd) {
2342 onDragEndEvent(event);
2343 }
2344 }
2345 element.setAttribute("data-is-drop-zone", "true");
2346 element.addEventListener("drop", onDrop);
2347 element.addEventListener("dragenter", onDragEnter);
2348 element.addEventListener("dragover", onDragOver);
2349 element.addEventListener("dragleave", onDragLeave);
2350 ownerDocument.addEventListener("dragenter", maybeDragStart);
2351 return () => {
2352 element.removeAttribute("data-is-drop-zone");
2353 element.removeEventListener("drop", onDrop);
2354 element.removeEventListener("dragenter", onDragEnter);
2355 element.removeEventListener("dragover", onDragOver);
2356 element.removeEventListener("dragleave", onDragLeave);
2357 ownerDocument.removeEventListener("dragend", maybeDragEnd);
2358 ownerDocument.removeEventListener("mousemove", maybeDragEnd);
2359 ownerDocument.removeEventListener(
2360 "dragenter",
2361 maybeDragStart
2362 );
2363 };
2364 },
2365 [isDisabled, dropZoneElement]
2366 // Refresh when the passed in dropZoneElement changes.
2367 );
2368 }
2369
2370 // packages/compose/build-module/hooks/use-focusable-iframe/index.mjs
2371 function useFocusableIframe() {
2372 return useRefEffect((element) => {
2373 const { ownerDocument } = element;
2374 if (!ownerDocument) {
2375 return;
2376 }
2377 const { defaultView } = ownerDocument;
2378 if (!defaultView) {
2379 return;
2380 }
2381 function checkFocus() {
2382 if (ownerDocument && ownerDocument.activeElement === element) {
2383 element.focus();
2384 }
2385 }
2386 defaultView.addEventListener("blur", checkFocus);
2387 return () => {
2388 defaultView.removeEventListener("blur", checkFocus);
2389 };
2390 }, []);
2391 }
2392
2393 // packages/compose/build-module/hooks/use-fixed-window-list/index.mjs
2394 var import_element28 = __toESM(require_element(), 1);
2395 var import_dom3 = __toESM(require_dom(), 1);
2396 var import_keycodes2 = __toESM(require_keycodes(), 1);
2397 var DEFAULT_INIT_WINDOW_SIZE = 30;
2398 function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
2399 const initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;
2400 const useWindowing = options?.useWindowing ?? true;
2401 const [fixedListWindow, setFixedListWindow] = (0, import_element28.useState)({
2402 visibleItems: initWindowSize,
2403 start: 0,
2404 end: initWindowSize,
2405 itemInView: (index) => {
2406 return index >= 0 && index <= initWindowSize;
2407 }
2408 });
2409 (0, import_element28.useLayoutEffect)(() => {
2410 if (!useWindowing) {
2411 return;
2412 }
2413 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current);
2414 const measureWindow = (initRender) => {
2415 if (!scrollContainer) {
2416 return;
2417 }
2418 const visibleItems = Math.ceil(
2419 scrollContainer.clientHeight / itemHeight
2420 );
2421 const windowOverscan = initRender ? visibleItems : options?.windowOverscan ?? visibleItems;
2422 const firstViewableIndex = Math.floor(
2423 scrollContainer.scrollTop / itemHeight
2424 );
2425 const start = Math.max(0, firstViewableIndex - windowOverscan);
2426 const end = Math.min(
2427 totalItems - 1,
2428 firstViewableIndex + visibleItems + windowOverscan
2429 );
2430 setFixedListWindow((lastWindow) => {
2431 const nextWindow = {
2432 visibleItems,
2433 start,
2434 end,
2435 itemInView: (index) => {
2436 return start <= index && index <= end;
2437 }
2438 };
2439 if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) {
2440 return nextWindow;
2441 }
2442 return lastWindow;
2443 });
2444 };
2445 measureWindow(true);
2446 const debounceMeasureList = debounce(() => {
2447 measureWindow();
2448 }, 16);
2449 scrollContainer?.addEventListener("scroll", debounceMeasureList);
2450 scrollContainer?.ownerDocument?.defaultView?.addEventListener(
2451 "resize",
2452 debounceMeasureList
2453 );
2454 scrollContainer?.ownerDocument?.defaultView?.addEventListener(
2455 "resize",
2456 debounceMeasureList
2457 );
2458 return () => {
2459 scrollContainer?.removeEventListener(
2460 "scroll",
2461 debounceMeasureList
2462 );
2463 scrollContainer?.ownerDocument?.defaultView?.removeEventListener(
2464 "resize",
2465 debounceMeasureList
2466 );
2467 };
2468 }, [
2469 itemHeight,
2470 elementRef,
2471 totalItems,
2472 options?.expandedState,
2473 options?.windowOverscan,
2474 useWindowing
2475 ]);
2476 (0, import_element28.useLayoutEffect)(() => {
2477 if (!useWindowing) {
2478 return;
2479 }
2480 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current);
2481 const handleKeyDown = (event) => {
2482 switch (event.keyCode) {
2483 case import_keycodes2.HOME: {
2484 return scrollContainer?.scrollTo({ top: 0 });
2485 }
2486 case import_keycodes2.END: {
2487 return scrollContainer?.scrollTo({
2488 top: totalItems * itemHeight
2489 });
2490 }
2491 case import_keycodes2.PAGEUP: {
2492 return scrollContainer?.scrollTo({
2493 top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight
2494 });
2495 }
2496 case import_keycodes2.PAGEDOWN: {
2497 return scrollContainer?.scrollTo({
2498 top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight
2499 });
2500 }
2501 }
2502 };
2503 scrollContainer?.ownerDocument?.defaultView?.addEventListener(
2504 "keydown",
2505 handleKeyDown
2506 );
2507 return () => {
2508 scrollContainer?.ownerDocument?.defaultView?.removeEventListener(
2509 "keydown",
2510 handleKeyDown
2511 );
2512 };
2513 }, [
2514 totalItems,
2515 itemHeight,
2516 elementRef,
2517 fixedListWindow.visibleItems,
2518 useWindowing,
2519 options?.expandedState
2520 ]);
2521 return [fixedListWindow, setFixedListWindow];
2522 }
2523
2524 // packages/compose/build-module/hooks/use-observable-value/index.mjs
2525 var import_element29 = __toESM(require_element(), 1);
2526 function useObservableValue(map, name) {
2527 const [subscribe, getValue] = (0, import_element29.useMemo)(
2528 () => [
2529 (listener2) => map.subscribe(name, listener2),
2530 () => map.get(name)
2531 ],
2532 [map, name]
2533 );
2534 return (0, import_element29.useSyncExternalStore)(subscribe, getValue, getValue);
2535 }
2536 return __toCommonJS(index_exports);
2537 })();
2538 //# sourceMappingURL=index.js.map
2539