Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard Shortcuts: Replace store name string with exposed store definition #27355

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import { Button, Dropdown, SVG, Path } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import {
useShortcut,
store as keyboardShortcutsStore,
} from '@wordpress/keyboard-shortcuts';
import { useCallback, forwardRef } from '@wordpress/element';

/**
Expand Down Expand Up @@ -40,7 +43,7 @@ function BlockNavigationDropdownToggle( {
);
const shortcut = useSelect(
( select ) =>
select( 'core/keyboard-shortcuts' ).getShortcutRepresentation(
select( keyboardShortcutsStore ).getShortcutRepresentation(
'core/edit-post/toggle-block-navigation'
),
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { moreVertical } from '@wordpress/icons';

import { Children, cloneElement, useCallback } from '@wordpress/element';
import { serialize } from '@wordpress/blocks';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Internal dependencies
Expand Down Expand Up @@ -45,9 +46,7 @@ export function BlockSettingsDropdown( {
const firstBlockClientId = blockClientIds[ 0 ];

const shortcuts = useSelect( ( select ) => {
const { getShortcutRepresentation } = select(
'core/keyboard-shortcuts'
);
const { getShortcutRepresentation } = select( keyboardShortcutsStore );
return {
duplicate: getShortcutRepresentation(
'core/block-editor/duplicate'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { first, last } from 'lodash';
*/
import { useEffect, useCallback } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import {
useShortcut,
store as keyboardShortcutsStore,
} from '@wordpress/keyboard-shortcuts';
import { __ } from '@wordpress/i18n';

