From b107e07a7e3847d751faf868a65e84228bb0cbae Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Tue, 18 Jul 2023 07:00:58 +0200 Subject: [PATCH 01/17] Filter out patterns that are not allowed in the inserter (#52675) --- .../edit-site/src/components/page-patterns/use-patterns.js | 1 + .../sidebar-navigation-screen-patterns/use-theme-patterns.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) 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/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 ] ); From 114a638c170762aba2055a690531959cdadd1d1a Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Tue, 18 Jul 2023 09:46:35 +0200 Subject: [PATCH 02/17] Remove autofocus and improve placeholder text consistency. (#52634) --- .../components/sidebar-edit-mode/page-panels/page-status.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-edit-mode/page-panels/page-status.js b/packages/edit-site/src/components/sidebar-edit-mode/page-panels/page-status.js index b872d4e12c25e9..ed41f8c2baa87e 100644 --- a/packages/edit-site/src/components/sidebar-edit-mode/page-panels/page-status.js +++ b/packages/edit-site/src/components/sidebar-edit-mode/page-panels/page-status.js @@ -212,11 +212,8 @@ export default function PageStatus( { } ) } value={ password } - /* eslint-disable jsx-a11y/no-autofocus */ - autoFocus={ ! password } - /* eslint-enable jsx-a11y/no-autofocus */ placeholder={ __( - 'Enter a secure password' + 'Use a secure password' ) } type="text" /> From 99d55d1e0572bf5a34a0f1b2446580dee7d2270c Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 18 Jul 2023 16:58:21 +0100 Subject: [PATCH 03/17] Do not navigate to the styles pages unless you're in a random listing page (#52728) --- .../src/hooks/commands/use-common-commands.js | 79 +++++++++++++------ 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/packages/edit-site/src/hooks/commands/use-common-commands.js b/packages/edit-site/src/hooks/commands/use-common-commands.js index dac547dc4d95c2..e10a04526bee13 100644 --- a/packages/edit-site/src/hooks/commands/use-common-commands.js +++ b/packages/edit-site/src/hooks/commands/use-common-commands.js @@ -11,15 +11,17 @@ import { privateApis as routerPrivateApis } from '@wordpress/router'; import { store as preferencesStore } from '@wordpress/preferences'; import { store as coreStore } from '@wordpress/core-data'; import { store as noticesStore } from '@wordpress/notices'; +import { useViewportMatch } from '@wordpress/compose'; /** * Internal dependencies */ import { unlock } from '../../lock-unlock'; import { store as editSiteStore } from '../../store'; +import getIsListPage from '../../utils/get-is-list-page'; const { useGlobalStylesReset } = unlock( blockEditorPrivateApis ); -const { useHistory } = unlock( routerPrivateApis ); +const { useHistory, useLocation } = unlock( routerPrivateApis ); function useGlobalStylesResetCommands() { const [ canReset, onReset ] = useGlobalStylesReset(); @@ -48,9 +50,12 @@ function useGlobalStylesResetCommands() { } function useGlobalStylesOpenCssCommands() { - const { openGeneralSidebar, setEditorCanvasContainerView } = unlock( - useDispatch( editSiteStore ) - ); + const { openGeneralSidebar, setEditorCanvasContainerView, setCanvasMode } = + unlock( useDispatch( editSiteStore ) ); + const { params } = useLocation(); + const isMobileViewport = useViewportMatch( 'medium', '<' ); + const isListPage = getIsListPage( params, isMobileViewport ); + const isEditorPage = ! isListPage; const history = useHistory(); const { canEditCSS } = useSelect( ( select ) => { const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = @@ -66,6 +71,7 @@ function useGlobalStylesOpenCssCommands() { !! globalStyles?._links?.[ 'wp:action-edit-css' ] ?? false, }; }, [] ); + const { getCanvasMode } = unlock( useSelect( editSiteStore ) ); const commands = useMemo( () => { if ( ! canEditCSS ) { @@ -79,10 +85,15 @@ function useGlobalStylesOpenCssCommands() { icon: styles, callback: ( { close } ) => { close(); - history.push( { - path: '/wp_global_styles', - canvas: 'edit', - } ); + if ( ! isEditorPage ) { + history.push( { + path: '/wp_global_styles', + canvas: 'edit', + } ); + } + if ( isEditorPage && getCanvasMode() !== 'edit' ) { + setCanvasMode( 'edit' ); + } openGeneralSidebar( 'edit-site/global-styles' ); setEditorCanvasContainerView( 'global-styles-css' ); }, @@ -93,6 +104,9 @@ function useGlobalStylesOpenCssCommands() { openGeneralSidebar, setEditorCanvasContainerView, canEditCSS, + isEditorPage, + getCanvasMode, + setCanvasMode, ] ); return { isLoading: false, @@ -101,9 +115,13 @@ function useGlobalStylesOpenCssCommands() { } export function useCommonCommands() { - const { openGeneralSidebar, setEditorCanvasContainerView } = unlock( - useDispatch( editSiteStore ) - ); + const { openGeneralSidebar, setEditorCanvasContainerView, setCanvasMode } = + unlock( useDispatch( editSiteStore ) ); + const { params } = useLocation(); + const isMobileViewport = useViewportMatch( 'medium', '<' ); + const isListPage = getIsListPage( params, isMobileViewport ); + const isEditorPage = ! isListPage; + const { getCanvasMode } = unlock( useSelect( editSiteStore ) ); const { set } = useDispatch( preferencesStore ); const { createInfoNotice } = useDispatch( noticesStore ); const history = useHistory(); @@ -127,10 +145,15 @@ export function useCommonCommands() { icon: backup, callback: ( { close } ) => { close(); - history.push( { - path: '/wp_global_styles', - canvas: 'edit', - } ); + if ( ! isEditorPage ) { + history.push( { + path: '/wp_global_styles', + canvas: 'edit', + } ); + } + if ( isEditorPage && getCanvasMode() !== 'edit' ) { + setCanvasMode( 'edit' ); + } openGeneralSidebar( 'edit-site/global-styles' ); setEditorCanvasContainerView( 'global-styles-revisions' ); }, @@ -141,10 +164,15 @@ export function useCommonCommands() { label: __( 'Open styles' ), callback: ( { close } ) => { close(); - history.push( { - path: '/wp_global_styles', - canvas: 'edit', - } ); + if ( ! isEditorPage ) { + history.push( { + path: '/wp_global_styles', + canvas: 'edit', + } ); + } + if ( isEditorPage && getCanvasMode() !== 'edit' ) { + setCanvasMode( 'edit' ); + } if ( isDistractionFree ) { set( editSiteStore.name, 'distractionFree', false ); createInfoNotice( __( 'Distraction free mode turned off.' ), { @@ -161,10 +189,15 @@ export function useCommonCommands() { label: __( 'Learn about styles' ), callback: ( { close } ) => { close(); - history.push( { - path: '/wp_global_styles', - canvas: 'edit', - } ); + if ( ! isEditorPage ) { + history.push( { + path: '/wp_global_styles', + canvas: 'edit', + } ); + } + if ( isEditorPage && getCanvasMode() !== 'edit' ) { + setCanvasMode( 'edit' ); + } openGeneralSidebar( 'edit-site/global-styles' ); set( 'core/edit-site', 'welcomeGuideStyles', true ); // sometimes there's a focus loss that happens after some time From 88e1896d29a8d1b9fe2eff64b32d931c889ac369 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 19 Jul 2023 15:10:04 +1200 Subject: [PATCH 04/17] Patterns: Don't override the rootClientID in create menu - only set if undefined (#52713) --- .../reusable-blocks-menu-items/index.js | 22 ++++++------------- .../reusable-block-convert-button.js | 15 ++++++++++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js index d7823483f5e09e..6affb00479b308 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { withSelect } from '@wordpress/data'; +import { useSelect } from '@wordpress/data'; import { store as blockEditorStore } from '@wordpress/block-editor'; /** @@ -10,7 +10,12 @@ import { store as blockEditorStore } from '@wordpress/block-editor'; import ReusableBlockConvertButton from './reusable-block-convert-button'; import ReusableBlocksManageButton from './reusable-blocks-manage-button'; -function ReusableBlocksMenuItems( { clientIds, rootClientId } ) { +export default function ReusableBlocksMenuItems( { rootClientId } ) { + const clientIds = useSelect( + ( select ) => select( blockEditorStore ).getSelectedBlockClientIds(), + [] + ); + return ( <> ); } - -export default withSelect( ( select ) => { - const { getSelectedBlockClientIds, getBlockRootClientId } = - select( blockEditorStore ); - const clientIds = getSelectedBlockClientIds(); - return { - clientIds, - rootClientId: - clientIds?.length > 0 - ? getBlockRootClientId( clientIds[ 0 ] ) - : undefined, - }; -} )( ReusableBlocksMenuItems ); diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js index 2dfd635e2963a3..7f7ab7e50e66eb 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js @@ -51,8 +51,17 @@ export default function ReusableBlockConvertButton( { const canConvert = useSelect( ( select ) => { const { canUser } = select( coreStore ); - const { getBlocksByClientId, canInsertBlockType } = - select( blockEditorStore ); + const { + getBlocksByClientId, + canInsertBlockType, + getBlockRootClientId, + } = select( blockEditorStore ); + + const rootId = + rootClientId || + ( clientIds.length > 0 + ? getBlockRootClientId( clientIds[ 0 ] ) + : undefined ); const blocks = getBlocksByClientId( clientIds ) ?? []; @@ -70,7 +79,7 @@ export default function ReusableBlockConvertButton( { // Hide when this is already a reusable block. ! isReusable && // Hide when reusable blocks are disabled. - canInsertBlockType( 'core/block', rootClientId ) && + canInsertBlockType( 'core/block', rootId ) && blocks.every( ( block ) => // Guard against the case where a regular block has *just* been converted. From 5a3ac1945021d17e2cfd6204418d5e205f98c6e1 Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Wed, 19 Jul 2023 19:03:37 +0200 Subject: [PATCH 05/17] Footnotes: store in revisions (#52686) --- .../block-library/src/footnotes/index.php | 126 ++++++++++++++++++ .../specs/editor/various/footnotes.spec.js | 86 +++++++++++- 2 files changed, 210 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index e4bd8dcdeaac2e..d3bee136725947 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -78,3 +78,129 @@ 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. + * + * @param int $revision_id The revision ID. + */ + 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. + */ + 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. + * + * @param WP_Post $post The post object. + */ + 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. + * + * @param int $post_id The post ID. + * @param int $revision_id The revision ID. + */ + 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. + * + * @param array $fields The revision fields. + * + * @return array The revision fields. + */ + function( $fields ) { + $fields['footnotes'] = __( 'Footnotes' ); + return $fields; + } +); + +add_filter( + 'wp_post_revision_field_footnotes', + /** + * Gets the footnotes field from the revision. + * + * @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. + */ + function( $revision_field, $field, $revision ) { + return get_metadata( 'post', $revision->ID, $field, true ); + }, + 10, + 3 +); diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index 376962b5c99ba7..ad3ab149095d2e 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -3,9 +3,11 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -async function getFootnotes( page ) { +async function getFootnotes( page, withoutSave = false ) { // Save post so we can check meta. - await page.click( 'button:text("Save draft")' ); + if ( ! withoutSave ) { + await page.click( 'button:text("Save draft")' ); + } await page.waitForSelector( 'button:text("Saved")' ); const footnotes = await page.evaluate( () => { return window.wp.data @@ -278,4 +280,84 @@ test.describe( 'Footnotes', () => { }, ] ); } ); + + test( 'works with revisions', async ( { editor, page } ) => { + await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await page.keyboard.type( 'first paragraph' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( 'second paragraph' ); + + await editor.showBlockToolbar(); + await editor.clickBlockToolbarButton( 'More' ); + await page.locator( 'button:text("Footnote")' ).click(); + + await page.keyboard.type( 'first footnote' ); + + const id1 = await editor.canvas.evaluate( () => { + return document.activeElement.id; + } ); + + await editor.canvas.click( 'p:text("first paragraph")' ); + + await editor.showBlockToolbar(); + await editor.clickBlockToolbarButton( 'More' ); + await page.locator( 'button:text("Footnote")' ).click(); + + await page.keyboard.type( 'second footnote' ); + + const id2 = await editor.canvas.evaluate( () => { + return document.activeElement.id; + } ); + + // This also saves the post! + expect( await getFootnotes( page ) ).toMatchObject( [ + { + content: 'second footnote', + id: id2, + }, + { + content: 'first footnote', + id: id1, + }, + ] ); + + await editor.canvas.click( 'p:text("first paragraph")' ); + + await editor.showBlockToolbar(); + await editor.clickBlockToolbarButton( 'Move down' ); + + // This also saves the post! + expect( await getFootnotes( page ) ).toMatchObject( [ + { + content: 'first footnote', + id: id1, + }, + { + content: 'second footnote', + id: id2, + }, + ] ); + + // Open revisions. + await editor.openDocumentSettingsSidebar(); + await page + .getByRole( 'region', { name: 'Editor settings' } ) + .getByRole( 'button', { name: 'Post' } ) + .click(); + await page.locator( 'a:text("2 Revisions")' ).click(); + await page.locator( '.revisions-controls .ui-slider-handle' ).focus(); + await page.keyboard.press( 'ArrowLeft' ); + await page.locator( 'input:text("Restore This Revision")' ).click(); + + expect( await getFootnotes( page, true ) ).toMatchObject( [ + { + content: 'second footnote', + id: id2, + }, + { + content: 'first footnote', + id: id1, + }, + ] ); + } ); } ); From c77d9f5450d8b808f11eec2c212ac35553a9a54c Mon Sep 17 00:00:00 2001 From: James Koster Date: Wed, 19 Jul 2023 18:48:59 +0100 Subject: [PATCH 06/17] Fix: Block toolbar obscuring document tools when Top Toolbar is enabled (#52722) * Update toolbar width * Site editor needs specific width * fixes top toolbar width for post editor when not in fullscreen * remove the body rule --------- Co-authored-by: Andrei Draganescu --- packages/block-editor/src/components/block-tools/style.scss | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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}); } } - } /** From ffd69e07852135fd69542eb62a025eea31b661f7 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 20 Jul 2023 09:10:42 +1200 Subject: [PATCH 07/17] Site Editor: Fix site link accessibility issues (#52744) --- packages/edit-site/src/components/site-hub/index.js | 2 +- packages/edit-site/src/components/site-hub/style.scss | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/site-hub/index.js b/packages/edit-site/src/components/site-hub/index.js index 1e6eddabe90a28..91eecbcbcb59fb 100644 --- a/packages/edit-site/src/components/site-hub/index.js +++ b/packages/edit-site/src/components/site-hub/index.js @@ -164,7 +164,7 @@ const SiteHub = forwardRef( ( props, ref ) => {