diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index 96cd4e4844039..9571d50fdf3f2 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -89,9 +89,6 @@ function gutenberg_enable_experiments() { if ( $gutenberg_experiments && array_key_exists( 'gutenberg-details-blocks', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableDetailsBlocks = true', 'before' ); } - if ( $gutenberg_experiments && array_key_exists( 'gutenberg-theme-previews', $gutenberg_experiments ) ) { - wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableThemePreviews = true', 'before' ); - } if ( $gutenberg_experiments && array_key_exists( 'gutenberg-pattern-enhancements', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnablePatternEnhancements = true', 'before' ); } diff --git a/packages/edit-site/src/components/save-panel/index.js b/packages/edit-site/src/components/save-panel/index.js index fa9516f3599d9..04f97e2afcf0e 100644 --- a/packages/edit-site/src/components/save-panel/index.js +++ b/packages/edit-site/src/components/save-panel/index.js @@ -7,10 +7,15 @@ import classnames from 'classnames'; * WordPress dependencies */ import { Button, Modal } from '@wordpress/components'; -import { EntitiesSavedStates } from '@wordpress/editor'; +import { + EntitiesSavedStates, + useEntitiesSavedStatesIsDirty, + privateApis, +} from '@wordpress/editor'; import { useDispatch, useSelect } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { NavigableRegion } from '@wordpress/interface'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -18,6 +23,59 @@ import { NavigableRegion } from '@wordpress/interface'; import { store as editSiteStore } from '../../store'; import { unlock } from '../../private-apis'; import { useActivateTheme } from '../../utils/use-activate-theme'; +import { + currentlyPreviewingTheme, + isPreviewingTheme, +} from '../../utils/is-previewing-theme'; + +const { EntitiesSavedStatesExtensible } = unlock( privateApis ); + +const EntitiesSavedStatesForPreview = ( { onClose } ) => { + const isDirtyProps = useEntitiesSavedStatesIsDirty(); + let activateSaveLabel; + if ( isDirtyProps.isDirty ) { + activateSaveLabel = __( 'Activate & Save' ); + } else { + activateSaveLabel = __( 'Activate' ); + } + + const { getTheme } = useSelect( coreStore ); + const theme = getTheme( currentlyPreviewingTheme() ); + const additionalPrompt = ( +

+ { sprintf( + 'Saving your changes will change your active theme to %1$s.', + theme?.name?.rendered + ) } +

+ ); + + const activateTheme = useActivateTheme(); + const onSave = async ( values ) => { + await activateTheme(); + return values; + }; + + return ( + + ); +}; + +const _EntitiesSavedStates = ( { onClose } ) => { + if ( isPreviewingTheme() ) { + return ; + } + return ; +}; export default function SavePanel() { const { isSaveViewOpen, canvasMode } = useSelect( ( select ) => { @@ -33,18 +91,7 @@ export default function SavePanel() { }; }, [] ); const { setIsSaveViewOpened } = useDispatch( editSiteStore ); - const activateTheme = useActivateTheme(); const onClose = () => setIsSaveViewOpened( false ); - const onSave = async ( values ) => { - await activateTheme(); - return values; - }; - - const entitySavedStates = window?.__experimentalEnableThemePreviews ? ( - - ) : ( - - ); if ( canvasMode === 'view' ) { return isSaveViewOpen ? ( @@ -56,7 +103,7 @@ export default function SavePanel() { 'Save site, content, and template changes' ) } > - { entitySavedStates } + <_EntitiesSavedStates onClose={ onClose } /> ) : null; } @@ -69,7 +116,7 @@ export default function SavePanel() { ariaLabel={ __( 'Save panel' ) } > { isSaveViewOpen ? ( - entitySavedStates + <_EntitiesSavedStates onClose={ onClose } /> ) : (