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

Site Editor: Styles: preview template to put focus on styles #67001

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export default function BlockEdit( {
]
) }
>
<Edit { ...props } />
<Edit
{ ...{
...props,
isSelected: isPreviewMode ? false : isSelected,
} }
/>
{ originalBlockClientId && (
<MultipleUsageWarning
originalBlockClientId={ originalBlockClientId }
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ function BlockListBlockProvider( props ) {
const blockType = getBlockType( blockName );
const { supportsLayout, isPreviewMode } = getSettings();
const hasLightBlockWrapper = blockType?.apiVersion > 1;
const _isSelected = isBlockSelected( clientId );
const previewContext = {
isPreviewMode,
blockWithoutAttributes,
Expand All @@ -627,6 +628,7 @@ function BlockListBlockProvider( props ) {
? getBlockDefaultClassName( blockName )
: undefined,
blockTitle: blockType?.title,
isSelected: _isSelected,
};

// When in preview mode, we can avoid a lot of selection and
Expand All @@ -635,7 +637,6 @@ function BlockListBlockProvider( props ) {
return previewContext;
}

const _isSelected = isBlockSelected( clientId );
const canRemove = canRemoveBlock( clientId );
const canMove = canMoveBlock( clientId );
const match = getActiveBlockVariation( blockName, attributes );
Expand Down Expand Up @@ -666,7 +667,6 @@ function BlockListBlockProvider( props ) {
isSectionBlock: _isSectionBlock( clientId ),
canRemove,
canMove,
isSelected: _isSelected,
isTemporarilyEditingAsBlocks:
getTemporarilyEditingAsBlocks() === clientId,
blockEditingMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { unlock } from '../../lock-unlock';

export function useInBetweenInserter() {
const openRef = useContext( InsertionPointOpenRef );
const isInBetweenInserterDisabled = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().isDistractionFree ||
unlock( select( blockEditorStore ) ).isZoomOut(),
[]
);
const isInBetweenInserterDisabled = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
return (
settings.isDistractionFree ||
settings.isPreviewMode ||
unlock( select( blockEditorStore ) ).isZoomOut()
);
}, [] );
const {
getBlockListSettings,
getBlockIndex,
Expand Down
17 changes: 14 additions & 3 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ export default function BlockTools( {
expandBlock,
} = unlock( useDispatch( blockEditorStore ) );

const ref = useRef( false );
const blockToolbarRef = usePopoverScroll( __unstableContentRef );
const blockToolbarAfterRef = usePopoverScroll( __unstableContentRef );

const isPreviewMode = useSelect(
( select ) => select( blockEditorStore ).getSettings().isPreviewMode,
[]
);

if ( isPreviewMode ) {
return children;
}

function onKeyDown( event ) {
if ( event.defaultPrevented ) {
return;
Expand Down Expand Up @@ -193,13 +206,11 @@ export default function BlockTools( {
}
}
}
const blockToolbarRef = usePopoverScroll( __unstableContentRef );
const blockToolbarAfterRef = usePopoverScroll( __unstableContentRef );

return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div { ...props } onKeyDown={ onKeyDown }>
<InsertionPointOpenRef.Provider value={ useRef( false ) }>
<InsertionPointOpenRef.Provider value={ ref }>
{ ! isTyping && ! isZoomOutMode && (
<InsertionPoint
__unstableContentRef={ __unstableContentRef }
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ const PublicForwardedRichTextContainer = forwardRef( ( props, ref ) => {
} = removeNativeProps( props );
return (
<Tag
ref={ ref }
{ ...contentProps }
dangerouslySetInnerHTML={ {
__html: valueToHTMLString( value, multiline ),
Expand Down
16 changes: 14 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const siteIconVariants = {
export default function EditSiteEditor( { isPostsList = false } ) {
const disableMotion = useReducedMotion();
const { params } = useLocation();
const { canvas = 'view' } = params;
const { canvas = 'view', path } = params;
const isLoading = useIsSiteEditorLoading();
useAdaptEditorToCanvas( canvas );
const entity = useResolveEditedEntity();
Expand Down Expand Up @@ -209,6 +209,17 @@ export default function EditSiteEditor( { isPostsList = false } ) {
duration: disableMotion ? 0 : 0.2,
};

const isGlobalStylesPreview = path === '/wp_global_styles';

const _settings = useMemo( () => {
return {
...settings,
isPreviewMode: isGlobalStylesPreview
? true
: settings.isPreviewMode,
};
}, [ settings, isGlobalStylesPreview ] );

return (
<>
<GlobalStylesRenderer
Expand All @@ -227,7 +238,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
postType={ postWithTemplate ? context.postType : postType }
postId={ postWithTemplate ? context.postId : postId }
templateId={ postWithTemplate ? postId : undefined }
settings={ settings }
settings={ _settings }
className={ clsx( 'edit-site-editor__editor-interface', {
'show-icon-labels': showIconLabels,
} ) }
Expand All @@ -237,6 +248,7 @@ export default function EditSiteEditor( { isPostsList = false } ) {
}
customSavePanel={ _isPreviewingTheme && <SavePanel /> }
forceDisableBlockTools={ ! hasDefaultEditorCanvasView }
showEditorFrame={ canvas === 'edit' }
title={ title }
iframeProps={ iframeProps }
onActionPerformed={ onActionPerformed }
Expand Down
12 changes: 8 additions & 4 deletions packages/editor/src/components/document-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import { store as editorStore } from '../../store';
import EditorHistoryRedo from '../editor-history/redo';
import EditorHistoryUndo from '../editor-history/undo';

function DocumentTools( { className, disableBlockTools = false } ) {
function DocumentTools( {
className,
disableBlockTools = false,
isPreviewMode,
} ) {
const { setIsInserterOpened, setIsListViewOpened } =
useDispatch( editorStore );
const {
Expand Down Expand Up @@ -116,7 +120,7 @@ function DocumentTools( { className, disableBlockTools = false } ) {
variant="unstyled"
>
<div className="editor-document-tools__left">
{ ! isDistractionFree && (
{ ! isDistractionFree && ! isPreviewMode && (
<ToolbarItem
ref={ inserterSidebarToggleRef }
as={ Button }
Expand All @@ -134,7 +138,7 @@ function DocumentTools( { className, disableBlockTools = false } ) {
) }
{ ( isWideViewport || ! showIconLabels ) && (
<>
{ showTools && isLargeViewport && (
{ showTools && isLargeViewport && ! isPreviewMode && (
<ToolbarItem
as={ ToolSelector }
showTooltip={ ! showIconLabels }
Expand All @@ -157,7 +161,7 @@ function DocumentTools( { className, disableBlockTools = false } ) {
variant={ showIconLabels ? 'tertiary' : undefined }
size="compact"
/>
{ ! isDistractionFree && (
{ ! isDistractionFree && ! isPreviewMode && (
<ToolbarItem
as={ Button }
className="editor-document-tools__document-overview-toggle"
Expand Down
14 changes: 8 additions & 6 deletions packages/editor/src/components/editor-interface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function EditorInterface( {
forceDisableBlockTools,
title,
iframeProps,
showEditorFrame,
} ) {
const {
mode,
Expand Down Expand Up @@ -110,6 +111,8 @@ export default function EditorInterface( {
[ entitiesSavedStatesCallback ]
);

const showFrame = ! isPreviewMode || showEditorFrame;

return (
<InterfaceSkeleton
isDistractionFree={ isDistractionFree }
Expand All @@ -122,34 +125,33 @@ export default function EditorInterface( {
secondarySidebar: secondarySidebarLabel,
} }
header={
! isPreviewMode && (
showFrame && (
<Header
forceIsDirty={ forceIsDirty }
setEntitiesSavedStatesCallback={
setEntitiesSavedStatesCallback
}
customSaveButton={ customSaveButton }
forceDisableBlockTools={ forceDisableBlockTools }
isPreviewMode={ isPreviewMode }
title={ title }
/>
)
}
editorNotices={ <EditorNotices /> }
secondarySidebar={
! isPreviewMode &&
showFrame &&
mode === 'visual' &&
( ( isInserterOpened && <InserterSidebar /> ) ||
( isListViewOpened && <ListViewSidebar /> ) )
}
sidebar={
! isPreviewMode &&
showFrame &&
! isDistractionFree && <ComplementaryArea.Slot scope="core" />
}
content={
<>
{ ! isDistractionFree && ! isPreviewMode && (
<EditorNotices />
) }
{ ! isDistractionFree && showFrame && <EditorNotices /> }

<EditorContentSlotFill.Slot>
{ ( [ editorCanvasView ] ) =>
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Header( {
forceDisableBlockTools,
setEntitiesSavedStatesCallback,
title,
isPreviewMode,
} ) {
const isWideViewport = useViewportMatch( 'large' );
const isLargeViewport = useViewportMatch( 'medium' );
Expand Down Expand Up @@ -122,6 +123,7 @@ function Header( {
>
<DocumentTools
disableBlockTools={ forceDisableBlockTools || isTextEditor }
isPreviewMode={ isPreviewMode }
/>
{ hasFixedToolbar && isLargeViewport && (
<CollapsibleBlockToolbar
Expand Down
20 changes: 11 additions & 9 deletions packages/editor/src/components/sidebar/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { sidebars } from './constants';

const { Tabs } = unlock( componentsPrivateApis );

const SidebarHeader = ( _, ref ) => {
const SidebarHeader = ( { isPreviewMode }, ref ) => {
const { documentLabel } = useSelect( ( select ) => {
const { getPostTypeLabel } = select( editorStore );

Expand All @@ -35,14 +35,16 @@ const SidebarHeader = ( _, ref ) => {
>
{ documentLabel }
</Tabs.Tab>
<Tabs.Tab
tabId={ sidebars.block }
// Used for focus management in the SettingsSidebar component.
data-tab-id={ sidebars.block }
>
{ /* translators: Text label for the Block Settings Sidebar tab. */ }
{ __( 'Block' ) }
</Tabs.Tab>
{ ! isPreviewMode && (
<Tabs.Tab
tabId={ sidebars.block }
// Used for focus management in the SettingsSidebar component.
data-tab-id={ sidebars.block }
>
{ /* translators: Text label for the Block Settings Sidebar tab. */ }
{ __( 'Block' ) }
</Tabs.Tab>
) }
</Tabs.TabList>
);
};
Expand Down
22 changes: 16 additions & 6 deletions packages/editor/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const SidebarContent = ( {
keyboardShortcut,
onActionPerformed,
extraPanels,
isPreviewMode,
} ) => {
const tabListRef = useRef( null );
// Because `PluginSidebar` renders a `ComplementaryArea`, we
Expand Down Expand Up @@ -92,7 +93,10 @@ const SidebarContent = ( {
identifier={ tabName }
header={
<Tabs.Context.Provider value={ tabsContextValue }>
<SidebarHeader ref={ tabListRef } />
<SidebarHeader
ref={ tabListRef }
isPreviewMode={ isPreviewMode }
/>
</Tabs.Context.Provider>
}
closeLabel={ __( 'Close Settings' ) }
Expand Down Expand Up @@ -120,17 +124,19 @@ const SidebarContent = ( {
<PatternOverridesPanel />
{ extraPanels }
</Tabs.TabPanel>
<Tabs.TabPanel tabId={ sidebars.block } focusable={ false }>
<BlockInspector />
</Tabs.TabPanel>
{ ! isPreviewMode && (
<Tabs.TabPanel tabId={ sidebars.block } focusable={ false }>
<BlockInspector />
</Tabs.TabPanel>
) }
</Tabs.Context.Provider>
</PluginSidebar>
);
};

const Sidebar = ( { extraPanels, onActionPerformed } ) => {
useAutoSwitchEditorSidebars();
const { tabName, keyboardShortcut, showSummary } = useSelect(
const { tabName, keyboardShortcut, showSummary, isPreviewMode } = useSelect(
( select ) => {
const shortcut = select(
keyboardShortcutsStore
Expand All @@ -151,14 +157,17 @@ const Sidebar = ( { extraPanels, onActionPerformed } ) => {
: sidebars.document;
}

const { getEditorSettings, getCurrentPostType } =
select( editorStore );
return {
tabName: _tabName,
keyboardShortcut: shortcut,
showSummary: ! [
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
NAVIGATION_POST_TYPE,
].includes( select( editorStore ).getCurrentPostType() ),
].includes( getCurrentPostType() ),
isPreviewMode: getEditorSettings().isPreviewMode,
};
},
[]
Expand Down Expand Up @@ -187,6 +196,7 @@ const Sidebar = ( { extraPanels, onActionPerformed } ) => {
showSummary={ showSummary }
onActionPerformed={ onActionPerformed }
extraPanels={ extraPanels }
isPreviewMode={ isPreviewMode }
/>
</Tabs>
);
Expand Down
Loading