Skip to content

Commit

Permalink
Remove position classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 10, 2020
1 parent 77cd3da commit 257a093
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function useBlockDropZone( { element, rootClientId } ) {
onHTMLDrop,
onDrop,
isDisabled: isLockedAll,
withExactPosition: true,
withPosition: true,
} );

useEffect( () => {
Expand Down
12 changes: 3 additions & 9 deletions packages/components/src/drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ export function useDropZone( {
onHTMLDrop,
onDrop,
isDisabled,
withExactPosition,
withPosition,
} ) {
const { addDropZone, removeDropZone } = useContext( Context );
const [ state, setState ] = useState( {
isDraggingOverDocument: false,
isDraggingOverElement: false,
position: null,
type: null,
} );

Expand All @@ -39,14 +38,14 @@ export function useDropZone( {
onFilesDrop,
onHTMLDrop,
setState,
withExactPosition,
withPosition,
};
addDropZone( dropZone );
return () => {
removeDropZone( dropZone );
};
}
}, [ isDisabled, onDrop, onFilesDrop, onHTMLDrop, withExactPosition ] );
}, [ isDisabled, onDrop, onFilesDrop, onHTMLDrop, withPosition ] );

return state;
}
Expand Down Expand Up @@ -74,7 +73,6 @@ function DropZoneComponent( {
const {
isDraggingOverDocument,
isDraggingOverElement,
position,
type,
} = useDropZone( { element, onFilesDrop, onHTMLDrop, onDrop } );

Expand Down Expand Up @@ -103,10 +101,6 @@ function DropZoneComponent( {
),
'is-dragging-over-document': isDraggingOverDocument,
'is-dragging-over-element': isDraggingOverElement,
'is-close-to-top': position && position.y === 'top',
'is-close-to-bottom': position && position.y === 'bottom',
'is-close-to-left': position && position.x === 'left',
'is-close-to-right': position && position.x === 'right',
[ `is-dragging-${ type }` ]: !! type,
} );

Expand Down
14 changes: 2 additions & 12 deletions packages/components/src/drop-zone/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,8 @@ class DropZoneProvider extends Component {

let position = null;

if ( hoveredDropZone ) {
const rect = hoveredDropZone.element.current.getBoundingClientRect();

let x = detail.clientX;
let y = detail.clientY;

if ( ! hoveredDropZone.withExactPosition ) {
x = detail.clientX - rect.left < rect.right - detail.clientX ? 'left' : 'right';
y = detail.clientY - rect.top < rect.bottom - detail.clientY ? 'top' : 'bottom';
}

position = { x, y };
if ( hoveredDropZone && hoveredDropZone.withPosition ) {
position = { x: detail.clientX, y: detail.clientY };
}

// Optimisation: Only update the changed dropzones
Expand Down

0 comments on commit 257a093

Please sign in to comment.