Skip to content

Commit

Permalink
Move to supports and rename it to experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Oct 14, 2020
1 parent 8a6a846 commit 8645666
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
42 changes: 26 additions & 16 deletions packages/block-editor/src/components/block-parent-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,33 @@ import BlockIcon from '../block-icon';
*/
export default function BlockParentSelector() {
const { selectBlock } = useDispatch( 'core/block-editor' );
const { parentBlockType, firstParentClientId } = useSelect( ( select ) => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientId,
} = select( 'core/block-editor' );
const selectedBlockClientId = getSelectedBlockClientId();
const parents = getBlockParents( selectedBlockClientId );
const _firstParentClientId = parents[ parents.length - 1 ];
const parentBlockName = getBlockName( _firstParentClientId );
return {
parentBlockType: getBlockType( parentBlockName ),
firstParentClientId: _firstParentClientId,
};
}, [] );
const { parentBlockType, firstParentClientId, shouldHide } = useSelect(
( select ) => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientId,
} = select( 'core/block-editor' );
const { hasBlockSupport } = select( 'core/blocks' );
const selectedBlockClientId = getSelectedBlockClientId();
const parents = getBlockParents( selectedBlockClientId );
const _firstParentClientId = parents[ parents.length - 1 ];
const parentBlockName = getBlockName( _firstParentClientId );
const _parentBlockType = getBlockType( parentBlockName );
return {
parentBlockType: _parentBlockType,
firstParentClientId: _firstParentClientId,
shouldHide: ! hasBlockSupport(
parentBlockType,
'__experimentalParentSelector',
true
),
};
},
[]
);

if ( parentBlockType.hideParentSelector ) {
if ( shouldHide ) {
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/edit-widgets/src/blocks/widget-area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const settings = {
title: __( 'Widget Area' ),
description: __( 'A widget area container.' ),
__experimentalLabel: ( { name: label } ) => label,
hideParentSelector: true,
supports: {
// Should show the parent selector for its children or not. Defaults to true.
__experimentalParentSelector: false,
},
edit,
};

0 comments on commit 8645666

Please sign in to comment.