Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distraction free to site editor #51173

Merged
merged 20 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
be8baa7
adds preference setter in UI
draganescu Jun 1, 2023
65bc029
Fix distraction free toolbar showing
Jun 1, 2023
e3e2299
fix distraction free flag in site editor, revert change in block tool…
draganescu Jun 2, 2023
c983dc9
basic distraction free enabled
draganescu Jun 2, 2023
7969e92
hide header items in distraction free
draganescu Jun 2, 2023
94763dc
fix the JS test for settings
draganescu Jun 15, 2023
f468154
fix the other test for editor settings
draganescu Jun 18, 2023
071bd81
remove the rerendering of the site editor header to maintain focus on…
draganescu Jun 20, 2023
b172b79
animated hader in edit mode for distraction free
draganescu Jun 20, 2023
ea5e647
fix sidebar header
draganescu Jun 21, 2023
edb7eb2
move static objects out of components
draganescu Jun 21, 2023
9171bf7
Refactor distractionFree site editor animations
jeryj Jun 22, 2023
e2db911
Remove invalid animation values for initial and exit
jeryj Jun 22, 2023
61ed821
Fix bug where edit-mode__actions would get stuck in isDistractionFree…
jeryj Jun 22, 2023
a786941
Override animation with !important CSS when focus is within header on…
jeryj Jun 22, 2023
c31b454
Adjust animation exit delay for header so the header remains visible …
jeryj Jun 22, 2023
eedf542
remove hardcoded z-index
draganescu Jun 23, 2023
3cdec4d
turn off distraction free mode when opening the styles sidebar from s…
draganescu Jun 23, 2023
7236c95
add distraction free mode to preferences panel in the site editor
draganescu Jun 23, 2023
ed86a44
Adds the distraction free mode keyboard shortcut
draganescu Jun 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading