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

Remove template-only mode from editor and edit-post packages #57700

Merged
merged 31 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f3bfce7
Resolve style conflict
glendaviesnz Jan 22, 2024
f35bc22
Remove use of `template-only` from post editor
glendaviesnz Jan 22, 2024
894ad66
Remove some of the editor package template-only references
glendaviesnz Jan 9, 2024
4fd7939
Remove remaining instances of template-only in editor package
glendaviesnz Jan 9, 2024
140f10a
Put back some template checks as probably not relevant to pattern edi…
glendaviesnz Jan 22, 2024
e6fb7a2
remove test code
glendaviesnz Jan 9, 2024
27caa0b
Remove template-only from site editor
glendaviesnz Jan 10, 2024
6294d72
Get the new template id when creating a template in site editor
glendaviesnz Jan 10, 2024
3dc8b2a
Fix broken string
glendaviesnz Jan 10, 2024
dcd6f0b
Fix breadcrumb label
glendaviesnz Jan 10, 2024
cce8dec
Remove unused class
glendaviesnz Jan 10, 2024
6f381ae
remove hasHistory checks from header bar
glendaviesnz Jan 22, 2024
d2a572b
Use the router in the site editor instead of getPostLinkProps
glendaviesnz Jan 10, 2024
36a6100
Set the default rendering mode in the post editor
glendaviesnz Jan 22, 2024
db8b1dc
Enable the code editor mode option for template mode in the post editor
talldan Jan 16, 2024
116c392
Remove randomly added dependency
talldan Jan 16, 2024
eca8305
Use post type label for document tab title
talldan Jan 16, 2024
0819e6b
Show the editor padding whenever a goBack is set
talldan Jan 16, 2024
ef5539a
Add the goBack link back into the edit template modal
glendaviesnz Jan 22, 2024
cd0d7b9
Return getEditorSettings from useSelect instead of goBack as goBack n…
glendaviesnz Jan 22, 2024
73ede7f
Add goBack link back for classic themes
glendaviesnz Jan 22, 2024
78b9d2d
Fix editor padding
glendaviesnz Jan 22, 2024
dbf7abc
Remove uncalled branch
glendaviesnz Jan 22, 2024
a749611
Fix issue with page content not showing in site editor page editor
glendaviesnz Jan 23, 2024
d6bebab
Get the back options working in the site editor
glendaviesnz Jan 23, 2024
79bb9ea
Remove `wp_template` check that isn't needed now.
glendaviesnz Jan 23, 2024
02201cb
Fix e2e tests
glendaviesnz Jan 23, 2024
016058f
Disable autosaving of templates in post editor
glendaviesnz Jan 23, 2024
a613541
Code tidy ups
glendaviesnz Jan 24, 2024
a04ff70
Pull the setting of the canvas mode back into the site editor
glendaviesnz Jan 24, 2024
c1a902f
Remove another reference to canvas: edit
glendaviesnz Jan 24, 2024
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
3 changes: 1 addition & 2 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1404,13 +1404,12 @@ _Returns_
Returns an action used to set the rendering mode of the post editor. We support multiple rendering modes:

- `all`: This is the default mode. It renders the post editor with all the features available. If a template is provided, it's preferred over the post.
- `template-only`: This mode renders the editor with only the template blocks visible.
- `post-only`: This mode extracts the post blocks from the template and renders only those. The idea is to allow the user to edit the post/page in isolation without the wrapping template.
- `template-locked`: This mode renders both the template and the post blocks but the template blocks are locked and can't be edited. The post blocks are editable.

_Parameters_

- _mode_ `string`: Mode (one of 'template-only', 'post-only', 'template-locked' or 'all').
- _mode_ `string`: Mode (one of 'post-only', 'template-locked' or 'all').

### setTemplateValidity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ iframe[name="editor-canvas"] {
display: block;
}

