kollapsminoriteten/wp-includes/js/dist/keyboard-shortcuts.js

798 lines
24 KiB
JavaScript
Raw Normal View History

2024-04-17 11:32:24 +02:00
/******/ (() => { // webpackBootstrap
2022-06-16 14:03:35 +02:00
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define getter functions for harmony exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.d = (exports, definition) => {
2022-06-16 14:03:35 +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] });
/******/ }
/******/ }
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
2024-04-17 11:32:24 +02:00
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/make namespace object */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define __esModule on exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.r = (exports) => {
2022-06-16 14:03:35 +02:00
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
2020-05-06 17:23:38 +02:00
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
2020-05-06 17:23:38 +02:00
/************************************************************************/
2022-06-16 14:03:35 +02:00
var __webpack_exports__ = {};
2021-07-23 11:58:50 +02:00
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
// EXPORTS
2022-06-16 14:03:35 +02:00
__webpack_require__.d(__webpack_exports__, {
2024-04-17 11:32:24 +02:00
ShortcutProvider: () => (/* reexport */ ShortcutProvider),
__unstableUseShortcutEventMatch: () => (/* reexport */ useShortcutEventMatch),
store: () => (/* reexport */ store),
useShortcut: () => (/* reexport */ useShortcut)
2022-06-16 14:03:35 +02:00
});
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
var actions_namespaceObject = {};
__webpack_require__.r(actions_namespaceObject);
2022-06-16 14:03:35 +02:00
__webpack_require__.d(actions_namespaceObject, {
2024-04-17 11:32:24 +02:00
registerShortcut: () => (registerShortcut),
unregisterShortcut: () => (unregisterShortcut)
2022-06-16 14:03:35 +02:00
});
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
var selectors_namespaceObject = {};
__webpack_require__.r(selectors_namespaceObject);
2022-06-16 14:03:35 +02:00
__webpack_require__.d(selectors_namespaceObject, {
2024-04-17 11:32:24 +02:00
getAllShortcutKeyCombinations: () => (getAllShortcutKeyCombinations),
getAllShortcutRawKeyCombinations: () => (getAllShortcutRawKeyCombinations),
getCategoryShortcuts: () => (getCategoryShortcuts),
getShortcutAliases: () => (getShortcutAliases),
getShortcutDescription: () => (getShortcutDescription),
getShortcutKeyCombination: () => (getShortcutKeyCombination),
getShortcutRepresentation: () => (getShortcutRepresentation)
2022-06-16 14:03:35 +02:00
});
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: external ["wp","data"]
2024-04-17 11:32:24 +02:00
const external_wp_data_namespaceObject = window["wp"]["data"];
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/reducer.js
2021-07-23 11:58:50 +02:00
/**
* Reducer returning the registered shortcuts
*
* @param {Object} state Current state.
* @param {Object} action Dispatched action.
*
* @return {Object} Updated state.
*/
2023-09-26 10:33:34 +02:00
function reducer(state = {}, action) {
2021-07-23 11:58:50 +02:00
switch (action.type) {
case 'REGISTER_SHORTCUT':
2023-12-07 09:44:11 +01:00
return {
...state,
2021-07-23 11:58:50 +02:00
[action.name]: {
category: action.category,
keyCombination: action.keyCombination,
aliases: action.aliases,
description: action.description
}
};
case 'UNREGISTER_SHORTCUT':
2022-12-15 17:47:31 +01:00
const {
[action.name]: actionName,
...remainingState
} = state;
return remainingState;
2021-07-23 11:58:50 +02:00
}
return state;
2020-05-06 17:23:38 +02:00
}
2024-04-17 11:32:24 +02:00
/* harmony default export */ const store_reducer = (reducer);
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
2021-07-23 11:58:50 +02:00
/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
/**
* Keyboard key combination.
*
* @typedef {Object} WPShortcutKeyCombination
*
* @property {string} character Character.
* @property {WPKeycodeModifier|undefined} modifier Modifier.
*/
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
/**
* Configuration of a registered keyboard shortcut.
*
* @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-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
/**
* Returns an action object used to register a new keyboard shortcut.
*
* @param {WPShortcutConfig} config Shortcut config.
*
2023-12-07 09:44:11 +01:00
* @example
*
*```js
2024-04-17 11:32:24 +02:00
* import { useEffect } from 'react';
2023-12-07 09:44:11 +01:00
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
* import { useSelect, useDispatch } from '@wordpress/data';
* 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-07-23 11:58:50 +02:00
* @return {Object} action.
*/
2023-09-26 10:33:34 +02:00
function registerShortcut({
name,
category,
description,
keyCombination,
aliases
}) {
2021-07-23 11:58:50 +02:00
return {
type: 'REGISTER_SHORTCUT',
name,
category,
keyCombination,
aliases,
description
};
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Returns an action object used to unregister a keyboard shortcut.
*
* @param {string} name Shortcut name.
*
2023-12-07 09:44:11 +01:00
* @example
*
*```js
2024-04-17 11:32:24 +02:00
* import { useEffect } from 'react';
2023-12-07 09:44:11 +01:00
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
* import { useSelect, useDispatch } from '@wordpress/data';
* import { __ } from '@wordpress/i18n';
*
* const ExampleComponent = () => {
* const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
*
* useEffect( () => {
2025-02-28 08:42:11 +01:00
* unregisterShortcut( 'core/editor/next-region' );
2023-12-07 09:44:11 +01:00
* }, [] );
*
* const shortcut = useSelect(
* ( select ) =>
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
2025-02-28 08:42:11 +01:00
* 'core/editor/next-region'
2023-12-07 09:44:11 +01:00
* ),
* []
* );
*
* return shortcut ? (
* <p>{ __( 'Shortcut is not unregistered.' ) }</p>
* ) : (
* <p>{ __( 'Shortcut is unregistered.' ) }</p>
* );
* };
*```
2021-07-23 11:58:50 +02:00
* @return {Object} action.
*/
function unregisterShortcut(name) {
return {
type: 'UNREGISTER_SHORTCUT',
name
};
2020-05-06 17:23:38 +02:00
}
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: external ["wp","keycodes"]
2024-04-17 11:32:24 +02:00
const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
/**
* WordPress dependencies
*/
2021-07-23 11:58:50 +02:00
2025-02-28 08:42:11 +01:00
2022-06-16 14:03:35 +02:00
/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */
2021-07-23 11:58:50 +02:00
2022-06-16 14:03:35 +02:00
/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */
2021-07-23 11:58:50 +02:00
/**
2022-06-16 14:03:35 +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-07-23 11:58:50 +02:00
*
2022-06-16 14:03:35 +02:00
* @type {Array<any>}
2021-07-23 11:58:50 +02:00
*/
2022-06-16 14:03:35 +02:00
const EMPTY_ARRAY = [];
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
2022-06-16 14:03:35 +02:00
* Shortcut formatting methods.
2021-07-23 11:58:50 +02:00
*
2022-06-16 14:03:35 +02:00
* @property {WPKeycodeHandlerByModifier} display Display formatting.
* @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.
* @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.
2021-07-23 11:58:50 +02:00
*/
2022-06-16 14:03:35 +02:00
const FORMATTING_METHODS = {
display: external_wp_keycodes_namespaceObject.displayShortcut,
raw: external_wp_keycodes_namespaceObject.rawShortcut,
ariaLabel: external_wp_keycodes_namespaceObject.shortcutAriaLabel
};
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
2022-06-16 14:03:35 +02:00
* Returns a string representing the key combination.
2021-07-23 11:58:50 +02:00
*
2022-06-16 14:03:35 +02:00
* @param {?WPShortcutKeyCombination} shortcut Key combination.
* @param {keyof FORMATTING_METHODS} representation Type of representation
* (display, raw, ariaLabel).
2021-07-23 11:58:50 +02:00
*
2022-06-16 14:03:35 +02:00
* @return {string?} Shortcut representation.
2021-07-23 11:58:50 +02:00
*/
2022-06-16 14:03:35 +02:00
function getKeyCombinationRepresentation(shortcut, representation) {
if (!shortcut) {
return null;
}
return shortcut.modifier ? FORMATTING_METHODS[representation][shortcut.modifier](shortcut.character) : shortcut.character;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
2022-06-16 14:03:35 +02:00
* Returns the main key combination for a given shortcut name.
2021-07-23 11:58:50 +02:00
*
2022-06-16 14:03:35 +02:00
* @param {Object} state Global state.
* @param {string} name Shortcut name.
2021-07-23 11:58:50 +02:00
*
2023-12-07 09:44:11 +01: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(
2025-02-28 08:42:11 +01:00
* 'core/editor/next-region'
2023-12-07 09:44:11 +01:00
* ),
* []
* );
*
* return (
* <div>
* { createInterpolateElement(
* sprintf(
* 'Character: <code>%s</code> / Modifier: <code>%s</code>',
* character,
* modifier
* ),
* {
* code: <code />,
* }
* ) }
* </div>
* );
* };
*```
*
2022-06-16 14:03:35 +02:00
* @return {WPShortcutKeyCombination?} Key combination.
2021-07-23 11:58:50 +02:00
*/
2022-06-16 14:03:35 +02:00
function getShortcutKeyCombination(state, name) {
return state[name] ? state[name].keyCombination : null;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
2022-06-16 14:03:35 +02:00
* Returns a string representing the main key combination for a given shortcut name.
2021-07-23 11:58:50 +02:00
*
2022-06-16 14:03:35 +02:00
* @param {Object} state Global state.
* @param {string} name Shortcut name.
* @param {keyof FORMATTING_METHODS} representation Type of representation
* (display, raw, ariaLabel).
2023-12-07 09:44:11 +01: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 {
2025-02-28 08:42:11 +01:00
* display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),
* raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),
* ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')
2023-12-07 09:44:11 +01:00
* }
* },
* []
* );
*
* 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-06-16 14:03:35 +02:00
*
* @return {string?} Shortcut representation.
*/
2023-09-26 10:33:34 +02:00
function getShortcutRepresentation(state, name, representation = 'display') {
2022-06-16 14:03:35 +02:00
const shortcut = getShortcutKeyCombination(state, name);
return getKeyCombinationRepresentation(shortcut, representation);
2021-07-23 11:58:50 +02:00
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
2022-06-16 14:03:35 +02:00
* Returns the shortcut description given its name.
2021-07-23 11:58:50 +02:00
*
2022-06-16 14:03:35 +02:00
* @param {Object} state Global state.
* @param {string} name Shortcut name.
2021-07-23 11:58:50 +02:00
*
2023-12-07 09:44:11 +01: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 ) =>
2025-02-28 08:42:11 +01:00
* select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),
2023-12-07 09:44:11 +01:00
* []
* );
*
* return shortcutDescription ? (
* <div>{ shortcutDescription }</div>
* ) : (
* <div>{ __( 'No description.' ) }</div>
* );
* };
*```
2022-06-16 14:03:35 +02:00
* @return {string?} Shortcut description.
2021-07-23 11:58:50 +02:00
*/
2022-06-16 14:03:35 +02:00
function getShortcutDescription(state, name) {
return state[name] ? state[name].description : null;
2021-07-23 11:58:50 +02:00
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
2022-06-16 14:03:35 +02:00
* Returns the aliases for a given shortcut name.
2020-05-06 17:23:38 +02:00
*
2022-06-16 14:03:35 +02:00
* @param {Object} state Global state.
* @param {string} name Shortcut name.
2023-12-07 09:44:11 +01: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(
2025-02-28 08:42:11 +01:00
* 'core/editor/next-region'
2023-12-07 09:44:11 +01:00
* ),
* []
* );
*
* 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>
* )
* );
* };
*```
2020-05-06 17:23:38 +02:00
*
2022-06-16 14:03:35 +02:00
* @return {WPShortcutKeyCombination[]} Key combinations.
2020-05-06 17:23:38 +02:00
*/
2022-06-16 14:03:35 +02:00
function getShortcutAliases(state, name) {
return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
}
2023-12-07 09:44:11 +01: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(
2025-02-28 08:42:11 +01:00
* 'core/editor/next-region'
2023-12-07 09:44:11 +01:00
* ),
* []
* );
*
* 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.
*/
2025-02-28 08:42:11 +01:00
const getAllShortcutKeyCombinations = (0,external_wp_data_namespaceObject.createSelector)((state, name) => {
2022-12-15 17:47:31 +01:00
return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean);
2022-06-16 14:03:35 +02:00
}, (state, name) => [state[name]]);
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +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-12-07 09:44:11 +01: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(
2025-02-28 08:42:11 +01:00
* 'core/editor/next-region'
2023-12-07 09:44:11 +01:00
* ),
* []
* );
*
* return (
* allShortcutRawKeyCombinations.length > 0 && (
* <ul>
* { allShortcutRawKeyCombinations.map(
* ( shortcutRawKeyCombination, index ) => (
* <li key={ index }>
* { createInterpolateElement(
* sprintf(
* ' <code>%s</code>',
* shortcutRawKeyCombination
* ),
* {
* code: <code />,
* }
* ) }
* </li>
* )
* ) }
* </ul>
* )
* );
* };
*```
*
2022-06-16 14:03:35 +02:00
* @return {string[]} Shortcuts.
*/
2025-02-28 08:42:11 +01:00
const getAllShortcutRawKeyCombinations = (0,external_wp_data_namespaceObject.createSelector)((state, name) => {
2022-06-16 14:03:35 +02:00
return getAllShortcutKeyCombinations(state, name).map(combination => getKeyCombinationRepresentation(combination, 'raw'));
}, (state, name) => [state[name]]);
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +02:00
/**
* Returns the shortcut names list for a given category name.
*
* @param {Object} state Global state.
* @param {string} name Category name.
2023-12-07 09:44:11 +01: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-06-16 14:03:35 +02:00
*
2023-12-07 09:44:11 +01:00
* return (
* categoryShortcuts.length > 0 && (
* <ul>
* { categoryShortcuts.map( ( categoryShortcut ) => (
* <li key={ categoryShortcut }>{ categoryShortcut }</li>
* ) ) }
* </ul>
* )
* );
* };
*```
2022-06-16 14:03:35 +02:00
* @return {string[]} Shortcut names.
*/
2025-02-28 08:42:11 +01:00
const getCategoryShortcuts = (0,external_wp_data_namespaceObject.createSelector)((state, categoryName) => {
2023-09-26 10:33:34 +02:00
return Object.entries(state).filter(([, shortcut]) => shortcut.category === categoryName).map(([name]) => name);
2022-06-16 14:03:35 +02:00
}, state => [state]);
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/index.js
/**
* WordPress dependencies
*/
2020-05-06 17:23:38 +02:00
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +02:00
/**
* Internal dependencies
*/
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
const STORE_NAME = 'core/keyboard-shortcuts';
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +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);
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: external ["wp","element"]
2024-04-17 11:32:24 +02:00
const external_wp_element_namespaceObject = window["wp"]["element"];
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut-event-match.js
/**
* WordPress dependencies
*/
2020-05-06 17:23:38 +02:00
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +02:00
/**
* Internal dependencies
*/
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
/**
* Returns a function to check if a keyboard event matches a shortcut name.
*
2022-12-15 17:47:31 +01:00
* @return {Function} A function to check if a keyboard event matches a
2022-06-16 14:03:35 +02:00
* predefined shortcut combination.
*/
function useShortcutEventMatch() {
const {
getAllShortcutKeyCombinations
} = (0,external_wp_data_namespaceObject.useSelect)(store);
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +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-09-26 10:33:34 +02:00
return getAllShortcutKeyCombinations(name).some(({
modifier,
character
}) => {
2022-06-16 14:03:35 +02:00
return external_wp_keycodes_namespaceObject.isKeyboardEvent[modifier](event, character);
});
}
return isMatch;
}
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/context.js
2025-02-28 08:42:11 +01:00
/* wp:polyfill */
2022-06-16 14:03:35 +02:00
/**
* WordPress dependencies
*/
2020-05-06 17:23:38 +02:00
2023-12-07 09:44:11 +01: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);
}
}
});
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut.js
/**
* WordPress dependencies
*/
2020-05-06 17:23:38 +02:00
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +02:00
/**
* Internal dependencies
*/
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +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-09-26 10:33:34 +02:00
function useShortcut(name, callback, {
2023-12-07 09:44:11 +01:00
isDisabled = false
2023-09-26 10:33:34 +02:00
} = {}) {
2022-06-16 14:03:35 +02:00
const shortcuts = (0,external_wp_element_namespaceObject.useContext)(context);
const isMatch = useShortcutEventMatch();
const callbackRef = (0,external_wp_element_namespaceObject.useRef)();
2023-12-07 09:44:11 +01:00
(0,external_wp_element_namespaceObject.useEffect)(() => {
callbackRef.current = callback;
}, [callback]);
2022-06-16 14:03:35 +02:00
(0,external_wp_element_namespaceObject.useEffect)(() => {
if (isDisabled) {
return;
}
function _callback(event) {
if (isMatch(name, event)) {
callbackRef.current(event);
}
}
2023-12-07 09:44:11 +01:00
shortcuts.add(_callback);
2022-06-16 14:03:35 +02:00
return () => {
2023-12-07 09:44:11 +01:00
shortcuts.delete(_callback);
2022-06-16 14:03:35 +02:00
};
2023-12-07 09:44:11 +01:00
}, [name, isDisabled, shortcuts]);
2022-06-16 14:03:35 +02:00
}
2022-04-02 10:26:41 +02:00
2025-02-28 08:42:11 +01:00
;// CONCATENATED MODULE: external "ReactJSXRuntime"
const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
2022-06-16 14:03:35 +02:00
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/components/shortcut-provider.js
2025-02-28 08:42:11 +01:00
/* wp:polyfill */
2022-06-16 14:03:35 +02:00
/**
* WordPress dependencies
*/
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +02:00
/**
* Internal dependencies
*/
2025-02-28 08:42:11 +01:00
2022-06-16 14:03:35 +02:00
const {
Provider
} = context;
2023-12-07 09:44:11 +01:00
2022-06-16 14:03:35 +02:00
/**
* Handles callbacks added to context by `useShortcut`.
2023-12-07 09:44:11 +01:00
* Adding a provider allows to register contextual shortcuts
* that are only active when a certain part of the UI is focused.
2022-06-16 14:03:35 +02:00
*
* @param {Object} props Props to pass to `div`.
*
2024-04-17 11:32:24 +02:00
* @return {Element} Component.
2022-06-16 14:03:35 +02:00
*/
function ShortcutProvider(props) {
2023-12-07 09:44:11 +01:00
const [keyboardShortcuts] = (0,external_wp_element_namespaceObject.useState)(() => new Set());
2022-06-16 14:03:35 +02:00
function onKeyDown(event) {
2025-02-28 08:42:11 +01:00
if (props.onKeyDown) {
props.onKeyDown(event);
}
2023-12-07 09:44:11 +01:00
for (const keyboardShortcut of keyboardShortcuts) {
2022-06-16 14:03:35 +02:00
keyboardShortcut(event);
}
}
2023-12-07 09:44:11 +01:00
/* eslint-disable jsx-a11y/no-static-element-interactions */
2025-02-28 08:42:11 +01:00
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Provider, {
value: keyboardShortcuts,
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
...props,
onKeyDown: onKeyDown
})
});
2022-06-16 14:03:35 +02:00
/* eslint-enable jsx-a11y/no-static-element-interactions */
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/keyboard-shortcuts/build-module/index.js
2022-04-02 10:26:41 +02:00
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
(window.wp = window.wp || {}).keyboardShortcuts = __webpack_exports__;
/******/ })()
;