Skip to content

Commit e1fdffe

Browse files
noisysockstellthemachinesandrewserongjasmussen
authored
Grid interactivity: Allow blocks to be positioned in manual mode using drag and drop (#61025)
Co-authored-by: noisysocks <[email protected]> Co-authored-by: tellthemachines <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: jasmussen <[email protected]>
1 parent b6c5b41 commit e1fdffe

File tree

13 files changed

+1143
-391
lines changed

13 files changed

+1143
-391
lines changed

packages/block-editor/src/components/block-mover/index.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ function BlockMover( {
2525
isBlockMoverUpButtonDisabled,
2626
isBlockMoverDownButtonDisabled,
2727
} ) {
28-
const { canMove, rootClientId, isFirst, isLast, orientation } = useSelect(
28+
const {
29+
canMove,
30+
rootClientId,
31+
isFirst,
32+
isLast,
33+
orientation,
34+
isManualGrid,
35+
} = useSelect(
2936
( select ) => {
3037
const {
3138
getBlockIndex,
3239
getBlockListSettings,
3340
canMoveBlocks,
3441
getBlockOrder,
3542
getBlockRootClientId,
43+
getBlockAttributes,
3644
} = select( blockEditorStore );
3745
const normalizedClientIds = Array.isArray( clientIds )
3846
? clientIds
@@ -44,13 +52,18 @@ function BlockMover( {
4452
normalizedClientIds[ normalizedClientIds.length - 1 ]
4553
);
4654
const blockOrder = getBlockOrder( _rootClientId );
55+
const { layout = {} } = getBlockAttributes( _rootClientId ) ?? {};
4756

4857
return {
4958
canMove: canMoveBlocks( clientIds ),
5059
rootClientId: _rootClientId,
5160
isFirst: firstIndex === 0,
5261
isLast: lastIndex === blockOrder.length - 1,
5362
orientation: getBlockListSettings( _rootClientId )?.orientation,
63+
isManualGrid:
64+
layout.type === 'grid' &&
65+
!! layout.columnCount &&
66+
window.__experimentalEnableGridInteractivity,
5467
};
5568
},
5669
[ clientIds ]
@@ -60,8 +73,6 @@ function BlockMover( {
6073
return null;
6174
}
6275

63-
const dragHandleLabel = __( 'Drag' );
64-
6576
return (
6677
<ToolbarGroup
6778
className={ clsx( 'block-editor-block-mover', {
@@ -75,7 +86,7 @@ function BlockMover( {
7586
icon={ dragHandle }
7687
className="block-editor-block-mover__drag-handle"
7788
aria-hidden="true"
78-
label={ dragHandleLabel }
89+
label={ __( 'Drag' ) }
7990
// Should not be able to tab to drag handle as this
8091
// button can only be used with a pointer device.
8192
tabIndex="-1"
@@ -84,26 +95,28 @@ function BlockMover( {
8495
) }
8596
</BlockDraggable>
8697
) }
87-
<div className="block-editor-block-mover__move-button-container">
88-
<ToolbarItem>
89-
{ ( itemProps ) => (
90-
<BlockMoverUpButton
91-
disabled={ isBlockMoverUpButtonDisabled }
92-
clientIds={ clientIds }
93-
{ ...itemProps }
94-
/>
95-
) }
96-
</ToolbarItem>
97-
<ToolbarItem>
98-
{ ( itemProps ) => (
99-
<BlockMoverDownButton
100-
disabled={ isBlockMoverDownButtonDisabled }
101-
clientIds={ clientIds }
102-
{ ...itemProps }
103-
/>
104-
) }
105-
</ToolbarItem>
106-
</div>
98+
{ ! isManualGrid && (
99+
<div className="block-editor-block-mover__move-button-container">
100+
<ToolbarItem>
101+
{ ( itemProps ) => (
102+
<BlockMoverUpButton
103+
disabled={ isBlockMoverUpButtonDisabled }
104+
clientIds={ clientIds }
105+
{ ...itemProps }
106+
/>
107+
) }
108+
</ToolbarItem>
109+
<ToolbarItem>
110+
{ ( itemProps ) => (
111+
<BlockMoverDownButton
112+
disabled={ isBlockMoverDownButtonDisabled }
113+
clientIds={ clientIds }
114+
{ ...itemProps }
115+
/>
116+
) }
117+
</ToolbarItem>
118+
</div>
119+
) }
107120
</ToolbarGroup>
108121
);
109122
}

0 commit comments

Comments
 (0)