1/******/ (() => { // webpackBootstrap 2/******/ "use strict"; 3/******/ // The require scope 4/******/ var __webpack_require__ = {}; 5/******/ 6/************************************************************************/ 7/******/ /* webpack/runtime/define property getters */ 8/******/ (() => { 9/******/ // define getter functions for harmony exports 10/******/ __webpack_require__.d = (exports, definition) => { 11/******/ for(var key in definition) { 12/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 13/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14/******/ } 15/******/ } 16/******/ }; 17/******/ })(); 18/******/ 19/******/ /* webpack/runtime/hasOwnProperty shorthand */ 20/******/ (() => { 21/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22/******/ })(); 23/******/ 24/******/ /* webpack/runtime/make namespace object */ 25/******/ (() => { 26/******/ // define __esModule on exports 27/******/ __webpack_require__.r = (exports) => { 28/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 29/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 30/******/ } 31/******/ Object.defineProperty(exports, '__esModule', { value: true }); 32/******/ }; 33/******/ })(); 34/******/ 35/************************************************************************/ 36var __webpack_exports__ = {}; 37// ESM COMPAT FLAG 38__webpack_require__.r(__webpack_exports__); 39 40// EXPORTS 41__webpack_require__.d(__webpack_exports__, { 42 "ShortcutProvider": () => (/* reexport */ ShortcutProvider), 43 "__unstableUseShortcutEventMatch": () => (/* reexport */ useShortcutEventMatch), 44 "store": () => (/* reexport */ store), 45 "useShortcut": () => (/* reexport */ useShortcut) 46}); 47 48// NAMESPACE OBJECT: ./packages/keyboard-shortcuts/build-module/store/actions.js 49var actions_namespaceObject = {}; 50__webpack_require__.r(actions_namespaceObject); 51__webpack_require__.d(actions_namespaceObject, { 52 "registerShortcut": () => (registerShortcut), 53 "unregisterShortcut": () => (unregisterShortcut) 54}); 55 56// NAMESPACE OBJECT: ./packages/keyboard-shortcuts/build-module/store/selectors.js 57var selectors_namespaceObject = {}; 58__webpack_require__.r(selectors_namespaceObject); 59__webpack_require__.d(selectors_namespaceObject, { 60 "getAllShortcutKeyCombinations": () => (getAllShortcutKeyCombinations), 61 "getAllShortcutRawKeyCombinations": () => (getAllShortcutRawKeyCombinations), 62 "getCategoryShortcuts": () => (getCategoryShortcuts), 63 "getShortcutAliases": () => (getShortcutAliases), 64 "getShortcutDescription": () => (getShortcutDescription), 65 "getShortcutKeyCombination": () => (getShortcutKeyCombination), 66 "getShortcutRepresentation": () => (getShortcutRepresentation) 67}); 68 69;// CONCATENATED MODULE: external ["wp","data"] 70const external_wp_data_namespaceObject = window["wp"]["data"]; 71;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/reducer.js 72/** 73 * Reducer returning the registered shortcuts 74 * 75 * @param {Object} state Current state. 76 * @param {Object} action Dispatched action. 77 * 78 * @return {Object} Updated state. 79 */ 80function reducer(state = {}, action) { 81 switch (action.type) { 82 case 'REGISTER_SHORTCUT': 83 return { 84 ...state, 85 [action.name]: { 86 category: action.category, 87 keyCombination: action.keyCombination, 88 aliases: action.aliases, 89 description: action.description 90 } 91 }; 92 case 'UNREGISTER_SHORTCUT': 93 const { 94 [action.name]: actionName, 95 ...remainingState 96 } = state; 97 return remainingState; 98 } 99 return state; 100} 101/* harmony default export */ const store_reducer = (reducer); 102 103;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/actions.js 104/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */ 105 106/** 107 * Keyboard key combination. 108 * 109 * @typedef {Object} WPShortcutKeyCombination 110 * 111 * @property {string} character Character. 112 * @property {WPKeycodeModifier|undefined} modifier Modifier. 113 */ 114 115/** 116 * Configuration of a registered keyboard shortcut. 117 * 118 * @typedef {Object} WPShortcutConfig 119 * 120 * @property {string} name Shortcut name. 121 * @property {string} category Shortcut category. 122 * @property {string} description Shortcut description. 123 * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination. 124 * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases. 125 */ 126 127/** 128 * Returns an action object used to register a new keyboard shortcut. 129 * 130 * @param {WPShortcutConfig} config Shortcut config. 131 * 132 * @example 133 * 134 *```js 135 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
136 * import { useSelect, useDispatch } from '@wordpress/data'; 137 * import { useEffect } from '@wordpress/element'; 138 * import { __ } from '@wordpress/i18n'; 139 * 140 * const ExampleComponent = () => { 141 * const { registerShortcut } = useDispatch( keyboardShortcutsStore ); 142 * 143 * useEffect( () => { 144 * registerShortcut( { 145 * name: 'custom/my-custom-shortcut', 146 * category: 'my-category', 147 * description: __( 'My custom shortcut' ), 148 * keyCombination: { 149 * modifier: 'primary', 150 * character: 'j', 151 * }, 152 * } ); 153 * }, [] ); 154 * 155 * const shortcut = useSelect( 156 * ( select ) => 157 * select( keyboardShortcutsStore ).getShortcutKeyCombination( 158 * 'custom/my-custom-shortcut' 159 * ), 160 * [] 161 * ); 162 * 163 * return shortcut ? ( 164 * <p>{ __( 'Shortcut is registered.' ) }</p> 165 * ) : ( 166 * <p>{ __( 'Shortcut is not registered.' ) }</p> 167 * ); 168 * }; 169 *``` 170 * @return {Object} action. 171 */ 172function registerShortcut({ 173 name, 174 category, 175 description, 176 keyCombination, 177 aliases 178}) { 179 return { 180 type: 'REGISTER_SHORTCUT', 181 name, 182 category, 183 keyCombination, 184 aliases, 185 description 186 }; 187} 188 189/** 190 * Returns an action object used to unregister a keyboard shortcut. 191 * 192 * @param {string} name Shortcut name. 193 * 194 * @example 195 * 196 *```js 197 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; 198 * import { useSelect, useDispatch } from '@wordpress/data'; 199 * import { useEffect } from '@wordpress/element'; 200 * import { __ } from '@wordpress/i18n'; 201 * 202 * const ExampleComponent = () => { 203 * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore ); 204 * 205 * useEffect( () => { 206 * unregisterShortcut( 'core/edit-post/next-region' ); 207 * }, [] ); 208 * 209 * const shortcut = useSelect( 210 * ( select ) => 211 * select( keyboardShortcutsStore ).getShortcutKeyCombination( 212 * 'core/edit-post/next-region' 213 * ), 214 * [] 215 * ); 216 * 217 * return shortcut ? ( 218 * <p>{ __( 'Shortcut is not unregistered.' ) }</p> 219 * ) : ( 220 * <p>{ __( 'Shortcut is unregistered.' ) }</p> 221 * ); 222 * }; 223 *``` 224 * @return {Object} action. 225 */ 226function unregisterShortcut(name) { 227 return { 228 type: 'UNREGISTER_SHORTCUT', 229 name 230 }; 231} 232 233;// CONCATENATED MODULE: ./node_modules/rememo/rememo.js 234 235 236/** @typedef {(...args: any[]) => *[]} GetDependants */ 237 238/** @typedef {() => void} Clear */ 239 240/** 241 * @typedef {{ 242 * getDependants: GetDependants, 243 * clear: Clear 244 * }} EnhancedSelector 245 */ 246 247/** 248 * Internal cache entry. 249 * 250 * @typedef CacheNode 251 * 252 * @property {?CacheNode|undefined} [prev] Previous node. 253 * @property {?CacheNode|undefined} [next] Next node. 254 * @property {*[]} args Function arguments for cache entry. 255 * @property {*} val Function result. 256 */ 257 258/** 259 * @typedef Cache 260 * 261 * @property {Clear} clear Function to clear cache. 262 * @property {boolean} [isUniqueByDependants] Whether dependants are valid in 263 * considering cache uniqueness. A cache is unique if dependents are all arrays 264 * or objects. 265 * @property {CacheNode?} [head] Cache head. 266 * @property {*[]} [lastDependants] Dependants from previous invocation. 267 */ 268 269/** 270 * Arbitrary value used as key for referencing cache object in WeakMap tree. 271 * 272 * @type {{}} 273 */ 274var LEAF_KEY = {}; 275 276/** 277 * Returns the first argument as the sole entry in an array. 278 * 279 * @template T 280 * 281 * @param {T} value Value to return. 282 * 283 * @return {[T]} Value returned as entry in array. 284 */ 285function arrayOf(value) { 286 return [value]; 287} 288 289/** 290 * Returns true if the value passed is object-like, or false otherwise. A value 291 * is object-like if it can support property assignment, e.g. object or array. 292 * 293 * @param {*} value Value to test. 294 * 295 * @return {boolean} Whether value is object-like. 296 */ 297function isObjectLike(value) { 298 return !!value && 'object' === typeof value; 299} 300 301/** 302 * Creates and returns a new cache object. 303 * 304 * @return {Cache} Cache object. 305 */ 306function createCache() { 307 /** @type {Cache} */ 308 var cache = { 309 clear: function () { 310 cache.head = null; 311 }, 312 }; 313 314 return cache; 315} 316 317/** 318 * Returns true if entries within the two arrays are strictly equal by 319 * reference from a starting index. 320 * 321 * @param {*[]} a First array. 322 * @param {*[]} b Second array. 323 * @param {number} fromIndex Index from which to start comparison. 324 * 325 * @return {boolean} Whether arrays are shallowly equal. 326 */ 327function isShallowEqual(a, b, fromIndex) { 328 var i; 329 330 if (a.length !== b.length) { 331 return false;
332 } 333 334 for (i = fromIndex; i < a.length; i++) { 335 if (a[i] !== b[i]) { 336 return false; 337 } 338 } 339 340 return true; 341} 342 343/** 344 * Returns a memoized selector function. The getDependants function argument is 345 * called before the memoized selector and is expected to return an immutable 346 * reference or array of references on which the selector depends for computing 347 * its own return value. The memoize cache is preserved only as long as those 348 * dependant references remain the same. If getDependants returns a different 349 * reference(s), the cache is cleared and the selector value regenerated. 350 * 351 * @template {(...args: *[]) => *} S 352 * 353 * @param {S} selector Selector function. 354 * @param {GetDependants=} getDependants Dependant getter returning an array of 355 * references used in cache bust consideration. 356 */ 357/* harmony default export */ function rememo(selector, getDependants) { 358 /** @type {WeakMap<*,*>} */ 359 var rootCache; 360 361 /** @type {GetDependants} */ 362 var normalizedGetDependants = getDependants ? getDependants : arrayOf; 363 364 /** 365 * Returns the cache for a given dependants array. When possible, a WeakMap 366 * will be used to create a unique cache for each set of dependants. This 367 * is feasible due to the nature of WeakMap in allowing garbage collection 368 * to occur on entries where the key object is no longer referenced. Since 369 * WeakMap requires the key to be an object, this is only possible when the 370 * dependant is object-like. The root cache is created as a hierarchy where 371 * each top-level key is the first entry in a dependants set, the value a 372 * WeakMap where each key is the next dependant, and so on. This continues 373 * so long as the dependants are object-like. If no dependants are object- 374 * like, then the cache is shared across all invocations. 375 * 376 * @see isObjectLike 377 * 378 * @param {*[]}
378 dependants Selector dependants. 379 * 380 * @return {Cache} Cache object. 381 */ 382 function getCache(dependants) { 383 var caches = rootCache, 384 isUniqueByDependants = true, 385 i, 386 dependant, 387 map, 388 cache; 389 390 for (i = 0; i < dependants.length; i++) { 391 dependant = dependants[i]; 392 393 // Can only compose WeakMap from object-like key. 394 if (!isObjectLike(dependant)) { 395 isUniqueByDependants = false; 396 break; 397 } 398 399 // Does current segment of cache already have a WeakMap? 400 if (caches.has(dependant)) { 401 // Traverse into nested WeakMap. 402 caches = caches.get(dependant); 403 } else { 404 // Create, set, and traverse into a new one. 405 map = new WeakMap(); 406 caches.set(dependant, map); 407 caches = map; 408 } 409 } 410 411 // We use an arbitrary (but consistent) object as key for the last item 412 // in the WeakMap to serve as our running cache. 413 if (!caches.has(LEAF_KEY)) { 414 cache = createCache(); 415 cache.isUniqueByDependants = isUniqueByDependants; 416 caches.set(LEAF_KEY, cache); 417 } 418 419 return caches.get(LEAF_KEY); 420 } 421 422 /** 423 * Resets root memoization cache. 424 */ 425 function clear() { 426 rootCache = new WeakMap(); 427 } 428 429 /* eslint-disable jsdoc/check-param-names */ 430 /** 431 * The augmented selector call, considering first whether dependants have 432 * changed before passing it to underlying memoize function. 433 * 434 * @param {*} source Source object for derivation. 435 * @param {...*} extraArgs Additional arguments to pass to selector. 436 * 437 * @return {*} Selector result. 438 */ 439 /* eslint-enable jsdoc/check-param-names */ 440 function callSelector(/* source, ...extraArgs */) { 441 var len = arguments.length, 442 cache, 443 node, 444 i, 445 args, 446 dependants; 447 448 // Create copy of arguments (avoid leaking deoptimization). 449 args = new Array(len); 450 for (i = 0; i < len; i++) { 451 args[i] = arguments[i]; 452 } 453 454 dependants = normalizedGetDependants.apply(null, args); 455 cache = getCache(dependants); 456 457 // If not guaranteed uniqueness by dependants (primitive type), shallow 458 // compare against last dependants and, if references have changed, 459 // destroy cache to recalculate result. 460 if (!cache.isUniqueByDependants) { 461 if ( 462 cache.lastDependants && 463 !isShallowEqual(dependants, cache.lastDependants, 0) 464 ) { 465 cache.clear(); 466 } 467 468 cache.lastDependants = dependants; 469 } 470 471 node = cache.head; 472 while (node) { 473 // Check whether node arguments match arguments 474 if (!isShallowEqual(node.args, args, 1)) { 475 node = node.next; 476 continue; 477 } 478 479 // At this point we can assume we've found a match 480 481 // Surface matched node to head if not already 482 if (node !== cache.head) { 483 // Adjust siblings to point to each other. 484 /** @type {CacheNode} */ (node.prev).next = node.next; 485 if (node.next) { 486 node.next.prev = node.prev; 487 } 488 489 node.next = cache.head; 490 node.prev = null; 491 /** @type {CacheNode} */ (cache.head).prev = node; 492 cache.head = node; 493 } 494 495 // Return immediately 496 return node.val; 497 } 498 499 // No cached value found. Continue to insertion phase: 500 501 node = /** @type {CacheNode} */ ({ 502 // Generate the result from original function 503 val: selector.apply(null, args), 504 }); 505 506 // Avoid including the source object in the cache. 507 args[0] = null; 508 node.args = args; 509 510 // Don't need to check whether node is already head, since it would 511 // have been returned above already if it was 512 513 // Shift existing head down list 514 if (cache.head) { 515 cache.head.prev = node; 516 node.next = cache.head; 517 } 518 519 cache.head = node; 520 521 return node.val; 522 } 523 524 callSelector.getDependants = normalizedGetDependants; 525 callSelector.clear = clear; 526 clear(); 527 528 return /** @type {S & EnhancedSelector} */ (callSelector); 529} 530 531;// CONCATENATED MODULE: external ["wp","keycodes"] 532const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; 533;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/selectors.js 534/** 535 * External dependencies 536 */ 537 538 539/** 540 * WordPress dependencies 541 */ 542 543 544/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */ 545 546/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */ 547 548/** 549 * Shared reference to an empty array for cases where it is important to avoid 550 * returning a new array reference on every invocation. 551 * 552 * @type {Array<any>} 553 */ 554const EMPTY_ARRAY = []; 555 556/** 557 * Shortcut formatting methods. 558 * 559 * @property {WPKeycodeHandlerByModifier} display Display formatting. 560 * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting. 561 * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting. 562 */ 563const FORMATTING_METHODS = { 564 display: external_wp_keycodes_namespaceObject.displayShortcut, 565 raw: external_wp_keycodes_namespaceObject.rawShortcut, 566 ariaLabel: external_wp_keycodes_namespaceObject.shortcutAriaLabel 567}; 568 569/** 570 * Returns a string representing the key combination. 571 * 572 * @param {?WPShortcutKeyCombination} shortcut Key combination. 573 * @param {keyof FORMATTING_METHODS} representation Type of representation 574 * (display, raw, ariaLabel). 575 * 576 * @return {string?} Shortcut representation. 577 */ 578function getKeyCombinationRepresentation(shortcut, representation) { 579 if (!shortcut) { 580 return null; 581 } 582 return shortcut.modifier ? FORMATTING_METHODS[representation][shortcut.modifier](shortcut.character) : shortcut.character; 583} 584 585/** 586 * Returns the main key combination for a given shortcut name. 587 * 588 * @param {Object} state Global state. 589 * @param {string} name Shortcut name. 590 * 591 * @example 592 * 593 *```js 594 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
595 * import { useSelect } from '@wordpress/data'; 596 * import { createInterpolateElement } from '@wordpress/element'; 597 * import { sprintf } from '@wordpress/i18n'; 598 * const ExampleComponent = () => { 599 * const {character, modifier} = useSelect( 600 * ( select ) => 601 * select( keyboardShortcutsStore ).getShortcutKeyCombination( 602 * 'core/edit-post/next-region' 603 * ), 604 * [] 605 * ); 606 * 607 * return ( 608 * <div> 609 * { createInterpolateElement( 610 * sprintf( 611 * 'Character: <code>%s</code> / Modifier: <code>%s</code>', 612 * character, 613 * modifier 614 * ), 615 * { 616 * code: <code />, 617 * } 618 * ) } 619 * </div> 620 * ); 621 * }; 622 *``` 623 * 624 * @return {WPShortcutKeyCombination?} Key combination. 625 */ 626function getShortcutKeyCombination(state, name) { 627 return state[name] ? state[name].keyCombination : null; 628} 629 630/** 631 * Returns a string representing the main key combination for a given shortcut name. 632 * 633 * @param {Object} state Global state. 634 * @param {string} name Shortcut name. 635 * @param {keyof FORMATTING_METHODS} representation Type of representation 636 * (display, raw, ariaLabel). 637 * @example 638 * 639 *```js 640 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; 641 * import { useSelect } from '@wordpress/data'; 642 * import { sprintf } from '@wordpress/i18n'; 643 * 644 * const ExampleComponent = () => { 645 * const {display, raw, ariaLabel} = useSelect( 646 * ( select ) =>{ 647 * return { 648 * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region' ), 649 * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ), 650 * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region', 'ariaLabel') 651 * } 652 * }, 653 * [] 654 * ); 655 * 656 * return ( 657 * <ul> 658 * <li>{ sprintf( 'display string: %s', display ) }</li> 659 * <li>{ sprintf( 'raw string: %s', raw ) }</li> 660 * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li> 661 * </ul> 662 * ); 663 * }; 664 *``` 665 * 666 * @return {string?} Shortcut representation. 667 */ 668function getShortcutRepresentation(state, name, representation = 'display') { 669 const shortcut = getShortcutKeyCombination(state, name); 670 return getKeyCombinationRepresentation(shortcut, representation); 671} 672 673/** 674 * Returns the shortcut description given its name. 675 * 676 * @param {Object} state Global state. 677 * @param {string} name Shortcut name. 678 * 679 * @example 680 * 681 *```js 682 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; 683 * import { useSelect } from '@wordpress/data'; 684 * import { __ } from '@wordpress/i18n'; 685 * const ExampleComponent = () => { 686 * const shortcutDescription = useSelect( 687 * ( select ) => 688 * select( keyboardShortcutsStore ).getShortcutDescription( 'core/edit-post/next-region' ), 689 * [] 690 * ); 691 * 692 * return shortcutDescription ? ( 693 * <div>{ shortcutDescription }</div> 694 * ) : ( 695 * <div>{ __( 'No description.' ) }</div> 696 * ); 697 * }; 698 *``` 699 * @return {string?} Shortcut description. 700 */ 701function getShortcutDescription(state, name) { 702 return state[name] ? state[name].description : null; 703} 704 705/** 706 * Returns the aliases for a given shortcut name. 707 * 708 * @param {Object} state Global state. 709 * @param {string} name Shortcut name. 710 * @example 711 * 712 *```js 713 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; 714 * import { useSelect } from '@wordpress/data'; 715 * import { createInterpolateElement } from '@wordpress/element'; 716 * import { sprintf } from '@wordpress/i18n'; 717 * const ExampleComponent = () => { 718 * const shortcutAliases = useSelect( 719 * ( select ) => 720 * select( keyboardShortcutsStore ).getShortcutAliases( 721 * 'core/edit-post/next-region' 722 * ), 723 * [] 724 * ); 725 * 726 * return ( 727 * shortcutAliases.length > 0 && ( 728 * <ul> 729 * { shortcutAliases.map( ( { character, modifier }, index ) => ( 730 * <li key={ index }> 731 * { createInterpolateElement( 732 * sprintf( 733 * 'Character: <code>%s</code> / Modifier: <code>%s</code>', 734 * character, 735 * modifier 736 * ), 737 * { 738 * code: <code />, 739 * } 740 * ) } 741 * </li> 742 * ) ) } 743 * </ul> 744 * ) 745 * ); 746 * }; 747 *``` 748 * 749 * @return {WPShortcutKeyCombination[]} Key combinations. 750 */ 751function getShortcutAliases(state, name) {
752 return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY; 753} 754 755/** 756 * Returns the shortcuts that include aliases for a given shortcut name. 757 * 758 * @param {Object} state Global state. 759 * @param {string} name Shortcut name. 760 * @example 761 * 762 *```js 763 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; 764 * import { useSelect } from '@wordpress/data'; 765 * import { createInterpolateElement } from '@wordpress/element'; 766 * import { sprintf } from '@wordpress/i18n'; 767 * 768 * const ExampleComponent = () => { 769 * const allShortcutKeyCombinations = useSelect( 770 * ( select ) => 771 * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations( 772 * 'core/edit-post/next-region' 773 * ), 774 * [] 775 * ); 776 * 777 * return ( 778 * allShortcutKeyCombinations.length > 0 && ( 779 * <ul> 780 * { allShortcutKeyCombinations.map( 781 * ( { character, modifier }, index ) => ( 782 * <li key={ index }> 783 * { createInterpolateElement( 784 * sprintf( 785 * 'Character: <code>%s</code> / Modifier: <code>%s</code>', 786 * character, 787 * modifier 788 * ), 789 * { 790 * code: <code />, 791 * } 792 * ) } 793 * </li> 794 * ) 795 * ) } 796 * </ul> 797 * ) 798 * ); 799 * }; 800 *``` 801 * 802 * @return {WPShortcutKeyCombination[]} Key combinations. 803 */ 804const getAllShortcutKeyCombinations = rememo((state, name) => { 805 return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean); 806}, (state, name) => [state[name]]); 807 808/** 809 * Returns the raw representation of all the keyboard combinations of a given shortcut name. 810 * 811 * @param {Object} state Global state. 812 * @param {string} name Shortcut name. 813 * 814 * @example 815 * 816 *```js 817 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; 818 * import { useSelect } from '@wordpress/data'; 819 * import { createInterpolateElement } from '@wordpress/element'; 820 * import { sprintf } from '@wordpress/i18n'; 821 * 822 * const ExampleComponent = () => { 823 * const allShortcutRawKeyCombinations = useSelect( 824 * ( select ) => 825 * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations( 826 * 'core/edit-post/next-region' 827 * ), 828 * [] 829 * ); 830 * 831 * return ( 832 * allShortcutRawKeyCombinations.length > 0 && ( 833 * <ul> 834 * { allShortcutRawKeyCombinations.map( 835 * ( shortcutRawKeyCombination, index ) => ( 836 * <li key={ index }> 837 * { createInterpolateElement( 838 * sprintf( 839 * ' <code>%s</code>', 840 * shortcutRawKeyCombination 841 * ), 842 * { 843 * code: <code />, 844 * } 845 * ) } 846 * </li> 847 * ) 848 * ) } 849 * </ul> 850 * ) 851 * ); 852 * }; 853 *``` 854 * 855 * @return {string[]} Shortcuts. 856 */ 857const getAllShortcutRawKeyCombinations = rememo((state, name) => { 858 return getAllShortcutKeyCombinations(state, name).map(combination => getKeyCombinationRepresentation(combination, 'raw')); 859}, (state, name) => [state[name]]); 860 861/** 862 * Returns the shortcut names list for a given category name. 863 * 864 * @param {Object} state Global state. 865 * @param {string} name Category name. 866 * @example 867 * 868 *```js 869 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; 870 * import { useSelect } from '@wordpress/data'; 871 *
872 * const ExampleComponent = () => { 873 * const categoryShortcuts = useSelect( 874 * ( select ) => 875 * select( keyboardShortcutsStore ).getCategoryShortcuts( 876 * 'block' 877 * ), 878 * [] 879 * ); 880 * 881 * return ( 882 * categoryShortcuts.length > 0 && ( 883 * <ul> 884 * { categoryShortcuts.map( ( categoryShortcut ) => ( 885 * <li key={ categoryShortcut }>{ categoryShortcut }</li> 886 * ) ) } 887 * </ul> 888 * ) 889 * ); 890 * }; 891 *``` 892 * @return {string[]} Shortcut names. 893 */ 894const getCategoryShortcuts = rememo((state, categoryName) => { 895 return Object.entries(state).filter(([, shortcut]) => shortcut.category === categoryName).map(([name]) => name); 896}, state => [state]); 897 898;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/index.js 899/** 900 * WordPress dependencies 901 */ 902 903 904/** 905 * Internal dependencies 906 */ 907 908 909 910const STORE_NAME = 'core/keyboard-shortcuts'; 911 912/** 913 * Store definition for the keyboard shortcuts namespace. 914 * 915 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore 916 * 917 * @type {Object} 918 */ 919const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, { 920 reducer: store_reducer, 921 actions: actions_namespaceObject, 922 selectors: selectors_namespaceObject 923}); 924(0,external_wp_data_namespaceObject.register)(store); 925 926;// CONCATENATED MODULE: external ["wp","element"] 927const external_wp_element_namespaceObject = window["wp"]["element"]; 928;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/hooks/use-shortcut-event-match.js 929/** 930 * WordPress dependencies 931 */ 932 933 934 935/** 936 * Internal dependencies 937 */ 938 939 940/** 941 * Returns a function to check if a keyboard event matches a shortcut name. 942 * 943 * @return {Function} A function to check if a keyboard event matches a 944 * predefined shortcut combination. 945 */ 946function useShortcutEventMatch() { 947 const { 948 getAllShortcutKeyCombinations 949 } = (0,external_wp_data_namespaceObject.useSelect)(store); 950 951 /** 952 * A function to check if a keyboard event matches a predefined shortcut 953 * combination. 954 * 955 * @param {string} name Shortcut name. 956 * @param {KeyboardEvent} event Event to check. 957 * 958 * @return {boolean} True if the event matches any shortcuts, false if not. 959 */ 960 function isMatch(name, event) { 961 return getAllShortcutKeyCombinations(name).some(({ 962 modifier, 963 character 964 }) => { 965 return external_wp_keycodes_namespaceObject.isKeyboardEvent[modifier](event, character); 966 }); 967 } 968 return isMatch; 969} 970 971;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/context.js 972/** 973 * WordPress dependencies 974 */ 975 976const globalShortcuts = new Set(); 977const globalListener = event => { 978 for (const keyboardShortcut of globalShortcuts) { 979 keyboardShortcut(event); 980 } 981}; 982const context = (0,external_wp_element_namespaceObject.createContext)({ 983 add: shortcut => { 984 if (globalShortcuts.size === 0) { 985 document.addEventListener('keydown', globalListener); 986 } 987 globalShortcuts.add(shortcut); 988 }, 989 delete: shortcut => { 990 globalShortcuts.delete(shortcut); 991 if (globalShortcuts.size === 0) { 992 document.removeEventListener('keydown', globalListener); 993 } 994 } 995}); 996 997;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/hooks/use-shortcut.js 998/** 999 * WordPress dependencies 1000 */ 1001 1002 1003/** 1004 * Internal dependencies 1005 */ 1006 1007 1008 1009/** 1010 * Attach a keyboard shortcut handler. 1011 * 1012 * @param {string} name Shortcut name. 1013 * @param {Function} callback Shortcut callback. 1014 * @param {Object} options Shortcut options. 1015 * @param {boolean} options.isDisabled Whether to disable to shortut. 1016 */ 1017function useShortcut(name, callback, { 1018 isDisabled = false 1019} = {}) { 1020 const shortcuts = (0,external_wp_element_namespaceObject.useContext)(context); 1021 const isMatch = useShortcutEventMatch(); 1022 const callbackRef = (0,external_wp_element_namespaceObject.useRef)(); 1023 (0,external_wp_element_namespaceObject.useEffect)(() => { 1024 callbackRef.current = callback; 1025 }, [callback]); 1026 (0,external_wp_element_namespaceObject.useEffect)(() => { 1027 if (isDisabled) { 1028 return; 1029 } 1030 function _callback(event) { 1031 if (isMatch(name, event)) { 1032 callbackRef.current(event); 1033 } 1034 } 1035 shortcuts.add(_callback); 1036 return () => { 1037 shortcuts.delete(_callback); 1038 }; 1039 }, [name, isDisabled, shortcuts]); 1040} 1041 1042;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/components/shortcut-provider.js 1043 1044/** 1045 * WordPress dependencies 1046 */ 1047 1048 1049/** 1050 * Internal dependencies 1051 */ 1052 1053const { 1054 Provider 1055} = context; 1056 1057/** 1058 * Handles callbacks added to context by `useShortcut`. 1059 * Adding a provider allows to register contextual shortcuts 1060 * that are only active when a certain part of the UI is focused. 1061 * 1062 * @param {Object} props Props to pass to `div`. 1063 * 1064 * @return {import('@wordpress/element').WPElement} Component. 1065 */ 1066function ShortcutProvider(props) { 1067 const [keyboardShortcuts] = (0,external_wp_element_namespaceObject.useState)(() => new Set()); 1068 function onKeyDown(event) { 1069 if (props.onKeyDown) props.onKeyDown(event); 1070 for (const keyboardShortcut of keyboardShortcuts) { 1071 keyboardShortcut(event); 1072 } 1073 } 1074 1075 /* eslint-disable jsx-a11y/no-static-element-interactions */ 1076 return (0,external_wp_element_namespaceObject.createElement)(Provider, { 1077 value: keyboardShortcuts 1078 }, (0,external_wp_element_namespaceObject.createElement)("div", { 1079 ...props, 1080 onKeyDown: onKeyDown 1081 })); 1082 /* eslint-enable jsx-a11y/no-static-element-interactions */ 1083} 1084 1085;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/index.js 1086 1087 1088 1089 1090 1091(window.wp = window.wp || {}).keyboardShortcuts = __webpack_exports__; 1092/******/ })() 1093;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.