Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
drawerVisibleHandler = (el, drawerEl, currentVisible, isBlurClose) => {
// el is missing
if (el && !domContains(document, el)) {
return currentVisible;
}
if (drawerEl && el && domContains(drawerEl, el)) {
return currentVisible;
}
return isBlurClose ? false : currentVisible;
};
triggerHandler = (el, triggerEl, popupEl, currentVisible, isBlurClose) => {
// el is missing
if (el && !domContains(document, el)) {
return currentVisible;
}
if ((triggerEl && el && domContains(triggerEl, el))
|| (popupEl && el && domContains(popupEl, el))) {
return currentVisible;
}
return isBlurClose ? false : currentVisible;
};
}
case Position.RIGHT_BOTTOM: {
result.left = leftHorizontalRight(triggerEl, triggerOffset);
result.top = topHorizontalBottom(triggerEl, triggerOffset, popupEl);
break;
}
case Position.CENTER: {
result.left = leftVerticalCenter(triggerEl, triggerOffset, popupEl);
result.top = topHorizontalMiddle(triggerEl, triggerOffset, popupEl);
break;
}
}
// to solve the fixed parent element problem
const closestFixedEl = Dom.getClosestFixed(triggerEl);
if (closestFixedEl && parentEl && domContains(parentEl, closestFixedEl)) {
result.position = 'fixed';
}
return result;
}
}
const { clientX, clientY, pageX, pageY } = getEventCoordinates(e)
let node = this.container(),
collides,
offsetData
// Right clicks
if (
e.which === 3 ||
e.button === 2 ||
!isOverContainer(node, clientX, clientY)
)
return
if (!this.globalMouse && node && !contains(node, e.target)) {
let { top, left, bottom, right } = normalizeDistance(0)
offsetData = getBoundsForNode(node)
collides = objectsCollide(
{
top: offsetData.top - top,
left: offsetData.left - left,
bottom: offsetData.bottom + bottom,
right: offsetData.right + right,
},
{ top: pageY, left: pageX }
)
if (!collides) return
}
_handleTerminatingEvent(e) {
const { pageX, pageY } = getEventCoordinates(e)
this.selecting = false
this._removeEndListener && this._removeEndListener()
this._removeMoveListener && this._removeMoveListener()
if (!this._initialEventData) return
let inRoot = !this.container || contains(this.container(), e.target)
let bounds = this._selectRect
let click = this.isClick(pageX, pageY)
this._initialEventData = null
if (e.key === 'Escape') {
return this.emit('reset')
}
if (!inRoot) {
return this.emit('reset')
}
if (click && inRoot) {
return this._handleClickEvent(e)
}
function isOverContainer(container, x, y) {
return !container || contains(container, document.elementFromPoint(x, y))
}
e => {
const currentTarget = ref && ('current' in ref ? ref.current : ref);
warning(
!!currentTarget,
'RootClose captured a close event but does not have a ref to compare it to. ' +
'useRootClose(), should be passed a ref that resolves to a DOM node',
);
preventMouseRootCloseRef.current =
!currentTarget ||
isModifiedEvent(e) ||
!isLeftClickEvent(e) ||
contains(currentTarget, e.target);
},
[ref],
handleMouseOverOut(handler: (e: React.MouseEvent) => void, e: React.MouseEvent) {
const target = e.currentTarget as EventTarget;
const related = e.relatedTarget;
if ((!related || related !== target) && !contains(target as Element, related as Element)) {
handler(e);
}
}
autoFocus() {
if (!this.props.autoFocus) return;
const currentActiveElement = activeElement(ownerDocument(this));
if (this.dialog && !contains(this.dialog, currentActiveElement)) {
this.lastFocus = currentActiveElement;
this.dialog.focus();
}
}