keyboard-shortcuts.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(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. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(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. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. // ESM COMPAT FLAG
  38. __webpack_require__.r(__webpack_exports__);
  39. // EXPORTS
  40. __webpack_require__.d(__webpack_exports__, {
  41. "ShortcutProvider": function() { return /* reexport */ ShortcutProvider; },
  42. "__unstableUseShortcutEventMatch": function() { return /* reexport */ useShortcutEventMatch; },
  43. "store": function() { return /* reexport */ store; },
  44. "useShortcut": function() { return /* reexport */ useShortcut; }
  45. });
  46. // NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
  47. var actions_namespaceObject = {};
  48. __webpack_require__.r(actions_namespaceObject);
  49. __webpack_require__.d(actions_namespaceObject, {
  50. "registerShortcut": function() { return registerShortcut; },
  51. "unregisterShortcut": function() { return unregisterShortcut; }
  52. });
  53. // NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
  54. var selectors_namespaceObject = {};
  55. __webpack_require__.r(selectors_namespaceObject);
  56. __webpack_require__.d(selectors_namespaceObject, {
  57. "getAllShortcutKeyCombinations": function() { return getAllShortcutKeyCombinations; },
  58. "getAllShortcutRawKeyCombinations": function() { return getAllShortcutRawKeyCombinations; },
  59. "getCategoryShortcuts": function() { return getCategoryShortcuts; },
  60. "getShortcutAliases": function() { return getShortcutAliases; },
  61. "getShortcutDescription": function() { return getShortcutDescription; },
  62. "getShortcutKeyCombination": function() { return getShortcutKeyCombination; },
  63. "getShortcutRepresentation": function() { return getShortcutRepresentation; }
  64. });
  65. ;// CONCATENATED MODULE: external ["wp","data"]
  66. var external_wp_data_namespaceObject = window["wp"]["data"];
  67. ;// CONCATENATED MODULE: external "lodash"
  68. var external_lodash_namespaceObject = window["lodash"];
  69. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/reducer.js
  70. /**
  71. * External dependencies
  72. */
  73. /**
  74. * Reducer returning the registered shortcuts
  75. *
  76. * @param {Object} state Current state.
  77. * @param {Object} action Dispatched action.
  78. *
  79. * @return {Object} Updated state.
  80. */
  81. function reducer() {
  82. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  83. let action = arguments.length > 1 ? arguments[1] : undefined;
  84. switch (action.type) {
  85. case 'REGISTER_SHORTCUT':
  86. return { ...state,
  87. [action.name]: {
  88. category: action.category,
  89. keyCombination: action.keyCombination,
  90. aliases: action.aliases,
  91. description: action.description
  92. }
  93. };
  94. case 'UNREGISTER_SHORTCUT':
  95. return (0,external_lodash_namespaceObject.omit)(state, action.name);
  96. }
  97. return state;
  98. }
  99. /* harmony default export */ var store_reducer = (reducer);
  100. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
  101. /** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */
  102. /**
  103. * Keyboard key combination.
  104. *
  105. * @typedef {Object} WPShortcutKeyCombination
  106. *
  107. * @property {string} character Character.
  108. * @property {WPKeycodeModifier|undefined} modifier Modifier.
  109. */
  110. /**
  111. * Configuration of a registered keyboard shortcut.
  112. *
  113. * @typedef {Object} WPShortcutConfig
  114. *
  115. * @property {string} name Shortcut name.
  116. * @property {string} category Shortcut category.
  117. * @property {string} description Shortcut description.
  118. * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.
  119. * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.
  120. */
  121. /**
  122. * Returns an action object used to register a new keyboard shortcut.
  123. *
  124. * @param {WPShortcutConfig} config Shortcut config.
  125. *
  126. * @return {Object} action.
  127. */
  128. function registerShortcut(_ref) {
  129. let {
  130. name,
  131. category,
  132. description,
  133. keyCombination,
  134. aliases
  135. } = _ref;
  136. return {
  137. type: 'REGISTER_SHORTCUT',
  138. name,
  139. category,
  140. keyCombination,
  141. aliases,
  142. description
  143. };
  144. }
  145. /**
  146. * Returns an action object used to unregister a keyboard shortcut.
  147. *
  148. * @param {string} name Shortcut name.
  149. *
  150. * @return {Object} action.
  151. */
  152. function unregisterShortcut(name) {
  153. return {
  154. type: 'UNREGISTER_SHORTCUT',
  155. name
  156. };
  157. }
  158. ;// CONCATENATED MODULE: ./node_modules/rememo/es/rememo.js
  159. var LEAF_KEY, hasWeakMap;
  160. /**
  161. * Arbitrary value used as key for referencing cache object in WeakMap tree.
  162. *
  163. * @type {Object}
  164. */
  165. LEAF_KEY = {};
  166. /**
  167. * Whether environment supports WeakMap.
  168. *
  169. * @type {boolean}
  170. */
  171. hasWeakMap = typeof WeakMap !== 'undefined';
  172. /**
  173. * Returns the first argument as the sole entry in an array.
  174. *
  175. * @param {*} value Value to return.
  176. *
  177. * @return {Array} Value returned as entry in array.
  178. */
  179. function arrayOf( value ) {
  180. return [ value ];
  181. }
  182. /**
  183. * Returns true if the value passed is object-like, or false otherwise. A value
  184. * is object-like if it can support property assignment, e.g. object or array.
  185. *
  186. * @param {*} value Value to test.
  187. *
  188. * @return {boolean} Whether value is object-like.
  189. */
  190. function isObjectLike( value ) {
  191. return !! value && 'object' === typeof value;
  192. }
  193. /**
  194. * Creates and returns a new cache object.
  195. *
  196. * @return {Object} Cache object.
  197. */
  198. function createCache() {
  199. var cache = {
  200. clear: function() {
  201. cache.head = null;
  202. },
  203. };
  204. return cache;
  205. }
  206. /**
  207. * Returns true if entries within the two arrays are strictly equal by
  208. * reference from a starting index.
  209. *
  210. * @param {Array} a First array.
  211. * @param {Array} b Second array.
  212. * @param {number} fromIndex Index from which to start comparison.
  213. *
  214. * @return {boolean} Whether arrays are shallowly equal.
  215. */
  216. function isShallowEqual( a, b, fromIndex ) {
  217. var i;
  218. if ( a.length !== b.length ) {
  219. return false;
  220. }
  221. for ( i = fromIndex; i < a.length; i++ ) {
  222. if ( a[ i ] !== b[ i ] ) {
  223. return false;
  224. }
  225. }
  226. return true;
  227. }
  228. /**
  229. * Returns a memoized selector function. The getDependants function argument is
  230. * called before the memoized selector and is expected to return an immutable
  231. * reference or array of references on which the selector depends for computing
  232. * its own return value. The memoize cache is preserved only as long as those
  233. * dependant references remain the same. If getDependants returns a different
  234. * reference(s), the cache is cleared and the selector value regenerated.
  235. *
  236. * @param {Function} selector Selector function.
  237. * @param {Function} getDependants Dependant getter returning an immutable
  238. * reference or array of reference used in
  239. * cache bust consideration.
  240. *
  241. * @return {Function} Memoized selector.
  242. */
  243. /* harmony default export */ function rememo(selector, getDependants ) {
  244. var rootCache, getCache;
  245. // Use object source as dependant if getter not provided
  246. if ( ! getDependants ) {
  247. getDependants = arrayOf;
  248. }
  249. /**
  250. * Returns the root cache. If WeakMap is supported, this is assigned to the
  251. * root WeakMap cache set, otherwise it is a shared instance of the default
  252. * cache object.
  253. *
  254. * @return {(WeakMap|Object)} Root cache object.
  255. */
  256. function getRootCache() {
  257. return rootCache;
  258. }
  259. /**
  260. * Returns the cache for a given dependants array. When possible, a WeakMap
  261. * will be used to create a unique cache for each set of dependants. This
  262. * is feasible due to the nature of WeakMap in allowing garbage collection
  263. * to occur on entries where the key object is no longer referenced. Since
  264. * WeakMap requires the key to be an object, this is only possible when the
  265. * dependant is object-like. The root cache is created as a hierarchy where
  266. * each top-level key is the first entry in a dependants set, the value a
  267. * WeakMap where each key is the next dependant, and so on. This continues
  268. * so long as the dependants are object-like. If no dependants are object-
  269. * like, then the cache is shared across all invocations.
  270. *
  271. * @see isObjectLike
  272. *
  273. * @param {Array} dependants Selector dependants.
  274. *
  275. * @return {Object} Cache object.
  276. */
  277. function getWeakMapCache( dependants ) {
  278. var caches = rootCache,
  279. isUniqueByDependants = true,
  280. i, dependant, map, cache;
  281. for ( i = 0; i < dependants.length; i++ ) {
  282. dependant = dependants[ i ];
  283. // Can only compose WeakMap from object-like key.
  284. if ( ! isObjectLike( dependant ) ) {
  285. isUniqueByDependants = false;
  286. break;
  287. }
  288. // Does current segment of cache already have a WeakMap?
  289. if ( caches.has( dependant ) ) {
  290. // Traverse into nested WeakMap.
  291. caches = caches.get( dependant );
  292. } else {
  293. // Create, set, and traverse into a new one.
  294. map = new WeakMap();
  295. caches.set( dependant, map );
  296. caches = map;
  297. }
  298. }
  299. // We use an arbitrary (but consistent) object as key for the last item
  300. // in the WeakMap to serve as our running cache.
  301. if ( ! caches.has( LEAF_KEY ) ) {
  302. cache = createCache();
  303. cache.isUniqueByDependants = isUniqueByDependants;
  304. caches.set( LEAF_KEY, cache );
  305. }
  306. return caches.get( LEAF_KEY );
  307. }
  308. // Assign cache handler by availability of WeakMap
  309. getCache = hasWeakMap ? getWeakMapCache : getRootCache;
  310. /**
  311. * Resets root memoization cache.
  312. */
  313. function clear() {
  314. rootCache = hasWeakMap ? new WeakMap() : createCache();
  315. }
  316. // eslint-disable-next-line jsdoc/check-param-names
  317. /**
  318. * The augmented selector call, considering first whether dependants have
  319. * changed before passing it to underlying memoize function.
  320. *
  321. * @param {Object} source Source object for derivation.
  322. * @param {...*} extraArgs Additional arguments to pass to selector.
  323. *
  324. * @return {*} Selector result.
  325. */
  326. function callSelector( /* source, ...extraArgs */ ) {
  327. var len = arguments.length,
  328. cache, node, i, args, dependants;
  329. // Create copy of arguments (avoid leaking deoptimization).
  330. args = new Array( len );
  331. for ( i = 0; i < len; i++ ) {
  332. args[ i ] = arguments[ i ];
  333. }
  334. dependants = getDependants.apply( null, args );
  335. cache = getCache( dependants );
  336. // If not guaranteed uniqueness by dependants (primitive type or lack
  337. // of WeakMap support), shallow compare against last dependants and, if
  338. // references have changed, destroy cache to recalculate result.
  339. if ( ! cache.isUniqueByDependants ) {
  340. if ( cache.lastDependants && ! isShallowEqual( dependants, cache.lastDependants, 0 ) ) {
  341. cache.clear();
  342. }
  343. cache.lastDependants = dependants;
  344. }
  345. node = cache.head;
  346. while ( node ) {
  347. // Check whether node arguments match arguments
  348. if ( ! isShallowEqual( node.args, args, 1 ) ) {
  349. node = node.next;
  350. continue;
  351. }
  352. // At this point we can assume we've found a match
  353. // Surface matched node to head if not already
  354. if ( node !== cache.head ) {
  355. // Adjust siblings to point to each other.
  356. node.prev.next = node.next;
  357. if ( node.next ) {
  358. node.next.prev = node.prev;
  359. }
  360. node.next = cache.head;
  361. node.prev = null;
  362. cache.head.prev = node;
  363. cache.head = node;
  364. }
  365. // Return immediately
  366. return node.val;
  367. }
  368. // No cached value found. Continue to insertion phase:
  369. node = {
  370. // Generate the result from original function
  371. val: selector.apply( null, args ),
  372. };
  373. // Avoid including the source object in the cache.
  374. args[ 0 ] = null;
  375. node.args = args;
  376. // Don't need to check whether node is already head, since it would
  377. // have been returned above already if it was
  378. // Shift existing head down list
  379. if ( cache.head ) {
  380. cache.head.prev = node;
  381. node.next = cache.head;
  382. }
  383. cache.head = node;
  384. return node.val;
  385. }
  386. callSelector.getDependants = getDependants;
  387. callSelector.clear = clear;
  388. clear();
  389. return callSelector;
  390. }
  391. ;// CONCATENATED MODULE: external ["wp","keycodes"]
  392. var external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
  393. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
  394. /**
  395. * External dependencies
  396. */
  397. /**
  398. * WordPress dependencies
  399. */
  400. /** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */
  401. /** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */
  402. /**
  403. * Shared reference to an empty array for cases where it is important to avoid
  404. * returning a new array reference on every invocation.
  405. *
  406. * @type {Array<any>}
  407. */
  408. const EMPTY_ARRAY = [];
  409. /**
  410. * Shortcut formatting methods.
  411. *
  412. * @property {WPKeycodeHandlerByModifier} display Display formatting.
  413. * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.
  414. * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.
  415. */
  416. const FORMATTING_METHODS = {
  417. display: external_wp_keycodes_namespaceObject.displayShortcut,
  418. raw: external_wp_keycodes_namespaceObject.rawShortcut,
  419. ariaLabel: external_wp_keycodes_namespaceObject.shortcutAriaLabel
  420. };
  421. /**
  422. * Returns a string representing the key combination.
  423. *
  424. * @param {?WPShortcutKeyCombination} shortcut Key combination.
  425. * @param {keyof FORMATTING_METHODS} representation Type of representation
  426. * (display, raw, ariaLabel).
  427. *
  428. * @return {string?} Shortcut representation.
  429. */
  430. function getKeyCombinationRepresentation(shortcut, representation) {
  431. if (!shortcut) {
  432. return null;
  433. }
  434. return shortcut.modifier ? FORMATTING_METHODS[representation][shortcut.modifier](shortcut.character) : shortcut.character;
  435. }
  436. /**
  437. * Returns the main key combination for a given shortcut name.
  438. *
  439. * @param {Object} state Global state.
  440. * @param {string} name Shortcut name.
  441. *
  442. * @return {WPShortcutKeyCombination?} Key combination.
  443. */
  444. function getShortcutKeyCombination(state, name) {
  445. return state[name] ? state[name].keyCombination : null;
  446. }
  447. /**
  448. * Returns a string representing the main key combination for a given shortcut name.
  449. *
  450. * @param {Object} state Global state.
  451. * @param {string} name Shortcut name.
  452. * @param {keyof FORMATTING_METHODS} representation Type of representation
  453. * (display, raw, ariaLabel).
  454. *
  455. * @return {string?} Shortcut representation.
  456. */
  457. function getShortcutRepresentation(state, name) {
  458. let representation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'display';
  459. const shortcut = getShortcutKeyCombination(state, name);
  460. return getKeyCombinationRepresentation(shortcut, representation);
  461. }
  462. /**
  463. * Returns the shortcut description given its name.
  464. *
  465. * @param {Object} state Global state.
  466. * @param {string} name Shortcut name.
  467. *
  468. * @return {string?} Shortcut description.
  469. */
  470. function getShortcutDescription(state, name) {
  471. return state[name] ? state[name].description : null;
  472. }
  473. /**
  474. * Returns the aliases for a given shortcut name.
  475. *
  476. * @param {Object} state Global state.
  477. * @param {string} name Shortcut name.
  478. *
  479. * @return {WPShortcutKeyCombination[]} Key combinations.
  480. */
  481. function getShortcutAliases(state, name) {
  482. return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
  483. }
  484. const getAllShortcutKeyCombinations = rememo((state, name) => {
  485. return (0,external_lodash_namespaceObject.compact)([getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)]);
  486. }, (state, name) => [state[name]]);
  487. /**
  488. * Returns the raw representation of all the keyboard combinations of a given shortcut name.
  489. *
  490. * @param {Object} state Global state.
  491. * @param {string} name Shortcut name.
  492. *
  493. * @return {string[]} Shortcuts.
  494. */
  495. const getAllShortcutRawKeyCombinations = rememo((state, name) => {
  496. return getAllShortcutKeyCombinations(state, name).map(combination => getKeyCombinationRepresentation(combination, 'raw'));
  497. }, (state, name) => [state[name]]);
  498. /**
  499. * Returns the shortcut names list for a given category name.
  500. *
  501. * @param {Object} state Global state.
  502. * @param {string} name Category name.
  503. *
  504. * @return {string[]} Shortcut names.
  505. */
  506. const getCategoryShortcuts = rememo((state, categoryName) => {
  507. return Object.entries(state).filter(_ref => {
  508. let [, shortcut] = _ref;
  509. return shortcut.category === categoryName;
  510. }).map(_ref2 => {
  511. let [name] = _ref2;
  512. return name;
  513. });
  514. }, state => [state]);
  515. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/index.js
  516. /**
  517. * WordPress dependencies
  518. */
  519. /**
  520. * Internal dependencies
  521. */
  522. const STORE_NAME = 'core/keyboard-shortcuts';
  523. /**
  524. * Store definition for the keyboard shortcuts namespace.
  525. *
  526. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  527. *
  528. * @type {Object}
  529. */
  530. const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
  531. reducer: store_reducer,
  532. actions: actions_namespaceObject,
  533. selectors: selectors_namespaceObject
  534. });
  535. (0,external_wp_data_namespaceObject.register)(store);
  536. ;// CONCATENATED MODULE: external ["wp","element"]
  537. var external_wp_element_namespaceObject = window["wp"]["element"];
  538. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut-event-match.js
  539. /**
  540. * WordPress dependencies
  541. */
  542. /**
  543. * Internal dependencies
  544. */
  545. /**
  546. * Returns a function to check if a keyboard event matches a shortcut name.
  547. *
  548. * @return {Function} A function to to check if a keyboard event matches a
  549. * predefined shortcut combination.
  550. */
  551. function useShortcutEventMatch() {
  552. const {
  553. getAllShortcutKeyCombinations
  554. } = (0,external_wp_data_namespaceObject.useSelect)(store);
  555. /**
  556. * A function to check if a keyboard event matches a predefined shortcut
  557. * combination.
  558. *
  559. * @param {string} name Shortcut name.
  560. * @param {KeyboardEvent} event Event to check.
  561. *
  562. * @return {boolean} True if the event matches any shortcuts, false if not.
  563. */
  564. function isMatch(name, event) {
  565. return getAllShortcutKeyCombinations(name).some(_ref => {
  566. let {
  567. modifier,
  568. character
  569. } = _ref;
  570. return external_wp_keycodes_namespaceObject.isKeyboardEvent[modifier](event, character);
  571. });
  572. }
  573. return isMatch;
  574. }
  575. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/context.js
  576. /**
  577. * WordPress dependencies
  578. */
  579. const context = (0,external_wp_element_namespaceObject.createContext)();
  580. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut.js
  581. /**
  582. * WordPress dependencies
  583. */
  584. /**
  585. * Internal dependencies
  586. */
  587. /**
  588. * Attach a keyboard shortcut handler.
  589. *
  590. * @param {string} name Shortcut name.
  591. * @param {Function} callback Shortcut callback.
  592. * @param {Object} options Shortcut options.
  593. * @param {boolean} options.isDisabled Whether to disable to shortut.
  594. */
  595. function useShortcut(name, callback) {
  596. let {
  597. isDisabled
  598. } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  599. const shortcuts = (0,external_wp_element_namespaceObject.useContext)(context);
  600. const isMatch = useShortcutEventMatch();
  601. const callbackRef = (0,external_wp_element_namespaceObject.useRef)();
  602. callbackRef.current = callback;
  603. (0,external_wp_element_namespaceObject.useEffect)(() => {
  604. if (isDisabled) {
  605. return;
  606. }
  607. function _callback(event) {
  608. if (isMatch(name, event)) {
  609. callbackRef.current(event);
  610. }
  611. }
  612. shortcuts.current.add(_callback);
  613. return () => {
  614. shortcuts.current.delete(_callback);
  615. };
  616. }, [name, isDisabled]);
  617. }
  618. ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
  619. function _extends() {
  620. _extends = Object.assign ? Object.assign.bind() : function (target) {
  621. for (var i = 1; i < arguments.length; i++) {
  622. var source = arguments[i];
  623. for (var key in source) {
  624. if (Object.prototype.hasOwnProperty.call(source, key)) {
  625. target[key] = source[key];
  626. }
  627. }
  628. }
  629. return target;
  630. };
  631. return _extends.apply(this, arguments);
  632. }
  633. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/components/shortcut-provider.js
  634. /**
  635. * WordPress dependencies
  636. */
  637. /**
  638. * Internal dependencies
  639. */
  640. const {
  641. Provider
  642. } = context;
  643. /**
  644. * Handles callbacks added to context by `useShortcut`.
  645. *
  646. * @param {Object} props Props to pass to `div`.
  647. *
  648. * @return {import('@wordpress/element').WPElement} Component.
  649. */
  650. function ShortcutProvider(props) {
  651. const keyboardShortcuts = (0,external_wp_element_namespaceObject.useRef)(new Set());
  652. function onKeyDown(event) {
  653. if (props.onKeyDown) props.onKeyDown(event);
  654. for (const keyboardShortcut of keyboardShortcuts.current) {
  655. keyboardShortcut(event);
  656. }
  657. }
  658. /* eslint-disable jsx-a11y/no-static-element-interactions */
  659. return (0,external_wp_element_namespaceObject.createElement)(Provider, {
  660. value: keyboardShortcuts
  661. }, (0,external_wp_element_namespaceObject.createElement)("div", _extends({}, props, {
  662. onKeyDown: onKeyDown
  663. })));
  664. /* eslint-enable jsx-a11y/no-static-element-interactions */
  665. }
  666. ;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/index.js
  667. (window.wp = window.wp || {}).keyboardShortcuts = __webpack_exports__;
  668. /******/ })()
  669. ;