diff --git a/lib/compat/wordpress-6.3/navigation-fallback.php b/lib/compat/wordpress-6.3/navigation-fallback.php index f3a22e5ce997c3..5619e3204627aa 100644 --- a/lib/compat/wordpress-6.3/navigation-fallback.php +++ b/lib/compat/wordpress-6.3/navigation-fallback.php @@ -26,10 +26,17 @@ function gutenberg_add_fields_to_navigation_fallback_embeded_links( $schema ) { $schema['properties']['content']['context'] = array_merge( $schema['properties']['content']['context'], array( 'embed' ) ); // Expose sub properties of content field. + // These aren't exposed by the posts controller by default, see: + // https://github.com/WordPress/wordpress-develop/blob/5c3c6258e468c67ba00bbd13db29994f1a57a52a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2425. $schema['properties']['content']['properties']['raw']['context'] = array_merge( $schema['properties']['content']['properties']['raw']['context'], array( 'embed' ) ); $schema['properties']['content']['properties']['rendered']['context'] = array_merge( $schema['properties']['content']['properties']['rendered']['context'], array( 'embed' ) ); $schema['properties']['content']['properties']['block_version']['context'] = array_merge( $schema['properties']['content']['properties']['block_version']['context'], array( 'embed' ) ); + // Expose sub properties of title field. + // These aren't exposed by the posts controller by default, see: + // https://github.com/WordPress/wordpress-develop/blob/5c3c6258e468c67ba00bbd13db29994f1a57a52a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2401. + $schema['properties']['title']['properties']['raw']['context'] = array_merge( $schema['properties']['title']['properties']['raw']['context'], array( 'embed' ) ); + return $schema; } diff --git a/packages/block-editor/src/components/block-tools/style.scss b/packages/block-editor/src/components/block-tools/style.scss index 07e400344bfe10..6ff3bbc721a10a 100644 --- a/packages/block-editor/src/components/block-tools/style.scss +++ b/packages/block-editor/src/components/block-tools/style.scss @@ -322,12 +322,15 @@ // for the block inserter the publish button @include break-large() { &.is-fixed { + width: auto; + } + .is-fullscreen-mode &.is-fixed { + // in full screen mode we need to account for // the combined with of the tools at the right of the header and the margin left // of the toolbar which includes four buttons width: calc(100% - 240px - #{4 * $grid-unit-80}); } } - } /** diff --git a/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js b/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js index 805a89ca8ff0c4..6d6333587b7d0e 100644 --- a/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js +++ b/packages/block-editor/src/components/inserter/hooks/use-patterns-state.js @@ -61,6 +61,7 @@ const usePatternsState = ( onInsert, rootClientId ) => { ), { type: 'snackbar', + id: 'block-pattern-inserted-notice', } ); }, diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index fc4db2c41f8a3f..9140248391cf8e 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -121,7 +121,7 @@ describe( 'selectors', () => { parent: [ 'core/test-block-b' ], } ); - registerBlockType( 'core/test-freeform', { + registerBlockType( 'core/freeform', { save: ( props ) => { props.attributes.content }, category: 'text', title: 'Test Freeform Content Handler', @@ -177,7 +177,7 @@ describe( 'selectors', () => { ancestor: [ 'core/test-block-ancestor' ], } ); - setFreeformContentHandlerName( 'core/test-freeform' ); + setFreeformContentHandlerName( 'core/freeform' ); cachedSelectors.forEach( ( { clear } ) => clear() ); } ); @@ -187,7 +187,7 @@ describe( 'selectors', () => { unregisterBlockType( 'core/test-block-a' ); unregisterBlockType( 'core/test-block-b' ); unregisterBlockType( 'core/test-block-c' ); - unregisterBlockType( 'core/test-freeform' ); + unregisterBlockType( 'core/freeform' ); unregisterBlockType( 'core/post-content-child' ); unregisterBlockType( 'core/test-block-ancestor' ); unregisterBlockType( 'core/test-block-parent' ); @@ -3450,7 +3450,7 @@ describe( 'selectors', () => { expect( firstBlockFirstCall.map( ( item ) => item.id ) ).toEqual( [ 'core/test-block-a', 'core/test-block-b', - 'core/test-freeform', + 'core/freeform', 'core/test-block-ancestor', 'core/test-block-parent', 'core/block/1', @@ -3466,7 +3466,7 @@ describe( 'selectors', () => { expect( secondBlockFirstCall.map( ( item ) => item.id ) ).toEqual( [ 'core/test-block-a', 'core/test-block-b', - 'core/test-freeform', + 'core/freeform', 'core/test-block-ancestor', 'core/test-block-parent', 'core/block/1', diff --git a/packages/block-library/src/comment-template/index.php b/packages/block-library/src/comment-template/index.php index bb1cfa474e4c36..5a0eef5685cf1c 100644 --- a/packages/block-library/src/comment-template/index.php +++ b/packages/block-library/src/comment-template/index.php @@ -8,6 +8,8 @@ /** * Function that recursively renders a list of nested comments. * + * @since 6.3.0 Changed render_block_context priority to `1`. + * * @global int $comment_depth * * @param WP_Comment[] $comments The array of comments. diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index e4bd8dcdeaac2e..ca9aca60abfb67 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -8,6 +8,8 @@ /** * Renders the `core/footnotes` block on the server. * + * @since 6.3.0 + * * @param array $attributes Block attributes. * @param string $content Block default content. * @param WP_Block $block Block instance. @@ -57,6 +59,8 @@ function render_block_core_footnotes( $attributes, $content, $block ) { /** * Registers the `core/footnotes` block on the server. + * + * @since 6.3.0 */ function register_block_core_footnotes() { foreach ( array( 'post', 'page' ) as $post_type ) { @@ -78,3 +82,137 @@ function register_block_core_footnotes() { ); } add_action( 'init', 'register_block_core_footnotes' ); + +add_action( + 'wp_after_insert_post', + /** + * Saves the footnotes meta value to the revision. + * + * @since 6.3.0 + * + * @param int $revision_id The revision ID. + */ + static function( $revision_id ) { + $post_id = wp_is_post_revision( $revision_id ); + + if ( $post_id ) { + $footnotes = get_post_meta( $post_id, 'footnotes', true ); + + if ( $footnotes ) { + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $revision_id, 'footnotes', $footnotes ); + } + } + } +); + +add_action( + '_wp_put_post_revision', + /** + * Keeps track of the revision ID for "rest_after_insert_{$post_type}". + * + * @param int $revision_id The revision ID. + */ + static function( $revision_id ) { + global $_gutenberg_revision_id; + $_gutenberg_revision_id = $revision_id; + } +); + +foreach ( array( 'post', 'page' ) as $post_type ) { + add_action( + "rest_after_insert_{$post_type}", + /** + * This is a specific fix for the REST API. The REST API doesn't update + * the post and post meta in one go (through `meta_input`). While it + * does fix the `wp_after_insert_post` hook to be called correctly after + * updating meta, it does NOT fix hooks such as post_updated and + * save_post, which are normally also fired after post meta is updated + * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is + * added to the `post_updated` action, which means the meta is not + * available at the time, so we have to add it afterwards through the + * `"rest_after_insert_{$post_type}"` action. + * + * @since 6.3.0 + * + * @param WP_Post $post The post object. + */ + static function( $post ) { + global $_gutenberg_revision_id; + + if ( $_gutenberg_revision_id ) { + $revision = get_post( $_gutenberg_revision_id ); + $post_id = $revision->post_parent; + + // Just making sure we're updating the right revision. + if ( $post->ID === $post_id ) { + $footnotes = get_post_meta( $post_id, 'footnotes', true ); + + if ( $footnotes ) { + // Can't use update_post_meta() because it doesn't allow revisions. + update_metadata( 'post', $_gutenberg_revision_id, 'footnotes', $footnotes ); + } + } + } + } + ); +} + +add_action( + 'wp_restore_post_revision', + /** + * Restores the footnotes meta value from the revision. + * + * @since 6.3.0 + * + * @param int $post_id The post ID. + * @param int $revision_id The revision ID. + */ + static function( $post_id, $revision_id ) { + $footnotes = get_post_meta( $revision_id, 'footnotes', true ); + + if ( $footnotes ) { + update_post_meta( $post_id, 'footnotes', $footnotes ); + } else { + delete_post_meta( $post_id, 'footnotes' ); + } + }, + 10, + 2 +); + +add_filter( + '_wp_post_revision_fields', + /** + * Adds the footnotes field to the revision. + * + * @since 6.3.0 + * + * @param array $fields The revision fields. + * @return array The revision fields. + */ + static function( $fields ) { + $fields['footnotes'] = __( 'Footnotes' ); + return $fields; + } +); + +add_filter( + 'wp_post_revision_field_footnotes', + /** + * Gets the footnotes field from the revision. + * + * @since 6.3.0 + * + * @param string $revision_field The field value, but $revision->$field + * (footnotes) does not exist. + * @param string $field The field name, in this case "footnotes". + * @param object $revision The revision object to compare against. + * @return string The field value. + */ + static function( $revision_field, $field, $revision ) { + return get_metadata( 'post', $revision->ID, $field, true ); + }, + 10, + 3 +); diff --git a/packages/block-library/src/pattern/index.php b/packages/block-library/src/pattern/index.php index a819cb6bd4cdfd..6368bdb7b74875 100644 --- a/packages/block-library/src/pattern/index.php +++ b/packages/block-library/src/pattern/index.php @@ -22,6 +22,8 @@ function register_block_core_pattern() { /** * Renders the `core/pattern` block on the server. * + * @since 6.3.0 Backwards compatibility: blocks with no `syncStatus` attribute do not receive block wrapper. + * * @param array $attributes Block attributes. * * @return string Returns the output of the pattern. diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index b1499d845f39a6..88b7c27f1c66f9 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -34,6 +34,8 @@ function block_core_post_template_uses_featured_image( $inner_blocks ) { /** * Renders the `core/post-template` block on the server. * + * @since 6.3.0 Changed render_block_context priority to `1`. + * * @param array $attributes Block attributes. * @param string $content Block default content. * @param WP_Block $block Block instance. diff --git a/packages/block-library/src/post-title/index.php b/packages/block-library/src/post-title/index.php index 1769b199cebf17..8b0e431b3a8be4 100644 --- a/packages/block-library/src/post-title/index.php +++ b/packages/block-library/src/post-title/index.php @@ -8,6 +8,8 @@ /** * Renders the `core/post-title` block on the server. * + * @since 6.3.0 Omitting the $post argument from the `get_the_title`. + * * @param array $attributes Block attributes. * @param string $content Block default content. * @param WP_Block $block Block instance. diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 700a299a92457a..b0fed54d2f385a 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -8,6 +8,8 @@ /** * Dynamically renders the `core/search` block. * + * @since 6.3.0 Using block.json `viewScript` to register script, and update `view_script_handles()` only when needed. + * * @param array $attributes The block attributes. * @param string $content The saved content. * @param WP_Block $block The parsed block. diff --git a/packages/blocks/src/api/parser/index.js b/packages/blocks/src/api/parser/index.js index 52facfb212c8c4..f8ff0c68964dc3 100644 --- a/packages/blocks/src/api/parser/index.js +++ b/packages/blocks/src/api/parser/index.js @@ -101,6 +101,7 @@ export function normalizeRawBlock( rawBlock, options ) { // meaning there are no negative consequences to repeated autop calls. if ( rawBlockName === fallbackBlockName && + rawBlockName === 'core/freeform' && ! options?.__unstableSkipAutop ) { rawInnerHTML = autop( rawInnerHTML ).trim(); diff --git a/packages/blocks/src/api/parser/test/index.js b/packages/blocks/src/api/parser/test/index.js index 589d6b81be5536..85e51e9d0af025 100644 --- a/packages/blocks/src/api/parser/test/index.js +++ b/packages/blocks/src/api/parser/test/index.js @@ -90,19 +90,30 @@ describe( 'block parser', () => { } ); it( 'should fall back to the freeform content handler if block type not specified', () => { - registerBlockType( 'core/freeform-block', unknownBlockSettings ); - setFreeformContentHandlerName( 'core/freeform-block' ); + registerBlockType( 'core/freeform', unknownBlockSettings ); + setFreeformContentHandlerName( 'core/freeform' ); const block = parseRawBlock( { innerHTML: 'content', } ); - expect( block.name ).toEqual( 'core/freeform-block' ); + expect( block.name ).toEqual( 'core/freeform' ); expect( block.attributes ).toEqual( { content: '

content

' } ); } ); + it( 'skips adding paragraph tags if freeform block is set to core/html', () => { + registerBlockType( 'core/html', unknownBlockSettings ); + setFreeformContentHandlerName( 'core/html' ); + + const block = parseRawBlock( { + innerHTML: 'content', + } ); + expect( block.name ).toEqual( 'core/html' ); + expect( block.attributes ).toEqual( { content: 'content' } ); + } ); + it( 'skips adding paragraph tags if __unstableSkipAutop is passed as an option', () => { - registerBlockType( 'core/freeform-block', unknownBlockSettings ); - setFreeformContentHandlerName( 'core/freeform-block' ); + registerBlockType( 'core/freeform', unknownBlockSettings ); + setFreeformContentHandlerName( 'core/freeform' ); const block = parseRawBlock( { @@ -112,7 +123,7 @@ describe( 'block parser', () => { __unstableSkipAutop: true, } ); - expect( block.name ).toEqual( 'core/freeform-block' ); + expect( block.name ).toEqual( 'core/freeform' ); expect( block.attributes ).toEqual( { content: 'content' } ); } ); diff --git a/packages/blocks/src/api/serializer.js b/packages/blocks/src/api/serializer.js index fff687767b7fa8..92559b1a0e7173 100644 --- a/packages/blocks/src/api/serializer.js +++ b/packages/blocks/src/api/serializer.js @@ -390,7 +390,8 @@ export function __unstableSerializeAndClean( blocks ) { // pre-block-editor removep'd content formatting. if ( blocks.length === 1 && - blocks[ 0 ].name === getFreeformContentHandlerName() + blocks[ 0 ].name === getFreeformContentHandlerName() && + blocks[ 0 ].name === 'core/freeform' ) { content = removep( content ); } diff --git a/packages/blocks/src/api/test/serializer.js b/packages/blocks/src/api/test/serializer.js index 22fa5bc7b6dc6a..6cb21470f9e1fa 100644 --- a/packages/blocks/src/api/test/serializer.js +++ b/packages/blocks/src/api/test/serializer.js @@ -244,7 +244,7 @@ describe( 'block serializer', () => { describe( 'serializeBlock()', () => { it( 'serializes the freeform content fallback block without comment delimiters', () => { - registerBlockType( 'core/freeform-block', { + registerBlockType( 'core/freeform', { category: 'text', title: 'freeform block', attributes: { @@ -254,8 +254,8 @@ describe( 'block serializer', () => { }, save: ( { attributes } ) => attributes.fruit, } ); - setFreeformContentHandlerName( 'core/freeform-block' ); - const block = createBlock( 'core/freeform-block', { + setFreeformContentHandlerName( 'core/freeform' ); + const block = createBlock( 'core/freeform', { fruit: 'Bananas', } ); @@ -264,7 +264,7 @@ describe( 'block serializer', () => { expect( content ).toBe( 'Bananas' ); } ); it( 'serializes the freeform content fallback block with comment delimiters in nested context', () => { - registerBlockType( 'core/freeform-block', { + registerBlockType( 'core/freeform', { category: 'text', title: 'freeform block', attributes: { @@ -274,17 +274,17 @@ describe( 'block serializer', () => { }, save: ( { attributes } ) => attributes.fruit, } ); - setFreeformContentHandlerName( 'core/freeform-block' ); - const block = createBlock( 'core/freeform-block', { + setFreeformContentHandlerName( 'core/freeform' ); + const block = createBlock( 'core/freeform', { fruit: 'Bananas', } ); const content = serializeBlock( block, { isInnerBlocks: true } ); expect( content ).toBe( - '\n' + + '\n' + 'Bananas\n' + - '' + '' ); } ); it( 'serializes the unregistered fallback block without comment delimiters', () => { diff --git a/packages/e2e-tests/plugins/iframed-enqueue-block-editor-settings.php b/packages/e2e-tests/plugins/iframed-enqueue-block-editor-settings.php new file mode 100644 index 00000000000000..2e5eb32c042784 --- /dev/null +++ b/packages/e2e-tests/plugins/iframed-enqueue-block-editor-settings.php @@ -0,0 +1,19 @@ + 'p { border: 1px solid red }', + '__unstableType' => 'plugin', + ); + return $settings; + } +); diff --git a/packages/e2e-tests/specs/editor/plugins/iframed-enqueue-block-editor-settings.test.js b/packages/e2e-tests/specs/editor/plugins/iframed-enqueue-block-editor-settings.test.js new file mode 100644 index 00000000000000..df6eb4bf840328 --- /dev/null +++ b/packages/e2e-tests/specs/editor/plugins/iframed-enqueue-block-editor-settings.test.js @@ -0,0 +1,108 @@ +/** + * WordPress dependencies + */ +import { + activatePlugin, + createNewPost, + deactivatePlugin, + canvas, + activateTheme, +} from '@wordpress/e2e-test-utils'; + +async function getComputedStyle( context, selector, property ) { + return await context.evaluate( + ( sel, prop ) => + window.getComputedStyle( document.querySelector( sel ) )[ prop ], + selector, + property + ); +} + +describe( 'iframed block editor settings styles', () => { + beforeEach( async () => { + // Activate the empty theme (block based theme), which is iframed. + await activateTheme( 'emptytheme' ); + await activatePlugin( + 'gutenberg-test-iframed-enqueue-block-editor-settings' + ); + await createNewPost(); + } ); + + afterEach( async () => { + await deactivatePlugin( + 'gutenberg-test-iframed-enqueue-block-editor-settings' + ); + await activateTheme( 'twentytwentyone' ); + } ); + + it( 'should load styles added through block editor settings', async () => { + await page.waitForSelector( 'iframe[name="editor-canvas"]' ); + // Expect a red border (added in PHP). + expect( await getComputedStyle( canvas(), 'p', 'border-color' ) ).toBe( + 'rgb(255, 0, 0)' + ); + + await page.evaluate( () => { + const settings = window.wp.data + .select( 'core/editor' ) + .getEditorSettings(); + wp.data.dispatch( 'core/editor' ).updateEditorSettings( { + ...settings, + styles: [ + ...settings.styles, + { + css: 'p { border-width: 2px; }', + __unstableType: 'plugin', + }, + ], + } ); + } ); + + // Expect a 2px border (added in JS). + expect( await getComputedStyle( canvas(), 'p', 'border-width' ) ).toBe( + '2px' + ); + } ); + + it( 'should load theme styles added through block editor settings', async () => { + await page.waitForSelector( 'iframe[name="editor-canvas"]' ); + + await page.evaluate( () => { + // Make sure that theme styles are added even if the theme styles + // preference is off. + window.wp.data + .dispatch( 'core/edit-post' ) + .toggleFeature( 'themeStyles' ); + const settings = window.wp.data + .select( 'core/editor' ) + .getEditorSettings(); + wp.data.dispatch( 'core/editor' ).updateEditorSettings( { + ...settings, + styles: [ + ...settings.styles, + { + css: 'p { border-width: 2px; }', + __unstableType: 'theme', + }, + ], + } ); + } ); + + // Expect a 1px border because theme styles are disabled. + expect( await getComputedStyle( canvas(), 'p', 'border-width' ) ).toBe( + '1px' + ); + + await page.evaluate( () => { + // Now enable theme styles. + window.wp.data + .dispatch( 'core/edit-post' ) + .toggleFeature( 'themeStyles' ); + } ); + + // Expect a 2px border because theme styles are enabled. + expect( await getComputedStyle( canvas(), 'p', 'border-width' ) ).toBe( + '2px' + ); + } ); +} ); diff --git a/packages/edit-post/src/components/layout/index.js b/packages/edit-post/src/components/layout/index.js index b7aa8bcd025af7..73e050af14df24 100644 --- a/packages/edit-post/src/components/layout/index.js +++ b/packages/edit-post/src/components/layout/index.js @@ -17,7 +17,10 @@ import { store as editorStore, } from '@wordpress/editor'; import { useSelect, useDispatch } from '@wordpress/data'; -import { BlockBreadcrumb } from '@wordpress/block-editor'; +import { + BlockBreadcrumb, + privateApis as blockEditorPrivateApis, +} from '@wordpress/block-editor'; import { Button, ScrollLock, Popover } from '@wordpress/components'; import { useViewportMatch } from '@wordpress/compose'; import { PluginArea } from '@wordpress/plugins'; @@ -50,6 +53,9 @@ import WelcomeGuide from '../welcome-guide'; import ActionsPanel from './actions-panel'; import StartPageOptions from '../start-page-options'; import { store as editPostStore } from '../../store'; +import { unlock } from '../../lock-unlock'; + +const { getLayoutStyles } = unlock( blockEditorPrivateApis ); const interfaceLabels = { /* translators: accessibility text for the editor top bar landmark region. */ @@ -64,7 +70,7 @@ const interfaceLabels = { footer: __( 'Editor footer' ), }; -function Layout( { styles } ) { +function Layout() { const isMobileViewport = useViewportMatch( 'medium', '<' ); const isHugeViewport = useViewportMatch( 'huge', '>=' ); const isLargeViewport = useViewportMatch( 'large' ); @@ -88,10 +94,45 @@ function Layout( { styles } ) { showBlockBreadcrumbs, isTemplateMode, documentLabel, + styles, } = useSelect( ( select ) => { const { getEditorSettings, getPostTypeLabel } = select( editorStore ); + const { isFeatureActive } = select( editPostStore ); const editorSettings = getEditorSettings(); const postTypeLabel = getPostTypeLabel(); + const hasThemeStyles = isFeatureActive( 'themeStyles' ); + + const themeStyles = []; + const presetStyles = []; + editorSettings.styles?.forEach( ( style ) => { + if ( ! style.__unstableType || style.__unstableType === 'theme' ) { + themeStyles.push( style ); + } else { + presetStyles.push( style ); + } + } ); + + const defaultEditorStyles = [ + ...editorSettings.defaultEditorStyles, + ...presetStyles, + ]; + + // If theme styles are not present or displayed, ensure that + // base layout styles are still present in the editor. + if ( + ! editorSettings.disableLayoutStyles && + ! ( hasThemeStyles && themeStyles.length ) + ) { + defaultEditorStyles.push( { + css: getLayoutStyles( { + style: {}, + selector: 'body', + hasBlockGapSupport: false, + hasFallbackGapSupport: true, + fallbackGapValue: '0.5em', + } ), + } ); + } return { isTemplateMode: select( editPostStore ).isEditingTemplate(), @@ -124,6 +165,10 @@ function Layout( { styles } ) { ), // translators: Default label for the Document in the Block Breadcrumb. documentLabel: postTypeLabel || _x( 'Document', 'noun' ), + styles: + hasThemeStyles && themeStyles.length + ? editorSettings.styles + : defaultEditorStyles, }; }, [] ); diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 6ec907bfe4b0b0..00bc911dd7626e 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -9,7 +9,6 @@ import { store as editorStore, privateApis as editorPrivateApis, } from '@wordpress/editor'; -import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; import { useMemo } from '@wordpress/element'; import { SlotFillProvider } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; @@ -28,7 +27,6 @@ import { unlock } from './lock-unlock'; import useCommonCommands from './hooks/commands/use-common-commands'; const { ExperimentalEditorProvider } = unlock( editorPrivateApis ); -const { getLayoutStyles } = unlock( blockEditorPrivateApis ); const { useCommands } = unlock( coreCommandsPrivateApis ); function Editor( { postId, postType, settings, initialEdits, ...props } ) { @@ -39,7 +37,6 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) { focusMode, isDistractionFree, hasInlineToolbar, - hasThemeStyles, post, preferredStyleVariations, hiddenBlockTypes, @@ -51,7 +48,6 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) { ( select ) => { const { isFeatureActive, - __experimentalGetPreviewDeviceType, isEditingTemplate, getEditedPostTemplate, getHiddenBlockTypes, @@ -80,13 +76,10 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) { const canEditTemplate = canUser( 'create', 'templates' ); return { - hasFixedToolbar: - isFeatureActive( 'fixedToolbar' ) || - __experimentalGetPreviewDeviceType() !== 'Desktop', + hasFixedToolbar: isFeatureActive( 'fixedToolbar' ), focusMode: isFeatureActive( 'focusMode' ), isDistractionFree: isFeatureActive( 'distractionFree' ), hasInlineToolbar: isFeatureActive( 'inlineToolbar' ), - hasThemeStyles: isFeatureActive( 'themeStyles' ), preferredStyleVariations: select( preferencesStore ).get( 'core/edit-post', 'preferredStyleVariations' @@ -158,44 +151,6 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) { keepCaretInsideBlock, ] ); - const styles = useMemo( () => { - const themeStyles = []; - const presetStyles = []; - settings.styles?.forEach( ( style ) => { - if ( ! style.__unstableType || style.__unstableType === 'theme' ) { - themeStyles.push( style ); - } else { - presetStyles.push( style ); - } - } ); - - const defaultEditorStyles = [ - ...settings.defaultEditorStyles, - ...presetStyles, - ]; - - // If theme styles are not present or displayed, ensure that - // base layout styles are still present in the editor. - if ( - ! settings.disableLayoutStyles && - ! ( hasThemeStyles && themeStyles.length ) - ) { - defaultEditorStyles.push( { - css: getLayoutStyles( { - style: {}, - selector: 'body', - hasBlockGapSupport: false, - hasFallbackGapSupport: true, - fallbackGapValue: '0.5em', - } ), - } ); - } - - return hasThemeStyles && themeStyles.length - ? settings.styles - : defaultEditorStyles; - }, [ settings, hasThemeStyles ] ); - if ( ! post ) { return null; } @@ -214,7 +169,7 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) { - + diff --git a/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js b/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js index f32441f6a41b06..801f3c02363fbd 100644 --- a/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js +++ b/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js @@ -21,11 +21,9 @@ function getRevisionLabel( revision ) { if ( 'unsaved' === revision?.id ) { return sprintf( - /* translators: %(name)s author display name */ - __( 'Unsaved changes by %(name)s' ), - { - name: authorDisplayName, - } + /* translators: %s author display name */ + __( 'Unsaved changes by %s' ), + authorDisplayName ); } const formattedDate = dateI18n( @@ -35,20 +33,16 @@ function getRevisionLabel( revision ) { return revision?.isLatest ? sprintf( - /* translators: %(name)s author display name, %(date)s: revision creation date */ - __( 'Changes saved by %(name)s on %(date)s (current)' ), - { - name: authorDisplayName, - date: formattedDate, - } + /* translators: %1$s author display name, %2$s: revision creation date */ + __( 'Changes saved by %1$s on %2$s (current)' ), + authorDisplayName, + formattedDate ) : sprintf( - /* translators: %(name)s author display name, %(date)s: revision creation date */ - __( 'Changes saved by %(name)s on %(date)s' ), - { - name: authorDisplayName, - date: formattedDate, - } + /* translators: %1$s author display name, %2$s: revision creation date */ + __( 'Changes saved by %1$s on %2$s' ), + authorDisplayName, + formattedDate ); } @@ -104,22 +98,14 @@ function RevisionsButtons( { userRevisions, selectedRevisionId, onChange } ) { { isUnsaved ? sprintf( - /* translators: %(name)s author display name */ - __( - 'Unsaved changes by %(name)s' - ), - { - name: authorDisplayName, - } + /* translators: %s author display name */ + __( 'Unsaved changes by %s' ), + authorDisplayName ) : sprintf( - /* translators: %(name)s author display name */ - __( - 'Changes saved by %(name)s' - ), - { - name: authorDisplayName, - } + /* translators: %s author display name */ + __( 'Changes saved by %s' ), + authorDisplayName ) } @@ -315,7 +318,13 @@ export default function Layout() { } initial={ false } layout="position" - className="edit-site-layout__canvas" + className={ classnames( + 'edit-site-layout__canvas', + { + 'is-right-aligned': + isResizableFrameOversized, + } + ) } transition={ { type: 'tween', duration: @@ -331,7 +340,12 @@ export default function Layout() { ! isEditorLoading } isFullWidth={ isEditing } - oversizedClassName="edit-site-layout__resizable-frame-oversized" + isOversized={ + isResizableFrameOversized + } + setIsOversized={ + setIsResizableFrameOversized + } innerContentStyle={ { background: gradientValue ?? diff --git a/packages/edit-site/src/components/layout/style.scss b/packages/edit-site/src/components/layout/style.scss index e5661c61eb7897..2fc8bbc6a5091e 100644 --- a/packages/edit-site/src/components/layout/style.scss +++ b/packages/edit-site/src/components/layout/style.scss @@ -121,7 +121,7 @@ justify-content: center; align-items: center; - &:has(.edit-site-layout__resizable-frame-oversized) { + &.is-right-aligned { justify-content: flex-end; } diff --git a/packages/edit-site/src/components/page-patterns/patterns-list.js b/packages/edit-site/src/components/page-patterns/patterns-list.js index 69bbcff7723002..9ebfc5dfe5c98f 100644 --- a/packages/edit-site/src/components/page-patterns/patterns-list.js +++ b/packages/edit-site/src/components/page-patterns/patterns-list.js @@ -27,7 +27,7 @@ import usePatterns from './use-patterns'; import SidebarButton from '../sidebar-button'; import useDebouncedInput from '../../utils/use-debounced-input'; import { unlock } from '../../lock-unlock'; -import { SYNC_TYPES, USER_PATTERN_CATEGORY } from './utils'; +import { SYNC_TYPES, USER_PATTERN_CATEGORY, PATTERNS } from './utils'; const { useLocation, useHistory } = unlock( routerPrivateApis ); @@ -58,9 +58,12 @@ export default function PatternsList( { categoryId, type } ) { const [ syncFilter, setSyncFilter ] = useState( 'all' ); const deferredSyncedFilter = useDeferredValue( syncFilter ); + const isUncategorizedThemePatterns = + type === PATTERNS && categoryId === 'uncategorized'; + const { patterns, isResolving } = usePatterns( type, - categoryId !== 'uncategorized' ? categoryId : '', + isUncategorizedThemePatterns ? '' : categoryId, { search: deferredFilterValue, syncStatus: diff --git a/packages/edit-site/src/components/page-patterns/use-patterns.js b/packages/edit-site/src/components/page-patterns/use-patterns.js index 66aba19e9b5b4f..37b4fcce6cfa7e 100644 --- a/packages/edit-site/src/components/page-patterns/use-patterns.js +++ b/packages/edit-site/src/components/page-patterns/use-patterns.js @@ -86,6 +86,7 @@ const selectThemePatterns = ( select, { categoryId, search = '' } = {} ) => { ( pattern ) => ! CORE_PATTERN_SOURCES.includes( pattern.source ) ) .filter( filterOutDuplicatesByName ) + .filter( ( pattern ) => pattern.inserter !== false ) .map( ( pattern ) => ( { ...pattern, keywords: pattern.keywords || [], diff --git a/packages/edit-site/src/components/resizable-frame/index.js b/packages/edit-site/src/components/resizable-frame/index.js index 1bb9315a07e38a..2b98e46a71532e 100644 --- a/packages/edit-site/src/components/resizable-frame/index.js +++ b/packages/edit-site/src/components/resizable-frame/index.js @@ -78,9 +78,10 @@ function calculateNewHeight( width, initialAspectRatio ) { function ResizableFrame( { isFullWidth, + isOversized, + setIsOversized, isReady, children, - oversizedClassName, innerContentStyle, } ) { const [ frameSize, setFrameSize ] = useState( INITIAL_FRAME_SIZE ); @@ -88,7 +89,6 @@ function ResizableFrame( { const [ startingWidth, setStartingWidth ] = useState(); const [ isResizing, setIsResizing ] = useState( false ); const [ shouldShowHandle, setShouldShowHandle ] = useState( false ); - const [ isOversized, setIsOversized ] = useState( false ); const [ resizeRatio, setResizeRatio ] = useState( 1 ); const canvasMode = useSelect( ( select ) => unlock( select( editSiteStore ) ).getCanvasMode(), @@ -314,7 +314,6 @@ function ResizableFrame( { onResizeStop={ handleResizeStop } className={ classnames( 'edit-site-resizable-frame__inner', { 'is-resizing': isResizing, - [ oversizedClassName ]: isOversized, } ) } > diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-patterns/use-theme-patterns.js b/packages/edit-site/src/components/sidebar-navigation-screen-patterns/use-theme-patterns.js index b4a0b570c3c8dd..bf6decf3414222 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-patterns/use-theme-patterns.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-patterns/use-theme-patterns.js @@ -36,7 +36,8 @@ export default function useThemePatterns() { ( pattern ) => ! CORE_PATTERN_SOURCES.includes( pattern.source ) ) - .filter( filterOutDuplicatesByName ), + .filter( filterOutDuplicatesByName ) + .filter( ( pattern ) => pattern.inserter !== false ), [ blockPatterns, restBlockPatterns ] ); diff --git a/packages/edit-site/src/components/site-hub/index.js b/packages/edit-site/src/components/site-hub/index.js index 1e6eddabe90a28..4ac1bea6c5b103 100644 --- a/packages/edit-site/src/components/site-hub/index.js +++ b/packages/edit-site/src/components/site-hub/index.js @@ -31,7 +31,7 @@ import { unlock } from '../../lock-unlock'; const HUB_ANIMATION_DURATION = 0.3; -const SiteHub = forwardRef( ( props, ref ) => { +const SiteHub = forwardRef( ( { isTransparent, ...restProps }, ref ) => { const { canvasMode, dashboardLink, homeUrl } = useSelect( ( select ) => { const { getCanvasMode, getSettings } = unlock( select( editSiteStore ) @@ -85,8 +85,11 @@ const SiteHub = forwardRef( ( props, ref ) => { return ( { spacing="0" > { exit={ { opacity: 0, } } - className="edit-site-site-hub__site-title" + className={ classnames( + 'edit-site-site-hub__site-title', + { 'is-transparent': isTransparent } + ) } transition={ { type: 'tween', duration: disableMotion ? 0 : 0.2, @@ -164,7 +175,7 @@ const SiteHub = forwardRef( ( props, ref ) => {