Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6cecbf2
refactor: migrate keyboard-shortcut package from js to ts for type s…
kushagra-goyal-14 Jul 24, 2025
ede305e
fix: handle undefined modifier in keyboard shortcut matching
kushagra-goyal-14 Jul 24, 2025
deb1918
refactor: remove explicit return types for functions in keyboard-shor…
kushagra-goyal-14 Aug 28, 2025
b46be4f
Fix a few tsconfig.json files
wwahammy Mar 8, 2026
b66a0d9
Rename from WPShortcutKeyCombination -> ShortcutKeyCombination
wwahammy Mar 8, 2026
87f4ce1
Switch from WPShortcutConfig -> ShortcutConfig
wwahammy Mar 8, 2026
a7fa635
Update docs for data-core-keyboard-shortcuts
wwahammy Mar 8, 2026
de8e726
Remove unneeded JSX import
wwahammy Mar 8, 2026
0dd43b0
Move keyboard-shortcuts store/reducer types into separate file
wwahammy Mar 8, 2026
1a779d1
Fix a prettier issue
wwahammy Mar 8, 2026
831f7ed
Remove unneeded comment
wwahammy Mar 8, 2026
d412f08
Update packages/keyboard-shortcuts/src/hooks/use-shortcut-event-match.ts
wwahammy Mar 8, 2026
b16ab0b
Update packages/keyboard-shortcuts/src/components/shortcut-provider.tsx
wwahammy Mar 8, 2026
19fe9b4
Remove unneeded export
wwahammy Mar 8, 2026
3894015
Readd some accidentally removed comments
wwahammy Mar 8, 2026
6a7c564
Genericize Object.entries call
wwahammy Mar 8, 2026
39eb9f1
Update packages/keyboard-shortcuts/src/store/selectors.ts
wwahammy Mar 8, 2026
56c5312
Add type exports into the package.json file
wwahammy Mar 8, 2026
ded422b
Remove unneeded expected error
wwahammy Mar 9, 2026
bb36b13
Reorganize package.json to remove warning about property ordering
wwahammy Mar 9, 2026
7f85bcd
Remove unneeded import
wwahammy Mar 11, 2026
1d4408d
Begin migration of @wordpress/commands to Typescript
wwahammy Mar 7, 2026
3357df6
Correct missing reference to keyboard-shortcuts
wwahammy Mar 8, 2026
3b2c3c3
WIP
wwahammy Mar 9, 2026
4dad708
More WIP
wwahammy Mar 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/reference-guides/data/data-core-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Namespace: `core/commands`.

## Selectors

<!-- START TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.js) -->
<!-- START TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.ts) -->

### getCommandLoaders

Expand Down Expand Up @@ -56,11 +56,11 @@ _Returns_

- `boolean`: Returns whether the command palette is open.

<!-- END TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.js) -->
<!-- END TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.ts) -->

## Actions

<!-- START TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.js) -->
<!-- START TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.ts) -->

### close

Expand Down Expand Up @@ -126,4 +126,4 @@ _Returns_

- `Object`: action.

<!-- END TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.js) -->
<!-- END TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.ts) -->
16 changes: 8 additions & 8 deletions docs/reference-guides/data/data-core-keyboard-shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Namespace: `core/keyboard-shortcuts`.

## Selectors

<!-- START TOKEN(Autogenerated selectors|../../../packages/keyboard-shortcuts/src/store/selectors.js) -->
<!-- START TOKEN(Autogenerated selectors|../../../packages/keyboard-shortcuts/src/store/selectors.ts) -->

### getAllShortcutKeyCombinations

Expand Down Expand Up @@ -59,7 +59,7 @@ _Parameters_

_Returns_

- `WPShortcutKeyCombination[]`: Key combinations.
- `ShortcutKeyCombination[]`: Key combinations.

### getAllShortcutRawKeyCombinations

Expand Down Expand Up @@ -203,7 +203,7 @@ _Parameters_

_Returns_

- `WPShortcutKeyCombination[]`: Key combinations.
- `ShortcutKeyCombination[]`: Key combinations.

### getShortcutDescription

Expand Down Expand Up @@ -285,7 +285,7 @@ _Parameters_

_Returns_

