@wordpress/keyboard-shortcuts 5.17.0 → 5.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 5.19.0 (2025-02-28)
6
+
7
+ ## 5.18.0 (2025-02-12)
8
+
5
9
  ## 5.17.0 (2025-01-29)
6
10
 
7
11
  ## 5.16.0 (2025-01-15)
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_keycodes","_store","useShortcutEventMatch","getAllShortcutKeyCombinations","useSelect","keyboardShortcutsStore","isMatch","name","event","some","modifier","character","isKeyboardEvent"],"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to check if a keyboard event matches a\n * predefined shortcut combination.\n */\nexport default function useShortcutEventMatch() {\n\tconst { getAllShortcutKeyCombinations } = useSelect(\n\t\tkeyboardShortcutsStore\n\t);\n\n\t/**\n\t * A function to check if a keyboard event matches a predefined shortcut\n\t * combination.\n\t *\n\t * @param {string} name Shortcut name.\n\t * @param {KeyboardEvent} event Event to check.\n\t *\n\t * @return {boolean} True if the event matches any shortcuts, false if not.\n\t */\n\tfunction isMatch( name, event ) {\n\t\treturn getAllShortcutKeyCombinations( name ).some(\n\t\t\t( { modifier, character } ) => {\n\t\t\t\treturn isKeyboardEvent[ modifier ]( event, character );\n\t\t\t}\n\t\t);\n\t}\n\n\treturn isMatch;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,qBAAqBA,CAAA,EAAG;EAC/C,MAAM;IAAEC;EAA8B,CAAC,GAAG,IAAAC,eAAS,EAClDC,YACD,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,SAASC,OAAOA,CAAEC,IAAI,EAAEC,KAAK,EAAG;IAC/B,OAAOL,6BAA6B,CAAEI,IAAK,CAAC,CAACE,IAAI,CAChD,CAAE;MAAEC,QAAQ;MAAEC;IAAU,CAAC,KAAM;MAC9B,OAAOC,yBAAe,CAAEF,QAAQ,CAAE,CAAEF,KAAK,EAAEG,SAAU,CAAC;IACvD,CACD,CAAC;EACF;EAEA,OAAOL,OAAO;AACf","ignoreList":[]}
1
+ {"version":3,"names":["_data","require","_keycodes","_store","useShortcutEventMatch","getAllShortcutKeyCombinations","useSelect","keyboardShortcutsStore","isMatch","name","event","some","modifier","character","isKeyboardEvent"],"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to check if a keyboard event matches a\n * predefined shortcut combination.\n */\nexport default function useShortcutEventMatch() {\n\tconst { getAllShortcutKeyCombinations } = useSelect(\n\t\tkeyboardShortcutsStore\n\t);\n\n\t/**\n\t * A function to check if a keyboard event matches a predefined shortcut\n\t * combination.\n\t *\n\t * @param {string} name Shortcut name.\n\t * @param {KeyboardEvent} event Event to check.\n\t *\n\t * @return {boolean} True if the event matches any shortcuts, false if not.\n\t */\n\tfunction isMatch( name, event ) {\n\t\treturn getAllShortcutKeyCombinations( name ).some(\n\t\t\t( { modifier, character } ) => {\n\t\t\t\treturn isKeyboardEvent[ modifier ]( event, character );\n\t\t\t}\n\t\t);\n\t}\n\n\treturn isMatch;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,qBAAqBA,CAAA,EAAG;EAC/C,MAAM;IAAEC;EAA8B,CAAC,GAAG,IAAAC,eAAS,EAClDC,YACD,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,SAASC,OAAOA,CAAEC,IAAI,EAAEC,KAAK,EAAG;IAC/B,OAAOL,6BAA6B,CAAEI,IAAK,CAAC,CAACE,IAAI,CAChD,CAAE;MAAEC,QAAQ;MAAEC;IAAU,CAAC,KAAM;MAC9B,OAAOC,yBAAe,CAAEF,QAAQ,CAAE,CAAEF,KAAK,EAAEG,SAAU,CAAC;IACvD,CACD,CAAC;EACF;EAEA,OAAOL,OAAO;AACf","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_keycodes","EMPTY_ARRAY","FORMATTING_METHODS","display","displayShortcut","raw","rawShortcut","ariaLabel","shortcutAriaLabel","getKeyCombinationRepresentation","shortcut","representation","modifier","character","getShortcutKeyCombination","state","name","keyCombination","getShortcutRepresentation","getShortcutDescription","description","getShortcutAliases","aliases","getAllShortcutKeyCombinations","exports","createSelector","filter","Boolean","getAllShortcutRawKeyCombinations","map","combination","getCategoryShortcuts","categoryName","Object","entries","category"],"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\nimport {\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n\trawShortcut,\n} from '@wordpress/keycodes';\n\n/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */\n\n/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Shortcut formatting methods.\n *\n * @property {WPKeycodeHandlerByModifier} display Display formatting.\n * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.\n * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.\n */\nconst FORMATTING_METHODS = {\n\tdisplay: displayShortcut,\n\traw: rawShortcut,\n\tariaLabel: shortcutAriaLabel,\n};\n\n/**\n * Returns a string representing the key combination.\n *\n * @param {?WPShortcutKeyCombination} shortcut Key combination.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n *\n * @return {?string} Shortcut representation.\n */\nfunction getKeyCombinationRepresentation( shortcut, representation ) {\n\tif ( ! shortcut ) {\n\t\treturn null;\n\t}\n\n\treturn shortcut.modifier\n\t\t? FORMATTING_METHODS[ representation ][ shortcut.modifier ](\n\t\t\t\tshortcut.character\n\t\t )\n\t\t: shortcut.character;\n}\n\n/**\n * Returns the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const {character, modifier} = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * <div>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </div>\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination?} Key combination.\n */\nexport function getShortcutKeyCombination( state, name ) {\n\treturn state[ name ] ? state[ name ].keyCombination : null;\n}\n\n/**\n * Returns a string representing the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const {display, raw, ariaLabel} = useSelect(\n * ( select ) =>{\n * return {\n * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')\n * }\n * },\n * []\n * );\n *\n * return (\n * <ul>\n * <li>{ sprintf( 'display string: %s', display ) }</li>\n * <li>{ sprintf( 'raw string: %s', raw ) }</li>\n * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>\n * </ul>\n * );\n * };\n *```\n *\n * @return {?string} Shortcut representation.\n */\nexport function getShortcutRepresentation(\n\tstate,\n\tname,\n\trepresentation = 'display'\n) {\n\tconst shortcut = getShortcutKeyCombination( state, name );\n\treturn getKeyCombinationRepresentation( shortcut, representation );\n}\n\n/**\n * Returns the shortcut description given its name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutDescription = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),\n * []\n * );\n *\n * return shortcutDescription ? (\n * <div>{ shortcutDescription }</div>\n * ) : (\n * <div>{ __( 'No description.' ) }</div>\n * );\n * };\n *```\n * @return {?string} Shortcut description.\n */\nexport function getShortcutDescription( state, name ) {\n\treturn state[ name ] ? state[ name ].description : null;\n}\n\n/**\n * Returns the aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutAliases = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutAliases(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * shortcutAliases.length > 0 && (\n * <ul>\n * { shortcutAliases.map( ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport function getShortcutAliases( state, name ) {\n\treturn state[ name ] && state[ name ].aliases\n\t\t? state[ name ].aliases\n\t\t: EMPTY_ARRAY;\n}\n\n/**\n * Returns the shortcuts that include aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutKeyCombinations.map(\n * ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport const getAllShortcutKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn [\n\t\t\tgetShortcutKeyCombination( state, name ),\n\t\t\t...getShortcutAliases( state, name ),\n\t\t].filter( Boolean );\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the raw representation of all the keyboard combinations of a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutRawKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutRawKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutRawKeyCombinations.map(\n * ( shortcutRawKeyCombination, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * ' <code>%s</code>',\n * shortcutRawKeyCombination\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {string[]} Shortcuts.\n */\nexport const getAllShortcutRawKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn getAllShortcutKeyCombinations( state, name ).map(\n\t\t\t( combination ) =>\n\t\t\t\tgetKeyCombinationRepresentation( combination, 'raw' )\n\t\t);\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the shortcut names list for a given category name.\n *\n * @param {Object} state Global state.\n * @param {string} name Category name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * const categoryShortcuts = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getCategoryShortcuts(\n * 'block'\n * ),\n * []\n * );\n *\n * return (\n * categoryShortcuts.length > 0 && (\n * <ul>\n * { categoryShortcuts.map( ( categoryShortcut ) => (\n * <li key={ categoryShortcut }>{ categoryShortcut }</li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n * @return {string[]} Shortcut names.\n */\nexport const getCategoryShortcuts = createSelector(\n\t( state, categoryName ) => {\n\t\treturn Object.entries( state )\n\t\t\t.filter( ( [ , shortcut ] ) => shortcut.category === categoryName )\n\t\t\t.map( ( [ name ] ) => name );\n\t},\n\t( state ) => [ state ]\n);\n"],"mappings":";;;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAQA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG;EAC1BC,OAAO,EAAEC,yBAAe;EACxBC,GAAG,EAAEC,qBAAW;EAChBC,SAAS,EAAEC;AACZ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,+BAA+BA,CAAEC,QAAQ,EAAEC,cAAc,EAAG;EACpE,IAAK,CAAED,QAAQ,EAAG;IACjB,OAAO,IAAI;EACZ;EAEA,OAAOA,QAAQ,CAACE,QAAQ,GACrBV,kBAAkB,CAAES,cAAc,CAAE,CAAED,QAAQ,CAACE,QAAQ,CAAE,CACzDF,QAAQ,CAACG,SACT,CAAC,GACDH,QAAQ,CAACG,SAAS;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,yBAAyBA,CAAEC,KAAK,EAAEC,IAAI,EAAG;EACxD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACC,cAAc,GAAG,IAAI;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,yBAAyBA,CACxCH,KAAK,EACLC,IAAI,EACJL,cAAc,GAAG,SAAS,EACzB;EACD,MAAMD,QAAQ,GAAGI,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC;EACzD,OAAOP,+BAA+B,CAAEC,QAAQ,EAAEC,cAAe,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASQ,sBAAsBA,CAAEJ,KAAK,EAAEC,IAAI,EAAG;EACrD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACI,WAAW,GAAG,IAAI;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAEN,KAAK,EAAEC,IAAI,EAAG;EACjD,OAAOD,KAAK,CAAEC,IAAI,CAAE,IAAID,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GAC1CP,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GACrBrB,WAAW;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMsB,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,IAAAE,oBAAc,EAC1D,CAAEV,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAO,CACNF,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC,EACxC,GAAGK,kBAAkB,CAAEN,KAAK,EAAEC,IAAK,CAAC,CACpC,CAACU,MAAM,CAAEC,OAAQ,CAAC;AACpB,CAAC,EACD,CAAEZ,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMY,gCAAgC,GAAAJ,OAAA,CAAAI,gCAAA,GAAG,IAAAH,oBAAc,EAC7D,CAAEV,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAOO,6BAA6B,CAAER,KAAK,EAAEC,IAAK,CAAC,CAACa,GAAG,CACpDC,WAAW,IACZrB,+BAA+B,CAAEqB,WAAW,EAAE,KAAM,CACtD,CAAC;AACF,CAAC,EACD,CAAEf,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMe,oBAAoB,GAAAP,OAAA,CAAAO,oBAAA,GAAG,IAAAN,oBAAc,EACjD,CAAEV,KAAK,EAAEiB,YAAY,KAAM;EAC1B,OAAOC,MAAM,CAACC,OAAO,CAAEnB,KAAM,CAAC,CAC5BW,MAAM,CAAE,CAAE,GAAIhB,QAAQ,CAAE,KAAMA,QAAQ,CAACyB,QAAQ,KAAKH,YAAa,CAAC,CAClEH,GAAG,CAAE,CAAE,CAAEb,IAAI,CAAE,KAAMA,IAAK,CAAC;AAC9B,CAAC,EACCD,KAAK,IAAM,CAAEA,KAAK,CACrB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_data","require","_keycodes","EMPTY_ARRAY","FORMATTING_METHODS","display","displayShortcut","raw","rawShortcut","ariaLabel","shortcutAriaLabel","getKeyCombinationRepresentation","shortcut","representation","modifier","character","getShortcutKeyCombination","state","name","keyCombination","getShortcutRepresentation","getShortcutDescription","description","getShortcutAliases","aliases","getAllShortcutKeyCombinations","exports","createSelector","filter","Boolean","getAllShortcutRawKeyCombinations","map","combination","getCategoryShortcuts","categoryName","Object","entries","category"],"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\nimport {\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n\trawShortcut,\n} from '@wordpress/keycodes';\n\n/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */\n\n/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Shortcut formatting methods.\n *\n * @property {WPKeycodeHandlerByModifier} display Display formatting.\n * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.\n * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.\n */\nconst FORMATTING_METHODS = {\n\tdisplay: displayShortcut,\n\traw: rawShortcut,\n\tariaLabel: shortcutAriaLabel,\n};\n\n/**\n * Returns a string representing the key combination.\n *\n * @param {?WPShortcutKeyCombination} shortcut Key combination.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n *\n * @return {?string} Shortcut representation.\n */\nfunction getKeyCombinationRepresentation( shortcut, representation ) {\n\tif ( ! shortcut ) {\n\t\treturn null;\n\t}\n\n\treturn shortcut.modifier\n\t\t? FORMATTING_METHODS[ representation ][ shortcut.modifier ](\n\t\t\t\tshortcut.character\n\t\t )\n\t\t: shortcut.character;\n}\n\n/**\n * Returns the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const {character, modifier} = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * <div>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </div>\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination?} Key combination.\n */\nexport function getShortcutKeyCombination( state, name ) {\n\treturn state[ name ] ? state[ name ].keyCombination : null;\n}\n\n/**\n * Returns a string representing the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const {display, raw, ariaLabel} = useSelect(\n * ( select ) =>{\n * return {\n * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')\n * }\n * },\n * []\n * );\n *\n * return (\n * <ul>\n * <li>{ sprintf( 'display string: %s', display ) }</li>\n * <li>{ sprintf( 'raw string: %s', raw ) }</li>\n * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>\n * </ul>\n * );\n * };\n *```\n *\n * @return {?string} Shortcut representation.\n */\nexport function getShortcutRepresentation(\n\tstate,\n\tname,\n\trepresentation = 'display'\n) {\n\tconst shortcut = getShortcutKeyCombination( state, name );\n\treturn getKeyCombinationRepresentation( shortcut, representation );\n}\n\n/**\n * Returns the shortcut description given its name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutDescription = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),\n * []\n * );\n *\n * return shortcutDescription ? (\n * <div>{ shortcutDescription }</div>\n * ) : (\n * <div>{ __( 'No description.' ) }</div>\n * );\n * };\n *```\n * @return {?string} Shortcut description.\n */\nexport function getShortcutDescription( state, name ) {\n\treturn state[ name ] ? state[ name ].description : null;\n}\n\n/**\n * Returns the aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutAliases = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutAliases(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * shortcutAliases.length > 0 && (\n * <ul>\n * { shortcutAliases.map( ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport function getShortcutAliases( state, name ) {\n\treturn state[ name ] && state[ name ].aliases\n\t\t? state[ name ].aliases\n\t\t: EMPTY_ARRAY;\n}\n\n/**\n * Returns the shortcuts that include aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutKeyCombinations.map(\n * ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport const getAllShortcutKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn [\n\t\t\tgetShortcutKeyCombination( state, name ),\n\t\t\t...getShortcutAliases( state, name ),\n\t\t].filter( Boolean );\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the raw representation of all the keyboard combinations of a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutRawKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutRawKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutRawKeyCombinations.map(\n * ( shortcutRawKeyCombination, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * ' <code>%s</code>',\n * shortcutRawKeyCombination\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {string[]} Shortcuts.\n */\nexport const getAllShortcutRawKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn getAllShortcutKeyCombinations( state, name ).map(\n\t\t\t( combination ) =>\n\t\t\t\tgetKeyCombinationRepresentation( combination, 'raw' )\n\t\t);\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the shortcut names list for a given category name.\n *\n * @param {Object} state Global state.\n * @param {string} name Category name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * const categoryShortcuts = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getCategoryShortcuts(\n * 'block'\n * ),\n * []\n * );\n *\n * return (\n * categoryShortcuts.length > 0 && (\n * <ul>\n * { categoryShortcuts.map( ( categoryShortcut ) => (\n * <li key={ categoryShortcut }>{ categoryShortcut }</li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n * @return {string[]} Shortcut names.\n */\nexport const getCategoryShortcuts = createSelector(\n\t( state, categoryName ) => {\n\t\treturn Object.entries( state )\n\t\t\t.filter( ( [ , shortcut ] ) => shortcut.category === categoryName )\n\t\t\t.map( ( [ name ] ) => name );\n\t},\n\t( state ) => [ state ]\n);\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAQA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG;EAC1BC,OAAO,EAAEC,yBAAe;EACxBC,GAAG,EAAEC,qBAAW;EAChBC,SAAS,EAAEC;AACZ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,+BAA+BA,CAAEC,QAAQ,EAAEC,cAAc,EAAG;EACpE,IAAK,CAAED,QAAQ,EAAG;IACjB,OAAO,IAAI;EACZ;EAEA,OAAOA,QAAQ,CAACE,QAAQ,GACrBV,kBAAkB,CAAES,cAAc,CAAE,CAAED,QAAQ,CAACE,QAAQ,CAAE,CACzDF,QAAQ,CAACG,SACT,CAAC,GACDH,QAAQ,CAACG,SAAS;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,yBAAyBA,CAAEC,KAAK,EAAEC,IAAI,EAAG;EACxD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACC,cAAc,GAAG,IAAI;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,yBAAyBA,CACxCH,KAAK,EACLC,IAAI,EACJL,cAAc,GAAG,SAAS,EACzB;EACD,MAAMD,QAAQ,GAAGI,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC;EACzD,OAAOP,+BAA+B,CAAEC,QAAQ,EAAEC,cAAe,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASQ,sBAAsBA,CAAEJ,KAAK,EAAEC,IAAI,EAAG;EACrD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACI,WAAW,GAAG,IAAI;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAEN,KAAK,EAAEC,IAAI,EAAG;EACjD,OAAOD,KAAK,CAAEC,IAAI,CAAE,IAAID,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GAC1CP,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GACrBrB,WAAW;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMsB,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,IAAAE,oBAAc,EAC1D,CAAEV,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAO,CACNF,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC,EACxC,GAAGK,kBAAkB,CAAEN,KAAK,EAAEC,IAAK,CAAC,CACpC,CAACU,MAAM,CAAEC,OAAQ,CAAC;AACpB,CAAC,EACD,CAAEZ,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMY,gCAAgC,GAAAJ,OAAA,CAAAI,gCAAA,GAAG,IAAAH,oBAAc,EAC7D,CAAEV,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAOO,6BAA6B,CAAER,KAAK,EAAEC,IAAK,CAAC,CAACa,GAAG,CACpDC,WAAW,IACZrB,+BAA+B,CAAEqB,WAAW,EAAE,KAAM,CACtD,CAAC;AACF,CAAC,EACD,CAAEf,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMe,oBAAoB,GAAAP,OAAA,CAAAO,oBAAA,GAAG,IAAAN,oBAAc,EACjD,CAAEV,KAAK,EAAEiB,YAAY,KAAM;EAC1B,OAAOC,MAAM,CAACC,OAAO,CAAEnB,KAAM,CAAC,CAC5BW,MAAM,CAAE,CAAE,GAAIhB,QAAQ,CAAE,KAAMA,QAAQ,CAACyB,QAAQ,KAAKH,YAAa,CAAC,CAClEH,GAAG,CAAE,CAAE,CAAEb,IAAI,CAAE,KAAMA,IAAK,CAAC;AAC9B,CAAC,EACCD,KAAK,IAAM,CAAEA,KAAK,CACrB,CAAC","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  /**
3
2
  * WordPress dependencies
