From 4e530ba2e2d647f9c3fc33ac00c4a2e62447ddb7 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Tue, 30 May 2023 13:25:55 -0400 Subject: [PATCH] Prevent theme styles from being used in the block-based product editor (#38491) --- .../changelog/fix-product-editor-theme-bleed | 4 ++ .../components/block-editor/block-editor.tsx | 4 -- .../content-preview/content-preview.tsx | 50 ++++++++++++++++--- .../src/components/content-preview/style.scss | 31 ++++++++---- 4 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 packages/js/product-editor/changelog/fix-product-editor-theme-bleed diff --git a/packages/js/product-editor/changelog/fix-product-editor-theme-bleed b/packages/js/product-editor/changelog/fix-product-editor-theme-bleed new file mode 100644 index 00000000000..37bfc36c9de --- /dev/null +++ b/packages/js/product-editor/changelog/fix-product-editor-theme-bleed @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Prevent theme styles from being used in the product editor. diff --git a/packages/js/product-editor/src/components/block-editor/block-editor.tsx b/packages/js/product-editor/src/components/block-editor/block-editor.tsx index de33904ec3a..a53e7ca52ad 100644 --- a/packages/js/product-editor/src/components/block-editor/block-editor.tsx +++ b/packages/js/product-editor/src/components/block-editor/block-editor.tsx @@ -19,9 +19,6 @@ import { EditorSettings, EditorBlockListSettings, ObserveTyping, - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore No types for this exist yet. - __unstableEditorStyles as EditorStyles, } from '@wordpress/block-editor'; // It doesn't seem to notice the External dependency block whn @ts-ignore is added. // eslint-disable-next-line @woocommerce/dependency-group @@ -103,7 +100,6 @@ export function BlockEditor( { onChange={ onChange } settings={ settings } > -
{ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ } { /* @ts-ignore No types for this exist yet. */ } diff --git a/packages/js/product-editor/src/components/content-preview/content-preview.tsx b/packages/js/product-editor/src/components/content-preview/content-preview.tsx index ddd86ecebd6..fae1220c7e0 100644 --- a/packages/js/product-editor/src/components/content-preview/content-preview.tsx +++ b/packages/js/product-editor/src/components/content-preview/content-preview.tsx @@ -1,7 +1,19 @@ /** * External dependencies */ -import { createElement } from '@wordpress/element'; +import { useSelect } from '@wordpress/data'; +import { createElement, Fragment } from '@wordpress/element'; +import { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore No types for this exist yet. + __unstableIframe as Iframe, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore No types for this exist yet. + __unstableEditorStyles as EditorStyles, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + store as blockEditorStore, +} from '@wordpress/block-editor'; /** * Internal dependencies @@ -47,13 +59,35 @@ const CONTENT_ATTR = [ ]; export function ContentPreview( { content }: ContentPreviewProps ) { + const parentEditorSettings = useSelect( ( select ) => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return select( blockEditorStore ).getSettings(); + } ); + return ( -
+
+ +
); } diff --git a/packages/js/product-editor/src/components/content-preview/style.scss b/packages/js/product-editor/src/components/content-preview/style.scss index 4c3e6bcc6d8..66c0a437343 100644 --- a/packages/js/product-editor/src/components/content-preview/style.scss +++ b/packages/js/product-editor/src/components/content-preview/style.scss @@ -1,18 +1,10 @@ .woocommerce-content-preview { border: 1px solid $gray-300; - max-height: 144px; - overflow: hidden; - padding: $gap-large; + max-height: 144px; + width: 100%; + overflow: hidden; margin-top: $gap-largest; - >:first-child { - margin-top: 0; - } - - > * { - max-width: 100%; - } - &:after { content: ''; display: block; @@ -23,4 +15,21 @@ width: 100%; background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 89.5%); } + + &__iframe { + width: 100%; + } + + &__content { + box-sizing: border-box; + padding: $gap-large; + + >:first-child { + margin-top: 0; + } + + > * { + max-width: 100%; + } + } }