-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Mechanism to keep styles during block transforms. #37596
Add: Mechanism to keep styles during block transforms. #37596
Conversation
Size Change: +309 B (0%) Total Size: 1.14 MB
ℹ️ View Unchanged
|
db681e5
to
6032402
Compare
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 working on this Jorge!
The problem is more convoluted because we can transform multiple blocks at once and here we don't take account for that (take first block's attributes).. I haven't thought about that in depth but we should also consider any possible different handling between blocks that produce 1-1 transformations or create wrapper blocks with Innerblocks.
It reminds me actually the case of matching block patterns here.
I have a recording that shows the use case of multiselecting two paragraphs and shows the preview of transform to: Heading and Group
Screen.Recording.2021-12-27.at.7.05.13.PM.mov
b7b4f99
to
54dfa35
Compare
Hi @ntsekouras, I expanded the logic to cover the cases you referred. It should now be working well on most of the cases. |
Hey Jorge! Do you think it's possible to integrate this functionality in |
Hi @ntsekouras,
Everything related to the styles is implemented as a block support hook, the styles are implemented as if they were plugins. Even adding style markup and classes is implemented as hook e.g: in https://raw.githubusercontent.com/WordPress/gutenberg/54dfa3527d9101dabb35cf6d630b6e25b809523c/packages/block-editor/src/hooks/color.js addSaveProps function. The UI is also implemented in the hook in ColorEdit. So our block API is not even aware of colors, typography etc. I think If everything related to this functionality is in the hook (the UI, the markup, etc) the way to deal with transforms should also be in the hook. If we add this to the block API we break the abstraction the API becomes aware of colors, typography, etc. So is the markup (the essential part) added as a hook and not directly in the engine if we add the transforms (which are less relevant) to the engine directly? |
Yes, you're right! It seems I rushed with my comment 😄 . I'll give a proper review first thing tomorrow morning. |
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 Jorge! This seems to work well in my testing. Should we add a small e2e test?
54dfa35
to
6349892
Compare
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 @jorgefilipecosta!
I still think some e2e testing would be good though 😄
Thank you for the review @ntsekouras. I'm working on some end to end tests :) |
Fixes: #36745
This PR proposes a mechanism to keep block styles during transforms. The mechanism is applied for color and font-size if this PR is accepted the mechanism will be expanded into other styles where it makes sense.
How has this been tested?
I created a paragraph.
I added a custom text color.
I added a named background color, and a named link color.
I added a custom font size.
I converted the paragraph to a list and verified all the styles were kept.
I added another list item.
I selected a preset font size.
I converted the list to paragraphs and verified all the styles were kept.
I selected the paragraphs and converted back to a list and verified the styles persisted on the list.