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

Support drag and drop in horizontal block lists and improve drop zone detection #23020

Merged
merged 10 commits into from
Jun 17, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@
}
}

.block-list-appender.is-drop-target > div::before {
content: "";
position: absolute;
right: -$grid-unit-10;
left: -$grid-unit-10;
top: -$grid-unit-10;
bottom: -$grid-unit-10;
border-radius: $radius-block-ui;
border: 3px solid var(--wp-admin-theme-color);
}

.block-list-appender > .block-editor-inserter {
display: block;
}
Expand Down
29 changes: 20 additions & 9 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function BlockList(
function selector( select ) {
const {
getBlockOrder,
getBlockListSettings,
isMultiSelecting,
getSelectedBlockClientId,
getMultiSelectedBlockClientIds,
Expand All @@ -50,6 +51,8 @@ function BlockList(
isMultiSelecting: isMultiSelecting(),
selectedBlockClientId: getSelectedBlockClientId(),
multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),
moverDirection: getBlockListSettings( rootClientId )
?.__experimentalMoverDirection,
hasMultiSelection: hasMultiSelection(),
enableAnimation:
! isTyping() &&
Expand All @@ -62,16 +65,19 @@ function BlockList(
isMultiSelecting,
selectedBlockClientId,
multiSelectedBlockClientIds,
moverDirection,
hasMultiSelection,
enableAnimation,
} = useSelect( selector, [ rootClientId ] );

const Container = rootClientId ? __experimentalTagName : RootContainer;
const targetClientId = useBlockDropZone( {
const dropTargetIndex = useBlockDropZone( {
element: ref,
rootClientId,
} );

const isAppenderDropTarget = dropTargetIndex === blockClientIds.length;

return (
<Container
{ ...__experimentalPassedProps }
Expand All @@ -87,6 +93,8 @@ function BlockList(
? multiSelectedBlockClientIds.includes( clientId )
: selectedBlockClientId === clientId;

const isDropTarget = dropTargetIndex === index;

return (
<AsyncModeProvider
key={ clientId }
Expand All @@ -101,11 +109,12 @@ function BlockList(
// otherwise there might be a small delay to trigger the animation.
index={ index }
enableAnimation={ enableAnimation }
className={
clientId === targetClientId
? 'is-drop-target'
: undefined
}
className={ classnames( {
'is-drop-target': isDropTarget,
'is-dropping-horizontally':
isDropTarget &&
moverDirection === 'horizontal',
} ) }
/>
</AsyncModeProvider>
);
Expand All @@ -114,9 +123,11 @@ function BlockList(
tagName={ __experimentalAppenderTagName }
rootClientId={ rootClientId }
renderAppender={ renderAppender }
className={
targetClientId === null ? 'is-drop-target' : undefined
}
className={ classnames( {
'is-drop-target': isAppenderDropTarget,
'is-dropping-horizontally':
isAppenderDropTarget && moverDirection === 'horizontal',
} ) }
/>
</Container>
);
Expand Down
17 changes: 15 additions & 2 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
opacity: 1;
}
}
}

.block-editor-block-list__layout .block-editor-block-list__block,
.block-editor-block-list__layout .block-list-appender {
position: relative;

// Between-blocks dropzone line indicator.
&.is-drop-target::before {
Expand All @@ -104,13 +109,21 @@
z-index: 0;
pointer-events: none;
transition: border-color 0.1s linear, border-style 0.1s linear, box-shadow 0.1s linear;
top: -$default-block-margin / 2;
right: 0;
left: 0;
top: -$default-block-margin / 2;
border-top: 4px solid var(--wp-admin-theme-color);
}
}

&.is-drop-target.is-dropping-horizontally::before {
top: 0;
bottom: 0;
// Drop target border-width plus a couple of pixels so that the border looks between blocks.
left: -6px;
border-top: none;
border-left: 4px solid var(--wp-admin-theme-color);
}
}

/**
* Cross-Block Selection
Expand Down
Loading