Skip to content

Commit

Permalink
Add distraction free to site editor (WordPress#51173)
Browse files Browse the repository at this point in the history
* adds preference setter in UI

* Fix distraction free toolbar showing

The store has the variable `distractionFree`, but `isDistractionFree` was incorrectly being used.

* fix distraction free flag in site editor, revert change in block toolbar hook

* basic distraction free enabled

* hide header items in distraction free

* fix the JS test for settings

* fix the other test for editor settings

* remove the rerendering of the site editor header to maintain focus on the writing options menu item

* animated hader in edit mode for distraction free

* fix sidebar header

* move static objects out of components

* Refactor distractionFree site editor animations

All animations are now triggered by the edit-site-layout__header-container which has an animationState determined by the view and isDistractionFree mode. It also currently sets a isDistractionFreeHovering animation when hovering that element. This will likely need to change to be able to keep the distraction free header visible when one of the header popovers is open.

* Remove invalid animation values for initial and exit

* Fix bug where edit-mode__actions would get stuck in isDistractionFreeState

The actions would get stuck in the isDistractionFree state when:
- loading the page in the editor view with distraction free on
- turn off distraction free
- action stuck above the frame

Why? Because the initial state of that component was -50px on page load, so that's what it would transition to when isDistractionFree was turned off. To fix this, we needed to either set an initial state of x: 0 so it can transition to that property, OR assign values for the other states like view or edit so it has a place to transition to.

* Override animation with !important CSS when focus is within header on distraction-free mode

* Adjust animation exit delay for header so the header remains visible longer when hovering out.

* remove hardcoded z-index

* turn off distraction free mode when opening the styles sidebar from site view

* add distraction free mode to preferences panel in the site editor

* Adds the distraction free mode keyboard shortcut

---------

Co-authored-by: Alex Lende <[email protected]>
Co-authored-by: Jerry Jones <[email protected]>
  • Loading branch information
3 people authored and sethrubenstein committed Jul 13, 2023
1 parent 6b923a3 commit 2183b1a
Show file tree
Hide file tree
Showing 21 changed files with 429 additions and 131 deletions.
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ $z-layers: (
".customize-widgets__block-toolbar": 7,

// Site editor layout
".edit-site-layout__header-container": 4,
".edit-site-layout__hub": 3,
".edit-site-layout__header": 2,
".edit-site-page-header": 2,
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ _Properties_
- _maxWidth_ `number`: Max width to constraint resizing
- _allowedBlockTypes_ `boolean|Array`: Allowed block types
- _hasFixedToolbar_ `boolean`: Whether or not the editor toolbar is fixed
- _distractionFree_ `boolean`: Whether or not the editor UI is distraction free
- _focusMode_ `boolean`: Whether the focus mode is enabled or not
- _styles_ `Array`: Editor Styles
- _keepCaretInsideBlock_ `boolean`: Whether caret should move between blocks in edit mode
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const PREFERENCES_DEFAULTS = {
* @property {number} maxWidth Max width to constraint resizing
* @property {boolean|Array} allowedBlockTypes Allowed block types
* @property {boolean} hasFixedToolbar Whether or not the editor toolbar is fixed
* @property {boolean} distractionFree Whether or not the editor UI is distraction free
* @property {boolean} focusMode Whether the focus mode is enabled or not
* @property {Array} styles Editor Styles
* @property {boolean} keepCaretInsideBlock Whether caret should move between blocks in edit mode
Expand Down
20 changes: 10 additions & 10 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ import MainDashboardButton from './main-dashboard-button';
import { store as editPostStore } from '../../store';
import DocumentTitle from './document-title';

const slideY = {
hidden: { y: '-50px' },
hover: { y: 0, transition: { type: 'tween', delay: 0.2 } },
};

const slideX = {
hidden: { x: '-100%' },
hover: { x: 0, transition: { type: 'tween', delay: 0.2 } },
};

function Header( { setEntitiesSavedStatesCallback } ) {
const isLargeViewport = useViewportMatch( 'large' );
const {
Expand All @@ -39,16 +49,6 @@ function Header( { setEntitiesSavedStatesCallback } ) {
[]
);

const slideY = {
hidden: { y: '-50px' },
hover: { y: 0, transition: { type: 'tween', delay: 0.2 } },
};

const slideX = {
hidden: { x: '-100%' },
hover: { x: 0, transition: { type: 'tween', delay: 0.2 } },
};

return (
<div className="edit-post-header">
<MainDashboardButton.Slot>
Expand Down
2 changes: 0 additions & 2 deletions packages/edit-post/src/components/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ function KeyboardShortcuts() {
} );

useShortcut( 'core/edit-post/toggle-distraction-free', () => {
closeGeneralSidebar();
setIsListViewOpened( false );
toggleDistractionFree();
toggleFeature( 'distractionFree' );
createInfoNotice(
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export default function Editor( { isLoading } ) {
<SidebarComplementaryAreaFills />
{ isEditMode && <StartTemplateOptions /> }
<InterfaceSkeleton
isDistractionFree={ true }
enableRegionNavigation={ false }
className={ classnames(
'edit-site-editor__interface-skeleton',
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-site/src/components/editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
&.is-loading {
opacity: 0;
}

.interface-interface-skeleton__header {
border: 0;
}
}

.edit-site-editor__toggle-save-panel {
Expand Down
150 changes: 96 additions & 54 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { useCallback, useRef } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import { useViewportMatch, useReducedMotion } from '@wordpress/compose';
import { store as coreStore } from '@wordpress/core-data';
import {
ToolSelector,
Expand All @@ -21,6 +21,7 @@ import { PinnedItems } from '@wordpress/interface';
import { _x, __ } from '@wordpress/i18n';
import { listView, plus, external, chevronUpDown } from '@wordpress/icons';
import {
__unstableMotion as motion,
Button,
ToolbarItem,
MenuGroup,
Expand Down Expand Up @@ -60,6 +61,7 @@ export default function HeaderEditMode() {
isListViewOpen,
listViewShortcut,
isVisualMode,
isDistractionFree,
blockEditorMode,
homeUrl,
showIconLabels,
Expand Down Expand Up @@ -99,6 +101,10 @@ export default function HeaderEditMode() {
editorCanvasView: unlock(
select( editSiteStore )
).getEditorCanvasContainerView(),
isDistractionFree: select( preferencesStore ).get(
'core/edit-site',
'distractionFree'
),
};
}, [] );

Expand All @@ -108,6 +114,7 @@ export default function HeaderEditMode() {
setIsListViewOpened,
} = useDispatch( editSiteStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );
const disableMotion = useReducedMotion();

const isLargeViewport = useViewportMatch( 'medium' );

Expand Down Expand Up @@ -156,6 +163,19 @@ export default function HeaderEditMode() {
window?.__experimentalEnableZoomedOutView && isVisualMode;
const isZoomedOutView = blockEditorMode === 'zoom-out';

const toolbarVariants = {
isDistractionFree: { y: '-50px' },
isDistractionFreeHovering: { y: 0 },
view: { y: 0 },
edit: { y: 0 },
};

const toolbarTransition = {
type: 'tween',
duration: disableMotion ? 0 : 0.2,
ease: 'easeOut',
};

return (
<div
className={ classnames( 'edit-site-header-edit-mode', {
Expand All @@ -164,26 +184,33 @@ export default function HeaderEditMode() {
>
{ hasDefaultEditorCanvasView && (
<NavigableToolbar
as={ motion.div }
className="edit-site-header-edit-mode__start"
aria-label={ __( 'Document tools' ) }
shouldUseKeyboardFocusShortcut={
! blockToolbarCanBeFocused
}
variants={ toolbarVariants }
transition={ toolbarTransition }
>
<div className="edit-site-header-edit-mode__toolbar">
<ToolbarItem
ref={ inserterButton }
as={ Button }
className="edit-site-header-edit-mode__inserter-toggle"
variant="primary"
isPressed={ isInserterOpen }
onMouseDown={ preventDefault }
onClick={ toggleInserter }
disabled={ ! isVisualMode }
icon={ plus }
label={ showIconLabels ? shortLabel : longLabel }
showTooltip={ ! showIconLabels }
/>
{ ! isDistractionFree && (
<ToolbarItem
ref={ inserterButton }
as={ Button }
className="edit-site-header-edit-mode__inserter-toggle"
variant="primary"
isPressed={ isInserterOpen }
onMouseDown={ preventDefault }
onClick={ toggleInserter }
disabled={ ! isVisualMode }
icon={ plus }
label={
showIconLabels ? shortLabel : longLabel
}
showTooltip={ ! showIconLabels }
/>
) }
{ isLargeViewport && (
<>
<ToolbarItem
Expand All @@ -208,57 +235,70 @@ export default function HeaderEditMode() {
showIconLabels ? 'tertiary' : undefined
}
/>
<ToolbarItem
as={ Button }
className="edit-site-header-edit-mode__list-view-toggle"
disabled={
! isVisualMode || isZoomedOutView
}
icon={ listView }
isPressed={ isListViewOpen }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'List View' ) }
onClick={ toggleListView }
shortcut={ listViewShortcut }
showTooltip={ ! showIconLabels }
variant={
showIconLabels ? 'tertiary' : undefined
}
/>
{ isZoomedOutViewExperimentEnabled && (
{ ! isDistractionFree && (
<ToolbarItem
as={ Button }
className="edit-site-header-edit-mode__zoom-out-view-toggle"
icon={ chevronUpDown }
isPressed={ isZoomedOutView }
className="edit-site-header-edit-mode__list-view-toggle"
disabled={
! isVisualMode || isZoomedOutView
}
icon={ listView }
isPressed={ isListViewOpen }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Zoom-out View' ) }
onClick={ () => {
setPreviewDeviceType( 'desktop' );
__unstableSetEditorMode(
isZoomedOutView
? 'edit'
: 'zoom-out'
);
} }
label={ __( 'List View' ) }
onClick={ toggleListView }
shortcut={ listViewShortcut }
showTooltip={ ! showIconLabels }
variant={
showIconLabels
? 'tertiary'
: undefined
}
/>
) }
{ isZoomedOutViewExperimentEnabled &&
! isDistractionFree && (
<ToolbarItem
as={ Button }
className="edit-site-header-edit-mode__zoom-out-view-toggle"
icon={ chevronUpDown }
isPressed={ isZoomedOutView }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Zoom-out View' ) }
onClick={ () => {
setPreviewDeviceType(
'desktop'
);
__unstableSetEditorMode(
isZoomedOutView
? 'edit'
: 'zoom-out'
);
} }
/>
) }
</>
) }
</div>
</NavigableToolbar>
) }

<div className="edit-site-header-edit-mode__center">
{ ! hasDefaultEditorCanvasView ? (
getEditorCanvasContainerTitle( editorCanvasView )
) : (
<DocumentActions />
) }
</div>
{ ! isDistractionFree && (
<div className="edit-site-header-edit-mode__center">
{ ! hasDefaultEditorCanvasView ? (
getEditorCanvasContainerTitle( editorCanvasView )
) : (
<DocumentActions />
) }
</div>
) }

<div className="edit-site-header-edit-mode__end">
<div className="edit-site-header-edit-mode__actions">
<motion.div
className="edit-site-header-edit-mode__actions"
variants={ toolbarVariants }
transition={ toolbarTransition }
>
{ ! isFocusMode && hasDefaultEditorCanvasView && (
<div
className={ classnames(
Expand Down Expand Up @@ -290,9 +330,11 @@ export default function HeaderEditMode() {
</div>
) }
<SaveButton />
<PinnedItems.Slot scope="core/edit-site" />
{ ! isDistractionFree && (
<PinnedItems.Slot scope="core/edit-site" />
) }
<MoreMenu showIconLabels={ showIconLabels } />
</div>
</motion.div>
</div>
</div>
);
Expand Down
Loading

0 comments on commit 2183b1a

Please sign in to comment.