@wordpress/keyboard-shortcuts 4.13.0 → 4.14.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,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.14.0 (2023-07-05)
6
+
5
7
  ## 4.13.0 (2023-06-23)
6
8
 
7
9
  ## 4.12.0 (2023-06-07)
@@ -34,6 +34,44 @@ exports.unregisterShortcut = unregisterShortcut;
34
34
  *
35
35
  * @param {WPShortcutConfig} config Shortcut config.
36
36
  *
37
+ * @example
38
+ *
39
+ *```js
40
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
41
+ * import { useSelect, useDispatch } from '@wordpress/data';
42
+ * import { useEffect } from '@wordpress/element';
43
+ * import { __ } from '@wordpress/i18n';
44
+ *
45
+ * const ExampleComponent = () => {
46
+ * const { registerShortcut } = useDispatch( keyboardShortcutsStore );
47
+ *
48
+ * useEffect( () => {
49
+ * registerShortcut( {
50
+ * name: 'custom/my-custom-shortcut',
51
+ * category: 'my-category',
52
+ * description: __( 'My custom shortcut' ),
53
+ * keyCombination: {
54
+ * modifier: 'primary',
55
+ * character: 'j',
56
+ * },
57
+ * } );
58
+ * }, [] );
59
+ *
60
+ * const shortcut = useSelect(
61
+ * ( select ) =>
62
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
63
+ * 'custom/my-custom-shortcut'
64
+ * ),
65
+ * []
66
+ * );
67
+ *
68
+ * return shortcut ? (
69
+ * <p>{ __( 'Shortcut is registered.' ) }</p>
70
+ * ) : (
71
+ * <p>{ __( 'Shortcut is not registered.' ) }</p>
72
+ * );
73
+ * };
74
+ *```
37
75
  * @return {Object} action.
38
76
  */
