@wordpress/keycodes 4.27.1-next.46f643fa0.0 → 4.28.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 +2 -0
- package/README.md +6 -18
- package/build/index.js +29 -54
- package/build/index.js.map +1 -1
- package/build/platform.js +3 -3
- package/build/platform.js.map +1 -1
- package/build-module/index.js +29 -54
- package/build-module/index.js.map +1 -1
- package/build-module/platform.js +3 -3
- package/build-module/platform.js.map +1 -1
- package/build-types/index.d.ts +53 -62
- package/build-types/index.d.ts.map +1 -1
- package/build-types/platform.d.ts +3 -3
- package/build-types/platform.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/{index.js → index.ts} +113 -111
- package/src/{platform.js → platform.ts} +3 -3
- package/src/test/{index.js → index.ts} +143 -100
- package/src/test/platform.ts +56 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/test/platform.js +0 -54
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -70,9 +70,7 @@ displayShortcut.primary( 'm' );
|
|
|
70
70
|
// "⌘M"
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
- `WPModifierHandler<WPKeyHandler<string>>`Keyed map of functions to display shortcuts.
|
|
73
|
+
Keyed map of functions to display shortcuts.
|
|
76
74
|
|
|
77
75
|
### displayShortcutList
|
|
78
76
|
|
|
@@ -86,9 +84,7 @@ displayShortcutList.primary( 'm' );
|
|
|
86
84
|
// [ "⌘", "M" ]
|
|
87
85
|
```
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- `WPModifierHandler<WPKeyHandler<string[]>>`Keyed map of functions to shortcut sequences.
|
|
87
|
+
Keyed map of functions to shortcut sequences.
|
|
92
88
|
|
|
93
89
|
### DOWN
|
|
94
90
|
|
|
@@ -120,7 +116,7 @@ Return true if platform is MacOS.
|
|
|
120
116
|
|
|
121
117
|
_Parameters_
|
|
122
118
|
|
|
123
|
-
- _\_window_ `Window
|
|
119
|
+
- _\_window_ `Window`: window object by default; used for DI testing.
|
|
124
120
|
|
|
125
121
|
_Returns_
|
|
126
122
|
|
|
@@ -138,9 +134,7 @@ isKeyboardEvent.primary( event, 'm' );
|
|
|
138
134
|
// true
|
|
139
135
|
```
|
|
140
136
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- `WPModifierHandler<WPEventKeyHandler>`Keyed map of functions to match events.
|
|
137
|
+
Keyed map of functions to match events.
|
|
144
138
|
|
|
145
139
|
### LEFT
|
|
146
140
|
|
|
@@ -152,7 +146,7 @@ Object that contains functions that return the available modifier depending on p
|
|
|
152
146
|
|
|
153
147
|
_Type_
|
|
154
148
|
|
|
155
|
-
- `WPModifierHandler<
|
|
149
|
+
- `WPModifierHandler< WPModifier >`
|
|
156
150
|
|
|
157
151
|
### PAGEDOWN
|
|
158
152
|
|
|
@@ -176,10 +170,6 @@ rawShortcut.primary( 'm' );
|
|
|
176
170
|
// "meta+m""
|
|
177
171
|
```
|
|
178
172
|
|
|
179
|
-
_Type_
|
|
180
|
-
|
|
181
|
-
- `WPModifierHandler<WPKeyHandler<string>>`Keyed map of functions to raw shortcuts.
|
|
182
|
-
|
|
183
173
|
### RIGHT
|
|
184
174
|
|
|
185
175
|
Keycode for RIGHT key.
|
|
@@ -200,9 +190,7 @@ shortcutAriaLabel.primary( '.' );
|
|
|
200
190
|
// "Command + Period"
|
|
201
191
|
```
|
|
202
192
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
- `WPModifierHandler<WPKeyHandler<string>>`Keyed map of functions to shortcut ARIA labels.
|
|
193
|
+
Keyed map of functions to shortcut ARIA labels.
|
|
206
194
|
|
|
207
195
|
### SPACE
|
|
208
196
|
|
package/build/index.js
CHANGED
|
@@ -32,27 +32,14 @@ var _platform = require("./platform");
|
|
|
32
32
|
* Internal dependencies
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
/** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */
|
|
36
|
-
|
|
37
|
-
/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */
|
|
38
|
-
|
|
39
35
|
/**
|
|
40
|
-
*
|
|
41
|
-
* combinations. A handler will return a value for a given key.
|
|
42
|
-
*
|
|
43
|
-
* @template T
|
|
44
|
-
*
|
|
45
|
-
* @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler
|
|
36
|
+
* External dependencies
|
|
46
37
|
*/
|
|
47
38
|
|
|
48
39
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler
|
|
40
|
+
* An object of handler functions for each of the possible modifier
|
|
41
|
+
* combinations. A handler will return a value for a given key.
|
|
52
42
|
*/
|
|
53
|
-
/** @typedef {(event: import('react').KeyboardEvent<HTMLElement> | KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */
|
|
54
|
-
|
|
55
|
-
/** @typedef {( isApple: () => boolean ) => WPModifierPart[]} WPModifier */
|
|
56
43
|
|
|
57
44
|
/**
|
|
58
45
|
* Keycode for BACKSPACE key.
|
|
@@ -155,8 +142,8 @@ const SHIFT = exports.SHIFT = 'shift';
|
|
|
155
142
|
const ZERO = exports.ZERO = 48;
|
|
156
143
|
/**
|
|
157
144
|
* Capitalise the first character of a string.
|
|
158
|
-
* @param
|
|
159
|
-
* @return
|
|
145
|
+
* @param string String to capitalise.
|
|
146
|
+
* @return Capitalised string.
|
|
160
147
|
*/
|
|
161
148
|
function capitaliseFirstCharacter(string) {
|
|
162
149
|
return string.length < 2 ? string.toUpperCase() : string.charAt(0).toUpperCase() + string.slice(1);
|
|
@@ -165,12 +152,12 @@ function capitaliseFirstCharacter(string) {
|
|
|
165
152
|
/**
|
|
166
153
|
* Map the values of an object with a specified callback and return the result object.
|
|
167
154
|
*
|
|
168
|
-
* @template
|
|
155
|
+
* @template T The object type
|
|
156
|
+
* @template R The return type of the mapping function
|
|
169
157
|
*
|
|
170
|
-
* @param
|
|
171
|
-
* @param
|
|
172
|
-
*
|
|
173
|
-
* @return {any} Active modifier constants.
|
|
158
|
+
* @param object Object to map values of.
|
|
159
|
+
* @param mapFn Mapping function to apply to each value.
|
|
160
|
+
* @return Object with the same keys and transformed values.
|
|
174
161
|
*/
|
|
175
162
|
function mapValues(object, mapFn) {
|
|
176
163
|
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, mapFn(value)]));
|
|
@@ -179,8 +166,6 @@ function mapValues(object, mapFn) {
|
|
|
179
166
|
/**
|
|
180
167
|
* Object that contains functions that return the available modifier
|
|
181
168
|
* depending on platform.
|
|
182
|
-
*
|
|
183
|
-
* @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>}
|
|
184
169
|
*/
|
|
185
170
|
const modifiers = exports.modifiers = {
|
|
186
171
|
primary: _isApple => _isApple() ? [COMMAND] : [CTRL],
|
|
@@ -207,13 +192,10 @@ const modifiers = exports.modifiers = {
|
|
|
207
192
|
* rawShortcut.primary( 'm' )
|
|
208
193
|
* // "meta+m""
|
|
209
194
|
* ```
|
|
210
|
-
*
|
|
211
|
-
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
|
|
212
|
-
* shortcuts.
|
|
213
195
|
*/
|
|
214
196
|
const rawShortcut = exports.rawShortcut = /* @__PURE__ */
|
|
215
|
-
mapValues(modifiers,
|
|
216
|
-
return
|
|
197
|
+
mapValues(modifiers, modifier => {
|
|
198
|
+
return (character, _isApple = _platform.isAppleOS) => {
|
|
217
199
|
return [...modifier(_isApple), character.toLowerCase()].join('+');
|
|
218
200
|
};
|
|
219
201
|
});
|
|
@@ -228,12 +210,11 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
228
210
|
* // [ "⌘", "M" ]
|
|
229
211
|
* ```
|
|
230
212
|
*
|
|
231
|
-
*
|
|
232
|
-
* shortcut sequences.
|
|
213
|
+
* Keyed map of functions to shortcut sequences.
|
|
233
214
|
*/
|
|
234
215
|
const displayShortcutList = exports.displayShortcutList = /* @__PURE__ */
|
|
235
|
-
mapValues(modifiers,
|
|
236
|
-
return
|
|
216
|
+
mapValues(modifiers, modifier => {
|
|
217
|
+
return (character, _isApple = _platform.isAppleOS) => {
|
|
237
218
|
const isApple = _isApple();
|
|
238
219
|
const replacementKeyMap = {
|
|
239
220
|
[ALT]: isApple ? '⌥' : 'Alt',
|
|
@@ -250,7 +231,7 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
250
231
|
return [...accumulator, replacementKey];
|
|
251
232
|
}
|
|
252
233
|
return [...accumulator, replacementKey, '+'];
|
|
253
|
-
},
|
|
234
|
+
}, []);
|
|
254
235
|
return [...modifierKeys, capitaliseFirstCharacter(character)];
|
|
255
236
|
};
|
|
256
237
|
});
|
|
@@ -265,12 +246,11 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
265
246
|
* // "⌘M"
|
|
266
247
|
* ```
|
|
267
248
|
*
|
|
268
|
-
*
|
|
269
|
-
* display shortcuts.
|
|
249
|
+
* Keyed map of functions to display shortcuts.
|
|
270
250
|
*/
|
|
271
251
|
const displayShortcut = exports.displayShortcut = /* @__PURE__ */
|
|
272
|
-
mapValues(displayShortcutList,
|
|
273
|
-
return
|
|
252
|
+
mapValues(displayShortcutList, shortcutList => {
|
|
253
|
+
return (character, _isApple = _platform.isAppleOS) => shortcutList(character, _isApple).join('');
|
|
274
254
|
});
|
|
275
255
|
|
|
276
256
|
/**
|
|
@@ -284,14 +264,12 @@ mapValues(displayShortcutList, (/** @type {WPKeyHandler<string[]>} */shortcutLis
|
|
|
284
264
|
* // "Command + Period"
|
|
285
265
|
* ```
|
|
286
266
|
*
|
|
287
|
-
*
|
|
288
|
-
* shortcut ARIA labels.
|
|
267
|
+
* Keyed map of functions to shortcut ARIA labels.
|
|
289
268
|
*/
|
|
290
269
|
const shortcutAriaLabel = exports.shortcutAriaLabel = /* @__PURE__ */
|
|
291
|
-
mapValues(modifiers,
|
|
292
|
-
return
|
|
270
|
+
mapValues(modifiers, modifier => {
|
|
271
|
+
return (character, _isApple = _platform.isAppleOS) => {
|
|
293
272
|
const isApple = _isApple();
|
|
294
|
-
/** @type {Record<string,string>} */
|
|
295
273
|
const replacementKeyMap = {
|
|
296
274
|
[SHIFT]: 'Shift',
|
|
297
275
|
[COMMAND]: isApple ? 'Command' : 'Control',
|
|
@@ -317,13 +295,12 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
317
295
|
* From a given KeyboardEvent, returns an array of active modifier constants for
|
|
318
296
|
* the event.
|
|
319
297
|
*
|
|
320
|
-
* @param
|
|
298
|
+
* @param event Keyboard event.
|
|
321
299
|
*
|
|
322
|
-
* @return
|
|
300
|
+
* @return Active modifier constants.
|
|
323
301
|
*/
|
|
324
302
|
function getEventModifiers(event) {
|
|
325
|
-
return
|
|
326
|
-
`${key}Key`)]);
|
|
303
|
+
return [ALT, CTRL, COMMAND, SHIFT].filter(key => event[`${key}Key`]);
|
|
327
304
|
}
|
|
328
305
|
|
|
329
306
|
/**
|
|
@@ -337,15 +314,13 @@ function getEventModifiers(event) {
|
|
|
337
314
|
* // true
|
|
338
315
|
* ```
|
|
339
316
|
*
|
|
340
|
-
*
|
|
341
|
-
* to match events.
|
|
317
|
+
* Keyed map of functions to match events.
|
|
342
318
|
*/
|
|
343
319
|
const isKeyboardEvent = exports.isKeyboardEvent = /* @__PURE__ */
|
|
344
|
-
mapValues(modifiers,
|
|
345
|
-
return
|
|
320
|
+
mapValues(modifiers, getModifiers => {
|
|
321
|
+
return (event, character, _isApple = _platform.isAppleOS) => {
|
|
346
322
|
const mods = getModifiers(_isApple);
|
|
347
323
|
const eventMods = getEventModifiers(event);
|
|
348
|
-
/** @type {Record<string,string>} */
|
|
349
324
|
const replacementWithShiftKeyMap = {
|
|
350
325
|
Comma: ',',
|
|
351
326
|
Backslash: '\\',
|
|
@@ -360,7 +335,7 @@ mapValues(modifiers, (/** @type {WPModifier} */getModifiers) => {
|
|
|
360
335
|
}
|
|
361
336
|
let key = event.key.toLowerCase();
|
|
362
337
|
if (!character) {
|
|
363
|
-
return mods.includes(
|
|
338
|
+
return mods.includes(key);
|
|
364
339
|
}
|
|
365
340
|
if (event.altKey && character.length === 1) {
|
|
366
341
|
key = String.fromCharCode(event.keyCode).toLowerCase();
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_platform","BACKSPACE","exports","TAB","ENTER","ESCAPE","SPACE","PAGEUP","PAGEDOWN","END","HOME","LEFT","UP","RIGHT","DOWN","DELETE","F10","ALT","CTRL","COMMAND","SHIFT","ZERO","capitaliseFirstCharacter","string","length","toUpperCase","charAt","slice","mapValues","object","mapFn","Object","fromEntries","entries","map","key","value","modifiers","primary","_isApple","primaryShift","primaryAlt","secondary","access","ctrl","alt","ctrlShift","shift","shiftAlt","undefined","rawShortcut","modifier","character","isAppleOS","toLowerCase","join","displayShortcutList","isApple","replacementKeyMap","modifierKeys","reduce","accumulator","_replacementKeyMap$ke","replacementKey","displayShortcut","shortcutList","shortcutAriaLabel","__","_replacementKeyMap$ke2","getEventModifiers","event","filter","isKeyboardEvent","getModifiers","mods","eventMods","replacementWithShiftKeyMap","Comma","Backslash","IntlRo","IntlYen","modsDiff","mod","includes","eventModsDiff","altKey","String","fromCharCode","keyCode","shiftKey","code"],"sources":["@wordpress/keycodes/src/index.js"],"sourcesContent":["/**\n * Note: The order of the modifier keys in many of the [foo]Shortcut()\n * functions in this file are intentional and should not be changed. They're\n * designed to fit with the standard menu keyboard shortcuts shown in the\n * user's platform.\n *\n * For example, on MacOS menu shortcuts will place Shift before Command, but\n * on Windows Control will usually come first. So don't provide your own\n * shortcut combos directly to keyboardShortcut().\n */\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { isAppleOS } from './platform';\n\n/** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */\n\n/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */\n\n/**\n * An object of handler functions for each of the possible modifier\n * combinations. A handler will return a value for a given key.\n *\n * @template T\n *\n * @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler\n */\n\n/**\n * @template T\n *\n * @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler\n */\n/** @typedef {(event: import('react').KeyboardEvent<HTMLElement> | KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */\n\n/** @typedef {( isApple: () => boolean ) => WPModifierPart[]} WPModifier */\n\n/**\n * Keycode for BACKSPACE key.\n */\nexport const BACKSPACE = 8;\n\n/**\n * Keycode for TAB key.\n */\nexport const TAB = 9;\n\n/**\n * Keycode for ENTER key.\n */\nexport const ENTER = 13;\n\n/**\n * Keycode for ESCAPE key.\n */\nexport const ESCAPE = 27;\n\n/**\n * Keycode for SPACE key.\n */\nexport const SPACE = 32;\n\n/**\n * Keycode for PAGEUP key.\n */\nexport const PAGEUP = 33;\n\n/**\n * Keycode for PAGEDOWN key.\n */\nexport const PAGEDOWN = 34;\n\n/**\n * Keycode for END key.\n */\nexport const END = 35;\n\n/**\n * Keycode for HOME key.\n */\nexport const HOME = 36;\n\n/**\n * Keycode for LEFT key.\n */\nexport const LEFT = 37;\n\n/**\n * Keycode for UP key.\n */\nexport const UP = 38;\n\n/**\n * Keycode for RIGHT key.\n */\nexport const RIGHT = 39;\n\n/**\n * Keycode for DOWN key.\n */\nexport const DOWN = 40;\n\n/**\n * Keycode for DELETE key.\n */\nexport const DELETE = 46;\n\n/**\n * Keycode for F10 key.\n */\nexport const F10 = 121;\n\n/**\n * Keycode for ALT key.\n */\nexport const ALT = 'alt';\n\n/**\n * Keycode for CTRL key.\n */\nexport const CTRL = 'ctrl';\n\n/**\n * Keycode for COMMAND/META key.\n */\nexport const COMMAND = 'meta';\n\n/**\n * Keycode for SHIFT key.\n */\nexport const SHIFT = 'shift';\n\n/**\n * Keycode for ZERO key.\n */\nexport const ZERO = 48;\n\nexport { isAppleOS };\n\n/**\n * Capitalise the first character of a string.\n * @param {string} string String to capitalise.\n * @return {string} Capitalised string.\n */\nfunction capitaliseFirstCharacter( string ) {\n\treturn string.length < 2\n\t\t? string.toUpperCase()\n\t\t: string.charAt( 0 ).toUpperCase() + string.slice( 1 );\n}\n\n/**\n * Map the values of an object with a specified callback and return the result object.\n *\n * @template {{ [s: string]: any; } | ArrayLike<any>} T\n *\n * @param {T} object Object to map values of.\n * @param {( value: any ) => any} mapFn Mapping function\n *\n * @return {any} Active modifier constants.\n */\nfunction mapValues( object, mapFn ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tmapFn( value ),\n\t\t] )\n\t);\n}\n\n/**\n * Object that contains functions that return the available modifier\n * depending on platform.\n *\n * @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>}\n */\nexport const modifiers = {\n\tprimary: ( _isApple ) => ( _isApple() ? [ COMMAND ] : [ CTRL ] ),\n\tprimaryShift: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],\n\tprimaryAlt: ( _isApple ) =>\n\t\t_isApple() ? [ ALT, COMMAND ] : [ CTRL, ALT ],\n\tsecondary: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ],\n\taccess: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ),\n\tctrl: () => [ CTRL ],\n\talt: () => [ ALT ],\n\tctrlShift: () => [ CTRL, SHIFT ],\n\tshift: () => [ SHIFT ],\n\tshiftAlt: () => [ SHIFT, ALT ],\n\tundefined: () => [],\n};\n\n/**\n * An object that contains functions to get raw shortcuts.\n *\n * These are intended for user with the KeyboardShortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * rawShortcut.primary( 'm' )\n * // \"meta+m\"\"\n * ```\n *\n * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw\n * shortcuts.\n */\nexport const rawShortcut =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {\n\t\treturn /** @type {WPKeyHandler<string>} */ (\n\t\t\tcharacter,\n\t\t\t_isApple = isAppleOS\n\t\t) => {\n\t\t\treturn [ ...modifier( _isApple ), character.toLowerCase() ].join(\n\t\t\t\t'+'\n\t\t\t);\n\t\t};\n\t} );\n\n/**\n * Return an array of the parts of a keyboard shortcut chord for display.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcutList.primary( 'm' );\n * // [ \"⌘\", \"M\" ]\n * ```\n *\n * @type {WPModifierHandler<WPKeyHandler<string[]>>} Keyed map of functions to\n * shortcut sequences.\n */\nexport const displayShortcutList =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {\n\t\treturn /** @type {WPKeyHandler<string[]>} */ (\n\t\t\tcharacter,\n\t\t\t_isApple = isAppleOS\n\t\t) => {\n\t\t\tconst isApple = _isApple();\n\t\t\tconst replacementKeyMap = {\n\t\t\t\t[ ALT ]: isApple ? '⌥' : 'Alt',\n\t\t\t\t[ CTRL ]: isApple ? '⌃' : 'Ctrl', // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.\n\t\t\t\t[ COMMAND ]: '⌘',\n\t\t\t\t[ SHIFT ]: isApple ? '⇧' : 'Shift',\n\t\t\t};\n\n\t\t\tconst modifierKeys = modifier( _isApple ).reduce(\n\t\t\t\t( accumulator, key ) => {\n\t\t\t\t\tconst replacementKey = replacementKeyMap[ key ] ?? key;\n\t\t\t\t\t// If on the Mac, adhere to platform convention and don't show plus between keys.\n\t\t\t\t\tif ( isApple ) {\n\t\t\t\t\t\treturn [ ...accumulator, replacementKey ];\n\t\t\t\t\t}\n\n\t\t\t\t\treturn [ ...accumulator, replacementKey, '+' ];\n\t\t\t\t},\n\t\t\t\t/** @type {string[]} */ ( [] )\n\t\t\t);\n\n\t\t\treturn [ ...modifierKeys, capitaliseFirstCharacter( character ) ];\n\t\t};\n\t} );\n\n/**\n * An object that contains functions to display shortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcut.primary( 'm' );\n * // \"⌘M\"\n * ```\n *\n * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to\n * display shortcuts.\n */\nexport const displayShortcut =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tdisplayShortcutList,\n\t\t( /** @type {WPKeyHandler<string[]>} */ shortcutList ) => {\n\t\t\treturn /** @type {WPKeyHandler<string>} */ (\n\t\t\t\tcharacter,\n\t\t\t\t_isApple = isAppleOS\n\t\t\t) => shortcutList( character, _isApple ).join( '' );\n\t\t}\n\t);\n\n/**\n * An object that contains functions to return an aria label for a keyboard\n * shortcut.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * shortcutAriaLabel.primary( '.' );\n * // \"Command + Period\"\n * ```\n *\n * @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to\n * shortcut ARIA labels.\n */\nexport const shortcutAriaLabel =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( /** @type {WPModifier} */ modifier ) => {\n\t\treturn /** @type {WPKeyHandler<string>} */ (\n\t\t\tcharacter,\n\t\t\t_isApple = isAppleOS\n\t\t) => {\n\t\t\tconst isApple = _isApple();\n\t\t\t/** @type {Record<string,string>} */\n\t\t\tconst replacementKeyMap = {\n\t\t\t\t[ SHIFT ]: 'Shift',\n\t\t\t\t[ COMMAND ]: isApple ? 'Command' : 'Control',\n\t\t\t\t[ CTRL ]: 'Control',\n\t\t\t\t[ ALT ]: isApple ? 'Option' : 'Alt',\n\t\t\t\t/* translators: comma as in the character ',' */\n\t\t\t\t',': __( 'Comma' ),\n\t\t\t\t/* translators: period as in the character '.' */\n\t\t\t\t'.': __( 'Period' ),\n\t\t\t\t/* translators: backtick as in the character '`' */\n\t\t\t\t'`': __( 'Backtick' ),\n\t\t\t\t/* translators: tilde as in the character '~' */\n\t\t\t\t'~': __( 'Tilde' ),\n\t\t\t};\n\n\t\t\treturn [ ...modifier( _isApple ), character ]\n\t\t\t\t.map( ( key ) =>\n\t\t\t\t\tcapitaliseFirstCharacter( replacementKeyMap[ key ] ?? key )\n\t\t\t\t)\n\t\t\t\t.join( isApple ? ' ' : ' + ' );\n\t\t};\n\t} );\n\n/**\n * From a given KeyboardEvent, returns an array of active modifier constants for\n * the event.\n *\n * @param {import('react').KeyboardEvent<HTMLElement> | KeyboardEvent} event Keyboard event.\n *\n * @return {Array<WPModifierPart>} Active modifier constants.\n */\nfunction getEventModifiers( event ) {\n\treturn /** @type {WPModifierPart[]} */ ( [\n\t\tALT,\n\t\tCTRL,\n\t\tCOMMAND,\n\t\tSHIFT,\n\t] ).filter(\n\t\t( key ) =>\n\t\t\tevent[\n\t\t\t\t/** @type {'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'} */ (\n\t\t\t\t\t`${ key }Key`\n\t\t\t\t)\n\t\t\t]\n\t);\n}\n\n/**\n * An object that contains functions to check if a keyboard event matches a\n * predefined shortcut combination.\n *\n * @example\n * ```js\n * // Assuming an event for ⌘M key press:\n * isKeyboardEvent.primary( event, 'm' );\n * // true\n * ```\n *\n * @type {WPModifierHandler<WPEventKeyHandler>} Keyed map of functions\n * to match events.\n */\nexport const isKeyboardEvent =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( /** @type {WPModifier} */ getModifiers ) => {\n\t\treturn /** @type {WPEventKeyHandler} */ (\n\t\t\tevent,\n\t\t\tcharacter,\n\t\t\t_isApple = isAppleOS\n\t\t) => {\n\t\t\tconst mods = getModifiers( _isApple );\n\t\t\tconst eventMods = getEventModifiers( event );\n\t\t\t/** @type {Record<string,string>} */\n\t\t\tconst replacementWithShiftKeyMap = {\n\t\t\t\tComma: ',',\n\t\t\t\tBackslash: '\\\\',\n\t\t\t\t// Windows returns `\\` for both IntlRo and IntlYen.\n\t\t\t\tIntlRo: '\\\\',\n\t\t\t\tIntlYen: '\\\\',\n\t\t\t};\n\n\t\t\tconst modsDiff = mods.filter(\n\t\t\t\t( mod ) => ! eventMods.includes( mod )\n\t\t\t);\n\t\t\tconst eventModsDiff = eventMods.filter(\n\t\t\t\t( mod ) => ! mods.includes( mod )\n\t\t\t);\n\n\t\t\tif ( modsDiff.length > 0 || eventModsDiff.length > 0 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet key = event.key.toLowerCase();\n\n\t\t\tif ( ! character ) {\n\t\t\t\treturn mods.includes( /** @type {WPModifierPart} */ ( key ) );\n\t\t\t}\n\n\t\t\tif ( event.altKey && character.length === 1 ) {\n\t\t\t\tkey = String.fromCharCode( event.keyCode ).toLowerCase();\n\t\t\t}\n\n\t\t\t// `event.key` returns the value of the key pressed, taking into the state of\n\t\t\t// modifier keys such as `Shift`. If the shift key is pressed, a different\n\t\t\t// value may be returned depending on the keyboard layout. It is necessary to\n\t\t\t// convert to the physical key value that don't take into account keyboard\n\t\t\t// layout or modifier key state.\n\t\t\tif (\n\t\t\t\tevent.shiftKey &&\n\t\t\t\tcharacter.length === 1 &&\n\t\t\t\treplacementWithShiftKeyMap[ event.code ]\n\t\t\t) {\n\t\t\t\tkey = replacementWithShiftKeyMap[ event.code ];\n\t\t\t}\n\n\t\t\t// For backwards compatibility.\n\t\t\tif ( character === 'del' ) {\n\t\t\t\tcharacter = 'delete';\n\t\t\t}\n\n\t\t\treturn key === character.toLowerCase();\n\t\t};\n\t} );\n"],"mappings":";;;;;;;;;;;;;AAcA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,SAAA,GAAAD,OAAA;AAnBA;AACA;AACA;AACA;AAC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AG,CAACmB,WAAW,CAAC,CAAC;IAEjC,IAAK,CAAEF,SAAS,EAAG;MAClB,OAAOsB,IAAI,CAACS,QAAQ,CAAE,6BAAgChD,GAAM,CAAC;IAC9D;IAEA,IAAKmC,KAAK,CAACe,MAAM,IAAIjC,SAAS,CAAC5B,MAAM,KAAK,CAAC,EAAG;MAC7CW,GAAG,GAAGmD,MAAM,CAACC,YAAY,CAAEjB,KAAK,CAACkB,OAAQ,CAAC,CAAClC,WAAW,CAAC,CAAC;IACzD;;IAEA;IACA;IACA;IACA;IACA;IACA,IACCgB,KAAK,CAACmB,QAAQ,IACdrC,SAAS,CAAC5B,MAAM,KAAK,CAAC,IACtBoD,0BAA0B,CAAEN,KAAK,CAACoB,IAAI,CAAE,EACvC;MACDvD,GAAG,GAAGyC,0BAA0B,CAAEN,KAAK,CAACoB,IAAI,CAAE;IAC/C;;IAEA;IACA,IAAKtC,SAAS,KAAK,KAAK,EAAG;MAC1BA,SAAS,GAAG,QAAQ;IACrB;IAEA,OAAOjB,GAAG,KAAKiB,SAAS,CAACE,WAAW,CAAC,CAAC;EACvC,CAAC;AACF,CAAE,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_i18n","require","_platform","BACKSPACE","exports","TAB","ENTER","ESCAPE","SPACE","PAGEUP","PAGEDOWN","END","HOME","LEFT","UP","RIGHT","DOWN","DELETE","F10","ALT","CTRL","COMMAND","SHIFT","ZERO","capitaliseFirstCharacter","string","length","toUpperCase","charAt","slice","mapValues","object","mapFn","Object","fromEntries","entries","map","key","value","modifiers","primary","_isApple","primaryShift","primaryAlt","secondary","access","ctrl","alt","ctrlShift","shift","shiftAlt","undefined","rawShortcut","modifier","character","isAppleOS","toLowerCase","join","displayShortcutList","isApple","replacementKeyMap","modifierKeys","reduce","accumulator","_replacementKeyMap$ke","replacementKey","displayShortcut","shortcutList","shortcutAriaLabel","__","_replacementKeyMap$ke2","getEventModifiers","event","filter","isKeyboardEvent","getModifiers","mods","eventMods","replacementWithShiftKeyMap","Comma","Backslash","IntlRo","IntlYen","modsDiff","mod","includes","eventModsDiff","altKey","String","fromCharCode","keyCode","shiftKey","code"],"sources":["@wordpress/keycodes/src/index.ts"],"sourcesContent":["/**\n * Note: The order of the modifier keys in many of the [foo]Shortcut()\n * functions in this file are intentional and should not be changed. They're\n * designed to fit with the standard menu keyboard shortcuts shown in the\n * user's platform.\n *\n * For example, on MacOS menu shortcuts will place Shift before Command, but\n * on Windows Control will usually come first. So don't provide your own\n * shortcut combos directly to keyboardShortcut().\n */\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { isAppleOS } from './platform';\n\n/**\n * External dependencies\n */\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\nexport type WPModifierPart =\n\t| typeof ALT\n\t| typeof CTRL\n\t| typeof COMMAND\n\t| typeof SHIFT;\n\nexport type WPKeycodeModifier =\n\t| 'primary'\n\t| 'primaryShift'\n\t| 'primaryAlt'\n\t| 'secondary'\n\t| 'access'\n\t| 'ctrl'\n\t| 'alt'\n\t| 'ctrlShift'\n\t| 'shift'\n\t| 'shiftAlt'\n\t| 'undefined';\n\n/**\n * An object of handler functions for each of the possible modifier\n * combinations. A handler will return a value for a given key.\n */\nexport type WPModifierHandler< T > = Record< WPKeycodeModifier, T >;\n\nexport type WPKeyHandler< T > = (\n\tcharacter: string,\n\tisApple?: () => boolean\n) => T;\n\nexport type WPEventKeyHandler = (\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent,\n\tcharacter: string,\n\tisApple?: () => boolean\n) => boolean;\n\nexport type WPModifier = ( isApple: () => boolean ) => WPModifierPart[];\n\n/**\n * Keycode for BACKSPACE key.\n */\nexport const BACKSPACE = 8;\n\n/**\n * Keycode for TAB key.\n */\nexport const TAB = 9;\n\n/**\n * Keycode for ENTER key.\n */\nexport const ENTER = 13;\n\n/**\n * Keycode for ESCAPE key.\n */\nexport const ESCAPE = 27;\n\n/**\n * Keycode for SPACE key.\n */\nexport const SPACE = 32;\n\n/**\n * Keycode for PAGEUP key.\n */\nexport const PAGEUP = 33;\n\n/**\n * Keycode for PAGEDOWN key.\n */\nexport const PAGEDOWN = 34;\n\n/**\n * Keycode for END key.\n */\nexport const END = 35;\n\n/**\n * Keycode for HOME key.\n */\nexport const HOME = 36;\n\n/**\n * Keycode for LEFT key.\n */\nexport const LEFT = 37;\n\n/**\n * Keycode for UP key.\n */\nexport const UP = 38;\n\n/**\n * Keycode for RIGHT key.\n */\nexport const RIGHT = 39;\n\n/**\n * Keycode for DOWN key.\n */\nexport const DOWN = 40;\n\n/**\n * Keycode for DELETE key.\n */\nexport const DELETE = 46;\n\n/**\n * Keycode for F10 key.\n */\nexport const F10 = 121;\n\n/**\n * Keycode for ALT key.\n */\nexport const ALT = 'alt';\n\n/**\n * Keycode for CTRL key.\n */\nexport const CTRL = 'ctrl';\n\n/**\n * Keycode for COMMAND/META key.\n */\nexport const COMMAND = 'meta';\n\n/**\n * Keycode for SHIFT key.\n */\nexport const SHIFT = 'shift';\n\n/**\n * Keycode for ZERO key.\n */\nexport const ZERO = 48;\n\nexport { isAppleOS };\n\n/**\n * Capitalise the first character of a string.\n * @param string String to capitalise.\n * @return Capitalised string.\n */\nfunction capitaliseFirstCharacter( string: string ): string {\n\treturn string.length < 2\n\t\t? string.toUpperCase()\n\t\t: string.charAt( 0 ).toUpperCase() + string.slice( 1 );\n}\n\n/**\n * Map the values of an object with a specified callback and return the result object.\n *\n * @template T The object type\n * @template R The return type of the mapping function\n *\n * @param object Object to map values of.\n * @param mapFn Mapping function to apply to each value.\n * @return Object with the same keys and transformed values.\n */\nfunction mapValues< T extends Record< string, any >, R >(\n\tobject: T,\n\tmapFn: ( value: T[ keyof T ] ) => R\n): Record< keyof T, R > {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tmapFn( value ),\n\t\t] )\n\t) as Record< keyof T, R >;\n}\n\n/**\n * Object that contains functions that return the available modifier\n * depending on platform.\n */\nexport const modifiers: WPModifierHandler< WPModifier > = {\n\tprimary: ( _isApple ) => ( _isApple() ? [ COMMAND ] : [ CTRL ] ),\n\tprimaryShift: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],\n\tprimaryAlt: ( _isApple ) =>\n\t\t_isApple() ? [ ALT, COMMAND ] : [ CTRL, ALT ],\n\tsecondary: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ],\n\taccess: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ),\n\tctrl: () => [ CTRL ],\n\talt: () => [ ALT ],\n\tctrlShift: () => [ CTRL, SHIFT ],\n\tshift: () => [ SHIFT ],\n\tshiftAlt: () => [ SHIFT, ALT ],\n\tundefined: () => [],\n};\n\n/**\n * An object that contains functions to get raw shortcuts.\n *\n * These are intended for user with the KeyboardShortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * rawShortcut.primary( 'm' )\n * // \"meta+m\"\"\n * ```\n */\nexport const rawShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ) => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\treturn [ ...modifier( _isApple ), character.toLowerCase() ].join(\n\t\t\t\t'+'\n\t\t\t);\n\t\t};\n\t} );\n\n/**\n * Return an array of the parts of a keyboard shortcut chord for display.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcutList.primary( 'm' );\n * // [ \"⌘\", \"M\" ]\n * ```\n *\n * Keyed map of functions to shortcut sequences.\n */\nexport const displayShortcutList: WPModifierHandler<\n\tWPKeyHandler< string[] >\n> =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tmodifiers,\n\t\t( modifier: WPModifier ): WPKeyHandler< string[] > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\t\tconst isApple = _isApple();\n\t\t\t\tconst replacementKeyMap = {\n\t\t\t\t\t[ ALT ]: isApple ? '⌥' : 'Alt',\n\t\t\t\t\t[ CTRL ]: isApple ? '⌃' : 'Ctrl', // Make sure ⌃ is the U+2303 UP ARROWHEAD unicode character and not the caret character.\n\t\t\t\t\t[ COMMAND ]: '⌘',\n\t\t\t\t\t[ SHIFT ]: isApple ? '⇧' : 'Shift',\n\t\t\t\t};\n\n\t\t\t\tconst modifierKeys = modifier( _isApple ).reduce< string[] >(\n\t\t\t\t\t( accumulator, key ) => {\n\t\t\t\t\t\tconst replacementKey = replacementKeyMap[ key ] ?? key;\n\t\t\t\t\t\t// If on the Mac, adhere to platform convention and don't show plus between keys.\n\t\t\t\t\t\tif ( isApple ) {\n\t\t\t\t\t\t\treturn [ ...accumulator, replacementKey ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn [ ...accumulator, replacementKey, '+' ];\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\n\t\t\t\treturn [\n\t\t\t\t\t...modifierKeys,\n\t\t\t\t\tcapitaliseFirstCharacter( character ),\n\t\t\t\t];\n\t\t\t};\n\t\t}\n\t);\n\n/**\n * An object that contains functions to display shortcuts.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * displayShortcut.primary( 'm' );\n * // \"⌘M\"\n * ```\n *\n * Keyed map of functions to display shortcuts.\n */\nexport const displayShortcut: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues(\n\t\tdisplayShortcutList,\n\t\t( shortcutList: WPKeyHandler< string[] > ): WPKeyHandler< string > => {\n\t\t\treturn ( character: string, _isApple = isAppleOS ) =>\n\t\t\t\tshortcutList( character, _isApple ).join( '' );\n\t\t}\n\t);\n\n/**\n * An object that contains functions to return an aria label for a keyboard\n * shortcut.\n *\n * @example\n * ```js\n * // Assuming macOS:\n * shortcutAriaLabel.primary( '.' );\n * // \"Command + Period\"\n * ```\n *\n * Keyed map of functions to shortcut ARIA labels.\n */\nexport const shortcutAriaLabel: WPModifierHandler< WPKeyHandler< string > > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( modifier: WPModifier ): WPKeyHandler< string > => {\n\t\treturn ( character: string, _isApple = isAppleOS ) => {\n\t\t\tconst isApple = _isApple();\n\t\t\tconst replacementKeyMap: Record< string, string > = {\n\t\t\t\t[ SHIFT ]: 'Shift',\n\t\t\t\t[ COMMAND ]: isApple ? 'Command' : 'Control',\n\t\t\t\t[ CTRL ]: 'Control',\n\t\t\t\t[ ALT ]: isApple ? 'Option' : 'Alt',\n\t\t\t\t/* translators: comma as in the character ',' */\n\t\t\t\t',': __( 'Comma' ),\n\t\t\t\t/* translators: period as in the character '.' */\n\t\t\t\t'.': __( 'Period' ),\n\t\t\t\t/* translators: backtick as in the character '`' */\n\t\t\t\t'`': __( 'Backtick' ),\n\t\t\t\t/* translators: tilde as in the character '~' */\n\t\t\t\t'~': __( 'Tilde' ),\n\t\t\t};\n\n\t\t\treturn [ ...modifier( _isApple ), character ]\n\t\t\t\t.map( ( key ) =>\n\t\t\t\t\tcapitaliseFirstCharacter( replacementKeyMap[ key ] ?? key )\n\t\t\t\t)\n\t\t\t\t.join( isApple ? ' ' : ' + ' );\n\t\t};\n\t} );\n\n/**\n * From a given KeyboardEvent, returns an array of active modifier constants for\n * the event.\n *\n * @param event Keyboard event.\n *\n * @return Active modifier constants.\n */\nfunction getEventModifiers(\n\tevent: ReactKeyboardEvent< HTMLElement > | KeyboardEvent\n): WPModifierPart[] {\n\treturn ( [ ALT, CTRL, COMMAND, SHIFT ] as const ).filter(\n\t\t( key ) =>\n\t\t\t( event as KeyboardEvent )[\n\t\t\t\t`${ key }Key` as 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'\n\t\t\t]\n\t);\n}\n\n/**\n * An object that contains functions to check if a keyboard event matches a\n * predefined shortcut combination.\n *\n * @example\n * ```js\n * // Assuming an event for ⌘M key press:\n * isKeyboardEvent.primary( event, 'm' );\n * // true\n * ```\n *\n * Keyed map of functions to match events.\n */\nexport const isKeyboardEvent: WPModifierHandler< WPEventKeyHandler > =\n\t/* @__PURE__ */\n\tmapValues( modifiers, ( getModifiers: WPModifier ): WPEventKeyHandler => {\n\t\treturn ( event, character, _isApple = isAppleOS ) => {\n\t\t\tconst mods = getModifiers( _isApple );\n\t\t\tconst eventMods = getEventModifiers( event );\n\n\t\t\tconst replacementWithShiftKeyMap: Record< string, string > = {\n\t\t\t\tComma: ',',\n\t\t\t\tBackslash: '\\\\',\n\t\t\t\t// Windows returns `\\` for both IntlRo and IntlYen.\n\t\t\t\tIntlRo: '\\\\',\n\t\t\t\tIntlYen: '\\\\',\n\t\t\t};\n\n\t\t\tconst modsDiff = mods.filter(\n\t\t\t\t( mod ) => ! eventMods.includes( mod )\n\t\t\t);\n\t\t\tconst eventModsDiff = eventMods.filter(\n\t\t\t\t( mod ) => ! mods.includes( mod )\n\t\t\t);\n\n\t\t\tif ( modsDiff.length > 0 || eventModsDiff.length > 0 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tlet key = event.key.toLowerCase();\n\n\t\t\tif ( ! character ) {\n\t\t\t\treturn mods.includes( key as WPModifierPart );\n\t\t\t}\n\n\t\t\tif ( event.altKey && character.length === 1 ) {\n\t\t\t\tkey = String.fromCharCode( event.keyCode ).toLowerCase();\n\t\t\t}\n\n\t\t\t// `event.key` returns the value of the key pressed, taking into the state of\n\t\t\t// modifier keys such as `Shift`. If the shift key is pressed, a different\n\t\t\t// value may be returned depending on the keyboard layout. It is necessary to\n\t\t\t// convert to the physical key value that don't take into account keyboard\n\t\t\t// layout or modifier key state.\n\t\t\tif (\n\t\t\t\tevent.shiftKey &&\n\t\t\t\tcharacter.length === 1 &&\n\t\t\t\treplacementWithShiftKeyMap[ event.code ]\n\t\t\t) {\n\t\t\t\tkey = replacementWithShiftKeyMap[ event.code ];\n\t\t\t}\n\n\t\t\t// For backwards compatibility.\n\t\t\tif ( character === 'del' ) {\n\t\t\t\tcharacter = 'delete';\n\t\t\t}\n\n\t\t\treturn key === character.toLowerCase();\n\t\t};\n\t} );\n"],"mappings":";;;;;;;;;;;;;AAcA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,SAAA,GAAAD,OAAA;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;AACA;;AAgBA;AACA;AACA;AACO,MAAME,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,CAAC;;AAE1B;AACA;AACA;AACO,MAAME,GAAG,GAAAD,OAAA,CAAAC,GAAA,GAAG,CAAC;;AAEpB;AACA;AACA;AACO,MAAMC,KAAK,GAAAF,OAAA,CAAAE,KAAA,GAAG,EAAE;;AAEvB;AACA;AACA;AACO,MAAMC,MAAM,GAAAH,OAAA,CAAAG,MAAA,GAAG,EAAE;;AAExB;AACA;AACA;AACO,MAAMC,KAAK,GAAAJ,OAAA,CAAAI,KAAA,GAAG,EAAE;;AAEvB;AACA;AACA;AACO,MAAMC,MAAM,GAAAL,OAAA,CAAAK,MAAA,GAAG,EAAE;;AAExB;AACA;AACA;AACO,MAAMC,QAAQ,GAAAN,OAAA,CAAAM,QAAA,GAAG,EAAE;;AAE1B;AACA;AACA;AACO,MAAMC,GAAG,GAAAP,OAAA,CAAAO,GAAA,GAAG,EAAE;;AAErB;AACA;AACA;AACO,MAAMC,IAAI,GAAAR,OAAA,CAAAQ,IAAA,GAAG,EAAE;;AAEtB;AACA;AACA;AACO,MAAMC,IAAI,GAAAT,OAAA,CAAAS,IAAA,GAAG,EAAE;;AAEtB;AACA;AACA;AACO,MAAMC,EAAE,GAAAV,OAAA,CAAAU,EAAA,GAAG,EAAE;;AAEpB;AACA;AACA;AACO,MAAMC,KAAK,GAAAX,OAAA,CAAAW,KAAA,GAAG,EAAE;;AAEvB;AACA;AACA;AAC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AC,CAAC;IAEjC,IAAK,CAAEF,SAAS,EAAG;MAClB,OAAOsB,IAAI,CAACS,QAAQ,CAAEhD,GAAsB,CAAC;IAC9C;IAEA,IAAKmC,KAAK,CAACe,MAAM,IAAIjC,SAAS,CAAC5B,MAAM,KAAK,CAAC,EAAG;MAC7CW,GAAG,GAAGmD,MAAM,CAACC,YAAY,CAAEjB,KAAK,CAACkB,OAAQ,CAAC,CAAClC,WAAW,CAAC,CAAC;IACzD;;IAEA;IACA;IACA;IACA;IACA;IACA,IACCgB,KAAK,CAACmB,QAAQ,IACdrC,SAAS,CAAC5B,MAAM,KAAK,CAAC,IACtBoD,0BAA0B,CAAEN,KAAK,CAACoB,IAAI,CAAE,EACvC;MACDvD,GAAG,GAAGyC,0BAA0B,CAAEN,KAAK,CAACoB,IAAI,CAAE;IAC/C;;IAEA;IACA,IAAKtC,SAAS,KAAK,KAAK,EAAG;MAC1BA,SAAS,GAAG,QAAQ;IACrB;IAEA,OAAOjB,GAAG,KAAKiB,SAAS,CAACE,WAAW,CAAC,CAAC;EACvC,CAAC;AACF,CAAE,CAAC","ignoreList":[]}
|
package/build/platform.js
CHANGED
|
@@ -7,11 +7,11 @@ exports.isAppleOS = isAppleOS;
|
|
|
7
7
|
/**
|
|
8
8
|
* Return true if platform is MacOS.
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
10
|
+
* @param _window window object by default; used for DI testing.
|
|
11
11
|
*
|
|
12
|
-
* @return
|
|
12
|
+
* @return True if MacOS; false otherwise.
|
|
13
13
|
*/
|
|
14
|
-
function isAppleOS(_window
|
|
14
|
+
function isAppleOS(_window) {
|
|
15
15
|
if (!_window) {
|
|
16
16
|
if (typeof window === 'undefined') {
|
|
17
17
|
return false;
|
package/build/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isAppleOS","_window","window","platform","navigator","indexOf","includes"],"sources":["@wordpress/keycodes/src/platform.
|
|
1
|
+
{"version":3,"names":["isAppleOS","_window","window","platform","navigator","indexOf","includes"],"sources":["@wordpress/keycodes/src/platform.ts"],"sourcesContent":["/**\n * Return true if platform is MacOS.\n *\n * @param _window window object by default; used for DI testing.\n *\n * @return True if MacOS; false otherwise.\n */\nexport function isAppleOS( _window?: Window ): boolean {\n\tif ( ! _window ) {\n\t\tif ( typeof window === 'undefined' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t_window = window;\n\t}\n\n\tconst { platform } = _window.navigator;\n\n\treturn (\n\t\tplatform.indexOf( 'Mac' ) !== -1 ||\n\t\t[ 'iPad', 'iPhone' ].includes( platform )\n\t);\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,SAASA,CAAEC,OAAgB,EAAY;EACtD,IAAK,CAAEA,OAAO,EAAG;IAChB,IAAK,OAAOC,MAAM,KAAK,WAAW,EAAG;MACpC,OAAO,KAAK;IACb;IAEAD,OAAO,GAAGC,MAAM;EACjB;EAEA,MAAM;IAAEC;EAAS,CAAC,GAAGF,OAAO,CAACG,SAAS;EAEtC,OACCD,QAAQ,CAACE,OAAO,CAAE,KAAM,CAAC,KAAK,CAAC,CAAC,IAChC,CAAE,MAAM,EAAE,QAAQ,CAAE,CAACC,QAAQ,CAAEH,QAAS,CAAC;AAE3C","ignoreList":[]}
|
package/build-module/index.js
CHANGED
|
@@ -19,27 +19,14 @@ import { __ } from '@wordpress/i18n';
|
|
|
19
19
|
*/
|
|
20
20
|
import { isAppleOS } from './platform';
|
|
21
21
|
|
|
22
|
-
/** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */
|
|
23
|
-
|
|
24
|
-
/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */
|
|
25
|
-
|
|
26
22
|
/**
|
|
27
|
-
*
|
|
28
|
-
* combinations. A handler will return a value for a given key.
|
|
29
|
-
*
|
|
30
|
-
* @template T
|
|
31
|
-
*
|
|
32
|
-
* @typedef {Record<WPKeycodeModifier, T>} WPModifierHandler
|
|
23
|
+
* External dependencies
|
|
33
24
|
*/
|
|
34
25
|
|
|
35
26
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @typedef {(character: string, isApple?: () => boolean) => T} WPKeyHandler
|
|
27
|
+
* An object of handler functions for each of the possible modifier
|
|
28
|
+
* combinations. A handler will return a value for a given key.
|
|
39
29
|
*/
|
|
40
|
-
/** @typedef {(event: import('react').KeyboardEvent<HTMLElement> | KeyboardEvent, character: string, isApple?: () => boolean) => boolean} WPEventKeyHandler */
|
|
41
|
-
|
|
42
|
-
/** @typedef {( isApple: () => boolean ) => WPModifierPart[]} WPModifier */
|
|
43
30
|
|
|
44
31
|
/**
|
|
45
32
|
* Keycode for BACKSPACE key.
|
|
@@ -144,8 +131,8 @@ export { isAppleOS };
|
|
|
144
131
|
|
|
145
132
|
/**
|
|
146
133
|
* Capitalise the first character of a string.
|
|
147
|
-
* @param
|
|
148
|
-
* @return
|
|
134
|
+
* @param string String to capitalise.
|
|
135
|
+
* @return Capitalised string.
|
|
149
136
|
*/
|
|
150
137
|
function capitaliseFirstCharacter(string) {
|
|
151
138
|
return string.length < 2 ? string.toUpperCase() : string.charAt(0).toUpperCase() + string.slice(1);
|
|
@@ -154,12 +141,12 @@ function capitaliseFirstCharacter(string) {
|
|
|
154
141
|
/**
|
|
155
142
|
* Map the values of an object with a specified callback and return the result object.
|
|
156
143
|
*
|
|
157
|
-
* @template
|
|
144
|
+
* @template T The object type
|
|
145
|
+
* @template R The return type of the mapping function
|
|
158
146
|
*
|
|
159
|
-
* @param
|
|
160
|
-
* @param
|
|
161
|
-
*
|
|
162
|
-
* @return {any} Active modifier constants.
|
|
147
|
+
* @param object Object to map values of.
|
|
148
|
+
* @param mapFn Mapping function to apply to each value.
|
|
149
|
+
* @return Object with the same keys and transformed values.
|
|
163
150
|
*/
|
|
164
151
|
function mapValues(object, mapFn) {
|
|
165
152
|
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, mapFn(value)]));
|
|
@@ -168,8 +155,6 @@ function mapValues(object, mapFn) {
|
|
|
168
155
|
/**
|
|
169
156
|
* Object that contains functions that return the available modifier
|
|
170
157
|
* depending on platform.
|
|
171
|
-
*
|
|
172
|
-
* @type {WPModifierHandler< ( isApple: () => boolean ) => WPModifierPart[]>}
|
|
173
158
|
*/
|
|
174
159
|
export const modifiers = {
|
|
175
160
|
primary: _isApple => _isApple() ? [COMMAND] : [CTRL],
|
|
@@ -196,13 +181,10 @@ export const modifiers = {
|
|
|
196
181
|
* rawShortcut.primary( 'm' )
|
|
197
182
|
* // "meta+m""
|
|
198
183
|
* ```
|
|
199
|
-
*
|
|
200
|
-
* @type {WPModifierHandler<WPKeyHandler<string>>} Keyed map of functions to raw
|
|
201
|
-
* shortcuts.
|
|
202
184
|
*/
|
|
203
185
|
export const rawShortcut = /* @__PURE__ */
|
|
204
|
-
mapValues(modifiers,
|
|
205
|
-
return
|
|
186
|
+
mapValues(modifiers, modifier => {
|
|
187
|
+
return (character, _isApple = isAppleOS) => {
|
|
206
188
|
return [...modifier(_isApple), character.toLowerCase()].join('+');
|
|
207
189
|
};
|
|
208
190
|
});
|
|
@@ -217,12 +199,11 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
217
199
|
* // [ "⌘", "M" ]
|
|
218
200
|
* ```
|
|
219
201
|
*
|
|
220
|
-
*
|
|
221
|
-
* shortcut sequences.
|
|
202
|
+
* Keyed map of functions to shortcut sequences.
|
|
222
203
|
*/
|
|
223
204
|
export const displayShortcutList = /* @__PURE__ */
|
|
224
|
-
mapValues(modifiers,
|
|
225
|
-
return
|
|
205
|
+
mapValues(modifiers, modifier => {
|
|
206
|
+
return (character, _isApple = isAppleOS) => {
|
|
226
207
|
const isApple = _isApple();
|
|
227
208
|
const replacementKeyMap = {
|
|
228
209
|
[ALT]: isApple ? '⌥' : 'Alt',
|
|
@@ -239,7 +220,7 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
239
220
|
return [...accumulator, replacementKey];
|
|
240
221
|
}
|
|
241
222
|
return [...accumulator, replacementKey, '+'];
|
|
242
|
-
},
|
|
223
|
+
}, []);
|
|
243
224
|
return [...modifierKeys, capitaliseFirstCharacter(character)];
|
|
244
225
|
};
|
|
245
226
|
});
|
|
@@ -254,12 +235,11 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
254
235
|
* // "⌘M"
|
|
255
236
|
* ```
|
|
256
237
|
*
|
|
257
|
-
*
|
|
258
|
-
* display shortcuts.
|
|
238
|
+
* Keyed map of functions to display shortcuts.
|
|
259
239
|
*/
|
|
260
240
|
export const displayShortcut = /* @__PURE__ */
|
|
261
|
-
mapValues(displayShortcutList,
|
|
262
|
-
return
|
|
241
|
+
mapValues(displayShortcutList, shortcutList => {
|
|
242
|
+
return (character, _isApple = isAppleOS) => shortcutList(character, _isApple).join('');
|
|
263
243
|
});
|
|
264
244
|
|
|
265
245
|
/**
|
|
@@ -273,14 +253,12 @@ mapValues(displayShortcutList, (/** @type {WPKeyHandler<string[]>} */shortcutLis
|
|
|
273
253
|
* // "Command + Period"
|
|
274
254
|
* ```
|
|
275
255
|
*
|
|
276
|
-
*
|
|
277
|
-
* shortcut ARIA labels.
|
|
256
|
+
* Keyed map of functions to shortcut ARIA labels.
|
|
278
257
|
*/
|
|
279
258
|
export const shortcutAriaLabel = /* @__PURE__ */
|
|
280
|
-
mapValues(modifiers,
|
|
281
|
-
return
|
|
259
|
+
mapValues(modifiers, modifier => {
|
|
260
|
+
return (character, _isApple = isAppleOS) => {
|
|
282
261
|
const isApple = _isApple();
|
|
283
|
-
/** @type {Record<string,string>} */
|
|
284
262
|
const replacementKeyMap = {
|
|
285
263
|
[SHIFT]: 'Shift',
|
|
286
264
|
[COMMAND]: isApple ? 'Command' : 'Control',
|
|
@@ -306,13 +284,12 @@ mapValues(modifiers, (/** @type {WPModifier} */modifier) => {
|
|
|
306
284
|
* From a given KeyboardEvent, returns an array of active modifier constants for
|
|
307
285
|
* the event.
|
|
308
286
|
*
|
|
309
|
-
* @param
|
|
287
|
+
* @param event Keyboard event.
|
|
310
288
|
*
|
|
311
|
-
* @return
|
|
289
|
+
* @return Active modifier constants.
|
|
312
290
|
*/
|
|
313
291
|
function getEventModifiers(event) {
|
|
314
|
-
return
|
|
315
|
-
`${key}Key`)]);
|
|
292
|
+
return [ALT, CTRL, COMMAND, SHIFT].filter(key => event[`${key}Key`]);
|
|
316
293
|
}
|
|
317
294
|
|
|
318
295
|
/**
|
|
@@ -326,15 +303,13 @@ function getEventModifiers(event) {
|
|
|
326
303
|
* // true
|
|
327
304
|
* ```
|
|
328
305
|
*
|
|
329
|
-
*
|
|
330
|
-
* to match events.
|
|
306
|
+
* Keyed map of functions to match events.
|
|
331
307
|
*/
|
|
332
308
|
export const isKeyboardEvent = /* @__PURE__ */
|
|
333
|
-
mapValues(modifiers,
|
|
334
|
-
return
|
|
309
|
+
mapValues(modifiers, getModifiers => {
|
|
310
|
+
return (event, character, _isApple = isAppleOS) => {
|
|
335
311
|
const mods = getModifiers(_isApple);
|
|
336
312
|
const eventMods = getEventModifiers(event);
|
|
337
|
-
/** @type {Record<string,string>} */
|
|
338
313
|
const replacementWithShiftKeyMap = {
|
|
339
314
|
Comma: ',',
|
|
340
315
|
Backslash: '\\',
|
|
@@ -349,7 +324,7 @@ mapValues(modifiers, (/** @type {WPModifier} */getModifiers) => {
|
|
|
349
324
|
}
|
|
350
325
|
let key = event.key.toLowerCase();
|
|
351
326
|
if (!character) {
|
|
352
|
-
return mods.includes(
|
|
327
|
+
return mods.includes(key);
|
|
353
328
|
}
|
|
354
329
|
if (event.altKey && character.length === 1) {
|
|
355
330
|
key = String.fromCharCode(event.keyCode).toLowerCase();
|