From 7716adc33017ef3fb4a33b6fcfd3ebac936b71b0 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Fri, 9 Apr 2021 19:25:28 +0200 Subject: [PATCH 01/33] Mobile - Read global styles and set color palette and gradients --- .../src/color-palette/index.native.js | 15 ++- packages/components/src/index.native.js | 1 + .../global-styles-context/utils.native.js | 41 ++++++ .../src/components/provider/index.native.js | 15 ++- .../components/provider/theme_data.native.js | 127 ++++++++++++++++++ 5 files changed, 190 insertions(+), 9 deletions(-) create mode 100644 packages/editor/src/components/provider/theme_data.native.js diff --git a/packages/components/src/color-palette/index.native.js b/packages/components/src/color-palette/index.native.js index 152845b80d2fcd..0dc215996b31c7 100644 --- a/packages/components/src/color-palette/index.native.js +++ b/packages/components/src/color-palette/index.native.js @@ -12,12 +12,15 @@ import { Text, } from 'react-native'; import { map, uniq } from 'lodash'; + /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { useRef, useEffect, useState } from '@wordpress/element'; import { usePreferredColorSchemeStyle } from '@wordpress/compose'; +import { __experimentalUseEditorFeature as useEditorFeature } from '@wordpress/block-editor'; + /** * Internal dependencies */ @@ -68,9 +71,17 @@ function ColorPalette( { const scale = useRef( new Animated.Value( 1 ) ).current; const opacity = useRef( new Animated.Value( 1 ) ).current; - const defaultColors = uniq( map( defaultSettings.colors, 'color' ) ); + const defaultColors = uniq( + map( + useEditorFeature( 'color.palette' ) || defaultSettings.colors, + 'color' + ) + ); const defaultGradientColors = uniq( - map( defaultSettings.gradients, 'gradient' ) + map( + useEditorFeature( 'color.gradients' ) || defaultSettings.gradients, + 'gradient' + ) ); const colors = isGradientSegment ? defaultGradientColors : defaultColors; diff --git a/packages/components/src/index.native.js b/packages/components/src/index.native.js index e4fe68573ceda2..b7b431463ac20c 100644 --- a/packages/components/src/index.native.js +++ b/packages/components/src/index.native.js @@ -110,3 +110,4 @@ export { withGlobalStyles, getMergedGlobalStyles, } from './mobile/global-styles-context'; +export { getGlobalStyles } from './mobile/global-styles-context/utils'; diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index c8e2bce0c91f8a..7d9a270faa13d2 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -66,3 +66,44 @@ export function getBlockColors( blockStyleAttributes, defaultColors ) { return blockStyles; } + +// To-do add tests +export function parseGradientsColorVariables( colorPalette, gradients ) { + const colorPrefixRegex = /var\(--wp--preset--color--(.*?)\)/g; + Object.keys( gradients ).forEach( ( key ) => { + const value = gradients[ key ]?.gradient; + const colorValue = value?.replace( colorPrefixRegex, ( _$1, $2 ) => { + const mappedColor = find( colorPalette, { + slug: $2, + } ); + return mappedColor?.color; + } ); + gradients[ key ].gradient = colorValue; + } ); + + return gradients; +} + +export function getGlobalStyles( baseStyles ) { + const globalStyles = { + ...baseStyles, + }; + const colorSettings = globalStyles?.settings?.color; + const palette = colorSettings?.palette; + const gradients = colorSettings?.gradients; + + if ( gradients ) { + parseGradientsColorVariables( palette, gradients ); + } + + return { + ...( palette || gradients + ? { + __experimentalFeatures: { + defaults: { color: { palette, gradients } }, + }, + } + : {} ), + __experimentalGlobalStylesBaseStyles: globalStyles, + }; +} diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index d788b1a2447e3f..21a0af12c1727c 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -1,6 +1,3 @@ -/** - * External dependencies - */ /** * WordPress dependencies */ @@ -15,10 +12,6 @@ import RNReactNativeGutenbergBridge, { subscribeUpdateCapabilities, subscribeShowNotice, } from '@wordpress/react-native-bridge'; - -/** - * WordPress dependencies - */ import { Component } from '@wordpress/element'; import { count as wordCount } from '@wordpress/wordcount'; import { @@ -34,6 +27,7 @@ import { validateThemeColors, validateThemeGradients, } from '@wordpress/block-editor'; +import { getGlobalStyles } from '@wordpress/components'; const postTypeEntities = [ { name: 'post', baseURL: '/wp/v2/posts' }, @@ -56,6 +50,7 @@ const postTypeEntities = [ * Internal dependencies */ import EditorProvider from './index.js'; +import GLOBAL_STYLES_DATA from './theme_data'; class NativeEditorProvider extends Component { constructor() { @@ -73,12 +68,18 @@ class NativeEditorProvider extends Component { componentDidMount() { const { capabilities, colors, gradients } = this.props; + const isFSETheme = GLOBAL_STYLES_DATA?.isFSETheme; this.props.updateSettings( { ...capabilities, // Set theme colors for the editor ...( colors ? { colors } : {} ), ...( gradients ? { gradients } : {} ), + ...( isFSETheme + ? getGlobalStyles( + GLOBAL_STYLES_DATA?.__experimentalGlobalStylesBaseStyles + ) + : {} ), } ); this.subscriptionParentGetHtml = subscribeParentGetHtml( () => { diff --git a/packages/editor/src/components/provider/theme_data.native.js b/packages/editor/src/components/provider/theme_data.native.js new file mode 100644 index 00000000000000..8f70d7936effb0 --- /dev/null +++ b/packages/editor/src/components/provider/theme_data.native.js @@ -0,0 +1,127 @@ +export default { + isFSETheme: true, + __experimentalGlobalStylesBaseStyles: { + settings: { + color: { + palette: [ + { + slug: 'black', + color: '#000000', + name: 'Black', + }, + { + slug: 'dark-gray', + color: '#28303D', + name: 'Dark Gray', + }, + { + slug: 'gray', + color: '#39414D', + name: 'Gray', + }, + { + slug: 'green', + color: '#D1E4DD', + name: 'Green', + }, + { + slug: 'blue', + color: '#D1DFE4', + name: 'Blue', + }, + { + slug: 'purple', + color: '#D1D1E4', + name: 'Purple', + }, + { + slug: 'red', + color: '#E4D1D1', + name: 'Red', + }, + { + slug: 'orange', + color: '#E4DAD1', + name: 'Orange', + }, + { + slug: 'yellow', + color: '#EEEADD', + name: 'Yellow', + }, + { + slug: 'white', + color: '#FFFFFF', + name: 'White', + }, + ], + gradients: [ + { + slug: 'purple-to-yellow', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--purple), var(--wp--preset--color--yellow))', + name: 'Purple to Yellow', + }, + { + slug: 'yellow-to-purple', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--yellow), var(--wp--preset--color--purple))', + name: 'Yellow to Purple', + }, + { + slug: 'green-to-yellow', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--green), var(--wp--preset--color--yellow))', + name: 'Green to Yellow', + }, + { + slug: 'yellow-to-green', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--yellow), var(--wp--preset--color--green))', + name: 'Yellow to Green', + }, + { + slug: 'red-to-yellow', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--red), var(--wp--preset--color--yellow))', + name: 'Red to Yellow', + }, + { + slug: 'yellow-to-red', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--yellow), var(--wp--preset--color--red))', + name: 'Yellow to Red', + }, + { + slug: 'purple-to-red', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--purple), var(--wp--preset--color--red))', + name: 'Purple to Red', + }, + { + slug: 'red-to-purple', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--red), var(--wp--preset--color--purple))', + name: 'Red to Purple', + }, + ], + custom: true, + link: true, + customGradient: true, + }, + }, + styles: { + color: { + background: 'var(--wp--preset--color--green)', + text: 'var(--wp--preset--color--dark-gray)', + }, + elements: { + link: { + color: { + text: 'green', + }, + }, + }, + }, + }, +}; From f670aec4e18b1330e0f008895031fd48d59a3ba1 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 13 Apr 2021 15:14:50 +0200 Subject: [PATCH 02/33] Mobile - Enable colors for blocks that support it --- packages/block-editor/src/hooks/color.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/hooks/color.js b/packages/block-editor/src/hooks/color.js index d8821b16713f39..ecc784b3173aae 100644 --- a/packages/block-editor/src/hooks/color.js +++ b/packages/block-editor/src/hooks/color.js @@ -227,7 +227,7 @@ export function ColorEdit( props ) { localAttributes.current = attributes; }, [ attributes ] ); - if ( ! hasColorSupport( blockName ) || Platform.OS !== 'web' ) { + if ( ! hasColorSupport( blockName ) ) { return null; } From 3f18835520df1beaa6fb9674ea649f2d556a50de Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 13 Apr 2021 17:07:44 +0200 Subject: [PATCH 03/33] Parse all color variables --- .../global-styles-context/utils.native.js | 34 ++++++++----------- .../components/provider/theme_data.native.js | 2 +- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 7d9a270faa13d2..e7005cb54773b8 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -68,33 +68,27 @@ export function getBlockColors( blockStyleAttributes, defaultColors ) { } // To-do add tests -export function parseGradientsColorVariables( colorPalette, gradients ) { +export function parseColorVariables( styles, colorPalette ) { + const stylesBase = JSON.stringify( styles ); const colorPrefixRegex = /var\(--wp--preset--color--(.*?)\)/g; - Object.keys( gradients ).forEach( ( key ) => { - const value = gradients[ key ]?.gradient; - const colorValue = value?.replace( colorPrefixRegex, ( _$1, $2 ) => { - const mappedColor = find( colorPalette, { - slug: $2, - } ); - return mappedColor?.color; - } ); - gradients[ key ].gradient = colorValue; - } ); - return gradients; + return stylesBase + ? JSON.parse( + stylesBase?.replace( colorPrefixRegex, ( _$1, $2 ) => { + const mappedColor = find( colorPalette, { + slug: $2, + } ); + return mappedColor?.color; + } ) + ) + : styles; } export function getGlobalStyles( baseStyles ) { - const globalStyles = { - ...baseStyles, - }; - const colorSettings = globalStyles?.settings?.color; + const colorSettings = baseStyles?.settings?.color; const palette = colorSettings?.palette; const gradients = colorSettings?.gradients; - - if ( gradients ) { - parseGradientsColorVariables( palette, gradients ); - } + const globalStyles = parseColorVariables( baseStyles, palette ); return { ...( palette || gradients diff --git a/packages/editor/src/components/provider/theme_data.native.js b/packages/editor/src/components/provider/theme_data.native.js index 8f70d7936effb0..5e6254ebbf98d4 100644 --- a/packages/editor/src/components/provider/theme_data.native.js +++ b/packages/editor/src/components/provider/theme_data.native.js @@ -118,7 +118,7 @@ export default { elements: { link: { color: { - text: 'green', + text: 'var(--wp--preset--color--dark-gray)', }, }, }, From 007e8629cafd9f853c75bafd32b166a3a188072a Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 13 Apr 2021 17:40:50 +0200 Subject: [PATCH 04/33] Mobile - Set background, title, text and link colors --- .../src/components/block-list/block.native.js | 7 ++++ .../src/paragraph/edit.native.js | 4 +++ .../global-styles-context/index.native.js | 5 +++ .../src/components/layout/index.native.js | 34 +++++++++++++------ .../src/components/post-title/index.native.js | 29 +++++++++++----- .../rich-text/src/component/index.native.js | 14 ++++---- 6 files changed, 67 insertions(+), 26 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 38bc62c6ca8503..192562258e9e9d 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -48,11 +48,13 @@ function BlockForType( { parentWidth, wrapperProps, blockWidth, + baseGlobalStyles, } ) { const defaultColors = useEditorFeature( 'color.palette' ) || emptyArray; const globalStyle = useGlobalStyles(); const mergedStyle = useMemo( () => { return getMergedGlobalStyles( + baseGlobalStyles, globalStyle, wrapperProps.style, attributes, @@ -306,6 +308,7 @@ export default compose( [ withSelect( ( select, { clientId, rootClientId } ) => { const { getBlockIndex, + getSettings, isBlockSelected, __unstableGetBlockWithoutInnerBlocks, getSelectedBlockClientId, @@ -353,6 +356,9 @@ export default compose( [ isDescendantOfParentSelected || isParentSelected || parentId === ''; + const baseGlobalStyles = getSettings() + ?.__experimentalGlobalStylesBaseStyles?.styles; + return { icon, name: name || 'core/missing', @@ -366,6 +372,7 @@ export default compose( [ isParentSelected, firstToSelectId, isTouchable, + baseGlobalStyles, wrapperProps: getWrapperProps( attributes, blockType.getEditWrapperProps diff --git a/packages/block-library/src/paragraph/edit.native.js b/packages/block-library/src/paragraph/edit.native.js index a51a708a222767..5450cd2ca4dd7a 100644 --- a/packages/block-library/src/paragraph/edit.native.js +++ b/packages/block-library/src/paragraph/edit.native.js @@ -30,6 +30,10 @@ function ParagraphBlock( { const { align, content, placeholder } = attributes; const styles = { + ...( mergedStyle?.baseColors && { + color: mergedStyle.baseColors?.color?.text, + linkColor: mergedStyle.baseColors?.elements?.link?.color?.text, + } ), ...mergedStyle, ...style, }; diff --git a/packages/components/src/mobile/global-styles-context/index.native.js b/packages/components/src/mobile/global-styles-context/index.native.js index 81a60ccc8eb56e..1d4d0d45be6761 100644 --- a/packages/components/src/mobile/global-styles-context/index.native.js +++ b/packages/components/src/mobile/global-styles-context/index.native.js @@ -22,16 +22,21 @@ const GlobalStylesContext = createContext( { style: {} } ); GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES = BLOCK_STYLE_ATTRIBUTES; export const getMergedGlobalStyles = ( + baseGlobalStyles, globalStyle, wrapperPropsStyle, blockAttributes, defaultColors ) => { + const baseGlobalColors = { + baseColors: baseGlobalStyles || {}, + }; const blockStyleAttributes = pick( blockAttributes, BLOCK_STYLE_ATTRIBUTES ); const mergedStyle = { + ...baseGlobalColors, ...globalStyle, ...wrapperPropsStyle, }; diff --git a/packages/edit-post/src/components/layout/index.native.js b/packages/edit-post/src/components/layout/index.native.js index f52798d87dc537..ed84dfe2df33bc 100644 --- a/packages/edit-post/src/components/layout/index.native.js +++ b/packages/edit-post/src/components/layout/index.native.js @@ -9,14 +9,18 @@ import SafeArea from 'react-native-safe-area'; */ import { Component } from '@wordpress/element'; import { withSelect } from '@wordpress/data'; -import { BottomSheetSettings, FloatingToolbar } from '@wordpress/block-editor'; +import { + BottomSheetSettings, + FloatingToolbar, + store as blockEditorStore, +} from '@wordpress/block-editor'; import { compose, withPreferredColorScheme } from '@wordpress/compose'; import { HTMLTextInput, KeyboardAvoidingView, NoticeList, } from '@wordpress/components'; -import { AutosaveMonitor } from '@wordpress/editor'; +import { AutosaveMonitor, store as editorStore } from '@wordpress/editor'; import { sendNativeEditorDidLayout } from '@wordpress/react-native-bridge'; /** @@ -99,7 +103,7 @@ class Layout extends Component { } render() { - const { getStylesFromColorScheme, mode } = this.props; + const { getStylesFromColorScheme, mode, globalStyles } = this.props; const isHtmlView = mode === 'text'; @@ -116,6 +120,16 @@ class Layout extends Component { bottom: this.state.safeAreaInsets.bottom, }; + const editorStyles = [ + getStylesFromColorScheme( + styles.background, + styles.backgroundDark + ), + globalStyles?.background && { + backgroundColor: globalStyles.background, + }, + ]; + return ( - + { isHtmlView ? this.renderHTML() : this.renderVisual() } { ! isHtmlView && Platform.OS === 'android' && ( @@ -163,12 +172,17 @@ class Layout extends Component { export default compose( [ withSelect( ( select ) => { const { __unstableIsEditorReady: isEditorReady } = select( - 'core/editor' + editorStore ); const { getEditorMode } = select( editPostStore ); + const { getSettings } = select( blockEditorStore ); + const globalStyles = getSettings()?.__experimentalGlobalStylesBaseStyles + ?.styles?.color; + return { isReady: isEditorReady(), mode: getEditorMode(), + globalStyles, }; } ), withPreferredColorScheme, diff --git a/packages/editor/src/components/post-title/index.native.js b/packages/editor/src/components/post-title/index.native.js index 0587f26227ec83..94b7941e38aa03 100644 --- a/packages/editor/src/components/post-title/index.native.js +++ b/packages/editor/src/components/post-title/index.native.js @@ -19,6 +19,8 @@ import { withFocusOutside } from '@wordpress/components'; import { withInstanceId, compose } from '@wordpress/compose'; import { __, sprintf } from '@wordpress/i18n'; import { pasteHandler } from '@wordpress/blocks'; +import { store as blockEditorStore } from '@wordpress/block-editor'; +import { store as editorStore } from '@wordpress/editor'; /** * Internal dependencies @@ -107,12 +109,19 @@ class PostTitle extends Component { borderStyle, isDimmed, postType, + globalStyles, } = this.props; const decodedPlaceholder = decodeEntities( placeholder ); const borderColor = this.props.isSelected ? focusedBorderColor : 'transparent'; + const titleStyles = { + ...style, + ...( globalStyles?.text && { + color: globalStyles.text, + } ), + }; return ( { const { isPostTitleSelected, getEditedPostAttribute } = select( - 'core/editor' - ); - - const { getSelectedBlockClientId, getBlockRootClientId } = select( - 'core/block-editor' + editorStore ); + const { + getSelectedBlockClientId, + getBlockRootClientId, + getSettings, + } = select( blockEditorStore ); const selectedId = getSelectedBlockClientId(); const selectionIsNested = !! getBlockRootClientId( selectedId ); + const globalStyles = getSettings()?.__experimentalGlobalStylesBaseStyles + ?.styles?.color; return { postType: getEditedPostAttribute( 'type' ), isAnyBlockSelected: !! selectedId, isSelected: isPostTitleSelected(), isDimmed: selectionIsNested, + globalStyles, }; } ), withDispatch( ( dispatch ) => { const { undo, redo, togglePostTitleSelection } = dispatch( - 'core/editor' + editorStore ); const { clearSelectedBlock, insertDefaultBlock } = dispatch( - 'core/block-editor' + blockEditorStore ); return { diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index ac83e09cec485b..5f3d4b6d87adcb 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -3,21 +3,18 @@ /** * External dependencies */ +import { View, Platform } from 'react-native'; +import { get, pickBy, debounce, isString } from 'lodash'; +import memize from 'memize'; + /** * WordPress dependencies */ import RCTAztecView from '@wordpress/react-native-aztec'; -import { View, Platform } from 'react-native'; import { showUserSuggestions, showXpostSuggestions, } from '@wordpress/react-native-bridge'; -import { get, pickBy, debounce, isString } from 'lodash'; -import memize from 'memize'; - -/** - * WordPress dependencies - */ import { BlockFormatControls } from '@wordpress/block-editor'; import { Component } from '@wordpress/element'; import { compose, withPreferredColorScheme } from '@wordpress/compose'; @@ -957,7 +954,8 @@ export class RichText extends Component { text: html, eventCount: this.lastEventCount, selection, - linkTextColor: defaultTextDecorationColor, + linkTextColor: + style?.linkColor || defaultTextDecorationColor, } } placeholder={ this.props.placeholder } placeholderTextColor={ From 65613635aa2a59f921869a8d0877e108206153cd Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 13 Apr 2021 17:47:56 +0200 Subject: [PATCH 05/33] Fix gradients --- .../components/src/mobile/global-styles-context/utils.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index e7005cb54773b8..981d7a803343b2 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -87,8 +87,8 @@ export function parseColorVariables( styles, colorPalette ) { export function getGlobalStyles( baseStyles ) { const colorSettings = baseStyles?.settings?.color; const palette = colorSettings?.palette; - const gradients = colorSettings?.gradients; const globalStyles = parseColorVariables( baseStyles, palette ); + const gradients = globalStyles?.settings?.color?.gradients; return { ...( palette || gradients From ac1ac60e64361e837902942c01b0bdab1708e158 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 20 Apr 2021 12:54:43 +0200 Subject: [PATCH 06/33] Add placeholder color --- packages/block-editor/src/components/block-list/block.native.js | 2 +- packages/block-library/src/paragraph/edit.native.js | 1 + .../components/src/mobile/global-styles-context/index.native.js | 2 +- packages/editor/src/components/post-title/index.native.js | 1 + packages/rich-text/src/component/index.native.js | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 192562258e9e9d..50e7e3c1a0125b 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -357,7 +357,7 @@ export default compose( [ isParentSelected || parentId === ''; const baseGlobalStyles = getSettings() - ?.__experimentalGlobalStylesBaseStyles?.styles; + ?.__experimentalGlobalStylesBaseStyles; return { icon, diff --git a/packages/block-library/src/paragraph/edit.native.js b/packages/block-library/src/paragraph/edit.native.js index 5450cd2ca4dd7a..1cd75758543006 100644 --- a/packages/block-library/src/paragraph/edit.native.js +++ b/packages/block-library/src/paragraph/edit.native.js @@ -32,6 +32,7 @@ function ParagraphBlock( { const styles = { ...( mergedStyle?.baseColors && { color: mergedStyle.baseColors?.color?.text, + placeholderColor: mergedStyle.baseColors?.color?.text, linkColor: mergedStyle.baseColors?.elements?.link?.color?.text, } ), ...mergedStyle, diff --git a/packages/components/src/mobile/global-styles-context/index.native.js b/packages/components/src/mobile/global-styles-context/index.native.js index 1d4d0d45be6761..113e768ca97a30 100644 --- a/packages/components/src/mobile/global-styles-context/index.native.js +++ b/packages/components/src/mobile/global-styles-context/index.native.js @@ -29,7 +29,7 @@ export const getMergedGlobalStyles = ( defaultColors ) => { const baseGlobalColors = { - baseColors: baseGlobalStyles || {}, + baseColors: baseGlobalStyles?.styles || {}, }; const blockStyleAttributes = pick( blockAttributes, diff --git a/packages/editor/src/components/post-title/index.native.js b/packages/editor/src/components/post-title/index.native.js index 94b7941e38aa03..8a12745ecb7f45 100644 --- a/packages/editor/src/components/post-title/index.native.js +++ b/packages/editor/src/components/post-title/index.native.js @@ -120,6 +120,7 @@ class PostTitle extends Component { ...style, ...( globalStyles?.text && { color: globalStyles.text, + placeholderColor: globalStyles.text, } ), }; diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 5f3d4b6d87adcb..230fb9345dda94 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -959,6 +959,7 @@ export class RichText extends Component { } } placeholder={ this.props.placeholder } placeholderTextColor={ + style?.placeholderColor || this.props.placeholderTextColor || defaultPlaceholderTextColor } From 6e67b405f839e4a1f5a5cdc8384c5ef98c511f07 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 20 Apr 2021 13:28:38 +0200 Subject: [PATCH 07/33] Add support to block styles --- .../src/components/block-list/block.native.js | 3 +- .../src/paragraph/edit.native.js | 3 +- .../global-styles-context/index.native.js | 13 +++- .../global-styles-context/utils.native.js | 63 ++++++++++++++++--- .../components/provider/theme_data.native.js | 25 ++++++++ .../rich-text/src/component/index.native.js | 4 +- 6 files changed, 97 insertions(+), 14 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 50e7e3c1a0125b..acabe89c36567d 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -58,7 +58,8 @@ function BlockForType( { globalStyle, wrapperProps.style, attributes, - defaultColors + defaultColors, + name ); }, [ defaultColors, diff --git a/packages/block-library/src/paragraph/edit.native.js b/packages/block-library/src/paragraph/edit.native.js index 1cd75758543006..f71cc4279a2ef4 100644 --- a/packages/block-library/src/paragraph/edit.native.js +++ b/packages/block-library/src/paragraph/edit.native.js @@ -32,7 +32,8 @@ function ParagraphBlock( { const styles = { ...( mergedStyle?.baseColors && { color: mergedStyle.baseColors?.color?.text, - placeholderColor: mergedStyle.baseColors?.color?.text, + placeholderColor: + mergedStyle.color || mergedStyle.baseColors?.color?.text, linkColor: mergedStyle.baseColors?.elements?.link?.color?.text, } ), ...mergedStyle, diff --git a/packages/components/src/mobile/global-styles-context/index.native.js b/packages/components/src/mobile/global-styles-context/index.native.js index 113e768ca97a30..4b92671d1293f8 100644 --- a/packages/components/src/mobile/global-styles-context/index.native.js +++ b/packages/components/src/mobile/global-styles-context/index.native.js @@ -26,7 +26,8 @@ export const getMergedGlobalStyles = ( globalStyle, wrapperPropsStyle, blockAttributes, - defaultColors + defaultColors, + blockName ) => { const baseGlobalColors = { baseColors: baseGlobalStyles?.styles || {}, @@ -40,12 +41,18 @@ export const getMergedGlobalStyles = ( ...globalStyle, ...wrapperPropsStyle, }; + const blockColors = getBlockColors( + blockStyleAttributes, + defaultColors, + blockName, + baseGlobalStyles + ); const blockPaddings = getBlockPaddings( mergedStyle, wrapperPropsStyle, - blockStyleAttributes + blockStyleAttributes, + blockColors ); - const blockColors = getBlockColors( blockStyleAttributes, defaultColors ); return { ...mergedStyle, ...blockPaddings, ...blockColors }; }; diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 981d7a803343b2..79034e65c0286c 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -3,28 +3,39 @@ */ import { find, startsWith } from 'lodash'; -export const BLOCK_STYLE_ATTRIBUTES = [ 'textColor', 'backgroundColor' ]; +export const BLOCK_STYLE_ATTRIBUTES = [ + 'textColor', + 'backgroundColor', + 'style', +]; // Mapping style properties name to native const BLOCK_STYLE_ATTRIBUTES_MAPPING = { textColor: 'color', + text: 'color', + background: 'backgroundColor', + link: 'linkColor', + placeholder: 'placeholderColor', }; -const PADDING = 12; // solid-border-space +const PADDING = 12; // $solid-border-space +const UNKNOWN_VALUE = 'undefined'; export function getBlockPaddings( mergedStyle, wrapperPropsStyle, - blockStyleAttributes + blockStyleAttributes, + blockColors ) { const blockPaddings = {}; if ( ! mergedStyle.padding && ( wrapperPropsStyle?.backgroundColor || - blockStyleAttributes?.backgroundColor ) + blockStyleAttributes?.backgroundColor || + blockColors?.backgroundColor ) ) { - blockPaddings.padding = PADDING; + blockPaddings.containerPadding = PADDING; return blockPaddings; } @@ -34,15 +45,53 @@ export function getBlockPaddings( ! wrapperPropsStyle?.backgroundColor && ! blockStyleAttributes?.backgroundColor ) { - blockPaddings.padding = undefined; + blockPaddings.containerPadding = undefined; } return blockPaddings; } -export function getBlockColors( blockStyleAttributes, defaultColors ) { +export function getBlockColors( + blockStyleAttributes, + defaultColors, + blockName, + baseGlobalStyles +) { const blockStyles = {}; + const customBlockStyles = blockStyleAttributes?.style?.color || {}; + const blockGlobalStyles = baseGlobalStyles?.blocks?.[ blockName ]; + + // Global styles colors + if ( blockGlobalStyles?.color ) { + Object.entries( blockGlobalStyles.color ).forEach( + ( [ key, value ] ) => { + const styleKey = BLOCK_STYLE_ATTRIBUTES_MAPPING[ key ]; + + if ( styleKey && value !== UNKNOWN_VALUE ) { + const color = customBlockStyles[ key ] ?? value; + blockStyles[ styleKey ] = color; + + if ( styleKey === BLOCK_STYLE_ATTRIBUTES_MAPPING.text ) { + blockStyles[ + BLOCK_STYLE_ATTRIBUTES_MAPPING.placeholder + ] = color; + } + } + } + ); + } + + // Global styles elements + if ( blockGlobalStyles?.elements ) { + const linkColor = blockGlobalStyles.elements?.link?.color?.text; + const styleKey = BLOCK_STYLE_ATTRIBUTES_MAPPING.link; + + if ( styleKey && linkColor && linkColor !== UNKNOWN_VALUE ) { + blockStyles[ styleKey ] = linkColor; + } + } + // Custom colors Object.entries( blockStyleAttributes ).forEach( ( [ key, value ] ) => { const isCustomColor = startsWith( value, '#' ); let styleKey = key; diff --git a/packages/editor/src/components/provider/theme_data.native.js b/packages/editor/src/components/provider/theme_data.native.js index 5e6254ebbf98d4..51b0942618363a 100644 --- a/packages/editor/src/components/provider/theme_data.native.js +++ b/packages/editor/src/components/provider/theme_data.native.js @@ -123,5 +123,30 @@ export default { }, }, }, + blocks: { + 'core/heading': { + elements: { + link: { + color: { + text: 'var(--wp--preset--color--yellow)', + }, + }, + }, + color: { + text: 'var(--wp--preset--color--white)', + background: 'var(--wp--preset--color--dark-gray)', + }, + }, + 'core/quote': { + color: { + text: 'var(--wp--preset--color--red)', + }, + }, + 'core/cover': { + color: { + text: 'var(--wp--preset--color--green)', + }, + }, + }, }, }; diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 230fb9345dda94..98180fb1b85013 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -918,9 +918,9 @@ export class RichText extends Component { maxWidth && this.state.width && maxWidth - this.state.width < 10 ? maxWidth : this.state.width; - const containerStyles = style?.padding && + const containerStyles = style?.containerPadding && style?.backgroundColor && { - padding: style.padding, + padding: style.containerPadding, backgroundColor: style.backgroundColor, }; From 0fc97af1d83f8f2d54b7bc3b38f75a21d3037f78 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 20 Apr 2021 14:00:59 +0200 Subject: [PATCH 08/33] Add reset button in color picker --- .../color-settings/palette.screen.native.js | 32 +++++++++++++++++-- .../mobile/color-settings/style.native.scss | 12 +++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/components/src/mobile/color-settings/palette.screen.native.js b/packages/components/src/mobile/color-settings/palette.screen.native.js index 91cd1cc8e71951..19e7c5847f9547 100644 --- a/packages/components/src/mobile/color-settings/palette.screen.native.js +++ b/packages/components/src/mobile/color-settings/palette.screen.native.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { View, Text } from 'react-native'; +import { View, Text, TouchableWithoutFeedback } from 'react-native'; /** * WordPress dependencies @@ -26,6 +26,8 @@ import { colorsUtils } from './utils'; import styles from './style.scss'; +const HIT_SLOP = { top: 22, bottom: 22, left: 22, right: 22 }; + const PaletteScreen = () => { const route = useRoute(); const navigation = useNavigation(); @@ -50,6 +52,10 @@ const PaletteScreen = () => { styles.horizontalSeparator, styles.horizontalSeparatorDark ); + const clearButtonStyle = usePreferredColorSchemeStyle( + styles.clearButton, + styles.clearButtonDark + ); const isSolidSegment = currentSegment === segments[ 0 ]; const isCustomGadientShown = ! isSolidSegment && isGradientColor; @@ -67,6 +73,15 @@ const PaletteScreen = () => { } }; + function onClear() { + setCurrentValue( undefined ); + if ( isSolidSegment ) { + onColorChange( '' ); + } else { + onGradientChange( '' ); + } + } + function onCustomPress() { if ( isSolidSegment ) { navigation.navigate( colorsUtils.screens.picker, { @@ -82,6 +97,16 @@ const PaletteScreen = () => { } } + function getClearButton() { + return ( + + + { __( 'Reset' ) } + + + ); + } + function getFooter() { if ( onGradientChange ) { return ( @@ -97,6 +122,7 @@ const PaletteScreen = () => { /> ) } + addonRight={ currentValue && getClearButton() } /> ); } @@ -116,7 +142,9 @@ const PaletteScreen = () => { > { __( 'Select a color' ) } - + + { currentValue && getClearButton() } + ); } diff --git a/packages/components/src/mobile/color-settings/style.native.scss b/packages/components/src/mobile/color-settings/style.native.scss index 5ea2417761c2da..a86ebe02388d7d 100644 --- a/packages/components/src/mobile/color-settings/style.native.scss +++ b/packages/components/src/mobile/color-settings/style.native.scss @@ -33,3 +33,15 @@ flex: 1; } +.clearButtonContainer { + align-items: flex-end; +} + +.clearButton { + color: $blue-50; + font-size: 17px; +} + +.clearButtonDark { + color: $blue-30; +} From e0af895bf9957fb50ac7a1561d34c21634c233eb Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 20 Apr 2021 14:06:26 +0200 Subject: [PATCH 09/33] Fix placeholder colors --- .../src/mobile/global-styles-context/utils.native.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 79034e65c0286c..cd0b802fd71d1d 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -70,12 +70,6 @@ export function getBlockColors( if ( styleKey && value !== UNKNOWN_VALUE ) { const color = customBlockStyles[ key ] ?? value; blockStyles[ styleKey ] = color; - - if ( styleKey === BLOCK_STYLE_ATTRIBUTES_MAPPING.text ) { - blockStyles[ - BLOCK_STYLE_ATTRIBUTES_MAPPING.placeholder - ] = color; - } } } ); @@ -113,6 +107,12 @@ export function getBlockColors( } } ); + // Color placeholder + if ( blockStyles?.color ) { + blockStyles[ BLOCK_STYLE_ATTRIBUTES_MAPPING.placeholder ] = + blockStyles.color; + } + return blockStyles; } From 1b74f6cb2a6d05f3c0c65909f519254d4717b205 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 20 Apr 2021 14:44:43 +0200 Subject: [PATCH 10/33] Fix paddings and remove Columns placeholder solid background --- packages/block-library/src/column/editor.native.scss | 2 -- .../src/mobile/global-styles-context/utils.native.js | 4 ++-- packages/editor/src/components/provider/theme_data.native.js | 4 ++-- packages/rich-text/src/component/index.native.js | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/block-library/src/column/editor.native.scss b/packages/block-library/src/column/editor.native.scss index 6c52b88af035e4..ab0d7be831e354 100644 --- a/packages/block-library/src/column/editor.native.scss +++ b/packages/block-library/src/column/editor.native.scss @@ -5,13 +5,11 @@ .columnPlaceholder { flex: 1; padding: $block-selected-to-content; - background-color: $white; border: $border-width dashed $gray; border-radius: 4px; } .columnPlaceholderDark { - background-color: $black; border: $border-width dashed $gray-70; } diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index cd0b802fd71d1d..107019f95b7f0b 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -35,7 +35,7 @@ export function getBlockPaddings( blockStyleAttributes?.backgroundColor || blockColors?.backgroundColor ) ) { - blockPaddings.containerPadding = PADDING; + blockPaddings.padding = PADDING; return blockPaddings; } @@ -45,7 +45,7 @@ export function getBlockPaddings( ! wrapperPropsStyle?.backgroundColor && ! blockStyleAttributes?.backgroundColor ) { - blockPaddings.containerPadding = undefined; + blockPaddings.padding = undefined; } return blockPaddings; diff --git a/packages/editor/src/components/provider/theme_data.native.js b/packages/editor/src/components/provider/theme_data.native.js index 51b0942618363a..f9d4ea12884525 100644 --- a/packages/editor/src/components/provider/theme_data.native.js +++ b/packages/editor/src/components/provider/theme_data.native.js @@ -142,9 +142,9 @@ export default { text: 'var(--wp--preset--color--red)', }, }, - 'core/cover': { + 'core/group': { color: { - text: 'var(--wp--preset--color--green)', + background: 'var(--wp--preset--color--red)', }, }, }, diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 98180fb1b85013..230fb9345dda94 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -918,9 +918,9 @@ export class RichText extends Component { maxWidth && this.state.width && maxWidth - this.state.width < 10 ? maxWidth : this.state.width; - const containerStyles = style?.containerPadding && + const containerStyles = style?.padding && style?.backgroundColor && { - padding: style.containerPadding, + padding: style.padding, backgroundColor: style.backgroundColor, }; From 05ed7b61c4e633f78a6ce7774cc1060c4727865e Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 20 Apr 2021 14:53:49 +0200 Subject: [PATCH 11/33] Don't reset paddings for inner blocks that have paddings already --- .../src/mobile/global-styles-context/utils.native.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 107019f95b7f0b..5817e9c6582c5f 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -43,7 +43,8 @@ export function getBlockPaddings( if ( mergedStyle?.padding && ! wrapperPropsStyle?.backgroundColor && - ! blockStyleAttributes?.backgroundColor + ! blockStyleAttributes?.backgroundColor && + ! blockColors?.backgroundColor ) { blockPaddings.padding = undefined; } From 5417603ac45b70ddd916bb007a035d0585e407c5 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Mon, 26 Apr 2021 14:23:35 +0200 Subject: [PATCH 12/33] Mobile - Block styles support --- .../block-library/src/button/edit.native.js | 13 +++++-- .../block-library/src/columns/edit.native.js | 6 ++-- packages/block-library/src/list/edit.js | 5 ++- .../src/media-text/edit.native.js | 35 +++++++++---------- .../src/media-text/style.native.scss | 4 +++ .../components/provider/theme_data.native.js | 26 +------------- 6 files changed, 40 insertions(+), 49 deletions(-) diff --git a/packages/block-library/src/button/edit.native.js b/packages/block-library/src/button/edit.native.js index 7c46ac27366afa..2bbfe51e83d8ab 100644 --- a/packages/block-library/src/button/edit.native.js +++ b/packages/block-library/src/button/edit.native.js @@ -184,7 +184,12 @@ class ButtonEdit extends Component { } getBackgroundColor() { - const { backgroundColor, attributes, gradientValue } = this.props; + const { + backgroundColor, + attributes, + gradientValue, + mergedStyle, + } = this.props; const { customGradient } = attributes; if ( customGradient || gradientValue ) { @@ -196,18 +201,20 @@ class ButtonEdit extends Component { colorAndStyleProps.style?.background || // We still need the `backgroundColor.color` to support colors from the color pallete (not custom ones) backgroundColor.color || + mergedStyle?.backgroundColor || styles.defaultButton.backgroundColor ); } getTextColor() { - const { textColor, attributes } = this.props; + const { textColor, attributes, mergedStyle } = this.props; const colorAndStyleProps = getColorAndStyleProps( attributes ); return ( colorAndStyleProps.style?.color || // We still need the `textColor.color` to support colors from the color pallete (not custom ones) textColor.color || + mergedStyle?.color || styles.defaultButton.color ); } @@ -351,6 +358,7 @@ class ButtonEdit extends Component { mergeBlocks, parentWidth, setAttributes, + mergedStyle, } = this.props; const { placeholder, @@ -437,6 +445,7 @@ class ButtonEdit extends Component { } } textAlign={ align } placeholderTextColor={ + mergedStyle?.color || styles.placeholderTextColor.color } identifier="text" diff --git a/packages/block-library/src/columns/edit.native.js b/packages/block-library/src/columns/edit.native.js index 241e5fe247e358..ce3012371c8614 100644 --- a/packages/block-library/src/columns/edit.native.js +++ b/packages/block-library/src/columns/edit.native.js @@ -438,7 +438,7 @@ const ColumnsEditContainerWrapper = withDispatch( )( memo( ColumnsEditContainer ) ); const ColumnsEdit = ( props ) => { - const { clientId, isSelected } = props; + const { clientId, isSelected, mergedStyle } = props; const { columnCount, isDefaultColumns, @@ -501,7 +501,7 @@ const ColumnsEdit = ( props ) => { }, [] ); return ( - <> + { clientId={ clientId } isVisible={ isVisible } /> - + ); }; diff --git a/packages/block-library/src/list/edit.js b/packages/block-library/src/list/edit.js index 8a9c8af53dd65c..c3aa33ba0d068a 100644 --- a/packages/block-library/src/list/edit.js +++ b/packages/block-library/src/list/edit.js @@ -42,6 +42,7 @@ export default function ListEdit( { mergeBlocks, onReplace, isSelected, + mergedStyle, } ) { const { ordered, values, type, reversed, start } = attributes; const tagName = ordered ? 'ol' : 'ul'; @@ -141,7 +142,9 @@ export default function ListEdit( { ); - const blockProps = useBlockProps(); + const blockProps = useBlockProps( { + style: mergedStyle, + } ); return ( <> diff --git a/packages/block-library/src/media-text/edit.native.js b/packages/block-library/src/media-text/edit.native.js index 49239ae4d0c303..77411cd81f8892 100644 --- a/packages/block-library/src/media-text/edit.native.js +++ b/packages/block-library/src/media-text/edit.native.js @@ -254,7 +254,7 @@ class MediaTextEdit extends Component { setAttributes, isSelected, isRTL, - wrapperProps, + mergedStyle, blockWidth, } = this.props; const { @@ -273,14 +273,21 @@ class MediaTextEdit extends Component { ? 100 : this.state.mediaWidth || mediaWidth; const widthString = `${ temporaryMediaWidth }%`; + const innerBlockWidth = shouldStack ? 100 : 100 - temporaryMediaWidth; + const innerBlockWidthString = `${ innerBlockWidth }%`; - const innerBlockContainerStyle = ! shouldStack - ? styles.innerBlock - : { - ...( mediaPosition === 'left' - ? styles.innerBlockStackMediaLeft - : styles.innerBlockStackMediaRight ), - }; + const innerBlockContainerStyle = [ + { width: innerBlockWidthString }, + ! shouldStack + ? styles.innerBlock + : { + ...( mediaPosition === 'left' + ? styles.innerBlockStackMediaLeft + : styles.innerBlockStackMediaRight ), + }, + ( mergedStyle?.backgroundColor || backgroundColor.color ) && + styles.innerBlockPaddings, + ]; const containerStyles = { ...styles[ 'wp-block-media-text' ], @@ -296,13 +303,10 @@ class MediaTextEdit extends Component { : {} ), ...( isSelected && styles[ 'is-selected' ] ), backgroundColor: - wrapperProps?.style?.backgroundColor || backgroundColor.color, + mergedStyle?.backgroundColor || backgroundColor.color, paddingBottom: 0, }; - const innerBlockWidth = shouldStack ? 100 : 100 - temporaryMediaWidth; - const innerBlockWidthString = `${ innerBlockWidth }%`; - const mediaContainerStyle = [ { flex: 1 }, shouldStack @@ -375,12 +379,7 @@ class MediaTextEdit extends Component { > { this.renderMediaArea( shouldStack ) } - + Date: Mon, 26 Apr 2021 16:07:12 +0200 Subject: [PATCH 13/33] Add fallback text color to blocks --- .../src/mobile/global-styles-context/utils.native.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 5817e9c6582c5f..7d28028b46fe9f 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -74,6 +74,9 @@ export function getBlockColors( } } ); + } else if ( baseGlobalStyles?.styles?.color?.text ) { + blockStyles[ BLOCK_STYLE_ATTRIBUTES_MAPPING.text ] = + baseGlobalStyles?.styles?.color?.text; } // Global styles elements From 7102a514094a2f92dcf38f6b2ad6cd2c91c27972 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Tue, 6 Apr 2021 22:05:43 +0300 Subject: [PATCH 14/33] Adds new Prop for Global Styles Settings --- .../java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt index 5e1e712cb414ab..7b4841e0402770 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt @@ -33,6 +33,8 @@ data class GutenbergProps @JvmOverloads constructor( editorTheme?.also { theme -> theme.getSerializable(PROP_COLORS)?.let { putSerializable(PROP_COLORS, it) } theme.getSerializable(PROP_GRADIENTS)?.let { putSerializable(PROP_GRADIENTS, it) } + theme.getSerializable(PROP_GLOBAL_STYLES) + ?.let { putSerializable(PROP_GLOBAL_STYLES, it) } } } @@ -63,6 +65,7 @@ data class GutenbergProps @JvmOverloads constructor( private const val PROP_TRANSLATIONS = "translations" private const val PROP_COLORS = "colors" private const val PROP_GRADIENTS = "gradients" + private const val PROP_GLOBAL_STYLES = "rawGlobalStylesBaseStyles" const val PROP_CAPABILITIES = "capabilities" const val PROP_CAPABILITIES_CONTACT_INFO_BLOCK = "contactInfoBlock" From 906a9f66e12a3637b31772e79d563eadf399daf2 Mon Sep 17 00:00:00 2001 From: Chip Date: Thu, 6 May 2021 15:10:36 -0400 Subject: [PATCH 15/33] Rename updateTheme to be more generic for update settings include GSS (#31566) --- .../src/components/provider/index.native.js | 24 ++++++----- .../RNReactNativeGutenbergBridgeModule.java | 4 +- packages/react-native-bridge/index.js | 7 +++- .../react-native-bridge/ios/Gutenberg.swift | 42 +++++++++++-------- .../ios/GutenbergBridgeDataSource.swift | 5 ++- .../ios/RNReactNativeGutenbergBridge.swift | 2 +- test/native/setup.js | 2 +- 7 files changed, 50 insertions(+), 36 deletions(-) diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 93f589bc7d9f47..421d930e17e16a 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -11,7 +11,7 @@ import RNReactNativeGutenbergBridge, { subscribeSetTitle, subscribeMediaAppend, subscribeReplaceBlock, - subscribeUpdateTheme, + subscribeUpdateEditorSettings, subscribeUpdateCapabilities, subscribeShowNotice, } from '@wordpress/react-native-bridge'; @@ -126,15 +126,17 @@ class NativeEditorProvider extends Component { } ); - this.subscriptionParentUpdateTheme = subscribeUpdateTheme( - ( theme ) => { + this.subscriptionParentUpdateEditorSettings = subscribeUpdateEditorSettings( + ( editorSettings ) => { // Reset the colors and gradients in case one theme was set with custom items and then updated to a theme without custom elements. - - theme.colors = validateThemeColors( theme.colors ); - - theme.gradients = validateThemeGradients( theme.gradients ); - - this.props.updateSettings( theme ); + editorSettings.colors = validateThemeColors( + editorSettings.colors + ); + editorSettings.gradients = validateThemeGradients( + editorSettings.gradients + ); + + this.props.updateSettings( editorSettings ); } ); @@ -176,8 +178,8 @@ class NativeEditorProvider extends Component { this.subscriptionParentMediaAppend.remove(); } - if ( this.subscriptionParentUpdateTheme ) { - this.subscriptionParentUpdateTheme.remove(); + if ( this.subscriptionParentUpdateEditorSettings ) { + this.subscriptionParentUpdateEditorSettings.remove(); } if ( this.subscriptionParentUpdateCapabilities ) { diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index 7cdd5d9c33cee1..61bd2e5dee17d6 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -44,7 +44,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu private static final String EVENT_NAME_NOTIFY_MODAL_CLOSED = "notifyModalClosed"; private static final String EVENT_NAME_PREFERRED_COLOR_SCHEME = "preferredColorScheme"; private static final String EVENT_NAME_MEDIA_REPLACE_BLOCK = "replaceBlock"; - private static final String EVENT_NAME_UPDATE_THEME = "updateTheme"; + private static final String EVENT_NAME_UPDATE_EDITOR_SETTINGS = "updateEditorSettings"; private static final String EVENT_NAME_SHOW_NOTICE = "showNotice"; private static final String MAP_KEY_UPDATE_HTML = "html"; @@ -153,7 +153,7 @@ public void updateTheme(@Nullable Bundle editorTheme) { writableMap.putArray(MAP_KEY_THEME_UPDATE_GRADIENTS, Arguments.fromList((ArrayList)gradients)); } - emitToJS(EVENT_NAME_UPDATE_THEME, writableMap); + emitToJS(EVENT_NAME_UPDATE_EDITOR_SETTINGS, writableMap); } @ReactMethod diff --git a/packages/react-native-bridge/index.js b/packages/react-native-bridge/index.js index 73099bd1eff3db..6a5e5c3ca80b84 100644 --- a/packages/react-native-bridge/index.js +++ b/packages/react-native-bridge/index.js @@ -125,8 +125,11 @@ export function subscribeAndroidModalClosed( callback ) { : undefined; } -export function subscribeUpdateTheme( callback ) { - return gutenbergBridgeEvents.addListener( 'updateTheme', callback ); +export function subscribeEditorSettingsTheme( callback ) { + return gutenbergBridgeEvents.addListener( + 'updateEditorSettings', + callback + ); } export function subscribePreferredColorScheme( callback ) { diff --git a/packages/react-native-bridge/ios/Gutenberg.swift b/packages/react-native-bridge/ios/Gutenberg.swift index d6cc7605385125..755cdade135add 100644 --- a/packages/react-native-bridge/ios/Gutenberg.swift +++ b/packages/react-native-bridge/ios/Gutenberg.swift @@ -79,13 +79,18 @@ public class Gutenberg: NSObject { initialProps["capabilities"] = capabilities.toJSPayload() } - let editorTheme = dataSource.gutenbergEditorTheme() - if let colors = editorTheme?.colors { - initialProps["colors"] = colors - } - - if let gradients = editorTheme?.gradients { - initialProps["gradients"] = gradients + let editorSettings = dataSource.gutenbergEditorSettings() + if let rawGlobalStylesBaseStyles = editorSettings?.rawGlobalStylesBaseStyles { + initialProps["rawGlobalStylesBaseStyles"] = rawGlobalStylesBaseStyles + } else { + // We only need to include Colors and Gradients here if the Global Styles data wasn't provided + if let colors = editorSettings?.colors { + initialProps["colors"] = colors + } + + if let gradients = editorSettings?.gradients { + initialProps["gradients"] = gradients + } } return initialProps @@ -184,19 +189,22 @@ public class Gutenberg: NSObject { bridgeModule.sendEventIfNeeded(.setFocusOnTitle, body: nil) } - public func updateTheme(_ editorTheme: GutenbergEditorTheme?) { - - var themeUpdates = [String : Any]() - - if let colors = editorTheme?.colors { - themeUpdates["colors"] = colors - } + public func updateEditorSettings(_ editorSettings: GutenbergEditorSettings?) { + var settingsUpdates = [String : Any]() + if let rawGlobalStylesBaseStyles = editorSettings?.rawGlobalStylesBaseStyles { + settingsUpdates["rawGlobalStylesBaseStyles"] = rawGlobalStylesBaseStyles + } else { + // We only need to include Colors and Gradients here if the Global Styles data wasn't provided + if let colors = editorSettings?.colors { + settingsUpdates["colors"] = colors + } - if let gradients = editorTheme?.gradients { - themeUpdates["gradients"] = gradients + if let gradients = editorSettings?.gradients { + settingsUpdates["gradients"] = gradients + } } - sendEvent(.updateTheme, body:themeUpdates) + sendEvent(.updateEditorSettings, body: settingsUpdates) } public func showNotice(_ message: String) { diff --git a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift index d6023f4d1508d7..a6f1cb2998123c 100644 --- a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift +++ b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift @@ -46,7 +46,7 @@ public protocol GutenbergBridgeDataSource: class { func gutenbergCapabilities() -> [Capabilities: Bool] /// Asks the data source for a list of theme colors. - func gutenbergEditorTheme() -> GutenbergEditorTheme? + func gutenbergEditorSettings() -> GutenbergEditorSettings? /// Asks the data source for a view to show while the Editor is loading. var loadingView: UIView? { get } @@ -70,7 +70,8 @@ public extension GutenbergBridgeDataSource { } } -public protocol GutenbergEditorTheme { +public protocol GutenbergEditorSettings { + var rawGlobalStylesBaseStyles: String? { get } var colors: [[String: String]]? { get } var gradients: [[String: String]]? { get } } diff --git a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift index 82f19d50a5a154..2b57384df96109 100644 --- a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift +++ b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift @@ -369,7 +369,7 @@ extension RNReactNativeGutenbergBridge { case mediaUpload case setFocusOnTitle case mediaAppend - case updateTheme + case updateEditorSettings case replaceBlock case updateCapabilities case showNotice diff --git a/test/native/setup.js b/test/native/setup.js index 9c89c8845d999a..47e584ce6406d3 100644 --- a/test/native/setup.js +++ b/test/native/setup.js @@ -34,7 +34,7 @@ jest.mock( '@wordpress/react-native-bridge', () => { subscribeFeaturedImageIdNativeUpdated: jest.fn(), subscribeMediaAppend: jest.fn(), subscribeAndroidModalClosed: jest.fn(), - subscribeUpdateTheme: jest.fn(), + subscribeUpdateEditorSettings: jest.fn(), subscribePreferredColorScheme: () => 'light', subscribeUpdateCapabilities: jest.fn(), subscribeShowNotice: jest.fn(), From 226780b30d5b2b3e0774a4a862cd1d03aab22565 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Fri, 7 May 2021 15:28:27 +0200 Subject: [PATCH 16/33] Fix wrong naming of subscribeUpdateEditorSettings --- packages/react-native-bridge/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native-bridge/index.js b/packages/react-native-bridge/index.js index 6a5e5c3ca80b84..b2443dc36cc829 100644 --- a/packages/react-native-bridge/index.js +++ b/packages/react-native-bridge/index.js @@ -125,7 +125,7 @@ export function subscribeAndroidModalClosed( callback ) { : undefined; } -export function subscribeEditorSettingsTheme( callback ) { +export function subscribeUpdateEditorSettings( callback ) { return gutenbergBridgeEvents.addListener( 'updateEditorSettings', callback From 8ad3a37f6b8434c2d38d6dc6fd0972a5ae2c5285 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Fri, 7 May 2021 16:54:00 +0200 Subject: [PATCH 17/33] Update Gutenberg demo --- .../ios/GutenbergDemo/GutenbergViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift b/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift index 162fb297c28f07..0adbc4569660c7 100644 --- a/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift +++ b/packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift @@ -294,7 +294,7 @@ extension GutenbergViewController: GutenbergBridgeDataSource { return ExampleAttachmentDelegate() } - func gutenbergEditorTheme() -> GutenbergEditorTheme? { + func gutenbergEditorSettings() -> GutenbergEditorSettings? { return nil } From 01321341e3d15e57f0aa578aec132038e4462717 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 13 May 2021 23:18:28 +0300 Subject: [PATCH 18/33] Updates new props to rawStyles and rawFeatures --- .../org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt index 7b4841e0402770..2f1d4b2993989f 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt @@ -33,8 +33,10 @@ data class GutenbergProps @JvmOverloads constructor( editorTheme?.also { theme -> theme.getSerializable(PROP_COLORS)?.let { putSerializable(PROP_COLORS, it) } theme.getSerializable(PROP_GRADIENTS)?.let { putSerializable(PROP_GRADIENTS, it) } - theme.getSerializable(PROP_GLOBAL_STYLES) - ?.let { putSerializable(PROP_GLOBAL_STYLES, it) } + theme.getSerializable(PROP_STYLES) + ?.let { putSerializable(PROP_STYLES, it) } + theme.getSerializable(PROP_FEATURES) + ?.let { putSerializable(PROP_FEATURES, it) } } } @@ -65,7 +67,8 @@ data class GutenbergProps @JvmOverloads constructor( private const val PROP_TRANSLATIONS = "translations" private const val PROP_COLORS = "colors" private const val PROP_GRADIENTS = "gradients" - private const val PROP_GLOBAL_STYLES = "rawGlobalStylesBaseStyles" + private const val PROP_STYLES = "rawStyles" + private const val PROP_FEATURES = "rawFeatures" const val PROP_CAPABILITIES = "capabilities" const val PROP_CAPABILITIES_CONTACT_INFO_BLOCK = "contactInfoBlock" From bf75be199696aa131e1d3dc4397c67b2f8c0e3a6 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Fri, 14 May 2021 16:22:22 -0400 Subject: [PATCH 19/33] Update iOS Bridge for new values --- .../react-native-bridge/ios/Gutenberg.swift | 48 ++++++++++--------- .../ios/GutenbergBridgeDataSource.swift | 4 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/react-native-bridge/ios/Gutenberg.swift b/packages/react-native-bridge/ios/Gutenberg.swift index 755cdade135add..b23b6b5dc4ca62 100644 --- a/packages/react-native-bridge/ios/Gutenberg.swift +++ b/packages/react-native-bridge/ios/Gutenberg.swift @@ -80,17 +80,9 @@ public class Gutenberg: NSObject { } let editorSettings = dataSource.gutenbergEditorSettings() - if let rawGlobalStylesBaseStyles = editorSettings?.rawGlobalStylesBaseStyles { - initialProps["rawGlobalStylesBaseStyles"] = rawGlobalStylesBaseStyles - } else { - // We only need to include Colors and Gradients here if the Global Styles data wasn't provided - if let colors = editorSettings?.colors { - initialProps["colors"] = colors - } - - if let gradients = editorSettings?.gradients { - initialProps["gradients"] = gradients - } + let settingsUpdates = properties(from: editorSettings) + initialProps.merge(properties(from: editorSettings)) { (intialProp, settingsUpdates) -> Any in + settingsUpdates } return initialProps @@ -190,21 +182,31 @@ public class Gutenberg: NSObject { } public func updateEditorSettings(_ editorSettings: GutenbergEditorSettings?) { + let settingsUpdates = properties(from: editorSettings) + sendEvent(.updateEditorSettings, body: settingsUpdates) + } + + private func properties(from editorSettings: GutenbergEditorSettings?) -> [String : Any] { var settingsUpdates = [String : Any]() - if let rawGlobalStylesBaseStyles = editorSettings?.rawGlobalStylesBaseStyles { - settingsUpdates["rawGlobalStylesBaseStyles"] = rawGlobalStylesBaseStyles - } else { - // We only need to include Colors and Gradients here if the Global Styles data wasn't provided - if let colors = editorSettings?.colors { - settingsUpdates["colors"] = colors - } - - if let gradients = editorSettings?.gradients { - settingsUpdates["gradients"] = gradients - } + settingsUpdates["isFSETheme"] = editorSettings?.isFSETheme ?? false + + if let rawStyles = editorSettings?.rawStyles { + settingsUpdates["rawStyles"] = rawStyles } - sendEvent(.updateEditorSettings, body: settingsUpdates) + if let rawFeatures = editorSettings?.rawFeatures { + settingsUpdates["rawFeatures"] = rawFeatures + } + + if let colors = editorSettings?.colors { + settingsUpdates["colors"] = colors + } + + if let gradients = editorSettings?.gradients { + settingsUpdates["gradients"] = gradients + } + + return settingsUpdates } public func showNotice(_ message: String) { diff --git a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift index a6f1cb2998123c..b082cbd60682df 100644 --- a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift +++ b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift @@ -71,7 +71,9 @@ public extension GutenbergBridgeDataSource { } public protocol GutenbergEditorSettings { - var rawGlobalStylesBaseStyles: String? { get } + var isFSETheme: Bool { get } + var rawStyles: String? { get } + var rawFeatures: String? { get } var colors: [[String: String]]? { get } var gradients: [[String: String]]? { get } } From aeaf65f43c4883c1955e8d75d7ec57269b5fd037 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 18 May 2021 17:08:19 +0200 Subject: [PATCH 20/33] Mobile - Global styles: Pass settings and set color palette and gradients (#30684) * Mobile - Read global styles and set color palette and gradients * Parse all color variables * Fix gradients * Update global styles mocked data * Move color settings * Removed added spaces * Add tests * Update experimental features path and prepare for rawGlobalStylesBaseStyles * Remove mock data and update code to use latest API changes --- .../block-settings/container.native.js | 9 +- packages/components/src/index.native.js | 1 + .../test/utils.native.js | 111 +++++++++++++++++- .../global-styles-context/utils.native.js | 35 ++++++ .../src/components/provider/index.native.js | 33 +++--- 5 files changed, 170 insertions(+), 19 deletions(-) diff --git a/packages/block-editor/src/components/block-settings/container.native.js b/packages/block-editor/src/components/block-settings/container.native.js index e9f16b185a5564..7f9d8a9073d398 100644 --- a/packages/block-editor/src/components/block-settings/container.native.js +++ b/packages/block-editor/src/components/block-settings/container.native.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { InspectorControls } from '@wordpress/block-editor'; +import { InspectorControls, useSetting } from '@wordpress/block-editor'; import { BottomSheet, ColorSettings, @@ -29,6 +29,11 @@ function BottomSheetSettings( { settings, ...props } ) { + const colorSettings = { + colors: useSetting( 'color.palette' ) || settings.colors, + gradients: useSetting( 'color.gradients' ) || settings.gradients, + }; + return ( - + { const PADDING = 12; @@ -84,3 +159,37 @@ describe( 'getBlockColors', () => { ); } ); } ); + +describe( 'parseColorVariables', () => { + it( 'returns the parsed colors values correctly', () => { + const blockColors = parseColorVariables( + JSON.stringify( DEFAULT_GLOBAL_STYLES ), + GLOBAL_STYLES_PALETTE + ); + expect( blockColors ).toEqual( + expect.objectContaining( PARSED_GLOBAL_STYLES ) + ); + } ); +} ); + +describe( 'getGlobalStyles', () => { + it( 'returns the global styles data correctly', () => { + const globalStyles = getGlobalStyles( + JSON.stringify( DEFAULT_GLOBAL_STYLES ), + JSON.stringify( DEFAULT_FEATURES ) + ); + const gradients = parseColorVariables( + JSON.stringify( DEFAULT_FEATURES ), + GLOBAL_STYLES_PALETTE + )?.color?.gradients; + + expect( globalStyles ).toEqual( + expect.objectContaining( { + __experimentalFeatures: { + color: { palette: GLOBAL_STYLES_PALETTE, gradients }, + }, + __experimentalGlobalStylesBaseStyles: PARSED_GLOBAL_STYLES, + } ) + ); + } ); +} ); diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index c8e2bce0c91f8a..35dc09f98b581d 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -66,3 +66,38 @@ export function getBlockColors( blockStyleAttributes, defaultColors ) { return blockStyles; } + +export function parseColorVariables( styles, colorPalette ) { + const stylesBase = styles; + const colorPrefixRegex = /var\(--wp--preset--color--(.*?)\)/g; + + return stylesBase + ? JSON.parse( + stylesBase?.replace( colorPrefixRegex, ( _$1, $2 ) => { + const mappedColor = find( colorPalette, { + slug: $2, + } ); + return mappedColor?.color; + } ) + ) + : styles; +} + +export function getGlobalStyles( rawStyles, rawFeatures ) { + const features = JSON.parse( rawFeatures ); + const palette = features?.color?.palette; + const gradients = parseColorVariables( rawFeatures, palette )?.color + ?.gradients; + const globalStyles = parseColorVariables( rawStyles, palette ); + + return { + ...( palette || gradients + ? { + __experimentalFeatures: { + color: { palette, gradients }, + }, + } + : {} ), + __experimentalGlobalStylesBaseStyles: globalStyles, + }; +} diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 421d930e17e16a..1f76a311ffaad6 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -1,6 +1,3 @@ -/** - * External dependencies - */ /** * WordPress dependencies */ @@ -15,10 +12,6 @@ import RNReactNativeGutenbergBridge, { subscribeUpdateCapabilities, subscribeShowNotice, } from '@wordpress/react-native-bridge'; - -/** - * WordPress dependencies - */ import { Component } from '@wordpress/element'; import { count as wordCount } from '@wordpress/wordcount'; import { @@ -35,6 +28,7 @@ import { validateThemeGradients, store as blockEditorStore, } from '@wordpress/block-editor'; +import { getGlobalStyles } from '@wordpress/components'; const postTypeEntities = [ { name: 'post', baseURL: '/wp/v2/posts' }, @@ -128,15 +122,22 @@ class NativeEditorProvider extends Component { this.subscriptionParentUpdateEditorSettings = subscribeUpdateEditorSettings( ( editorSettings ) => { - // Reset the colors and gradients in case one theme was set with custom items and then updated to a theme without custom elements. - editorSettings.colors = validateThemeColors( - editorSettings.colors - ); - editorSettings.gradients = validateThemeGradients( - editorSettings.gradients - ); - - this.props.updateSettings( editorSettings ); + const { + colors: updatedColors, + gradients: updatedGradients, + rawFeatures, + rawStyles, + } = editorSettings; + const updatedSettings = { + // Reset the colors and gradients in case one theme was set with custom items and then updated to a theme without custom elements. + colors: validateThemeColors( updatedColors ), + gradients: validateThemeGradients( updatedGradients ), + ...( rawStyles + ? getGlobalStyles( rawStyles, rawFeatures ) + : {} ), + }; + + this.props.updateSettings( updatedSettings ); } ); From 32a2b3aff85ed83d2a3c953f94d4f37685b4f2ca Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 27 May 2021 14:35:19 +0300 Subject: [PATCH 21/33] Removes Android rawFeatures prop --- .../java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt index d89f0557cf9df3..b1ac2fbd5ce4ac 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt @@ -37,8 +37,6 @@ data class GutenbergProps @JvmOverloads constructor( theme.getSerializable(PROP_GRADIENTS)?.let { putSerializable(PROP_GRADIENTS, it) } theme.getSerializable(PROP_STYLES) ?.let { putSerializable(PROP_STYLES, it) } - theme.getSerializable(PROP_FEATURES) - ?.let { putSerializable(PROP_FEATURES, it) } } } @@ -72,7 +70,6 @@ data class GutenbergProps @JvmOverloads constructor( private const val PROP_COLORS = "colors" private const val PROP_GRADIENTS = "gradients" private const val PROP_STYLES = "rawStyles" - private const val PROP_FEATURES = "rawFeatures" const val PROP_CAPABILITIES = "capabilities" const val PROP_CAPABILITIES_CONTACT_INFO_BLOCK = "contactInfoBlock" From 9741f39592d8cc5613f7c2557cbf0647650c605c Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Thu, 27 May 2021 14:46:05 +0200 Subject: [PATCH 22/33] Mobile - Remove usage of rawFeatures --- .../test/utils.native.js | 42 +++++++++---------- .../global-styles-context/utils.native.js | 16 +++---- .../src/components/provider/index.native.js | 36 +++++++--------- 3 files changed, 42 insertions(+), 52 deletions(-) diff --git a/packages/components/src/mobile/global-styles-context/test/utils.native.js b/packages/components/src/mobile/global-styles-context/test/utils.native.js index f4df181fed9531..eb10086fffcb3c 100644 --- a/packages/components/src/mobile/global-styles-context/test/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/test/utils.native.js @@ -32,6 +32,21 @@ const GLOBAL_STYLES_PALETTE = [ }, ]; +const GLOBAL_STYLES_GRADIENTS = [ + { + slug: 'purple-to-blue', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--purple), var(--wp--preset--color--blue))', + name: 'Purple to Blue', + }, + { + slug: 'green-to-purple', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--green), var(--wp--preset--color--purple))', + name: 'Green to Purple', + }, +]; + const DEFAULT_GLOBAL_STYLES = { styles: { color: { @@ -48,26 +63,6 @@ const DEFAULT_GLOBAL_STYLES = { }, }; -const DEFAULT_FEATURES = { - color: { - palette: GLOBAL_STYLES_PALETTE, - gradients: [ - { - slug: 'purple-to-blue', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--purple), var(--wp--preset--color--blue))', - name: 'Purple to Blue', - }, - { - slug: 'green-to-purple', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--green), var(--wp--preset--color--purple))', - name: 'Green to Purple', - }, - ], - }, -}; - const PARSED_GLOBAL_STYLES = { styles: { color: { @@ -176,12 +171,13 @@ describe( 'getGlobalStyles', () => { it( 'returns the global styles data correctly', () => { const globalStyles = getGlobalStyles( JSON.stringify( DEFAULT_GLOBAL_STYLES ), - JSON.stringify( DEFAULT_FEATURES ) + GLOBAL_STYLES_PALETTE, + GLOBAL_STYLES_GRADIENTS ); const gradients = parseColorVariables( - JSON.stringify( DEFAULT_FEATURES ), + JSON.stringify( GLOBAL_STYLES_GRADIENTS ), GLOBAL_STYLES_PALETTE - )?.color?.gradients; + ); expect( globalStyles ).toEqual( expect.objectContaining( { diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 35dc09f98b581d..a30162d0578f88 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -83,18 +83,18 @@ export function parseColorVariables( styles, colorPalette ) { : styles; } -export function getGlobalStyles( rawStyles, rawFeatures ) { - const features = JSON.parse( rawFeatures ); - const palette = features?.color?.palette; - const gradients = parseColorVariables( rawFeatures, palette )?.color - ?.gradients; - const globalStyles = parseColorVariables( rawStyles, palette ); +export function getGlobalStyles( rawStyles, colors, gradients ) { + const parsedGradients = parseColorVariables( + JSON.stringify( gradients ), + colors + ); + const globalStyles = parseColorVariables( rawStyles, colors ); return { - ...( palette || gradients + ...( colors || gradients ? { __experimentalFeatures: { - color: { palette, gradients }, + color: { palette: colors, gradients: parsedGradients }, }, } : {} ), diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index b560870f5c1a66..063a46ce9ddd50 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -81,13 +81,11 @@ class NativeEditorProvider extends Component { } componentDidMount() { - const { capabilities, colors, gradients } = this.props; + const { capabilities, updateSettings } = this.props; - this.props.updateSettings( { + updateSettings( { ...capabilities, - // Set theme colors for the editor - ...( colors ? { colors } : {} ), - ...( gradients ? { gradients } : {} ), + ...this.getThemeColors( this.props ), } ); this.subscriptionParentGetHtml = subscribeParentGetHtml( () => { @@ -136,22 +134,8 @@ class NativeEditorProvider extends Component { this.subscriptionParentUpdateEditorSettings = subscribeUpdateEditorSettings( ( editorSettings ) => { - const { - colors: updatedColors, - gradients: updatedGradients, - rawFeatures, - rawStyles, - } = editorSettings; - const updatedSettings = { - // Reset the colors and gradients in case one theme was set with custom items and then updated to a theme without custom elements. - colors: validateThemeColors( updatedColors ), - gradients: validateThemeGradients( updatedGradients ), - ...( rawStyles - ? getGlobalStyles( rawStyles, rawFeatures ) - : {} ), - }; - - this.props.updateSettings( updatedSettings ); + const themeColors = this.getThemeColors( editorSettings ); + updateSettings( themeColors ); } ); @@ -206,6 +190,16 @@ class NativeEditorProvider extends Component { } } + getThemeColors( { colors, gradients, rawStyles } ) { + return { + colors: validateThemeColors( colors ) ?? [], + gradients: validateThemeGradients( gradients ) ?? [], + ...( rawStyles + ? getGlobalStyles( rawStyles, colors, gradients ) + : {} ), + }; + } + componentDidUpdate( prevProps ) { if ( ! prevProps.isReady && this.props.isReady ) { const blocks = this.props.blocks; From 9a404b49488d053997676b55b07eedf1e6157046 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Thu, 27 May 2021 16:03:00 -0400 Subject: [PATCH 23/33] Remove rawFeatures --- packages/react-native-bridge/ios/Gutenberg.swift | 4 ---- .../react-native-bridge/ios/GutenbergBridgeDataSource.swift | 1 - 2 files changed, 5 deletions(-) diff --git a/packages/react-native-bridge/ios/Gutenberg.swift b/packages/react-native-bridge/ios/Gutenberg.swift index b23b6b5dc4ca62..a7942f3e1368fe 100644 --- a/packages/react-native-bridge/ios/Gutenberg.swift +++ b/packages/react-native-bridge/ios/Gutenberg.swift @@ -194,10 +194,6 @@ public class Gutenberg: NSObject { settingsUpdates["rawStyles"] = rawStyles } - if let rawFeatures = editorSettings?.rawFeatures { - settingsUpdates["rawFeatures"] = rawFeatures - } - if let colors = editorSettings?.colors { settingsUpdates["colors"] = colors } diff --git a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift index b082cbd60682df..59e7f7709e2dc3 100644 --- a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift +++ b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift @@ -73,7 +73,6 @@ public extension GutenbergBridgeDataSource { public protocol GutenbergEditorSettings { var isFSETheme: Bool { get } var rawStyles: String? { get } - var rawFeatures: String? { get } var colors: [[String: String]]? { get } var gradients: [[String: String]]? { get } } From 792ab77824f3bbdf2bdb1a0548f540fc3945ec5f Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 28 May 2021 11:39:44 +0300 Subject: [PATCH 24/33] Adds raw Styles in React Native Bridge --- .../RNReactNativeGutenbergBridgeModule.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index 07172011548c20..7b7a6cee27051a 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -57,6 +57,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_TYPE = "mediaType"; private static final String MAP_KEY_THEME_UPDATE_COLORS = "colors"; private static final String MAP_KEY_THEME_UPDATE_GRADIENTS = "gradients"; + private static final String MAP_KEY_THEME_UPDATE_RAW_STYLES = "rawStyles"; public static final String MAP_KEY_MEDIA_FINAL_SAVE_RESULT_SUCCESS_VALUE = "success"; private static final String MAP_KEY_IS_PREFERRED_COLOR_SCHEME_DARK = "isPreferredColorSchemeDark"; @@ -144,6 +145,7 @@ public void updateTheme(@Nullable Bundle editorTheme) { WritableMap writableMap = new WritableNativeMap(); Serializable colors = editorTheme.getSerializable(MAP_KEY_THEME_UPDATE_COLORS); Serializable gradients = editorTheme.getSerializable(MAP_KEY_THEME_UPDATE_GRADIENTS); + Serializable rawStyles = editorTheme.getSerializable(MAP_KEY_THEME_UPDATE_RAW_STYLES); if (colors != null) { writableMap.putArray(MAP_KEY_THEME_UPDATE_COLORS, Arguments.fromList((ArrayList)colors)); @@ -153,6 +155,10 @@ public void updateTheme(@Nullable Bundle editorTheme) { writableMap.putArray(MAP_KEY_THEME_UPDATE_GRADIENTS, Arguments.fromList((ArrayList)gradients)); } + if (rawStyles != null) { + writableMap.putString(MAP_KEY_THEME_UPDATE_RAW_STYLES, rawStyles.toString()); + } + emitToJS(EVENT_NAME_UPDATE_EDITOR_SETTINGS, writableMap); } From 954d3372176426ba21d454888846d452e8367f96 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Fri, 28 May 2021 10:47:03 +0200 Subject: [PATCH 25/33] Mobile - Pass rawStyles on initial props and fix colors and gradients --- .../global-styles-context/test/utils.native.js | 2 ++ .../src/mobile/global-styles-context/utils.native.js | 12 +++++------- .../editor/src/components/provider/index.native.js | 7 ++++--- packages/react-native-editor/src/index.js | 2 ++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/components/src/mobile/global-styles-context/test/utils.native.js b/packages/components/src/mobile/global-styles-context/test/utils.native.js index eb10086fffcb3c..bac1c53d028989 100644 --- a/packages/components/src/mobile/global-styles-context/test/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/test/utils.native.js @@ -181,6 +181,8 @@ describe( 'getGlobalStyles', () => { expect( globalStyles ).toEqual( expect.objectContaining( { + colors: GLOBAL_STYLES_PALETTE, + gradients, __experimentalFeatures: { color: { palette: GLOBAL_STYLES_PALETTE, gradients }, }, diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index a30162d0578f88..636559a8f9195d 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -91,13 +91,11 @@ export function getGlobalStyles( rawStyles, colors, gradients ) { const globalStyles = parseColorVariables( rawStyles, colors ); return { - ...( colors || gradients - ? { - __experimentalFeatures: { - color: { palette: colors, gradients: parsedGradients }, - }, - } - : {} ), + colors, + gradients: parsedGradients, + __experimentalFeatures: { + color: { palette: colors, gradients: parsedGradients }, + }, __experimentalGlobalStylesBaseStyles: globalStyles, }; } diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 063a46ce9ddd50..0fa4e826aaf1ae 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -192,11 +192,12 @@ class NativeEditorProvider extends Component { getThemeColors( { colors, gradients, rawStyles } ) { return { - colors: validateThemeColors( colors ) ?? [], - gradients: validateThemeGradients( gradients ) ?? [], ...( rawStyles ? getGlobalStyles( rawStyles, colors, gradients ) - : {} ), + : { + colors: validateThemeColors( colors ), + gradients: validateThemeGradients( gradients ), + } ), }; } diff --git a/packages/react-native-editor/src/index.js b/packages/react-native-editor/src/index.js index 6198c043a3ab83..574ecac69bada5 100644 --- a/packages/react-native-editor/src/index.js +++ b/packages/react-native-editor/src/index.js @@ -79,6 +79,7 @@ const setupInitHooks = () => { featuredImageId, colors, gradients, + rawStyles, } = props; if ( initialData === undefined && __DEV__ ) { @@ -104,6 +105,7 @@ const setupInitHooks = () => { capabilities, colors, gradients, + rawStyles, }; } ); From 2e12d2c4483eb76edb8296d8159e7def7dca5ef5 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Wed, 16 Jun 2021 15:43:06 -0400 Subject: [PATCH 26/33] Add Raw Features back --- packages/react-native-bridge/ios/Gutenberg.swift | 6 +++++- .../react-native-bridge/ios/GutenbergBridgeDataSource.swift | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-native-bridge/ios/Gutenberg.swift b/packages/react-native-bridge/ios/Gutenberg.swift index a7942f3e1368fe..cd143ae0d831f4 100644 --- a/packages/react-native-bridge/ios/Gutenberg.swift +++ b/packages/react-native-bridge/ios/Gutenberg.swift @@ -81,7 +81,7 @@ public class Gutenberg: NSObject { let editorSettings = dataSource.gutenbergEditorSettings() let settingsUpdates = properties(from: editorSettings) - initialProps.merge(properties(from: editorSettings)) { (intialProp, settingsUpdates) -> Any in + initialProps.merge(settingsUpdates) { (intialProp, settingsUpdates) -> Any in settingsUpdates } @@ -194,6 +194,10 @@ public class Gutenberg: NSObject { settingsUpdates["rawStyles"] = rawStyles } + if let rawFeatures = editorSettings?.rawFeatures { + settingsUpdates["rawFeatures"] = rawFeatures + } + if let colors = editorSettings?.colors { settingsUpdates["colors"] = colors } diff --git a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift index 59e7f7709e2dc3..b082cbd60682df 100644 --- a/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift +++ b/packages/react-native-bridge/ios/GutenbergBridgeDataSource.swift @@ -73,6 +73,7 @@ public extension GutenbergBridgeDataSource { public protocol GutenbergEditorSettings { var isFSETheme: Bool { get } var rawStyles: String? { get } + var rawFeatures: String? { get } var colors: [[String: String]]? { get } var gradients: [[String: String]]? { get } } From 1bbda5263ee1ad66a4494d0ea6f2d91eca031549 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 17 Jun 2021 09:13:41 +0300 Subject: [PATCH 27/33] Revert "Removes Android rawFeatures prop" This reverts commit 32a2b3aff85ed83d2a3c953f94d4f37685b4f2ca. --- .../java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt index 8234447af7cfa1..6f7ff9fc796a0e 100644 --- a/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt +++ b/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/WPAndroidGlue/GutenbergProps.kt @@ -37,6 +37,8 @@ data class GutenbergProps @JvmOverloads constructor( theme.getSerializable(PROP_GRADIENTS)?.let { putSerializable(PROP_GRADIENTS, it) } theme.getSerializable(PROP_STYLES) ?.let { putSerializable(PROP_STYLES, it) } + theme.getSerializable(PROP_FEATURES) + ?.let { putSerializable(PROP_FEATURES, it) } } } @@ -70,6 +72,7 @@ data class GutenbergProps @JvmOverloads constructor( private const val PROP_COLORS = "colors" private const val PROP_GRADIENTS = "gradients" private const val PROP_STYLES = "rawStyles" + private const val PROP_FEATURES = "rawFeatures" const val PROP_CAPABILITIES = "capabilities" const val PROP_CAPABILITIES_CONTACT_INFO_BLOCK = "contactInfoBlock" From 1f34a2761f9281d607762a4a8639aa01ea0767ff Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Thu, 17 Jun 2021 13:31:39 +0200 Subject: [PATCH 28/33] Add rawFeatures in the mobile editor --- .../test/utils.native.js | 82 ++++++++++++++++++- .../global-styles-context/utils.native.js | 11 ++- .../src/components/provider/index.native.js | 4 +- packages/react-native-editor/src/index.js | 2 + 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/packages/components/src/mobile/global-styles-context/test/utils.native.js b/packages/components/src/mobile/global-styles-context/test/utils.native.js index bac1c53d028989..e29dc8bbed7fa8 100644 --- a/packages/components/src/mobile/global-styles-context/test/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/test/utils.native.js @@ -79,6 +79,77 @@ const PARSED_GLOBAL_STYLES = { }, }; +const RAW_FEATURES = { + color: { + palette: { + core: [ + { + name: 'Black', + slug: 'black', + color: '#000000', + }, + { + name: 'Cyan bluish gray', + slug: 'cyan-bluish-gray', + color: '#abb8c3', + }, + { + name: 'White', + slug: 'white', + color: '#ffffff', + }, + ], + theme: [ + { + slug: 'green', + color: '#D1E4DD', + name: 'Green', + }, + { + slug: 'blue', + color: '#D1DFE4', + name: 'Blue', + }, + { + slug: 'purple', + color: '#D1D1E4', + name: 'Purple', + }, + ], + }, + gradients: { + core: [ + { + name: 'Vivid cyan blue to vivid purple', + gradient: + 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)', + slug: 'vivid-cyan-blue-to-vivid-purple', + }, + { + name: 'Light green cyan to vivid green cyan', + gradient: + 'linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%)', + slug: 'light-green-cyan-to-vivid-green-cyan', + }, + ], + theme: [ + { + slug: 'purple-to-blue', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--purple), var(--wp--preset--color--blue))', + name: 'Purple to Blue', + }, + { + slug: 'green-to-purple', + gradient: + 'linear-gradient(160deg, var(--wp--preset--color--green), var(--wp--preset--color--purple))', + name: 'Green to Purple', + }, + ], + }, + }, +}; + describe( 'getBlockPaddings', () => { const PADDING = 12; @@ -169,8 +240,10 @@ describe( 'parseColorVariables', () => { describe( 'getGlobalStyles', () => { it( 'returns the global styles data correctly', () => { + const rawFeatures = JSON.stringify( RAW_FEATURES ); const globalStyles = getGlobalStyles( JSON.stringify( DEFAULT_GLOBAL_STYLES ), + rawFeatures, GLOBAL_STYLES_PALETTE, GLOBAL_STYLES_GRADIENTS ); @@ -178,13 +251,20 @@ describe( 'getGlobalStyles', () => { JSON.stringify( GLOBAL_STYLES_GRADIENTS ), GLOBAL_STYLES_PALETTE ); + const parsedExperimentalFeatures = parseColorVariables( + rawFeatures, + GLOBAL_STYLES_PALETTE + ); expect( globalStyles ).toEqual( expect.objectContaining( { colors: GLOBAL_STYLES_PALETTE, gradients, __experimentalFeatures: { - color: { palette: GLOBAL_STYLES_PALETTE, gradients }, + color: { + palette: parsedExperimentalFeatures?.color?.palette, + gradients: parsedExperimentalFeatures?.color?.gradients, + }, }, __experimentalGlobalStylesBaseStyles: PARSED_GLOBAL_STYLES, } ) diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 636559a8f9195d..0cf5bee75c4c75 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -83,18 +83,25 @@ export function parseColorVariables( styles, colorPalette ) { : styles; } -export function getGlobalStyles( rawStyles, colors, gradients ) { +export function getGlobalStyles( rawStyles, rawFeatures, colors, gradients ) { const parsedGradients = parseColorVariables( JSON.stringify( gradients ), colors ); const globalStyles = parseColorVariables( rawStyles, colors ); + const parsedExperimentalFeatures = parseColorVariables( + rawFeatures, + colors + ); return { colors, gradients: parsedGradients, __experimentalFeatures: { - color: { palette: colors, gradients: parsedGradients }, + color: { + palette: parsedExperimentalFeatures?.color?.palette, + gradients: parsedExperimentalFeatures?.color?.gradients, + }, }, __experimentalGlobalStylesBaseStyles: globalStyles, }; diff --git a/packages/editor/src/components/provider/index.native.js b/packages/editor/src/components/provider/index.native.js index 0fa4e826aaf1ae..8440c998856622 100644 --- a/packages/editor/src/components/provider/index.native.js +++ b/packages/editor/src/components/provider/index.native.js @@ -190,10 +190,10 @@ class NativeEditorProvider extends Component { } } - getThemeColors( { colors, gradients, rawStyles } ) { + getThemeColors( { colors, gradients, rawStyles, rawFeatures } ) { return { ...( rawStyles - ? getGlobalStyles( rawStyles, colors, gradients ) + ? getGlobalStyles( rawStyles, rawFeatures, colors, gradients ) : { colors: validateThemeColors( colors ), gradients: validateThemeGradients( gradients ), diff --git a/packages/react-native-editor/src/index.js b/packages/react-native-editor/src/index.js index 818aa2a2a7bc48..c8b8fd8b152ab2 100644 --- a/packages/react-native-editor/src/index.js +++ b/packages/react-native-editor/src/index.js @@ -82,6 +82,7 @@ const setupInitHooks = () => { colors, gradients, rawStyles, + rawFeatures, } = props; if ( initialData === undefined && __DEV__ ) { @@ -108,6 +109,7 @@ const setupInitHooks = () => { colors, gradients, rawStyles, + rawFeatures, }; } ); From 3d780d37918b991b508edfa927989a095b979ac1 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Fri, 18 Jun 2021 16:18:56 +0200 Subject: [PATCH 29/33] Mobile - Global styles: Set theme's background and text color (#30810) * Mobile - Read global styles and set color palette and gradients * Mobile - Enable colors for blocks that support it * Parse all color variables * Mobile - Set background, title, text and link colors * Fix gradients * Add placeholder color * Update global styles mocked data * Move color settings * Removed added spaces * Add tests * Update experimental features path and prepare for rawGlobalStylesBaseStyles * Add missing provider * Get the right color attribute * Remove mock data * Mobile - Fix base global colors --- .../src/components/block-list/block.native.js | 7 +++++ .../src/components/provider/index.native.js | 3 +- packages/block-editor/src/hooks/color.js | 2 +- .../src/paragraph/edit.native.js | 5 ++++ .../global-styles-context/index.native.js | 5 ++++ .../src/components/layout/index.native.js | 30 ++++++++++++++----- .../src/components/post-title/index.native.js | 30 ++++++++++++++----- .../rich-text/src/component/index.native.js | 15 +++++----- 8 files changed, 71 insertions(+), 26 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 018cf4760a07eb..c81a2d5469ecc1 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -48,11 +48,13 @@ function BlockForType( { parentWidth, wrapperProps, blockWidth, + baseGlobalStyles, } ) { const defaultColors = useSetting( 'color.palette' ) || emptyArray; const globalStyle = useGlobalStyles(); const mergedStyle = useMemo( () => { return getMergedGlobalStyles( + baseGlobalStyles, globalStyle, wrapperProps.style, attributes, @@ -300,6 +302,7 @@ export default compose( [ withSelect( ( select, { clientId, rootClientId } ) => { const { getBlockIndex, + getSettings, isBlockSelected, __unstableGetBlockWithoutInnerBlocks, getSelectedBlockClientId, @@ -347,6 +350,9 @@ export default compose( [ isDescendantOfParentSelected || isParentSelected || parentId === ''; + const baseGlobalStyles = getSettings() + ?.__experimentalGlobalStylesBaseStyles; + return { icon, name: name || 'core/missing', @@ -360,6 +366,7 @@ export default compose( [ isParentSelected, firstToSelectId, isTouchable, + baseGlobalStyles, wrapperProps: getWrapperProps( attributes, blockType.getEditWrapperProps diff --git a/packages/block-editor/src/components/provider/index.native.js b/packages/block-editor/src/components/provider/index.native.js index 157cd72d1f237b..8851a2b9b47a15 100644 --- a/packages/block-editor/src/components/provider/index.native.js +++ b/packages/block-editor/src/components/provider/index.native.js @@ -10,6 +10,7 @@ import { useEffect } from '@wordpress/element'; import withRegistryProvider from './with-registry-provider'; import useBlockSync from './use-block-sync'; import { store as blockEditorStore } from '../../store'; +import { BlockRefsProvider } from './block-refs-provider'; /** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */ @@ -24,7 +25,7 @@ function BlockEditorProvider( props ) { // Syncs the entity provider with changes in the block-editor store. useBlockSync( props ); - return children; + return { children }; } export default withRegistryProvider( BlockEditorProvider ); diff --git a/packages/block-editor/src/hooks/color.js b/packages/block-editor/src/hooks/color.js index 554781d057b5fd..2da9875c07584f 100644 --- a/packages/block-editor/src/hooks/color.js +++ b/packages/block-editor/src/hooks/color.js @@ -234,7 +234,7 @@ export function ColorEdit( props ) { localAttributes.current = attributes; }, [ attributes ] ); - if ( ! hasColorSupport( blockName ) || Platform.OS !== 'web' ) { + if ( ! hasColorSupport( blockName ) ) { return null; } diff --git a/packages/block-library/src/paragraph/edit.native.js b/packages/block-library/src/paragraph/edit.native.js index a51a708a222767..1cd75758543006 100644 --- a/packages/block-library/src/paragraph/edit.native.js +++ b/packages/block-library/src/paragraph/edit.native.js @@ -30,6 +30,11 @@ function ParagraphBlock( { const { align, content, placeholder } = attributes; const styles = { + ...( mergedStyle?.baseColors && { + color: mergedStyle.baseColors?.color?.text, + placeholderColor: mergedStyle.baseColors?.color?.text, + linkColor: mergedStyle.baseColors?.elements?.link?.color?.text, + } ), ...mergedStyle, ...style, }; diff --git a/packages/components/src/mobile/global-styles-context/index.native.js b/packages/components/src/mobile/global-styles-context/index.native.js index 81a60ccc8eb56e..1d4d0d45be6761 100644 --- a/packages/components/src/mobile/global-styles-context/index.native.js +++ b/packages/components/src/mobile/global-styles-context/index.native.js @@ -22,16 +22,21 @@ const GlobalStylesContext = createContext( { style: {} } ); GlobalStylesContext.BLOCK_STYLE_ATTRIBUTES = BLOCK_STYLE_ATTRIBUTES; export const getMergedGlobalStyles = ( + baseGlobalStyles, globalStyle, wrapperPropsStyle, blockAttributes, defaultColors ) => { + const baseGlobalColors = { + baseColors: baseGlobalStyles || {}, + }; const blockStyleAttributes = pick( blockAttributes, BLOCK_STYLE_ATTRIBUTES ); const mergedStyle = { + ...baseGlobalColors, ...globalStyle, ...wrapperPropsStyle, }; diff --git a/packages/edit-post/src/components/layout/index.native.js b/packages/edit-post/src/components/layout/index.native.js index f0abe54cfc9e97..d98bae6739ef59 100644 --- a/packages/edit-post/src/components/layout/index.native.js +++ b/packages/edit-post/src/components/layout/index.native.js @@ -9,7 +9,11 @@ import SafeArea from 'react-native-safe-area'; */ import { Component } from '@wordpress/element'; import { withSelect } from '@wordpress/data'; -import { BottomSheetSettings, FloatingToolbar } from '@wordpress/block-editor'; +import { + BottomSheetSettings, + FloatingToolbar, + store as blockEditorStore, +} from '@wordpress/block-editor'; import { compose, withPreferredColorScheme } from '@wordpress/compose'; import { HTMLTextInput, @@ -101,7 +105,7 @@ class Layout extends Component { } render() { - const { getStylesFromColorScheme, mode } = this.props; + const { getStylesFromColorScheme, mode, globalStyles } = this.props; const isHtmlView = mode === 'text'; @@ -118,6 +122,16 @@ class Layout extends Component { bottom: this.state.safeAreaInsets.bottom, }; + const editorStyles = [ + getStylesFromColorScheme( + styles.background, + styles.backgroundDark + ), + globalStyles?.background && { + backgroundColor: globalStyles.background, + }, + ]; + return ( - + { isHtmlView ? this.renderHTML() : this.renderVisual() } { ! isHtmlView && Platform.OS === 'android' && ( @@ -176,9 +185,14 @@ export default compose( [ editorStore ); const { getEditorMode } = select( editPostStore ); + const { getSettings } = select( blockEditorStore ); + const globalStyles = getSettings()?.__experimentalGlobalStylesBaseStyles + ?.color; + return { isReady: isEditorReady(), mode: getEditorMode(), + globalStyles, }; } ), withPreferredColorScheme, diff --git a/packages/editor/src/components/post-title/index.native.js b/packages/editor/src/components/post-title/index.native.js index 0587f26227ec83..4e117f73fb315b 100644 --- a/packages/editor/src/components/post-title/index.native.js +++ b/packages/editor/src/components/post-title/index.native.js @@ -19,6 +19,8 @@ import { withFocusOutside } from '@wordpress/components'; import { withInstanceId, compose } from '@wordpress/compose'; import { __, sprintf } from '@wordpress/i18n'; import { pasteHandler } from '@wordpress/blocks'; +import { store as blockEditorStore } from '@wordpress/block-editor'; +import { store as editorStore } from '@wordpress/editor'; /** * Internal dependencies @@ -107,12 +109,20 @@ class PostTitle extends Component { borderStyle, isDimmed, postType, + globalStyles, } = this.props; const decodedPlaceholder = decodeEntities( placeholder ); const borderColor = this.props.isSelected ? focusedBorderColor : 'transparent'; + const titleStyles = { + ...style, + ...( globalStyles?.text && { + color: globalStyles.text, + placeholderColor: globalStyles.text, + } ), + }; return ( { const { isPostTitleSelected, getEditedPostAttribute } = select( - 'core/editor' - ); - - const { getSelectedBlockClientId, getBlockRootClientId } = select( - 'core/block-editor' + editorStore ); + const { + getSelectedBlockClientId, + getBlockRootClientId, + getSettings, + } = select( blockEditorStore ); const selectedId = getSelectedBlockClientId(); const selectionIsNested = !! getBlockRootClientId( selectedId ); + const globalStyles = getSettings()?.__experimentalGlobalStylesBaseStyles + ?.color; return { postType: getEditedPostAttribute( 'type' ), isAnyBlockSelected: !! selectedId, isSelected: isPostTitleSelected(), isDimmed: selectionIsNested, + globalStyles, }; } ), withDispatch( ( dispatch ) => { const { undo, redo, togglePostTitleSelection } = dispatch( - 'core/editor' + editorStore ); const { clearSelectedBlock, insertDefaultBlock } = dispatch( - 'core/block-editor' + blockEditorStore ); return { diff --git a/packages/rich-text/src/component/index.native.js b/packages/rich-text/src/component/index.native.js index 195de53e802fed..8f5afcc4857168 100644 --- a/packages/rich-text/src/component/index.native.js +++ b/packages/rich-text/src/component/index.native.js @@ -3,21 +3,18 @@ /** * External dependencies */ +import { View, Platform } from 'react-native'; +import { get, pickBy, debounce, isString } from 'lodash'; +import memize from 'memize'; + /** * WordPress dependencies */ import RCTAztecView from '@wordpress/react-native-aztec'; -import { View, Platform } from 'react-native'; import { showUserSuggestions, showXpostSuggestions, } from '@wordpress/react-native-bridge'; -import { get, pickBy, debounce, isString } from 'lodash'; -import memize from 'memize'; - -/** - * WordPress dependencies - */ import { BlockFormatControls } from '@wordpress/block-editor'; import { Component } from '@wordpress/element'; import { compose, withPreferredColorScheme } from '@wordpress/compose'; @@ -982,10 +979,12 @@ export class RichText extends Component { text: html, eventCount: this.lastEventCount, selection, - linkTextColor: defaultTextDecorationColor, + linkTextColor: + style?.linkColor || defaultTextDecorationColor, } } placeholder={ this.props.placeholder } placeholderTextColor={ + style?.placeholderColor || this.props.placeholderTextColor || defaultPlaceholderTextColor } From 853acac3ecfdbf01fd90f6eec763fc696633fe9e Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Fri, 18 Jun 2021 17:24:43 +0200 Subject: [PATCH 30/33] Remove old usage of useEditorFeature --- .../components/src/color-palette/index.native.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/components/src/color-palette/index.native.js b/packages/components/src/color-palette/index.native.js index 9317faaf04e643..decfddf44b0ad7 100644 --- a/packages/components/src/color-palette/index.native.js +++ b/packages/components/src/color-palette/index.native.js @@ -19,7 +19,6 @@ import { map, uniq } from 'lodash'; import { __ } from '@wordpress/i18n'; import { useRef, useEffect } from '@wordpress/element'; import { usePreferredColorSchemeStyle } from '@wordpress/compose'; -import { __experimentalUseEditorFeature as useEditorFeature } from '@wordpress/block-editor'; /** * Internal dependencies @@ -62,17 +61,9 @@ function ColorPalette( { const scale = useRef( new Animated.Value( 1 ) ).current; const opacity = useRef( new Animated.Value( 1 ) ).current; - const defaultColors = uniq( - map( - useEditorFeature( 'color.palette' ) || defaultSettings.colors, - 'color' - ) - ); + const defaultColors = uniq( map( defaultSettings.colors, 'color' ) ); const defaultGradientColors = uniq( - map( - useEditorFeature( 'color.gradients' ) || defaultSettings.gradients, - 'gradient' - ) + map( defaultSettings.gradients, 'gradient' ) ); const colors = isGradientSegment ? defaultGradientColors : defaultColors; From 0548227818b28b9d3083d986900728c1e27993a9 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Fri, 18 Jun 2021 17:28:35 +0200 Subject: [PATCH 31/33] Remove old mock data --- .../components/provider/theme_data.native.js | 128 ------------------ 1 file changed, 128 deletions(-) delete mode 100644 packages/editor/src/components/provider/theme_data.native.js diff --git a/packages/editor/src/components/provider/theme_data.native.js b/packages/editor/src/components/provider/theme_data.native.js deleted file mode 100644 index b66e83ec9568c4..00000000000000 --- a/packages/editor/src/components/provider/theme_data.native.js +++ /dev/null @@ -1,128 +0,0 @@ -export default { - isFSETheme: true, - __experimentalGlobalStylesBaseStyles: { - settings: { - color: { - palette: [ - { - slug: 'black', - color: '#000000', - name: 'Black', - }, - { - slug: 'dark-gray', - color: '#28303D', - name: 'Dark Gray', - }, - { - slug: 'gray', - color: '#39414D', - name: 'Gray', - }, - { - slug: 'green', - color: '#D1E4DD', - name: 'Green', - }, - { - slug: 'blue', - color: '#D1DFE4', - name: 'Blue', - }, - { - slug: 'purple', - color: '#D1D1E4', - name: 'Purple', - }, - { - slug: 'red', - color: '#E4D1D1', - name: 'Red', - }, - { - slug: 'orange', - color: '#E4DAD1', - name: 'Orange', - }, - { - slug: 'yellow', - color: '#EEEADD', - name: 'Yellow', - }, - { - slug: 'white', - color: '#FFFFFF', - name: 'White', - }, - ], - gradients: [ - { - slug: 'purple-to-yellow', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--purple), var(--wp--preset--color--yellow))', - name: 'Purple to Yellow', - }, - { - slug: 'yellow-to-purple', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--yellow), var(--wp--preset--color--purple))', - name: 'Yellow to Purple', - }, - { - slug: 'green-to-yellow', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--green), var(--wp--preset--color--yellow))', - name: 'Green to Yellow', - }, - { - slug: 'yellow-to-green', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--yellow), var(--wp--preset--color--green))', - name: 'Yellow to Green', - }, - { - slug: 'red-to-yellow', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--red), var(--wp--preset--color--yellow))', - name: 'Red to Yellow', - }, - { - slug: 'yellow-to-red', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--yellow), var(--wp--preset--color--red))', - name: 'Yellow to Red', - }, - { - slug: 'purple-to-red', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--purple), var(--wp--preset--color--red))', - name: 'Purple to Red', - }, - { - slug: 'red-to-purple', - gradient: - 'linear-gradient(160deg, var(--wp--preset--color--red), var(--wp--preset--color--purple))', - name: 'Red to Purple', - }, - ], - custom: true, - link: true, - customGradient: true, - }, - }, - styles: { - color: { - background: 'var(--wp--preset--color--green)', - text: 'var(--wp--preset--color--dark-gray)', - }, - elements: { - link: { - color: { - text: 'var(--wp--preset--color--dark-gray)', - }, - }, - }, - }, - blocks: {}, - }, -}; From 0b9b34b9ee7a0cba33561474f292a029d6ec5c48 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 22 Jun 2021 16:48:27 +0200 Subject: [PATCH 32/33] Add support for block styles of the Verse block in mobile --- packages/block-library/src/verse/edit.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/block-library/src/verse/edit.js b/packages/block-library/src/verse/edit.js index f6fac870d89114..0f0f0b54078233 100644 --- a/packages/block-library/src/verse/edit.js +++ b/packages/block-library/src/verse/edit.js @@ -19,12 +19,14 @@ export default function VerseEdit( { setAttributes, mergeBlocks, onRemove, + mergedStyle, } ) { const { textAlign, content } = attributes; const blockProps = useBlockProps( { className: classnames( { [ `has-text-align-${ textAlign }` ]: textAlign, } ), + style: mergedStyle, } ); return ( From ed6e9d2021b2ffa84bb34988ca7a816e3eae1107 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 6 Jul 2021 17:02:48 +0200 Subject: [PATCH 33/33] Rename mergedStyle to style --- .../src/components/block-list/block.native.js | 2 +- .../block-library/src/button/edit.native.js | 17 ++++++++--------- .../block-library/src/columns/edit.native.js | 4 ++-- packages/block-library/src/group/edit.native.js | 8 ++++---- packages/block-library/src/heading/edit.js | 4 ++-- packages/block-library/src/list/edit.js | 4 ++-- .../block-library/src/media-text/edit.native.js | 7 +++---- .../block-library/src/paragraph/edit.native.js | 11 ++++------- packages/block-library/src/quote/edit.js | 4 ++-- packages/block-library/src/verse/edit.js | 4 ++-- 10 files changed, 30 insertions(+), 35 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 5e04046aaf0147..3f700ec22a2920 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -86,7 +86,7 @@ function BlockForType( { // Block level styles wrapperProps={ wrapperProps } // inherited styles merged with block level styles - mergedStyle={ mergedStyle } + style={ mergedStyle } clientId={ clientId } parentWidth={ parentWidth } contentStyle={ contentStyle } diff --git a/packages/block-library/src/button/edit.native.js b/packages/block-library/src/button/edit.native.js index f2d488e2714599..923ed47282efb8 100644 --- a/packages/block-library/src/button/edit.native.js +++ b/packages/block-library/src/button/edit.native.js @@ -184,7 +184,7 @@ class ButtonEdit extends Component { } getBackgroundColor() { - const { attributes, colors, gradients, mergedStyle } = this.props; + const { attributes, colors, gradients, style } = this.props; const { backgroundColor, gradient } = attributes; // Return named gradient value if available. @@ -207,13 +207,13 @@ class ButtonEdit extends Component { colorObject?.color || colorProps.style?.backgroundColor || colorProps.style?.background || - mergedStyle?.backgroundColor || + style?.backgroundColor || styles.defaultButton.backgroundColor ); } getTextColor() { - const { attributes, colors, mergedStyle } = this.props; + const { attributes, colors, style } = this.props; const colorProps = getColorClassesAndStyles( attributes ); // Retrieve named color object to force inline styles for themes that @@ -226,7 +226,7 @@ class ButtonEdit extends Component { return ( colorObject?.color || colorProps.style?.color || - mergedStyle?.color || + style?.color || styles.defaultButton.color ); } @@ -377,12 +377,12 @@ class ButtonEdit extends Component { mergeBlocks, parentWidth, setAttributes, - mergedStyle, + style, } = this.props; const { placeholder, text, - style, + style: buttonStyle, url, align = 'center', width, @@ -394,7 +394,7 @@ class ButtonEdit extends Component { return null; } - const borderRadius = style?.border?.radius; + const borderRadius = buttonStyle?.border?.radius; const borderRadiusValue = Number.isInteger( borderRadius ) ? borderRadius @@ -466,8 +466,7 @@ class ButtonEdit extends Component { } } textAlign={ align } placeholderTextColor={ - mergedStyle?.color || - styles.placeholderTextColor.color + style?.color || styles.placeholderTextColor.color } identifier="text" tagName="p" diff --git a/packages/block-library/src/columns/edit.native.js b/packages/block-library/src/columns/edit.native.js index 00b7e38e42c97e..40afe71538fdef 100644 --- a/packages/block-library/src/columns/edit.native.js +++ b/packages/block-library/src/columns/edit.native.js @@ -442,7 +442,7 @@ const ColumnsEditContainerWrapper = withDispatch( )( memo( ColumnsEditContainer ) ); const ColumnsEdit = ( props ) => { - const { clientId, isSelected, mergedStyle } = props; + const { clientId, isSelected, style } = props; const { columnCount, isDefaultColumns, @@ -505,7 +505,7 @@ const ColumnsEdit = ( props ) => { }, [] ); return ( - + diff --git a/packages/block-library/src/heading/edit.js b/packages/block-library/src/heading/edit.js index 0f8d900b62c4cf..023184969babd6 100644 --- a/packages/block-library/src/heading/edit.js +++ b/packages/block-library/src/heading/edit.js @@ -25,7 +25,7 @@ function HeadingEdit( { setAttributes, mergeBlocks, onReplace, - mergedStyle, + style, clientId, } ) { const { textAlign, content, level, placeholder } = attributes; @@ -34,7 +34,7 @@ function HeadingEdit( { className: classnames( { [ `has-text-align-${ textAlign }` ]: textAlign, } ), - style: mergedStyle, + style, } ); return ( diff --git a/packages/block-library/src/list/edit.js b/packages/block-library/src/list/edit.js index 15ed51bbb6fe15..8d39252aee128b 100644 --- a/packages/block-library/src/list/edit.js +++ b/packages/block-library/src/list/edit.js @@ -41,7 +41,7 @@ export default function ListEdit( { setAttributes, mergeBlocks, onReplace, - mergedStyle, + style, } ) { const { ordered, values, type, reversed, start, placeholder } = attributes; const tagName = ordered ? 'ol' : 'ul'; @@ -134,7 +134,7 @@ export default function ListEdit( { ); const blockProps = useBlockProps( { - style: mergedStyle, + style, } ); return ( diff --git a/packages/block-library/src/media-text/edit.native.js b/packages/block-library/src/media-text/edit.native.js index 77411cd81f8892..895dc40e7d7be1 100644 --- a/packages/block-library/src/media-text/edit.native.js +++ b/packages/block-library/src/media-text/edit.native.js @@ -254,7 +254,7 @@ class MediaTextEdit extends Component { setAttributes, isSelected, isRTL, - mergedStyle, + style, blockWidth, } = this.props; const { @@ -285,7 +285,7 @@ class MediaTextEdit extends Component { ? styles.innerBlockStackMediaLeft : styles.innerBlockStackMediaRight ), }, - ( mergedStyle?.backgroundColor || backgroundColor.color ) && + ( style?.backgroundColor || backgroundColor.color ) && styles.innerBlockPaddings, ]; @@ -302,8 +302,7 @@ class MediaTextEdit extends Component { ? styles[ 'is-stacked-on-mobile.has-media-on-the-right' ] : {} ), ...( isSelected && styles[ 'is-selected' ] ), - backgroundColor: - mergedStyle?.backgroundColor || backgroundColor.color, + backgroundColor: style?.backgroundColor || backgroundColor.color, paddingBottom: 0, }; diff --git a/packages/block-library/src/paragraph/edit.native.js b/packages/block-library/src/paragraph/edit.native.js index f71cc4279a2ef4..5bb6c32f8fea9d 100644 --- a/packages/block-library/src/paragraph/edit.native.js +++ b/packages/block-library/src/paragraph/edit.native.js @@ -19,7 +19,6 @@ function ParagraphBlock( { mergeBlocks, onReplace, setAttributes, - mergedStyle, style, clientId, } ) { @@ -30,13 +29,11 @@ function ParagraphBlock( { const { align, content, placeholder } = attributes; const styles = { - ...( mergedStyle?.baseColors && { - color: mergedStyle.baseColors?.color?.text, - placeholderColor: - mergedStyle.color || mergedStyle.baseColors?.color?.text, - linkColor: mergedStyle.baseColors?.elements?.link?.color?.text, + ...( style?.baseColors && { + color: style.baseColors?.color?.text, + placeholderColor: style.color || style.baseColors?.color?.text, + linkColor: style.baseColors?.elements?.link?.color?.text, } ), - ...mergedStyle, ...style, }; diff --git a/packages/block-library/src/quote/edit.js b/packages/block-library/src/quote/edit.js index ff0a8ac76d1a9e..1852f92e7e13f6 100644 --- a/packages/block-library/src/quote/edit.js +++ b/packages/block-library/src/quote/edit.js @@ -27,14 +27,14 @@ export default function QuoteEdit( { onReplace, className, insertBlocksAfter, - mergedStyle, + style, } ) { const { align, value, citation } = attributes; const blockProps = useBlockProps( { className: classnames( className, { [ `has-text-align-${ align }` ]: align, } ), - style: mergedStyle, + style, } ); return ( diff --git a/packages/block-library/src/verse/edit.js b/packages/block-library/src/verse/edit.js index 0f0f0b54078233..1ca846fb848b53 100644 --- a/packages/block-library/src/verse/edit.js +++ b/packages/block-library/src/verse/edit.js @@ -19,14 +19,14 @@ export default function VerseEdit( { setAttributes, mergeBlocks, onRemove, - mergedStyle, + style, } ) { const { textAlign, content } = attributes; const blockProps = useBlockProps( { className: classnames( { [ `has-text-align-${ textAlign }` ]: textAlign, } ), - style: mergedStyle, + style, } ); return (