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

Nav offcanvas disable direct insertion #46898

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Changes from 1 commit
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
Next Next commit
Add new shouldDirectInsert prop to enabling disabling of direct inser…
…tion
getdave committed Jan 5, 2023
commit 3b8f38b8cb03519cbbba1b6b98adabc5a702c9e1
87 changes: 46 additions & 41 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
@@ -220,48 +220,53 @@ class Inserter extends Component {
}

export default compose( [
withSelect( ( select, { clientId, rootClientId } ) => {
const {
getBlockRootClientId,
hasInserterItems,
__experimentalGetAllowedBlocks,
__experimentalGetDirectInsertBlock,
getSettings,
} = select( blockEditorStore );

const { getBlockVariations } = select( blocksStore );

rootClientId =
rootClientId || getBlockRootClientId( clientId ) || undefined;

const allowedBlocks = __experimentalGetAllowedBlocks( rootClientId );

const directInsertBlock =
__experimentalGetDirectInsertBlock( rootClientId );

const settings = getSettings();

const hasSingleBlockType =
allowedBlocks?.length === 1 &&
getBlockVariations( allowedBlocks[ 0 ].name, 'inserter' )
?.length === 0;

let allowedBlockType = false;
if ( hasSingleBlockType ) {
allowedBlockType = allowedBlocks[ 0 ];
withSelect(
( select, { clientId, rootClientId, shouldDirectInsert = true } ) => {
const {
getBlockRootClientId,
hasInserterItems,
__experimentalGetAllowedBlocks,
__experimentalGetDirectInsertBlock,
getSettings,
} = select( blockEditorStore );

const { getBlockVariations } = select( blocksStore );

rootClientId =
rootClientId || getBlockRootClientId( clientId ) || undefined;

const allowedBlocks =
__experimentalGetAllowedBlocks( rootClientId );

const directInsertBlock =
shouldDirectInsert &&
__experimentalGetDirectInsertBlock( rootClientId );

const settings = getSettings();

const hasSingleBlockType =
allowedBlocks?.length === 1 &&
getBlockVariations( allowedBlocks[ 0 ].name, 'inserter' )
?.length === 0;

let allowedBlockType = false;
if ( hasSingleBlockType ) {
allowedBlockType = allowedBlocks[ 0 ];
}

return {
hasItems: hasInserterItems( rootClientId ),
hasSingleBlockType,
blockTitle: allowedBlockType ? allowedBlockType.title : '',
allowedBlockType,
directInsertBlock,
rootClientId,
prioritizePatterns:
settings.__experimentalPreferPatternsOnRoot &&
! rootClientId,
};
}

return {
hasItems: hasInserterItems( rootClientId ),
hasSingleBlockType,
blockTitle: allowedBlockType ? allowedBlockType.title : '',
allowedBlockType,
directInsertBlock,
rootClientId,
prioritizePatterns:
settings.__experimentalPreferPatternsOnRoot && ! rootClientId,
};
} ),
),
withDispatch( ( dispatch, ownProps, { select } ) => {
return {
insertOnlyAllowedBlock() {