UNPKG

react-beautiful-dnd

Version:

Beautiful, accessible drag and drop for lists with React.js

46 lines (31 loc) 1.58 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _isWithin = require('../is-within'); var _isWithin2 = _interopRequireDefault(_isWithin); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = function (frame) { var isWithinVertical = (0, _isWithin2.default)(frame.top, frame.bottom); var isWithinHorizontal = (0, _isWithin2.default)(frame.left, frame.right); return function (subject) { var isContained = isWithinVertical(subject.top) && isWithinVertical(subject.bottom) && isWithinHorizontal(subject.left) && isWithinHorizontal(subject.right); if (isContained) { return true; } var isPartiallyVisibleVertically = isWithinVertical(subject.top) || isWithinVertical(subject.bottom); var isPartiallyVisibleHorizontally = isWithinHorizontal(subject.left) || isWithinHorizontal(subject.right); var isPartiallyContained = isPartiallyVisibleVertically && isPartiallyVisibleHorizontally; if (isPartiallyContained) { return true; } var isBiggerVertically = subject.top < frame.top && subject.bottom > frame.bottom; var isBiggerHorizontally = subject.left < frame.left && subject.right > frame.right; var isTargetBiggerThanFrame = isBiggerVertically && isBiggerHorizontally; if (isTargetBiggerThanFrame) { return true; } var isTargetBiggerOnOneAxis = isBiggerVertically && isPartiallyVisibleHorizontally || isBiggerHorizontally && isPartiallyVisibleVertically; return isTargetBiggerOnOneAxis; }; };