2023-09-21 15:26:32 +02:00
|
|
|
/******/ (function() { // webpackBootstrap
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ "use strict";
|
|
|
|
/******/ // The require scope
|
|
|
|
/******/ var __webpack_require__ = {};
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ /* webpack/runtime/define property getters */
|
2023-09-21 15:26:32 +02:00
|
|
|
/******/ !function() {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ // define getter functions for harmony exports
|
2023-09-21 15:26:32 +02:00
|
|
|
/******/ __webpack_require__.d = function(exports, definition) {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ for(var key in definition) {
|
|
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
|
|
/******/ }
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
2023-09-21 15:26:32 +02:00
|
|
|
/******/ }();
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
2023-09-21 15:26:32 +02:00
|
|
|
/******/ !function() {
|
|
|
|
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
|
|
/******/ }();
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/make namespace object */
|
2023-09-21 15:26:32 +02:00
|
|
|
/******/ !function() {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ // define __esModule on exports
|
2023-09-21 15:26:32 +02:00
|
|
|
/******/ __webpack_require__.r = function(exports) {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
/******/ }
|
|
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
2020-01-22 23:06:21 +01:00
|
|
|
/******/ };
|
2023-09-21 15:26:32 +02:00
|
|
|
/******/ }();
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/
|
2020-01-22 23:06:21 +01:00
|
|
|
/************************************************************************/
|
2022-04-11 14:04:30 +02:00
|
|
|
var __webpack_exports__ = {};
|
2021-05-20 14:20:04 +02:00
|
|
|
// ESM COMPAT FLAG
|
|
|
|
__webpack_require__.r(__webpack_exports__);
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
// EXPORTS
|
2022-04-11 14:04:30 +02:00
|
|
|
__webpack_require__.d(__webpack_exports__, {
|
2023-09-21 15:26:32 +02:00
|
|
|
ShortcutProvider: function() { return /* reexport */ ShortcutProvider; },
|
|
|
|
__unstableUseShortcutEventMatch: function() { return /* reexport */ useShortcutEventMatch; },
|
|
|
|
store: function() { return /* reexport */ store; },
|
|
|
|
useShortcut: function() { return /* reexport */ useShortcut; }
|
2022-04-11 14:04:30 +02:00
|
|
|
});
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
// NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
|
|
|
|
var actions_namespaceObject = {};
|
|
|
|
__webpack_require__.r(actions_namespaceObject);
|
2022-04-11 14:04:30 +02:00
|
|
|
__webpack_require__.d(actions_namespaceObject, {
|
2023-09-21 15:26:32 +02:00
|
|
|
registerShortcut: function() { return registerShortcut; },
|
|
|
|
unregisterShortcut: function() { return unregisterShortcut; }
|
2022-04-11 14:04:30 +02:00
|
|
|
});
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
// NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
|
|
|
|
var selectors_namespaceObject = {};
|
|
|
|
__webpack_require__.r(selectors_namespaceObject);
|
2022-04-11 14:04:30 +02:00
|
|
|
__webpack_require__.d(selectors_namespaceObject, {
|
2023-09-21 15:26:32 +02:00
|
|
|
getAllShortcutKeyCombinations: function() { return getAllShortcutKeyCombinations; },
|
|
|
|
getAllShortcutRawKeyCombinations: function() { return getAllShortcutRawKeyCombinations; },
|
|
|
|
getCategoryShortcuts: function() { return getCategoryShortcuts; },
|
|
|
|
getShortcutAliases: function() { return getShortcutAliases; },
|
|
|
|
getShortcutDescription: function() { return getShortcutDescription; },
|
|
|
|
getShortcutKeyCombination: function() { return getShortcutKeyCombination; },
|
|
|
|
getShortcutRepresentation: function() { return getShortcutRepresentation; }
|
2022-04-11 14:04:30 +02:00
|
|
|
});
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","data"]
|
2023-09-21 15:26:32 +02:00
|
|
|
var external_wp_data_namespaceObject = window["wp"]["data"];
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/reducer.js
|
2020-01-22 23:06:21 +01:00
|
|
|
/**
|
2021-05-20 14:20:04 +02:00
|
|
|
* Reducer returning the registered shortcuts
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-05-20 14:20:04 +02:00
|
|
|
* @param {Object} state Current state.
|
|
|
|
* @param {Object} action Dispatched action.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-05-20 14:20:04 +02:00
|
|
|
* @return {Object} Updated state.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2023-06-27 16:24:19 +02:00
|
|
|
function reducer(state = {}, action) {
|
2021-05-20 14:20:04 +02:00
|
|
|
switch (action.type) {
|
|
|
|
case 'REGISTER_SHORTCUT':
|
2023-09-26 16:23:26 +02:00
|
|
|
return {
|
|
|
|
...state,
|
2021-05-20 14:20:04 +02:00
|
|
|
[action.name]: {
|
|
|
|
category: action.category,
|
|
|
|
keyCombination: action.keyCombination,
|
|
|
|
aliases: action.aliases,
|
|
|
|
description: action.description
|
|
|
|
}
|
|
|
|
};
|
|
|
|
case 'UNREGISTER_SHORTCUT':
|
2022-09-20 17:43:29 +02:00
|
|
|
const {
|
|
|
|
[action.name]: actionName,
|
|
|
|
...remainingState
|
|
|
|
} = state;
|
|
|
|
return remainingState;
|
2021-05-20 14:20:04 +02:00
|
|
|
}
|
|
|
|
return state;
|
2020-01-22 23:06:21 +01:00
|
|
|
}
|
2023-09-21 15:26:32 +02:00
|
|
|
/* harmony default export */ var store_reducer = (reducer);
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
|
2021-05-20 14:20:04 +02:00
|
|
|
/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */
|
|
|
|
|
2020-01-22 23:06:21 +01:00
|
|
|
/**
|
2021-05-20 14:20:04 +02:00
|
|
|
* Keyboard key combination.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-05-20 14:20:04 +02:00
|
|
|
* @typedef {Object} WPShortcutKeyCombination
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-05-20 14:20:04 +02:00
|
|
|
* @property {string} character Character.
|
|
|
|
* @property {WPKeycodeModifier|undefined} modifier Modifier.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-05-20 14:20:04 +02:00
|
|
|
* Configuration of a registered keyboard shortcut.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-05-20 14:20:04 +02:00
|
|
|
* @typedef {Object} WPShortcutConfig
|
|
|
|
*
|
|
|
|
* @property {string} name Shortcut name.
|
|
|
|
* @property {string} category Shortcut category.
|
|
|
|
* @property {string} description Shortcut description.
|
|
|
|
* @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.
|
|
|
|
* @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-05-20 14:20:04 +02:00
|
|
|
* Returns an action object used to register a new keyboard shortcut.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-05-20 14:20:04 +02:00
|
|
|
* @param {WPShortcutConfig} config Shortcut config.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
|
* import { useEffect } from '@wordpress/element';
|
|
|
|
* import { __ } from '@wordpress/i18n';
|
|
|
|
*
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const { registerShortcut } = useDispatch( keyboardShortcutsStore );
|
|
|
|
*
|
|
|
|
* useEffect( () => {
|
|
|
|
* registerShortcut( {
|
|
|
|
* name: 'custom/my-custom-shortcut',
|
|
|
|
* category: 'my-category',
|
|
|
|
* description: __( 'My custom shortcut' ),
|
|
|
|
* keyCombination: {
|
|
|
|
* modifier: 'primary',
|
|
|
|
* character: 'j',
|
|
|
|
* },
|
|
|
|
* } );
|
|
|
|
* }, [] );
|
|
|
|
*
|
|
|
|
* const shortcut = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
|
|
* 'custom/my-custom-shortcut'
|
|
|
|
* ),
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return shortcut ? (
|
|
|
|
* <p>{ __( 'Shortcut is registered.' ) }</p>
|
|
|
|
* ) : (
|
|
|
|
* <p>{ __( 'Shortcut is not registered.' ) }</p>
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
2021-05-20 14:20:04 +02:00
|
|
|
* @return {Object} action.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2023-06-27 16:24:19 +02:00
|
|
|
function registerShortcut({
|
|
|
|
name,
|
|
|
|
category,
|
|
|
|
description,
|
|
|
|
keyCombination,
|
|
|
|
aliases
|
|
|
|
}) {
|
2021-05-20 14:20:04 +02:00
|
|
|
return {
|
|
|
|
type: 'REGISTER_SHORTCUT',
|
|
|
|
name,
|
|
|
|
category,
|
|
|
|
keyCombination,
|
|
|
|
aliases,
|
|
|
|
description
|
|
|
|
};
|
2020-01-22 23:06:21 +01:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-01-22 23:06:21 +01:00
|
|
|
/**
|
2021-05-20 14:20:04 +02:00
|
|
|
* Returns an action object used to unregister a keyboard shortcut.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-05-20 14:20:04 +02:00
|
|
|
* @param {string} name Shortcut name.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
|
* import { useEffect } from '@wordpress/element';
|
|
|
|
* import { __ } from '@wordpress/i18n';
|
|
|
|
*
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
|
|
|
|
*
|
|
|
|
* useEffect( () => {
|
|
|
|
* unregisterShortcut( 'core/edit-post/next-region' );
|
|
|
|
* }, [] );
|
|
|
|
*
|
|
|
|
* const shortcut = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
|
|
* 'core/edit-post/next-region'
|
|
|
|
* ),
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return shortcut ? (
|
|
|
|
* <p>{ __( 'Shortcut is not unregistered.' ) }</p>
|
|
|
|
* ) : (
|
|
|
|
* <p>{ __( 'Shortcut is unregistered.' ) }</p>
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
2021-05-20 14:20:04 +02:00
|
|
|
* @return {Object} action.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
function unregisterShortcut(name) {
|
|
|
|
return {
|
|
|
|
type: 'UNREGISTER_SHORTCUT',
|
|
|
|
name
|
|
|
|
};
|
|
|
|
}
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/rememo/rememo.js
|
|
|
|
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
/** @typedef {(...args: any[]) => *[]} GetDependants */
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
/** @typedef {() => void} Clear */
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/**
|
2022-09-20 17:43:29 +02:00
|
|
|
* @typedef {{
|
|
|
|
* getDependants: GetDependants,
|
|
|
|
* clear: Clear
|
|
|
|
* }} EnhancedSelector
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal cache entry.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @typedef CacheNode
|
|
|
|
*
|
|
|
|
* @property {?CacheNode|undefined} [prev] Previous node.
|
|
|
|
* @property {?CacheNode|undefined} [next] Next node.
|
|
|
|
* @property {*[]} args Function arguments for cache entry.
|
|
|
|
* @property {*} val Function result.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef Cache
|
|
|
|
*
|
|
|
|
* @property {Clear} clear Function to clear cache.
|
|
|
|
* @property {boolean} [isUniqueByDependants] Whether dependants are valid in
|
|
|
|
* considering cache uniqueness. A cache is unique if dependents are all arrays
|
|
|
|
* or objects.
|
|
|
|
* @property {CacheNode?} [head] Cache head.
|
|
|
|
* @property {*[]} [lastDependants] Dependants from previous invocation.
|
2021-05-20 14:20:04 +02:00
|
|
|
*/
|
2020-01-22 23:06:21 +01:00
|
|
|
|
|
|
|
/**
|
2022-09-20 17:43:29 +02:00
|
|
|
* Arbitrary value used as key for referencing cache object in WeakMap tree.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @type {{}}
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2022-09-20 17:43:29 +02:00
|
|
|
var LEAF_KEY = {};
|
2020-01-22 23:06:21 +01:00
|
|
|
|
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns the first argument as the sole entry in an array.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @template T
|
|
|
|
*
|
|
|
|
* @param {T} value Value to return.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @return {[T]} Value returned as entry in array.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2022-09-20 17:43:29 +02:00
|
|
|
function arrayOf(value) {
|
|
|
|
return [value];
|
2020-01-22 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns true if the value passed is object-like, or false otherwise. A value
|
|
|
|
* is object-like if it can support property assignment, e.g. object or array.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @param {*} value Value to test.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {boolean} Whether value is object-like.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2022-09-20 17:43:29 +02:00
|
|
|
function isObjectLike(value) {
|
|
|
|
return !!value && 'object' === typeof value;
|
2020-01-22 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Creates and returns a new cache object.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @return {Cache} Cache object.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
function createCache() {
|
2022-09-20 17:43:29 +02:00
|
|
|
/** @type {Cache} */
|
2022-04-11 14:04:30 +02:00
|
|
|
var cache = {
|
2022-09-20 17:43:29 +02:00
|
|
|
clear: function () {
|
2022-04-11 14:04:30 +02:00
|
|
|
cache.head = null;
|
|
|
|
},
|
|
|
|
};
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
return cache;
|
2020-01-22 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2020-02-10 23:33:27 +01:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns true if entries within the two arrays are strictly equal by
|
|
|
|
* reference from a starting index.
|
2020-02-10 23:33:27 +01:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @param {*[]} a First array.
|
|
|
|
* @param {*[]} b Second array.
|
2022-04-11 14:04:30 +02:00
|
|
|
* @param {number} fromIndex Index from which to start comparison.
|
2020-02-10 23:33:27 +01:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {boolean} Whether arrays are shallowly equal.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2022-09-20 17:43:29 +02:00
|
|
|
function isShallowEqual(a, b, fromIndex) {
|
2022-04-11 14:04:30 +02:00
|
|
|
var i;
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
if (a.length !== b.length) {
|
2022-04-11 14:04:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
for (i = fromIndex; i < a.length; i++) {
|
|
|
|
if (a[i] !== b[i]) {
|
2022-04-11 14:04:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2021-01-28 03:04:13 +01:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns a memoized selector function. The getDependants function argument is
|
|
|
|
* called before the memoized selector and is expected to return an immutable
|
|
|
|
* reference or array of references on which the selector depends for computing
|
|
|
|
* its own return value. The memoize cache is preserved only as long as those
|
|
|
|
* dependant references remain the same. If getDependants returns a different
|
|
|
|
* reference(s), the cache is cleared and the selector value regenerated.
|
2021-01-28 03:04:13 +01:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @template {(...args: *[]) => *} S
|
2021-01-28 03:04:13 +01:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @param {S} selector Selector function.
|
|
|
|
* @param {GetDependants=} getDependants Dependant getter returning an array of
|
|
|
|
* references used in cache bust consideration.
|
2021-01-28 03:04:13 +01:00
|
|
|
*/
|
2022-09-20 17:43:29 +02:00
|
|
|
/* harmony default export */ function rememo(selector, getDependants) {
|
|
|
|
/** @type {WeakMap<*,*>} */
|
|
|
|
var rootCache;
|
2021-01-28 03:04:13 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
/** @type {GetDependants} */
|
|
|
|
var normalizedGetDependants = getDependants ? getDependants : arrayOf;
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Returns the cache for a given dependants array. When possible, a WeakMap
|
|
|
|
* will be used to create a unique cache for each set of dependants. This
|
|
|
|
* is feasible due to the nature of WeakMap in allowing garbage collection
|
|
|
|
* to occur on entries where the key object is no longer referenced. Since
|
|
|
|
* WeakMap requires the key to be an object, this is only possible when the
|
|
|
|
* dependant is object-like. The root cache is created as a hierarchy where
|
|
|
|
* each top-level key is the first entry in a dependants set, the value a
|
|
|
|
* WeakMap where each key is the next dependant, and so on. This continues
|
|
|
|
* so long as the dependants are object-like. If no dependants are object-
|
|
|
|
* like, then the cache is shared across all invocations.
|
|
|
|
*
|
|
|
|
* @see isObjectLike
|
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @param {*[]} dependants Selector dependants.
|
2022-04-11 14:04:30 +02:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @return {Cache} Cache object.
|
2022-04-11 14:04:30 +02:00
|
|
|
*/
|
2022-09-20 17:43:29 +02:00
|
|
|
function getCache(dependants) {
|
2022-04-11 14:04:30 +02:00
|
|
|
var caches = rootCache,
|
|
|
|
isUniqueByDependants = true,
|
2022-09-20 17:43:29 +02:00
|
|
|
i,
|
|
|
|
dependant,
|
|
|
|
map,
|
|
|
|
cache;
|
2021-07-15 20:55:29 +02:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
for (i = 0; i < dependants.length; i++) {
|
|
|
|
dependant = dependants[i];
|
2021-07-15 20:55:29 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Can only compose WeakMap from object-like key.
|
2022-09-20 17:43:29 +02:00
|
|
|
if (!isObjectLike(dependant)) {
|
2022-04-11 14:04:30 +02:00
|
|
|
isUniqueByDependants = false;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-15 20:55:29 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Does current segment of cache already have a WeakMap?
|
2022-09-20 17:43:29 +02:00
|
|
|
if (caches.has(dependant)) {
|
2022-04-11 14:04:30 +02:00
|
|
|
// Traverse into nested WeakMap.
|
2022-09-20 17:43:29 +02:00
|
|
|
caches = caches.get(dependant);
|
2022-04-11 14:04:30 +02:00
|
|
|
} else {
|
|
|
|
// Create, set, and traverse into a new one.
|
|
|
|
map = new WeakMap();
|
2022-09-20 17:43:29 +02:00
|
|
|
caches.set(dependant, map);
|
2022-04-11 14:04:30 +02:00
|
|
|
caches = map;
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 20:55:29 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// We use an arbitrary (but consistent) object as key for the last item
|
|
|
|
// in the WeakMap to serve as our running cache.
|
2022-09-20 17:43:29 +02:00
|
|
|
if (!caches.has(LEAF_KEY)) {
|
2022-04-11 14:04:30 +02:00
|
|
|
cache = createCache();
|
|
|
|
cache.isUniqueByDependants = isUniqueByDependants;
|
2022-09-20 17:43:29 +02:00
|
|
|
caches.set(LEAF_KEY, cache);
|
2022-04-11 14:04:30 +02:00
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
return caches.get(LEAF_KEY);
|
2022-04-11 14:04:30 +02:00
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Resets root memoization cache.
|
|
|
|
*/
|
|
|
|
function clear() {
|
2022-09-20 17:43:29 +02:00
|
|
|
rootCache = new WeakMap();
|
2022-04-11 14:04:30 +02:00
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
/* eslint-disable jsdoc/check-param-names */
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* The augmented selector call, considering first whether dependants have
|
|
|
|
* changed before passing it to underlying memoize function.
|
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @param {*} source Source object for derivation.
|
|
|
|
* @param {...*} extraArgs Additional arguments to pass to selector.
|
2022-04-11 14:04:30 +02:00
|
|
|
*
|
|
|
|
* @return {*} Selector result.
|
|
|
|
*/
|
2022-09-20 17:43:29 +02:00
|
|
|
/* eslint-enable jsdoc/check-param-names */
|
|
|
|
function callSelector(/* source, ...extraArgs */) {
|
2022-04-11 14:04:30 +02:00
|
|
|
var len = arguments.length,
|
2022-09-20 17:43:29 +02:00
|
|
|
cache,
|
|
|
|
node,
|
|
|
|
i,
|
|
|
|
args,
|
|
|
|
dependants;
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Create copy of arguments (avoid leaking deoptimization).
|
2022-09-20 17:43:29 +02:00
|
|
|
args = new Array(len);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
args[i] = arguments[i];
|
2022-04-11 14:04:30 +02:00
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
dependants = normalizedGetDependants.apply(null, args);
|
|
|
|
cache = getCache(dependants);
|
|
|
|
|
|
|
|
// If not guaranteed uniqueness by dependants (primitive type), shallow
|
|
|
|
// compare against last dependants and, if references have changed,
|
|
|
|
// destroy cache to recalculate result.
|
|
|
|
if (!cache.isUniqueByDependants) {
|
|
|
|
if (
|
|
|
|
cache.lastDependants &&
|
|
|
|
!isShallowEqual(dependants, cache.lastDependants, 0)
|
|
|
|
) {
|
2022-04-11 14:04:30 +02:00
|
|
|
cache.clear();
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
cache.lastDependants = dependants;
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
node = cache.head;
|
2022-09-20 17:43:29 +02:00
|
|
|
while (node) {
|
2022-04-11 14:04:30 +02:00
|
|
|
// Check whether node arguments match arguments
|
2022-09-20 17:43:29 +02:00
|
|
|
if (!isShallowEqual(node.args, args, 1)) {
|
2022-04-11 14:04:30 +02:00
|
|
|
node = node.next;
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// At this point we can assume we've found a match
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Surface matched node to head if not already
|
2022-09-20 17:43:29 +02:00
|
|
|
if (node !== cache.head) {
|
2022-04-11 14:04:30 +02:00
|
|
|
// Adjust siblings to point to each other.
|
2022-09-20 17:43:29 +02:00
|
|
|
/** @type {CacheNode} */ (node.prev).next = node.next;
|
|
|
|
if (node.next) {
|
2022-04-11 14:04:30 +02:00
|
|
|
node.next.prev = node.prev;
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
node.next = cache.head;
|
|
|
|
node.prev = null;
|
2022-09-20 17:43:29 +02:00
|
|
|
/** @type {CacheNode} */ (cache.head).prev = node;
|
2022-04-11 14:04:30 +02:00
|
|
|
cache.head = node;
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Return immediately
|
|
|
|
return node.val;
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// No cached value found. Continue to insertion phase:
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
node = /** @type {CacheNode} */ ({
|
2022-04-11 14:04:30 +02:00
|
|
|
// Generate the result from original function
|
2022-09-20 17:43:29 +02:00
|
|
|
val: selector.apply(null, args),
|
|
|
|
});
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Avoid including the source object in the cache.
|
2022-09-20 17:43:29 +02:00
|
|
|
args[0] = null;
|
2022-04-11 14:04:30 +02:00
|
|
|
node.args = args;
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Don't need to check whether node is already head, since it would
|
|
|
|
// have been returned above already if it was
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// Shift existing head down list
|
2022-09-20 17:43:29 +02:00
|
|
|
if (cache.head) {
|
2022-04-11 14:04:30 +02:00
|
|
|
cache.head.prev = node;
|
|
|
|
node.next = cache.head;
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
cache.head = node;
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
return node.val;
|
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
callSelector.getDependants = normalizedGetDependants;
|
2022-04-11 14:04:30 +02:00
|
|
|
callSelector.clear = clear;
|
|
|
|
clear();
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
return /** @type {S & EnhancedSelector} */ (callSelector);
|
2021-11-08 15:29:21 +01:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","keycodes"]
|
2023-09-21 15:26:32 +02:00
|
|
|
var external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */
|
2021-05-20 14:20:04 +02:00
|
|
|
|
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Shared reference to an empty array for cases where it is important to avoid
|
|
|
|
* returning a new array reference on every invocation.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @type {Array<any>}
|
2021-05-20 14:20:04 +02:00
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
const EMPTY_ARRAY = [];
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Shortcut formatting methods.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @property {WPKeycodeHandlerByModifier} display Display formatting.
|
|
|
|
* @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.
|
|
|
|
* @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.
|
2021-05-20 14:20:04 +02:00
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
const FORMATTING_METHODS = {
|
|
|
|
display: external_wp_keycodes_namespaceObject.displayShortcut,
|
|
|
|
raw: external_wp_keycodes_namespaceObject.rawShortcut,
|
|
|
|
ariaLabel: external_wp_keycodes_namespaceObject.shortcutAriaLabel
|
|
|
|
};
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns a string representing the key combination.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @param {?WPShortcutKeyCombination} shortcut Key combination.
|
|
|
|
* @param {keyof FORMATTING_METHODS} representation Type of representation
|
|
|
|
* (display, raw, ariaLabel).
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {string?} Shortcut representation.
|
2021-05-20 14:20:04 +02:00
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
function getKeyCombinationRepresentation(shortcut, representation) {
|
|
|
|
if (!shortcut) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return shortcut.modifier ? FORMATTING_METHODS[representation][shortcut.modifier](shortcut.character) : shortcut.character;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns the main key combination for a given shortcut name.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @param {Object} state Global state.
|
|
|
|
* @param {string} name Shortcut name.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect } from '@wordpress/data';
|
|
|
|
* import { createInterpolateElement } from '@wordpress/element';
|
|
|
|
* import { sprintf } from '@wordpress/i18n';
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const {character, modifier} = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
|
|
* 'core/edit-post/next-region'
|
|
|
|
* ),
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return (
|
|
|
|
* <div>
|
|
|
|
* { createInterpolateElement(
|
|
|
|
* sprintf(
|
|
|
|
* 'Character: <code>%s</code> / Modifier: <code>%s</code>',
|
|
|
|
* character,
|
|
|
|
* modifier
|
|
|
|
* ),
|
|
|
|
* {
|
|
|
|
* code: <code />,
|
|
|
|
* }
|
|
|
|
* ) }
|
|
|
|
* </div>
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {WPShortcutKeyCombination?} Key combination.
|
2021-05-20 14:20:04 +02:00
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
function getShortcutKeyCombination(state, name) {
|
|
|
|
return state[name] ? state[name].keyCombination : null;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns a string representing the main key combination for a given shortcut name.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @param {Object} state Global state.
|
|
|
|
* @param {string} name Shortcut name.
|
|
|
|
* @param {keyof FORMATTING_METHODS} representation Type of representation
|
|
|
|
* (display, raw, ariaLabel).
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect } from '@wordpress/data';
|
|
|
|
* import { sprintf } from '@wordpress/i18n';
|
|
|
|
*
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const {display, raw, ariaLabel} = useSelect(
|
|
|
|
* ( select ) =>{
|
|
|
|
* return {
|
|
|
|
* display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region' ),
|
|
|
|
* raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ),
|
|
|
|
* ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region', 'ariaLabel')
|
|
|
|
* }
|
|
|
|
* },
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return (
|
|
|
|
* <ul>
|
|
|
|
* <li>{ sprintf( 'display string: %s', display ) }</li>
|
|
|
|
* <li>{ sprintf( 'raw string: %s', raw ) }</li>
|
|
|
|
* <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>
|
|
|
|
* </ul>
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
2022-04-11 14:04:30 +02:00
|
|
|
*
|
|
|
|
* @return {string?} Shortcut representation.
|
|
|
|
*/
|
2023-06-27 16:24:19 +02:00
|
|
|
function getShortcutRepresentation(state, name, representation = 'display') {
|
2022-04-11 14:04:30 +02:00
|
|
|
const shortcut = getShortcutKeyCombination(state, name);
|
|
|
|
return getKeyCombinationRepresentation(shortcut, representation);
|
2021-05-20 14:20:04 +02:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns the shortcut description given its name.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @param {Object} state Global state.
|
|
|
|
* @param {string} name Shortcut name.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect } from '@wordpress/data';
|
|
|
|
* import { __ } from '@wordpress/i18n';
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const shortcutDescription = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getShortcutDescription( 'core/edit-post/next-region' ),
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return shortcutDescription ? (
|
|
|
|
* <div>{ shortcutDescription }</div>
|
|
|
|
* ) : (
|
|
|
|
* <div>{ __( 'No description.' ) }</div>
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {string?} Shortcut description.
|
2021-05-20 14:20:04 +02:00
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
function getShortcutDescription(state, name) {
|
|
|
|
return state[name] ? state[name].description : null;
|
2021-05-20 14:20:04 +02:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/**
|
2022-04-11 14:04:30 +02:00
|
|
|
* Returns the aliases for a given shortcut name.
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @param {Object} state Global state.
|
|
|
|
* @param {string} name Shortcut name.
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect } from '@wordpress/data';
|
|
|
|
* import { createInterpolateElement } from '@wordpress/element';
|
|
|
|
* import { sprintf } from '@wordpress/i18n';
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const shortcutAliases = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getShortcutAliases(
|
|
|
|
* 'core/edit-post/next-region'
|
|
|
|
* ),
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return (
|
|
|
|
* shortcutAliases.length > 0 && (
|
|
|
|
* <ul>
|
|
|
|
* { shortcutAliases.map( ( { character, modifier }, index ) => (
|
|
|
|
* <li key={ index }>
|
|
|
|
* { createInterpolateElement(
|
|
|
|
* sprintf(
|
|
|
|
* 'Character: <code>%s</code> / Modifier: <code>%s</code>',
|
|
|
|
* character,
|
|
|
|
* modifier
|
|
|
|
* ),
|
|
|
|
* {
|
|
|
|
* code: <code />,
|
|
|
|
* }
|
|
|
|
* ) }
|
|
|
|
* </li>
|
|
|
|
* ) ) }
|
|
|
|
* </ul>
|
|
|
|
* )
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
2021-05-20 14:20:04 +02:00
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {WPShortcutKeyCombination[]} Key combinations.
|
2021-05-20 14:20:04 +02:00
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
function getShortcutAliases(state, name) {
|
|
|
|
return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the shortcuts that include aliases for a given shortcut name.
|
|
|
|
*
|
|
|
|
* @param {Object} state Global state.
|
|
|
|
* @param {string} name Shortcut name.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect } from '@wordpress/data';
|
|
|
|
* import { createInterpolateElement } from '@wordpress/element';
|
|
|
|
* import { sprintf } from '@wordpress/i18n';
|
|
|
|
*
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const allShortcutKeyCombinations = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
|
|
|
|
* 'core/edit-post/next-region'
|
|
|
|
* ),
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return (
|
|
|
|
* allShortcutKeyCombinations.length > 0 && (
|
|
|
|
* <ul>
|
|
|
|
* { allShortcutKeyCombinations.map(
|
|
|
|
* ( { character, modifier }, index ) => (
|
|
|
|
* <li key={ index }>
|
|
|
|
* { createInterpolateElement(
|
|
|
|
* sprintf(
|
|
|
|
* 'Character: <code>%s</code> / Modifier: <code>%s</code>',
|
|
|
|
* character,
|
|
|
|
* modifier
|
|
|
|
* ),
|
|
|
|
* {
|
|
|
|
* code: <code />,
|
|
|
|
* }
|
|
|
|
* ) }
|
|
|
|
* </li>
|
|
|
|
* )
|
|
|
|
* ) }
|
|
|
|
* </ul>
|
|
|
|
* )
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
|
|
|
*
|
|
|
|
* @return {WPShortcutKeyCombination[]} Key combinations.
|
|
|
|
*/
|
2022-04-11 14:04:30 +02:00
|
|
|
const getAllShortcutKeyCombinations = rememo((state, name) => {
|
2022-09-20 17:43:29 +02:00
|
|
|
return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean);
|
2022-04-11 14:04:30 +02:00
|
|
|
}, (state, name) => [state[name]]);
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Returns the raw representation of all the keyboard combinations of a given shortcut name.
|
|
|
|
*
|
|
|
|
* @param {Object} state Global state.
|
|
|
|
* @param {string} name Shortcut name.
|
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect } from '@wordpress/data';
|
|
|
|
* import { createInterpolateElement } from '@wordpress/element';
|
|
|
|
* import { sprintf } from '@wordpress/i18n';
|
|
|
|
*
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const allShortcutRawKeyCombinations = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
|
|
|
|
* 'core/edit-post/next-region'
|
|
|
|
* ),
|
|
|
|
* []
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* return (
|
|
|
|
* allShortcutRawKeyCombinations.length > 0 && (
|
|
|
|
* <ul>
|
|
|
|
* { allShortcutRawKeyCombinations.map(
|
|
|
|
* ( shortcutRawKeyCombination, index ) => (
|
|
|
|
* <li key={ index }>
|
|
|
|
* { createInterpolateElement(
|
|
|
|
* sprintf(
|
|
|
|
* ' <code>%s</code>',
|
|
|
|
* shortcutRawKeyCombination
|
|
|
|
* ),
|
|
|
|
* {
|
|
|
|
* code: <code />,
|
|
|
|
* }
|
|
|
|
* ) }
|
|
|
|
* </li>
|
|
|
|
* )
|
|
|
|
* ) }
|
|
|
|
* </ul>
|
|
|
|
* )
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
|
|
|
*
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {string[]} Shortcuts.
|
|
|
|
*/
|
|
|
|
const getAllShortcutRawKeyCombinations = rememo((state, name) => {
|
|
|
|
return getAllShortcutKeyCombinations(state, name).map(combination => getKeyCombinationRepresentation(combination, 'raw'));
|
|
|
|
}, (state, name) => [state[name]]);
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Returns the shortcut names list for a given category name.
|
|
|
|
*
|
|
|
|
* @param {Object} state Global state.
|
|
|
|
* @param {string} name Category name.
|
2023-09-26 16:23:26 +02:00
|
|
|
* @example
|
|
|
|
*
|
|
|
|
*```js
|
|
|
|
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
|
|
* import { useSelect } from '@wordpress/data';
|
|
|
|
*
|
|
|
|
* const ExampleComponent = () => {
|
|
|
|
* const categoryShortcuts = useSelect(
|
|
|
|
* ( select ) =>
|
|
|
|
* select( keyboardShortcutsStore ).getCategoryShortcuts(
|
|
|
|
* 'block'
|
|
|
|
* ),
|
|
|
|
* []
|
|
|
|
* );
|
2022-04-11 14:04:30 +02:00
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* return (
|
|
|
|
* categoryShortcuts.length > 0 && (
|
|
|
|
* <ul>
|
|
|
|
* { categoryShortcuts.map( ( categoryShortcut ) => (
|
|
|
|
* <li key={ categoryShortcut }>{ categoryShortcut }</li>
|
|
|
|
* ) ) }
|
|
|
|
* </ul>
|
|
|
|
* )
|
|
|
|
* );
|
|
|
|
* };
|
|
|
|
*```
|
2022-04-11 14:04:30 +02:00
|
|
|
* @return {string[]} Shortcut names.
|
|
|
|
*/
|
|
|
|
const getCategoryShortcuts = rememo((state, categoryName) => {
|
2023-06-27 16:24:19 +02:00
|
|
|
return Object.entries(state).filter(([, shortcut]) => shortcut.category === categoryName).map(([name]) => name);
|
2022-04-11 14:04:30 +02:00
|
|
|
}, state => [state]);
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/index.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
const STORE_NAME = 'core/keyboard-shortcuts';
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Store definition for the keyboard shortcuts namespace.
|
|
|
|
*
|
|
|
|
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
|
|
|
|
reducer: store_reducer,
|
|
|
|
actions: actions_namespaceObject,
|
|
|
|
selectors: selectors_namespaceObject
|
|
|
|
});
|
|
|
|
(0,external_wp_data_namespaceObject.register)(store);
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","element"]
|
2023-09-21 15:26:32 +02:00
|
|
|
var external_wp_element_namespaceObject = window["wp"]["element"];
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut-event-match.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Returns a function to check if a keyboard event matches a shortcut name.
|
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @return {Function} A function to check if a keyboard event matches a
|
2022-04-11 14:04:30 +02:00
|
|
|
* predefined shortcut combination.
|
|
|
|
*/
|
|
|
|
function useShortcutEventMatch() {
|
|
|
|
const {
|
|
|
|
getAllShortcutKeyCombinations
|
|
|
|
} = (0,external_wp_data_namespaceObject.useSelect)(store);
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* A function to check if a keyboard event matches a predefined shortcut
|
|
|
|
* combination.
|
|
|
|
*
|
|
|
|
* @param {string} name Shortcut name.
|
|
|
|
* @param {KeyboardEvent} event Event to check.
|
|
|
|
*
|
|
|
|
* @return {boolean} True if the event matches any shortcuts, false if not.
|
|
|
|
*/
|
|
|
|
function isMatch(name, event) {
|
2023-06-27 16:24:19 +02:00
|
|
|
return getAllShortcutKeyCombinations(name).some(({
|
|
|
|
modifier,
|
|
|
|
character
|
|
|
|
}) => {
|
2022-04-11 14:04:30 +02:00
|
|
|
return external_wp_keycodes_namespaceObject.isKeyboardEvent[modifier](event, character);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return isMatch;
|
|
|
|
}
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/context.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
const globalShortcuts = new Set();
|
|
|
|
const globalListener = event => {
|
|
|
|
for (const keyboardShortcut of globalShortcuts) {
|
|
|
|
keyboardShortcut(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const context = (0,external_wp_element_namespaceObject.createContext)({
|
|
|
|
add: shortcut => {
|
|
|
|
if (globalShortcuts.size === 0) {
|
|
|
|
document.addEventListener('keydown', globalListener);
|
|
|
|
}
|
|
|
|
globalShortcuts.add(shortcut);
|
|
|
|
},
|
|
|
|
delete: shortcut => {
|
|
|
|
globalShortcuts.delete(shortcut);
|
|
|
|
if (globalShortcuts.size === 0) {
|
|
|
|
document.removeEventListener('keydown', globalListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-05-20 14:20:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Attach a keyboard shortcut handler.
|
|
|
|
*
|
|
|
|
* @param {string} name Shortcut name.
|
|
|
|
* @param {Function} callback Shortcut callback.
|
|
|
|
* @param {Object} options Shortcut options.
|
|
|
|
* @param {boolean} options.isDisabled Whether to disable to shortut.
|
|
|
|
*/
|
2023-06-27 16:24:19 +02:00
|
|
|
function useShortcut(name, callback, {
|
2023-09-26 16:23:26 +02:00
|
|
|
isDisabled = false
|
2023-06-27 16:24:19 +02:00
|
|
|
} = {}) {
|
2022-04-11 14:04:30 +02:00
|
|
|
const shortcuts = (0,external_wp_element_namespaceObject.useContext)(context);
|
|
|
|
const isMatch = useShortcutEventMatch();
|
|
|
|
const callbackRef = (0,external_wp_element_namespaceObject.useRef)();
|
2023-09-26 16:23:26 +02:00
|
|
|
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
|
|
callbackRef.current = callback;
|
|
|
|
}, [callback]);
|
2022-04-11 14:04:30 +02:00
|
|
|
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
|
|
if (isDisabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
function _callback(event) {
|
|
|
|
if (isMatch(name, event)) {
|
|
|
|
callbackRef.current(event);
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
shortcuts.add(_callback);
|
2022-04-11 14:04:30 +02:00
|
|
|
return () => {
|
2023-09-26 16:23:26 +02:00
|
|
|
shortcuts.delete(_callback);
|
2022-04-11 14:04:30 +02:00
|
|
|
};
|
2023-09-26 16:23:26 +02:00
|
|
|
}, [name, isDisabled, shortcuts]);
|
2022-04-11 14:04:30 +02:00
|
|
|
}
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/components/shortcut-provider.js
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
const {
|
|
|
|
Provider
|
|
|
|
} = context;
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/**
|
|
|
|
* Handles callbacks added to context by `useShortcut`.
|
2023-09-26 16:23:26 +02:00
|
|
|
* Adding a provider allows to register contextual shortcuts
|
|
|
|
* that are only active when a certain part of the UI is focused.
|
2022-04-11 14:04:30 +02:00
|
|
|
*
|
|
|
|
* @param {Object} props Props to pass to `div`.
|
|
|
|
*
|
|
|
|
* @return {import('@wordpress/element').WPElement} Component.
|
|
|
|
*/
|
|
|
|
function ShortcutProvider(props) {
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 20:58:22 +02:00
|
|
|
const [keyboardShortcuts] = (0,external_wp_element_namespaceObject.useState)(() => new Set());
|
2022-04-11 14:04:30 +02:00
|
|
|
function onKeyDown(event) {
|
|
|
|
if (props.onKeyDown) props.onKeyDown(event);
|
Update npm packages to latest.
The npm packages needed a further update for beta 2 in preparation for 6.4.
Props @mmaattiiaass , @wildworks , @aaronrobertshaw, @bartkalisz, @mamaduka, @artemiosans, @youknowriad, @czapla, @richtabor, @glendaviesnz, @pbking, @cbravobernal, @madhudollu, @kevin940726, @adamsilverstein, @get_dave, @ntsekouras, @ramonopoly, @jffng, @swissspidy, @carlosgprim, @siobhyb, @mikachan.
See #59411.
Built from https://develop.svn.wordpress.org/trunk@56755
git-svn-id: http://core.svn.wordpress.org/trunk@56267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-10-02 20:58:22 +02:00
|
|
|
for (const keyboardShortcut of keyboardShortcuts) {
|
2022-04-11 14:04:30 +02:00
|
|
|
keyboardShortcut(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
2022-04-11 14:04:30 +02:00
|
|
|
return (0,external_wp_element_namespaceObject.createElement)(Provider, {
|
|
|
|
value: keyboardShortcuts
|
2023-09-26 16:23:26 +02:00
|
|
|
}, (0,external_wp_element_namespaceObject.createElement)("div", {
|
|
|
|
...props,
|
2022-04-11 14:04:30 +02:00
|
|
|
onKeyDown: onKeyDown
|
2023-06-27 16:24:19 +02:00
|
|
|
}));
|
2022-04-11 14:04:30 +02:00
|
|
|
/* eslint-enable jsx-a11y/no-static-element-interactions */
|
|
|
|
}
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/index.js
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2020-01-22 23:06:21 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
(window.wp = window.wp || {}).keyboardShortcuts = __webpack_exports__;
|
|
|
|
/******/ })()
|
|
|
|
;
|