- `WPShortcutKeyCombination?`: Key combination.
- `ShortcutKeyCombination?`: Key combination.

### getShortcutRepresentation

Expand Down Expand Up @@ -337,11 +337,11 @@ _Returns_

- `?string`: Shortcut representation.

<!-- END TOKEN(Autogenerated selectors|../../../packages/keyboard-shortcuts/src/store/selectors.js) -->
<!-- END TOKEN(Autogenerated selectors|../../../packages/keyboard-shortcuts/src/store/selectors.ts) -->

## Actions

<!-- START TOKEN(Autogenerated actions|../../../packages/keyboard-shortcuts/src/store/actions.js) -->
<!-- START TOKEN(Autogenerated actions|../../../packages/keyboard-shortcuts/src/store/actions.ts) -->

### registerShortcut

Expand Down Expand Up @@ -388,7 +388,7 @@ const ExampleComponent = () => {

_Parameters_

- _config_ `WPShortcutConfig`: Shortcut config.
- _config_ `ShortcutConfig`: Shortcut config.

_Returns_

Expand Down Expand Up @@ -437,4 +437,4 @@ _Returns_

- `Object`: action.

<!-- END TOKEN(Autogenerated actions|../../../packages/keyboard-shortcuts/src/store/actions.js) -->
<!-- END TOKEN(Autogenerated actions|../../../packages/keyboard-shortcuts/src/store/actions.ts) -->
2 changes: 2 additions & 0 deletions packages/block-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ "path": "../api-fetch" },
{ "path": "../block-serialization-default-parser" },
{ "path": "../blob" },
{ "path": "../commands" },
{ "path": "../components" },
{ "path": "../compose" },
{ "path": "../data" },
Expand All @@ -27,6 +28,7 @@
{ "path": "../interactivity" },
{ "path": "../is-shallow-equal" },
{ "path": "../keycodes" },
{ "path": "../keyboard-shortcuts" },
{ "path": "../notices" },
{ "path": "../rich-text" },
{ "path": "../style-engine" },
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
{ "path": "../latex-to-mathml" },
{ "path": "../notices" },
{ "path": "../keycodes" },
{ "path": "../keyboard-shortcuts" },
{ "path": "../primitives" },
{ "path": "../rich-text" },
{ "path": "../upload-media" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useEffect } from '@wordpress/element';
import {
useShortcut,
store as keyboardShortcutsStore,
// @ts-expect-error - No types available yet.
} from '@wordpress/keyboard-shortcuts';
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
Expand Down
2 changes: 2 additions & 0 deletions packages/boot/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"references": [
{ "path": "../a11y" },
{ "path": "../admin-ui" },
{ "path": "../commands" },
{ "path": "../components" },
{ "path": "../compose" },
{ "path": "../core-data" },
Expand All @@ -16,6 +17,7 @@
{ "path": "../html-entities" },
{ "path": "../i18n" },
{ "path": "../icons" },
{ "path": "../keyboard-shortcuts" },
{ "path": "../keycodes" },
{ "path": "../lazy-editor" },
{ "path": "../notices" },
Expand Down
4 changes: 2 additions & 2 deletions packages/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ useCommand( {

_Parameters_

- _command_ `import('../store/actions').WPCommandConfig`: command config.
- _command_ `WPCommandConfig`:

### useCommandLoader

Expand Down Expand Up @@ -200,7 +200,7 @@ useCommandLoader( {

_Parameters_

- _loader_ `import('../store/actions').WPCommandLoaderConfig`: command loader config.
- _loader_ `WPCommandLoaderConfig`: command loader config.

### useCommands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Component,
} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import type { TranslatableText } from '@wordpress/i18n';
import {
Modal,
TextHighlight,
Expand All @@ -35,6 +36,7 @@
*/
import { store as commandsStore } from '../store';
import { unlock } from '../lock-unlock';
import type { WPCommandConfig } from '../store/actions';

const { withIgnoreIMEEvents } = unlock( componentsPrivateApis );

Expand All @@ -45,14 +47,14 @@
* Categories listed here will always use the specified icon,
* ignoring whatever icon the command itself provides.
*/
const CATEGORY_ICONS = {
const CATEGORY_ICONS: Record< string, JSX.Element > = {
view: arrowRight,
};

/**
* Translatable labels for command categories.
*/
const CATEGORY_LABELS = {
const CATEGORY_LABELS: Record< string, TranslatableText< string > > = {
command: __( 'Command' ),
view: __( 'View' ),
edit: __( 'Edit' ),
Expand All @@ -70,7 +72,7 @@
* @return {boolean} True if the parameter is a valid icon and false otherwise.
*/

export function isValidIcon( icon ) {
export function isValidIcon( icon: unknown ) {
return (
!! icon &&
( typeof icon === 'string' ||
Expand All @@ -80,15 +82,29 @@
);
}

type SetLoader = ( name: string, isLoading: boolean ) => void;

interface CommandMenuLoaderProps {
name: string;
search: string;
hook: ( search: string ) => {
isLoading: boolean;
commands?: WPCommandConfig[];
};
setLoader: SetLoader;
close: () => void;
category: string | undefined;
}

function CommandMenuLoader( {
name,
search,
hook,
setLoader,
close,
category,
} ) {
const { isLoading, commands = [] } = hook( { search } ) ?? {};
}: CommandMenuLoaderProps ) {
const { isLoading, commands = [] } = hook( search ) ?? {};
useEffect( () => {
setLoader( name, isLoading );
}, [ setLoader, name, isLoading ] );
Expand Down Expand Up @@ -145,13 +161,24 @@
);
}

interface CommandMenuLoaderWrapperProps {
hook: ( search: string ) => {
isLoading?: boolean;
commands?: WPCommandConfig[];
};
search: string;
setLoader: SetLoader;
close: () => void;
category: string | undefined;
}

export function CommandMenuLoaderWrapper( {
hook,
search,
setLoader,
close,
category,
} ) {
}: CommandMenuLoaderWrapperProps ) {
// The "hook" prop is actually a custom React hook
// so to avoid breaking the rules of hooks
// the CommandMenuLoaderWrapper component need to be
Expand All @@ -169,7 +196,7 @@
return (
<CommandMenuLoader
key={ key }
hook={ currentLoaderRef.current }

Check failure on line 199 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Check

Type '(search: string) => { isLoading?: boolean | undefined; commands?: WPCommandConfig[] | undefined; }' is not assignable to type '(search: string) => { isLoading: boolean; commands?: WPCommandConfig[] | undefined; }'.

Check failure on line 199 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / All

Type '(search: string) => { isLoading?: boolean | undefined; commands?: WPCommandConfig[] | undefined; }' is not assignable to type '(search: string) => { isLoading: boolean; commands?: WPCommandConfig[] | undefined; }'.

Check failure on line 199 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Type '(search: string) => { isLoading?: boolean | undefined; commands?: WPCommandConfig[] | undefined; }' is not assignable to type '(search: string) => { isLoading: boolean; commands?: WPCommandConfig[] | undefined; }'.
search={ search }
setLoader={ setLoader }
close={ close }
Expand All @@ -178,7 +205,19 @@
);
}

export function CommandMenuGroup( { isContextual, search, setLoader, close } ) {
interface CommandMenuGroupProps {
isContextual?: any;
search: string;
setLoader: SetLoader;
close: () => void;
}

export function CommandMenuGroup( {
isContextual,
search,
setLoader,
close,
}: CommandMenuGroupProps ) {
const { commands, loaders } = useSelect(
( select ) => {
const { getCommands, getCommandLoaders } = select( commandsStore );
Expand Down Expand Up @@ -234,7 +273,7 @@
{ loaders.map( ( loader ) => (
<CommandMenuLoaderWrapper
key={ loader.name }
hook={ loader.hook }

Check failure on line 276 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Check

Type 'WPCommandLoaderHook' is not assignable to type '(search: string) => { isLoading?: boolean | undefined; commands?: WPCommandConfig[] | undefined; }'.

Check failure on line 276 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / All

Type 'WPCommandLoaderHook' is not assignable to type '(search: string) => { isLoading?: boolean | undefined; commands?: WPCommandConfig[] | undefined; }'.

Check failure on line 276 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Type 'WPCommandLoaderHook' is not assignable to type '(search: string) => { isLoading?: boolean | undefined; commands?: WPCommandConfig[] | undefined; }'.
search={ search }
setLoader={ setLoader }
close={ close }
Expand All @@ -245,8 +284,14 @@
);
}

function CommandInput( { isOpen, search, setSearch } ) {
const commandMenuInput = useRef();
interface CommandInputProps {
isOpen: boolean;
search: string;
setSearch: ( search: string ) => void;
}

function CommandInput( { isOpen, search, setSearch }: CommandInputProps ) {
const commandMenuInput = useRef< HTMLInputElement >( null );
const _value = useCommandState( ( state ) => state.value );
const selectedItemId = useMemo( () => {
const item = document.querySelector(
Expand All @@ -257,7 +302,7 @@
useEffect( () => {
// Focus the command palette input when mounting the modal.
if ( isOpen ) {
commandMenuInput.current.focus();
commandMenuInput.current?.focus();
}
}, [ isOpen ] );
return (
Expand All @@ -266,7 +311,9 @@
value={ search }
onValueChange={ setSearch }
placeholder={ inputLabel }
aria-activedescendant={ selectedItemId }
aria-activedescendant={
selectedItemId ? selectedItemId : undefined
}
/>
);
}
Expand All @@ -282,7 +329,7 @@
[]
);
const { open, close } = useDispatch( commandsStore );
const [ loaders, setLoaders ] = useState( {} );
const [ loaders, setLoaders ] = useState< SetLoader >( {} );

Check failure on line 332 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Check

Argument of type '{}' is not assignable to parameter of type 'SetLoader | (() => SetLoader)'.

Check failure on line 332 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / All

Argument of type '{}' is not assignable to parameter of type 'SetLoader | (() => SetLoader)'.

Check failure on line 332 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Argument of type '{}' is not assignable to parameter of type 'SetLoader | (() => SetLoader)'.

useEffect( () => {
registerShortcut( {
Expand All @@ -299,7 +346,7 @@
useShortcut(
'core/commands',
/** @type {React.KeyboardEventHandler} */
withIgnoreIMEEvents( ( event ) => {
withIgnoreIMEEvents( ( event: KeyboardEvent ) => {
// Bails to avoid obscuring the effect of the preceding handler(s).
if ( event.defaultPrevented ) {
return;
Expand All @@ -313,13 +360,14 @@
}
} ),
{
// @ts-expect-error this isn't in the useShortcut type but might be in the future
bindGlobal: true,
}
);

const setLoader = useCallback(
( name, value ) =>
( name: string, value ) =>

Check failure on line 369 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Check

Parameter 'value' implicitly has an 'any' type.

Check failure on line 369 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / All

Parameter 'value' implicitly has an 'any' type.

Check failure on line 369 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Parameter 'value' implicitly has an 'any' type.
setLoaders( ( current ) => ( {

Check failure on line 370 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Check

Parameter 'current' implicitly has an 'any' type.

Check failure on line 370 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / All

Parameter 'current' implicitly has an 'any' type.

Check failure on line 370 in packages/commands/src/components/command-menu.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Parameter 'current' implicitly has an 'any' type.
...current,
[ name ]: value,
} ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { unlock } from '../lock-unlock';
*
* @param {string} context Context to set.
*/
export default function useCommandContext( context ) {
export default function useCommandContext( context: string ) {
const { getContext } = useSelect( commandsStore );
const initialContext = useRef( getContext() );
const { setContext } = unlock( useDispatch( commandsStore ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { useDispatch } from '@wordpress/data';
* Internal dependencies
*/
import { store as commandsStore } from '../store';
import type { WPCommandLoaderConfig } from '../store/actions';

/**
* Attach a command loader to the command palette. Used for dynamic commands.
*
* @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
* @param loader command loader config.
*
* @example
* ```js
Expand Down Expand Up @@ -79,7 +80,7 @@ import { store as commandsStore } from '../store';
* } );
* ```
*/
export default function useCommandLoader( loader ) {
export default function useCommandLoader( loader: WPCommandLoaderConfig ) {
const { registerCommandLoader, unregisterCommandLoader } =
useDispatch( commandsStore );
useEffect( () => {
Expand Down
Loading
Loading