@wordpress/keyboard-shortcuts 5.40.1-next.v.202602241322.0 → 5.40.1
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-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/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 +5 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface ShortcutProviderProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
2
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Handles callbacks added to context by `useShortcut`.
|
|
6
|
+
* Adding a provider allows to register contextual shortcuts
|
|
7
|
+
* that are only active when a certain part of the UI is focused.
|
|
8
|
+
*
|
|
9
|
+
* @param props Props to pass to `div`.
|
|
10
|
+
*
|
|
11
|
+
* @return Component.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ShortcutProvider(props: ShortcutProviderProps): import("react").JSX.Element;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=shortcut-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcut-provider.d.ts","sourceRoot":"","sources":["../../src/components/shortcut-provider.tsx"],"names":[],"mappings":"AAcA,UAAU,qBAAsB,SAAQ,KAAK,CAAC,cAAc,CAAE,cAAc,CAAE;IAC7E,SAAS,CAAC,EAAE,CAAE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAE,cAAc,CAAE,KAAM,IAAI,CAAC;CACrE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAE,KAAK,EAAE,qBAAqB,+BAwB7D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type ShortcutCallback = (event: KeyboardEvent) => void;
|
|
2
|
+
interface ShortcutContextType {
|
|
3
|
+
add: (shortcut: ShortcutCallback) => void;
|
|
4
|
+
delete: (shortcut: ShortcutCallback) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const context: import("react").Context<ShortcutContextType>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAKA,KAAK,gBAAgB,GAAG,CAAE,KAAK,EAAE,aAAa,KAAM,IAAI,CAAC;AAEzD,UAAU,mBAAmB;IAC5B,GAAG,EAAE,CAAE,QAAQ,EAAE,gBAAgB,KAAM,IAAI,CAAC;IAC5C,MAAM,EAAE,CAAE,QAAQ,EAAE,gBAAgB,KAAM,IAAI,CAAC;CAC/C;AASD,eAAO,MAAM,OAAO,8CAajB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a function to check if a keyboard event matches a shortcut name.
|
|
3
|
+
*
|
|
4
|
+
* @return A function to check if a keyboard event matches a
|
|
5
|
+
* predefined shortcut combination.
|
|
6
|
+
*/
|
|
7
|
+
export default function useShortcutEventMatch(): (name: string, event: KeyboardEvent) => boolean;
|
|
8
|
+
//# sourceMappingURL=use-shortcut-event-match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-shortcut-event-match.d.ts","sourceRoot":"","sources":["../../src/hooks/use-shortcut-event-match.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,IAAI,CAChD,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,aAAa,KAChB,OAAO,CA6BX"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface UseShortcutOptions {
|
|
2
|
+
isDisabled?: boolean;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Attach a keyboard shortcut handler.
|
|
6
|
+
*
|
|
7
|
+
* @param name Shortcut name.
|
|
8
|
+
* @param callback Shortcut callback.
|
|
9
|
+
* @param options Shortcut options.
|
|
10
|
+
* @param options.isDisabled Whether to disable the shortcut.
|
|
11
|
+
*/
|
|
12
|
+
export default function useShortcut(name: string, callback: (event: KeyboardEvent) => void, { isDisabled }?: UseShortcutOptions): void;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=use-shortcut.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-shortcut.d.ts","sourceRoot":"","sources":["../../src/hooks/use-shortcut.ts"],"names":[],"mappings":"AAWA,UAAU,kBAAkB;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAE,KAAK,EAAE,aAAa,KAAM,IAAI,EAC1C,EAAE,UAAkB,EAAE,GAAE,kBAAuB,QA0B/C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { store } from './store';
|
|
2
|
+
export { default as useShortcut } from './hooks/use-shortcut';
|
|
3
|
+
export { ShortcutProvider } from './components/shortcut-provider';
|
|
4
|
+
export { default as __unstableUseShortcutEventMatch } from './hooks/use-shortcut-event-match';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,+BAA+B,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { WPKeycodeModifier } from '@wordpress/keycodes';
|
|
2
|
+
/**
|
|
3
|
+
* Keyboard key combination.
|
|
4
|
+
*/
|
|
5
|
+
export interface ShortcutKeyCombination {
|
|
6
|
+
character: string;
|
|
7
|
+
modifier: WPKeycodeModifier | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Configuration of a registered keyboard shortcut.
|
|
11
|
+
*/
|
|
12
|
+
export interface ShortcutConfig {
|
|
13
|
+
name: string;
|
|
14
|
+
category: string;
|
|
15
|
+
description: string;
|
|
16
|
+
keyCombination: ShortcutKeyCombination;
|
|
17
|
+
aliases?: ShortcutKeyCombination[];
|
|
18
|
+
}
|
|
19
|
+
export type ShortcutAction = ReturnType<typeof registerShortcut> | ReturnType<typeof unregisterShortcut>;
|
|
20
|
+
/**
|
|
21
|
+
* Returns an action object used to register a new keyboard shortcut.
|
|
22
|
+
*
|
|
23
|
+
* @param {ShortcutConfig} config Shortcut config.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
*
|
|
27
|
+
*```js
|
|
28
|
+
* import { useEffect } from 'react';
|
|
29
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
30
|
+
* import { useSelect, useDispatch } from '@wordpress/data';
|
|
31
|
+
* import { __ } from '@wordpress/i18n';
|
|
32
|
+
*
|
|
33
|
+
* const ExampleComponent = () => {
|
|
34
|
+
* const { registerShortcut } = useDispatch( keyboardShortcutsStore );
|
|
35
|
+
*
|
|
36
|
+
* useEffect( () => {
|
|
37
|
+
* registerShortcut( {
|
|
38
|
+
* name: 'custom/my-custom-shortcut',
|
|
39
|
+
* category: 'my-category',
|
|
40
|
+
* description: __( 'My custom shortcut' ),
|
|
41
|
+
* keyCombination: {
|
|
42
|
+
* modifier: 'primary',
|
|
43
|
+
* character: 'j',
|
|
44
|
+
* },
|
|
45
|
+
* } );
|
|
46
|
+
* }, [] );
|
|
47
|
+
*
|
|
48
|
+
* const shortcut = useSelect(
|
|
49
|
+
* ( select ) =>
|
|
50
|
+
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
51
|
+
* 'custom/my-custom-shortcut'
|
|
52
|
+
* ),
|
|
53
|
+
* []
|
|
54
|
+
* );
|
|
55
|
+
*
|
|
56
|
+
* return shortcut ? (
|
|
57
|
+
* <p>{ __( 'Shortcut is registered.' ) }</p>
|
|
58
|
+
* ) : (
|
|
59
|
+
* <p>{ __( 'Shortcut is not registered.' ) }</p>
|
|
60
|
+
* );
|
|
61
|
+
* };
|
|
62
|
+
*```
|
|
63
|
+
* @return {Object} action.
|
|
64
|
+
*/
|
|
65
|
+
export declare function registerShortcut({ name, category, description, keyCombination, aliases }: ShortcutConfig): {
|
|
66
|
+
type: 'REGISTER_SHORTCUT';
|
|
67
|
+
name: string;
|
|
68
|
+
category: string;
|
|
69
|
+
keyCombination: ShortcutKeyCombination;
|
|
70
|
+
aliases: ShortcutKeyCombination[] | undefined;
|
|
71
|
+
description: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Returns an action object used to unregister a keyboard shortcut.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} name Shortcut name.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
*
|
|
80
|
+
*```js
|
|
81
|
+
* import { useEffect } from 'react';
|
|
82
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
83
|
+
* import { useSelect, useDispatch } from '@wordpress/data';
|
|
84
|
+
* import { __ } from '@wordpress/i18n';
|
|
85
|
+
*
|
|
86
|
+
* const ExampleComponent = () => {
|
|
87
|
+
* const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
|
|
88
|
+
*
|
|
89
|
+
* useEffect( () => {
|
|
90
|
+
* unregisterShortcut( 'core/editor/next-region' );
|
|
91
|
+
* }, [] );
|
|
92
|
+
*
|
|
93
|
+
* const shortcut = useSelect(
|
|
94
|
+
* ( select ) =>
|
|
95
|
+
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
96
|
+
* 'core/editor/next-region'
|
|
97
|
+
* ),
|
|
98
|
+
* []
|
|
99
|
+
* );
|
|
100
|
+
*
|
|
101
|
+
* return shortcut ? (
|
|
102
|
+
* <p>{ __( 'Shortcut is not unregistered.' ) }</p>
|
|
103
|
+
* ) : (
|
|
104
|
+
* <p>{ __( 'Shortcut is unregistered.' ) }</p>
|
|
105
|
+
* );
|
|
106
|
+
* };
|
|
107
|
+
*```
|
|
108
|
+
* @return {Object} action.
|
|
109
|
+
*/
|
|
110
|
+
export declare function unregisterShortcut(name: string): {
|
|
111
|
+
type: 'UNREGISTER_SHORTCUT';
|
|
112
|
+
name: string;
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,iBAAiB,GAAG,SAAS,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,sBAAsB,CAAC;IACvC,OAAO,CAAC,EAAE,sBAAsB,EAAE,CAAC;CACnC;AAED,MAAM,MAAM,cAAc,GACvB,UAAU,CAAE,OAAO,gBAAgB,CAAE,GACrC,UAAU,CAAE,OAAO,kBAAkB,CAAE,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,gBAAgB,CAAE,EACjC,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,cAAc,EACd,OAAO,EACP,EAAE,cAAc;UAET,mBAAmB;;;;;;EAO1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,kBAAkB,CAAE,IAAI,EAAE,MAAM;UAExC,qBAAqB;;EAG5B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as actions from './actions';
|
|
2
|
+
import * as selectors from './selectors';
|
|
3
|
+
/**
|
|
4
|
+
* Store definition for the keyboard shortcuts namespace.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
7
|
+
*/
|
|
8
|
+
export declare const store: import("@wordpress/data").StoreDescriptor<import("@wordpress/data").ReduxStoreConfig<unknown, typeof actions, typeof selectors>>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAIzC;;;;GAIG;AACH,eAAO,MAAM,KAAK,kIAIf,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ShortcutAction } from './actions';
|
|
5
|
+
import type { ShortcutsState } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Reducer returning the registered shortcuts
|
|
8
|
+
*
|
|
9
|
+
* @param state Current state.
|
|
10
|
+
* @param action Dispatched action.
|
|
11
|
+
*
|
|
12
|
+
* @return Updated state.
|
|
13
|
+
*/
|
|
14
|
+
declare function reducer(state: ShortcutsState | undefined, action: ShortcutAction): ShortcutsState;
|
|
15
|
+
export default reducer;
|
|
16
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/store/reducer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;GAOG;AACH,iBAAS,OAAO,CACf,KAAK,EAAE,cAAc,YAAK,EAC1B,MAAM,EAAE,cAAc,GACpB,cAAc,CAkBhB;eAEc,OAAO"}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ShortcutKeyCombination } from './actions';
|
|
5
|
+
interface ShortcutState {
|
|
6
|
+
category: string;
|
|
7
|
+
keyCombination: ShortcutKeyCombination;
|
|
8
|
+
aliases?: ShortcutKeyCombination[];
|
|
9
|
+
description: string;
|
|
10
|
+
}
|
|
11
|
+
type ShortcutsState = Record<string, ShortcutState>;
|
|
12
|
+
/**
|
|
13
|
+
* Shortcut formatting methods.
|
|
14
|
+
*/
|
|
15
|
+
declare const FORMATTING_METHODS: {
|
|
16
|
+
/**
|
|
17
|
+
* Display formatting.
|
|
18
|
+
*/
|
|
19
|
+
display: import("@wordpress/keycodes").WPModifierHandler<import("@wordpress/keycodes").WPKeyHandler<string>>;
|
|
20
|
+
/**
|
|
21
|
+
* Raw shortcut formatting.
|
|
22
|
+
*/
|
|
23
|
+
raw: import("@wordpress/keycodes").WPModifierHandler<import("@wordpress/keycodes").WPKeyHandler<string>>;
|
|
24
|
+
/**
|
|
25
|
+
* ARIA label formatting.
|
|
26
|
+
*/
|
|
27
|
+
ariaLabel: import("@wordpress/keycodes").WPModifierHandler<import("@wordpress/keycodes").WPKeyHandler<string>>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Returns the main key combination for a given shortcut name.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} state Global state.
|
|
33
|
+
* @param {string} name Shortcut name.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
*
|
|
37
|
+
*```js
|
|
38
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
39
|
+
* import { useSelect } from '@wordpress/data';
|
|
40
|
+
* import { createInterpolateElement } from '@wordpress/element';
|
|
41
|
+
* import { sprintf } from '@wordpress/i18n';
|
|
42
|
+
* const ExampleComponent = () => {
|
|
43
|
+
* const {character, modifier} = useSelect(
|
|
44
|
+
* ( select ) =>
|
|
45
|
+
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
|
46
|
+
* 'core/editor/next-region'
|
|
47
|
+
* ),
|
|
48
|
+
* []
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* return (
|
|
52
|
+
* <div>
|
|
53
|
+
* { createInterpolateElement(
|
|
54
|
+
* sprintf(
|
|
55
|
+
* 'Character: <code>%s</code> / Modifier: <code>%s</code>',
|
|
56
|
+
* character,
|
|
57
|
+
* modifier
|
|
58
|
+
* ),
|
|
59
|
+
* {
|
|
60
|
+
* code: <code />,
|
|
61
|
+
* }
|
|
62
|
+
* ) }
|
|
63
|
+
* </div>
|
|
64
|
+
* );
|
|
65
|
+
* };
|
|
66
|
+
*```
|
|
67
|
+
*
|
|
68
|
+
* @return {ShortcutKeyCombination?} Key combination.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getShortcutKeyCombination(state: ShortcutsState, name: string): ShortcutKeyCombination | null;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a string representing the main key combination for a given shortcut name.
|
|
73
|
+
*
|
|
74
|
+
* @param {Object} state Global state.
|
|
75
|
+
* @param {string} name Shortcut name.
|
|
76
|
+
* @param {keyof FORMATTING_METHODS} representation Type of representation
|
|
77
|
+
* (display, raw, ariaLabel).
|
|
78
|
+
* @example
|
|
79
|
+
*
|
|
80
|
+
*```js
|
|
81
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
82
|
+
* import { useSelect } from '@wordpress/data';
|
|
83
|
+
* import { sprintf } from '@wordpress/i18n';
|
|
84
|
+
*
|
|
85
|
+
* const ExampleComponent = () => {
|
|
86
|
+
* const {display, raw, ariaLabel} = useSelect(
|
|
87
|
+
* ( select ) =>{
|
|
88
|
+
* return {
|
|
89
|
+
* display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),
|
|
90
|
+
* raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),
|
|
91
|
+
* ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')
|
|
92
|
+
* }
|
|
93
|
+
* },
|
|
94
|
+
* []
|
|
95
|
+
* );
|
|
96
|
+
*
|
|
97
|
+
* return (
|
|
98
|
+
* <ul>
|
|
99
|
+
* <li>{ sprintf( 'display string: %s', display ) }</li>
|
|
100
|
+
* <li>{ sprintf( 'raw string: %s', raw ) }</li>
|
|
101
|
+
* <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>
|
|
102
|
+
* </ul>
|
|
103
|
+
* );
|
|
104
|
+
* };
|
|
105
|
+
*```
|
|
106
|
+
*
|
|
107
|
+
* @return {?string} Shortcut representation.
|
|
108
|
+
*/
|
|
109
|
+
export declare function getShortcutRepresentation(state: ShortcutsState, name: string, representation?: keyof typeof FORMATTING_METHODS): string | null;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the shortcut description given its name.
|
|
112
|
+
*
|
|
113
|
+
* @param {Object} state Global state.
|
|
114
|
+
* @param {string} name Shortcut name.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
*
|
|
118
|
+
*```js
|
|
119
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
120
|
+
* import { useSelect } from '@wordpress/data';
|
|
121
|
+
* import { __ } from '@wordpress/i18n';
|
|
122
|
+
* const ExampleComponent = () => {
|
|
123
|
+
* const shortcutDescription = useSelect(
|
|
124
|
+
* ( select ) =>
|
|
125
|
+
* select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),
|
|
126
|
+
* []
|
|
127
|
+
* );
|
|
128
|
+
*
|
|
129
|
+
* return shortcutDescription ? (
|
|
130
|
+
* <div>{ shortcutDescription }</div>
|
|
131
|
+
* ) : (
|
|
132
|
+
* <div>{ __( 'No description.' ) }</div>
|
|
133
|
+
* );
|
|
134
|
+
* };
|
|
135
|
+
*```
|
|
136
|
+
* @return {?string} Shortcut description.
|
|
137
|
+
*/
|
|
138
|
+
export declare function getShortcutDescription(state: ShortcutsState, name: string): string | null;
|
|
139
|
+
/**
|
|
140
|
+
* Returns the aliases for a given shortcut name.
|
|
141
|
+
*
|
|
142
|
+
* @param {Object} state Global state.
|
|
143
|
+
* @param {string} name Shortcut name.
|
|
144
|
+
* @example
|
|
145
|
+
*
|
|
146
|
+
*```js
|
|
147
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
148
|
+
* import { useSelect } from '@wordpress/data';
|
|
149
|
+
* import { createInterpolateElement } from '@wordpress/element';
|
|
150
|
+
* import { sprintf } from '@wordpress/i18n';
|
|
151
|
+
* const ExampleComponent = () => {
|
|
152
|
+
* const shortcutAliases = useSelect(
|
|
153
|
+
* ( select ) =>
|
|
154
|
+
* select( keyboardShortcutsStore ).getShortcutAliases(
|
|
155
|
+
* 'core/editor/next-region'
|
|
156
|
+
* ),
|
|
157
|
+
* []
|
|
158
|
+
* );
|
|
159
|
+
*
|
|
160
|
+
* return (
|
|
161
|
+
* shortcutAliases.length > 0 && (
|
|
162
|
+
* <ul>
|
|
163
|
+
* { shortcutAliases.map( ( { character, modifier }, index ) => (
|
|
164
|
+
* <li key={ index }>
|
|
165
|
+
* { createInterpolateElement(
|
|
166
|
+
* sprintf(
|
|
167
|
+
* 'Character: <code>%s</code> / Modifier: <code>%s</code>',
|
|
168
|
+
* character,
|
|
169
|
+
* modifier
|
|
170
|
+
* ),
|
|
171
|
+
* {
|
|
172
|
+
* code: <code />,
|
|
173
|
+
* }
|
|
174
|
+
* ) }
|
|
175
|
+
* </li>
|
|
176
|
+
* ) ) }
|
|
177
|
+
* </ul>
|
|
178
|
+
* )
|
|
179
|
+
* );
|
|
180
|
+
* };
|
|
181
|
+
*```
|
|
182
|
+
*
|
|
183
|
+
* @return {ShortcutKeyCombination[]} Key combinations.
|
|
184
|
+
*/
|
|
185
|
+
export declare function getShortcutAliases(state: ShortcutsState, name: string): ShortcutKeyCombination[];
|
|
186
|
+
/**
|
|
187
|
+
* Returns the shortcuts that include aliases for a given shortcut name.
|
|
188
|
+
*
|
|
189
|
+
* @param {Object} state Global state.
|
|
190
|
+
* @param {string} name Shortcut name.
|
|
191
|
+
* @example
|
|
192
|
+
*
|
|
193
|
+
*```js
|
|
194
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
195
|
+
* import { useSelect } from '@wordpress/data';
|
|
196
|
+
* import { createInterpolateElement } from '@wordpress/element';
|
|
197
|
+
* import { sprintf } from '@wordpress/i18n';
|
|
198
|
+
*
|
|
199
|
+
* const ExampleComponent = () => {
|
|
200
|
+
* const allShortcutKeyCombinations = useSelect(
|
|
201
|
+
* ( select ) =>
|
|
202
|
+
* select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
|
|
203
|
+
* 'core/editor/next-region'
|
|
204
|
+
* ),
|
|
205
|
+
* []
|
|
206
|
+
* );
|
|
207
|
+
*
|
|
208
|
+
* return (
|
|
209
|
+
* allShortcutKeyCombinations.length > 0 && (
|
|
210
|
+
* <ul>
|
|
211
|
+
* { allShortcutKeyCombinations.map(
|
|
212
|
+
* ( { character, modifier }, index ) => (
|
|
213
|
+
* <li key={ index }>
|
|
214
|
+
* { createInterpolateElement(
|
|
215
|
+
* sprintf(
|
|
216
|
+
* 'Character: <code>%s</code> / Modifier: <code>%s</code>',
|
|
217
|
+
* character,
|
|
218
|
+
* modifier
|
|
219
|
+
* ),
|
|
220
|
+
* {
|
|
221
|
+
* code: <code />,
|
|
222
|
+
* }
|
|
223
|
+
* ) }
|
|
224
|
+
* </li>
|
|
225
|
+
* )
|
|
226
|
+
* ) }
|
|
227
|
+
* </ul>
|
|
228
|
+
* )
|
|
229
|
+
* );
|
|
230
|
+
* };
|
|
231
|
+
*```
|
|
232
|
+
*
|
|
233
|
+
* @return {ShortcutKeyCombination[]} Key combinations.
|
|
234
|
+
*/
|
|
235
|
+
export declare const getAllShortcutKeyCombinations: ((state: any, name: any) => ShortcutKeyCombination[]) & import("rememo").EnhancedSelector;
|
|
236
|
+
/**
|
|
237
|
+
* Returns the raw representation of all the keyboard combinations of a given shortcut name.
|
|
238
|
+
*
|
|
239
|
+
* @param {Object} state Global state.
|
|
240
|
+
* @param {string} name Shortcut name.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
*
|
|
244
|
+
*```js
|
|
245
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
246
|
+
* import { useSelect } from '@wordpress/data';
|
|
247
|
+
* import { createInterpolateElement } from '@wordpress/element';
|
|
248
|
+
* import { sprintf } from '@wordpress/i18n';
|
|
249
|
+
*
|
|
250
|
+
* const ExampleComponent = () => {
|
|
251
|
+
* const allShortcutRawKeyCombinations = useSelect(
|
|
252
|
+
* ( select ) =>
|
|
253
|
+
* select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
|
|
254
|
+
* 'core/editor/next-region'
|
|
255
|
+
* ),
|
|
256
|
+
* []
|
|
257
|
+
* );
|
|
258
|
+
*
|
|
259
|
+
* return (
|
|
260
|
+
* allShortcutRawKeyCombinations.length > 0 && (
|
|
261
|
+
* <ul>
|
|
262
|
+
* { allShortcutRawKeyCombinations.map(
|
|
263
|
+
* ( shortcutRawKeyCombination, index ) => (
|
|
264
|
+
* <li key={ index }>
|
|
265
|
+
* { createInterpolateElement(
|
|
266
|
+
* sprintf(
|
|
267
|
+
* ' <code>%s</code>',
|
|
268
|
+
* shortcutRawKeyCombination
|
|
269
|
+
* ),
|
|
270
|
+
* {
|
|
271
|
+
* code: <code />,
|
|
272
|
+
* }
|
|
273
|
+
* ) }
|
|
274
|
+
* </li>
|
|
275
|
+
* )
|
|
276
|
+
* ) }
|
|
277
|
+
* </ul>
|
|
278
|
+
* )
|
|
279
|
+
* );
|
|
280
|
+
* };
|
|
281
|
+
*```
|
|
282
|
+
*
|
|
283
|
+
* @return {string[]} Shortcuts.
|
|
284
|
+
*/
|
|
285
|
+
export declare const getAllShortcutRawKeyCombinations: ((state: any, name: any) => (string | null)[]) & import("rememo").EnhancedSelector;
|
|
286
|
+
/**
|
|
287
|
+
* Returns the shortcut names list for a given category name.
|
|
288
|
+
*
|
|
289
|
+
* @param {Object} state Global state.
|
|
290
|
+
* @param {string} name Category name.
|
|
291
|
+
* @example
|
|
292
|
+
*
|
|
293
|
+
*```js
|
|
294
|
+
* import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
295
|
+
* import { useSelect } from '@wordpress/data';
|
|
296
|
+
*
|
|
297
|
+
* const ExampleComponent = () => {
|
|
298
|
+
* const categoryShortcuts = useSelect(
|
|
299
|
+
* ( select ) =>
|
|
300
|
+
* select( keyboardShortcutsStore ).getCategoryShortcuts(
|
|
301
|
+
* 'block'
|
|
302
|
+
* ),
|
|
303
|
+
* []
|
|
304
|
+
* );
|
|
305
|
+
*
|
|
306
|
+
* return (
|
|
307
|
+
* categoryShortcuts.length > 0 && (
|
|
308
|
+
* <ul>
|
|
309
|
+
* { categoryShortcuts.map( ( categoryShortcut ) => (
|
|
310
|
+
* <li key={ categoryShortcut }>{ categoryShortcut }</li>
|
|
311
|
+
* ) ) }
|
|
312
|
+
* </ul>
|
|
313
|
+
* )
|
|
314
|
+
* );
|
|
315
|
+
* };
|
|
316
|
+
*```
|
|
317
|
+
* @return {string[]} Shortcut names.
|
|
318
|
+
*/
|
|
319
|
+
export declare const getCategoryShortcuts: ((state: ShortcutsState, categoryName: string) => string[]) & import("rememo").EnhancedSelector;
|
|
320
|
+
export {};
|
|
321
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,UAAU,aAAa;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,sBAAsB,CAAC;IACvC,OAAO,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,KAAK,cAAc,GAAG,MAAM,CAAE,MAAM,EAAE,aAAa,CAAE,CAAC;AAQtD;;GAEG;AACH,QAAA,MAAM,kBAAkB;IACvB;;OAEG;IACH,OAAO;IACP;;OAEG;IACH,GAAG;IACH;;OAEG;IACH,SAAS;CACT,CAAC;AA0BF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,GACV,sBAAsB,GAAG,IAAI,CAE/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,MAAM,OAAO,kBAA8B,GACzD,MAAM,GAAG,IAAI,CAGf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,GACV,MAAM,GAAG,IAAI,CAEf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,GACV,sBAAsB,EAAE,CAI1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,6BAA6B,2FAWzC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,gCAAgC,oFAQ5C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,oBAAoB,WACvB,cAAc,gBAAgB,MAAM,KAAI,MAAM,EAAE,qCAMzD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ShortcutKeyCombination } from './actions';
|
|
2
|
+
export interface ShortcutState {
|
|
3
|
+
category: string;
|
|
4
|
+
keyCombination: ShortcutKeyCombination;
|
|
5
|
+
aliases?: ShortcutKeyCombination[];
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
export type ShortcutsState = Record<string, ShortcutState>;
|
|
9
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,WAAW,aAAa;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,sBAAsB,CAAC;IACvC,OAAO,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAE,MAAM,EAAE,aAAa,CAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/keyboard-shortcuts",
|
|
3
|
-
"version": "5.40.1
|
|
3
|
+
"version": "5.40.1",
|
|
4
4
|
"description": "Handling keyboard shortcuts.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"react-native": "src/index",
|
|
42
42
|
"wpScript": true,
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@wordpress/data": "^10.40.1
|
|
45
|
-
"@wordpress/element": "^6.40.1
|
|
46
|
-
"@wordpress/keycodes": "^4.40.1
|
|
44
|
+
"@wordpress/data": "^10.40.1",
|
|
45
|
+
"@wordpress/element": "^6.40.1",
|
|
46
|
+
"@wordpress/keycodes": "^4.40.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"react": "^18.0.0"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "adb6623c9f32490cfc73c7ac7f122578c1f10c65"
|
|
55
55
|
}
|