Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7102a51
Adds new Prop for Global Styles Settings
antonis Apr 6, 2021
906a9f6
Rename updateTheme to be more generic for update settings include GSS…
chipsnyder May 6, 2021
226780b
Fix wrong naming of subscribeUpdateEditorSettings
May 7, 2021
8ad3a37
Update Gutenberg demo
May 7, 2021
0132134
Updates new props to rawStyles and rawFeatures
antonis May 13, 2021
0f4fffc
Merge branch 'trunk' into rnmobile/3163-GSS
chipsnyder May 14, 2021
bf75be1
Update iOS Bridge for new values
chipsnyder May 14, 2021
aeaf65f
Mobile - Global styles: Pass settings and set color palette and gradi…
May 18, 2021
ee936cb
Merge branch 'trunk' into rnmobile/3163-GSS
May 21, 2021
4058908
Merge branch 'trunk' into rnmobile/3163-GSS
antonis May 26, 2021
32a2b3a
Removes Android rawFeatures prop
antonis May 27, 2021
9741f39
Mobile - Remove usage of rawFeatures
May 27, 2021
9a404b4
Remove rawFeatures
chipsnyder May 27, 2021
792ab77
Adds raw Styles in React Native Bridge
antonis May 28, 2021
954d337
Mobile - Pass rawStyles on initial props and fix colors and gradients
May 28, 2021
eae36b0
Merge branch 'rnmobile/3163-GSS' of github.com:WordPress/gutenberg in…
May 28, 2021
d2ba74f
Merge remote-tracking branch 'origin/trunk' into rnmobile/3163-GSS
chipsnyder Jun 16, 2021
2e12d2c
Add Raw Features back
chipsnyder Jun 16, 2021
1bbda52
Revert "Removes Android rawFeatures prop"
antonis Jun 17, 2021
1f34a27
Add rawFeatures in the mobile editor
Jun 17, 2021
3d780d3
Mobile - Global styles: Set theme's background and text color (#30810)
Jun 18, 2021
f8e2fa7
Merge branch 'trunk' into rnmobile/3163-GSS
Jun 22, 2021
a0e9a1d
Merge branch 'trunk' into rnmobile/3163-GSS
antonis Jun 23, 2021
aee06f1
Merge branch 'trunk' into rnmobile/3163-GSS
antonis Jun 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -300,6 +302,7 @@ export default compose( [
withSelect( ( select, { clientId, rootClientId } ) => {
const {
getBlockIndex,
getSettings,
isBlockSelected,
__unstableGetBlockWithoutInnerBlocks,
getSelectedBlockClientId,
Expand Down Expand Up @@ -347,6 +350,9 @@ export default compose( [
isDescendantOfParentSelected ||
isParentSelected ||
parentId === '';
const baseGlobalStyles = getSettings()
?.__experimentalGlobalStylesBaseStyles;

return {
icon,
name: name || 'core/missing',
Expand All @@ -360,6 +366,7 @@ export default compose( [
isParentSelected,
firstToSelectId,
isTouchable,
baseGlobalStyles,
wrapperProps: getWrapperProps(
attributes,
blockType.getEditWrapperProps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { InspectorControls } from '@wordpress/block-editor';
import { InspectorControls, useSetting } from '@wordpress/block-editor';
import {
BottomSheet,
ColorSettings,
Expand Down Expand Up @@ -29,6 +29,11 @@ function BottomSheetSettings( {
settings,
...props
} ) {
const colorSettings = {
colors: useSetting( 'color.palette' ) || settings.colors,
gradients: useSetting( 'color.gradients' ) || settings.gradients,
};

return (
<BottomSheet
isVisible={ editorSidebarOpened }
Expand All @@ -53,7 +58,7 @@ function BottomSheetSettings( {
<BottomSheet.NavigationScreen
name={ blockSettingsScreens.color }
>
<ColorSettings defaultSettings={ settings } />
<ColorSettings defaultSettings={ colorSettings } />
</BottomSheet.NavigationScreen>
<BottomSheet.NavigationScreen
name={ blockSettingsScreens.focalPoint }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -24,7 +25,7 @@ function BlockEditorProvider( props ) {
// Syncs the entity provider with changes in the block-editor store.
useBlockSync( props );

return children;
return <BlockRefsProvider>{ children }</BlockRefsProvider>;
}

export default withRegistryProvider( BlockEditorProvider );
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function ColorEdit( props ) {
localAttributes.current = attributes;
}, [ attributes ] );

if ( ! hasColorSupport( blockName ) || Platform.OS !== 'web' ) {
if ( ! hasColorSupport( blockName ) ) {
return null;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ export {
withGlobalStyles,
getMergedGlobalStyles,
} from './mobile/global-styles-context';
export { getGlobalStyles } from './mobile/global-styles-context/utils';
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,155 @@
/**
* Internal dependencies
*/
import { getBlockPaddings, getBlockColors } from '../utils';
import {
getBlockPaddings,
getBlockColors,
parseColorVariables,
getGlobalStyles,
} from '../utils';

const DEFAULT_COLORS = [
{ color: '#cd2653', name: 'Accent Color', slug: 'accent' },
{ color: '#000000', name: 'Primary', slug: 'primary' },
{ color: '#6d6d6d', name: 'Secondary', slug: 'secondary' },
];

const GLOBAL_STYLES_PALETTE = [
{
slug: 'green',
color: '#D1E4DD',
name: 'Green',
},
{
slug: 'blue',
color: '#D1DFE4',
name: 'Blue',
},
{
slug: 'purple',
color: '#D1D1E4',
name: 'Purple',
},
];

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: {
background: 'var(--wp--preset--color--green)',
text: 'var(--wp--preset--color--blue)',
},
elements: {
link: {
color: {
text: 'var(--wp--preset--color--purple)',
},
},
},
},
};

const PARSED_GLOBAL_STYLES = {
styles: {
color: {
background: '#D1E4DD',
text: '#D1DFE4',
},
elements: {
link: {
color: {
text: '#D1D1E4',
},
},
},
},
};

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;

Expand Down Expand Up @@ -84,3 +225,49 @@ 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 rawFeatures = JSON.stringify( RAW_FEATURES );
const globalStyles = getGlobalStyles(
JSON.stringify( DEFAULT_GLOBAL_STYLES ),
rawFeatures,
GLOBAL_STYLES_PALETTE,
GLOBAL_STYLES_GRADIENTS
);
const gradients = parseColorVariables(
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: parsedExperimentalFeatures?.color?.palette,
gradients: parsedExperimentalFeatures?.color?.gradients,
},
},
__experimentalGlobalStylesBaseStyles: PARSED_GLOBAL_STYLES,
} )
);
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,43 @@ 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, 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: parsedExperimentalFeatures?.color?.palette,
gradients: parsedExperimentalFeatures?.color?.gradients,
},
},
__experimentalGlobalStylesBaseStyles: globalStyles,
};
}
Loading