Prevent theme styles from being used in the block-based product editor (#38491)

This commit is contained in:
Matt Sherman 2023-05-30 13:25:55 -04:00 committed by GitHub
parent 1c7c99636e
commit 4e530ba2e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 23 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Prevent theme styles from being used in the product editor.

View File

@ -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 }
>
<EditorStyles styles={ settings?.styles } />
<div className="editor-styles-wrapper">
{ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ }
{ /* @ts-ignore No types for this exist yet. */ }

View File

@ -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 (
<div className="woocommerce-content-preview">
<Iframe
head={
<>
<EditorStyles styles={ parentEditorSettings?.styles } />
<style>
{ `body {
overflow: hidden;
}` }
</style>
</>
}
className="woocommerce-content-preview__iframe"
>
<div
className="woocommerce-content-preview"
className="woocommerce-content-preview__content"
dangerouslySetInnerHTML={ sanitizeHTML( content, {
tags: CONTENT_TAGS,
attr: CONTENT_ATTR,
} ) }
/>
</Iframe>
</div>
);
}

View File

@ -1,18 +1,10 @@
.woocommerce-content-preview {
border: 1px solid $gray-300;
max-height: 144px;
width: 100%;
overflow: hidden;
padding: $gap-large;
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%;
}
}
}