diff --git a/package-lock.json b/package-lock.json index de4627eb245adb..e078fdc71484c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53415,7 +53415,6 @@ "dependencies": { "@babel/runtime": "7.25.7", "@wordpress/api-fetch": "*", - "@wordpress/block-editor": "*", "@wordpress/blocks": "*", "@wordpress/compose": "*", "@wordpress/data": "*", diff --git a/packages/block-editor/src/components/inner-blocks/index.js b/packages/block-editor/src/components/inner-blocks/index.js index ae587720278200..1ed0ce36abc60f 100644 --- a/packages/block-editor/src/components/inner-blocks/index.js +++ b/packages/block-editor/src/components/inner-blocks/index.js @@ -13,6 +13,7 @@ import { getBlockSupport, store as blocksStore, __unstableGetInnerBlocksProps as getInnerBlocksProps, + InnerBlocksContent, } from '@wordpress/blocks'; /** @@ -309,7 +310,7 @@ useInnerBlocksProps.save = getInnerBlocksProps; ForwardedInnerBlocks.DefaultBlockAppender = DefaultBlockAppender; ForwardedInnerBlocks.ButtonBlockAppender = ButtonBlockAppender; -ForwardedInnerBlocks.Content = () => useInnerBlocksProps.save().children; +ForwardedInnerBlocks.Content = InnerBlocksContent; /** * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inner-blocks/README.md diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 768ffbb0cdd2dc..827f848ca56b75 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -20,7 +20,11 @@ import { removeFormat, } from '@wordpress/rich-text'; import { Popover } from '@wordpress/components'; -import { getBlockBindingsSource } from '@wordpress/blocks'; +import { + getBlockBindingsSource, + RichTextContent, + valueToHTMLString, +} from '@wordpress/blocks'; import deprecated from '@wordpress/deprecated'; import { __, sprintf } from '@wordpress/i18n'; @@ -37,7 +41,6 @@ import { useFormatTypes } from './use-format-types'; import { useEventListeners } from './event-listeners'; import FormatEdit from './format-edit'; import { getAllowedFormats } from './utils'; -import { Content, valueToHTMLString } from './content'; import { withDeprecations } from './with-deprecations'; import { canBindBlock } from '../../utils/block-bindings'; import BlockContext from '../block-context'; @@ -504,7 +507,7 @@ export const PrivateRichText = withDeprecations( forwardRef( RichTextWrapper ) ); -PrivateRichText.Content = Content; +PrivateRichText.Content = RichTextContent; PrivateRichText.isEmpty = ( value ) => { return ! value || value.length === 0; }; @@ -562,7 +565,7 @@ const PublicForwardedRichTextContainer = forwardRef( ( props, ref ) => { return ; } ); -PublicForwardedRichTextContainer.Content = Content; +PublicForwardedRichTextContainer.Content = RichTextContent; PublicForwardedRichTextContainer.isEmpty = ( value ) => { return ! value || value.length === 0; }; diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index 687c2759c05de2..6b44d4108f75a9 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -14,6 +14,7 @@ import { getBlockTransforms, findTransform, isUnmodifiedDefaultBlock, + RichTextContent, } from '@wordpress/blocks'; import { useInstanceId, useMergeRefs } from '@wordpress/compose'; import { @@ -42,7 +43,6 @@ import { createLinkInParagraph, } from './utils'; import EmbedHandlerPicker from './embed-handler-picker'; -import { Content } from './content'; import RichText from './native'; import { withDeprecations } from './with-deprecations'; import { findSelection } from './event-listeners/input-rules'; @@ -679,7 +679,7 @@ export const PrivateRichText = withDeprecations( forwardRef( RichTextWrapper ) ); -PrivateRichText.Content = Content; +PrivateRichText.Content = RichTextContent; PrivateRichText.isEmpty = ( value ) => { return ! value || value.length === 0; diff --git a/packages/block-editor/src/private-apis.js b/packages/block-editor/src/private-apis.js index 21b9f4bca7fc3d..dd82c049b8ca15 100644 --- a/packages/block-editor/src/private-apis.js +++ b/packages/block-editor/src/private-apis.js @@ -4,7 +4,6 @@ import * as globalStyles from './components/global-styles'; import { ExperimentalBlockEditorProvider } from './components/provider'; import { lock } from './lock-unlock'; -import { getRichTextValues } from './components/rich-text/get-rich-text-values'; import ResizableBoxPopover from './components/resizable-box-popover'; import { default as PrivateQuickInserter } from './components/inserter/quick-inserter'; import { @@ -59,7 +58,6 @@ lock( privateApis, { ExperimentalBlockCanvas, ExperimentalBlockEditorProvider, getDuotoneFilter, - getRichTextValues, PrivateQuickInserter, extractWords, getNormalizedSearchTerms, diff --git a/packages/block-editor/src/private-apis.native.js b/packages/block-editor/src/private-apis.native.js index f99d523933106b..092af8d54cbc16 100644 --- a/packages/block-editor/src/private-apis.native.js +++ b/packages/block-editor/src/private-apis.native.js @@ -3,7 +3,6 @@ */ import * as globalStyles from './components/global-styles'; import { ExperimentalBlockEditorProvider } from './components/provider'; -import { getRichTextValues } from './components/rich-text/get-rich-text-values'; import { lock } from './lock-unlock'; import { PrivateRichText } from './components/rich-text/'; @@ -14,6 +13,5 @@ export const privateApis = {}; lock( privateApis, { ...globalStyles, ExperimentalBlockEditorProvider, - getRichTextValues, PrivateRichText, } ); diff --git a/packages/blocks/README.md b/packages/blocks/README.md index f4805e1c60b381..8683f63bb3cfd5 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -291,6 +291,10 @@ _Returns_ - `Array`: Block types that the blocks argument can be transformed to. +### getRichTextValues + +Undocumented declaration. + ### getSaveContent Given a block type containing a save render implementation and attributes, returns the static markup to be saved. @@ -365,6 +369,10 @@ _Returns_ - `boolean`: True if a block contains at least one child blocks with inserter support and false otherwise. +### InnerBlocksContent + +Undocumented declaration. + ### isReusableBlock Determines whether or not the given block is a reusable block. This is a special block type that is used to point to a global block stored via the API. @@ -681,6 +689,10 @@ _Parameters_ - _blockName_ `string`: Name of the block (example: “core/columns”). - _variation_ `WPBlockVariation`: Object describing a block variation. +### RichTextContent + +Undocumented declaration. + ### serialize Takes a block or set of blocks and returns the serialized post content. @@ -1004,6 +1016,10 @@ _Returns_ - `[boolean,Array]`: validation results. +### valueToHTMLString + +Undocumented declaration. + ### withBlockContentContext > **Deprecated** diff --git a/packages/block-editor/src/components/rich-text/content.js b/packages/blocks/src/api/content.js similarity index 66% rename from packages/block-editor/src/components/rich-text/content.js rename to packages/blocks/src/api/content.js index 64f747879c4e9e..95d7779afe1cb9 100644 --- a/packages/block-editor/src/components/rich-text/content.js +++ b/packages/blocks/src/api/content.js @@ -2,27 +2,38 @@ * WordPress dependencies */ import { RawHTML } from '@wordpress/element'; -import { children as childrenSource } from '@wordpress/blocks'; import deprecated from '@wordpress/deprecated'; /** * Internal dependencies */ -import RichText from './'; +import childrenSource from './children'; +import { getInnerBlocksProps } from './serializer'; -/** - * Internal dependencies - */ -import { getMultilineTag } from './utils'; +export function InnerBlocksContent() { + return getInnerBlocksProps().children; +} + +function isEmpty( value ) { + return ! value || value.length === 0; +} + +function getMultilineTag( multiline ) { + if ( multiline !== true && multiline !== 'p' && multiline !== 'li' ) { + return undefined; + } + + return multiline === true ? 'p' : multiline; +} export function valueToHTMLString( value, multiline ) { - if ( RichText.isEmpty( value ) ) { + if ( isEmpty( value ) ) { const multilineTag = getMultilineTag( multiline ); return multilineTag ? `<${ multilineTag }>` : ''; } if ( Array.isArray( value ) ) { - deprecated( 'wp.blockEditor.RichText value prop as children type', { + deprecated( 'wp.blocks.RichTextContent value prop as children type', { since: '6.1', version: '6.3', alternative: 'value prop as string', @@ -42,7 +53,7 @@ export function valueToHTMLString( value, multiline ) { return value.toHTMLString(); } -export function Content( { +export function RichTextContent( { value, tagName: Tag, multiline, diff --git a/packages/block-editor/src/components/rich-text/get-rich-text-values.js b/packages/blocks/src/api/get-rich-text-values.js similarity index 90% rename from packages/block-editor/src/components/rich-text/get-rich-text-values.js rename to packages/blocks/src/api/get-rich-text-values.js index ee2bc638269308..5bd47e1e258dcd 100644 --- a/packages/block-editor/src/components/rich-text/get-rich-text-values.js +++ b/packages/blocks/src/api/get-rich-text-values.js @@ -2,17 +2,13 @@ * WordPress dependencies */ import { RawHTML, StrictMode, Fragment } from '@wordpress/element'; -import { - getSaveElement, - __unstableGetBlockProps as getBlockProps, -} from '@wordpress/blocks'; import { RichTextData } from '@wordpress/rich-text'; /** * Internal dependencies */ -import InnerBlocks from '../inner-blocks'; -import { Content } from './content'; +import { getSaveElement, getBlockProps } from './serializer'; +import { InnerBlocksContent, RichTextContent } from './content'; /* * This function is similar to `@wordpress/element`'s `renderToString` function, @@ -42,9 +38,9 @@ function addValuesForElement( element, values, innerBlocks ) { return addValuesForElements( props.children, values, innerBlocks ); case RawHTML: return; - case InnerBlocks.Content: + case InnerBlocksContent: return addValuesForBlocks( values, innerBlocks ); - case Content: + case RichTextContent: values.push( props.value ); return; } @@ -85,7 +81,7 @@ function addValuesForBlocks( values, blocks ) { // Instead of letting save elements use `useInnerBlocksProps.save`, // force them to use InnerBlocks.Content instead so we can intercept // a single component. - + ); addValuesForElement( saveElement, values, innerBlocks ); } diff --git a/packages/blocks/src/api/index.js b/packages/blocks/src/api/index.js index a03a58d8f9b21c..bc97a0bed047f2 100644 --- a/packages/blocks/src/api/index.js +++ b/packages/blocks/src/api/index.js @@ -175,6 +175,12 @@ export { __EXPERIMENTAL_ELEMENTS, __EXPERIMENTAL_PATHS_WITH_OVERRIDE, } from './constants'; +export { + RichTextContent, + InnerBlocksContent, + valueToHTMLString, +} from './content'; +export { getRichTextValues } from './get-rich-text-values'; export const privateApis = {}; lock( privateApis, { isContentBlock } ); diff --git a/packages/core-data/package.json b/packages/core-data/package.json index b0e5c10ddd24bc..2403f14d28ee22 100644 --- a/packages/core-data/package.json +++ b/packages/core-data/package.json @@ -34,7 +34,6 @@ "dependencies": { "@babel/runtime": "7.25.7", "@wordpress/api-fetch": "*", - "@wordpress/block-editor": "*", "@wordpress/blocks": "*", "@wordpress/compose": "*", "@wordpress/data": "*", diff --git a/packages/core-data/src/footnotes/get-rich-text-values-cached.js b/packages/core-data/src/footnotes/get-rich-text-values-cached.js index a5c2d258108612..e4db3b77323b66 100644 --- a/packages/core-data/src/footnotes/get-rich-text-values-cached.js +++ b/packages/core-data/src/footnotes/get-rich-text-values-cached.js @@ -1,35 +1,15 @@ /** * WordPress dependencies */ -import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; - -/** - * Internal dependencies - */ -import { unlock } from '../lock-unlock'; - -// TODO: The following line should have been: -// -// const unlockedApis = unlock( blockEditorPrivateApis ); -// -// But there are hidden circular dependencies in RNMobile code, specifically in -// certain native components in the `components` package that depend on -// `block-editor`. What follows is a workaround that defers the `unlock` call -// to prevent native code from failing. -// -// Fix once https://github.com/WordPress/gutenberg/issues/52692 is closed. -let unlockedApis; +import { getRichTextValues } from '@wordpress/blocks'; const cache = new WeakMap(); export default function getRichTextValuesCached( block ) { - if ( ! unlockedApis ) { - unlockedApis = unlock( blockEditorPrivateApis ); - } - - if ( ! cache.has( block ) ) { - const values = unlockedApis.getRichTextValues( [ block ] ); + let values = cache.get( block ); + if ( ! values ) { + values = getRichTextValues( [ block ] ); cache.set( block, values ); } - return cache.get( block ); + return values; }