You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1092 lines
32 KiB

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