-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add Block Transform to transform Embed blocks into Paragraph blocks. #17413
Add Block Transform to transform Embed blocks into Paragraph blocks. #17413
Conversation
} ); | ||
}, | ||
} ], | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a breaking change or not. Simply changed the schema of JSON to make it consistent with other transforms.
Same for Speaker Deck block.
transforms: { | ||
from: concat( get( transforms, 'from', [] ), get( embedSettings, 'transforms.from', [] ) ).filter( Boolean ), | ||
to: concat( get( transforms, 'to', [] ), get( embedSettings, 'transforms.to', [] ) ).filter( Boolean ), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, apply combined transformations of core/embed
as well as other core-embed/common/*
Same for core-embed/other/*
…cks-into-paragraph-block # Conflicts: # packages/e2e-tests/specs/__snapshots__/block-transforms.test.js.snap
Hey @desaiuditd Here is even more information: #21029 Are you able to continue working on these things? |
…cks-into-paragraph-block # Conflicts: # packages/block-library/src/embed/core-embeds.js # packages/block-library/src/embed/index.js # packages/e2e-tests/fixtures/block-transforms.js
This is good for review again. |
Hey Udit. I tested the PR here: I then pasted the following links: All three links brought up a following type of Embed placeholder box: I clicked to embed but none of them could be embedded. Option 1: The user pastes inn a link and it automatically shows up as a text link. But some links that can also be embedded. For these special links there can be an option to transform the text link into an embed through for instance the Transform area. The embed option will only show up where a transform to an embed can happen. EDIT: I will ping Miguel, so we can discuss it further here. |
This changes the current default behaviour, which @mcsf mentioned. Some would consider this a breaking change.
So can we let the current behaviour be as is? And when the process may fail, user has two options to revert. Either transform to paragraph block or click |
…cks-into-paragraph-block
I've one question for Option 1 that @paaljoachim has suggested.
how can I check which embed transformation to allow? E.g., if I paste a WordPress Make URL, it’s not probably right to show Youtube embed in the transformation popup, right? Check this Gif. I got this far. But not sure how to enable only valid embeds out of all. It’s even erroring out for any mismatched embed. @mcsf Do you have any thoughts on this? Meanwhile, I will try and see if I can get Option 2 working. |
@mcsf I was trying to follow DRY because it was same logic for
@mcsf Do you think, I should raise another PR to add smart handling of Embeds as per what Paal is suggesting? That way, this PR can just be about adding new block transform which converts embed into a paragraph with link to the embed url. |
I think I am just confusing myself here..... I might be running around in circles... sorry about that. I am happy to see that @mcsf Miguel is giving some feedback so we get the concept/development on the right course. Thank you Miguel. |
So the process should be: |
Cool. Let me raise another PR to fix this (#21029), so we can have some separation of concern. This PR can fix #15102 in isolation. |
…cks-into-paragraph-block
I wrote the following in the core editor slack channel a few hours ago and will add it here as well. So from my understanding of this PR. It takes a part various embeds. Then @desaiuditd will create a follow up PR where embeds are put together even better again. We are looking at all pasted links that embed such as a video etc to work as normal. But pasting a WP post content which normally just adds an embed will instead give the user a placeholder option to either embed the link or to show it as a text link. If someone can check out the PR and let us know if this is the correct approach that would be great. Thanks for any feedback and thoughts shared. |
Right, the custom I appreciate the concern for DRY, although it's a constant tug between DRY and the visual and immediate clarity that sometimes an inline transformation can best provide. In this case, we don't need to touch any of it, so I recommend reverting.
Yes, it's best to keep things focused. I personally am not convinced about smart handling of embeds, at least in the way it was it presented, but it can be put up for discussion. Thanks for coming back to this PR, for making these changes and for keeping things organised! |
@mcsf This is good for review again. I have made the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this fix!
NB! @mcsf Bottom line is that adding the test links I have further above in this PR, and a few Youtube URLs none of these can be embedded. Another example. (Clicking pencil. This is what I see.) Going to Gutenberg.run and testing this PR. |
I'm not experiencing any regressions so far. I've compared 81d4f4c (PR head) with the base branch at 601ee4b, and I've tested again with the commit to master at 48aba1e. You may be experiencing this for being stuck with a stale build in gutenberg.run, something which should be fixed soon (Slack link). |
@paaljoachim This PR was never meant to fix the smart auto embedding which you suggested earlier. This PR only allows user to convert an existing embed block into a paragraph block. So it only fixes #15102 in isolation. The approach you suggested is still being discussed at #21029. |
Hey @desaiuditd My concern during the test at gutenberg.run was that one is not able to embed even the Youtube embeds that I tested with. So from what you are saying (hopefully) the above would be an error. |
transform: ( { url, caption } ) => { | ||
const link = <a href={ url }>{ caption || url }</a>; | ||
return createBlock( 'core/paragraph', { | ||
content: renderToString( link ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not write the html as a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind the added peace of mind of running this through the element serialiser. Do you have drawbacks in mind?
The PR seems to work well in my tests. I am also able to reproduce the issue @paaljoachim referred but only on gutenberg.run. @aduth verified gutenberg.run has an issue in requests to the endpoint |
Thanks for debugging that! Seems we can move on with the release. |
Testing with 8.1.0-rc.1 This PR adds a transform an Embed to Paragraph option. Using an URL that automatically made an embed. Transformed Embed block which has now turned into a Paragraph Block: |
Great job @desaiuditd ! @jorgefilipecosta |
Description
Fixes #15102 by providing a block transform to transform Embeds into Paragraphs.
Ref: #15102 (comment)
How has this been tested?
Pasting a URL into the Paragraph block automatically converts into an Embed blocks. After that, now, I'm able to transform the same Embed block into a Paragraph block. Performing an Undo action brings the Embed block back.
While working on this, I found a bug that none of the transformations of
core/embed
block were applied tocore-embed/common/*
andcore-embed/others/*
blocks. So I've fixed that as well.Screenshots
Types of changes
While converting the Embed into Paragraph, if the caption is present, then I'm using that as the text for the link in the Paragraph. That seemed like a sensible behaviour without the data loss for the user. Happy to defer on someone who's more close to this.
Checklist: