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: Displace list view items when dragging (a bit more WYSIWYG) #56625

Merged
merged 32 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c1be69e
Include earlier experiment to make drag chip resemble the list view item
andrewserong Nov 29, 2023
30b3442
Try displacing list view items via transform: translateY while dragging
andrewserong Nov 29, 2023
671ed67
Try adding a bit of styling when nesting
andrewserong Nov 29, 2023
44c1962
Try to fix tests
andrewserong Nov 29, 2023
f6d14a4
Offset the top of the table to match the displacement
andrewserong Dec 1, 2023
775c3ab
Improve the experience when beginning to drag a block
andrewserong Dec 4, 2023
d79d944
Smoothly hide gap when dragging outside of the list view area
andrewserong Dec 4, 2023
cd228f9
Merge in changes from drag to collapsed block to expand PR
andrewserong Dec 5, 2023
5892875
Try collapsing selected blocks down to a single row space while dragging
andrewserong Dec 5, 2023
1f86527
Fix jumpiness in Safari
andrewserong Dec 7, 2023
2f723ef
Try making styling match the selected state
andrewserong Dec 7, 2023
5e6809b
Try smoothly dropping to the final position
andrewserong Dec 8, 2023
cf616ff
Fix transitions above dragged items
andrewserong Dec 12, 2023
d9eb4ca
Fix flickering issue in Safari
andrewserong Jan 5, 2024
c46879b
Try a transparent background color
andrewserong Jan 8, 2024
416303b
Fix drag behaviour in navigation block
andrewserong Jan 8, 2024
e887ba6
Add vertical drop indicator
andrewserong Jan 9, 2024
7e148bb
Try using existing drop indicator line
andrewserong Jan 10, 2024
9f45580
Add reduced motion, fix e2e test
andrewserong Jan 10, 2024
7bf8be5
Tidy up classname for drag chip in prep for subsequent changes
andrewserong Jan 11, 2024
8c6699c
Remove indent from drop chip, ensure indent is applied to the position
andrewserong Jan 11, 2024
d882564
Try updating the drag chip to use a border
andrewserong Jan 11, 2024
ba2be74
Try drop indicator line as preview of final list item
andrewserong Jan 11, 2024
29aa240
Try offsets for nesting level of drop indicator, and use darker color…
andrewserong Jan 12, 2024
1cdfc53
Use drag chip as on trunk, but with opacity of 0.8
andrewserong Jan 15, 2024
66ac213
Consolidate drop indicator logic
andrewserong Jan 15, 2024
3839470
Fix drop indicator when dragging files
andrewserong Jan 16, 2024
d7cec73
Don't add nesting classname when dragging files as the editor thinks …
andrewserong Jan 16, 2024
2dd5f23
Move displacement logic to a helper function, add tests
andrewserong Jan 17, 2024
66ba7a2
Remove unneeded changes from useMovingAnimation
andrewserong Jan 17, 2024
a931c1b
Add explanatory comments
andrewserong Jan 17, 2024
c397ce1
Try a timeout for the list view drop zone updates of 50ms instead of …
andrewserong Jan 22, 2024
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
21 changes: 16 additions & 5 deletions packages/block-editor/src/components/block-draggable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-pr
import { isDropTargetValid } from '../use-block-drop-zone';

