diff --git a/packages/e2e-test-utils/src/inserter.js b/packages/e2e-test-utils/src/inserter.js index a2c73abe666552..cf5d7c48c9dfdd 100644 --- a/packages/e2e-test-utils/src/inserter.js +++ b/packages/e2e-test-utils/src/inserter.js @@ -64,7 +64,8 @@ export async function toggleGlobalBlockInserter() { // "Add block" selector is required to make sure performance comparison // doesn't fail on older branches where we still had "Add block" as label. await page.click( - '.edit-post-header [aria-label="Add block"],' + + '.editor-document-tools__inserter-toggle,' + + '.edit-post-header [aria-label="Add block"],' + '.edit-site-header [aria-label="Add block"],' + '.edit-post-header [aria-label="Toggle block inserter"],' + '.edit-site-header [aria-label="Toggle block inserter"],' + diff --git a/packages/e2e-test-utils/src/list-view.js b/packages/e2e-test-utils/src/list-view.js index f02b5d1729dccd..21861d023a9f90 100644 --- a/packages/e2e-test-utils/src/list-view.js +++ b/packages/e2e-test-utils/src/list-view.js @@ -1,7 +1,7 @@ async function toggleListView() { // selector .edit-post-header-toolbar__list-view-toggle is still required because the performance tests also execute against older versions that still use that selector. await page.click( - '.edit-post-header-toolbar__document-overview-toggle, .edit-post-header-toolbar__list-view-toggle, .edit-site-header-edit-mode__list-view-toggle, .edit-widgets-header-toolbar__list-view-toggle' + '.edit-post-header-toolbar__document-overview-toggle, .edit-post-header-toolbar__list-view-toggle, .edit-site-header-edit-mode__list-view-toggle, .edit-widgets-header-toolbar__list-view-toggle, editor-document-tools__document-overview-toggle' ); } @@ -9,7 +9,7 @@ export async function isListViewOpen() { return await page.evaluate( () => { // selector .edit-post-header-toolbar__list-view-toggle is still required because the performance tests also execute against older versions that still use that selector. return !! document.querySelector( - '.edit-post-header-toolbar__document-overview-toggle.is-pressed, .edit-post-header-toolbar__list-view-toggle.is-pressed, .edit-site-header-edit-mode__list-view-toggle.is-pressed, .edit-widgets-header-toolbar__list-view-toggle.is-pressed' + '.edit-post-header-toolbar__document-overview-toggle.is-pressed, .edit-post-header-toolbar__list-view-toggle.is-pressed, .edit-site-header-edit-mode__list-view-toggle.is-pressed, .edit-widgets-header-toolbar__list-view-toggle.is-pressed, editor-document-tools__document-overview-toggle.is-pressed' ); } ); } diff --git a/packages/e2e-tests/specs/editor/various/editor-modes.test.js b/packages/e2e-tests/specs/editor/various/editor-modes.test.js index 017237df9fbede..bb051fe705b38d 100644 --- a/packages/e2e-tests/specs/editor/various/editor-modes.test.js +++ b/packages/e2e-tests/specs/editor/various/editor-modes.test.js @@ -127,7 +127,7 @@ describe( 'Editing modes (visual/HTML)', () => { // The inserter is disabled. const disabledInserter = await page.$( - '.edit-post-header-toolbar__inserter-toggle:disabled, .edit-post-header-toolbar__inserter-toggle[aria-disabled="true"]' + '.editor-document-tools__inserter-toggle:disabled, .editor-document-tools__inserter-toggle[aria-disabled="true"]' ); expect( disabledInserter ).not.toBeNull(); } ); diff --git a/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js b/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js index 4285a410f891e5..100a515013721c 100644 --- a/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/inserting-blocks.test.js @@ -332,7 +332,7 @@ describe( 'Inserting blocks', () => { it( 'closes the main inserter after inserting a single-use block, like the More block', async () => { await insertBlock( 'More' ); await page.waitForSelector( - '.edit-post-header-toolbar__inserter-toggle:not(.is-pressed)' + '.editor-document-tools__inserter-toggle:not(.is-pressed)' ); // The inserter panel should've closed. diff --git a/packages/edit-post/src/components/header/index.js b/packages/edit-post/src/components/header/index.js index 1e0a1f31956130..79229175185cd9 100644 --- a/packages/edit-post/src/components/header/index.js +++ b/packages/edit-post/src/components/header/index.js @@ -34,14 +34,14 @@ import { store as preferencesStore } from '@wordpress/preferences'; * Internal dependencies */ import FullscreenModeClose from './fullscreen-mode-close'; -import HeaderToolbar from './header-toolbar'; import MoreMenu from './more-menu'; import PostPublishButtonOrToggle from './post-publish-button-or-toggle'; import MainDashboardButton from './main-dashboard-button'; import { store as editPostStore } from '../../store'; import { unlock } from '../../lock-unlock'; -const { PostViewLink, PreviewDropdown } = unlock( editorPrivateApis ); +const { DocumentTools, PostViewLink, PreviewDropdown } = + unlock( editorPrivateApis ); const slideY = { hidden: { y: '-50px' }, @@ -60,6 +60,7 @@ function Header( { setEntitiesSavedStatesCallback } ) { const isLargeViewport = useViewportMatch( 'medium' ); const blockToolbarRef = useRef(); const { + isTextEditor, hasBlockSelection, hasActiveMetaboxes, hasFixedToolbar, @@ -68,8 +69,10 @@ function Header( { setEntitiesSavedStatesCallback } ) { showIconLabels, } = useSelect( ( select ) => { const { get: getPreference } = select( preferencesStore ); + const { getEditorMode } = select( editPostStore ); return { + isTextEditor: getEditorMode() === 'text', hasBlockSelection: !! select( blockEditorStore ).getBlockSelectionStart(), hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(), @@ -108,7 +111,10 @@ function Header( { setEntitiesSavedStatesCallback } ) { transition={ { type: 'tween', delay: 0.8 } } className="edit-post-header__toolbar" > - + { hasFixedToolbar && isLargeViewport && ( <>
.edit-post-header__toolbar .edit-post-header-toolbar__inserter-toggle, - & > .edit-post-header__toolbar .edit-post-header-toolbar__document-overview-toggle, + & > .edit-post-header__toolbar .editor-document-tools__inserter-toggle, + & > .edit-post-header__toolbar .editor-document-tools__document-overview-toggle, & > .edit-post-header__settings > .editor-preview-dropdown, & > .edit-post-header__settings > .interface-pinned-items { display: none; diff --git a/packages/edit-post/src/style.scss b/packages/edit-post/src/style.scss index fe03b2f7133735..4ed6875e2c5130 100644 --- a/packages/edit-post/src/style.scss +++ b/packages/edit-post/src/style.scss @@ -1,7 +1,6 @@ @import "../../interface/src/style.scss"; @import "./components/header/style.scss"; @import "./components/header/fullscreen-mode-close/style.scss"; -@import "./components/header/header-toolbar/style.scss"; @import "./components/keyboard-shortcut-help-modal/style.scss"; @import "./components/layout/style.scss"; @import "./components/block-manager/style.scss"; diff --git a/packages/edit-site/src/components/block-editor/use-site-editor-settings.js b/packages/edit-site/src/components/block-editor/use-site-editor-settings.js index 3cd65802b29de5..cbe70cbee83c07 100644 --- a/packages/edit-site/src/components/block-editor/use-site-editor-settings.js +++ b/packages/edit-site/src/components/block-editor/use-site-editor-settings.js @@ -150,6 +150,7 @@ export function useSpecificEditorSettings() { return { ...settings, + richEditingEnabled: true, supportsTemplateMode: true, focusMode: canvasMode === 'view' && focusMode ? false : focusMode, allowRightClickOverrides, diff --git a/packages/edit-site/src/components/header-edit-mode/document-tools/index.js b/packages/edit-site/src/components/header-edit-mode/document-tools/index.js index ec37cadfbc0de0..b09a2cfde618bd 100644 --- a/packages/edit-site/src/components/header-edit-mode/document-tools/index.js +++ b/packages/edit-site/src/components/header-edit-mode/document-tools/index.js @@ -1,34 +1,24 @@ /** * WordPress dependencies */ -import { useCallback, useRef } from '@wordpress/element'; import { useViewportMatch } from '@wordpress/compose'; -import { - ToolSelector, - NavigableToolbar, - store as blockEditorStore, - privateApis as blockEditorPrivateApis, -} from '@wordpress/block-editor'; +import { store as blockEditorStore } from '@wordpress/block-editor'; import { useSelect, useDispatch } from '@wordpress/data'; -import { _x, __ } from '@wordpress/i18n'; -import { listView, plus, chevronUpDown } from '@wordpress/icons'; +import { __ } from '@wordpress/i18n'; +import { chevronUpDown } from '@wordpress/icons'; import { Button, ToolbarItem } from '@wordpress/components'; -import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; -import { store as editorStore } from '@wordpress/editor'; +import { + store as editorStore, + privateApis as editorPrivateApis, +} from '@wordpress/editor'; /** * Internal dependencies */ -import UndoButton from '../undo-redo/undo'; -import RedoButton from '../undo-redo/redo'; import { store as editSiteStore } from '../../../store'; import { unlock } from '../../../lock-unlock'; -const { useCanBlockToolbarBeFocused } = unlock( blockEditorPrivateApis ); - -const preventDefault = ( event ) => { - event.preventDefault(); -}; +const { DocumentTools: EditorDocumentTools } = unlock( editorPrivateApis ); export default function DocumentTools( { blockEditorMode, @@ -36,159 +26,46 @@ export default function DocumentTools( { isDistractionFree, showIconLabels, } ) { - const inserterButton = useRef(); - const { - isInserterOpen, - isListViewOpen, - listViewShortcut, - isVisualMode, - listViewToggleRef, - } = useSelect( ( select ) => { + const { isVisualMode } = useSelect( ( select ) => { const { getEditorMode } = select( editSiteStore ); - const { getShortcutRepresentation } = select( keyboardShortcutsStore ); - const { isInserterOpened, isListViewOpened, getListViewToggleRef } = - unlock( select( editorStore ) ); return { - isInserterOpen: isInserterOpened(), - isListViewOpen: isListViewOpened(), - listViewShortcut: getShortcutRepresentation( - 'core/editor/toggle-list-view' - ), isVisualMode: getEditorMode() === 'visual', - listViewToggleRef: getListViewToggleRef(), }; }, [] ); const { __unstableSetEditorMode } = useDispatch( blockEditorStore ); - const { setDeviceType, setIsInserterOpened, setIsListViewOpened } = - useDispatch( editorStore ); - + const { setDeviceType } = useDispatch( editorStore ); const isLargeViewport = useViewportMatch( 'medium' ); - - const toggleInserter = useCallback( () => { - if ( isInserterOpen ) { - // Focusing the inserter button should close the inserter popover. - // However, there are some cases it won't close when the focus is lost. - // See https://github.com/WordPress/gutenberg/issues/43090 for more details. - inserterButton.current.focus(); - setIsInserterOpened( false ); - } else { - setIsInserterOpened( true ); - } - }, [ isInserterOpen, setIsInserterOpened ] ); - - const toggleListView = useCallback( - () => setIsListViewOpened( ! isListViewOpen ), - [ setIsListViewOpened, isListViewOpen ] - ); - - // If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar. - const blockToolbarCanBeFocused = useCanBlockToolbarBeFocused(); - - /* translators: button label text should, if possible, be under 16 characters. */ - const longLabel = _x( - 'Toggle block inserter', - 'Generic label for block inserter button' - ); - const shortLabel = ! isInserterOpen ? __( 'Add' ) : __( 'Close' ); - const isZoomedOutViewExperimentEnabled = window?.__experimentalEnableZoomedOutView && isVisualMode; const isZoomedOutView = blockEditorMode === 'zoom-out'; return ( - -
- { ! isDistractionFree && ( + { isZoomedOutViewExperimentEnabled && + isLargeViewport && + ! isDistractionFree && + ! hasFixedToolbar && ( { + setDeviceType( 'Desktop' ); + __unstableSetEditorMode( + isZoomedOutView ? 'edit' : 'zoom-out' + ); + } } size="compact" /> ) } - { isLargeViewport && ( - <> - { ! hasFixedToolbar && ( - - ) } - - - { ! isDistractionFree && ( - - ) } - { isZoomedOutViewExperimentEnabled && - ! isDistractionFree && - ! hasFixedToolbar && ( - { - setDeviceType( 'Desktop' ); - __unstableSetEditorMode( - isZoomedOutView - ? 'edit' - : 'zoom-out' - ); - } } - size="compact" - /> - ) } - - ) } -
-
+ ); } diff --git a/packages/edit-site/src/components/header-edit-mode/mode-switcher/index.js b/packages/edit-site/src/components/header-edit-mode/mode-switcher/index.js index f4b63edfae6e80..2c27444f669c03 100644 --- a/packages/edit-site/src/components/header-edit-mode/mode-switcher/index.js +++ b/packages/edit-site/src/components/header-edit-mode/mode-switcher/index.js @@ -33,10 +33,6 @@ function ModeSwitcher() { shortcut: select( keyboardShortcutsStore ).getShortcutRepresentation( 'core/edit-site/toggle-mode' ), - isRichEditingEnabled: - select( editSiteStore ).getSettings().richEditingEnabled, - isCodeEditingEnabled: - select( editSiteStore ).getSettings().codeEditingEnabled, mode: select( editSiteStore ).getEditorMode(), } ), [] diff --git a/packages/edit-site/src/components/header-edit-mode/style.scss b/packages/edit-site/src/components/header-edit-mode/style.scss index cbd0a7422b5364..44b762a667bb7b 100644 --- a/packages/edit-site/src/components/header-edit-mode/style.scss +++ b/packages/edit-site/src/components/header-edit-mode/style.scss @@ -99,49 +99,6 @@ $header-toolbar-min-width: 335px; } } -.edit-site-header-edit-mode__document-tools { - display: flex; - border: none; - - // The Toolbar component adds different styles to buttons, so we reset them - // here to the original button styles - .edit-site-header-edit-mode__toolbar > .components-button.has-icon, - .edit-site-header-edit-mode__toolbar > .components-dropdown > .components-button.has-icon { - // @todo: override toolbar group inherited paddings from components/block-tools/style.scss. - // This is best fixed by making the mover control area a proper single toolbar group. - // It needs specificity due to style inherited from .components-accessible-toolbar .components-button.has-icon.has-icon. - height: $button-size-compact; - min-width: $button-size-compact; - padding: 4px; - - &.is-pressed { - background: $gray-900; - } - - &:focus:not(:disabled) { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color), inset 0 0 0 $border-width $white; - outline: $border-width solid transparent; - } - - &::before { - display: none; - } - } - - .edit-site-header-edit-mode__toolbar > .edit-site-header-edit-mode__inserter-toggle.has-icon { - // Special dimensions for this button. - min-width: $button-size-compact; - width: $button-size-compact; - height: $button-size-compact; - padding: 0; - } - - .edit-site-header-edit-mode__toolbar > .edit-site-header-edit-mode__inserter-toggle.has-text.has-icon { - width: auto; - padding: 0 $grid-unit-10; - } -} - // Button text label styles .edit-site-header-edit-mode.show-icon-labels { @@ -185,10 +142,6 @@ $header-toolbar-min-width: 335px; padding: 0 $grid-unit-10; } - .edit-site-header-edit-mode__document-tools .edit-site-header-edit-mode__toolbar > * + * { - margin-left: $grid-unit-10; - } - .block-editor-block-mover { border-left: none; diff --git a/packages/edit-site/src/components/header-edit-mode/undo-redo/redo.js b/packages/edit-site/src/components/header-edit-mode/undo-redo/redo.js deleted file mode 100644 index 17d0ecb892d0a5..00000000000000 --- a/packages/edit-site/src/components/header-edit-mode/undo-redo/redo.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * WordPress dependencies - */ -import { __, isRTL } from '@wordpress/i18n'; -import { Button } from '@wordpress/components'; -import { useSelect, useDispatch } from '@wordpress/data'; -import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons'; -import { displayShortcut, isAppleOS } from '@wordpress/keycodes'; -import { store as coreStore } from '@wordpress/core-data'; -import { forwardRef } from '@wordpress/element'; - -function RedoButton( props, ref ) { - const shortcut = isAppleOS() - ? displayShortcut.primaryShift( 'z' ) - : displayShortcut.primary( 'y' ); - - const hasRedo = useSelect( - ( select ) => select( coreStore ).hasRedo(), - [] - ); - const { redo } = useDispatch( coreStore ); - return ( -