UNPKG

@wordpress/edit-post

Version:
107 lines (93 loc) 3.83 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { Component } from '@wordpress/element'; import { KeyboardShortcuts } from '@wordpress/components'; import { withSelect, withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; /** * Internal dependencies */ import shortcuts from '../../keyboard-shortcuts'; var EditorModeKeyboardShortcuts = /*#__PURE__*/ function (_Component) { _inherits(EditorModeKeyboardShortcuts, _Component); function EditorModeKeyboardShortcuts() { var _this; _classCallCheck(this, EditorModeKeyboardShortcuts); _this = _possibleConstructorReturn(this, _getPrototypeOf(EditorModeKeyboardShortcuts).apply(this, arguments)); _this.toggleMode = _this.toggleMode.bind(_assertThisInitialized(_assertThisInitialized(_this))); _this.toggleSidebar = _this.toggleSidebar.bind(_assertThisInitialized(_assertThisInitialized(_this))); return _this; } _createClass(EditorModeKeyboardShortcuts, [{ key: "toggleMode", value: function toggleMode() { var _this$props = this.props, mode = _this$props.mode, switchMode = _this$props.switchMode, isRichEditingEnabled = _this$props.isRichEditingEnabled; if (!isRichEditingEnabled) { return; } switchMode(mode === 'visual' ? 'text' : 'visual'); } }, { key: "toggleSidebar", value: function toggleSidebar(event) { // This shortcut has no known clashes, but use preventDefault to prevent any // obscure shortcuts from triggering. event.preventDefault(); var _this$props2 = this.props, isEditorSidebarOpen = _this$props2.isEditorSidebarOpen, closeSidebar = _this$props2.closeSidebar, openSidebar = _this$props2.openSidebar; if (isEditorSidebarOpen) { closeSidebar(); } else { openSidebar(); } } }, { key: "render", value: function render() { var _ref; return createElement(KeyboardShortcuts, { bindGlobal: true, shortcuts: (_ref = {}, _defineProperty(_ref, shortcuts.toggleEditorMode.raw, this.toggleMode), _defineProperty(_ref, shortcuts.toggleSidebar.raw, this.toggleSidebar), _ref) }); } }]); return EditorModeKeyboardShortcuts; }(Component); export default compose([withSelect(function (select) { return { isRichEditingEnabled: select('core/editor').getEditorSettings().richEditingEnabled, mode: select('core/edit-post').getEditorMode(), isEditorSidebarOpen: select('core/edit-post').isEditorSidebarOpened() }; }), withDispatch(function (dispatch, ownProps, _ref2) { var select = _ref2.select; return { switchMode: function switchMode(mode) { dispatch('core/edit-post').switchEditorMode(mode); }, openSidebar: function openSidebar() { var _select = select('core/block-editor'), getBlockSelectionStart = _select.getBlockSelectionStart; var sidebarToOpen = getBlockSelectionStart() ? 'edit-post/block' : 'edit-post/document'; dispatch('core/edit-post').openGeneralSidebar(sidebarToOpen); }, closeSidebar: dispatch('core/edit-post').closeGeneralSidebar }; })])(EditorModeKeyboardShortcuts); //# sourceMappingURL=index.js.map