From e558540d912285f3bfcaecd5c44ef6ef91543818 Mon Sep 17 00:00:00 2001 From: Adam Bosco Date: Sat, 28 Nov 2020 20:06:15 -0700 Subject: [PATCH] Keyboard Shortcuts: Replace store name string with exposed store definition Replaces references to the `core/keyboard-shortcuts` store name string with the store definition object, adding `import`s where necessary. Addresses #27088. --- .../src/components/block-navigation/dropdown.js | 7 +++++-- .../block-settings-menu/block-settings-dropdown.js | 5 ++--- .../src/components/keyboard-shortcuts/index.js | 7 +++++-- .../edit-navigation/src/components/layout/shortcuts.js | 7 +++++-- .../edit-post/src/components/header/mode-switcher/index.js | 3 ++- .../keyboard-shortcut-help-modal/dynamic-shortcut.js | 3 ++- .../src/components/keyboard-shortcut-help-modal/index.js | 7 +++++-- .../edit-post/src/components/keyboard-shortcuts/index.js | 7 +++++-- packages/edit-post/src/components/layout/index.js | 5 +++-- .../src/components/sidebar/plugin-sidebar/index.js | 3 ++- .../src/components/sidebar/settings-sidebar/index.js | 3 ++- .../src/components/visual-editor/block-inspector-button.js | 3 ++- .../edit-site/src/components/keyboard-shortcuts/index.js | 7 +++++-- .../src/components/keyboard-shortcuts/index.js | 7 +++++-- .../global-keyboard-shortcuts/register-shortcuts.js | 3 ++- packages/keyboard-shortcuts/src/hooks/use-shortcut.js | 7 ++++++- 16 files changed, 58 insertions(+), 26 deletions(-) diff --git a/packages/block-editor/src/components/block-navigation/dropdown.js b/packages/block-editor/src/components/block-navigation/dropdown.js index e2c4ea1b62e424..d71c0c370ea7ae 100644 --- a/packages/block-editor/src/components/block-navigation/dropdown.js +++ b/packages/block-editor/src/components/block-navigation/dropdown.js @@ -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'; /** @@ -40,7 +43,7 @@ function BlockNavigationDropdownToggle( { ); const shortcut = useSelect( ( select ) => - select( 'core/keyboard-shortcuts' ).getShortcutRepresentation( + select( keyboardShortcutsStore ).getShortcutRepresentation( 'core/edit-post/toggle-block-navigation' ), [] diff --git a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js index b4e6b97e120579..acb7bfcf39d318 100644 --- a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js +++ b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js @@ -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 @@ -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' diff --git a/packages/block-editor/src/components/keyboard-shortcuts/index.js b/packages/block-editor/src/components/keyboard-shortcuts/index.js index 563b158bd97519..d13ea908c9cda0 100644 --- a/packages/block-editor/src/components/keyboard-shortcuts/index.js +++ b/packages/block-editor/src/components/keyboard-shortcuts/index.js @@ -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() { @@ -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', diff --git a/packages/edit-navigation/src/components/layout/shortcuts.js b/packages/edit-navigation/src/components/layout/shortcuts.js index d75d3f176e2e40..9c2e228b4cc0e9 100644 --- a/packages/edit-navigation/src/components/layout/shortcuts.js +++ b/packages/edit-navigation/src/components/layout/shortcuts.js @@ -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 } ) { @@ -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', diff --git a/packages/edit-post/src/components/header/mode-switcher/index.js b/packages/edit-post/src/components/header/mode-switcher/index.js index 5ee3ec93747978..fa32c71f6d3f3d 100644 --- a/packages/edit-post/src/components/header/mode-switcher/index.js +++ b/packages/edit-post/src/components/header/mode-switcher/index.js @@ -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. @@ -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, diff --git a/packages/edit-post/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.js b/packages/edit-post/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.js index f60e0f2aad846d..fe97fba37e14ac 100644 --- a/packages/edit-post/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +++ b/packages/edit-post/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.js @@ -2,6 +2,7 @@ * WordPress dependencies */ import { useSelect } from '@wordpress/data'; +import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; /** * Internal dependencies @@ -14,7 +15,7 @@ function DynamicShortcut( { name } ) { getShortcutKeyCombination, getShortcutDescription, getShortcutAliases, - } = select( 'core/keyboard-shortcuts' ); + } = select( keyboardShortcutsStore ); return { keyCombination: getShortcutKeyCombination( name ), diff --git a/packages/edit-post/src/components/keyboard-shortcut-help-modal/index.js b/packages/edit-post/src/components/keyboard-shortcut-help-modal/index.js index ebabc14ca3b747..9c269c4a1be751 100644 --- a/packages/edit-post/src/components/keyboard-shortcut-help-modal/index.js +++ b/packages/edit-post/src/components/keyboard-shortcut-help-modal/index.js @@ -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'; @@ -71,7 +74,7 @@ const ShortcutCategorySection = ( { } ) => { const categoryShortcuts = useSelect( ( select ) => { - return select( 'core/keyboard-shortcuts' ).getCategoryShortcuts( + return select( keyboardShortcutsStore ).getCategoryShortcuts( categoryName ); }, diff --git a/packages/edit-post/src/components/keyboard-shortcuts/index.js b/packages/edit-post/src/components/keyboard-shortcuts/index.js index 77ea945af679bd..65facebd21891a 100644 --- a/packages/edit-post/src/components/keyboard-shortcuts/index.js +++ b/packages/edit-post/src/components/keyboard-shortcuts/index.js @@ -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() { @@ -32,7 +35,7 @@ function KeyboardShortcuts() { closeGeneralSidebar, toggleFeature, } = useDispatch( 'core/edit-post' ); - const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' ); + const { registerShortcut } = useDispatch( keyboardShortcutsStore ); useEffect( () => { registerShortcut( { diff --git a/packages/edit-post/src/components/layout/index.js b/packages/edit-post/src/components/layout/index.js index 9200c56812022c..449ab7535baeb5 100644 --- a/packages/edit-post/src/components/layout/index.js +++ b/packages/edit-post/src/components/layout/index.js @@ -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 @@ -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' diff --git a/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js b/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js index 27a1d7733f1b80..d6193b0448979e 100644 --- a/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js +++ b/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js @@ -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. @@ -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' diff --git a/packages/edit-post/src/components/sidebar/settings-sidebar/index.js b/packages/edit-post/src/components/sidebar/settings-sidebar/index.js index c4548ba61820b3..d488179edc7184 100644 --- a/packages/edit-post/src/components/sidebar/settings-sidebar/index.js +++ b/packages/edit-post/src/components/sidebar/settings-sidebar/index.js @@ -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 @@ -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 }; }, [] ); diff --git a/packages/edit-post/src/components/visual-editor/block-inspector-button.js b/packages/edit-post/src/components/visual-editor/block-inspector-button.js index 5a57dcd63e5ae7..2eb90256b4c17d 100644 --- a/packages/edit-post/src/components/visual-editor/block-inspector-button.js +++ b/packages/edit-post/src/components/visual-editor/block-inspector-button.js @@ -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() === diff --git a/packages/edit-site/src/components/keyboard-shortcuts/index.js b/packages/edit-site/src/components/keyboard-shortcuts/index.js index a0588857ea2451..75fe5b085c31d6 100644 --- a/packages/edit-site/src/components/keyboard-shortcuts/index.js +++ b/packages/edit-site/src/components/keyboard-shortcuts/index.js @@ -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'; @@ -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', diff --git a/packages/edit-widgets/src/components/keyboard-shortcuts/index.js b/packages/edit-widgets/src/components/keyboard-shortcuts/index.js index 6494d83cafc27d..3b0e00e5a155e3 100644 --- a/packages/edit-widgets/src/components/keyboard-shortcuts/index.js +++ b/packages/edit-widgets/src/components/keyboard-shortcuts/index.js @@ -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'; @@ -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', diff --git a/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js b/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js index 4879a83d1d5ddd..ed65b49d3cc8c3 100644 --- a/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js +++ b/packages/editor/src/components/global-keyboard-shortcuts/register-shortcuts.js @@ -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', diff --git a/packages/keyboard-shortcuts/src/hooks/use-shortcut.js b/packages/keyboard-shortcuts/src/hooks/use-shortcut.js index f6b0f4e584b90f..7447209d5ba713 100644 --- a/packages/keyboard-shortcuts/src/hooks/use-shortcut.js +++ b/packages/keyboard-shortcuts/src/hooks/use-shortcut.js @@ -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. * @@ -15,7 +20,7 @@ function useShortcut( name, callback, options ) { const shortcuts = useSelect( ( select ) => { return select( - 'core/keyboard-shortcuts' + keyboardShortcutsStore ).getAllShortcutRawKeyCombinations( name ); }, [ name ]