@@ -6,19 +6,15 @@ import classnames from 'classnames';
66/**
77 * WordPress dependencies
88 */
9- import { useRef } from '@wordpress/element' ;
10- import { AsyncModeProvider , useSelect , useDispatch } from '@wordpress/data' ;
9+ import { AsyncModeProvider , useSelect } from '@wordpress/data' ;
1110
1211/**
1312 * Internal dependencies
1413 */
1514import BlockListBlock from './block' ;
1615import BlockListAppender from '../block-list-appender' ;
1716import __experimentalBlockListFooter from '../block-list-footer' ;
18- import useMultiSelection from './use-multi-selection' ;
19- import { getBlockClientId } from '../../utils/dom' ;
20-
21- /** @typedef {import('@wordpress/element').WPSyntheticEvent } WPSyntheticEvent */
17+ import RootContainer from './root-container' ;
2218
2319/**
2420 * If the block count exceeds the threshold, we disable the reordering animation
@@ -74,64 +70,21 @@ function BlockList( {
7470 hasMultiSelection,
7571 enableAnimation,
7672 } = useSelect ( selector , [ rootClientId ] ) ;
77- const { selectBlock } = useDispatch ( 'core/block-editor' ) ;
78- const ref = useRef ( ) ;
79- const onSelectionStart = useMultiSelection ( { ref, rootClientId } ) ;
8073
8174 const uiParts = {
8275 hasMovers : true ,
8376 hasSelectedUI : true ,
8477 ...__experimentalUIParts ,
8578 } ;
8679
87- let onFocus ;
88- let onDragStart ;
89-
90- if ( ! rootClientId ) {
91- /**
92- * Marks the block as selected when focused and not already selected. This
93- * specifically handles the case where block does not set focus on its own
94- * (via `setFocus`), typically if there is no focusable input in the block.
95- *
96- * @param {WPSyntheticEvent } event
97- */
98- onFocus = ( event ) => {
99- if ( hasMultiSelection ) {
100- return ;
101- }
102-
103- const clientId = getBlockClientId ( event . target ) ;
104-
105- if ( clientId && clientId !== selectedBlockClientId ) {
106- selectBlock ( clientId ) ;
107- }
108- } ;
109-
110- /**
111- * Prevents default dragging behavior within a block.
112- * To do: we must handle this in the future and clean up the drag target.
113- * Previously dragging was prevented for multi-selected, but this is no longer
114- * needed.
115- *
116- * @param {WPSyntheticEvent } event Synthetic drag event.
117- */
118- onDragStart = ( event ) => {
119- // Ensure we target block content, not block controls.
120- if ( getBlockClientId ( event . target ) ) {
121- event . preventDefault ( ) ;
122- }
123- } ;
124- }
80+ const Container = rootClientId ? 'div' : RootContainer ;
12581
12682 return (
127- < div
128- ref = { ref }
83+ < Container
12984 className = { classnames (
13085 'block-editor-block-list__layout' ,
13186 className
13287 ) }
133- onFocus = { onFocus }
134- onDragStart = { onDragStart }
13588 >
13689 { blockClientIds . map ( ( clientId , index ) => {
13790 const isBlockInSelection = hasMultiSelection ?
@@ -143,7 +96,6 @@ function BlockList( {
14396 < BlockListBlock
14497 rootClientId = { rootClientId }
14598 clientId = { clientId }
146- onSelectionStart = { onSelectionStart }
14799 isDraggable = { isDraggable }
148100 moverDirection = { moverDirection }
149101 isMultiSelecting = { isMultiSelecting }
@@ -163,7 +115,7 @@ function BlockList( {
163115 renderAppender = { renderAppender }
164116 />
165117 < __experimentalBlockListFooter . Slot />
166- </ div >
118+ </ Container >
167119 ) ;
168120}
169121
0 commit comments