From 7d73069e918aa3671ed0787cf223d8bd5dcc634d Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 17 Nov 2023 15:11:51 +0100 Subject: [PATCH 1/5] PostFormat suggestion: fix double parsing --- packages/editor/src/store/selectors.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index a2bbf0f47770f..d82e5ecb16e06 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -10,7 +10,6 @@ import { getFreeformContentHandlerName, getDefaultBlockName, __unstableSerializeAndClean, - parse, } from '@wordpress/blocks'; import { isInTheFuture, getDate } from '@wordpress/date'; import { addQueryArgs, cleanForSlug } from '@wordpress/url'; @@ -1102,16 +1101,8 @@ export const isPublishSidebarEnabled = createRegistrySelector( * @return {Array} Block list. */ export const getEditorBlocks = createSelector( - ( state ) => { - return ( - getEditedPostAttribute( state, 'blocks' ) || - parse( getEditedPostContent( state ) ) - ); - }, - ( state ) => [ - getEditedPostAttribute( state, 'blocks' ), - getEditedPostContent( state ), - ] + () => getBlocks(), + () => [ getBlocks() ] ); /** From 19bb9fe4b3da094f92d9d0b32ea408faebbe1ed4 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 17 Nov 2023 15:48:29 +0100 Subject: [PATCH 2/5] Don't use deprecated fn --- docs/reference-guides/data/data-core-editor.md | 4 ---- packages/editor/src/store/selectors.js | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/docs/reference-guides/data/data-core-editor.md b/docs/reference-guides/data/data-core-editor.md index 5dbcb095bbf08..db70d29c16696 100644 --- a/docs/reference-guides/data/data-core-editor.md +++ b/docs/reference-guides/data/data-core-editor.md @@ -321,10 +321,6 @@ _Returns_ Return the current block list. -_Parameters_ - -- _state_ `Object`: - _Returns_ - `Array`: Block list. diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index d82e5ecb16e06..d44e5ae6f0f87 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1097,12 +1097,10 @@ export const isPublishSidebarEnabled = createRegistrySelector( /** * Return the current block list. * - * @param {Object} state * @return {Array} Block list. */ -export const getEditorBlocks = createSelector( - () => getBlocks(), - () => [ getBlocks() ] +export const getEditorBlocks = createRegistrySelector( + ( select ) => () => select( blockEditorStore ).getBlocks() ); /** From 8bb2845023b1fed77a305d7eb689465f0bd2442d Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 17 Nov 2023 17:00:54 +0100 Subject: [PATCH 3/5] Move to util --- .../reference-guides/data/data-core-editor.md | 6 +- .../src/components/post-format/index.js | 27 +-- .../maybe-post-format-panel.js | 31 ++- .../post-publish-panel/maybe-upload-media.js | 21 +- .../src/components/provider/index.native.js | 10 +- packages/editor/src/store/selectors.js | 51 +--- packages/editor/src/store/test/selectors.js | 228 ------------------ .../src/utils/get-suggested-post-format.js | 51 ++++ .../utils/test/get-suggested-post-format.js | 132 ++++++++++ 9 files changed, 233 insertions(+), 324 deletions(-) create mode 100644 packages/editor/src/utils/get-suggested-post-format.js create mode 100644 packages/editor/src/utils/test/get-suggested-post-format.js diff --git a/docs/reference-guides/data/data-core-editor.md b/docs/reference-guides/data/data-core-editor.md index db70d29c16696..6e1404772370e 100644 --- a/docs/reference-guides/data/data-core-editor.md +++ b/docs/reference-guides/data/data-core-editor.md @@ -529,11 +529,9 @@ Returns state object prior to a specified optimist transaction ID, or `null` if ### getSuggestedPostFormat -Returns a suggested post format for the current post, inferred only if there is a single block within the post and it is of a type known to match a default post format. Returns null if the format cannot be determined. - -_Parameters_ +> **Deprecated** -- _state_ `Object`: Global application state. +Returns a suggested post format for the current post, inferred only if there is a single block within the post and it is of a type known to match a default post format. Returns null if the format cannot be determined. _Returns_ diff --git a/packages/editor/src/components/post-format/index.js b/packages/editor/src/components/post-format/index.js index 2b422ccebbaa8..7846a9786fa5c 100644 --- a/packages/editor/src/components/post-format/index.js +++ b/packages/editor/src/components/post-format/index.js @@ -6,12 +6,14 @@ import { Button, SelectControl } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { useInstanceId } from '@wordpress/compose'; import { store as coreStore } from '@wordpress/core-data'; +import { store as blockEditorStore } from '@wordpress/block-editor'; /** * Internal dependencies */ import PostFormatCheck from './check'; import { store as editorStore } from '../../store'; +import { getSuggestedPostFormat } from '../../utils/get-suggested-post-format'; // All WP post formats, sorted alphabetically by translated name. export const POST_FORMATS = [ @@ -42,20 +44,17 @@ export default function PostFormat() { const instanceId = useInstanceId( PostFormat ); const postFormatSelectorId = `post-format-selector-${ instanceId }`; - const { postFormat, suggestedFormat, supportedFormats } = useSelect( - ( select ) => { - const { getEditedPostAttribute, getSuggestedPostFormat } = - select( editorStore ); - const _postFormat = getEditedPostAttribute( 'format' ); - const themeSupports = select( coreStore ).getThemeSupports(); - return { - postFormat: _postFormat ?? 'standard', - suggestedFormat: getSuggestedPostFormat(), - supportedFormats: themeSupports.formats, - }; - }, - [] - ); + const { postFormat, blocks, supportedFormats } = useSelect( ( select ) => { + const { getEditedPostAttribute } = select( editorStore ); + const _postFormat = getEditedPostAttribute( 'format' ); + const themeSupports = select( coreStore ).getThemeSupports(); + return { + postFormat: _postFormat ?? 'standard', + blocks: select( blockEditorStore ).getBlocks(), + supportedFormats: themeSupports.formats, + }; + }, [] ); + const suggestedFormat = getSuggestedPostFormat( blocks ); const formats = POST_FORMATS.filter( ( format ) => { // Ensure current format is always in the set. diff --git a/packages/editor/src/components/post-publish-panel/maybe-post-format-panel.js b/packages/editor/src/components/post-publish-panel/maybe-post-format-panel.js index 4555b33dbb9ef..dc375ee9b9d0e 100644 --- a/packages/editor/src/components/post-publish-panel/maybe-post-format-panel.js +++ b/packages/editor/src/components/post-publish-panel/maybe-post-format-panel.js @@ -5,12 +5,14 @@ import { Button, PanelBody } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; import { store as coreStore } from '@wordpress/core-data'; +import { store as blockEditorStore } from '@wordpress/block-editor'; /** * Internal dependencies */ import { POST_FORMATS } from '../post-format'; import { store as editorStore } from '../../store'; +import { getSuggestedPostFormat } from '../../utils/get-suggested-post-format'; const getSuggestion = ( supportedFormats, suggestedPostFormat ) => { const formats = POST_FORMATS.filter( ( format ) => @@ -33,19 +35,22 @@ const PostFormatSuggestion = ( { ); export default function PostFormatPanel() { - const { currentPostFormat, suggestion } = useSelect( ( select ) => { - const { getEditedPostAttribute, getSuggestedPostFormat } = - select( editorStore ); - const supportedFormats = - select( coreStore ).getThemeSupports().formats ?? []; - return { - currentPostFormat: getEditedPostAttribute( 'format' ), - suggestion: getSuggestion( - supportedFormats, - getSuggestedPostFormat() - ), - }; - }, [] ); + const { currentPostFormat, supportedFormats, blocks } = useSelect( + ( select ) => { + const { getEditedPostAttribute } = select( editorStore ); + return { + currentPostFormat: getEditedPostAttribute( 'format' ), + supportedFormats: + select( coreStore ).getThemeSupports().formats, + blocks: select( blockEditorStore ).getBlocks(), + }; + }, + [] + ); + const suggestion = getSuggestion( + supportedFormats ?? [], + getSuggestedPostFormat( blocks ) + ); const { editPost } = useDispatch( editorStore ); diff --git a/packages/editor/src/components/post-publish-panel/maybe-upload-media.js b/packages/editor/src/components/post-publish-panel/maybe-upload-media.js index 0097b3f0ea741..9b7a24ac1abb0 100644 --- a/packages/editor/src/components/post-publish-panel/maybe-upload-media.js +++ b/packages/editor/src/components/post-publish-panel/maybe-upload-media.js @@ -15,11 +15,6 @@ import { store as blockEditorStore } from '@wordpress/block-editor'; import { useState } from '@wordpress/element'; import { isBlobURL } from '@wordpress/blob'; -/** - * Internal dependencies - */ -import { store as editorStore } from '../../store'; - function flattenBlocks( blocks ) { const result = []; @@ -66,14 +61,14 @@ function Image( block ) { export default function PostFormatPanel() { const [ isUploading, setIsUploading ] = useState( false ); - const { editorBlocks, mediaUpload } = useSelect( - ( select ) => ( { - editorBlocks: select( editorStore ).getEditorBlocks(), - mediaUpload: select( blockEditorStore ).getSettings().mediaUpload, - } ), - [] - ); - const externalImages = flattenBlocks( editorBlocks ).filter( + const { blocks, mediaUpload } = useSelect( ( select ) => { + const { getEditorBlocks, getSettings } = select( blockEditorStore ); + return { + blocks: getEditorBlocks(), + mediaUpload: getSettings().mediaUpload, + }; + }, [] ); + const externalImages = flattenBlocks( blocks ).filter( ( block ) => block.name === 'core/image' && block.attributes.url && diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 5fd6a4cdbb888..1f81b76c806aa 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -25,7 +25,6 @@ import { Component } from '@wordpress/element'; import { count as wordCount } from '@wordpress/wordcount'; import { parse, - serialize, getUnregisteredTypeHandlerName, createBlock, } from '@wordpress/blocks'; @@ -256,7 +255,9 @@ class NativeEditorProvider extends Component { componentDidUpdate( prevProps ) { if ( ! prevProps.isReady && this.props.isReady ) { - const blocks = this.props.blocks; + const blocks = + this.props.getEditedPostAttribute( 'blocks' ) || + parse( this.props.getEditedPostContent() ); const isUnsupportedBlock = ( { name } ) => name === getUnregisteredTypeHandlerName(); const unsupportedBlockNames = blocks @@ -277,7 +278,7 @@ class NativeEditorProvider extends Component { // Let's request the HTML from the component's state directly. html = applyFilters( 'native.persist-html' ); } else { - html = serialize( this.props.blocks ); + html = this.props.getEditedPostContent(); } const hasChanges = @@ -354,7 +355,6 @@ const ComposedNativeProvider = compose( [ withSelect( ( select ) => { const { __unstableIsEditorReady: isEditorReady, - getEditorBlocks, getEditedPostAttribute, getEditedPostContent, getEditorSettings, @@ -372,8 +372,8 @@ const ComposedNativeProvider = compose( [ return { mode: getEditorMode(), isReady: isEditorReady(), - blocks: getEditorBlocks(), title: getEditedPostAttribute( 'title' ), + getEditedPostAttribute, getEditedPostContent, defaultEditorColors, defaultEditorGradients, diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index d44e5ae6f0f87..47bf2f13f4254 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -818,53 +818,12 @@ export function getEditedPostPreviewLink( state ) { * is a single block within the post and it is of a type known to match a * default post format. Returns null if the format cannot be determined. * - * @param {Object} state Global application state. + * @deprecated * * @return {?string} Suggested post format. */ -export function getSuggestedPostFormat( state ) { - const blocks = getEditorBlocks( state ); - - if ( blocks.length > 2 ) return null; - - let name; - // If there is only one block in the content of the post grab its name - // so we can derive a suitable post format from it. - if ( blocks.length === 1 ) { - name = blocks[ 0 ].name; - // Check for core/embed `video` and `audio` eligible suggestions. - if ( name === 'core/embed' ) { - const provider = blocks[ 0 ].attributes?.providerNameSlug; - if ( [ 'youtube', 'vimeo' ].includes( provider ) ) { - name = 'core/video'; - } else if ( [ 'spotify', 'soundcloud' ].includes( provider ) ) { - name = 'core/audio'; - } - } - } - - // If there are two blocks in the content and the last one is a text blocks - // grab the name of the first one to also suggest a post format from it. - if ( blocks.length === 2 && blocks[ 1 ].name === 'core/paragraph' ) { - name = blocks[ 0 ].name; - } - - // We only convert to default post formats in core. - switch ( name ) { - case 'core/image': - return 'image'; - case 'core/quote': - case 'core/pullquote': - return 'quote'; - case 'core/gallery': - return 'gallery'; - case 'core/video': - return 'video'; - case 'core/audio': - return 'audio'; - default: - return null; - } +export function getSuggestedPostFormat() { + return null; } /** @@ -1099,9 +1058,7 @@ export const isPublishSidebarEnabled = createRegistrySelector( * * @return {Array} Block list. */ -export const getEditorBlocks = createRegistrySelector( - ( select ) => () => select( blockEditorStore ).getBlocks() -); +export const getEditorBlocks = getBlockEditorSelector( 'getBlocks' ); /** * A block selection object. diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js index c18377c4e385e..d421949d13438 100644 --- a/packages/editor/src/store/test/selectors.js +++ b/packages/editor/src/store/test/selectors.js @@ -169,7 +169,6 @@ const { isSavingNonPostEntityChanges, didPostSaveRequestSucceed, didPostSaveRequestFail, - getSuggestedPostFormat, getEditedPostContent, isPermalinkEditable, getPermalink, @@ -2152,233 +2151,6 @@ describe( 'selectors', () => { } ); } ); - describe( 'getSuggestedPostFormat', () => { - it( 'returns null if cannot be determined', () => { - const state = { - editor: { - present: { - blocks: { - value: [], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - - expect( getSuggestedPostFormat( state ) ).toBeNull(); - } ); - - it( 'return null if only one block of type `core/embed` and provider not matched', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 567, - name: 'core/embed', - attributes: { - providerNameSlug: 'instagram', - }, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - expect( getSuggestedPostFormat( state ) ).toBeNull(); - } ); - - it( 'return null if only one block of type `core/embed` and provider not exists', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 567, - name: 'core/embed', - attributes: {}, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - expect( getSuggestedPostFormat( state ) ).toBeNull(); - } ); - - it( 'returns null if there is more than one block in the post', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 123, - name: 'core/image', - attributes: {}, - innerBlocks: [], - }, - { - clientId: 456, - name: 'core/quote', - attributes: {}, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - - expect( getSuggestedPostFormat( state ) ).toBeNull(); - } ); - - it( 'returns Image if the first block is of type `core/image`', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 123, - name: 'core/image', - attributes: {}, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - - expect( getSuggestedPostFormat( state ) ).toBe( 'image' ); - } ); - - it( 'returns Quote if the first block is of type `core/quote`', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 456, - name: 'core/quote', - attributes: {}, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - - expect( getSuggestedPostFormat( state ) ).toBe( 'quote' ); - } ); - - it( 'returns Video if the first block is of type `core/embed from youtube`', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 567, - name: 'core/embed', - attributes: { - providerNameSlug: 'youtube', - }, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - - expect( getSuggestedPostFormat( state ) ).toBe( 'video' ); - } ); - - it( 'returns Audio if the first block is of type `core/embed from soundcloud`', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 567, - name: 'core/embed', - attributes: { - providerNameSlug: 'soundcloud', - }, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - - expect( getSuggestedPostFormat( state ) ).toBe( 'audio' ); - } ); - - it( 'returns Quote if the first block is of type `core/quote` and second is of type `core/paragraph`', () => { - const state = { - editor: { - present: { - blocks: { - value: [ - { - clientId: 456, - name: 'core/quote', - attributes: {}, - innerBlocks: [], - }, - { - clientId: 789, - name: 'core/paragraph', - attributes: {}, - innerBlocks: [], - }, - ], - }, - edits: {}, - }, - }, - initialEdits: {}, - currentPost: {}, - }; - - expect( getSuggestedPostFormat( state ) ).toBe( 'quote' ); - } ); - } ); - describe( 'getEditedPostContent', () => { let originalDefaultBlockName; diff --git a/packages/editor/src/utils/get-suggested-post-format.js b/packages/editor/src/utils/get-suggested-post-format.js new file mode 100644 index 0000000000000..fe9b86f3b7c23 --- /dev/null +++ b/packages/editor/src/utils/get-suggested-post-format.js @@ -0,0 +1,51 @@ +/** + * Returns a suggested post format for the given blocks, inferred only if there + * is a single block within the post and it is of a type known to match a + * default post format. Returns null if the format cannot be determined. + * + * @param {Array} blocks The blocks to check. + * + * @return {?string} Suggested post format. + */ +export function getSuggestedPostFormat( blocks ) { + if ( blocks.length > 2 ) return null; + + let name; + // If there is only one block in the content of the post grab its name + // so we can derive a suitable post format from it. + if ( blocks.length === 1 ) { + name = blocks[ 0 ].name; + // Check for core/embed `video` and `audio` eligible suggestions. + if ( name === 'core/embed' ) { + const provider = blocks[ 0 ].attributes?.providerNameSlug; + if ( [ 'youtube', 'vimeo' ].includes( provider ) ) { + name = 'core/video'; + } else if ( [ 'spotify', 'soundcloud' ].includes( provider ) ) { + name = 'core/audio'; + } + } + } + + // If there are two blocks in the content and the last one is a text blocks + // grab the name of the first one to also suggest a post format from it. + if ( blocks.length === 2 && blocks[ 1 ].name === 'core/paragraph' ) { + name = blocks[ 0 ].name; + } + + // We only convert to default post formats in core. + switch ( name ) { + case 'core/image': + return 'image'; + case 'core/quote': + case 'core/pullquote': + return 'quote'; + case 'core/gallery': + return 'gallery'; + case 'core/video': + return 'video'; + case 'core/audio': + return 'audio'; + default: + return null; + } +} diff --git a/packages/editor/src/utils/test/get-suggested-post-format.js b/packages/editor/src/utils/test/get-suggested-post-format.js new file mode 100644 index 0000000000000..437a61bc09f3b --- /dev/null +++ b/packages/editor/src/utils/test/get-suggested-post-format.js @@ -0,0 +1,132 @@ +/** + * Internal dependencies + */ +import { getSuggestedPostFormat } from '../get-suggested-post-format'; + +describe( 'getSuggestedPostFormat', () => { + it( 'returns null if cannot be determined', () => { + const blocks = []; + + expect( getSuggestedPostFormat( blocks ) ).toBeNull(); + } ); + + it( 'return null if only one block of type `core/embed` and provider not matched', () => { + const blocks = [ + { + clientId: 567, + name: 'core/embed', + attributes: { + providerNameSlug: 'instagram', + }, + innerBlocks: [], + }, + ]; + expect( getSuggestedPostFormat( blocks ) ).toBeNull(); + } ); + + it( 'return null if only one block of type `core/embed` and provider not exists', () => { + const blocks = [ + { + clientId: 567, + name: 'core/embed', + attributes: {}, + innerBlocks: [], + }, + ]; + expect( getSuggestedPostFormat( blocks ) ).toBeNull(); + } ); + + it( 'returns null if there is more than one block in the post', () => { + const blocks = [ + { + clientId: 123, + name: 'core/image', + attributes: {}, + innerBlocks: [], + }, + { + clientId: 456, + name: 'core/quote', + attributes: {}, + innerBlocks: [], + }, + ]; + + expect( getSuggestedPostFormat( blocks ) ).toBeNull(); + } ); + + it( 'returns Image if the first block is of type `core/image`', () => { + const blocks = [ + { + clientId: 123, + name: 'core/image', + attributes: {}, + innerBlocks: [], + }, + ]; + + expect( getSuggestedPostFormat( blocks ) ).toBe( 'image' ); + } ); + + it( 'returns Quote if the first block is of type `core/quote`', () => { + const blocks = [ + { + clientId: 456, + name: 'core/quote', + attributes: {}, + innerBlocks: [], + }, + ]; + + expect( getSuggestedPostFormat( blocks ) ).toBe( 'quote' ); + } ); + + it( 'returns Video if the first block is of type `core/embed from youtube`', () => { + const blocks = [ + { + clientId: 567, + name: 'core/embed', + attributes: { + providerNameSlug: 'youtube', + }, + innerBlocks: [], + }, + ]; + + expect( getSuggestedPostFormat( blocks ) ).toBe( 'video' ); + } ); + + it( 'returns Audio if the first block is of type `core/embed from soundcloud`', () => { + const blocks = [ + { + clientId: 567, + name: 'core/embed', + attributes: { + providerNameSlug: 'soundcloud', + }, + innerBlocks: [], + }, + ]; + + expect( getSuggestedPostFormat( blocks ) ).toBe( 'audio' ); + } ); + + it( 'returns Quote if the first block is of type `core/quote` and second is of type `core/paragraph`', () => { + const blocks = [ + { + clientId: 456, + name: 'core/quote', + attributes: {}, + innerBlocks: [], + }, + { + clientId: 789, + name: 'core/paragraph', + attributes: {}, + innerBlocks: [], + }, + ]; + + expect( getSuggestedPostFormat( blocks ) ).toBe( 'quote' ); + } ); +} ); From d88430ad9117809ae668209cc48cdd16653563a6 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 17 Nov 2023 17:21:07 +0100 Subject: [PATCH 4/5] Fix native --- packages/editor/src/components/provider/index.native.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 1f81b76c806aa..07b425d2f6a59 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -25,6 +25,7 @@ import { Component } from '@wordpress/element'; import { count as wordCount } from '@wordpress/wordcount'; import { parse, + serialize, getUnregisteredTypeHandlerName, createBlock, } from '@wordpress/blocks'; @@ -278,7 +279,10 @@ class NativeEditorProvider extends Component { // Let's request the HTML from the component's state directly. html = applyFilters( 'native.persist-html' ); } else { - html = this.props.getEditedPostContent(); + const blocks = this.props.getEditedPostAttribute( 'blocks' ); + html = blocks?.length + ? serialize( blocks ) + : this.props.getEditedPostContent(); } const hasChanges = From 2746a6392d1946ec3ba85a681361f1b868d08acd Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 17 Nov 2023 17:43:32 +0100 Subject: [PATCH 5/5] Fix typo --- .../src/components/post-publish-panel/maybe-upload-media.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/components/post-publish-panel/maybe-upload-media.js b/packages/editor/src/components/post-publish-panel/maybe-upload-media.js index 9b7a24ac1abb0..318e54af67921 100644 --- a/packages/editor/src/components/post-publish-panel/maybe-upload-media.js +++ b/packages/editor/src/components/post-publish-panel/maybe-upload-media.js @@ -62,9 +62,9 @@ function Image( block ) { export default function PostFormatPanel() { const [ isUploading, setIsUploading ] = useState( false ); const { blocks, mediaUpload } = useSelect( ( select ) => { - const { getEditorBlocks, getSettings } = select( blockEditorStore ); + const { getBlocks, getSettings } = select( blockEditorStore ); return { - blocks: getEditorBlocks(), + blocks: getBlocks(), mediaUpload: getSettings().mediaUpload, }; }, [] );