@wordpress/keyboard-shortcuts 5.32.0 → 5.32.1-next.ff1cebbba.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/build/components/shortcut-provider.js +32 -41
- package/build/components/shortcut-provider.js.map +7 -1
- package/build/context.js +35 -19
- package/build/context.js.map +7 -1
- package/build/hooks/use-shortcut-event-match.js +33 -42
- package/build/hooks/use-shortcut-event-match.js.map +7 -1
- package/build/hooks/use-shortcut.js +41 -34
- package/build/hooks/use-shortcut.js.map +7 -1
- package/build/index.js +44 -32
- package/build/index.js.map +7 -1
- package/build/store/actions.js +30 -115
- package/build/store/actions.js.map +7 -1
- package/build/store/index.js +44 -33
- package/build/store/index.js.map +7 -1
- package/build/store/reducer.js +26 -21
- package/build/store/reducer.js.map +7 -1
- package/build/store/selectors.js +70 -349
- package/build/store/selectors.js.map +7 -1
- package/build-module/components/shortcut-provider.js +11 -36
- package/build-module/components/shortcut-provider.js.map +7 -1
- package/build-module/context.js +13 -13
- package/build-module/context.js.map +7 -1
- package/build-module/hooks/use-shortcut-event-match.js +16 -38
- package/build-module/hooks/use-shortcut-event-match.js.map +7 -1
- package/build-module/hooks/use-shortcut.js +8 -23
- package/build-module/hooks/use-shortcut.js.map +7 -1
- package/build-module/index.js +11 -5
- package/build-module/index.js.map +7 -1
- package/build-module/store/actions.js +9 -111
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/index.js +10 -22
- package/build-module/store/index.js.map +7 -1
- package/build-module/store/reducer.js +8 -16
- package/build-module/store/reducer.js.map +7 -1
- package/build-module/store/selectors.js +46 -340
- package/build-module/store/selectors.js.map +7 -1
- package/package.json +12 -6
- package/build/hooks/use-shortcut.native.js +0 -9
- package/build/hooks/use-shortcut.native.js.map +0 -1
- package/build-module/hooks/use-shortcut.native.js +0 -3
- package/build-module/hooks/use-shortcut.native.js.map +0 -1
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var shortcut_provider_exports = {};
|
|
19
|
+
__export(shortcut_provider_exports, {
|
|
20
|
+
ShortcutProvider: () => ShortcutProvider
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const {
|
|
19
|
-
Provider
|
|
20
|
-
} = _context.context;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Handles callbacks added to context by `useShortcut`.
|
|
24
|
-
* Adding a provider allows to register contextual shortcuts
|
|
25
|
-
* that are only active when a certain part of the UI is focused.
|
|
26
|
-
*
|
|
27
|
-
* @param {Object} props Props to pass to `div`.
|
|
28
|
-
*
|
|
29
|
-
* @return {Element} Component.
|
|
30
|
-
*/
|
|
22
|
+
module.exports = __toCommonJS(shortcut_provider_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_element = require("@wordpress/element");
|
|
25
|
+
var import_context = require("../context");
|
|
26
|
+
const { Provider } = import_context.context;
|
|
31
27
|
function ShortcutProvider(props) {
|
|
32
|
-
const [keyboardShortcuts] = (0,
|
|
28
|
+
const [keyboardShortcuts] = (0, import_element.useState)(() => /* @__PURE__ */ new Set());
|
|
33
29
|
function onKeyDown(event) {
|
|
34
30
|
if (props.onKeyDown) {
|
|
35
31
|
props.onKeyDown(event);
|
|
@@ -38,15 +34,10 @@ function ShortcutProvider(props) {
|
|
|
38
34
|
keyboardShortcut(event);
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
43
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
|
|
44
|
-
value: keyboardShortcuts,
|
|
45
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
46
|
-
...props,
|
|
47
|
-
onKeyDown: onKeyDown
|
|
48
|
-
})
|
|
49
|
-
});
|
|
50
|
-
/* eslint-enable jsx-a11y/no-static-element-interactions */
|
|
37
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, { value: keyboardShortcuts, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...props, onKeyDown }) });
|
|
51
38
|
}
|
|
52
|
-
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
ShortcutProvider
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=shortcut-provider.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/shortcut-provider.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { context } from '../context';\n\nconst { Provider } = context;\n\n/**\n * Handles callbacks added to context by `useShortcut`.\n * Adding a provider allows to register contextual shortcuts\n * that are only active when a certain part of the UI is focused.\n *\n * @param {Object} props Props to pass to `div`.\n *\n * @return {Element} Component.\n */\nexport function ShortcutProvider( props ) {\n\tconst [ keyboardShortcuts ] = useState( () => new Set() );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( props.onKeyDown ) {\n\t\t\tprops.onKeyDown( event );\n\t\t}\n\n\t\tfor ( const keyboardShortcut of keyboardShortcuts ) {\n\t\t\tkeyboardShortcut( event );\n\t\t}\n\t}\n\n\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\treturn (\n\t\t<Provider value={ keyboardShortcuts }>\n\t\t\t<div { ...props } onKeyDown={ onKeyDown } />\n\t\t</Provider>\n\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions */\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCG;AAlCH,qBAAyB;AAKzB,qBAAwB;AAExB,MAAM,EAAE,SAAS,IAAI;AAWd,SAAS,iBAAkB,OAAQ;AACzC,QAAM,CAAE,iBAAkB,QAAI,yBAAU,MAAM,oBAAI,IAAI,CAAE;AAExD,WAAS,UAAW,OAAQ;AAC3B,QAAK,MAAM,WAAY;AACtB,YAAM,UAAW,KAAM;AAAA,IACxB;AAEA,eAAY,oBAAoB,mBAAoB;AACnD,uBAAkB,KAAM;AAAA,IACzB;AAAA,EACD;AAGA,SACC,4CAAC,YAAS,OAAQ,mBACjB,sDAAC,SAAM,GAAG,OAAQ,WAAwB,GAC3C;AAGF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/context.js
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var context_exports = {};
|
|
19
|
+
__export(context_exports, {
|
|
20
|
+
context: () => context
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const globalShortcuts = new Set();
|
|
13
|
-
const globalListener = event => {
|
|
22
|
+
module.exports = __toCommonJS(context_exports);
|
|
23
|
+
var import_element = require("@wordpress/element");
|
|
24
|
+
const globalShortcuts = /* @__PURE__ */ new Set();
|
|
25
|
+
const globalListener = (event) => {
|
|
14
26
|
for (const keyboardShortcut of globalShortcuts) {
|
|
15
27
|
keyboardShortcut(event);
|
|
16
28
|
}
|
|
17
29
|
};
|
|
18
|
-
const context =
|
|
19
|
-
add: shortcut => {
|
|
30
|
+
const context = (0, import_element.createContext)({
|
|
31
|
+
add: (shortcut) => {
|
|
20
32
|
if (globalShortcuts.size === 0) {
|
|
21
|
-
document.addEventListener(
|
|
33
|
+
document.addEventListener("keydown", globalListener);
|
|
22
34
|
}
|
|
23
35
|
globalShortcuts.add(shortcut);
|
|
24
36
|
},
|
|
25
|
-
delete: shortcut => {
|
|
37
|
+
delete: (shortcut) => {
|
|
26
38
|
globalShortcuts.delete(shortcut);
|
|
27
39
|
if (globalShortcuts.size === 0) {
|
|
28
|
-
document.removeEventListener(
|
|
40
|
+
document.removeEventListener("keydown", globalListener);
|
|
29
41
|
}
|
|
30
42
|
}
|
|
31
43
|
});
|
|
32
|
-
context.displayName =
|
|
33
|
-
|
|
44
|
+
context.displayName = "KeyboardShortcutsContext";
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
context
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=context.js.map
|
package/build/context.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/context.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\nconst globalShortcuts = new Set();\nconst globalListener = ( event ) => {\n\tfor ( const keyboardShortcut of globalShortcuts ) {\n\t\tkeyboardShortcut( event );\n\t}\n};\n\nexport const context = createContext( {\n\tadd: ( shortcut ) => {\n\t\tif ( globalShortcuts.size === 0 ) {\n\t\t\tdocument.addEventListener( 'keydown', globalListener );\n\t\t}\n\t\tglobalShortcuts.add( shortcut );\n\t},\n\tdelete: ( shortcut ) => {\n\t\tglobalShortcuts.delete( shortcut );\n\t\tif ( globalShortcuts.size === 0 ) {\n\t\t\tdocument.removeEventListener( 'keydown', globalListener );\n\t\t}\n\t},\n} );\n\ncontext.displayName = 'KeyboardShortcutsContext';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAE9B,MAAM,kBAAkB,oBAAI,IAAI;AAChC,MAAM,iBAAiB,CAAE,UAAW;AACnC,aAAY,oBAAoB,iBAAkB;AACjD,qBAAkB,KAAM;AAAA,EACzB;AACD;AAEO,MAAM,cAAU,8BAAe;AAAA,EACrC,KAAK,CAAE,aAAc;AACpB,QAAK,gBAAgB,SAAS,GAAI;AACjC,eAAS,iBAAkB,WAAW,cAAe;AAAA,IACtD;AACA,oBAAgB,IAAK,QAAS;AAAA,EAC/B;AAAA,EACA,QAAQ,CAAE,aAAc;AACvB,oBAAgB,OAAQ,QAAS;AACjC,QAAK,gBAAgB,SAAS,GAAI;AACjC,eAAS,oBAAqB,WAAW,cAAe;AAAA,IACzD;AAAA,EACD;AACD,CAAE;AAEF,QAAQ,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,48 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var use_shortcut_event_match_exports = {};
|
|
19
|
+
__export(use_shortcut_event_match_exports, {
|
|
20
|
+
default: () => useShortcutEventMatch
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns a function to check if a keyboard event matches a shortcut name.
|
|
20
|
-
*
|
|
21
|
-
* @return {Function} A function to check if a keyboard event matches a
|
|
22
|
-
* predefined shortcut combination.
|
|
23
|
-
*/
|
|
22
|
+
module.exports = __toCommonJS(use_shortcut_event_match_exports);
|
|
23
|
+
var import_data = require("@wordpress/data");
|
|
24
|
+
var import_keycodes = require("@wordpress/keycodes");
|
|
25
|
+
var import_store = require("../store");
|
|
24
26
|
function useShortcutEventMatch() {
|
|
25
|
-
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* A function to check if a keyboard event matches a predefined shortcut
|
|
31
|
-
* combination.
|
|
32
|
-
*
|
|
33
|
-
* @param {string} name Shortcut name.
|
|
34
|
-
* @param {KeyboardEvent} event Event to check.
|
|
35
|
-
*
|
|
36
|
-
* @return {boolean} True if the event matches any shortcuts, false if not.
|
|
37
|
-
*/
|
|
27
|
+
const { getAllShortcutKeyCombinations } = (0, import_data.useSelect)(
|
|
28
|
+
import_store.store
|
|
29
|
+
);
|
|
38
30
|
function isMatch(name, event) {
|
|
39
|
-
return getAllShortcutKeyCombinations(name).some(
|
|
40
|
-
modifier,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
31
|
+
return getAllShortcutKeyCombinations(name).some(
|
|
32
|
+
({ modifier, character }) => {
|
|
33
|
+
return import_keycodes.isKeyboardEvent[modifier](event, character);
|
|
34
|
+
}
|
|
35
|
+
);
|
|
45
36
|
}
|
|
46
37
|
return isMatch;
|
|
47
38
|
}
|
|
48
|
-
//# sourceMappingURL=use-shortcut-event-match.js.map
|
|
39
|
+
//# sourceMappingURL=use-shortcut-event-match.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-shortcut-event-match.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,sBAAgC;AAKhC,mBAAgD;AAQjC,SAAR,wBAAyC;AAC/C,QAAM,EAAE,8BAA8B,QAAI;AAAA,IACzC,aAAAA;AAAA,EACD;AAWA,WAAS,QAAS,MAAM,OAAQ;AAC/B,WAAO,8BAA+B,IAAK,EAAE;AAAA,MAC5C,CAAE,EAAE,UAAU,UAAU,MAAO;AAC9B,eAAO,gCAAiB,QAAS,EAAG,OAAO,SAAU;AAAA,MACtD;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": ["keyboardShortcutsStore"]
|
|
7
|
+
}
|
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var use_shortcut_exports = {};
|
|
29
|
+
__export(use_shortcut_exports, {
|
|
30
|
+
default: () => useShortcut
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* Internal dependencies
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Attach a keyboard shortcut handler.
|
|
21
|
-
*
|
|
22
|
-
* @param {string} name Shortcut name.
|
|
23
|
-
* @param {Function} callback Shortcut callback.
|
|
24
|
-
* @param {Object} options Shortcut options.
|
|
25
|
-
* @param {boolean} options.isDisabled Whether to disable to shortut.
|
|
26
|
-
*/
|
|
27
|
-
function useShortcut(name, callback, {
|
|
28
|
-
isDisabled = false
|
|
29
|
-
} = {}) {
|
|
30
|
-
const shortcuts = (0, _element.useContext)(_context.context);
|
|
31
|
-
const isMatch = (0, _useShortcutEventMatch.default)();
|
|
32
|
-
const callbackRef = (0, _element.useRef)();
|
|
33
|
-
(0, _element.useEffect)(() => {
|
|
32
|
+
module.exports = __toCommonJS(use_shortcut_exports);
|
|
33
|
+
var import_element = require("@wordpress/element");
|
|
34
|
+
var import_use_shortcut_event_match = __toESM(require("./use-shortcut-event-match"));
|
|
35
|
+
var import_context = require("../context");
|
|
36
|
+
function useShortcut(name, callback, { isDisabled = false } = {}) {
|
|
37
|
+
const shortcuts = (0, import_element.useContext)(import_context.context);
|
|
38
|
+
const isMatch = (0, import_use_shortcut_event_match.default)();
|
|
39
|
+
const callbackRef = (0, import_element.useRef)();
|
|
40
|
+
(0, import_element.useEffect)(() => {
|
|
34
41
|
callbackRef.current = callback;
|
|
35
42
|
}, [callback]);
|
|
36
|
-
(0,
|
|
43
|
+
(0, import_element.useEffect)(() => {
|
|
37
44
|
if (isDisabled) {
|
|
38
45
|
return;
|
|
39
46
|
}
|
|
@@ -48,4 +55,4 @@ function useShortcut(name, callback, {
|
|
|
48
55
|
};
|
|
49
56
|
}, [name, isDisabled, shortcuts]);
|
|
50
57
|
}
|
|
51
|
-
//# sourceMappingURL=use-shortcut.js.map
|
|
58
|
+
//# sourceMappingURL=use-shortcut.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-shortcut.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useShortcutEventMatch from './use-shortcut-event-match';\nimport { context } from '../context';\n\n/**\n * Attach a keyboard shortcut handler.\n *\n * @param {string} name Shortcut name.\n * @param {Function} callback Shortcut callback.\n * @param {Object} options Shortcut options.\n * @param {boolean} options.isDisabled Whether to disable to shortut.\n */\nexport default function useShortcut(\n\tname,\n\tcallback,\n\t{ isDisabled = false } = {}\n) {\n\tconst shortcuts = useContext( context );\n\tconst isMatch = useShortcutEventMatch();\n\tconst callbackRef = useRef();\n\n\tuseEffect( () => {\n\t\tcallbackRef.current = callback;\n\t}, [ callback ] );\n\n\tuseEffect( () => {\n\t\tif ( isDisabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction _callback( event ) {\n\t\t\tif ( isMatch( name, event ) ) {\n\t\t\t\tcallbackRef.current( event );\n\t\t\t}\n\t\t}\n\n\t\tshortcuts.add( _callback );\n\t\treturn () => {\n\t\t\tshortcuts.delete( _callback );\n\t\t};\n\t}, [ name, isDisabled, shortcuts ] );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8C;AAK9C,sCAAkC;AAClC,qBAAwB;AAUT,SAAR,YACN,MACA,UACA,EAAE,aAAa,MAAM,IAAI,CAAC,GACzB;AACD,QAAM,gBAAY,2BAAY,sBAAQ;AACtC,QAAM,cAAU,gCAAAA,SAAsB;AACtC,QAAM,kBAAc,uBAAO;AAE3B,gCAAW,MAAM;AAChB,gBAAY,UAAU;AAAA,EACvB,GAAG,CAAE,QAAS,CAAE;AAEhB,gCAAW,MAAM;AAChB,QAAK,YAAa;AACjB;AAAA,IACD;AAEA,aAAS,UAAW,OAAQ;AAC3B,UAAK,QAAS,MAAM,KAAM,GAAI;AAC7B,oBAAY,QAAS,KAAM;AAAA,MAC5B;AAAA,IACD;AAEA,cAAU,IAAK,SAAU;AACzB,WAAO,MAAM;AACZ,gBAAU,OAAQ,SAAU;AAAA,IAC7B;AAAA,EACD,GAAG,CAAE,MAAM,YAAY,SAAU,CAAE;AACpC;",
|
|
6
|
+
"names": ["useShortcutEventMatch"]
|
|
7
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,35 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return _useShortcutEventMatch.default;
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
16
|
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var index_exports = {};
|
|
29
|
+
__export(index_exports, {
|
|
30
|
+
ShortcutProvider: () => import_shortcut_provider.ShortcutProvider,
|
|
31
|
+
__unstableUseShortcutEventMatch: () => import_use_shortcut_event_match.default,
|
|
32
|
+
store: () => import_store.store,
|
|
33
|
+
useShortcut: () => import_use_shortcut.default
|
|
18
34
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_store = require("./store");
|
|
37
|
+
var import_use_shortcut = __toESM(require("./hooks/use-shortcut"));
|
|
38
|
+
var import_shortcut_provider = require("./components/shortcut-provider");
|
|
39
|
+
var import_use_shortcut_event_match = __toESM(require("./hooks/use-shortcut-event-match"));
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
ShortcutProvider,
|
|
43
|
+
__unstableUseShortcutEventMatch,
|
|
44
|
+
store,
|
|
45
|
+
useShortcut
|
|
30
46
|
});
|
|
31
|
-
|
|
32
|
-
var _useShortcut = _interopRequireDefault(require("./hooks/use-shortcut"));
|
|
33
|
-
var _shortcutProvider = require("./components/shortcut-provider");
|
|
34
|
-
var _useShortcutEventMatch = _interopRequireDefault(require("./hooks/use-shortcut-event-match"));
|
|
35
|
-
//# sourceMappingURL=index.js.map
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"sourcesContent": ["export { store } from './store';\nexport { default as useShortcut } from './hooks/use-shortcut';\nexport { ShortcutProvider } from './components/shortcut-provider';\nexport { default as __unstableUseShortcutEventMatch } from './hooks/use-shortcut-event-match';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,0BAAuC;AACvC,+BAAiC;AACjC,sCAA2D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/store/actions.js
CHANGED
|
@@ -1,78 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var actions_exports = {};
|
|
19
|
+
__export(actions_exports, {
|
|
20
|
+
registerShortcut: () => registerShortcut,
|
|
21
|
+
unregisterShortcut: () => unregisterShortcut
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
exports.unregisterShortcut = unregisterShortcut;
|
|
8
|
-
/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Keyboard key combination.
|
|
12
|
-
*
|
|
13
|
-
* @typedef {Object} WPShortcutKeyCombination
|
|
14
|
-
*
|
|
15
|
-
* @property {string} character Character.
|
|
16
|
-
* @property {WPKeycodeModifier|undefined} modifier Modifier.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Configuration of a registered keyboard shortcut.
|
|
21
|
-
*
|
|
22
|
-
* @typedef {Object} WPShortcutConfig
|
|
23
|
-
*
|
|
24
|
-
* @property {string} name Shortcut name.
|
|
25
|
-
* @property {string} category Shortcut category.
|
|
26
|
-
* @property {string} description Shortcut description.
|
|
27
|
-
* @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.
|
|
28
|
-
* @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Returns an action object used to register a new keyboard shortcut.
|
|
33
|
-
*
|
|
34
|
-
* @param {WPShortcutConfig} config Shortcut config.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
*
|
|
38
|
-
*```js
|
|
39
|
-
* import { useEffect } from 'react';
|
|
40
|
-
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
41
|
-
* import { useSelect, useDispatch } from '@wordpress/data';
|
|
42
|
-
* import { __ } from '@wordpress/i18n';
|
|
43
|
-
*
|
|
44
|
-
* const ExampleComponent = () => {
|
|
45
|
-
* const { registerShortcut } = useDispatch( keyboardShortcutsStore );
|
|
46
|
-
*
|
|
47
|
-
* useEffect( () => {
|
|
48
|
-
* registerShortcut( {
|
|
49
|
-
* name: 'custom/my-custom-shortcut',
|
|
50
|
-
* category: 'my-category',
|
|
51
|
-
* description: __( 'My custom shortcut' ),
|
|
52
|
-
* keyCombination: {
|
|
53
|
-
* modifier: 'primary',
|
|
54
|
-
* character: 'j',
|
|
55
|
-
* },
|
|
56
|
-
* } );
|
|
57
|
-
* }, [] );
|
|
58
|
-
*
|
|
59
|
-
* const shortcut = useSelect(
|
|
60
|
-
* ( select ) =>
|
|
61
|
-
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
62
|
-
* 'custom/my-custom-shortcut'
|
|
63
|
-
* ),
|
|
64
|
-
* []
|
|
65
|
-
* );
|
|
66
|
-
*
|
|
67
|
-
* return shortcut ? (
|
|
68
|
-
* <p>{ __( 'Shortcut is registered.' ) }</p>
|
|
69
|
-
* ) : (
|
|
70
|
-
* <p>{ __( 'Shortcut is not registered.' ) }</p>
|
|
71
|
-
* );
|
|
72
|
-
* };
|
|
73
|
-
*```
|
|
74
|
-
* @return {Object} action.
|
|
75
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(actions_exports);
|
|
76
24
|
function registerShortcut({
|
|
77
25
|
name,
|
|
78
26
|
category,
|
|
@@ -81,7 +29,7 @@ function registerShortcut({
|
|
|
81
29
|
aliases
|
|
82
30
|
}) {
|
|
83
31
|
return {
|
|
84
|
-
type:
|
|
32
|
+
type: "REGISTER_SHORTCUT",
|
|
85
33
|
name,
|
|
86
34
|
category,
|
|
87
35
|
keyCombination,
|
|
@@ -89,48 +37,15 @@ function registerShortcut({
|
|
|
89
37
|
description
|
|
90
38
|
};
|
|
91
39
|
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Returns an action object used to unregister a keyboard shortcut.
|
|
95
|
-
*
|
|
96
|
-
* @param {string} name Shortcut name.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
*
|
|
100
|
-
*```js
|
|
101
|
-
* import { useEffect } from 'react';
|
|
102
|
-
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
103
|
-
* import { useSelect, useDispatch } from '@wordpress/data';
|
|
104
|
-
* import { __ } from '@wordpress/i18n';
|
|
105
|
-
*
|
|
106
|
-
* const ExampleComponent = () => {
|
|
107
|
-
* const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
|
|
108
|
-
*
|
|
109
|
-
* useEffect( () => {
|
|
110
|
-
* unregisterShortcut( 'core/editor/next-region' );
|
|
111
|
-
* }, [] );
|
|
112
|
-
*
|
|
113
|
-
* const shortcut = useSelect(
|
|
114
|
-
* ( select ) =>
|
|
115
|
-
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
116
|
-
* 'core/editor/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
|
-
*```
|
|
128
|
-
* @return {Object} action.
|
|
129
|
-
*/
|
|
130
40
|
function unregisterShortcut(name) {
|
|
131
41
|
return {
|
|
132
|
-
type:
|
|
42
|
+
type: "UNREGISTER_SHORTCUT",
|
|
133
43
|
name
|
|
134
44
|
};
|
|
135
45
|
}
|
|
136
|
-
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
registerShortcut,
|
|
49
|
+
unregisterShortcut
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=actions.js.map
|