diff --git a/bin/packages/build.js b/bin/packages/build.js index 16a886cac0479..f2a9e381875f2 100755 --- a/bin/packages/build.js +++ b/bin/packages/build.js @@ -193,7 +193,14 @@ if ( files.length ) { bar.tick( 0 ); stream = glob.stream( - [ `${ PACKAGES_DIR }/*/src/**/*.js`, `${ PACKAGES_DIR }/*/src/*.scss` ], + [ + `${ PACKAGES_DIR }/*/src/**/*.js`, + `${ PACKAGES_DIR }/*/src/*.scss`, + `${ PACKAGES_DIR }/block-library/src/**/*.js`, + `${ PACKAGES_DIR }/block-library/src/*/style.scss`, + `${ PACKAGES_DIR }/block-library/src/*/editor.scss`, + `${ PACKAGES_DIR }/block-library/src/*.scss`, + ], { ignore: [ `**/benchmark/**`, diff --git a/lib/blocks.php b/lib/blocks.php index 751b178fc8a27..f4f5a6536cee2 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -17,7 +17,7 @@ function gutenberg_reregister_core_block_types() { 'audio', 'button', 'buttons', - 'classic', + 'freeform', 'code', 'column', 'columns', @@ -120,6 +120,7 @@ function gutenberg_reregister_core_block_types() { $registry->unregister( $metadata['name'] ); } + gutenberg_register_core_block_styles( $folder_name ); register_block_type_from_metadata( $block_json_file ); } @@ -132,11 +133,13 @@ function gutenberg_reregister_core_block_types() { if ( $registry->is_registered( $block_names ) ) { $registry->unregister( $block_names ); } + gutenberg_register_core_block_styles( $block_names ); } elseif ( is_array( $block_names ) ) { foreach ( $block_names as $block_name ) { if ( $registry->is_registered( $block_name ) ) { $registry->unregister( $block_name ); } + gutenberg_register_core_block_styles( $block_name ); } } @@ -147,6 +150,46 @@ function gutenberg_reregister_core_block_types() { add_action( 'init', 'gutenberg_reregister_core_block_types' ); +/** + * Registers block styles for a core block. + * + * @param string $block_name The block-name. + * + * @return void + */ +function gutenberg_register_core_block_styles( $block_name ) { + if ( ! gutenberg_should_load_separate_block_styles() ) { + return; + } + + $block_name = str_replace( 'core/', '', $block_name ); + + $style_path = is_rtl() + ? "build/block-library/blocks/$block_name/style-rtl.css" + : "build/block-library/blocks/$block_name/style.css"; + $editor_style_path = is_rtl() + ? "build/block-library/blocks/$block_name/style-editor-rtl.css" + : "build/block-library/blocks/$block_name/style-editor.css"; + + if ( file_exists( gutenberg_dir_path() . $style_path ) ) { + wp_register_style( + 'wp-block-' . $block_name, + gutenberg_url( $style_path ), + array(), + filemtime( gutenberg_dir_path() . $style_path ) + ); + } + + if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) { + wp_register_style( + 'wp-block-' . $block_name . '-editor', + gutenberg_url( $editor_style_path ), + array(), + filemtime( gutenberg_dir_path() . $editor_style_path ) + ); + } +} + /** * Complements the implementation of block type `core/social-icon`, whether it * be provided by core or the plugin, with derived block types for each diff --git a/lib/client-assets.php b/lib/client-assets.php index fb3b528a56642..47d178667b2ba 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -335,12 +335,13 @@ function gutenberg_register_packages_styles( $styles ) { ); $styles->add_data( 'wp-components', 'rtl', 'replace' ); + $block_library_filename = gutenberg_should_load_separate_block_styles() ? 'common' : 'style'; gutenberg_override_style( $styles, 'wp-block-library', - gutenberg_url( 'build/block-library/style.css' ), + gutenberg_url( 'build/block-library/' . $block_library_filename . '.css' ), array(), - filemtime( gutenberg_dir_path() . 'build/block-library/style.css' ) + filemtime( gutenberg_dir_path() . 'build/block-library/' . $block_library_filename . '.css' ) ); $styles->add_data( 'wp-block-library', 'rtl', 'replace' ); diff --git a/lib/compat.php b/lib/compat.php index df4e144a1131a..d211a23dc4915 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -412,6 +412,48 @@ function gutenberg_render_block_with_assigned_block_context( $pre_render, $parse } add_filter( 'pre_render_block', 'gutenberg_render_block_with_assigned_block_context', 9, 2 ); +/** + * Determine if the current theme needs to load separate block styles or not. + * + * @return bool + */ +function gutenberg_should_load_separate_block_styles() { + $load_separate_styles = gutenberg_is_fse_theme(); + /** + * Determine if separate styles will be loaded for blocks on-render or not. + * + * @param bool $load_separate_styles Whether separate styles will be loaded or not. + * + * @return bool + */ + return apply_filters( 'load_separate_block_styles', $load_separate_styles ); +} + +/** + * Remove the `wp_enqueue_registered_block_scripts_and_styles` hook if needed. + * + * @return void + */ +function gutenberg_remove_hook_wp_enqueue_registered_block_scripts_and_styles() { + if ( gutenberg_should_load_separate_block_styles() ) { + /** + * Avoid enqueueing block assets of all registered blocks for all posts, instead + * deferring to block render mechanics to enqueue scripts, thereby ensuring only + * blocks of the content have their assets enqueued. + * + * This can be removed once minimum support for the plugin is outside the range + * of the version associated with closure of the following ticket. + * + * @see https://core.trac.wordpress.org/ticket/50328 + * + * @see WP_Block::render + */ + remove_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); + } +} + +add_action( 'init', 'gutenberg_remove_hook_wp_enqueue_registered_block_scripts_and_styles' ); + /** * Callback hooked to the register_block_type_args filter. * diff --git a/packages/block-library/src/archives/block.json b/packages/block-library/src/archives/block.json index 7be2a90e41e8d..d35f8b05001c4 100644 --- a/packages/block-library/src/archives/block.json +++ b/packages/block-library/src/archives/block.json @@ -15,5 +15,6 @@ "supports": { "align": true, "html": false - } + }, + "editorStyle": "wp-block-archives-editor" } diff --git a/packages/block-library/src/audio/block.json b/packages/block-library/src/audio/block.json index a077767932e73..c8e6e8e19d693 100644 --- a/packages/block-library/src/audio/block.json +++ b/packages/block-library/src/audio/block.json @@ -39,5 +39,7 @@ "supports": { "anchor": true, "align": true - } + }, + "editorStyle": "wp-block-audio-editor", + "style": "wp-block-audio" } diff --git a/packages/block-library/src/block/block.json b/packages/block-library/src/block/block.json index 97afcca2e594b..aece916ab601b 100644 --- a/packages/block-library/src/block/block.json +++ b/packages/block-library/src/block/block.json @@ -11,5 +11,6 @@ "customClassName": false, "html": false, "inserter": false - } + }, + "editorStyle": "wp-block-editor" } diff --git a/packages/block-library/src/button/block.json b/packages/block-library/src/button/block.json index 622c43ef12429..a5b4435271483 100644 --- a/packages/block-library/src/button/block.json +++ b/packages/block-library/src/button/block.json @@ -63,5 +63,7 @@ "alignWide": false, "reusable": false, "__experimentalSelector": ".wp-block-button > a" - } + }, + "editorStyle": "wp-block-button-editor", + "style": "wp-block-button" } diff --git a/packages/block-library/src/buttons/block.json b/packages/block-library/src/buttons/block.json index 003f7719e9811..704b3a33b29a9 100644 --- a/packages/block-library/src/buttons/block.json +++ b/packages/block-library/src/buttons/block.json @@ -14,5 +14,7 @@ "supports": { "anchor": true, "align": [ "wide", "full" ] - } + }, + "editorStyle": "wp-block-buttons-editor", + "style": "wp-block-buttons" } diff --git a/packages/block-library/src/calendar/block.json b/packages/block-library/src/calendar/block.json index eb585dec70156..edb73671e692a 100644 --- a/packages/block-library/src/calendar/block.json +++ b/packages/block-library/src/calendar/block.json @@ -12,5 +12,6 @@ }, "supports": { "align": true - } + }, + "style": "wp-block-calendar" } diff --git a/packages/block-library/src/categories/block.json b/packages/block-library/src/categories/block.json index be8e9d1c213e7..5fe562622c83e 100644 --- a/packages/block-library/src/categories/block.json +++ b/packages/block-library/src/categories/block.json @@ -19,5 +19,7 @@ "supports": { "align": true, "html": false - } + }, + "editorStyle": "wp-block-categories-editor", + "style": "wp-block-categories" } diff --git a/packages/block-library/src/code/block.json b/packages/block-library/src/code/block.json index e6a0c94e51ba3..0f29cf33cc030 100644 --- a/packages/block-library/src/code/block.json +++ b/packages/block-library/src/code/block.json @@ -12,5 +12,6 @@ "supports": { "anchor": true, "fontSize": true - } + }, + "style": "wp-block-code" } diff --git a/packages/block-library/src/columns/block.json b/packages/block-library/src/columns/block.json index 0cc93b718a89b..7aa5ff3e1bc8c 100644 --- a/packages/block-library/src/columns/block.json +++ b/packages/block-library/src/columns/block.json @@ -18,5 +18,7 @@ "gradients": true, "link": true } - } + }, + "editorStyle": "wp-block-columns-editor", + "style": "wp-block-columns" } diff --git a/packages/block-library/src/common.scss b/packages/block-library/src/common.scss new file mode 100644 index 0000000000000..bf437ce82cbb2 --- /dev/null +++ b/packages/block-library/src/common.scss @@ -0,0 +1,66 @@ +// The following selectors have increased specificity (using the :root prefix) +// to assure colors take effect over another base class color, mainly to let +// the colors override the added specificity by link states such as :hover. + +:root { + // Background colors. + @include background-colors(); + + // Foreground colors. + @include foreground-colors(); + + // Gradients + @include gradient-colors(); + + .has-link-color a { + color: var(--wp--style--color--link, #00e); + } +} + +// Font sizes. +.has-small-font-size { + font-size: 0.8125em; +} + +.has-regular-font-size, // Not used now, kept because of backward compatibility. +.has-normal-font-size { + font-size: 1em; +} + +.has-medium-font-size { + font-size: 1.25em; +} + +.has-large-font-size { + font-size: 2.25em; +} + +.has-larger-font-size, // Not used now, kept because of backward compatibility. +.has-huge-font-size { + font-size: 2.625em; +} + +// Text alignments. +.has-text-align-center { + text-align: center; +} + +.has-text-align-left { + /*rtl:ignore*/ + text-align: left; +} + +.has-text-align-right { + /*rtl:ignore*/ + text-align: right; +} + +// This tag marks the end of the styles that apply to editing canvas contents and need to be manipulated when we resize the editor. +#end-resizable-editor-section { + display: none; +} + +// Block alignments. +.aligncenter { + clear: both; +} diff --git a/packages/block-library/src/cover/block.json b/packages/block-library/src/cover/block.json index 29f1b17d7bb23..b0b2d58bde2aa 100644 --- a/packages/block-library/src/cover/block.json +++ b/packages/block-library/src/cover/block.json @@ -57,5 +57,7 @@ "spacing": { "padding": true } - } + }, + "editorStyle": "wp-block-cover-editor", + "style": "wp-block-cover" } diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index e1f73e1edf8c7..0ece7da318dc6 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -13,7 +13,7 @@ @import "./cover/editor.scss"; @import "./embed/editor.scss"; @import "./file/editor.scss"; -@import "./classic/editor.scss"; +@import "./freeform/editor.scss"; @import "./gallery/editor.scss"; @import "./group/editor.scss"; @import "./heading/editor.scss"; diff --git a/packages/block-library/src/embed/block.json b/packages/block-library/src/embed/block.json index 3f6531af5779f..04de8cb589ddd 100644 --- a/packages/block-library/src/embed/block.json +++ b/packages/block-library/src/embed/block.json @@ -34,5 +34,7 @@ "align": true, "reusable": false, "html": false - } + }, + "editorStyle": "wp-block-embed-editor", + "style": "wp-block-embed" } diff --git a/packages/block-library/src/file/block.json b/packages/block-library/src/file/block.json index 230942f76a6c3..ec42e3e31bf87 100644 --- a/packages/block-library/src/file/block.json +++ b/packages/block-library/src/file/block.json @@ -39,5 +39,7 @@ "supports": { "anchor": true, "align": true - } + }, + "editorStyle": "wp-block-file-editor", + "style": "wp-block-file" } diff --git a/packages/block-library/src/classic/block.json b/packages/block-library/src/freeform/block.json similarity index 83% rename from packages/block-library/src/classic/block.json rename to packages/block-library/src/freeform/block.json index 0ee6ba171b3f8..a18cd84635004 100644 --- a/packages/block-library/src/classic/block.json +++ b/packages/block-library/src/freeform/block.json @@ -12,5 +12,6 @@ "className": false, "customClassName": false, "reusable": false - } + }, + "editorStyle": "wp-block-freeform-editor" } diff --git a/packages/block-library/src/classic/convert-to-blocks-button.js b/packages/block-library/src/freeform/convert-to-blocks-button.js similarity index 100% rename from packages/block-library/src/classic/convert-to-blocks-button.js rename to packages/block-library/src/freeform/convert-to-blocks-button.js diff --git a/packages/block-library/src/classic/edit.js b/packages/block-library/src/freeform/edit.js similarity index 100% rename from packages/block-library/src/classic/edit.js rename to packages/block-library/src/freeform/edit.js diff --git a/packages/block-library/src/classic/edit.native.js b/packages/block-library/src/freeform/edit.native.js similarity index 100% rename from packages/block-library/src/classic/edit.native.js rename to packages/block-library/src/freeform/edit.native.js diff --git a/packages/block-library/src/classic/editor.scss b/packages/block-library/src/freeform/editor.scss similarity index 100% rename from packages/block-library/src/classic/editor.scss rename to packages/block-library/src/freeform/editor.scss diff --git a/packages/block-library/src/classic/index.js b/packages/block-library/src/freeform/index.js similarity index 100% rename from packages/block-library/src/classic/index.js rename to packages/block-library/src/freeform/index.js diff --git a/packages/block-library/src/classic/save.js b/packages/block-library/src/freeform/save.js similarity index 100% rename from packages/block-library/src/classic/save.js rename to packages/block-library/src/freeform/save.js diff --git a/packages/block-library/src/gallery/block.json b/packages/block-library/src/gallery/block.json index 07c4afcc1ff7e..8beac02827f61 100644 --- a/packages/block-library/src/gallery/block.json +++ b/packages/block-library/src/gallery/block.json @@ -79,5 +79,7 @@ "supports": { "anchor": true, "align": true - } + }, + "editorStyle": "wp-block-gallery-editor", + "style": "wp-block-gallery" } diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json index 6014985192acf..e0be130edc00a 100644 --- a/packages/block-library/src/group/block.json +++ b/packages/block-library/src/group/block.json @@ -25,5 +25,7 @@ "spacing": { "padding": true } - } + }, + "editorStyle": "wp-block-group-editor", + "style": "wp-block-group" } diff --git a/packages/block-library/src/heading/block.json b/packages/block-library/src/heading/block.json index fd8a683cfd404..6cd496431f799 100644 --- a/packages/block-library/src/heading/block.json +++ b/packages/block-library/src/heading/block.json @@ -74,5 +74,7 @@ } }, "__unstablePasteTextInline": true - } + }, + "editorStyle": "wp-block-heading-editor", + "style": "wp-block-heading" } diff --git a/packages/block-library/src/html/block.json b/packages/block-library/src/html/block.json index 13aa611346e07..266b4511e0fe5 100644 --- a/packages/block-library/src/html/block.json +++ b/packages/block-library/src/html/block.json @@ -12,5 +12,6 @@ "customClassName": false, "className": false, "html": false - } + }, + "editorStyle": "wp-block-html-editor" } diff --git a/packages/block-library/src/image/block.json b/packages/block-library/src/image/block.json index ec80dc4c9ed25..02cfd21dfd9cd 100644 --- a/packages/block-library/src/image/block.json +++ b/packages/block-library/src/image/block.json @@ -72,5 +72,7 @@ }, "supports": { "anchor": true - } + }, + "editorStyle": "wp-block-image-editor", + "style": "wp-block-image" } diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 5b7ef0492d2d4..7cfcb0e0c74a9 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -57,7 +57,7 @@ import * as textColumns from './text-columns'; import * as verse from './verse'; import * as video from './video'; import * as tagCloud from './tag-cloud'; -import * as classic from './classic'; +import * as classic from './freeform'; import * as socialLinks from './social-links'; import * as socialLink from './social-link'; diff --git a/packages/block-library/src/index.native.js b/packages/block-library/src/index.native.js index 23f13a448337d..65785c7f3fb37 100644 --- a/packages/block-library/src/index.native.js +++ b/packages/block-library/src/index.native.js @@ -58,7 +58,7 @@ import * as textColumns from './text-columns'; import * as verse from './verse'; import * as video from './video'; import * as tagCloud from './tag-cloud'; -import * as classic from './classic'; +import * as classic from './freeform'; import * as group from './group'; import * as buttons from './buttons'; import * as socialLink from './social-link'; diff --git a/packages/block-library/src/latest-comments/block.json b/packages/block-library/src/latest-comments/block.json index 8ad73394cd93b..37600026f8f71 100644 --- a/packages/block-library/src/latest-comments/block.json +++ b/packages/block-library/src/latest-comments/block.json @@ -25,5 +25,7 @@ "supports": { "align": true, "html": false - } + }, + "editorStyle": "wp-block-latest-comments-editor", + "style": "wp-block-latest-comments" } diff --git a/packages/block-library/src/latest-posts/block.json b/packages/block-library/src/latest-posts/block.json index fbe711ee99788..2f603bc57274e 100644 --- a/packages/block-library/src/latest-posts/block.json +++ b/packages/block-library/src/latest-posts/block.json @@ -84,5 +84,7 @@ "supports": { "align": true, "html": false - } + }, + "editorStyle": "wp-block-latest-posts-editor", + "style": "wp-block-latest-posts" } diff --git a/packages/block-library/src/list/block.json b/packages/block-library/src/list/block.json index 23bca15ac9459..002f0bc82bc7b 100644 --- a/packages/block-library/src/list/block.json +++ b/packages/block-library/src/list/block.json @@ -33,5 +33,7 @@ "gradients": true }, "__unstablePasteTextInline": true - } + }, + "editorStyle": "wp-block-list-editor", + "style": "wp-block-list" } diff --git a/packages/block-library/src/media-text/block.json b/packages/block-library/src/media-text/block.json index e88b1b1d1b818..0e175cf04bd53 100644 --- a/packages/block-library/src/media-text/block.json +++ b/packages/block-library/src/media-text/block.json @@ -89,5 +89,7 @@ "gradients": true, "link": true } - } + }, + "editorStyle": "wp-block-media-text-editor", + "style": "wp-block-media-text" } diff --git a/packages/block-library/src/more/block.json b/packages/block-library/src/more/block.json index 4279443517b00..f49bbd58583a3 100644 --- a/packages/block-library/src/more/block.json +++ b/packages/block-library/src/more/block.json @@ -16,5 +16,6 @@ "className": false, "html": false, "multiple": false - } + }, + "editorStyle": "wp-block-more-editor" } diff --git a/packages/block-library/src/navigation-link/block.json b/packages/block-library/src/navigation-link/block.json index 689707fc5ba77..2104f50a13870 100644 --- a/packages/block-library/src/navigation-link/block.json +++ b/packages/block-library/src/navigation-link/block.json @@ -42,5 +42,7 @@ "supports": { "reusable": false, "html": false - } + }, + "editorStyle": "wp-block-navigation-link-editor", + "style": "wp-block-navigation-link" } diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index 56a586f1aac25..5b70d51eaafa7 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -56,5 +56,7 @@ "color": true, "__experimentalFontFamily": true, "__experimentalTextDecoration": true - } + }, + "editorStyle": "wp-block-navigation-editor", + "style": "wp-block-navigation" } diff --git a/packages/block-library/src/nextpage/block.json b/packages/block-library/src/nextpage/block.json index 2236627dbb7e0..f1a8a2745cb57 100644 --- a/packages/block-library/src/nextpage/block.json +++ b/packages/block-library/src/nextpage/block.json @@ -7,5 +7,6 @@ "customClassName": false, "className": false, "html": false - } + }, + "editorStyle": "wp-block-nextpage-editor" } diff --git a/packages/block-library/src/paragraph/block.json b/packages/block-library/src/paragraph/block.json index 44118c165c277..a29e22c01d5af 100644 --- a/packages/block-library/src/paragraph/block.json +++ b/packages/block-library/src/paragraph/block.json @@ -37,5 +37,7 @@ "lineHeight": true, "__experimentalSelector": "p", "__unstablePasteTextInline": true - } + }, + "editorStyle": "wp-block-paragraph-editor", + "style": "wp-block-paragraph" } diff --git a/packages/block-library/src/post-author/block.json b/packages/block-library/src/post-author/block.json index 99f1cd2c8a816..8a4d8d66dbb67 100644 --- a/packages/block-library/src/post-author/block.json +++ b/packages/block-library/src/post-author/block.json @@ -33,5 +33,7 @@ "link": true }, "lineHeight": true - } + }, + "editorStyle": "wp-block-post-author-editor", + "style": "wp-block-post-author" } diff --git a/packages/block-library/src/post-content/block.json b/packages/block-library/src/post-content/block.json index 9eb24596ec59f..1869af668fd83 100644 --- a/packages/block-library/src/post-content/block.json +++ b/packages/block-library/src/post-content/block.json @@ -9,5 +9,6 @@ "supports": { "align": [ "wide", "full" ], "html": false - } + }, + "editorStyle": "wp-block-post-content-editor" } diff --git a/packages/block-library/src/post-excerpt/block.json b/packages/block-library/src/post-excerpt/block.json index f45971f774636..2e2690d398625 100644 --- a/packages/block-library/src/post-excerpt/block.json +++ b/packages/block-library/src/post-excerpt/block.json @@ -30,5 +30,6 @@ "link": true }, "lineHeight": true - } + }, + "editorStyle": "wp-block-post-excerpt-editor" } diff --git a/packages/block-library/src/post-featured-image/block.json b/packages/block-library/src/post-featured-image/block.json index a7ac68c85ff89..f3a2deb587122 100644 --- a/packages/block-library/src/post-featured-image/block.json +++ b/packages/block-library/src/post-featured-image/block.json @@ -15,5 +15,7 @@ "supports": { "align": [ "left", "right", "center", "wide", "full" ], "html": false - } + }, + "editorStyle": "wp-block-post-featured-image-editor", + "style": "wp-block-post-featured-image" } diff --git a/packages/block-library/src/pullquote/block.json b/packages/block-library/src/pullquote/block.json index fa49196bec1d4..e8a0fd00d52b9 100644 --- a/packages/block-library/src/pullquote/block.json +++ b/packages/block-library/src/pullquote/block.json @@ -36,5 +36,7 @@ "wide", "full" ] - } + }, + "editorStyle": "wp-block-pullquote-editor", + "style": "wp-block-pullquote" } diff --git a/packages/block-library/src/query-loop/block.json b/packages/block-library/src/query-loop/block.json index 5373403ea79a5..6059febae1dd6 100644 --- a/packages/block-library/src/query-loop/block.json +++ b/packages/block-library/src/query-loop/block.json @@ -11,5 +11,7 @@ "supports": { "reusable": false, "html": false - } + }, + "style": "wp-block-query-loop", + "editorStyle": "wp-block-query-loop-editor" } diff --git a/packages/block-library/src/query/block.json b/packages/block-library/src/query/block.json index 016fa44fbcc0e..302ea1a8e8085 100644 --- a/packages/block-library/src/query/block.json +++ b/packages/block-library/src/query/block.json @@ -41,5 +41,6 @@ ], "supports": { "html": false - } + }, + "editorStyle": "wp-block-query-editor" } diff --git a/packages/block-library/src/quote/block.json b/packages/block-library/src/quote/block.json index 9de3a338c9f1e..bba83461367fa 100644 --- a/packages/block-library/src/quote/block.json +++ b/packages/block-library/src/quote/block.json @@ -22,5 +22,7 @@ }, "supports": { "anchor": true - } + }, + "editorStyle": "wp-block-quote-editor", + "style": "wp-block-quote" } diff --git a/packages/block-library/src/rss/block.json b/packages/block-library/src/rss/block.json index 49555c41cb0ea..15a0feaa6f355 100644 --- a/packages/block-library/src/rss/block.json +++ b/packages/block-library/src/rss/block.json @@ -39,5 +39,7 @@ "supports": { "align": true, "html": false - } + }, + "editorStyle": "wp-block-rss-editor", + "style": "wp-block-rss" } diff --git a/packages/block-library/src/search/block.json b/packages/block-library/src/search/block.json index d57ba7fd9c390..534be0e97cb5f 100644 --- a/packages/block-library/src/search/block.json +++ b/packages/block-library/src/search/block.json @@ -35,5 +35,7 @@ "supports": { "align": [ "left", "center", "right" ], "html": false - } + }, + "editorStyle": "wp-block-search-editor", + "style": "wp-block-search" } diff --git a/packages/block-library/src/separator/block.json b/packages/block-library/src/separator/block.json index 3cf6ae1b505ee..2983a93a86190 100644 --- a/packages/block-library/src/separator/block.json +++ b/packages/block-library/src/separator/block.json @@ -13,5 +13,7 @@ "supports": { "anchor": true, "align": ["center","wide","full"] - } + }, + "editorStyle": "wp-block-separator-editor", + "style": "wp-block-separator" } diff --git a/packages/block-library/src/shortcode/block.json b/packages/block-library/src/shortcode/block.json index 8c41976373904..4f92abd419f6e 100644 --- a/packages/block-library/src/shortcode/block.json +++ b/packages/block-library/src/shortcode/block.json @@ -12,5 +12,6 @@ "className": false, "customClassName": false, "html": false - } + }, + "editorStyle": "wp-block-shortcode-editor" } diff --git a/packages/block-library/src/site-logo/block.json b/packages/block-library/src/site-logo/block.json index b2818f5e751ac..35313f0212b39 100644 --- a/packages/block-library/src/site-logo/block.json +++ b/packages/block-library/src/site-logo/block.json @@ -12,5 +12,7 @@ }, "supports": { "html": false - } + }, + "editorStyle": "wp-block-site-logo-editor", + "style": "wp-block-site-logo" } diff --git a/packages/block-library/src/social-link/block.json b/packages/block-library/src/social-link/block.json index 0b9072548b6f8..0ec91e23d905d 100644 --- a/packages/block-library/src/social-link/block.json +++ b/packages/block-library/src/social-link/block.json @@ -22,5 +22,6 @@ "supports": { "reusable": false, "html": false - } + }, + "editorStyle": "wp-block-social-link-editor" } diff --git a/packages/block-library/src/social-links/block.json b/packages/block-library/src/social-links/block.json index 47147dee69c89..2bc44dd79f36e 100644 --- a/packages/block-library/src/social-links/block.json +++ b/packages/block-library/src/social-links/block.json @@ -21,5 +21,7 @@ "right" ], "anchor": true - } + }, + "editorStyle": "wp-block-social-links-editor", + "style": "wp-block-social-links" } diff --git a/packages/block-library/src/spacer/block.json b/packages/block-library/src/spacer/block.json index 9882f53dfa5af..fd4172079fa50 100644 --- a/packages/block-library/src/spacer/block.json +++ b/packages/block-library/src/spacer/block.json @@ -10,5 +10,7 @@ }, "supports": { "anchor": true - } + }, + "editorStyle": "wp-block-spacer-editor", + "style": "wp-block-spacer" } diff --git a/packages/block-library/src/style.scss b/packages/block-library/src/style.scss index e9b44f287033c..f1a2cbd05c678 100644 --- a/packages/block-library/src/style.scss +++ b/packages/block-library/src/style.scss @@ -42,69 +42,4 @@ @import "./video/style.scss"; @import "./post-featured-image/style.scss"; -// The following selectors have increased specificity (using the :root prefix) -// to assure colors take effect over another base class color, mainly to let -// the colors override the added specificity by link states such as :hover. - -:root { - // Background colors. - @include background-colors(); - - // Foreground colors. - @include foreground-colors(); - - // Gradients - @include gradient-colors(); - - .has-link-color a { - color: var(--wp--style--color--link, #00e); - } -} - -// Font sizes. -.has-small-font-size { - font-size: 0.8125em; -} - -.has-regular-font-size, // Not used now, kept because of backward compatibility. -.has-normal-font-size { - font-size: 1em; -} - -.has-medium-font-size { - font-size: 1.25em; -} - -.has-large-font-size { - font-size: 2.25em; -} - -.has-larger-font-size, // Not used now, kept because of backward compatibility. -.has-huge-font-size { - font-size: 2.625em; -} - -// Text alignments. -.has-text-align-center { - text-align: center; -} - -.has-text-align-left { - /*rtl:ignore*/ - text-align: left; -} - -.has-text-align-right { - /*rtl:ignore*/ - text-align: right; -} - -// This tag marks the end of the styles that apply to editing canvas contents and need to be manipulated when we resize the editor. -#end-resizable-editor-section { - display: none; -} - -// Block alignments. -.aligncenter { - clear: both; -} +@import "common.scss"; diff --git a/packages/block-library/src/subhead/block.json b/packages/block-library/src/subhead/block.json index 6fe2bf287f7ea..2dd213d5391d0 100644 --- a/packages/block-library/src/subhead/block.json +++ b/packages/block-library/src/subhead/block.json @@ -15,5 +15,7 @@ "supports": { "inserter": false, "multiple": false - } + }, + "editorStyle": "wp-block-subhead-editor", + "style": "wp-block-subhead" } diff --git a/packages/block-library/src/table/block.json b/packages/block-library/src/table/block.json index 1c3529f93eca9..65e907620afb5 100644 --- a/packages/block-library/src/table/block.json +++ b/packages/block-library/src/table/block.json @@ -126,5 +126,7 @@ "anchor": true, "align": true, "__experimentalSelector": ".wp-block-table > table" - } + }, + "editorStyle": "wp-block-table-editor", + "style": "wp-block-table" } diff --git a/packages/block-library/src/tag-cloud/block.json b/packages/block-library/src/tag-cloud/block.json index 3ec21ed2765cc..de4b9b9714f66 100644 --- a/packages/block-library/src/tag-cloud/block.json +++ b/packages/block-library/src/tag-cloud/block.json @@ -15,5 +15,6 @@ "supports": { "html": false, "align": true - } + }, + "editorStyle": "wp-block-tag-cloud-editor" } diff --git a/packages/block-library/src/template-part/block.json b/packages/block-library/src/template-part/block.json index 2cf99160a027b..3d9e5dfa0476e 100644 --- a/packages/block-library/src/template-part/block.json +++ b/packages/block-library/src/template-part/block.json @@ -24,5 +24,6 @@ "gradients": true, "link": true } - } + }, + "editorStyle": "wp-block-template-part-editor" } diff --git a/packages/block-library/src/text-columns/block.json b/packages/block-library/src/text-columns/block.json index 5cfe5e4712b07..bb52b71b0183d 100644 --- a/packages/block-library/src/text-columns/block.json +++ b/packages/block-library/src/text-columns/block.json @@ -29,5 +29,7 @@ }, "supports": { "inserter": false - } + }, + "editorStyle": "wp-block-text-columns-editor", + "style": "wp-block-text-columns" } diff --git a/packages/block-library/src/verse/block.json b/packages/block-library/src/verse/block.json index 77111fac4849c..ce6936ab7f40c 100644 --- a/packages/block-library/src/verse/block.json +++ b/packages/block-library/src/verse/block.json @@ -17,5 +17,7 @@ "supports": { "anchor": true, "__experimentalFontFamily": true - } + }, + "style": "wp-block-verse", + "editorStyle": "wp-block-verse-editor" } diff --git a/packages/block-library/src/video/block.json b/packages/block-library/src/video/block.json index e2b7eab17560e..9f8b569d239b2 100644 --- a/packages/block-library/src/video/block.json +++ b/packages/block-library/src/video/block.json @@ -72,5 +72,7 @@ "supports": { "anchor": true, "align": true - } + }, + "editorStyle": "wp-block-video-editor", + "style": "wp-block-video" } diff --git a/packages/edit-widgets/src/blocks/legacy-widget/block.json b/packages/edit-widgets/src/blocks/legacy-widget/block.json index 49b8c20eacd12..934ea46ca1493 100644 --- a/packages/edit-widgets/src/blocks/legacy-widget/block.json +++ b/packages/edit-widgets/src/blocks/legacy-widget/block.json @@ -28,5 +28,6 @@ }, "parent": [ "core/widget-area" - ] + ], + "editorStyle": "wp-block-legacy-widget-editor" } diff --git a/packages/edit-widgets/src/blocks/widget-area/block.json b/packages/edit-widgets/src/blocks/widget-area/block.json index e5d4d713a3bd9..fdec21c57e931 100644 --- a/packages/edit-widgets/src/blocks/widget-area/block.json +++ b/packages/edit-widgets/src/blocks/widget-area/block.json @@ -15,5 +15,7 @@ "customClassName": false, "reusable": false, "__experimentalToolbar": false - } + }, + "editorStyle": "wp-block-widget-area-editor", + "style": "wp-block-widget-area" } diff --git a/webpack.config.js b/webpack.config.js index 9bb0bcde35b2f..de8be6fab09e9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -41,6 +41,29 @@ const gutenbergPackages = Object.keys( dependencies ) ) .map( ( packageName ) => packageName.replace( WORDPRESS_NAMESPACE, '' ) ); +const stylesTransform = ( content ) => { + if ( mode === 'production' ) { + return postcss( [ + require( 'cssnano' )( { + preset: [ + 'default', + { + discardComments: { + removeAll: true, + }, + }, + ], + } ), + ] ) + .process( content, { + from: 'src/app.css', + to: 'dest/app.css', + } ) + .then( ( result ) => result.css ); + } + return content; +}; + module.exports = { optimization: { // Only concatenate modules in production, when not analyzing bundles. @@ -140,30 +163,43 @@ module.exports = { from: `./packages/${ packageName }/build-style/*.css`, to: `./build/${ packageName }/`, flatten: true, - transform: ( content ) => { - if ( mode === 'production' ) { - return postcss( [ - require( 'cssnano' )( { - preset: [ - 'default', - { - discardComments: { - removeAll: true, - }, - }, - ], - } ), - ] ) - .process( content, { - from: 'src/app.css', - to: 'dest/app.css', - } ) - .then( ( result ) => result.css ); - } - return content; - }, + transform: stylesTransform, } ) ) ), + new CopyWebpackPlugin( [ + { + from: './packages/block-library/build-style/*/style.css', + test: new RegExp( + `([\\w-]+)${ escapeRegExp( sep ) }style\\.css$` + ), + to: 'build/block-library/blocks/[1]/style.css', + transform: stylesTransform, + }, + { + from: './packages/block-library/build-style/*/style-rtl.css', + test: new RegExp( + `([\\w-]+)${ escapeRegExp( sep ) }style-rtl\\.css$` + ), + to: 'build/block-library/blocks/[1]/style-rtl.css', + transform: stylesTransform, + }, + { + from: './packages/block-library/build-style/*/editor.css', + test: new RegExp( + `([\\w-]+)${ escapeRegExp( sep ) }editor\\.css$` + ), + to: 'build/block-library/blocks/[1]/editor.css', + transform: stylesTransform, + }, + { + from: './packages/block-library/build-style/*/editor-rtl.css', + test: new RegExp( + `([\\w-]+)${ escapeRegExp( sep ) }editor-rtl\\.css$` + ), + to: 'build/block-library/blocks/[1]/editor-rtl.css', + transform: stylesTransform, + }, + ] ), new CopyWebpackPlugin( Object.entries( { './packages/block-library/src/': 'build/block-library/blocks/',