diff --git a/.idea/GitLink.xml b/.idea/GitLink.xml
new file mode 100644
index 00000000000000..009597cc2f1e8e
--- /dev/null
+++ b/.idea/GitLink.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 00000000000000..d9f67957a1b9b6
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 00000000000000..79ee123c2b23e0
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 00000000000000..7c4836fbe32725
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
new file mode 100644
index 00000000000000..933ba591767b32
--- /dev/null
+++ b/.idea/php.xml
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000000000..94a25f7f4cb416
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 00000000000000..c5377a2f0645d2
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,1068 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $PROJECT_DIR$/composer.json
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "keyToString": {
+ "Notification.DisplayName-DoNotAsk-Dependencies from package.json": "Dependencies from package.json available",
+ "Notification.DoNotAsk-Dependencies from package.json": "true",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "WebServerToolWindowFactoryState": "false",
+ "last_opened_file_path": "/Users/ramon/projects/gutenberg/packages/edit-site/src/components/template-actions",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.standard": "true",
+ "node.js.detected.package.stylelint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.standard": "",
+ "node.js.selected.package.stylelint": "/Users/ramon/projects/gutenberg/node_modules/stylelint",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs.jest.jest_package": "/Users/ramon/projects/gutenberg/node_modules/jest",
+ "nodejs_interpreter_path": "/Users/ramon/.nvm/versions/node/v18.13.0/bin/node",
+ "nodejs_package_manager_path": "npm",
+ "prettierjs.PrettierConfiguration.Package": "/Users/ramon/projects/gutenberg/node_modules/prettier",
+ "run.code.analysis.last.selected.profile": "pProject Default",
+ "settings.editor.selected.configurable": "preferences.sourceCode.SCSS",
+ "ts.external.directory.path": "/Users/ramon/projects/gutenberg/node_modules/typescript/lib",
+ "vue.rearranger.settings.migration": "true"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1681465457967
+
+
+ 1681465457967
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1701126940620
+
+
+
+ 1701126940620
+
+
+ 1701136167073
+
+
+
+ 1701136167073
+
+
+ 1701153696097
+
+
+
+ 1701153696097
+
+
+ 1701153898545
+
+
+
+ 1701153898545
+
+
+ 1701210604257
+
+
+
+ 1701210604257
+
+
+ 1701224111840
+
+
+
+ 1701224111840
+
+
+ 1701234260257
+
+
+
+ 1701234260258
+
+
+ 1701236074459
+
+
+
+ 1701236074459
+
+
+ 1701313577819
+
+
+
+ 1701313577819
+
+
+ 1701321643744
+
+
+
+ 1701321643744
+
+
+ 1701334330491
+
+
+
+ 1701334330491
+
+
+ 1701334999997
+
+
+
+ 1701334999997
+
+
+ 1701392225525
+
+
+
+ 1701392225525
+
+
+ 1701412316980
+
+
+
+ 1701412316980
+
+
+ 1701640805253
+
+
+
+ 1701640805253
+
+
+ 1701641325307
+
+
+
+ 1701641325307
+
+
+ 1701641665471
+
+
+
+ 1701641665471
+
+
+ 1701642159703
+
+
+
+ 1701642159703
+
+
+ 1701655033075
+
+
+
+ 1701655033075
+
+
+ 1701663551785
+
+
+
+ 1701663551785
+
+
+ 1701663635873
+
+
+
+ 1701663635873
+
+
+ 1701667512931
+
+
+
+ 1701667512931
+
+
+ 1701668349444
+
+
+
+ 1701668349444
+
+
+ 1701733462361
+
+
+
+ 1701733462361
+
+
+ 1701733837500
+
+
+
+ 1701733837500
+
+
+ 1701734581182
+
+
+
+ 1701734581182
+
+
+ 1701749822730
+
+
+
+ 1701749822730
+
+
+ 1701774746747
+
+
+
+ 1701774746747
+
+
+ 1701831351134
+
+
+
+ 1701831351134
+
+
+ 1701833838329
+
+
+
+ 1701833838329
+
+
+ 1701835088917
+
+
+
+ 1701835088917
+
+
+ 1701835885871
+
+
+
+ 1701835885871
+
+
+ 1701851613435
+
+
+
+ 1701851613435
+
+
+ 1701901278373
+
+
+
+ 1701901278373
+
+
+ 1701919397889
+
+
+
+ 1701919397889
+
+
+ 1701922582211
+
+
+
+ 1701922582211
+
+
+ 1701923293166
+
+
+
+ 1701923293166
+
+
+ 1701924607873
+
+
+
+ 1701924607873
+
+
+ 1701936016856
+
+
+
+ 1701936016856
+
+
+ 1701993805533
+
+
+
+ 1701993805533
+
+
+ 1702012223090
+
+
+
+ 1702012223091
+
+
+ 1702012611427
+
+
+
+ 1702012611427
+
+
+ 1702012777299
+
+
+
+ 1702012777299
+
+
+ 1702250902522
+
+
+
+ 1702250902522
+
+
+ 1702252557659
+
+
+
+ 1702252557659
+
+
+ 1702267617228
+
+
+
+ 1702267617228
+
+
+ 1702268095389
+
+
+
+ 1702268095389
+
+
+ 1702269533072
+
+
+
+ 1702269533072
+
+
+ 1702281880489
+
+
+
+ 1702281880489
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/packages/compose/src/hooks/use-resize-observer/index.tsx
+ 226
+
+
+
+ file://$PROJECT_DIR$/packages/edit-site/src/components/page-content-focus-manager/disable-non-page-content-blocks.js
+ 51
+
+
+
+ file://$PROJECT_DIR$/packages/edit-site/src/hooks/push-changes-to-global-styles/index.js
+ 392
+
+
+
+ file://$PROJECT_DIR$/packages/core-data/src/resolvers.js
+ 192
+
+
+
+ file://$PROJECT_DIR$/packages/edit-site/src/components/sync-state-with-url/use-sync-path-with-url.js
+ 50
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js
index 295f4ec3cf5c60..352ac902e8e764 100644
--- a/packages/edit-site/src/components/editor/index.js
+++ b/packages/edit-site/src/components/editor/index.js
@@ -25,6 +25,7 @@ import {
import {
EditorNotices,
EditorSnackbars,
+ PostLockedModal,
privateApis as editorPrivateApis,
store as editorStore,
} from '@wordpress/editor';
@@ -288,6 +289,7 @@ export default function Editor( { listViewToggleElement, isLoading } ) {
secondarySidebar: secondarySidebarLabel,
} }
/>
+
) }
>
diff --git a/packages/edit-site/src/components/page-patterns/grid-item.js b/packages/edit-site/src/components/page-patterns/grid-item.js
index b394ef8eb6e76c..7596541a55bc3e 100644
--- a/packages/edit-site/src/components/page-patterns/grid-item.js
+++ b/packages/edit-site/src/components/page-patterns/grid-item.js
@@ -41,7 +41,6 @@ import { downloadBlob } from '@wordpress/blob';
/**
* Internal dependencies
*/
-import RenameMenuItem from './rename-menu-item';
import DuplicateMenuItem from './duplicate-menu-item';
import {
PATTERN_TYPES,
@@ -51,6 +50,7 @@ import {
import { store as editSiteStore } from '../../store';
import { useLink } from '../routes/link';
import { unlock } from '../../lock-unlock';
+import RenameMenuItem from '../template-actions/rename-menu-item';
const { useGlobalStyle } = unlock( blockEditorPrivateApis );
@@ -283,7 +283,8 @@ function GridItem( { categoryId, item, ...props } ) {
{ isCustomPattern && ! hasThemeFile && (
) }
diff --git a/packages/edit-site/src/components/page-patterns/rename-menu-item.js b/packages/edit-site/src/components/page-patterns/rename-menu-item.js
index c2b3b960fb6677..e69de29bb2d1d6 100644
--- a/packages/edit-site/src/components/page-patterns/rename-menu-item.js
+++ b/packages/edit-site/src/components/page-patterns/rename-menu-item.js
@@ -1,132 +0,0 @@
-/**
- * WordPress dependencies
- */
-import {
- Button,
- MenuItem,
- Modal,
- TextControl,
- __experimentalHStack as HStack,
- __experimentalVStack as VStack,
-} from '@wordpress/components';
-import { store as coreStore } from '@wordpress/core-data';
-import { useDispatch } from '@wordpress/data';
-import { useState } from '@wordpress/element';
-import { __ } from '@wordpress/i18n';
-import { store as noticesStore } from '@wordpress/notices';
-
-/**
- * Internal dependencies
- */
-import { TEMPLATE_PART_POST_TYPE } from '../../utils/constants';
-
-export default function RenameMenuItem( { item, onClose } ) {
- const [ title, setTitle ] = useState( () => item.title );
- const [ isModalOpen, setIsModalOpen ] = useState( false );
-
- const { editEntityRecord, saveEditedEntityRecord } =
- useDispatch( coreStore );
- const { createSuccessNotice, createErrorNotice } =
- useDispatch( noticesStore );
-
- if ( item.type === TEMPLATE_PART_POST_TYPE && ! item.isCustom ) {
- return null;
- }
-
- async function onRename( event ) {
- event.preventDefault();
-
- try {
- await editEntityRecord( 'postType', item.type, item.id, { title } );
-
- // Update state before saving rerenders the list.
- setTitle( '' );
- setIsModalOpen( false );
- onClose();
-
- // Persist edited entity.
- await saveEditedEntityRecord( 'postType', item.type, item.id, {
- throwOnError: true,
- } );
-
- createSuccessNotice(
- item.type === TEMPLATE_PART_POST_TYPE
- ? __( 'Template part renamed.' )
- : __( 'Pattern renamed.' ),
- {
- type: 'snackbar',
- }
- );
- } catch ( error ) {
- const fallbackErrorMessage =
- item.type === TEMPLATE_PART_POST_TYPE
- ? __(
- 'An error occurred while renaming the template part.'
- )
- : __( 'An error occurred while renaming the pattern.' );
- const errorMessage =
- error.message && error.code !== 'unknown_error'
- ? error.message
- : fallbackErrorMessage;
-
- createErrorNotice( errorMessage, { type: 'snackbar' } );
- }
- }
-
- return (
- <>
-
- { isModalOpen && (
- {
- setIsModalOpen( false );
- onClose();
- } }
- overlayClassName="edit-site-list__rename-modal"
- >
-
-
- ) }
- >
- );
-}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js
index e6ead651fbbfc9..0e6c2674c01654 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js
@@ -104,6 +104,11 @@ export default function SidebarNavigationScreenTemplate() {
postId
);
+ // The absence of a post type in the query params for templates
+ // indicates the user has arrived at the template via the "manage all"
+ // page and the back button should return them to that list page.
+ const backPath =
+ postType !== 'wp_template' ? `/${ postType }/all` : `/${ postType }`;
return (
{
- navigator.goTo( `/${ postType }/all` );
+ navigator.goTo( backPath );
} }
/>
select( coreStore ).getEntityRecord( 'postType', postType, postId ),
[ postType, postId ]
@@ -40,27 +46,69 @@ export default function TemplateActions( {
const { saveEditedEntityRecord } = useDispatch( coreStore );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
- const isRemovable = isTemplateRemovable( template );
- const isRevertable = isTemplateRevertable( template );
+ const { __experimentalDeleteReusableBlock } =
+ useDispatch( reusableBlocksStore );
+ const isRemovable = isTemplateRemovable( record );
+ // Only custom patterns or custom template parts can be renamed or deleted.
+ const isUserPattern = record?.type === PATTERN_TYPES.user;
+ const isTemplate = record?.type === TEMPLATE_POST_TYPE;
+ const isTemplatePart = record?.type === TEMPLATE_PART_POST_TYPE;
- if ( ! isRemovable && ! isRevertable ) {
+ if (
+ ! isRemovable &&
+ ! isTemplatePart &&
+ ! isTemplate &&
+ ! isUserPattern
+ ) {
return null;
}
- async function revertAndSaveTemplate() {
+ const isEditable = isUserPattern || isRemovable;
+ const decodedTitle = decodeEntities(
+ record?.title?.rendered || record?.title?.raw
+ );
+
+ const deletePattern = async ( pattern ) => {
try {
- await revertTemplate( template, { allowUndo: false } );
- await saveEditedEntityRecord(
- 'postType',
- template.type,
- template.id
+ await __experimentalDeleteReusableBlock( pattern.id );
+ createSuccessNotice(
+ sprintf(
+ // translators: %s: The pattern's title e.g. 'Call to action'.
+ __( '"%s" deleted.' ),
+ decodedTitle
+ ),
+ { type: 'snackbar', id: 'edit-site-patterns-success' }
);
+ } catch ( error ) {
+ const errorMessage =
+ error.message && error.code !== 'unknown_error'
+ ? error.message
+ : __( 'An error occurred while deleting the pattern.' );
+ createErrorNotice( errorMessage, {
+ type: 'snackbar',
+ id: 'edit-site-patterns-error',
+ } );
+ }
+ };
+
+ const deleteItem = async ( item ) => {
+ if ( isTemplateRemovable( item ) ) {
+ removeTemplate( item );
+ } else if ( isUserPattern ) {
+ deletePattern( item );
+ }
+ };
+
+ async function revertAndSaveTemplate( item ) {
+ try {
+ await revertTemplate( record, { allowUndo: false } );
+ await saveEditedEntityRecord( 'postType', item.type, item.id );
createSuccessNotice(
sprintf(
/* translators: The template/part's name. */
__( '"%s" reverted.' ),
- decodeEntities( template.title.rendered )
+ decodedTitle
),
{
type: 'snackbar',
@@ -68,12 +116,12 @@ export default function TemplateActions( {
}
);
} catch ( error ) {
- const fallbackErrorMessage =
- template.type === TEMPLATE_POST_TYPE
- ? __( 'An error occurred while reverting the template.' )
- : __(
- 'An error occurred while reverting the template part.'
- );
+ const fallbackErrorMessage = sprintf(
+ // translators: %s is a post type label, e.g., Template, Template Part or Pattern.
+ __( 'An error occurred while reverting the %s.' ),
+ POST_TYPE_LABELS[ postType ] ??
+ POST_TYPE_LABELS[ TEMPLATE_POST_TYPE ]
+ );
const errorMessage =
error.message && error.code !== 'unknown_error'
? error.message
@@ -83,6 +131,12 @@ export default function TemplateActions( {
}
}
+ const shouldDisplayMenu = isEditable || isTemplateRevertable( record );
+
+ if ( ! shouldDisplayMenu ) {
+ return null;
+ }
+
return (
{ ( { onClose } ) => (
- { isRemovable && (
+ { isEditable && (
<>
{
- removeTemplate( template );
+ deleteItem( record );
onRemove?.();
onClose();
} }
- title={ template.title.rendered }
+ title={ decodedTitle }
/>
>
) }
- { isRevertable && (
+
+ { isTemplateRevertable( record ) && (