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