@popperjs/core
Advanced tools
Comparing version 2.0.0-next.8 to 2.0.0-next.9
'use strict'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function getWindow(node) { | ||
@@ -124,3 +91,3 @@ var ownerDocument = node.ownerDocument; | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var target = isBody ? getWindow(scrollParent) : scrollParent; | ||
var updatedList = list.concat(target); | ||
@@ -333,4 +300,2 @@ return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
break; | ||
default: | ||
} | ||
@@ -427,2 +392,238 @@ } | ||
// DOM Utils | ||
var INVALID_ELEMENT_ERROR = 'Popper: Invalid reference or popper argument provided to Popper, they must be either a valid DOM element or a jQuery-wrapped DOM element.'; | ||
var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.'; | ||
var areValidElements = function areValidElements(a, b) { | ||
return a instanceof Element && b instanceof Element; | ||
}; | ||
var defaultOptions = { | ||
placement: 'bottom', | ||
eventListeners: { | ||
scroll: true, | ||
resize: true | ||
}, | ||
modifiers: [], | ||
strategy: 'absolute' | ||
}; | ||
var Popper = | ||
/*#__PURE__*/ | ||
function () { | ||
function Popper(reference, popper, options) { | ||
var _this = this; | ||
if (options === void 0) { | ||
options = defaultOptions; | ||
} | ||
this.state = { | ||
placement: 'bottom', | ||
orderedModifiers: [], | ||
options: defaultOptions, | ||
modifiersData: {} | ||
}; | ||
this.update = microtaskDebounce(function () { | ||
return new Promise(function (success, reject) { | ||
_this.forceUpdate(); | ||
success(_this.state); | ||
}); | ||
}); | ||
// Unwrap `reference` and `popper` elements in case they are | ||
// wrapped by jQuery, otherwise consume them as is | ||
this.state.elements = { | ||
reference: unwrapJqueryElement(reference), | ||
popper: unwrapJqueryElement(popper) | ||
}; | ||
var _this$state$elements = this.state.elements, | ||
referenceElement = _this$state$elements.reference, | ||
popperElement = _this$state$elements.popper; // Store options into state | ||
this.state.options = Object.assign({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
} | ||
this.state.scrollParents = { | ||
reference: listScrollParents(referenceElement), | ||
popper: listScrollParents(popperElement) | ||
}; // Order `options.modifiers` so that the dependencies are fulfilled | ||
// once the modifiers are executed | ||
this.state.orderedModifiers = orderModifiers([].concat(this.constructor.defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
.map(function (modifier) { | ||
return Object.assign({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
var name = _ref.name; | ||
return name === modifier.name; | ||
})); | ||
}); // Validate the provided modifiers so that the consumer will get warned | ||
// of one of the custom modifiers is invalid for any reason | ||
if (process.env.NODE_ENV !== "production") { | ||
validateModifiers(this.state.options.modifiers); | ||
} // Modifiers have the opportunity to execute some arbitrary code before | ||
// the first update cycle is ran, the order of execution will be the same | ||
// defined by the modifier dependencies directive. | ||
// The `onLoad` function may add or alter the options of themselves | ||
this.state.orderedModifiers.forEach(function (_ref2) { | ||
var onLoad = _ref2.onLoad, | ||
enabled = _ref2.enabled; | ||
return enabled && onLoad && onLoad(_this.state); | ||
}); | ||
this.update().then(function () { | ||
// After the first update completed, enable the event listeners | ||
_this.enableEventListeners(_this.state.options.eventListeners); | ||
}); | ||
} // Async and optimistically optimized update | ||
// it will not be executed if not necessary | ||
// debounced, so that it only runs at most once-per-tick | ||
var _proto = Popper.prototype; | ||
// Syncronous and forcefully executed update | ||
// it will always be executed even if not necessary, usually NOT needed | ||
// use Popper#update instead | ||
_proto.forceUpdate = function forceUpdate() { | ||
var _this2 = this; | ||
var _this$state$elements2 = this.state.elements, | ||
referenceElement = _this$state$elements2.reference, | ||
popperElement = _this$state$elements2.popper; // Don't proceed if `reference` or `popper` are not valid elements anymore | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
} // Get initial measurements | ||
// these are going to be used to compute the initial popper offsets | ||
// and as cache for any modifier that needs them later | ||
this.state.measures = { | ||
reference: getElementClientRect(referenceElement), | ||
popper: getElementClientRect(popperElement) | ||
}; // Get scrollTop and scrollLeft of the offsetParent | ||
// this will be used in the `computeOffsets` function to properly | ||
// position the popper taking in account the scroll position | ||
// FIXME: right now we only look for a single offsetParent (the popper one) | ||
// but we really want to take in account the reference offsetParent as well | ||
var offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Modifiers have the ability to read the current Popper state, included | ||
// the popper offsets, and modify it to address specifc cases | ||
this.state.reset = false; // Cache the placement in cache to make it available to the modifiers | ||
// modifiers will modify this one (rather than the one in options) | ||
this.state.placement = this.state.options.placement; | ||
this.state.orderedModifiers.forEach(function (modifier) { | ||
return _this2.state.modifiersData[modifier.name] = Object.assign({}, modifier.data); | ||
}); | ||
var __debug_loops__ = 0; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
if (process.env.NODE_ENV !== "production") { | ||
__debug_loops__ += 1; | ||
if (__debug_loops__ > 100) { | ||
console.error(INFINITE_LOOP_ERROR); | ||
break; | ||
} | ||
} | ||
if (index === 0) { | ||
// Offsets are the actual position the popper needs to have to be | ||
// properly positioned near its reference element | ||
// This is the most basic placement, and will be adjusted by | ||
// the modifiers in the next step | ||
this.state.offsets = { | ||
popper: computeOffsets({ | ||
reference: this.state.measures.reference, | ||
element: this.state.measures.popper, | ||
strategy: 'absolute', | ||
placement: this.state.placement, | ||
scroll: getCommonTotalScroll(referenceElement, this.state.scrollParents.reference, this.state.scrollParents.popper) | ||
}) | ||
}; | ||
} | ||
if (this.state.reset === true) { | ||
this.state.reset = false; | ||
index = -1; | ||
continue; | ||
} | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
if (enabled && typeof fn === 'function') { | ||
this.state = fn(this.state, options); | ||
} | ||
} | ||
}; | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this3 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _ref3 = typeof eventListeners === 'boolean' ? expandToHashMap(eventListeners, ['scroll', 'resize']) : eventListeners, | ||
scroll = _ref3.scroll, | ||
resize = _ref3.resize; | ||
if (scroll) { | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this3.update, { | ||
passive: true | ||
}); | ||
}); | ||
} | ||
if (resize) { | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
passive: true | ||
}); | ||
} | ||
}; | ||
_proto.destroy = function destroy() { | ||
var _this4 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this4.update); | ||
}); // Remove resize event listeners | ||
var window = getWindow(this.state.elements.popper); | ||
window.removeEventListener('resize', this.update); // Run `onDestroy` modifier methods | ||
this.state.orderedModifiers.forEach(function (_ref4) { | ||
var onDestroy = _ref4.onDestroy, | ||
enabled = _ref4.enabled; | ||
return enabled && onDestroy && onDestroy(_this4.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
Popper.defaultModifiers = []; | ||
var getBoundingClientRect = (function (element) { | ||
@@ -432,2 +633,6 @@ return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
var getDocumentElement = (function (element) { | ||
return element.ownerDocument.documentElement; | ||
}); | ||
// clipping (or hiding) overflowing elements with a position different from `initial` | ||
@@ -439,3 +644,3 @@ | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent)), offsetParent); | ||
return offsetParent === win ? getDocumentElement(element) : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent)), offsetParent); | ||
} | ||
@@ -445,3 +650,3 @@ | ||
var win = getWindow(element); | ||
var documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
var documentRect = getElementClientRect(getDocumentElement(element)); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
@@ -453,3 +658,3 @@ documentRect.width = Math.max(documentRect.width, win.innerWidth); | ||
var rectToClientRect = (function (rect) { | ||
return _extends({}, rect, { | ||
return Object.assign({}, rect, { | ||
left: rect.x, | ||
@@ -472,6 +677,9 @@ top: rect.y, | ||
var popperRect = state.measures.popper; | ||
var documentElement = options.boundaryElement.ownerDocument.documentElement; | ||
var documentElement = getDocumentElement(options.boundaryElement); | ||
if (!options.boundaryElement.contains(popperElement)) { | ||
console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
} | ||
return state; | ||
@@ -492,3 +700,3 @@ } | ||
}); | ||
var popperClientRect = rectToClientRect(_extends({}, popperRect, {}, popperOffsets)); | ||
var popperClientRect = rectToClientRect(Object.assign({}, popperRect, {}, popperOffsets)); | ||
state.modifiersData.detectOverflow = { | ||
@@ -606,8 +814,8 @@ top: boundaryClientRect.top - popperClientRect.top, | ||
Object.keys(state.elements).forEach(function (name) { | ||
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? _extends({}, state.styles[name]) : {}); // Set all values to an empty string to unset them | ||
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? Object.assign({}, state.styles[name]) : {}); // Set all values to an empty string to unset them | ||
var style = styleProperties.reduce(function (style, property) { | ||
var _extends2; | ||
var _Object$assign; | ||
return _extends({}, style, (_extends2 = {}, _extends2[String(property)] = '', _extends2)); | ||
return Object.assign({}, style, (_Object$assign = {}, _Object$assign[String(property)] = '', _Object$assign)); | ||
}, {}); // Flow doesn't support to extend this property, but it's the most | ||
@@ -634,3 +842,3 @@ // effective way to apply styles to an HTMLElement | ||
var _getOffsets = getOffsets(_extends({}, measures, { | ||
var _getOffsets = getOffsets(Object.assign({}, measures, { | ||
placement: placement | ||
@@ -677,3 +885,3 @@ })), | ||
var mergePaddingObject = (function (paddingObject) { | ||
return _extends({ | ||
return Object.assign({ | ||
top: 0, | ||
@@ -779,3 +987,4 @@ bottom: 0, | ||
var tetherMax = state.offsets.popper[mainAxis] + referenceRect[len] / 2 - popperRect[len] / 2; | ||
state.offsets.popper[mainAxis] = within(tether ? Math.min(tetherMin, min) : min, offset, tether ? Math.max(tetherMax, max) : max); | ||
var isReferenceLarger = referenceRect[len] > popperRect[len]; | ||
state.offsets.popper[mainAxis] = within(tether ? Math.min(min, isReferenceLarger ? tetherMax : tetherMin) : min, offset, tether ? Math.max(max, isReferenceLarger ? tetherMin : tetherMax) : max); | ||
} | ||
@@ -804,2 +1013,3 @@ | ||
var modifiers = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
detectOverflow: detectOverflow$1, | ||
@@ -813,231 +1023,5 @@ computeStyles: computeStyles$1, | ||
var defaultModifiers = Object.values(modifiers); | ||
var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.'; | ||
Popper.defaultModifiers = Object.values(modifiers); | ||
var areValidElements = function areValidElements(a, b) { | ||
return a instanceof Element && b instanceof Element; | ||
}; | ||
var defaultOptions = { | ||
placement: 'bottom', | ||
eventListeners: { | ||
scroll: true, | ||
resize: true | ||
}, | ||
modifiers: [], | ||
strategy: 'absolute' | ||
}; | ||
var Popper = | ||
/*#__PURE__*/ | ||
function () { | ||
function Popper(reference, popper, options) { | ||
var _this = this; | ||
if (options === void 0) { | ||
options = defaultOptions; | ||
} | ||
_defineProperty(this, "state", { | ||
placement: 'bottom', | ||
orderedModifiers: [], | ||
options: defaultOptions, | ||
modifiersData: {} | ||
}); | ||
_defineProperty(this, "update", microtaskDebounce(function () { | ||
return new Promise(function (success, reject) { | ||
_this.forceUpdate(); | ||
success(_this.state); | ||
}); | ||
})); | ||
// Unwrap `reference` and `popper` elements in case they are | ||
// wrapped by jQuery, otherwise consume them as is | ||
this.state.elements = { | ||
reference: unwrapJqueryElement(reference), | ||
popper: unwrapJqueryElement(popper) | ||
}; | ||
var _this$state$elements = this.state.elements, | ||
referenceElement = _this$state$elements.reference, | ||
popperElement = _this$state$elements.popper; // Store options into state | ||
this.state.options = _extends({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
return; | ||
} | ||
this.state.scrollParents = { | ||
reference: listScrollParents(referenceElement), | ||
popper: listScrollParents(popperElement) | ||
}; // Order `options.modifiers` so that the dependencies are fulfilled | ||
// once the modifiers are executed | ||
this.state.orderedModifiers = orderModifiers([].concat(defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
.map(function (modifier) { | ||
return _extends({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
var name = _ref.name; | ||
return name === modifier.name; | ||
})); | ||
}); // Validate the provided modifiers so that the consumer will get warned | ||
// of one of the custom modifiers is invalid for any reason | ||
if (process.env.NODE_ENV !== "production") { | ||
validateModifiers(this.state.options.modifiers); | ||
} // Modifiers have the opportunity to execute some arbitrary code before | ||
// the first update cycle is ran, the order of execution will be the same | ||
// defined by the modifier dependencies directive. | ||
// The `onLoad` function may add or alter the options of themselves | ||
this.state.orderedModifiers.forEach(function (_ref2) { | ||
var onLoad = _ref2.onLoad, | ||
enabled = _ref2.enabled; | ||
return enabled && onLoad && onLoad(_this.state); | ||
}); | ||
this.update().then(function () { | ||
// After the first update completed, enable the event listeners | ||
_this.enableEventListeners(_this.state.options.eventListeners); | ||
}); | ||
} // Async and optimistically optimized update | ||
// it will not be executed if not necessary | ||
// debounced, so that it only runs at most once-per-tick | ||
var _proto = Popper.prototype; | ||
// Syncronous and forcefully executed update | ||
// it will always be executed even if not necessary, usually NOT needed | ||
// use Popper#update instead | ||
_proto.forceUpdate = function forceUpdate() { | ||
var _this2 = this; | ||
var _this$state$elements2 = this.state.elements, | ||
referenceElement = _this$state$elements2.reference, | ||
popperElement = _this$state$elements2.popper; // Don't proceed if `reference` or `popper` are not valid elements anymore | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
return; | ||
} // Get initial measurements | ||
// these are going to be used to compute the initial popper offsets | ||
// and as cache for any modifier that needs them later | ||
this.state.measures = { | ||
reference: getElementClientRect(referenceElement), | ||
popper: getElementClientRect(popperElement) | ||
}; // Get scrollTop and scrollLeft of the offsetParent | ||
// this will be used in the `computeOffsets` function to properly | ||
// position the popper taking in account the scroll position | ||
// FIXME: right now we only look for a single offsetParent (the popper one) | ||
// but we really want to take in account the reference offsetParent as well | ||
var offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Modifiers have the ability to read the current Popper state, included | ||
// the popper offsets, and modify it to address specifc cases | ||
this.state.reset = false; // Cache the placement in cache to make it available to the modifiers | ||
// modifiers will modify this one (rather than the one in options) | ||
this.state.placement = this.state.options.placement; | ||
this.state.orderedModifiers.forEach(function (modifier) { | ||
return _this2.state.modifiersData[modifier.name] = _extends({}, modifier.data); | ||
}); | ||
var __debug_loops__ = 0; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
if (process.env.NODE_ENV !== "production") { | ||
__debug_loops__ += 1; | ||
if (__debug_loops__ > 100) { | ||
console.error(INFINITE_LOOP_ERROR); | ||
break; | ||
} | ||
} | ||
if (index === 0) { | ||
// Offsets are the actual position the popper needs to have to be | ||
// properly positioned near its reference element | ||
// This is the most basic placement, and will be adjusted by | ||
// the modifiers in the next step | ||
this.state.offsets = { | ||
popper: computeOffsets({ | ||
reference: this.state.measures.reference, | ||
element: this.state.measures.popper, | ||
strategy: 'absolute', | ||
placement: this.state.placement, | ||
scroll: getCommonTotalScroll(referenceElement, this.state.scrollParents.reference, this.state.scrollParents.popper) | ||
}) | ||
}; | ||
} | ||
if (this.state.reset === true) { | ||
this.state.reset = false; | ||
index = -1; | ||
continue; | ||
} | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
if (enabled && typeof fn === 'function') { | ||
this.state = fn(this.state, options); | ||
} | ||
} | ||
}; | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this3 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _ref3 = typeof eventListeners === 'boolean' ? expandToHashMap(eventListeners, ['scroll', 'resize']) : eventListeners, | ||
scroll = _ref3.scroll, | ||
resize = _ref3.resize; | ||
if (scroll) { | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this3.update, { | ||
passive: true | ||
}); | ||
}); | ||
} | ||
if (resize) { | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
passive: true | ||
}); | ||
} | ||
}; | ||
_proto.destroy = function destroy() { | ||
var _this4 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this4.update); | ||
}); // Remove resize event listeners | ||
var window = getWindow(this.state.elements.popper); | ||
window.removeEventListener('resize', this.update); // Run `onDestroy` modifier methods | ||
this.state.orderedModifiers.forEach(function (_ref4) { | ||
var onDestroy = _ref4.onDestroy, | ||
enabled = _ref4.enabled; | ||
return enabled && onDestroy && onDestroy(_this4.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
module.exports = Popper; | ||
//# sourceMappingURL=popper.js.map |
@@ -1,34 +0,1 @@ | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function getWindow(node) { | ||
@@ -122,3 +89,3 @@ var ownerDocument = node.ownerDocument; | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var target = isBody ? getWindow(scrollParent) : scrollParent; | ||
var updatedList = list.concat(target); | ||
@@ -331,4 +298,2 @@ return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
break; | ||
default: | ||
} | ||
@@ -425,377 +390,4 @@ } | ||
var getBoundingClientRect = (function (element) { | ||
return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
}); | ||
// clipping (or hiding) overflowing elements with a position different from `initial` | ||
function getClippingParent(element, offsetElement) { | ||
var scrollParent = getScrollParent(element); | ||
var offsetParent = offsetElement || getOffsetParent(element); | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent)), offsetParent); | ||
} | ||
var getDocumentRect = (function (element) { | ||
var win = getWindow(element); | ||
var documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
documentRect.width = Math.max(documentRect.width, win.innerWidth); | ||
return documentRect; | ||
}); | ||
var rectToClientRect = (function (rect) { | ||
return _extends({}, rect, { | ||
left: rect.x, | ||
top: rect.y, | ||
right: rect.x + rect.width, | ||
bottom: rect.y + rect.height | ||
}); | ||
}); | ||
function detectOverflow(state, options) { | ||
if (options === void 0) { | ||
options = { | ||
boundaryElement: getClippingParent(state.elements.popper) | ||
}; | ||
} | ||
var popperElement = state.elements.popper; | ||
var referenceElement = state.elements.reference; | ||
var popperRect = state.measures.popper; | ||
var documentElement = options.boundaryElement.ownerDocument.documentElement; | ||
if (!options.boundaryElement.contains(popperElement)) { | ||
console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
return state; | ||
} | ||
var boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect(getDocumentRect(documentElement)) : getBoundingClientRect(options.boundaryElement); | ||
var referenceClientRect = getBoundingClientRect(referenceElement); | ||
var popperOffsets = computeOffsets({ | ||
reference: referenceClientRect, | ||
element: popperRect, | ||
strategy: 'absolute', | ||
placement: state.placement, | ||
scroll: { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
} | ||
}); | ||
var popperClientRect = rectToClientRect(_extends({}, popperRect, {}, popperOffsets)); | ||
state.modifiersData.detectOverflow = { | ||
top: boundaryClientRect.top - popperClientRect.top, | ||
bottom: popperClientRect.bottom - boundaryClientRect.bottom, | ||
left: boundaryClientRect.left - popperClientRect.left, | ||
right: popperClientRect.right - boundaryClientRect.right | ||
}; | ||
return state; | ||
} | ||
var detectOverflow$1 = { | ||
name: 'detectOverflow', | ||
enabled: true, | ||
phase: 'read', | ||
fn: detectOverflow, | ||
data: {} | ||
}; | ||
// This modifier takes the Popper state and prepares some StyleSheet properties | ||
// that can be applied to the popper element to make it render in the expected position. | ||
var mapStrategyToPosition = function mapStrategyToPosition(strategy) { | ||
switch (strategy) { | ||
case 'fixed': | ||
return 'fixed'; | ||
case 'absolute': | ||
default: | ||
return 'absolute'; | ||
} | ||
}; | ||
var computePopperStyles = function computePopperStyles(_ref) { | ||
var offsets = _ref.offsets, | ||
strategy = _ref.strategy, | ||
gpuAcceleration = _ref.gpuAcceleration; | ||
// by default it is active, disable it only if explicitly set to false | ||
if (gpuAcceleration === false) { | ||
return { | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: mapStrategyToPosition(strategy) | ||
}; | ||
} else { | ||
return { | ||
top: '0px', | ||
left: '0px', | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: mapStrategyToPosition(strategy) | ||
}; | ||
} | ||
}; | ||
var computeArrowStyles = function computeArrowStyles(_ref2) { | ||
var offsets = _ref2.offsets, | ||
gpuAcceleration = _ref2.gpuAcceleration; | ||
if (gpuAcceleration) { | ||
return { | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: 'absolute' | ||
}; | ||
} else { | ||
return { | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: 'absolute' | ||
}; | ||
} | ||
}; | ||
function computeStyles(state, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var _options = options, | ||
_options$gpuAccelerat = _options.gpuAcceleration, | ||
gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat; | ||
state.styles = {}; // popper offsets are always available | ||
state.styles.popper = computePopperStyles({ | ||
offsets: state.offsets.popper, | ||
strategy: state.options.strategy, | ||
gpuAcceleration: gpuAcceleration | ||
}); // arrow offsets may not be available | ||
if (state.offsets.arrow != null) { | ||
state.styles.arrow = computeArrowStyles({ | ||
offsets: state.offsets.arrow, | ||
gpuAcceleration: gpuAcceleration | ||
}); | ||
} | ||
return state; | ||
} | ||
var computeStyles$1 = { | ||
name: 'computeStyles', | ||
enabled: true, | ||
phase: 'afterMain', | ||
fn: computeStyles | ||
}; | ||
// This modifier takes the styles prepared by the `computeStyles` modifier | ||
// and applies them to the HTMLElements such as popper and arrow | ||
function applyStyles(state) { | ||
Object.keys(state.elements).forEach(function (name) { | ||
var style = state.styles.hasOwnProperty(name) ? state.styles[name] : {}; // Flow doesn't support to extend this property, but it's the most | ||
// effective way to apply styles to an HTMLElement | ||
// $FlowIgnore | ||
Object.assign(state.elements[name].style, style); | ||
}); | ||
return state; | ||
} | ||
function onDestroy(state) { | ||
Object.keys(state.elements).forEach(function (name) { | ||
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? _extends({}, state.styles[name]) : {}); // Set all values to an empty string to unset them | ||
var style = styleProperties.reduce(function (style, property) { | ||
var _extends2; | ||
return _extends({}, style, (_extends2 = {}, _extends2[String(property)] = '', _extends2)); | ||
}, {}); // Flow doesn't support to extend this property, but it's the most | ||
// effective way to apply styles to an HTMLElement | ||
// $FlowIgnore | ||
Object.assign(state.elements[name].style, style); | ||
}); | ||
} | ||
var applyStyles$1 = { | ||
name: 'applyStyles', | ||
enabled: true, | ||
phase: 'write', | ||
fn: applyStyles, | ||
onDestroy: onDestroy, | ||
requires: ['computeStyles'] | ||
}; | ||
function distanceAndSkiddingToXY(placement, measures, getOffsets) { | ||
var basePlacement = getBasePlacement(placement); | ||
var invertDistance = ['left', 'top'].includes(basePlacement) ? -1 : 1; | ||
var invertSkidding = ['top', 'bottom'].includes(basePlacement) ? -1 : 1; | ||
var _getOffsets = getOffsets(_extends({}, measures, { | ||
placement: placement | ||
})), | ||
distance = _getOffsets[0], | ||
skidding = _getOffsets[1]; | ||
distance = (distance || 0) * invertDistance; | ||
skidding = (distance || 0) * invertSkidding; | ||
return ['left', 'right'].includes(basePlacement) ? [distance, skidding] : [skidding, distance]; | ||
} | ||
function offset(state, options) { | ||
if (options && typeof options.offset === 'function') { | ||
var _distanceAndSkiddingT = distanceAndSkiddingToXY(state.placement, state.measures, options.offset), | ||
x = _distanceAndSkiddingT[0], | ||
y = _distanceAndSkiddingT[1]; | ||
state.offsets.popper.x += x; | ||
state.offsets.popper.y += y; | ||
} | ||
return state; | ||
} | ||
var offset$1 = { | ||
name: 'offset', | ||
enabled: true, | ||
phase: 'main', | ||
fn: offset | ||
}; | ||
var hash = { | ||
left: 'right', | ||
right: 'left', | ||
bottom: 'top', | ||
top: 'bottom' | ||
}; | ||
var getOppositePlacement = (function (placement) { | ||
return placement.replace(/left|right|bottom|top/g, function (matched) { | ||
return hash[matched]; | ||
}); | ||
}); | ||
var mergePaddingObject = (function (paddingObject) { | ||
return _extends({ | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0 | ||
}, paddingObject); | ||
}); | ||
function flip(state, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var placement = state.placement; | ||
var defaultBehavior = [state.options.placement, getOppositePlacement(state.options.placement)]; | ||
var _options = options, | ||
_options$behavior = _options.behavior, | ||
behavior = _options$behavior === void 0 ? defaultBehavior : _options$behavior, | ||
_options$padding = _options.padding, | ||
padding = _options$padding === void 0 ? 0 : _options$padding; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var flipIndex = state.modifiersData.flip.index; | ||
var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements)); | ||
var flippedPlacement = behavior[flipIndex]; | ||
if (!flippedPlacement && placement !== state.options.placement) { | ||
state.placement = state.options.placement; | ||
state.reset = true; | ||
return state; | ||
} | ||
if (!flippedPlacement && placement === state.options.placement) { | ||
return state; | ||
} | ||
var basePlacement = getBasePlacement(flippedPlacement); | ||
var fits = overflow[basePlacement] + paddingObject[basePlacement] <= 0; | ||
if (!fits) { | ||
state.modifiersData.flip.index += 1; | ||
state.reset = true; | ||
return state; | ||
} else if (fits && state.placement !== flippedPlacement) { | ||
state.placement = flippedPlacement; | ||
state.reset = true; | ||
return state; | ||
} | ||
return state; | ||
} | ||
var flip$1 = { | ||
name: 'flip', | ||
enabled: true, | ||
phase: 'main', | ||
fn: flip, | ||
requires: ['detectOverflow'], | ||
data: { | ||
index: 0 | ||
} | ||
}; | ||
var getAltAxis = (function (axis) { | ||
return axis === 'x' ? 'y' : 'x'; | ||
}); | ||
var within = (function (min, value, max) { | ||
return Math.max(min, Math.min(value, max)); | ||
}); | ||
function preventOverflow(state, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var _options = options, | ||
_options$mainAxis = _options.mainAxis, | ||
checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis, | ||
_options$altAxis = _options.altAxis, | ||
checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis, | ||
_options$tether = _options.tether, | ||
tether = _options$tether === void 0 ? true : _options$tether, | ||
_options$padding = _options.padding, | ||
padding = _options$padding === void 0 ? 0 : _options$padding; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var basePlacement = getBasePlacement(state.placement); | ||
var mainAxis = getMainAxisFromPlacement(basePlacement); | ||
var altAxis = getAltAxis(mainAxis); | ||
var popperOffsets = state.offsets.popper; | ||
var referenceRect = state.measures.reference; | ||
var popperRect = state.measures.popper; | ||
var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements)); | ||
if (checkMainAxis) { | ||
var mainSide = mainAxis === 'y' ? top : left; | ||
var altSide = mainAxis === 'y' ? bottom : right; | ||
var len = mainAxis === 'y' ? 'height' : 'width'; | ||
var offset = popperOffsets[mainAxis]; | ||
var min = popperOffsets[mainAxis] + overflow[mainSide] + paddingObject[mainSide]; | ||
var max = popperOffsets[mainAxis] - overflow[altSide] - paddingObject[altSide]; | ||
var tetherMin = state.offsets.popper[mainAxis] - referenceRect[len] / 2 + popperRect[len] / 2; | ||
var tetherMax = state.offsets.popper[mainAxis] + referenceRect[len] / 2 - popperRect[len] / 2; | ||
state.offsets.popper[mainAxis] = within(tether ? Math.min(tetherMin, min) : min, offset, tether ? Math.max(tetherMax, max) : max); | ||
} | ||
if (checkAltAxis) { | ||
var _mainSide = mainAxis === 'x' ? top : left; | ||
var _altSide = mainAxis === 'x' ? bottom : right; | ||
state.offsets.popper[altAxis] = within(popperOffsets[altAxis] + overflow[_mainSide] + paddingObject[_mainSide], popperOffsets[altAxis], popperOffsets[altAxis] - overflow[_altSide] - paddingObject[_altSide]); | ||
} | ||
return state; | ||
} | ||
var preventOverflow$1 = { | ||
name: 'preventOverflow', | ||
enabled: true, | ||
phase: 'main', | ||
fn: preventOverflow, | ||
requires: ['detectOverflow'] | ||
}; | ||
var modifiers = /*#__PURE__*/Object.freeze({ | ||
detectOverflow: detectOverflow$1, | ||
computeStyles: computeStyles$1, | ||
applyStyles: applyStyles$1, | ||
offset: offset$1, | ||
flip: flip$1, | ||
preventOverflow: preventOverflow$1 | ||
}); | ||
var defaultModifiers = Object.values(modifiers); | ||
// DOM Utils | ||
var INVALID_ELEMENT_ERROR = 'Popper: Invalid reference or popper argument provided to Popper, they must be either a valid DOM element or a jQuery-wrapped DOM element.'; | ||
var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.'; | ||
@@ -827,3 +419,3 @@ | ||
_defineProperty(this, "state", { | ||
this.state = { | ||
placement: 'bottom', | ||
@@ -833,5 +425,4 @@ orderedModifiers: [], | ||
modifiersData: {} | ||
}); | ||
_defineProperty(this, "update", microtaskDebounce(function () { | ||
}; | ||
this.update = microtaskDebounce(function () { | ||
return new Promise(function (success, reject) { | ||
@@ -842,4 +433,3 @@ _this.forceUpdate(); | ||
}); | ||
})); | ||
}); | ||
// Unwrap `reference` and `popper` elements in case they are | ||
@@ -855,5 +445,9 @@ // wrapped by jQuery, otherwise consume them as is | ||
this.state.options = _extends({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
this.state.options = Object.assign({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
@@ -868,5 +462,5 @@ } | ||
this.state.orderedModifiers = orderModifiers([].concat(defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
this.state.orderedModifiers = orderModifiers([].concat(this.constructor.defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
.map(function (modifier) { | ||
return _extends({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
return Object.assign({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
var name = _ref.name; | ||
@@ -913,2 +507,6 @@ return name === modifier.name; | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
@@ -937,3 +535,3 @@ } // Get initial measurements | ||
this.state.orderedModifiers.forEach(function (modifier) { | ||
return _this2.state.modifiersData[modifier.name] = _extends({}, modifier.data); | ||
return _this2.state.modifiersData[modifier.name] = Object.assign({}, modifier.data); | ||
}); | ||
@@ -1034,4 +632,5 @@ var __debug_loops__ = 0; | ||
}(); | ||
Popper.defaultModifiers = []; | ||
export default Popper; | ||
//# sourceMappingURL=popper.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.Popper = factory()); | ||
(global = global || self, global.Popper = factory()); | ||
}(this, (function () { 'use strict'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function getWindow(node) { | ||
@@ -128,3 +95,3 @@ var ownerDocument = node.ownerDocument; | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var target = isBody ? getWindow(scrollParent) : scrollParent; | ||
var updatedList = list.concat(target); | ||
@@ -337,4 +304,2 @@ return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
break; | ||
default: | ||
} | ||
@@ -431,2 +396,238 @@ } | ||
// DOM Utils | ||
var INVALID_ELEMENT_ERROR = 'Popper: Invalid reference or popper argument provided to Popper, they must be either a valid DOM element or a jQuery-wrapped DOM element.'; | ||
var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.'; | ||
var areValidElements = function areValidElements(a, b) { | ||
return a instanceof Element && b instanceof Element; | ||
}; | ||
var defaultOptions = { | ||
placement: 'bottom', | ||
eventListeners: { | ||
scroll: true, | ||
resize: true | ||
}, | ||
modifiers: [], | ||
strategy: 'absolute' | ||
}; | ||
var Popper = | ||
/*#__PURE__*/ | ||
function () { | ||
function Popper(reference, popper, options) { | ||
var _this = this; | ||
if (options === void 0) { | ||
options = defaultOptions; | ||
} | ||
this.state = { | ||
placement: 'bottom', | ||
orderedModifiers: [], | ||
options: defaultOptions, | ||
modifiersData: {} | ||
}; | ||
this.update = microtaskDebounce(function () { | ||
return new Promise(function (success, reject) { | ||
_this.forceUpdate(); | ||
success(_this.state); | ||
}); | ||
}); | ||
// Unwrap `reference` and `popper` elements in case they are | ||
// wrapped by jQuery, otherwise consume them as is | ||
this.state.elements = { | ||
reference: unwrapJqueryElement(reference), | ||
popper: unwrapJqueryElement(popper) | ||
}; | ||
var _this$state$elements = this.state.elements, | ||
referenceElement = _this$state$elements.reference, | ||
popperElement = _this$state$elements.popper; // Store options into state | ||
this.state.options = Object.assign({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
{ | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
} | ||
this.state.scrollParents = { | ||
reference: listScrollParents(referenceElement), | ||
popper: listScrollParents(popperElement) | ||
}; // Order `options.modifiers` so that the dependencies are fulfilled | ||
// once the modifiers are executed | ||
this.state.orderedModifiers = orderModifiers([].concat(this.constructor.defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
.map(function (modifier) { | ||
return Object.assign({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
var name = _ref.name; | ||
return name === modifier.name; | ||
})); | ||
}); // Validate the provided modifiers so that the consumer will get warned | ||
// of one of the custom modifiers is invalid for any reason | ||
{ | ||
validateModifiers(this.state.options.modifiers); | ||
} // Modifiers have the opportunity to execute some arbitrary code before | ||
// the first update cycle is ran, the order of execution will be the same | ||
// defined by the modifier dependencies directive. | ||
// The `onLoad` function may add or alter the options of themselves | ||
this.state.orderedModifiers.forEach(function (_ref2) { | ||
var onLoad = _ref2.onLoad, | ||
enabled = _ref2.enabled; | ||
return enabled && onLoad && onLoad(_this.state); | ||
}); | ||
this.update().then(function () { | ||
// After the first update completed, enable the event listeners | ||
_this.enableEventListeners(_this.state.options.eventListeners); | ||
}); | ||
} // Async and optimistically optimized update | ||
// it will not be executed if not necessary | ||
// debounced, so that it only runs at most once-per-tick | ||
var _proto = Popper.prototype; | ||
// Syncronous and forcefully executed update | ||
// it will always be executed even if not necessary, usually NOT needed | ||
// use Popper#update instead | ||
_proto.forceUpdate = function forceUpdate() { | ||
var _this2 = this; | ||
var _this$state$elements2 = this.state.elements, | ||
referenceElement = _this$state$elements2.reference, | ||
popperElement = _this$state$elements2.popper; // Don't proceed if `reference` or `popper` are not valid elements anymore | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
{ | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
} // Get initial measurements | ||
// these are going to be used to compute the initial popper offsets | ||
// and as cache for any modifier that needs them later | ||
this.state.measures = { | ||
reference: getElementClientRect(referenceElement), | ||
popper: getElementClientRect(popperElement) | ||
}; // Get scrollTop and scrollLeft of the offsetParent | ||
// this will be used in the `computeOffsets` function to properly | ||
// position the popper taking in account the scroll position | ||
// FIXME: right now we only look for a single offsetParent (the popper one) | ||
// but we really want to take in account the reference offsetParent as well | ||
var offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Modifiers have the ability to read the current Popper state, included | ||
// the popper offsets, and modify it to address specifc cases | ||
this.state.reset = false; // Cache the placement in cache to make it available to the modifiers | ||
// modifiers will modify this one (rather than the one in options) | ||
this.state.placement = this.state.options.placement; | ||
this.state.orderedModifiers.forEach(function (modifier) { | ||
return _this2.state.modifiersData[modifier.name] = Object.assign({}, modifier.data); | ||
}); | ||
var __debug_loops__ = 0; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
{ | ||
__debug_loops__ += 1; | ||
if (__debug_loops__ > 100) { | ||
console.error(INFINITE_LOOP_ERROR); | ||
break; | ||
} | ||
} | ||
if (index === 0) { | ||
// Offsets are the actual position the popper needs to have to be | ||
// properly positioned near its reference element | ||
// This is the most basic placement, and will be adjusted by | ||
// the modifiers in the next step | ||
this.state.offsets = { | ||
popper: computeOffsets({ | ||
reference: this.state.measures.reference, | ||
element: this.state.measures.popper, | ||
strategy: 'absolute', | ||
placement: this.state.placement, | ||
scroll: getCommonTotalScroll(referenceElement, this.state.scrollParents.reference, this.state.scrollParents.popper) | ||
}) | ||
}; | ||
} | ||
if (this.state.reset === true) { | ||
this.state.reset = false; | ||
index = -1; | ||
continue; | ||
} | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
if (enabled && typeof fn === 'function') { | ||
this.state = fn(this.state, options); | ||
} | ||
} | ||
}; | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this3 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _ref3 = typeof eventListeners === 'boolean' ? expandToHashMap(eventListeners, ['scroll', 'resize']) : eventListeners, | ||
scroll = _ref3.scroll, | ||
resize = _ref3.resize; | ||
if (scroll) { | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this3.update, { | ||
passive: true | ||
}); | ||
}); | ||
} | ||
if (resize) { | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
passive: true | ||
}); | ||
} | ||
}; | ||
_proto.destroy = function destroy() { | ||
var _this4 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this4.update); | ||
}); // Remove resize event listeners | ||
var window = getWindow(this.state.elements.popper); | ||
window.removeEventListener('resize', this.update); // Run `onDestroy` modifier methods | ||
this.state.orderedModifiers.forEach(function (_ref4) { | ||
var onDestroy = _ref4.onDestroy, | ||
enabled = _ref4.enabled; | ||
return enabled && onDestroy && onDestroy(_this4.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
Popper.defaultModifiers = []; | ||
var getBoundingClientRect = (function (element) { | ||
@@ -436,2 +637,6 @@ return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
var getDocumentElement = (function (element) { | ||
return element.ownerDocument.documentElement; | ||
}); | ||
// clipping (or hiding) overflowing elements with a position different from `initial` | ||
@@ -443,3 +648,3 @@ | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent)), offsetParent); | ||
return offsetParent === win ? getDocumentElement(element) : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent)), offsetParent); | ||
} | ||
@@ -449,3 +654,3 @@ | ||
var win = getWindow(element); | ||
var documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
var documentRect = getElementClientRect(getDocumentElement(element)); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
@@ -457,3 +662,3 @@ documentRect.width = Math.max(documentRect.width, win.innerWidth); | ||
var rectToClientRect = (function (rect) { | ||
return _extends({}, rect, { | ||
return Object.assign({}, rect, { | ||
left: rect.x, | ||
@@ -476,6 +681,9 @@ top: rect.y, | ||
var popperRect = state.measures.popper; | ||
var documentElement = options.boundaryElement.ownerDocument.documentElement; | ||
var documentElement = getDocumentElement(options.boundaryElement); | ||
if (!options.boundaryElement.contains(popperElement)) { | ||
console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
{ | ||
console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
} | ||
return state; | ||
@@ -496,3 +704,3 @@ } | ||
}); | ||
var popperClientRect = rectToClientRect(_extends({}, popperRect, {}, popperOffsets)); | ||
var popperClientRect = rectToClientRect(Object.assign({}, popperRect, {}, popperOffsets)); | ||
state.modifiersData.detectOverflow = { | ||
@@ -610,8 +818,8 @@ top: boundaryClientRect.top - popperClientRect.top, | ||
Object.keys(state.elements).forEach(function (name) { | ||
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? _extends({}, state.styles[name]) : {}); // Set all values to an empty string to unset them | ||
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? Object.assign({}, state.styles[name]) : {}); // Set all values to an empty string to unset them | ||
var style = styleProperties.reduce(function (style, property) { | ||
var _extends2; | ||
var _Object$assign; | ||
return _extends({}, style, (_extends2 = {}, _extends2[String(property)] = '', _extends2)); | ||
return Object.assign({}, style, (_Object$assign = {}, _Object$assign[String(property)] = '', _Object$assign)); | ||
}, {}); // Flow doesn't support to extend this property, but it's the most | ||
@@ -638,3 +846,3 @@ // effective way to apply styles to an HTMLElement | ||
var _getOffsets = getOffsets(_extends({}, measures, { | ||
var _getOffsets = getOffsets(Object.assign({}, measures, { | ||
placement: placement | ||
@@ -681,3 +889,3 @@ })), | ||
var mergePaddingObject = (function (paddingObject) { | ||
return _extends({ | ||
return Object.assign({ | ||
top: 0, | ||
@@ -783,3 +991,4 @@ bottom: 0, | ||
var tetherMax = state.offsets.popper[mainAxis] + referenceRect[len] / 2 - popperRect[len] / 2; | ||
state.offsets.popper[mainAxis] = within(tether ? Math.min(tetherMin, min) : min, offset, tether ? Math.max(tetherMax, max) : max); | ||
var isReferenceLarger = referenceRect[len] > popperRect[len]; | ||
state.offsets.popper[mainAxis] = within(tether ? Math.min(min, isReferenceLarger ? tetherMax : tetherMin) : min, offset, tether ? Math.max(max, isReferenceLarger ? tetherMin : tetherMax) : max); | ||
} | ||
@@ -808,2 +1017,3 @@ | ||
var modifiers = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
detectOverflow: detectOverflow$1, | ||
@@ -817,230 +1027,4 @@ computeStyles: computeStyles$1, | ||
var defaultModifiers = Object.values(modifiers); | ||
var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.'; | ||
Popper.defaultModifiers = Object.values(modifiers); | ||
var areValidElements = function areValidElements(a, b) { | ||
return a instanceof Element && b instanceof Element; | ||
}; | ||
var defaultOptions = { | ||
placement: 'bottom', | ||
eventListeners: { | ||
scroll: true, | ||
resize: true | ||
}, | ||
modifiers: [], | ||
strategy: 'absolute' | ||
}; | ||
var Popper = | ||
/*#__PURE__*/ | ||
function () { | ||
function Popper(reference, popper, options) { | ||
var _this = this; | ||
if (options === void 0) { | ||
options = defaultOptions; | ||
} | ||
_defineProperty(this, "state", { | ||
placement: 'bottom', | ||
orderedModifiers: [], | ||
options: defaultOptions, | ||
modifiersData: {} | ||
}); | ||
_defineProperty(this, "update", microtaskDebounce(function () { | ||
return new Promise(function (success, reject) { | ||
_this.forceUpdate(); | ||
success(_this.state); | ||
}); | ||
})); | ||
// Unwrap `reference` and `popper` elements in case they are | ||
// wrapped by jQuery, otherwise consume them as is | ||
this.state.elements = { | ||
reference: unwrapJqueryElement(reference), | ||
popper: unwrapJqueryElement(popper) | ||
}; | ||
var _this$state$elements = this.state.elements, | ||
referenceElement = _this$state$elements.reference, | ||
popperElement = _this$state$elements.popper; // Store options into state | ||
this.state.options = _extends({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
return; | ||
} | ||
this.state.scrollParents = { | ||
reference: listScrollParents(referenceElement), | ||
popper: listScrollParents(popperElement) | ||
}; // Order `options.modifiers` so that the dependencies are fulfilled | ||
// once the modifiers are executed | ||
this.state.orderedModifiers = orderModifiers([].concat(defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
.map(function (modifier) { | ||
return _extends({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
var name = _ref.name; | ||
return name === modifier.name; | ||
})); | ||
}); // Validate the provided modifiers so that the consumer will get warned | ||
// of one of the custom modifiers is invalid for any reason | ||
{ | ||
validateModifiers(this.state.options.modifiers); | ||
} // Modifiers have the opportunity to execute some arbitrary code before | ||
// the first update cycle is ran, the order of execution will be the same | ||
// defined by the modifier dependencies directive. | ||
// The `onLoad` function may add or alter the options of themselves | ||
this.state.orderedModifiers.forEach(function (_ref2) { | ||
var onLoad = _ref2.onLoad, | ||
enabled = _ref2.enabled; | ||
return enabled && onLoad && onLoad(_this.state); | ||
}); | ||
this.update().then(function () { | ||
// After the first update completed, enable the event listeners | ||
_this.enableEventListeners(_this.state.options.eventListeners); | ||
}); | ||
} // Async and optimistically optimized update | ||
// it will not be executed if not necessary | ||
// debounced, so that it only runs at most once-per-tick | ||
var _proto = Popper.prototype; | ||
// Syncronous and forcefully executed update | ||
// it will always be executed even if not necessary, usually NOT needed | ||
// use Popper#update instead | ||
_proto.forceUpdate = function forceUpdate() { | ||
var _this2 = this; | ||
var _this$state$elements2 = this.state.elements, | ||
referenceElement = _this$state$elements2.reference, | ||
popperElement = _this$state$elements2.popper; // Don't proceed if `reference` or `popper` are not valid elements anymore | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
return; | ||
} // Get initial measurements | ||
// these are going to be used to compute the initial popper offsets | ||
// and as cache for any modifier that needs them later | ||
this.state.measures = { | ||
reference: getElementClientRect(referenceElement), | ||
popper: getElementClientRect(popperElement) | ||
}; // Get scrollTop and scrollLeft of the offsetParent | ||
// this will be used in the `computeOffsets` function to properly | ||
// position the popper taking in account the scroll position | ||
// FIXME: right now we only look for a single offsetParent (the popper one) | ||
// but we really want to take in account the reference offsetParent as well | ||
var offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Modifiers have the ability to read the current Popper state, included | ||
// the popper offsets, and modify it to address specifc cases | ||
this.state.reset = false; // Cache the placement in cache to make it available to the modifiers | ||
// modifiers will modify this one (rather than the one in options) | ||
this.state.placement = this.state.options.placement; | ||
this.state.orderedModifiers.forEach(function (modifier) { | ||
return _this2.state.modifiersData[modifier.name] = _extends({}, modifier.data); | ||
}); | ||
var __debug_loops__ = 0; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
{ | ||
__debug_loops__ += 1; | ||
if (__debug_loops__ > 100) { | ||
console.error(INFINITE_LOOP_ERROR); | ||
break; | ||
} | ||
} | ||
if (index === 0) { | ||
// Offsets are the actual position the popper needs to have to be | ||
// properly positioned near its reference element | ||
// This is the most basic placement, and will be adjusted by | ||
// the modifiers in the next step | ||
this.state.offsets = { | ||
popper: computeOffsets({ | ||
reference: this.state.measures.reference, | ||
element: this.state.measures.popper, | ||
strategy: 'absolute', | ||
placement: this.state.placement, | ||
scroll: getCommonTotalScroll(referenceElement, this.state.scrollParents.reference, this.state.scrollParents.popper) | ||
}) | ||
}; | ||
} | ||
if (this.state.reset === true) { | ||
this.state.reset = false; | ||
index = -1; | ||
continue; | ||
} | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
if (enabled && typeof fn === 'function') { | ||
this.state = fn(this.state, options); | ||
} | ||
} | ||
}; | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this3 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _ref3 = typeof eventListeners === 'boolean' ? expandToHashMap(eventListeners, ['scroll', 'resize']) : eventListeners, | ||
scroll = _ref3.scroll, | ||
resize = _ref3.resize; | ||
if (scroll) { | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this3.update, { | ||
passive: true | ||
}); | ||
}); | ||
} | ||
if (resize) { | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
passive: true | ||
}); | ||
} | ||
}; | ||
_proto.destroy = function destroy() { | ||
var _this4 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this4.update); | ||
}); // Remove resize event listeners | ||
var window = getWindow(this.state.elements.popper); | ||
window.removeEventListener('resize', this.update); // Run `onDestroy` modifier methods | ||
this.state.orderedModifiers.forEach(function (_ref4) { | ||
var onDestroy = _ref4.onDestroy, | ||
enabled = _ref4.enabled; | ||
return enabled && onDestroy && onDestroy(_this4.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
return Popper; | ||
@@ -1047,0 +1031,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Popper=t()}(this,function(){"use strict";function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e){var t=e.ownerDocument;return t?t.defaultView:window}function n(e){return r(e).getComputedStyle(e)}var o=function(e){var t=e.offsetWidth,r=e.offsetHeight,o=e.offsetTop,s=e.offsetLeft,i=function(e){var t=n(e);return{top:parseFloat(t.marginTop)||0,right:parseFloat(t.marginRight)||0,bottom:parseFloat(t.marginBottom)||0,left:parseFloat(t.marginLeft)||0}}(e);return{width:t+i.left+i.right,height:r+i.top+i.bottom,y:o-i.top,x:s-i.left}},s=function(e){return e?e.nodeName.toUpperCase():null},i=function(e){return"HTML"===s(e)?e:e.parentNode||e.host||document.ownerDocument||document.documentElement};function a(e){if(!e)return document.body;if(["HTML","BODY","#document"].includes(e.nodeName.toUpperCase()))return e.ownerDocument.body;if(e instanceof HTMLElement){var t=n(e),r=t.overflow,o=t.overflowX,s=t.overflowY;if(/(auto|scroll|overlay)/.test(r+s+o))return e}return a(i(e))}function f(e,t){void 0===t&&(t=[]);var r=a(e),n="BODY"===s(r),o=n?r.ownerDocument.defaultView:r,c=t.concat(o);return n?c:c.concat(f(i(o)))}function c(e){return e!==r(e)&&e instanceof HTMLElement?{scrollLeft:(t=e).scrollLeft,scrollTop:t.scrollTop}:function(e){var t=r(e);return{scrollLeft:t.pageXOffset,scrollTop:t.pageYOffset}}(e);var t}function u(e){var t=e instanceof HTMLElement?e.offsetParent:null,n=r(e);return"BODY"===s(t)?n:t||n}var l=function(e){return e.reduce(function(e,t){var r=c(t);return e.scrollTop+=r.scrollTop,e.scrollLeft+=r.scrollLeft,e},{scrollTop:0,scrollLeft:0})};function p(e,t,r,n){t.filter(function(e){return!r.includes(e)});var o=u(e),s=t.findIndex(function(e){return e===(n||o)}),i=t.slice(0,-1===s?void 0:s);return l(i)}var d=function(e){return e&&e.jquery?e[0]:e},m=function(e){var t=e.reduce(function(e,t){return e[t.name]=t,e},{});return e.sort(function(e,r){return~function e(r){return t[r]&&t[r].requires?t[r].requires.reduce(function(t,r){return[].concat(t,[r],e(r))},[]):[]}(r.name).indexOf(e.name)?-1:1})},h=function(e){return[].concat(m(e.filter(function(e){return"read"===e.phase})),m(e.filter(function(e){return"main"===e.phase})),m(e.filter(function(e){return"afterMain"===e.phase})),m(e.filter(function(e){return"write"===e.phase})))};function v(e,t){return t.reduce(function(t,r){return t[r]=e,t},{})}var y=function(e){return e.split("-")[0]},b=function(e){return["top","bottom"].includes(e)?"x":"y"},g="top",w="bottom",x="right",O="left",E=[g,w,x,O],L=(E.reduce(function(e,t){return e.concat([t,t+"-start",t+"-end"])},[]),function(e){var t,r=e.reference,n=e.element,o=(e.strategy,e.placement),s=e.scroll,i=o?y(o):null,a=o?function(e){return e.split("-")[1]}(o):null,f=s.scrollTop,c=s.scrollLeft;switch(i){case g:t={x:r.x+r.width/2-n.width/2-c,y:r.y-n.height-f};break;case w:t={x:r.x+r.width/2-n.width/2-c,y:r.y+r.height-f};break;case x:t={x:r.x+r.width-c,y:r.y+r.height/2-n.height/2-f};break;case O:t={x:r.x-n.width-c,y:r.y+r.height/2-n.height/2-f};break;default:t={x:r.x-c,y:r.y-f}}var u=i?b(i):null;if(null!=u){var l="y"===u?"height":"width";switch(a){case"start":t[u]-=r[l]/2-n[l]/2;break;case"end":t[u]+=r[l]/2-n[l]/2}}return t});var M=function(e){return JSON.parse(JSON.stringify(e.getBoundingClientRect()))};function D(e,t){var n=a(e),o=t||u(e);return o===r(e)?e.ownerDocument.documentElement:n.contains(o)?n:D(a(i(n)),o)}var P=function(e){var t=r(e),n=o(e.ownerDocument.documentElement);return n.height=Math.max(n.height,t.innerHeight),n.width=Math.max(n.width,t.innerWidth),n},T=function(e){return t({},e,{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})};var j={name:"detectOverflow",enabled:!0,phase:"read",fn:function(e,r){void 0===r&&(r={boundaryElement:D(e.elements.popper)});var n=e.elements.popper,o=e.elements.reference,s=e.measures.popper,i=r.boundaryElement.ownerDocument.documentElement;if(!r.boundaryElement.contains(n))return console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'),e;var a=i===r.boundaryElement?T(P(i)):M(r.boundaryElement),f=M(o),c=L({reference:f,element:s,strategy:"absolute",placement:e.placement,scroll:{scrollTop:0,scrollLeft:0}}),u=T(t({},s,{},c));return e.modifiersData.detectOverflow={top:a.top-u.top,bottom:u.bottom-a.bottom,left:a.left-u.left,right:u.right-a.right},e},data:{}},S=function(e){switch(e){case"fixed":return"fixed";case"absolute":default:return"absolute"}},k=function(e){var t=e.offsets,r=e.strategy;return!1===e.gpuAcceleration?{top:t.y+"px",left:t.x+"px",position:S(r)}:{top:"0px",left:"0px",transform:"translate3d("+t.x+"px, "+t.y+"px, 0)",position:S(r)}},A=function(e){var t=e.offsets;return e.gpuAcceleration?{top:t.y+"px",left:t.x+"px",position:"absolute"}:{transform:"translate3d("+t.x+"px, "+t.y+"px, 0)",position:"absolute"}};var H={name:"computeStyles",enabled:!0,phase:"afterMain",fn:function(e,t){void 0===t&&(t={});var r=t.gpuAcceleration,n=void 0===r||r;return e.styles={},e.styles.popper=k({offsets:e.offsets.popper,strategy:e.options.strategy,gpuAcceleration:n}),null!=e.offsets.arrow&&(e.styles.arrow=A({offsets:e.offsets.arrow,gpuAcceleration:n})),e}};var q={name:"applyStyles",enabled:!0,phase:"write",fn:function(e){return Object.keys(e.elements).forEach(function(t){var r=e.styles.hasOwnProperty(t)?e.styles[t]:{};Object.assign(e.elements[t].style,r)}),e},onDestroy:function(e){Object.keys(e.elements).forEach(function(r){var n=Object.keys(e.styles.hasOwnProperty(r)?t({},e.styles[r]):{}).reduce(function(e,r){var n;return t({},e,((n={})[String(r)]="",n))},{});Object.assign(e.elements[r].style,n)})},requires:["computeStyles"]};var z={name:"offset",enabled:!0,phase:"main",fn:function(e,r){if(r&&"function"==typeof r.offset){var n=(i=e.placement,a=e.measures,f=r.offset,c=y(i),u=["left","top"].includes(c)?-1:1,l=["top","bottom"].includes(c)?-1:1,p=f(t({},a,{placement:i})),d=p[0],m=p[1],m=((d=(d||0)*u)||0)*l,["left","right"].includes(c)?[d,m]:[m,d]),o=n[0],s=n[1];e.offsets.popper.x+=o,e.offsets.popper.y+=s}var i,a,f,c,u,l,p,d,m;return e}},B={left:"right",right:"left",bottom:"top",top:"bottom"},N=function(e){return e.replace(/left|right|bottom|top/g,function(e){return B[e]})},Y=function(e){return t({top:0,bottom:0,left:0,right:0},e)};var C={name:"flip",enabled:!0,phase:"main",fn:function(e,t){void 0===t&&(t={});var r=e.placement,n=[e.options.placement,N(e.options.placement)],o=t,s=o.behavior,i=void 0===s?n:s,a=o.padding,f=void 0===a?0:a,c=e.modifiersData.detectOverflow,u=e.modifiersData.flip.index,l=Y("number"!=typeof f?f:v(f,E)),p=i[u];if(!p&&r!==e.options.placement)return e.placement=e.options.placement,e.reset=!0,e;if(!p&&r===e.options.placement)return e;var d=y(p),m=c[d]+l[d]<=0;return m?m&&e.placement!==p?(e.placement=p,e.reset=!0,e):e:(e.modifiersData.flip.index+=1,e.reset=!0,e)},requires:["detectOverflow"],data:{index:0}},F=function(e){return"x"===e?"y":"x"},U=function(e,t,r){return Math.max(e,Math.min(t,r))};var J={name:"preventOverflow",enabled:!0,phase:"main",fn:function(e,t){void 0===t&&(t={});var r=t,n=r.mainAxis,o=void 0===n||n,s=r.altAxis,i=void 0!==s&&s,a=r.tether,f=void 0===a||a,c=r.padding,u=void 0===c?0:c,l=e.modifiersData.detectOverflow,p=y(e.placement),d=b(p),m=F(d),h=e.offsets.popper,L=e.measures.reference,M=e.measures.popper,D=Y("number"!=typeof u?u:v(u,E));if(o){var P="y"===d?g:O,T="y"===d?w:x,j="y"===d?"height":"width",S=h[d],k=h[d]+l[P]+D[P],A=h[d]-l[T]-D[T],H=e.offsets.popper[d]-L[j]/2+M[j]/2,q=e.offsets.popper[d]+L[j]/2-M[j]/2;e.offsets.popper[d]=U(f?Math.min(H,k):k,S,f?Math.max(q,A):A)}if(i){var z="x"===d?g:O,B="x"===d?w:x;e.offsets.popper[m]=U(h[m]+l[z]+D[z],h[m],h[m]-l[B]-D[B])}return e},requires:["detectOverflow"]},R=Object.freeze({detectOverflow:j,computeStyles:H,applyStyles:q,offset:z,flip:C,preventOverflow:J}),V=Object.values(R),W=function(e,t){return e instanceof Element&&t instanceof Element},X={placement:"bottom",eventListeners:{scroll:!0,resize:!0},modifiers:[],strategy:"absolute"};return function(){function n(r,n,o){var s,i,a=this;void 0===o&&(o=X),e(this,"state",{placement:"bottom",orderedModifiers:[],options:X,modifiersData:{}}),e(this,"update",(s=function(){return new Promise(function(e,t){a.forceUpdate(),e(a.state)})},i=!1,function(){return new Promise(function(e){if(i)return e();i=!0,Promise.resolve().then(function(){i=!1,e(s())})})})),this.state.elements={reference:d(r),popper:d(n)};var c=this.state.elements,u=c.reference,l=c.popper;this.state.options=t({},X,{},o),W(u,l)&&(this.state.scrollParents={reference:f(u),popper:f(l)},this.state.orderedModifiers=h([].concat(V,this.state.options.modifiers)).map(function(e){return t({},e,{},a.state.options.modifiers.find(function(t){return t.name===e.name}))}),this.state.orderedModifiers.forEach(function(e){var t=e.onLoad;return e.enabled&&t&&t(a.state)}),this.update().then(function(){a.enableEventListeners(a.state.options.eventListeners)}))}var s=n.prototype;return s.forceUpdate=function(){var e=this,r=this.state.elements,n=r.reference,s=r.popper;if(W(n,s)){this.state.measures={reference:o(n),popper:o(s)};c(u(s));this.state.reset=!1,this.state.placement=this.state.options.placement,this.state.orderedModifiers.forEach(function(r){return e.state.modifiersData[r.name]=t({},r.data)});for(var i=0;i<this.state.orderedModifiers.length;i++)if(0===i&&(this.state.offsets={popper:L({reference:this.state.measures.reference,element:this.state.measures.popper,strategy:"absolute",placement:this.state.placement,scroll:p(n,this.state.scrollParents.reference,this.state.scrollParents.popper)})}),!0!==this.state.reset){var a=this.state.orderedModifiers[i],f=a.fn,l=a.enabled,d=a.options;l&&"function"==typeof f&&(this.state=f(this.state,d))}else this.state.reset=!1,i=-1}},s.enableEventListeners=function(e){var t=this,n=this.state.elements,o=(n.reference,n.popper,"boolean"==typeof e?v(e,["scroll","resize"]):e),s=o.scroll,i=o.resize;s&&[].concat(this.state.scrollParents.reference,this.state.scrollParents.popper).forEach(function(e){return e.addEventListener("scroll",t.update,{passive:!0})});i&&r(this.state.elements.popper).addEventListener("resize",this.update,{passive:!0})},s.destroy=function(){var e=this;[].concat(this.state.scrollParents.reference,this.state.scrollParents.popper).forEach(function(t){return t.removeEventListener("scroll",e.update)}),r(this.state.elements.popper).removeEventListener("resize",this.update),this.state.orderedModifiers.forEach(function(t){var r=t.onDestroy;return t.enabled&&r&&r(e.state)})},n}()}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Popper=t()}(this,(function(){"use strict";function e(e){var t=e.ownerDocument;return t?t.defaultView:window}function t(t){return e(t).getComputedStyle(t)}var r=function(e){var r=e.offsetWidth,n=e.offsetHeight,o=e.offsetTop,s=e.offsetLeft,i=function(e){var r=t(e);return{top:parseFloat(r.marginTop)||0,right:parseFloat(r.marginRight)||0,bottom:parseFloat(r.marginBottom)||0,left:parseFloat(r.marginLeft)||0}}(e);return{width:r+i.left+i.right,height:n+i.top+i.bottom,y:o-i.top,x:s-i.left}},n=function(e){return e?e.nodeName.toUpperCase():null},o=function(e){return"HTML"===n(e)?e:e.parentNode||e.host||document.ownerDocument||document.documentElement};function s(e){if(!e)return document.body;if(["HTML","BODY","#document"].includes(e.nodeName.toUpperCase()))return e.ownerDocument.body;if(e instanceof HTMLElement){var r=t(e),n=r.overflow,i=r.overflowX,a=r.overflowY;if(/(auto|scroll|overlay)/.test(n+a+i))return e}return s(o(e))}function i(t,r){void 0===r&&(r=[]);var a=s(t),f="BODY"===n(a),c=f?e(a):a,u=r.concat(c);return f?u:u.concat(i(o(c)))}function a(t){return t!==e(t)&&t instanceof HTMLElement?{scrollLeft:(r=t).scrollLeft,scrollTop:r.scrollTop}:function(t){var r=e(t);return{scrollLeft:r.pageXOffset,scrollTop:r.pageYOffset}}(t);var r}function f(t){var r=t instanceof HTMLElement?t.offsetParent:null,o=e(t);return"BODY"===n(r)?o:r||o}var c=function(e){return e.reduce((function(e,t){var r=a(t);return e.scrollTop+=r.scrollTop,e.scrollLeft+=r.scrollLeft,e}),{scrollTop:0,scrollLeft:0})};function u(e,t,r,n){t.filter((function(e){return!r.includes(e)}));var o=f(e),s=t.findIndex((function(e){return e===(n||o)})),i=t.slice(0,-1===s?void 0:s);return c(i)}var l=function(e){return e&&e.jquery?e[0]:e},p=function(e){var t=e.reduce((function(e,t){return e[t.name]=t,e}),{});return e.sort((function(e,r){return~function e(r){return t[r]&&t[r].requires?t[r].requires.reduce((function(t,r){return[].concat(t,[r],e(r))}),[]):[]}(r.name).indexOf(e.name)?-1:1}))},d=function(e){return[].concat(p(e.filter((function(e){return"read"===e.phase}))),p(e.filter((function(e){return"main"===e.phase}))),p(e.filter((function(e){return"afterMain"===e.phase}))),p(e.filter((function(e){return"write"===e.phase}))))};function m(e,t){return t.reduce((function(t,r){return t[r]=e,t}),{})}var h=function(e){return e.split("-")[0]},v=function(e){return["top","bottom"].includes(e)?"x":"y"},y="top",b="bottom",g="right",x="left",w=[y,b,g,x],O=(w.reduce((function(e,t){return e.concat([t,t+"-start",t+"-end"])}),[]),function(e){var t,r=e.reference,n=e.element,o=(e.strategy,e.placement),s=e.scroll,i=o?h(o):null,a=o?function(e){return e.split("-")[1]}(o):null,f=s.scrollTop,c=s.scrollLeft;switch(i){case y:t={x:r.x+r.width/2-n.width/2-c,y:r.y-n.height-f};break;case b:t={x:r.x+r.width/2-n.width/2-c,y:r.y+r.height-f};break;case g:t={x:r.x+r.width-c,y:r.y+r.height/2-n.height/2-f};break;case x:t={x:r.x-n.width-c,y:r.y+r.height/2-n.height/2-f};break;default:t={x:r.x-c,y:r.y-f}}var u=i?v(i):null;if(null!=u){var l="y"===u?"height":"width";switch(a){case"start":t[u]-=r[l]/2-n[l]/2;break;case"end":t[u]+=r[l]/2-n[l]/2}}return t});var E=function(e,t){return e instanceof Element&&t instanceof Element},L={placement:"bottom",eventListeners:{scroll:!0,resize:!0},modifiers:[],strategy:"absolute"},M=function(){function t(e,t,r){var n,o,s=this;void 0===r&&(r=L),this.state={placement:"bottom",orderedModifiers:[],options:L,modifiersData:{}},this.update=(n=function(){return new Promise((function(e,t){s.forceUpdate(),e(s.state)}))},o=!1,function(){return new Promise((function(e){if(o)return e();o=!0,Promise.resolve().then((function(){o=!1,e(n())}))}))}),this.state.elements={reference:l(e),popper:l(t)};var a=this.state.elements,f=a.reference,c=a.popper;this.state.options=Object.assign({},L,{},r),E(f,c)&&(this.state.scrollParents={reference:i(f),popper:i(c)},this.state.orderedModifiers=d([].concat(this.constructor.defaultModifiers,this.state.options.modifiers)).map((function(e){return Object.assign({},e,{},s.state.options.modifiers.find((function(t){return t.name===e.name})))})),this.state.orderedModifiers.forEach((function(e){var t=e.onLoad;return e.enabled&&t&&t(s.state)})),this.update().then((function(){s.enableEventListeners(s.state.options.eventListeners)})))}var n=t.prototype;return n.forceUpdate=function(){var e=this,t=this.state.elements,n=t.reference,o=t.popper;if(E(n,o)){this.state.measures={reference:r(n),popper:r(o)};a(f(o));this.state.reset=!1,this.state.placement=this.state.options.placement,this.state.orderedModifiers.forEach((function(t){return e.state.modifiersData[t.name]=Object.assign({},t.data)}));for(var s=0;s<this.state.orderedModifiers.length;s++)if(0===s&&(this.state.offsets={popper:O({reference:this.state.measures.reference,element:this.state.measures.popper,strategy:"absolute",placement:this.state.placement,scroll:u(n,this.state.scrollParents.reference,this.state.scrollParents.popper)})}),!0!==this.state.reset){var i=this.state.orderedModifiers[s],c=i.fn,l=i.enabled,p=i.options;l&&"function"==typeof c&&(this.state=c(this.state,p))}else this.state.reset=!1,s=-1}},n.enableEventListeners=function(t){var r=this,n=this.state.elements,o=(n.reference,n.popper,"boolean"==typeof t?m(t,["scroll","resize"]):t),s=o.scroll,i=o.resize;s&&[].concat(this.state.scrollParents.reference,this.state.scrollParents.popper).forEach((function(e){return e.addEventListener("scroll",r.update,{passive:!0})}));i&&e(this.state.elements.popper).addEventListener("resize",this.update,{passive:!0})},n.destroy=function(){var t=this;[].concat(this.state.scrollParents.reference,this.state.scrollParents.popper).forEach((function(e){return e.removeEventListener("scroll",t.update)})),e(this.state.elements.popper).removeEventListener("resize",this.update),this.state.orderedModifiers.forEach((function(e){var r=e.onDestroy;return e.enabled&&r&&r(t.state)}))},t}();M.defaultModifiers=[];var j=function(e){return JSON.parse(JSON.stringify(e.getBoundingClientRect()))},D=function(e){return e.ownerDocument.documentElement};function T(t,r){var n=s(t),i=r||f(t);return i===e(t)?D(t):n.contains(i)?n:T(s(o(n)),i)}var P=function(t){var n=e(t),o=r(D(t));return o.height=Math.max(o.height,n.innerHeight),o.width=Math.max(o.width,n.innerWidth),o},S=function(e){return Object.assign({},e,{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})};var k={name:"detectOverflow",enabled:!0,phase:"read",fn:function(e,t){void 0===t&&(t={boundaryElement:T(e.elements.popper)});var r=e.elements.popper,n=e.elements.reference,o=e.measures.popper,s=D(t.boundaryElement);if(!t.boundaryElement.contains(r))return e;var i=s===t.boundaryElement?S(P(s)):j(t.boundaryElement),a=j(n),f=O({reference:a,element:o,strategy:"absolute",placement:e.placement,scroll:{scrollTop:0,scrollLeft:0}}),c=S(Object.assign({},o,{},f));return e.modifiersData.detectOverflow={top:i.top-c.top,bottom:c.bottom-i.bottom,left:i.left-c.left,right:c.right-i.right},e},data:{}},A=function(e){switch(e){case"fixed":return"fixed";case"absolute":default:return"absolute"}},H=function(e){var t=e.offsets,r=e.strategy;return!1===e.gpuAcceleration?{top:t.y+"px",left:t.x+"px",position:A(r)}:{top:"0px",left:"0px",transform:"translate3d("+t.x+"px, "+t.y+"px, 0)",position:A(r)}},q=function(e){var t=e.offsets;return e.gpuAcceleration?{top:t.y+"px",left:t.x+"px",position:"absolute"}:{transform:"translate3d("+t.x+"px, "+t.y+"px, 0)",position:"absolute"}};var z={name:"computeStyles",enabled:!0,phase:"afterMain",fn:function(e,t){void 0===t&&(t={});var r=t.gpuAcceleration,n=void 0===r||r;return e.styles={},e.styles.popper=H({offsets:e.offsets.popper,strategy:e.options.strategy,gpuAcceleration:n}),null!=e.offsets.arrow&&(e.styles.arrow=q({offsets:e.offsets.arrow,gpuAcceleration:n})),e}};var B={name:"applyStyles",enabled:!0,phase:"write",fn:function(e){return Object.keys(e.elements).forEach((function(t){var r=e.styles.hasOwnProperty(t)?e.styles[t]:{};Object.assign(e.elements[t].style,r)})),e},onDestroy:function(e){Object.keys(e.elements).forEach((function(t){var r=Object.keys(e.styles.hasOwnProperty(t)?Object.assign({},e.styles[t]):{}).reduce((function(e,t){var r;return Object.assign({},e,((r={})[String(t)]="",r))}),{});Object.assign(e.elements[t].style,r)}))},requires:["computeStyles"]};var N={name:"offset",enabled:!0,phase:"main",fn:function(e,t){if(t&&"function"==typeof t.offset){var r=(s=e.placement,i=e.measures,a=t.offset,f=h(s),c=["left","top"].includes(f)?-1:1,u=["top","bottom"].includes(f)?-1:1,l=a(Object.assign({},i,{placement:s})),p=l[0],d=l[1],d=((p=(p||0)*c)||0)*u,["left","right"].includes(f)?[p,d]:[d,p]),n=r[0],o=r[1];e.offsets.popper.x+=n,e.offsets.popper.y+=o}var s,i,a,f,c,u,l,p,d;return e}},Y={left:"right",right:"left",bottom:"top",top:"bottom"},C=function(e){return e.replace(/left|right|bottom|top/g,(function(e){return Y[e]}))},F=function(e){return Object.assign({top:0,bottom:0,left:0,right:0},e)};var U={name:"flip",enabled:!0,phase:"main",fn:function(e,t){void 0===t&&(t={});var r=e.placement,n=[e.options.placement,C(e.options.placement)],o=t,s=o.behavior,i=void 0===s?n:s,a=o.padding,f=void 0===a?0:a,c=e.modifiersData.detectOverflow,u=e.modifiersData.flip.index,l=F("number"!=typeof f?f:m(f,w)),p=i[u];if(!p&&r!==e.options.placement)return e.placement=e.options.placement,e.reset=!0,e;if(!p&&r===e.options.placement)return e;var d=h(p),v=c[d]+l[d]<=0;return v?v&&e.placement!==p?(e.placement=p,e.reset=!0,e):e:(e.modifiersData.flip.index+=1,e.reset=!0,e)},requires:["detectOverflow"],data:{index:0}},_=function(e){return"x"===e?"y":"x"},J=function(e,t,r){return Math.max(e,Math.min(t,r))};var R={name:"preventOverflow",enabled:!0,phase:"main",fn:function(e,t){void 0===t&&(t={});var r=t,n=r.mainAxis,o=void 0===n||n,s=r.altAxis,i=void 0!==s&&s,a=r.tether,f=void 0===a||a,c=r.padding,u=void 0===c?0:c,l=e.modifiersData.detectOverflow,p=h(e.placement),d=v(p),O=_(d),E=e.offsets.popper,L=e.measures.reference,M=e.measures.popper,j=F("number"!=typeof u?u:m(u,w));if(o){var D="y"===d?y:x,T="y"===d?b:g,P="y"===d?"height":"width",S=E[d],k=E[d]+l[D]+j[D],A=E[d]-l[T]-j[T],H=e.offsets.popper[d]-L[P]/2+M[P]/2,q=e.offsets.popper[d]+L[P]/2-M[P]/2,z=L[P]>M[P];e.offsets.popper[d]=J(f?Math.min(k,z?q:H):k,S,f?Math.max(A,z?H:q):A)}if(i){var B="x"===d?y:x,N="x"===d?b:g;e.offsets.popper[O]=J(E[O]+l[B]+j[B],E[O],E[O]-l[N]-j[N])}return e},requires:["detectOverflow"]},W=Object.freeze({__proto__:null,detectOverflow:k,computeStyles:z,applyStyles:B,offset:N,flip:U,preventOverflow:R});return M.defaultModifiers=Object.values(W),M})); | ||
//# sourceMappingURL=popper.min.js.map |
import getScrollParent from './getScrollParent'; | ||
import getOffsetParent from './getOffsetParent'; | ||
import getParentNode from './getParentNode'; | ||
import getWindow from './getWindow'; // A "clipping parent" is a scrolling container with the characteristic of | ||
import getWindow from './getWindow'; | ||
import getDocumentElement from './getDocumentElement'; // A "clipping parent" is a scrolling container with the characteristic of | ||
// clipping (or hiding) overflowing elements with a position different from `initial` | ||
@@ -11,3 +12,3 @@ | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent)), offsetParent); | ||
return offsetParent === win ? getDocumentElement(element) : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent)), offsetParent); | ||
} |
import getElementClientRect from './getElementClientRect'; | ||
import getWindow from './getWindow'; | ||
import getDocumentElement from './getDocumentElement'; | ||
export default (function (element) { | ||
var win = getWindow(element); | ||
var documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
var documentRect = getElementClientRect(getDocumentElement(element)); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
@@ -7,0 +8,0 @@ documentRect.width = Math.max(documentRect.width, win.innerWidth); |
import getScrollParent from './getScrollParent'; | ||
import getParentNode from './getParentNode'; | ||
import getNodeName from './getNodeName'; | ||
import getWindow from './getWindow'; | ||
export default function listScrollParents(element, list) { | ||
@@ -11,5 +12,5 @@ if (list === void 0) { | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var target = isBody ? getWindow(scrollParent) : scrollParent; | ||
var updatedList = list.concat(target); | ||
return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
} |
@@ -1,5 +0,1 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
// DOM Utils | ||
@@ -19,7 +15,4 @@ import getElementClientRect from './dom-utils/getElementClientRect'; | ||
import debounce from './utils/debounce'; | ||
import validateModifiers from './utils/validateModifiers'; // Default modifiers | ||
import * as modifiers from './modifiers/index'; | ||
var defaultModifiers = Object.values(modifiers); | ||
var INVALID_ELEMENT_ERROR = 'Popper: Invalid `%s` argument provided to Popper, it must be either a valid DOM element or a jQuery-wrapped DOM element, you provided `%s`'; | ||
import validateModifiers from './utils/validateModifiers'; | ||
var INVALID_ELEMENT_ERROR = 'Popper: Invalid reference or popper argument provided to Popper, they must be either a valid DOM element or a jQuery-wrapped DOM element.'; | ||
var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.'; | ||
@@ -51,3 +44,3 @@ | ||
_defineProperty(this, "state", { | ||
this.state = { | ||
placement: 'bottom', | ||
@@ -57,5 +50,4 @@ orderedModifiers: [], | ||
modifiersData: {} | ||
}); | ||
_defineProperty(this, "update", debounce(function () { | ||
}; | ||
this.update = debounce(function () { | ||
return new Promise(function (success, reject) { | ||
@@ -66,4 +58,3 @@ _this.forceUpdate(); | ||
}); | ||
})); | ||
}); | ||
// Unwrap `reference` and `popper` elements in case they are | ||
@@ -79,5 +70,9 @@ // wrapped by jQuery, otherwise consume them as is | ||
this.state.options = _extends({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
this.state.options = Object.assign({}, defaultOptions, {}, options); // Don't proceed if `reference` or `popper` are invalid elements | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
@@ -92,5 +87,5 @@ } | ||
this.state.orderedModifiers = orderModifiers([].concat(defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
this.state.orderedModifiers = orderModifiers([].concat(this.constructor.defaultModifiers, this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
.map(function (modifier) { | ||
return _extends({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
return Object.assign({}, modifier, {}, _this.state.options.modifiers.find(function (_ref) { | ||
var name = _ref.name; | ||
@@ -137,2 +132,6 @@ return name === modifier.name; | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error(INVALID_ELEMENT_ERROR); | ||
} | ||
return; | ||
@@ -161,3 +160,3 @@ } // Get initial measurements | ||
this.state.orderedModifiers.forEach(function (modifier) { | ||
return _this2.state.modifiersData[modifier.name] = _extends({}, modifier.data); | ||
return _this2.state.modifiersData[modifier.name] = Object.assign({}, modifier.data); | ||
}); | ||
@@ -259,2 +258,3 @@ var __debug_loops__ = 0; | ||
export { Popper as default }; | ||
export { Popper as default }; | ||
Popper.defaultModifiers = []; |
@@ -1,3 +0,1 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
// This modifier takes the styles prepared by the `computeStyles` modifier | ||
@@ -17,8 +15,8 @@ // and applies them to the HTMLElements such as popper and arrow | ||
Object.keys(state.elements).forEach(function (name) { | ||
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? _extends({}, state.styles[name]) : {}); // Set all values to an empty string to unset them | ||
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? Object.assign({}, state.styles[name]) : {}); // Set all values to an empty string to unset them | ||
var style = styleProperties.reduce(function (style, property) { | ||
var _extends2; | ||
var _Object$assign; | ||
return _extends({}, style, (_extends2 = {}, _extends2[String(property)] = '', _extends2)); | ||
return Object.assign({}, style, (_Object$assign = {}, _Object$assign[String(property)] = '', _Object$assign)); | ||
}, {}); // Flow doesn't support to extend this property, but it's the most | ||
@@ -25,0 +23,0 @@ // effective way to apply styles to an HTMLElement |
@@ -1,6 +0,5 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import getBoundingClientRect from '../dom-utils/getBoundingClientRect'; | ||
import getClippingParent from '../dom-utils/getClippingParent'; | ||
import getDocumentRect from '../dom-utils/getDocumentRect'; | ||
import getDocumentElement from '../dom-utils/getDocumentElement'; | ||
import computeOffsets from '../utils/computeOffsets'; | ||
@@ -18,6 +17,9 @@ import rectToClientRect from '../utils/rectToClientRect'; | ||
var popperRect = state.measures.popper; | ||
var documentElement = options.boundaryElement.ownerDocument.documentElement; | ||
var documentElement = getDocumentElement(options.boundaryElement); | ||
if (!options.boundaryElement.contains(popperElement)) { | ||
console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
if (process.env.NODE_ENV !== "production") { | ||
console.error('Popper: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
} | ||
return state; | ||
@@ -38,3 +40,3 @@ } | ||
}); | ||
var popperClientRect = rectToClientRect(_extends({}, popperRect, {}, popperOffsets)); | ||
var popperClientRect = rectToClientRect(Object.assign({}, popperRect, {}, popperOffsets)); | ||
state.modifiersData.detectOverflow = { | ||
@@ -41,0 +43,0 @@ top: boundaryClientRect.top - popperClientRect.top, |
@@ -1,3 +0,1 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import getBasePlacement from '../utils/getBasePlacement'; | ||
@@ -9,3 +7,3 @@ export function distanceAndSkiddingToXY(placement, measures, getOffsets) { | ||
var _getOffsets = getOffsets(_extends({}, measures, { | ||
var _getOffsets = getOffsets(Object.assign({}, measures, { | ||
placement: placement | ||
@@ -12,0 +10,0 @@ })), |
@@ -40,3 +40,4 @@ import { basePlacements, top, left, right, bottom } from '../enums'; | ||
var tetherMax = state.offsets.popper[mainAxis] + referenceRect[len] / 2 - popperRect[len] / 2; | ||
state.offsets.popper[mainAxis] = within(tether ? Math.min(tetherMin, min) : min, offset, tether ? Math.max(tetherMax, max) : max); | ||
var isReferenceLarger = referenceRect[len] > popperRect[len]; | ||
state.offsets.popper[mainAxis] = within(tether ? Math.min(min, isReferenceLarger ? tetherMax : tetherMin) : min, offset, tether ? Math.max(max, isReferenceLarger ? tetherMin : tetherMax) : max); | ||
} | ||
@@ -43,0 +44,0 @@ |
@@ -1,5 +0,3 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
export default (function (paddingObject) { | ||
return _extends({ | ||
return Object.assign({ | ||
top: 0, | ||
@@ -6,0 +4,0 @@ bottom: 0, |
@@ -1,5 +0,3 @@ | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
export default (function (rect) { | ||
return _extends({}, rect, { | ||
return Object.assign({}, rect, { | ||
left: rect.x, | ||
@@ -6,0 +4,0 @@ top: rect.y, |
{ | ||
"name": "@popperjs/core", | ||
"version": "2.0.0-next.8", | ||
"version": "2.0.0-next.9", | ||
"description": "A kickass library used to manage poppers in web applications", | ||
@@ -8,2 +8,3 @@ "main": "dist/cjs/popper.js", | ||
"module": "lib/index.js", | ||
"unpkg": "dist/umd/popper.min.js", | ||
"author": "Federico Zivolo <fzivolo@quid.com>", | ||
@@ -22,3 +23,4 @@ "license": "MIT", | ||
"build:bundles": "rollup -c rollup.config.js", | ||
"build:flow": "flow-copy-source src dist/cjs --ignore '{__mocks__/*,*.test}.js'" | ||
"build:flow": "flow-copy-source src dist/cjs --ignore '{__mocks__/*,*.test}.js'", | ||
"prepare": "yarn build" | ||
}, | ||
@@ -47,3 +49,15 @@ "files": [ | ||
"@babel/plugin-transform-flow-strip-types", | ||
"@babel/plugin-proposal-class-properties", | ||
[ | ||
"@babel/plugin-proposal-object-rest-spread", | ||
{ | ||
"loose": true, | ||
"useBuiltIns": true | ||
} | ||
], | ||
[ | ||
"@babel/plugin-proposal-class-properties", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
"dev-expression" | ||
@@ -82,7 +96,7 @@ ], | ||
"raf": "^3.4.1", | ||
"rollup": "^0.67.0", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"rollup": "^1.27.0", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-bundle-size": "^1.0.2", | ||
"rollup-plugin-replace": "^2.1.0", | ||
"rollup-plugin-terser": "^3.0.0", | ||
"rollup-plugin-terser": "^5.1.2", | ||
"serve": "^10.0.2" | ||
@@ -89,0 +103,0 @@ }, |
@@ -17,10 +17,24 @@ <p align="center"> | ||
### 1. Package Manager | ||
```bash | ||
# With Yarn package mnager | ||
yarn add @popper/core@next | ||
# With Yarn | ||
yarn add @popperjs/core@next | ||
# With npm | ||
npm install @popper/core@next | ||
npm install --save @popperjs/core@next | ||
``` | ||
### 2. CDN | ||
```html | ||
<script src="https://unpkg.com/@popperjs/core"></script> | ||
``` | ||
### 3. Direct Download | ||
Manually downloading the library is not recommended because you lose versioning management that the unpkg CDN or npm/Yarn provide. | ||
You don't receive fix/feat updates easily and will lag behind the website documentation, among other issues, and this quickly becomes an unmaintainable way to manage dependencies. | ||
## Usage | ||
@@ -37,2 +51,19 @@ | ||
## Distribution targets | ||
Popper is distributed in 3 different versions: | ||
The 3 versions are: | ||
- `popper`: includes all the modifiers (features); | ||
- `popper-lite`: includes only the minimum amount of modifiers to provide the basic functionality; | ||
- `popper-minimal`: doesn't include any modifier, you must import them seprately; | ||
Below you can find the size of each version, minified and compressed with | ||
the [Brotli compression algorithm](https://medium.com/groww-engineering/enable-brotli-compression-in-webpack-with-fallback-to-gzip-397a57cf9fc6): | ||
![](https://badge-size.now.sh/https://unpkg.com/@popperjs/core/dist/umd/popper.min.js?compression=brotli&label=popper) | ||
![](https://badge-size.now.sh/https://unpkg.com/@popperjs/core/dist/umd/popper-lite.min.js?compression=brotli&label=popper-lite) | ||
![](https://badge-size.now.sh/https://unpkg.com/@popperjs/core/dist/umd/popper-minimal.min.js?compression=brotli&label=popper-minimal) | ||
## Hacking the library | ||
@@ -39,0 +70,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
914458
129
6542
102
6