| [ 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/.store/mousetrap@1.6.5-wXrhfo95WfPhGlz0ygmxKA/node_modules/mousetrap/mousetrap.js 79 var require_mousetrap = __commonJS({ 80 "node_modules/.store/mousetrap@1.6.5-wXrhfo95WfPhGlz0ygmxKA/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 // packages/compose/build-module/index.mjs 555 var index_exports = {}; 556 __export(index_exports, { 557 __experimentalUseDialog: () => use_dialog_default, 558 __experimentalUseDragging: () => useDragging, 559 __experimentalUseDropZone: () => useDropZone, 560 __experimentalUseFixedWindowList: () => useFixedWindowList, 561 __experimentalUseFocusOutside: () => useFocusOutside, 562 compose: () => compose_default, 563 createHigherOrderComponent: () => createHigherOrderComponent, 564 debounce: () => debounce, 565 ifCondition: () => if_condition_default, 566 observableMap: () => observableMap, 567 pipe: () => pipe_default, 568 privateApis: () => privateApis, 569 pure: () => pure_default, 570 throttle: () => throttle, 571 useAsyncList: () => use_async_list_default, 572 useConstrainedTabbing: () => use_constrained_tabbing_default, 573 useCopyOnClick: () => useCopyOnClick, 574 useCopyToClipboard: () => useCopyToClipboard, 575 useDebounce: () => useDebounce, 576 useDebouncedInput: () => useDebouncedInput, 577 useDisabled: () => useDisabled, 578 useEvent: () => useEvent, 579 useFocusOnMount: () => useFocusOnMount, 580 useFocusReturn: () => use_focus_return_default, 581 useFocusableIframe: () => useFocusableIframe, 582 useInstanceId: () => use_instance_id_default, 583 useIsomorphicLayoutEffect: () => use_isomorphic_layout_effect_default, 584 useKeyboardShortcut: () => use_keyboard_shortcut_default, 585 useMediaQuery: () => useMediaQuery, 586 useMergeRefs: () => useMergeRefs, 587 useObservableValue: () => useObservableValue, 588 usePrevious: () => usePrevious, 589 useReducedMotion: () => use_reduced_motion_default, 590 useRefEffect: () => useRefEffect, 591 useResizeObserver: () => useResizeObserver2, 592 useStateWithHistory: () => useStateWithHistory, 593 useThrottle: () => useThrottle, 594 useViewportMatch: () => use_viewport_match_default, 595 useWarnOnChange: () => use_warn_on_change_default, 596 withGlobalEvents: () => withGlobalEvents, 597 withInstanceId: () => with_instance_id_default, 598 withSafeTimeout: () => with_safe_timeout_default, 599 withState: () => withState 600 }); 601 602 // node_modules/.store/tslib@2.8.1-LT-dxu1EkVy7OUDyVf5glQ/node_modules/tslib/tslib.es6.mjs 603 var __assign = function() { 604 __assign = Object.assign || function __assign2(t) { 605 for (var s, i = 1, n = arguments.length; i < n; i++) { 606 s = arguments[i]; 607 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; 608 } 609 return t; 610 }; 611 return __assign.apply(this, arguments); 612 }; 613 614 // node_modules/.store/lower-case@2.0.2-5YZP5nczP5_f_8Vt5KBPjA/node_modules/lower-case/dist.es2015/index.js 615 function lowerCase(str) { 616 return str.toLowerCase(); 617 } 618 619 // node_modules/.store/no-case@3.0.4-R4Hzt6qn-erEsTak7ojDpg/node_modules/no-case/dist.es2015/index.js 620 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g]; 621 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi; 622 function noCase(input, options) { 623 if (options === void 0) { 624 options = {}; 625 } 626 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; 627 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0"); 628 var start = 0; 629 var end = result.length; 630 while (result.charAt(start) === "\0") 631 start++; 632 while (result.charAt(end - 1) === "\0") 633 end--; 634 return result.slice(start, end).split("\0").map(transform).join(delimiter); 635 } 636 function replace(input, re, value) { 637 if (re instanceof RegExp) 638 return input.replace(re, value); 639 return re.reduce(function(input2, re2) { 640 return input2.replace(re2, value); 641 }, input); 642 } 643 644 // node_modules/.store/pascal-case@3.1.2-khtSA9hpCTEVLYfMgyRdoA/node_modules/pascal-case/dist.es2015/index.js 645 function pascalCaseTransform(input, index) { 646 var firstChar = input.charAt(0); 647 var lowerChars = input.substr(1).toLowerCase(); 648 if (index > 0 && firstChar >= "0" && firstChar <= "9") { 649 return "_" + firstChar + lowerChars; 650 } 651 return "" + firstChar.toUpperCase() + lowerChars; 652 } 653 function pascalCase(input, options) { 654 if (options === void 0) { 655 options = {}; 656 } 657 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options)); 658 } 659 660 // packages/compose/build-module/utils/create-higher-order-component/index.mjs 661 function createHigherOrderComponent(mapComponent, modifierName) { 662 return (Inner) => { 663 const Outer = mapComponent(Inner); 664 Outer.displayName = hocName(modifierName, Inner); 665 return Outer; 666 }; 667 } 668 var hocName = (name, Inner) => { 669 const inner = Inner.displayName || Inner.name || "Component"; 670 const outer = pascalCase(name ?? ""); 671 return `$outer}($inner})`; 672 }; 673 674 // packages/compose/build-module/utils/debounce/index.mjs 675 var debounce = (func, wait, options) => { 676 let lastArgs; 677 let lastThis; 678 let maxWait = 0; 679 let result; 680 let timerId; 681 let lastCallTime; 682 let lastInvokeTime = 0; 683 let leading = false; 684 let maxing = false; 685 let trailing = true; 686 if (options) { 687 leading = !!options.leading; 688 maxing = "maxWait" in options; 689 if (options.maxWait !== void 0) { 690 maxWait = Math.max(options.maxWait, wait); 691 } 692 trailing = "trailing" in options ? !!options.trailing : trailing; 693 } 694 function invokeFunc(time) { 695 const args = lastArgs; 696 const thisArg = lastThis; 697 lastArgs = void 0; 698 lastThis = void 0; 699 lastInvokeTime = time; 700 result = func.apply(thisArg, args); 701 return result; 702 } 703 function startTimer(pendingFunc, waitTime) { 704 timerId = setTimeout(pendingFunc, waitTime); 705 } 706 function cancelTimer() { 707 if (timerId !== void 0) { 708 clearTimeout(timerId); 709 } 710 } 711 function leadingEdge(time) { 712 lastInvokeTime = time; 713 startTimer(timerExpired, wait); 714 return leading ? invokeFunc(time) : result; 715 } 716 function getTimeSinceLastCall(time) { 717 return time - (lastCallTime || 0); 718 } 719 function remainingWait(time) { 720 const timeSinceLastCall = getTimeSinceLastCall(time); 721 const timeSinceLastInvoke = time - lastInvokeTime; 722 const timeWaiting = wait - timeSinceLastCall; 723 return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting; 724 } 725 function shouldInvoke(time) { 726 const timeSinceLastCall = getTimeSinceLastCall(time); 727 const timeSinceLastInvoke = time - lastInvokeTime; 728 return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; 729 } 730 function timerExpired() { 731 const time = Date.now(); 732 if (shouldInvoke(time)) { 733 return trailingEdge(time); 734 } 735 startTimer(timerExpired, remainingWait(time)); 736 return void 0; 737 } 738 function clearTimer() { 739 timerId = void 0; 740 } 741 function trailingEdge(time) { 742 clearTimer(); 743 if (trailing && lastArgs) { 744 return invokeFunc(time); 745 } 746 lastArgs = lastThis = void 0; 747 return result; 748 } 749 function cancel() { 750 cancelTimer(); 751 lastInvokeTime = 0; 752 clearTimer(); 753 lastArgs = lastCallTime = lastThis = void 0; 754 } 755 function flush() { 756 return pending() ? trailingEdge(Date.now()) : result; 757 } 758 function pending() { 759 return timerId !== void 0; 760 } 761 function debounced(...args) { 762 const time = Date.now(); 763 const isInvoking = shouldInvoke(time); 764 lastArgs = args; 765 lastThis = this; 766 lastCallTime = time; 767 if (isInvoking) { 768 if (!pending()) { 769 return leadingEdge(lastCallTime); 770 } 771 if (maxing) { 772 startTimer(timerExpired, wait); 773 return invokeFunc(lastCallTime); 774 } 775 } 776 if (!pending()) { 777 startTimer(timerExpired, wait); 778 } 779 return result; 780 } 781 debounced.cancel = cancel; 782 debounced.flush = flush; 783 debounced.pending = pending; 784 return debounced; 785 }; 786 787 // packages/compose/build-module/utils/throttle/index.mjs 788 var throttle = (func, wait, options) => { 789 let leading = true; 790 let trailing = true; 791 if (options) { 792 leading = "leading" in options ? !!options.leading : leading; 793 trailing = "trailing" in options ? !!options.trailing : trailing; 794 } 795 return debounce(func, wait, { 796 leading, 797 trailing, 798 maxWait: wait 799 }); 800 }; 801 802 // packages/compose/build-module/utils/observable-map/index.mjs 803 function observableMap() { 804 const map = /* @__PURE__ */ new Map(); 805 const listeners = /* @__PURE__ */ new Map(); 806 function callListeners(name) { 807 const list = listeners.get(name); 808 if (!list) { 809 return; 810 } 811 for (const listener2 of list) { 812 listener2(); 813 } 814 } 815 return { 816 get(name) { 817 return map.get(name); 818 }, 819 set(name, value) { 820 map.set(name, value); 821 callListeners(name); 822 }, 823 delete(name) { 824 map.delete(name); 825 callListeners(name); 826 }, 827 subscribe(name, listener2) { 828 let list = listeners.get(name); 829 if (!list) { 830 list = /* @__PURE__ */ new Set(); 831 listeners.set(name, list); 832 } 833 list.add(listener2); 834 return () => { 835 list.delete(listener2); 836 if (list.size === 0) { 837 listeners.delete(name); 838 } 839 }; 840 } 841 }; 842 } 843 844 // packages/compose/build-module/lock-unlock.mjs 845 var import_private_apis = __toESM(require_private_apis(), 1); 846 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)( 847 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.", 848 "@wordpress/compose" 849 ); 850 851 // packages/compose/build-module/utils/subscribe-delegated-listener/index.mjs 852 var registries = /* @__PURE__ */ new WeakMap(); 853 function subscribeDelegatedListener(target, eventType, callback, capture = false) { 854 const ownerDoc = target.ownerDocument; 855 const root = ownerDoc ?? target; 856 const isWindow = ownerDoc === void 0; 857 let perRoot = registries.get(root); 858 if (!perRoot) { 859 perRoot = /* @__PURE__ */ new Map(); 860 registries.set(root, perRoot); 861 } 862 const key = capture ? `$eventType}:capture` : eventType; 863 let perEvent = perRoot.get(key); 864 if (!perEvent) { 865 perEvent = /* @__PURE__ */ new WeakMap(); 866 perRoot.set(key, perEvent); 867 const subscribers = perEvent; 868 root.addEventListener( 869 eventType, 870 (event) => { 871 if (isWindow) { 872 const set2 = subscribers.get(root); 873 if (set2) { 874 for (const cb of set2) { 875 cb(event); 876 } 877 } 878 return; 879 } 880 if (capture) { 881 const path = []; 882 let current = event.target; 883 while (current) { 884 path.push(current); 885 if (current === root) { 886 break; 887 } 888 current = current.parentNode; 889 } 890 for (let i = path.length - 1; i >= 0; i--) { 891 const set2 = subscribers.get(path[i]); 892 if (set2) { 893 for (const cb of set2) { 894 cb(event); 895 } 896 } 897 } 898 } else { 899 let current = event.target; 900 while (current) { 901 const set2 = subscribers.get(current); 902 if (set2) { 903 for (const cb of set2) { 904 cb(event); 905 } 906 } 907 if (current === root) { 908 break; 909 } 910 current = current.parentNode; 911 } 912 } 913 }, 914 capture 915 ); 916 } 917 let set = perEvent.get(target); 918 if (!set) { 919 set = /* @__PURE__ */ new Set(); 920 perEvent.set(target, set); 921 } 922 set.add(callback); 923 return () => { 924 set.delete(callback); 925 }; 926 } 927 928 // packages/compose/build-module/private-apis.mjs 929 var privateApis = {}; 930 lock(privateApis, { 931 subscribeDelegatedListener 932 }); 933 934 // packages/compose/build-module/higher-order/pipe.mjs 935 var basePipe = (reverse = false) => (...funcs) => (...args) => { 936 const functions = funcs.flat(); 937 if (reverse) { 938 functions.reverse(); 939 } 940 return functions.reduce( 941 (prev, func) => [func(...prev)], 942 args 943 )[0]; 944 }; 945 var pipe = basePipe(); 946 var pipe_default = pipe; 947 948 // packages/compose/build-module/higher-order/compose.mjs 949 var compose = basePipe(true); 950 var compose_default = compose; 951 952 // packages/compose/build-module/higher-order/if-condition/index.mjs 953 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1); 954 function ifCondition(predicate) { 955 return createHigherOrderComponent( 956 (WrappedComponent) => (props) => { 957 if (!predicate(props)) { 958 return null; 959 } 960 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...props }); 961 }, 962 "ifCondition" 963 ); 964 } 965 var if_condition_default = ifCondition; 966 967 // packages/compose/build-module/higher-order/pure/index.mjs 968 var import_is_shallow_equal = __toESM(require_is_shallow_equal(), 1); 969 var import_element = __toESM(require_element(), 1); 970 var import_deprecated = __toESM(require_deprecated(), 1); 971 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1); 972 var pure = createHigherOrderComponent(function(WrappedComponent) { 973 (0, import_deprecated.default)("wp.compose.pure", { 974 since: "7.1", 975 alternative: "Use `memo` or `PureComponent` instead" 976 }); 977 if (WrappedComponent.prototype instanceof import_element.Component) { 978 return class extends WrappedComponent { 979 shouldComponentUpdate(nextProps, nextState) { 980 return !(0, import_is_shallow_equal.isShallowEqual)(nextProps, this.props) || !(0, import_is_shallow_equal.isShallowEqual)(nextState, this.state); 981 } 982 }; 983 } 984 return class extends import_element.Component { 985 shouldComponentUpdate(nextProps) { 986 return !(0, import_is_shallow_equal.isShallowEqual)(nextProps, this.props); 987 } 988 render() { 989 return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WrappedComponent, { ...this.props }); 990 } 991 }; 992 }, "pure"); 993 var pure_default = pure; 994 995 // packages/compose/build-module/higher-order/with-global-events/index.mjs 996 var import_element2 = __toESM(require_element(), 1); 997 var import_deprecated2 = __toESM(require_deprecated(), 1); 998 999 // packages/compose/build-module/higher-order/with-global-events/listener.mjs 1000 var Listener = class { 1001 constructor() { 1002 this.listeners = {}; 1003 this.handleEvent = this.handleEvent.bind(this); 1004 } 1005 add(eventType, instance) { 1006 if (!this.listeners[eventType]) { 1007 window.addEventListener(eventType, this.handleEvent); 1008 this.listeners[eventType] = []; 1009 } 1010 this.listeners[eventType].push(instance); 1011 } 1012 remove(eventType, instance) { 1013 if (!this.listeners[eventType]) { 1014 return; 1015 } 1016 this.listeners[eventType] = this.listeners[eventType].filter( 1017 (listener2) => listener2 !== instance 1018 ); 1019 if (!this.listeners[eventType].length) { 1020 window.removeEventListener(eventType, this.handleEvent); 1021 delete this.listeners[eventType]; 1022 } 1023 } 1024 handleEvent(event) { 1025 this.listeners[event.type]?.forEach((instance) => { 1026 instance.handleEvent(event); 1027 }); 1028 } 1029 }; 1030 var listener_default = Listener; 1031 1032 // packages/compose/build-module/higher-order/with-global-events/index.mjs 1033 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1); 1034 var listener = new listener_default(); 1035 function withGlobalEvents(eventTypesToHandlers) { 1036 (0, import_deprecated2.default)("wp.compose.withGlobalEvents", { 1037 since: "5.7", 1038 alternative: "useEffect" 1039 }); 1040 return createHigherOrderComponent((WrappedComponent) => { 1041 class Wrapper extends import_element2.Component { 1042 constructor(props) { 1043 super(props); 1044 this.handleEvent = this.handleEvent.bind(this); 1045 this.handleRef = this.handleRef.bind(this); 1046 } 1047 componentDidMount() { 1048 Object.keys(eventTypesToHandlers).forEach((eventType) => { 1049 listener.add(eventType, this); 1050 }); 1051 } 1052 componentWillUnmount() { 1053 Object.keys(eventTypesToHandlers).forEach((eventType) => { 1054 listener.remove(eventType, this); 1055 }); 1056 } 1057 handleEvent(event) { 1058 const handler = eventTypesToHandlers[event.type]; 1059 if (typeof this.wrappedRef[handler] === "function") { 1060 this.wrappedRef[handler]( 1061 event 1062 ); 1063 } 1064 } 1065 handleRef(el) { 1066 this.wrappedRef = el; 1067 if (this.props.forwardedRef) { 1068 this.props.forwardedRef(el); 1069 } 1070 } 1071 render() { 1072 return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( 1073 WrappedComponent, 1074 { 1075 ...this.props.ownProps, 1076 ref: this.handleRef 1077 } 1078 ); 1079 } 1080 } 1081 return (0, import_element2.forwardRef)((props, ref) => { 1082 return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( 1083 Wrapper, 1084 { 1085 ownProps: props, 1086 forwardedRef: ref 1087 } 1088 ); 1089 }); 1090 }, "withGlobalEvents"); 1091 } 1092 1093 // packages/compose/build-module/hooks/use-instance-id/index.mjs 1094 var import_element3 = __toESM(require_element(), 1); 1095 var instanceMap = /* @__PURE__ */ new WeakMap(); 1096 function createId(object) { 1097 const instances = instanceMap.get(object) || 0; 1098 instanceMap.set(object, instances + 1); 1099 return instances; 1100 } 1101 function useInstanceId(object, prefix, preferredId) { 1102 return (0, import_element3.useMemo)(() => { 1103 if (preferredId) { 1104 return preferredId; 1105 } 1106 const id = createId(object); 1107 return prefix ? `$prefix}-$id}` : id; 1108 }, [object, preferredId, prefix]); 1109 } 1110 var use_instance_id_default = useInstanceId; 1111 1112 // packages/compose/build-module/higher-order/with-instance-id/index.mjs 1113 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1); 1114 var withInstanceId = createHigherOrderComponent( 1115 (WrappedComponent) => { 1116 return (props) => { 1117 const instanceId = use_instance_id_default(WrappedComponent); 1118 return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(WrappedComponent, { ...props, instanceId }); 1119 }; 1120 }, 1121 "instanceId" 1122 ); 1123 var with_instance_id_default = withInstanceId; 1124 1125 // packages/compose/build-module/higher-order/with-safe-timeout/index.mjs 1126 var import_element4 = __toESM(require_element(), 1); 1127 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1); 1128 var withSafeTimeout = createHigherOrderComponent( 1129 (OriginalComponent) => { 1130 return class WrappedComponent extends import_element4.Component { 1131 timeouts; 1132 constructor(props) { 1133 super(props); 1134 this.timeouts = []; 1135 this.setTimeout = this.setTimeout.bind(this); 1136 this.clearTimeout = this.clearTimeout.bind(this); 1137 } 1138 componentWillUnmount() { 1139 this.timeouts.forEach(clearTimeout); 1140 } 1141 setTimeout(fn, delay) { 1142 const id = setTimeout(() => { 1143 fn(); 1144 this.clearTimeout(id); 1145 }, delay); 1146 this.timeouts.push(id); 1147 return id; 1148 } 1149 clearTimeout(id) { 1150 clearTimeout(id); 1151 this.timeouts = this.timeouts.filter( 1152 (timeoutId) => timeoutId !== id 1153 ); 1154 } 1155 render() { 1156 return ( 1157 // @ts-expect-error `LibraryManagedAttributes` cannot see the injected timeout props. 1158 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( 1159 OriginalComponent, 1160 { 1161 ...this.props, 1162 setTimeout: this.setTimeout, 1163 clearTimeout: this.clearTimeout 1164 } 1165 ) 1166 ); 1167 } 1168 }; 1169 }, 1170 "withSafeTimeout" 1171 ); 1172 var with_safe_timeout_default = withSafeTimeout; 1173 1174 // packages/compose/build-module/higher-order/with-state/index.mjs 1175 var import_element5 = __toESM(require_element(), 1); 1176 var import_deprecated3 = __toESM(require_deprecated(), 1); 1177 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1); 1178 function createWithState(initialState) { 1179 (0, import_deprecated3.default)("wp.compose.withState", { 1180 since: "5.8", 1181 alternative: "wp.element.useState" 1182 }); 1183 return createHigherOrderComponent( 1184 (OriginalComponent) => { 1185 const Inner = OriginalComponent; 1186 return class WrappedComponent extends import_element5.Component { 1187 constructor(props) { 1188 super(props); 1189 this.setState = this.setState.bind(this); 1190 this.state = initialState; 1191 } 1192 render() { 1193 return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( 1194 Inner, 1195 { 1196 ...this.props, 1197 ...this.state, 1198 setState: this.setState 1199 } 1200 ); 1201 } 1202 }; 1203 }, 1204 "withState" 1205 ); 1206 } 1207 function withState(initialState = {}) { 1208 return createWithState(initialState); 1209 } 1210 1211 // packages/compose/build-module/hooks/use-constrained-tabbing/index.mjs 1212 var import_dom = __toESM(require_dom(), 1); 1213 1214 // packages/compose/build-module/hooks/use-ref-effect/index.mjs 1215 var import_element6 = __toESM(require_element(), 1); 1216 function useRefEffect(callback, dependencies) { 1217 const cleanupRef = (0, import_element6.useRef)(void 0); 1218 return (0, import_element6.useCallback)((node) => { 1219 if (node) { 1220 cleanupRef.current = callback(node); 1221 } else if (cleanupRef.current) { 1222 cleanupRef.current(); 1223 } 1224 }, dependencies); 1225 } 1226 1227 // packages/compose/build-module/hooks/use-constrained-tabbing/index.mjs 1228 function useConstrainedTabbing() { 1229 return useRefEffect((node) => { 1230 function onKeyDown(event) { 1231 const { key, shiftKey, target } = event; 1232 if (key !== "Tab") { 1233 return; 1234 } 1235 const action = shiftKey ? "findPrevious" : "findNext"; 1236 const nextElement = import_dom.focus.tabbable[action](target) || null; 1237 if (target.contains(nextElement)) { 1238 event.preventDefault(); 1239 nextElement?.focus(); 1240 return; 1241 } 1242 if (node.contains(nextElement)) { 1243 return; 1244 } 1245 if (!import_dom.focus.tabbable.find(node).length) { 1246 event.preventDefault(); 1247 return; 1248 } 1249 const domAction = shiftKey ? "append" : "prepend"; 1250 const { ownerDocument } = node; 1251 const trap = ownerDocument.createElement("div"); 1252 trap.tabIndex = -1; 1253 node[domAction](trap); 1254 trap.addEventListener("blur", () => node.removeChild(trap)); 1255 trap.focus(); 1256 } 1257 node.addEventListener("keydown", onKeyDown); 1258 return () => { 1259 node.removeEventListener("keydown", onKeyDown); 1260 }; 1261 }, []); 1262 } 1263 var use_constrained_tabbing_default = useConstrainedTabbing; 1264 1265 // packages/compose/build-module/hooks/use-copy-on-click/index.mjs 1266 var import_element8 = __toESM(require_element(), 1); 1267 var import_deprecated4 = __toESM(require_deprecated(), 1); 1268 1269 // packages/compose/build-module/hooks/use-copy-to-clipboard/index.mjs 1270 var import_element7 = __toESM(require_element(), 1); 1271 async function copyToClipboard(text, trigger) { 1272 if (!trigger) { 1273 return false; 1274 } 1275 const { ownerDocument } = trigger; 1276 if (!ownerDocument) { 1277 return false; 1278 } 1279 const { defaultView } = ownerDocument; 1280 try { 1281 if (defaultView?.navigator?.clipboard?.writeText) { 1282 await defaultView.navigator.clipboard.writeText(text); 1283 return true; 1284 } 1285 const textarea = ownerDocument.createElement("textarea"); 1286 textarea.value = text; 1287 textarea.setAttribute("readonly", ""); 1288 textarea.style.position = "fixed"; 1289 textarea.style.left = "-9999px"; 1290 textarea.style.top = "-9999px"; 1291 ownerDocument.body.appendChild(textarea); 1292 textarea.select(); 1293 const success = ownerDocument.execCommand("copy"); 1294 textarea.remove(); 1295 return success; 1296 } catch { 1297 return false; 1298 } 1299 } 1300 function restoreFocus(trigger) { 1301 if ("focus" in trigger && typeof trigger.focus === "function") { 1302 trigger.focus(); 1303 } 1304 } 1305 function useUpdatedRef(value) { 1306 const ref = (0, import_element7.useRef)(value); 1307 (0, import_element7.useLayoutEffect)(() => { 1308 ref.current = value; 1309 }, [value]); 1310 return ref; 1311 } 1312 function useCopyToClipboard(text, onSuccess) { 1313 const textRef = useUpdatedRef(text); 1314 const onSuccessRef = useUpdatedRef(onSuccess); 1315 return useRefEffect((node) => { 1316 let isActive = true; 1317 const handleClick = async () => { 1318 const textToCopy = typeof textRef.current === "function" ? textRef.current() : textRef.current || ""; 1319 const success = await copyToClipboard(textToCopy, node); 1320 if (success) { 1321 if (isActive) { 1322 restoreFocus(node); 1323 } 1324 if (onSuccessRef.current) { 1325 onSuccessRef.current(); 1326 } 1327 } 1328 }; 1329 node.addEventListener("click", handleClick); 1330 return () => { 1331 isActive = false; 1332 node.removeEventListener("click", handleClick); 1333 }; 1334 }, []); 1335 } 1336 1337 // packages/compose/build-module/hooks/use-copy-on-click/index.mjs 1338 function useCopyOnClick(ref, text, timeout = 4e3) { 1339 (0, import_deprecated4.default)("wp.compose.useCopyOnClick", { 1340 since: "5.8", 1341 alternative: "wp.compose.useCopyToClipboard" 1342 }); 1343 const [hasCopied, setHasCopied] = (0, import_element8.useState)(false); 1344 (0, import_element8.useEffect)(() => { 1345 let isActive = true; 1346 let timeoutId; 1347 if (!ref.current) { 1348 return; 1349 } 1350 let targets; 1351 if (typeof ref.current === "string") { 1352 targets = typeof document !== "undefined" ? Array.from(document.querySelectorAll(ref.current)) : []; 1353 } else if ("length" in ref.current && typeof ref.current.length === "number") { 1354 targets = Array.from(ref.current); 1355 } else { 1356 targets = [ref.current]; 1357 } 1358 if (targets.length === 0) { 1359 return; 1360 } 1361 const handleClick = async (event) => { 1362 const trigger = event.currentTarget; 1363 if (!trigger) { 1364 return; 1365 } 1366 const success = await copyToClipboard( 1367 typeof text === "function" ? text() : text || "", 1368 trigger 1369 ); 1370 if (!isActive) { 1371 return; 1372 } 1373 if (success) { 1374 restoreFocus(trigger); 1375 if (timeout) { 1376 setHasCopied(true); 1377 clearTimeout(timeoutId); 1378 timeoutId = setTimeout( 1379 () => setHasCopied(false), 1380 timeout 1381 ); 1382 } 1383 } 1384 }; 1385 for (const target of targets) { 1386 target.addEventListener("click", handleClick); 1387 } 1388 return () => { 1389 isActive = false; 1390 for (const target of targets) { 1391 target.removeEventListener("click", handleClick); 1392 } 1393 clearTimeout(timeoutId); 1394 }; 1395 }, [ref, text, timeout]); 1396 return hasCopied; 1397 } 1398 1399 // packages/compose/build-module/hooks/use-dialog/index.mjs 1400 var import_element13 = __toESM(require_element(), 1); 1401 1402 // packages/compose/build-module/hooks/use-focus-on-mount/index.mjs 1403 var import_dom2 = __toESM(require_dom(), 1); 1404 var import_element9 = __toESM(require_element(), 1); 1405 function useFocusOnMount(focusOnMount = "firstElement") { 1406 const focusOnMountRef = (0, import_element9.useRef)(focusOnMount); 1407 const setFocus = (target) => { 1408 target.focus({ 1409 // When focusing newly mounted dialogs, 1410 // the position of the popover is often not right on the first render 1411 // This prevents the layout shifts when focusing the dialogs. 1412 preventScroll: true 1413 }); 1414 }; 1415 (0, import_element9.useEffect)(() => { 1416 focusOnMountRef.current = focusOnMount; 1417 }, [focusOnMount]); 1418 return useRefEffect((node) => { 1419 if (focusOnMountRef.current === false) { 1420 return; 1421 } 1422 if (node.contains(node.ownerDocument?.activeElement ?? null)) { 1423 return; 1424 } 1425 if (focusOnMountRef.current !== "firstElement" && focusOnMountRef.current !== "firstInputElement") { 1426 setFocus(node); 1427 return; 1428 } 1429 const timerId = setTimeout(() => { 1430 if (focusOnMountRef.current === "firstInputElement") { 1431 const formInput = node.querySelector( 1432 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])' 1433 ); 1434 if (formInput) { 1435 setFocus(formInput); 1436 return; 1437 } 1438 } 1439 const firstTabbable = import_dom2.focus.tabbable.find(node)[0]; 1440 if (firstTabbable) { 1441 setFocus(firstTabbable); 1442 } 1443 }, 0); 1444 return () => { 1445 clearTimeout(timerId); 1446 }; 1447 }, []); 1448 } 1449 1450 // packages/compose/build-module/hooks/use-focus-return/index.mjs 1451 var import_element10 = __toESM(require_element(), 1); 1452 var origin = null; 1453 function useFocusReturn(onFocusReturn) { 1454 const ref = (0, import_element10.useRef)(null); 1455 const focusedBeforeMountRef = (0, import_element10.useRef)(null); 1456 const onFocusReturnRef = (0, import_element10.useRef)( 1457 onFocusReturn 1458 ); 1459 (0, import_element10.useEffect)(() => { 1460 onFocusReturnRef.current = onFocusReturn; 1461 }, [onFocusReturn]); 1462 return (0, import_element10.useCallback)((node) => { 1463 if (node) { 1464 ref.current = node; 1465 if (focusedBeforeMountRef.current) { 1466 return; 1467 } 1468 const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument; 1469 focusedBeforeMountRef.current = activeDocument?.activeElement ?? null; 1470 } else if (focusedBeforeMountRef.current) { 1471 const isFocused = ref.current?.contains( 1472 ref.current?.ownerDocument.activeElement ?? null 1473 ); 1474 if (ref.current?.isConnected && !isFocused) { 1475 origin ??= focusedBeforeMountRef.current; 1476 return; 1477 } 1478 if (onFocusReturnRef.current) { 1479 onFocusReturnRef.current(); 1480 } else { 1481 const elementToFocus = !focusedBeforeMountRef.current.isConnected ? origin : focusedBeforeMountRef.current; 1482 elementToFocus?.focus(); 1483 } 1484 origin = null; 1485 } 1486 }, []); 1487 } 1488 var use_focus_return_default = useFocusReturn; 1489 1490 // packages/compose/build-module/hooks/use-focus-outside/index.mjs 1491 var import_element11 = __toESM(require_element(), 1); 1492 var INPUT_BUTTON_TYPES = ["button", "submit"]; 1493 function isFocusNormalizedButton(eventTarget) { 1494 if (!(eventTarget instanceof window.HTMLElement)) { 1495 return false; 1496 } 1497 switch (eventTarget.nodeName) { 1498 case "A": 1499 case "BUTTON": 1500 return true; 1501 case "INPUT": 1502 return INPUT_BUTTON_TYPES.includes( 1503 eventTarget.type 1504 ); 1505 } 1506 return false; 1507 } 1508 function useFocusOutside(onFocusOutside) { 1509 const currentOnFocusOutsideRef = (0, import_element11.useRef)(onFocusOutside); 1510 (0, import_element11.useEffect)(() => { 1511 currentOnFocusOutsideRef.current = onFocusOutside; 1512 }, [onFocusOutside]); 1513 const preventBlurCheckRef = (0, import_element11.useRef)(false); 1514 const blurCheckTimeoutIdRef = (0, import_element11.useRef)(void 0); 1515 const cancelBlurCheck = (0, import_element11.useCallback)(() => { 1516 clearTimeout(blurCheckTimeoutIdRef.current); 1517 }, []); 1518 (0, import_element11.useEffect)(() => { 1519 if (!onFocusOutside) { 1520 cancelBlurCheck(); 1521 } 1522 }, [onFocusOutside, cancelBlurCheck]); 1523 const normalizeButtonFocus = (0, import_element11.useCallback)((event) => { 1524 const { type, target } = event; 1525 const isInteractionEnd = ["mouseup", "touchend"].includes(type); 1526 if (isInteractionEnd) { 1527 preventBlurCheckRef.current = false; 1528 } else if (isFocusNormalizedButton(target)) { 1529 preventBlurCheckRef.current = true; 1530 } 1531 }, []); 1532 const queueBlurCheck = (0, import_element11.useCallback)((event) => { 1533 event.persist(); 1534 if (preventBlurCheckRef.current) { 1535 return; 1536 } 1537 const ignoreForRelatedTarget = event.target.getAttribute( 1538 "data-unstable-ignore-focus-outside-for-relatedtarget" 1539 ); 1540 if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) { 1541 return; 1542 } 1543 clearTimeout(blurCheckTimeoutIdRef.current); 1544 blurCheckTimeoutIdRef.current = setTimeout(() => { 1545 if (!document.hasFocus()) { 1546 event.preventDefault(); 1547 return; 1548 } 1549 if ("function" === typeof currentOnFocusOutsideRef.current) { 1550 currentOnFocusOutsideRef.current(event); 1551 } 1552 }, 0); 1553 }, []); 1554 return { 1555 onFocus: cancelBlurCheck, 1556 onMouseDown: normalizeButtonFocus, 1557 onMouseUp: normalizeButtonFocus, 1558 onTouchStart: normalizeButtonFocus, 1559 onTouchEnd: normalizeButtonFocus, 1560 onBlur: queueBlurCheck 1561 }; 1562 } 1563 1564 // packages/compose/build-module/hooks/use-merge-refs/index.mjs 1565 var import_element12 = __toESM(require_element(), 1); 1566 function assignRef(ref, value) { 1567 if (typeof ref === "function") { 1568 const returned = ref(value); 1569 return typeof returned === "function" ? returned : void 0; 1570 } else if (ref && ref.hasOwnProperty("current")) { 1571 ref.current = value; 1572 } 1573 return void 0; 1574 } 1575 function detachRef(ref, index, cleanups) { 1576 const cleanup = cleanups[index]; 1577 if (cleanup) { 1578 cleanups[index] = void 0; 1579 cleanup(); 1580 } else { 1581 assignRef(ref, null); 1582 } 1583 } 1584 function useMergeRefs(refs) { 1585 const elementRef = (0, import_element12.useRef)(null); 1586 const attachedRefsRef = (0, import_element12.useRef)([]); 1587 const currentRefsRef = (0, import_element12.useRef)(refs); 1588 const cleanupsRef = (0, import_element12.useRef)([]); 1589 currentRefsRef.current = refs; 1590 (0, import_element12.useLayoutEffect)(() => { 1591 const element = elementRef.current; 1592 if (element === null) { 1593 return; 1594 } 1595 refs.forEach((ref, index) => { 1596 const attachedRef = attachedRefsRef.current[index]; 1597 if (ref !== attachedRef) { 1598 detachRef(attachedRef, index, cleanupsRef.current); 1599 cleanupsRef.current[index] = assignRef(ref, element); 1600 } 1601 }); 1602 attachedRefsRef.current = refs; 1603 }, refs); 1604 return (0, import_element12.useCallback)((value) => { 1605 elementRef.current = value; 1606 if (value === null) { 1607 attachedRefsRef.current.forEach((ref, index) => { 1608 detachRef(ref, index, cleanupsRef.current); 1609 }); 1610 attachedRefsRef.current = []; 1611 } else { 1612 attachedRefsRef.current = currentRefsRef.current; 1613 attachedRefsRef.current.forEach((ref, index) => { 1614 cleanupsRef.current[index] = assignRef(ref, value); 1615 }); 1616 } 1617 }, []); 1618 } 1619 1620 // packages/compose/build-module/hooks/use-dialog/index.mjs 1621 function useDialog(options) { 1622 const currentOptions = (0, import_element13.useRef)(void 0); 1623 const { constrainTabbing = options.focusOnMount !== false } = options; 1624 (0, import_element13.useEffect)(() => { 1625 currentOptions.current = options; 1626 }, Object.values(options)); 1627 const constrainedTabbingRef = use_constrained_tabbing_default(); 1628 const focusOnMountRef = useFocusOnMount(options.focusOnMount); 1629 const focusReturnRef = use_focus_return_default(); 1630 const focusOutsideProps = useFocusOutside((event) => { 1631 if (currentOptions.current?.__unstableOnClose) { 1632 currentOptions.current.__unstableOnClose("focus-outside", event); 1633 } else if (currentOptions.current?.onClose) { 1634 currentOptions.current.onClose(); 1635 } 1636 }); 1637 const onKeyDown = (0, import_element13.useCallback)((event) => { 1638 currentOptions.current?.onKeyDown?.(event); 1639 if (event.key === "Escape" && !event.defaultPrevented && currentOptions.current?.onClose) { 1640 event.preventDefault(); 1641 event.stopPropagation(); 1642 currentOptions.current.onClose(); 1643 } 1644 }, []); 1645 return [ 1646 useMergeRefs([ 1647 constrainTabbing ? constrainedTabbingRef : null, 1648 options.focusOnMount !== false ? focusReturnRef : null, 1649 options.focusOnMount !== false ? focusOnMountRef : null 1650 ]), 1651 { 1652 ...focusOutsideProps, 1653 onKeyDown, 1654 tabIndex: -1 1655 } 1656 ]; 1657 } 1658 var use_dialog_default = useDialog; 1659 1660 // packages/compose/build-module/hooks/use-disabled/index.mjs 1661 function useDisabled({ 1662 isDisabled: isDisabledProp = false 1663 } = {}) { 1664 return useRefEffect( 1665 (node) => { 1666 if (isDisabledProp) { 1667 return; 1668 } 1669 const defaultView = node?.ownerDocument?.defaultView; 1670 if (!defaultView) { 1671 return; 1672 } 1673 const updates = []; 1674 const disable = () => { 1675 node.childNodes.forEach((child) => { 1676 if (!(child instanceof defaultView.HTMLElement)) { 1677 return; 1678 } 1679 if (!child.hasAttribute("inert")) { 1680 child.setAttribute("inert", "true"); 1681 updates.push(() => { 1682 child.removeAttribute("inert"); 1683 }); 1684 } 1685 }); 1686 }; 1687 const debouncedDisable = debounce(disable, 0, { 1688 leading: true 1689 }); 1690 disable(); 1691 const observer = new window.MutationObserver(debouncedDisable); 1692 observer.observe(node, { 1693 childList: true 1694 }); 1695 return () => { 1696 if (observer) { 1697 observer.disconnect(); 1698 } 1699 debouncedDisable.cancel(); 1700 updates.forEach((update) => update()); 1701 }; 1702 }, 1703 [isDisabledProp] 1704 ); 1705 } 1706 1707 // packages/compose/build-module/hooks/use-event/index.mjs 1708 var import_element14 = __toESM(require_element(), 1); 1709 function useEvent(callback) { 1710 const ref = (0, import_element14.useRef)(() => { 1711 throw new Error( 1712 "Callbacks created with `useEvent` cannot be called during rendering." 1713 ); 1714 }); 1715 (0, import_element14.useInsertionEffect)(() => { 1716 ref.current = callback; 1717 }); 1718 return (0, import_element14.useCallback)( 1719 (...args) => ref.current?.(...args), 1720 [] 1721 ); 1722 } 1723 1724 // packages/compose/build-module/hooks/use-dragging/index.mjs 1725 var import_element16 = __toESM(require_element(), 1); 1726 1727 // packages/compose/build-module/hooks/use-isomorphic-layout-effect/index.mjs 1728 var import_element15 = __toESM(require_element(), 1); 1729 var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_element15.useLayoutEffect : import_element15.useEffect; 1730 var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect; 1731 1732 // packages/compose/build-module/hooks/use-dragging/index.mjs 1733 function useDragging({ 1734 onDragStart, 1735 onDragMove, 1736 onDragEnd 1737 }) { 1738 const [isDragging, setIsDragging] = (0, import_element16.useState)(false); 1739 const eventsRef = (0, import_element16.useRef)({ 1740 onDragStart, 1741 onDragMove, 1742 onDragEnd 1743 }); 1744 use_isomorphic_layout_effect_default(() => { 1745 eventsRef.current.onDragStart = onDragStart; 1746 eventsRef.current.onDragMove = onDragMove; 1747 eventsRef.current.onDragEnd = onDragEnd; 1748 }, [onDragStart, onDragMove, onDragEnd]); 1749 const onMouseMove = (0, import_element16.useCallback)((event) => { 1750 eventsRef.current.onDragMove?.(event); 1751 }, []); 1752 const endDrag = (0, import_element16.useCallback)( 1753 function handleEndDrag(event) { 1754 eventsRef.current.onDragEnd?.(event); 1755 document.removeEventListener("mousemove", onMouseMove); 1756 document.removeEventListener("mouseup", handleEndDrag); 1757 setIsDragging(false); 1758 }, 1759 [onMouseMove] 1760 ); 1761 const startDrag = (0, import_element16.useCallback)( 1762 (event) => { 1763 eventsRef.current.onDragStart?.(event); 1764 document.addEventListener("mousemove", onMouseMove); 1765 document.addEventListener("mouseup", endDrag); 1766 setIsDragging(true); 1767 }, 1768 [onMouseMove, endDrag] 1769 ); 1770 (0, import_element16.useEffect)(() => { 1771 return () => { 1772 if (isDragging) { 1773 document.removeEventListener("mousemove", onMouseMove); 1774 document.removeEventListener("mouseup", endDrag); 1775 } 1776 }; 1777 }, [isDragging, onMouseMove, endDrag]); 1778 return { 1779 startDrag, 1780 endDrag, 1781 isDragging 1782 }; 1783 } 1784 1785 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs 1786 var import_mousetrap = __toESM(require_mousetrap(), 1); 1787 1788 // node_modules/.store/mousetrap@1.6.5-wXrhfo95WfPhGlz0ygmxKA/node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js 1789 (function(Mousetrap3) { 1790 if (!Mousetrap3) { 1791 return; 1792 } 1793 var _globalCallbacks = {}; 1794 var _originalStopCallback = Mousetrap3.prototype.stopCallback; 1795 Mousetrap3.prototype.stopCallback = function(e, element, combo, sequence) { 1796 var self = this; 1797 if (self.paused) { 1798 return true; 1799 } 1800 if (_globalCallbacks[combo] || _globalCallbacks[sequence]) { 1801 return false; 1802 } 1803 return _originalStopCallback.call(self, e, element, combo); 1804 }; 1805 Mousetrap3.prototype.bindGlobal = function(keys, callback, action) { 1806 var self = this; 1807 self.bind(keys, callback, action); 1808 if (keys instanceof Array) { 1809 for (var i = 0; i < keys.length; i++) { 1810 _globalCallbacks[keys[i]] = true; 1811 } 1812 return; 1813 } 1814 _globalCallbacks[keys] = true; 1815 }; 1816 Mousetrap3.init(); 1817 })(typeof Mousetrap !== "undefined" ? Mousetrap : void 0); 1818 1819 // packages/compose/build-module/hooks/use-keyboard-shortcut/index.mjs 1820 var import_element17 = __toESM(require_element(), 1); 1821 var import_keycodes = __toESM(require_keycodes(), 1); 1822 function useKeyboardShortcut(shortcuts, callback, { 1823 bindGlobal = false, 1824 eventName = "keydown", 1825 isDisabled = false, 1826 target 1827 } = {}) { 1828 const currentCallbackRef = (0, import_element17.useRef)(callback); 1829 (0, import_element17.useEffect)(() => { 1830 currentCallbackRef.current = callback; 1831 }, [callback]); 1832 (0, import_element17.useEffect)(() => { 1833 if (isDisabled) { 1834 return; 1835 } 1836 const mousetrap = new import_mousetrap.default( 1837 target && target.current ? target.current : ( 1838 // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`. 1839 // 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 1840 // necessary to maintain the existing behavior. 1841 document 1842 ) 1843 ); 1844 const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts]; 1845 shortcutsArray.forEach((shortcut) => { 1846 const keys = shortcut.split("+"); 1847 const modifiers = new Set( 1848 keys.filter((value) => value.length > 1) 1849 ); 1850 const hasAlt = modifiers.has("alt"); 1851 const hasShift = modifiers.has("shift"); 1852 if ((0, import_keycodes.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) { 1853 throw new Error( 1854 `Cannot bind $shortcut}. Alt and Shift+Alt modifiers are reserved for character input.` 1855 ); 1856 } 1857 const bindFn = bindGlobal ? "bindGlobal" : "bind"; 1858 mousetrap[bindFn]( 1859 shortcut, 1860 (...args) => currentCallbackRef.current(...args), 1861 eventName 1862 ); 1863 }); 1864 return () => { 1865 mousetrap.reset(); 1866 }; 1867 }, [shortcuts, bindGlobal, eventName, target, isDisabled]); 1868 } 1869 var use_keyboard_shortcut_default = useKeyboardShortcut; 1870 1871 // packages/compose/build-module/hooks/use-media-query/index.mjs 1872 var import_element18 = __toESM(require_element(), 1); 1873 var perWindowCache = /* @__PURE__ */ new WeakMap(); 1874 var EMPTY_SUBSCRIBER = { 1875 subscribe: () => () => { 1876 }, 1877 getValue: () => false 1878 }; 1879 function getMQLSubscriber(view, query) { 1880 if (!view || !query || typeof view.matchMedia !== "function") { 1881 return EMPTY_SUBSCRIBER; 1882 } 1883 let queryCache = perWindowCache.get(view); 1884 if (!queryCache) { 1885 queryCache = /* @__PURE__ */ new Map(); 1886 perWindowCache.set(view, queryCache); 1887 } 1888 const cached = queryCache.get(query); 1889 if (cached) { 1890 return cached; 1891 } 1892 const mediaQueryList = view.matchMedia(query); 1893 const listeners = /* @__PURE__ */ new Set(); 1894 const notify = () => { 1895 for (const listener2 of listeners) { 1896 listener2(); 1897 } 1898 }; 1899 const subscriber = { 1900 subscribe(onStoreChange) { 1901 if (listeners.size === 0) { 1902 mediaQueryList.addEventListener?.("change", notify); 1903 } 1904 listeners.add(onStoreChange); 1905 return () => { 1906 listeners.delete(onStoreChange); 1907 if (listeners.size === 0) { 1908 mediaQueryList.removeEventListener?.("change", notify); 1909 } 1910 }; 1911 }, 1912 getValue() { 1913 return mediaQueryList.matches; 1914 } 1915 }; 1916 queryCache.set(query, subscriber); 1917 return subscriber; 1918 } 1919 function useMediaQuery(query, view = typeof window !== "undefined" ? window : void 0) { 1920 const source = getMQLSubscriber(view, query); 1921 return (0, import_element18.useSyncExternalStore)( 1922 source.subscribe, 1923 source.getValue, 1924 () => false 1925 ); 1926 } 1927 1928 // packages/compose/build-module/hooks/use-previous/index.mjs 1929 var import_element19 = __toESM(require_element(), 1); 1930 function usePrevious(value) { 1931 const ref = (0, import_element19.useRef)(void 0); 1932 (0, import_element19.useEffect)(() => { 1933 ref.current = value; 1934 }, [value]); 1935 return ref.current; 1936 } 1937 1938 // packages/compose/build-module/hooks/use-reduced-motion/index.mjs 1939 var useReducedMotion = () => useMediaQuery("(prefers-reduced-motion: reduce)"); 1940 var use_reduced_motion_default = useReducedMotion; 1941 1942 // packages/compose/build-module/hooks/use-state-with-history/index.mjs 1943 var import_undo_manager = __toESM(require_undo_manager(), 1); 1944 var import_element20 = __toESM(require_element(), 1); 1945 function undoRedoReducer(state, action) { 1946 switch (action.type) { 1947 case "UNDO": { 1948 const undoRecord = state.manager.undo(); 1949 if (undoRecord) { 1950 return { 1951 ...state, 1952 value: undoRecord[0].changes.prop.from 1953 }; 1954 } 1955 return state; 1956 } 1957 case "REDO": { 1958 const redoRecord = state.manager.redo(); 1959 if (redoRecord) { 1960 return { 1961 ...state, 1962 value: redoRecord[0].changes.prop.to 1963 }; 1964 } 1965 return state; 1966 } 1967 case "RECORD": { 1968 state.manager.addRecord( 1969 [ 1970 { 1971 id: "object", 1972 changes: { 1973 prop: { from: state.value, to: action.value } 1974 } 1975 } 1976 ], 1977 action.isStaged 1978 ); 1979 return { 1980 ...state, 1981 value: action.value 1982 }; 1983 } 1984 } 1985 return state; 1986 } 1987 function initReducer(value) { 1988 return { 1989 manager: (0, import_undo_manager.createUndoManager)(), 1990 value 1991 }; 1992 } 1993 function useStateWithHistory(initialValue) { 1994 const [state, dispatch] = (0, import_element20.useReducer)( 1995 undoRedoReducer, 1996 initialValue, 1997 initReducer 1998 ); 1999 return { 2000 value: state.value, 2001 setValue: (0, import_element20.useCallback)((newValue, isStaged) => { 2002 dispatch({ 2003 type: "RECORD", 2004 value: newValue, 2005 isStaged 2006 }); 2007 }, []), 2008 hasUndo: state.manager.hasUndo(), 2009 hasRedo: state.manager.hasRedo(), 2010 undo: (0, import_element20.useCallback)(() => { 2011 dispatch({ type: "UNDO" }); 2012 }, []), 2013 redo: (0, import_element20.useCallback)(() => { 2014 dispatch({ type: "REDO" }); 2015 }, []) 2016 }; 2017 } 2018 2019 // packages/compose/build-module/hooks/use-viewport-match/index.mjs 2020 var import_element21 = __toESM(require_element(), 1); 2021 var BREAKPOINTS = { 2022 xhuge: 1920, 2023 huge: 1440, 2024 wide: 1280, 2025 xlarge: 1080, 2026 large: 960, 2027 medium: 782, 2028 small: 600, 2029 mobile: 480 2030 }; 2031 var CONDITIONS = { 2032 ">=": "min-width", 2033 "<": "max-width" 2034 }; 2035 var OPERATOR_EVALUATORS = { 2036 ">=": (breakpointValue, width) => width >= breakpointValue, 2037 "<": (breakpointValue, width) => width < breakpointValue 2038 }; 2039 var ViewportMatchWidthContext = (0, import_element21.createContext)(null); 2040 ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext"; 2041 var useViewportMatch = (breakpoint, operator = ">=", view = typeof window !== "undefined" ? window : void 0) => { 2042 const simulatedWidth = (0, import_element21.useContext)(ViewportMatchWidthContext); 2043 const mediaQuery = !simulatedWidth && `screen and ($CONDITIONS[operator]}: $BREAKPOINTS[breakpoint]}px)`; 2044 const mediaQueryResult = useMediaQuery(mediaQuery || void 0, view); 2045 if (simulatedWidth) { 2046 return OPERATOR_EVALUATORS[operator]( 2047 BREAKPOINTS[breakpoint], 2048 simulatedWidth 2049 ); 2050 } 2051 return mediaQueryResult; 2052 }; 2053 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider; 2054 var use_viewport_match_default = useViewportMatch; 2055 2056 // packages/compose/build-module/hooks/use-resize-observer/use-resize-observer.mjs 2057 var import_element22 = __toESM(require_element(), 1); 2058 function useResizeObserver(callback, resizeObserverOptions = {}) { 2059 const callbackEvent = useEvent(callback); 2060 const observedElementRef = (0, import_element22.useRef)(null); 2061 const resizeObserverRef = (0, import_element22.useRef)(void 0); 2062 (0, import_element22.useEffect)(() => { 2063 if (observedElementRef.current) { 2064 resizeObserverRef.current?.observe( 2065 observedElementRef.current, 2066 resizeObserverOptions 2067 ); 2068 } 2069 return () => resizeObserverRef.current?.disconnect(); 2070 }, []); 2071 return useEvent((element) => { 2072 if (element === observedElementRef.current) { 2073 return; 2074 } 2075 resizeObserverRef.current ??= new ResizeObserver(callbackEvent); 2076 const { current: resizeObserver } = resizeObserverRef; 2077 if (observedElementRef.current) { 2078 resizeObserver.unobserve(observedElementRef.current); 2079 } 2080 observedElementRef.current = element ?? null; 2081 if (element) { 2082 resizeObserver.observe(element, resizeObserverOptions); 2083 } 2084 }); 2085 } 2086 2087 // packages/compose/build-module/hooks/use-resize-observer/legacy/index.mjs 2088 var import_element23 = __toESM(require_element(), 1); 2089 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1); 2090 var extractSize = (entry) => { 2091 let entrySize; 2092 if (!entry.contentBoxSize) { 2093 entrySize = [entry.contentRect.width, entry.contentRect.height]; 2094 } else if (entry.contentBoxSize[0]) { 2095 const contentBoxSize = entry.contentBoxSize[0]; 2096 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize]; 2097 } else { 2098 const contentBoxSize = entry.contentBoxSize; 2099 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize]; 2100 } 2101 const [width, height] = entrySize.map((d) => Math.round(d)); 2102 return { width, height }; 2103 }; 2104 var RESIZE_ELEMENT_STYLES = { 2105 position: "absolute", 2106 top: 0, 2107 left: 0, 2108 right: 0, 2109 bottom: 0, 2110 pointerEvents: "none", 2111 opacity: 0, 2112 overflow: "hidden", 2113 zIndex: -1 2114 }; 2115 function ResizeElement({ onResize }) { 2116 const resizeElementRef = useResizeObserver((entries) => { 2117 const newSize = extractSize(entries.at(-1)); 2118 onResize(newSize); 2119 }); 2120 return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)( 2121 "div", 2122 { 2123 ref: resizeElementRef, 2124 style: RESIZE_ELEMENT_STYLES, 2125 "aria-hidden": "true" 2126 } 2127 ); 2128 } 2129 function sizeEquals(a, b) { 2130 return a.width === b.width && a.height === b.height; 2131 } 2132 var NULL_SIZE = { width: null, height: null }; 2133 function useLegacyResizeObserver() { 2134 const [size, setSize] = (0, import_element23.useState)(NULL_SIZE); 2135 const previousSizeRef = (0, import_element23.useRef)(NULL_SIZE); 2136 const handleResize = (0, import_element23.useCallback)((newSize) => { 2137 if (!sizeEquals(previousSizeRef.current, newSize)) { 2138 previousSizeRef.current = newSize; 2139 setSize(newSize); 2140 } 2141 }, []); 2142 const resizeElement = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ResizeElement, { onResize: handleResize }); 2143 return [resizeElement, size]; 2144 } 2145 2146 // packages/compose/build-module/hooks/use-resize-observer/index.mjs 2147 function useResizeObserver2(callback, options = {}) { 2148 return callback ? useResizeObserver(callback, options) : useLegacyResizeObserver(); 2149 } 2150 2151 // packages/compose/build-module/hooks/use-async-list/index.mjs 2152 var import_element24 = __toESM(require_element(), 1); 2153 var import_priority_queue = __toESM(require_priority_queue(), 1); 2154 function getFirstItemsPresentInState(list, state) { 2155 const firstItems = []; 2156 for (let i = 0; i < list.length; i++) { 2157 const item = list[i]; 2158 if (!state.includes(item)) { 2159 break; 2160 } 2161 firstItems.push(item); 2162 } 2163 return firstItems; 2164 } 2165 function useAsyncList(list, config = { step: 1 }) { 2166 const { step = 1 } = config; 2167 const [current, setCurrent] = (0, import_element24.useState)([]); 2168 (0, import_element24.useEffect)(() => { 2169 let firstItems = getFirstItemsPresentInState(list, current); 2170 if (firstItems.length < step) { 2171 firstItems = firstItems.concat( 2172 list.slice(firstItems.length, step) 2173 ); 2174 } 2175 setCurrent(firstItems); 2176 const asyncQueue = (0, import_priority_queue.createQueue)(); 2177 for (let i = firstItems.length; i < list.length; i += step) { 2178 asyncQueue.add({}, () => { 2179 (0, import_element24.flushSync)(() => { 2180 setCurrent((state) => [ 2181 ...state, 2182 ...list.slice(i, i + step) 2183 ]); 2184 }); 2185 }); 2186 } 2187 return () => asyncQueue.reset(); 2188 }, [list]); 2189 return current; 2190 } 2191 var use_async_list_default = useAsyncList; 2192 2193 // packages/compose/build-module/hooks/use-warn-on-change/index.mjs 2194 function useWarnOnChange(object, prefix = "Change detection") { 2195 const previousValues = usePrevious(object); 2196 Object.entries(previousValues ?? []).forEach(([key, value]) => { 2197 if (value !== object[key]) { 2198 console.warn( 2199 `$prefix}: $key} key changed:`, 2200 value, 2201 object[key] 2202 ); 2203 } 2204 }); 2205 } 2206 var use_warn_on_change_default = useWarnOnChange; 2207 2208 // packages/compose/build-module/hooks/use-debounce/index.mjs 2209 var import_element25 = __toESM(require_element(), 1); 2210 function useDebounce(fn, wait, options) { 2211 const debounced = (0, import_element25.useMemo)( 2212 () => debounce(fn, wait ?? 0, options), 2213 // Depends on the individual options rather than the `options` object. 2214 // eslint-disable-next-line react-hooks/exhaustive-deps 2215 [fn, wait, options?.leading, options?.trailing, options?.maxWait] 2216 ); 2217 (0, import_element25.useEffect)(() => () => debounced.cancel(), [debounced]); 2218 return debounced; 2219 } 2220 2221 // packages/compose/build-module/hooks/use-debounced-input/index.mjs 2222 var import_element26 = __toESM(require_element(), 1); 2223 function useDebouncedInput(defaultValue = "") { 2224 const [input, setInput] = (0, import_element26.useState)(defaultValue); 2225 const [debouncedInput, setDebouncedState] = (0, import_element26.useState)(defaultValue); 2226 const setDebouncedInput = useDebounce(setDebouncedState, 250); 2227 (0, import_element26.useEffect)(() => { 2228 setDebouncedInput(input); 2229 }, [input, setDebouncedInput]); 2230 return [input, setInput, debouncedInput]; 2231 } 2232 2233 // packages/compose/build-module/hooks/use-throttle/index.mjs 2234 var import_element27 = __toESM(require_element(), 1); 2235 function useThrottle(fn, wait, options) { 2236 const throttled = (0, import_element27.useMemo)( 2237 () => throttle(fn, wait ?? 0, options), 2238 [fn, wait, options] 2239 ); 2240 (0, import_element27.useEffect)(() => () => throttled.cancel(), [throttled]); 2241 return throttled; 2242 } 2243 2244 // packages/compose/build-module/hooks/use-drop-zone/index.mjs 2245 function useDropZone({ 2246 dropZoneElement, 2247 isDisabled, 2248 onDrop: _onDrop, 2249 onDragStart: _onDragStart, 2250 onDragEnter: _onDragEnter, 2251 onDragLeave: _onDragLeave, 2252 onDragEnd: _onDragEnd, 2253 onDragOver: _onDragOver 2254 }) { 2255 const onDropEvent = useEvent(_onDrop); 2256 const onDragStartEvent = useEvent(_onDragStart); 2257 const onDragEnterEvent = useEvent(_onDragEnter); 2258 const onDragLeaveEvent = useEvent(_onDragLeave); 2259 const onDragEndEvent = useEvent(_onDragEnd); 2260 const onDragOverEvent = useEvent(_onDragOver); 2261 return useRefEffect( 2262 (elem) => { 2263 if (isDisabled) { 2264 return; 2265 } 2266 const element = dropZoneElement ?? elem; 2267 let isDragging = false; 2268 const { ownerDocument } = element; 2269 function isElementInZone(targetToCheck) { 2270 const { defaultView } = ownerDocument; 2271 if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) { 2272 return false; 2273 } 2274 let elementToCheck = targetToCheck; 2275 do { 2276 if (elementToCheck.dataset.isDropZone) { 2277 return elementToCheck === element; 2278 } 2279 } while (elementToCheck = elementToCheck.parentElement); 2280 return false; 2281 } 2282 function maybeDragStart(event) { 2283 if (isDragging) { 2284 return; 2285 } 2286 isDragging = true; 2287 ownerDocument.addEventListener("dragend", maybeDragEnd); 2288 ownerDocument.addEventListener("mousemove", maybeDragEnd); 2289 if (_onDragStart) { 2290 onDragStartEvent(event); 2291 } 2292 } 2293 function onDragEnter(event) { 2294 event.preventDefault(); 2295 if (element.contains(event.relatedTarget)) { 2296 return; 2297 } 2298 if (_onDragEnter) { 2299 onDragEnterEvent(event); 2300 } 2301 } 2302 function onDragOver(event) { 2303 if (!event.defaultPrevented && _onDragOver) { 2304 onDragOverEvent(event); 2305 } 2306 event.preventDefault(); 2307 } 2308 function onDragLeave(event) { 2309 if (isElementInZone(event.relatedTarget)) { 2310 return; 2311 } 2312 if (_onDragLeave) { 2313 onDragLeaveEvent(event); 2314 } 2315 } 2316 function onDrop(event) { 2317 if (event.defaultPrevented) { 2318 return; 2319 } 2320 event.preventDefault(); 2321 event.dataTransfer && event.dataTransfer.files.length; 2322 if (_onDrop) { 2323 onDropEvent(event); 2324 } 2325 maybeDragEnd(event); 2326 } 2327 function maybeDragEnd(event) { 2328 if (!isDragging) { 2329 return; 2330 } 2331 isDragging = false; 2332 ownerDocument.removeEventListener("dragend", maybeDragEnd); 2333 ownerDocument.removeEventListener("mousemove", maybeDragEnd); 2334 if (_onDragEnd) { 2335 onDragEndEvent(event); 2336 } 2337 } 2338 element.setAttribute("data-is-drop-zone", "true"); 2339 element.addEventListener("drop", onDrop); 2340 element.addEventListener("dragenter", onDragEnter); 2341 element.addEventListener("dragover", onDragOver); 2342 element.addEventListener("dragleave", onDragLeave); 2343 ownerDocument.addEventListener("dragenter", maybeDragStart); 2344 return () => { 2345 element.removeAttribute("data-is-drop-zone"); 2346 element.removeEventListener("drop", onDrop); 2347 element.removeEventListener("dragenter", onDragEnter); 2348 element.removeEventListener("dragover", onDragOver); 2349 element.removeEventListener("dragleave", onDragLeave); 2350 ownerDocument.removeEventListener("dragend", maybeDragEnd); 2351 ownerDocument.removeEventListener("mousemove", maybeDragEnd); 2352 ownerDocument.removeEventListener( 2353 "dragenter", 2354 maybeDragStart 2355 ); 2356 }; 2357 }, 2358 [isDisabled, dropZoneElement] 2359 // Refresh when the passed in dropZoneElement changes. 2360 ); 2361 } 2362 2363 // packages/compose/build-module/hooks/use-focusable-iframe/index.mjs 2364 function useFocusableIframe() { 2365 return useRefEffect((element) => { 2366 const { ownerDocument } = element; 2367 if (!ownerDocument) { 2368 return; 2369 } 2370 const { defaultView } = ownerDocument; 2371 if (!defaultView) { 2372 return; 2373 } 2374 function checkFocus() { 2375 if (ownerDocument && ownerDocument.activeElement === element) { 2376 element.focus(); 2377 } 2378 } 2379 defaultView.addEventListener("blur", checkFocus); 2380 return () => { 2381 defaultView.removeEventListener("blur", checkFocus); 2382 }; 2383 }, []); 2384 } 2385 2386 // packages/compose/build-module/hooks/use-fixed-window-list/index.mjs 2387 var import_element28 = __toESM(require_element(), 1); 2388 var import_dom3 = __toESM(require_dom(), 1); 2389 var import_keycodes2 = __toESM(require_keycodes(), 1); 2390 var DEFAULT_INIT_WINDOW_SIZE = 30; 2391 function useFixedWindowList(elementRef, itemHeight, totalItems, options) { 2392 const { 2393 windowOverscan, 2394 useWindowing = true, 2395 initWindowSize = DEFAULT_INIT_WINDOW_SIZE, 2396 expandedState 2397 } = options ?? {}; 2398 const [fixedListWindow, setFixedListWindow] = (0, import_element28.useState)( 2399 { 2400 visibleItems: initWindowSize, 2401 start: 0, 2402 end: initWindowSize, 2403 itemInView: (index) => { 2404 return index >= 0 && index <= initWindowSize; 2405 } 2406 } 2407 ); 2408 const visibleItemsRef = (0, import_element28.useRef)(initWindowSize); 2409 const isFirstMeasurementRef = (0, import_element28.useRef)(true); 2410 const measureWindow = useEvent((initRender) => { 2411 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current); 2412 if (!scrollContainer) { 2413 return; 2414 } 2415 const visibleItems = Math.ceil( 2416 scrollContainer.clientHeight / itemHeight 2417 ); 2418 visibleItemsRef.current = visibleItems; 2419 const isFirstMeasurement = isFirstMeasurementRef.current; 2420 isFirstMeasurementRef.current = false; 2421 const overscan = initRender ? visibleItems : windowOverscan ?? visibleItems; 2422 const firstViewableIndex = Math.floor( 2423 scrollContainer.scrollTop / itemHeight 2424 ); 2425 const start = Math.max(0, firstViewableIndex - overscan); 2426 const end = Math.min( 2427 totalItems - 1, 2428 firstViewableIndex + visibleItems + overscan 2429 ); 2430 setFixedListWindow((lastWindow) => { 2431 if (lastWindow.start <= start && lastWindow.end >= end) { 2432 return lastWindow; 2433 } 2434 if (isFirstMeasurement && lastWindow.start <= firstViewableIndex && lastWindow.end >= firstViewableIndex + visibleItems) { 2435 return lastWindow; 2436 } 2437 return { 2438 visibleItems, 2439 start, 2440 end, 2441 itemInView: (index) => { 2442 return start <= index && index <= end; 2443 } 2444 }; 2445 }); 2446 }); 2447 const handleKeyDown = useEvent( 2448 (event, scrollContainer) => { 2449 switch (event.keyCode) { 2450 case import_keycodes2.HOME: { 2451 return scrollContainer.scrollTo({ top: 0 }); 2452 } 2453 case import_keycodes2.END: { 2454 return scrollContainer.scrollTo({ 2455 top: totalItems * itemHeight 2456 }); 2457 } 2458 case import_keycodes2.PAGEUP: { 2459 return scrollContainer.scrollTo({ 2460 top: scrollContainer.scrollTop - visibleItemsRef.current * itemHeight 2461 }); 2462 } 2463 case import_keycodes2.PAGEDOWN: { 2464 return scrollContainer.scrollTo({ 2465 top: scrollContainer.scrollTop + visibleItemsRef.current * itemHeight 2466 }); 2467 } 2468 } 2469 } 2470 ); 2471 (0, import_element28.useLayoutEffect)(() => { 2472 if (!useWindowing) { 2473 return; 2474 } 2475 measureWindow(true); 2476 }, [ 2477 useWindowing, 2478 measureWindow, 2479 itemHeight, 2480 totalItems, 2481 windowOverscan, 2482 expandedState 2483 ]); 2484 (0, import_element28.useLayoutEffect)(() => { 2485 if (!useWindowing) { 2486 return; 2487 } 2488 const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current); 2489 if (!scrollContainer) { 2490 return; 2491 } 2492 const { defaultView } = scrollContainer.ownerDocument; 2493 const onMeasure = () => measureWindow(); 2494 const onKeyDown = (event) => handleKeyDown(event, scrollContainer); 2495 scrollContainer.addEventListener("scroll", onMeasure); 2496 defaultView?.addEventListener("resize", onMeasure); 2497 defaultView?.addEventListener("keydown", onKeyDown); 2498 return () => { 2499 scrollContainer.removeEventListener("scroll", onMeasure); 2500 defaultView?.removeEventListener("resize", onMeasure); 2501 defaultView?.removeEventListener("keydown", onKeyDown); 2502 }; 2503 }, [ 2504 useWindowing, 2505 elementRef, 2506 itemHeight, 2507 totalItems, 2508 expandedState, 2509 measureWindow, 2510 handleKeyDown 2511 ]); 2512 return [fixedListWindow, setFixedListWindow]; 2513 } 2514 2515 // packages/compose/build-module/hooks/use-observable-value/index.mjs 2516 var import_element29 = __toESM(require_element(), 1); 2517 function useObservableValue(map, name) { 2518 const [subscribe, getValue] = (0, import_element29.useMemo)( 2519 () => [ 2520 (listener2) => map.subscribe(name, listener2), 2521 () => map.get(name) 2522 ], 2523 [map, name] 2524 ); 2525 return (0, import_element29.useSyncExternalStore)(subscribe, getValue, getValue); 2526 } 2527 return __toCommonJS(index_exports); 2528 })(); 2529 (window.wp ||= {}).compose = wp.compose; 2530 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Nov 4 08:20:38 2026 | Cross-referenced by PHPXref |