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

Disable block supports derived design tools when Blocking Editing Mode is not default #50912

Merged
merged 1 commit into from
Jun 2, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
</div>
) }
<InspectorControls.Slot />
<InspectorControls.Slot group="list" />
<InspectorControls.Slot
group="color"
label={ __( 'Color' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default function InspectorControlsTabs( {
const initialTabName = ! useIsListViewTabDisabled( blockName )
? TAB_LIST_VIEW.name
: undefined;

return (
<TabPanel
className="block-editor-block-inspector__tabs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,5 @@ export default function useInspectorControlsTabs( blockName ) {
}, [] );

const showTabs = getShowTabs( blockName, tabSettings );

return showTabs ? tabs : EMPTY_ARRAY;
}
4 changes: 3 additions & 1 deletion packages/block-editor/src/hooks/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Platform } from '@wordpress/element';
* Internal dependencies
*/
import { InspectorControls } from '../components';
import { useBlockEditingMode } from '../components/block-editing-mode';

/**
* Regular expression matching invalid anchor characters for replacement.
Expand Down Expand Up @@ -63,6 +64,7 @@ export const withInspectorControl = createHigherOrderComponent(
( BlockEdit ) => {
return ( props ) => {
const hasAnchor = hasBlockSupport( props.name, 'anchor' );
const blockEditingMode = useBlockEditingMode();

if ( hasAnchor && props.isSelected ) {
const isWeb = Platform.OS === 'web';
Expand Down Expand Up @@ -104,7 +106,7 @@ export const withInspectorControl = createHigherOrderComponent(
return (
<>
<BlockEdit { ...props } />
{ isWeb && (
{ isWeb && blockEditingMode === 'default' && (
<InspectorControls group="advanced">
{ textControl }
</InspectorControls>
Expand Down
42 changes: 23 additions & 19 deletions packages/block-editor/src/hooks/custom-class-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { createHigherOrderComponent } from '@wordpress/compose';
* Internal dependencies
*/
import { InspectorControls } from '../components';
import { useBlockEditingMode } from '../components/block-editing-mode';

/**
* Filters registered block settings, extending attributes to include `className`.
Expand Down Expand Up @@ -50,6 +51,7 @@ export function addAttribute( settings ) {
export const withInspectorControl = createHigherOrderComponent(
( BlockEdit ) => {
return ( props ) => {
const blockEditingMode = useBlockEditingMode();
const hasCustomClassName = hasBlockSupport(
props.name,
'customClassName',
Expand All @@ -59,25 +61,27 @@ export const withInspectorControl = createHigherOrderComponent(
return (
<>
<BlockEdit { ...props } />
<InspectorControls group="advanced">
<TextControl
__nextHasNoMarginBottom
autoComplete="off"
label={ __( 'Additional CSS class(es)' ) }
value={ props.attributes.className || '' }
onChange={ ( nextValue ) => {
props.setAttributes( {
className:
nextValue !== ''
? nextValue
: undefined,
} );
} }
help={ __(
'Separate multiple classes with spaces.'
) }
/>
</InspectorControls>
{ blockEditingMode === 'default' && (
<InspectorControls group="advanced">
<TextControl
__nextHasNoMarginBottom
autoComplete="off"
label={ __( 'Additional CSS class(es)' ) }
value={ props.attributes.className || '' }
onChange={ ( nextValue ) => {
props.setAttributes( {
className:
nextValue !== ''
? nextValue
: undefined,
} );
} }
help={ __(
'Separate multiple classes with spaces.'
) }
/>
</InspectorControls>
) }
</>
);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,11 @@ export const withInspectorControls = createHigherOrderComponent(
layoutBlockSupportKey
);

const blockEditingMode = useBlockEditingMode();
return [
supportLayout && <LayoutPanel key="layout" { ...props } />,
supportLayout && blockEditingMode === 'default' && (
<LayoutPanel key="layout" { ...props } />
),
<BlockEdit key="edit" { ...props } />,
];
},
Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from './dimensions';
import useDisplayBlockControls from '../components/use-display-block-controls';
import { shouldSkipSerialization } from './utils';
import { useBlockEditingMode } from '../components/block-editing-mode';

const styleSupportKeys = [
...TYPOGRAPHY_SUPPORT_KEYS,
Expand Down Expand Up @@ -347,10 +348,11 @@ export function addEditProps( settings ) {
export const withBlockControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const shouldDisplayControls = useDisplayBlockControls();
const blockEditingMode = useBlockEditingMode();

return (
<>
{ shouldDisplayControls && (
{ shouldDisplayControls && blockEditingMode === 'default' && (
<>
<ColorEdit { ...props } />
<TypographyPanel { ...props } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import { store as noticesStore } from '@wordpress/notices';
import { useSupportedStyles } from '../../components/global-styles/hooks';
import { unlock } from '../../private-apis';

const { GlobalStylesContext } = unlock( blockEditorPrivateApis );
const { GlobalStylesContext, useBlockEditingMode } = unlock(
blockEditorPrivateApis
);

// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be
// removed by moving PushChangesToGlobalStylesControl to
Expand Down Expand Up @@ -208,15 +210,19 @@ function PushChangesToGlobalStylesControl( {
}

const withPushChangesToGlobalStyles = createHigherOrderComponent(
( BlockEdit ) => ( props ) =>
(
( BlockEdit ) => ( props ) => {
const blockEditingMode = useBlockEditingMode();
return (
<>
<BlockEdit { ...props } />
<InspectorAdvancedControls>
<PushChangesToGlobalStylesControl { ...props } />
</InspectorAdvancedControls>
{ blockEditingMode === 'default' && (
<InspectorAdvancedControls>
<PushChangesToGlobalStylesControl { ...props } />
</InspectorAdvancedControls>
) }
</>
)
);
}
);

addFilter(
Expand Down