diff --git a/docs/manifest.json b/docs/manifest.json
index 75b5514dca1e96..f085fcbe45fa06 100644
--- a/docs/manifest.json
+++ b/docs/manifest.json
@@ -1361,6 +1361,12 @@
"markdown_source": "../packages/format-library/README.md",
"parent": "packages"
},
+ {
+ "title": "@wordpress/global-styles",
+ "slug": "packages-global-styles",
+ "markdown_source": "../packages/global-styles/README.md",
+ "parent": "packages"
+ },
{
"title": "@wordpress/hooks",
"slug": "packages-hooks",
diff --git a/experimental-default-global-styles.json b/experimental-default-global-styles.json
deleted file mode 100644
index da4314beaaf322..00000000000000
--- a/experimental-default-global-styles.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "color": {
- "primary": "#52accc",
- "background": "white",
- "text": "black"
- }
-}
diff --git a/lib/global-styles.php b/lib/global-styles.php
index 6c98d272202976..4cbbc197b2ddc1 100644
--- a/lib/global-styles.php
+++ b/lib/global-styles.php
@@ -90,11 +90,11 @@ function gutenberg_experimental_global_styles_get_user() {
*
* @param array $post_status_filter Filter CPT by post status.
* By default, only fetches published posts.
- * @param bool $should_create_draft Whether a new draft should be created
- * if no CPT was found. False by default.
+ * @param bool $should_create_cpt Whether a new draft should be created
+ * if no CPT was found. False by default.
* @return array Custom Post Type for the user's Global Styles.
*/
-function gutenberg_experimental_global_styles_get_user_cpt( $post_status_filter = array( 'publish' ), $should_create_draft = false ) {
+function gutenberg_experimental_global_styles_get_user_cpt( $post_status_filter = array( 'publish' ), $should_create_cpt = false ) {
$user_cpt = array();
$post_type_filter = 'wp_global_styles';
$post_name_filter = 'wp-global-styles-' . strtolower( wp_get_theme()->get( 'TextDomain' ) );
@@ -111,11 +111,11 @@ function gutenberg_experimental_global_styles_get_user_cpt( $post_status_filter
if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) {
$user_cpt = $recent_posts[0];
- } elseif ( $should_create_draft ) {
+ } elseif ( $should_create_cpt ) {
$cpt_post_id = wp_insert_post(
array(
'post_content' => '{}',
- 'post_status' => 'draft',
+ 'post_status' => 'publish',
'post_type' => $post_type_filter,
'post_name' => $post_name_filter,
),
@@ -148,7 +148,7 @@ function gutenberg_experimental_global_styles_get_user_cpt_id() {
*/
function gutenberg_experimental_global_styles_get_core() {
return gutenberg_experimental_global_styles_get_from_file(
- dirname( dirname( __FILE__ ) ) . '/experimental-default-global-styles.json'
+ dirname( __FILE__ ) . '/global-styles/experimental-default-global-styles.json'
);
}
@@ -164,15 +164,21 @@ function gutenberg_experimental_global_styles_get_theme() {
}
/**
- * Takes a Global Styles tree and returns a CSS rule
+ * Takes core, theme, and user preferences,
+ * builds a single global styles tree and returns a CSS rule
* that contains the corresponding CSS custom properties.
*
- * @param array $global_styles Global Styles tree.
* @return string CSS rule.
*/
-function gutenberg_experimental_global_styles_resolver( $global_styles ) {
+function gutenberg_experimental_global_styles_resolver() {
$css_rule = '';
+ $global_styles = array_replace_recursive(
+ gutenberg_experimental_global_styles_get_core(),
+ gutenberg_experimental_global_styles_get_theme(),
+ gutenberg_experimental_global_styles_get_user()
+ );
+
$token = '--';
$prefix = '--wp' . $token;
$css_vars = gutenberg_experimental_global_styles_get_css_vars( $global_styles, $prefix, $token );
@@ -189,16 +195,6 @@ function gutenberg_experimental_global_styles_resolver( $global_styles ) {
return $css_rule;
}
-/**
- * Fetches the Global Styles for each level (core, theme, user)
- * and enqueues the resulting CSS custom properties for the editor.
- */
-function gutenberg_experimental_global_styles_enqueue_assets_editor() {
- if ( gutenberg_experimental_global_styles_is_site_editor() ) {
- gutenberg_experimental_global_styles_enqueue_assets();
- }
-}
-
/**
* Fetches the Global Styles for each level (core, theme, user)
* and enqueues the resulting CSS custom properties.
@@ -208,13 +204,7 @@ function gutenberg_experimental_global_styles_enqueue_assets() {
return;
}
- $global_styles = array_merge(
- gutenberg_experimental_global_styles_get_core(),
- gutenberg_experimental_global_styles_get_theme(),
- gutenberg_experimental_global_styles_get_user()
- );
-
- $inline_style = gutenberg_experimental_global_styles_resolver( $global_styles );
+ $inline_style = gutenberg_experimental_global_styles_resolver();
if ( empty( $inline_style ) ) {
return;
}
@@ -224,51 +214,6 @@ function gutenberg_experimental_global_styles_enqueue_assets() {
wp_enqueue_style( 'global-styles' );
}
-/**
- * Adds class wp-gs to the frontend body class.
- *
- * @param array $classes Existing body classes.
- * @return array The filtered array of body classes.
- */
-function gutenberg_experimental_global_styles_wp_gs_class_front_end( $classes ) {
- if ( ! gutenberg_experimental_global_styles_has_theme_support() ) {
- return $classes;
- }
-
- return array_merge( $classes, array( 'wp-gs' ) );
-}
-
-/**
- * Adds class wp-gs to the block-editor body class.
- *
- * @param string $classes Existing body classes separated by space.
- * @return string The filtered string of body classes.
- */
-function gutenberg_experimental_global_styles_wp_gs_class_editor( $classes ) {
- if (
- ! gutenberg_experimental_global_styles_has_theme_support() ||
- ! gutenberg_experimental_global_styles_is_site_editor()
- ) {
- return $classes;
- }
-
- return $classes . ' wp-gs';
-}
-
-/**
- * Whether the loaded page is the site editor.
- *
- * @return boolean Whether the loaded page is the site editor.
- */
-function gutenberg_experimental_global_styles_is_site_editor() {
- if ( ! function_exists( 'get_current_screen' ) ) {
- return false;
- }
-
- $screen = get_current_screen();
- return ! empty( $screen ) && gutenberg_is_edit_site_page( $screen->id );
-}
-
/**
* Makes the base Global Styles (core, theme)
* and the ID of the CPT that stores the user's Global Styles
@@ -279,8 +224,7 @@ function gutenberg_experimental_global_styles_is_site_editor() {
*/
function gutenberg_experimental_global_styles_settings( $settings ) {
if (
- ! gutenberg_experimental_global_styles_has_theme_support() ||
- ! gutenberg_experimental_global_styles_is_site_editor()
+ ! gutenberg_experimental_global_styles_has_theme_support()
) {
return $settings;
}
@@ -332,10 +276,8 @@ function gutenberg_experimental_global_styles_register_cpt() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ) ) {
add_action( 'init', 'gutenberg_experimental_global_styles_register_cpt' );
- add_filter( 'body_class', 'gutenberg_experimental_global_styles_wp_gs_class_front_end' );
- add_filter( 'admin_body_class', 'gutenberg_experimental_global_styles_wp_gs_class_editor' );
add_filter( 'block_editor_settings', 'gutenberg_experimental_global_styles_settings' );
// enqueue_block_assets is not fired in edit-site, so we use separate back/front hooks instead.
add_action( 'wp_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' );
- add_action( 'admin_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets_editor' );
+ add_action( 'admin_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' );
}
diff --git a/lib/global-styles/experimental-default-global-styles.json b/lib/global-styles/experimental-default-global-styles.json
new file mode 100644
index 00000000000000..1f9ddc72d724c2
--- /dev/null
+++ b/lib/global-styles/experimental-default-global-styles.json
@@ -0,0 +1,14 @@
+{
+ "color": {
+ "background": "white",
+ "text": "black"
+ },
+ "typography": {
+ "font-base": 16,
+ "font-scale": 1.2,
+ "font-weight-base": 400,
+ "font-weight-heading": 400,
+ "line-height-base": 1.5,
+ "line-height-heading": 1.5
+ }
+}
diff --git a/package-lock.json b/package-lock.json
index 277652195f2763..1ccbad327dbec9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11013,6 +11013,7 @@
"@wordpress/data": "file:packages/data",
"@wordpress/editor": "file:packages/editor",
"@wordpress/element": "file:packages/element",
+ "@wordpress/global-styles": "file:packages/global-styles",
"@wordpress/hooks": "file:packages/hooks",
"@wordpress/i18n": "file:packages/i18n",
"@wordpress/icons": "file:packages/icons",
@@ -11387,6 +11388,16 @@
"lodash": "^4.17.15"
}
},
+ "@wordpress/global-styles": {
+ "version": "file:packages/global-styles",
+ "requires": {
+ "@babel/runtime": "^7.8.3",
+ "@wordpress/components": "file:packages/components",
+ "@wordpress/element": "file:packages/element",
+ "@wordpress/i18n": "file:packages/i18n",
+ "lodash": "4.17.15"
+ }
+ },
"@wordpress/hooks": {
"version": "file:packages/hooks",
"requires": {
diff --git a/package.json b/package.json
index ebdbd2d6dc50a1..bfe5aaa33223a5 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
"@wordpress/element": "file:packages/element",
"@wordpress/escape-html": "file:packages/escape-html",
"@wordpress/format-library": "file:packages/format-library",
+ "@wordpress/global-styles": "file:packages/global-styles",
"@wordpress/hooks": "file:packages/hooks",
"@wordpress/html-entities": "file:packages/html-entities",
"@wordpress/i18n": "file:packages/i18n",
diff --git a/packages/block-library/src/button/style.scss b/packages/block-library/src/button/style.scss
index 7bbe8900b8dc29..f2ad6bf77b130c 100644
--- a/packages/block-library/src/button/style.scss
+++ b/packages/block-library/src/button/style.scss
@@ -36,10 +36,6 @@ $blocks-button__height: 56px;
}
}
-.wp-gs .wp-block-button__link:not(.has-background) {
- background-color: var(--wp--color--primary);
-}
-
.is-style-squared .wp-block-button__link {
border-radius: 0;
}
diff --git a/packages/block-library/src/heading/style.scss b/packages/block-library/src/heading/style.scss
index b9a64de5655ec6..7b0faf3247d0c3 100644
--- a/packages/block-library/src/heading/style.scss
+++ b/packages/block-library/src/heading/style.scss
@@ -7,7 +7,8 @@
h6 {
background-color: var(--wp--color--background);
color: var(--wp--color--text);
- line-height: var(--wp--typography--line-height);
+ line-height: var(--wp--typography--line-height, var(--wp--typography--line-height-heading));
+ font-weight: var(--wp--typography--font-weight-heading);
}
}
@@ -21,3 +22,27 @@ h6 {
padding: $block-bg-padding--v $block-bg-padding--h;
}
}
+
+:root h1 {
+ font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale));
+}
+
+:root h2 {
+ font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale));
+}
+
+:root h3 {
+ font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale));
+}
+
+:root h4 {
+ font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale) * var(--wp--typography--font-scale));
+}
+
+:root h5 {
+ font-size: calc(1px * var(--wp--typography--font-base) * var(--wp--typography--font-scale));
+}
+
+:root h6 {
+ font-size: calc(0.5px * var(--wp--typography--font-base) * var(--wp--typography--font-scale));
+}
diff --git a/packages/block-library/src/paragraph/style.scss b/packages/block-library/src/paragraph/style.scss
index 9c0f3d7edc7612..c3017e3ebc1de2 100644
--- a/packages/block-library/src/paragraph/style.scss
+++ b/packages/block-library/src/paragraph/style.scss
@@ -1,7 +1,9 @@
:root p {
background-color: var(--wp--color--background);
color: var(--wp--color--text);
- line-height: var(--wp--typography--line-height);
+ line-height: var(--wp--typography--line-height, var(--wp--typography--line-height-base));
+ font-size: calc(1px * var(--wp--typography--font-base));
+ font-weight: var(--wp--typography--font-weight-base);
}
.is-small-text {
diff --git a/packages/edit-site/package.json b/packages/edit-site/package.json
index 67f140d977d0d3..adbd9cd31110ed 100644
--- a/packages/edit-site/package.json
+++ b/packages/edit-site/package.json
@@ -30,6 +30,7 @@
"@wordpress/data": "file:../data",
"@wordpress/editor": "file:../editor",
"@wordpress/element": "file:../element",
+ "@wordpress/global-styles": "file:../global-styles",
"@wordpress/hooks": "file:../hooks",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js
index 11531062934865..d9e67bba2ea4c4 100644
--- a/packages/edit-site/src/components/editor/index.js
+++ b/packages/edit-site/src/components/editor/index.js
@@ -21,6 +21,7 @@ import {
__unstableEditorStyles as EditorStyles,
} from '@wordpress/block-editor';
import { useViewportMatch } from '@wordpress/compose';
+import { GlobalStylesProvider } from '@wordpress/global-styles';
/**
* Internal dependencies
@@ -64,34 +65,41 @@ function Editor( { settings: _settings } ) {
<>
-
-
-
-
-
-
- }
- header={ }
- content={
- <>
-
-
-
- >
- }
- />
-
-
-
+
+
+
+
+
+
+
+
+ }
+ header={ }
+ content={
+ <>
+
+
+
+ >
+ }
+ />
+
+
+
+
-
-
-
+
+
+
>
) : null;
}
diff --git a/packages/edit-site/src/components/sidebar/index.js b/packages/edit-site/src/components/sidebar/index.js
index f5ee7eda2d9a23..e5486dc4cba724 100644
--- a/packages/edit-site/src/components/sidebar/index.js
+++ b/packages/edit-site/src/components/sidebar/index.js
@@ -4,31 +4,57 @@
import { createSlotFill } from '@wordpress/components';
import { ComplementaryArea } from '@wordpress/interface';
import { __ } from '@wordpress/i18n';
-import { cog, pencil } from '@wordpress/icons';
+import { cog, typography } from '@wordpress/icons';
+import { GlobalStylesControls } from '@wordpress/global-styles';
+import { useSelect } from '@wordpress/data';
const { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill(
'EditSiteSidebarInspector'
);
function Sidebar() {
+ const hasGlobalStylesSupport = useSelect( ( select ) => {
+ return Object.keys( select( 'core/block-editor' ).getSettings() ).some(
+ ( key ) => key === '__experimentalGlobalStylesUserEntityId'
+ );
+ } );
return (
<>
-
-
-
-
-
- Global Styles area
-
+ className="edit-site-complementary-area"
+ />
+ { hasGlobalStylesSupport ? (
+ <>
+
+
+
+
+
+
+ >
+ ) : (
+
+
+
+ ) }
>
);
}
diff --git a/packages/edit-site/src/components/sidebar/style.scss b/packages/edit-site/src/components/sidebar/style.scss
index 2d1771f3f796e9..77d5b922a1517d 100644
--- a/packages/edit-site/src/components/sidebar/style.scss
+++ b/packages/edit-site/src/components/sidebar/style.scss
@@ -1,4 +1,4 @@
-.edit-site-sidebar {
+.edit-site-complementary-area {
width: $sidebar-width;
> .components-panel {
@@ -15,4 +15,5 @@
.block-editor-block-inspector__card {
margin: 0;
}
+
}
diff --git a/packages/edit-site/src/style.scss b/packages/edit-site/src/style.scss
index a2a4c6023f3403..94d2885e6e14b3 100644
--- a/packages/edit-site/src/style.scss
+++ b/packages/edit-site/src/style.scss
@@ -24,6 +24,12 @@ body.toplevel_page_gutenberg-edit-site {
@include reset;
}
+// This is to prevent the blocks styles
+// from leaking into the saving modal.
+.components-modal__frame h1 {
+ background-color: inherit;
+}
+
.edit-site {
// On mobile the main content area has to scroll, otherwise you can invoke
// the over-scroll bounce on the non-scrolling container, for a bad experience.
diff --git a/packages/editor/src/editor-styles.scss b/packages/editor/src/editor-styles.scss
index a7608813a5fcc2..688f4ddb97fae9 100644
--- a/packages/editor/src/editor-styles.scss
+++ b/packages/editor/src/editor-styles.scss
@@ -42,17 +42,6 @@ h6 {
font-size: 0.8em;
}
-// Adjust line spacing for larger headings.
-h1,
-h2,
-h3 {
- line-height: 1.4;
-}
-
-h4 {
- line-height: 1.5;
-}
-
// Default margins.
h1 {
margin-top: 0.67em;
@@ -84,15 +73,6 @@ h6 {
margin-bottom: 2.33em;
}
-h1,
-h2,
-h3,
-h4,
-h5,
-h6 {
- color: inherit;
-}
-
p {
font-size: inherit;
margin-top: $default-block-margin;
diff --git a/packages/global-styles/README.md b/packages/global-styles/README.md
new file mode 100644
index 00000000000000..5d765ae85542e8
--- /dev/null
+++ b/packages/global-styles/README.md
@@ -0,0 +1,3 @@
+# Global Styles
+
+(Experimental) Global Styles Library
diff --git a/packages/global-styles/package-lock.json b/packages/global-styles/package-lock.json
new file mode 100644
index 00000000000000..34b0869ec7d1b5
--- /dev/null
+++ b/packages/global-styles/package-lock.json
@@ -0,0 +1,319 @@
+{
+ "name": "@wordpress/global-styles",
+ "version": "0.0.1",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "@wordpress/compose": {
+ "version": "3.11.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/compose/-/compose-3.11.0.tgz",
+ "integrity": "sha512-CNbLn9NtG2A0X71wjEux126uEHpWp3v546FtSgMoWlq73z3LEEBDoEeS2glIPAbIK6e1X2UibsKrn5Tn651tlg==",
+ "requires": {
+ "@babel/runtime": "^7.8.3",
+ "@wordpress/element": "^2.11.0",
+ "@wordpress/is-shallow-equal": "^1.8.0",
+ "lodash": "^4.17.15",
+ "mousetrap": "^1.6.2"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ },
+ "@wordpress/element": {
+ "version": "2.11.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-2.11.0.tgz",
+ "integrity": "sha512-56ZO8a+E7QEsYwiqS+3BQPSHrCPsOAIEz5smXzntb2f6BjvOKeA64pup40mdn1pNGexe06LBA8cjoZVdLBHB1w==",
+ "requires": {
+ "@babel/runtime": "^7.8.3",
+ "@wordpress/escape-html": "^1.7.0",
+ "lodash": "^4.17.15",
+ "react": "^16.9.0",
+ "react-dom": "^16.9.0"
+ }
+ }
+ }
+ },
+ "@wordpress/data": {
+ "version": "4.14.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/data/-/data-4.14.0.tgz",
+ "integrity": "sha512-Q4N3DnIgzmYh2xTgBY8e6Mwu6Y8UeBSX686u3Ypu9GjgSj/XJnLD741+eowVGxbZCEA8NnqBL+R40zgoT75YmA==",
+ "requires": {
+ "@babel/runtime": "^7.8.3",
+ "@wordpress/compose": "^3.11.0",
+ "@wordpress/deprecated": "^2.7.0",
+ "@wordpress/element": "^2.11.0",
+ "@wordpress/is-shallow-equal": "^1.8.0",
+ "@wordpress/priority-queue": "^1.5.0",
+ "@wordpress/redux-routine": "^3.7.0",
+ "equivalent-key-map": "^0.2.2",
+ "is-promise": "^2.1.0",
+ "lodash": "^4.17.15",
+ "memize": "^1.0.5",
+ "redux": "^4.0.0",
+ "turbo-combine-reducers": "^1.0.2",
+ "use-memo-one": "^1.1.1"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ },
+ "@wordpress/element": {
+ "version": "2.11.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-2.11.0.tgz",
+ "integrity": "sha512-56ZO8a+E7QEsYwiqS+3BQPSHrCPsOAIEz5smXzntb2f6BjvOKeA64pup40mdn1pNGexe06LBA8cjoZVdLBHB1w==",
+ "requires": {
+ "@babel/runtime": "^7.8.3",
+ "@wordpress/escape-html": "^1.7.0",
+ "lodash": "^4.17.15",
+ "react": "^16.9.0",
+ "react-dom": "^16.9.0"
+ }
+ }
+ }
+ },
+ "@wordpress/deprecated": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/deprecated/-/deprecated-2.7.0.tgz",
+ "integrity": "sha512-Pq5r2/p0+3BgwkinSRMTky+iNerm34qPQeil0UCtFxNP5usJaK2ZI0W/pv6DokomOtxTNZyv2lMRlUoXmglDuQ==",
+ "requires": {
+ "@babel/runtime": "^7.8.3",
+ "@wordpress/hooks": "^2.7.0"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ }
+ }
+ },
+ "@wordpress/escape-html": {
+ "version": "1.7.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-1.7.0.tgz",
+ "integrity": "sha512-xDOBo0P3Jnbdbb/UypsQaplsD2k4UXgd/EpKhMAKhDa2m20GxWWmEKW9IB3/5bS4Rh2YZjVM9WL4JyWPUo4hEA==",
+ "requires": {
+ "@babel/runtime": "^7.8.3"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ }
+ }
+ },
+ "@wordpress/hooks": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/hooks/-/hooks-2.7.0.tgz",
+ "integrity": "sha512-Cr8uGEVxuGLkMq9UsbfAQqSTFVGBDhP8PagyIYJRUX6OkLiUF72OyT3xox7aM+ZlSr3INle2mEO+ZLPw0ieIPg==",
+ "requires": {
+ "@babel/runtime": "^7.8.3"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ }
+ }
+ },
+ "@wordpress/is-shallow-equal": {
+ "version": "1.8.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/is-shallow-equal/-/is-shallow-equal-1.8.0.tgz",
+ "integrity": "sha512-OV3qJqP9LhjuOzt85TsyBwv+//CvC8Byf/81D3NmjPKlstLaD/bBCC5nBhH6dKAv4bShYtQ2Hmut+V4dZnOM1A==",
+ "requires": {
+ "@babel/runtime": "^7.8.3"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ }
+ }
+ },
+ "@wordpress/priority-queue": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/priority-queue/-/priority-queue-1.5.0.tgz",
+ "integrity": "sha512-r5Pqv2TXNP7yqDiBhsD/cemnoC/mpnUhOZC1HlJ1mdRSvfIkCk4TDONIAae/MexItVZzxLXdtepIa4FIar1r+w==",
+ "requires": {
+ "@babel/runtime": "^7.8.3"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ }
+ }
+ },
+ "@wordpress/redux-routine": {
+ "version": "3.7.0",
+ "resolved": "https://registry.npmjs.org/@wordpress/redux-routine/-/redux-routine-3.7.0.tgz",
+ "integrity": "sha512-dnt/NA4bgXDdkoTlmZrb5QFSgYoVH/lHrJEpy32KyIkxgF8SCvu8aU5lz08hQaV2MQ3OCJA8WtLIAMw0nCidPg==",
+ "requires": {
+ "@babel/runtime": "^7.8.3",
+ "is-promise": "^2.1.0",
+ "lodash": "^4.17.15",
+ "rungen": "^0.3.2"
+ },
+ "dependencies": {
+ "@babel/runtime": {
+ "version": "7.8.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.8.4.tgz",
+ "integrity": "sha512-neAp3zt80trRVBI1x0azq6c57aNBqYZH8KhMm3TaB7wEI5Q4A2SHfBHE8w9gOhI/lrqxtEbXZgQIrHP+wvSGwQ==",
+ "requires": {
+ "regenerator-runtime": "^0.13.2"
+ }
+ }
+ }
+ },
+ "equivalent-key-map": {
+ "version": "0.2.2",
+ "resolved": "https://registry.npmjs.org/equivalent-key-map/-/equivalent-key-map-0.2.2.tgz",
+ "integrity": "sha512-xvHeyCDbZzkpN4VHQj/n+j2lOwL0VWszG30X4cOrc9Y7Tuo2qCdZK/0AMod23Z5dCtNUbaju6p0rwOhHUk05ew=="
+ },
+ "is-promise": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
+ "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
+ },
+ "js-tokens": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
+ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
+ },
+ "lodash": {
+ "version": "4.17.15",
+ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
+ "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
+ },
+ "loose-envify": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
+ "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
+ "requires": {
+ "js-tokens": "^3.0.0 || ^4.0.0"
+ }
+ },
+ "memize": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/memize/-/memize-1.0.5.tgz",
+ "integrity": "sha512-Dm8Jhb5kiC4+ynYsVR4QDXKt+o2dfqGuY4hE2x+XlXZkdndlT80bJxfcMv5QGp/FCy6MhG7f5ElpmKPFKOSEpg=="
+ },
+ "mousetrap": {
+ "version": "1.6.5",
+ "resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.5.tgz",
+ "integrity": "sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA=="
+ },
+ "object-assign": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
+ "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
+ },
+ "prop-types": {
+ "version": "15.7.2",
+ "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz",
+ "integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==",
+ "requires": {
+ "loose-envify": "^1.4.0",
+ "object-assign": "^4.1.1",
+ "react-is": "^16.8.1"
+ }
+ },
+ "react": {
+ "version": "16.12.0",
+ "resolved": "https://registry.npmjs.org/react/-/react-16.12.0.tgz",
+ "integrity": "sha512-fglqy3k5E+81pA8s+7K0/T3DBCF0ZDOher1elBFzF7O6arXJgzyu/FW+COxFvAWXJoJN9KIZbT2LXlukwphYTA==",
+ "requires": {
+ "loose-envify": "^1.1.0",
+ "object-assign": "^4.1.1",
+ "prop-types": "^15.6.2"
+ }
+ },
+ "react-dom": {
+ "version": "16.12.0",
+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.12.0.tgz",
+ "integrity": "sha512-LMxFfAGrcS3kETtQaCkTKjMiifahaMySFDn71fZUNpPHZQEzmk/GiAeIT8JSOrHB23fnuCOMruL2a8NYlw+8Gw==",
+ "requires": {
+ "loose-envify": "^1.1.0",
+ "object-assign": "^4.1.1",
+ "prop-types": "^15.6.2",
+ "scheduler": "^0.18.0"
+ }
+ },
+ "react-is": {
+ "version": "16.12.0",
+ "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.12.0.tgz",
+ "integrity": "sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q=="
+ },
+ "redux": {
+ "version": "4.0.5",
+ "resolved": "https://registry.npmjs.org/redux/-/redux-4.0.5.tgz",
+ "integrity": "sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==",
+ "requires": {
+ "loose-envify": "^1.4.0",
+ "symbol-observable": "^1.2.0"
+ }
+ },
+ "regenerator-runtime": {
+ "version": "0.13.3",
+ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
+ "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw=="
+ },
+ "rungen": {
+ "version": "0.3.2",
+ "resolved": "https://registry.npmjs.org/rungen/-/rungen-0.3.2.tgz",
+ "integrity": "sha1-QAwJ6+kU57F+C27zJjQA/Cq8fLM="
+ },
+ "scheduler": {
+ "version": "0.18.0",
+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.18.0.tgz",
+ "integrity": "sha512-agTSHR1Nbfi6ulI0kYNK0203joW2Y5W4po4l+v03tOoiJKpTBbxpNhWDvqc/4IcOw+KLmSiQLTasZ4cab2/UWQ==",
+ "requires": {
+ "loose-envify": "^1.1.0",
+ "object-assign": "^4.1.1"
+ }
+ },
+ "symbol-observable": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz",
+ "integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ=="
+ },
+ "turbo-combine-reducers": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/turbo-combine-reducers/-/turbo-combine-reducers-1.0.2.tgz",
+ "integrity": "sha512-gHbdMZlA6Ym6Ur5pSH/UWrNQMIM9IqTH6SoL1DbHpqEdQ8i+cFunSmSlFykPt0eGQwZ4d/XTHOl74H0/kFBVWw=="
+ },
+ "use-memo-one": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/use-memo-one/-/use-memo-one-1.1.1.tgz",
+ "integrity": "sha512-oFfsyun+bP7RX8X2AskHNTxu+R3QdE/RC5IefMbqptmACAA/gfol1KDD5KRzPsGMa62sWxGZw+Ui43u6x4ddoQ=="
+ }
+ }
+}
diff --git a/packages/global-styles/package.json b/packages/global-styles/package.json
new file mode 100644
index 00000000000000..9063779f7a4e0c
--- /dev/null
+++ b/packages/global-styles/package.json
@@ -0,0 +1,34 @@
+{
+ "name": "@wordpress/global-styles",
+ "version": "0.0.1",
+ "private": true,
+ "description": "Global Styles module for WordPress.",
+ "author": "The WordPress Contributors",
+ "license": "GPL-2.0-or-later",
+ "keywords": [
+ "wordpress"
+ ],
+ "homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/global-styles/README.md",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/WordPress/gutenberg.git",
+ "directory": "packages/global-styles"
+ },
+ "bugs": {
+ "url": "https://github.com/WordPress/gutenberg/issues"
+ },
+ "main": "build/index.js",
+ "module": "build-module/index.js",
+ "react-native": "src/index",
+ "dependencies": {
+ "@babel/runtime": "^7.8.3",
+ "@wordpress/components": "../components",
+ "@wordpress/data": "4.14.0",
+ "@wordpress/element": "../element",
+ "@wordpress/i18n": "../i18n",
+ "lodash": "4.17.15"
+ },
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/global-styles/src/controls/index.js b/packages/global-styles/src/controls/index.js
new file mode 100644
index 00000000000000..fa96e0739a237e
--- /dev/null
+++ b/packages/global-styles/src/controls/index.js
@@ -0,0 +1,20 @@
+/**
+ * Internal dependencies
+ */
+import TypographyControls from './typography-controls';
+import { useGlobalStylesContext } from '../provider';
+
+export function GlobalStylesControls() {
+ const { typography, setTypography } = useGlobalStylesContext();
+
+ if ( typography === undefined ) {
+ return null;
+ }
+
+ return (
+
+ );
+}
diff --git a/packages/global-styles/src/controls/typography-controls.js b/packages/global-styles/src/controls/typography-controls.js
new file mode 100644
index 00000000000000..387647730de0d4
--- /dev/null
+++ b/packages/global-styles/src/controls/typography-controls.js
@@ -0,0 +1,80 @@
+/**
+ * WordPress dependencies
+ */
+import { __ } from '@wordpress/i18n';
+import { PanelBody, RangeControl } from '@wordpress/components';
+
+export default function TypographyControls( {
+ typography: {
+ fontBase,
+ fontScale,
+ lineHeightBase,
+ lineHeightHeading,
+ fontWeightBase,
+ fontWeightHeading,
+ },
+ setTypography,
+} ) {
+ return (
+
+ setTypography( { fontBase: value } ) }
+ />
+ setTypography( { fontScale: value } ) }
+ />
+ { __( 'Heading' ) }
+
+ setTypography( { lineHeightHeading: value } )
+ }
+ />
+
+ setTypography( { fontWeightHeading: value } )
+ }
+ />
+ { __( 'Base' ) }
+
+ setTypography( { lineHeightBase: value } )
+ }
+ />
+
+ setTypography( { fontWeightBase: value } )
+ }
+ />
+
+ );
+}
diff --git a/packages/global-styles/src/index.js b/packages/global-styles/src/index.js
new file mode 100644
index 00000000000000..5b1005d29e9d08
--- /dev/null
+++ b/packages/global-styles/src/index.js
@@ -0,0 +1,2 @@
+export * from './provider';
+export * from './controls';
diff --git a/packages/global-styles/src/provider.js b/packages/global-styles/src/provider.js
new file mode 100644
index 00000000000000..37e78f9f646910
--- /dev/null
+++ b/packages/global-styles/src/provider.js
@@ -0,0 +1,142 @@
+/**
+ * External dependencies
+ */
+import { camelCase, kebabCase } from 'lodash';
+
+/**
+ * WordPress dependencies
+ */
+import { useContext, createContext } from '@wordpress/element';
+import { useDispatch, useSelect } from '@wordpress/data';
+
+/**
+ * Internal dependencies
+ */
+import { useRenderedGlobalStyles } from './renderer';
+
+const GlobalStylesContext = createContext( {} );
+export const useGlobalStylesContext = () => useContext( GlobalStylesContext );
+
+export function GlobalStylesProvider( { children, baseStyles, userEntityId } ) {
+ // Trigger entity retrieval.
+ useSelect( ( select ) =>
+ select( 'core' ).getEntityRecord(
+ 'postType',
+ 'wp_global_styles',
+ userEntityId
+ )
+ );
+ const globalStyles = useGlobalStyles( baseStyles, userEntityId );
+
+ return (
+
+ { children }
+
+ );
+}
+
+function toCase( tree, transformCase ) {
+ if ( ! ( tree instanceof Object ) ) {
+ return tree;
+ }
+
+ const newTree = {};
+ for ( const key in tree ) {
+ if ( ! tree.hasOwnProperty( key ) ) continue;
+
+ if ( tree[ key ] instanceof Object ) {
+ newTree[ transformCase( key ) ] = toCase(
+ tree[ key ],
+ transformCase
+ );
+ } else {
+ newTree[ transformCase( key ) ] = tree[ key ];
+ }
+ }
+ return newTree;
+}
+
+// Make object reference immutable
+// so it stays the same in the function setters.
+let styles = {};
+function useGlobalStyles( baseStyles, userEntityId ) {
+ // Start with base styles.
+ styles = {
+ ...toCase( baseStyles, camelCase ),
+ };
+
+ // Merge user styles, if any.
+ const userData = useSelect( ( select ) =>
+ select( 'core' ).getEditedEntityRecord(
+ 'postType',
+ 'wp_global_styles',
+ userEntityId
+ )
+ );
+ let userStyles = {};
+ if ( Object.keys( userData ).length > 0 ) {
+ userStyles = toCase( JSON.parse( userData.content ), camelCase );
+ styles = {
+ color: {
+ ...styles.color,
+ ...userStyles.color,
+ },
+ typography: {
+ ...styles.typography,
+ ...userStyles.typography,
+ },
+ };
+ }
+
+ // Convert styles to CSS props.
+ useRenderedGlobalStyles( toCase( styles, kebabCase ) );
+
+ // Create and bind function settters to context,
+ // so controls can modify the styles.
+ const { editEntityRecord } = useDispatch( 'core' );
+
+ const setColor = ( newStyles ) => {
+ editEntityRecord( 'postType', 'wp_global_styles', userEntityId, {
+ content: JSON.stringify(
+ toCase(
+ {
+ typography: {
+ ...userStyles.typography,
+ },
+ color: {
+ ...userStyles.color,
+ ...newStyles,
+ },
+ },
+ kebabCase
+ )
+ ),
+ } );
+ };
+
+ const setTypography = ( newStyles ) => {
+ editEntityRecord( 'postType', 'wp_global_styles', userEntityId, {
+ content: JSON.stringify(
+ toCase(
+ {
+ color: {
+ ...userStyles.color,
+ },
+ typography: {
+ ...userStyles.typography,
+ ...newStyles,
+ },
+ },
+ kebabCase
+ )
+ ),
+ } );
+ };
+
+ // Return context value.
+ return {
+ ...styles,
+ setColor,
+ setTypography,
+ };
+}
diff --git a/packages/global-styles/src/renderer.js b/packages/global-styles/src/renderer.js
new file mode 100644
index 00000000000000..a956ee94603342
--- /dev/null
+++ b/packages/global-styles/src/renderer.js
@@ -0,0 +1,63 @@
+/**
+ * WordPress dependencies
+ */
+import { useEffect } from '@wordpress/element';
+
+export function useRenderedGlobalStyles( styles = {} ) {
+ const generatedStyles = compileStyles( styles );
+
+ useEffect( () => {
+ // styleNodeId should match server ID, see global-styles.php
+ const styleNodeId = 'global-styles-inline-css';
+ let styleNode = document.getElementById( styleNodeId );
+
+ if ( ! styleNode ) {
+ styleNode = document.createElement( 'style' );
+ styleNode.id = styleNodeId;
+ document
+ .getElementsByTagName( 'head' )[ 0 ]
+ .appendChild( styleNode );
+ }
+
+ styleNode.innerText = generatedStyles;
+ }, [ generatedStyles ] );
+}
+
+function flattenObject( ob, token = '' ) {
+ const toReturn = {};
+
+ for ( const i in ob ) {
+ if ( ! ob.hasOwnProperty( i ) ) continue;
+
+ if ( typeof ob[ i ] === 'object' ) {
+ const flatObject = flattenObject( ob[ i ], token );
+ for ( const x in flatObject ) {
+ if ( ! flatObject.hasOwnProperty( x ) ) continue;
+
+ toReturn[ i + token + x ] = flatObject[ x ];
+ }
+ } else {
+ toReturn[ i ] = ob[ i ];
+ }
+ }
+ return toReturn;
+}
+
+function compileStyles( styles = {} ) {
+ const prefix = '--wp';
+ const token = '--';
+ const flattenedStyles = { ...flattenObject( styles, token ) };
+ const html = [];
+ html.push( ':root {' );
+
+ for ( const key in flattenedStyles ) {
+ const value = flattenedStyles[ key ];
+ if ( value ) {
+ const style = `${ prefix + token + key }: ${ value };`;
+ html.push( style );
+ }
+ }
+ html.push( '}' );
+
+ return html.join( '' );
+}
diff --git a/packages/interface/src/components/complementary-area/style.scss b/packages/interface/src/components/complementary-area/style.scss
index 51284edf5769cf..9c442c3d4f3963 100644
--- a/packages/interface/src/components/complementary-area/style.scss
+++ b/packages/interface/src/components/complementary-area/style.scss
@@ -50,6 +50,21 @@
p {
margin-top: 0;
+ font-size: $default-font-size;
+ font-weight: normal;
+ line-height: 1.5;
+ color: $dark-gray-500;
+ background-color: inherit;
+ }
+
+ h2 {
+ font-weight: 500;
+ line-height: $default-line-height;
+ }
+
+ h3 {
+ font-weight: normal;
+ line-height: 1.5;
}
h2,
@@ -57,6 +72,7 @@
font-size: $default-font-size;
color: $dark-gray-500;
margin-bottom: 1.5em;
+ background-color: inherit;
}
hr {