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

List View: Experiment with drag in place #34022

Closed
wants to merge 8 commits into from
Closed
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
20 changes: 11 additions & 9 deletions packages/block-editor/src/components/list-view/appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __experimentalTreeGridCell as TreeGridCell } from '@wordpress/components';
import {
__experimentalTreeGridCell as TreeGridCell,
__experimentalTreeGridRow as TreeGridRow,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import ListViewLeaf from './leaf';
import Inserter from '../inserter';
import { store as blockEditorStore } from '../../store';

Expand All @@ -23,7 +25,6 @@ export default function ListViewAppender( {
position,
level,
rowCount,
path,
} ) {
const isDragging = useSelect(
( select ) => {
Expand All @@ -49,12 +50,13 @@ export default function ListViewAppender( {
);

return (
<ListViewLeaf
className={ classnames( { 'is-dragging': isDragging } ) }
<TreeGridRow
className={ classnames( 'block-editor-list-view-leaf', {
'is-dragging': isDragging,
} ) }
level={ level }
position={ position }
rowCount={ rowCount }
path={ path }
positionInSet={ position }
setSize={ rowCount }
>
<TreeGridCell
className="block-editor-list-view-appender__cell"
Expand All @@ -77,6 +79,6 @@ export default function ListViewAppender( {
</div>
) }
</TreeGridCell>
</ListViewLeaf>
</TreeGridRow>
);
}
95 changes: 25 additions & 70 deletions packages/block-editor/src/components/list-view/block-contents.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { forwardRef } from '@wordpress/element';

/**
Expand All @@ -15,8 +9,6 @@ import { forwardRef } from '@wordpress/element';
import { useListViewContext } from './context';
import ListViewBlockSlot from './block-slot';
import ListViewBlockSelectButton from './block-select-button';
import BlockDraggable from '../block-draggable';
import { store as blockEditorStore } from '../../store';

const ListViewBlockContents = forwardRef(
(
Expand All @@ -34,68 +26,31 @@ const ListViewBlockContents = forwardRef(
) => {
const { __experimentalFeatures } = useListViewContext();

const { clientId } = block;

const { blockMovingClientId, selectedBlockInBlockEditor } = useSelect(
( select ) => {
const {
getBlockRootClientId,
hasBlockMovingClientId,
getSelectedBlockClientId,
} = select( blockEditorStore );
return {
rootClientId: getBlockRootClientId( clientId ) || '',
blockMovingClientId: hasBlockMovingClientId(),
selectedBlockInBlockEditor: getSelectedBlockClientId(),
};
},
[ clientId ]
);

const isBlockMoveTarget =
blockMovingClientId && selectedBlockInBlockEditor === clientId;

const className = classnames( 'block-editor-list-view-block-contents', {
'is-dropping-before': isBlockMoveTarget,
} );

return (
<BlockDraggable clientIds={ [ block.clientId ] }>
{ ( { draggable, onDragStart, onDragEnd } ) =>
__experimentalFeatures ? (
<ListViewBlockSlot
ref={ ref }
className={ className }
block={ block }
onToggleExpanded={ onToggleExpanded }
isSelected={ isSelected }
position={ position }
siblingBlockCount={ siblingBlockCount }
level={ level }
draggable={ draggable && __experimentalFeatures }
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
{ ...props }
/>
) : (
<ListViewBlockSelectButton
ref={ ref }
className={ className }
block={ block }
onClick={ onClick }
onToggleExpanded={ onToggleExpanded }
isSelected={ isSelected }
position={ position }
siblingBlockCount={ siblingBlockCount }
level={ level }
draggable={ draggable }
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
{ ...props }
/>
)
}
</BlockDraggable>
return __experimentalFeatures ? (
<ListViewBlockSlot
ref={ ref }
className="block-editor-list-view-block-contents"
block={ block }
onToggleExpanded={ onToggleExpanded }
isSelected={ isSelected }
position={ position }
siblingBlockCount={ siblingBlockCount }
level={ level }
{ ...props }
/>
) : (
<ListViewBlockSelectButton
ref={ ref }
className="block-editor-list-view-block-contents"
block={ block }
onClick={ onClick }
onToggleExpanded={ onToggleExpanded }
isSelected={ isSelected }
position={ position }
siblingBlockCount={ siblingBlockCount }
level={ level }
{ ...props }
/>
);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ function ListViewBlockSelectButton(
level,
tabIndex,
onFocus,
onDragStart,
onDragEnd,
draggable,
},
ref
) {
Expand All @@ -59,13 +56,12 @@ function ListViewBlockSelectButton(
ref={ ref }
tabIndex={ tabIndex }
onFocus={ onFocus }
onDragStart={ onDragStart }
onDragEnd={ onDragEnd }
draggable={ draggable }
>
<ListViewExpander onClick={ onToggleExpanded } />
<BlockIcon icon={ blockInformation?.icon } showColors />
<BlockTitle clientId={ clientId } />
<span className="block-editor-list-view-block-select-button__title">
<BlockTitle clientId={ clientId } />
</span>
{ blockInformation?.anchor && (
<span className="block-editor-list-view-block-select-button__anchor">
{ blockInformation.anchor }
Expand Down
Loading