{
  "version": 3,
  "sources": ["../../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,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAYP,IAAM,cAAc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