-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Borders: Stabilize border block supports within block processing #66918
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 7 commits
5c954b8
03f745d
0377da1
50caa72
32df888
611de98
f51cbc0
9c32c4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/7069 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/63401 | ||
| * https://github.com/WordPress/gutenberg/pull/66918 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,40 +6,85 @@ | |
| */ | ||
|
|
||
| /** | ||
| * Filters the block type arguments during registration to stabilize experimental block supports. | ||
| * Filters the block type arguments during registration to stabilize | ||
| * experimental block supports. | ||
| * | ||
| * This is a temporary compatibility shim as the approach in core is for this to be handled | ||
| * within the WP_Block_Type class rather than requiring a filter. | ||
| * This is a temporary compatibility shim as the approach in core is for this | ||
| * to be handled within the WP_Block_Type class rather than requiring a filter. | ||
| * | ||
| * @param array $args Array of arguments for registering a block type. | ||
| * @return array Array of arguments for registering a block type. | ||
| */ | ||
| function gutenberg_stabilize_experimental_block_supports( $args ) { | ||
| if ( empty( $args['supports']['typography'] ) ) { | ||
| if ( empty( $args['supports'] ) ) { | ||
| return $args; | ||
| } | ||
|
|
||
| $experimental_typography_supports_to_stable = array( | ||
| '__experimentalFontFamily' => 'fontFamily', | ||
| '__experimentalFontStyle' => 'fontStyle', | ||
| '__experimentalFontWeight' => 'fontWeight', | ||
| '__experimentalLetterSpacing' => 'letterSpacing', | ||
| '__experimentalTextDecoration' => 'textDecoration', | ||
| '__experimentalTextTransform' => 'textTransform', | ||
| $experimental_to_stable_keys = array( | ||
| 'typography' => array( | ||
| '__experimentalFontFamily' => 'fontFamily', | ||
| '__experimentalFontStyle' => 'fontStyle', | ||
| '__experimentalFontWeight' => 'fontWeight', | ||
| '__experimentalLetterSpacing' => 'letterSpacing', | ||
| '__experimentalTextDecoration' => 'textDecoration', | ||
| '__experimentalTextTransform' => 'textTransform', | ||
| ), | ||
| '__experimentalBorder' => 'border', | ||
| ); | ||
|
|
||
| $current_typography_supports = $args['supports']['typography']; | ||
| $stable_typography_supports = array(); | ||
| $updated_supports = array(); | ||
| foreach ( $args['supports'] as $support => $config ) { | ||
| // Add the support's config as is when it's not in need of stabilization. | ||
| if ( empty( $experimental_to_stable_keys[ $support ] ) ) { | ||
| $updated_supports[ $support ] = $config; | ||
| continue; | ||
| } | ||
|
|
||
| // Stabilize the support's key if needed e.g. __experimentalBorder => border. | ||
| if ( is_string( $experimental_to_stable_keys[ $support ] ) ) { | ||
| $stabilized_key = $experimental_to_stable_keys[ $support ]; | ||
|
|
||
| // If there is no stabilized key present, use the experimental config as is. | ||
| if ( ! array_key_exists( $stabilized_key, $args['supports'] ) ) { | ||
| $updated_supports[ $stabilized_key ] = $config; | ||
| continue; | ||
| } | ||
|
|
||
| // Determine the order of keys, so the last defined can be preferred. | ||
| $key_positions = array_flip( array_keys( $args['supports'] ) ); | ||
| $experimental_index = $key_positions[ $support ] ?? -1; | ||
| $stabilized_index = $key_positions[ $stabilized_key ] ?? -1; | ||
| $experimental_first = $experimental_index < $stabilized_index; | ||
|
|
||
| // Update support config, prefer the last defined value. | ||
| if ( is_array( $config ) ) { | ||
|
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 not at all a blocker for now, but in the JS implementation we check for an object, so there'd never be a match against the In practice it's not an issue because we don't have anything in For now, though, I think it's fine to leave as-is. And please excuse my verbose comment here 😄
Contributor
Author
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. Appreciate you raising this one. It has vaguely been on my radar but I was struggling to come up with a real-word case where it should happen. The In the end, rather than waste too much time on coming up with hypotheticals to test, I decided to leave this until it was a problem. Does that allay your concern at all? What else am I missing?
Contributor
Author
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 meant to also add that in recent times, there's been a decided effort to not land block supports at all unless they were stable. To prevent being in the situation like we are with some typography and border supports. That's been the case for entire block support features like If the approach to not landing experimental block supports continues, there shouldn't be a scenario with a new experimental block support that needs stabilizing.
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. Absolutely, what you've described captures my thinking, too, so you're not missing anything here!
That's where I was coming from, too. I was mostly thinking out loud, which is to say, flagging something that could theoretically be an issue at some distant point in the future. And it's at that distant point (if we're adding an experimental support that uses arrays) where I think it could be addressed, rather than now 🙂
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.
Indeed — my vote is to avoid using the
Contributor
Author
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. 👍 Having it on the record here will also flag it for our future selves or others, if it is really needed in the end. |
||
| $updated_supports[ $stabilized_key ] = $experimental_first | ||
| ? array_merge( $config, $args['supports'][ $stabilized_key ] ) | ||
| : array_merge( $args['supports'][ $stabilized_key ], $config ); | ||
| } else { | ||
| $updated_supports[ $stabilized_key ] = $experimental_first | ||
| ? $args['supports'][ $stabilized_key ] | ||
| : $config; | ||
| } | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| foreach ( $current_typography_supports as $key => $value ) { | ||
| if ( array_key_exists( $key, $experimental_typography_supports_to_stable ) ) { | ||
| $stable_typography_supports[ $experimental_typography_supports_to_stable[ $key ] ] = $value; | ||
| } else { | ||
| $stable_typography_supports[ $key ] = $value; | ||
| // Stabilize individual support feature keys e.g. __experimentalFontFamily => fontFamily. | ||
| if ( is_array( $experimental_to_stable_keys[ $support ] ) ) { | ||
| $stable_support_config = array(); | ||
| foreach ( $config as $key => $value ) { | ||
| if ( array_key_exists( $key, $experimental_to_stable_keys[ $support ] ) ) { | ||
| $stable_support_config[ $experimental_to_stable_keys[ $support ][ $key ] ] = $value; | ||
| } else { | ||
| $stable_support_config[ $key ] = $value; | ||
| } | ||
| } | ||
| $updated_supports[ $support ] = $stable_support_config; | ||
| } | ||
| } | ||
|
|
||
| $args['supports']['typography'] = $stable_typography_supports; | ||
| $args['supports'] = $updated_supports; | ||
|
|
||
| return $args; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.