-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Duotone: Pass filters to the Post Editor #49239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a98c60b
32355ba
7810e0a
0e6304e
690cca4
5a99e30
8f9541e
2b8484b
6a19107
6e0d5c0
44e46c8
0b4dfe7
9f84812
57471f9
05121a2
20a6fde
9b4e96c
4fb10d4
5fe3835
32f2147
3688db6
f426d62
0dabaf4
6bc19a9
a0be2bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,21 @@ function useDarkThemeBodyClassName( styles ) { | |
|
|
||
| export default function EditorStyles( { styles } ) { | ||
ajlende marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const transformedStyles = useMemo( | ||
| () => transformStyles( styles, EDITOR_STYLES_SELECTOR ), | ||
| () => | ||
| transformStyles( | ||
| // Assume that non-SVG styles are CSS that can be transformed. | ||
| styles.filter( ( style ) => style.__unstableType !== 'svgs' ), | ||
| EDITOR_STYLES_SELECTOR | ||
| ), | ||
| [ styles ] | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a potentially subtle issue, but the filter here appears to be to ensure that the When this change is eventually backported, it'll likely happen at slightly different times, typically with the PHP changes landing before the JS changes. Would it be possible or worthwhile to have the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmmm... I can see how that's an issue, but I don't have any good ideas for how to solve it right now. Since we've decided to keep
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable to me, if it's the right path forward for the feature. It'd be good to make sure the comments are clear in the PHP code for when it comes time to backport, so that we don't forget 🙂
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is what you're talking about, but I added a comment in the php in a0be2bf. |
||
|
|
||
| const transformedSvgs = useMemo( | ||
| () => | ||
| styles | ||
| .filter( ( style ) => style.__unstableType == 'svgs' ) | ||
| .map( ( style ) => style.assets ) | ||
| .join( '' ), | ||
| [ styles ] | ||
| ); | ||
|
|
||
|
|
@@ -80,6 +94,15 @@ export default function EditorStyles( { styles } ) { | |
| { transformedStyles.map( ( css, index ) => ( | ||
| <style key={ index }>{ css }</style> | ||
| ) ) } | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| viewBox="0 0 0 0" | ||
| width="0" | ||
| height="0" | ||
| focusable="false" | ||
| role="none" | ||
| dangerouslySetInnerHTML={ { __html: transformedSvgs } } | ||
| /> | ||
|
||
| </> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ import { | |
| __experimentaluseLayoutStyles as useLayoutStyles, | ||
| } from '@wordpress/block-editor'; | ||
| import { useEffect, useRef, useMemo } from '@wordpress/element'; | ||
| import { Button, __unstableMotion as motion, SVG } from '@wordpress/components'; | ||
| import { Button, __unstableMotion as motion } from '@wordpress/components'; | ||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||
| import { useMergeRefs } from '@wordpress/compose'; | ||
| import { arrowLeft } from '@wordpress/icons'; | ||
|
|
@@ -46,15 +46,9 @@ import { store as editPostStore } from '../../store'; | |
|
|
||
| const isGutenbergPlugin = process.env.IS_GUTENBERG_PLUGIN ? true : false; | ||
|
|
||
| function MaybeIframe( { | ||
| children, | ||
| contentRef, | ||
| shouldIframe, | ||
| styles, | ||
| style, | ||
| filters, | ||
| } ) { | ||
| function MaybeIframe( { children, contentRef, shouldIframe, styles, style } ) { | ||
| const ref = useMouseMoveTypingReset(); | ||
|
|
||
| if ( ! shouldIframe ) { | ||
| return ( | ||
| <> | ||
|
|
@@ -73,14 +67,13 @@ function MaybeIframe( { | |
|
|
||
| return ( | ||
| <Iframe | ||
| head={ <EditorStyles styles={ styles } /> } | ||
ajlende marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ref={ ref } | ||
| contentRef={ contentRef } | ||
| style={ { width: '100%', height: '100%', display: 'block' } } | ||
| name="editor-canvas" | ||
| > | ||
| <EditorStyles styles={ styles } /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we adding non styles to Also what if we move this to the iframe component in the block-editor package? Wouldn't it then work automatically in all editors and allow us to remove a bunch of duplication?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my suggestion and for me these SVG filters are styles. They're just not "CSS styles". Basically if you check the code base, in all the places we use The move to body is necessary because the filters can't be inserted into head in HTML. I suggest that we could potentially use ownerDocument to solve that.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you could use a portal. Maybe we should build
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@ellatrix Is it okay if that's handled in a follow-up? Or do you think it's important for this PR?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tried doing this, but it causes a flash of unstyled content while React is grabbing the ref to use for the portal. Is there any reason we can't have the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { children } | ||
| <SVG dangerouslySetInnerHTML={ { __html: filters } } /> | ||
| </Iframe> | ||
| ); | ||
| } | ||
|
|
@@ -111,7 +104,7 @@ function getPostContentAttributes( blocks ) { | |
| } | ||
| } | ||
|
|
||
| export default function VisualEditor( { styles, filters } ) { | ||
| export default function VisualEditor( { styles } ) { | ||
| const { | ||
| deviceType, | ||
| isWelcomeGuideVisible, | ||
|
|
@@ -371,7 +364,6 @@ export default function VisualEditor( { styles, filters } ) { | |
| } | ||
| contentRef={ contentRef } | ||
| styles={ styles } | ||
| filters={ filters } | ||
| > | ||
| { themeSupportsLayout && | ||
| ! themeHasDisabledLayoutStyles && | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.