4
3
  */
@@ -1 +1 @@
1
- {"version":3,"names":["useSelect","isKeyboardEvent","store","keyboardShortcutsStore","useShortcutEventMatch","getAllShortcutKeyCombinations","isMatch","name","event","some","modifier","character"],"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to check if a keyboard event matches a\n * predefined shortcut combination.\n */\nexport default function useShortcutEventMatch() {\n\tconst { getAllShortcutKeyCombinations } = useSelect(\n\t\tkeyboardShortcutsStore\n\t);\n\n\t/**\n\t * A function to check if a keyboard event matches a predefined shortcut\n\t * combination.\n\t *\n\t * @param {string} name Shortcut name.\n\t * @param {KeyboardEvent} event Event to check.\n\t *\n\t * @return {boolean} True if the event matches any shortcuts, false if not.\n\t */\n\tfunction isMatch( name, event ) {\n\t\treturn getAllShortcutKeyCombinations( name ).some(\n\t\t\t( { modifier, character } ) => {\n\t\t\t\treturn isKeyboardEvent[ modifier ]( event, character );\n\t\t\t}\n\t\t);\n\t}\n\n\treturn isMatch;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,QAAQ,qBAAqB;;AAErD;AACA;AACA;AACA,SAASC,KAAK,IAAIC,sBAAsB,QAAQ,UAAU;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAAA,EAAG;EAC/C,MAAM;IAAEC;EAA8B,CAAC,GAAGL,SAAS,CAClDG,sBACD,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,SAASG,OAAOA,CAAEC,IAAI,EAAEC,KAAK,EAAG;IAC/B,OAAOH,6BAA6B,CAAEE,IAAK,CAAC,CAACE,IAAI,CAChD,CAAE;MAAEC,QAAQ;MAAEC;IAAU,CAAC,KAAM;MAC9B,OAAOV,eAAe,CAAES,QAAQ,CAAE,CAAEF,KAAK,EAAEG,SAAU,CAAC;IACvD,CACD,CAAC;EACF;EAEA,OAAOL,OAAO;AACf","ignoreList":[]}
1
+ {"version":3,"names":["useSelect","isKeyboardEvent","store","keyboardShortcutsStore","useShortcutEventMatch","getAllShortcutKeyCombinations","isMatch","name","event","some","modifier","character"],"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to check if a keyboard event matches a\n * predefined shortcut combination.\n */\nexport default function useShortcutEventMatch() {\n\tconst { getAllShortcutKeyCombinations } = useSelect(\n\t\tkeyboardShortcutsStore\n\t);\n\n\t/**\n\t * A function to check if a keyboard event matches a predefined shortcut\n\t * combination.\n\t *\n\t * @param {string} name Shortcut name.\n\t * @param {KeyboardEvent} event Event to check.\n\t *\n\t * @return {boolean} True if the event matches any shortcuts, false if not.\n\t */\n\tfunction isMatch( name, event ) {\n\t\treturn getAllShortcutKeyCombinations( name ).some(\n\t\t\t( { modifier, character } ) => {\n\t\t\t\treturn isKeyboardEvent[ modifier ]( event, character );\n\t\t\t}\n\t\t);\n\t}\n\n\treturn isMatch;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,QAAQ,qBAAqB;;AAErD;AACA;AACA;AACA,SAASC,KAAK,IAAIC,sBAAsB,QAAQ,UAAU;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAAA,EAAG;EAC/C,MAAM;IAAEC;EAA8B,CAAC,GAAGL,SAAS,CAClDG,sBACD,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,SAASG,OAAOA,CAAEC,IAAI,EAAEC,KAAK,EAAG;IAC/B,OAAOH,6BAA6B,CAAEE,IAAK,CAAC,CAACE,IAAI,CAChD,CAAE;MAAEC,QAAQ;MAAEC;IAAU,CAAC,KAAM;MAC9B,OAAOV,eAAe,CAAES,QAAQ,CAAE,CAAEF,KAAK,EAAEG,SAAU,CAAC;IACvD,CACD,CAAC;EACF;EAEA,OAAOL,OAAO;AACf","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  /**
3
2
  * WordPress dependencies
4
3
  */
@@ -1 +1 @@
1
- {"version":3,"names":["createSelector","displayShortcut","shortcutAriaLabel","rawShortcut","EMPTY_ARRAY","FORMATTING_METHODS","display","raw","ariaLabel","getKeyCombinationRepresentation","shortcut","representation","modifier","character","getShortcutKeyCombination","state","name","keyCombination","getShortcutRepresentation","getShortcutDescription","description","getShortcutAliases","aliases","getAllShortcutKeyCombinations","filter","Boolean","getAllShortcutRawKeyCombinations","map","combination","getCategoryShortcuts","categoryName","Object","entries","category"],"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\nimport {\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n\trawShortcut,\n} from '@wordpress/keycodes';\n\n/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */\n\n/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Shortcut formatting methods.\n *\n * @property {WPKeycodeHandlerByModifier} display Display formatting.\n * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.\n * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.\n */\nconst FORMATTING_METHODS = {\n\tdisplay: displayShortcut,\n\traw: rawShortcut,\n\tariaLabel: shortcutAriaLabel,\n};\n\n/**\n * Returns a string representing the key combination.\n *\n * @param {?WPShortcutKeyCombination} shortcut Key combination.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n *\n * @return {?string} Shortcut representation.\n */\nfunction getKeyCombinationRepresentation( shortcut, representation ) {\n\tif ( ! shortcut ) {\n\t\treturn null;\n\t}\n\n\treturn shortcut.modifier\n\t\t? FORMATTING_METHODS[ representation ][ shortcut.modifier ](\n\t\t\t\tshortcut.character\n\t\t )\n\t\t: shortcut.character;\n}\n\n/**\n * Returns the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const {character, modifier} = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * <div>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </div>\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination?} Key combination.\n */\nexport function getShortcutKeyCombination( state, name ) {\n\treturn state[ name ] ? state[ name ].keyCombination : null;\n}\n\n/**\n * Returns a string representing the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const {display, raw, ariaLabel} = useSelect(\n * ( select ) =>{\n * return {\n * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')\n * }\n * },\n * []\n * );\n *\n * return (\n * <ul>\n * <li>{ sprintf( 'display string: %s', display ) }</li>\n * <li>{ sprintf( 'raw string: %s', raw ) }</li>\n * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>\n * </ul>\n * );\n * };\n *```\n *\n * @return {?string} Shortcut representation.\n */\nexport function getShortcutRepresentation(\n\tstate,\n\tname,\n\trepresentation = 'display'\n) {\n\tconst shortcut = getShortcutKeyCombination( state, name );\n\treturn getKeyCombinationRepresentation( shortcut, representation );\n}\n\n/**\n * Returns the shortcut description given its name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutDescription = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),\n * []\n * );\n *\n * return shortcutDescription ? (\n * <div>{ shortcutDescription }</div>\n * ) : (\n * <div>{ __( 'No description.' ) }</div>\n * );\n * };\n *```\n * @return {?string} Shortcut description.\n */\nexport function getShortcutDescription( state, name ) {\n\treturn state[ name ] ? state[ name ].description : null;\n}\n\n/**\n * Returns the aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutAliases = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutAliases(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * shortcutAliases.length > 0 && (\n * <ul>\n * { shortcutAliases.map( ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport function getShortcutAliases( state, name ) {\n\treturn state[ name ] && state[ name ].aliases\n\t\t? state[ name ].aliases\n\t\t: EMPTY_ARRAY;\n}\n\n/**\n * Returns the shortcuts that include aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutKeyCombinations.map(\n * ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport const getAllShortcutKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn [\n\t\t\tgetShortcutKeyCombination( state, name ),\n\t\t\t...getShortcutAliases( state, name ),\n\t\t].filter( Boolean );\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the raw representation of all the keyboard combinations of a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutRawKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutRawKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutRawKeyCombinations.map(\n * ( shortcutRawKeyCombination, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * ' <code>%s</code>',\n * shortcutRawKeyCombination\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {string[]} Shortcuts.\n */\nexport const getAllShortcutRawKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn getAllShortcutKeyCombinations( state, name ).map(\n\t\t\t( combination ) =>\n\t\t\t\tgetKeyCombinationRepresentation( combination, 'raw' )\n\t\t);\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the shortcut names list for a given category name.\n *\n * @param {Object} state Global state.\n * @param {string} name Category name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * const categoryShortcuts = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getCategoryShortcuts(\n * 'block'\n * ),\n * []\n * );\n *\n * return (\n * categoryShortcuts.length > 0 && (\n * <ul>\n * { categoryShortcuts.map( ( categoryShortcut ) => (\n * <li key={ categoryShortcut }>{ categoryShortcut }</li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n * @return {string[]} Shortcut names.\n */\nexport const getCategoryShortcuts = createSelector(\n\t( state, categoryName ) => {\n\t\treturn Object.entries( state )\n\t\t\t.filter( ( [ , shortcut ] ) => shortcut.category === categoryName )\n\t\t\t.map( ( [ name ] ) => name );\n\t},\n\t( state ) => [ state ]\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,cAAc,QAAQ,iBAAiB;AAChD,SACCC,eAAe,EACfC,iBAAiB,EACjBC,WAAW,QACL,qBAAqB;;AAE5B;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG;EAC1BC,OAAO,EAAEL,eAAe;EACxBM,GAAG,EAAEJ,WAAW;EAChBK,SAAS,EAAEN;AACZ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASO,+BAA+BA,CAAEC,QAAQ,EAAEC,cAAc,EAAG;EACpE,IAAK,CAAED,QAAQ,EAAG;IACjB,OAAO,IAAI;EACZ;EAEA,OAAOA,QAAQ,CAACE,QAAQ,GACrBP,kBAAkB,CAAEM,cAAc,CAAE,CAAED,QAAQ,CAACE,QAAQ,CAAE,CACzDF,QAAQ,CAACG,SACT,CAAC,GACDH,QAAQ,CAACG,SAAS;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CAAEC,KAAK,EAAEC,IAAI,EAAG;EACxD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACC,cAAc,GAAG,IAAI;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACxCH,KAAK,EACLC,IAAI,EACJL,cAAc,GAAG,SAAS,EACzB;EACD,MAAMD,QAAQ,GAAGI,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC;EACzD,OAAOP,+BAA+B,CAAEC,QAAQ,EAAEC,cAAe,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,sBAAsBA,CAAEJ,KAAK,EAAEC,IAAI,EAAG;EACrD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACI,WAAW,GAAG,IAAI;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAEN,KAAK,EAAEC,IAAI,EAAG;EACjD,OAAOD,KAAK,CAAEC,IAAI,CAAE,IAAID,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GAC1CP,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GACrBlB,WAAW;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMmB,6BAA6B,GAAGvB,cAAc,CAC1D,CAAEe,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAO,CACNF,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC,EACxC,GAAGK,kBAAkB,CAAEN,KAAK,EAAEC,IAAK,CAAC,CACpC,CAACQ,MAAM,CAAEC,OAAQ,CAAC;AACpB,CAAC,EACD,CAAEV,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMU,gCAAgC,GAAG1B,cAAc,CAC7D,CAAEe,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAOO,6BAA6B,CAAER,KAAK,EAAEC,IAAK,CAAC,CAACW,GAAG,CACpDC,WAAW,IACZnB,+BAA+B,CAAEmB,WAAW,EAAE,KAAM,CACtD,CAAC;AACF,CAAC,EACD,CAAEb,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMa,oBAAoB,GAAG7B,cAAc,CACjD,CAAEe,KAAK,EAAEe,YAAY,KAAM;EAC1B,OAAOC,MAAM,CAACC,OAAO,CAAEjB,KAAM,CAAC,CAC5BS,MAAM,CAAE,CAAE,GAAId,QAAQ,CAAE,KAAMA,QAAQ,CAACuB,QAAQ,KAAKH,YAAa,CAAC,CAClEH,GAAG,CAAE,CAAE,CAAEX,IAAI,CAAE,KAAMA,IAAK,CAAC;AAC9B,CAAC,EACCD,KAAK,IAAM,CAAEA,KAAK,CACrB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createSelector","displayShortcut","shortcutAriaLabel","rawShortcut","EMPTY_ARRAY","FORMATTING_METHODS","display","raw","ariaLabel","getKeyCombinationRepresentation","shortcut","representation","modifier","character","getShortcutKeyCombination","state","name","keyCombination","getShortcutRepresentation","getShortcutDescription","description","getShortcutAliases","aliases","getAllShortcutKeyCombinations","filter","Boolean","getAllShortcutRawKeyCombinations","map","combination","getCategoryShortcuts","categoryName","Object","entries","category"],"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\nimport {\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n\trawShortcut,\n} from '@wordpress/keycodes';\n\n/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */\n\n/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Shortcut formatting methods.\n *\n * @property {WPKeycodeHandlerByModifier} display Display formatting.\n * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.\n * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.\n */\nconst FORMATTING_METHODS = {\n\tdisplay: displayShortcut,\n\traw: rawShortcut,\n\tariaLabel: shortcutAriaLabel,\n};\n\n/**\n * Returns a string representing the key combination.\n *\n * @param {?WPShortcutKeyCombination} shortcut Key combination.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n *\n * @return {?string} Shortcut representation.\n */\nfunction getKeyCombinationRepresentation( shortcut, representation ) {\n\tif ( ! shortcut ) {\n\t\treturn null;\n\t}\n\n\treturn shortcut.modifier\n\t\t? FORMATTING_METHODS[ representation ][ shortcut.modifier ](\n\t\t\t\tshortcut.character\n\t\t )\n\t\t: shortcut.character;\n}\n\n/**\n * Returns the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const {character, modifier} = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * <div>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </div>\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination?} Key combination.\n */\nexport function getShortcutKeyCombination( state, name ) {\n\treturn state[ name ] ? state[ name ].keyCombination : null;\n}\n\n/**\n * Returns a string representing the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const {display, raw, ariaLabel} = useSelect(\n * ( select ) =>{\n * return {\n * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')\n * }\n * },\n * []\n * );\n *\n * return (\n * <ul>\n * <li>{ sprintf( 'display string: %s', display ) }</li>\n * <li>{ sprintf( 'raw string: %s', raw ) }</li>\n * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>\n * </ul>\n * );\n * };\n *```\n *\n * @return {?string} Shortcut representation.\n */\nexport function getShortcutRepresentation(\n\tstate,\n\tname,\n\trepresentation = 'display'\n) {\n\tconst shortcut = getShortcutKeyCombination( state, name );\n\treturn getKeyCombinationRepresentation( shortcut, representation );\n}\n\n/**\n * Returns the shortcut description given its name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutDescription = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),\n * []\n * );\n *\n * return shortcutDescription ? (\n * <div>{ shortcutDescription }</div>\n * ) : (\n * <div>{ __( 'No description.' ) }</div>\n * );\n * };\n *```\n * @return {?string} Shortcut description.\n */\nexport function getShortcutDescription( state, name ) {\n\treturn state[ name ] ? state[ name ].description : null;\n}\n\n/**\n * Returns the aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutAliases = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutAliases(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * shortcutAliases.length > 0 && (\n * <ul>\n * { shortcutAliases.map( ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport function getShortcutAliases( state, name ) {\n\treturn state[ name ] && state[ name ].aliases\n\t\t? state[ name ].aliases\n\t\t: EMPTY_ARRAY;\n}\n\n/**\n * Returns the shortcuts that include aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutKeyCombinations.map(\n * ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport const getAllShortcutKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn [\n\t\t\tgetShortcutKeyCombination( state, name ),\n\t\t\t...getShortcutAliases( state, name ),\n\t\t].filter( Boolean );\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the raw representation of all the keyboard combinations of a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutRawKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutRawKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutRawKeyCombinations.map(\n * ( shortcutRawKeyCombination, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * ' <code>%s</code>',\n * shortcutRawKeyCombination\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {string[]} Shortcuts.\n */\nexport const getAllShortcutRawKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn getAllShortcutKeyCombinations( state, name ).map(\n\t\t\t( combination ) =>\n\t\t\t\tgetKeyCombinationRepresentation( combination, 'raw' )\n\t\t);\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the shortcut names list for a given category name.\n *\n * @param {Object} state Global state.\n * @param {string} name Category name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * const categoryShortcuts = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getCategoryShortcuts(\n * 'block'\n * ),\n * []\n * );\n *\n * return (\n * categoryShortcuts.length > 0 && (\n * <ul>\n * { categoryShortcuts.map( ( categoryShortcut ) => (\n * <li key={ categoryShortcut }>{ categoryShortcut }</li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n * @return {string[]} Shortcut names.\n */\nexport const getCategoryShortcuts = createSelector(\n\t( state, categoryName ) => {\n\t\treturn Object.entries( state )\n\t\t\t.filter( ( [ , shortcut ] ) => shortcut.category === categoryName )\n\t\t\t.map( ( [ name ] ) => name );\n\t},\n\t( state ) => [ state ]\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,QAAQ,iBAAiB;AAChD,SACCC,eAAe,EACfC,iBAAiB,EACjBC,WAAW,QACL,qBAAqB;;AAE5B;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG;EAC1BC,OAAO,EAAEL,eAAe;EACxBM,GAAG,EAAEJ,WAAW;EAChBK,SAAS,EAAEN;AACZ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASO,+BAA+BA,CAAEC,QAAQ,EAAEC,cAAc,EAAG;EACpE,IAAK,CAAED,QAAQ,EAAG;IACjB,OAAO,IAAI;EACZ;EAEA,OAAOA,QAAQ,CAACE,QAAQ,GACrBP,kBAAkB,CAAEM,cAAc,CAAE,CAAED,QAAQ,CAACE,QAAQ,CAAE,CACzDF,QAAQ,CAACG,SACT,CAAC,GACDH,QAAQ,CAACG,SAAS;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CAAEC,KAAK,EAAEC,IAAI,EAAG;EACxD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACC,cAAc,GAAG,IAAI;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACxCH,KAAK,EACLC,IAAI,EACJL,cAAc,GAAG,SAAS,EACzB;EACD,MAAMD,QAAQ,GAAGI,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC;EACzD,OAAOP,+BAA+B,CAAEC,QAAQ,EAAEC,cAAe,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,sBAAsBA,CAAEJ,KAAK,EAAEC,IAAI,EAAG;EACrD,OAAOD,KAAK,CAAEC,IAAI,CAAE,GAAGD,KAAK,CAAEC,IAAI,CAAE,CAACI,WAAW,GAAG,IAAI;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAEN,KAAK,EAAEC,IAAI,EAAG;EACjD,OAAOD,KAAK,CAAEC,IAAI,CAAE,IAAID,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GAC1CP,KAAK,CAAEC,IAAI,CAAE,CAACM,OAAO,GACrBlB,WAAW;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMmB,6BAA6B,GAAGvB,cAAc,CAC1D,CAAEe,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAO,CACNF,yBAAyB,CAAEC,KAAK,EAAEC,IAAK,CAAC,EACxC,GAAGK,kBAAkB,CAAEN,KAAK,EAAEC,IAAK,CAAC,CACpC,CAACQ,MAAM,CAAEC,OAAQ,CAAC;AACpB,CAAC,EACD,CAAEV,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMU,gCAAgC,GAAG1B,cAAc,CAC7D,CAAEe,KAAK,EAAEC,IAAI,KAAM;EAClB,OAAOO,6BAA6B,CAAER,KAAK,EAAEC,IAAK,CAAC,CAACW,GAAG,CACpDC,WAAW,IACZnB,+BAA+B,CAAEmB,WAAW,EAAE,KAAM,CACtD,CAAC;AACF,CAAC,EACD,CAAEb,KAAK,EAAEC,IAAI,KAAM,CAAED,KAAK,CAAEC,IAAI,CAAE,CACnC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMa,oBAAoB,GAAG7B,cAAc,CACjD,CAAEe,KAAK,EAAEe,YAAY,KAAM;EAC1B,OAAOC,MAAM,CAACC,OAAO,CAAEjB,KAAM,CAAC,CAC5BS,MAAM,CAAE,CAAE,GAAId,QAAQ,CAAE,KAAMA,QAAQ,CAACuB,QAAQ,KAAKH,YAAa,CAAC,CAClEH,GAAG,CAAE,CAAE,CAAEX,IAAI,CAAE,KAAMA,IAAK,CAAC;AAC9B,CAAC,EACCD,KAAK,IAAM,CAAEA,KAAK,CACrB,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/keyboard-shortcuts",
3
- "version": "5.17.0",
3
+ "version": "5.19.0",
4
4
  "description": "Handling keyboard shortcuts.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -28,9 +28,9 @@
28
28
  "wpScript": true,
29
29
  "dependencies": {
30
30
  "@babel/runtime": "7.25.7",
31
- "@wordpress/data": "^10.17.0",
32
- "@wordpress/element": "^6.17.0",
33
- "@wordpress/keycodes": "^4.17.0"
31
+ "@wordpress/data": "^10.19.0",
32
+ "@wordpress/element": "^6.19.0",
33
+ "@wordpress/keycodes": "^4.19.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": "^18.0.0"
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "68a831c3178197fe87db284d4b94e5743bfb6b6c"
41
+ "gitHead": "d6b0b20fa927b110140dc7fdd906a7e0bf662004"
42
42
  }