| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ var __webpack_modules__ = ({ |
| 3 |
|
| 4 |
/***/ 1933: |
| 5 |
/***/ ((module, exports, __webpack_require__) => { |
| 6 |
|
| 7 |
var __WEBPACK_AMD_DEFINE_RESULT__;/*global define:false */ |
| 8 |
/** |
| 9 |
* Copyright 2012-2017 Craig Campbell |
| 10 |
* |
| 11 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 |
* you may not use this file except in compliance with the License. |
| 13 |
* You may obtain a copy of the License at |
| 14 |
* |
| 15 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 16 |
* |
| 17 |
* Unless required by applicable law or agreed to in writing, software |
| 18 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 19 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 |
* See the License for the specific language governing permissions and |
| 21 |
* limitations under the License. |
| 22 |
* |
| 23 |
* Mousetrap is a simple keyboard shortcut library for Javascript with |
| 24 |
* no external dependencies |
| 25 |
* |
| 26 |
* @version 1.6.5 |
| 27 |
* @url craig.is/killing/mice |
| 28 |
*/ |
| 29 |
(function(window, document, undefined) { |
| 30 |
|
| 31 |
// Check if mousetrap is used inside browser, if not, return |
| 32 |
if (!window) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* mapping of special keycodes to their corresponding keys |
| 38 |
* |
| 39 |
* everything in this dictionary cannot use keypress events |
| 40 |
* so it has to be here to map to the correct keycodes for |
| 41 |
* keyup/keydown events |
| 42 |
* |
| 43 |
* @type {Object} |
| 44 |
*/ |
| 45 |
var _MAP = { |
| 46 |
8: 'backspace', |
| 47 |
9: 'tab', |
| 48 |
13: 'enter', |
| 49 |
16: 'shift', |
| 50 |
17: 'ctrl', |
| 51 |
18: 'alt', |
| 52 |
20: 'capslock', |
| 53 |
27: 'esc', |
| 54 |
32: 'space', |
| 55 |
33: 'pageup', |
| 56 |
34: 'pagedown', |
| 57 |
35: 'end', |
| 58 |
36: 'home', |
| 59 |
37: 'left', |
| 60 |
38: 'up', |
| 61 |
39: 'right', |
| 62 |
40: 'down', |
| 63 |
45: 'ins', |
| 64 |
46: 'del', |
| 65 |
91: 'meta', |
| 66 |
93: 'meta', |
| 67 |
224: 'meta' |
| 68 |
}; |
| 69 |
|
| 70 |
/** |
| 71 |
* mapping for special characters so they can support |
| 72 |
* |
| 73 |
* this dictionary is only used incase you want to bind a |
| 74 |
* keyup or keydown event to one of these keys |
| 75 |
* |
| 76 |
* @type {Object} |
| 77 |
*/ |
| 78 |
var _KEYCODE_MAP = { |
| 79 |
106: '*', |
| 80 |
107: '+', |
| 81 |
109: '-', |
| 82 |
110: '.', |
| 83 |
111 : '/', |
| 84 |
186: ';', |
| 85 |
187: '=', |
| 86 |
188: ',', |
| 87 |
189: '-', |
| 88 |
190: '.', |
| 89 |
191: '/', |
| 90 |
192: '`', |
| 91 |
219: '[', |
| 92 |
220: '\\', |
| 93 |
221: ']', |
| 94 |
222: '\'' |
| 95 |
}; |
| 96 |
|
| 97 |
/** |
| 98 |
* this is a mapping of keys that require shift on a US keypad |
| 99 |
* back to the non shift equivelents |
| 100 |
* |
| 101 |
* this is so you can use keyup events with these keys |
| 102 |
* |
| 103 |
* note that this will only work reliably on US keyboards |
| 104 |
* |
| 105 |
* @type {Object} |
| 106 |
*/ |
| 107 |
var _SHIFT_MAP = { |
| 108 |
'~': '`', |
| 109 |
'!': '1', |
| 110 |
'@': '2', |
| 111 |
'#': '3', |
| 112 |
'$': '4', |
| 113 |
'%': '5', |
| 114 |
'^': '6', |
| 115 |
'&': '7', |
| 116 |
'*': '8', |
| 117 |
'(': '9', |
| 118 |
')': '0', |
| 119 |
'_': '-', |
| 120 |
'+': '=', |
| 121 |
':': ';', |
| 122 |
'\"': '\'', |
| 123 |
'<': ',', |
| 124 |
'>': '.', |
| 125 |
'?': '/', |
| 126 |
'|': '\\' |
| 127 |
}; |
| 128 |
|
| 129 |
/** |
| 130 |
* this is a list of special strings you can use to map |
| 131 |
* to modifier keys when you specify your keyboard shortcuts |
| 132 |
* |
| 133 |
* @type {Object} |
| 134 |
*/ |
| 135 |
var _SPECIAL_ALIASES = { |
| 136 |
'option': 'alt', |
| 137 |
'command': 'meta', |
| 138 |
'return': 'enter', |
| 139 |
'escape': 'esc', |
| 140 |
'plus': '+', |
| 141 |
'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl' |
| 142 |
}; |
| 143 |
|
| 144 |
/** |
| 145 |
* variable to store the flipped version of _MAP from above |
| 146 |
* needed to check if we should use keypress or not when no action |
| 147 |
* is specified |
| 148 |
* |
| 149 |
* @type {Object|undefined} |
| 150 |
*/ |
| 151 |
var _REVERSE_MAP; |
| 152 |
|
| 153 |
/** |
| 154 |
* loop through the f keys, f1 to f19 and add them to the map |
| 155 |
* programatically |
| 156 |
*/ |
| 157 |
for (var i = 1; i < 20; ++i) { |
| 158 |
_MAP[111 + i] = 'f' + i; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* loop through to map numbers on the numeric keypad |
| 163 |
*/ |
| 164 |
for (i = 0; i <= 9; ++i) { |
| 165 |
|
| 166 |
// This needs to use a string cause otherwise since 0 is falsey |
| 167 |
// mousetrap will never fire for numpad 0 pressed as part of a keydown |
| 168 |
// event. |
| 169 |
// |
| 170 |
// @see https://github.com/ccampbell/mousetrap/pull/258 |
| 171 |
_MAP[i + 96] = i.toString(); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* cross browser add event method |
| 176 |
* |
| 177 |
* @param {Element|HTMLDocument} object |
| 178 |
* @param {string} type |
| 179 |
* @param {Function} callback |
| 180 |
* @returns void |
| 181 |
*/ |
| 182 |
function _addEvent(object, type, callback) { |
| 183 |
if (object.addEventListener) { |
| 184 |
object.addEventListener(type, callback, false); |
| 185 |
return; |
| 186 |
} |
| 187 |
|
| 188 |
object.attachEvent('on' + type, callback); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* takes the event and returns the key character |
| 193 |
* |
| 194 |
* @param {Event} e |
| 195 |
* @return {string} |
| 196 |
*/ |
| 197 |
function _characterFromEvent(e) { |
| 198 |
|
| 199 |
// for keypress events we should return the character as is |
| 200 |
if (e.type == 'keypress') { |
| 201 |
var character = String.fromCharCode(e.which); |
| 202 |
|
| 203 |
// if the shift key is not pressed then it is safe to assume |
| 204 |
// that we want the character to be lowercase. this means if |
| 205 |
// you accidentally have caps lock on then your key bindings |
| 206 |
// will continue to work |
| 207 |
// |
| 208 |
// the only side effect that might not be desired is if you |
| 209 |
// bind something like 'A' cause you want to trigger an |
| 210 |
// event when capital A is pressed caps lock will no longer |
| 211 |
// trigger the event. shift+a will though. |
| 212 |
if (!e.shiftKey) { |
| 213 |
character = character.toLowerCase(); |
| 214 |
} |
| 215 |
|
| 216 |
return character; |
| 217 |
} |
| 218 |
|
| 219 |
// for non keypress events the special maps are needed |
| 220 |
if (_MAP[e.which]) { |
| 221 |
return _MAP[e.which]; |
| 222 |
} |
| 223 |
|
| 224 |
if (_KEYCODE_MAP[e.which]) { |
| 225 |
return _KEYCODE_MAP[e.which]; |
| 226 |
} |
| 227 |
|
| 228 |
// if it is not in the special map |
| 229 |
|
| 230 |
// with keydown and keyup events the character seems to always |
| 231 |
// come in as an uppercase character whether you are pressing shift |
| 232 |
// or not. we should make sure it is always lowercase for comparisons |
| 233 |
return String.fromCharCode(e.which).toLowerCase(); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* checks if two arrays are equal |
| 238 |
* |
| 239 |
* @param {Array} modifiers1 |
| 240 |
* @param {Array} modifiers2 |
| 241 |
* @returns {boolean} |
| 242 |
*/ |
| 243 |
function _modifiersMatch(modifiers1, modifiers2) { |
| 244 |
return modifiers1.sort().join(',') === modifiers2.sort().join(','); |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* takes a key event and figures out what the modifiers are |
| 249 |
* |
| 250 |
* @param {Event} e |
| 251 |
* @returns {Array} |
| 252 |
*/ |
| 253 |
function _eventModifiers(e) { |
| 254 |
var modifiers = []; |
| 255 |
|
| 256 |
if (e.shiftKey) { |
| 257 |
modifiers.push('shift'); |
| 258 |
} |
| 259 |
|
| 260 |
if (e.altKey) { |
| 261 |
modifiers.push('alt'); |
| 262 |
} |
| 263 |
|
| 264 |
if (e.ctrlKey) { |
| 265 |
modifiers.push('ctrl'); |
| 266 |
} |
| 267 |
|
| 268 |
if (e.metaKey) { |
| 269 |
modifiers.push('meta'); |
| 270 |
} |
| 271 |
|
| 272 |
return modifiers; |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* prevents default for this event |
| 277 |
* |
| 278 |
* @param {Event} e |
| 279 |
* @returns void |
| 280 |
*/ |
| 281 |
function _preventDefault(e) { |
| 282 |
if (e.preventDefault) { |
| 283 |
e.preventDefault(); |
| 284 |
return; |
| 285 |
} |
| 286 |
|
| 287 |
e.returnValue = false; |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* stops propogation for this event |
| 292 |
* |
| 293 |
* @param {Event} e |
| 294 |
* @returns void |
| 295 |
*/ |
| 296 |
function _stopPropagation(e) { |
| 297 |
if (e.stopPropagation) { |
| 298 |
e.stopPropagation(); |
| 299 |
return; |
| 300 |
} |
| 301 |
|
| 302 |
e.cancelBubble = true; |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* determines if the keycode specified is a modifier key or not |
| 307 |
* |
| 308 |
* @param {string} key |
| 309 |
* @returns {boolean} |
| 310 |
*/ |
| 311 |
function _isModifier(key) { |
| 312 |
return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta'; |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* reverses the map lookup so that we can look for specific keys |
| 317 |
* to see what can and can't use keypress |
| 318 |
* |
| 319 |
* @return {Object} |
| 320 |
*/ |
| 321 |
function _getReverseMap() { |
| 322 |
if (!_REVERSE_MAP) { |
| 323 |
_REVERSE_MAP = {}; |
| 324 |
for (var key in _MAP) { |
| 325 |
|
| 326 |
// pull out the numeric keypad from here cause keypress should |
| 327 |
// be able to detect the keys from the character |
| 328 |
if (key > 95 && key < 112) { |
| 329 |
continue; |
| 330 |
} |
| 331 |
|
| 332 |
if (_MAP.hasOwnProperty(key)) { |
| 333 |
_REVERSE_MAP[_MAP[key]] = key; |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
return _REVERSE_MAP; |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* picks the best action based on the key combination |
| 342 |
* |
| 343 |
* @param {string} key - character for key |
| 344 |
* @param {Array} modifiers |
| 345 |
* @param {string=} action passed in |
| 346 |
*/ |
| 347 |
function _pickBestAction(key, modifiers, action) { |
| 348 |
|
| 349 |
// if no action was picked in we should try to pick the one |
| 350 |
// that we think would work best for this key |
| 351 |
if (!action) { |
| 352 |
action = _getReverseMap()[key] ? 'keydown' : 'keypress'; |
| 353 |
} |
| 354 |
|
| 355 |
// modifier keys don't work as expected with keypress, |
| 356 |
// switch to keydown |
| 357 |
if (action == 'keypress' && modifiers.length) { |
| 358 |
action = 'keydown'; |
| 359 |
} |
| 360 |
|
| 361 |
return action; |
| 362 |
} |
| 363 |
|
| 364 |
/** |
| 365 |
* Converts from a string key combination to an array |
| 366 |
* |
| 367 |
* @param {string} combination like "command+shift+l" |
| 368 |
* @return {Array} |
| 369 |
*/ |
| 370 |
function _keysFromString(combination) { |
| 371 |
if (combination === '+') { |
| 372 |
return ['+']; |
| 373 |
} |
| 374 |
|
| 375 |
combination = combination.replace(/\+{2}/g, '+plus'); |
| 376 |
return combination.split('+'); |
| 377 |
} |
| 378 |
|
| 379 |
/** |
| 380 |
* Gets info for a specific key combination |
| 381 |
* |
| 382 |
* @param {string} combination key combination ("command+s" or "a" or "*") |
| 383 |
* @param {string=} action |
| 384 |
* @returns {Object} |
| 385 |
*/ |
| 386 |
function _getKeyInfo(combination, action) { |
| 387 |
var keys; |
| 388 |
var key; |
| 389 |
var i; |
| 390 |
var modifiers = []; |
| 391 |
|
| 392 |
// take the keys from this pattern and figure out what the actual |
| 393 |
// pattern is all about |
| 394 |
keys = _keysFromString(combination); |
| 395 |
|
| 396 |
for (i = 0; i < keys.length; ++i) { |
| 397 |
key = keys[i]; |
| 398 |
|
| 399 |
// normalize key names |
| 400 |
if (_SPECIAL_ALIASES[key]) { |
| 401 |
key = _SPECIAL_ALIASES[key]; |
| 402 |
} |
| 403 |
|
| 404 |
// if this is not a keypress event then we should |
| 405 |
// be smart about using shift keys |
| 406 |
// this will only work for US keyboards however |
| 407 |
if (action && action != 'keypress' && _SHIFT_MAP[key]) { |
| 408 |
key = _SHIFT_MAP[key]; |
| 409 |
modifiers.push('shift'); |
| 410 |
} |
| 411 |
|
| 412 |
// if this key is a modifier then add it to the list of modifiers |
| 413 |
if (_isModifier(key)) { |
| 414 |
modifiers.push(key); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
// depending on what the key combination is |
| 419 |
// we will try to pick the best event for it |
| 420 |
action = _pickBestAction(key, modifiers, action); |
| 421 |
|
| 422 |
return { |
| 423 |
key: key, |
| 424 |
modifiers: modifiers, |
| 425 |
action: action |
| 426 |
}; |
| 427 |
} |
| 428 |
|
| 429 |
function _belongsTo(element, ancestor) { |
| 430 |
if (element === null || element === document) { |
| 431 |
return false; |
| 432 |
} |
| 433 |
|
| 434 |
if (element === ancestor) { |
| 435 |
return true; |
| 436 |
} |
| 437 |
|
| 438 |
return _belongsTo(element.parentNode, ancestor); |
| 439 |
} |
| 440 |
|
| 441 |
function Mousetrap(targetElement) { |
| 442 |
var self = this; |
| 443 |
|
| 444 |
targetElement = targetElement || document; |
| 445 |
|
| 446 |
if (!(self instanceof Mousetrap)) { |
| 447 |
return new Mousetrap(targetElement); |
| 448 |
} |
| 449 |
|
| 450 |
/** |
| 451 |
* element to attach key events to |
| 452 |
* |
| 453 |
* @type {Element} |
| 454 |
*/ |
| 455 |
self.target = targetElement; |
| 456 |
|
| 457 |
/** |
| 458 |
* a list of all the callbacks setup via Mousetrap.bind() |
| 459 |
* |
| 460 |
* @type {Object} |
| 461 |
*/ |
| 462 |
self._callbacks = {}; |
| 463 |
|
| 464 |
/** |
| 465 |
* direct map of string combinations to callbacks used for trigger() |
| 466 |
* |
| 467 |
* @type {Object} |
| 468 |
*/ |
| 469 |
self._directMap = {}; |
| 470 |
|
| 471 |
/** |
| 472 |
* keeps track of what level each sequence is at since multiple |
| 473 |
* sequences can start out with the same sequence |
| 474 |
* |
| 475 |
* @type {Object} |
| 476 |
*/ |
| 477 |
var _sequenceLevels = {}; |
| 478 |
|
| 479 |
/** |
| 480 |
* variable to store the setTimeout call |
| 481 |
* |
| 482 |
* @type {null|number} |
| 483 |
*/ |
| 484 |
var _resetTimer; |
| 485 |
|
| 486 |
/** |
| 487 |
* temporary state where we will ignore the next keyup |
| 488 |
* |
| 489 |
* @type {boolean|string} |
| 490 |
*/ |
| 491 |
var _ignoreNextKeyup = false; |
| 492 |
|
| 493 |
/** |
| 494 |
* temporary state where we will ignore the next keypress |
| 495 |
* |
| 496 |
* @type {boolean} |
| 497 |
*/ |
| 498 |
var _ignoreNextKeypress = false; |
| 499 |
|
| 500 |
/** |
| 501 |
* are we currently inside of a sequence? |
| 502 |
* type of action ("keyup" or "keydown" or "keypress") or false |
| 503 |
* |
| 504 |
* @type {boolean|string} |
| 505 |
*/ |
| 506 |
var _nextExpectedAction = false; |
| 507 |
|
| 508 |
/** |
| 509 |
* resets all sequence counters except for the ones passed in |
| 510 |
* |
| 511 |
* @param {Object} doNotReset |
| 512 |
* @returns void |
| 513 |
*/ |
| 514 |
function _resetSequences(doNotReset) { |
| 515 |
doNotReset = doNotReset || {}; |
| 516 |
|
| 517 |
var activeSequences = false, |
| 518 |
key; |
| 519 |
|
| 520 |
for (key in _sequenceLevels) { |
| 521 |
if (doNotReset[key]) { |
| 522 |
activeSequences = true; |
| 523 |
continue; |
| 524 |
} |
| 525 |
_sequenceLevels[key] = 0; |
| 526 |
} |
| 527 |
|
| 528 |
if (!activeSequences) { |
| 529 |
_nextExpectedAction = false; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
/** |
| 534 |
* finds all callbacks that match based on the keycode, modifiers, |
| 535 |
* and action |
| 536 |
* |
| 537 |
* @param {string} character |
| 538 |
* @param {Array} modifiers |
| 539 |
* @param {Event|Object} e |
| 540 |
* @param {string=} sequenceName - name of the sequence we are looking for |
| 541 |
* @param {string=} combination |
| 542 |
* @param {number=} level |
| 543 |
* @returns {Array} |
| 544 |
*/ |
| 545 |
function _getMatches(character, modifiers, e, sequenceName, combination, level) { |
| 546 |
var i; |
| 547 |
var callback; |
| 548 |
var matches = []; |
| 549 |
var action = e.type; |
| 550 |
|
| 551 |
// if there are no events related to this keycode |
| 552 |
if (!self._callbacks[character]) { |
| 553 |
return []; |
| 554 |
} |
| 555 |
|
| 556 |
// if a modifier key is coming up on its own we should allow it |
| 557 |
if (action == 'keyup' && _isModifier(character)) { |
| 558 |
modifiers = [character]; |
| 559 |
} |
| 560 |
|
| 561 |
// loop through all callbacks for the key that was pressed |
| 562 |
// and see if any of them match |
| 563 |
for (i = 0; i < self._callbacks[character].length; ++i) { |
| 564 |
callback = self._callbacks[character][i]; |
| 565 |
|
| 566 |
// if a sequence name is not specified, but this is a sequence at |
| 567 |
// the wrong level then move onto the next match |
| 568 |
if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) { |
| 569 |
continue; |
| 570 |
} |
| 571 |
|
| 572 |
// if the action we are looking for doesn't match the action we got |
| 573 |
// then we should keep going |
| 574 |
if (action != callback.action) { |
| 575 |
continue; |
| 576 |
} |
| 577 |
|
| 578 |
// if this is a keypress event and the meta key and control key |
| 579 |
// are not pressed that means that we need to only look at the |
| 580 |
// character, otherwise check the modifiers as well |
| 581 |
// |
| 582 |
// chrome will not fire a keypress if meta or control is down |
| 583 |
// safari will fire a keypress if meta or meta+shift is down |
| 584 |
// firefox will fire a keypress if meta or control is down |
| 585 |
if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) { |
| 586 |
|
| 587 |
// when you bind a combination or sequence a second time it |
| 588 |
// should overwrite the first one. if a sequenceName or |
| 589 |
// combination is specified in this call it does just that |
| 590 |
// |
| 591 |
// @todo make deleting its own method? |
| 592 |
var deleteCombo = !sequenceName && callback.combo == combination; |
| 593 |
var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level; |
| 594 |
if (deleteCombo || deleteSequence) { |
| 595 |
self._callbacks[character].splice(i, 1); |
| 596 |
} |
| 597 |
|
| 598 |
matches.push(callback); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
return matches; |
| 603 |
} |
| 604 |
|
| 605 |
/** |
| 606 |
* actually calls the callback function |
| 607 |
* |
| 608 |
* if your callback function returns false this will use the jquery |
| 609 |
* convention - prevent default and stop propogation on the event |
| 610 |
* |
| 611 |
* @param {Function} callback |
| 612 |
* @param {Event} e |
| 613 |
* @returns void |
| 614 |
*/ |
| 615 |
function _fireCallback(callback, e, combo, sequence) { |
| 616 |
|
| 617 |
// if this event should not happen stop here |
| 618 |
if (self.stopCallback(e, e.target || e.srcElement, combo, sequence)) { |
| 619 |
return; |
| 620 |
} |
| 621 |
|
| 622 |
if (callback(e, combo) === false) { |
| 623 |
_preventDefault(e); |
| 624 |
_stopPropagation(e); |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
/** |
| 629 |
* handles a character key event |
| 630 |
* |
| 631 |
* @param {string} character |
| 632 |
* @param {Array} modifiers |
| 633 |
* @param {Event} e |
| 634 |
* @returns void |
| 635 |
*/ |
| 636 |
self._handleKey = function(character, modifiers, e) { |
| 637 |
var callbacks = _getMatches(character, modifiers, e); |
| 638 |
var i; |
| 639 |
var doNotReset = {}; |
| 640 |
var maxLevel = 0; |
| 641 |
var processedSequenceCallback = false; |
| 642 |
|
| 643 |
// Calculate the maxLevel for sequences so we can only execute the longest callback sequence |
| 644 |
for (i = 0; i < callbacks.length; ++i) { |
| 645 |
if (callbacks[i].seq) { |
| 646 |
maxLevel = Math.max(maxLevel, callbacks[i].level); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
// loop through matching callbacks for this key event |
| 651 |
for (i = 0; i < callbacks.length; ++i) { |
| 652 |
|
| 653 |
// fire for all sequence callbacks |
| 654 |
// this is because if for example you have multiple sequences |
| 655 |
// bound such as "g i" and "g t" they both need to fire the |
| 656 |
// callback for matching g cause otherwise you can only ever |
| 657 |
// match the first one |
| 658 |
if (callbacks[i].seq) { |
| 659 |
|
| 660 |
// only fire callbacks for the maxLevel to prevent |
| 661 |
// subsequences from also firing |
| 662 |
// |
| 663 |
// for example 'a option b' should not cause 'option b' to fire |
| 664 |
// even though 'option b' is part of the other sequence |
| 665 |
// |
| 666 |
// any sequences that do not match here will be discarded |
| 667 |
// below by the _resetSequences call |
| 668 |
if (callbacks[i].level != maxLevel) { |
| 669 |
continue; |
| 670 |
} |
| 671 |
|
| 672 |
processedSequenceCallback = true; |
| 673 |
|
| 674 |
// keep a list of which sequences were matches for later |
| 675 |
doNotReset[callbacks[i].seq] = 1; |
| 676 |
_fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq); |
| 677 |
continue; |
| 678 |
} |
| 679 |
|
| 680 |
// if there were no sequence matches but we are still here |
| 681 |
// that means this is a regular match so we should fire that |
| 682 |
if (!processedSequenceCallback) { |
| 683 |
_fireCallback(callbacks[i].callback, e, callbacks[i].combo); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
// if the key you pressed matches the type of sequence without |
| 688 |
// being a modifier (ie "keyup" or "keypress") then we should |
| 689 |
// reset all sequences that were not matched by this event |
| 690 |
// |
| 691 |
// this is so, for example, if you have the sequence "h a t" and you |
| 692 |
// type "h e a r t" it does not match. in this case the "e" will |
| 693 |
// cause the sequence to reset |
| 694 |
// |
| 695 |
// modifier keys are ignored because you can have a sequence |
| 696 |
// that contains modifiers such as "enter ctrl+space" and in most |
| 697 |
// cases the modifier key will be pressed before the next key |
| 698 |
// |
| 699 |
// also if you have a sequence such as "ctrl+b a" then pressing the |
| 700 |
// "b" key will trigger a "keypress" and a "keydown" |
| 701 |
// |
| 702 |
// the "keydown" is expected when there is a modifier, but the |
| 703 |
// "keypress" ends up matching the _nextExpectedAction since it occurs |
| 704 |
// after and that causes the sequence to reset |
| 705 |
// |
| 706 |
// we ignore keypresses in a sequence that directly follow a keydown |
| 707 |
// for the same character |
| 708 |
var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress; |
| 709 |
if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) { |
| 710 |
_resetSequences(doNotReset); |
| 711 |
} |
| 712 |
|
| 713 |
_ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown'; |
| 714 |
}; |
| 715 |
|
| 716 |
/** |
| 717 |
* handles a keydown event |
| 718 |
* |
| 719 |
* @param {Event} e |
| 720 |
* @returns void |
| 721 |
*/ |
| 722 |
function _handleKeyEvent(e) { |
| 723 |
|
| 724 |
// normalize e.which for key events |
| 725 |
// @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion |
| 726 |
if (typeof e.which !== 'number') { |
| 727 |
e.which = e.keyCode; |
| 728 |
} |
| 729 |
|
| 730 |
var character = _characterFromEvent(e); |
| 731 |
|
| 732 |
// no character found then stop |
| 733 |
if (!character) { |
| 734 |
return; |
| 735 |
} |
| 736 |
|
| 737 |
// need to use === for the character check because the character can be 0 |
| 738 |
if (e.type == 'keyup' && _ignoreNextKeyup === character) { |
| 739 |
_ignoreNextKeyup = false; |
| 740 |
return; |
| 741 |
} |
| 742 |
|
| 743 |
self.handleKey(character, _eventModifiers(e), e); |
| 744 |
} |
| 745 |
|
| 746 |
/** |
| 747 |
* called to set a 1 second timeout on the specified sequence |
| 748 |
* |
| 749 |
* this is so after each key press in the sequence you have 1 second |
| 750 |
* to press the next key before you have to start over |
| 751 |
* |
| 752 |
* @returns void |
| 753 |
*/ |
| 754 |
function _resetSequenceTimer() { |
| 755 |
clearTimeout(_resetTimer); |
| 756 |
_resetTimer = setTimeout(_resetSequences, 1000); |
| 757 |
} |
| 758 |
|
| 759 |
/** |
| 760 |
* binds a key sequence to an event |
| 761 |
* |
| 762 |
* @param {string} combo - combo specified in bind call |
| 763 |
* @param {Array} keys |
| 764 |
* @param {Function} callback |
| 765 |
* @param {string=} action |
| 766 |
* @returns void |
| 767 |
*/ |
| 768 |
function _bindSequence(combo, keys, callback, action) { |
| 769 |
|
| 770 |
// start off by adding a sequence level record for this combination |
| 771 |
// and setting the level to 0 |
| 772 |
_sequenceLevels[combo] = 0; |
| 773 |
|
| 774 |
/** |
| 775 |
* callback to increase the sequence level for this sequence and reset |
| 776 |
* all other sequences that were active |
| 777 |
* |
| 778 |
* @param {string} nextAction |
| 779 |
* @returns {Function} |
| 780 |
*/ |
| 781 |
function _increaseSequence(nextAction) { |
| 782 |
return function() { |
| 783 |
_nextExpectedAction = nextAction; |
| 784 |
++_sequenceLevels[combo]; |
| 785 |
_resetSequenceTimer(); |
| 786 |
}; |
| 787 |
} |
| 788 |
|
| 789 |
/** |
| 790 |
* wraps the specified callback inside of another function in order |
| 791 |
* to reset all sequence counters as soon as this sequence is done |
| 792 |
* |
| 793 |
* @param {Event} e |
| 794 |
* @returns void |
| 795 |
*/ |
| 796 |
function _callbackAndReset(e) { |
| 797 |
_fireCallback(callback, e, combo); |
| 798 |
|
| 799 |
// we should ignore the next key up if the action is key down |
| 800 |
// or keypress. this is so if you finish a sequence and |
| 801 |
// release the key the final key will not trigger a keyup |
| 802 |
if (action !== 'keyup') { |
| 803 |
_ignoreNextKeyup = _characterFromEvent(e); |
| 804 |
} |
| 805 |
|
| 806 |
// weird race condition if a sequence ends with the key |
| 807 |
// another sequence begins with |
| 808 |
setTimeout(_resetSequences, 10); |
| 809 |
} |
| 810 |
|
| 811 |
// loop through keys one at a time and bind the appropriate callback |
| 812 |
// function. for any key leading up to the final one it should |
| 813 |
// increase the sequence. after the final, it should reset all sequences |
| 814 |
// |
| 815 |
// if an action is specified in the original bind call then that will |
| 816 |
// be used throughout. otherwise we will pass the action that the |
| 817 |
// next key in the sequence should match. this allows a sequence |
| 818 |
// to mix and match keypress and keydown events depending on which |
| 819 |
// ones are better suited to the key provided |
| 820 |
for (var i = 0; i < keys.length; ++i) { |
| 821 |
var isFinal = i + 1 === keys.length; |
| 822 |
var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action); |
| 823 |
_bindSingle(keys[i], wrappedCallback, action, combo, i); |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
/** |
| 828 |
* binds a single keyboard combination |
| 829 |
* |
| 830 |
* @param {string} combination |
| 831 |
* @param {Function} callback |
| 832 |
* @param {string=} action |
| 833 |
* @param {string=} sequenceName - name of sequence if part of sequence |
| 834 |
* @param {number=} level - what part of the sequence the command is |
| 835 |
* @returns void |
| 836 |
*/ |
| 837 |
function _bindSingle(combination, callback, action, sequenceName, level) { |
| 838 |
|
| 839 |
// store a direct mapped reference for use with Mousetrap.trigger |
| 840 |
self._directMap[combination + ':' + action] = callback; |
| 841 |
|
| 842 |
// make sure multiple spaces in a row become a single space |
| 843 |
combination = combination.replace(/\s+/g, ' '); |
| 844 |
|
| 845 |
var sequence = combination.split(' '); |
| 846 |
var info; |
| 847 |
|
| 848 |
// if this pattern is a sequence of keys then run through this method |
| 849 |
// to reprocess each pattern one key at a time |
| 850 |
if (sequence.length > 1) { |
| 851 |
_bindSequence(combination, sequence, callback, action); |
| 852 |
return; |
| 853 |
} |
| 854 |
|
| 855 |
info = _getKeyInfo(combination, action); |
| 856 |
|
| 857 |
// make sure to initialize array if this is the first time |
| 858 |
// a callback is added for this key |
| 859 |
self._callbacks[info.key] = self._callbacks[info.key] || []; |
| 860 |
|
| 861 |
// remove an existing match if there is one |
| 862 |
_getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level); |
| 863 |
|
| 864 |
// add this call back to the array |
| 865 |
// if it is a sequence put it at the beginning |
| 866 |
// if not put it at the end |
| 867 |
// |
| 868 |
// this is important because the way these are processed expects |
| 869 |
// the sequence ones to come first |
| 870 |
self._callbacks[info.key][sequenceName ? 'unshift' : 'push']({ |
| 871 |
callback: callback, |
| 872 |
modifiers: info.modifiers, |
| 873 |
action: info.action, |
| 874 |
seq: sequenceName, |
| 875 |
level: level, |
| 876 |
combo: combination |
| 877 |
}); |
| 878 |
} |
| 879 |
|
| 880 |
/** |
| 881 |
* binds multiple combinations to the same callback |
| 882 |
* |
| 883 |
* @param {Array} combinations |
| 884 |
* @param {Function} callback |
| 885 |
* @param {string|undefined} action |
| 886 |
* @returns void |
| 887 |
*/ |
| 888 |
self._bindMultiple = function(combinations, callback, action) { |
| 889 |
for (var i = 0; i < combinations.length; ++i) { |
| 890 |
_bindSingle(combinations[i], callback, action); |
| 891 |
} |
| 892 |
}; |
| 893 |
|
| 894 |
// start! |
| 895 |
_addEvent(targetElement, 'keypress', _handleKeyEvent); |
| 896 |
_addEvent(targetElement, 'keydown', _handleKeyEvent); |
| 897 |
_addEvent(targetElement, 'keyup', _handleKeyEvent); |
| 898 |
} |
| 899 |
|
| 900 |
/** |
| 901 |
* binds an event to mousetrap |
| 902 |
* |
| 903 |
* can be a single key, a combination of keys separated with +, |
| 904 |
* an array of keys, or a sequence of keys separated by spaces |
| 905 |
* |
| 906 |
* be sure to list the modifier keys first to make sure that the |
| 907 |
* correct key ends up getting bound (the last key in the pattern) |
| 908 |
* |
| 909 |
* @param {string|Array} keys |
| 910 |
* @param {Function} callback |
| 911 |
* @param {string=} action - 'keypress', 'keydown', or 'keyup' |
| 912 |
* @returns void |
| 913 |
*/ |
| 914 |
Mousetrap.prototype.bind = function(keys, callback, action) { |
| 915 |
var self = this; |
| 916 |
keys = keys instanceof Array ? keys : [keys]; |
| 917 |
self._bindMultiple.call(self, keys, callback, action); |
| 918 |
return self; |
| 919 |
}; |
| 920 |
|
| 921 |
/** |
| 922 |
* unbinds an event to mousetrap |
| 923 |
* |
| 924 |
* the unbinding sets the callback function of the specified key combo |
| 925 |
* to an empty function and deletes the corresponding key in the |
| 926 |
* _directMap dict. |
| 927 |
* |
| 928 |
* TODO: actually remove this from the _callbacks dictionary instead |
| 929 |
* of binding an empty function |
| 930 |
* |
| 931 |
* the keycombo+action has to be exactly the same as |
| 932 |
* it was defined in the bind method |
| 933 |
* |
| 934 |
* @param {string|Array} keys |
| 935 |
* @param {string} action |
| 936 |
* @returns void |
| 937 |
*/ |
| 938 |
Mousetrap.prototype.unbind = function(keys, action) { |
| 939 |
var self = this; |
| 940 |
return self.bind.call(self, keys, function() {}, action); |
| 941 |
}; |
| 942 |
|
| 943 |
/** |
| 944 |
* triggers an event that has already been bound |
| 945 |
* |
| 946 |
* @param {string} keys |
| 947 |
* @param {string=} action |
| 948 |
* @returns void |
| 949 |
*/ |
| 950 |
Mousetrap.prototype.trigger = function(keys, action) { |
| 951 |
var self = this; |
| 952 |
if (self._directMap[keys + ':' + action]) { |
| 953 |
self._directMap[keys + ':' + action]({}, keys); |
| 954 |
} |
| 955 |
return self; |
| 956 |
}; |
| 957 |
|
| 958 |
/** |
| 959 |
* resets the library back to its initial state. this is useful |
| 960 |
* if you want to clear out the current keyboard shortcuts and bind |
| 961 |
* new ones - for example if you switch to another page |
| 962 |
* |
| 963 |
* @returns void |
| 964 |
*/ |
| 965 |
Mousetrap.prototype.reset = function() { |
| 966 |
var self = this; |
| 967 |
self._callbacks = {}; |
| 968 |
self._directMap = {}; |
| 969 |
return self; |
| 970 |
}; |
| 971 |
|
| 972 |
/** |
| 973 |
* should we stop this event before firing off callbacks |
| 974 |
* |
| 975 |
* @param {Event} e |
| 976 |
* @param {Element} element |
| 977 |
* @return {boolean} |
| 978 |
*/ |
| 979 |
Mousetrap.prototype.stopCallback = function(e, element) { |
| 980 |
var self = this; |
| 981 |
|
| 982 |
// if the element has the class "mousetrap" then no need to stop |
| 983 |
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { |
| 984 |
return false; |
| 985 |
} |
| 986 |
|
| 987 |
if (_belongsTo(element, self.target)) { |
| 988 |
return false; |
| 989 |
} |
| 990 |
|
| 991 |
// Events originating from a shadow DOM are re-targetted and `e.target` is the shadow host, |
| 992 |
// not the initial event target in the shadow tree. Note that not all events cross the |
| 993 |
// shadow boundary. |
| 994 |
// For shadow trees with `mode: 'open'`, the initial event target is the first element in |
| 995 |
// the event’s composed path. For shadow trees with `mode: 'closed'`, the initial event |
| 996 |
// target cannot be obtained. |
| 997 |
if ('composedPath' in e && typeof e.composedPath === 'function') { |
| 998 |
// For open shadow trees, update `element` so that the following check works. |
| 999 |
var initialEventTarget = e.composedPath()[0]; |
| 1000 |
if (initialEventTarget !== e.target) { |
| 1001 |
element = initialEventTarget; |
| 1002 |
} |
| 1003 |
} |
| 1004 |
|
| 1005 |
// stop for input, select, and textarea |
| 1006 |
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable; |
| 1007 |
}; |
| 1008 |
|
| 1009 |
/** |
| 1010 |
* exposes _handleKey publicly so it can be overwritten by extensions |
| 1011 |
*/ |
| 1012 |
Mousetrap.prototype.handleKey = function() { |
| 1013 |
var self = this; |
| 1014 |
return self._handleKey.apply(self, arguments); |
| 1015 |
}; |
| 1016 |
|
| 1017 |
/** |
| 1018 |
* allow custom key mappings |
| 1019 |
*/ |
| 1020 |
Mousetrap.addKeycodes = function(object) { |
| 1021 |
for (var key in object) { |
| 1022 |
if (object.hasOwnProperty(key)) { |
| 1023 |
_MAP[key] = object[key]; |
| 1024 |
} |
| 1025 |
} |
| 1026 |
_REVERSE_MAP = null; |
| 1027 |
}; |
| 1028 |
|
| 1029 |
/** |
| 1030 |
* Init the global mousetrap functions |
| 1031 |
* |
| 1032 |
* This method is needed to allow the global mousetrap functions to work |
| 1033 |
* now that mousetrap is a constructor function. |
| 1034 |
*/ |
| 1035 |
Mousetrap.init = function() { |
| 1036 |
var documentMousetrap = Mousetrap(document); |
| 1037 |
for (var method in documentMousetrap) { |
| 1038 |
if (method.charAt(0) !== '_') { |
| 1039 |
Mousetrap[method] = (function(method) { |
| 1040 |
return function() { |
| 1041 |
return documentMousetrap[method].apply(documentMousetrap, arguments); |
| 1042 |
}; |
| 1043 |
} (method)); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
}; |
| 1047 |
|
| 1048 |
Mousetrap.init(); |
| 1049 |
|
| 1050 |
// expose mousetrap to the global object |
| 1051 |
window.Mousetrap = Mousetrap; |
| 1052 |
|
| 1053 |
// expose as a common js module |
| 1054 |
if ( true && module.exports) { |
| 1055 |
module.exports = Mousetrap; |
| 1056 |
} |
| 1057 |
|
| 1058 |
// expose mousetrap as an AMD module |
| 1059 |
if (true) { |
| 1060 |
!(__WEBPACK_AMD_DEFINE_RESULT__ = (function() { |
| 1061 |
return Mousetrap; |
| 1062 |
}).call(exports, __webpack_require__, exports, module), |
| 1063 |
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
| 1064 |
} |
| 1065 |
}) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null); |
| 1066 |
|
| 1067 |
|
| 1068 |
/***/ }), |
| 1069 |
|
| 1070 |
/***/ 5760: |
| 1071 |
/***/ (() => { |
| 1072 |
|
| 1073 |
/** |
| 1074 |
* adds a bindGlobal method to Mousetrap that allows you to |
| 1075 |
* bind specific keyboard shortcuts that will still work |
| 1076 |
* inside a text input field |
| 1077 |
* |
| 1078 |
* usage: |
| 1079 |
* Mousetrap.bindGlobal('ctrl+s', _saveChanges); |
| 1080 |
*/ |
| 1081 |
/* global Mousetrap:true */ |
| 1082 |
(function(Mousetrap) { |
| 1083 |
if (! Mousetrap) { |
| 1084 |
return; |
| 1085 |
} |
| 1086 |
var _globalCallbacks = {}; |
| 1087 |
var _originalStopCallback = Mousetrap.prototype.stopCallback; |
| 1088 |
|
| 1089 |
Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) { |
| 1090 |
var self = this; |
| 1091 |
|
| 1092 |
if (self.paused) { |
| 1093 |
return true; |
| 1094 |
} |
| 1095 |
|
| 1096 |
if (_globalCallbacks[combo] || _globalCallbacks[sequence]) { |
| 1097 |
return false; |
| 1098 |
} |
| 1099 |
|
| 1100 |
return _originalStopCallback.call(self, e, element, combo); |
| 1101 |
}; |
| 1102 |
|
| 1103 |
Mousetrap.prototype.bindGlobal = function(keys, callback, action) { |
| 1104 |
var self = this; |
| 1105 |
self.bind(keys, callback, action); |
| 1106 |
|
| 1107 |
if (keys instanceof Array) { |
| 1108 |
for (var i = 0; i < keys.length; i++) { |
| 1109 |
_globalCallbacks[keys[i]] = true; |
| 1110 |
} |
| 1111 |
return; |
| 1112 |
} |
| 1113 |
|
| 1114 |
_globalCallbacks[keys] = true; |
| 1115 |
}; |
| 1116 |
|
| 1117 |
Mousetrap.init(); |
| 1118 |
}) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined); |
| 1119 |
|
| 1120 |
|
| 1121 |
/***/ }), |
| 1122 |
|
| 1123 |
/***/ 5359: |
| 1124 |
/***/ (function(module) { |
| 1125 |
|
| 1126 |
/*! |
| 1127 |
* clipboard.js v2.0.11 |
| 1128 |
* https://clipboardjs.com/ |
| 1129 |
* |
| 1130 |
* Licensed MIT © Zeno Rocha |
| 1131 |
*/ |
| 1132 |
(function webpackUniversalModuleDefinition(root, factory) { |
| 1133 |
if(true) |
| 1134 |
module.exports = factory(); |
| 1135 |
else {} |
| 1136 |
})(this, function() { |
| 1137 |
return /******/ (function() { // webpackBootstrap |
| 1138 |
/******/ var __webpack_modules__ = ({ |
| 1139 |
|
| 1140 |
/***/ 686: |
| 1141 |
/***/ (function(__unused_webpack_module, __nested_webpack_exports__, __nested_webpack_require_623__) { |
| 1142 |
|
| 1143 |
"use strict"; |
| 1144 |
|
| 1145 |
// EXPORTS |
| 1146 |
__nested_webpack_require_623__.d(__nested_webpack_exports__, { |
| 1147 |
"default": function() { return /* binding */ clipboard; } |
| 1148 |
}); |
| 1149 |
|
| 1150 |
// EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js |
| 1151 |
var tiny_emitter = __nested_webpack_require_623__(279); |
| 1152 |
var tiny_emitter_default = /*#__PURE__*/__nested_webpack_require_623__.n(tiny_emitter); |
| 1153 |
// EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js |
| 1154 |
var listen = __nested_webpack_require_623__(370); |
| 1155 |
var listen_default = /*#__PURE__*/__nested_webpack_require_623__.n(listen); |
| 1156 |
// EXTERNAL MODULE: ./node_modules/select/src/select.js |
| 1157 |
var src_select = __nested_webpack_require_623__(817); |
| 1158 |
var select_default = /*#__PURE__*/__nested_webpack_require_623__.n(src_select); |
| 1159 |
;// CONCATENATED MODULE: ./src/common/command.js |
| 1160 |
/** |
| 1161 |
* Executes a given operation type. |
| 1162 |
* @param {String} type |
| 1163 |
* @return {Boolean} |
| 1164 |
*/ |
| 1165 |
function command(type) { |
| 1166 |
try { |
| 1167 |
return document.execCommand(type); |
| 1168 |
} catch (err) { |
| 1169 |
return false; |
| 1170 |
} |
| 1171 |
} |
| 1172 |
;// CONCATENATED MODULE: ./src/actions/cut.js |
| 1173 |
|
| 1174 |
|
| 1175 |
/** |
| 1176 |
* Cut action wrapper. |
| 1177 |
* @param {String|HTMLElement} target |
| 1178 |
* @return {String} |
| 1179 |
*/ |
| 1180 |
|
| 1181 |
var ClipboardActionCut = function ClipboardActionCut(target) { |
| 1182 |
var selectedText = select_default()(target); |
| 1183 |
command('cut'); |
| 1184 |
return selectedText; |
| 1185 |
}; |
| 1186 |
|
| 1187 |
/* harmony default export */ var actions_cut = (ClipboardActionCut); |
| 1188 |
;// CONCATENATED MODULE: ./src/common/create-fake-element.js |
| 1189 |
/** |
| 1190 |
* Creates a fake textarea element with a value. |
| 1191 |
* @param {String} value |
| 1192 |
* @return {HTMLElement} |
| 1193 |
*/ |
| 1194 |
function createFakeElement(value) { |
| 1195 |
var isRTL = document.documentElement.getAttribute('dir') === 'rtl'; |
| 1196 |
var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS |
| 1197 |
|
| 1198 |
fakeElement.style.fontSize = '12pt'; // Reset box model |
| 1199 |
|
| 1200 |
fakeElement.style.border = '0'; |
| 1201 |
fakeElement.style.padding = '0'; |
| 1202 |
fakeElement.style.margin = '0'; // Move element out of screen horizontally |
| 1203 |
|
| 1204 |
fakeElement.style.position = 'absolute'; |
| 1205 |
fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically |
| 1206 |
|
| 1207 |
var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
| 1208 |
fakeElement.style.top = "".concat(yPosition, "px"); |
| 1209 |
fakeElement.setAttribute('readonly', ''); |
| 1210 |
fakeElement.value = value; |
| 1211 |
return fakeElement; |
| 1212 |
} |
| 1213 |
;// CONCATENATED MODULE: ./src/actions/copy.js |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
/** |
| 1218 |
* Create fake copy action wrapper using a fake element. |
| 1219 |
* @param {String} target |
| 1220 |
* @param {Object} options |
| 1221 |
* @return {String} |
| 1222 |
*/ |
| 1223 |
|
| 1224 |
var fakeCopyAction = function fakeCopyAction(value, options) { |
| 1225 |
var fakeElement = createFakeElement(value); |
| 1226 |
options.container.appendChild(fakeElement); |
| 1227 |
var selectedText = select_default()(fakeElement); |
| 1228 |
command('copy'); |
| 1229 |
fakeElement.remove(); |
| 1230 |
return selectedText; |
| 1231 |
}; |
| 1232 |
/** |
| 1233 |
* Copy action wrapper. |
| 1234 |
* @param {String|HTMLElement} target |
| 1235 |
* @param {Object} options |
| 1236 |
* @return {String} |
| 1237 |
*/ |
| 1238 |
|
| 1239 |
|
| 1240 |
var ClipboardActionCopy = function ClipboardActionCopy(target) { |
| 1241 |
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
| 1242 |
container: document.body |
| 1243 |
}; |
| 1244 |
var selectedText = ''; |
| 1245 |
|
| 1246 |
if (typeof target === 'string') { |
| 1247 |
selectedText = fakeCopyAction(target, options); |
| 1248 |
} else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) { |
| 1249 |
// If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange |
| 1250 |
selectedText = fakeCopyAction(target.value, options); |
| 1251 |
} else { |
| 1252 |
selectedText = select_default()(target); |
| 1253 |
command('copy'); |
| 1254 |
} |
| 1255 |
|
| 1256 |
return selectedText; |
| 1257 |
}; |
| 1258 |
|
| 1259 |
/* harmony default export */ var actions_copy = (ClipboardActionCopy); |
| 1260 |
;// CONCATENATED MODULE: ./src/actions/default.js |
| 1261 |
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
/** |
| 1266 |
* Inner function which performs selection from either `text` or `target` |
| 1267 |
* properties and then executes copy or cut operations. |
| 1268 |
* @param {Object} options |
| 1269 |
*/ |
| 1270 |
|
| 1271 |
var ClipboardActionDefault = function ClipboardActionDefault() { |
| 1272 |
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
| 1273 |
// Defines base properties passed from constructor. |
| 1274 |
var _options$action = options.action, |
| 1275 |
action = _options$action === void 0 ? 'copy' : _options$action, |
| 1276 |
container = options.container, |
| 1277 |
target = options.target, |
| 1278 |
text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'. |
| 1279 |
|
| 1280 |
if (action !== 'copy' && action !== 'cut') { |
| 1281 |
throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
| 1282 |
} // Sets the `target` property using an element that will be have its content copied. |
| 1283 |
|
| 1284 |
|
| 1285 |
if (target !== undefined) { |
| 1286 |
if (target && _typeof(target) === 'object' && target.nodeType === 1) { |
| 1287 |
if (action === 'copy' && target.hasAttribute('disabled')) { |
| 1288 |
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
| 1289 |
} |
| 1290 |
|
| 1291 |
if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
| 1292 |
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
| 1293 |
} |
| 1294 |
} else { |
| 1295 |
throw new Error('Invalid "target" value, use a valid Element'); |
| 1296 |
} |
| 1297 |
} // Define selection strategy based on `text` property. |
| 1298 |
|
| 1299 |
|
| 1300 |
if (text) { |
| 1301 |
return actions_copy(text, { |
| 1302 |
container: container |
| 1303 |
}); |
| 1304 |
} // Defines which selection strategy based on `target` property. |
| 1305 |
|
| 1306 |
|
| 1307 |
if (target) { |
| 1308 |
return action === 'cut' ? actions_cut(target) : actions_copy(target, { |
| 1309 |
container: container |
| 1310 |
}); |
| 1311 |
} |
| 1312 |
}; |
| 1313 |
|
| 1314 |
/* harmony default export */ var actions_default = (ClipboardActionDefault); |
| 1315 |
;// CONCATENATED MODULE: ./src/clipboard.js |
| 1316 |
function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); } |
| 1317 |
|
| 1318 |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 1319 |
|
| 1320 |
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } |
| 1321 |
|
| 1322 |
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
| 1323 |
|
| 1324 |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } |
| 1325 |
|
| 1326 |
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } |
| 1327 |
|
| 1328 |
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } |
| 1329 |
|
| 1330 |
function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } |
| 1331 |
|
| 1332 |
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } |
| 1333 |
|
| 1334 |
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } |
| 1335 |
|
| 1336 |
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
/** |
| 1344 |
* Helper function to retrieve attribute value. |
| 1345 |
* @param {String} suffix |
| 1346 |
* @param {Element} element |
| 1347 |
*/ |
| 1348 |
|
| 1349 |
function getAttributeValue(suffix, element) { |
| 1350 |
var attribute = "data-clipboard-".concat(suffix); |
| 1351 |
|
| 1352 |
if (!element.hasAttribute(attribute)) { |
| 1353 |
return; |
| 1354 |
} |
| 1355 |
|
| 1356 |
return element.getAttribute(attribute); |
| 1357 |
} |
| 1358 |
/** |
| 1359 |
* Base class which takes one or more elements, adds event listeners to them, |
| 1360 |
* and instantiates a new `ClipboardAction` on each click. |
| 1361 |
*/ |
| 1362 |
|
| 1363 |
|
| 1364 |
var Clipboard = /*#__PURE__*/function (_Emitter) { |
| 1365 |
_inherits(Clipboard, _Emitter); |
| 1366 |
|
| 1367 |
var _super = _createSuper(Clipboard); |
| 1368 |
|
| 1369 |
/** |
| 1370 |
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
| 1371 |
* @param {Object} options |
| 1372 |
*/ |
| 1373 |
function Clipboard(trigger, options) { |
| 1374 |
var _this; |
| 1375 |
|
| 1376 |
_classCallCheck(this, Clipboard); |
| 1377 |
|
| 1378 |
_this = _super.call(this); |
| 1379 |
|
| 1380 |
_this.resolveOptions(options); |
| 1381 |
|
| 1382 |
_this.listenClick(trigger); |
| 1383 |
|
| 1384 |
return _this; |
| 1385 |
} |
| 1386 |
/** |
| 1387 |
* Defines if attributes would be resolved using internal setter functions |
| 1388 |
* or custom functions that were passed in the constructor. |
| 1389 |
* @param {Object} options |
| 1390 |
*/ |
| 1391 |
|
| 1392 |
|
| 1393 |
_createClass(Clipboard, [{ |
| 1394 |
key: "resolveOptions", |
| 1395 |
value: function resolveOptions() { |
| 1396 |
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
| 1397 |
this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
| 1398 |
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
| 1399 |
this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
| 1400 |
this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body; |
| 1401 |
} |
| 1402 |
/** |
| 1403 |
* Adds a click event listener to the passed trigger. |
| 1404 |
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
| 1405 |
*/ |
| 1406 |
|
| 1407 |
}, { |
| 1408 |
key: "listenClick", |
| 1409 |
value: function listenClick(trigger) { |
| 1410 |
var _this2 = this; |
| 1411 |
|
| 1412 |
this.listener = listen_default()(trigger, 'click', function (e) { |
| 1413 |
return _this2.onClick(e); |
| 1414 |
}); |
| 1415 |
} |
| 1416 |
/** |
| 1417 |
* Defines a new `ClipboardAction` on each click event. |
| 1418 |
* @param {Event} e |
| 1419 |
*/ |
| 1420 |
|
| 1421 |
}, { |
| 1422 |
key: "onClick", |
| 1423 |
value: function onClick(e) { |
| 1424 |
var trigger = e.delegateTarget || e.currentTarget; |
| 1425 |
var action = this.action(trigger) || 'copy'; |
| 1426 |
var text = actions_default({ |
| 1427 |
action: action, |
| 1428 |
container: this.container, |
| 1429 |
target: this.target(trigger), |
| 1430 |
text: this.text(trigger) |
| 1431 |
}); // Fires an event based on the copy operation result. |
| 1432 |
|
| 1433 |
this.emit(text ? 'success' : 'error', { |
| 1434 |
action: action, |
| 1435 |
text: text, |
| 1436 |
trigger: trigger, |
| 1437 |
clearSelection: function clearSelection() { |
| 1438 |
if (trigger) { |
| 1439 |
trigger.focus(); |
| 1440 |
} |
| 1441 |
|
| 1442 |
window.getSelection().removeAllRanges(); |
| 1443 |
} |
| 1444 |
}); |
| 1445 |
} |
| 1446 |
/** |
| 1447 |
* Default `action` lookup function. |
| 1448 |
* @param {Element} trigger |
| 1449 |
*/ |
| 1450 |
|
| 1451 |
}, { |
| 1452 |
key: "defaultAction", |
| 1453 |
value: function defaultAction(trigger) { |
| 1454 |
return getAttributeValue('action', trigger); |
| 1455 |
} |
| 1456 |
/** |
| 1457 |
* Default `target` lookup function. |
| 1458 |
* @param {Element} trigger |
| 1459 |
*/ |
| 1460 |
|
| 1461 |
}, { |
| 1462 |
key: "defaultTarget", |
| 1463 |
value: function defaultTarget(trigger) { |
| 1464 |
var selector = getAttributeValue('target', trigger); |
| 1465 |
|
| 1466 |
if (selector) { |
| 1467 |
return document.querySelector(selector); |
| 1468 |
} |
| 1469 |
} |
| 1470 |
/** |
| 1471 |
* Allow fire programmatically a copy action |
| 1472 |
* @param {String|HTMLElement} target |
| 1473 |
* @param {Object} options |
| 1474 |
* @returns Text copied. |
| 1475 |
*/ |
| 1476 |
|
| 1477 |
}, { |
| 1478 |
key: "defaultText", |
| 1479 |
|
| 1480 |
/** |
| 1481 |
* Default `text` lookup function. |
| 1482 |
* @param {Element} trigger |
| 1483 |
*/ |
| 1484 |
value: function defaultText(trigger) { |
| 1485 |
return getAttributeValue('text', trigger); |
| 1486 |
} |
| 1487 |
/** |
| 1488 |
* Destroy lifecycle. |
| 1489 |
*/ |
| 1490 |
|
| 1491 |
}, { |
| 1492 |
key: "destroy", |
| 1493 |
value: function destroy() { |
| 1494 |
this.listener.destroy(); |
| 1495 |
} |
| 1496 |
}], [{ |
| 1497 |
key: "copy", |
| 1498 |
value: function copy(target) { |
| 1499 |
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
| 1500 |
container: document.body |
| 1501 |
}; |
| 1502 |
return actions_copy(target, options); |
| 1503 |
} |
| 1504 |
/** |
| 1505 |
* Allow fire programmatically a cut action |
| 1506 |
* @param {String|HTMLElement} target |
| 1507 |
* @returns Text cutted. |
| 1508 |
*/ |
| 1509 |
|
| 1510 |
}, { |
| 1511 |
key: "cut", |
| 1512 |
value: function cut(target) { |
| 1513 |
return actions_cut(target); |
| 1514 |
} |
| 1515 |
/** |
| 1516 |
* Returns the support of the given action, or all actions if no action is |
| 1517 |
* given. |
| 1518 |
* @param {String} [action] |
| 1519 |
*/ |
| 1520 |
|
| 1521 |
}, { |
| 1522 |
key: "isSupported", |
| 1523 |
value: function isSupported() { |
| 1524 |
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
| 1525 |
var actions = typeof action === 'string' ? [action] : action; |
| 1526 |
var support = !!document.queryCommandSupported; |
| 1527 |
actions.forEach(function (action) { |
| 1528 |
support = support && !!document.queryCommandSupported(action); |
| 1529 |
}); |
| 1530 |
return support; |
| 1531 |
} |
| 1532 |
}]); |
| 1533 |
|
| 1534 |
return Clipboard; |
| 1535 |
}((tiny_emitter_default())); |
| 1536 |
|
| 1537 |
/* harmony default export */ var clipboard = (Clipboard); |
| 1538 |
|
| 1539 |
/***/ }), |
| 1540 |
|
| 1541 |
/***/ 828: |
| 1542 |
/***/ (function(module) { |
| 1543 |
|
| 1544 |
var DOCUMENT_NODE_TYPE = 9; |
| 1545 |
|
| 1546 |
/** |
| 1547 |
* A polyfill for Element.matches() |
| 1548 |
*/ |
| 1549 |
if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
| 1550 |
var proto = Element.prototype; |
| 1551 |
|
| 1552 |
proto.matches = proto.matchesSelector || |
| 1553 |
proto.mozMatchesSelector || |
| 1554 |
proto.msMatchesSelector || |
| 1555 |
proto.oMatchesSelector || |
| 1556 |
proto.webkitMatchesSelector; |
| 1557 |
} |
| 1558 |
|
| 1559 |
/** |
| 1560 |
* Finds the closest parent that matches a selector. |
| 1561 |
* |
| 1562 |
* @param {Element} element |
| 1563 |
* @param {String} selector |
| 1564 |
* @return {Function} |
| 1565 |
*/ |
| 1566 |
function closest (element, selector) { |
| 1567 |
while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
| 1568 |
if (typeof element.matches === 'function' && |
| 1569 |
element.matches(selector)) { |
| 1570 |
return element; |
| 1571 |
} |
| 1572 |
element = element.parentNode; |
| 1573 |
} |
| 1574 |
} |
| 1575 |
|
| 1576 |
module.exports = closest; |
| 1577 |
|
| 1578 |
|
| 1579 |
/***/ }), |
| 1580 |
|
| 1581 |
/***/ 438: |
| 1582 |
/***/ (function(module, __unused_webpack_exports, __nested_webpack_require_15749__) { |
| 1583 |
|
| 1584 |
var closest = __nested_webpack_require_15749__(828); |
| 1585 |
|
| 1586 |
/** |
| 1587 |
* Delegates event to a selector. |
| 1588 |
* |
| 1589 |
* @param {Element} element |
| 1590 |
* @param {String} selector |
| 1591 |
* @param {String} type |
| 1592 |
* @param {Function} callback |
| 1593 |
* @param {Boolean} useCapture |
| 1594 |
* @return {Object} |
| 1595 |
*/ |
| 1596 |
function _delegate(element, selector, type, callback, useCapture) { |
| 1597 |
var listenerFn = listener.apply(this, arguments); |
| 1598 |
|
| 1599 |
element.addEventListener(type, listenerFn, useCapture); |
| 1600 |
|
| 1601 |
return { |
| 1602 |
destroy: function() { |
| 1603 |
element.removeEventListener(type, listenerFn, useCapture); |
| 1604 |
} |
| 1605 |
} |
| 1606 |
} |
| 1607 |
|
| 1608 |
/** |
| 1609 |
* Delegates event to a selector. |
| 1610 |
* |
| 1611 |
* @param {Element|String|Array} [elements] |
| 1612 |
* @param {String} selector |
| 1613 |
* @param {String} type |
| 1614 |
* @param {Function} callback |
| 1615 |
* @param {Boolean} useCapture |
| 1616 |
* @return {Object} |
| 1617 |
*/ |
| 1618 |
function delegate(elements, selector, type, callback, useCapture) { |
| 1619 |
// Handle the regular Element usage |
| 1620 |
if (typeof elements.addEventListener === 'function') { |
| 1621 |
return _delegate.apply(null, arguments); |
| 1622 |
} |
| 1623 |
|
| 1624 |
// Handle Element-less usage, it defaults to global delegation |
| 1625 |
if (typeof type === 'function') { |
| 1626 |
// Use `document` as the first parameter, then apply arguments |
| 1627 |
// This is a short way to .unshift `arguments` without running into deoptimizations |
| 1628 |
return _delegate.bind(null, document).apply(null, arguments); |
| 1629 |
} |
| 1630 |
|
| 1631 |
// Handle Selector-based usage |
| 1632 |
if (typeof elements === 'string') { |
| 1633 |
elements = document.querySelectorAll(elements); |
| 1634 |
} |
| 1635 |
|
| 1636 |
// Handle Array-like based usage |
| 1637 |
return Array.prototype.map.call(elements, function (element) { |
| 1638 |
return _delegate(element, selector, type, callback, useCapture); |
| 1639 |
}); |
| 1640 |
} |
| 1641 |
|
| 1642 |
/** |
| 1643 |
* Finds closest match and invokes callback. |
| 1644 |
* |
| 1645 |
* @param {Element} element |
| 1646 |
* @param {String} selector |
| 1647 |
* @param {String} type |
| 1648 |
* @param {Function} callback |
| 1649 |
* @return {Function} |
| 1650 |
*/ |
| 1651 |
function listener(element, selector, type, callback) { |
| 1652 |
return function(e) { |
| 1653 |
e.delegateTarget = closest(e.target, selector); |
| 1654 |
|
| 1655 |
if (e.delegateTarget) { |
| 1656 |
callback.call(element, e); |
| 1657 |
} |
| 1658 |
} |
| 1659 |
} |
| 1660 |
|
| 1661 |
module.exports = delegate; |
| 1662 |
|
| 1663 |
|
| 1664 |
/***/ }), |
| 1665 |
|
| 1666 |
/***/ 879: |
| 1667 |
/***/ (function(__unused_webpack_module, exports) { |
| 1668 |
|
| 1669 |
/** |
| 1670 |
* Check if argument is a HTML element. |
| 1671 |
* |
| 1672 |
* @param {Object} value |
| 1673 |
* @return {Boolean} |
| 1674 |
*/ |
| 1675 |
exports.node = function(value) { |
| 1676 |
return value !== undefined |
| 1677 |
&& value instanceof HTMLElement |
| 1678 |
&& value.nodeType === 1; |
| 1679 |
}; |
| 1680 |
|
| 1681 |
/** |
| 1682 |
* Check if argument is a list of HTML elements. |
| 1683 |
* |
| 1684 |
* @param {Object} value |
| 1685 |
* @return {Boolean} |
| 1686 |
*/ |
| 1687 |
exports.nodeList = function(value) { |
| 1688 |
var type = Object.prototype.toString.call(value); |
| 1689 |
|
| 1690 |
return value !== undefined |
| 1691 |
&& (type === '[object NodeList]' || type === '[object HTMLCollection]') |
| 1692 |
&& ('length' in value) |
| 1693 |
&& (value.length === 0 || exports.node(value[0])); |
| 1694 |
}; |
| 1695 |
|
| 1696 |
/** |
| 1697 |
* Check if argument is a string. |
| 1698 |
* |
| 1699 |
* @param {Object} value |
| 1700 |
* @return {Boolean} |
| 1701 |
*/ |
| 1702 |
exports.string = function(value) { |
| 1703 |
return typeof value === 'string' |
| 1704 |
|| value instanceof String; |
| 1705 |
}; |
| 1706 |
|
| 1707 |
/** |
| 1708 |
* Check if argument is a function. |
| 1709 |
* |
| 1710 |
* @param {Object} value |
| 1711 |
* @return {Boolean} |
| 1712 |
*/ |
| 1713 |
exports.fn = function(value) { |
| 1714 |
var type = Object.prototype.toString.call(value); |
| 1715 |
|
| 1716 |
return type === '[object Function]'; |
| 1717 |
}; |
| 1718 |
|
| 1719 |
|
| 1720 |
/***/ }), |
| 1721 |
|
| 1722 |
/***/ 370: |
| 1723 |
/***/ (function(module, __unused_webpack_exports, __nested_webpack_require_19113__) { |
| 1724 |
|
| 1725 |
var is = __nested_webpack_require_19113__(879); |
| 1726 |
var delegate = __nested_webpack_require_19113__(438); |
| 1727 |
|
| 1728 |
/** |
| 1729 |
* Validates all params and calls the right |
| 1730 |
* listener function based on its target type. |
| 1731 |
* |
| 1732 |
* @param {String|HTMLElement|HTMLCollection|NodeList} target |
| 1733 |
* @param {String} type |
| 1734 |
* @param {Function} callback |
| 1735 |
* @return {Object} |
| 1736 |
*/ |
| 1737 |
function listen(target, type, callback) { |
| 1738 |
if (!target && !type && !callback) { |
| 1739 |
throw new Error('Missing required arguments'); |
| 1740 |
} |
| 1741 |
|
| 1742 |
if (!is.string(type)) { |
| 1743 |
throw new TypeError('Second argument must be a String'); |
| 1744 |
} |
| 1745 |
|
| 1746 |
if (!is.fn(callback)) { |
| 1747 |
throw new TypeError('Third argument must be a Function'); |
| 1748 |
} |
| 1749 |
|
| 1750 |
if (is.node(target)) { |
| 1751 |
return listenNode(target, type, callback); |
| 1752 |
} |
| 1753 |
else if (is.nodeList(target)) { |
| 1754 |
return listenNodeList(target, type, callback); |
| 1755 |
} |
| 1756 |
else if (is.string(target)) { |
| 1757 |
return listenSelector(target, type, callback); |
| 1758 |
} |
| 1759 |
else { |
| 1760 |
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
| 1761 |
} |
| 1762 |
} |
| 1763 |
|
| 1764 |
/** |
| 1765 |
* Adds an event listener to a HTML element |
| 1766 |
* and returns a remove listener function. |
| 1767 |
* |
| 1768 |
* @param {HTMLElement} node |
| 1769 |
* @param {String} type |
| 1770 |
* @param {Function} callback |
| 1771 |
* @return {Object} |
| 1772 |
*/ |
| 1773 |
function listenNode(node, type, callback) { |
| 1774 |
node.addEventListener(type, callback); |
| 1775 |
|
| 1776 |
return { |
| 1777 |
destroy: function() { |
| 1778 |
node.removeEventListener(type, callback); |
| 1779 |
} |
| 1780 |
} |
| 1781 |
} |
| 1782 |
|
| 1783 |
/** |
| 1784 |
* Add an event listener to a list of HTML elements |
| 1785 |
* and returns a remove listener function. |
| 1786 |
* |
| 1787 |
* @param {NodeList|HTMLCollection} nodeList |
| 1788 |
* @param {String} type |
| 1789 |
* @param {Function} callback |
| 1790 |
* @return {Object} |
| 1791 |
*/ |
| 1792 |
function listenNodeList(nodeList, type, callback) { |
| 1793 |
Array.prototype.forEach.call(nodeList, function(node) { |
| 1794 |
node.addEventListener(type, callback); |
| 1795 |
}); |
| 1796 |
|
| 1797 |
return { |
| 1798 |
destroy: function() { |
| 1799 |
Array.prototype.forEach.call(nodeList, function(node) { |
| 1800 |
node.removeEventListener(type, callback); |
| 1801 |
}); |
| 1802 |
} |
| 1803 |
} |
| 1804 |
} |
| 1805 |
|
| 1806 |
/** |
| 1807 |
* Add an event listener to a selector |
| 1808 |
* and returns a remove listener function. |
| 1809 |
* |
| 1810 |
* @param {String} selector |
| 1811 |
* @param {String} type |
| 1812 |
* @param {Function} callback |
| 1813 |
* @return {Object} |
| 1814 |
*/ |
| 1815 |
function listenSelector(selector, type, callback) { |
| 1816 |
return delegate(document.body, selector, type, callback); |
| 1817 |
} |
| 1818 |
|
| 1819 |
module.exports = listen; |
| 1820 |
|
| 1821 |
|
| 1822 |
/***/ }), |
| 1823 |
|
| 1824 |
/***/ 817: |
| 1825 |
/***/ (function(module) { |
| 1826 |
|
| 1827 |
function select(element) { |
| 1828 |
var selectedText; |
| 1829 |
|
| 1830 |
if (element.nodeName === 'SELECT') { |
| 1831 |
element.focus(); |
| 1832 |
|
| 1833 |
selectedText = element.value; |
| 1834 |
} |
| 1835 |
else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
| 1836 |
var isReadOnly = element.hasAttribute('readonly'); |
| 1837 |
|
| 1838 |
if (!isReadOnly) { |
| 1839 |
element.setAttribute('readonly', ''); |
| 1840 |
} |
| 1841 |
|
| 1842 |
element.select(); |
| 1843 |
element.setSelectionRange(0, element.value.length); |
| 1844 |
|
| 1845 |
if (!isReadOnly) { |
| 1846 |
element.removeAttribute('readonly'); |
| 1847 |
} |
| 1848 |
|
| 1849 |
selectedText = element.value; |
| 1850 |
} |
| 1851 |
else { |
| 1852 |
if (element.hasAttribute('contenteditable')) { |
| 1853 |
element.focus(); |
| 1854 |
} |
| 1855 |
|
| 1856 |
var selection = window.getSelection(); |
| 1857 |
var range = document.createRange(); |
| 1858 |
|
| 1859 |
range.selectNodeContents(element); |
| 1860 |
selection.removeAllRanges(); |
| 1861 |
selection.addRange(range); |
| 1862 |
|
| 1863 |
selectedText = selection.toString(); |
| 1864 |
} |
| 1865 |
|
| 1866 |
return selectedText; |
| 1867 |
} |
| 1868 |
|
| 1869 |
module.exports = select; |
| 1870 |
|
| 1871 |
|
| 1872 |
/***/ }), |
| 1873 |
|
| 1874 |
/***/ 279: |
| 1875 |
/***/ (function(module) { |
| 1876 |
|
| 1877 |
function E () { |
| 1878 |
// Keep this empty so it's easier to inherit from |
| 1879 |
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
| 1880 |
} |
| 1881 |
|
| 1882 |
E.prototype = { |
| 1883 |
on: function (name, callback, ctx) { |
| 1884 |
var e = this.e || (this.e = {}); |
| 1885 |
|
| 1886 |
(e[name] || (e[name] = [])).push({ |
| 1887 |
fn: callback, |
| 1888 |
ctx: ctx |
| 1889 |
}); |
| 1890 |
|
| 1891 |
return this; |
| 1892 |
}, |
| 1893 |
|
| 1894 |
once: function (name, callback, ctx) { |
| 1895 |
var self = this; |
| 1896 |
function listener () { |
| 1897 |
self.off(name, listener); |
| 1898 |
callback.apply(ctx, arguments); |
| 1899 |
}; |
| 1900 |
|
| 1901 |
listener._ = callback |
| 1902 |
return this.on(name, listener, ctx); |
| 1903 |
}, |
| 1904 |
|
| 1905 |
emit: function (name) { |
| 1906 |
var data = [].slice.call(arguments, 1); |
| 1907 |
var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
| 1908 |
var i = 0; |
| 1909 |
var len = evtArr.length; |
| 1910 |
|
| 1911 |
for (i; i < len; i++) { |
| 1912 |
evtArr[i].fn.apply(evtArr[i].ctx, data); |
| 1913 |
} |
| 1914 |
|
| 1915 |
return this; |
| 1916 |
}, |
| 1917 |
|
| 1918 |
off: function (name, callback) { |
| 1919 |
var e = this.e || (this.e = {}); |
| 1920 |
var evts = e[name]; |
| 1921 |
var liveEvents = []; |
| 1922 |
|
| 1923 |
if (evts && callback) { |
| 1924 |
for (var i = 0, len = evts.length; i < len; i++) { |
| 1925 |
if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
| 1926 |
liveEvents.push(evts[i]); |
| 1927 |
} |
| 1928 |
} |
| 1929 |
|
| 1930 |
// Remove event from queue to prevent memory leak |
| 1931 |
// Suggested by https://github.com/lazd |
| 1932 |
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
| 1933 |
|
| 1934 |
(liveEvents.length) |
| 1935 |
? e[name] = liveEvents |
| 1936 |
: delete e[name]; |
| 1937 |
|
| 1938 |
return this; |
| 1939 |
} |
| 1940 |
}; |
| 1941 |
|
| 1942 |
module.exports = E; |
| 1943 |
module.exports.TinyEmitter = E; |
| 1944 |
|
| 1945 |
|
| 1946 |
/***/ }) |
| 1947 |
|
| 1948 |
/******/ }); |
| 1949 |
/************************************************************************/ |
| 1950 |
/******/ // The module cache |
| 1951 |
/******/ var __webpack_module_cache__ = {}; |
| 1952 |
/******/ |
| 1953 |
/******/ // The require function |
| 1954 |
/******/ function __nested_webpack_require_24495__(moduleId) { |
| 1955 |
/******/ // Check if module is in cache |
| 1956 |
/******/ if(__webpack_module_cache__[moduleId]) { |
| 1957 |
/******/ return __webpack_module_cache__[moduleId].exports; |
| 1958 |
/******/ } |
| 1959 |
/******/ // Create a new module (and put it into the cache) |
| 1960 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 1961 |
/******/ // no module.id needed |
| 1962 |
/******/ // no module.loaded needed |
| 1963 |
/******/ exports: {} |
| 1964 |
/******/ }; |
| 1965 |
/******/ |
| 1966 |
/******/ // Execute the module function |
| 1967 |
/******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_24495__); |
| 1968 |
/******/ |
| 1969 |
/******/ // Return the exports of the module |
| 1970 |
/******/ return module.exports; |
| 1971 |
/******/ } |
| 1972 |
/******/ |
| 1973 |
/************************************************************************/ |
| 1974 |
/******/ /* webpack/runtime/compat get default export */ |
| 1975 |
/******/ !function() { |
| 1976 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 1977 |
/******/ __nested_webpack_require_24495__.n = function(module) { |
| 1978 |
/******/ var getter = module && module.__esModule ? |
| 1979 |
/******/ function() { return module['default']; } : |
| 1980 |
/******/ function() { return module; }; |
| 1981 |
/******/ __nested_webpack_require_24495__.d(getter, { a: getter }); |
| 1982 |
/******/ return getter; |
| 1983 |
/******/ }; |
| 1984 |
/******/ }(); |
| 1985 |
/******/ |
| 1986 |
/******/ /* webpack/runtime/define property getters */ |
| 1987 |
/******/ !function() { |
| 1988 |
/******/ // define getter functions for harmony exports |
| 1989 |
/******/ __nested_webpack_require_24495__.d = function(exports, definition) { |
| 1990 |
/******/ for(var key in definition) { |
| 1991 |
/******/ if(__nested_webpack_require_24495__.o(definition, key) && !__nested_webpack_require_24495__.o(exports, key)) { |
| 1992 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 1993 |
/******/ } |
| 1994 |
/******/ } |
| 1995 |
/******/ }; |
| 1996 |
/******/ }(); |
| 1997 |
/******/ |
| 1998 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 1999 |
/******/ !function() { |
| 2000 |
/******/ __nested_webpack_require_24495__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
| 2001 |
/******/ }(); |
| 2002 |
/******/ |
| 2003 |
/************************************************************************/ |
| 2004 |
/******/ // module exports must be returned from runtime so entry inlining is disabled |
| 2005 |
/******/ // startup |
| 2006 |
/******/ // Load entry module and return exports |
| 2007 |
/******/ return __nested_webpack_require_24495__(686); |
| 2008 |
/******/ })() |
| 2009 |
.default; |
| 2010 |
}); |
| 2011 |
|
| 2012 |
/***/ }) |
| 2013 |
|
| 2014 |
/******/ }); |
| 2015 |
/************************************************************************/ |
| 2016 |
/******/ // The module cache |
| 2017 |
/******/ var __webpack_module_cache__ = {}; |
| 2018 |
/******/ |
| 2019 |
/******/ // The require function |
| 2020 |
/******/ function __webpack_require__(moduleId) { |
| 2021 |
/******/ // Check if module is in cache |
| 2022 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 2023 |
/******/ if (cachedModule !== undefined) { |
| 2024 |
/******/ return cachedModule.exports; |
| 2025 |
/******/ } |
| 2026 |
/******/ // Create a new module (and put it into the cache) |
| 2027 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 2028 |
/******/ // no module.id needed |
| 2029 |
/******/ // no module.loaded needed |
| 2030 |
/******/ exports: {} |
| 2031 |
/******/ }; |
| 2032 |
/******/ |
| 2033 |
/******/ // Execute the module function |
| 2034 |
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 2035 |
/******/ |
| 2036 |
/******/ // Return the exports of the module |
| 2037 |
/******/ return module.exports; |
| 2038 |
/******/ } |
| 2039 |
/******/ |
| 2040 |
/************************************************************************/ |
| 2041 |
/******/ /* webpack/runtime/compat get default export */ |
| 2042 |
/******/ (() => { |
| 2043 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 2044 |
/******/ __webpack_require__.n = (module) => { |
| 2045 |
/******/ var getter = module && module.__esModule ? |
| 2046 |
/******/ () => (module['default']) : |
| 2047 |
/******/ () => (module); |
| 2048 |
/******/ __webpack_require__.d(getter, { a: getter }); |
| 2049 |
/******/ return getter; |
| 2050 |
/******/ }; |
| 2051 |
/******/ })(); |
| 2052 |
/******/ |
| 2053 |
/******/ /* webpack/runtime/define property getters */ |
| 2054 |
/******/ (() => { |
| 2055 |
/******/ // define getter functions for harmony exports |
| 2056 |
/******/ __webpack_require__.d = (exports, definition) => { |
| 2057 |
/******/ for(var key in definition) { |
| 2058 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 2059 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 2060 |
/******/ } |
| 2061 |
/******/ } |
| 2062 |
/******/ }; |
| 2063 |
/******/ })(); |
| 2064 |
/******/ |
| 2065 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 2066 |
/******/ (() => { |
| 2067 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| 2068 |
/******/ })(); |
| 2069 |
/******/ |
| 2070 |
/******/ /* webpack/runtime/make namespace object */ |
| 2071 |
/******/ (() => { |
| 2072 |
/******/ // define __esModule on exports |
| 2073 |
/******/ __webpack_require__.r = (exports) => { |
| 2074 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 2075 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 2076 |
/******/ } |
| 2077 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 2078 |
/******/ }; |
| 2079 |
/******/ })(); |
| 2080 |
/******/ |
| 2081 |
/************************************************************************/ |
| 2082 |
var __webpack_exports__ = {}; |
| 2083 |
// This entry need to be wrapped in an IIFE because it need to be in strict mode. |
| 2084 |
(() => { |
| 2085 |
"use strict"; |
| 2086 |
// ESM COMPAT FLAG |
| 2087 |
__webpack_require__.r(__webpack_exports__); |
| 2088 |
|
| 2089 |
// EXPORTS |
| 2090 |
__webpack_require__.d(__webpack_exports__, { |
| 2091 |
__experimentalUseDialog: () => (/* reexport */ use_dialog), |
| 2092 |
__experimentalUseDragging: () => (/* reexport */ useDragging), |
| 2093 |
__experimentalUseDropZone: () => (/* reexport */ useDropZone), |
| 2094 |
__experimentalUseFixedWindowList: () => (/* reexport */ useFixedWindowList), |
| 2095 |
__experimentalUseFocusOutside: () => (/* reexport */ useFocusOutside), |
| 2096 |
compose: () => (/* reexport */ higher_order_compose), |
| 2097 |
createHigherOrderComponent: () => (/* reexport */ createHigherOrderComponent), |
| 2098 |
debounce: () => (/* reexport */ debounce), |
| 2099 |
ifCondition: () => (/* reexport */ if_condition), |
| 2100 |
observableMap: () => (/* reexport */ observableMap), |
| 2101 |
pipe: () => (/* reexport */ higher_order_pipe), |
| 2102 |
pure: () => (/* reexport */ higher_order_pure), |
| 2103 |
throttle: () => (/* reexport */ throttle), |
| 2104 |
useAsyncList: () => (/* reexport */ use_async_list), |
| 2105 |
useConstrainedTabbing: () => (/* reexport */ use_constrained_tabbing), |
| 2106 |
useCopyOnClick: () => (/* reexport */ useCopyOnClick), |
| 2107 |
useCopyToClipboard: () => (/* reexport */ useCopyToClipboard), |
| 2108 |
useDebounce: () => (/* reexport */ useDebounce), |
| 2109 |
useDebouncedInput: () => (/* reexport */ useDebouncedInput), |
| 2110 |
useDisabled: () => (/* reexport */ useDisabled), |
| 2111 |
useEvent: () => (/* reexport */ useEvent), |
| 2112 |
useFocusOnMount: () => (/* reexport */ useFocusOnMount), |
| 2113 |
useFocusReturn: () => (/* reexport */ use_focus_return), |
| 2114 |
useFocusableIframe: () => (/* reexport */ useFocusableIframe), |
| 2115 |
useInstanceId: () => (/* reexport */ use_instance_id), |
| 2116 |
useIsomorphicLayoutEffect: () => (/* reexport */ use_isomorphic_layout_effect), |
| 2117 |
useKeyboardShortcut: () => (/* reexport */ use_keyboard_shortcut), |
| 2118 |
useMediaQuery: () => (/* reexport */ useMediaQuery), |
| 2119 |
useMergeRefs: () => (/* reexport */ useMergeRefs), |
| 2120 |
useObservableValue: () => (/* reexport */ useObservableValue), |
| 2121 |
usePrevious: () => (/* reexport */ usePrevious), |
| 2122 |
useReducedMotion: () => (/* reexport */ use_reduced_motion), |
| 2123 |
useRefEffect: () => (/* reexport */ useRefEffect), |
| 2124 |
useResizeObserver: () => (/* reexport */ use_resize_observer_useResizeObserver), |
| 2125 |
useStateWithHistory: () => (/* reexport */ useStateWithHistory), |
| 2126 |
useThrottle: () => (/* reexport */ useThrottle), |
| 2127 |
useViewportMatch: () => (/* reexport */ use_viewport_match), |
| 2128 |
useWarnOnChange: () => (/* reexport */ use_warn_on_change), |
| 2129 |
withGlobalEvents: () => (/* reexport */ withGlobalEvents), |
| 2130 |
withInstanceId: () => (/* reexport */ with_instance_id), |
| 2131 |
withSafeTimeout: () => (/* reexport */ with_safe_timeout), |
| 2132 |
withState: () => (/* reexport */ withState) |
| 2133 |
}); |
| 2134 |
|
| 2135 |
;// ./node_modules/tslib/tslib.es6.mjs |
| 2136 |
/****************************************************************************** |
| 2137 |
Copyright (c) Microsoft Corporation. |
| 2138 |
|
| 2139 |
Permission to use, copy, modify, and/or distribute this software for any |
| 2140 |
purpose with or without fee is hereby granted. |
| 2141 |
|
| 2142 |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 2143 |
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 2144 |
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 2145 |
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 2146 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 2147 |
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 2148 |
PERFORMANCE OF THIS SOFTWARE. |
| 2149 |
***************************************************************************** */ |
| 2150 |
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */ |
| 2151 |
|
| 2152 |
var extendStatics = function(d, b) { |
| 2153 |
extendStatics = Object.setPrototypeOf || |
| 2154 |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 2155 |
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |
| 2156 |
return extendStatics(d, b); |
| 2157 |
}; |
| 2158 |
|
| 2159 |
function __extends(d, b) { |
| 2160 |
if (typeof b !== "function" && b !== null) |
| 2161 |
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); |
| 2162 |
extendStatics(d, b); |
| 2163 |
function __() { this.constructor = d; } |
| 2164 |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 2165 |
} |
| 2166 |
|
| 2167 |
var __assign = function() { |
| 2168 |
__assign = Object.assign || function __assign(t) { |
| 2169 |
for (var s, i = 1, n = arguments.length; i < n; i++) { |
| 2170 |
s = arguments[i]; |
| 2171 |
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; |
| 2172 |
} |
| 2173 |
return t; |
| 2174 |
} |
| 2175 |
return __assign.apply(this, arguments); |
| 2176 |
} |
| 2177 |
|
| 2178 |
function __rest(s, e) { |
| 2179 |
var t = {}; |
| 2180 |
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) |
| 2181 |
t[p] = s[p]; |
| 2182 |
if (s != null && typeof Object.getOwnPropertySymbols === "function") |
| 2183 |
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { |
| 2184 |
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) |
| 2185 |
t[p[i]] = s[p[i]]; |
| 2186 |
} |
| 2187 |
return t; |
| 2188 |
} |
| 2189 |
|
| 2190 |
function __decorate(decorators, target, key, desc) { |
| 2191 |
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
| 2192 |
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
| 2193 |
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
| 2194 |
return c > 3 && r && Object.defineProperty(target, key, r), r; |
| 2195 |
} |
| 2196 |
|
| 2197 |
function __param(paramIndex, decorator) { |
| 2198 |
return function (target, key) { decorator(target, key, paramIndex); } |
| 2199 |
} |
| 2200 |
|
| 2201 |
function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { |
| 2202 |
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } |
| 2203 |
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; |
| 2204 |
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; |
| 2205 |
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); |
| 2206 |
var _, done = false; |
| 2207 |
for (var i = decorators.length - 1; i >= 0; i--) { |
| 2208 |
var context = {}; |
| 2209 |
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; |
| 2210 |
for (var p in contextIn.access) context.access[p] = contextIn.access[p]; |
| 2211 |
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; |
| 2212 |
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); |
| 2213 |
if (kind === "accessor") { |
| 2214 |
if (result === void 0) continue; |
| 2215 |
if (result === null || typeof result !== "object") throw new TypeError("Object expected"); |
| 2216 |
if (_ = accept(result.get)) descriptor.get = _; |
| 2217 |
if (_ = accept(result.set)) descriptor.set = _; |
| 2218 |
if (_ = accept(result.init)) initializers.unshift(_); |
| 2219 |
} |
| 2220 |
else if (_ = accept(result)) { |
| 2221 |
if (kind === "field") initializers.unshift(_); |
| 2222 |
else descriptor[key] = _; |
| 2223 |
} |
| 2224 |
} |
| 2225 |
if (target) Object.defineProperty(target, contextIn.name, descriptor); |
| 2226 |
done = true; |
| 2227 |
}; |
| 2228 |
|
| 2229 |
function __runInitializers(thisArg, initializers, value) { |
| 2230 |
var useValue = arguments.length > 2; |
| 2231 |
for (var i = 0; i < initializers.length; i++) { |
| 2232 |
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); |
| 2233 |
} |
| 2234 |
return useValue ? value : void 0; |
| 2235 |
}; |
| 2236 |
|
| 2237 |
function __propKey(x) { |
| 2238 |
return typeof x === "symbol" ? x : "".concat(x); |
| 2239 |
}; |
| 2240 |
|
| 2241 |
function __setFunctionName(f, name, prefix) { |
| 2242 |
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; |
| 2243 |
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); |
| 2244 |
}; |
| 2245 |
|
| 2246 |
function __metadata(metadataKey, metadataValue) { |
| 2247 |
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); |
| 2248 |
} |
| 2249 |
|
| 2250 |
function __awaiter(thisArg, _arguments, P, generator) { |
| 2251 |
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 2252 |
return new (P || (P = Promise))(function (resolve, reject) { |
| 2253 |
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 2254 |
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 2255 |
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 2256 |
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 2257 |
}); |
| 2258 |
} |
| 2259 |
|
| 2260 |
function __generator(thisArg, body) { |
| 2261 |
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); |
| 2262 |
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; |
| 2263 |
function verb(n) { return function (v) { return step([n, v]); }; } |
| 2264 |
function step(op) { |
| 2265 |
if (f) throw new TypeError("Generator is already executing."); |
| 2266 |
while (g && (g = 0, op[0] && (_ = 0)), _) try { |
| 2267 |
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; |
| 2268 |
if (y = 0, t) op = [op[0] & 2, t.value]; |
| 2269 |
switch (op[0]) { |
| 2270 |
case 0: case 1: t = op; break; |
| 2271 |
case 4: _.label++; return { value: op[1], done: false }; |
| 2272 |
case 5: _.label++; y = op[1]; op = [0]; continue; |
| 2273 |
case 7: op = _.ops.pop(); _.trys.pop(); continue; |
| 2274 |
default: |
| 2275 |
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } |
| 2276 |
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } |
| 2277 |
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } |
| 2278 |
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } |
| 2279 |
if (t[2]) _.ops.pop(); |
| 2280 |
_.trys.pop(); continue; |
| 2281 |
} |
| 2282 |
op = body.call(thisArg, _); |
| 2283 |
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } |
| 2284 |
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; |
| 2285 |
} |
| 2286 |
} |
| 2287 |
|
| 2288 |
var __createBinding = Object.create ? (function(o, m, k, k2) { |
| 2289 |
if (k2 === undefined) k2 = k; |
| 2290 |
var desc = Object.getOwnPropertyDescriptor(m, k); |
| 2291 |
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
| 2292 |
desc = { enumerable: true, get: function() { return m[k]; } }; |
| 2293 |
} |
| 2294 |
Object.defineProperty(o, k2, desc); |
| 2295 |
}) : (function(o, m, k, k2) { |
| 2296 |
if (k2 === undefined) k2 = k; |
| 2297 |
o[k2] = m[k]; |
| 2298 |
}); |
| 2299 |
|
| 2300 |
function __exportStar(m, o) { |
| 2301 |
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); |
| 2302 |
} |
| 2303 |
|
| 2304 |
function __values(o) { |
| 2305 |
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; |
| 2306 |
if (m) return m.call(o); |
| 2307 |
if (o && typeof o.length === "number") return { |
| 2308 |
next: function () { |
| 2309 |
if (o && i >= o.length) o = void 0; |
| 2310 |
return { value: o && o[i++], done: !o }; |
| 2311 |
} |
| 2312 |
}; |
| 2313 |
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); |
| 2314 |
} |
| 2315 |
|
| 2316 |
function __read(o, n) { |
| 2317 |
var m = typeof Symbol === "function" && o[Symbol.iterator]; |
| 2318 |
if (!m) return o; |
| 2319 |
var i = m.call(o), r, ar = [], e; |
| 2320 |
try { |
| 2321 |
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); |
| 2322 |
} |
| 2323 |
catch (error) { e = { error: error }; } |
| 2324 |
finally { |
| 2325 |
try { |
| 2326 |
if (r && !r.done && (m = i["return"])) m.call(i); |
| 2327 |
} |
| 2328 |
finally { if (e) throw e.error; } |
| 2329 |
} |
| 2330 |
return ar; |
| 2331 |
} |
| 2332 |
|
| 2333 |
/** @deprecated */ |
| 2334 |
function __spread() { |
| 2335 |
for (var ar = [], i = 0; i < arguments.length; i++) |
| 2336 |
ar = ar.concat(__read(arguments[i])); |
| 2337 |
return ar; |
| 2338 |
} |
| 2339 |
|
| 2340 |
/** @deprecated */ |
| 2341 |
function __spreadArrays() { |
| 2342 |
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; |
| 2343 |
for (var r = Array(s), k = 0, i = 0; i < il; i++) |
| 2344 |
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) |
| 2345 |
r[k] = a[j]; |
| 2346 |
return r; |
| 2347 |
} |
| 2348 |
|
| 2349 |
function __spreadArray(to, from, pack) { |
| 2350 |
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { |
| 2351 |
if (ar || !(i in from)) { |
| 2352 |
if (!ar) ar = Array.prototype.slice.call(from, 0, i); |
| 2353 |
ar[i] = from[i]; |
| 2354 |
} |
| 2355 |
} |
| 2356 |
return to.concat(ar || Array.prototype.slice.call(from)); |
| 2357 |
} |
| 2358 |
|
| 2359 |
function __await(v) { |
| 2360 |
return this instanceof __await ? (this.v = v, this) : new __await(v); |
| 2361 |
} |
| 2362 |
|
| 2363 |
function __asyncGenerator(thisArg, _arguments, generator) { |
| 2364 |
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); |
| 2365 |
var g = generator.apply(thisArg, _arguments || []), i, q = []; |
| 2366 |
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i; |
| 2367 |
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; } |
| 2368 |
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } } |
| 2369 |
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } |
| 2370 |
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } |
| 2371 |
function fulfill(value) { resume("next", value); } |
| 2372 |
function reject(value) { resume("throw", value); } |
| 2373 |
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } |
| 2374 |
} |
| 2375 |
|
| 2376 |
function __asyncDelegator(o) { |
| 2377 |
var i, p; |
| 2378 |
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; |
| 2379 |
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; } |
| 2380 |
} |
| 2381 |
|
| 2382 |
function __asyncValues(o) { |
| 2383 |
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); |
| 2384 |
var m = o[Symbol.asyncIterator], i; |
| 2385 |
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); |
| 2386 |
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } |
| 2387 |
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } |
| 2388 |
} |
| 2389 |
|
| 2390 |
function __makeTemplateObject(cooked, raw) { |
| 2391 |
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } |
| 2392 |
return cooked; |
| 2393 |
}; |
| 2394 |
|
| 2395 |
var __setModuleDefault = Object.create ? (function(o, v) { |
| 2396 |
Object.defineProperty(o, "default", { enumerable: true, value: v }); |
| 2397 |
}) : function(o, v) { |
| 2398 |
o["default"] = v; |
| 2399 |
}; |
| 2400 |
|
| 2401 |
function __importStar(mod) { |
| 2402 |
if (mod && mod.__esModule) return mod; |
| 2403 |
var result = {}; |
| 2404 |
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); |
| 2405 |
__setModuleDefault(result, mod); |
| 2406 |
return result; |
| 2407 |
} |
| 2408 |
|
| 2409 |
function __importDefault(mod) { |
| 2410 |
return (mod && mod.__esModule) ? mod : { default: mod }; |
| 2411 |
} |
| 2412 |
|
| 2413 |
function __classPrivateFieldGet(receiver, state, kind, f) { |
| 2414 |
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); |
| 2415 |
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); |
| 2416 |
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); |
| 2417 |
} |
| 2418 |
|
| 2419 |
function __classPrivateFieldSet(receiver, state, value, kind, f) { |
| 2420 |
if (kind === "m") throw new TypeError("Private method is not writable"); |
| 2421 |
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); |
| 2422 |
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); |
| 2423 |
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; |
| 2424 |
} |
| 2425 |
|
| 2426 |
function __classPrivateFieldIn(state, receiver) { |
| 2427 |
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object"); |
| 2428 |
return typeof state === "function" ? receiver === state : state.has(receiver); |
| 2429 |
} |
| 2430 |
|
| 2431 |
function __addDisposableResource(env, value, async) { |
| 2432 |
if (value !== null && value !== void 0) { |
| 2433 |
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); |
| 2434 |
var dispose, inner; |
| 2435 |
if (async) { |
| 2436 |
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); |
| 2437 |
dispose = value[Symbol.asyncDispose]; |
| 2438 |
} |
| 2439 |
if (dispose === void 0) { |
| 2440 |
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); |
| 2441 |
dispose = value[Symbol.dispose]; |
| 2442 |
if (async) inner = dispose; |
| 2443 |
} |
| 2444 |
if (typeof dispose !== "function") throw new TypeError("Object not disposable."); |
| 2445 |
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; |
| 2446 |
env.stack.push({ value: value, dispose: dispose, async: async }); |
| 2447 |
} |
| 2448 |
else if (async) { |
| 2449 |
env.stack.push({ async: true }); |
| 2450 |
} |
| 2451 |
return value; |
| 2452 |
} |
| 2453 |
|
| 2454 |
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { |
| 2455 |
var e = new Error(message); |
| 2456 |
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; |
| 2457 |
}; |
| 2458 |
|
| 2459 |
function __disposeResources(env) { |
| 2460 |
function fail(e) { |
| 2461 |
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; |
| 2462 |
env.hasError = true; |
| 2463 |
} |
| 2464 |
var r, s = 0; |
| 2465 |
function next() { |
| 2466 |
while (r = env.stack.pop()) { |
| 2467 |
try { |
| 2468 |
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); |
| 2469 |
if (r.dispose) { |
| 2470 |
var result = r.dispose.call(r.value); |
| 2471 |
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); |
| 2472 |
} |
| 2473 |
else s |= 1; |
| 2474 |
} |
| 2475 |
catch (e) { |
| 2476 |
fail(e); |
| 2477 |
} |
| 2478 |
} |
| 2479 |
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); |
| 2480 |
if (env.hasError) throw env.error; |
| 2481 |
} |
| 2482 |
return next(); |
| 2483 |
} |
| 2484 |
|
| 2485 |
function __rewriteRelativeImportExtension(path, preserveJsx) { |
| 2486 |
if (typeof path === "string" && /^\.\.?\//.test(path)) { |
| 2487 |
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { |
| 2488 |
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); |
| 2489 |
}); |
| 2490 |
} |
| 2491 |
return path; |
| 2492 |
} |
| 2493 |
|
| 2494 |
/* harmony default export */ const tslib_es6 = ({ |
| 2495 |
__extends, |
| 2496 |
__assign, |
| 2497 |
__rest, |
| 2498 |
__decorate, |
| 2499 |
__param, |
| 2500 |
__esDecorate, |
| 2501 |
__runInitializers, |
| 2502 |
__propKey, |
| 2503 |
__setFunctionName, |
| 2504 |
__metadata, |
| 2505 |
__awaiter, |
| 2506 |
__generator, |
| 2507 |
__createBinding, |
| 2508 |
__exportStar, |
| 2509 |
__values, |
| 2510 |
__read, |
| 2511 |
__spread, |
| 2512 |
__spreadArrays, |
| 2513 |
__spreadArray, |
| 2514 |
__await, |
| 2515 |
__asyncGenerator, |
| 2516 |
__asyncDelegator, |
| 2517 |
__asyncValues, |
| 2518 |
__makeTemplateObject, |
| 2519 |
__importStar, |
| 2520 |
__importDefault, |
| 2521 |
__classPrivateFieldGet, |
| 2522 |
__classPrivateFieldSet, |
| 2523 |
__classPrivateFieldIn, |
| 2524 |
__addDisposableResource, |
| 2525 |
__disposeResources, |
| 2526 |
__rewriteRelativeImportExtension, |
| 2527 |
}); |
| 2528 |
|
| 2529 |
;// ./node_modules/lower-case/dist.es2015/index.js |
| 2530 |
/** |
| 2531 |
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt |
| 2532 |
*/ |
| 2533 |
var SUPPORTED_LOCALE = { |
| 2534 |
tr: { |
| 2535 |
regexp: /\u0130|\u0049|\u0049\u0307/g, |
| 2536 |
map: { |
| 2537 |
İ: "\u0069", |
| 2538 |
I: "\u0131", |
| 2539 |
İ: "\u0069", |
| 2540 |
}, |
| 2541 |
}, |
| 2542 |
az: { |
| 2543 |
regexp: /\u0130/g, |
| 2544 |
map: { |
| 2545 |
İ: "\u0069", |
| 2546 |
I: "\u0131", |
| 2547 |
İ: "\u0069", |
| 2548 |
}, |
| 2549 |
}, |
| 2550 |
lt: { |
| 2551 |
regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g, |
| 2552 |
map: { |
| 2553 |
I: "\u0069\u0307", |
| 2554 |
J: "\u006A\u0307", |
| 2555 |
Į: "\u012F\u0307", |
| 2556 |
Ì: "\u0069\u0307\u0300", |
| 2557 |
Í: "\u0069\u0307\u0301", |
| 2558 |
Ĩ: "\u0069\u0307\u0303", |
| 2559 |
}, |
| 2560 |
}, |
| 2561 |
}; |
| 2562 |
/** |
| 2563 |
* Localized lower case. |
| 2564 |
*/ |
| 2565 |
function localeLowerCase(str, locale) { |
| 2566 |
var lang = SUPPORTED_LOCALE[locale.toLowerCase()]; |
| 2567 |
if (lang) |
| 2568 |
return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; })); |
| 2569 |
return lowerCase(str); |
| 2570 |
} |
| 2571 |
/** |
| 2572 |
* Lower case as a function. |
| 2573 |
*/ |
| 2574 |
function lowerCase(str) { |
| 2575 |
return str.toLowerCase(); |
| 2576 |
} |
| 2577 |
|
| 2578 |
;// ./node_modules/no-case/dist.es2015/index.js |
| 2579 |
|
| 2580 |
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case"). |
| 2581 |
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g]; |
| 2582 |
// Remove all non-word characters. |
| 2583 |
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi; |
| 2584 |
/** |
| 2585 |
* Normalize the string into something other libraries can manipulate easier. |
| 2586 |
*/ |
| 2587 |
function noCase(input, options) { |
| 2588 |
if (options === void 0) { options = {}; } |
| 2589 |
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; |
| 2590 |
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0"); |
| 2591 |
var start = 0; |
| 2592 |
var end = result.length; |
| 2593 |
// Trim the delimiter from around the output string. |
| 2594 |
while (result.charAt(start) === "\0") |
| 2595 |
start++; |
| 2596 |
while (result.charAt(end - 1) === "\0") |
| 2597 |
end--; |
| 2598 |
// Transform each token independently. |
| 2599 |
return result.slice(start, end).split("\0").map(transform).join(delimiter); |
| 2600 |
} |
| 2601 |
/** |
| 2602 |
* Replace `re` in the input string with the replacement value. |
| 2603 |
*/ |
| 2604 |
function replace(input, re, value) { |
| 2605 |
if (re instanceof RegExp) |
| 2606 |
return input.replace(re, value); |
| 2607 |
return re.reduce(function (input, re) { return input.replace(re, value); }, input); |
| 2608 |
} |
| 2609 |
|
| 2610 |
;// ./node_modules/pascal-case/dist.es2015/index.js |
| 2611 |
|
| 2612 |
|
| 2613 |
function pascalCaseTransform(input, index) { |
| 2614 |
var firstChar = input.charAt(0); |
| 2615 |
var lowerChars = input.substr(1).toLowerCase(); |
| 2616 |
if (index > 0 && firstChar >= "0" && firstChar <= "9") { |
| 2617 |
return "_" + firstChar + lowerChars; |
| 2618 |
} |
| 2619 |
return "" + firstChar.toUpperCase() + lowerChars; |
| 2620 |
} |
| 2621 |
function pascalCaseTransformMerge(input) { |
| 2622 |
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase(); |
| 2623 |
} |
| 2624 |
function pascalCase(input, options) { |
| 2625 |
if (options === void 0) { options = {}; } |
| 2626 |
return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options)); |
| 2627 |
} |
| 2628 |
|
| 2629 |
;// ./packages/compose/build-module/utils/create-higher-order-component/index.js |
| 2630 |
/** |
| 2631 |
* External dependencies |
| 2632 |
*/ |
| 2633 |
|
| 2634 |
/** |
| 2635 |
* Given a function mapping a component to an enhanced component and modifier |
| 2636 |
* name, returns the enhanced component augmented with a generated displayName. |
| 2637 |
* |
| 2638 |
* @param mapComponent Function mapping component to enhanced component. |
| 2639 |
* @param modifierName Seed name from which to generated display name. |
| 2640 |
* |
| 2641 |
* @return Component class with generated display name assigned. |
| 2642 |
*/ |
| 2643 |
function createHigherOrderComponent(mapComponent, modifierName) { |
| 2644 |
return Inner => { |
| 2645 |
const Outer = mapComponent(Inner); |
| 2646 |
Outer.displayName = hocName(modifierName, Inner); |
| 2647 |
return Outer; |
| 2648 |
}; |
| 2649 |
} |
| 2650 |
|
| 2651 |
/** |
| 2652 |
* Returns a displayName for a higher-order component, given a wrapper name. |
| 2653 |
* |
| 2654 |
* @example |
| 2655 |
* hocName( 'MyMemo', Widget ) === 'MyMemo(Widget)'; |
| 2656 |
* hocName( 'MyMemo', <div /> ) === 'MyMemo(Component)'; |
| 2657 |
* |
| 2658 |
* @param name Name assigned to higher-order component's wrapper component. |
| 2659 |
* @param Inner Wrapped component inside higher-order component. |
| 2660 |
* @return Wrapped name of higher-order component. |
| 2661 |
*/ |
| 2662 |
const hocName = (name, Inner) => { |
| 2663 |
const inner = Inner.displayName || Inner.name || 'Component'; |
| 2664 |
const outer = pascalCase(name !== null && name !== void 0 ? name : ''); |
| 2665 |
return `${outer}(${inner})`; |
| 2666 |
}; |
| 2667 |
|
| 2668 |
;// ./packages/compose/build-module/utils/debounce/index.js |
| 2669 |
/** |
| 2670 |
* Parts of this source were derived and modified from lodash, |
| 2671 |
* released under the MIT license. |
| 2672 |
* |
| 2673 |
* https://github.com/lodash/lodash |
| 2674 |
* |
| 2675 |
* Copyright JS Foundation and other contributors <https://js.foundation/> |
| 2676 |
* |
| 2677 |
* Based on Underscore.js, copyright Jeremy Ashkenas, |
| 2678 |
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> |
| 2679 |
* |
| 2680 |
* This software consists of voluntary contributions made by many |
| 2681 |
* individuals. For exact contribution history, see the revision history |
| 2682 |
* available at https://github.com/lodash/lodash |
| 2683 |
* |
| 2684 |
* The following license applies to all parts of this software except as |
| 2685 |
* documented below: |
| 2686 |
* |
| 2687 |
* ==== |
| 2688 |
* |
| 2689 |
* Permission is hereby granted, free of charge, to any person obtaining |
| 2690 |
* a copy of this software and associated documentation files (the |
| 2691 |
* "Software"), to deal in the Software without restriction, including |
| 2692 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 2693 |
* distribute, sublicense, and/or sell copies of the Software, and to |
| 2694 |
* permit persons to whom the Software is furnished to do so, subject to |
| 2695 |
* the following conditions: |
| 2696 |
* |
| 2697 |
* The above copyright notice and this permission notice shall be |
| 2698 |
* included in all copies or substantial portions of the Software. |
| 2699 |
* |
| 2700 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 2701 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 2702 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 2703 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 2704 |
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 2705 |
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 2706 |
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 2707 |
*/ |
| 2708 |
|
| 2709 |
/** |
| 2710 |
* A simplified and properly typed version of lodash's `debounce`, that |
| 2711 |
* always uses timers instead of sometimes using rAF. |
| 2712 |
* |
| 2713 |
* Creates a debounced function that delays invoking `func` until after `wait` |
| 2714 |
* milliseconds have elapsed since the last time the debounced function was |
| 2715 |
* invoked. The debounced function comes with a `cancel` method to cancel delayed |
| 2716 |
* `func` invocations and a `flush` method to immediately invoke them. Provide |
| 2717 |
* `options` to indicate whether `func` should be invoked on the leading and/or |
| 2718 |
* trailing edge of the `wait` timeout. The `func` is invoked with the last |
| 2719 |
* arguments provided to the debounced function. Subsequent calls to the debounced |
| 2720 |
* function return the result of the last `func` invocation. |
| 2721 |
* |
| 2722 |
* **Note:** If `leading` and `trailing` options are `true`, `func` is |
| 2723 |
* invoked on the trailing edge of the timeout only if the debounced function |
| 2724 |
* is invoked more than once during the `wait` timeout. |
| 2725 |
* |
| 2726 |
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred |
| 2727 |
* until the next tick, similar to `setTimeout` with a timeout of `0`. |
| 2728 |
* |
| 2729 |
* @param {Function} func The function to debounce. |
| 2730 |
* @param {number} wait The number of milliseconds to delay. |
| 2731 |
* @param {Partial< DebounceOptions >} options The options object. |
| 2732 |
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout. |
| 2733 |
* @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked. |
| 2734 |
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout. |
| 2735 |
* |
| 2736 |
* @return Returns the new debounced function. |
| 2737 |
*/ |
| 2738 |
const debounce = (func, wait, options) => { |
| 2739 |
let lastArgs; |
| 2740 |
let lastThis; |
| 2741 |
let maxWait = 0; |
| 2742 |
let result; |
| 2743 |
let timerId; |
| 2744 |
let lastCallTime; |
| 2745 |
let lastInvokeTime = 0; |
| 2746 |
let leading = false; |
| 2747 |
let maxing = false; |
| 2748 |
let trailing = true; |
| 2749 |
if (options) { |
| 2750 |
leading = !!options.leading; |
| 2751 |
maxing = 'maxWait' in options; |
| 2752 |
if (options.maxWait !== undefined) { |
| 2753 |
maxWait = Math.max(options.maxWait, wait); |
| 2754 |
} |
| 2755 |
trailing = 'trailing' in options ? !!options.trailing : trailing; |
| 2756 |
} |
| 2757 |
function invokeFunc(time) { |
| 2758 |
const args = lastArgs; |
| 2759 |
const thisArg = lastThis; |
| 2760 |
lastArgs = undefined; |
| 2761 |
lastThis = undefined; |
| 2762 |
lastInvokeTime = time; |
| 2763 |
result = func.apply(thisArg, args); |
| 2764 |
return result; |
| 2765 |
} |
| 2766 |
function startTimer(pendingFunc, waitTime) { |
| 2767 |
timerId = setTimeout(pendingFunc, waitTime); |
| 2768 |
} |
| 2769 |
function cancelTimer() { |
| 2770 |
if (timerId !== undefined) { |
| 2771 |
clearTimeout(timerId); |
| 2772 |
} |
| 2773 |
} |
| 2774 |
function leadingEdge(time) { |
| 2775 |
// Reset any `maxWait` timer. |
| 2776 |
lastInvokeTime = time; |
| 2777 |
// Start the timer for the trailing edge. |
| 2778 |
startTimer(timerExpired, wait); |
| 2779 |
// Invoke the leading edge. |
| 2780 |
return leading ? invokeFunc(time) : result; |
| 2781 |
} |
| 2782 |
function getTimeSinceLastCall(time) { |
| 2783 |
return time - (lastCallTime || 0); |
| 2784 |
} |
| 2785 |
function remainingWait(time) { |
| 2786 |
const timeSinceLastCall = getTimeSinceLastCall(time); |
| 2787 |
const timeSinceLastInvoke = time - lastInvokeTime; |
| 2788 |
const timeWaiting = wait - timeSinceLastCall; |
| 2789 |
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting; |
| 2790 |
} |
| 2791 |
function shouldInvoke(time) { |
| 2792 |
const timeSinceLastCall = getTimeSinceLastCall(time); |
| 2793 |
const timeSinceLastInvoke = time - lastInvokeTime; |
| 2794 |
|
| 2795 |
// Either this is the first call, activity has stopped and we're at the |
| 2796 |
// trailing edge, the system time has gone backwards and we're treating |
| 2797 |
// it as the trailing edge, or we've hit the `maxWait` limit. |
| 2798 |
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; |
| 2799 |
} |
| 2800 |
function timerExpired() { |
| 2801 |
const time = Date.now(); |
| 2802 |
if (shouldInvoke(time)) { |
| 2803 |
return trailingEdge(time); |
| 2804 |
} |
| 2805 |
// Restart the timer. |
| 2806 |
startTimer(timerExpired, remainingWait(time)); |
| 2807 |
return undefined; |
| 2808 |
} |
| 2809 |
function clearTimer() { |
| 2810 |
timerId = undefined; |
| 2811 |
} |
| 2812 |
function trailingEdge(time) { |
| 2813 |
clearTimer(); |
| 2814 |
|
| 2815 |
// Only invoke if we have `lastArgs` which means `func` has been |
| 2816 |
// debounced at least once. |
| 2817 |
if (trailing && lastArgs) { |
| 2818 |
return invokeFunc(time); |
| 2819 |
} |
| 2820 |
lastArgs = lastThis = undefined; |
| 2821 |
return result; |
| 2822 |
} |
| 2823 |
function cancel() { |
| 2824 |
cancelTimer(); |
| 2825 |
lastInvokeTime = 0; |
| 2826 |
clearTimer(); |
| 2827 |
lastArgs = lastCallTime = lastThis = undefined; |
| 2828 |
} |
| 2829 |
function flush() { |
| 2830 |
return pending() ? trailingEdge(Date.now()) : result; |
| 2831 |
} |
| 2832 |
function pending() { |
| 2833 |
return timerId !== undefined; |
| 2834 |
} |
| 2835 |
function debounced(...args) { |
| 2836 |
const time = Date.now(); |
| 2837 |
const isInvoking = shouldInvoke(time); |
| 2838 |
lastArgs = args; |
| 2839 |
lastThis = this; |
| 2840 |
lastCallTime = time; |
| 2841 |
if (isInvoking) { |
| 2842 |
if (!pending()) { |
| 2843 |
return leadingEdge(lastCallTime); |
| 2844 |
} |
| 2845 |
if (maxing) { |
| 2846 |
// Handle invocations in a tight loop. |
| 2847 |
startTimer(timerExpired, wait); |
| 2848 |
return invokeFunc(lastCallTime); |
| 2849 |
} |
| 2850 |
} |
| 2851 |
if (!pending()) { |
| 2852 |
startTimer(timerExpired, wait); |
| 2853 |
} |
| 2854 |
return result; |
| 2855 |
} |
| 2856 |
debounced.cancel = cancel; |
| 2857 |
debounced.flush = flush; |
| 2858 |
debounced.pending = pending; |
| 2859 |
return debounced; |
| 2860 |
}; |
| 2861 |
|
| 2862 |
;// ./packages/compose/build-module/utils/throttle/index.js |
| 2863 |
/** |
| 2864 |
* Parts of this source were derived and modified from lodash, |
| 2865 |
* released under the MIT license. |
| 2866 |
* |
| 2867 |
* https://github.com/lodash/lodash |
| 2868 |
* |
| 2869 |
* Copyright JS Foundation and other contributors <https://js.foundation/> |
| 2870 |
* |
| 2871 |
* Based on Underscore.js, copyright Jeremy Ashkenas, |
| 2872 |
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> |
| 2873 |
* |
| 2874 |
* This software consists of voluntary contributions made by many |
| 2875 |
* individuals. For exact contribution history, see the revision history |
| 2876 |
* available at https://github.com/lodash/lodash |
| 2877 |
* |
| 2878 |
* The following license applies to all parts of this software except as |
| 2879 |
* documented below: |
| 2880 |
* |
| 2881 |
* ==== |
| 2882 |
* |
| 2883 |
* Permission is hereby granted, free of charge, to any person obtaining |
| 2884 |
* a copy of this software and associated documentation files (the |
| 2885 |
* "Software"), to deal in the Software without restriction, including |
| 2886 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 2887 |
* distribute, sublicense, and/or sell copies of the Software, and to |
| 2888 |
* permit persons to whom the Software is furnished to do so, subject to |
| 2889 |
* the following conditions: |
| 2890 |
* |
| 2891 |
* The above copyright notice and this permission notice shall be |
| 2892 |
* included in all copies or substantial portions of the Software. |
| 2893 |
* |
| 2894 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 2895 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 2896 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 2897 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 2898 |
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 2899 |
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 2900 |
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 2901 |
*/ |
| 2902 |
|
| 2903 |
/** |
| 2904 |
* Internal dependencies |
| 2905 |
*/ |
| 2906 |
|
| 2907 |
/** |
| 2908 |
* A simplified and properly typed version of lodash's `throttle`, that |
| 2909 |
* always uses timers instead of sometimes using rAF. |
| 2910 |
* |
| 2911 |
* Creates a throttled function that only invokes `func` at most once per |
| 2912 |
* every `wait` milliseconds. The throttled function comes with a `cancel` |
| 2913 |
* method to cancel delayed `func` invocations and a `flush` method to |
| 2914 |
* immediately invoke them. Provide `options` to indicate whether `func` |
| 2915 |
* should be invoked on the leading and/or trailing edge of the `wait` |
| 2916 |
* timeout. The `func` is invoked with the last arguments provided to the |
| 2917 |
* throttled function. Subsequent calls to the throttled function return |
| 2918 |
* the result of the last `func` invocation. |
| 2919 |
* |
| 2920 |
* **Note:** If `leading` and `trailing` options are `true`, `func` is |
| 2921 |
* invoked on the trailing edge of the timeout only if the throttled function |
| 2922 |
* is invoked more than once during the `wait` timeout. |
| 2923 |
* |
| 2924 |
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred |
| 2925 |
* until the next tick, similar to `setTimeout` with a timeout of `0`. |
| 2926 |
* |
| 2927 |
* @param {Function} func The function to throttle. |
| 2928 |
* @param {number} wait The number of milliseconds to throttle invocations to. |
| 2929 |
* @param {Partial< ThrottleOptions >} options The options object. |
| 2930 |
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout. |
| 2931 |
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout. |
| 2932 |
* @return Returns the new throttled function. |
| 2933 |
*/ |
| 2934 |
const throttle = (func, wait, options) => { |
| 2935 |
let leading = true; |
| 2936 |
let trailing = true; |
| 2937 |
if (options) { |
| 2938 |
leading = 'leading' in options ? !!options.leading : leading; |
| 2939 |
trailing = 'trailing' in options ? !!options.trailing : trailing; |
| 2940 |
} |
| 2941 |
return debounce(func, wait, { |
| 2942 |
leading, |
| 2943 |
trailing, |
| 2944 |
maxWait: wait |
| 2945 |
}); |
| 2946 |
}; |
| 2947 |
|
| 2948 |
;// ./packages/compose/build-module/utils/observable-map/index.js |
| 2949 |
/* wp:polyfill */ |
| 2950 |
/** |
| 2951 |
* A constructor (factory) for `ObservableMap`, a map-like key/value data structure |
| 2952 |
* where the individual entries are observable: using the `subscribe` method, you can |
| 2953 |
* subscribe to updates for a particular keys. Each subscriber always observes one |
| 2954 |
* specific key and is not notified about any unrelated changes (for different keys) |
| 2955 |
* in the `ObservableMap`. |
| 2956 |
* |
| 2957 |
* @template K The type of the keys in the map. |
| 2958 |
* @template V The type of the values in the map. |
| 2959 |
* @return A new instance of the `ObservableMap` type. |
| 2960 |
*/ |
| 2961 |
function observableMap() { |
| 2962 |
const map = new Map(); |
| 2963 |
const listeners = new Map(); |
| 2964 |
function callListeners(name) { |
| 2965 |
const list = listeners.get(name); |
| 2966 |
if (!list) { |
| 2967 |
return; |
| 2968 |
} |
| 2969 |
for (const listener of list) { |
| 2970 |
listener(); |
| 2971 |
} |
| 2972 |
} |
| 2973 |
return { |
| 2974 |
get(name) { |
| 2975 |
return map.get(name); |
| 2976 |
}, |
| 2977 |
set(name, value) { |
| 2978 |
map.set(name, value); |
| 2979 |
callListeners(name); |
| 2980 |
}, |
| 2981 |
delete(name) { |
| 2982 |
map.delete(name); |
| 2983 |
callListeners(name); |
| 2984 |
}, |
| 2985 |
subscribe(name, listener) { |
| 2986 |
let list = listeners.get(name); |
| 2987 |
if (!list) { |
| 2988 |
list = new Set(); |
| 2989 |
listeners.set(name, list); |
| 2990 |
} |
| 2991 |
list.add(listener); |
| 2992 |
return () => { |
| 2993 |
list.delete(listener); |
| 2994 |
if (list.size === 0) { |
| 2995 |
listeners.delete(name); |
| 2996 |
} |
| 2997 |
}; |
| 2998 |
} |
| 2999 |
}; |
| 3000 |
} |
| 3001 |
|
| 3002 |
;// ./packages/compose/build-module/higher-order/pipe.js |
| 3003 |
/** |
| 3004 |
* Parts of this source were derived and modified from lodash, |
| 3005 |
* released under the MIT license. |
| 3006 |
* |
| 3007 |
* https://github.com/lodash/lodash |
| 3008 |
* |
| 3009 |
* Copyright JS Foundation and other contributors <https://js.foundation/> |
| 3010 |
* |
| 3011 |
* Based on Underscore.js, copyright Jeremy Ashkenas, |
| 3012 |
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> |
| 3013 |
* |
| 3014 |
* This software consists of voluntary contributions made by many |
| 3015 |
* individuals. For exact contribution history, see the revision history |
| 3016 |
* available at https://github.com/lodash/lodash |
| 3017 |
* |
| 3018 |
* The following license applies to all parts of this software except as |
| 3019 |
* documented below: |
| 3020 |
* |
| 3021 |
* ==== |
| 3022 |
* |
| 3023 |
* Permission is hereby granted, free of charge, to any person obtaining |
| 3024 |
* a copy of this software and associated documentation files (the |
| 3025 |
* "Software"), to deal in the Software without restriction, including |
| 3026 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 3027 |
* distribute, sublicense, and/or sell copies of the Software, and to |
| 3028 |
* permit persons to whom the Software is furnished to do so, subject to |
| 3029 |
* the following conditions: |
| 3030 |
* |
| 3031 |
* The above copyright notice and this permission notice shall be |
| 3032 |
* included in all copies or substantial portions of the Software. |
| 3033 |
* |
| 3034 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 3035 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 3036 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 3037 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 3038 |
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 3039 |
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 3040 |
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 3041 |
*/ |
| 3042 |
|
| 3043 |
/** |
| 3044 |
* Creates a pipe function. |
| 3045 |
* |
| 3046 |
* Allows to choose whether to perform left-to-right or right-to-left composition. |
| 3047 |
* |
| 3048 |
* @see https://lodash.com/docs/4#flow |
| 3049 |
* |
| 3050 |
* @param {boolean} reverse True if right-to-left, false for left-to-right composition. |
| 3051 |
*/ |
| 3052 |
const basePipe = (reverse = false) => (...funcs) => (...args) => { |
| 3053 |
const functions = funcs.flat(); |
| 3054 |
if (reverse) { |
| 3055 |
functions.reverse(); |
| 3056 |
} |
| 3057 |
return functions.reduce((prev, func) => [func(...prev)], args)[0]; |
| 3058 |
}; |
| 3059 |
|
| 3060 |
/** |
| 3061 |
* Composes multiple higher-order components into a single higher-order component. Performs left-to-right function |
| 3062 |
* composition, where each successive invocation is supplied the return value of the previous. |
| 3063 |
* |
| 3064 |
* This is inspired by `lodash`'s `flow` function. |
| 3065 |
* |
| 3066 |
* @see https://lodash.com/docs/4#flow |
| 3067 |
*/ |
| 3068 |
const pipe = basePipe(); |
| 3069 |
|
| 3070 |
/* harmony default export */ const higher_order_pipe = (pipe); |
| 3071 |
|
| 3072 |
;// ./packages/compose/build-module/higher-order/compose.js |
| 3073 |
/** |
| 3074 |
* Internal dependencies |
| 3075 |
*/ |
| 3076 |
|
| 3077 |
|
| 3078 |
/** |
| 3079 |
* Composes multiple higher-order components into a single higher-order component. Performs right-to-left function |
| 3080 |
* composition, where each successive invocation is supplied the return value of the previous. |
| 3081 |
* |
| 3082 |
* This is inspired by `lodash`'s `flowRight` function. |
| 3083 |
* |
| 3084 |
* @see https://lodash.com/docs/4#flow-right |
| 3085 |
*/ |
| 3086 |
const compose = basePipe(true); |
| 3087 |
/* harmony default export */ const higher_order_compose = (compose); |
| 3088 |
|
| 3089 |
;// external "ReactJSXRuntime" |
| 3090 |
const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; |
| 3091 |
;// ./packages/compose/build-module/higher-order/if-condition/index.js |
| 3092 |
/** |
| 3093 |
* External dependencies |
| 3094 |
*/ |
| 3095 |
|
| 3096 |
/** |
| 3097 |
* Internal dependencies |
| 3098 |
*/ |
| 3099 |
|
| 3100 |
|
| 3101 |
/** |
| 3102 |
* Higher-order component creator, creating a new component which renders if |
| 3103 |
* the given condition is satisfied or with the given optional prop name. |
| 3104 |
* |
| 3105 |
* @example |
| 3106 |
* ```ts |
| 3107 |
* type Props = { foo: string }; |
| 3108 |
* const Component = ( props: Props ) => <div>{ props.foo }</div>; |
| 3109 |
* const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component ); |
| 3110 |
* <ConditionalComponent foo="" />; // => null |
| 3111 |
* <ConditionalComponent foo="bar" />; // => <div>bar</div>; |
| 3112 |
* ``` |
| 3113 |
* |
| 3114 |
* @param predicate Function to test condition. |
| 3115 |
* |
| 3116 |
* @return Higher-order component. |
| 3117 |
*/ |
| 3118 |
|
| 3119 |
function ifCondition(predicate) { |
| 3120 |
return createHigherOrderComponent(WrappedComponent => props => { |
| 3121 |
if (!predicate(props)) { |
| 3122 |
return null; |
| 3123 |
} |
| 3124 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { |
| 3125 |
...props |
| 3126 |
}); |
| 3127 |
}, 'ifCondition'); |
| 3128 |
} |
| 3129 |
/* harmony default export */ const if_condition = (ifCondition); |
| 3130 |
|
| 3131 |
;// external ["wp","isShallowEqual"] |
| 3132 |
const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
| 3133 |
var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
| 3134 |
;// external ["wp","element"] |
| 3135 |
const external_wp_element_namespaceObject = window["wp"]["element"]; |
| 3136 |
;// ./packages/compose/build-module/higher-order/pure/index.js |
| 3137 |
/** |
| 3138 |
* External dependencies |
| 3139 |
*/ |
| 3140 |
|
| 3141 |
/** |
| 3142 |
* WordPress dependencies |
| 3143 |
*/ |
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
/** |
| 3148 |
* Internal dependencies |
| 3149 |
*/ |
| 3150 |
|
| 3151 |
|
| 3152 |
/** |
| 3153 |
* Given a component returns the enhanced component augmented with a component |
| 3154 |
* only re-rendering when its props/state change |
| 3155 |
* |
| 3156 |
* @deprecated Use `memo` or `PureComponent` instead. |
| 3157 |
*/ |
| 3158 |
|
| 3159 |
const pure = createHigherOrderComponent(function (WrappedComponent) { |
| 3160 |
if (WrappedComponent.prototype instanceof external_wp_element_namespaceObject.Component) { |
| 3161 |
return class extends WrappedComponent { |
| 3162 |
shouldComponentUpdate(nextProps, nextState) { |
| 3163 |
return !external_wp_isShallowEqual_default()(nextProps, this.props) || !external_wp_isShallowEqual_default()(nextState, this.state); |
| 3164 |
} |
| 3165 |
}; |
| 3166 |
} |
| 3167 |
return class extends external_wp_element_namespaceObject.Component { |
| 3168 |
shouldComponentUpdate(nextProps) { |
| 3169 |
return !external_wp_isShallowEqual_default()(nextProps, this.props); |
| 3170 |
} |
| 3171 |
render() { |
| 3172 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { |
| 3173 |
...this.props |
| 3174 |
}); |
| 3175 |
} |
| 3176 |
}; |
| 3177 |
}, 'pure'); |
| 3178 |
/* harmony default export */ const higher_order_pure = (pure); |
| 3179 |
|
| 3180 |
;// external ["wp","deprecated"] |
| 3181 |
const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
| 3182 |
var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
| 3183 |
;// ./packages/compose/build-module/higher-order/with-global-events/listener.js |
| 3184 |
/** |
| 3185 |
* Class responsible for orchestrating event handling on the global window, |
| 3186 |
* binding a single event to be shared across all handling instances, and |
| 3187 |
* removing the handler when no instances are listening for the event. |
| 3188 |
*/ |
| 3189 |
class Listener { |
| 3190 |
constructor() { |
| 3191 |
/** @type {any} */ |
| 3192 |
this.listeners = {}; |
| 3193 |
this.handleEvent = this.handleEvent.bind(this); |
| 3194 |
} |
| 3195 |
add(/** @type {any} */eventType, /** @type {any} */instance) { |
| 3196 |
if (!this.listeners[eventType]) { |
| 3197 |
// Adding first listener for this type, so bind event. |
| 3198 |
window.addEventListener(eventType, this.handleEvent); |
| 3199 |
this.listeners[eventType] = []; |
| 3200 |
} |
| 3201 |
this.listeners[eventType].push(instance); |
| 3202 |
} |
| 3203 |
remove(/** @type {any} */eventType, /** @type {any} */instance) { |
| 3204 |
if (!this.listeners[eventType]) { |
| 3205 |
return; |
| 3206 |
} |
| 3207 |
this.listeners[eventType] = this.listeners[eventType].filter((/** @type {any} */listener) => listener !== instance); |
| 3208 |
if (!this.listeners[eventType].length) { |
| 3209 |
// Removing last listener for this type, so unbind event. |
| 3210 |
window.removeEventListener(eventType, this.handleEvent); |
| 3211 |
delete this.listeners[eventType]; |
| 3212 |
} |
| 3213 |
} |
| 3214 |
handleEvent(/** @type {any} */event) { |
| 3215 |
this.listeners[event.type]?.forEach((/** @type {any} */instance) => { |
| 3216 |
instance.handleEvent(event); |
| 3217 |
}); |
| 3218 |
} |
| 3219 |
} |
| 3220 |
/* harmony default export */ const listener = (Listener); |
| 3221 |
|
| 3222 |
;// ./packages/compose/build-module/higher-order/with-global-events/index.js |
| 3223 |
/** |
| 3224 |
* WordPress dependencies |
| 3225 |
*/ |
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
/** |
| 3230 |
* Internal dependencies |
| 3231 |
*/ |
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
/** |
| 3236 |
* Listener instance responsible for managing document event handling. |
| 3237 |
*/ |
| 3238 |
|
| 3239 |
const with_global_events_listener = new listener(); |
| 3240 |
|
| 3241 |
/* eslint-disable jsdoc/no-undefined-types */ |
| 3242 |
/** |
| 3243 |
* Higher-order component creator which, given an object of DOM event types and |
| 3244 |
* values corresponding to a callback function name on the component, will |
| 3245 |
* create or update a window event handler to invoke the callback when an event |
| 3246 |
* occurs. On behalf of the consuming developer, the higher-order component |
| 3247 |
* manages unbinding when the component unmounts, and binding at most a single |
| 3248 |
* event handler for the entire application. |
| 3249 |
* |
| 3250 |
* @deprecated |
| 3251 |
* |
| 3252 |
* @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM |
| 3253 |
* event type, the value a |
| 3254 |
* name of the function on |
| 3255 |
* the original component's |
| 3256 |
* instance which handles |
| 3257 |
* the event. |
| 3258 |
* |
| 3259 |
* @return {any} Higher-order component. |
| 3260 |
*/ |
| 3261 |
function withGlobalEvents(eventTypesToHandlers) { |
| 3262 |
external_wp_deprecated_default()('wp.compose.withGlobalEvents', { |
| 3263 |
since: '5.7', |
| 3264 |
alternative: 'useEffect' |
| 3265 |
}); |
| 3266 |
|
| 3267 |
// @ts-ignore We don't need to fix the type-related issues because this is deprecated. |
| 3268 |
return createHigherOrderComponent(WrappedComponent => { |
| 3269 |
class Wrapper extends external_wp_element_namespaceObject.Component { |
| 3270 |
constructor(/** @type {any} */props) { |
| 3271 |
super(props); |
| 3272 |
this.handleEvent = this.handleEvent.bind(this); |
| 3273 |
this.handleRef = this.handleRef.bind(this); |
| 3274 |
} |
| 3275 |
componentDidMount() { |
| 3276 |
Object.keys(eventTypesToHandlers).forEach(eventType => { |
| 3277 |
with_global_events_listener.add(eventType, this); |
| 3278 |
}); |
| 3279 |
} |
| 3280 |
componentWillUnmount() { |
| 3281 |
Object.keys(eventTypesToHandlers).forEach(eventType => { |
| 3282 |
with_global_events_listener.remove(eventType, this); |
| 3283 |
}); |
| 3284 |
} |
| 3285 |
handleEvent(/** @type {any} */event) { |
| 3286 |
const handler = eventTypesToHandlers[(/** @type {keyof GlobalEventHandlersEventMap} */ |
| 3287 |
event.type |
| 3288 |
|
| 3289 |
/* eslint-enable jsdoc/no-undefined-types */)]; |
| 3290 |
if (typeof this.wrappedRef[handler] === 'function') { |
| 3291 |
this.wrappedRef[handler](event); |
| 3292 |
} |
| 3293 |
} |
| 3294 |
handleRef(/** @type {any} */el) { |
| 3295 |
this.wrappedRef = el; |
| 3296 |
// Any component using `withGlobalEvents` that is not setting a `ref` |
| 3297 |
// will cause `this.props.forwardedRef` to be `null`, so we need this |
| 3298 |
// check. |
| 3299 |
if (this.props.forwardedRef) { |
| 3300 |
this.props.forwardedRef(el); |
| 3301 |
} |
| 3302 |
} |
| 3303 |
render() { |
| 3304 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { |
| 3305 |
...this.props.ownProps, |
| 3306 |
ref: this.handleRef |
| 3307 |
}); |
| 3308 |
} |
| 3309 |
} |
| 3310 |
return (0,external_wp_element_namespaceObject.forwardRef)((props, ref) => { |
| 3311 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Wrapper, { |
| 3312 |
ownProps: props, |
| 3313 |
forwardedRef: ref |
| 3314 |
}); |
| 3315 |
}); |
| 3316 |
}, 'withGlobalEvents'); |
| 3317 |
} |
| 3318 |
|
| 3319 |
;// ./packages/compose/build-module/hooks/use-instance-id/index.js |
| 3320 |
/** |
| 3321 |
* WordPress dependencies |
| 3322 |
*/ |
| 3323 |
|
| 3324 |
const instanceMap = new WeakMap(); |
| 3325 |
|
| 3326 |
/** |
| 3327 |
* Creates a new id for a given object. |
| 3328 |
* |
| 3329 |
* @param object Object reference to create an id for. |
| 3330 |
* @return The instance id (index). |
| 3331 |
*/ |
| 3332 |
function createId(object) { |
| 3333 |
const instances = instanceMap.get(object) || 0; |
| 3334 |
instanceMap.set(object, instances + 1); |
| 3335 |
return instances; |
| 3336 |
} |
| 3337 |
|
| 3338 |
/** |
| 3339 |
* Specify the useInstanceId *function* signatures. |
| 3340 |
* |
| 3341 |
* More accurately, useInstanceId distinguishes between three different |
| 3342 |
* signatures: |
| 3343 |
* |
| 3344 |
* 1. When only object is given, the returned value is a number |
| 3345 |
* 2. When object and prefix is given, the returned value is a string |
| 3346 |
* 3. When preferredId is given, the returned value is the type of preferredId |
| 3347 |
* |
| 3348 |
* @param object Object reference to create an id for. |
| 3349 |
*/ |
| 3350 |
|
| 3351 |
/** |
| 3352 |
* Provides a unique instance ID. |
| 3353 |
* |
| 3354 |
* @param object Object reference to create an id for. |
| 3355 |
* @param [prefix] Prefix for the unique id. |
| 3356 |
* @param [preferredId] Default ID to use. |
| 3357 |
* @return The unique instance id. |
| 3358 |
*/ |
| 3359 |
function useInstanceId(object, prefix, preferredId) { |
| 3360 |
return (0,external_wp_element_namespaceObject.useMemo)(() => { |
| 3361 |
if (preferredId) { |
| 3362 |
return preferredId; |
| 3363 |
} |
| 3364 |
const id = createId(object); |
| 3365 |
return prefix ? `${prefix}-${id}` : id; |
| 3366 |
}, [object, preferredId, prefix]); |
| 3367 |
} |
| 3368 |
/* harmony default export */ const use_instance_id = (useInstanceId); |
| 3369 |
|
| 3370 |
;// ./packages/compose/build-module/higher-order/with-instance-id/index.js |
| 3371 |
/** |
| 3372 |
* Internal dependencies |
| 3373 |
*/ |
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
/** |
| 3379 |
* A Higher Order Component used to provide a unique instance ID by component. |
| 3380 |
*/ |
| 3381 |
const withInstanceId = createHigherOrderComponent(WrappedComponent => { |
| 3382 |
return props => { |
| 3383 |
const instanceId = use_instance_id(WrappedComponent); |
| 3384 |
// @ts-ignore |
| 3385 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { |
| 3386 |
...props, |
| 3387 |
instanceId: instanceId |
| 3388 |
}); |
| 3389 |
}; |
| 3390 |
}, 'instanceId'); |
| 3391 |
/* harmony default export */ const with_instance_id = (withInstanceId); |
| 3392 |
|
| 3393 |
;// ./packages/compose/build-module/higher-order/with-safe-timeout/index.js |
| 3394 |
/** |
| 3395 |
* WordPress dependencies |
| 3396 |
*/ |
| 3397 |
|
| 3398 |
|
| 3399 |
/** |
| 3400 |
* Internal dependencies |
| 3401 |
*/ |
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
/** |
| 3406 |
* We cannot use the `Window['setTimeout']` and `Window['clearTimeout']` |
| 3407 |
* types here because those functions include functionality that is not handled |
| 3408 |
* by this component, like the ability to pass extra arguments. |
| 3409 |
* |
| 3410 |
* In the case of this component, we only handle the simplest case where |
| 3411 |
* `setTimeout` only accepts a function (not a string) and an optional delay. |
| 3412 |
*/ |
| 3413 |
|
| 3414 |
/** |
| 3415 |
* A higher-order component used to provide and manage delayed function calls |
| 3416 |
* that ought to be bound to a component's lifecycle. |
| 3417 |
*/ |
| 3418 |
const withSafeTimeout = createHigherOrderComponent(OriginalComponent => { |
| 3419 |
return class WrappedComponent extends external_wp_element_namespaceObject.Component { |
| 3420 |
constructor(props) { |
| 3421 |
super(props); |
| 3422 |
this.timeouts = []; |
| 3423 |
this.setTimeout = this.setTimeout.bind(this); |
| 3424 |
this.clearTimeout = this.clearTimeout.bind(this); |
| 3425 |
} |
| 3426 |
componentWillUnmount() { |
| 3427 |
this.timeouts.forEach(clearTimeout); |
| 3428 |
} |
| 3429 |
setTimeout(fn, delay) { |
| 3430 |
const id = setTimeout(() => { |
| 3431 |
fn(); |
| 3432 |
this.clearTimeout(id); |
| 3433 |
}, delay); |
| 3434 |
this.timeouts.push(id); |
| 3435 |
return id; |
| 3436 |
} |
| 3437 |
clearTimeout(id) { |
| 3438 |
clearTimeout(id); |
| 3439 |
this.timeouts = this.timeouts.filter(timeoutId => timeoutId !== id); |
| 3440 |
} |
| 3441 |
render() { |
| 3442 |
return ( |
| 3443 |
/*#__PURE__*/ |
| 3444 |
// @ts-ignore |
| 3445 |
(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, { |
| 3446 |
...this.props, |
| 3447 |
setTimeout: this.setTimeout, |
| 3448 |
clearTimeout: this.clearTimeout |
| 3449 |
}) |
| 3450 |
); |
| 3451 |
} |
| 3452 |
}; |
| 3453 |
}, 'withSafeTimeout'); |
| 3454 |
/* harmony default export */ const with_safe_timeout = (withSafeTimeout); |
| 3455 |
|
| 3456 |
;// ./packages/compose/build-module/higher-order/with-state/index.js |
| 3457 |
/** |
| 3458 |
* WordPress dependencies |
| 3459 |
*/ |
| 3460 |
|
| 3461 |
|
| 3462 |
|
| 3463 |
/** |
| 3464 |
* Internal dependencies |
| 3465 |
*/ |
| 3466 |
|
| 3467 |
|
| 3468 |
/** |
| 3469 |
* A Higher Order Component used to provide and manage internal component state |
| 3470 |
* via props. |
| 3471 |
* |
| 3472 |
* @deprecated Use `useState` instead. |
| 3473 |
* |
| 3474 |
* @param {any} initialState Optional initial state of the component. |
| 3475 |
* |
| 3476 |
* @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props. |
| 3477 |
*/ |
| 3478 |
|
| 3479 |
function withState(initialState = {}) { |
| 3480 |
external_wp_deprecated_default()('wp.compose.withState', { |
| 3481 |
since: '5.8', |
| 3482 |
alternative: 'wp.element.useState' |
| 3483 |
}); |
| 3484 |
return createHigherOrderComponent(OriginalComponent => { |
| 3485 |
return class WrappedComponent extends external_wp_element_namespaceObject.Component { |
| 3486 |
constructor(/** @type {any} */props) { |
| 3487 |
super(props); |
| 3488 |
this.setState = this.setState.bind(this); |
| 3489 |
this.state = initialState; |
| 3490 |
} |
| 3491 |
render() { |
| 3492 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, { |
| 3493 |
...this.props, |
| 3494 |
...this.state, |
| 3495 |
setState: this.setState |
| 3496 |
}); |
| 3497 |
} |
| 3498 |
}; |
| 3499 |
}, 'withState'); |
| 3500 |
} |
| 3501 |
|
| 3502 |
;// external ["wp","dom"] |
| 3503 |
const external_wp_dom_namespaceObject = window["wp"]["dom"]; |
| 3504 |
;// ./packages/compose/build-module/hooks/use-ref-effect/index.js |
| 3505 |
/** |
| 3506 |
* External dependencies |
| 3507 |
*/ |
| 3508 |
|
| 3509 |
/** |
| 3510 |
* WordPress dependencies |
| 3511 |
*/ |
| 3512 |
|
| 3513 |
|
| 3514 |
/** |
| 3515 |
* Effect-like ref callback. Just like with `useEffect`, this allows you to |
| 3516 |
* return a cleanup function to be run if the ref changes or one of the |
| 3517 |
* dependencies changes. The ref is provided as an argument to the callback |
| 3518 |
* functions. The main difference between this and `useEffect` is that |
| 3519 |
* the `useEffect` callback is not called when the ref changes, but this is. |
| 3520 |
* Pass the returned ref callback as the component's ref and merge multiple refs |
| 3521 |
* with `useMergeRefs`. |
| 3522 |
* |
| 3523 |
* It's worth noting that if the dependencies array is empty, there's not |
| 3524 |
* strictly a need to clean up event handlers for example, because the node is |
| 3525 |
* to be removed. It *is* necessary if you add dependencies because the ref |
| 3526 |
* callback will be called multiple times for the same node. |
| 3527 |
* |
| 3528 |
* @param callback Callback with ref as argument. |
| 3529 |
* @param dependencies Dependencies of the callback. |
| 3530 |
* |
| 3531 |
* @return Ref callback. |
| 3532 |
*/ |
| 3533 |
function useRefEffect(callback, dependencies) { |
| 3534 |
const cleanupRef = (0,external_wp_element_namespaceObject.useRef)(); |
| 3535 |
return (0,external_wp_element_namespaceObject.useCallback)(node => { |
| 3536 |
if (node) { |
| 3537 |
cleanupRef.current = callback(node); |
| 3538 |
} else if (cleanupRef.current) { |
| 3539 |
cleanupRef.current(); |
| 3540 |
} |
| 3541 |
}, dependencies); |
| 3542 |
} |
| 3543 |
|
| 3544 |
;// ./packages/compose/build-module/hooks/use-constrained-tabbing/index.js |
| 3545 |
/** |
| 3546 |
* WordPress dependencies |
| 3547 |
*/ |
| 3548 |
|
| 3549 |
|
| 3550 |
/** |
| 3551 |
* Internal dependencies |
| 3552 |
*/ |
| 3553 |
|
| 3554 |
|
| 3555 |
/** |
| 3556 |
* In Dialogs/modals, the tabbing must be constrained to the content of |
| 3557 |
* the wrapper element. This hook adds the behavior to the returned ref. |
| 3558 |
* |
| 3559 |
* @return {import('react').RefCallback<Element>} Element Ref. |
| 3560 |
* |
| 3561 |
* @example |
| 3562 |
* ```js |
| 3563 |
* import { useConstrainedTabbing } from '@wordpress/compose'; |
| 3564 |
* |
| 3565 |
* const ConstrainedTabbingExample = () => { |
| 3566 |
* const constrainedTabbingRef = useConstrainedTabbing() |
| 3567 |
* return ( |
| 3568 |
* <div ref={ constrainedTabbingRef }> |
| 3569 |
* <Button /> |
| 3570 |
* <Button /> |
| 3571 |
* </div> |
| 3572 |
* ); |
| 3573 |
* } |
| 3574 |
* ``` |
| 3575 |
*/ |
| 3576 |
function useConstrainedTabbing() { |
| 3577 |
return useRefEffect((/** @type {HTMLElement} */node) => { |
| 3578 |
function onKeyDown(/** @type {KeyboardEvent} */event) { |
| 3579 |
const { |
| 3580 |
key, |
| 3581 |
shiftKey, |
| 3582 |
target |
| 3583 |
} = event; |
| 3584 |
if (key !== 'Tab') { |
| 3585 |
return; |
| 3586 |
} |
| 3587 |
const action = shiftKey ? 'findPrevious' : 'findNext'; |
| 3588 |
const nextElement = external_wp_dom_namespaceObject.focus.tabbable[action](/** @type {HTMLElement} */target) || null; |
| 3589 |
|
| 3590 |
// When the target element contains the element that is about to |
| 3591 |
// receive focus, for example when the target is a tabbable |
| 3592 |
// container, browsers may disagree on where to move focus next. |
| 3593 |
// In this case we can't rely on native browsers behavior. We need |
| 3594 |
// to manage focus instead. |
| 3595 |
// See https://github.com/WordPress/gutenberg/issues/46041. |
| 3596 |
if (/** @type {HTMLElement} */target.contains(nextElement)) { |
| 3597 |
event.preventDefault(); |
| 3598 |
nextElement?.focus(); |
| 3599 |
return; |
| 3600 |
} |
| 3601 |
|
| 3602 |
// If the element that is about to receive focus is inside the |
| 3603 |
// area, rely on native browsers behavior and let tabbing follow |
| 3604 |
// the native tab sequence. |
| 3605 |
if (node.contains(nextElement)) { |
| 3606 |
return; |
| 3607 |
} |
| 3608 |
|
| 3609 |
// If the element that is about to receive focus is outside the |
| 3610 |
// area, move focus to a div and insert it at the start or end of |
| 3611 |
// the area, depending on the direction. Without preventing default |
| 3612 |
// behaviour, the browser will then move focus to the next element. |
| 3613 |
const domAction = shiftKey ? 'append' : 'prepend'; |
| 3614 |
const { |
| 3615 |
ownerDocument |
| 3616 |
} = node; |
| 3617 |
const trap = ownerDocument.createElement('div'); |
| 3618 |
trap.tabIndex = -1; |
| 3619 |
node[domAction](trap); |
| 3620 |
|
| 3621 |
// Remove itself when the trap loses focus. |
| 3622 |
trap.addEventListener('blur', () => node.removeChild(trap)); |
| 3623 |
trap.focus(); |
| 3624 |
} |
| 3625 |
node.addEventListener('keydown', onKeyDown); |
| 3626 |
return () => { |
| 3627 |
node.removeEventListener('keydown', onKeyDown); |
| 3628 |
}; |
| 3629 |
}, []); |
| 3630 |
} |
| 3631 |
/* harmony default export */ const use_constrained_tabbing = (useConstrainedTabbing); |
| 3632 |
|
| 3633 |
// EXTERNAL MODULE: ./packages/compose/node_modules/clipboard/dist/clipboard.js |
| 3634 |
var dist_clipboard = __webpack_require__(5359); |
| 3635 |
var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard); |
| 3636 |
;// ./packages/compose/build-module/hooks/use-copy-on-click/index.js |
| 3637 |
/** |
| 3638 |
* External dependencies |
| 3639 |
*/ |
| 3640 |
|
| 3641 |
|
| 3642 |
/** |
| 3643 |
* WordPress dependencies |
| 3644 |
*/ |
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
/* eslint-disable jsdoc/no-undefined-types */ |
| 3649 |
/** |
| 3650 |
* Copies the text to the clipboard when the element is clicked. |
| 3651 |
* |
| 3652 |
* @deprecated |
| 3653 |
* |
| 3654 |
* @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element. |
| 3655 |
* @param {string|Function} text The text to copy. |
| 3656 |
* @param {number} [timeout] Optional timeout to reset the returned |
| 3657 |
* state. 4 seconds by default. |
| 3658 |
* |
| 3659 |
* @return {boolean} Whether or not the text has been copied. Resets after the |
| 3660 |
* timeout. |
| 3661 |
*/ |
| 3662 |
function useCopyOnClick(ref, text, timeout = 4000) { |
| 3663 |
/* eslint-enable jsdoc/no-undefined-types */ |
| 3664 |
external_wp_deprecated_default()('wp.compose.useCopyOnClick', { |
| 3665 |
since: '5.8', |
| 3666 |
alternative: 'wp.compose.useCopyToClipboard' |
| 3667 |
}); |
| 3668 |
|
| 3669 |
/** @type {import('react').MutableRefObject<Clipboard | undefined>} */ |
| 3670 |
const clipboardRef = (0,external_wp_element_namespaceObject.useRef)(); |
| 3671 |
const [hasCopied, setHasCopied] = (0,external_wp_element_namespaceObject.useState)(false); |
| 3672 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 3673 |
/** @type {number | undefined} */ |
| 3674 |
let timeoutId; |
| 3675 |
if (!ref.current) { |
| 3676 |
return; |
| 3677 |
} |
| 3678 |
|
| 3679 |
// Clipboard listens to click events. |
| 3680 |
clipboardRef.current = new (clipboard_default())(ref.current, { |
| 3681 |
text: () => typeof text === 'function' ? text() : text |
| 3682 |
}); |
| 3683 |
clipboardRef.current.on('success', ({ |
| 3684 |
clearSelection, |
| 3685 |
trigger |
| 3686 |
}) => { |
| 3687 |
// Clearing selection will move focus back to the triggering button, |
| 3688 |
// ensuring that it is not reset to the body, and further that it is |
| 3689 |
// kept within the rendered node. |
| 3690 |
clearSelection(); |
| 3691 |
|
| 3692 |
// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680 |
| 3693 |
if (trigger) { |
| 3694 |
/** @type {HTMLElement} */trigger.focus(); |
| 3695 |
} |
| 3696 |
if (timeout) { |
| 3697 |
setHasCopied(true); |
| 3698 |
clearTimeout(timeoutId); |
| 3699 |
timeoutId = setTimeout(() => setHasCopied(false), timeout); |
| 3700 |
} |
| 3701 |
}); |
| 3702 |
return () => { |
| 3703 |
if (clipboardRef.current) { |
| 3704 |
clipboardRef.current.destroy(); |
| 3705 |
} |
| 3706 |
clearTimeout(timeoutId); |
| 3707 |
}; |
| 3708 |
}, [text, timeout, setHasCopied]); |
| 3709 |
return hasCopied; |
| 3710 |
} |
| 3711 |
|
| 3712 |
;// ./packages/compose/build-module/hooks/use-copy-to-clipboard/index.js |
| 3713 |
/** |
| 3714 |
* External dependencies |
| 3715 |
*/ |
| 3716 |
|
| 3717 |
|
| 3718 |
/** |
| 3719 |
* WordPress dependencies |
| 3720 |
*/ |
| 3721 |
|
| 3722 |
|
| 3723 |
/** |
| 3724 |
* Internal dependencies |
| 3725 |
*/ |
| 3726 |
|
| 3727 |
|
| 3728 |
/** |
| 3729 |
* @template T |
| 3730 |
* @param {T} value |
| 3731 |
* @return {import('react').RefObject<T>} The updated ref |
| 3732 |
*/ |
| 3733 |
function useUpdatedRef(value) { |
| 3734 |
const ref = (0,external_wp_element_namespaceObject.useRef)(value); |
| 3735 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
| 3736 |
ref.current = value; |
| 3737 |
}, [value]); |
| 3738 |
return ref; |
| 3739 |
} |
| 3740 |
|
| 3741 |
/** |
| 3742 |
* Copies the given text to the clipboard when the element is clicked. |
| 3743 |
* |
| 3744 |
* @template {HTMLElement} TElementType |
| 3745 |
* @param {string | (() => string)} text The text to copy. Use a function if not |
| 3746 |
* already available and expensive to compute. |
| 3747 |
* @param {Function} onSuccess Called when to text is copied. |
| 3748 |
* |
| 3749 |
* @return {import('react').Ref<TElementType>} A ref to assign to the target element. |
| 3750 |
*/ |
| 3751 |
function useCopyToClipboard(text, onSuccess) { |
| 3752 |
// Store the dependencies as refs and continuously update them so they're |
| 3753 |
// fresh when the callback is called. |
| 3754 |
const textRef = useUpdatedRef(text); |
| 3755 |
const onSuccessRef = useUpdatedRef(onSuccess); |
| 3756 |
return useRefEffect(node => { |
| 3757 |
// Clipboard listens to click events. |
| 3758 |
const clipboard = new (clipboard_default())(node, { |
| 3759 |
text() { |
| 3760 |
return typeof textRef.current === 'function' ? textRef.current() : textRef.current || ''; |
| 3761 |
} |
| 3762 |
}); |
| 3763 |
clipboard.on('success', ({ |
| 3764 |
clearSelection |
| 3765 |
}) => { |
| 3766 |
// Clearing selection will move focus back to the triggering |
| 3767 |
// button, ensuring that it is not reset to the body, and |
| 3768 |
// further that it is kept within the rendered node. |
| 3769 |
clearSelection(); |
| 3770 |
if (onSuccessRef.current) { |
| 3771 |
onSuccessRef.current(); |
| 3772 |
} |
| 3773 |
}); |
| 3774 |
return () => { |
| 3775 |
clipboard.destroy(); |
| 3776 |
}; |
| 3777 |
}, []); |
| 3778 |
} |
| 3779 |
|
| 3780 |
;// external ["wp","keycodes"] |
| 3781 |
const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; |
| 3782 |
;// ./packages/compose/build-module/hooks/use-focus-on-mount/index.js |
| 3783 |
/** |
| 3784 |
* WordPress dependencies |
| 3785 |
*/ |
| 3786 |
|
| 3787 |
|
| 3788 |
|
| 3789 |
/** |
| 3790 |
* Internal dependencies |
| 3791 |
*/ |
| 3792 |
|
| 3793 |
|
| 3794 |
/** |
| 3795 |
* Hook used to focus the first tabbable element on mount. |
| 3796 |
* |
| 3797 |
* @param {boolean | 'firstElement'} focusOnMount Focus on mount mode. |
| 3798 |
* @return {import('react').RefCallback<HTMLElement>} Ref callback. |
| 3799 |
* |
| 3800 |
* @example |
| 3801 |
* ```js |
| 3802 |
* import { useFocusOnMount } from '@wordpress/compose'; |
| 3803 |
* |
| 3804 |
* const WithFocusOnMount = () => { |
| 3805 |
* const ref = useFocusOnMount() |
| 3806 |
* return ( |
| 3807 |
* <div ref={ ref }> |
| 3808 |
* <Button /> |
| 3809 |
* <Button /> |
| 3810 |
* </div> |
| 3811 |
* ); |
| 3812 |
* } |
| 3813 |
* ``` |
| 3814 |
*/ |
| 3815 |
function useFocusOnMount(focusOnMount = 'firstElement') { |
| 3816 |
const focusOnMountRef = (0,external_wp_element_namespaceObject.useRef)(focusOnMount); |
| 3817 |
|
| 3818 |
/** |
| 3819 |
* Sets focus on a DOM element. |
| 3820 |
* |
| 3821 |
* @param {HTMLElement} target The DOM element to set focus to. |
| 3822 |
* @return {void} |
| 3823 |
*/ |
| 3824 |
const setFocus = target => { |
| 3825 |
target.focus({ |
| 3826 |
// When focusing newly mounted dialogs, |
| 3827 |
// the position of the popover is often not right on the first render |
| 3828 |
// This prevents the layout shifts when focusing the dialogs. |
| 3829 |
preventScroll: true |
| 3830 |
}); |
| 3831 |
}; |
| 3832 |
|
| 3833 |
/** @type {import('react').MutableRefObject<ReturnType<setTimeout> | undefined>} */ |
| 3834 |
const timerIdRef = (0,external_wp_element_namespaceObject.useRef)(); |
| 3835 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 3836 |
focusOnMountRef.current = focusOnMount; |
| 3837 |
}, [focusOnMount]); |
| 3838 |
return useRefEffect(node => { |
| 3839 |
var _node$ownerDocument$a; |
| 3840 |
if (!node || focusOnMountRef.current === false) { |
| 3841 |
return; |
| 3842 |
} |
| 3843 |
if (node.contains((_node$ownerDocument$a = node.ownerDocument?.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) { |
| 3844 |
return; |
| 3845 |
} |
| 3846 |
if (focusOnMountRef.current !== 'firstElement') { |
| 3847 |
setFocus(node); |
| 3848 |
return; |
| 3849 |
} |
| 3850 |
timerIdRef.current = setTimeout(() => { |
| 3851 |
const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0]; |
| 3852 |
if (firstTabbable) { |
| 3853 |
setFocus(firstTabbable); |
| 3854 |
} |
| 3855 |
}, 0); |
| 3856 |
return () => { |
| 3857 |
if (timerIdRef.current) { |
| 3858 |
clearTimeout(timerIdRef.current); |
| 3859 |
} |
| 3860 |
}; |
| 3861 |
}, []); |
| 3862 |
} |
| 3863 |
|
| 3864 |
;// ./packages/compose/build-module/hooks/use-focus-return/index.js |
| 3865 |
/** |
| 3866 |
* WordPress dependencies |
| 3867 |
*/ |
| 3868 |
|
| 3869 |
|
| 3870 |
/** @type {Element|null} */ |
| 3871 |
let origin = null; |
| 3872 |
|
| 3873 |
/** |
| 3874 |
* Adds the unmount behavior of returning focus to the element which had it |
| 3875 |
* previously as is expected for roles like menus or dialogs. |
| 3876 |
* |
| 3877 |
* @param {() => void} [onFocusReturn] Overrides the default return behavior. |
| 3878 |
* @return {import('react').RefCallback<HTMLElement>} Element Ref. |
| 3879 |
* |
| 3880 |
* @example |
| 3881 |
* ```js |
| 3882 |
* import { useFocusReturn } from '@wordpress/compose'; |
| 3883 |
* |
| 3884 |
* const WithFocusReturn = () => { |
| 3885 |
* const ref = useFocusReturn() |
| 3886 |
* return ( |
| 3887 |
* <div ref={ ref }> |
| 3888 |
* <Button /> |
| 3889 |
* <Button /> |
| 3890 |
* </div> |
| 3891 |
* ); |
| 3892 |
* } |
| 3893 |
* ``` |
| 3894 |
*/ |
| 3895 |
function useFocusReturn(onFocusReturn) { |
| 3896 |
/** @type {import('react').MutableRefObject<null | HTMLElement>} */ |
| 3897 |
const ref = (0,external_wp_element_namespaceObject.useRef)(null); |
| 3898 |
/** @type {import('react').MutableRefObject<null | Element>} */ |
| 3899 |
const focusedBeforeMount = (0,external_wp_element_namespaceObject.useRef)(null); |
| 3900 |
const onFocusReturnRef = (0,external_wp_element_namespaceObject.useRef)(onFocusReturn); |
| 3901 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 3902 |
onFocusReturnRef.current = onFocusReturn; |
| 3903 |
}, [onFocusReturn]); |
| 3904 |
return (0,external_wp_element_namespaceObject.useCallback)(node => { |
| 3905 |
if (node) { |
| 3906 |
// Set ref to be used when unmounting. |
| 3907 |
ref.current = node; |
| 3908 |
|
| 3909 |
// Only set when the node mounts. |
| 3910 |
if (focusedBeforeMount.current) { |
| 3911 |
return; |
| 3912 |
} |
| 3913 |
focusedBeforeMount.current = node.ownerDocument.activeElement; |
| 3914 |
} else if (focusedBeforeMount.current) { |
| 3915 |
const isFocused = ref.current?.contains(ref.current?.ownerDocument.activeElement); |
| 3916 |
if (ref.current?.isConnected && !isFocused) { |
| 3917 |
var _origin; |
| 3918 |
(_origin = origin) !== null && _origin !== void 0 ? _origin : origin = focusedBeforeMount.current; |
| 3919 |
return; |
| 3920 |
} |
| 3921 |
|
| 3922 |
// Defer to the component's own explicit focus return behavior, if |
| 3923 |
// specified. This allows for support that the `onFocusReturn` |
| 3924 |
// decides to allow the default behavior to occur under some |
| 3925 |
// conditions. |
| 3926 |
if (onFocusReturnRef.current) { |
| 3927 |
onFocusReturnRef.current(); |
| 3928 |
} else { |
| 3929 |
/** @type {null|HTMLElement} */(!focusedBeforeMount.current.isConnected ? origin : focusedBeforeMount.current)?.focus(); |
| 3930 |
} |
| 3931 |
origin = null; |
| 3932 |
} |
| 3933 |
}, []); |
| 3934 |
} |
| 3935 |
/* harmony default export */ const use_focus_return = (useFocusReturn); |
| 3936 |
|
| 3937 |
;// ./packages/compose/build-module/hooks/use-focus-outside/index.js |
| 3938 |
/** |
| 3939 |
* WordPress dependencies |
| 3940 |
*/ |
| 3941 |
|
| 3942 |
|
| 3943 |
/** |
| 3944 |
* Input types which are classified as button types, for use in considering |
| 3945 |
* whether element is a (focus-normalized) button. |
| 3946 |
*/ |
| 3947 |
const INPUT_BUTTON_TYPES = ['button', 'submit']; |
| 3948 |
|
| 3949 |
/** |
| 3950 |
* List of HTML button elements subject to focus normalization |
| 3951 |
* |
| 3952 |
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus |
| 3953 |
*/ |
| 3954 |
|
| 3955 |
/** |
| 3956 |
* Returns true if the given element is a button element subject to focus |
| 3957 |
* normalization, or false otherwise. |
| 3958 |
* |
| 3959 |
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus |
| 3960 |
* |
| 3961 |
* @param eventTarget The target from a mouse or touch event. |
| 3962 |
* |
| 3963 |
* @return Whether the element is a button element subject to focus normalization. |
| 3964 |
*/ |
| 3965 |
function isFocusNormalizedButton(eventTarget) { |
| 3966 |
if (!(eventTarget instanceof window.HTMLElement)) { |
| 3967 |
return false; |
| 3968 |
} |
| 3969 |
switch (eventTarget.nodeName) { |
| 3970 |
case 'A': |
| 3971 |
case 'BUTTON': |
| 3972 |
return true; |
| 3973 |
case 'INPUT': |
| 3974 |
return INPUT_BUTTON_TYPES.includes(eventTarget.type); |
| 3975 |
} |
| 3976 |
return false; |
| 3977 |
} |
| 3978 |
/** |
| 3979 |
* A react hook that can be used to check whether focus has moved outside the |
| 3980 |
* element the event handlers are bound to. |
| 3981 |
* |
| 3982 |
* @param onFocusOutside A callback triggered when focus moves outside |
| 3983 |
* the element the event handlers are bound to. |
| 3984 |
* |
| 3985 |
* @return An object containing event handlers. Bind the event handlers to a |
| 3986 |
* wrapping element element to capture when focus moves outside that element. |
| 3987 |
*/ |
| 3988 |
function useFocusOutside(onFocusOutside) { |
| 3989 |
const currentOnFocusOutsideRef = (0,external_wp_element_namespaceObject.useRef)(onFocusOutside); |
| 3990 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 3991 |
currentOnFocusOutsideRef.current = onFocusOutside; |
| 3992 |
}, [onFocusOutside]); |
| 3993 |
const preventBlurCheckRef = (0,external_wp_element_namespaceObject.useRef)(false); |
| 3994 |
const blurCheckTimeoutIdRef = (0,external_wp_element_namespaceObject.useRef)(); |
| 3995 |
|
| 3996 |
/** |
| 3997 |
* Cancel a blur check timeout. |
| 3998 |
*/ |
| 3999 |
const cancelBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(() => { |
| 4000 |
clearTimeout(blurCheckTimeoutIdRef.current); |
| 4001 |
}, []); |
| 4002 |
|
| 4003 |
// Cancel blur checks on unmount. |
| 4004 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 4005 |
return () => cancelBlurCheck(); |
| 4006 |
}, []); |
| 4007 |
|
| 4008 |
// Cancel a blur check if the callback or ref is no longer provided. |
| 4009 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 4010 |
if (!onFocusOutside) { |
| 4011 |
cancelBlurCheck(); |
| 4012 |
} |
| 4013 |
}, [onFocusOutside, cancelBlurCheck]); |
| 4014 |
|
| 4015 |
/** |
| 4016 |
* Handles a mousedown or mouseup event to respectively assign and |
| 4017 |
* unassign a flag for preventing blur check on button elements. Some |
| 4018 |
* browsers, namely Firefox and Safari, do not emit a focus event on |
| 4019 |
* button elements when clicked, while others do. The logic here |
| 4020 |
* intends to normalize this as treating click on buttons as focus. |
| 4021 |
* |
| 4022 |
* @param event |
| 4023 |
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus |
| 4024 |
*/ |
| 4025 |
const normalizeButtonFocus = (0,external_wp_element_namespaceObject.useCallback)(event => { |
| 4026 |
const { |
| 4027 |
type, |
| 4028 |
target |
| 4029 |
} = event; |
| 4030 |
const isInteractionEnd = ['mouseup', 'touchend'].includes(type); |
| 4031 |
if (isInteractionEnd) { |
| 4032 |
preventBlurCheckRef.current = false; |
| 4033 |
} else if (isFocusNormalizedButton(target)) { |
| 4034 |
preventBlurCheckRef.current = true; |
| 4035 |
} |
| 4036 |
}, []); |
| 4037 |
|
| 4038 |
/** |
| 4039 |
* A callback triggered when a blur event occurs on the element the handler |
| 4040 |
* is bound to. |
| 4041 |
* |
| 4042 |
* Calls the `onFocusOutside` callback in an immediate timeout if focus has |
| 4043 |
* move outside the bound element and is still within the document. |
| 4044 |
*/ |
| 4045 |
const queueBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(event => { |
| 4046 |
// React does not allow using an event reference asynchronously |
| 4047 |
// due to recycling behavior, except when explicitly persisted. |
| 4048 |
event.persist(); |
| 4049 |
|
| 4050 |
// Skip blur check if clicking button. See `normalizeButtonFocus`. |
| 4051 |
if (preventBlurCheckRef.current) { |
| 4052 |
return; |
| 4053 |
} |
| 4054 |
|
| 4055 |
// The usage of this attribute should be avoided. The only use case |
| 4056 |
// would be when we load modals that are not React components and |
| 4057 |
// therefore don't exist in the React tree. An example is opening |
| 4058 |
// the Media Library modal from another dialog. |
| 4059 |
// This attribute should contain a selector of the related target |
| 4060 |
// we want to ignore, because we still need to trigger the blur event |
| 4061 |
// on all other cases. |
| 4062 |
const ignoreForRelatedTarget = event.target.getAttribute('data-unstable-ignore-focus-outside-for-relatedtarget'); |
| 4063 |
if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) { |
| 4064 |
return; |
| 4065 |
} |
| 4066 |
blurCheckTimeoutIdRef.current = setTimeout(() => { |
| 4067 |
// If document is not focused then focus should remain |
| 4068 |
// inside the wrapped component and therefore we cancel |
| 4069 |
// this blur event thereby leaving focus in place. |
| 4070 |
// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus. |
| 4071 |
if (!document.hasFocus()) { |
| 4072 |
event.preventDefault(); |
| 4073 |
return; |
| 4074 |
} |
| 4075 |
if ('function' === typeof currentOnFocusOutsideRef.current) { |
| 4076 |
currentOnFocusOutsideRef.current(event); |
| 4077 |
} |
| 4078 |
}, 0); |
| 4079 |
}, []); |
| 4080 |
return { |
| 4081 |
onFocus: cancelBlurCheck, |
| 4082 |
onMouseDown: normalizeButtonFocus, |
| 4083 |
onMouseUp: normalizeButtonFocus, |
| 4084 |
onTouchStart: normalizeButtonFocus, |
| 4085 |
onTouchEnd: normalizeButtonFocus, |
| 4086 |
onBlur: queueBlurCheck |
| 4087 |
}; |
| 4088 |
} |
| 4089 |
|
| 4090 |
;// ./packages/compose/build-module/hooks/use-merge-refs/index.js |
| 4091 |
/** |
| 4092 |
* WordPress dependencies |
| 4093 |
*/ |
| 4094 |
|
| 4095 |
|
| 4096 |
/* eslint-disable jsdoc/valid-types */ |
| 4097 |
/** |
| 4098 |
* @template T |
| 4099 |
* @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef |
| 4100 |
*/ |
| 4101 |
/* eslint-enable jsdoc/valid-types */ |
| 4102 |
|
| 4103 |
/** |
| 4104 |
* @template T |
| 4105 |
* @param {import('react').Ref<T>} ref |
| 4106 |
* @param {T} value |
| 4107 |
*/ |
| 4108 |
function assignRef(ref, value) { |
| 4109 |
if (typeof ref === 'function') { |
| 4110 |
ref(value); |
| 4111 |
} else if (ref && ref.hasOwnProperty('current')) { |
| 4112 |
/* eslint-disable jsdoc/no-undefined-types */ |
| 4113 |
/** @type {import('react').MutableRefObject<T>} */ref.current = value; |
| 4114 |
/* eslint-enable jsdoc/no-undefined-types */ |
| 4115 |
} |
| 4116 |
} |
| 4117 |
|
| 4118 |
/** |
| 4119 |
* Merges refs into one ref callback. |
| 4120 |
* |
| 4121 |
* It also ensures that the merged ref callbacks are only called when they |
| 4122 |
* change (as a result of a `useCallback` dependency update) OR when the ref |
| 4123 |
* value changes, just as React does when passing a single ref callback to the |
| 4124 |
* component. |
| 4125 |
* |
| 4126 |
* As expected, if you pass a new function on every render, the ref callback |
| 4127 |
* will be called after every render. |
| 4128 |
* |
| 4129 |
* If you don't wish a ref callback to be called after every render, wrap it |
| 4130 |
* with `useCallback( callback, dependencies )`. When a dependency changes, the |
| 4131 |
* old ref callback will be called with `null` and the new ref callback will be |
| 4132 |
* called with the same value. |
| 4133 |
* |
| 4134 |
* To make ref callbacks easier to use, you can also pass the result of |
| 4135 |
* `useRefEffect`, which makes cleanup easier by allowing you to return a |
| 4136 |
* cleanup function instead of handling `null`. |
| 4137 |
* |
| 4138 |
* It's also possible to _disable_ a ref (and its behaviour) by simply not |
| 4139 |
* passing the ref. |
| 4140 |
* |
| 4141 |
* ```jsx |
| 4142 |
* const ref = useRefEffect( ( node ) => { |
| 4143 |
* node.addEventListener( ... ); |
| 4144 |
* return () => { |
| 4145 |
* node.removeEventListener( ... ); |
| 4146 |
* }; |
| 4147 |
* }, [ ...dependencies ] ); |
| 4148 |
* const otherRef = useRef(); |
| 4149 |
* const mergedRefs useMergeRefs( [ |
| 4150 |
* enabled && ref, |
| 4151 |
* otherRef, |
| 4152 |
* ] ); |
| 4153 |
* return <div ref={ mergedRefs } />; |
| 4154 |
* ``` |
| 4155 |
* |
| 4156 |
* @template {import('react').Ref<any>} TRef |
| 4157 |
* @param {Array<TRef>} refs The refs to be merged. |
| 4158 |
* |
| 4159 |
* @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback. |
| 4160 |
*/ |
| 4161 |
function useMergeRefs(refs) { |
| 4162 |
const element = (0,external_wp_element_namespaceObject.useRef)(); |
| 4163 |
const isAttachedRef = (0,external_wp_element_namespaceObject.useRef)(false); |
| 4164 |
const didElementChangeRef = (0,external_wp_element_namespaceObject.useRef)(false); |
| 4165 |
/* eslint-disable jsdoc/no-undefined-types */ |
| 4166 |
/** @type {import('react').MutableRefObject<TRef[]>} */ |
| 4167 |
/* eslint-enable jsdoc/no-undefined-types */ |
| 4168 |
const previousRefsRef = (0,external_wp_element_namespaceObject.useRef)([]); |
| 4169 |
const currentRefsRef = (0,external_wp_element_namespaceObject.useRef)(refs); |
| 4170 |
|
| 4171 |
// Update on render before the ref callback is called, so the ref callback |
| 4172 |
// always has access to the current refs. |
| 4173 |
currentRefsRef.current = refs; |
| 4174 |
|
| 4175 |
// If any of the refs change, call the previous ref with `null` and the new |
| 4176 |
// ref with the node, except when the element changes in the same cycle, in |
| 4177 |
// which case the ref callbacks will already have been called. |
| 4178 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
| 4179 |
if (didElementChangeRef.current === false && isAttachedRef.current === true) { |
| 4180 |
refs.forEach((ref, index) => { |
| 4181 |
const previousRef = previousRefsRef.current[index]; |
| 4182 |
if (ref !== previousRef) { |
| 4183 |
assignRef(previousRef, null); |
| 4184 |
assignRef(ref, element.current); |
| 4185 |
} |
| 4186 |
}); |
| 4187 |
} |
| 4188 |
previousRefsRef.current = refs; |
| 4189 |
}, refs); |
| 4190 |
|
| 4191 |
// No dependencies, must be reset after every render so ref callbacks are |
| 4192 |
// correctly called after a ref change. |
| 4193 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
| 4194 |
didElementChangeRef.current = false; |
| 4195 |
}); |
| 4196 |
|
| 4197 |
// There should be no dependencies so that `callback` is only called when |
| 4198 |
// the node changes. |
| 4199 |
return (0,external_wp_element_namespaceObject.useCallback)(value => { |
| 4200 |
// Update the element so it can be used when calling ref callbacks on a |
| 4201 |
// dependency change. |
| 4202 |
assignRef(element, value); |
| 4203 |
didElementChangeRef.current = true; |
| 4204 |
isAttachedRef.current = value !== null; |
| 4205 |
|
| 4206 |
// When an element changes, the current ref callback should be called |
| 4207 |
// with the new element and the previous one with `null`. |
| 4208 |
const refsToAssign = value ? currentRefsRef.current : previousRefsRef.current; |
| 4209 |
|
| 4210 |
// Update the latest refs. |
| 4211 |
for (const ref of refsToAssign) { |
| 4212 |
assignRef(ref, value); |
| 4213 |
} |
| 4214 |
}, []); |
| 4215 |
} |
| 4216 |
|
| 4217 |
;// ./packages/compose/build-module/hooks/use-dialog/index.js |
| 4218 |
/** |
| 4219 |
* External dependencies |
| 4220 |
*/ |
| 4221 |
|
| 4222 |
/** |
| 4223 |
* WordPress dependencies |
| 4224 |
*/ |
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
/** |
| 4229 |
* Internal dependencies |
| 4230 |
*/ |
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
/** |
| 4237 |
* Returns a ref and props to apply to a dialog wrapper to enable the following behaviors: |
| 4238 |
* - constrained tabbing. |
| 4239 |
* - focus on mount. |
| 4240 |
* - return focus on unmount. |
| 4241 |
* - focus outside. |
| 4242 |
* |
| 4243 |
* @param options Dialog Options. |
| 4244 |
*/ |
| 4245 |
function useDialog(options) { |
| 4246 |
const currentOptions = (0,external_wp_element_namespaceObject.useRef)(); |
| 4247 |
const { |
| 4248 |
constrainTabbing = options.focusOnMount !== false |
| 4249 |
} = options; |
| 4250 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 4251 |
currentOptions.current = options; |
| 4252 |
}, Object.values(options)); |
| 4253 |
const constrainedTabbingRef = use_constrained_tabbing(); |
| 4254 |
const focusOnMountRef = useFocusOnMount(options.focusOnMount); |
| 4255 |
const focusReturnRef = use_focus_return(); |
| 4256 |
const focusOutsideProps = useFocusOutside(event => { |
| 4257 |
// This unstable prop is here only to manage backward compatibility |
| 4258 |
// for the Popover component otherwise, the onClose should be enough. |
| 4259 |
if (currentOptions.current?.__unstableOnClose) { |
| 4260 |
currentOptions.current.__unstableOnClose('focus-outside', event); |
| 4261 |
} else if (currentOptions.current?.onClose) { |
| 4262 |
currentOptions.current.onClose(); |
| 4263 |
} |
| 4264 |
}); |
| 4265 |
const closeOnEscapeRef = (0,external_wp_element_namespaceObject.useCallback)(node => { |
| 4266 |
if (!node) { |
| 4267 |
return; |
| 4268 |
} |
| 4269 |
node.addEventListener('keydown', event => { |
| 4270 |
// Close on escape. |
| 4271 |
if (event.keyCode === external_wp_keycodes_namespaceObject.ESCAPE && !event.defaultPrevented && currentOptions.current?.onClose) { |
| 4272 |
event.preventDefault(); |
| 4273 |
currentOptions.current.onClose(); |
| 4274 |
} |
| 4275 |
}); |
| 4276 |
}, []); |
| 4277 |
return [useMergeRefs([constrainTabbing ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), { |
| 4278 |
...focusOutsideProps, |
| 4279 |
tabIndex: -1 |
| 4280 |
}]; |
| 4281 |
} |
| 4282 |
/* harmony default export */ const use_dialog = (useDialog); |
| 4283 |
|
| 4284 |
;// ./packages/compose/build-module/hooks/use-disabled/index.js |
| 4285 |
/** |
| 4286 |
* Internal dependencies |
| 4287 |
*/ |
| 4288 |
|
| 4289 |
|
| 4290 |
|
| 4291 |
/** |
| 4292 |
* In some circumstances, such as block previews, all focusable DOM elements |
| 4293 |
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the |
| 4294 |
* behavior to disable nested DOM elements to the returned ref. |
| 4295 |
* |
| 4296 |
* If you can, prefer the use of the inert HTML attribute. |
| 4297 |
* |
| 4298 |
* @param {Object} config Configuration object. |
| 4299 |
* @param {boolean=} config.isDisabled Whether the element should be disabled. |
| 4300 |
* @return {import('react').RefCallback<HTMLElement>} Element Ref. |
| 4301 |
* |
| 4302 |
* @example |
| 4303 |
* ```js |
| 4304 |
* import { useDisabled } from '@wordpress/compose'; |
| 4305 |
* |
| 4306 |
* const DisabledExample = () => { |
| 4307 |
* const disabledRef = useDisabled(); |
| 4308 |
* return ( |
| 4309 |
* <div ref={ disabledRef }> |
| 4310 |
* <a href="#">This link will have tabindex set to -1</a> |
| 4311 |
* <input placeholder="This input will have the disabled attribute added to it." type="text" /> |
| 4312 |
* </div> |
| 4313 |
* ); |
| 4314 |
* }; |
| 4315 |
* ``` |
| 4316 |
*/ |
| 4317 |
function useDisabled({ |
| 4318 |
isDisabled: isDisabledProp = false |
| 4319 |
} = {}) { |
| 4320 |
return useRefEffect(node => { |
| 4321 |
if (isDisabledProp) { |
| 4322 |
return; |
| 4323 |
} |
| 4324 |
const defaultView = node?.ownerDocument?.defaultView; |
| 4325 |
if (!defaultView) { |
| 4326 |
return; |
| 4327 |
} |
| 4328 |
|
| 4329 |
/** A variable keeping track of the previous updates in order to restore them. */ |
| 4330 |
const updates = []; |
| 4331 |
const disable = () => { |
| 4332 |
node.childNodes.forEach(child => { |
| 4333 |
if (!(child instanceof defaultView.HTMLElement)) { |
| 4334 |
return; |
| 4335 |
} |
| 4336 |
if (!child.getAttribute('inert')) { |
| 4337 |
child.setAttribute('inert', 'true'); |
| 4338 |
updates.push(() => { |
| 4339 |
child.removeAttribute('inert'); |
| 4340 |
}); |
| 4341 |
} |
| 4342 |
}); |
| 4343 |
}; |
| 4344 |
|
| 4345 |
// Debounce re-disable since disabling process itself will incur |
| 4346 |
// additional mutations which should be ignored. |
| 4347 |
const debouncedDisable = debounce(disable, 0, { |
| 4348 |
leading: true |
| 4349 |
}); |
| 4350 |
disable(); |
| 4351 |
|
| 4352 |
/** @type {MutationObserver | undefined} */ |
| 4353 |
const observer = new window.MutationObserver(debouncedDisable); |
| 4354 |
observer.observe(node, { |
| 4355 |
childList: true |
| 4356 |
}); |
| 4357 |
return () => { |
| 4358 |
if (observer) { |
| 4359 |
observer.disconnect(); |
| 4360 |
} |
| 4361 |
debouncedDisable.cancel(); |
| 4362 |
updates.forEach(update => update()); |
| 4363 |
}; |
| 4364 |
}, [isDisabledProp]); |
| 4365 |
} |
| 4366 |
|
| 4367 |
;// ./packages/compose/build-module/hooks/use-event/index.js |
| 4368 |
/** |
| 4369 |
* WordPress dependencies |
| 4370 |
*/ |
| 4371 |
|
| 4372 |
|
| 4373 |
/** |
| 4374 |
* Any function. |
| 4375 |
*/ |
| 4376 |
|
| 4377 |
/** |
| 4378 |
* Creates a stable callback function that has access to the latest state and |
| 4379 |
* can be used within event handlers and effect callbacks. Throws when used in |
| 4380 |
* the render phase. |
| 4381 |
* |
| 4382 |
* @param callback The callback function to wrap. |
| 4383 |
* |
| 4384 |
* @example |
| 4385 |
* |
| 4386 |
* ```tsx |
| 4387 |
* function Component( props ) { |
| 4388 |
* const onClick = useEvent( props.onClick ); |
| 4389 |
* useEffect( () => { |
| 4390 |
* onClick(); |
| 4391 |
* // Won't trigger the effect again when props.onClick is updated. |
| 4392 |
* }, [ onClick ] ); |
| 4393 |
* // Won't re-render Button when props.onClick is updated (if `Button` is |
| 4394 |
* // wrapped in `React.memo`). |
| 4395 |
* return <Button onClick={ onClick } />; |
| 4396 |
* } |
| 4397 |
* ``` |
| 4398 |
*/ |
| 4399 |
function useEvent( |
| 4400 |
/** |
| 4401 |
* The callback function to wrap. |
| 4402 |
*/ |
| 4403 |
callback) { |
| 4404 |
const ref = (0,external_wp_element_namespaceObject.useRef)(() => { |
| 4405 |
throw new Error('Callbacks created with `useEvent` cannot be called during rendering.'); |
| 4406 |
}); |
| 4407 |
(0,external_wp_element_namespaceObject.useInsertionEffect)(() => { |
| 4408 |
ref.current = callback; |
| 4409 |
}); |
| 4410 |
return (0,external_wp_element_namespaceObject.useCallback)((...args) => ref.current?.(...args), []); |
| 4411 |
} |
| 4412 |
|
| 4413 |
;// ./packages/compose/build-module/hooks/use-isomorphic-layout-effect/index.js |
| 4414 |
/** |
| 4415 |
* WordPress dependencies |
| 4416 |
*/ |
| 4417 |
|
| 4418 |
|
| 4419 |
/** |
| 4420 |
* Preferred over direct usage of `useLayoutEffect` when supporting |
| 4421 |
* server rendered components (SSR) because currently React |
| 4422 |
* throws a warning when using useLayoutEffect in that environment. |
| 4423 |
*/ |
| 4424 |
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_namespaceObject.useLayoutEffect : external_wp_element_namespaceObject.useEffect; |
| 4425 |
/* harmony default export */ const use_isomorphic_layout_effect = (useIsomorphicLayoutEffect); |
| 4426 |
|
| 4427 |
;// ./packages/compose/build-module/hooks/use-dragging/index.js |
| 4428 |
/** |
| 4429 |
* WordPress dependencies |
| 4430 |
*/ |
| 4431 |
|
| 4432 |
|
| 4433 |
/** |
| 4434 |
* Internal dependencies |
| 4435 |
*/ |
| 4436 |
|
| 4437 |
|
| 4438 |
// Event handlers that are triggered from `document` listeners accept a MouseEvent, |
| 4439 |
// while those triggered from React listeners accept a React.MouseEvent. |
| 4440 |
/** |
| 4441 |
* @param {Object} props |
| 4442 |
* @param {(e: import('react').MouseEvent) => void} props.onDragStart |
| 4443 |
* @param {(e: MouseEvent) => void} props.onDragMove |
| 4444 |
* @param {(e?: MouseEvent) => void} props.onDragEnd |
| 4445 |
*/ |
| 4446 |
function useDragging({ |
| 4447 |
onDragStart, |
| 4448 |
onDragMove, |
| 4449 |
onDragEnd |
| 4450 |
}) { |
| 4451 |
const [isDragging, setIsDragging] = (0,external_wp_element_namespaceObject.useState)(false); |
| 4452 |
const eventsRef = (0,external_wp_element_namespaceObject.useRef)({ |
| 4453 |
onDragStart, |
| 4454 |
onDragMove, |
| 4455 |
onDragEnd |
| 4456 |
}); |
| 4457 |
use_isomorphic_layout_effect(() => { |
| 4458 |
eventsRef.current.onDragStart = onDragStart; |
| 4459 |
eventsRef.current.onDragMove = onDragMove; |
| 4460 |
eventsRef.current.onDragEnd = onDragEnd; |
| 4461 |
}, [onDragStart, onDragMove, onDragEnd]); |
| 4462 |
|
| 4463 |
/** @type {(e: MouseEvent) => void} */ |
| 4464 |
const onMouseMove = (0,external_wp_element_namespaceObject.useCallback)(event => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), []); |
| 4465 |
/** @type {(e?: MouseEvent) => void} */ |
| 4466 |
const endDrag = (0,external_wp_element_namespaceObject.useCallback)(event => { |
| 4467 |
if (eventsRef.current.onDragEnd) { |
| 4468 |
eventsRef.current.onDragEnd(event); |
| 4469 |
} |
| 4470 |
document.removeEventListener('mousemove', onMouseMove); |
| 4471 |
document.removeEventListener('mouseup', endDrag); |
| 4472 |
setIsDragging(false); |
| 4473 |
}, []); |
| 4474 |
/** @type {(e: import('react').MouseEvent) => void} */ |
| 4475 |
const startDrag = (0,external_wp_element_namespaceObject.useCallback)(event => { |
| 4476 |
if (eventsRef.current.onDragStart) { |
| 4477 |
eventsRef.current.onDragStart(event); |
| 4478 |
} |
| 4479 |
document.addEventListener('mousemove', onMouseMove); |
| 4480 |
document.addEventListener('mouseup', endDrag); |
| 4481 |
setIsDragging(true); |
| 4482 |
}, []); |
| 4483 |
|
| 4484 |
// Remove the global events when unmounting if needed. |
| 4485 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 4486 |
return () => { |
| 4487 |
if (isDragging) { |
| 4488 |
document.removeEventListener('mousemove', onMouseMove); |
| 4489 |
document.removeEventListener('mouseup', endDrag); |
| 4490 |
} |
| 4491 |
}; |
| 4492 |
}, [isDragging]); |
| 4493 |
return { |
| 4494 |
startDrag, |
| 4495 |
endDrag, |
| 4496 |
isDragging |
| 4497 |
}; |
| 4498 |
} |
| 4499 |
|
| 4500 |
// EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js |
| 4501 |
var mousetrap_mousetrap = __webpack_require__(1933); |
| 4502 |
var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap); |
| 4503 |
// EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js |
| 4504 |
var mousetrap_global_bind = __webpack_require__(5760); |
| 4505 |
;// ./packages/compose/build-module/hooks/use-keyboard-shortcut/index.js |
| 4506 |
/* wp:polyfill */ |
| 4507 |
/** |
| 4508 |
* External dependencies |
| 4509 |
*/ |
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
/** |
| 4514 |
* WordPress dependencies |
| 4515 |
*/ |
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
/** |
| 4520 |
* A block selection object. |
| 4521 |
* |
| 4522 |
* @typedef {Object} WPKeyboardShortcutConfig |
| 4523 |
* |
| 4524 |
* @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields. |
| 4525 |
* @property {string} [eventName] Event name used to trigger the handler, defaults to keydown. |
| 4526 |
* @property {boolean} [isDisabled] Disables the keyboard handler if the value is true. |
| 4527 |
* @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event. |
| 4528 |
*/ |
| 4529 |
|
| 4530 |
/* eslint-disable jsdoc/valid-types */ |
| 4531 |
/** |
| 4532 |
* Attach a keyboard shortcut handler. |
| 4533 |
* |
| 4534 |
* @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter. |
| 4535 |
* |
| 4536 |
* @param {string[]|string} shortcuts Keyboard Shortcuts. |
| 4537 |
* @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback. |
| 4538 |
* @param {WPKeyboardShortcutConfig} options Shortcut options. |
| 4539 |
*/ |
| 4540 |
function useKeyboardShortcut(/* eslint-enable jsdoc/valid-types */ |
| 4541 |
shortcuts, callback, { |
| 4542 |
bindGlobal = false, |
| 4543 |
eventName = 'keydown', |
| 4544 |
isDisabled = false, |
| 4545 |
// This is important for performance considerations. |
| 4546 |
target |
| 4547 |
} = {}) { |
| 4548 |
const currentCallbackRef = (0,external_wp_element_namespaceObject.useRef)(callback); |
| 4549 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 4550 |
currentCallbackRef.current = callback; |
| 4551 |
}, [callback]); |
| 4552 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 4553 |
if (isDisabled) { |
| 4554 |
return; |
| 4555 |
} |
| 4556 |
const mousetrap = new (mousetrap_default())(target && target.current ? target.current : |
| 4557 |
// We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`. |
| 4558 |
// 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 |
| 4559 |
// necessary to maintain the existing behavior. |
| 4560 |
/** @type {Element} */ /** @type {unknown} */ |
| 4561 |
document); |
| 4562 |
const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts]; |
| 4563 |
shortcutsArray.forEach(shortcut => { |
| 4564 |
const keys = shortcut.split('+'); |
| 4565 |
// Determines whether a key is a modifier by the length of the string. |
| 4566 |
// E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that |
| 4567 |
// the modifiers are Shift and Cmd because they're not a single character. |
| 4568 |
const modifiers = new Set(keys.filter(value => value.length > 1)); |
| 4569 |
const hasAlt = modifiers.has('alt'); |
| 4570 |
const hasShift = modifiers.has('shift'); |
| 4571 |
|
| 4572 |
// This should be better moved to the shortcut registration instead. |
| 4573 |
if ((0,external_wp_keycodes_namespaceObject.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) { |
| 4574 |
throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`); |
| 4575 |
} |
| 4576 |
const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; |
| 4577 |
// @ts-ignore `bindGlobal` is an undocumented property |
| 4578 |
mousetrap[bindFn](shortcut, (/* eslint-disable jsdoc/valid-types */ |
| 4579 |
/** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */...args) => /* eslint-enable jsdoc/valid-types */ |
| 4580 |
currentCallbackRef.current(...args), eventName); |
| 4581 |
}); |
| 4582 |
return () => { |
| 4583 |
mousetrap.reset(); |
| 4584 |
}; |
| 4585 |
}, [shortcuts, bindGlobal, eventName, target, isDisabled]); |
| 4586 |
} |
| 4587 |
/* harmony default export */ const use_keyboard_shortcut = (useKeyboardShortcut); |
| 4588 |
|
| 4589 |
;// ./packages/compose/build-module/hooks/use-media-query/index.js |
| 4590 |
/** |
| 4591 |
* WordPress dependencies |
| 4592 |
*/ |
| 4593 |
|
| 4594 |
const matchMediaCache = new Map(); |
| 4595 |
|
| 4596 |
/** |
| 4597 |
* A new MediaQueryList object for the media query |
| 4598 |
* |
| 4599 |
* @param {string} [query] Media Query. |
| 4600 |
* @return {MediaQueryList|null} A new object for the media query |
| 4601 |
*/ |
| 4602 |
function getMediaQueryList(query) { |
| 4603 |
if (!query) { |
| 4604 |
return null; |
| 4605 |
} |
| 4606 |
let match = matchMediaCache.get(query); |
| 4607 |
if (match) { |
| 4608 |
return match; |
| 4609 |
} |
| 4610 |
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') { |
| 4611 |
match = window.matchMedia(query); |
| 4612 |
matchMediaCache.set(query, match); |
| 4613 |
return match; |
| 4614 |
} |
| 4615 |
return null; |
| 4616 |
} |
| 4617 |
|
| 4618 |
/** |
| 4619 |
* Runs a media query and returns its value when it changes. |
| 4620 |
* |
| 4621 |
* @param {string} [query] Media Query. |
| 4622 |
* @return {boolean} return value of the media query. |
| 4623 |
*/ |
| 4624 |
function useMediaQuery(query) { |
| 4625 |
const source = (0,external_wp_element_namespaceObject.useMemo)(() => { |
| 4626 |
const mediaQueryList = getMediaQueryList(query); |
| 4627 |
return { |
| 4628 |
/** @type {(onStoreChange: () => void) => () => void} */ |
| 4629 |
subscribe(onStoreChange) { |
| 4630 |
if (!mediaQueryList) { |
| 4631 |
return () => {}; |
| 4632 |
} |
| 4633 |
|
| 4634 |
// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList. |
| 4635 |
mediaQueryList.addEventListener?.('change', onStoreChange); |
| 4636 |
return () => { |
| 4637 |
mediaQueryList.removeEventListener?.('change', onStoreChange); |
| 4638 |
}; |
| 4639 |
}, |
| 4640 |
getValue() { |
| 4641 |
var _mediaQueryList$match; |
| 4642 |
return (_mediaQueryList$match = mediaQueryList?.matches) !== null && _mediaQueryList$match !== void 0 ? _mediaQueryList$match : false; |
| 4643 |
} |
| 4644 |
}; |
| 4645 |
}, [query]); |
| 4646 |
return (0,external_wp_element_namespaceObject.useSyncExternalStore)(source.subscribe, source.getValue, () => false); |
| 4647 |
} |
| 4648 |
|
| 4649 |
;// ./packages/compose/build-module/hooks/use-previous/index.js |
| 4650 |
/** |
| 4651 |
* WordPress dependencies |
| 4652 |
*/ |
| 4653 |
|
| 4654 |
|
| 4655 |
/** |
| 4656 |
* Use something's value from the previous render. |
| 4657 |
* Based on https://usehooks.com/usePrevious/. |
| 4658 |
* |
| 4659 |
* @param value The value to track. |
| 4660 |
* |
| 4661 |
* @return The value from the previous render. |
| 4662 |
*/ |
| 4663 |
function usePrevious(value) { |
| 4664 |
const ref = (0,external_wp_element_namespaceObject.useRef)(); |
| 4665 |
|
| 4666 |
// Store current value in ref. |
| 4667 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 4668 |
ref.current = value; |
| 4669 |
}, [value]); // Re-run when value changes. |
| 4670 |
|
| 4671 |
// Return previous value (happens before update in useEffect above). |
| 4672 |
return ref.current; |
| 4673 |
} |
| 4674 |
|
| 4675 |
;// ./packages/compose/build-module/hooks/use-reduced-motion/index.js |
| 4676 |
/** |
| 4677 |
* Internal dependencies |
| 4678 |
*/ |
| 4679 |
|
| 4680 |
|
| 4681 |
/** |
| 4682 |
* Hook returning whether the user has a preference for reduced motion. |
| 4683 |
* |
| 4684 |
* @return {boolean} Reduced motion preference value. |
| 4685 |
*/ |
| 4686 |
const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)'); |
| 4687 |
/* harmony default export */ const use_reduced_motion = (useReducedMotion); |
| 4688 |
|
| 4689 |
;// ./packages/undo-manager/build-module/index.js |
| 4690 |
/** |
| 4691 |
* WordPress dependencies |
| 4692 |
*/ |
| 4693 |
|
| 4694 |
|
| 4695 |
/** @typedef {import('./types').HistoryRecord} HistoryRecord */ |
| 4696 |
/** @typedef {import('./types').HistoryChange} HistoryChange */ |
| 4697 |
/** @typedef {import('./types').HistoryChanges} HistoryChanges */ |
| 4698 |
/** @typedef {import('./types').UndoManager} UndoManager */ |
| 4699 |
|
| 4700 |
/** |
| 4701 |
* Merge changes for a single item into a record of changes. |
| 4702 |
* |
| 4703 |
* @param {Record< string, HistoryChange >} changes1 Previous changes |
| 4704 |
* @param {Record< string, HistoryChange >} changes2 NextChanges |
| 4705 |
* |
| 4706 |
* @return {Record< string, HistoryChange >} Merged changes |
| 4707 |
*/ |
| 4708 |
function mergeHistoryChanges(changes1, changes2) { |
| 4709 |
/** |
| 4710 |
* @type {Record< string, HistoryChange >} |
| 4711 |
*/ |
| 4712 |
const newChanges = { |
| 4713 |
...changes1 |
| 4714 |
}; |
| 4715 |
Object.entries(changes2).forEach(([key, value]) => { |
| 4716 |
if (newChanges[key]) { |
| 4717 |
newChanges[key] = { |
| 4718 |
...newChanges[key], |
| 4719 |
to: value.to |
| 4720 |
}; |
| 4721 |
} else { |
| 4722 |
newChanges[key] = value; |
| 4723 |
} |
| 4724 |
}); |
| 4725 |
return newChanges; |
| 4726 |
} |
| 4727 |
|
| 4728 |
/** |
| 4729 |
* Adds history changes for a single item into a record of changes. |
| 4730 |
* |
| 4731 |
* @param {HistoryRecord} record The record to merge into. |
| 4732 |
* @param {HistoryChanges} changes The changes to merge. |
| 4733 |
*/ |
| 4734 |
const addHistoryChangesIntoRecord = (record, changes) => { |
| 4735 |
const existingChangesIndex = record?.findIndex(({ |
| 4736 |
id: recordIdentifier |
| 4737 |
}) => { |
| 4738 |
return typeof recordIdentifier === 'string' ? recordIdentifier === changes.id : external_wp_isShallowEqual_default()(recordIdentifier, changes.id); |
| 4739 |
}); |
| 4740 |
const nextRecord = [...record]; |
| 4741 |
if (existingChangesIndex !== -1) { |
| 4742 |
// If the edit is already in the stack leave the initial "from" value. |
| 4743 |
nextRecord[existingChangesIndex] = { |
| 4744 |
id: changes.id, |
| 4745 |
changes: mergeHistoryChanges(nextRecord[existingChangesIndex].changes, changes.changes) |
| 4746 |
}; |
| 4747 |
} else { |
| 4748 |
nextRecord.push(changes); |
| 4749 |
} |
| 4750 |
return nextRecord; |
| 4751 |
}; |
| 4752 |
|
| 4753 |
/** |
| 4754 |
* Creates an undo manager. |
| 4755 |
* |
| 4756 |
* @return {UndoManager} Undo manager. |
| 4757 |
*/ |
| 4758 |
function createUndoManager() { |
| 4759 |
/** |
| 4760 |
* @type {HistoryRecord[]} |
| 4761 |
*/ |
| 4762 |
let history = []; |
| 4763 |
/** |
| 4764 |
* @type {HistoryRecord} |
| 4765 |
*/ |
| 4766 |
let stagedRecord = []; |
| 4767 |
/** |
| 4768 |
* @type {number} |
| 4769 |
*/ |
| 4770 |
let offset = 0; |
| 4771 |
const dropPendingRedos = () => { |
| 4772 |
history = history.slice(0, offset || undefined); |
| 4773 |
offset = 0; |
| 4774 |
}; |
| 4775 |
const appendStagedRecordToLatestHistoryRecord = () => { |
| 4776 |
var _history$index; |
| 4777 |
const index = history.length === 0 ? 0 : history.length - 1; |
| 4778 |
let latestRecord = (_history$index = history[index]) !== null && _history$index !== void 0 ? _history$index : []; |
| 4779 |
stagedRecord.forEach(changes => { |
| 4780 |
latestRecord = addHistoryChangesIntoRecord(latestRecord, changes); |
| 4781 |
}); |
| 4782 |
stagedRecord = []; |
| 4783 |
history[index] = latestRecord; |
| 4784 |
}; |
| 4785 |
|
| 4786 |
/** |
| 4787 |
* Checks whether a record is empty. |
| 4788 |
* A record is considered empty if it the changes keep the same values. |
| 4789 |
* Also updates to function values are ignored. |
| 4790 |
* |
| 4791 |
* @param {HistoryRecord} record |
| 4792 |
* @return {boolean} Whether the record is empty. |
| 4793 |
*/ |
| 4794 |
const isRecordEmpty = record => { |
| 4795 |
const filteredRecord = record.filter(({ |
| 4796 |
changes |
| 4797 |
}) => { |
| 4798 |
return Object.values(changes).some(({ |
| 4799 |
from, |
| 4800 |
to |
| 4801 |
}) => typeof from !== 'function' && typeof to !== 'function' && !external_wp_isShallowEqual_default()(from, to)); |
| 4802 |
}); |
| 4803 |
return !filteredRecord.length; |
| 4804 |
}; |
| 4805 |
return { |
| 4806 |
/** |
| 4807 |
* Record changes into the history. |
| 4808 |
* |
| 4809 |
* @param {HistoryRecord=} record A record of changes to record. |
| 4810 |
* @param {boolean} isStaged Whether to immediately create an undo point or not. |
| 4811 |
*/ |
| 4812 |
addRecord(record, isStaged = false) { |
| 4813 |
const isEmpty = !record || isRecordEmpty(record); |
| 4814 |
if (isStaged) { |
| 4815 |
if (isEmpty) { |
| 4816 |
return; |
| 4817 |
} |
| 4818 |
record.forEach(changes => { |
| 4819 |
stagedRecord = addHistoryChangesIntoRecord(stagedRecord, changes); |
| 4820 |
}); |
| 4821 |
} else { |
| 4822 |
dropPendingRedos(); |
| 4823 |
if (stagedRecord.length) { |
| 4824 |
appendStagedRecordToLatestHistoryRecord(); |
| 4825 |
} |
| 4826 |
if (isEmpty) { |
| 4827 |
return; |
| 4828 |
} |
| 4829 |
history.push(record); |
| 4830 |
} |
| 4831 |
}, |
| 4832 |
undo() { |
| 4833 |
if (stagedRecord.length) { |
| 4834 |
dropPendingRedos(); |
| 4835 |
appendStagedRecordToLatestHistoryRecord(); |
| 4836 |
} |
| 4837 |
const undoRecord = history[history.length - 1 + offset]; |
| 4838 |
if (!undoRecord) { |
| 4839 |
return; |
| 4840 |
} |
| 4841 |
offset -= 1; |
| 4842 |
return undoRecord; |
| 4843 |
}, |
| 4844 |
redo() { |
| 4845 |
const redoRecord = history[history.length + offset]; |
| 4846 |
if (!redoRecord) { |
| 4847 |
return; |
| 4848 |
} |
| 4849 |
offset += 1; |
| 4850 |
return redoRecord; |
| 4851 |
}, |
| 4852 |
hasUndo() { |
| 4853 |
return !!history[history.length - 1 + offset]; |
| 4854 |
}, |
| 4855 |
hasRedo() { |
| 4856 |
return !!history[history.length + offset]; |
| 4857 |
} |
| 4858 |
}; |
| 4859 |
} |
| 4860 |
|
| 4861 |
;// ./packages/compose/build-module/hooks/use-state-with-history/index.js |
| 4862 |
/** |
| 4863 |
* WordPress dependencies |
| 4864 |
*/ |
| 4865 |
|
| 4866 |
|
| 4867 |
function undoRedoReducer(state, action) { |
| 4868 |
switch (action.type) { |
| 4869 |
case 'UNDO': |
| 4870 |
{ |
| 4871 |
const undoRecord = state.manager.undo(); |
| 4872 |
if (undoRecord) { |
| 4873 |
return { |
| 4874 |
...state, |
| 4875 |
value: undoRecord[0].changes.prop.from |
| 4876 |
}; |
| 4877 |
} |
| 4878 |
return state; |
| 4879 |
} |
| 4880 |
case 'REDO': |
| 4881 |
{ |
| 4882 |
const redoRecord = state.manager.redo(); |
| 4883 |
if (redoRecord) { |
| 4884 |
return { |
| 4885 |
...state, |
| 4886 |
value: redoRecord[0].changes.prop.to |
| 4887 |
}; |
| 4888 |
} |
| 4889 |
return state; |
| 4890 |
} |
| 4891 |
case 'RECORD': |
| 4892 |
{ |
| 4893 |
state.manager.addRecord([{ |
| 4894 |
id: 'object', |
| 4895 |
changes: { |
| 4896 |
prop: { |
| 4897 |
from: state.value, |
| 4898 |
to: action.value |
| 4899 |
} |
| 4900 |
} |
| 4901 |
}], action.isStaged); |
| 4902 |
return { |
| 4903 |
...state, |
| 4904 |
value: action.value |
| 4905 |
}; |
| 4906 |
} |
| 4907 |
} |
| 4908 |
return state; |
| 4909 |
} |
| 4910 |
function initReducer(value) { |
| 4911 |
return { |
| 4912 |
manager: createUndoManager(), |
| 4913 |
value |
| 4914 |
}; |
| 4915 |
} |
| 4916 |
|
| 4917 |
/** |
| 4918 |
* useState with undo/redo history. |
| 4919 |
* |
| 4920 |
* @param initialValue Initial value. |
| 4921 |
* @return Value, setValue, hasUndo, hasRedo, undo, redo. |
| 4922 |
*/ |
| 4923 |
function useStateWithHistory(initialValue) { |
| 4924 |
const [state, dispatch] = (0,external_wp_element_namespaceObject.useReducer)(undoRedoReducer, initialValue, initReducer); |
| 4925 |
return { |
| 4926 |
value: state.value, |
| 4927 |
setValue: (0,external_wp_element_namespaceObject.useCallback)((newValue, isStaged) => { |
| 4928 |
dispatch({ |
| 4929 |
type: 'RECORD', |
| 4930 |
value: newValue, |
| 4931 |
isStaged |
| 4932 |
}); |
| 4933 |
}, []), |
| 4934 |
hasUndo: state.manager.hasUndo(), |
| 4935 |
hasRedo: state.manager.hasRedo(), |
| 4936 |
undo: (0,external_wp_element_namespaceObject.useCallback)(() => { |
| 4937 |
dispatch({ |
| 4938 |
type: 'UNDO' |
| 4939 |
}); |
| 4940 |
}, []), |
| 4941 |
redo: (0,external_wp_element_namespaceObject.useCallback)(() => { |
| 4942 |
dispatch({ |
| 4943 |
type: 'REDO' |
| 4944 |
}); |
| 4945 |
}, []) |
| 4946 |
}; |
| 4947 |
} |
| 4948 |
|
| 4949 |
;// ./packages/compose/build-module/hooks/use-viewport-match/index.js |
| 4950 |
/** |
| 4951 |
* WordPress dependencies |
| 4952 |
*/ |
| 4953 |
|
| 4954 |
|
| 4955 |
/** |
| 4956 |
* Internal dependencies |
| 4957 |
*/ |
| 4958 |
|
| 4959 |
|
| 4960 |
/** |
| 4961 |
* @typedef {"xhuge" | "huge" | "wide" | "xlarge" | "large" | "medium" | "small" | "mobile"} WPBreakpoint |
| 4962 |
*/ |
| 4963 |
|
| 4964 |
/** |
| 4965 |
* Hash of breakpoint names with pixel width at which it becomes effective. |
| 4966 |
* |
| 4967 |
* @see _breakpoints.scss |
| 4968 |
* |
| 4969 |
* @type {Record<WPBreakpoint, number>} |
| 4970 |
*/ |
| 4971 |
const BREAKPOINTS = { |
| 4972 |
xhuge: 1920, |
| 4973 |
huge: 1440, |
| 4974 |
wide: 1280, |
| 4975 |
xlarge: 1080, |
| 4976 |
large: 960, |
| 4977 |
medium: 782, |
| 4978 |
small: 600, |
| 4979 |
mobile: 480 |
| 4980 |
}; |
| 4981 |
|
| 4982 |
/** |
| 4983 |
* @typedef {">=" | "<"} WPViewportOperator |
| 4984 |
*/ |
| 4985 |
|
| 4986 |
/** |
| 4987 |
* Object mapping media query operators to the condition to be used. |
| 4988 |
* |
| 4989 |
* @type {Record<WPViewportOperator, string>} |
| 4990 |
*/ |
| 4991 |
const CONDITIONS = { |
| 4992 |
'>=': 'min-width', |
| 4993 |
'<': 'max-width' |
| 4994 |
}; |
| 4995 |
|
| 4996 |
/** |
| 4997 |
* Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values. |
| 4998 |
* |
| 4999 |
* @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>} |
| 5000 |
*/ |
| 5001 |
const OPERATOR_EVALUATORS = { |
| 5002 |
'>=': (breakpointValue, width) => width >= breakpointValue, |
| 5003 |
'<': (breakpointValue, width) => width < breakpointValue |
| 5004 |
}; |
| 5005 |
const ViewportMatchWidthContext = (0,external_wp_element_namespaceObject.createContext)(/** @type {null | number} */null); |
| 5006 |
|
| 5007 |
/** |
| 5008 |
* Returns true if the viewport matches the given query, or false otherwise. |
| 5009 |
* |
| 5010 |
* @param {WPBreakpoint} breakpoint Breakpoint size name. |
| 5011 |
* @param {WPViewportOperator} [operator=">="] Viewport operator. |
| 5012 |
* |
| 5013 |
* @example |
| 5014 |
* |
| 5015 |
* ```js |
| 5016 |
* useViewportMatch( 'huge', '<' ); |
| 5017 |
* useViewportMatch( 'medium' ); |
| 5018 |
* ``` |
| 5019 |
* |
| 5020 |
* @return {boolean} Whether viewport matches query. |
| 5021 |
*/ |
| 5022 |
const useViewportMatch = (breakpoint, operator = '>=') => { |
| 5023 |
const simulatedWidth = (0,external_wp_element_namespaceObject.useContext)(ViewportMatchWidthContext); |
| 5024 |
const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`; |
| 5025 |
const mediaQueryResult = useMediaQuery(mediaQuery || undefined); |
| 5026 |
if (simulatedWidth) { |
| 5027 |
return OPERATOR_EVALUATORS[operator](BREAKPOINTS[breakpoint], simulatedWidth); |
| 5028 |
} |
| 5029 |
return mediaQueryResult; |
| 5030 |
}; |
| 5031 |
useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider; |
| 5032 |
/* harmony default export */ const use_viewport_match = (useViewportMatch); |
| 5033 |
|
| 5034 |
;// ./packages/compose/build-module/hooks/use-resize-observer/use-resize-observer.js |
| 5035 |
/** |
| 5036 |
* WordPress dependencies |
| 5037 |
*/ |
| 5038 |
|
| 5039 |
/** |
| 5040 |
* Internal dependencies |
| 5041 |
*/ |
| 5042 |
|
| 5043 |
|
| 5044 |
// This is the current implementation of `useResizeObserver`. |
| 5045 |
// |
| 5046 |
// The legacy implementation is still supported for backwards compatibility. |
| 5047 |
// This is achieved by overloading the exported function with both signatures, |
| 5048 |
// and detecting which API is being used at runtime. |
| 5049 |
function useResizeObserver(callback, resizeObserverOptions = {}) { |
| 5050 |
const callbackEvent = useEvent(callback); |
| 5051 |
const observedElementRef = (0,external_wp_element_namespaceObject.useRef)(); |
| 5052 |
const resizeObserverRef = (0,external_wp_element_namespaceObject.useRef)(); |
| 5053 |
return useEvent(element => { |
| 5054 |
var _resizeObserverRef$cu; |
| 5055 |
if (element === observedElementRef.current) { |
| 5056 |
return; |
| 5057 |
} |
| 5058 |
|
| 5059 |
// Set up `ResizeObserver`. |
| 5060 |
(_resizeObserverRef$cu = resizeObserverRef.current) !== null && _resizeObserverRef$cu !== void 0 ? _resizeObserverRef$cu : resizeObserverRef.current = new ResizeObserver(callbackEvent); |
| 5061 |
const { |
| 5062 |
current: resizeObserver |
| 5063 |
} = resizeObserverRef; |
| 5064 |
|
| 5065 |
// Unobserve previous element. |
| 5066 |
if (observedElementRef.current) { |
| 5067 |
resizeObserver.unobserve(observedElementRef.current); |
| 5068 |
} |
| 5069 |
|
| 5070 |
// Observe new element. |
| 5071 |
observedElementRef.current = element; |
| 5072 |
if (element) { |
| 5073 |
resizeObserver.observe(element, resizeObserverOptions); |
| 5074 |
} |
| 5075 |
}); |
| 5076 |
} |
| 5077 |
|
| 5078 |
;// ./packages/compose/build-module/hooks/use-resize-observer/legacy/index.js |
| 5079 |
/** |
| 5080 |
* External dependencies |
| 5081 |
*/ |
| 5082 |
|
| 5083 |
/** |
| 5084 |
* WordPress dependencies |
| 5085 |
*/ |
| 5086 |
|
| 5087 |
/** |
| 5088 |
* Internal dependencies |
| 5089 |
*/ |
| 5090 |
|
| 5091 |
|
| 5092 |
// We're only using the first element of the size sequences, until future versions of the spec solidify on how |
| 5093 |
// exactly it'll be used for fragments in multi-column scenarios: |
| 5094 |
// From the spec: |
| 5095 |
// > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments, |
| 5096 |
// > which occur in multi-column scenarios. However the current definitions of content rect and border box do not |
| 5097 |
// > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single |
| 5098 |
// > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column. |
| 5099 |
// > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information. |
| 5100 |
// (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface) |
| 5101 |
// |
| 5102 |
// Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback, |
| 5103 |
// regardless of the "box" option. |
| 5104 |
// The spec states the following on this: |
| 5105 |
// > This does not have any impact on which box dimensions are returned to the defined callback when the event |
| 5106 |
// > is fired, it solely defines which box the author wishes to observe layout changes on. |
| 5107 |
// (https://drafts.csswg.org/resize-observer/#resize-observer-interface) |
| 5108 |
// I'm not exactly clear on what this means, especially when you consider a later section stating the following: |
| 5109 |
// > This section is non-normative. An author may desire to observe more than one CSS box. |
| 5110 |
// > In this case, author will need to use multiple ResizeObservers. |
| 5111 |
// (https://drafts.csswg.org/resize-observer/#resize-observer-interface) |
| 5112 |
// Which is clearly not how current browser implementations behave, and seems to contradict the previous quote. |
| 5113 |
// For this reason I decided to only return the requested size, |
| 5114 |
// even though it seems we have access to results for all box types. |
| 5115 |
// This also means that we get to keep the current api, being able to return a simple { width, height } pair, |
| 5116 |
// regardless of box option. |
| 5117 |
const extractSize = entry => { |
| 5118 |
let entrySize; |
| 5119 |
if (!entry.contentBoxSize) { |
| 5120 |
// The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec. |
| 5121 |
// See the 6th step in the description for the RO algorithm: |
| 5122 |
// https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h |
| 5123 |
// > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box". |
| 5124 |
// In real browser implementations of course these objects differ, but the width/height values should be equivalent. |
| 5125 |
entrySize = [entry.contentRect.width, entry.contentRect.height]; |
| 5126 |
} else if (entry.contentBoxSize[0]) { |
| 5127 |
const contentBoxSize = entry.contentBoxSize[0]; |
| 5128 |
entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize]; |
| 5129 |
} else { |
| 5130 |
// TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy |
| 5131 |
// behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`. |
| 5132 |
const contentBoxSize = entry.contentBoxSize; |
| 5133 |
entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize]; |
| 5134 |
} |
| 5135 |
const [width, height] = entrySize.map(d => Math.round(d)); |
| 5136 |
return { |
| 5137 |
width, |
| 5138 |
height |
| 5139 |
}; |
| 5140 |
}; |
| 5141 |
const RESIZE_ELEMENT_STYLES = { |
| 5142 |
position: 'absolute', |
| 5143 |
top: 0, |
| 5144 |
left: 0, |
| 5145 |
right: 0, |
| 5146 |
bottom: 0, |
| 5147 |
pointerEvents: 'none', |
| 5148 |
opacity: 0, |
| 5149 |
overflow: 'hidden', |
| 5150 |
zIndex: -1 |
| 5151 |
}; |
| 5152 |
function ResizeElement({ |
| 5153 |
onResize |
| 5154 |
}) { |
| 5155 |
const resizeElementRef = useResizeObserver(entries => { |
| 5156 |
const newSize = extractSize(entries.at(-1)); // Entries are never empty. |
| 5157 |
onResize(newSize); |
| 5158 |
}); |
| 5159 |
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { |
| 5160 |
ref: resizeElementRef, |
| 5161 |
style: RESIZE_ELEMENT_STYLES, |
| 5162 |
"aria-hidden": "true" |
| 5163 |
}); |
| 5164 |
} |
| 5165 |
function sizeEquals(a, b) { |
| 5166 |
return a.width === b.width && a.height === b.height; |
| 5167 |
} |
| 5168 |
const NULL_SIZE = { |
| 5169 |
width: null, |
| 5170 |
height: null |
| 5171 |
}; |
| 5172 |
|
| 5173 |
/** |
| 5174 |
* Hook which allows to listen to the resize event of any target element when it changes size. |
| 5175 |
* _Note: `useResizeObserver` will report `null` sizes until after first render. |
| 5176 |
* |
| 5177 |
* @example |
| 5178 |
* |
| 5179 |
* ```js |
| 5180 |
* const App = () => { |
| 5181 |
* const [ resizeListener, sizes ] = useResizeObserver(); |
| 5182 |
* |
| 5183 |
* return ( |
| 5184 |
* <div> |
| 5185 |
* { resizeListener } |
| 5186 |
* Your content here |
| 5187 |
* </div> |
| 5188 |
* ); |
| 5189 |
* }; |
| 5190 |
* ``` |
| 5191 |
*/ |
| 5192 |
function useLegacyResizeObserver() { |
| 5193 |
const [size, setSize] = (0,external_wp_element_namespaceObject.useState)(NULL_SIZE); |
| 5194 |
|
| 5195 |
// Using a ref to track the previous width / height to avoid unnecessary renders. |
| 5196 |
const previousSizeRef = (0,external_wp_element_namespaceObject.useRef)(NULL_SIZE); |
| 5197 |
const handleResize = (0,external_wp_element_namespaceObject.useCallback)(newSize => { |
| 5198 |
if (!sizeEquals(previousSizeRef.current, newSize)) { |
| 5199 |
previousSizeRef.current = newSize; |
| 5200 |
setSize(newSize); |
| 5201 |
} |
| 5202 |
}, []); |
| 5203 |
const resizeElement = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ResizeElement, { |
| 5204 |
onResize: handleResize |
| 5205 |
}); |
| 5206 |
return [resizeElement, size]; |
| 5207 |
} |
| 5208 |
|
| 5209 |
;// ./packages/compose/build-module/hooks/use-resize-observer/index.js |
| 5210 |
/** |
| 5211 |
* Internal dependencies |
| 5212 |
*/ |
| 5213 |
|
| 5214 |
|
| 5215 |
/** |
| 5216 |
* External dependencies |
| 5217 |
*/ |
| 5218 |
|
| 5219 |
/** |
| 5220 |
* Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API) |
| 5221 |
* for an HTML or SVG element. |
| 5222 |
* |
| 5223 |
* Pass the returned setter as a callback ref to the React element you want |
| 5224 |
* to observe, or use it in layout effects for advanced use cases. |
| 5225 |
* |
| 5226 |
* @example |
| 5227 |
* |
| 5228 |
* ```tsx |
| 5229 |
* const setElement = useResizeObserver( |
| 5230 |
* ( resizeObserverEntries ) => console.log( resizeObserverEntries ), |
| 5231 |
* { box: 'border-box' } |
| 5232 |
* ); |
| 5233 |
* <div ref={ setElement } />; |
| 5234 |
* |
| 5235 |
* // The setter can be used in other ways, for example: |
| 5236 |
* useLayoutEffect( () => { |
| 5237 |
* setElement( document.querySelector( `data-element-id="${ elementId }"` ) ); |
| 5238 |
* }, [ elementId ] ); |
| 5239 |
* ``` |
| 5240 |
* |
| 5241 |
* @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback). |
| 5242 |
* @param options Options passed to `ResizeObserver.observe` when called - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options). Changes will be ignored. |
| 5243 |
*/ |
| 5244 |
|
| 5245 |
/** |
| 5246 |
* **This is a legacy API and should not be used.** |
| 5247 |
* |
| 5248 |
* @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`. |
| 5249 |
* |
| 5250 |
* Hook which allows to listen to the resize event of any target element when it changes size. |
| 5251 |
* _Note: `useResizeObserver` will report `null` sizes until after first render. |
| 5252 |
* |
| 5253 |
* @example |
| 5254 |
* |
| 5255 |
* ```js |
| 5256 |
* const App = () => { |
| 5257 |
* const [ resizeListener, sizes ] = useResizeObserver(); |
| 5258 |
* |
| 5259 |
* return ( |
| 5260 |
* <div> |
| 5261 |
* { resizeListener } |
| 5262 |
* Your content here |
| 5263 |
* </div> |
| 5264 |
* ); |
| 5265 |
* }; |
| 5266 |
* ``` |
| 5267 |
*/ |
| 5268 |
|
| 5269 |
function use_resize_observer_useResizeObserver(callback, options = {}) { |
| 5270 |
return callback ? useResizeObserver(callback, options) : useLegacyResizeObserver(); |
| 5271 |
} |
| 5272 |
|
| 5273 |
;// external ["wp","priorityQueue"] |
| 5274 |
const external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; |
| 5275 |
;// ./packages/compose/build-module/hooks/use-async-list/index.js |
| 5276 |
/** |
| 5277 |
* WordPress dependencies |
| 5278 |
*/ |
| 5279 |
|
| 5280 |
|
| 5281 |
/** |
| 5282 |
* Returns the first items from list that are present on state. |
| 5283 |
* |
| 5284 |
* @param list New array. |
| 5285 |
* @param state Current state. |
| 5286 |
* @return First items present iin state. |
| 5287 |
*/ |
| 5288 |
function getFirstItemsPresentInState(list, state) { |
| 5289 |
const firstItems = []; |
| 5290 |
for (let i = 0; i < list.length; i++) { |
| 5291 |
const item = list[i]; |
| 5292 |
if (!state.includes(item)) { |
| 5293 |
break; |
| 5294 |
} |
| 5295 |
firstItems.push(item); |
| 5296 |
} |
| 5297 |
return firstItems; |
| 5298 |
} |
| 5299 |
|
| 5300 |
/** |
| 5301 |
* React hook returns an array which items get asynchronously appended from a source array. |
| 5302 |
* This behavior is useful if we want to render a list of items asynchronously for performance reasons. |
| 5303 |
* |
| 5304 |
* @param list Source array. |
| 5305 |
* @param config Configuration object. |
| 5306 |
* |
| 5307 |
* @return Async array. |
| 5308 |
*/ |
| 5309 |
function useAsyncList(list, config = { |
| 5310 |
step: 1 |
| 5311 |
}) { |
| 5312 |
const { |
| 5313 |
step = 1 |
| 5314 |
} = config; |
| 5315 |
const [current, setCurrent] = (0,external_wp_element_namespaceObject.useState)([]); |
| 5316 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 5317 |
// On reset, we keep the first items that were previously rendered. |
| 5318 |
let firstItems = getFirstItemsPresentInState(list, current); |
| 5319 |
if (firstItems.length < step) { |
| 5320 |
firstItems = firstItems.concat(list.slice(firstItems.length, step)); |
| 5321 |
} |
| 5322 |
setCurrent(firstItems); |
| 5323 |
const asyncQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)(); |
| 5324 |
for (let i = firstItems.length; i < list.length; i += step) { |
| 5325 |
asyncQueue.add({}, () => { |
| 5326 |
(0,external_wp_element_namespaceObject.flushSync)(() => { |
| 5327 |
setCurrent(state => [...state, ...list.slice(i, i + step)]); |
| 5328 |
}); |
| 5329 |
}); |
| 5330 |
} |
| 5331 |
return () => asyncQueue.reset(); |
| 5332 |
}, [list]); |
| 5333 |
return current; |
| 5334 |
} |
| 5335 |
/* harmony default export */ const use_async_list = (useAsyncList); |
| 5336 |
|
| 5337 |
;// ./packages/compose/build-module/hooks/use-warn-on-change/index.js |
| 5338 |
/** |
| 5339 |
* Internal dependencies |
| 5340 |
*/ |
| 5341 |
|
| 5342 |
|
| 5343 |
// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case |
| 5344 |
// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript |
| 5345 |
/* eslint-disable jsdoc/check-types */ |
| 5346 |
/** |
| 5347 |
* Hook that performs a shallow comparison between the preview value of an object |
| 5348 |
* and the new one, if there's a difference, it prints it to the console. |
| 5349 |
* this is useful in performance related work, to check why a component re-renders. |
| 5350 |
* |
| 5351 |
* @example |
| 5352 |
* |
| 5353 |
* ```jsx |
| 5354 |
* function MyComponent(props) { |
| 5355 |
* useWarnOnChange(props); |
| 5356 |
* |
| 5357 |
* return "Something"; |
| 5358 |
* } |
| 5359 |
* ``` |
| 5360 |
* |
| 5361 |
* @param {object} object Object which changes to compare. |
| 5362 |
* @param {string} prefix Just a prefix to show when console logging. |
| 5363 |
*/ |
| 5364 |
function useWarnOnChange(object, prefix = 'Change detection') { |
| 5365 |
const previousValues = usePrevious(object); |
| 5366 |
Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(([key, value]) => { |
| 5367 |
if (value !== object[(/** @type {keyof typeof object} */key)]) { |
| 5368 |
// eslint-disable-next-line no-console |
| 5369 |
console.warn(`${prefix}: ${key} key changed:`, value, object[(/** @type {keyof typeof object} */key)] |
| 5370 |
/* eslint-enable jsdoc/check-types */); |
| 5371 |
} |
| 5372 |
}); |
| 5373 |
} |
| 5374 |
/* harmony default export */ const use_warn_on_change = (useWarnOnChange); |
| 5375 |
|
| 5376 |
;// external "React" |
| 5377 |
const external_React_namespaceObject = window["React"]; |
| 5378 |
;// ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
| 5379 |
|
| 5380 |
|
| 5381 |
function areInputsEqual(newInputs, lastInputs) { |
| 5382 |
if (newInputs.length !== lastInputs.length) { |
| 5383 |
return false; |
| 5384 |
} |
| 5385 |
|
| 5386 |
for (var i = 0; i < newInputs.length; i++) { |
| 5387 |
if (newInputs[i] !== lastInputs[i]) { |
| 5388 |
return false; |
| 5389 |
} |
| 5390 |
} |
| 5391 |
|
| 5392 |
return true; |
| 5393 |
} |
| 5394 |
|
| 5395 |
function useMemoOne(getResult, inputs) { |
| 5396 |
var initial = (0,external_React_namespaceObject.useState)(function () { |
| 5397 |
return { |
| 5398 |
inputs: inputs, |
| 5399 |
result: getResult() |
| 5400 |
}; |
| 5401 |
})[0]; |
| 5402 |
var committed = (0,external_React_namespaceObject.useRef)(initial); |
| 5403 |
var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); |
| 5404 |
var cache = isInputMatch ? committed.current : { |
| 5405 |
inputs: inputs, |
| 5406 |
result: getResult() |
| 5407 |
}; |
| 5408 |
(0,external_React_namespaceObject.useEffect)(function () { |
| 5409 |
committed.current = cache; |
| 5410 |
}, [cache]); |
| 5411 |
return cache.result; |
| 5412 |
} |
| 5413 |
function useCallbackOne(callback, inputs) { |
| 5414 |
return useMemoOne(function () { |
| 5415 |
return callback; |
| 5416 |
}, inputs); |
| 5417 |
} |
| 5418 |
var useMemo = (/* unused pure expression or super */ null && (useMemoOne)); |
| 5419 |
var useCallback = (/* unused pure expression or super */ null && (useCallbackOne)); |
| 5420 |
|
| 5421 |
|
| 5422 |
|
| 5423 |
;// ./packages/compose/build-module/hooks/use-debounce/index.js |
| 5424 |
/** |
| 5425 |
* External dependencies |
| 5426 |
*/ |
| 5427 |
|
| 5428 |
|
| 5429 |
/** |
| 5430 |
* WordPress dependencies |
| 5431 |
*/ |
| 5432 |
|
| 5433 |
|
| 5434 |
/** |
| 5435 |
* Internal dependencies |
| 5436 |
*/ |
| 5437 |
|
| 5438 |
|
| 5439 |
/** |
| 5440 |
* Debounces a function similar to Lodash's `debounce`. A new debounced function will |
| 5441 |
* be returned and any scheduled calls cancelled if any of the arguments change, |
| 5442 |
* including the function to debounce, so please wrap functions created on |
| 5443 |
* render in components in `useCallback`. |
| 5444 |
* |
| 5445 |
* @see https://lodash.com/docs/4#debounce |
| 5446 |
* |
| 5447 |
* @template {(...args: any[]) => void} TFunc |
| 5448 |
* |
| 5449 |
* @param {TFunc} fn The function to debounce. |
| 5450 |
* @param {number} [wait] The number of milliseconds to delay. |
| 5451 |
* @param {import('../../utils/debounce').DebounceOptions} [options] The options object. |
| 5452 |
* @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function. |
| 5453 |
*/ |
| 5454 |
function useDebounce(fn, wait, options) { |
| 5455 |
const debounced = useMemoOne(() => debounce(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]); |
| 5456 |
(0,external_wp_element_namespaceObject.useEffect)(() => () => debounced.cancel(), [debounced]); |
| 5457 |
return debounced; |
| 5458 |
} |
| 5459 |
|
| 5460 |
;// ./packages/compose/build-module/hooks/use-debounced-input/index.js |
| 5461 |
/** |
| 5462 |
* WordPress dependencies |
| 5463 |
*/ |
| 5464 |
|
| 5465 |
|
| 5466 |
/** |
| 5467 |
* Internal dependencies |
| 5468 |
*/ |
| 5469 |
|
| 5470 |
|
| 5471 |
/** |
| 5472 |
* Helper hook for input fields that need to debounce the value before using it. |
| 5473 |
* |
| 5474 |
* @param defaultValue The default value to use. |
| 5475 |
* @return The input value, the setter and the debounced input value. |
| 5476 |
*/ |
| 5477 |
function useDebouncedInput(defaultValue = '') { |
| 5478 |
const [input, setInput] = (0,external_wp_element_namespaceObject.useState)(defaultValue); |
| 5479 |
const [debouncedInput, setDebouncedState] = (0,external_wp_element_namespaceObject.useState)(defaultValue); |
| 5480 |
const setDebouncedInput = useDebounce(setDebouncedState, 250); |
| 5481 |
(0,external_wp_element_namespaceObject.useEffect)(() => { |
| 5482 |
setDebouncedInput(input); |
| 5483 |
}, [input, setDebouncedInput]); |
| 5484 |
return [input, setInput, debouncedInput]; |
| 5485 |
} |
| 5486 |
|
| 5487 |
;// ./packages/compose/build-module/hooks/use-throttle/index.js |
| 5488 |
/** |
| 5489 |
* External dependencies |
| 5490 |
*/ |
| 5491 |
|
| 5492 |
|
| 5493 |
/** |
| 5494 |
* WordPress dependencies |
| 5495 |
*/ |
| 5496 |
|
| 5497 |
|
| 5498 |
/** |
| 5499 |
* Internal dependencies |
| 5500 |
*/ |
| 5501 |
|
| 5502 |
|
| 5503 |
/** |
| 5504 |
* Throttles a function similar to Lodash's `throttle`. A new throttled function will |
| 5505 |
* be returned and any scheduled calls cancelled if any of the arguments change, |
| 5506 |
* including the function to throttle, so please wrap functions created on |
| 5507 |
* render in components in `useCallback`. |
| 5508 |
* |
| 5509 |
* @see https://lodash.com/docs/4#throttle |
| 5510 |
* |
| 5511 |
* @template {(...args: any[]) => void} TFunc |
| 5512 |
* |
| 5513 |
* @param {TFunc} fn The function to throttle. |
| 5514 |
* @param {number} [wait] The number of milliseconds to throttle invocations to. |
| 5515 |
* @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details. |
| 5516 |
* @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function. |
| 5517 |
*/ |
| 5518 |
function useThrottle(fn, wait, options) { |
| 5519 |
const throttled = useMemoOne(() => throttle(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]); |
| 5520 |
(0,external_wp_element_namespaceObject.useEffect)(() => () => throttled.cancel(), [throttled]); |
| 5521 |
return throttled; |
| 5522 |
} |
| 5523 |
|
| 5524 |
;// ./packages/compose/build-module/hooks/use-drop-zone/index.js |
| 5525 |
/** |
| 5526 |
* Internal dependencies |
| 5527 |
*/ |
| 5528 |
|
| 5529 |
|
| 5530 |
|
| 5531 |
/** |
| 5532 |
* A hook to facilitate drag and drop handling. |
| 5533 |
* |
| 5534 |
* @param {Object} props Named parameters. |
| 5535 |
* @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone. |
| 5536 |
* @param {boolean} [props.isDisabled] Whether or not to disable the drop zone. |
| 5537 |
* @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started. |
| 5538 |
* @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered. |
| 5539 |
* @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within. |
| 5540 |
* @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left. |
| 5541 |
* @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended. |
| 5542 |
* @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone. |
| 5543 |
* |
| 5544 |
* @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element. |
| 5545 |
*/ |
| 5546 |
function useDropZone({ |
| 5547 |
dropZoneElement, |
| 5548 |
isDisabled, |
| 5549 |
onDrop: _onDrop, |
| 5550 |
onDragStart: _onDragStart, |
| 5551 |
onDragEnter: _onDragEnter, |
| 5552 |
onDragLeave: _onDragLeave, |
| 5553 |
onDragEnd: _onDragEnd, |
| 5554 |
onDragOver: _onDragOver |
| 5555 |
}) { |
| 5556 |
const onDropEvent = useEvent(_onDrop); |
| 5557 |
const onDragStartEvent = useEvent(_onDragStart); |
| 5558 |
const onDragEnterEvent = useEvent(_onDragEnter); |
| 5559 |
const onDragLeaveEvent = useEvent(_onDragLeave); |
| 5560 |
const onDragEndEvent = useEvent(_onDragEnd); |
| 5561 |
const onDragOverEvent = useEvent(_onDragOver); |
| 5562 |
return useRefEffect(elem => { |
| 5563 |
if (isDisabled) { |
| 5564 |
return; |
| 5565 |
} |
| 5566 |
|
| 5567 |
// If a custom dropZoneRef is passed, use that instead of the element. |
| 5568 |
// This allows the dropzone to cover an expanded area, rather than |
| 5569 |
// be restricted to the area of the ref returned by this hook. |
| 5570 |
const element = dropZoneElement !== null && dropZoneElement !== void 0 ? dropZoneElement : elem; |
| 5571 |
let isDragging = false; |
| 5572 |
const { |
| 5573 |
ownerDocument |
| 5574 |
} = element; |
| 5575 |
|
| 5576 |
/** |
| 5577 |
* Checks if an element is in the drop zone. |
| 5578 |
* |
| 5579 |
* @param {EventTarget|null} targetToCheck |
| 5580 |
* |
| 5581 |
* @return {boolean} True if in drop zone, false if not. |
| 5582 |
*/ |
| 5583 |
function isElementInZone(targetToCheck) { |
| 5584 |
const { |
| 5585 |
defaultView |
| 5586 |
} = ownerDocument; |
| 5587 |
if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) { |
| 5588 |
return false; |
| 5589 |
} |
| 5590 |
|
| 5591 |
/** @type {HTMLElement|null} */ |
| 5592 |
let elementToCheck = targetToCheck; |
| 5593 |
do { |
| 5594 |
if (elementToCheck.dataset.isDropZone) { |
| 5595 |
return elementToCheck === element; |
| 5596 |
} |
| 5597 |
} while (elementToCheck = elementToCheck.parentElement); |
| 5598 |
return false; |
| 5599 |
} |
| 5600 |
function maybeDragStart(/** @type {DragEvent} */event) { |
| 5601 |
if (isDragging) { |
| 5602 |
return; |
| 5603 |
} |
| 5604 |
isDragging = true; |
| 5605 |
|
| 5606 |
// Note that `dragend` doesn't fire consistently for file and |
| 5607 |
// HTML drag events where the drag origin is outside the browser |
| 5608 |
// window. In Firefox it may also not fire if the originating |
| 5609 |
// node is removed. |
| 5610 |
ownerDocument.addEventListener('dragend', maybeDragEnd); |
| 5611 |
ownerDocument.addEventListener('mousemove', maybeDragEnd); |
| 5612 |
if (_onDragStart) { |
| 5613 |
onDragStartEvent(event); |
| 5614 |
} |
| 5615 |
} |
| 5616 |
function onDragEnter(/** @type {DragEvent} */event) { |
| 5617 |
event.preventDefault(); |
| 5618 |
|
| 5619 |
// The `dragenter` event will also fire when entering child |
| 5620 |
// elements, but we only want to call `onDragEnter` when |
| 5621 |
// entering the drop zone, which means the `relatedTarget` |
| 5622 |
// (element that has been left) should be outside the drop zone. |
| 5623 |
if (element.contains(/** @type {Node} */event.relatedTarget)) { |
| 5624 |
return; |
| 5625 |
} |
| 5626 |
if (_onDragEnter) { |
| 5627 |
onDragEnterEvent(event); |
| 5628 |
} |
| 5629 |
} |
| 5630 |
function onDragOver(/** @type {DragEvent} */event) { |
| 5631 |
// Only call onDragOver for the innermost hovered drop zones. |
| 5632 |
if (!event.defaultPrevented && _onDragOver) { |
| 5633 |
onDragOverEvent(event); |
| 5634 |
} |
| 5635 |
|
| 5636 |
// Prevent the browser default while also signalling to parent |
| 5637 |
// drop zones that `onDragOver` is already handled. |
| 5638 |
event.preventDefault(); |
| 5639 |
} |
| 5640 |
function onDragLeave(/** @type {DragEvent} */event) { |
| 5641 |
// The `dragleave` event will also fire when leaving child |
| 5642 |
// elements, but we only want to call `onDragLeave` when |
| 5643 |
// leaving the drop zone, which means the `relatedTarget` |
| 5644 |
// (element that has been entered) should be outside the drop |
| 5645 |
// zone. |
| 5646 |
// Note: This is not entirely reliable in Safari due to this bug |
| 5647 |
// https://bugs.webkit.org/show_bug.cgi?id=66547 |
| 5648 |
|
| 5649 |
if (isElementInZone(event.relatedTarget)) { |
| 5650 |
return; |
| 5651 |
} |
| 5652 |
if (_onDragLeave) { |
| 5653 |
onDragLeaveEvent(event); |
| 5654 |
} |
| 5655 |
} |
| 5656 |
function onDrop(/** @type {DragEvent} */event) { |
| 5657 |
// Don't handle drop if an inner drop zone already handled it. |
| 5658 |
if (event.defaultPrevented) { |
| 5659 |
return; |
| 5660 |
} |
| 5661 |
|
| 5662 |
// Prevent the browser default while also signalling to parent |
| 5663 |
// drop zones that `onDrop` is already handled. |
| 5664 |
event.preventDefault(); |
| 5665 |
|
| 5666 |
// This seemingly useless line has been shown to resolve a |
| 5667 |
// Safari issue where files dragged directly from the dock are |
| 5668 |
// not recognized. |
| 5669 |
// eslint-disable-next-line no-unused-expressions |
| 5670 |
event.dataTransfer && event.dataTransfer.files.length; |
| 5671 |
if (_onDrop) { |
| 5672 |
onDropEvent(event); |
| 5673 |
} |
| 5674 |
maybeDragEnd(event); |
| 5675 |
} |
| 5676 |
function maybeDragEnd(/** @type {MouseEvent} */event) { |
| 5677 |
if (!isDragging) { |
| 5678 |
return; |
| 5679 |
} |
| 5680 |
isDragging = false; |
| 5681 |
ownerDocument.removeEventListener('dragend', maybeDragEnd); |
| 5682 |
ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
| 5683 |
if (_onDragEnd) { |
| 5684 |
onDragEndEvent(event); |
| 5685 |
} |
| 5686 |
} |
| 5687 |
element.setAttribute('data-is-drop-zone', 'true'); |
| 5688 |
element.addEventListener('drop', onDrop); |
| 5689 |
element.addEventListener('dragenter', onDragEnter); |
| 5690 |
element.addEventListener('dragover', onDragOver); |
| 5691 |
element.addEventListener('dragleave', onDragLeave); |
| 5692 |
// The `dragstart` event doesn't fire if the drag started outside |
| 5693 |
// the document. |
| 5694 |
ownerDocument.addEventListener('dragenter', maybeDragStart); |
| 5695 |
return () => { |
| 5696 |
element.removeAttribute('data-is-drop-zone'); |
| 5697 |
element.removeEventListener('drop', onDrop); |
| 5698 |
element.removeEventListener('dragenter', onDragEnter); |
| 5699 |
element.removeEventListener('dragover', onDragOver); |
| 5700 |
element.removeEventListener('dragleave', onDragLeave); |
| 5701 |
ownerDocument.removeEventListener('dragend', maybeDragEnd); |
| 5702 |
ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
| 5703 |
ownerDocument.removeEventListener('dragenter', maybeDragStart); |
| 5704 |
}; |
| 5705 |
}, [isDisabled, dropZoneElement] // Refresh when the passed in dropZoneElement changes. |
| 5706 |
); |
| 5707 |
} |
| 5708 |
|
| 5709 |
;// ./packages/compose/build-module/hooks/use-focusable-iframe/index.js |
| 5710 |
/** |
| 5711 |
* External dependencies |
| 5712 |
*/ |
| 5713 |
|
| 5714 |
/** |
| 5715 |
* Internal dependencies |
| 5716 |
*/ |
| 5717 |
|
| 5718 |
|
| 5719 |
/** |
| 5720 |
* Dispatches a bubbling focus event when the iframe receives focus. Use |
| 5721 |
* `onFocus` as usual on the iframe or a parent element. |
| 5722 |
* |
| 5723 |
* @return Ref to pass to the iframe. |
| 5724 |
*/ |
| 5725 |
function useFocusableIframe() { |
| 5726 |
return useRefEffect(element => { |
| 5727 |
const { |
| 5728 |
ownerDocument |
| 5729 |
} = element; |
| 5730 |
if (!ownerDocument) { |
| 5731 |
return; |
| 5732 |
} |
| 5733 |
const { |
| 5734 |
defaultView |
| 5735 |
} = ownerDocument; |
| 5736 |
if (!defaultView) { |
| 5737 |
return; |
| 5738 |
} |
| 5739 |
|
| 5740 |
/** |
| 5741 |
* Checks whether the iframe is the activeElement, inferring that it has |
| 5742 |
* then received focus, and dispatches a focus event. |
| 5743 |
*/ |
| 5744 |
function checkFocus() { |
| 5745 |
if (ownerDocument && ownerDocument.activeElement === element) { |
| 5746 |
element.focus(); |
| 5747 |
} |
| 5748 |
} |
| 5749 |
defaultView.addEventListener('blur', checkFocus); |
| 5750 |
return () => { |
| 5751 |
defaultView.removeEventListener('blur', checkFocus); |
| 5752 |
}; |
| 5753 |
}, []); |
| 5754 |
} |
| 5755 |
|
| 5756 |
;// ./packages/compose/build-module/hooks/use-fixed-window-list/index.js |
| 5757 |
/** |
| 5758 |
* WordPress dependencies |
| 5759 |
*/ |
| 5760 |
|
| 5761 |
|
| 5762 |
|
| 5763 |
|
| 5764 |
/** |
| 5765 |
* Internal dependencies |
| 5766 |
*/ |
| 5767 |
|
| 5768 |
const DEFAULT_INIT_WINDOW_SIZE = 30; |
| 5769 |
|
| 5770 |
/** |
| 5771 |
* @typedef {Object} WPFixedWindowList |
| 5772 |
* |
| 5773 |
* @property {number} visibleItems Items visible in the current viewport |
| 5774 |
* @property {number} start Start index of the window |
| 5775 |
* @property {number} end End index of the window |
| 5776 |
* @property {(index:number)=>boolean} itemInView Returns true if item is in the window |
| 5777 |
*/ |
| 5778 |
|
| 5779 |
/** |
| 5780 |
* @typedef {Object} WPFixedWindowListOptions |
| 5781 |
* |
| 5782 |
* @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window. |
| 5783 |
* @property {boolean} [useWindowing] When false avoids calculating the window size |
| 5784 |
* @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size. |
| 5785 |
* @property {any} [expandedState] Used to recalculate the window size when the expanded state of a list changes. |
| 5786 |
*/ |
| 5787 |
|
| 5788 |
/** |
| 5789 |
* |
| 5790 |
* @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element. |
| 5791 |
* @param { number } itemHeight Fixed item height in pixels |
| 5792 |
* @param { number } totalItems Total items in list |
| 5793 |
* @param { WPFixedWindowListOptions } [options] Options object |
| 5794 |
* @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter |
| 5795 |
*/ |
| 5796 |
function useFixedWindowList(elementRef, itemHeight, totalItems, options) { |
| 5797 |
var _options$initWindowSi, _options$useWindowing; |
| 5798 |
const initWindowSize = (_options$initWindowSi = options?.initWindowSize) !== null && _options$initWindowSi !== void 0 ? _options$initWindowSi : DEFAULT_INIT_WINDOW_SIZE; |
| 5799 |
const useWindowing = (_options$useWindowing = options?.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true; |
| 5800 |
const [fixedListWindow, setFixedListWindow] = (0,external_wp_element_namespaceObject.useState)({ |
| 5801 |
visibleItems: initWindowSize, |
| 5802 |
start: 0, |
| 5803 |
end: initWindowSize, |
| 5804 |
itemInView: (/** @type {number} */index) => { |
| 5805 |
return index >= 0 && index <= initWindowSize; |
| 5806 |
} |
| 5807 |
}); |
| 5808 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
| 5809 |
if (!useWindowing) { |
| 5810 |
return; |
| 5811 |
} |
| 5812 |
const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
| 5813 |
const measureWindow = (/** @type {boolean | undefined} */initRender) => { |
| 5814 |
var _options$windowOversc; |
| 5815 |
if (!scrollContainer) { |
| 5816 |
return; |
| 5817 |
} |
| 5818 |
const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); |
| 5819 |
// Aim to keep opening list view fast, afterward we can optimize for scrolling. |
| 5820 |
const windowOverscan = initRender ? visibleItems : (_options$windowOversc = options?.windowOverscan) !== null && _options$windowOversc !== void 0 ? _options$windowOversc : visibleItems; |
| 5821 |
const firstViewableIndex = Math.floor(scrollContainer.scrollTop / itemHeight); |
| 5822 |
const start = Math.max(0, firstViewableIndex - windowOverscan); |
| 5823 |
const end = Math.min(totalItems - 1, firstViewableIndex + visibleItems + windowOverscan); |
| 5824 |
setFixedListWindow(lastWindow => { |
| 5825 |
const nextWindow = { |
| 5826 |
visibleItems, |
| 5827 |
start, |
| 5828 |
end, |
| 5829 |
itemInView: (/** @type {number} */index) => { |
| 5830 |
return start <= index && index <= end; |
| 5831 |
} |
| 5832 |
}; |
| 5833 |
if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) { |
| 5834 |
return nextWindow; |
| 5835 |
} |
| 5836 |
return lastWindow; |
| 5837 |
}); |
| 5838 |
}; |
| 5839 |
measureWindow(true); |
| 5840 |
const debounceMeasureList = debounce(() => { |
| 5841 |
measureWindow(); |
| 5842 |
}, 16); |
| 5843 |
scrollContainer?.addEventListener('scroll', debounceMeasureList); |
| 5844 |
scrollContainer?.ownerDocument?.defaultView?.addEventListener('resize', debounceMeasureList); |
| 5845 |
scrollContainer?.ownerDocument?.defaultView?.addEventListener('resize', debounceMeasureList); |
| 5846 |
return () => { |
| 5847 |
scrollContainer?.removeEventListener('scroll', debounceMeasureList); |
| 5848 |
scrollContainer?.ownerDocument?.defaultView?.removeEventListener('resize', debounceMeasureList); |
| 5849 |
}; |
| 5850 |
}, [itemHeight, elementRef, totalItems, options?.expandedState, options?.windowOverscan, useWindowing]); |
| 5851 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
| 5852 |
if (!useWindowing) { |
| 5853 |
return; |
| 5854 |
} |
| 5855 |
const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
| 5856 |
const handleKeyDown = (/** @type {KeyboardEvent} */event) => { |
| 5857 |
switch (event.keyCode) { |
| 5858 |
case external_wp_keycodes_namespaceObject.HOME: |
| 5859 |
{ |
| 5860 |
return scrollContainer?.scrollTo({ |
| 5861 |
top: 0 |
| 5862 |
}); |
| 5863 |
} |
| 5864 |
case external_wp_keycodes_namespaceObject.END: |
| 5865 |
{ |
| 5866 |
return scrollContainer?.scrollTo({ |
| 5867 |
top: totalItems * itemHeight |
| 5868 |
}); |
| 5869 |
} |
| 5870 |
case external_wp_keycodes_namespaceObject.PAGEUP: |
| 5871 |
{ |
| 5872 |
return scrollContainer?.scrollTo({ |
| 5873 |
top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight |
| 5874 |
}); |
| 5875 |
} |
| 5876 |
case external_wp_keycodes_namespaceObject.PAGEDOWN: |
| 5877 |
{ |
| 5878 |
return scrollContainer?.scrollTo({ |
| 5879 |
top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight |
| 5880 |
}); |
| 5881 |
} |
| 5882 |
} |
| 5883 |
}; |
| 5884 |
scrollContainer?.ownerDocument?.defaultView?.addEventListener('keydown', handleKeyDown); |
| 5885 |
return () => { |
| 5886 |
scrollContainer?.ownerDocument?.defaultView?.removeEventListener('keydown', handleKeyDown); |
| 5887 |
}; |
| 5888 |
}, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems, useWindowing, options?.expandedState]); |
| 5889 |
return [fixedListWindow, setFixedListWindow]; |
| 5890 |
} |
| 5891 |
|
| 5892 |
;// ./packages/compose/build-module/hooks/use-observable-value/index.js |
| 5893 |
/** |
| 5894 |
* WordPress dependencies |
| 5895 |
*/ |
| 5896 |
|
| 5897 |
|
| 5898 |
/** |
| 5899 |
* Internal dependencies |
| 5900 |
*/ |
| 5901 |
|
| 5902 |
/** |
| 5903 |
* React hook that lets you observe an entry in an `ObservableMap`. The hook returns the |
| 5904 |
* current value corresponding to the key, or `undefined` when there is no value stored. |
| 5905 |
* It also observes changes to the value and triggers an update of the calling component |
| 5906 |
* in case the value changes. |
| 5907 |
* |
| 5908 |
* @template K The type of the keys in the map. |
| 5909 |
* @template V The type of the values in the map. |
| 5910 |
* @param map The `ObservableMap` to observe. |
| 5911 |
* @param name The map key to observe. |
| 5912 |
* @return The value corresponding to the map key requested. |
| 5913 |
*/ |
| 5914 |
function useObservableValue(map, name) { |
| 5915 |
const [subscribe, getValue] = (0,external_wp_element_namespaceObject.useMemo)(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]); |
| 5916 |
return (0,external_wp_element_namespaceObject.useSyncExternalStore)(subscribe, getValue, getValue); |
| 5917 |
} |
| 5918 |
|
| 5919 |
;// ./packages/compose/build-module/index.js |
| 5920 |
// The `createHigherOrderComponent` helper and helper types. |
| 5921 |
|
| 5922 |
// The `debounce` helper and its types. |
| 5923 |
|
| 5924 |
// The `throttle` helper and its types. |
| 5925 |
|
| 5926 |
// The `ObservableMap` data structure |
| 5927 |
|
| 5928 |
|
| 5929 |
// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash). |
| 5930 |
|
| 5931 |
|
| 5932 |
|
| 5933 |
// Higher-order components. |
| 5934 |
|
| 5935 |
|
| 5936 |
|
| 5937 |
|
| 5938 |
|
| 5939 |
|
| 5940 |
|
| 5941 |
// Hooks. |
| 5942 |
|
| 5943 |
|
| 5944 |
|
| 5945 |
|
| 5946 |
|
| 5947 |
|
| 5948 |
|
| 5949 |
|
| 5950 |
|
| 5951 |
|
| 5952 |
|
| 5953 |
|
| 5954 |
|
| 5955 |
|
| 5956 |
|
| 5957 |
|
| 5958 |
|
| 5959 |
|
| 5960 |
|
| 5961 |
|
| 5962 |
|
| 5963 |
|
| 5964 |
|
| 5965 |
|
| 5966 |
|
| 5967 |
|
| 5968 |
|
| 5969 |
|
| 5970 |
|
| 5971 |
|
| 5972 |
|
| 5973 |
})(); |
| 5974 |
|
| 5975 |
(window.wp = window.wp || {}).compose = __webpack_exports__; |
| 5976 |
/******/ })() |
| 5977 |
; |