iframe[name="editor-canvas"]:not(.has-history) {
iframe[name="editor-canvas"]:not(.has-editor-padding) {
background-color: $white;
}

iframe[name="editor-canvas"].has-history {
iframe[name="editor-canvas"].has-editor-padding {
padding: $grid-unit-60 $grid-unit-60 0;
}
1 change: 0 additions & 1 deletion packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export default function ReusableBlockEdit( {
? getPostLinkProps( {
postId: ref,
postType: 'wp_block',
canvas: 'edit',
} )
: {};

Expand Down
7 changes: 2 additions & 5 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function Header( { setEntitiesSavedStatesCallback } ) {
hasBlockSelection,
hasActiveMetaboxes,
hasFixedToolbar,
isEditingTemplate,
isPublishSidebarOpened,
showIconLabels,
hasHistory,
Expand All @@ -78,8 +77,6 @@ function Header( { setEntitiesSavedStatesCallback } ) {
!! select( blockEditorStore ).getBlockSelectionStart(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
hasHistory: !! select( editorStore ).getEditorSettings().goBack,
isEditingTemplate:
select( editorStore ).getRenderingMode() === 'template-only',
talldan marked this conversation as resolved.
Show resolved Hide resolved
isPublishSidebarOpened:
select( editPostStore ).isPublishSidebarOpened(),
hasFixedToolbar: getPreference( 'core', 'fixedToolbar' ),
Expand Down Expand Up @@ -150,14 +147,14 @@ function Header( { setEntitiesSavedStatesCallback } ) {
<div
className={ classnames( 'edit-post-header__center', {
'is-collapsed':
isEditingTemplate &&
hasHistory &&
hasBlockSelection &&
! isBlockToolsCollapsed &&
hasFixedToolbar &&
isLargeViewport,
} ) }
>
{ ( isEditingTemplate || hasHistory ) && <DocumentBar /> }
{ hasHistory && <DocumentBar /> }
</div>
</motion.div>
<motion.div
Expand Down
41 changes: 16 additions & 25 deletions packages/edit-post/src/components/header/mode-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,24 @@ const MODES = [
];

function ModeSwitcher() {
const {
shortcut,
isRichEditingEnabled,
isCodeEditingEnabled,
isEditingTemplate,
mode,
} = useSelect(
( select ) => ( {
shortcut: select(
keyboardShortcutsStore
).getShortcutRepresentation( 'core/edit-post/toggle-mode' ),
isRichEditingEnabled:
select( editorStore ).getEditorSettings().richEditingEnabled,
isCodeEditingEnabled:
select( editorStore ).getEditorSettings().codeEditingEnabled,
isEditingTemplate:
select( editorStore ).getRenderingMode() === 'template-only',
mode: select( editPostStore ).getEditorMode(),
} ),
[]
);
const { shortcut, isRichEditingEnabled, isCodeEditingEnabled, mode } =
useSelect(
( select ) => ( {
shortcut: select(
keyboardShortcutsStore
).getShortcutRepresentation( 'core/edit-post/toggle-mode' ),
isRichEditingEnabled:
select( editorStore ).getEditorSettings()
.richEditingEnabled,
isCodeEditingEnabled:
select( editorStore ).getEditorSettings()
.codeEditingEnabled,
mode: select( editPostStore ).getEditorMode(),
} ),
[]
);
const { switchEditorMode } = useDispatch( editPostStore );

if ( isEditingTemplate ) {
return null;
}

let selectedMode = mode;
if ( ! isRichEditingEnabled && mode === 'visual' ) {
selectedMode = 'text';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@ import { sidebars } from '../settings-sidebar';
const { Tabs } = unlock( componentsPrivateApis );

const SettingsHeader = () => {
const { documentLabel, isTemplateMode } = useSelect( ( select ) => {
const { getPostTypeLabel, getRenderingMode } = select( editorStore );
const { documentLabel } = useSelect( ( select ) => {
const { getPostTypeLabel } = select( editorStore );

return {
// translators: Default label for the Document sidebar tab, not selected.
documentLabel: getPostTypeLabel() || _x( 'Document', 'noun' ),
isTemplateMode: getRenderingMode() === 'template-only',
};
}, [] );

return (
<Tabs.TabList>
<Tabs.Tab tabId={ sidebars.document }>
{ isTemplateMode ? __( 'Template' ) : documentLabel }
</Tabs.Tab>
<Tabs.Tab tabId={ sidebars.document }>{ documentLabel }</Tabs.Tab>
<Tabs.Tab tabId={ sidebars.block }>
{ /* translators: Text label for the Block Settings Sidebar tab. */ }
{ __( 'Block' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const sidebars = {
const SidebarContent = ( {
sidebarName,
keyboardShortcut,
isTemplateMode,
isEditingTemplate,
} ) => {
// Because `PluginSidebarEditPost` renders a `ComplementaryArea`, we
// need to forward the `Tabs` context so it can be passed through the
Expand Down Expand Up @@ -77,7 +77,7 @@ const SidebarContent = ( {
>
<Tabs.Context.Provider value={ tabsContextValue }>
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }>
{ ! isTemplateMode && (
{ ! isEditingTemplate && (
<>
<PostStatus />
<PluginDocumentSettingPanel.Slot />
Expand All @@ -90,7 +90,7 @@ const SidebarContent = ( {
<MetaBoxes location="side" />
</>
) }
{ isTemplateMode && <TemplateSummary /> }
{ isEditingTemplate && <TemplateSummary /> }
glendaviesnz marked this conversation as resolved.
Show resolved Hide resolved
</Tabs.TabPanel>
<Tabs.TabPanel tabId={ sidebars.block } focusable={ false }>
<BlockInspector />
Expand All @@ -105,7 +105,7 @@ const SettingsSidebar = () => {
sidebarName,
isSettingsSidebarActive,
keyboardShortcut,
isTemplateMode,
isEditingTemplate,
} = useSelect( ( select ) => {
// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.
// sidebarName represents the sidebar that is active or that should be active when the SettingsSidebar toggle button is pressed.
Expand All @@ -132,8 +132,8 @@ const SettingsSidebar = () => {
sidebarName: sidebar,
isSettingsSidebarActive: isSettingsSidebar,
keyboardShortcut: shortcut,
isTemplateMode:
select( editorStore ).getRenderingMode() === 'template-only',
isEditingTemplate:
select( editorStore ).getCurrentPostType() === 'wp_template',
};
}, [] );

Expand Down Expand Up @@ -161,7 +161,7 @@ const SettingsSidebar = () => {
<SidebarContent
sidebarName={ sidebarName }
keyboardShortcut={ keyboardShortcut }
isTemplateMode={ isTemplateMode }
isEditingTemplate={ isEditingTemplate }
/>
</Tabs>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
import { Icon, layout } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { Flex, FlexItem, FlexBlock, PanelBody } from '@wordpress/components';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
import { store as editorStore } from '@wordpress/editor';

function TemplateSummary() {
const template = useSelect( ( select ) => {
const { getEditedPostTemplate } = select( editPostStore );
return getEditedPostTemplate();
const { getCurrentPost } = select( editorStore );
return getCurrentPost();
}, [] );

if ( ! template ) {
Expand Down
6 changes: 4 additions & 2 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function VisualEditor( { styles } ) {
renderingMode,
isBlockBasedTheme,
hasV3BlocksOnly,
isEditingTemplate,
} = useSelect( ( select ) => {
const { isFeatureActive } = select( editPostStore );
const { getEditorSettings, getRenderingMode } = select( editorStore );
Expand All @@ -43,6 +44,8 @@ export default function VisualEditor( { styles } ) {
hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
return type.apiVersion >= 3;
} ),
isEditingTemplate:
select( editorStore ).getCurrentPostType() === 'wp_template',
};
}, [] );
const hasMetaBoxes = useSelect(
Expand Down Expand Up @@ -74,12 +77,11 @@ export default function VisualEditor( { styles } ) {
const isToBeIframed =
( ( hasV3BlocksOnly || ( isGutenbergPlugin && isBlockBasedTheme ) ) &&
! hasMetaBoxes ) ||
renderingMode === 'template-only';
isEditingTemplate;

return (
<div
className={ classnames( 'edit-post-visual-editor', {
'is-template-mode': renderingMode === 'template-only',
'has-inline-canvas': ! isToBeIframed,
} ) }
>
Expand Down
17 changes: 11 additions & 6 deletions packages/edit-post/src/components/welcome-guide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@ import WelcomeGuideTemplate from './template';
import { store as editPostStore } from '../../store';

export default function WelcomeGuide() {
const { isActive, isTemplateMode } = useSelect( ( select ) => {
const { isActive, isEditingTemplate } = useSelect( ( select ) => {
const { isFeatureActive } = select( editPostStore );
const { getRenderingMode } = select( editorStore );
const _isTemplateMode = getRenderingMode() === 'template-only';
const feature = _isTemplateMode
const { getCurrentPostType } = select( editorStore );
const _isEditingTemplate = getCurrentPostType() === 'wp_template';

const feature = _isEditingTemplate
? 'welcomeGuideTemplate'
: 'welcomeGuide';

return {
isActive: isFeatureActive( feature ),
isTemplateMode: _isTemplateMode,
isEditingTemplate: _isEditingTemplate,
};
}, [] );

if ( ! isActive ) {
return null;
}

return isTemplateMode ? <WelcomeGuideTemplate /> : <WelcomeGuideDefault />;
return isEditingTemplate ? (
<WelcomeGuideTemplate />
) : (
<WelcomeGuideDefault />
);
}
47 changes: 17 additions & 30 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,16 @@ function Editor( {
( select ) => {
const { isFeatureActive, getEditedPostTemplate } =
select( editPostStore );
const {
getEntityRecord,
getPostType,
getEntityRecords,
canUser,
} = select( coreStore );
const { getEntityRecord, getPostType, canUser } =
select( coreStore );
const { getEditorSettings } = select( editorStore );
const isTemplate = [
'wp_template',
'wp_template_part',
].includes( currentPost.postType );
// Ideally the initializeEditor function should be called using the ID of the REST endpoint.
// to avoid the special case.
let postObject;
if ( isTemplate ) {
const posts = getEntityRecords(
'postType',
currentPost.postType,
{
wp_id: currentPost.postId,
}
);
postObject = posts?.[ 0 ];
} else {
postObject = getEntityRecord(
'postType',
currentPost.postType,
currentPost.postId
);
}

const postObject = getEntityRecord(
'postType',
currentPost.postType,
currentPost.postId
);

const supportsTemplateMode =
getEditorSettings().supportsTemplateMode;
const isViewable =
Expand All @@ -84,7 +64,10 @@ function Editor( {
'preferredStyleVariations'
),
template:
supportsTemplateMode && isViewable && canEditTemplate
supportsTemplateMode &&
isViewable &&
canEditTemplate &&
currentPost.postType !== 'wp_template'
? getEditedPostTemplate()
: null,
post: postObject,
Expand All @@ -94,12 +77,15 @@ function Editor( {
);

const { updatePreferredStyleVariations } = useDispatch( editPostStore );
const defaultRenderingMode =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way to merge "all" and "post-only" mode, what's the remaining difference between these two modes?

Copy link
Contributor Author

@glendaviesnz glendaviesnz Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post-only is still quite different to all, eg. with post-only the theme layout width, etc. are applied to the full post, page title displays larger, etc:

post-only:
Screenshot 2024-01-24 at 9 18 01 AM

all:
Screenshot 2024-01-24 at 9 18 51 AM

We may be able to refactor this somehow to get rid of the need for these modes, but I think we should limit this PR to template-only and revisit the other modes post 6.5.

currentPost.postType === 'wp_template' ? 'all' : 'post-only';

const editorSettings = useMemo( () => {
const result = {
...settings,
getPostLinkProps,
goBack,
defaultRenderingMode,
__experimentalPreferredStyleVariations: {
value: preferredStyleVariations,
onChange: updatePreferredStyleVariations,
Expand All @@ -114,6 +100,7 @@ function Editor( {
updatePreferredStyleVariations,
getPostLinkProps,
goBack,
defaultRenderingMode,
] );

if ( ! post ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/hooks/use-post-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function usePostHistory( initialPostId, initialPostType ) {
return {
href: newUrl,
onClick: ( event ) => {
event.preventDefault();
event?.preventDefault();
dispatch( {
type: 'push',
post: { postId: params.postId, postType: params.postType },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { __ } from '@wordpress/i18n';
import { store as editorStore } from '@wordpress/editor';

export default function WelcomeGuideMenuItem() {
const isTemplateMode = useSelect(
const isEditingTemplate = useSelect(
( select ) =>
select( editorStore ).getRenderingMode() === 'template-only',
select( editorStore ).getCurrentPostType() === 'wp_template',
[]
);

return (
<PreferenceToggleMenuItem
scope="core/edit-post"
name={ isTemplateMode ? 'welcomeGuideTemplate' : 'welcomeGuide' }
name={ isEditingTemplate ? 'welcomeGuideTemplate' : 'welcomeGuide' }
label={ __( 'Welcome Guide' ) }
/>
);
Expand Down
Loading
Loading