keyboard-shortcuts.js 22 KB

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