Skip to content

Commit

Permalink
Editor: Unify the editor commands between post and site editors
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 14, 2024
1 parent 8cc54ee commit c390fb5
Show file tree
Hide file tree
Showing 31 changed files with 527 additions and 705 deletions.
4 changes: 4 additions & 0 deletions docs/reference-guides/data/data-core-edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ _Parameters_

### switchEditorMode

> **Deprecated**
Triggers an action used to switch editor mode.

_Parameters_
Expand All @@ -484,6 +486,8 @@ _Parameters_

### toggleDistractionFree

> **Deprecated**
Action that toggles Distraction free mode. Distraction free mode expects there are no sidebars, as due to the z-index values set, you can't close sidebars.

### toggleEditorPanelEnabled
Expand Down
10 changes: 9 additions & 1 deletion docs/reference-guides/data/data-core-edit-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,18 @@ _Returns_

### switchEditorMode

Undocumented declaration.
> **Deprecated**
Triggers an action used to switch editor mode.

_Parameters_

- _mode_ `string`: The editor mode.

### toggleDistractionFree

> **Deprecated**
Action that toggles Distraction free mode. Distraction free mode expects there are no sidebars, as due to the z-index values set, you can't close sidebars.

### toggleFeature
Expand Down
24 changes: 24 additions & 0 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,18 @@ _Returns_

- `Array`: Block list.

### getEditorMode

Returns the current editing mode.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `string`: Editing mode.

### getEditorSelection

Returns the current selection.
Expand Down Expand Up @@ -1467,6 +1479,14 @@ _Related_

- stopTyping in core/block-editor store.

### switchEditorMode

Triggers an action used to switch editor mode.

_Parameters_

- _mode_ `string`: The editor mode.

### synchronizeTemplate

_Related_
Expand All @@ -1479,6 +1499,10 @@ _Related_

- toggleBlockMode in core/block-editor store.

### toggleDistractionFree

Action that toggles Distraction free mode. Distraction free mode expects there are no sidebars, as due to the z-index values set, you can't close sidebars.

### toggleEditorPanelEnabled

Returns an action object used to enable or disable a panel in the editor.
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
hasHistory,
} = useSelect( ( select ) => {
const { get: getPreference } = select( preferencesStore );
const { getEditorMode } = select( editPostStore );
const { getEditorMode } = select( editorStore );

return {
isTextEditor: getEditorMode() === 'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as editorStore } from '@wordpress/editor';

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

/**
* Set of available mode options.
*
Expand Down Expand Up @@ -41,11 +36,11 @@ function ModeSwitcher() {
isCodeEditingEnabled:
select( editorStore ).getEditorSettings()
.codeEditingEnabled,
mode: select( editPostStore ).getEditorMode(),
mode: select( editorStore ).getEditorMode(),
} ),
[]
);
const { switchEditorMode } = useDispatch( editPostStore );
const { switchEditorMode } = useDispatch( editorStore );

let selectedMode = mode;
if ( ! isRichEditingEnabled && mode === 'visual' ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import {
PreferenceToggleMenuItem,
store as preferencesStore,
} from '@wordpress/preferences';

/**
* Internal dependencies
*/
import { store as postEditorStore } from '../../../store';
import { store as editorStore } from '@wordpress/editor';

function WritingMenu() {
const { set: setPreference } = useDispatch( preferencesStore );
const { toggleDistractionFree } = useDispatch( postEditorStore );
const { toggleDistractionFree } = useDispatch( editorStore );

const turnOffDistractionFree = () => {
setPreference( 'core', 'distractionFree', false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function KeyboardShortcuts() {
openGeneralSidebar,
closeGeneralSidebar,
toggleFeature,
toggleDistractionFree,
} = useDispatch( editPostStore );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
const { replaceBlocks } = useDispatch( blockEditorStore );
Expand All @@ -39,6 +38,7 @@ function KeyboardShortcuts() {
getBlockAttributes,
getBlockSelectionStart,
} = useSelect( blockEditorStore );
const { toggleDistractionFree } = useDispatch( editorStore );

const handleTextLevelShortcut = ( event, level ) => {
event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function Layout( { initialPost } ) {
select( editPostStore ).isFeatureActive( 'fullscreenMode' ),
isInserterOpened: select( editorStore ).isInserterOpened(),
isListViewOpened: select( editorStore ).isListViewOpened(),
mode: select( editPostStore ).getEditorMode(),
mode: select( editorStore ).getEditorMode(),
isRichEditingEnabled: editorSettings.richEditingEnabled,
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
previousShortcut: select(
Expand Down
4 changes: 1 addition & 3 deletions packages/edit-post/src/components/layout/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import styles from './style.scss';
import headerToolbarStyles from '../header/header-toolbar/style.scss';
import Header from '../header';
import VisualEditor from '../visual-editor';
import { store as editPostStore } from '../../store';

class Layout extends Component {
constructor() {
Expand Down Expand Up @@ -192,9 +191,8 @@ class Layout extends Component {

export default compose( [
withSelect( ( select ) => {
const { __unstableIsEditorReady: isEditorReady } =
const { __unstableIsEditorReady: isEditorReady, getEditorMode } =
select( editorStore );
const { getEditorMode } = select( editPostStore );
const { getSettings } = select( blockEditorStore );
const globalStyles =
getSettings()?.__experimentalGlobalStylesBaseStyles?.color;
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function TextEditor() {
const isRichEditingEnabled = useSelect( ( select ) => {
return select( editorStore ).getEditorSettings().richEditingEnabled;
}, [] );
const { switchEditorMode } = useDispatch( editPostStore );
const { switchEditorMode } = useDispatch( editorStore );

const { isWelcomeGuideVisible } = useSelect( ( select ) => {
const { isFeatureActive } = select( editPostStore );
Expand Down
7 changes: 3 additions & 4 deletions packages/edit-post/src/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GestureHandlerRootView } from 'react-native-gesture-handler';
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { EditorProvider } from '@wordpress/editor';
import { EditorProvider, store as editorStore } from '@wordpress/editor';
import { parse, serialize } from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
Expand All @@ -24,7 +24,6 @@ import { store as coreStore } from '@wordpress/core-data';
* Internal dependencies
*/
import Layout from './components/layout';
import { store as editPostStore } from './store';

class Editor extends Component {
constructor( props ) {
Expand Down Expand Up @@ -154,14 +153,14 @@ class Editor extends Component {

export default compose( [
withSelect( ( select ) => {
const { getEditorMode } = select( editPostStore );
const { getEditorMode } = select( editorStore );

return {
mode: getEditorMode(),
};
} ),
withDispatch( ( dispatch ) => {
const { switchEditorMode } = dispatch( editPostStore );
const { switchEditorMode } = dispatch( editorStore );
const { editEntityRecord } = dispatch( coreStore );
return {
switchEditorMode,
Expand Down
Loading

0 comments on commit c390fb5

Please sign in to comment.