@wordpress/keyboard-shortcuts 3.9.0 → 3.12.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 +6 -0
- package/build/hooks/use-shortcut-event-match.js +1 -1
- package/build/hooks/use-shortcut-event-match.js.map +1 -1
- package/build/store/reducer.js +5 -7
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +1 -3
- package/build/store/selectors.js.map +1 -1
- package/build-module/hooks/use-shortcut-event-match.js +1 -1
- package/build-module/hooks/use-shortcut-event-match.js.map +1 -1
- package/build-module/store/reducer.js +5 -6
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +1 -2
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +5 -6
- package/src/hooks/use-shortcut-event-match.js +1 -1
- package/src/store/reducer.js +2 -6
- package/src/store/selectors.js +2 -3
package/CHANGELOG.md
CHANGED
@@ -22,7 +22,7 @@ var _store = require("../store");
|
|
22
22
|
/**
|
23
23
|
* Returns a function to check if a keyboard event matches a shortcut name.
|
24
24
|
*
|
25
|
-
* @return {Function} A function to
|
25
|
+
* @return {Function} A function to check if a keyboard event matches a
|
26
26
|
* predefined shortcut combination.
|
27
27
|
*/
|
28
28
|
function useShortcutEventMatch() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"names":["useShortcutEventMatch","getAllShortcutKeyCombinations","keyboardShortcutsStore","isMatch","name","event","some","modifier","character","isKeyboardEvent"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,qBAAT,GAAiC;AAC/C,QAAM;AAAEC,IAAAA;AAAF,MAAoC,qBACzCC,YADyC,CAA1C;AAIA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,WAASC,OAAT,CAAkBC,IAAlB,EAAwBC,KAAxB,EAAgC;AAC/B,WAAOJ,6BAA6B,CAAEG,IAAF,CAA7B,CAAsCE,IAAtC,CACN,QAA+B;AAAA,UAA7B;AAAEC,QAAAA,QAAF;AAAYC,QAAAA;AAAZ,OAA6B;AAC9B,aAAOC,0BAAiBF,QAAjB,EAA6BF,KAA7B,EAAoCG,SAApC,CAAP;AACA,KAHK,CAAP;AAKA;;AAED,SAAOL,OAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to
|
1
|
+
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"names":["useShortcutEventMatch","getAllShortcutKeyCombinations","keyboardShortcutsStore","isMatch","name","event","some","modifier","character","isKeyboardEvent"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,qBAAT,GAAiC;AAC/C,QAAM;AAAEC,IAAAA;AAAF,MAAoC,qBACzCC,YADyC,CAA1C;AAIA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,WAASC,OAAT,CAAkBC,IAAlB,EAAwBC,KAAxB,EAAgC;AAC/B,WAAOJ,6BAA6B,CAAEG,IAAF,CAA7B,CAAsCE,IAAtC,CACN,QAA+B;AAAA,UAA7B;AAAEC,QAAAA,QAAF;AAAYC,QAAAA;AAAZ,OAA6B;AAC9B,aAAOC,0BAAiBF,QAAjB,EAA6BF,KAA7B,EAAoCG,SAApC,CAAP;AACA,KAHK,CAAP;AAKA;;AAED,SAAOL,OAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to check if a keyboard event matches a\n * predefined shortcut combination.\n */\nexport default function useShortcutEventMatch() {\n\tconst { getAllShortcutKeyCombinations } = useSelect(\n\t\tkeyboardShortcutsStore\n\t);\n\n\t/**\n\t * A function to check if a keyboard event matches a predefined shortcut\n\t * combination.\n\t *\n\t * @param {string} name Shortcut name.\n\t * @param {KeyboardEvent} event Event to check.\n\t *\n\t * @return {boolean} True if the event matches any shortcuts, false if not.\n\t */\n\tfunction isMatch( name, event ) {\n\t\treturn getAllShortcutKeyCombinations( name ).some(\n\t\t\t( { modifier, character } ) => {\n\t\t\t\treturn isKeyboardEvent[ modifier ]( event, character );\n\t\t\t}\n\t\t);\n\t}\n\n\treturn isMatch;\n}\n"]}
|
package/build/store/reducer.js
CHANGED
@@ -5,12 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
var _lodash = require("lodash");
|
9
|
-
|
10
|
-
/**
|
11
|
-
* External dependencies
|
12
|
-
*/
|
13
|
-
|
14
8
|
/**
|
15
9
|
* Reducer returning the registered shortcuts
|
16
10
|
*
|
@@ -35,7 +29,11 @@ function reducer() {
|
|
35
29
|
};
|
36
30
|
|
37
31
|
case 'UNREGISTER_SHORTCUT':
|
38
|
-
|
32
|
+
const {
|
33
|
+
[action.name]: actionName,
|
34
|
+
...remainingState
|
35
|
+
} = state;
|
36
|
+
return remainingState;
|
39
37
|
}
|
40
38
|
|
41
39
|
return state;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/reducer.js"],"names":["reducer","state","action","type","name","category","keyCombination","aliases","description"],"mappings":";;;;;;;
|
1
|
+
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/reducer.js"],"names":["reducer","state","action","type","name","category","keyCombination","aliases","description","actionName","remainingState"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAT,GAAuC;AAAA,MAArBC,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AACtC,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,mBAAL;AACC,aAAO,EACN,GAAGF,KADG;AAEN,SAAEC,MAAM,CAACE,IAAT,GAAiB;AAChBC,UAAAA,QAAQ,EAAEH,MAAM,CAACG,QADD;AAEhBC,UAAAA,cAAc,EAAEJ,MAAM,CAACI,cAFP;AAGhBC,UAAAA,OAAO,EAAEL,MAAM,CAACK,OAHA;AAIhBC,UAAAA,WAAW,EAAEN,MAAM,CAACM;AAJJ;AAFX,OAAP;;AASD,SAAK,qBAAL;AACC,YAAM;AAAE,SAAEN,MAAM,CAACE,IAAT,GAAiBK,UAAnB;AAA+B,WAAGC;AAAlC,UAAqDT,KAA3D;AACA,aAAOS,cAAP;AAbF;;AAgBA,SAAOT,KAAP;AACA;;eAEcD,O","sourcesContent":["/**\n * Reducer returning the registered shortcuts\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction reducer( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_SHORTCUT':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tcategory: action.category,\n\t\t\t\t\tkeyCombination: action.keyCombination,\n\t\t\t\t\taliases: action.aliases,\n\t\t\t\t\tdescription: action.description,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_SHORTCUT':\n\t\t\tconst { [ action.name ]: actionName, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t}\n\n\treturn state;\n}\n\nexport default reducer;\n"]}
|
package/build/store/selectors.js
CHANGED
@@ -13,8 +13,6 @@ exports.getShortcutRepresentation = getShortcutRepresentation;
|
|
13
13
|
|
14
14
|
var _rememo = _interopRequireDefault(require("rememo"));
|
15
15
|
|
16
|
-
var _lodash = require("lodash");
|
17
|
-
|
18
16
|
var _keycodes = require("@wordpress/keycodes");
|
19
17
|
|
20
18
|
/**
|
@@ -124,7 +122,7 @@ function getShortcutAliases(state, name) {
|
|
124
122
|
}
|
125
123
|
|
126
124
|
const getAllShortcutKeyCombinations = (0, _rememo.default)((state, name) => {
|
127
|
-
return
|
125
|
+
return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean);
|
128
126
|
}, (state, name) => [state[name]]);
|
129
127
|
/**
|
130
128
|
* Returns the raw representation of all the keyboard combinations of a given shortcut name.
|
@@ -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","getAllShortcutRawKeyCombinations","map","combination","getCategoryShortcuts","categoryName","Object","entries","
|
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;A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* 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"]}
|
@@ -11,7 +11,7 @@ import { store as keyboardShortcutsStore } from '../store';
|
|
11
11
|
/**
|
12
12
|
* Returns a function to check if a keyboard event matches a shortcut name.
|
13
13
|
*
|
14
|
-
* @return {Function} A function to
|
14
|
+
* @return {Function} A function to check if a keyboard event matches a
|
15
15
|
* predefined shortcut combination.
|
16
16
|
*/
|
17
17
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"names":["useSelect","isKeyboardEvent","store","keyboardShortcutsStore","useShortcutEventMatch","getAllShortcutKeyCombinations","isMatch","name","event","some","modifier","character"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,sBAAlB,QAAgD,UAAhD;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,qBAAT,GAAiC;AAC/C,QAAM;AAAEC,IAAAA;AAAF,MAAoCL,SAAS,CAClDG,sBADkD,CAAnD;AAIA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,WAASG,OAAT,CAAkBC,IAAlB,EAAwBC,KAAxB,EAAgC;AAC/B,WAAOH,6BAA6B,CAAEE,IAAF,CAA7B,CAAsCE,IAAtC,CACN,QAA+B;AAAA,UAA7B;AAAEC,QAAAA,QAAF;AAAYC,QAAAA;AAAZ,OAA6B;AAC9B,aAAOV,eAAe,CAAES,QAAF,CAAf,CAA6BF,KAA7B,EAAoCG,SAApC,CAAP;AACA,KAHK,CAAP;AAKA;;AAED,SAAOL,OAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to
|
1
|
+
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/hooks/use-shortcut-event-match.js"],"names":["useSelect","isKeyboardEvent","store","keyboardShortcutsStore","useShortcutEventMatch","getAllShortcutKeyCombinations","isMatch","name","event","some","modifier","character"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,eAAT,QAAgC,qBAAhC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,sBAAlB,QAAgD,UAAhD;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,qBAAT,GAAiC;AAC/C,QAAM;AAAEC,IAAAA;AAAF,MAAoCL,SAAS,CAClDG,sBADkD,CAAnD;AAIA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,WAASG,OAAT,CAAkBC,IAAlB,EAAwBC,KAAxB,EAAgC;AAC/B,WAAOH,6BAA6B,CAAEE,IAAF,CAA7B,CAAsCE,IAAtC,CACN,QAA+B;AAAA,UAA7B;AAAEC,QAAAA,QAAF;AAAYC,QAAAA;AAAZ,OAA6B;AAC9B,aAAOV,eAAe,CAAES,QAAF,CAAf,CAA6BF,KAA7B,EAAoCG,SAApC,CAAP;AACA,KAHK,CAAP;AAKA;;AAED,SAAOL,OAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { isKeyboardEvent } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as keyboardShortcutsStore } from '../store';\n\n/**\n * Returns a function to check if a keyboard event matches a shortcut name.\n *\n * @return {Function} A function to check if a keyboard event matches a\n * predefined shortcut combination.\n */\nexport default function useShortcutEventMatch() {\n\tconst { getAllShortcutKeyCombinations } = useSelect(\n\t\tkeyboardShortcutsStore\n\t);\n\n\t/**\n\t * A function to check if a keyboard event matches a predefined shortcut\n\t * combination.\n\t *\n\t * @param {string} name Shortcut name.\n\t * @param {KeyboardEvent} event Event to check.\n\t *\n\t * @return {boolean} True if the event matches any shortcuts, false if not.\n\t */\n\tfunction isMatch( name, event ) {\n\t\treturn getAllShortcutKeyCombinations( name ).some(\n\t\t\t( { modifier, character } ) => {\n\t\t\t\treturn isKeyboardEvent[ modifier ]( event, character );\n\t\t\t}\n\t\t);\n\t}\n\n\treturn isMatch;\n}\n"]}
|
@@ -1,7 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* External dependencies
|
3
|
-
*/
|
4
|
-
import { omit } from 'lodash';
|
5
1
|
/**
|
6
2
|
* Reducer returning the registered shortcuts
|
7
3
|
*
|
@@ -10,7 +6,6 @@ import { omit } from 'lodash';
|
|
10
6
|
*
|
11
7
|
* @return {Object} Updated state.
|
12
8
|
*/
|
13
|
-
|
14
9
|
function reducer() {
|
15
10
|
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
16
11
|
let action = arguments.length > 1 ? arguments[1] : undefined;
|
@@ -27,7 +22,11 @@ function reducer() {
|
|
27
22
|
};
|
28
23
|
|
29
24
|
case 'UNREGISTER_SHORTCUT':
|
30
|
-
|
25
|
+
const {
|
26
|
+
[action.name]: actionName,
|
27
|
+
...remainingState
|
28
|
+
} = state;
|
29
|
+
return remainingState;
|
31
30
|
}
|
32
31
|
|
33
32
|
return state;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/reducer.js"],"names":["
|
1
|
+
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/reducer.js"],"names":["reducer","state","action","type","name","category","keyCombination","aliases","description","actionName","remainingState"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAT,GAAuC;AAAA,MAArBC,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AACtC,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,mBAAL;AACC,aAAO,EACN,GAAGF,KADG;AAEN,SAAEC,MAAM,CAACE,IAAT,GAAiB;AAChBC,UAAAA,QAAQ,EAAEH,MAAM,CAACG,QADD;AAEhBC,UAAAA,cAAc,EAAEJ,MAAM,CAACI,cAFP;AAGhBC,UAAAA,OAAO,EAAEL,MAAM,CAACK,OAHA;AAIhBC,UAAAA,WAAW,EAAEN,MAAM,CAACM;AAJJ;AAFX,OAAP;;AASD,SAAK,qBAAL;AACC,YAAM;AAAE,SAAEN,MAAM,CAACE,IAAT,GAAiBK,UAAnB;AAA+B,WAAGC;AAAlC,UAAqDT,KAA3D;AACA,aAAOS,cAAP;AAbF;;AAgBA,SAAOT,KAAP;AACA;;AAED,eAAeD,OAAf","sourcesContent":["/**\n * Reducer returning the registered shortcuts\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction reducer( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_SHORTCUT':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tcategory: action.category,\n\t\t\t\t\tkeyCombination: action.keyCombination,\n\t\t\t\t\taliases: action.aliases,\n\t\t\t\t\tdescription: action.description,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_SHORTCUT':\n\t\t\tconst { [ action.name ]: actionName, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t}\n\n\treturn state;\n}\n\nexport default reducer;\n"]}
|
@@ -2,7 +2,6 @@
|
|
2
2
|
* External dependencies
|
3
3
|
*/
|
4
4
|
import createSelector from 'rememo';
|
5
|
-
import { compact } from 'lodash';
|
6
5
|
/**
|
7
6
|
* WordPress dependencies
|
8
7
|
*/
|
@@ -104,7 +103,7 @@ export function getShortcutAliases(state, name) {
|
|
104
103
|
return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
|
105
104
|
}
|
106
105
|
export const getAllShortcutKeyCombinations = createSelector((state, name) => {
|
107
|
-
return
|
106
|
+
return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean);
|
108
107
|
}, (state, name) => [state[name]]);
|
109
108
|
/**
|
110
109
|
* Returns the raw representation of all the keyboard combinations of a given shortcut name.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/keyboard-shortcuts/src/store/selectors.js"],"names":["createSelector","
|
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,OAAO,SAASC,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A;;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,OAAO,MAAMa,oBAAoB,GAAG7B,cAAc,CACjD,CAAEe,KAAF,EAASe,YAAT,KAA2B;AAC1B,SAAOC,MAAM,CAACC,OAAP,CAAgBjB,KAAhB,EACLS,MADK,CACG;AAAA,QAAE,GAAId,QAAJ,CAAF;AAAA,WAAsBA,QAAQ,CAACuB,QAAT,KAAsBH,YAA5C;AAAA,GADH,EAELH,GAFK,CAEA;AAAA,QAAE,CAAEX,IAAF,CAAF;AAAA,WAAgBA,IAAhB;AAAA,GAFA,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 * @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"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wordpress/keyboard-shortcuts",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.12.0",
|
4
4
|
"description": "Handling keyboard shortcuts.",
|
5
5
|
"author": "The WordPress Contributors",
|
6
6
|
"license": "GPL-2.0-or-later",
|
@@ -26,10 +26,9 @@
|
|
26
26
|
"react-native": "src/index",
|
27
27
|
"dependencies": {
|
28
28
|
"@babel/runtime": "^7.16.0",
|
29
|
-
"@wordpress/data": "^6.
|
30
|
-
"@wordpress/element": "^4.
|
31
|
-
"@wordpress/keycodes": "^3.
|
32
|
-
"lodash": "^4.17.21",
|
29
|
+
"@wordpress/data": "^6.14.0",
|
30
|
+
"@wordpress/element": "^4.12.0",
|
31
|
+
"@wordpress/keycodes": "^3.14.0",
|
33
32
|
"rememo": "^4.0.0"
|
34
33
|
},
|
35
34
|
"peerDependencies": {
|
@@ -38,5 +37,5 @@
|
|
38
37
|
"publishConfig": {
|
39
38
|
"access": "public"
|
40
39
|
},
|
41
|
-
"gitHead": "
|
40
|
+
"gitHead": "0315dbc240cb2aa146d7c1bafd251f004b88300e"
|
42
41
|
}
|
@@ -12,7 +12,7 @@ import { store as keyboardShortcutsStore } from '../store';
|
|
12
12
|
/**
|
13
13
|
* Returns a function to check if a keyboard event matches a shortcut name.
|
14
14
|
*
|
15
|
-
* @return {Function} A function to
|
15
|
+
* @return {Function} A function to check if a keyboard event matches a
|
16
16
|
* predefined shortcut combination.
|
17
17
|
*/
|
18
18
|
export default function useShortcutEventMatch() {
|
package/src/store/reducer.js
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* External dependencies
|
3
|
-
*/
|
4
|
-
import { omit } from 'lodash';
|
5
|
-
|
6
1
|
/**
|
7
2
|
* Reducer returning the registered shortcuts
|
8
3
|
*
|
@@ -24,7 +19,8 @@ function reducer( state = {}, action ) {
|
|
24
19
|
},
|
25
20
|
};
|
26
21
|
case 'UNREGISTER_SHORTCUT':
|
27
|
-
|
22
|
+
const { [ action.name ]: actionName, ...remainingState } = state;
|
23
|
+
return remainingState;
|
28
24
|
}
|
29
25
|
|
30
26
|
return state;
|
package/src/store/selectors.js
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
* External dependencies
|
3
3
|
*/
|
4
4
|
import createSelector from 'rememo';
|
5
|
-
import { compact } from 'lodash';
|
6
5
|
|
7
6
|
/**
|
8
7
|
* WordPress dependencies
|
@@ -118,10 +117,10 @@ export function getShortcutAliases( state, name ) {
|
|
118
117
|
|
119
118
|
export const getAllShortcutKeyCombinations = createSelector(
|
120
119
|
( state, name ) => {
|
121
|
-
return
|
120
|
+
return [
|
122
121
|
getShortcutKeyCombination( state, name ),
|
123
122
|
...getShortcutAliases( state, name ),
|
124
|
-
] );
|
123
|
+
].filter( Boolean );
|
125
124
|
},
|
126
125
|
( state, name ) => [ state[ name ] ]
|
127
126
|
);
|