-
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 default editor styles applied to themes without theme.json and without editor styles #34439
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9c0a85b
Add default editor styles applied to themes without theme.json, witho…
youknowriad eea9799
Fix global styles override
youknowriad 9d32ac2
Push some default styles.
jasmussen a9da477
Update packages/block-editor/src/default-editor-styles.scss
jasmussen ae1b05d
Fix unit tests
youknowriad 7ead394
Fix PHPCS
youknowriad 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 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,38 @@ | ||
<?php | ||
/** | ||
* Loads the default editor styles. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Load the default editor styles. | ||
* These styles are used if the "no theme styles" options is triggered | ||
* or on themes without their own editor styles. | ||
* | ||
* @param array $settings Default editor settings. | ||
* | ||
* @return array Filtered editor settings. | ||
*/ | ||
function gutenberg_extend_block_editor_settings_with_default_editor_styles( $settings ) { | ||
$default_editor_styles_file = gutenberg_dir_path() . 'build/block-editor/default-editor-styles.css'; | ||
$settings['defaultEditorStyles'] = array( | ||
array( | ||
'css' => file_get_contents( $default_editor_styles_file ), | ||
), | ||
); | ||
|
||
// Remove the default font addition from Core Code. | ||
$styles_without_core_styles = array(); | ||
if ( isset( $settings['styles'] ) ) { | ||
foreach ( $settings['styles'] as $style ) { | ||
if ( 'core' !== $style['__unstableType'] ) { | ||
$styles_without_core_styles[] = $style; | ||
} | ||
} | ||
} | ||
$settings['styles'] = $styles_without_core_styles; | ||
|
||
return $settings; | ||
} | ||
add_filter( 'block_editor_settings_all', 'gutenberg_extend_block_editor_settings_with_default_editor_styles' ); |
This file contains 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 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 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 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,24 @@ | ||
/** | ||
* Default editor styles. | ||
* | ||
* These styles are shown if a theme does not register its own editor style, | ||
* a theme.json file, or has toggled off "Use theme styles" in preferences. | ||
*/ | ||
|
||
body { | ||
font-family: $default-font; | ||
font-size: 18px; | ||
line-height: 1.5; | ||
--wp--style--block-gap: 2em; | ||
} | ||
|
||
p { | ||
line-height: 1.8; | ||
} | ||
|
||
.editor-post-title__block { | ||
margin-top: 2em; | ||
margin-bottom: 1em; | ||
font-size: 2.5em; | ||
font-weight: 800; | ||
} | ||
This file contains 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
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.
@jasmussen this is the styles file if you want to tweak it.
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've got a related PR at #34334 that enqueues the global styles for all themes. After it lands, shouldn't these styles live at
lib/theme.json
?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 know, what I know is that they need to be in a dedicated setting in order for this logic to apply https://github.com/WordPress/gutenberg/pull/34439/files#diff-d00cfe048041886ee9b16f6f42422317b6e770cbea20cbe0e4d0ca7c8e0ec0e1R159-R161
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.
hey, so since #35424 all themes provide some
styles
to settings: at least they'll have the core preset styles. That inadvertently cause a bug for themes that don't provide any editor styles: they no longer had any defaults. See issue at #35730I've created a fix for this at #35736 but I'm not convinced is the right approach. So I've prepared a second fix to absorb the defaults as part of the styles we send to the client in
global-styles.php
, see #35737I'd love hearing your thoughts on which approach makes more sense to you.