Skip to content

Commit

Permalink
Fix for including the first element
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed May 15, 2024
1 parent 22d79b7 commit a8cadad
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const EditBlockWrapper = (props) => {
let ref0 = React.useRef(null);
let ref = React.useRef(null);

let useDropHook = (ref) =>
let useDropHook = (ref, isFirst) =>
useDrop({
ref,
async onDrop(e) {
Expand All @@ -94,7 +94,10 @@ const EditBlockWrapper = (props) => {
JSON.parse(items[0]).id,
);
let indexDroppable = properties.blocks_layout.items.indexOf(block);
if (indexDroppable < indexDraggable) {

if (isFirst) {
indexDroppable = 0;
} else if (indexDroppable < indexDraggable) {
indexDroppable += 1;
}
onMoveBlock(indexDraggable, indexDroppable);
Expand All @@ -113,12 +116,13 @@ const EditBlockWrapper = (props) => {
/>
);

const DropTarget0 = () => makeDropTarget(useDropHook(ref0), ref0);
const DropTarget0 = () => makeDropTarget(useDropHook(ref0, true), ref0);
const DropTarget = () => makeDropTarget(useDropHook(ref), ref);

const blockIndex = properties.blocks_layout.items.indexOf(block);
return (
<div>
<DropTarget0 />
{blockIndex === 0 ? <DropTarget0 /> : ''}
<div
{...dragProps}
{...styleMergedWithDragProps}
Expand Down

0 comments on commit a8cadad

Please sign in to comment.