@wordpress/edit-post
Version:
Edit Post module for WordPress.
152 lines (142 loc) • 4.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
var _i18n = require("@wordpress/i18n");
var _store = require("../../store");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function KeyboardShortcuts() {
const {
getBlockSelectionStart
} = (0, _data.useSelect)('core/block-editor');
const {
getEditorMode,
isEditorSidebarOpened
} = (0, _data.useSelect)(_store.store);
const isModeToggleDisabled = (0, _data.useSelect)(select => {
const {
richEditingEnabled,
codeEditingEnabled
} = select('core/editor').getEditorSettings();
return !richEditingEnabled || !codeEditingEnabled;
}, []);
const {
switchEditorMode,
openGeneralSidebar,
closeGeneralSidebar,
toggleFeature
} = (0, _data.useDispatch)(_store.store);
const {
registerShortcut
} = (0, _data.useDispatch)(_keyboardShortcuts.store);
(0, _element.useEffect)(() => {
registerShortcut({
name: 'core/edit-post/toggle-mode',
category: 'global',
description: (0, _i18n.__)('Switch between visual editor and code editor.'),
keyCombination: {
modifier: 'secondary',
character: 'm'
}
});
registerShortcut({
name: 'core/edit-post/toggle-fullscreen',
category: 'global',
description: (0, _i18n.__)('Toggle fullscreen mode.'),
keyCombination: {
modifier: 'secondary',
character: 'f'
}
});
registerShortcut({
name: 'core/edit-post/toggle-block-navigation',
category: 'global',
description: (0, _i18n.__)('Open the block list view.'),
keyCombination: {
modifier: 'access',
character: 'o'
}
});
registerShortcut({
name: 'core/edit-post/toggle-sidebar',
category: 'global',
description: (0, _i18n.__)('Show or hide the settings sidebar.'),
keyCombination: {
modifier: 'primaryShift',
character: ','
}
});
registerShortcut({
name: 'core/edit-post/next-region',
category: 'global',
description: (0, _i18n.__)('Navigate to the next part of the editor.'),
keyCombination: {
modifier: 'ctrl',
character: '`'
},
aliases: [{
modifier: 'access',
character: 'n'
}]
});
registerShortcut({
name: 'core/edit-post/previous-region',
category: 'global',
description: (0, _i18n.__)('Navigate to the previous part of the editor.'),
keyCombination: {
modifier: 'ctrlShift',
character: '`'
},
aliases: [{
modifier: 'access',
character: 'p'
}]
});
registerShortcut({
name: 'core/edit-post/keyboard-shortcuts',
category: 'main',
description: (0, _i18n.__)('Display these keyboard shortcuts.'),
keyCombination: {
modifier: 'access',
character: 'h'
}
});
}, []);
(0, _keyboardShortcuts.useShortcut)('core/edit-post/toggle-mode', () => {
switchEditorMode(getEditorMode() === 'visual' ? 'text' : 'visual');
}, {
bindGlobal: true,
isDisabled: isModeToggleDisabled
});
(0, _keyboardShortcuts.useShortcut)('core/edit-post/toggle-fullscreen', () => {
toggleFeature('fullscreenMode');
}, {
bindGlobal: true
});
(0, _keyboardShortcuts.useShortcut)('core/edit-post/toggle-sidebar', event => {
// This shortcut has no known clashes, but use preventDefault to prevent any
// obscure shortcuts from triggering.
event.preventDefault();
if (isEditorSidebarOpened()) {
closeGeneralSidebar();
} else {
const sidebarToOpen = getBlockSelectionStart() ? 'edit-post/block' : 'edit-post/document';
openGeneralSidebar(sidebarToOpen);
}
}, {
bindGlobal: true
});
return null;
}
var _default = KeyboardShortcuts;
exports.default = _default;
//# sourceMappingURL=index.js.map