Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function useResizeCanvas( deviceType ) {
const [ actualWidth, updateActualWidth ] = useState( window.innerWidth );

useEffect( () => {
if ( deviceType === 'Desktop' ) {
if ( deviceType === 'Desktop' || deviceType === 'Responsive' ) {
return;
}

Expand Down Expand Up @@ -49,6 +49,8 @@ export default function useResizeCanvas( deviceType ) {
const marginHorizontal = 'auto';

switch ( device ) {
case 'Responsive':
return {};
case 'Tablet':
case 'Mobile':
return {
Expand Down
14 changes: 1 addition & 13 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ import PostViewLink from '../post-view-link';
import PreviewDropdown from '../preview-dropdown';
import ZoomOutToggle from '../zoom-out-toggle';
import { store as editorStore } from '../../store';
import {
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
NAVIGATION_POST_TYPE,
} from '../../store/constants';
import { unlock } from '../../lock-unlock';

const toolbarVariations = {
Expand Down Expand Up @@ -96,13 +91,6 @@ function Header( {
[ 'post', 'page', 'wp_template' ].includes( postType ) &&
hasSectionRootClientId;

const disablePreviewOption =
[
NAVIGATION_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
].includes( postType ) || isStylesCanvasActive;

const [ isBlockToolsCollapsed, setIsBlockToolsCollapsed ] =
useState( true );

Expand Down Expand Up @@ -172,7 +160,7 @@ function Header( {

<PreviewDropdown
forceIsAutosaveable={ forceIsDirty }
disabled={ disablePreviewOption }
disabled={ isStylesCanvasActive }
/>

<PostPreviewButton
Expand Down
15 changes: 14 additions & 1 deletion packages/editor/src/components/preview-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import {
Icon,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { desktop, mobile, tablet, external, check } from '@wordpress/icons';
import {
desktop,
mobile,
tablet,
external,
check,
fullscreen,
} from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -93,6 +100,7 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
desktop,
mobile,
tablet,
responsive: fullscreen,
};

/**
Expand All @@ -116,6 +124,11 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
label: __( 'Mobile' ),
icon: mobile,
},
{
value: 'Responsive',
label: __( 'Responsive' ),
icon: fullscreen,
},
];

return (
Expand Down
9 changes: 1 addition & 8 deletions packages/editor/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import EditTemplateBlocksNotification from './edit-template-blocks-notification'
import ResizableEditor from '../resizable-editor';
import useSelectNearestEditableBlock from './use-select-nearest-editable-block';
import {
NAVIGATION_POST_TYPE,
PATTERN_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
TEMPLATE_POST_TYPE,
DESIGN_POST_TYPES,
} from '../../store/constants';
Expand Down Expand Up @@ -108,7 +106,6 @@ function VisualEditor( {
deviceType,
isFocusedEntity,
isDesignPostType,
postType,
isPreview,
styles,
canvasMinHeight,
Expand Down Expand Up @@ -321,11 +318,7 @@ function VisualEditor( {
.is-root-container.alignfull:where(.is-layout-flow) > :not(.alignleft):not(.alignright) { max-width: none;}`;

const enableResizing =
[
NAVIGATION_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
].includes( postType ) &&
deviceType === 'Responsive' &&
// Disable in previews / view mode.
! isPreview &&
// Disable resizing in mobile viewport.
Expand Down
16 changes: 16 additions & 0 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { combineReducers } from '@wordpress/data';
*/
import { EDITOR_SETTINGS_DEFAULTS } from './defaults';
import dataviewsReducer from '../dataviews/store/reducer';
import {
PATTERN_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
NAVIGATION_POST_TYPE,
} from './constants';

/**
* Returns a post attribute value, flattening nested rendered content using its
Expand Down Expand Up @@ -288,6 +293,17 @@ export function deviceType( state = 'Desktop', action ) {
switch ( action.type ) {
case 'SET_DEVICE_TYPE':
return action.deviceType;
case 'SET_EDITED_POST':
if (
[
PATTERN_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
NAVIGATION_POST_TYPE,
].includes( action.postType )
) {
return 'Responsive';
}
return 'Desktop';
}

return state;
Expand Down
Loading