const BlockDraggable = ( {
appendToOwnerDocument,
children,
clientIds,
cloneClassname,
elementId,
onDragStart,
onDragEnd,
fadeWhenDisabled = false,
dragComponent,
} ) => {
const {
srcRootClientId,
Expand Down Expand Up @@ -181,6 +184,7 @@ const BlockDraggable = ( {

return (
<Draggable
appendToOwnerDocument={ appendToOwnerDocument }
cloneClassname={ cloneClassname }
__experimentalTransferDataType="wp-blocks"
transferData={ transferData }
Expand Down Expand Up @@ -210,12 +214,19 @@ const BlockDraggable = ( {
}
} }
__experimentalDragComponent={
<BlockDraggableChip
count={ clientIds.length }
icon={ icon }
fadeWhenDisabled
/>
// Check against `undefined` so that `null` can be used to disable
// the default drag component.
dragComponent !== undefined ? (
dragComponent
) : (
<BlockDraggableChip
count={ clientIds.length }
icon={ icon }
fadeWhenDisabled
/>
)
}
elementId={ elementId }
>
{ ( { onDraggableStart, onDraggableEnd } ) => {
return children( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ const ListViewBlockContents = forwardRef(
setInsertedBlock={ setInsertedBlock }
/>
) }
<BlockDraggable clientIds={ draggableClientIds }>
<BlockDraggable
appendToOwnerDocument
clientIds={ draggableClientIds }
cloneClassname={ 'block-editor-list-view-draggable-chip' }
>
{ ( { draggable, onDragStart, onDragEnd } ) => (
<ListViewBlockSelectButton
ref={ ref }
Expand Down
9 changes: 9 additions & 0 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import AriaReferencedText from './aria-referenced-text';

function ListViewBlock( {
block: { clientId },
displacement,
isAfterDraggedBlocks,
isDragged,
isNesting,
isSelected,
isBranchSelected,
selectBlock,
Expand Down Expand Up @@ -270,6 +273,11 @@ function ListViewBlock( {
'has-single-cell': ! showBlockActions,
'is-synced': blockInformation?.isSynced,
'is-draggable': canMove,
'is-displacement-normal': displacement === 'normal',
'is-displacement-up': displacement === 'up',
'is-displacement-down': displacement === 'down',
'is-after-dragged-blocks': isAfterDraggedBlocks,
'is-nesting': isNesting,
} );

// Only include all selected blocks if the currently clicked on block
Expand All @@ -296,6 +304,7 @@ function ListViewBlock( {
return (
<ListViewLeaf
className={ classes }
isDragged={ isDragged }
onKeyDown={ onKeyDown }
onMouseEnter={ onMouseEnter }
onMouseLeave={ onMouseLeave }
Expand Down
40 changes: 30 additions & 10 deletions packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AsyncModeProvider, useSelect } from '@wordpress/data';
import { Appender } from './appender';
import ListViewBlock from './block';
import { useListViewContext } from './context';
import { isClientIdSelected } from './utils';
import { getDragDisplacementValues, isClientIdSelected } from './utils';
import { store as blockEditorStore } from '../../store';
import useBlockDisplayInformation from '../use-block-display-information';

Expand Down Expand Up @@ -91,7 +91,6 @@ function ListViewBranch( props ) {
selectedClientIds,
level = 1,
path = '',
isBranchDragged = false,
isBranchSelected = false,
listPosition = 0,
fixedListWindow,
Expand All @@ -115,7 +114,14 @@ function ListViewBranch( props ) {
[ parentId ]
);

const { expandedState, draggedClientIds } = useListViewContext();
const {
blockDropPosition,
blockDropTargetIndex,
firstDraggedBlockIndex,
blockIndexes,
expandedState,
draggedClientIds,
} = useListViewContext();

if ( ! canParentExpand ) {
return null;
Expand Down Expand Up @@ -143,6 +149,21 @@ function ListViewBranch( props ) {
);
}

const isDragged = !! draggedClientIds?.includes( clientId );

// Determine the displacement of the block while dragging. This
// works out whether the current block should be displaced up or
// down, relative to the dragged blocks and the drop target.
const { displacement, isAfterDraggedBlocks, isNesting } =
getDragDisplacementValues( {
blockIndexes,
blockDropTargetIndex,
blockDropPosition,
clientId,
firstDraggedBlockIndex,
isDragged,
} );

const { itemInView } = fixedListWindow;
const blockInView = itemInView( nextPosition );

Expand All @@ -158,8 +179,6 @@ function ListViewBranch( props ) {
? expandedState[ clientId ] ?? isExpanded
: undefined;

const isDragged = !! draggedClientIds?.includes( clientId );

// Make updates to the selected or dragged blocks synchronous,
// but asynchronous for any other block.
const isSelected = isClientIdSelected(
Expand All @@ -178,7 +197,6 @@ function ListViewBranch( props ) {
const showBlock =
isDragged ||
blockInView ||
isBranchDragged ||
( isSelected && clientId === selectedClientIds[ 0 ] );
return (
<AsyncModeProvider key={ clientId } value={ ! isSelected }>
Expand All @@ -188,25 +206,28 @@ function ListViewBranch( props ) {
selectBlock={ selectBlock }
isSelected={ isSelected }
isBranchSelected={ isSelectedBranch }
isDragged={ isDragged || isBranchDragged }
isDragged={ isDragged }
level={ level }
position={ position }
rowCount={ rowCount }
siblingBlockCount={ blockCount }
showBlockMovers={ showBlockMovers }
path={ updatedPath }
isExpanded={ shouldExpand }
isExpanded={ isDragged ? false : shouldExpand }
listPosition={ nextPosition }
selectedClientIds={ selectedClientIds }
isSyncedBranch={ syncedBranch }
displacement={ displacement }
isAfterDraggedBlocks={ isAfterDraggedBlocks }
isNesting={ isNesting }
/>
) }
{ ! showBlock && (
<tr>
<td className="block-editor-list-view-placeholder" />
</tr>
) }
{ hasNestedBlocks && shouldExpand && (
{ hasNestedBlocks && shouldExpand && ! isDragged && (
<ListViewBranch
parentId={ clientId }
blocks={ innerBlocks }
Expand All @@ -217,7 +238,6 @@ function ListViewBranch( props ) {
listPosition={ nextPosition + 1 }
fixedListWindow={ fixedListWindow }
isBranchSelected={ isSelectedBranch }
isBranchDragged={ isDragged || isBranchDragged }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
isSyncedBranch={ syncedBranch }
Expand Down
Loading
Loading