Prevent theme styles from being used in the block-based product editor (#38491)
This commit is contained in:
parent
1c7c99636e
commit
4e530ba2e2
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Prevent theme styles from being used in the product editor.
|
|
@ -19,9 +19,6 @@ import {
|
||||||
EditorSettings,
|
EditorSettings,
|
||||||
EditorBlockListSettings,
|
EditorBlockListSettings,
|
||||||
ObserveTyping,
|
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';
|
} from '@wordpress/block-editor';
|
||||||
// It doesn't seem to notice the External dependency block whn @ts-ignore is added.
|
// It doesn't seem to notice the External dependency block whn @ts-ignore is added.
|
||||||
// eslint-disable-next-line @woocommerce/dependency-group
|
// eslint-disable-next-line @woocommerce/dependency-group
|
||||||
|
@ -103,7 +100,6 @@ export function BlockEditor( {
|
||||||
onChange={ onChange }
|
onChange={ onChange }
|
||||||
settings={ settings }
|
settings={ settings }
|
||||||
>
|
>
|
||||||
<EditorStyles styles={ settings?.styles } />
|
|
||||||
<div className="editor-styles-wrapper">
|
<div className="editor-styles-wrapper">
|
||||||
{ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ }
|
{ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ }
|
||||||
{ /* @ts-ignore No types for this exist yet. */ }
|
{ /* @ts-ignore No types for this exist yet. */ }
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* 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
|
* Internal dependencies
|
||||||
|
@ -47,13 +59,35 @@ const CONTENT_ATTR = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export function ContentPreview( { content }: ContentPreviewProps ) {
|
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 (
|
return (
|
||||||
|
<div className="woocommerce-content-preview">
|
||||||
|
<Iframe
|
||||||
|
head={
|
||||||
|
<>
|
||||||
|
<EditorStyles styles={ parentEditorSettings?.styles } />
|
||||||
|
<style>
|
||||||
|
{ `body {
|
||||||
|
overflow: hidden;
|
||||||
|
}` }
|
||||||
|
</style>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
className="woocommerce-content-preview__iframe"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
className="woocommerce-content-preview"
|
className="woocommerce-content-preview__content"
|
||||||
dangerouslySetInnerHTML={ sanitizeHTML( content, {
|
dangerouslySetInnerHTML={ sanitizeHTML( content, {
|
||||||
tags: CONTENT_TAGS,
|
tags: CONTENT_TAGS,
|
||||||
attr: CONTENT_ATTR,
|
attr: CONTENT_ATTR,
|
||||||
} ) }
|
} ) }
|
||||||
/>
|
/>
|
||||||
|
</Iframe>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
.woocommerce-content-preview {
|
.woocommerce-content-preview {
|
||||||
border: 1px solid $gray-300;
|
border: 1px solid $gray-300;
|
||||||
max-height: 144px;
|
max-height: 144px;
|
||||||
|
width: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: $gap-large;
|
|
||||||
margin-top: $gap-largest;
|
margin-top: $gap-largest;
|
||||||
|
|
||||||
>:first-child {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
> * {
|
|
||||||
max-width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:after {
|
&:after {
|
||||||
content: '';
|
content: '';
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -23,4 +15,21 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 89.5%);
|
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%;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue