-
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
[POC] Pattern blocks as sections #49885
Conversation
Size Change: +64 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
860f25e
to
551fa59
Compare
Flaky tests detected in 551fa59. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4729897999
|
Thank you for exploring this. |
Oh, the "section" type is not a string mapped to the HTML tag, but actually an enum type to differentiate it from the original. We might want to look into what you described here but likely not at this stage though! This is just an experimental PR. We have other explorations in #49967 if you're interested! |
Yes I understand that it is experimental. Where is a better place to keep the discussion going? |
We are just discussing it internally, we haven't had anything concrete to share yet (other than what has already been shared on the issues). But we'll share more on the issue or on a public Slack channel on Making WordPress though! |
As a full time contributor, it makes it incredibly difficult to decide what is worth spending time on. |
@carolinan There's now an open discussion/proposal at #50456 if you're interested! |
Closed as it's no longer up-to-date with the proposal. |
A really simple and adhoc POC of how a pattern block as a section element could be implemented. This PR introduces a new attribute to the
core/pattern
block:type
. Currently, the only possible value issection
.The original
pattern
blockThe implementation of the pattern block is relatively simple, it doesn't have a
save
function, and itsedit
function replaces itself with the registered pattern blocks by itsslug
. For instance, a pattern block like this:<!-- wp:pattern {"slug":"twentytwentythree/footer-default"} /-->
...will transform itself into this when it's loaded in the editor (if it's registered):
Notice that the original
wp:pattern
block disappears and no longer exists.However, this approach stops us from keeping the metadata of the block. We no longer know that the replaced blocks are from a "footer" pattern, nor the pattern is from the
twentytwentythree
theme.A solution
One solution is to keep the wrapper pattern block when it's transformed, so that we won't lose any of the information. The pattern block will then behaves like a "group" block with semantic meaning.
It also doesn't do any transforming or replacing in its
edit
function, instead it simply renders the inner blocks if it's defined. It relies on the source to populate the inner blocks upon insertion, just like how a group block is implemented.This PR changes how a pattern block is inserted from the global block inserter. Instead of sending just the
slug
attribute, it will now populate the inner blocks as well.To maintain backward compatibility, the original behavior when no
type
attribute is specified is kept. So that template parts which rely on this behavior can continue to functionas before. It also implies different "syncing" behavior as this will always sync data from the registered patterns. We might also want to explore different syncing behavior for patterns with
type: section
too.Note that this is not the final proposal but just a POC and an idea that we can play with in future iterations. Hope that a runnable branch could spark more ideas and feedback.
Testing Instructions
wp:pattern
block is still present, and with atype: section
attribute.Screenshots or screencast
Kapture.2023-04-18.at.15.28.40.mp4