39
77
  function registerShortcut({
@@ -57,6 +95,36 @@ function registerShortcut({
57
95
  *
58
96
  * @param {string} name Shortcut name.
59
97
  *
98
+ * @example
99
+ *
100
+ *```js
101
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
102
+ * import { useSelect, useDispatch } from '@wordpress/data';
103
+ * import { useEffect } from '@wordpress/element';
104
+ * import { __ } from '@wordpress/i18n';
105
+ *
106
+ * const ExampleComponent = () => {
107
+ * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
108
+ *
109
+ * useEffect( () => {
110
+ * unregisterShortcut( 'core/edit-post/next-region' );
111
+ * }, [] );
112
+ *
113
+ * const shortcut = useSelect(
114
+ * ( select ) =>
115
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
116
+ * 'core/edit-post/next-region'
117
+ * ),
118
+ * []
119
+ * );
120
+ *
121
+ * return shortcut ? (
122
+ * <p>{ __( 'Shortcut is not unregistered.' ) }</p>
123
+ * ) : (
124
+ * <p>{ __( 'Shortcut is unregistered.' ) }</p>
125
+ * );
126
+ * };
127
+ *```
60
128
  * @return {Object} action.
61
129
  */
62
130
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"mappings":";;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gBAAT,CAA2B;AACjCC,EAAAA,IADiC;AAEjCC,EAAAA,QAFiC;AAGjCC,EAAAA,WAHiC;AAIjCC,EAAAA,cAJiC;AAKjCC,EAAAA;AALiC,CAA3B,EAMH;AACH,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENL,IAAAA,IAFM;AAGNC,IAAAA,QAHM;AAINE,IAAAA,cAJM;AAKNC,IAAAA,OALM;AAMNF,IAAAA;AANM,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,kBAAT,CAA6BN,IAA7B,EAAoC;AAC1C,SAAO;AACNK,IAAAA,IAAI,EAAE,qBADA;AAENL,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"mappings":";;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;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;AACO,SAASA,gBAAT,CAA2B;AACjCC,EAAAA,IADiC;AAEjCC,EAAAA,QAFiC;AAGjCC,EAAAA,WAHiC;AAIjCC,EAAAA,cAJiC;AAKjCC,EAAAA;AALiC,CAA3B,EAMH;AACH,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENL,IAAAA,IAFM;AAGNC,IAAAA,QAHM;AAINE,IAAAA,cAJM;AAKNC,IAAAA,OALM;AAMNF,IAAAA;AANM,GAAP;AAQA;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;;;AACO,SAASI,kBAAT,CAA6BN,IAA7B,EAAoC;AAC1C,SAAO;AACNK,IAAAA,IAAI,EAAE,qBADA;AAENL,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { registerShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * registerShortcut( {\n * name: 'custom/my-custom-shortcut',\n * category: 'my-category',\n * description: __( 'My custom shortcut' ),\n * keyCombination: {\n * modifier: 'primary',\n * character: 'j',\n * },\n * } );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'custom/my-custom-shortcut'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is registered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is not registered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * unregisterShortcut( 'core/edit-post/next-region' );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/edit-post/next-region'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is not unregistered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is unregistered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"]}
@@ -70,6 +70,39 @@ function getKeyCombinationRepresentation(shortcut, representation) {
70
70
  * @param {Object} state Global state.
71
71
  * @param {string} name Shortcut name.
72
72
  *
73
+ * @example
74
+ *
75
+ *```js
76
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
77
+ * import { useSelect } from '@wordpress/data';
78
+ * import { createInterpolateElement } from '@wordpress/element';
79
+ * import { sprintf } from '@wordpress/i18n';
80
+ * const ExampleComponent = () => {
81
+ * const {character, modifier} = useSelect(
82
+ * ( select ) =>
83
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
84
+ * 'core/edit-post/next-region'
85
+ * ),
86
+ * []
87
+ * );
88
+ *
89
+ * return (
90
+ * <div>
91
+ * { createInterpolateElement(
92
+ * sprintf(
93
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
94
+ * character,
95
+ * modifier
96
+ * ),
97
+ * {
98
+ * code: <code />,
99
+ * }
100
+ * ) }
101
+ * </div>
102
+ * );
103
+ * };
104
+ *```
105
+ *
73
106
  * @return {WPShortcutKeyCombination?} Key combination.
74
107
  */
75
108
 
@@ -84,6 +117,34 @@ function getShortcutKeyCombination(state, name) {
84
117
  * @param {string} name Shortcut name.
85
118
  * @param {keyof FORMATTING_METHODS} representation Type of representation
86
119
  * (display, raw, ariaLabel).
120
+ * @example
121
+ *
122
+ *```js
123
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
124
+ * import { useSelect } from '@wordpress/data';
125
+ * import { sprintf } from '@wordpress/i18n';
126
+ *
127
+ * const ExampleComponent = () => {
128
+ * const {display, raw, ariaLabel} = useSelect(
129
+ * ( select ) =>{
130
+ * return {
131
+ * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region' ),
132
+ * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ),
133
+ * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region', 'ariaLabel')
134
+ * }
135
+ * },
136
+ * []
137
+ * );
138
+ *
139
+ * return (
140
+ * <ul>
141
+ * <li>{ sprintf( 'display string: %s', display ) }</li>
142
+ * <li>{ sprintf( 'raw string: %s', raw ) }</li>
143
+ * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>
144
+ * </ul>
145
+ * );
146
+ * };
147
+ *```
87
148
  *
88
149
  * @return {string?} Shortcut representation.
89
150
  */
@@ -99,6 +160,26 @@ function getShortcutRepresentation(state, name, representation = 'display') {
99
160
  * @param {Object} state Global state.
100
161
  * @param {string} name Shortcut name.
101
162
  *
163
+ * @example
164
+ *
165
+ *```js
166
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
167
+ * import { useSelect } from '@wordpress/data';
168
+ * import { __ } from '@wordpress/i18n';
169
+ * const ExampleComponent = () => {
170
+ * const shortcutDescription = useSelect(
171
+ * ( select ) =>
172
+ * select( keyboardShortcutsStore ).getShortcutDescription( 'core/edit-post/next-region' ),
173
+ * []
174
+ * );
175
+ *
176
+ * return shortcutDescription ? (
177
+ * <div>{ shortcutDescription }</div>
178
+ * ) : (
179
+ * <div>{ __( 'No description.' ) }</div>
180
+ * );
181
+ * };
182
+ *```
102
183
  * @return {string?} Shortcut description.
103
184
  */
104
185
 
@@ -111,6 +192,44 @@ function getShortcutDescription(state, name) {
111
192
  *
112
193
  * @param {Object} state Global state.
113
194
  * @param {string} name Shortcut name.
195
+ * @example
196
+ *
197
+ *```js
198
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
199
+ * import { useSelect } from '@wordpress/data';
200
+ * import { createInterpolateElement } from '@wordpress/element';
201
+ * import { sprintf } from '@wordpress/i18n';
202
+ * const ExampleComponent = () => {
203
+ * const shortcutAliases = useSelect(
204
+ * ( select ) =>
205
+ * select( keyboardShortcutsStore ).getShortcutAliases(
206
+ * 'core/edit-post/next-region'
207
+ * ),
208
+ * []
209
+ * );
210
+ *
211
+ * return (
212
+ * shortcutAliases.length > 0 && (
213
+ * <ul>
214
+ * { shortcutAliases.map( ( { character, modifier }, index ) => (
215
+ * <li key={ index }>
216
+ * { createInterpolateElement(
217
+ * sprintf(
218
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
219
+ * character,
220
+ * modifier
221
+ * ),
222
+ * {
223
+ * code: <code />,
224
+ * }
225
+ * ) }
226
+ * </li>
227
+ * ) ) }
228
+ * </ul>
229
+ * )
230
+ * );
231
+ * };
232
+ *```
114
233
  *
115
234
  * @return {WPShortcutKeyCombination[]} Key combinations.
116
235
  */
@@ -119,6 +238,56 @@ function getShortcutDescription(state, name) {
119
238
  function getShortcutAliases(state, name) {
120
239
  return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
121
240
  }
241
+ /**
242
+ * Returns the shortcuts that include aliases for a given shortcut name.
243
+ *
244
+ * @param {Object} state Global state.
245
+ * @param {string} name Shortcut name.
246
+ * @example
247
+ *
248
+ *```js
249
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
250
+ * import { useSelect } from '@wordpress/data';
251
+ * import { createInterpolateElement } from '@wordpress/element';
252
+ * import { sprintf } from '@wordpress/i18n';
253
+ *
254
+ * const ExampleComponent = () => {
255
+ * const allShortcutKeyCombinations = useSelect(
256
+ * ( select ) =>
257
+ * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
258
+ * 'core/edit-post/next-region'
259
+ * ),
260
+ * []
261
+ * );
262
+ *
263
+ * return (
264
+ * allShortcutKeyCombinations.length > 0 && (
265
+ * <ul>
266
+ * { allShortcutKeyCombinations.map(
267
+ * ( { character, modifier }, index ) => (
268
+ * <li key={ index }>
269
+ * { createInterpolateElement(
270
+ * sprintf(
271
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
272
+ * character,
273
+ * modifier
274
+ * ),
275
+ * {
276
+ * code: <code />,
277
+ * }
278
+ * ) }
279
+ * </li>
280
+ * )
281
+ * ) }
282
+ * </ul>
283
+ * )
284
+ * );
285
+ * };
286
+ *```
287
+ *
288
+ * @return {WPShortcutKeyCombination[]} Key combinations.
289
+ */
290
+
122
291
 
123
292
  const getAllShortcutKeyCombinations = (0, _rememo.default)((state, name) => {
124
293
  return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean);
@@ -129,6 +298,47 @@ const getAllShortcutKeyCombinations = (0, _rememo.default)((state, name) => {
129
298
  * @param {Object} state Global state.
130
299
  * @param {string} name Shortcut name.
131
300
  *
301
+ * @example
302
+ *
303
+ *```js
304
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
305
+ * import { useSelect } from '@wordpress/data';
306
+ * import { createInterpolateElement } from '@wordpress/element';
307
+ * import { sprintf } from '@wordpress/i18n';
308
+ *
309
+ * const ExampleComponent = () => {
310
+ * const allShortcutRawKeyCombinations = useSelect(
311
+ * ( select ) =>
312
+ * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
313
+ * 'core/edit-post/next-region'
314
+ * ),
315
+ * []
316
+ * );
317
+ *
318
+ * return (
319
+ * allShortcutRawKeyCombinations.length > 0 && (
320
+ * <ul>
321
+ * { allShortcutRawKeyCombinations.map(
322
+ * ( shortcutRawKeyCombination, index ) => (
323
+ * <li key={ index }>
324
+ * { createInterpolateElement(
325
+ * sprintf(
326
+ * ' <code>%s</code>',
327
+ * shortcutRawKeyCombination
328
+ * ),
329
+ * {
330
+ * code: <code />,
331
+ * }
332
+ * ) }
333
+ * </li>
334
+ * )
335
+ * ) }
336
+ * </ul>
337
+ * )
338
+ * );
339
+ * };
340
+ *```
341
+ *
132
342
  * @return {string[]} Shortcuts.
133
343
  */
134
344
 
@@ -141,7 +351,32 @@ const getAllShortcutRawKeyCombinations = (0, _rememo.default)((state, name) => {
141
351
  *
142
352
  * @param {Object} state Global state.
143
353
  * @param {string} name Category name.
354
+ * @example
355
+ *
356
+ *```js
357
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
358
+ * import { useSelect } from '@wordpress/data';
359
+ *
360
+ * const ExampleComponent = () => {
361
+ * const categoryShortcuts = useSelect(
362
+ * ( select ) =>
363
+ * select( keyboardShortcutsStore ).getCategoryShortcuts(
364
+ * 'block'
365
+ * ),
366
+ * []
367
+ * );
144
368
  *
369
+ * return (
370
+ * categoryShortcuts.length > 0 && (
371
+ * <ul>
372
+ * { categoryShortcuts.map( ( categoryShortcut ) => (
373
+ * <li key={ categoryShortcut }>{ categoryShortcut }</li>
374
+ * ) ) }
375
+ * </ul>
376
+ * )
377
+ * );
378
+ * };
379
+ *```
145
380
  * @return {string[]} Shortcut names.
146
381
  */
147
382
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"names":["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","filter","Boolean","getAllShortcutRawKeyCombinations","map","combination","getCategoryShortcuts","categoryName","Object","entries","category"],"mappings":"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","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\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 * @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 *\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 * @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 *\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\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 * @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 *\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"]}
1
+ {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"names":["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","filter","Boolean","getAllShortcutRawKeyCombinations","map","combination","getCategoryShortcuts","categoryName","Object","entries","category"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,kBAAkB,GAAG;AAC1BC,EAAAA,OAAO,EAAEC,yBADiB;AAE1BC,EAAAA,GAAG,EAAEC,qBAFqB;AAG1BC,EAAAA,SAAS,EAAEC;AAHe,CAA3B;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,+BAAT,CAA0CC,QAA1C,EAAoDC,cAApD,EAAqE;AACpE,MAAK,CAAED,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SAAOA,QAAQ,CAACE,QAAT,GACJV,kBAAkB,CAAES,cAAF,CAAlB,CAAsCD,QAAQ,CAACE,QAA/C,EACAF,QAAQ,CAACG,SADT,CADI,GAIJH,QAAQ,CAACG,SAJZ;AAKA;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;;;AACO,SAASC,yBAAT,CAAoCC,KAApC,EAA2CC,IAA3C,EAAkD;AACxD,SAAOD,KAAK,CAAEC,IAAF,CAAL,GAAgBD,KAAK,CAAEC,IAAF,CAAL,CAAcC,cAA9B,GAA+C,IAAtD;AACA;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;;;AACO,SAASC,yBAAT,CACNH,KADM,EAENC,IAFM,EAGNL,cAAc,GAAG,SAHX,EAIL;AACD,QAAMD,QAAQ,GAAGI,yBAAyB,CAAEC,KAAF,EAASC,IAAT,CAA1C;AACA,SAAOP,+BAA+B,CAAEC,QAAF,EAAYC,cAAZ,CAAtC;AACA;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;;;AACO,SAASQ,sBAAT,CAAiCJ,KAAjC,EAAwCC,IAAxC,EAA+C;AACrD,SAAOD,KAAK,CAAEC,IAAF,CAAL,GAAgBD,KAAK,CAAEC,IAAF,CAAL,CAAcI,WAA9B,GAA4C,IAAnD;AACA;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;;;AACO,SAASC,kBAAT,CAA6BN,KAA7B,EAAoCC,IAApC,EAA2C;AACjD,SAAOD,KAAK,CAAEC,IAAF,CAAL,IAAiBD,KAAK,CAAEC,IAAF,CAAL,CAAcM,OAA/B,GACJP,KAAK,CAAEC,IAAF,CAAL,CAAcM,OADV,GAEJrB,WAFH;AAGA;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,MAAMsB,6BAA6B,GAAG,qBAC5C,CAAER,KAAF,EAASC,IAAT,KAAmB;AAClB,SAAO,CACNF,yBAAyB,CAAEC,KAAF,EAASC,IAAT,CADnB,EAEN,GAAGK,kBAAkB,CAAEN,KAAF,EAASC,IAAT,CAFf,EAGLQ,MAHK,CAGGC,OAHH,CAAP;AAIA,CAN2C,EAO5C,CAAEV,KAAF,EAASC,IAAT,KAAmB,CAAED,KAAK,CAAEC,IAAF,CAAP,CAPyB,CAAtC;AAUP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,MAAMU,gCAAgC,GAAG,qBAC/C,CAAEX,KAAF,EAASC,IAAT,KAAmB;AAClB,SAAOO,6BAA6B,CAAER,KAAF,EAASC,IAAT,CAA7B,CAA6CW,GAA7C,CACJC,WAAF,IACCnB,+BAA+B,CAAEmB,WAAF,EAAe,KAAf,CAF1B,CAAP;AAIA,CAN8C,EAO/C,CAAEb,KAAF,EAASC,IAAT,KAAmB,CAAED,KAAK,CAAEC,IAAF,CAAP,CAP4B,CAAzC;AAUP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,MAAMa,oBAAoB,GAAG,qBACnC,CAAEd,KAAF,EAASe,YAAT,KAA2B;AAC1B,SAAOC,MAAM,CAACC,OAAP,CAAgBjB,KAAhB,EACLS,MADK,CACG,CAAE,GAAId,QAAJ,CAAF,KAAsBA,QAAQ,CAACuB,QAAT,KAAsBH,YAD/C,EAELH,GAFK,CAEA,CAAE,CAAEX,IAAF,CAAF,KAAgBA,IAFhB,CAAP;AAGA,CALkC,EAMjCD,KAAF,IAAa,CAAEA,KAAF,CANsB,CAA7B","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\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/edit-post/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/edit-post/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/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/edit-post/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/edit-post/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/edit-post/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/edit-post/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"]}
@@ -26,6 +26,44 @@
26
26
  *
27
27
  * @param {WPShortcutConfig} config Shortcut config.
28
28
  *
29
+ * @example
30
+ *
31
+ *```js
32
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
33
+ * import { useSelect, useDispatch } from '@wordpress/data';
34
+ * import { useEffect } from '@wordpress/element';
35
+ * import { __ } from '@wordpress/i18n';
36
+ *
37
+ * const ExampleComponent = () => {
38
+ * const { registerShortcut } = useDispatch( keyboardShortcutsStore );
39
+ *
40
+ * useEffect( () => {
41
+ * registerShortcut( {
42
+ * name: 'custom/my-custom-shortcut',
43
+ * category: 'my-category',
44
+ * description: __( 'My custom shortcut' ),
45
+ * keyCombination: {
46
+ * modifier: 'primary',
47
+ * character: 'j',
48
+ * },
49
+ * } );
50
+ * }, [] );
51
+ *
52
+ * const shortcut = useSelect(
53
+ * ( select ) =>
54
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
55
+ * 'custom/my-custom-shortcut'
56
+ * ),
57
+ * []
58
+ * );
59
+ *
60
+ * return shortcut ? (
61
+ * <p>{ __( 'Shortcut is registered.' ) }</p>
62
+ * ) : (
63
+ * <p>{ __( 'Shortcut is not registered.' ) }</p>
64
+ * );
65
+ * };
66
+ *```
29
67
  * @return {Object} action.
30
68
  */
31
69
  export function registerShortcut({
@@ -49,6 +87,36 @@ export function registerShortcut({
49
87
  *
50
88
  * @param {string} name Shortcut name.
51
89
  *
90
+ * @example
91
+ *
92
+ *```js
93
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
94
+ * import { useSelect, useDispatch } from '@wordpress/data';
95
+ * import { useEffect } from '@wordpress/element';
96
+ * import { __ } from '@wordpress/i18n';
97
+ *
98
+ * const ExampleComponent = () => {
99
+ * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
100
+ *
101
+ * useEffect( () => {
102
+ * unregisterShortcut( 'core/edit-post/next-region' );
103
+ * }, [] );
104
+ *
105
+ * const shortcut = useSelect(
106
+ * ( select ) =>
107
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
108
+ * 'core/edit-post/next-region'
109
+ * ),
110
+ * []
111
+ * );
112
+ *
113
+ * return shortcut ? (
114
+ * <p>{ __( 'Shortcut is not unregistered.' ) }</p>
115
+ * ) : (
116
+ * <p>{ __( 'Shortcut is unregistered.' ) }</p>
117
+ * );
118
+ * };
119
+ *```
52
120
  * @return {Object} action.
53
121
  */
54
122
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,gBAAT,CAA2B;AACjCC,EAAAA,IADiC;AAEjCC,EAAAA,QAFiC;AAGjCC,EAAAA,WAHiC;AAIjCC,EAAAA,cAJiC;AAKjCC,EAAAA;AALiC,CAA3B,EAMH;AACH,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENL,IAAAA,IAFM;AAGNC,IAAAA,QAHM;AAINE,IAAAA,cAJM;AAKNC,IAAAA,OALM;AAMNF,IAAAA;AANM,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,kBAAT,CAA6BN,IAA7B,EAAoC;AAC1C,SAAO;AACNK,IAAAA,IAAI,EAAE,qBADA;AAENL,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;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,OAAO,SAASA,gBAAT,CAA2B;AACjCC,EAAAA,IADiC;AAEjCC,EAAAA,QAFiC;AAGjCC,EAAAA,WAHiC;AAIjCC,EAAAA,cAJiC;AAKjCC,EAAAA;AALiC,CAA3B,EAMH;AACH,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENL,IAAAA,IAFM;AAGNC,IAAAA,QAHM;AAINE,IAAAA,cAJM;AAKNC,IAAAA,OALM;AAMNF,IAAAA;AANM,GAAP;AAQA;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,OAAO,SAASI,kBAAT,CAA6BN,IAA7B,EAAoC;AAC1C,SAAO;AACNK,IAAAA,IAAI,EAAE,qBADA;AAENL,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { registerShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * registerShortcut( {\n * name: 'custom/my-custom-shortcut',\n * category: 'my-category',\n * description: __( 'My custom shortcut' ),\n * keyCombination: {\n * modifier: 'primary',\n * character: 'j',\n * },\n * } );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'custom/my-custom-shortcut'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is registered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is not registered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * unregisterShortcut( 'core/edit-post/next-region' );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/edit-post/next-region'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is not unregistered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is unregistered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"]}
@@ -55,6 +55,39 @@ function getKeyCombinationRepresentation(shortcut, representation) {
55
55
  * @param {Object} state Global state.
56
56
  * @param {string} name Shortcut name.
57
57
  *
58
+ * @example
59
+ *
60
+ *```js
61
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
62
+ * import { useSelect } from '@wordpress/data';
63
+ * import { createInterpolateElement } from '@wordpress/element';
64
+ * import { sprintf } from '@wordpress/i18n';
65
+ * const ExampleComponent = () => {
66
+ * const {character, modifier} = useSelect(
67
+ * ( select ) =>
68
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
69
+ * 'core/edit-post/next-region'
70
+ * ),
71
+ * []
72
+ * );
73
+ *
74
+ * return (
75
+ * <div>
76
+ * { createInterpolateElement(
77
+ * sprintf(
78
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
79
+ * character,
80
+ * modifier
81
+ * ),
82
+ * {
83
+ * code: <code />,
84
+ * }
85
+ * ) }
86
+ * </div>
87
+ * );
88
+ * };
89
+ *```
90
+ *
58
91
  * @return {WPShortcutKeyCombination?} Key combination.
59
92
  */
60
93
 
@@ -69,6 +102,34 @@ export function getShortcutKeyCombination(state, name) {
69
102
  * @param {string} name Shortcut name.
70
103
  * @param {keyof FORMATTING_METHODS} representation Type of representation
71
104
  * (display, raw, ariaLabel).
105
+ * @example
106
+ *
107
+ *```js
108
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
109
+ * import { useSelect } from '@wordpress/data';
110
+ * import { sprintf } from '@wordpress/i18n';
111
+ *
112
+ * const ExampleComponent = () => {
113
+ * const {display, raw, ariaLabel} = useSelect(
114
+ * ( select ) =>{
115
+ * return {
116
+ * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region' ),
117
+ * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ),
118
+ * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region', 'ariaLabel')
119
+ * }
120
+ * },
121
+ * []
122
+ * );
123
+ *
124
+ * return (
125
+ * <ul>
126
+ * <li>{ sprintf( 'display string: %s', display ) }</li>
127
+ * <li>{ sprintf( 'raw string: %s', raw ) }</li>
128
+ * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>
129
+ * </ul>
130
+ * );
131
+ * };
132
+ *```
72
133
  *
73
134
  * @return {string?} Shortcut representation.
74
135
  */
@@ -83,6 +144,26 @@ export function getShortcutRepresentation(state, name, representation = 'display
83
144
  * @param {Object} state Global state.
84
145
  * @param {string} name Shortcut name.
85
146
  *
147
+ * @example
148
+ *
149
+ *```js
150
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
151
+ * import { useSelect } from '@wordpress/data';
152
+ * import { __ } from '@wordpress/i18n';
153
+ * const ExampleComponent = () => {
154
+ * const shortcutDescription = useSelect(
155
+ * ( select ) =>
156
+ * select( keyboardShortcutsStore ).getShortcutDescription( 'core/edit-post/next-region' ),
157
+ * []
158
+ * );
159
+ *
160
+ * return shortcutDescription ? (
161
+ * <div>{ shortcutDescription }</div>
162
+ * ) : (
163
+ * <div>{ __( 'No description.' ) }</div>
164
+ * );
165
+ * };
166
+ *```
86
167
  * @return {string?} Shortcut description.
87
168
  */
88
169
 
@@ -94,6 +175,44 @@ export function getShortcutDescription(state, name) {
94
175
  *
95
176
  * @param {Object} state Global state.
96
177
  * @param {string} name Shortcut name.
178
+ * @example
179
+ *
180
+ *```js
181
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
182
+ * import { useSelect } from '@wordpress/data';
183
+ * import { createInterpolateElement } from '@wordpress/element';
184
+ * import { sprintf } from '@wordpress/i18n';
185
+ * const ExampleComponent = () => {
186
+ * const shortcutAliases = useSelect(
187
+ * ( select ) =>
188
+ * select( keyboardShortcutsStore ).getShortcutAliases(
189
+ * 'core/edit-post/next-region'
190
+ * ),
191
+ * []
192
+ * );
193
+ *
194
+ * return (
195
+ * shortcutAliases.length > 0 && (
196
+ * <ul>
197
+ * { shortcutAliases.map( ( { character, modifier }, index ) => (
198
+ * <li key={ index }>
199
+ * { createInterpolateElement(
200
+ * sprintf(
201
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
202
+ * character,
203
+ * modifier
204
+ * ),
205
+ * {
206
+ * code: <code />,
207
+ * }
208
+ * ) }
209
+ * </li>
210
+ * ) ) }
211
+ * </ul>
212
+ * )
213
+ * );
214
+ * };
215
+ *```
97
216
  *
98
217
  * @return {WPShortcutKeyCombination[]} Key combinations.
99
218
  */
@@ -101,6 +220,56 @@ export function getShortcutDescription(state, name) {
101
220
  export function getShortcutAliases(state, name) {
102
221
  return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
103
222
  }
223
+ /**
224
+ * Returns the shortcuts that include aliases for a given shortcut name.
225
+ *
226
+ * @param {Object} state Global state.
227
+ * @param {string} name Shortcut name.
228
+ * @example
229
+ *
230
+ *```js
231
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
232
+ * import { useSelect } from '@wordpress/data';
233
+ * import { createInterpolateElement } from '@wordpress/element';
234
+ * import { sprintf } from '@wordpress/i18n';
235
+ *
236
+ * const ExampleComponent = () => {
237
+ * const allShortcutKeyCombinations = useSelect(
238
+ * ( select ) =>
239
+ * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
240
+ * 'core/edit-post/next-region'
241
+ * ),
242
+ * []
243
+ * );
244
+ *
245
+ * return (
246
+ * allShortcutKeyCombinations.length > 0 && (
247
+ * <ul>
248
+ * { allShortcutKeyCombinations.map(
249
+ * ( { character, modifier }, index ) => (
250
+ * <li key={ index }>
251
+ * { createInterpolateElement(
252
+ * sprintf(
253
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
254
+ * character,
255
+ * modifier
256
+ * ),
257
+ * {
258
+ * code: <code />,
259
+ * }
260
+ * ) }
261
+ * </li>
262
+ * )
263
+ * ) }
264
+ * </ul>
265
+ * )
266
+ * );
267
+ * };
268
+ *```
269
+ *
270
+ * @return {WPShortcutKeyCombination[]} Key combinations.
271
+ */
272
+
104
273
  export const getAllShortcutKeyCombinations = createSelector((state, name) => {
105
274
  return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean);
106
275
  }, (state, name) => [state[name]]);
@@ -110,6 +279,47 @@ export const getAllShortcutKeyCombinations = createSelector((state, name) => {
110
279
  * @param {Object} state Global state.
111
280
  * @param {string} name Shortcut name.
112
281
  *
282
+ * @example
283
+ *
284
+ *```js
285
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
286
+ * import { useSelect } from '@wordpress/data';
287
+ * import { createInterpolateElement } from '@wordpress/element';
288
+ * import { sprintf } from '@wordpress/i18n';
289
+ *
290
+ * const ExampleComponent = () => {
291
+ * const allShortcutRawKeyCombinations = useSelect(
292
+ * ( select ) =>
293
+ * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
294
+ * 'core/edit-post/next-region'
295
+ * ),
296
+ * []
297
+ * );
298
+ *
299
+ * return (
300
+ * allShortcutRawKeyCombinations.length > 0 && (
301
+ * <ul>
302
+ * { allShortcutRawKeyCombinations.map(
303
+ * ( shortcutRawKeyCombination, index ) => (
304
+ * <li key={ index }>
305
+ * { createInterpolateElement(
306
+ * sprintf(
307
+ * ' <code>%s</code>',
308
+ * shortcutRawKeyCombination
309
+ * ),
310
+ * {
311
+ * code: <code />,
312
+ * }
313
+ * ) }
314
+ * </li>
315
+ * )
316
+ * ) }
317
+ * </ul>
318
+ * )
319
+ * );
320
+ * };
321
+ *```
322
+ *
113
323
  * @return {string[]} Shortcuts.
114
324
  */
115
325
 
@@ -121,7 +331,32 @@ export const getAllShortcutRawKeyCombinations = createSelector((state, name) =>
121
331
  *
122
332
  * @param {Object} state Global state.
123
333
  * @param {string} name Category name.
334
+ * @example
335
+ *
336
+ *```js
337
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
338
+ * import { useSelect } from '@wordpress/data';
339
+ *
340
+ * const ExampleComponent = () => {
341
+ * const categoryShortcuts = useSelect(
342
+ * ( select ) =>
343
+ * select( keyboardShortcutsStore ).getCategoryShortcuts(
344
+ * 'block'
345
+ * ),
346
+ * []
347
+ * );
124
348
  *
349
+ * return (
350
+ * categoryShortcuts.length > 0 && (
351
+ * <ul>
352
+ * { categoryShortcuts.map( ( categoryShortcut ) => (
353
+ * <li key={ categoryShortcut }>{ categoryShortcut }</li>
354
+ * ) ) }
355
+ * </ul>
356
+ * )
357
+ * );
358
+ * };
359
+ *```
125
360
  * @return {string[]} Shortcut names.
126
361
  */
127
362
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"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"],"mappings":"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","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\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 * @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 *\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 * @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 *\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\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 * @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 *\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"]}
1
+ {"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,QAA3B;AAEA;AACA;AACA;;AACA,SACCC,eADD,EAECC,iBAFD,EAGCC,WAHD,QAIO,qBAJP;AAMA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,kBAAkB,GAAG;AAC1BC,EAAAA,OAAO,EAAEL,eADiB;AAE1BM,EAAAA,GAAG,EAAEJ,WAFqB;AAG1BK,EAAAA,SAAS,EAAEN;AAHe,CAA3B;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASO,+BAAT,CAA0CC,QAA1C,EAAoDC,cAApD,EAAqE;AACpE,MAAK,CAAED,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SAAOA,QAAQ,CAACE,QAAT,GACJP,kBAAkB,CAAEM,cAAF,CAAlB,CAAsCD,QAAQ,CAACE,QAA/C,EACAF,QAAQ,CAACG,SADT,CADI,GAIJH,QAAQ,CAACG,SAJZ;AAKA;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,OAAO,SAASC,yBAAT,CAAoCC,KAApC,EAA2CC,IAA3C,EAAkD;AACxD,SAAOD,KAAK,CAAEC,IAAF,CAAL,GAAgBD,KAAK,CAAEC,IAAF,CAAL,CAAcC,cAA9B,GAA+C,IAAtD;AACA;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,OAAO,SAASC,yBAAT,CACNH,KADM,EAENC,IAFM,EAGNL,cAAc,GAAG,SAHX,EAIL;AACD,QAAMD,QAAQ,GAAGI,yBAAyB,CAAEC,KAAF,EAASC,IAAT,CAA1C;AACA,SAAOP,+BAA+B,CAAEC,QAAF,EAAYC,cAAZ,CAAtC;AACA;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,OAAO,SAASQ,sBAAT,CAAiCJ,KAAjC,EAAwCC,IAAxC,EAA+C;AACrD,SAAOD,KAAK,CAAEC,IAAF,CAAL,GAAgBD,KAAK,CAAEC,IAAF,CAAL,CAAcI,WAA9B,GAA4C,IAAnD;AACA;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,OAAO,SAASC,kBAAT,CAA6BN,KAA7B,EAAoCC,IAApC,EAA2C;AACjD,SAAOD,KAAK,CAAEC,IAAF,CAAL,IAAiBD,KAAK,CAAEC,IAAF,CAAL,CAAcM,OAA/B,GACJP,KAAK,CAAEC,IAAF,CAAL,CAAcM,OADV,GAEJlB,WAFH;AAGA;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,MAAMmB,6BAA6B,GAAGvB,cAAc,CAC1D,CAAEe,KAAF,EAASC,IAAT,KAAmB;AAClB,SAAO,CACNF,yBAAyB,CAAEC,KAAF,EAASC,IAAT,CADnB,EAEN,GAAGK,kBAAkB,CAAEN,KAAF,EAASC,IAAT,CAFf,EAGLQ,MAHK,CAGGC,OAHH,CAAP;AAIA,CANyD,EAO1D,CAAEV,KAAF,EAASC,IAAT,KAAmB,CAAED,KAAK,CAAEC,IAAF,CAAP,CAPuC,CAApD;AAUP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,KAAF,EAASC,IAAT,KAAmB;AAClB,SAAOO,6BAA6B,CAAER,KAAF,EAASC,IAAT,CAA7B,CAA6CW,GAA7C,CACJC,WAAF,IACCnB,+BAA+B,CAAEmB,WAAF,EAAe,KAAf,CAF1B,CAAP;AAIA,CAN4D,EAO7D,CAAEb,KAAF,EAASC,IAAT,KAAmB,CAAED,KAAK,CAAEC,IAAF,CAAP,CAP0C,CAAvD;AAUP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,KAAF,EAASe,YAAT,KAA2B;AAC1B,SAAOC,MAAM,CAACC,OAAP,CAAgBjB,KAAhB,EACLS,MADK,CACG,CAAE,GAAId,QAAJ,CAAF,KAAsBA,QAAQ,CAACuB,QAAT,KAAsBH,YAD/C,EAELH,GAFK,CAEA,CAAE,CAAEX,IAAF,CAAF,KAAgBA,IAFhB,CAAP;AAGA,CALgD,EAM/CD,KAAF,IAAa,CAAEA,KAAF,CANoC,CAA3C","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\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/edit-post/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/edit-post/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/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/edit-post/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/edit-post/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/edit-post/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/edit-post/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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/keyboard-shortcuts",
3
- "version": "4.13.0",
3
+ "version": "4.14.0",
4
4
  "description": "Handling keyboard shortcuts.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,9 +26,9 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/data": "^9.6.0",
30
- "@wordpress/element": "^5.13.0",
31
- "@wordpress/keycodes": "^3.36.0",
29
+ "@wordpress/data": "^9.7.0",
30
+ "@wordpress/element": "^5.14.0",
31
+ "@wordpress/keycodes": "^3.37.0",
32
32
  "rememo": "^4.0.2"
33
33
  },
34
34
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "d47d8069e1aae05d4a16dc287902eb90edcbff50"
40
+ "gitHead": "bcd13d59b22553b3c9dc5869077bff1e864cf9f5"
41
41
  }
@@ -26,6 +26,44 @@
26
26
  *
27
27
  * @param {WPShortcutConfig} config Shortcut config.
28
28
  *
29
+ * @example
30
+ *
31
+ *```js
32
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
33
+ * import { useSelect, useDispatch } from '@wordpress/data';
34
+ * import { useEffect } from '@wordpress/element';
35
+ * import { __ } from '@wordpress/i18n';
36
+ *
37
+ * const ExampleComponent = () => {
38
+ * const { registerShortcut } = useDispatch( keyboardShortcutsStore );
39
+ *
40
+ * useEffect( () => {
41
+ * registerShortcut( {
42
+ * name: 'custom/my-custom-shortcut',
43
+ * category: 'my-category',
44
+ * description: __( 'My custom shortcut' ),
45
+ * keyCombination: {
46
+ * modifier: 'primary',
47
+ * character: 'j',
48
+ * },
49
+ * } );
50
+ * }, [] );
51
+ *
52
+ * const shortcut = useSelect(
53
+ * ( select ) =>
54
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
55
+ * 'custom/my-custom-shortcut'
56
+ * ),
57
+ * []
58
+ * );
59
+ *
60
+ * return shortcut ? (
61
+ * <p>{ __( 'Shortcut is registered.' ) }</p>
62
+ * ) : (
63
+ * <p>{ __( 'Shortcut is not registered.' ) }</p>
64
+ * );
65
+ * };
66
+ *```
29
67
  * @return {Object} action.
30
68
  */
31
69
  export function registerShortcut( {
@@ -50,6 +88,36 @@ export function registerShortcut( {
50
88
  *
51
89
  * @param {string} name Shortcut name.
52
90
  *
91
+ * @example
92
+ *
93
+ *```js
94
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
95
+ * import { useSelect, useDispatch } from '@wordpress/data';
96
+ * import { useEffect } from '@wordpress/element';
97
+ * import { __ } from '@wordpress/i18n';
98
+ *
99
+ * const ExampleComponent = () => {
100
+ * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
101
+ *
102
+ * useEffect( () => {
103
+ * unregisterShortcut( 'core/edit-post/next-region' );
104
+ * }, [] );
105
+ *
106
+ * const shortcut = useSelect(
107
+ * ( select ) =>
108
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
109
+ * 'core/edit-post/next-region'
110
+ * ),
111
+ * []
112
+ * );
113
+ *
114
+ * return shortcut ? (
115
+ * <p>{ __( 'Shortcut is not unregistered.' ) }</p>
116
+ * ) : (
117
+ * <p>{ __( 'Shortcut is unregistered.' ) }</p>
118
+ * );
119
+ * };
120
+ *```
53
121
  * @return {Object} action.
54
122
  */
55
123
  export function unregisterShortcut( name ) {
@@ -64,6 +64,39 @@ function getKeyCombinationRepresentation( shortcut, representation ) {
64
64
  * @param {Object} state Global state.
65
65
  * @param {string} name Shortcut name.
66
66
  *
67
+ * @example
68
+ *
69
+ *```js
70
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
71
+ * import { useSelect } from '@wordpress/data';
72
+ * import { createInterpolateElement } from '@wordpress/element';
73
+ * import { sprintf } from '@wordpress/i18n';
74
+ * const ExampleComponent = () => {
75
+ * const {character, modifier} = useSelect(
76
+ * ( select ) =>
77
+ * select( keyboardShortcutsStore ).getShortcutKeyCombination(
78
+ * 'core/edit-post/next-region'
79
+ * ),
80
+ * []
81
+ * );
82
+ *
83
+ * return (
84
+ * <div>
85
+ * { createInterpolateElement(
86
+ * sprintf(
87
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
88
+ * character,
89
+ * modifier
90
+ * ),
91
+ * {
92
+ * code: <code />,
93
+ * }
94
+ * ) }
95
+ * </div>
96
+ * );
97
+ * };
98
+ *```
99
+ *
67
100
  * @return {WPShortcutKeyCombination?} Key combination.
68
101
  */
69
102
  export function getShortcutKeyCombination( state, name ) {
@@ -77,6 +110,34 @@ export function getShortcutKeyCombination( state, name ) {
77
110
  * @param {string} name Shortcut name.
78
111
  * @param {keyof FORMATTING_METHODS} representation Type of representation
79
112
  * (display, raw, ariaLabel).
113
+ * @example
114
+ *
115
+ *```js
116
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
117
+ * import { useSelect } from '@wordpress/data';
118
+ * import { sprintf } from '@wordpress/i18n';
119
+ *
120
+ * const ExampleComponent = () => {
121
+ * const {display, raw, ariaLabel} = useSelect(
122
+ * ( select ) =>{
123
+ * return {
124
+ * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region' ),
125
+ * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ),
126
+ * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region', 'ariaLabel')
127
+ * }
128
+ * },
129
+ * []
130
+ * );
131
+ *
132
+ * return (
133
+ * <ul>
134
+ * <li>{ sprintf( 'display string: %s', display ) }</li>
135
+ * <li>{ sprintf( 'raw string: %s', raw ) }</li>
136
+ * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>
137
+ * </ul>
138
+ * );
139
+ * };
140
+ *```
80
141
  *
81
142
  * @return {string?} Shortcut representation.
82
143
  */
@@ -95,6 +156,26 @@ export function getShortcutRepresentation(
95
156
  * @param {Object} state Global state.
96
157
  * @param {string} name Shortcut name.
97
158
  *
159
+ * @example
160
+ *
161
+ *```js
162
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
163
+ * import { useSelect } from '@wordpress/data';
164
+ * import { __ } from '@wordpress/i18n';
165
+ * const ExampleComponent = () => {
166
+ * const shortcutDescription = useSelect(
167
+ * ( select ) =>
168
+ * select( keyboardShortcutsStore ).getShortcutDescription( 'core/edit-post/next-region' ),
169
+ * []
170
+ * );
171
+ *
172
+ * return shortcutDescription ? (
173
+ * <div>{ shortcutDescription }</div>
174
+ * ) : (
175
+ * <div>{ __( 'No description.' ) }</div>
176
+ * );
177
+ * };
178
+ *```
98
179
  * @return {string?} Shortcut description.
99
180
  */
100
181
  export function getShortcutDescription( state, name ) {
@@ -106,6 +187,44 @@ export function getShortcutDescription( state, name ) {
106
187
  *
107
188
  * @param {Object} state Global state.
108
189
  * @param {string} name Shortcut name.
190
+ * @example
191
+ *
192
+ *```js
193
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
194
+ * import { useSelect } from '@wordpress/data';
195
+ * import { createInterpolateElement } from '@wordpress/element';
196
+ * import { sprintf } from '@wordpress/i18n';
197
+ * const ExampleComponent = () => {
198
+ * const shortcutAliases = useSelect(
199
+ * ( select ) =>
200
+ * select( keyboardShortcutsStore ).getShortcutAliases(
201
+ * 'core/edit-post/next-region'
202
+ * ),
203
+ * []
204
+ * );
205
+ *
206
+ * return (
207
+ * shortcutAliases.length > 0 && (
208
+ * <ul>
209
+ * { shortcutAliases.map( ( { character, modifier }, index ) => (
210
+ * <li key={ index }>
211
+ * { createInterpolateElement(
212
+ * sprintf(
213
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
214
+ * character,
215
+ * modifier
216
+ * ),
217
+ * {
218
+ * code: <code />,
219
+ * }
220
+ * ) }
221
+ * </li>
222
+ * ) ) }
223
+ * </ul>
224
+ * )
225
+ * );
226
+ * };
227
+ *```
109
228
  *
110
229
  * @return {WPShortcutKeyCombination[]} Key combinations.
111
230
  */
@@ -115,6 +234,55 @@ export function getShortcutAliases( state, name ) {
115
234
  : EMPTY_ARRAY;
116
235
  }
117
236
 
237
+ /**
238
+ * Returns the shortcuts that include aliases for a given shortcut name.
239
+ *
240
+ * @param {Object} state Global state.
241
+ * @param {string} name Shortcut name.
242
+ * @example
243
+ *
244
+ *```js
245
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
246
+ * import { useSelect } from '@wordpress/data';
247
+ * import { createInterpolateElement } from '@wordpress/element';
248
+ * import { sprintf } from '@wordpress/i18n';
249
+ *
250
+ * const ExampleComponent = () => {
251
+ * const allShortcutKeyCombinations = useSelect(
252
+ * ( select ) =>
253
+ * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
254
+ * 'core/edit-post/next-region'
255
+ * ),
256
+ * []
257
+ * );
258
+ *
259
+ * return (
260
+ * allShortcutKeyCombinations.length > 0 && (
261
+ * <ul>
262
+ * { allShortcutKeyCombinations.map(
263
+ * ( { character, modifier }, index ) => (
264
+ * <li key={ index }>
265
+ * { createInterpolateElement(
266
+ * sprintf(
267
+ * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
268
+ * character,
269
+ * modifier
270
+ * ),
271
+ * {
272
+ * code: <code />,
273
+ * }
274
+ * ) }
275
+ * </li>
276
+ * )
277
+ * ) }
278
+ * </ul>
279
+ * )
280
+ * );
281
+ * };
282
+ *```
283
+ *
284
+ * @return {WPShortcutKeyCombination[]} Key combinations.
285
+ */
118
286
  export const getAllShortcutKeyCombinations = createSelector(
119
287
  ( state, name ) => {
120
288
  return [
@@ -131,6 +299,47 @@ export const getAllShortcutKeyCombinations = createSelector(
131
299
  * @param {Object} state Global state.
132
300
  * @param {string} name Shortcut name.
133
301
  *
302
+ * @example
303
+ *
304
+ *```js
305
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
306
+ * import { useSelect } from '@wordpress/data';
307
+ * import { createInterpolateElement } from '@wordpress/element';
308
+ * import { sprintf } from '@wordpress/i18n';
309
+ *
310
+ * const ExampleComponent = () => {
311
+ * const allShortcutRawKeyCombinations = useSelect(
312
+ * ( select ) =>
313
+ * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
314
+ * 'core/edit-post/next-region'
315
+ * ),
316
+ * []
317
+ * );
318
+ *
319
+ * return (
320
+ * allShortcutRawKeyCombinations.length > 0 && (
321
+ * <ul>
322
+ * { allShortcutRawKeyCombinations.map(
323
+ * ( shortcutRawKeyCombination, index ) => (
324
+ * <li key={ index }>
325
+ * { createInterpolateElement(
326
+ * sprintf(
327
+ * ' <code>%s</code>',
328
+ * shortcutRawKeyCombination
329
+ * ),
330
+ * {
331
+ * code: <code />,
332
+ * }
333
+ * ) }
334
+ * </li>
335
+ * )
336
+ * ) }
337
+ * </ul>
338
+ * )
339
+ * );
340
+ * };
341
+ *```
342
+ *
134
343
  * @return {string[]} Shortcuts.
135
344
  */
136
345
  export const getAllShortcutRawKeyCombinations = createSelector(
@@ -148,7 +357,32 @@ export const getAllShortcutRawKeyCombinations = createSelector(
148
357
  *
149
358
  * @param {Object} state Global state.
150
359
  * @param {string} name Category name.
360
+ * @example
361
+ *
362
+ *```js
363
+ * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
364
+ * import { useSelect } from '@wordpress/data';
365
+ *
366
+ * const ExampleComponent = () => {
367
+ * const categoryShortcuts = useSelect(
368
+ * ( select ) =>
369
+ * select( keyboardShortcutsStore ).getCategoryShortcuts(
370
+ * 'block'
371
+ * ),
372
+ * []
373
+ * );
151
374
  *
375
+ * return (
376
+ * categoryShortcuts.length > 0 && (
377
+ * <ul>
378
+ * { categoryShortcuts.map( ( categoryShortcut ) => (
379
+ * <li key={ categoryShortcut }>{ categoryShortcut }</li>
380
+ * ) ) }
381
+ * </ul>
382
+ * )
383
+ * );
384
+ * };
385
+ *```
152
386
  * @return {string[]} Shortcut names.
153
387
  */
154
388
  export const getCategoryShortcuts = createSelector(