@wordpress/keyboard-shortcuts 5.44.0 → 5.44.1-next.v.202604201441.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/README.md +5 -9
- package/build/components/shortcut-provider.cjs +7 -3
- package/build/components/shortcut-provider.cjs.map +3 -3
- package/build/context.cjs +2 -1
- package/build/context.cjs.map +3 -3
- package/build/hooks/use-shortcut-event-match.cjs +16 -9
- package/build/hooks/use-shortcut-event-match.cjs.map +3 -3
- package/build/hooks/use-shortcut.cjs +4 -3
- package/build/hooks/use-shortcut.cjs.map +3 -3
- package/build/index.cjs +2 -1
- package/build/index.cjs.map +2 -2
- package/build/store/actions.cjs +2 -1
- package/build/store/actions.cjs.map +3 -3
- package/build/store/index.cjs +2 -1
- package/build/store/index.cjs.map +3 -3
- package/build/store/reducer.cjs +2 -1
- package/build/store/reducer.cjs.map +3 -3
- package/build/store/selectors.cjs +14 -2
- package/build/store/selectors.cjs.map +3 -3
- package/build/store/types.cjs +19 -0
- package/build/store/types.cjs.map +7 -0
- package/build-module/components/shortcut-provider.mjs +6 -3
- package/build-module/components/shortcut-provider.mjs.map +3 -3
- package/build-module/context.mjs +1 -1
- package/build-module/context.mjs.map +3 -3
- package/build-module/hooks/use-shortcut-event-match.mjs +15 -9
- package/build-module/hooks/use-shortcut-event-match.mjs.map +3 -3
- package/build-module/hooks/use-shortcut.mjs +3 -3
- package/build-module/hooks/use-shortcut.mjs.map +3 -3
- package/build-module/index.mjs +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-module/store/actions.mjs +1 -1
- package/build-module/store/actions.mjs.map +3 -3
- package/build-module/store/index.mjs +1 -1
- package/build-module/store/index.mjs.map +3 -3
- package/build-module/store/reducer.mjs +1 -1
- package/build-module/store/reducer.mjs.map +3 -3
- package/build-module/store/selectors.mjs +13 -2
- package/build-module/store/selectors.mjs.map +3 -3
- package/build-module/store/types.mjs +1 -0
- package/build-module/store/types.mjs.map +7 -0
- package/build-types/components/shortcut-provider.d.ts +15 -0
- package/build-types/components/shortcut-provider.d.ts.map +1 -0
- package/build-types/context.d.ts +8 -0
- package/build-types/context.d.ts.map +1 -0
- package/build-types/hooks/use-shortcut-event-match.d.ts +8 -0
- package/build-types/hooks/use-shortcut-event-match.d.ts.map +1 -0
- package/build-types/hooks/use-shortcut.d.ts +14 -0
- package/build-types/hooks/use-shortcut.d.ts.map +1 -0
- package/build-types/hooks/use-shortcut.native.d.ts +3 -0
- package/build-types/hooks/use-shortcut.native.d.ts.map +1 -0
- package/build-types/index.d.ts +5 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +114 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/index.d.ts +9 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +16 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +321 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/build-types/store/types.d.ts +9 -0
- package/build-types/store/types.d.ts.map +1 -0
- package/package.json +8 -6
- package/src/components/{shortcut-provider.js → shortcut-provider.tsx} +16 -6
- package/src/{context.js → context.ts} +12 -5
- package/src/hooks/use-shortcut-event-match.ts +51 -0
- package/src/hooks/{use-shortcut.js → use-shortcut.ts} +15 -11
- package/src/store/{actions.js → actions.ts} +21 -19
- package/src/store/{index.js → index.ts} +0 -2
- package/src/store/{reducer.js → reducer.ts} +13 -4
- package/src/store/{selectors.js → selectors.ts} +56 -28
- package/src/store/types.ts +10 -0
- package/src/hooks/use-shortcut-event-match.js +0 -41
- /package/src/hooks/{use-shortcut.native.js → use-shortcut.native.ts} +0 -0
- /package/src/{index.js → index.ts} +0 -0
package/README.md
CHANGED
|
@@ -22,11 +22,11 @@ Handles callbacks added to context by `useShortcut`. Adding a provider allows to
|
|
|
22
22
|
|
|
23
23
|
_Parameters_
|
|
24
24
|
|
|
25
|
-
- _props_ `
|
|
25
|
+
- _props_ `ShortcutProviderProps`: Props to pass to `div`.
|
|
26
26
|
|
|
27
27
|
_Returns_
|
|
28
28
|
|
|
29
|
-
-
|
|
29
|
+
- Component.
|
|
30
30
|
|
|
31
31
|
### store
|
|
32
32
|
|
|
@@ -36,10 +36,6 @@ _Related_
|
|
|
36
36
|
|
|
37
37
|
- <https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore>
|
|
38
38
|
|
|
39
|
-
_Type_
|
|
40
|
-
|
|
41
|
-
- `Object`
|
|
42
|
-
|
|
43
39
|
### useShortcut
|
|
44
40
|
|
|
45
41
|
Attach a keyboard shortcut handler.
|
|
@@ -47,9 +43,9 @@ Attach a keyboard shortcut handler.
|
|
|
47
43
|
_Parameters_
|
|
48
44
|
|
|
49
45
|
- _name_ `string`: Shortcut name.
|
|
50
|
-
- _callback_ `
|
|
51
|
-
- _options_ `
|
|
52
|
-
- _options.isDisabled_ `
|
|
46
|
+
- _callback_ `( event: KeyboardEvent ) => void`: Shortcut callback.
|
|
47
|
+
- _options_ `UseShortcutOptions`: Shortcut options.
|
|
48
|
+
- _options.isDisabled_ `UseShortcutOptions[ 'isDisabled' ]`: Whether to disable the shortcut.
|
|
53
49
|
|
|
54
50
|
<!-- END TOKEN(Autogenerated API docs) -->
|
|
55
51
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/keyboard-shortcuts/src/components/shortcut-provider.
|
|
20
|
+
// packages/keyboard-shortcuts/src/components/shortcut-provider.tsx
|
|
20
21
|
var shortcut_provider_exports = {};
|
|
21
22
|
__export(shortcut_provider_exports, {
|
|
22
23
|
ShortcutProvider: () => ShortcutProvider
|
|
@@ -27,13 +28,16 @@ var import_context = require("../context.cjs");
|
|
|
27
28
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
29
|
var { Provider } = import_context.context;
|
|
29
30
|
function ShortcutProvider(props) {
|
|
30
|
-
const [keyboardShortcuts] = (0, import_element.useState)(
|
|
31
|
+
const [keyboardShortcuts] = (0, import_element.useState)(
|
|
32
|
+
() => /* @__PURE__ */ new Set()
|
|
33
|
+
);
|
|
31
34
|
function onKeyDown(event) {
|
|
32
35
|
if (props.onKeyDown) {
|
|
33
36
|
props.onKeyDown(event);
|
|
34
37
|
}
|
|
38
|
+
const nativeEvent = event.nativeEvent;
|
|
35
39
|
for (const keyboardShortcut of keyboardShortcuts) {
|
|
36
|
-
keyboardShortcut(
|
|
40
|
+
keyboardShortcut(nativeEvent);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, { value: keyboardShortcuts, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...props, onKeyDown }) });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/components/shortcut-provider.
|
|
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
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/components/shortcut-provider.tsx"],
|
|
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\ntype ShortcutCallback = ( event: KeyboardEvent ) => void;\n\ninterface ShortcutProviderProps extends React.HTMLAttributes< HTMLDivElement > {\n\tonKeyDown?: ( event: React.KeyboardEvent< HTMLDivElement > ) => void;\n}\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 props Props to pass to `div`.\n *\n * @return Component.\n */\nexport function ShortcutProvider( props: ShortcutProviderProps ) {\n\tconst [ keyboardShortcuts ] = useState(\n\t\t() => new Set< ShortcutCallback >()\n\t);\n\n\tfunction onKeyDown( event: React.KeyboardEvent< HTMLDivElement > ) {\n\t\tif ( props.onKeyDown ) {\n\t\t\tprops.onKeyDown( event );\n\t\t}\n\n\t\t// Convert React event to native KeyboardEvent for compatibility\n\t\tconst nativeEvent = event.nativeEvent;\n\t\tfor ( const keyboardShortcut of keyboardShortcuts ) {\n\t\t\tkeyboardShortcut( nativeEvent );\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;AAGA,qBAAyB;AAKzB,qBAAwB;AAuCrB;AArCH,IAAM,EAAE,SAAS,IAAI;AAiBd,SAAS,iBAAkB,OAA+B;AAChE,QAAM,CAAE,iBAAkB,QAAI;AAAA,IAC7B,MAAM,oBAAI,IAAwB;AAAA,EACnC;AAEA,WAAS,UAAW,OAA+C;AAClE,QAAK,MAAM,WAAY;AACtB,YAAM,UAAW,KAAM;AAAA,IACxB;AAGA,UAAM,cAAc,MAAM;AAC1B,eAAY,oBAAoB,mBAAoB;AACnD,uBAAkB,WAAY;AAAA,IAC/B;AAAA,EACD;AAGA,SACC,4CAAC,YAAS,OAAQ,mBACjB,sDAAC,SAAM,GAAG,OAAQ,WAAwB,GAC3C;AAGF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/context.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/keyboard-shortcuts/src/context.
|
|
20
|
+
// packages/keyboard-shortcuts/src/context.ts
|
|
20
21
|
var context_exports = {};
|
|
21
22
|
__export(context_exports, {
|
|
22
23
|
context: () => context
|
package/build/context.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/context.
|
|
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": "
|
|
3
|
+
"sources": ["../src/context.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\ntype ShortcutCallback = ( event: KeyboardEvent ) => void;\n\ninterface ShortcutContextType {\n\tadd: ( shortcut: ShortcutCallback ) => void;\n\tdelete: ( shortcut: ShortcutCallback ) => void;\n}\n\nconst globalShortcuts = new Set< ShortcutCallback >();\nconst globalListener = ( event: KeyboardEvent ) => {\n\tfor ( const keyboardShortcut of globalShortcuts ) {\n\t\tkeyboardShortcut( event );\n\t}\n};\n\nexport const context = createContext< ShortcutContextType >( {\n\tadd: ( shortcut: ShortcutCallback ) => {\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: ShortcutCallback ) => {\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;AAS9B,IAAM,kBAAkB,oBAAI,IAAwB;AACpD,IAAM,iBAAiB,CAAE,UAA0B;AAClD,aAAY,oBAAoB,iBAAkB;AACjD,qBAAkB,KAAM;AAAA,EACzB;AACD;AAEO,IAAM,cAAU,8BAAsC;AAAA,EAC5D,KAAK,CAAE,aAAgC;AACtC,QAAK,gBAAgB,SAAS,GAAI;AACjC,eAAS,iBAAkB,WAAW,cAAe;AAAA,IACtD;AACA,oBAAgB,IAAK,QAAS;AAAA,EAC/B;AAAA,EACA,QAAQ,CAAE,aAAgC;AACzC,oBAAgB,OAAQ,QAAS;AACjC,QAAK,gBAAgB,SAAS,GAAI;AACjC,eAAS,oBAAqB,WAAW,cAAe;AAAA,IACzD;AAAA,EACD;AACD,CAAE;AAEF,QAAQ,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,26 +17,32 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/keyboard-shortcuts/src/hooks/use-shortcut-event-match.
|
|
20
|
+
// packages/keyboard-shortcuts/src/hooks/use-shortcut-event-match.ts
|
|
20
21
|
var use_shortcut_event_match_exports = {};
|
|
21
22
|
__export(use_shortcut_event_match_exports, {
|
|
22
23
|
default: () => useShortcutEventMatch
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(use_shortcut_event_match_exports);
|
|
25
26
|
var import_data = require("@wordpress/data");
|
|
27
|
+
var import_element = require("@wordpress/element");
|
|
26
28
|
var import_keycodes = require("@wordpress/keycodes");
|
|
27
29
|
var import_store = require("../store/index.cjs");
|
|
28
30
|
function useShortcutEventMatch() {
|
|
29
31
|
const { getAllShortcutKeyCombinations } = (0, import_data.useSelect)(
|
|
30
32
|
import_store.store
|
|
31
33
|
);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
return (0, import_element.useCallback)(
|
|
35
|
+
(name, event) => {
|
|
36
|
+
return getAllShortcutKeyCombinations(name).some(
|
|
37
|
+
(combination) => {
|
|
38
|
+
if (!combination) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return import_keycodes.isKeyboardEvent[combination.modifier ?? "undefined"](event, combination.character);
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
[getAllShortcutKeyCombinations]
|
|
46
|
+
);
|
|
40
47
|
}
|
|
41
48
|
//# sourceMappingURL=use-shortcut-event-match.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/use-shortcut-event-match.
|
|
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
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/hooks/use-shortcut-event-match.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useCallback } from '@wordpress/element';\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 A function to check if a keyboard event matches a\n * predefined shortcut combination.\n */\nexport default function useShortcutEventMatch(): (\n\tname: string,\n\tevent: KeyboardEvent\n) => boolean {\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 name Shortcut name.\n\t * @param event Event to check.\n\t *\n\t * @return True if the event matches the shortcuts, false if not.\n\t */\n\treturn useCallback(\n\t\t( name: string, event: KeyboardEvent ) => {\n\t\t\treturn getAllShortcutKeyCombinations( name ).some(\n\t\t\t\t( combination ) => {\n\t\t\t\t\tif ( ! combination ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn isKeyboardEvent[\n\t\t\t\t\t\tcombination.modifier ?? 'undefined'\n\t\t\t\t\t]( event, combination.character );\n\t\t\t\t}\n\t\t\t);\n\t\t},\n\t\t[ getAllShortcutKeyCombinations ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,qBAA4B;AAC5B,sBAAgC;AAKhC,mBAAgD;AAQjC,SAAR,wBAGM;AACZ,QAAM,EAAE,8BAA8B,QAAI;AAAA,IACzC,aAAAA;AAAA,EACD;AAWA,aAAO;AAAA,IACN,CAAE,MAAc,UAA0B;AACzC,aAAO,8BAA+B,IAAK,EAAE;AAAA,QAC5C,CAAE,gBAAiB;AAClB,cAAK,CAAE,aAAc;AACpB,mBAAO;AAAA,UACR;AACA,iBAAO,gCACN,YAAY,YAAY,WACzB,EAAG,OAAO,YAAY,SAAU;AAAA,QACjC;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,6BAA8B;AAAA,EACjC;AACD;",
|
|
6
6
|
"names": ["keyboardShortcutsStore"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
27
|
));
|
|
27
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
29
|
|
|
29
|
-
// packages/keyboard-shortcuts/src/hooks/use-shortcut.
|
|
30
|
+
// packages/keyboard-shortcuts/src/hooks/use-shortcut.ts
|
|
30
31
|
var use_shortcut_exports = {};
|
|
31
32
|
__export(use_shortcut_exports, {
|
|
32
33
|
default: () => useShortcut
|
|
@@ -47,7 +48,7 @@ function useShortcut(name, callback, { isDisabled = false } = {}) {
|
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
49
50
|
function _callback(event) {
|
|
50
|
-
if (isMatch(name, event)) {
|
|
51
|
+
if (isMatch(name, event) && callbackRef.current) {
|
|
51
52
|
callbackRef.current(event);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -55,6 +56,6 @@ function useShortcut(name, callback, { isDisabled = false } = {}) {
|
|
|
55
56
|
return () => {
|
|
56
57
|
shortcuts.delete(_callback);
|
|
57
58
|
};
|
|
58
|
-
}, [name, isDisabled, shortcuts]);
|
|
59
|
+
}, [name, isDisabled, shortcuts, isMatch]);
|
|
59
60
|
}
|
|
60
61
|
//# sourceMappingURL=use-shortcut.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/hooks/use-shortcut.
|
|
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
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/hooks/use-shortcut.ts"],
|
|
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\ninterface UseShortcutOptions {\n\tisDisabled?: boolean;\n}\n\n/**\n * Attach a keyboard shortcut handler.\n *\n * @param name Shortcut name.\n * @param callback Shortcut callback.\n * @param options Shortcut options.\n * @param options.isDisabled Whether to disable the shortcut.\n */\nexport default function useShortcut(\n\tname: string,\n\tcallback: ( event: KeyboardEvent ) => void,\n\t{ isDisabled = false }: UseShortcutOptions = {}\n) {\n\tconst shortcuts = useContext( context );\n\tconst isMatch = useShortcutEventMatch();\n\tconst callbackRef = useRef< ( event: KeyboardEvent ) => void >();\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: KeyboardEvent ) {\n\t\t\tif ( isMatch( name, event ) && callbackRef.current ) {\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, isMatch ] );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8C;AAK9C,sCAAkC;AAClC,qBAAwB;AAcT,SAAR,YACN,MACA,UACA,EAAE,aAAa,MAAM,IAAwB,CAAC,GAC7C;AACD,QAAM,gBAAY,2BAAY,sBAAQ;AACtC,QAAM,cAAU,gCAAAA,SAAsB;AACtC,QAAM,kBAAc,uBAA2C;AAE/D,gCAAW,MAAM;AAChB,gBAAY,UAAU;AAAA,EACvB,GAAG,CAAE,QAAS,CAAE;AAEhB,gCAAW,MAAM;AAChB,QAAK,YAAa;AACjB;AAAA,IACD;AAEA,aAAS,UAAW,OAAuB;AAC1C,UAAK,QAAS,MAAM,KAAM,KAAK,YAAY,SAAU;AACpD,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,WAAW,OAAQ,CAAE;AAC7C;",
|
|
6
6
|
"names": ["useShortcutEventMatch"]
|
|
7
7
|
}
|
package/build/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
27
|
));
|
|
27
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
29
|
|
|
29
|
-
// packages/keyboard-shortcuts/src/index.
|
|
30
|
+
// packages/keyboard-shortcuts/src/index.ts
|
|
30
31
|
var index_exports = {};
|
|
31
32
|
__export(index_exports, {
|
|
32
33
|
ShortcutProvider: () => import_shortcut_provider.ShortcutProvider,
|
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,0BAAuC;AACvC,+BAAiC;AACjC,sCAA2D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/store/actions.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/keyboard-shortcuts/src/store/actions.
|
|
20
|
+
// packages/keyboard-shortcuts/src/store/actions.ts
|
|
20
21
|
var actions_exports = {};
|
|
21
22
|
__export(actions_exports, {
|
|
22
23
|
registerShortcut: () => registerShortcut,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/actions.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/store/actions.ts"],
|
|
4
|
+
"sourcesContent": ["import type { WPKeycodeModifier } from '@wordpress/keycodes';\n\n/**\n * Keyboard key combination.\n */\nexport interface ShortcutKeyCombination {\n\tcharacter: string;\n\tmodifier: WPKeycodeModifier | undefined;\n}\n\n/**\n * Configuration of a registered keyboard shortcut.\n */\nexport interface ShortcutConfig {\n\tname: string;\n\tcategory: string;\n\tdescription: string;\n\tkeyCombination: ShortcutKeyCombination;\n\taliases?: ShortcutKeyCombination[];\n}\n\nexport type ShortcutAction =\n\t| ReturnType< typeof registerShortcut >\n\t| ReturnType< typeof unregisterShortcut >;\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {ShortcutConfig} config Shortcut config.\n *\n * @example\n *\n *```js\n * import { useEffect } from 'react';\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { registerShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * registerShortcut( {\n * name: 'custom/my-custom-shortcut',\n * category: 'my-category',\n * description: __( 'My custom shortcut' ),\n * keyCombination: {\n * modifier: 'primary',\n * character: 'j',\n * },\n * } );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'custom/my-custom-shortcut'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is registered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is not registered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n}: ShortcutConfig ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT' as const,\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { useEffect } from 'react';\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * unregisterShortcut( 'core/editor/next-region' );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is not unregistered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is unregistered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function unregisterShortcut( name: string ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT' as const,\n\t\tname,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsEO,SAAS,iBAAkB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAoB;AACnB,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAuCO,SAAS,mBAAoB,MAAe;AAClD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/store/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -26,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
27
|
));
|
|
27
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
29
|
|
|
29
|
-
// packages/keyboard-shortcuts/src/store/index.
|
|
30
|
+
// packages/keyboard-shortcuts/src/store/index.ts
|
|
30
31
|
var store_exports = {};
|
|
31
32
|
__export(store_exports, {
|
|
32
33
|
store: () => store
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\n\nconst STORE_NAME = 'core/keyboard-shortcuts';\n\n/**\n * Store definition for the keyboard shortcuts namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/store/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\n\nconst STORE_NAME = 'core/keyboard-shortcuts';\n\n/**\n * Store definition for the keyboard shortcuts namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,cAAyB;AACzB,gBAA2B;AAE3B,IAAM,aAAa;AAOZ,IAAM,YAAQ,8BAAkB,YAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
|
|
6
6
|
"names": ["reducer"]
|
|
7
7
|
}
|
package/build/store/reducer.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/keyboard-shortcuts/src/store/reducer.
|
|
20
|
+
// packages/keyboard-shortcuts/src/store/reducer.ts
|
|
20
21
|
var reducer_exports = {};
|
|
21
22
|
__export(reducer_exports, {
|
|
22
23
|
default: () => reducer_default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/reducer.
|
|
4
|
-
"sourcesContent": ["/**\n * Reducer returning the registered shortcuts\n *\n * @param
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/store/reducer.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { ShortcutAction } from './actions';\nimport type { ShortcutsState } from './types';\n\n/**\n * Reducer returning the registered shortcuts\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Updated state.\n */\nfunction reducer(\n\tstate: ShortcutsState = {},\n\taction: ShortcutAction\n): ShortcutsState {\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,SAAS,QACR,QAAwB,CAAC,GACzB,QACiB;AACjB,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,OAAO,IAAK,GAAG;AAAA,UAChB,UAAU,OAAO;AAAA,UACjB,gBAAgB,OAAO;AAAA,UACvB,SAAS,OAAO;AAAA,UAChB,aAAa,OAAO;AAAA,QACrB;AAAA,MACD;AAAA,IACD,KAAK;AACJ,YAAM,EAAE,CAAE,OAAO,IAAK,GAAG,YAAY,GAAG,eAAe,IAAI;AAC3D,aAAO;AAAA,EACT;AAEA,SAAO;AACR;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -16,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
};
|
|
17
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
19
|
|
|
19
|
-
// packages/keyboard-shortcuts/src/store/selectors.
|
|
20
|
+
// packages/keyboard-shortcuts/src/store/selectors.ts
|
|
20
21
|
var selectors_exports = {};
|
|
21
22
|
__export(selectors_exports, {
|
|
22
23
|
getAllShortcutKeyCombinations: () => getAllShortcutKeyCombinations,
|
|
@@ -32,8 +33,17 @@ var import_data = require("@wordpress/data");
|
|
|
32
33
|
var import_keycodes = require("@wordpress/keycodes");
|
|
33
34
|
var EMPTY_ARRAY = [];
|
|
34
35
|
var FORMATTING_METHODS = {
|
|
36
|
+
/**
|
|
37
|
+
* Display formatting.
|
|
38
|
+
*/
|
|
35
39
|
display: import_keycodes.displayShortcut,
|
|
40
|
+
/**
|
|
41
|
+
* Raw shortcut formatting.
|
|
42
|
+
*/
|
|
36
43
|
raw: import_keycodes.rawShortcut,
|
|
44
|
+
/**
|
|
45
|
+
* ARIA label formatting.
|
|
46
|
+
*/
|
|
37
47
|
ariaLabel: import_keycodes.shortcutAriaLabel
|
|
38
48
|
};
|
|
39
49
|
function getKeyCombinationRepresentation(shortcut, representation) {
|
|
@@ -62,7 +72,9 @@ var getAllShortcutKeyCombinations = (0, import_data.createSelector)(
|
|
|
62
72
|
return [
|
|
63
73
|
getShortcutKeyCombination(state, name),
|
|
64
74
|
...getShortcutAliases(state, name)
|
|
65
|
-
].filter(
|
|
75
|
+
].filter(
|
|
76
|
+
(combination) => !!combination
|
|
77
|
+
);
|
|
66
78
|
},
|
|
67
79
|
(state, name) => [state[name]]
|
|
68
80
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/selectors.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\nimport {\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n\trawShortcut,\n} from '@wordpress/keycodes';\n\n/** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */\n\n/** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Shortcut formatting methods.\n *\n * @property {WPKeycodeHandlerByModifier} display Display formatting.\n * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.\n * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.\n */\nconst FORMATTING_METHODS = {\n\tdisplay: displayShortcut,\n\traw: rawShortcut,\n\tariaLabel: shortcutAriaLabel,\n};\n\n/**\n * Returns a string representing the key combination.\n *\n * @param {?WPShortcutKeyCombination} shortcut Key combination.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n *\n * @return {?string} Shortcut representation.\n */\nfunction getKeyCombinationRepresentation( shortcut, representation ) {\n\tif ( ! shortcut ) {\n\t\treturn null;\n\t}\n\n\treturn shortcut.modifier\n\t\t? FORMATTING_METHODS[ representation ][ shortcut.modifier ](\n\t\t\t\tshortcut.character\n\t\t )\n\t\t: shortcut.character;\n}\n\n/**\n * Returns the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const {character, modifier} = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * <div>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </div>\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination?} Key combination.\n */\nexport function getShortcutKeyCombination( state, name ) {\n\treturn state[ name ] ? state[ name ].keyCombination : null;\n}\n\n/**\n * Returns a string representing the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const {display, raw, ariaLabel} = useSelect(\n * ( select ) =>{\n * return {\n * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')\n * }\n * },\n * []\n * );\n *\n * return (\n * <ul>\n * <li>{ sprintf( 'display string: %s', display ) }</li>\n * <li>{ sprintf( 'raw string: %s', raw ) }</li>\n * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>\n * </ul>\n * );\n * };\n *```\n *\n * @return {?string} Shortcut representation.\n */\nexport function getShortcutRepresentation(\n\tstate,\n\tname,\n\trepresentation = 'display'\n) {\n\tconst shortcut = getShortcutKeyCombination( state, name );\n\treturn getKeyCombinationRepresentation( shortcut, representation );\n}\n\n/**\n * Returns the shortcut description given its name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutDescription = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),\n * []\n * );\n *\n * return shortcutDescription ? (\n * <div>{ shortcutDescription }</div>\n * ) : (\n * <div>{ __( 'No description.' ) }</div>\n * );\n * };\n *```\n * @return {?string} Shortcut description.\n */\nexport function getShortcutDescription( state, name ) {\n\treturn state[ name ] ? state[ name ].description : null;\n}\n\n/**\n * Returns the aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutAliases = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutAliases(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * shortcutAliases.length > 0 && (\n * <ul>\n * { shortcutAliases.map( ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport function getShortcutAliases( state, name ) {\n\treturn state[ name ] && state[ name ].aliases\n\t\t? state[ name ].aliases\n\t\t: EMPTY_ARRAY;\n}\n\n/**\n * Returns the shortcuts that include aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutKeyCombinations.map(\n * ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {WPShortcutKeyCombination[]} Key combinations.\n */\nexport const getAllShortcutKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn [\n\t\t\tgetShortcutKeyCombination( state, name ),\n\t\t\t...getShortcutAliases( state, name ),\n\t\t].filter( Boolean );\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the raw representation of all the keyboard combinations of a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutRawKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutRawKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutRawKeyCombinations.map(\n * ( shortcutRawKeyCombination, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * ' <code>%s</code>',\n * shortcutRawKeyCombination\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {string[]} Shortcuts.\n */\nexport const getAllShortcutRawKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn getAllShortcutKeyCombinations( state, name ).map(\n\t\t\t( combination ) =>\n\t\t\t\tgetKeyCombinationRepresentation( combination, 'raw' )\n\t\t);\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the shortcut names list for a given category name.\n *\n * @param {Object} state Global state.\n * @param {string} name Category name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * const categoryShortcuts = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getCategoryShortcuts(\n * 'block'\n * ),\n * []\n * );\n *\n * return (\n * categoryShortcuts.length > 0 && (\n * <ul>\n * { categoryShortcuts.map( ( categoryShortcut ) => (\n * <li key={ categoryShortcut }>{ categoryShortcut }</li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n * @return {string[]} Shortcut names.\n */\nexport const getCategoryShortcuts = createSelector(\n\t( state, 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"],
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../../src/store/selectors.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\nimport {\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n\trawShortcut,\n} from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport type { ShortcutKeyCombination } from './actions';\n\ninterface ShortcutState {\n\tcategory: string;\n\tkeyCombination: ShortcutKeyCombination;\n\taliases?: ShortcutKeyCombination[];\n\tdescription: string;\n}\n\ntype ShortcutsState = Record< string, ShortcutState >;\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n */\nconst EMPTY_ARRAY: ShortcutKeyCombination[] = [];\n\n/**\n * Shortcut formatting methods.\n */\nconst FORMATTING_METHODS = {\n\t/**\n\t * Display formatting.\n\t */\n\tdisplay: displayShortcut,\n\t/**\n\t * Raw shortcut formatting.\n\t */\n\traw: rawShortcut,\n\t/**\n\t * ARIA label formatting.\n\t */\n\tariaLabel: shortcutAriaLabel,\n};\n\n/**\n * Returns a string representing the key combination.\n *\n * @param shortcut Key combination.\n * @param representation Type of representation\n * (display, raw, ariaLabel).\n *\n * @return Shortcut representation.\n */\nfunction getKeyCombinationRepresentation(\n\tshortcut: ShortcutKeyCombination | null,\n\trepresentation: keyof typeof FORMATTING_METHODS\n): string | null {\n\tif ( ! shortcut ) {\n\t\treturn null;\n\t}\n\n\treturn shortcut.modifier\n\t\t? FORMATTING_METHODS[ representation ][ shortcut.modifier ](\n\t\t\t\tshortcut.character\n\t\t )\n\t\t: shortcut.character;\n}\n\n/**\n * Returns the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const {character, modifier} = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * <div>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </div>\n * );\n * };\n *```\n *\n * @return {ShortcutKeyCombination?} Key combination.\n */\nexport function getShortcutKeyCombination(\n\tstate: ShortcutsState,\n\tname: string\n): ShortcutKeyCombination | null {\n\treturn state[ name ] ? state[ name ].keyCombination : null;\n}\n\n/**\n * Returns a string representing the main key combination for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @param {keyof FORMATTING_METHODS} representation Type of representation\n * (display, raw, ariaLabel).\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const {display, raw, ariaLabel} = useSelect(\n * ( select ) =>{\n * return {\n * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),\n * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),\n * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')\n * }\n * },\n * []\n * );\n *\n * return (\n * <ul>\n * <li>{ sprintf( 'display string: %s', display ) }</li>\n * <li>{ sprintf( 'raw string: %s', raw ) }</li>\n * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>\n * </ul>\n * );\n * };\n *```\n *\n * @return {?string} Shortcut representation.\n */\nexport function getShortcutRepresentation(\n\tstate: ShortcutsState,\n\tname: string,\n\trepresentation: keyof typeof FORMATTING_METHODS = 'display'\n): string | null {\n\tconst shortcut = getShortcutKeyCombination( state, name );\n\treturn getKeyCombinationRepresentation( shortcut, representation );\n}\n\n/**\n * Returns the shortcut description given its name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutDescription = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),\n * []\n * );\n *\n * return shortcutDescription ? (\n * <div>{ shortcutDescription }</div>\n * ) : (\n * <div>{ __( 'No description.' ) }</div>\n * );\n * };\n *```\n * @return {?string} Shortcut description.\n */\nexport function getShortcutDescription(\n\tstate: ShortcutsState,\n\tname: string\n): string | null {\n\treturn state[ name ] ? state[ name ].description : null;\n}\n\n/**\n * Returns the aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n * const ExampleComponent = () => {\n * const shortcutAliases = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutAliases(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * shortcutAliases.length > 0 && (\n * <ul>\n * { shortcutAliases.map( ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {ShortcutKeyCombination[]} Key combinations.\n */\nexport function getShortcutAliases(\n\tstate: ShortcutsState,\n\tname: string\n): ShortcutKeyCombination[] {\n\treturn state[ name ] && state[ name ].aliases\n\t\t? state[ name ].aliases\n\t\t: EMPTY_ARRAY;\n}\n\n/**\n * Returns the shortcuts that include aliases for a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutKeyCombinations.map(\n * ( { character, modifier }, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * 'Character: <code>%s</code> / Modifier: <code>%s</code>',\n * character,\n * modifier\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {ShortcutKeyCombination[]} Key combinations.\n */\nexport const getAllShortcutKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn [\n\t\t\tgetShortcutKeyCombination( state, name ),\n\t\t\t...getShortcutAliases( state, name ),\n\t\t].filter(\n\t\t\t( combination ): combination is ShortcutKeyCombination =>\n\t\t\t\t!! combination\n\t\t);\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the raw representation of all the keyboard combinations of a given shortcut name.\n *\n * @param {Object} state Global state.\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n * import { createInterpolateElement } from '@wordpress/element';\n * import { sprintf } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const allShortcutRawKeyCombinations = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(\n * 'core/editor/next-region'\n * ),\n * []\n * );\n *\n * return (\n * allShortcutRawKeyCombinations.length > 0 && (\n * <ul>\n * { allShortcutRawKeyCombinations.map(\n * ( shortcutRawKeyCombination, index ) => (\n * <li key={ index }>\n * { createInterpolateElement(\n * sprintf(\n * ' <code>%s</code>',\n * shortcutRawKeyCombination\n * ),\n * {\n * code: <code />,\n * }\n * ) }\n * </li>\n * )\n * ) }\n * </ul>\n * )\n * );\n * };\n *```\n *\n * @return {string[]} Shortcuts.\n */\nexport const getAllShortcutRawKeyCombinations = createSelector(\n\t( state, name ) => {\n\t\treturn getAllShortcutKeyCombinations( state, name ).map(\n\t\t\t( combination ) =>\n\t\t\t\tgetKeyCombinationRepresentation( combination, 'raw' )\n\t\t);\n\t},\n\t( state, name ) => [ state[ name ] ]\n);\n\n/**\n * Returns the shortcut names list for a given category name.\n *\n * @param {Object} state Global state.\n * @param {string} name Category name.\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * const categoryShortcuts = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getCategoryShortcuts(\n * 'block'\n * ),\n * []\n * );\n *\n * return (\n * categoryShortcuts.length > 0 && (\n * <ul>\n * { categoryShortcuts.map( ( categoryShortcut ) => (\n * <li key={ categoryShortcut }>{ categoryShortcut }</li>\n * ) ) }\n * </ul>\n * )\n * );\n * };\n *```\n * @return {string[]} Shortcut names.\n */\nexport const getCategoryShortcuts = createSelector(\n\t( state: ShortcutsState, categoryName: string ): string[] => {\n\t\treturn Object.entries< ShortcutState >( state )\n\t\t\t.filter( ( [ , shortcut ] ) => shortcut.category === categoryName )\n\t\t\t.map( ( [ name ] ) => name );\n\t},\n\t( state: ShortcutsState ) => [ state ]\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA+B;AAC/B,sBAIO;AAoBP,IAAM,cAAwC,CAAC;AAK/C,IAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA;AAAA;AAAA;AAAA,EAIT,KAAK;AAAA;AAAA;AAAA;AAAA,EAIL,WAAW;AACZ;AAWA,SAAS,gCACR,UACA,gBACgB;AAChB,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,SAAO,SAAS,WACb,mBAAoB,cAAe,EAAG,SAAS,QAAS;AAAA,IACxD,SAAS;AAAA,EACT,IACA,SAAS;AACb;AA2CO,SAAS,0BACf,OACA,MACgC;AAChC,SAAO,MAAO,IAAK,IAAI,MAAO,IAAK,EAAE,iBAAiB;AACvD;AAwCO,SAAS,0BACf,OACA,MACA,iBAAkD,WAClC;AAChB,QAAM,WAAW,0BAA2B,OAAO,IAAK;AACxD,SAAO,gCAAiC,UAAU,cAAe;AAClE;AA8BO,SAAS,uBACf,OACA,MACgB;AAChB,SAAO,MAAO,IAAK,IAAI,MAAO,IAAK,EAAE,cAAc;AACpD;AAgDO,SAAS,mBACf,OACA,MAC2B;AAC3B,SAAO,MAAO,IAAK,KAAK,MAAO,IAAK,EAAE,UACnC,MAAO,IAAK,EAAE,UACd;AACJ;AAmDO,IAAM,oCAAgC;AAAA,EAC5C,CAAE,OAAO,SAAU;AAClB,WAAO;AAAA,MACN,0BAA2B,OAAO,IAAK;AAAA,MACvC,GAAG,mBAAoB,OAAO,IAAK;AAAA,IACpC,EAAE;AAAA,MACD,CAAE,gBACD,CAAC,CAAE;AAAA,IACL;AAAA,EACD;AAAA,EACA,CAAE,OAAO,SAAU,CAAE,MAAO,IAAK,CAAE;AACpC;AAmDO,IAAM,uCAAmC;AAAA,EAC/C,CAAE,OAAO,SAAU;AAClB,WAAO,8BAA+B,OAAO,IAAK,EAAE;AAAA,MACnD,CAAE,gBACD,gCAAiC,aAAa,KAAM;AAAA,IACtD;AAAA,EACD;AAAA,EACA,CAAE,OAAO,SAAU,CAAE,MAAO,IAAK,CAAE;AACpC;AAmCO,IAAM,2BAAuB;AAAA,EACnC,CAAE,OAAuB,iBAAoC;AAC5D,WAAO,OAAO,QAA0B,KAAM,EAC5C,OAAQ,CAAE,CAAE,EAAE,QAAS,MAAO,SAAS,aAAa,YAAa,EACjE,IAAK,CAAE,CAAE,IAAK,MAAO,IAAK;AAAA,EAC7B;AAAA,EACA,CAAE,UAA2B,CAAE,KAAM;AACtC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/keyboard-shortcuts/src/store/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/types.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ShortcutKeyCombination } from './actions';\n\nexport interface ShortcutState {\n\tcategory: string;\n\tkeyCombination: ShortcutKeyCombination;\n\taliases?: ShortcutKeyCombination[];\n\tdescription: string;\n}\n\nexport type ShortcutsState = Record< string, ShortcutState >;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
// packages/keyboard-shortcuts/src/components/shortcut-provider.
|
|
1
|
+
// packages/keyboard-shortcuts/src/components/shortcut-provider.tsx
|
|
2
2
|
import { useState } from "@wordpress/element";
|
|
3
3
|
import { context } from "../context.mjs";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
var { Provider } = context;
|
|
6
6
|
function ShortcutProvider(props) {
|
|
7
|
-
const [keyboardShortcuts] = useState(
|
|
7
|
+
const [keyboardShortcuts] = useState(
|
|
8
|
+
() => /* @__PURE__ */ new Set()
|
|
9
|
+
);
|
|
8
10
|
function onKeyDown(event) {
|
|
9
11
|
if (props.onKeyDown) {
|
|
10
12
|
props.onKeyDown(event);
|
|
11
13
|
}
|
|
14
|
+
const nativeEvent = event.nativeEvent;
|
|
12
15
|
for (const keyboardShortcut of keyboardShortcuts) {
|
|
13
|
-
keyboardShortcut(
|
|
16
|
+
keyboardShortcut(nativeEvent);
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
return /* @__PURE__ */ jsx(Provider, { value: keyboardShortcuts, children: /* @__PURE__ */ jsx("div", { ...props, onKeyDown }) });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/components/shortcut-provider.
|
|
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
|
|
5
|
-
"mappings": ";AAGA,SAAS,gBAAgB;AAKzB,SAAS,eAAe;
|
|
3
|
+
"sources": ["../../src/components/shortcut-provider.tsx"],
|
|
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\ntype ShortcutCallback = ( event: KeyboardEvent ) => void;\n\ninterface ShortcutProviderProps extends React.HTMLAttributes< HTMLDivElement > {\n\tonKeyDown?: ( event: React.KeyboardEvent< HTMLDivElement > ) => void;\n}\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 props Props to pass to `div`.\n *\n * @return Component.\n */\nexport function ShortcutProvider( props: ShortcutProviderProps ) {\n\tconst [ keyboardShortcuts ] = useState(\n\t\t() => new Set< ShortcutCallback >()\n\t);\n\n\tfunction onKeyDown( event: React.KeyboardEvent< HTMLDivElement > ) {\n\t\tif ( props.onKeyDown ) {\n\t\t\tprops.onKeyDown( event );\n\t\t}\n\n\t\t// Convert React event to native KeyboardEvent for compatibility\n\t\tconst nativeEvent = event.nativeEvent;\n\t\tfor ( const keyboardShortcut of keyboardShortcuts ) {\n\t\t\tkeyboardShortcut( nativeEvent );\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": ";AAGA,SAAS,gBAAgB;AAKzB,SAAS,eAAe;AAuCrB;AArCH,IAAM,EAAE,SAAS,IAAI;AAiBd,SAAS,iBAAkB,OAA+B;AAChE,QAAM,CAAE,iBAAkB,IAAI;AAAA,IAC7B,MAAM,oBAAI,IAAwB;AAAA,EACnC;AAEA,WAAS,UAAW,OAA+C;AAClE,QAAK,MAAM,WAAY;AACtB,YAAM,UAAW,KAAM;AAAA,IACxB;AAGA,UAAM,cAAc,MAAM;AAC1B,eAAY,oBAAoB,mBAAoB;AACnD,uBAAkB,WAAY;AAAA,IAC/B;AAAA,EACD;AAGA,SACC,oBAAC,YAAS,OAAQ,mBACjB,8BAAC,SAAM,GAAG,OAAQ,WAAwB,GAC3C;AAGF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/context.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/context.
|
|
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": ";AAGA,SAAS,qBAAqB;
|
|
3
|
+
"sources": ["../src/context.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\ntype ShortcutCallback = ( event: KeyboardEvent ) => void;\n\ninterface ShortcutContextType {\n\tadd: ( shortcut: ShortcutCallback ) => void;\n\tdelete: ( shortcut: ShortcutCallback ) => void;\n}\n\nconst globalShortcuts = new Set< ShortcutCallback >();\nconst globalListener = ( event: KeyboardEvent ) => {\n\tfor ( const keyboardShortcut of globalShortcuts ) {\n\t\tkeyboardShortcut( event );\n\t}\n};\n\nexport const context = createContext< ShortcutContextType >( {\n\tadd: ( shortcut: ShortcutCallback ) => {\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: ShortcutCallback ) => {\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": ";AAGA,SAAS,qBAAqB;AAS9B,IAAM,kBAAkB,oBAAI,IAAwB;AACpD,IAAM,iBAAiB,CAAE,UAA0B;AAClD,aAAY,oBAAoB,iBAAkB;AACjD,qBAAkB,KAAM;AAAA,EACzB;AACD;AAEO,IAAM,UAAU,cAAsC;AAAA,EAC5D,KAAK,CAAE,aAAgC;AACtC,QAAK,gBAAgB,SAAS,GAAI;AACjC,eAAS,iBAAkB,WAAW,cAAe;AAAA,IACtD;AACA,oBAAgB,IAAK,QAAS;AAAA,EAC/B;AAAA,EACA,QAAQ,CAAE,aAAgC;AACzC,oBAAgB,OAAQ,QAAS;AACjC,QAAK,gBAAgB,SAAS,GAAI;AACjC,eAAS,oBAAqB,WAAW,cAAe;AAAA,IACzD;AAAA,EACD;AACD,CAAE;AAEF,QAAQ,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|