Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove preferred style variations legacy support #58930

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 0 additions & 14 deletions docs/reference-guides/block-api/block-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,6 @@ supports: {
}
```

## defaultStylePicker

- Type: `boolean`
- Default value: `true`

When the style picker is shown, the user can set a default style for a block type based on the block's currently active style. If you prefer not to make this option available, set this property to `false`.

```js
supports: {
// Remove the Default Style picker.
defaultStylePicker: false
}
```

## dimensions

_**Note:** Since WordPress 6.2._
Expand Down
7 changes: 2 additions & 5 deletions docs/reference-guides/data/data-core-edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,8 @@ _Returns_

### updatePreferredStyleVariations

Returns an action object used in signaling that a style should be auto-applied when a block is created.

_Parameters_
> **Deprecated**

- _blockName_ `string`: Name of the block.
- _blockStyle_ `?string`: Name of the style that should be auto applied. If undefined, the "auto apply" setting of the block is removed.
Returns an action object used in signaling that a style should be auto-applied when a block is created.

<!-- END TOKEN(Autogenerated actions|../../../packages/edit-post/src/store/actions.js) -->
11 changes: 0 additions & 11 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { __ } from '@wordpress/i18n';
import {
getBlockType,
getUnregisteredTypeHandlerName,
hasBlockSupport,
store as blocksStore,
} from '@wordpress/blocks';
import { PanelBody, __unstableMotion as motion } from '@wordpress/components';
Expand All @@ -21,7 +20,6 @@ import BlockVariationTransforms from '../block-variation-transforms';
import useBlockDisplayInformation from '../use-block-display-information';
import { store as blockEditorStore } from '../../store';
import BlockStyles from '../block-styles';
import DefaultStylePicker from '../default-style-picker';
import { default as InspectorControls } from '../inspector-controls';
import { default as InspectorControlsTabs } from '../inspector-controls-tabs';
import useInspectorControlsTabs from '../inspector-controls-tabs/use-inspector-controls-tabs';
Expand Down Expand Up @@ -275,15 +273,6 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
<div>
<PanelBody title={ __( 'Styles' ) }>
<BlockStyles clientId={ clientId } />
{ hasBlockSupport(
blockName,
'defaultStylePicker',
true
) && (
<DefaultStylePicker
blockName={ blockName }
/>
) }
</PanelBody>
</div>
) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.block-editor-block-styles + .default-style-picker__default-switcher {
margin-top: $grid-unit-20;
}

.block-editor-block-styles__preview-panel {
display: none;
// Same layer as the sidebar from which it's triggered.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/**
* WordPress dependencies
*/
import { hasBlockSupport } from '@wordpress/blocks';
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import BlockStyles from '../block-styles';
import DefaultStylePicker from '../default-style-picker';
import InspectorControls from '../inspector-controls';
import { getBorderPanelLabel } from '../../hooks/border';

Expand All @@ -22,11 +20,6 @@ const StylesTab = ( { blockName, clientId, hasBlockStyles } ) => {
<div>
<PanelBody title={ __( 'Styles' ) }>
<BlockStyles clientId={ clientId } />
{ hasBlockSupport(
blockName,
'defaultStylePicker',
true
) && <DefaultStylePicker blockName={ blockName } /> }
</PanelBody>
</div>
) }
Expand Down
40 changes: 2 additions & 38 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,36 +331,6 @@ export function toggleSelection( isSelectionEnabled = true ) {
};
}

function getBlocksWithDefaultStylesApplied( blocks, blockEditorSettings ) {
const preferredStyleVariations =
blockEditorSettings?.__experimentalPreferredStyleVariations?.value ??
{};
return blocks.map( ( block ) => {
const blockName = block.name;
if ( ! hasBlockSupport( blockName, 'defaultStylePicker', true ) ) {
return block;
}
if ( ! preferredStyleVariations[ blockName ] ) {
return block;
}
const className = block.attributes?.className;
if ( className?.includes( 'is-style-' ) ) {
return block;
}
const { attributes = {} } = block;
const blockStyle = preferredStyleVariations[ blockName ];
return {
...block,
attributes: {
...attributes,
className: `${
className || ''
} is-style-${ blockStyle }`.trim(),
},
};
} );
}

/* eslint-disable jsdoc/valid-types */
/**
* Action that replaces given blocks with one or more replacement blocks.
Expand All @@ -378,10 +348,7 @@ export const replaceBlocks =
( { select, dispatch, registry } ) => {
/* eslint-enable jsdoc/valid-types */
clientIds = castArray( clientIds );
blocks = getBlocksWithDefaultStylesApplied(
castArray( blocks ),
select.getSettings()
);
blocks = castArray( blocks );
const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
// Replace is valid if the new blocks can be inserted in the root block.
for ( let index = 0; index < blocks.length; index++ ) {
Expand Down Expand Up @@ -594,10 +561,7 @@ export const insertBlocks =
);
}

blocks = getBlocksWithDefaultStylesApplied(
castArray( blocks ),
select.getSettings()
);
blocks = castArray( blocks );
const allowedBlocks = [];
for ( const block of blocks ) {
const isValid = select.canInsertBlockType(
Expand Down
101 changes: 0 additions & 101 deletions packages/block-editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,107 +380,6 @@ describe( 'actions', () => {
} );

describe( 'insertBlocks', () => {
it( 'should apply default styles to blocks if blocks do not contain a style', () => {
const ribsBlock = {
clientId: 'ribs',
name: 'core/test-ribs',
};
const chickenBlock = {
clientId: 'chicken',
name: 'core/test-chicken',
};
const chickenRibsBlock = {
clientId: 'chicken-ribs',
name: 'core/test-chicken-ribs',
};
const blocks = [ ribsBlock, chickenBlock, chickenRibsBlock ];

const select = {
getSettings: () => ( {
__experimentalPreferredStyleVariations: {
value: {
'core/test-ribs': 'squared',
'core/test-chicken-ribs': 'colorful',
},
},
} ),
canInsertBlockType: () => true,
};
const dispatch = jest.fn();

insertBlocks(
blocks,
5,
'testrootid',
false
)( { select, dispatch } );

expect( dispatch ).toHaveBeenCalledWith( {
type: 'INSERT_BLOCKS',
blocks: [
{
...ribsBlock,
attributes: { className: 'is-style-squared' },
},
chickenBlock,
{
...chickenRibsBlock,
attributes: { className: 'is-style-colorful' },
},
],
index: 5,
rootClientId: 'testrootid',
time: expect.any( Number ),
updateSelection: false,
initialPosition: null,
} );
} );

it( 'should keep styles explicitly set even if different from the default', () => {
const ribsWithStyleBlock = {
clientId: 'ribs',
name: 'core/test-ribs',
attributes: {
className: 'is-style-colorful',
},
};
const blocks = [ ribsWithStyleBlock ];

const select = {
getSettings: () => ( {
__experimentalPreferredStyleVariations: {
value: {
'core/test-ribs': 'squared',
},
},
} ),
canInsertBlockType: () => true,
};
const dispatch = jest.fn();

insertBlocks(
blocks,
5,
'testrootid',
false
)( { select, dispatch } );

expect( dispatch ).toHaveBeenCalledWith( {
type: 'INSERT_BLOCKS',
blocks: [
{
...ribsWithStyleBlock,
attributes: { className: 'is-style-colorful' },
},
],
index: 5,
rootClientId: 'testrootid',
time: expect.any( Number ),
updateSelection: false,
initialPosition: null,
} );
} );

it( 'should filter the allowed blocks in INSERT_BLOCKS action', () => {
const ribsBlock = {
clientId: 'ribs',
Expand Down
19 changes: 3 additions & 16 deletions packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
useBlockProps,
useInnerBlocksProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';

Expand All @@ -36,16 +32,12 @@ function ButtonsEdit( { attributes, className } ) {
'has-custom-font-size': fontSize || style?.typography?.fontSize,
} ),
} );
const { preferredStyle, hasButtonVariations } = useSelect( ( select ) => {
const preferredStyleVariations =
select( blockEditorStore ).getSettings()
.__experimentalPreferredStyleVariations;
const { hasButtonVariations } = useSelect( ( select ) => {
const buttonVariations = select( blocksStore ).getBlockVariations(
'core/button',
'inserter'
);
return {
preferredStyle: preferredStyleVariations?.value?.[ 'core/button' ],
hasButtonVariations: buttonVariations.length > 0,
};
}, [] );
Expand All @@ -54,12 +46,7 @@ function ButtonsEdit( { attributes, className } ) {
defaultBlock: DEFAULT_BLOCK,
// This check should be handled by the `Inserter` internally to be consistent across all blocks that use it.
directInsert: ! hasButtonVariations,
template: [
[
'core/button',
{ className: preferredStyle && `is-style-${ preferredStyle }` },
],
],
template: [ [ 'core/button' ] ],
templateInsertUpdatesSelection: true,
orientation: layout?.orientation ?? 'horizontal',
} );
Expand Down
Loading
Loading