From 261b00b3d8a74eb9d21ec5924615efe905da559e Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Mon, 13 Nov 2023 08:56:20 +0200 Subject: [PATCH] Native Mobile: RichText: fix circular dependency (#56061) --- .../src/components/rich-text/index.native.js | 4 +++- .../rich-text/native}/format-edit.js | 5 ++-- .../native}/get-format-colors.native.js | 4 ++-- .../src/components/rich-text/native/index.js | 1 + .../rich-text/native}/index.native.js | 24 ++++++++++--------- .../rich-text/native}/style.native.scss | 0 .../test/__snapshots__/index.native.js.snap | 0 .../rich-text/native}/test/index.native.js | 6 ++--- .../test/performance/rich-text.native.js | 2 +- .../toolbar-button-with-options.native.js | 0 .../rich-text/native}/use-format-types.js | 5 +--- .../src/components/post-title/index.native.js | 12 ++++------ packages/rich-text/src/index.ts | 1 - 13 files changed, 30 insertions(+), 34 deletions(-) rename packages/{rich-text/src/component => block-editor/src/components/rich-text/native}/format-edit.js (86%) rename packages/{rich-text/src => block-editor/src/components/rich-text/native}/get-format-colors.native.js (92%) create mode 100644 packages/block-editor/src/components/rich-text/native/index.js rename packages/{rich-text/src/component => block-editor/src/components/rich-text/native}/index.native.js (98%) rename packages/{rich-text/src/component => block-editor/src/components/rich-text/native}/style.native.scss (100%) rename packages/{rich-text/src => block-editor/src/components/rich-text/native}/test/__snapshots__/index.native.js.snap (100%) rename packages/{rich-text/src => block-editor/src/components/rich-text/native}/test/index.native.js (98%) rename packages/{rich-text/src => block-editor/src/components/rich-text/native}/test/performance/rich-text.native.js (94%) rename packages/{rich-text/src/component => block-editor/src/components/rich-text/native}/toolbar-button-with-options.native.js (100%) rename packages/{rich-text/src/component => block-editor/src/components/rich-text/native}/use-format-types.js (97%) 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 32bd1afd3d5404..aab10e9ab65476 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -17,7 +17,6 @@ import { } from '@wordpress/blocks'; import { useInstanceId, useMergeRefs } from '@wordpress/compose'; import { - __experimentalRichText as RichText, __unstableCreateElement, isEmpty, insert, @@ -46,6 +45,7 @@ import { } from './utils'; import EmbedHandlerPicker from './embed-handler-picker'; import { Content } from './content'; +import RichText from './native'; const classes = 'block-editor-rich-text__editable'; @@ -688,6 +688,8 @@ ForwardedRichTextContainer.Content.defaultProps = { value: '', }; +ForwardedRichTextContainer.Raw = RichText; + /** * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md */ diff --git a/packages/rich-text/src/component/format-edit.js b/packages/block-editor/src/components/rich-text/native/format-edit.js similarity index 86% rename from packages/rich-text/src/component/format-edit.js rename to packages/block-editor/src/components/rich-text/native/format-edit.js index 1867c1ef2e4f75..75b077ab321d43 100644 --- a/packages/rich-text/src/component/format-edit.js +++ b/packages/block-editor/src/components/rich-text/native/format-edit.js @@ -1,8 +1,7 @@ /** - * Internal dependencies + * WordPress dependencies */ -import { getActiveFormat } from '../get-active-format'; -import { getActiveObject } from '../get-active-object'; +import { getActiveFormat, getActiveObject } from '@wordpress/rich-text'; export default function FormatEdit( { formatTypes, diff --git a/packages/rich-text/src/get-format-colors.native.js b/packages/block-editor/src/components/rich-text/native/get-format-colors.native.js similarity index 92% rename from packages/rich-text/src/get-format-colors.native.js rename to packages/block-editor/src/components/rich-text/native/get-format-colors.native.js index f9b3a9187ca2b9..a54d3e10f78a0a 100644 --- a/packages/rich-text/src/get-format-colors.native.js +++ b/packages/block-editor/src/components/rich-text/native/get-format-colors.native.js @@ -1,7 +1,7 @@ /** - * WordPress dependencies + * Internal dependencies */ -import { getColorObjectByAttributeValues } from '@wordpress/block-editor'; +import { getColorObjectByAttributeValues } from '../../../components/colors'; const FORMAT_TYPE = 'core/text-color'; const REGEX_TO_MATCH = /^has-(.*)-color$/; diff --git a/packages/block-editor/src/components/rich-text/native/index.js b/packages/block-editor/src/components/rich-text/native/index.js new file mode 100644 index 00000000000000..2d1ec238274a0b --- /dev/null +++ b/packages/block-editor/src/components/rich-text/native/index.js @@ -0,0 +1 @@ +export default () => {}; diff --git a/packages/rich-text/src/component/index.native.js b/packages/block-editor/src/components/rich-text/native/index.native.js similarity index 98% rename from packages/rich-text/src/component/index.native.js rename to packages/block-editor/src/components/rich-text/native/index.native.js index 47b47d58c59885..2381b9809eca86 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/block-editor/src/components/rich-text/native/index.native.js @@ -29,23 +29,25 @@ import { BACKSPACE, DELETE, ENTER } from '@wordpress/keycodes'; import { isURL } from '@wordpress/url'; import { atSymbol, plus } from '@wordpress/icons'; import { __ } from '@wordpress/i18n'; +import { + applyFormat, + getActiveFormat, + getActiveFormats, + insert, + getTextContent, + isEmpty, + create, + toHTMLString, + isCollapsed, + remove, +} from '@wordpress/rich-text'; /** * Internal dependencies */ import { useFormatTypes } from './use-format-types'; import FormatEdit from './format-edit'; -import { applyFormat } from '../apply-format'; -import { getActiveFormat } from '../get-active-format'; -import { getActiveFormats } from '../get-active-formats'; -import { insert } from '../insert'; -import { getTextContent } from '../get-text-content'; -import { isEmpty } from '../is-empty'; -import { create } from '../create'; -import { toHTMLString } from '../to-html-string'; -import { isCollapsed } from '../is-collapsed'; -import { remove } from '../remove'; -import { getFormatColors } from '../get-format-colors'; +import { getFormatColors } from './get-format-colors'; import styles from './style.scss'; import ToolbarButtonWithOptions from './toolbar-button-with-options'; diff --git a/packages/rich-text/src/component/style.native.scss b/packages/block-editor/src/components/rich-text/native/style.native.scss similarity index 100% rename from packages/rich-text/src/component/style.native.scss rename to packages/block-editor/src/components/rich-text/native/style.native.scss diff --git a/packages/rich-text/src/test/__snapshots__/index.native.js.snap b/packages/block-editor/src/components/rich-text/native/test/__snapshots__/index.native.js.snap similarity index 100% rename from packages/rich-text/src/test/__snapshots__/index.native.js.snap rename to packages/block-editor/src/components/rich-text/native/test/__snapshots__/index.native.js.snap diff --git a/packages/rich-text/src/test/index.native.js b/packages/block-editor/src/components/rich-text/native/test/index.native.js similarity index 98% rename from packages/rich-text/src/test/index.native.js rename to packages/block-editor/src/components/rich-text/native/test/index.native.js index e0ce7ff78d6ccf..64bfb3b183c6b9 100644 --- a/packages/rich-text/src/test/index.native.js +++ b/packages/block-editor/src/components/rich-text/native/test/index.native.js @@ -8,7 +8,7 @@ import { getEditorHtml, render, initializeEditor } from 'test/helpers'; * WordPress dependencies */ import { select } from '@wordpress/data'; -import { store as blockEditorStore } from '@wordpress/block-editor'; +import { store as richTextStore } from '@wordpress/rich-text'; import { coreBlocks } from '@wordpress/block-library'; import { getBlockTypes, @@ -19,8 +19,8 @@ import { /** * Internal dependencies */ -import { store as richTextStore } from '../store'; -import RichText from '../component/index.native'; +import { store as blockEditorStore } from '../../../../store'; +import RichText from '../index.native'; /** * Mock `useSelect` with various global application settings, e.g., styles. diff --git a/packages/rich-text/src/test/performance/rich-text.native.js b/packages/block-editor/src/components/rich-text/native/test/performance/rich-text.native.js similarity index 94% rename from packages/rich-text/src/test/performance/rich-text.native.js rename to packages/block-editor/src/components/rich-text/native/test/performance/rich-text.native.js index aaaf42c90137f9..7be9981d04bcec 100644 --- a/packages/rich-text/src/test/performance/rich-text.native.js +++ b/packages/block-editor/src/components/rich-text/native/test/performance/rich-text.native.js @@ -11,7 +11,7 @@ import { /** * Internal dependencies */ -import RichText from '../../component/index.native'; +import RichText from '../../index.native'; describe( 'RichText Performance', () => { const onCreateUndoLevel = jest.fn(); diff --git a/packages/rich-text/src/component/toolbar-button-with-options.native.js b/packages/block-editor/src/components/rich-text/native/toolbar-button-with-options.native.js similarity index 100% rename from packages/rich-text/src/component/toolbar-button-with-options.native.js rename to packages/block-editor/src/components/rich-text/native/toolbar-button-with-options.native.js diff --git a/packages/rich-text/src/component/use-format-types.js b/packages/block-editor/src/components/rich-text/native/use-format-types.js similarity index 97% rename from packages/rich-text/src/component/use-format-types.js rename to packages/block-editor/src/components/rich-text/native/use-format-types.js index 637be62b4361e0..ff65d7421ae5cc 100644 --- a/packages/rich-text/src/component/use-format-types.js +++ b/packages/block-editor/src/components/rich-text/native/use-format-types.js @@ -3,10 +3,7 @@ */ import { useMemo } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; -/** - * Internal dependencies - */ -import { store as richTextStore } from '../store'; +import { store as richTextStore } from '@wordpress/rich-text'; function formatTypesSelector( select ) { return select( richTextStore ).getFormatTypes(); diff --git a/packages/editor/src/components/post-title/index.native.js b/packages/editor/src/components/post-title/index.native.js index 0b58ee774b699e..1ec0dd3ade3bfc 100644 --- a/packages/editor/src/components/post-title/index.native.js +++ b/packages/editor/src/components/post-title/index.native.js @@ -7,18 +7,14 @@ import { View } from 'react-native'; * WordPress dependencies */ import { Component } from '@wordpress/element'; -import { - __experimentalRichText as RichText, - create, - insert, -} from '@wordpress/rich-text'; +import { create, insert } from '@wordpress/rich-text'; import { decodeEntities } from '@wordpress/html-entities'; import { withDispatch, withSelect } from '@wordpress/data'; import { withFocusOutside } from '@wordpress/components'; import { withInstanceId, compose } from '@wordpress/compose'; import { __, sprintf } from '@wordpress/i18n'; import { pasteHandler } from '@wordpress/blocks'; -import { store as blockEditorStore } from '@wordpress/block-editor'; +import { store as blockEditorStore, RichText } from '@wordpress/block-editor'; import { store as editorStore } from '@wordpress/editor'; /** @@ -152,7 +148,7 @@ class PostTitle extends Component { accessibilityLabel={ this.getTitle( title, postType ) } accessibilityHint={ __( 'Updates the title.' ) } > - {} } - > + /> ); } diff --git a/packages/rich-text/src/index.ts b/packages/rich-text/src/index.ts index f487845a4cd76f..14d26cab8f7fb1 100644 --- a/packages/rich-text/src/index.ts +++ b/packages/rich-text/src/index.ts @@ -30,7 +30,6 @@ export { default as __experimentalRichText, useRichText as __unstableUseRichText, } from './component'; -export { default as __unstableFormatEdit } from './component/format-edit'; /** * An object which represents a formatted string. See main `@wordpress/rich-text`