Skip to content

Commit

Permalink
Removing changes that would affect post-editor, and isolating to site…
Browse files Browse the repository at this point in the history
… editor

Removing blockglobalstyle context and provider since we'll use global style provider.
Starting to reset user config when resetting block-level styles.
Deliberately not rebuilding docs here :)
  • Loading branch information
ramonjd committed Dec 7, 2022
1 parent f9c93b3 commit cf94d86
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 307 deletions.
1 change: 0 additions & 1 deletion packages/block-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@wordpress/blocks": "file:../blocks",
"@wordpress/components": "file:../components",
"@wordpress/compose": "file:../compose",
"@wordpress/core-data": "file:../core-data",
"@wordpress/data": "file:../data",
"@wordpress/date": "file:../date",
"@wordpress/deprecated": "file:../deprecated",
Expand Down

This file was deleted.

158 changes: 0 additions & 158 deletions packages/block-editor/src/components/block-global-styles/provider.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,3 @@ export { default as useDisplayBlockControls } from './use-display-block-controls

export { default as BlockEditorProvider } from './provider';
export { default as useSetting } from './use-setting';
export { default as BlockGlobalStylesProvider } from './block-global-styles/provider';
export { default as BlockGlobalStylesContext } from './block-global-styles/context';
16 changes: 12 additions & 4 deletions packages/block-editor/src/hooks/border-radius.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function BorderRadiusEdit( props ) {
const {
attributes: { style },
setAttributes,
setBlockGlobalStyles,
} = props;

const onChange = ( newRadius ) => {
Expand All @@ -28,6 +29,7 @@ export function BorderRadiusEdit( props ) {
} );

setAttributes( { style: newStyle } );
setBlockGlobalStyles( 'border.radius', newRadius );
};

return (
Expand Down Expand Up @@ -60,11 +62,17 @@ export function hasBorderRadiusValue( props ) {
* disabling the border radius support controls for a block via a progressive
* discovery panel.
*
* @param {Object} props Block props.
* @param {Object} props.attributes Block's attributes.
* @param {Object} props.setAttributes Function to set block's attributes.
* @param {Object} props Block props.
* @param {Object} props.attributes Block's attributes.
* @param {Function} props.setAttributes Function to set block's attributes.
* @param {Function} props.setBlockGlobalStyles Function to set block's global styles.
*/
export function resetBorderRadius( { attributes = {}, setAttributes } ) {
export function resetBorderRadius( {
attributes = {},
setAttributes,
setBlockGlobalStyles,
} ) {
const { style } = attributes;
setAttributes( { style: removeBorderAttribute( style, 'radius' ) } );
setBlockGlobalStyles( 'border.radius', undefined );
}
45 changes: 31 additions & 14 deletions packages/block-editor/src/hooks/border.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,41 @@ const hasBorderValue = ( props ) => {

// The border color, style, and width are omitted so they get undefined. The
// border radius is separate and must retain its selection.
const resetBorder = ( { attributes = {}, setAttributes } ) => {
const resetBorder = ( {
attributes = {},
setAttributes,
setBlockGlobalStyles,
} ) => {
const { style } = attributes;
const border = cleanEmptyObject( {
radius: style?.border?.radius,
} );
setAttributes( {
borderColor: undefined,
style: {
...style,
border: cleanEmptyObject( {
radius: style?.border?.radius,
} ),
border,
},
} );

setBlockGlobalStyles( 'border', border );
};

const resetBorderFilter = ( newAttributes ) => ( {
...newAttributes,
borderColor: undefined,
style: {
...newAttributes.style,
border: {
radius: newAttributes.style?.border?.radius,
const resetBorderFilter = ( newAttributes, { setBlockGlobalStyles } ) => {
setBlockGlobalStyles( 'border', {
radius: newAttributes.style?.border?.radius,
} );
return {
...newAttributes,
borderColor: undefined,
style: {
...newAttributes.style,
border: {
radius: newAttributes.style?.border?.radius,
},
},
},
} );
};
};

const getColorByProperty = ( colors, property, value ) => {
let matchedColor;
Expand Down Expand Up @@ -255,6 +267,9 @@ export function BorderPanel( props ) {
setBlockGlobalStyles( 'border', {
radius: style?.border?.radius,
...newBorderStyles,
color: newBorderColor
? `var:preset|color|${ newBorderColor }`
: newBorderStyles.color,
} );
};

Expand All @@ -268,7 +283,9 @@ export function BorderPanel( props ) {
label={ __( 'Border' ) }
onDeselect={ () => resetBorder( props ) }
isShownByDefault={ showBorderByDefault }
resetAllFilter={ resetBorderFilter }
resetAllFilter={ ( newAttributes ) =>
resetBorderFilter( newAttributes, props )
}
panelId={ clientId }
>
<BorderBoxControl
Expand Down
Loading

0 comments on commit cf94d86

Please sign in to comment.