{
  "version": 3,
  "sources": ["../../src/store/selectors.ts"],
  "sourcesContent": ["import { createSelector } from '@wordpress/data';\nimport {\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n\trawShortcut,\n} from '@wordpress/keycodes';\nimport type { ShortcutKeyCombination } from './actions';\n\ninterface ShortcutState {\n\tcategory: string;\n\tkeyCombination: ShortcutKeyCombination;\n\taliases?: ShortcutKeyCombination[];\n\tdescription: string;\n}\n\ntype ShortcutsState = Record< string, ShortcutState >;\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 */\nconst EMPTY_ARRAY: ShortcutKeyCombination[] = [];\n\n/**\n * Shortcut formatting methods.\n */\nconst FORMATTING_METHODS = {\n\t/**\n\t * Display formatting.\n\t */\n\tdisplay: displayShortcut,\n\t/**\n\t * Raw shortcut formatting.\n\t */\n\traw: rawShortcut,\n\t/**\n\t * ARIA label formatting.\n\t */\n\tariaLabel: shortcutAriaLabel,\n};\n\n/**\n * Returns a string representing the key combination.\n *\n * @param shortcut       Key combination.\n * @param representation Type of representation\n *                       (display, raw, ariaLabel).\n *\n * @return Shortcut representation.\n */\nfunction getKeyCombinationRepresentation(\n\tshortcut: ShortcutKeyCombination | null,\n\trepresentation: keyof typeof FORMATTING_METHODS\n): string | null {\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 {ShortcutKeyCombination?} Key combination.\n */\nexport function getShortcutKeyCombination(\n\tstate: ShortcutsState,\n\tname: string\n): ShortcutKeyCombination | null {\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: ShortcutsState,\n\tname: string,\n\trepresentation: keyof typeof FORMATTING_METHODS = 'display'\n): string | null {\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(\n\tstate: ShortcutsState,\n\tname: string\n): string | null {\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 {ShortcutKeyCombination[]} Key combinations.\n */\nexport function getShortcutAliases(\n\tstate: ShortcutsState,\n\tname: string\n): ShortcutKeyCombination[] {\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 {ShortcutKeyCombination[]} 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(\n\t\t\t( combination ): combination is ShortcutKeyCombination =>\n\t\t\t\t!! combination\n\t\t);\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: ShortcutsState, categoryName: string ): string[] => {\n\t\treturn Object.entries< ShortcutState >( state )\n\t\t\t.filter( ( [ , shortcut ] ) => shortcut.category === categoryName )\n\t\t\t.map( ( [ name ] ) => name );\n\t},\n\t( state: ShortcutsState ) => [ state ]\n);\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+B;AAC/B,sBAIO;AAgBP,IAAM,cAAwC,CAAC;AAK/C,IAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA;AAAA;AAAA;AAAA,EAIT,KAAK;AAAA;AAAA;AAAA;AAAA,EAIL,WAAW;AACZ;AAWA,SAAS,gCACR,UACA,gBACgB;AAChB,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,SAAO,SAAS,WACb,mBAAoB,cAAe,EAAG,SAAS,QAAS;AAAA,IACxD,SAAS;AAAA,EACT,IACA,SAAS;AACb;AA2CO,SAAS,0BACf,OACA,MACgC;AAChC,SAAO,MAAO,IAAK,IAAI,MAAO,IAAK,EAAE,iBAAiB;AACvD;AAwCO,SAAS,0BACf,OACA,MACA,iBAAkD,WAClC;AAChB,QAAM,WAAW,0BAA2B,OAAO,IAAK;AACxD,SAAO,gCAAiC,UAAU,cAAe;AAClE;AA8BO,SAAS,uBACf,OACA,MACgB;AAChB,SAAO,MAAO,IAAK,IAAI,MAAO,IAAK,EAAE,cAAc;AACpD;AAgDO,SAAS,mBACf,OACA,MAC2B;AAC3B,SAAO,MAAO,IAAK,KAAK,MAAO,IAAK,EAAE,UACnC,MAAO,IAAK,EAAE,UACd;AACJ;AAmDO,IAAM,oCAAgC;AAAA,EAC5C,CAAE,OAAO,SAAU;AAClB,WAAO;AAAA,MACN,0BAA2B,OAAO,IAAK;AAAA,MACvC,GAAG,mBAAoB,OAAO,IAAK;AAAA,IACpC,EAAE;AAAA,MACD,CAAE,gBACD,CAAC,CAAE;AAAA,IACL;AAAA,EACD;AAAA,EACA,CAAE,OAAO,SAAU,CAAE,MAAO,IAAK,CAAE;AACpC;AAmDO,IAAM,uCAAmC;AAAA,EAC/C,CAAE,OAAO,SAAU;AAClB,WAAO,8BAA+B,OAAO,IAAK,EAAE;AAAA,MACnD,CAAE,gBACD,gCAAiC,aAAa,KAAM;AAAA,IACtD;AAAA,EACD;AAAA,EACA,CAAE,OAAO,SAAU,CAAE,MAAO,IAAK,CAAE;AACpC;AAmCO,IAAM,2BAAuB;AAAA,EACnC,CAAE,OAAuB,iBAAoC;AAC5D,WAAO,OAAO,QAA0B,KAAM,EAC5C,OAAQ,CAAE,CAAE,EAAE,QAAS,MAAO,SAAS,aAAa,YAAa,EACjE,IAAK,CAAE,CAAE,IAAK,MAAO,IAAK;AAAA,EAC7B;AAAA,EACA,CAAE,UAA2B,CAAE,KAAM;AACtC;",
  "names": []
}
