@atlaskit/pragmatic-drag-and-drop-auto-scroll
Version:
An optional Pragmatic drag and drop package that enables automatic scrolling during a drag operation
43 lines • 1.61 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { axisLookup } from './axis';
import { mainAxisSideLookup } from './side';
function makeGetHitbox(_ref) {
var edge = _ref.edge,
axis = _ref.axis;
return function hitbox(_ref2) {
var clientRect = _ref2.clientRect,
config = _ref2.config;
var _axisLookup$axis = axisLookup[axis],
mainAxis = _axisLookup$axis.mainAxis,
crossAxis = _axisLookup$axis.crossAxis;
var side = mainAxisSideLookup[edge];
var mainAxisHitboxSize = Math.min(
// scale the size of the hitbox down for smaller elements
config.startHitboxAtPercentageRemainingOfElement[edge] * clientRect[mainAxis.size],
// Don't let the hitbox grow too big for big elements
config.maxMainAxisHitboxSize);
return DOMRect.fromRect(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, mainAxis.point, side === 'start' ?
// begin from the start edge and grow inwards
clientRect[mainAxis.point] :
// begin from inside the end edge and grow towards the end edge
clientRect[mainAxis.point] + clientRect[mainAxis.size] - mainAxisHitboxSize), crossAxis.point, clientRect[crossAxis.point]), mainAxis.size, mainAxisHitboxSize), crossAxis.size, clientRect[crossAxis.size]));
};
}
export var getOverElementHitbox = {
top: makeGetHitbox({
axis: 'vertical',
edge: 'top'
}),
right: makeGetHitbox({
axis: 'horizontal',
edge: 'right'
}),
bottom: makeGetHitbox({
axis: 'vertical',
edge: 'bottom'
}),
left: makeGetHitbox({
axis: 'horizontal',
edge: 'left'
})
};