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