diff --git a/packages/block-editor/src/components/block-patterns/style.scss b/packages/block-editor/src/components/block-patterns/style.scss deleted file mode 100644 index 78869f7d043e4..0000000000000 --- a/packages/block-editor/src/components/block-patterns/style.scss +++ /dev/null @@ -1,40 +0,0 @@ -.block-editor-patterns { - background: $light-gray-200; - padding: $grid-unit-20; -} - -.block-editor-patterns__item { - background: $white; - border-radius: $radius-block-ui; - padding: $grid-unit-20; -} - -.block-editor-patterns__item { - border-radius: $radius-block-ui; - cursor: pointer; - margin-bottom: $grid-unit-20; - border: 1px solid $light-gray-500; - transition: all 0.05s ease-in-out; - position: relative; - - &:hover { - background: $white; - box-shadow: 0 0 0 1px $white, 0 0 0 3px $dark-gray-500; - } - - &:focus { - box-shadow: inset 0 0 0 1px $white, 0 0 0 $border-width-focus $theme-color; - - // Windows High Contrast mode will show this outline, but not the box-shadow. - outline: 2px solid transparent; - } -} - -.block-editor-patterns__item-preview { - padding: $grid-unit-20; -} - -.block-editor-patterns__item-title { - text-align: center; - padding: 10px 0; -} diff --git a/packages/block-editor/src/components/index.js b/packages/block-editor/src/components/index.js index 3e83be72f19a6..94fc975e108d7 100644 --- a/packages/block-editor/src/components/index.js +++ b/packages/block-editor/src/components/index.js @@ -15,7 +15,6 @@ export { default as BlockFormatControls } from './block-format-controls'; export { default as BlockIcon } from './block-icon'; export { default as BlockNavigationDropdown } from './block-navigation/dropdown'; export { default as __experimentalBlockNavigationList } from './block-navigation/list'; -export { default as __experimentalBlockPatterns } from './block-patterns'; export { default as __experimentalBlockVariationPicker } from './block-variation-picker'; export { default as BlockVerticalAlignmentToolbar } from './block-vertical-alignment-toolbar'; export { default as ButtonBlockerAppender } from './button-block-appender'; diff --git a/packages/block-editor/src/components/inserter/block-list.js b/packages/block-editor/src/components/inserter/block-list.js index c16ffe5c5ad38..ecfc946172d7a 100644 --- a/packages/block-editor/src/components/inserter/block-list.js +++ b/packages/block-editor/src/components/inserter/block-list.js @@ -3,7 +3,6 @@ */ import { map, - pick, includes, filter, findIndex, @@ -23,9 +22,9 @@ import { PanelBody, withSpokenMessages } from '@wordpress/components'; import { addQueryArgs } from '@wordpress/url'; import { controlsRepeat } from '@wordpress/icons'; import { speak } from '@wordpress/a11y'; -import { createBlock, isUnmodifiedDefaultBlock } from '@wordpress/blocks'; +import { createBlock } from '@wordpress/blocks'; import { useMemo, useEffect, useState, useRef } from '@wordpress/element'; -import { useSelect, useDispatch } from '@wordpress/data'; +import { useSelect } from '@wordpress/data'; import { compose, withSafeTimeout } from '@wordpress/compose'; /** @@ -54,10 +53,8 @@ const getBlockNamespace = ( item ) => item.name.split( '/' )[ 0 ]; const MAX_SUGGESTED_ITEMS = 9; function InserterBlockList( { - clientId, - isAppender, rootClientId, - onSelect, + onInsert, onHover, __experimentalSelectBlockOnInsert: selectBlockOnInsert, filterValue, @@ -69,61 +66,30 @@ function InserterBlockList( { collections, items, rootChildBlocks, - getSelectedBlock, - destinationRootClientId, - getBlockIndex, - getBlockSelectionEnd, - getBlockOrder, fetchReusableBlocks, } = useSelect( ( select ) => { - const { - getInserterItems, - getBlockName, - getBlockRootClientId, - getBlockSelectionEnd: _getBlockSelectionEnd, - getSettings, - } = select( 'core/block-editor' ); + const { getInserterItems, getBlockName, getSettings } = select( + 'core/block-editor' + ); const { getCategories, getCollections, getChildBlockNames, } = select( 'core/blocks' ); - - let destRootClientId = rootClientId; - if ( ! destRootClientId && ! clientId && ! isAppender ) { - const end = _getBlockSelectionEnd(); - if ( end ) { - destRootClientId = getBlockRootClientId( end ) || undefined; - } - } - const destinationRootBlockName = getBlockName( destRootClientId ); - + const rootBlockName = getBlockName( rootClientId ); const { __experimentalFetchReusableBlocks } = getSettings(); return { categories: getCategories(), collections: getCollections(), - rootChildBlocks: getChildBlockNames( destinationRootBlockName ), - items: getInserterItems( destRootClientId ), - destinationRootClientId: destRootClientId, + rootChildBlocks: getChildBlockNames( rootBlockName ), + items: getInserterItems( rootClientId ), fetchReusableBlocks: __experimentalFetchReusableBlocks, - ...pick( select( 'core/block-editor' ), [ - 'getSelectedBlock', - 'getBlockIndex', - 'getBlockSelectionEnd', - 'getBlockOrder', - ] ), }; }, - [ clientId, isAppender, rootClientId ] + [ rootClientId ] ); - const { - replaceBlocks, - insertBlock, - showInsertionPoint, - hideInsertionPoint, - } = useDispatch( 'core/block-editor' ); // Fetch resuable blocks on mount useEffect( () => { @@ -132,68 +98,21 @@ function InserterBlockList( { } }, [] ); - // To avoid duplication, getInsertionIndex is extracted and used in two event handlers - // This breaks the withDispatch not containing any logic rule. - // Since it's a function only called when the event handlers are called, - // it's fine to extract it. - // eslint-disable-next-line no-restricted-syntax - function getInsertionIndex() { - // If the clientId is defined, we insert at the position of the block. - if ( clientId ) { - return getBlockIndex( clientId, destinationRootClientId ); - } - - // If there a selected block, we insert after the selected block. - const end = getBlockSelectionEnd(); - if ( ! isAppender && end ) { - return getBlockIndex( end, destinationRootClientId ) + 1; - } - - // Otherwise, we insert at the end of the current rootClientId - return getBlockOrder( destinationRootClientId ).length; - } - - const onHoverItem = ( item ) => { - onHover( item ); - if ( item ) { - const index = getInsertionIndex(); - showInsertionPoint( destinationRootClientId, index ); - } else { - hideInsertionPoint(); - } - }; - const onSelectItem = ( item ) => { const { name, title, initialAttributes, innerBlocks } = item; - const selectedBlock = getSelectedBlock(); const insertedBlock = createBlock( name, initialAttributes, createBlocksFromInnerBlocksTemplate( innerBlocks ) ); - if ( - ! isAppender && - selectedBlock && - isUnmodifiedDefaultBlock( selectedBlock ) - ) { - replaceBlocks( selectedBlock.clientId, insertedBlock ); - } else { - insertBlock( - insertedBlock, - getInsertionIndex(), - destinationRootClientId, - selectBlockOnInsert - ); - if ( ! selectBlockOnInsert ) { - // translators: %s: the name of the block that has been added - const message = sprintf( __( '%s block added' ), title ); - speak( message ); - } - } + onInsert( insertedBlock ); - onSelect(); - return insertedBlock; + if ( ! selectBlockOnInsert ) { + // translators: %s: the name of the block that has been added + const message = sprintf( __( '%s block added' ), title ); + speak( message ); + } }; const filteredItems = useMemo( () => { @@ -327,7 +246,6 @@ function InserterBlockList( { return (
{ !! suggestedItems.length && ! filterValue && ( @@ -350,7 +268,7 @@ function InserterBlockList( {