function KeyboardShortcuts() {
Expand Down Expand Up @@ -168,7 +171,7 @@ function KeyboardShortcuts() {

function KeyboardShortcutsRegister() {
// Registering the shortcuts
const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
useEffect( () => {
registerShortcut( {
name: 'core/block-editor/duplicate',
Expand Down
7 changes: 5 additions & 2 deletions packages/edit-navigation/src/components/layout/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/
import { useEffect, useCallback } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import {
useShortcut,
store as keyboardShortcutsStore,
} from '@wordpress/keyboard-shortcuts';
import { __ } from '@wordpress/i18n';

function NavigationEditorShortcuts( { saveBlocks } ) {
Expand Down Expand Up @@ -41,7 +44,7 @@ function NavigationEditorShortcuts( { saveBlocks } ) {
}

function RegisterNavigationEditorShortcuts() {
const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
useEffect( () => {
registerShortcut( {
name: 'core/edit-navigation/save-menu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { __ } from '@wordpress/i18n';
import { MenuItemsChoice, MenuGroup } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Set of available mode options.
Expand All @@ -30,7 +31,7 @@ function ModeSwitcher() {
} = useSelect(
( select ) => ( {
shortcut: select(
'core/keyboard-shortcuts'
keyboardShortcutsStore
).getShortcutRepresentation( 'core/edit-post/toggle-mode' ),
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings()
.richEditingEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Internal dependencies
Expand All @@ -14,7 +15,7 @@ function DynamicShortcut( { name } ) {
getShortcutKeyCombination,
getShortcutDescription,
getShortcutAliases,
} = select( 'core/keyboard-shortcuts' );
} = select( keyboardShortcutsStore );

return {
keyCombination: getShortcutKeyCombination( name ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { isString } from 'lodash';
*/
import { Modal } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import {
useShortcut,
store as keyboardShortcutsStore,
} from '@wordpress/keyboard-shortcuts';
import { withSelect, withDispatch, useSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';

Expand Down Expand Up @@ -71,7 +74,7 @@ const ShortcutCategorySection = ( {
} ) => {
const categoryShortcuts = useSelect(
( select ) => {
return select( 'core/keyboard-shortcuts' ).getCategoryShortcuts(
return select( keyboardShortcutsStore ).getCategoryShortcuts(
categoryName
);
},
Expand Down
7 changes: 5 additions & 2 deletions packages/edit-post/src/components/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/
import { useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import {
useShortcut,
store as keyboardShortcutsStore,
} from '@wordpress/keyboard-shortcuts';
import { __ } from '@wordpress/i18n';

function KeyboardShortcuts() {
Expand Down Expand Up @@ -32,7 +35,7 @@ function KeyboardShortcuts() {
closeGeneralSidebar,
toggleFeature,
} = useDispatch( 'core/edit-post' );
const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );

useEffect( () => {
registerShortcut( {
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from '@wordpress/interface';
import { useState, useEffect, useCallback, useRef } from '@wordpress/element';
import { close } from '@wordpress/icons';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Internal dependencies
Expand Down Expand Up @@ -111,12 +112,12 @@ function Layout( { settings } ) {
.richEditingEnabled,
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
previousShortcut: select(
'core/keyboard-shortcuts'
keyboardShortcutsStore
).getAllShortcutRawKeyCombinations(
'core/edit-post/previous-region'
),
nextShortcut: select(
'core/keyboard-shortcuts'
keyboardShortcutsStore
).getAllShortcutRawKeyCombinations( 'core/edit-post/next-region' ),
showIconLabels: select( 'core/edit-post' ).isFeatureActive(
'showIconLabels'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { ComplementaryArea } from '@wordpress/interface';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Renders a sidebar when activated. The contents within the `PluginSidebar` will appear as content within the sidebar.
Expand Down Expand Up @@ -78,7 +79,7 @@ export default function PluginSidebarEditPost( { className, ...props } ) {
'title'
),
shortcut: select(
'core/keyboard-shortcuts'
keyboardShortcutsStore
).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' ),
showIconLabels: select( 'core/edit-post' ).isFeatureActive(
'showIconLabels'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { BlockInspector } from '@wordpress/block-editor';
import { cog } from '@wordpress/icons';
import { Platform } from '@wordpress/element';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Internal dependencies
Expand Down Expand Up @@ -49,7 +50,7 @@ const SettingsSidebar = () => {
sidebar = 'edit-post/document';
}
const shortcut = select(
'core/keyboard-shortcuts'
keyboardShortcutsStore
).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' );
return { sidebarName: sidebar, keyboardShortcut: shortcut };
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { __ } from '@wordpress/i18n';
import { MenuItem } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { speak } from '@wordpress/a11y';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

export function BlockInspectorButton( { onClick = noop, small = false } ) {
const { shortcut, areAdvancedSettingsOpened } = useSelect(
( select ) => ( {
shortcut: select(
'core/keyboard-shortcuts'
keyboardShortcutsStore
).getShortcutRepresentation( 'core/edit-post/toggle-sidebar' ),
areAdvancedSettingsOpened:
select( 'core/edit-post' ).getActiveGeneralSidebarName() ===
Expand Down
7 changes: 5 additions & 2 deletions packages/edit-site/src/components/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import {
useShortcut,
store as keyboardShortcutsStore,
} from '@wordpress/keyboard-shortcuts';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -31,7 +34,7 @@ function KeyboardShortcuts() {
}
function KeyboardShortcutsRegister() {
// Registering the shortcuts
const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
useEffect( () => {
registerShortcut( {
name: 'core/edit-site/undo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import {
useShortcut,
store as keyboardShortcutsStore,
} from '@wordpress/keyboard-shortcuts';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -42,7 +45,7 @@ function KeyboardShortcuts() {

function KeyboardShortcutsRegister() {
// Registering the shortcuts
const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
useEffect( () => {
registerShortcut( {
name: 'core/edit-widgets/undo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { useEffect } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { BlockEditorKeyboardShortcuts } from '@wordpress/block-editor';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

function EditorKeyboardShortcutsRegister() {
// Registering the shortcuts
const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
useEffect( () => {
registerShortcut( {
name: 'core/editor/save',
Expand Down
7 changes: 6 additions & 1 deletion packages/keyboard-shortcuts/src/hooks/use-shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import { useSelect } from '@wordpress/data';
import { useKeyboardShortcut } from '@wordpress/compose';

/**
* Internal dependencies
*/
import { store as keyboardShortcutsStore } from '../store';

/**
* Attach a keyboard shortcut handler.
*
Expand All @@ -15,7 +20,7 @@ function useShortcut( name, callback, options ) {
const shortcuts = useSelect(
( select ) => {
return select(
'core/keyboard-shortcuts'
keyboardShortcutsStore
).getAllShortcutRawKeyCombinations( name );
},
[ name ]
Expand Down