-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add/drag handle #9569
Add/drag handle #9569
Changes from all commits
546eab5
13eebbe
380d621
eabf09a
a430b5c
a9280d3
79ff752
7a9125e
22d1a4a
d4b3a80
601c575
87f2975
3df86ad
6f8e5f8
2475778
66b9d6b
59639b1
070b059
043e191
ac3f475
dca05f5
172daa5
4cbbfc5
638393a
6901e69
48d0d6f
8152297
42ed441
e9f994c
f253641
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Draggable } from '@wordpress/components'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
const BlockDraggable = ( { children, clientId, rootClientId, blockElementId, index, layout, onDragStart, onDragEnd } ) => { | ||
const transferData = { | ||
type: 'block', | ||
fromIndex: index, | ||
rootClientId, | ||
clientId, | ||
layout, | ||
}; | ||
|
||
return ( | ||
<Draggable | ||
elementId={ blockElementId } | ||
transferData={ transferData } | ||
onDragStart={ onDragStart } | ||
onDragEnd={ onDragEnd } | ||
> | ||
{ | ||
( { onDraggableStart, onDraggableEnd } ) => { | ||
return children( { | ||
onDraggableStart: onDraggableStart, | ||
onDraggableEnd: onDraggableEnd, | ||
} ); | ||
} | ||
} | ||
</Draggable> | ||
); | ||
}; | ||
|
||
export default withSelect( ( select, { clientId } ) => { | ||
const { getBlockIndex, getBlockRootClientId } = select( 'core/editor' ); | ||
return { | ||
index: getBlockIndex( clientId ), | ||
rootClientId: getBlockRootClientId( clientId ), | ||
}; | ||
} )( BlockDraggable ); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ import BlockContextualToolbar from './block-contextual-toolbar'; | |
import BlockMultiControls from './multi-controls'; | ||
import BlockMobileToolbar from './block-mobile-toolbar'; | ||
import BlockInsertionPoint from './insertion-point'; | ||
import BlockDraggable from './block-draggable'; | ||
import IgnoreNestedEvents from './ignore-nested-events'; | ||
import InserterWithShortcuts from '../inserter-with-shortcuts'; | ||
import Inserter from '../inserter'; | ||
|
@@ -373,6 +372,7 @@ export class BlockListBlock extends Component { | |
hasSelectedInnerBlock, | ||
isParentOfSelectedBlock, | ||
hasMultiSelection, | ||
isDraggable, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this prop is useless, (in the block layout as well), I don't see where it's being set? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it isn't. This is a Matías' request so specific editor implementations can hide the drag handler. To maintain backwards-compatibility, unless it is specifically set to |
||
} = this.props; | ||
const isHovered = this.state.isHovered && ! isMultiSelecting; | ||
const { name: blockName, isValid } = block; | ||
|
@@ -410,7 +410,7 @@ export class BlockListBlock extends Component { | |
'is-selected-parent': shouldAppearSelectedParent, | ||
'is-hovered': shouldAppearHovered, | ||
'is-reusable': isReusableBlock( blockType ), | ||
'is-hidden': dragging, | ||
'is-dragging': dragging, | ||
'is-typing': isTypingWithinBlock, | ||
'is-focused': isFocusMode && ( isSelected || isParentOfSelectedBlock ), | ||
'is-focus-mode': isFocusMode, | ||
|
@@ -480,18 +480,6 @@ export class BlockListBlock extends Component { | |
] } | ||
{ ...wrapperProps } | ||
> | ||
{ ! isPartOfMultiSelection && isMovable && ( | ||
<BlockDraggable | ||
clientId={ clientId } | ||
rootClientId={ rootClientId } | ||
blockElementId={ blockElementId } | ||
layout={ layout } | ||
order={ order } | ||
onDragStart={ this.onDragStart } | ||
onDragEnd={ this.onDragEnd } | ||
isDragging={ dragging } | ||
/> | ||
) } | ||
{ shouldShowInsertionPoint && ( | ||
<BlockInsertionPoint | ||
clientId={ clientId } | ||
|
@@ -509,11 +497,14 @@ export class BlockListBlock extends Component { | |
{ shouldRenderMovers && ( | ||
<BlockMover | ||
clientIds={ clientId } | ||
rootClientId={ rootClientId } | ||
blockElementId={ blockElementId } | ||
layout={ layout } | ||
isFirst={ isFirst } | ||
isLast={ isLast } | ||
isHidden={ ! ( isHovered || isSelected ) || hoverArea !== 'left' } | ||
isDraggable={ ( isDraggable !== false ) && ( ! isPartOfMultiSelection && isMovable ) } | ||
onDragStart={ this.onDragStart } | ||
onDragEnd={ this.onDragEnd } | ||
/> | ||
) } | ||
{ shouldShowBreadcrumb && ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,35 @@ | ||
.editor-block-list__layout .components-draggable__clone { | ||
& > .editor-block-list__block > .editor-block-list__block-draggable { | ||
background: $white; // @todo: ensure this works with themes that invert the color | ||
box-shadow: $shadow-popover; | ||
|
||
@include break-small { | ||
left: -$block-parent-side-ui-clearance - $border-width; | ||
right: -$block-parent-side-ui-clearance - $border-width; | ||
|
||
.editor-block-list__layout & { | ||
left: -$border-width; | ||
right: -$border-width; | ||
} | ||
} | ||
} | ||
|
||
// Hide the Block UI when dragging the block | ||
// This ensures the page scroll properly (no sticky elements) | ||
.editor-block-contextual-toolbar, | ||
.editor-block-mover, | ||
.editor-block-settings-menu { | ||
// I think important is fine here to avoid over complexing the selector | ||
display: none !important; | ||
} | ||
} | ||
|
||
.editor-block-list__layout .editor-block-list__block-draggable { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
z-index: z-index(".editor-block-list__block-draggable"); | ||
|
||
> .editor-block-list__block-draggable-inner { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
visibility: hidden; | ||
|
||
// Use opacity to work in various editor styles. | ||
background-color: $dark-opacity-light-200; | ||
|
||
.is-dark-theme & { | ||
background-color: $light-opacity-light-200; | ||
.editor-block-list__layout .editor-block-list__block.is-selected { // Needs specificity to override inherited styles. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the changes here introduced a regression in Spotlight mode. It should be fixed here #9951 |
||
// While block is being dragged, dim the slot dragged from, and hide some UI. | ||
&.is-dragging { | ||
.editor-block-list__block-edit::before { | ||
outline: none; | ||
} | ||
|
||
@include break-small { | ||
margin: 0 48px; | ||
> .editor-block-list__block-edit > * { | ||
background: $light-gray-100; | ||
} | ||
} | ||
|
||
&.is-visible > .editor-block-list__block-draggable-inner { | ||
visibility: visible; | ||
} | ||
|
||
@include break-small { | ||
// use a wider available space for hovering/selecting/dragging on top level blocks | ||
left: -$parent-block-padding - $block-padding; | ||
right: -$parent-block-padding - $block-padding; | ||
|
||
// use smaller space for hovering/selecting/dragging on child blocks | ||
.editor-block-list__layout & { | ||
left: 0; | ||
right: 0; | ||
> .editor-block-list__block-edit > * > * { | ||
visibility: hidden; | ||
} | ||
|
||
// Full width blocks don't have the place to expand on the side | ||
.editor-block-list__block[data-align="full"] & { | ||
left: 0; | ||
right: 0; | ||
.editor-block-mover, | ||
.editor-block-contextual-toolbar { | ||
display: none; | ||
} | ||
} | ||
|
||
|
||
cursor: move; // Fallback for IE/Edge < 14 | ||
cursor: grab; | ||
} | ||
|
||
|
||
// Allow Drag & Drop when clicking on the empty area of the mover and the settings menu | ||
.editor-block-list__layout .editor-block-list__block .editor-block-mover, | ||
.editor-block-list__layout .editor-block-list__block .editor-block-settings-menu { | ||
pointer-events: none; | ||
|
||
// Nested blocks don't have any side affordance for drag and drop | ||
.editor-block-list__layout &, | ||
> * { | ||
pointer-events: auto; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adds a feature by removing code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤘 |
||
} | ||
} | ||
|
||
.editor-block-list__block { | ||
&.is-hidden *, | ||
&.is-hidden > * { | ||
visibility: hidden; | ||
} | ||
|
||
.editor-block-list__block-edit .reusable-block-edit-panel * { | ||
> .editor-block-list__block-edit .reusable-block-edit-panel * { | ||
z-index: z-index(".editor-block-list__block-edit .reusable-block-edit-panel *"); | ||
} | ||
|
||
|
@@ -438,12 +369,6 @@ | |
float: left; | ||
} | ||
|
||
// There is no side UI clearance on full-wide elements, so they are simply not draggable on the sides | ||
> .editor-block-list__block-draggable { | ||
left: 0; | ||
right: 0; | ||
} | ||
|
||
// Position hover label on the right | ||
> .editor-block-list__breadcrumb { | ||
right: -$border-width; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import BlockDraggable from '../block-draggable'; | ||
|
||
export const IconDragHandle = ( { isVisible, className, icon, onDragStart, onDragEnd, blockElementId, clientId, layout } ) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: This component looks useless to me, we can just embed it inside the mover but I don't feel strongly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it useful to hide how the drag logic works from the block-mover itself, so the icons in the |
||
if ( ! isVisible ) { | ||
return null; | ||
} | ||
|
||
const dragHandleClassNames = classnames( 'editor-block-mover__control-drag-handle', className ); | ||
|
||
return ( | ||
<BlockDraggable | ||
clientId={ clientId } | ||
blockElementId={ blockElementId } | ||
layout={ layout } | ||
onDragStart={ onDragStart } | ||
onDragEnd={ onDragEnd } | ||
> | ||
{ | ||
( { onDraggableStart, onDraggableEnd } ) => ( | ||
<div | ||
className={ dragHandleClassNames } | ||
aria-hidden="true" | ||
onDragStart={ onDraggableStart } | ||
onDragEnd={ onDraggableEnd } | ||
draggable | ||
> | ||
{ icon } | ||
</div> | ||
) } | ||
</BlockDraggable> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dragging no longer needs a dedicated DOM node. This PR removes the
editor-block-list__block-draggable
node fromBlockDraggable
.