Repository navigation
Style states: Use symbols for property keys to avoid clashes #79210
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0f0ed7a
Use @ symbol for responsive states and - symbol for custom states
talldan 0c3b4a8
Fix preview panel
talldan 15d7d86
Linter fix
talldan 190bf48
Add back compat code
talldan c088f10
Move resolve_style_state_aliases to lib/compat
talldan 4fe5a67
Add helpful comment
talldan f970042
Add changelog
talldan 8b12bf9
Fix list item symbol for backport changelog
talldan 998c47f
Fix backport changelog formatting again
talldan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/12253 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/79210 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?php | ||
| /** | ||
| * Plugin-specific style state alias back compatibility. | ||
| * | ||
| * @package Gutenberg | ||
| */ | ||
|
|
||
| /** | ||
| * Resolves temporary aliases for persisted style state keys to their canonical keys. | ||
| * | ||
| * This keeps compatibility for Gutenberg plugin content created before | ||
| * responsive states used '@' and custom states used '-'. Remove after the | ||
| * deprecation window ends. | ||
| * | ||
| * DO NOT BACKPORT TO CORE. | ||
| * | ||
| * @param array $styles Persisted style data. | ||
| * @param string|null $block_name Current block name, when walking block styles. | ||
| * @return array Style data with canonical style state keys. | ||
| */ | ||
| function gutenberg_resolve_style_state_aliases( $styles, $block_name = null ) { | ||
| if ( ! is_array( $styles ) ) { | ||
| return $styles; | ||
| } | ||
|
|
||
| $responsive_breakpoint_aliases = array( | ||
| '@mobile' => 'mobile', | ||
| '@tablet' => 'tablet', | ||
| ); | ||
|
|
||
| foreach ( $responsive_breakpoint_aliases as $state => $legacy_state ) { | ||
| if ( array_key_exists( $legacy_state, $styles ) && ! array_key_exists( $state, $styles ) ) { | ||
| $styles[ $state ] = $styles[ $legacy_state ]; | ||
| } | ||
| unset( $styles[ $legacy_state ] ); | ||
| } | ||
|
|
||
| $block_custom_state_aliases = array( | ||
| 'core/navigation-link' => array( | ||
| '-current' => '@current', | ||
| ), | ||
| ); | ||
|
|
||
| if ( $block_name && isset( $block_custom_state_aliases[ $block_name ] ) ) { | ||
| foreach ( $block_custom_state_aliases[ $block_name ] as $state => $legacy_state ) { | ||
| if ( array_key_exists( $legacy_state, $styles ) && ! array_key_exists( $state, $styles ) ) { | ||
| $styles[ $state ] = $styles[ $legacy_state ]; | ||
| } | ||
| unset( $styles[ $legacy_state ] ); | ||
| } | ||
| } | ||
|
|
||
| foreach ( $styles as $key => $value ) { | ||
| if ( ! is_array( $value ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| if ( 'blocks' === $key ) { | ||
| foreach ( $value as $child_block_name => $child_value ) { | ||
| $styles[ $key ][ $child_block_name ] = gutenberg_resolve_style_state_aliases( $child_value, $child_block_name ); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| if ( 'elements' === $key || 'variations' === $key ) { | ||
| foreach ( $value as $child_key => $child_value ) { | ||
| $styles[ $key ][ $child_key ] = gutenberg_resolve_style_state_aliases( $child_value, $block_name ); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| $styles[ $key ] = gutenberg_resolve_style_state_aliases( $value, $block_name ); | ||
| } | ||
|
|
||
| return $styles; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 did some drive-by smoke testing, it's working well and I like the syntax direction!
Especially
@mobile/@tabletfor responsive states... avoids style property clashes without changing the shape.One thing that occurred to me for later in the cycle: as pseudo, responsive, and custom selector states grow, we'll probably want some small unifying doc for "style states" and their key prefixes.
They seem to be documented separately, so a convention exists but could be explicit.