@popperjs/core
Advanced tools
Comparing version 2.0.0-next.6 to 2.0.0-next.7
@@ -18,38 +18,22 @@ 'use strict'; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return keys; | ||
} | ||
return target; | ||
}; | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
return _extends.apply(this, arguments); | ||
} | ||
function getWindow(node) { | ||
const ownerDocument = node.ownerDocument; | ||
var ownerDocument = node.ownerDocument; | ||
return ownerDocument ? ownerDocument.defaultView : window; | ||
@@ -62,24 +46,24 @@ } | ||
var getElementMargins = (element => { | ||
var getElementMargins = (function (element) { | ||
// get the element margins, we need them to properly align the popper | ||
const styles = getComputedStyle(element); | ||
const top = parseFloat(styles.marginTop) || 0; | ||
const right = parseFloat(styles.marginRight) || 0; | ||
const bottom = parseFloat(styles.marginBottom) || 0; | ||
const left = parseFloat(styles.marginLeft) || 0; | ||
var styles = getComputedStyle(element); | ||
var top = parseFloat(styles.marginTop) || 0; | ||
var right = parseFloat(styles.marginRight) || 0; | ||
var bottom = parseFloat(styles.marginBottom) || 0; | ||
var left = parseFloat(styles.marginLeft) || 0; | ||
return { | ||
top, | ||
right, | ||
bottom, | ||
left | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left | ||
}; | ||
}); | ||
var getElementClientRect = (element => { | ||
var getElementClientRect = (function (element) { | ||
// get the basic client rect, it doesn't include margins | ||
const width = element.offsetWidth; | ||
const height = element.offsetHeight; | ||
const top = element.offsetTop; | ||
const left = element.offsetLeft; | ||
const margins = getElementMargins(element); | ||
var width = element.offsetWidth; | ||
var height = element.offsetHeight; | ||
var top = element.offsetTop; | ||
var left = element.offsetLeft; | ||
var margins = getElementMargins(element); | ||
return { | ||
@@ -93,4 +77,8 @@ width: width + margins.left + margins.right, | ||
var getParentNode = (element => { | ||
if (element.nodeName === 'HTML') { | ||
var getNodeName = (function (element) { | ||
return element ? element.nodeName.toUpperCase() : null; | ||
}); | ||
var getParentNode = (function (element) { | ||
if (getNodeName(element) === 'HTML') { | ||
// DocumentElement detectedF | ||
@@ -119,7 +107,6 @@ return element; | ||
// Firefox want us to check `-x` and `-y` variations as well | ||
const { | ||
overflow, | ||
overflowX, | ||
overflowY | ||
} = getComputedStyle(node); | ||
var _getComputedStyle = getComputedStyle(node), | ||
overflow = _getComputedStyle.overflow, | ||
overflowX = _getComputedStyle.overflowX, | ||
overflowY = _getComputedStyle.overflowY; | ||
@@ -134,7 +121,11 @@ if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) { | ||
function listScrollParents(element, list = []) { | ||
const scrollParent = getScrollParent(element); | ||
const isBody = scrollParent.nodeName === 'BODY'; | ||
const target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
const updatedList = list.concat(target); | ||
function listScrollParents(element, list) { | ||
if (list === void 0) { | ||
list = []; | ||
} | ||
var scrollParent = getScrollParent(element); | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var updatedList = list.concat(target); | ||
return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
@@ -144,8 +135,8 @@ } | ||
function getWindowScroll(node) { | ||
const win = getWindow(node); | ||
const scrollLeft = win.pageXOffset; | ||
const scrollTop = win.pageYOffset; | ||
var win = getWindow(node); | ||
var scrollLeft = win.pageXOffset; | ||
var scrollTop = win.pageYOffset; | ||
return { | ||
scrollLeft, | ||
scrollTop | ||
scrollLeft: scrollLeft, | ||
scrollTop: scrollTop | ||
}; | ||
@@ -170,6 +161,6 @@ } | ||
function getOffsetParent(element) { | ||
const offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
const window = getWindow(element); | ||
var offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
var window = getWindow(element); | ||
if (offsetParent && offsetParent.nodeName && offsetParent.nodeName.toUpperCase() === 'BODY') { | ||
if (getNodeName(offsetParent) === 'BODY') { | ||
return window; | ||
@@ -181,11 +172,13 @@ } | ||
const sumScroll = scrollParents => scrollParents.reduce((scroll, scrollParent) => { | ||
const nodeScroll = getElementScroll(scrollParent); | ||
scroll.scrollTop += nodeScroll.scrollTop; | ||
scroll.scrollLeft += nodeScroll.scrollLeft; | ||
return scroll; | ||
}, { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
}); | ||
var sumScroll = function sumScroll(scrollParents) { | ||
return scrollParents.reduce(function (scroll, scrollParent) { | ||
var nodeScroll = getElementScroll(scrollParent); | ||
scroll.scrollTop += nodeScroll.scrollTop; | ||
scroll.scrollLeft += nodeScroll.scrollLeft; | ||
return scroll; | ||
}, { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
}); | ||
}; | ||
@@ -195,18 +188,24 @@ function getCommonTotalScroll(reference, referenceScrollParents, popperScrollParents, limiter) { | ||
// it because it wouldn't add anything to the equation (they nulllify themselves) | ||
const nonCommonReference = referenceScrollParents.filter(node => !popperScrollParents.includes(node)); // we then want to pick any scroll offset except for the one of the offsetParent | ||
var nonCommonReference = referenceScrollParents.filter(function (node) { | ||
return !popperScrollParents.includes(node); | ||
}); // we then want to pick any scroll offset except for the one of the offsetParent | ||
// not sure why but that's how I got it working 😅 | ||
// TODO: improve this comment with proper explanation | ||
const offsetParent = getOffsetParent(reference); | ||
const index = referenceScrollParents.findIndex(node => node === (limiter || offsetParent)); | ||
const scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
var offsetParent = getOffsetParent(reference); | ||
var index = referenceScrollParents.findIndex(function (node) { | ||
return node === (limiter || offsetParent); | ||
}); | ||
var scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
return sumScroll(scrollParents); | ||
} | ||
var unwrapJqueryElement = (element => element && element.jquery ? element[0] : element); | ||
var unwrapJqueryElement = (function (element) { | ||
return element && element.jquery ? element[0] : element; | ||
}); | ||
// source: https://stackoverflow.com/questions/49875255 | ||
const order = modifiers => { | ||
var order = function order(modifiers) { | ||
// indexed by name | ||
const mapped = modifiers.reduce((mem, i) => { | ||
var mapped = modifiers.reduce(function (mem, i) { | ||
mem[i.name] = i; | ||
@@ -216,5 +215,5 @@ return mem; | ||
const inherited = i => { | ||
return mapped[i].requires ? mapped[i].requires.reduce((mem, i) => { | ||
return [...mem, i, ...inherited(i)]; | ||
var inherited = function inherited(i) { | ||
return mapped[i].requires ? mapped[i].requires.reduce(function (mem, i) { | ||
return [].concat(mem, [i], inherited(i)); | ||
}, []) : []; | ||
@@ -224,3 +223,3 @@ }; // order ... | ||
const ordered = modifiers.sort((a, b) => { | ||
var ordered = modifiers.sort(function (a, b) { | ||
return !!~inherited(b.name).indexOf(a.name) ? -1 : 1; | ||
@@ -231,11 +230,17 @@ }); | ||
var orderModifiers = (modifiers => [...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'read')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'main')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'afterMain')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'write'))]); | ||
var orderModifiers = (function (modifiers) { | ||
return [].concat(order(modifiers.filter(function (_ref) { | ||
var phase = _ref.phase; | ||
return phase === 'read'; | ||
})), order(modifiers.filter(function (_ref2) { | ||
var phase = _ref2.phase; | ||
return phase === 'main'; | ||
})), order(modifiers.filter(function (_ref3) { | ||
var phase = _ref3.phase; | ||
return phase === 'afterMain'; | ||
})), order(modifiers.filter(function (_ref4) { | ||
var phase = _ref4.phase; | ||
return phase === 'write'; | ||
}))); | ||
}); | ||
@@ -249,4 +254,4 @@ // Expands the eventListeners value to an object containing the | ||
// false, false => false, false | ||
var expandEventListeners = (eventListeners => { | ||
const fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
var expandEventListeners = (function (eventListeners) { | ||
var fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
return { | ||
@@ -258,39 +263,46 @@ scroll: typeof eventListeners.scroll === 'boolean' ? eventListeners.scroll : fallbackValue, | ||
var getBasePlacement = (placement => placement.split('-')[0]); | ||
var getBasePlacement = (function (placement) { | ||
return placement.split('-')[0]; | ||
}); | ||
var getVariationPlacement = (placement => placement.split('-')[1]); | ||
var getVariationPlacement = (function (placement) { | ||
return placement.split('-')[1]; | ||
}); | ||
var getMainAxisFromPlacement = (placement => ['top', 'bottom'].includes(placement) ? 'x' : 'y'); | ||
var getMainAxisFromPlacement = (function (placement) { | ||
return ['top', 'bottom'].includes(placement) ? 'x' : 'y'; | ||
}); | ||
var getAltAxis = (axis => axis === 'x' ? 'y' : 'x'); | ||
var getAltAxis = (function (axis) { | ||
return axis === 'x' ? 'y' : 'x'; | ||
}); | ||
const top = 'top'; | ||
const bottom = 'bottom'; | ||
const right = 'right'; | ||
const left = 'left'; | ||
const basePlacements = [top, bottom, right, left]; | ||
const start = 'start'; | ||
const end = 'end'; | ||
const placements = basePlacements.reduce((acc, placement) => acc.concat([placement, `${placement}-${start}`, `${placement}-${end}`]), []); // modifiers that need to read the DOM | ||
var top = 'top'; | ||
var bottom = 'bottom'; | ||
var right = 'right'; | ||
var left = 'left'; | ||
var basePlacements = [top, bottom, right, left]; | ||
var start = 'start'; | ||
var end = 'end'; | ||
var placements = basePlacements.reduce(function (acc, placement) { | ||
return acc.concat([placement, placement + "-" + start, placement + "-" + end]); | ||
}, []); // modifiers that need to read the DOM | ||
const read = 'read'; // pure-logic modifiers | ||
var read = 'read'; // pure-logic modifiers | ||
const main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
var main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
const write = 'write'; | ||
var write = 'write'; | ||
var computeOffsets = (({ | ||
reference, | ||
element, | ||
strategy, | ||
placement, | ||
scroll | ||
}) => { | ||
const basePlacement = placement ? getBasePlacement(placement) : null; | ||
const variationPlacement = placement ? getVariationPlacement(placement) : null; | ||
const { | ||
scrollTop, | ||
scrollLeft | ||
} = scroll; | ||
let offsets; | ||
var computeOffsets = (function (_ref) { | ||
var reference = _ref.reference, | ||
element = _ref.element, | ||
strategy = _ref.strategy, | ||
placement = _ref.placement, | ||
scroll = _ref.scroll; | ||
var basePlacement = placement ? getBasePlacement(placement) : null; | ||
var variationPlacement = placement ? getVariationPlacement(placement) : null; | ||
var scrollTop = scroll.scrollTop, | ||
scrollLeft = scroll.scrollLeft; | ||
var offsets; | ||
@@ -333,6 +345,6 @@ switch (basePlacement) { | ||
const mainAxis = placement ? getMainAxisFromPlacement(placement) : null; | ||
const altAxis = mainAxis ? getAltAxis(mainAxis) : null; | ||
const len = altAxis === 'x' ? 'width' : 'height'; | ||
const axis = [right, left].includes(basePlacement) ? mainAxis : altAxis; | ||
var mainAxis = placement ? getMainAxisFromPlacement(placement) : null; | ||
var altAxis = mainAxis ? getAltAxis(mainAxis) : null; | ||
var len = altAxis === 'x' ? 'width' : 'height'; | ||
var axis = [right, left].includes(basePlacement) ? mainAxis : altAxis; | ||
@@ -356,28 +368,38 @@ if (axis != null) { | ||
var format = ((str, ...args) => [...args].reduce((p, c) => p.replace(/%s/, c), str)); | ||
var format = (function (str) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return [].concat(args).reduce(function (p, c) { | ||
return p.replace(/%s/, c); | ||
}, str); | ||
}); | ||
function microtaskDebounce(fn) { | ||
let called = false; | ||
return () => new Promise(resolve => { | ||
if (called) { | ||
return resolve(); | ||
} | ||
var called = false; | ||
return function () { | ||
return new Promise(function (resolve) { | ||
if (called) { | ||
return resolve(); | ||
} | ||
called = true; | ||
Promise.resolve().then(() => { | ||
called = false; | ||
resolve(fn()); | ||
called = true; | ||
Promise.resolve().then(function () { | ||
called = false; | ||
resolve(fn()); | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
const ERROR_MESSAGE = 'PopperJS: modifier "%s" provided an invalid %s property, expected %s but got %s'; | ||
const VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'onLoad', 'requires', 'options']; | ||
var validateModifiers = (modifiers => { | ||
modifiers.forEach(modifier => { | ||
Object.keys(modifier).forEach(key => { | ||
var ERROR_MESSAGE = 'PopperJS: modifier "%s" provided an invalid %s property, expected %s but got %s'; | ||
var VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'onLoad', 'requires', 'options']; | ||
var validateModifiers = (function (modifiers) { | ||
modifiers.forEach(function (modifier) { | ||
Object.keys(modifier).forEach(function (key) { | ||
switch (key) { | ||
case 'name': | ||
if (typeof modifier.name !== 'string') { | ||
console.error(format(ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', `"${String(modifier.name)}"`)); | ||
console.error(format(ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\"")); | ||
} | ||
@@ -389,3 +411,3 @@ | ||
if (typeof modifier.enabled !== 'boolean') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', `"${String(modifier.enabled)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\"")); | ||
} | ||
@@ -395,3 +417,3 @@ | ||
if (![read, main, write].includes(modifier.phase)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', `"${String(modifier.phase)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', "\"" + String(modifier.phase) + "\"")); | ||
} | ||
@@ -403,3 +425,3 @@ | ||
if (typeof modifier.fn !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"fn"', '"function"', `"${String(modifier.fn)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
@@ -411,3 +433,3 @@ | ||
if (typeof modifier.onLoad !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', `"${String(modifier.fn)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
@@ -419,3 +441,3 @@ | ||
if (!Array.isArray(modifier.requires)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"requires"', '"array"', `"${String(modifier.requires)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\"")); | ||
} | ||
@@ -429,3 +451,5 @@ | ||
default: | ||
console.error(`PopperJS: an invalid property has been provided to the "${modifier.name}" modifier, valid properties are ${VALID_PROPERTIES.map(s => `"${s}"`).join(', ')}; but "${key}" was provided.`); | ||
console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) { | ||
return "\"" + s + "\""; | ||
}).join(', ') + "; but \"" + key + "\" was provided."); | ||
} | ||
@@ -436,3 +460,3 @@ }); | ||
var getBoundingClientRect = (element => { | ||
var getBoundingClientRect = (function (element) { | ||
return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
@@ -444,11 +468,11 @@ }); | ||
function getClippingParent(element) { | ||
const scrollParent = getScrollParent(element); | ||
const offsetParent = getOffsetParent(element); | ||
const win = getWindow(element); | ||
var scrollParent = getScrollParent(element); | ||
var offsetParent = getOffsetParent(element); | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent))); | ||
} | ||
var getDocumentRect = (element => { | ||
const win = getWindow(element); | ||
const documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
var getDocumentRect = (function (element) { | ||
var win = getWindow(element); | ||
var documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
@@ -459,17 +483,23 @@ documentRect.width = Math.max(documentRect.width, win.innerWidth); | ||
var rectToClientRect = (rect => _objectSpread2({}, rect, { | ||
left: rect.x, | ||
top: rect.y, | ||
right: rect.x + rect.width, | ||
bottom: rect.y + rect.height | ||
})); | ||
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 = { | ||
boundaryElement: getClippingParent(state.elements.popper) | ||
}) { | ||
const popperElement = state.elements.popper; | ||
const referenceElement = state.elements.reference; | ||
const popperRect = state.measures.popper; | ||
const documentElement = options.boundaryElement.ownerDocument.documentElement; | ||
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)) { | ||
@@ -480,5 +510,5 @@ console.error('PopperJS: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
const boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect(getDocumentRect(documentElement)) : getBoundingClientRect(options.boundaryElement); | ||
const referenceClientRect = getBoundingClientRect(referenceElement); | ||
const popperOffsets = computeOffsets({ | ||
var boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect(getDocumentRect(documentElement)) : getBoundingClientRect(options.boundaryElement); | ||
var referenceClientRect = getBoundingClientRect(referenceElement); | ||
var popperOffsets = computeOffsets({ | ||
reference: referenceClientRect, | ||
@@ -493,3 +523,3 @@ element: popperRect, | ||
}); | ||
const popperClientRect = rectToClientRect(_objectSpread2({}, popperRect, {}, popperOffsets)); | ||
var popperClientRect = rectToClientRect(_extends({}, popperRect, {}, popperOffsets)); | ||
state.modifiersData.detectOverflow = { | ||
@@ -513,3 +543,3 @@ top: boundaryClientRect.top - popperClientRect.top, | ||
// that can be applied to the popper element to make it render in the expected position. | ||
const mapStrategyToPosition = strategy => { | ||
var mapStrategyToPosition = function mapStrategyToPosition(strategy) { | ||
switch (strategy) { | ||
@@ -524,12 +554,12 @@ case 'fixed': | ||
}; | ||
const computePopperStyles = ({ | ||
offsets, | ||
strategy, | ||
gpuAcceleration | ||
}) => { | ||
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`, | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: mapStrategyToPosition(strategy) | ||
@@ -539,3 +569,5 @@ }; | ||
return { | ||
transform: `translate3d(${offsets.x}px, ${offsets.y}px, 0)`, | ||
top: '0px', | ||
left: '0px', | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: mapStrategyToPosition(strategy) | ||
@@ -545,10 +577,10 @@ }; | ||
}; | ||
const computeArrowStyles = ({ | ||
offsets, | ||
gpuAcceleration | ||
}) => { | ||
var computeArrowStyles = function computeArrowStyles(_ref2) { | ||
var offsets = _ref2.offsets, | ||
gpuAcceleration = _ref2.gpuAcceleration; | ||
if (gpuAcceleration) { | ||
return { | ||
top: `${offsets.y}px`, | ||
left: `${offsets.x}px`, | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: 'absolute' | ||
@@ -558,3 +590,3 @@ }; | ||
return { | ||
transform: `translate3d(${offsets.x}px, ${offsets.y}px, 0)`, | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: 'absolute' | ||
@@ -565,3 +597,3 @@ }; | ||
function computeStyles(state, options) { | ||
const gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
var gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
state.styles = {}; // popper offsets are always available | ||
@@ -572,3 +604,3 @@ | ||
strategy: state.options.strategy, | ||
gpuAcceleration | ||
gpuAcceleration: gpuAcceleration | ||
}); // arrow offsets may not be available | ||
@@ -579,3 +611,3 @@ | ||
offsets: state.offsets.arrow, | ||
gpuAcceleration | ||
gpuAcceleration: gpuAcceleration | ||
}); | ||
@@ -596,5 +628,5 @@ } | ||
function applyStyles(state) { | ||
Object.keys(state.elements).forEach(name => { | ||
const style = state.styles.hasOwnProperty(name) ? state.styles[name] : null; // Flow doesn't support to extend this property, but it's the most | ||
// effective way to apply styles to an HTMLElemen | ||
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 | ||
@@ -606,2 +638,17 @@ | ||
} | ||
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 = { | ||
@@ -612,2 +659,3 @@ name: 'applyStyles', | ||
fn: applyStyles, | ||
onDestroy: onDestroy, | ||
requires: ['computeStyles'] | ||
@@ -617,8 +665,12 @@ }; | ||
function distanceAndSkiddingToXY(placement, measures, getOffsets) { | ||
const basePlacement = getBasePlacement(placement); | ||
const invertDistance = ['left', 'top'].includes(basePlacement) ? -1 : 1; | ||
const invertSkidding = ['top', 'bottom'].includes(basePlacement) ? -1 : 1; | ||
let [distance, skidding] = getOffsets(_objectSpread2({}, measures, { | ||
placement | ||
})); | ||
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; | ||
@@ -630,3 +682,6 @@ skidding = (distance || 0) * invertSkidding; | ||
if (options && typeof options.offset === 'function') { | ||
const [x, y] = distanceAndSkiddingToXY(state.placement, state.measures, options.offset); | ||
var _distanceAndSkiddingT = distanceAndSkiddingToXY(state.placement, state.measures, options.offset), | ||
x = _distanceAndSkiddingT[0], | ||
y = _distanceAndSkiddingT[1]; | ||
state.offsets.popper.x += x; | ||
@@ -645,3 +700,3 @@ state.offsets.popper.y += y; | ||
const hash = { | ||
var hash = { | ||
left: 'right', | ||
@@ -652,12 +707,18 @@ right: 'left', | ||
}; | ||
var getOppositePlacement = (placement => placement.replace(/left|right|bottom|top/g, matched => hash[matched])); | ||
var getOppositePlacement = (function (placement) { | ||
return placement.replace(/left|right|bottom|top/g, function (matched) { | ||
return hash[matched]; | ||
}); | ||
}); | ||
function flip(state, options) { | ||
const placement = state.placement; | ||
const behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement(placement)]; | ||
const overflow = state.modifiersData.detectOverflow; | ||
const flippedPlacement = behavior.find(newPlacement => overflow[getBasePlacement(newPlacement)] <= 0); | ||
var placement = state.placement; | ||
var behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement(placement)]; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var flippedPlacement = behavior.find(function (newPlacement) { | ||
return overflow[getBasePlacement(newPlacement)] <= 0; | ||
}); | ||
if (flippedPlacement && flippedPlacement !== placement) { | ||
state = _objectSpread2({}, state, { | ||
state = _extends({}, state, { | ||
placement: flippedPlacement, | ||
@@ -677,4 +738,44 @@ reset: true | ||
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; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var basePlacement = getBasePlacement(state.placement); | ||
var mainAxis = getMainAxisFromPlacement(basePlacement); | ||
var altAxis = getAltAxis(mainAxis); | ||
var popperOffsets = state.offsets.popper; | ||
if (checkMainAxis) { | ||
var mainSide = mainAxis === 'y' ? top : left; | ||
var altSide = mainAxis === 'y' ? bottom : right; | ||
state.offsets.popper[mainAxis] = Math.max(Math.min(popperOffsets[mainAxis], popperOffsets[mainAxis] - overflow[altSide]), popperOffsets[mainAxis] + overflow[mainSide]); | ||
} | ||
if (checkAltAxis) { | ||
var _mainSide = mainAxis === 'x' ? top : left; | ||
var _altSide = mainAxis === 'x' ? bottom : right; | ||
console.log(altAxis, _mainSide, overflow[_altSide]); | ||
state.offsets.popper[altAxis] = Math.max(Math.min(popperOffsets[altAxis], popperOffsets[altAxis] - overflow[_altSide]), popperOffsets[altAxis] + overflow[_mainSide]); | ||
} | ||
return state; | ||
} | ||
var preventOverflow$1 = { | ||
name: 'flip', | ||
enabled: true, | ||
phase: 'main', | ||
fn: preventOverflow | ||
}; | ||
var modifiers = /*#__PURE__*/Object.freeze({ | ||
@@ -685,10 +786,13 @@ detectOverflow: detectOverflow$1, | ||
offset: offset$1, | ||
flip: flip$1 | ||
flip: flip$1, | ||
preventOverflow: preventOverflow$1 | ||
}); | ||
const defaultModifiers = Object.values(modifiers); | ||
var defaultModifiers = Object.values(modifiers); | ||
const areValidElements = (a, b) => a instanceof Element && b instanceof Element; | ||
var areValidElements = function areValidElements(a, b) { | ||
return a instanceof Element && b instanceof Element; | ||
}; | ||
const defaultOptions = { | ||
var defaultOptions = { | ||
placement: 'bottom', | ||
@@ -702,4 +806,13 @@ eventListeners: { | ||
}; | ||
class Popper { | ||
constructor(reference, popper, options = defaultOptions) { | ||
var Popper = | ||
/*#__PURE__*/ | ||
function () { | ||
function Popper(reference, popper, options) { | ||
var _this = this; | ||
if (options === void 0) { | ||
options = defaultOptions; | ||
} | ||
_defineProperty(this, "state", { | ||
@@ -712,7 +825,10 @@ placement: 'bottom', | ||
_defineProperty(this, "update", microtaskDebounce(() => new Promise((success, reject) => { | ||
this.forceUpdate(); | ||
success(this.state); | ||
}))); | ||
_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 | ||
@@ -724,11 +840,10 @@ // wrapped by jQuery, otherwise consume them as is | ||
}; | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; // Store options into state | ||
var _this$state$elements = this.state.elements, | ||
referenceElement = _this$state$elements.reference, | ||
popperElement = _this$state$elements.popper; // Store options into state | ||
this.state.options = _objectSpread2({}, defaultOptions, {}, options); // Cache the placement in cache to make it available to the modifiers | ||
this.state.options = _extends({}, defaultOptions, {}, options); // 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 = options.placement; // Don't proceed if `reference` or `popper` are invalid elements | ||
this.state.placement = this.state.options.placement; // Don't proceed if `reference` or `popper` are invalid elements | ||
@@ -745,9 +860,12 @@ if (!areValidElements(referenceElement, popperElement)) { | ||
this.state.orderedModifiers = orderModifiers([...defaultModifiers, ...this.state.options.modifiers]) // Apply user defined preferences to modifiers | ||
.map(modifier => _objectSpread2({}, modifier, {}, this.state.options.modifiers.find(({ | ||
name | ||
}) => name === modifier.name))); // Validate the provided modifiers so that the consumer will get warned | ||
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') { | ||
if (process.env.NODE_ENV !== "production") { | ||
validateModifiers(this.state.options.modifiers); | ||
@@ -760,9 +878,10 @@ } // Modifiers have the opportunity to execute some arbitrary code before | ||
this.state.orderedModifiers.forEach(({ | ||
onLoad, | ||
enabled | ||
}) => enabled && onLoad && onLoad(this.state)); | ||
this.update().then(() => { | ||
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); | ||
_this.enableEventListeners(_this.state.options.eventListeners); | ||
}); | ||
@@ -774,10 +893,11 @@ } // Async and optimistically optimized update | ||
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 | ||
forceUpdate() { | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; // Don't proceed if `reference` or `popper` are not valid elements anymore | ||
_proto.forceUpdate = function forceUpdate() { | ||
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 | ||
@@ -800,3 +920,3 @@ if (!areValidElements(referenceElement, popperElement)) { | ||
const offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Offsets are the actual position the popper needs to have to be | ||
var offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Offsets are the actual position the popper needs to have to be | ||
// properly positioned near its reference element | ||
@@ -819,8 +939,7 @@ // This is the most basic placement, and will be adjusted by | ||
for (let index = 0; index < this.state.orderedModifiers.length; index++) { | ||
const { | ||
fn, | ||
enabled, | ||
options | ||
} = this.state.orderedModifiers[index]; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
@@ -837,23 +956,26 @@ if (this.state.reset === true) { | ||
} | ||
} | ||
}; | ||
enableEventListeners(eventListeners) { | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; | ||
const { | ||
scroll, | ||
resize | ||
} = expandEventListeners(eventListeners); | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this2 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _expandEventListeners = expandEventListeners(eventListeners), | ||
scroll = _expandEventListeners.scroll, | ||
resize = _expandEventListeners.resize; | ||
if (scroll) { | ||
const scrollParents = [...this.state.scrollParents.reference, ...this.state.scrollParents.popper]; | ||
scrollParents.forEach(scrollParent => scrollParent.addEventListener('scroll', this.update, { | ||
passive: true | ||
})); | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this2.update, { | ||
passive: true | ||
}); | ||
}); | ||
} | ||
if (resize) { | ||
const window = getWindow(this.state.elements.popper); | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
@@ -863,7 +985,27 @@ passive: true | ||
} | ||
} | ||
}; | ||
} | ||
_proto.destroy = function destroy() { | ||
var _this3 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this3.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 (_ref3) { | ||
var onDestroy = _ref3.onDestroy, | ||
enabled = _ref3.enabled; | ||
return enabled && onDestroy && onDestroy(_this3.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
module.exports = Popper; | ||
//# sourceMappingURL=popper.js.map |
@@ -16,38 +16,22 @@ function _defineProperty(obj, key, value) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return keys; | ||
} | ||
return target; | ||
}; | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
return _extends.apply(this, arguments); | ||
} | ||
function getWindow(node) { | ||
const ownerDocument = node.ownerDocument; | ||
var ownerDocument = node.ownerDocument; | ||
return ownerDocument ? ownerDocument.defaultView : window; | ||
@@ -60,24 +44,24 @@ } | ||
var getElementMargins = (element => { | ||
var getElementMargins = (function (element) { | ||
// get the element margins, we need them to properly align the popper | ||
const styles = getComputedStyle(element); | ||
const top = parseFloat(styles.marginTop) || 0; | ||
const right = parseFloat(styles.marginRight) || 0; | ||
const bottom = parseFloat(styles.marginBottom) || 0; | ||
const left = parseFloat(styles.marginLeft) || 0; | ||
var styles = getComputedStyle(element); | ||
var top = parseFloat(styles.marginTop) || 0; | ||
var right = parseFloat(styles.marginRight) || 0; | ||
var bottom = parseFloat(styles.marginBottom) || 0; | ||
var left = parseFloat(styles.marginLeft) || 0; | ||
return { | ||
top, | ||
right, | ||
bottom, | ||
left | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left | ||
}; | ||
}); | ||
var getElementClientRect = (element => { | ||
var getElementClientRect = (function (element) { | ||
// get the basic client rect, it doesn't include margins | ||
const width = element.offsetWidth; | ||
const height = element.offsetHeight; | ||
const top = element.offsetTop; | ||
const left = element.offsetLeft; | ||
const margins = getElementMargins(element); | ||
var width = element.offsetWidth; | ||
var height = element.offsetHeight; | ||
var top = element.offsetTop; | ||
var left = element.offsetLeft; | ||
var margins = getElementMargins(element); | ||
return { | ||
@@ -91,4 +75,8 @@ width: width + margins.left + margins.right, | ||
var getParentNode = (element => { | ||
if (element.nodeName === 'HTML') { | ||
var getNodeName = (function (element) { | ||
return element ? element.nodeName.toUpperCase() : null; | ||
}); | ||
var getParentNode = (function (element) { | ||
if (getNodeName(element) === 'HTML') { | ||
// DocumentElement detectedF | ||
@@ -117,7 +105,6 @@ return element; | ||
// Firefox want us to check `-x` and `-y` variations as well | ||
const { | ||
overflow, | ||
overflowX, | ||
overflowY | ||
} = getComputedStyle(node); | ||
var _getComputedStyle = getComputedStyle(node), | ||
overflow = _getComputedStyle.overflow, | ||
overflowX = _getComputedStyle.overflowX, | ||
overflowY = _getComputedStyle.overflowY; | ||
@@ -132,7 +119,11 @@ if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) { | ||
function listScrollParents(element, list = []) { | ||
const scrollParent = getScrollParent(element); | ||
const isBody = scrollParent.nodeName === 'BODY'; | ||
const target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
const updatedList = list.concat(target); | ||
function listScrollParents(element, list) { | ||
if (list === void 0) { | ||
list = []; | ||
} | ||
var scrollParent = getScrollParent(element); | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var updatedList = list.concat(target); | ||
return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
@@ -142,8 +133,8 @@ } | ||
function getWindowScroll(node) { | ||
const win = getWindow(node); | ||
const scrollLeft = win.pageXOffset; | ||
const scrollTop = win.pageYOffset; | ||
var win = getWindow(node); | ||
var scrollLeft = win.pageXOffset; | ||
var scrollTop = win.pageYOffset; | ||
return { | ||
scrollLeft, | ||
scrollTop | ||
scrollLeft: scrollLeft, | ||
scrollTop: scrollTop | ||
}; | ||
@@ -168,6 +159,6 @@ } | ||
function getOffsetParent(element) { | ||
const offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
const window = getWindow(element); | ||
var offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
var window = getWindow(element); | ||
if (offsetParent && offsetParent.nodeName && offsetParent.nodeName.toUpperCase() === 'BODY') { | ||
if (getNodeName(offsetParent) === 'BODY') { | ||
return window; | ||
@@ -179,11 +170,13 @@ } | ||
const sumScroll = scrollParents => scrollParents.reduce((scroll, scrollParent) => { | ||
const nodeScroll = getElementScroll(scrollParent); | ||
scroll.scrollTop += nodeScroll.scrollTop; | ||
scroll.scrollLeft += nodeScroll.scrollLeft; | ||
return scroll; | ||
}, { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
}); | ||
var sumScroll = function sumScroll(scrollParents) { | ||
return scrollParents.reduce(function (scroll, scrollParent) { | ||
var nodeScroll = getElementScroll(scrollParent); | ||
scroll.scrollTop += nodeScroll.scrollTop; | ||
scroll.scrollLeft += nodeScroll.scrollLeft; | ||
return scroll; | ||
}, { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
}); | ||
}; | ||
@@ -193,18 +186,24 @@ function getCommonTotalScroll(reference, referenceScrollParents, popperScrollParents, limiter) { | ||
// it because it wouldn't add anything to the equation (they nulllify themselves) | ||
const nonCommonReference = referenceScrollParents.filter(node => !popperScrollParents.includes(node)); // we then want to pick any scroll offset except for the one of the offsetParent | ||
var nonCommonReference = referenceScrollParents.filter(function (node) { | ||
return !popperScrollParents.includes(node); | ||
}); // we then want to pick any scroll offset except for the one of the offsetParent | ||
// not sure why but that's how I got it working 😅 | ||
// TODO: improve this comment with proper explanation | ||
const offsetParent = getOffsetParent(reference); | ||
const index = referenceScrollParents.findIndex(node => node === (limiter || offsetParent)); | ||
const scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
var offsetParent = getOffsetParent(reference); | ||
var index = referenceScrollParents.findIndex(function (node) { | ||
return node === (limiter || offsetParent); | ||
}); | ||
var scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
return sumScroll(scrollParents); | ||
} | ||
var unwrapJqueryElement = (element => element && element.jquery ? element[0] : element); | ||
var unwrapJqueryElement = (function (element) { | ||
return element && element.jquery ? element[0] : element; | ||
}); | ||
// source: https://stackoverflow.com/questions/49875255 | ||
const order = modifiers => { | ||
var order = function order(modifiers) { | ||
// indexed by name | ||
const mapped = modifiers.reduce((mem, i) => { | ||
var mapped = modifiers.reduce(function (mem, i) { | ||
mem[i.name] = i; | ||
@@ -214,5 +213,5 @@ return mem; | ||
const inherited = i => { | ||
return mapped[i].requires ? mapped[i].requires.reduce((mem, i) => { | ||
return [...mem, i, ...inherited(i)]; | ||
var inherited = function inherited(i) { | ||
return mapped[i].requires ? mapped[i].requires.reduce(function (mem, i) { | ||
return [].concat(mem, [i], inherited(i)); | ||
}, []) : []; | ||
@@ -222,3 +221,3 @@ }; // order ... | ||
const ordered = modifiers.sort((a, b) => { | ||
var ordered = modifiers.sort(function (a, b) { | ||
return !!~inherited(b.name).indexOf(a.name) ? -1 : 1; | ||
@@ -229,11 +228,17 @@ }); | ||
var orderModifiers = (modifiers => [...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'read')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'main')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'afterMain')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'write'))]); | ||
var orderModifiers = (function (modifiers) { | ||
return [].concat(order(modifiers.filter(function (_ref) { | ||
var phase = _ref.phase; | ||
return phase === 'read'; | ||
})), order(modifiers.filter(function (_ref2) { | ||
var phase = _ref2.phase; | ||
return phase === 'main'; | ||
})), order(modifiers.filter(function (_ref3) { | ||
var phase = _ref3.phase; | ||
return phase === 'afterMain'; | ||
})), order(modifiers.filter(function (_ref4) { | ||
var phase = _ref4.phase; | ||
return phase === 'write'; | ||
}))); | ||
}); | ||
@@ -247,4 +252,4 @@ // Expands the eventListeners value to an object containing the | ||
// false, false => false, false | ||
var expandEventListeners = (eventListeners => { | ||
const fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
var expandEventListeners = (function (eventListeners) { | ||
var fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
return { | ||
@@ -256,39 +261,46 @@ scroll: typeof eventListeners.scroll === 'boolean' ? eventListeners.scroll : fallbackValue, | ||
var getBasePlacement = (placement => placement.split('-')[0]); | ||
var getBasePlacement = (function (placement) { | ||
return placement.split('-')[0]; | ||
}); | ||
var getVariationPlacement = (placement => placement.split('-')[1]); | ||
var getVariationPlacement = (function (placement) { | ||
return placement.split('-')[1]; | ||
}); | ||
var getMainAxisFromPlacement = (placement => ['top', 'bottom'].includes(placement) ? 'x' : 'y'); | ||
var getMainAxisFromPlacement = (function (placement) { | ||
return ['top', 'bottom'].includes(placement) ? 'x' : 'y'; | ||
}); | ||
var getAltAxis = (axis => axis === 'x' ? 'y' : 'x'); | ||
var getAltAxis = (function (axis) { | ||
return axis === 'x' ? 'y' : 'x'; | ||
}); | ||
const top = 'top'; | ||
const bottom = 'bottom'; | ||
const right = 'right'; | ||
const left = 'left'; | ||
const basePlacements = [top, bottom, right, left]; | ||
const start = 'start'; | ||
const end = 'end'; | ||
const placements = basePlacements.reduce((acc, placement) => acc.concat([placement, `${placement}-${start}`, `${placement}-${end}`]), []); // modifiers that need to read the DOM | ||
var top = 'top'; | ||
var bottom = 'bottom'; | ||
var right = 'right'; | ||
var left = 'left'; | ||
var basePlacements = [top, bottom, right, left]; | ||
var start = 'start'; | ||
var end = 'end'; | ||
var placements = basePlacements.reduce(function (acc, placement) { | ||
return acc.concat([placement, placement + "-" + start, placement + "-" + end]); | ||
}, []); // modifiers that need to read the DOM | ||
const read = 'read'; // pure-logic modifiers | ||
var read = 'read'; // pure-logic modifiers | ||
const main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
var main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
const write = 'write'; | ||
var write = 'write'; | ||
var computeOffsets = (({ | ||
reference, | ||
element, | ||
strategy, | ||
placement, | ||
scroll | ||
}) => { | ||
const basePlacement = placement ? getBasePlacement(placement) : null; | ||
const variationPlacement = placement ? getVariationPlacement(placement) : null; | ||
const { | ||
scrollTop, | ||
scrollLeft | ||
} = scroll; | ||
let offsets; | ||
var computeOffsets = (function (_ref) { | ||
var reference = _ref.reference, | ||
element = _ref.element, | ||
strategy = _ref.strategy, | ||
placement = _ref.placement, | ||
scroll = _ref.scroll; | ||
var basePlacement = placement ? getBasePlacement(placement) : null; | ||
var variationPlacement = placement ? getVariationPlacement(placement) : null; | ||
var scrollTop = scroll.scrollTop, | ||
scrollLeft = scroll.scrollLeft; | ||
var offsets; | ||
@@ -331,6 +343,6 @@ switch (basePlacement) { | ||
const mainAxis = placement ? getMainAxisFromPlacement(placement) : null; | ||
const altAxis = mainAxis ? getAltAxis(mainAxis) : null; | ||
const len = altAxis === 'x' ? 'width' : 'height'; | ||
const axis = [right, left].includes(basePlacement) ? mainAxis : altAxis; | ||
var mainAxis = placement ? getMainAxisFromPlacement(placement) : null; | ||
var altAxis = mainAxis ? getAltAxis(mainAxis) : null; | ||
var len = altAxis === 'x' ? 'width' : 'height'; | ||
var axis = [right, left].includes(basePlacement) ? mainAxis : altAxis; | ||
@@ -354,28 +366,38 @@ if (axis != null) { | ||
var format = ((str, ...args) => [...args].reduce((p, c) => p.replace(/%s/, c), str)); | ||
var format = (function (str) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return [].concat(args).reduce(function (p, c) { | ||
return p.replace(/%s/, c); | ||
}, str); | ||
}); | ||
function microtaskDebounce(fn) { | ||
let called = false; | ||
return () => new Promise(resolve => { | ||
if (called) { | ||
return resolve(); | ||
} | ||
var called = false; | ||
return function () { | ||
return new Promise(function (resolve) { | ||
if (called) { | ||
return resolve(); | ||
} | ||
called = true; | ||
Promise.resolve().then(() => { | ||
called = false; | ||
resolve(fn()); | ||
called = true; | ||
Promise.resolve().then(function () { | ||
called = false; | ||
resolve(fn()); | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
const ERROR_MESSAGE = 'PopperJS: modifier "%s" provided an invalid %s property, expected %s but got %s'; | ||
const VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'onLoad', 'requires', 'options']; | ||
var validateModifiers = (modifiers => { | ||
modifiers.forEach(modifier => { | ||
Object.keys(modifier).forEach(key => { | ||
var ERROR_MESSAGE = 'PopperJS: modifier "%s" provided an invalid %s property, expected %s but got %s'; | ||
var VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'onLoad', 'requires', 'options']; | ||
var validateModifiers = (function (modifiers) { | ||
modifiers.forEach(function (modifier) { | ||
Object.keys(modifier).forEach(function (key) { | ||
switch (key) { | ||
case 'name': | ||
if (typeof modifier.name !== 'string') { | ||
console.error(format(ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', `"${String(modifier.name)}"`)); | ||
console.error(format(ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\"")); | ||
} | ||
@@ -387,3 +409,3 @@ | ||
if (typeof modifier.enabled !== 'boolean') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', `"${String(modifier.enabled)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\"")); | ||
} | ||
@@ -393,3 +415,3 @@ | ||
if (![read, main, write].includes(modifier.phase)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', `"${String(modifier.phase)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', "\"" + String(modifier.phase) + "\"")); | ||
} | ||
@@ -401,3 +423,3 @@ | ||
if (typeof modifier.fn !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"fn"', '"function"', `"${String(modifier.fn)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
@@ -409,3 +431,3 @@ | ||
if (typeof modifier.onLoad !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', `"${String(modifier.fn)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
@@ -417,3 +439,3 @@ | ||
if (!Array.isArray(modifier.requires)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"requires"', '"array"', `"${String(modifier.requires)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\"")); | ||
} | ||
@@ -427,3 +449,5 @@ | ||
default: | ||
console.error(`PopperJS: an invalid property has been provided to the "${modifier.name}" modifier, valid properties are ${VALID_PROPERTIES.map(s => `"${s}"`).join(', ')}; but "${key}" was provided.`); | ||
console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) { | ||
return "\"" + s + "\""; | ||
}).join(', ') + "; but \"" + key + "\" was provided."); | ||
} | ||
@@ -434,3 +458,3 @@ }); | ||
var getBoundingClientRect = (element => { | ||
var getBoundingClientRect = (function (element) { | ||
return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
@@ -442,11 +466,11 @@ }); | ||
function getClippingParent(element) { | ||
const scrollParent = getScrollParent(element); | ||
const offsetParent = getOffsetParent(element); | ||
const win = getWindow(element); | ||
var scrollParent = getScrollParent(element); | ||
var offsetParent = getOffsetParent(element); | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent))); | ||
} | ||
var getDocumentRect = (element => { | ||
const win = getWindow(element); | ||
const documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
var getDocumentRect = (function (element) { | ||
var win = getWindow(element); | ||
var documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
@@ -457,17 +481,23 @@ documentRect.width = Math.max(documentRect.width, win.innerWidth); | ||
var rectToClientRect = (rect => _objectSpread2({}, rect, { | ||
left: rect.x, | ||
top: rect.y, | ||
right: rect.x + rect.width, | ||
bottom: rect.y + rect.height | ||
})); | ||
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 = { | ||
boundaryElement: getClippingParent(state.elements.popper) | ||
}) { | ||
const popperElement = state.elements.popper; | ||
const referenceElement = state.elements.reference; | ||
const popperRect = state.measures.popper; | ||
const documentElement = options.boundaryElement.ownerDocument.documentElement; | ||
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)) { | ||
@@ -478,5 +508,5 @@ console.error('PopperJS: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
const boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect(getDocumentRect(documentElement)) : getBoundingClientRect(options.boundaryElement); | ||
const referenceClientRect = getBoundingClientRect(referenceElement); | ||
const popperOffsets = computeOffsets({ | ||
var boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect(getDocumentRect(documentElement)) : getBoundingClientRect(options.boundaryElement); | ||
var referenceClientRect = getBoundingClientRect(referenceElement); | ||
var popperOffsets = computeOffsets({ | ||
reference: referenceClientRect, | ||
@@ -491,3 +521,3 @@ element: popperRect, | ||
}); | ||
const popperClientRect = rectToClientRect(_objectSpread2({}, popperRect, {}, popperOffsets)); | ||
var popperClientRect = rectToClientRect(_extends({}, popperRect, {}, popperOffsets)); | ||
state.modifiersData.detectOverflow = { | ||
@@ -511,3 +541,3 @@ top: boundaryClientRect.top - popperClientRect.top, | ||
// that can be applied to the popper element to make it render in the expected position. | ||
const mapStrategyToPosition = strategy => { | ||
var mapStrategyToPosition = function mapStrategyToPosition(strategy) { | ||
switch (strategy) { | ||
@@ -522,12 +552,12 @@ case 'fixed': | ||
}; | ||
const computePopperStyles = ({ | ||
offsets, | ||
strategy, | ||
gpuAcceleration | ||
}) => { | ||
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`, | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: mapStrategyToPosition(strategy) | ||
@@ -537,3 +567,5 @@ }; | ||
return { | ||
transform: `translate3d(${offsets.x}px, ${offsets.y}px, 0)`, | ||
top: '0px', | ||
left: '0px', | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: mapStrategyToPosition(strategy) | ||
@@ -543,10 +575,10 @@ }; | ||
}; | ||
const computeArrowStyles = ({ | ||
offsets, | ||
gpuAcceleration | ||
}) => { | ||
var computeArrowStyles = function computeArrowStyles(_ref2) { | ||
var offsets = _ref2.offsets, | ||
gpuAcceleration = _ref2.gpuAcceleration; | ||
if (gpuAcceleration) { | ||
return { | ||
top: `${offsets.y}px`, | ||
left: `${offsets.x}px`, | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: 'absolute' | ||
@@ -556,3 +588,3 @@ }; | ||
return { | ||
transform: `translate3d(${offsets.x}px, ${offsets.y}px, 0)`, | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: 'absolute' | ||
@@ -563,3 +595,3 @@ }; | ||
function computeStyles(state, options) { | ||
const gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
var gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
state.styles = {}; // popper offsets are always available | ||
@@ -570,3 +602,3 @@ | ||
strategy: state.options.strategy, | ||
gpuAcceleration | ||
gpuAcceleration: gpuAcceleration | ||
}); // arrow offsets may not be available | ||
@@ -577,3 +609,3 @@ | ||
offsets: state.offsets.arrow, | ||
gpuAcceleration | ||
gpuAcceleration: gpuAcceleration | ||
}); | ||
@@ -594,5 +626,5 @@ } | ||
function applyStyles(state) { | ||
Object.keys(state.elements).forEach(name => { | ||
const style = state.styles.hasOwnProperty(name) ? state.styles[name] : null; // Flow doesn't support to extend this property, but it's the most | ||
// effective way to apply styles to an HTMLElemen | ||
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 | ||
@@ -604,2 +636,17 @@ | ||
} | ||
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 = { | ||
@@ -610,2 +657,3 @@ name: 'applyStyles', | ||
fn: applyStyles, | ||
onDestroy: onDestroy, | ||
requires: ['computeStyles'] | ||
@@ -615,8 +663,12 @@ }; | ||
function distanceAndSkiddingToXY(placement, measures, getOffsets) { | ||
const basePlacement = getBasePlacement(placement); | ||
const invertDistance = ['left', 'top'].includes(basePlacement) ? -1 : 1; | ||
const invertSkidding = ['top', 'bottom'].includes(basePlacement) ? -1 : 1; | ||
let [distance, skidding] = getOffsets(_objectSpread2({}, measures, { | ||
placement | ||
})); | ||
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; | ||
@@ -628,3 +680,6 @@ skidding = (distance || 0) * invertSkidding; | ||
if (options && typeof options.offset === 'function') { | ||
const [x, y] = distanceAndSkiddingToXY(state.placement, state.measures, options.offset); | ||
var _distanceAndSkiddingT = distanceAndSkiddingToXY(state.placement, state.measures, options.offset), | ||
x = _distanceAndSkiddingT[0], | ||
y = _distanceAndSkiddingT[1]; | ||
state.offsets.popper.x += x; | ||
@@ -643,3 +698,3 @@ state.offsets.popper.y += y; | ||
const hash = { | ||
var hash = { | ||
left: 'right', | ||
@@ -650,12 +705,18 @@ right: 'left', | ||
}; | ||
var getOppositePlacement = (placement => placement.replace(/left|right|bottom|top/g, matched => hash[matched])); | ||
var getOppositePlacement = (function (placement) { | ||
return placement.replace(/left|right|bottom|top/g, function (matched) { | ||
return hash[matched]; | ||
}); | ||
}); | ||
function flip(state, options) { | ||
const placement = state.placement; | ||
const behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement(placement)]; | ||
const overflow = state.modifiersData.detectOverflow; | ||
const flippedPlacement = behavior.find(newPlacement => overflow[getBasePlacement(newPlacement)] <= 0); | ||
var placement = state.placement; | ||
var behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement(placement)]; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var flippedPlacement = behavior.find(function (newPlacement) { | ||
return overflow[getBasePlacement(newPlacement)] <= 0; | ||
}); | ||
if (flippedPlacement && flippedPlacement !== placement) { | ||
state = _objectSpread2({}, state, { | ||
state = _extends({}, state, { | ||
placement: flippedPlacement, | ||
@@ -675,4 +736,44 @@ reset: true | ||
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; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var basePlacement = getBasePlacement(state.placement); | ||
var mainAxis = getMainAxisFromPlacement(basePlacement); | ||
var altAxis = getAltAxis(mainAxis); | ||
var popperOffsets = state.offsets.popper; | ||
if (checkMainAxis) { | ||
var mainSide = mainAxis === 'y' ? top : left; | ||
var altSide = mainAxis === 'y' ? bottom : right; | ||
state.offsets.popper[mainAxis] = Math.max(Math.min(popperOffsets[mainAxis], popperOffsets[mainAxis] - overflow[altSide]), popperOffsets[mainAxis] + overflow[mainSide]); | ||
} | ||
if (checkAltAxis) { | ||
var _mainSide = mainAxis === 'x' ? top : left; | ||
var _altSide = mainAxis === 'x' ? bottom : right; | ||
console.log(altAxis, _mainSide, overflow[_altSide]); | ||
state.offsets.popper[altAxis] = Math.max(Math.min(popperOffsets[altAxis], popperOffsets[altAxis] - overflow[_altSide]), popperOffsets[altAxis] + overflow[_mainSide]); | ||
} | ||
return state; | ||
} | ||
var preventOverflow$1 = { | ||
name: 'flip', | ||
enabled: true, | ||
phase: 'main', | ||
fn: preventOverflow | ||
}; | ||
var modifiers = /*#__PURE__*/Object.freeze({ | ||
@@ -683,10 +784,13 @@ detectOverflow: detectOverflow$1, | ||
offset: offset$1, | ||
flip: flip$1 | ||
flip: flip$1, | ||
preventOverflow: preventOverflow$1 | ||
}); | ||
const defaultModifiers = Object.values(modifiers); | ||
var defaultModifiers = Object.values(modifiers); | ||
const areValidElements = (a, b) => a instanceof Element && b instanceof Element; | ||
var areValidElements = function areValidElements(a, b) { | ||
return a instanceof Element && b instanceof Element; | ||
}; | ||
const defaultOptions = { | ||
var defaultOptions = { | ||
placement: 'bottom', | ||
@@ -700,4 +804,13 @@ eventListeners: { | ||
}; | ||
class Popper { | ||
constructor(reference, popper, options = defaultOptions) { | ||
var Popper = | ||
/*#__PURE__*/ | ||
function () { | ||
function Popper(reference, popper, options) { | ||
var _this = this; | ||
if (options === void 0) { | ||
options = defaultOptions; | ||
} | ||
_defineProperty(this, "state", { | ||
@@ -710,7 +823,10 @@ placement: 'bottom', | ||
_defineProperty(this, "update", microtaskDebounce(() => new Promise((success, reject) => { | ||
this.forceUpdate(); | ||
success(this.state); | ||
}))); | ||
_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 | ||
@@ -722,11 +838,10 @@ // wrapped by jQuery, otherwise consume them as is | ||
}; | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; // Store options into state | ||
var _this$state$elements = this.state.elements, | ||
referenceElement = _this$state$elements.reference, | ||
popperElement = _this$state$elements.popper; // Store options into state | ||
this.state.options = _objectSpread2({}, defaultOptions, {}, options); // Cache the placement in cache to make it available to the modifiers | ||
this.state.options = _extends({}, defaultOptions, {}, options); // 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 = options.placement; // Don't proceed if `reference` or `popper` are invalid elements | ||
this.state.placement = this.state.options.placement; // Don't proceed if `reference` or `popper` are invalid elements | ||
@@ -743,9 +858,12 @@ if (!areValidElements(referenceElement, popperElement)) { | ||
this.state.orderedModifiers = orderModifiers([...defaultModifiers, ...this.state.options.modifiers]) // Apply user defined preferences to modifiers | ||
.map(modifier => _objectSpread2({}, modifier, {}, this.state.options.modifiers.find(({ | ||
name | ||
}) => name === modifier.name))); // Validate the provided modifiers so that the consumer will get warned | ||
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') { | ||
if (process.env.NODE_ENV !== "production") { | ||
validateModifiers(this.state.options.modifiers); | ||
@@ -758,9 +876,10 @@ } // Modifiers have the opportunity to execute some arbitrary code before | ||
this.state.orderedModifiers.forEach(({ | ||
onLoad, | ||
enabled | ||
}) => enabled && onLoad && onLoad(this.state)); | ||
this.update().then(() => { | ||
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); | ||
_this.enableEventListeners(_this.state.options.eventListeners); | ||
}); | ||
@@ -772,10 +891,11 @@ } // Async and optimistically optimized update | ||
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 | ||
forceUpdate() { | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; // Don't proceed if `reference` or `popper` are not valid elements anymore | ||
_proto.forceUpdate = function forceUpdate() { | ||
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 | ||
@@ -798,3 +918,3 @@ if (!areValidElements(referenceElement, popperElement)) { | ||
const offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Offsets are the actual position the popper needs to have to be | ||
var offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Offsets are the actual position the popper needs to have to be | ||
// properly positioned near its reference element | ||
@@ -817,8 +937,7 @@ // This is the most basic placement, and will be adjusted by | ||
for (let index = 0; index < this.state.orderedModifiers.length; index++) { | ||
const { | ||
fn, | ||
enabled, | ||
options | ||
} = this.state.orderedModifiers[index]; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
@@ -835,23 +954,26 @@ if (this.state.reset === true) { | ||
} | ||
} | ||
}; | ||
enableEventListeners(eventListeners) { | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; | ||
const { | ||
scroll, | ||
resize | ||
} = expandEventListeners(eventListeners); | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this2 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _expandEventListeners = expandEventListeners(eventListeners), | ||
scroll = _expandEventListeners.scroll, | ||
resize = _expandEventListeners.resize; | ||
if (scroll) { | ||
const scrollParents = [...this.state.scrollParents.reference, ...this.state.scrollParents.popper]; | ||
scrollParents.forEach(scrollParent => scrollParent.addEventListener('scroll', this.update, { | ||
passive: true | ||
})); | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this2.update, { | ||
passive: true | ||
}); | ||
}); | ||
} | ||
if (resize) { | ||
const window = getWindow(this.state.elements.popper); | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
@@ -861,7 +983,27 @@ passive: true | ||
} | ||
} | ||
}; | ||
} | ||
_proto.destroy = function destroy() { | ||
var _this3 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this3.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 (_ref3) { | ||
var onDestroy = _ref3.onDestroy, | ||
enabled = _ref3.enabled; | ||
return enabled && onDestroy && onDestroy(_this3.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
export default Popper; | ||
//# sourceMappingURL=popper.js.map |
@@ -22,38 +22,22 @@ (function (global, factory) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return keys; | ||
} | ||
return target; | ||
}; | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
return _extends.apply(this, arguments); | ||
} | ||
function getWindow(node) { | ||
const ownerDocument = node.ownerDocument; | ||
var ownerDocument = node.ownerDocument; | ||
return ownerDocument ? ownerDocument.defaultView : window; | ||
@@ -66,24 +50,24 @@ } | ||
var getElementMargins = (element => { | ||
var getElementMargins = (function (element) { | ||
// get the element margins, we need them to properly align the popper | ||
const styles = getComputedStyle(element); | ||
const top = parseFloat(styles.marginTop) || 0; | ||
const right = parseFloat(styles.marginRight) || 0; | ||
const bottom = parseFloat(styles.marginBottom) || 0; | ||
const left = parseFloat(styles.marginLeft) || 0; | ||
var styles = getComputedStyle(element); | ||
var top = parseFloat(styles.marginTop) || 0; | ||
var right = parseFloat(styles.marginRight) || 0; | ||
var bottom = parseFloat(styles.marginBottom) || 0; | ||
var left = parseFloat(styles.marginLeft) || 0; | ||
return { | ||
top, | ||
right, | ||
bottom, | ||
left | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left | ||
}; | ||
}); | ||
var getElementClientRect = (element => { | ||
var getElementClientRect = (function (element) { | ||
// get the basic client rect, it doesn't include margins | ||
const width = element.offsetWidth; | ||
const height = element.offsetHeight; | ||
const top = element.offsetTop; | ||
const left = element.offsetLeft; | ||
const margins = getElementMargins(element); | ||
var width = element.offsetWidth; | ||
var height = element.offsetHeight; | ||
var top = element.offsetTop; | ||
var left = element.offsetLeft; | ||
var margins = getElementMargins(element); | ||
return { | ||
@@ -97,4 +81,8 @@ width: width + margins.left + margins.right, | ||
var getParentNode = (element => { | ||
if (element.nodeName === 'HTML') { | ||
var getNodeName = (function (element) { | ||
return element ? element.nodeName.toUpperCase() : null; | ||
}); | ||
var getParentNode = (function (element) { | ||
if (getNodeName(element) === 'HTML') { | ||
// DocumentElement detectedF | ||
@@ -123,7 +111,6 @@ return element; | ||
// Firefox want us to check `-x` and `-y` variations as well | ||
const { | ||
overflow, | ||
overflowX, | ||
overflowY | ||
} = getComputedStyle(node); | ||
var _getComputedStyle = getComputedStyle(node), | ||
overflow = _getComputedStyle.overflow, | ||
overflowX = _getComputedStyle.overflowX, | ||
overflowY = _getComputedStyle.overflowY; | ||
@@ -138,7 +125,11 @@ if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) { | ||
function listScrollParents(element, list = []) { | ||
const scrollParent = getScrollParent(element); | ||
const isBody = scrollParent.nodeName === 'BODY'; | ||
const target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
const updatedList = list.concat(target); | ||
function listScrollParents(element, list) { | ||
if (list === void 0) { | ||
list = []; | ||
} | ||
var scrollParent = getScrollParent(element); | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var updatedList = list.concat(target); | ||
return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
@@ -148,8 +139,8 @@ } | ||
function getWindowScroll(node) { | ||
const win = getWindow(node); | ||
const scrollLeft = win.pageXOffset; | ||
const scrollTop = win.pageYOffset; | ||
var win = getWindow(node); | ||
var scrollLeft = win.pageXOffset; | ||
var scrollTop = win.pageYOffset; | ||
return { | ||
scrollLeft, | ||
scrollTop | ||
scrollLeft: scrollLeft, | ||
scrollTop: scrollTop | ||
}; | ||
@@ -174,6 +165,6 @@ } | ||
function getOffsetParent(element) { | ||
const offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
const window = getWindow(element); | ||
var offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
var window = getWindow(element); | ||
if (offsetParent && offsetParent.nodeName && offsetParent.nodeName.toUpperCase() === 'BODY') { | ||
if (getNodeName(offsetParent) === 'BODY') { | ||
return window; | ||
@@ -185,11 +176,13 @@ } | ||
const sumScroll = scrollParents => scrollParents.reduce((scroll, scrollParent) => { | ||
const nodeScroll = getElementScroll(scrollParent); | ||
scroll.scrollTop += nodeScroll.scrollTop; | ||
scroll.scrollLeft += nodeScroll.scrollLeft; | ||
return scroll; | ||
}, { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
}); | ||
var sumScroll = function sumScroll(scrollParents) { | ||
return scrollParents.reduce(function (scroll, scrollParent) { | ||
var nodeScroll = getElementScroll(scrollParent); | ||
scroll.scrollTop += nodeScroll.scrollTop; | ||
scroll.scrollLeft += nodeScroll.scrollLeft; | ||
return scroll; | ||
}, { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
}); | ||
}; | ||
@@ -199,18 +192,24 @@ function getCommonTotalScroll(reference, referenceScrollParents, popperScrollParents, limiter) { | ||
// it because it wouldn't add anything to the equation (they nulllify themselves) | ||
const nonCommonReference = referenceScrollParents.filter(node => !popperScrollParents.includes(node)); // we then want to pick any scroll offset except for the one of the offsetParent | ||
var nonCommonReference = referenceScrollParents.filter(function (node) { | ||
return !popperScrollParents.includes(node); | ||
}); // we then want to pick any scroll offset except for the one of the offsetParent | ||
// not sure why but that's how I got it working 😅 | ||
// TODO: improve this comment with proper explanation | ||
const offsetParent = getOffsetParent(reference); | ||
const index = referenceScrollParents.findIndex(node => node === (limiter || offsetParent)); | ||
const scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
var offsetParent = getOffsetParent(reference); | ||
var index = referenceScrollParents.findIndex(function (node) { | ||
return node === (limiter || offsetParent); | ||
}); | ||
var scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
return sumScroll(scrollParents); | ||
} | ||
var unwrapJqueryElement = (element => element && element.jquery ? element[0] : element); | ||
var unwrapJqueryElement = (function (element) { | ||
return element && element.jquery ? element[0] : element; | ||
}); | ||
// source: https://stackoverflow.com/questions/49875255 | ||
const order = modifiers => { | ||
var order = function order(modifiers) { | ||
// indexed by name | ||
const mapped = modifiers.reduce((mem, i) => { | ||
var mapped = modifiers.reduce(function (mem, i) { | ||
mem[i.name] = i; | ||
@@ -220,5 +219,5 @@ return mem; | ||
const inherited = i => { | ||
return mapped[i].requires ? mapped[i].requires.reduce((mem, i) => { | ||
return [...mem, i, ...inherited(i)]; | ||
var inherited = function inherited(i) { | ||
return mapped[i].requires ? mapped[i].requires.reduce(function (mem, i) { | ||
return [].concat(mem, [i], inherited(i)); | ||
}, []) : []; | ||
@@ -228,3 +227,3 @@ }; // order ... | ||
const ordered = modifiers.sort((a, b) => { | ||
var ordered = modifiers.sort(function (a, b) { | ||
return !!~inherited(b.name).indexOf(a.name) ? -1 : 1; | ||
@@ -235,11 +234,17 @@ }); | ||
var orderModifiers = (modifiers => [...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'read')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'main')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'afterMain')), ...order(modifiers.filter(({ | ||
phase | ||
}) => phase === 'write'))]); | ||
var orderModifiers = (function (modifiers) { | ||
return [].concat(order(modifiers.filter(function (_ref) { | ||
var phase = _ref.phase; | ||
return phase === 'read'; | ||
})), order(modifiers.filter(function (_ref2) { | ||
var phase = _ref2.phase; | ||
return phase === 'main'; | ||
})), order(modifiers.filter(function (_ref3) { | ||
var phase = _ref3.phase; | ||
return phase === 'afterMain'; | ||
})), order(modifiers.filter(function (_ref4) { | ||
var phase = _ref4.phase; | ||
return phase === 'write'; | ||
}))); | ||
}); | ||
@@ -253,4 +258,4 @@ // Expands the eventListeners value to an object containing the | ||
// false, false => false, false | ||
var expandEventListeners = (eventListeners => { | ||
const fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
var expandEventListeners = (function (eventListeners) { | ||
var fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
return { | ||
@@ -262,39 +267,46 @@ scroll: typeof eventListeners.scroll === 'boolean' ? eventListeners.scroll : fallbackValue, | ||
var getBasePlacement = (placement => placement.split('-')[0]); | ||
var getBasePlacement = (function (placement) { | ||
return placement.split('-')[0]; | ||
}); | ||
var getVariationPlacement = (placement => placement.split('-')[1]); | ||
var getVariationPlacement = (function (placement) { | ||
return placement.split('-')[1]; | ||
}); | ||
var getMainAxisFromPlacement = (placement => ['top', 'bottom'].includes(placement) ? 'x' : 'y'); | ||
var getMainAxisFromPlacement = (function (placement) { | ||
return ['top', 'bottom'].includes(placement) ? 'x' : 'y'; | ||
}); | ||
var getAltAxis = (axis => axis === 'x' ? 'y' : 'x'); | ||
var getAltAxis = (function (axis) { | ||
return axis === 'x' ? 'y' : 'x'; | ||
}); | ||
const top = 'top'; | ||
const bottom = 'bottom'; | ||
const right = 'right'; | ||
const left = 'left'; | ||
const basePlacements = [top, bottom, right, left]; | ||
const start = 'start'; | ||
const end = 'end'; | ||
const placements = basePlacements.reduce((acc, placement) => acc.concat([placement, `${placement}-${start}`, `${placement}-${end}`]), []); // modifiers that need to read the DOM | ||
var top = 'top'; | ||
var bottom = 'bottom'; | ||
var right = 'right'; | ||
var left = 'left'; | ||
var basePlacements = [top, bottom, right, left]; | ||
var start = 'start'; | ||
var end = 'end'; | ||
var placements = basePlacements.reduce(function (acc, placement) { | ||
return acc.concat([placement, placement + "-" + start, placement + "-" + end]); | ||
}, []); // modifiers that need to read the DOM | ||
const read = 'read'; // pure-logic modifiers | ||
var read = 'read'; // pure-logic modifiers | ||
const main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
var main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
const write = 'write'; | ||
var write = 'write'; | ||
var computeOffsets = (({ | ||
reference, | ||
element, | ||
strategy, | ||
placement, | ||
scroll | ||
}) => { | ||
const basePlacement = placement ? getBasePlacement(placement) : null; | ||
const variationPlacement = placement ? getVariationPlacement(placement) : null; | ||
const { | ||
scrollTop, | ||
scrollLeft | ||
} = scroll; | ||
let offsets; | ||
var computeOffsets = (function (_ref) { | ||
var reference = _ref.reference, | ||
element = _ref.element, | ||
strategy = _ref.strategy, | ||
placement = _ref.placement, | ||
scroll = _ref.scroll; | ||
var basePlacement = placement ? getBasePlacement(placement) : null; | ||
var variationPlacement = placement ? getVariationPlacement(placement) : null; | ||
var scrollTop = scroll.scrollTop, | ||
scrollLeft = scroll.scrollLeft; | ||
var offsets; | ||
@@ -337,6 +349,6 @@ switch (basePlacement) { | ||
const mainAxis = placement ? getMainAxisFromPlacement(placement) : null; | ||
const altAxis = mainAxis ? getAltAxis(mainAxis) : null; | ||
const len = altAxis === 'x' ? 'width' : 'height'; | ||
const axis = [right, left].includes(basePlacement) ? mainAxis : altAxis; | ||
var mainAxis = placement ? getMainAxisFromPlacement(placement) : null; | ||
var altAxis = mainAxis ? getAltAxis(mainAxis) : null; | ||
var len = altAxis === 'x' ? 'width' : 'height'; | ||
var axis = [right, left].includes(basePlacement) ? mainAxis : altAxis; | ||
@@ -360,28 +372,38 @@ if (axis != null) { | ||
var format = ((str, ...args) => [...args].reduce((p, c) => p.replace(/%s/, c), str)); | ||
var format = (function (str) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return [].concat(args).reduce(function (p, c) { | ||
return p.replace(/%s/, c); | ||
}, str); | ||
}); | ||
function microtaskDebounce(fn) { | ||
let called = false; | ||
return () => new Promise(resolve => { | ||
if (called) { | ||
return resolve(); | ||
} | ||
var called = false; | ||
return function () { | ||
return new Promise(function (resolve) { | ||
if (called) { | ||
return resolve(); | ||
} | ||
called = true; | ||
Promise.resolve().then(() => { | ||
called = false; | ||
resolve(fn()); | ||
called = true; | ||
Promise.resolve().then(function () { | ||
called = false; | ||
resolve(fn()); | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
const ERROR_MESSAGE = 'PopperJS: modifier "%s" provided an invalid %s property, expected %s but got %s'; | ||
const VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'onLoad', 'requires', 'options']; | ||
var validateModifiers = (modifiers => { | ||
modifiers.forEach(modifier => { | ||
Object.keys(modifier).forEach(key => { | ||
var ERROR_MESSAGE = 'PopperJS: modifier "%s" provided an invalid %s property, expected %s but got %s'; | ||
var VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'onLoad', 'requires', 'options']; | ||
var validateModifiers = (function (modifiers) { | ||
modifiers.forEach(function (modifier) { | ||
Object.keys(modifier).forEach(function (key) { | ||
switch (key) { | ||
case 'name': | ||
if (typeof modifier.name !== 'string') { | ||
console.error(format(ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', `"${String(modifier.name)}"`)); | ||
console.error(format(ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\"")); | ||
} | ||
@@ -393,3 +415,3 @@ | ||
if (typeof modifier.enabled !== 'boolean') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', `"${String(modifier.enabled)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\"")); | ||
} | ||
@@ -399,3 +421,3 @@ | ||
if (![read, main, write].includes(modifier.phase)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', `"${String(modifier.phase)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', "\"" + String(modifier.phase) + "\"")); | ||
} | ||
@@ -407,3 +429,3 @@ | ||
if (typeof modifier.fn !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"fn"', '"function"', `"${String(modifier.fn)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
@@ -415,3 +437,3 @@ | ||
if (typeof modifier.onLoad !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', `"${String(modifier.fn)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
@@ -423,3 +445,3 @@ | ||
if (!Array.isArray(modifier.requires)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"requires"', '"array"', `"${String(modifier.requires)}"`)); | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\"")); | ||
} | ||
@@ -433,3 +455,5 @@ | ||
default: | ||
console.error(`PopperJS: an invalid property has been provided to the "${modifier.name}" modifier, valid properties are ${VALID_PROPERTIES.map(s => `"${s}"`).join(', ')}; but "${key}" was provided.`); | ||
console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) { | ||
return "\"" + s + "\""; | ||
}).join(', ') + "; but \"" + key + "\" was provided."); | ||
} | ||
@@ -440,3 +464,3 @@ }); | ||
var getBoundingClientRect = (element => { | ||
var getBoundingClientRect = (function (element) { | ||
return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
@@ -448,11 +472,11 @@ }); | ||
function getClippingParent(element) { | ||
const scrollParent = getScrollParent(element); | ||
const offsetParent = getOffsetParent(element); | ||
const win = getWindow(element); | ||
var scrollParent = getScrollParent(element); | ||
var offsetParent = getOffsetParent(element); | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent))); | ||
} | ||
var getDocumentRect = (element => { | ||
const win = getWindow(element); | ||
const documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
var getDocumentRect = (function (element) { | ||
var win = getWindow(element); | ||
var documentRect = getElementClientRect(element.ownerDocument.documentElement); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
@@ -463,17 +487,23 @@ documentRect.width = Math.max(documentRect.width, win.innerWidth); | ||
var rectToClientRect = (rect => _objectSpread2({}, rect, { | ||
left: rect.x, | ||
top: rect.y, | ||
right: rect.x + rect.width, | ||
bottom: rect.y + rect.height | ||
})); | ||
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 = { | ||
boundaryElement: getClippingParent(state.elements.popper) | ||
}) { | ||
const popperElement = state.elements.popper; | ||
const referenceElement = state.elements.reference; | ||
const popperRect = state.measures.popper; | ||
const documentElement = options.boundaryElement.ownerDocument.documentElement; | ||
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)) { | ||
@@ -484,5 +514,5 @@ console.error('PopperJS: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
const boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect(getDocumentRect(documentElement)) : getBoundingClientRect(options.boundaryElement); | ||
const referenceClientRect = getBoundingClientRect(referenceElement); | ||
const popperOffsets = computeOffsets({ | ||
var boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect(getDocumentRect(documentElement)) : getBoundingClientRect(options.boundaryElement); | ||
var referenceClientRect = getBoundingClientRect(referenceElement); | ||
var popperOffsets = computeOffsets({ | ||
reference: referenceClientRect, | ||
@@ -497,3 +527,3 @@ element: popperRect, | ||
}); | ||
const popperClientRect = rectToClientRect(_objectSpread2({}, popperRect, {}, popperOffsets)); | ||
var popperClientRect = rectToClientRect(_extends({}, popperRect, {}, popperOffsets)); | ||
state.modifiersData.detectOverflow = { | ||
@@ -517,3 +547,3 @@ top: boundaryClientRect.top - popperClientRect.top, | ||
// that can be applied to the popper element to make it render in the expected position. | ||
const mapStrategyToPosition = strategy => { | ||
var mapStrategyToPosition = function mapStrategyToPosition(strategy) { | ||
switch (strategy) { | ||
@@ -528,12 +558,12 @@ case 'fixed': | ||
}; | ||
const computePopperStyles = ({ | ||
offsets, | ||
strategy, | ||
gpuAcceleration | ||
}) => { | ||
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`, | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: mapStrategyToPosition(strategy) | ||
@@ -543,3 +573,5 @@ }; | ||
return { | ||
transform: `translate3d(${offsets.x}px, ${offsets.y}px, 0)`, | ||
top: '0px', | ||
left: '0px', | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: mapStrategyToPosition(strategy) | ||
@@ -549,10 +581,10 @@ }; | ||
}; | ||
const computeArrowStyles = ({ | ||
offsets, | ||
gpuAcceleration | ||
}) => { | ||
var computeArrowStyles = function computeArrowStyles(_ref2) { | ||
var offsets = _ref2.offsets, | ||
gpuAcceleration = _ref2.gpuAcceleration; | ||
if (gpuAcceleration) { | ||
return { | ||
top: `${offsets.y}px`, | ||
left: `${offsets.x}px`, | ||
top: offsets.y + "px", | ||
left: offsets.x + "px", | ||
position: 'absolute' | ||
@@ -562,3 +594,3 @@ }; | ||
return { | ||
transform: `translate3d(${offsets.x}px, ${offsets.y}px, 0)`, | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: 'absolute' | ||
@@ -569,3 +601,3 @@ }; | ||
function computeStyles(state, options) { | ||
const gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
var gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
state.styles = {}; // popper offsets are always available | ||
@@ -576,3 +608,3 @@ | ||
strategy: state.options.strategy, | ||
gpuAcceleration | ||
gpuAcceleration: gpuAcceleration | ||
}); // arrow offsets may not be available | ||
@@ -583,3 +615,3 @@ | ||
offsets: state.offsets.arrow, | ||
gpuAcceleration | ||
gpuAcceleration: gpuAcceleration | ||
}); | ||
@@ -600,5 +632,5 @@ } | ||
function applyStyles(state) { | ||
Object.keys(state.elements).forEach(name => { | ||
const style = state.styles.hasOwnProperty(name) ? state.styles[name] : null; // Flow doesn't support to extend this property, but it's the most | ||
// effective way to apply styles to an HTMLElemen | ||
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 | ||
@@ -610,2 +642,17 @@ | ||
} | ||
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 = { | ||
@@ -616,2 +663,3 @@ name: 'applyStyles', | ||
fn: applyStyles, | ||
onDestroy: onDestroy, | ||
requires: ['computeStyles'] | ||
@@ -621,8 +669,12 @@ }; | ||
function distanceAndSkiddingToXY(placement, measures, getOffsets) { | ||
const basePlacement = getBasePlacement(placement); | ||
const invertDistance = ['left', 'top'].includes(basePlacement) ? -1 : 1; | ||
const invertSkidding = ['top', 'bottom'].includes(basePlacement) ? -1 : 1; | ||
let [distance, skidding] = getOffsets(_objectSpread2({}, measures, { | ||
placement | ||
})); | ||
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; | ||
@@ -634,3 +686,6 @@ skidding = (distance || 0) * invertSkidding; | ||
if (options && typeof options.offset === 'function') { | ||
const [x, y] = distanceAndSkiddingToXY(state.placement, state.measures, options.offset); | ||
var _distanceAndSkiddingT = distanceAndSkiddingToXY(state.placement, state.measures, options.offset), | ||
x = _distanceAndSkiddingT[0], | ||
y = _distanceAndSkiddingT[1]; | ||
state.offsets.popper.x += x; | ||
@@ -649,3 +704,3 @@ state.offsets.popper.y += y; | ||
const hash = { | ||
var hash = { | ||
left: 'right', | ||
@@ -656,12 +711,18 @@ right: 'left', | ||
}; | ||
var getOppositePlacement = (placement => placement.replace(/left|right|bottom|top/g, matched => hash[matched])); | ||
var getOppositePlacement = (function (placement) { | ||
return placement.replace(/left|right|bottom|top/g, function (matched) { | ||
return hash[matched]; | ||
}); | ||
}); | ||
function flip(state, options) { | ||
const placement = state.placement; | ||
const behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement(placement)]; | ||
const overflow = state.modifiersData.detectOverflow; | ||
const flippedPlacement = behavior.find(newPlacement => overflow[getBasePlacement(newPlacement)] <= 0); | ||
var placement = state.placement; | ||
var behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement(placement)]; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var flippedPlacement = behavior.find(function (newPlacement) { | ||
return overflow[getBasePlacement(newPlacement)] <= 0; | ||
}); | ||
if (flippedPlacement && flippedPlacement !== placement) { | ||
state = _objectSpread2({}, state, { | ||
state = _extends({}, state, { | ||
placement: flippedPlacement, | ||
@@ -681,4 +742,44 @@ reset: true | ||
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; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var basePlacement = getBasePlacement(state.placement); | ||
var mainAxis = getMainAxisFromPlacement(basePlacement); | ||
var altAxis = getAltAxis(mainAxis); | ||
var popperOffsets = state.offsets.popper; | ||
if (checkMainAxis) { | ||
var mainSide = mainAxis === 'y' ? top : left; | ||
var altSide = mainAxis === 'y' ? bottom : right; | ||
state.offsets.popper[mainAxis] = Math.max(Math.min(popperOffsets[mainAxis], popperOffsets[mainAxis] - overflow[altSide]), popperOffsets[mainAxis] + overflow[mainSide]); | ||
} | ||
if (checkAltAxis) { | ||
var _mainSide = mainAxis === 'x' ? top : left; | ||
var _altSide = mainAxis === 'x' ? bottom : right; | ||
console.log(altAxis, _mainSide, overflow[_altSide]); | ||
state.offsets.popper[altAxis] = Math.max(Math.min(popperOffsets[altAxis], popperOffsets[altAxis] - overflow[_altSide]), popperOffsets[altAxis] + overflow[_mainSide]); | ||
} | ||
return state; | ||
} | ||
var preventOverflow$1 = { | ||
name: 'flip', | ||
enabled: true, | ||
phase: 'main', | ||
fn: preventOverflow | ||
}; | ||
var modifiers = /*#__PURE__*/Object.freeze({ | ||
@@ -689,10 +790,13 @@ detectOverflow: detectOverflow$1, | ||
offset: offset$1, | ||
flip: flip$1 | ||
flip: flip$1, | ||
preventOverflow: preventOverflow$1 | ||
}); | ||
const defaultModifiers = Object.values(modifiers); | ||
var defaultModifiers = Object.values(modifiers); | ||
const areValidElements = (a, b) => a instanceof Element && b instanceof Element; | ||
var areValidElements = function areValidElements(a, b) { | ||
return a instanceof Element && b instanceof Element; | ||
}; | ||
const defaultOptions = { | ||
var defaultOptions = { | ||
placement: 'bottom', | ||
@@ -706,4 +810,13 @@ eventListeners: { | ||
}; | ||
class Popper { | ||
constructor(reference, popper, options = defaultOptions) { | ||
var Popper = | ||
/*#__PURE__*/ | ||
function () { | ||
function Popper(reference, popper, options) { | ||
var _this = this; | ||
if (options === void 0) { | ||
options = defaultOptions; | ||
} | ||
_defineProperty(this, "state", { | ||
@@ -716,7 +829,10 @@ placement: 'bottom', | ||
_defineProperty(this, "update", microtaskDebounce(() => new Promise((success, reject) => { | ||
this.forceUpdate(); | ||
success(this.state); | ||
}))); | ||
_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 | ||
@@ -728,11 +844,10 @@ // wrapped by jQuery, otherwise consume them as is | ||
}; | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; // Store options into state | ||
var _this$state$elements = this.state.elements, | ||
referenceElement = _this$state$elements.reference, | ||
popperElement = _this$state$elements.popper; // Store options into state | ||
this.state.options = _objectSpread2({}, defaultOptions, {}, options); // Cache the placement in cache to make it available to the modifiers | ||
this.state.options = _extends({}, defaultOptions, {}, options); // 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 = options.placement; // Don't proceed if `reference` or `popper` are invalid elements | ||
this.state.placement = this.state.options.placement; // Don't proceed if `reference` or `popper` are invalid elements | ||
@@ -749,6 +864,9 @@ if (!areValidElements(referenceElement, popperElement)) { | ||
this.state.orderedModifiers = orderModifiers([...defaultModifiers, ...this.state.options.modifiers]) // Apply user defined preferences to modifiers | ||
.map(modifier => _objectSpread2({}, modifier, {}, this.state.options.modifiers.find(({ | ||
name | ||
}) => name === modifier.name))); // Validate the provided modifiers so that the consumer will get warned | ||
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 | ||
@@ -764,9 +882,10 @@ | ||
this.state.orderedModifiers.forEach(({ | ||
onLoad, | ||
enabled | ||
}) => enabled && onLoad && onLoad(this.state)); | ||
this.update().then(() => { | ||
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); | ||
_this.enableEventListeners(_this.state.options.eventListeners); | ||
}); | ||
@@ -778,10 +897,11 @@ } // Async and optimistically optimized update | ||
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 | ||
forceUpdate() { | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; // Don't proceed if `reference` or `popper` are not valid elements anymore | ||
_proto.forceUpdate = function forceUpdate() { | ||
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 | ||
@@ -804,3 +924,3 @@ if (!areValidElements(referenceElement, popperElement)) { | ||
const offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Offsets are the actual position the popper needs to have to be | ||
var offsetParentScroll = getElementScroll(getOffsetParent(popperElement)); // Offsets are the actual position the popper needs to have to be | ||
// properly positioned near its reference element | ||
@@ -823,8 +943,7 @@ // This is the most basic placement, and will be adjusted by | ||
for (let index = 0; index < this.state.orderedModifiers.length; index++) { | ||
const { | ||
fn, | ||
enabled, | ||
options | ||
} = this.state.orderedModifiers[index]; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
@@ -841,23 +960,26 @@ if (this.state.reset === true) { | ||
} | ||
} | ||
}; | ||
enableEventListeners(eventListeners) { | ||
const { | ||
reference: referenceElement, | ||
popper: popperElement | ||
} = this.state.elements; | ||
const { | ||
scroll, | ||
resize | ||
} = expandEventListeners(eventListeners); | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this2 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _expandEventListeners = expandEventListeners(eventListeners), | ||
scroll = _expandEventListeners.scroll, | ||
resize = _expandEventListeners.resize; | ||
if (scroll) { | ||
const scrollParents = [...this.state.scrollParents.reference, ...this.state.scrollParents.popper]; | ||
scrollParents.forEach(scrollParent => scrollParent.addEventListener('scroll', this.update, { | ||
passive: true | ||
})); | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this2.update, { | ||
passive: true | ||
}); | ||
}); | ||
} | ||
if (resize) { | ||
const window = getWindow(this.state.elements.popper); | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
@@ -867,6 +989,26 @@ passive: true | ||
} | ||
} | ||
}; | ||
} | ||
_proto.destroy = function destroy() { | ||
var _this3 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this3.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 (_ref3) { | ||
var onDestroy = _ref3.onDestroy, | ||
enabled = _ref3.enabled; | ||
return enabled && onDestroy && onDestroy(_this3.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
return Popper; | ||
@@ -873,0 +1015,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,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function t(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,r)}return o}function o(o){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?t(n,!0).forEach(function(t){e(o,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(n)):t(n).forEach(function(e){Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(n,e))})}return o}function r(e){const t=e.ownerDocument;return t?t.defaultView:window}function n(e){return r(e).getComputedStyle(e)}var s=e=>{const t=e.offsetWidth,o=e.offsetHeight,r=e.offsetTop,s=e.offsetLeft,i=(e=>{const 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:o+i.top+i.bottom,y:r-i.top,x:s-i.left}},i=e=>"HTML"===e.nodeName?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){const{overflow:t,overflowX:o,overflowY:r}=n(e);if(/(auto|scroll|overlay)/.test(t+r+o))return e}return a(i(e))}function l(e,t=[]){const o=a(e),r="BODY"===o.nodeName,n=r?o.ownerDocument.defaultView:o,s=t.concat(n);return r?s:s.concat(l(i(n)))}function c(e){return e!==r(e)&&e instanceof HTMLElement?{scrollLeft:(t=e).scrollLeft,scrollTop:t.scrollTop}:function(e){const t=r(e);return{scrollLeft:t.pageXOffset,scrollTop:t.pageYOffset}}(e);var t}function p(e){const t=e instanceof HTMLElement?e.offsetParent:null,o=r(e);return t&&t.nodeName&&"BODY"===t.nodeName.toUpperCase()?o:t||o}const f=e=>e.reduce((e,t)=>{const o=c(t);return e.scrollTop+=o.scrollTop,e.scrollLeft+=o.scrollLeft,e},{scrollTop:0,scrollLeft:0});function u(e,t,o,r){t.filter(e=>!o.includes(e));const n=p(e),s=t.findIndex(e=>e===(r||n)),i=t.slice(0,-1===s?void 0:s);return f(i)}var d=e=>e&&e.jquery?e[0]:e;const m=e=>{const t=e.reduce((e,t)=>(e[t.name]=t,e),{}),o=e=>t[e].requires?t[e].requires.reduce((e,t)=>[...e,t,...o(t)],[]):[];return e.sort((e,t)=>~o(t.name).indexOf(e.name)?-1:1)};var h=e=>[...m(e.filter(({phase:e})=>"read"===e)),...m(e.filter(({phase:e})=>"main"===e)),...m(e.filter(({phase:e})=>"afterMain"===e)),...m(e.filter(({phase:e})=>"write"===e))],y=e=>{const t="boolean"==typeof e&&e;return{scroll:"boolean"==typeof e.scroll?e.scroll:t,resize:"boolean"==typeof e.resize?e.resize:t}},b=e=>e.split("-")[0];const g="right",w="left";["top","bottom",g,w].reduce((e,t)=>e.concat([t,`${t}-start`,`${t}-end`]),[]);var v=({reference:e,element:t,strategy:o,placement:r,scroll:n})=>{const s=r?b(r):null,i=r?(e=>e.split("-")[1])(r):null,{scrollTop:a,scrollLeft:l}=n;let c;switch(s){case"top":c={x:e.x+e.width/2-t.width/2-l,y:e.y-t.height-a};break;case"bottom":c={x:e.x+e.width/2-t.width/2-l,y:e.y+e.height-a};break;case g:c={x:e.x+e.width-l,y:e.y+e.height/2-t.height/2-a};break;case w:c={x:e.x-t.width-l,y:e.y+e.height/2-t.height/2-a};break;default:c={x:e.x-l,y:e.y-a}}const p=r?(e=>["top","bottom"].includes(e)?"x":"y")(r):null,f=p?(e=>"x"===e?"y":"x")(p):null,u="x"===f?"width":"height",d=[g,w].includes(s)?p:f;if(null!=d)switch(i){case"start":c[d]-=t[u]/2;break;case"end":c[d]+=t[u]/2}return c};var x=e=>JSON.parse(JSON.stringify(e.getBoundingClientRect()));function O(e){const t=a(e),o=p(e);return o===r(e)?e.ownerDocument.documentElement:t.contains(o)?t:O(a(i(t)))}var E=e=>{const t=r(e),o=s(e.ownerDocument.documentElement);return o.height=Math.max(o.height,t.innerHeight),o.width=Math.max(o.width,t.innerWidth),o},L=e=>o({},e,{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height});var P={name:"detectOverflow",enabled:!0,phase:"read",fn:function(e,t={boundaryElement:O(e.elements.popper)}){const r=e.elements.popper,n=e.elements.reference,s=e.measures.popper,i=t.boundaryElement.ownerDocument.documentElement;if(!t.boundaryElement.contains(r))return console.error('PopperJS: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'),e;const a=i===t.boundaryElement?L(E(i)):x(t.boundaryElement),l=x(n),c=v({reference:l,element:s,strategy:"absolute",placement:e.options.placement,scroll:{scrollTop:0,scrollLeft:0}}),p=L(o({},s,{},c));return e.modifiersData.detectOverflow={top:a.top-p.top,bottom:p.bottom-a.bottom,left:a.left-p.left,right:p.right-a.right},e},data:{}};const D=e=>{switch(e){case"fixed":return"fixed";case"absolute":default:return"absolute"}},j=({offsets:e,strategy:t,gpuAcceleration:o})=>!1===o?{top:`${e.y}px`,left:`${e.x}px`,position:D(t)}:{transform:`translate3d(${e.x}px, ${e.y}px, 0)`,position:D(t)},T=({offsets:e,gpuAcceleration:t})=>t?{top:`${e.y}px`,left:`${e.x}px`,position:"absolute"}:{transform:`translate3d(${e.x}px, ${e.y}px, 0)`,position:"absolute"};var M={name:"computeStyles",enabled:!0,phase:"afterMain",fn:function(e,t){const o=!t||null==t.gpuAcceleration||t.gpuAcceleration;return e.styles={},e.styles.popper=j({offsets:e.offsets.popper,strategy:e.options.strategy,gpuAcceleration:o}),null!=e.offsets.arrow&&(e.styles.arrow=T({offsets:e.offsets.arrow,gpuAcceleration:o})),e}};var S={name:"applyStyles",enabled:!0,phase:"write",fn:function(e){return Object.keys(e.elements).forEach(t=>{const o=e.styles.hasOwnProperty(t)?e.styles[t]:null;Object.assign(e.elements[t].style,o)}),e},requires:["computeStyles"]};var $={name:"offset",enabled:!0,phase:"main",fn:function(e,t){if(t&&"function"==typeof t.offset){const[r,n]=function(e,t,r){const n=b(e),s=["left","top"].includes(n)?-1:1,i=["top","bottom"].includes(n)?-1:1;let[a,l]=r(o({},t,{placement:e}));return l=((a=(a||0)*s)||0)*i,["left","right"].includes(n)?[a,l]:[l,a]}(e.placement,e.measures,t.offset);e.offsets.popper.x+=r,e.offsets.popper.y+=n}return e}};const N={left:"right",right:"left",bottom:"top",top:"bottom"};var k=e=>e.replace(/left|right|bottom|top/g,e=>N[e]);var z={name:"flip",enabled:!0,phase:"main",fn:function(e,t){const r=e.placement,n=t&&t.behavior?t.behavior:[e.options.placement,k(r)],s=e.modifiersData.detectOverflow,i=n.find(e=>s[b(e)]<=0);return i&&i!==r&&(e=o({},e,{placement:i,reset:!0})),e}},H=Object.freeze({detectOverflow:P,computeStyles:M,applyStyles:S,offset:$,flip:z});const A=Object.values(H),B=(e,t)=>e instanceof Element&&t instanceof Element,Y={placement:"bottom",eventListeners:{scroll:!0,resize:!0},modifiers:[],strategy:"absolute"};return class{constructor(t,r,n=Y){e(this,"state",{placement:"bottom",orderedModifiers:[],options:Y,modifiersData:{}}),e(this,"update",function(e){let t=!1;return()=>new Promise(o=>{if(t)return o();t=!0,Promise.resolve().then(()=>{t=!1,o(e())})})}(()=>new Promise((e,t)=>{this.forceUpdate(),e(this.state)}))),this.state.elements={reference:d(t),popper:d(r)};const{reference:s,popper:i}=this.state.elements;this.state.options=o({},Y,{},n),this.state.placement=n.placement,B(s,i)&&(this.state.scrollParents={reference:l(s),popper:l(i)},this.state.orderedModifiers=h([...A,...this.state.options.modifiers]).map(e=>o({},e,{},this.state.options.modifiers.find(({name:t})=>t===e.name))),this.state.orderedModifiers.forEach(({onLoad:e,enabled:t})=>t&&e&&e(this.state)),this.update().then(()=>{this.enableEventListeners(this.state.options.eventListeners)}))}forceUpdate(){const{reference:e,popper:t}=this.state.elements;if(B(e,t)){this.state.measures={reference:s(e),popper:s(t)},c(p(t)),this.state.offsets={popper:v({reference:this.state.measures.reference,element:this.state.measures.popper,strategy:"absolute",placement:this.state.placement,scroll:u(e,this.state.scrollParents.reference,this.state.scrollParents.popper)})},this.state.reset=!1;for(let e=0;e<this.state.orderedModifiers.length;e++){const{fn:t,enabled:o,options:r}=this.state.orderedModifiers[e];!0!==this.state.reset?o&&"function"==typeof t&&(this.state=t(this.state,r)):(this.state.reset=!1,e=0)}}}enableEventListeners(e){const{reference:t,popper:o}=this.state.elements,{scroll:n,resize:s}=y(e);n&&[...this.state.scrollParents.reference,...this.state.scrollParents.popper].forEach(e=>e.addEventListener("scroll",this.update,{passive:!0})),s&&r(this.state.elements.popper).addEventListener("resize",this.update,{passive:!0})}}}); | ||
!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,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function n(e){var t=e.ownerDocument;return t?t.defaultView:window}function r(e){return n(e).getComputedStyle(e)}var o=function(e){var t=e.offsetWidth,n=e.offsetHeight,o=e.offsetTop,s=e.offsetLeft,i=function(e){var t=r(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:n+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=r(e),n=t.overflow,o=t.overflowX,s=t.overflowY;if(/(auto|scroll|overlay)/.test(n+s+o))return e}return a(i(e))}function f(e,t){void 0===t&&(t=[]);var n=a(e),r="BODY"===s(n),o=r?n.ownerDocument.defaultView:n,c=t.concat(o);return r?c:c.concat(f(i(o)))}function c(e){return e!==n(e)&&e instanceof HTMLElement?{scrollLeft:(t=e).scrollLeft,scrollTop:t.scrollTop}:function(e){var t=n(e);return{scrollLeft:t.pageXOffset,scrollTop:t.pageYOffset}}(e);var t}function l(e){var t=e instanceof HTMLElement?e.offsetParent:null,r=n(e);return"BODY"===s(t)?r:t||r}var u=function(e){return e.reduce(function(e,t){var n=c(t);return e.scrollTop+=n.scrollTop,e.scrollLeft+=n.scrollLeft,e},{scrollTop:0,scrollLeft:0})};function p(e,t,n,r){t.filter(function(e){return!n.includes(e)});var o=l(e),s=t.findIndex(function(e){return e===(r||o)}),i=t.slice(0,-1===s?void 0:s);return u(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,n){return~function e(n){return t[n].requires?t[n].requires.reduce(function(t,n){return[].concat(t,[n],e(n))},[]):[]}(n.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})))},v=function(e){return e.split("-")[0]},y=function(e){return["top","bottom"].includes(e)?"x":"y"},b=function(e){return"x"===e?"y":"x"},g="top",w="bottom",x="right",O="left",E=([g,w,x,O].reduce(function(e,t){return e.concat([t,t+"-start",t+"-end"])},[]),function(e){var t,n=e.reference,r=e.element,o=(e.strategy,e.placement),s=e.scroll,i=o?v(o):null,a=o?function(e){return e.split("-")[1]}(o):null,f=s.scrollTop,c=s.scrollLeft;switch(i){case g:t={x:n.x+n.width/2-r.width/2-c,y:n.y-r.height-f};break;case w:t={x:n.x+n.width/2-r.width/2-c,y:n.y+n.height-f};break;case x:t={x:n.x+n.width-c,y:n.y+n.height/2-r.height/2-f};break;case O:t={x:n.x-r.width-c,y:n.y+n.height/2-r.height/2-f};break;default:t={x:n.x-c,y:n.y-f}}var l=o?y(o):null,u=l?b(l):null,p="x"===u?"width":"height",d=[x,O].includes(i)?l:u;if(null!=d)switch(a){case"start":t[d]-=r[p]/2;break;case"end":t[d]+=r[p]/2}return t});var L=function(e){return JSON.parse(JSON.stringify(e.getBoundingClientRect()))};function M(e){var t=a(e),r=l(e);return r===n(e)?e.ownerDocument.documentElement:t.contains(r)?t:M(a(i(t)))}var P=function(e){var t=n(e),r=o(e.ownerDocument.documentElement);return r.height=Math.max(r.height,t.innerHeight),r.width=Math.max(r.width,t.innerWidth),r},D=function(e){return t({},e,{left:e.x,top:e.y,right:e.x+e.width,bottom:e.y+e.height})};var T={name:"detectOverflow",enabled:!0,phase:"read",fn:function(e,n){void 0===n&&(n={boundaryElement:M(e.elements.popper)});var r=e.elements.popper,o=e.elements.reference,s=e.measures.popper,i=n.boundaryElement.ownerDocument.documentElement;if(!n.boundaryElement.contains(r))return console.error('PopperJS: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'),e;var a=i===n.boundaryElement?D(P(i)):L(n.boundaryElement),f=L(o),c=E({reference:f,element:s,strategy:"absolute",placement:e.options.placement,scroll:{scrollTop:0,scrollLeft:0}}),l=D(t({},s,{},c));return e.modifiersData.detectOverflow={top:a.top-l.top,bottom:l.bottom-a.bottom,left:a.left-l.left,right:l.right-a.right},e},data:{}},j=function(e){switch(e){case"fixed":return"fixed";case"absolute":default:return"absolute"}},S=function(e){var t=e.offsets,n=e.strategy;return!1===e.gpuAcceleration?{top:t.y+"px",left:t.x+"px",position:j(n)}:{top:"0px",left:"0px",transform:"translate3d("+t.x+"px, "+t.y+"px, 0)",position:j(n)}},k=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){var n=!t||null==t.gpuAcceleration||t.gpuAcceleration;return e.styles={},e.styles.popper=S({offsets:e.offsets.popper,strategy:e.options.strategy,gpuAcceleration:n}),null!=e.offsets.arrow&&(e.styles.arrow=k({offsets:e.offsets.arrow,gpuAcceleration:n})),e}};var A={name:"applyStyles",enabled:!0,phase:"write",fn:function(e){return Object.keys(e.elements).forEach(function(t){var n=e.styles.hasOwnProperty(t)?e.styles[t]:{};Object.assign(e.elements[t].style,n)}),e},onDestroy:function(e){Object.keys(e.elements).forEach(function(n){var r=Object.keys(e.styles.hasOwnProperty(n)?t({},e.styles[n]):{}).reduce(function(e,n){var r;return t({},e,((r={})[String(n)]="",r))},{});Object.assign(e.elements[n].style,r)})},requires:["computeStyles"]};var H={name:"offset",enabled:!0,phase:"main",fn:function(e,n){if(n&&"function"==typeof n.offset){var r=(i=e.placement,a=e.measures,f=n.offset,c=v(i),l=["left","top"].includes(c)?-1:1,u=["top","bottom"].includes(c)?-1:1,p=f(t({},a,{placement:i})),d=p[0],m=p[1],m=((d=(d||0)*l)||0)*u,["left","right"].includes(c)?[d,m]:[m,d]),o=r[0],s=r[1];e.offsets.popper.x+=o,e.offsets.popper.y+=s}var i,a,f,c,l,u,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]})};var Y={name:"flip",enabled:!0,phase:"main",fn:function(e,n){var r=e.placement,o=n&&n.behavior?n.behavior:[e.options.placement,N(r)],s=e.modifiersData.detectOverflow,i=o.find(function(e){return s[v(e)]<=0});return i&&i!==r&&(e=t({},e,{placement:i,reset:!0})),e}};var q={name:"flip",enabled:!0,phase:"main",fn:function(e,t){void 0===t&&(t={});var n=t,r=n.mainAxis,o=void 0===r||r,s=n.altAxis,i=void 0!==s&&s,a=e.modifiersData.detectOverflow,f=v(e.placement),c=y(f),l=b(c),u=e.offsets.popper;if(o){var p="y"===c?g:O,d="y"===c?w:x;e.offsets.popper[c]=Math.max(Math.min(u[c],u[c]-a[d]),u[c]+a[p])}if(i){var m="x"===c?g:O,h="x"===c?w:x;console.log(l,m,a[h]),e.offsets.popper[l]=Math.max(Math.min(u[l],u[l]-a[h]),u[l]+a[m])}return e}},C=Object.freeze({detectOverflow:T,computeStyles:z,applyStyles:A,offset:H,flip:Y,preventOverflow:q}),F=Object.values(C),U=function(e,t){return e instanceof Element&&t instanceof Element},J={placement:"bottom",eventListeners:{scroll:!0,resize:!0},modifiers:[],strategy:"absolute"};return function(){function r(n,r,o){var s,i,a=this;void 0===o&&(o=J),e(this,"state",{placement:"bottom",orderedModifiers:[],options:J,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(n),popper:d(r)};var c=this.state.elements,l=c.reference,u=c.popper;this.state.options=t({},J,{},o),this.state.placement=this.state.options.placement,U(l,u)&&(this.state.scrollParents={reference:f(l),popper:f(u)},this.state.orderedModifiers=h([].concat(F,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=r.prototype;return s.forceUpdate=function(){var e=this.state.elements,t=e.reference,n=e.popper;if(U(t,n)){this.state.measures={reference:o(t),popper:o(n)};c(l(n));this.state.offsets={popper:E({reference:this.state.measures.reference,element:this.state.measures.popper,strategy:"absolute",placement:this.state.placement,scroll:p(t,this.state.scrollParents.reference,this.state.scrollParents.popper)})},this.state.reset=!1;for(var r=0;r<this.state.orderedModifiers.length;r++){var s=this.state.orderedModifiers[r],i=s.fn,a=s.enabled,f=s.options;!0!==this.state.reset?a&&"function"==typeof i&&(this.state=i(this.state,f)):(this.state.reset=!1,r=0)}}},s.enableEventListeners=function(e){var t=this,r=this.state.elements,o=(r.reference,r.popper,function(e){var t="boolean"==typeof e&&e;return{scroll:"boolean"==typeof e.scroll?e.scroll:t,resize:"boolean"==typeof e.resize?e.resize:t}}(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&&n(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)}),n(this.state.elements.popper).removeEventListener("resize",this.update),this.state.orderedModifiers.forEach(function(t){var n=t.onDestroy;return t.enabled&&n&&n(e.state)})},r}()}); | ||
//# sourceMappingURL=popper.min.js.map |
@@ -1,5 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (element) { | ||
return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
}); | ||
export default (function (element) { | ||
return JSON.parse(JSON.stringify(element.getBoundingClientRect())); | ||
}); |
@@ -1,14 +0,12 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getScrollParent_1 = require("./getScrollParent"); | ||
var getOffsetParent_1 = require("./getOffsetParent"); | ||
var getParentNode_1 = require("./getParentNode"); | ||
var getWindow_1 = require("./getWindow"); // A "clipping parent" is a scrolling container with the characteristic of | ||
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 | ||
// clipping (or hiding) overflowing elements with a position different from `initial` | ||
function getClippingParent(element) { | ||
var scrollParent = getScrollParent_1["default"](element); | ||
var offsetParent = getOffsetParent_1["default"](element); | ||
var win = getWindow_1["default"](element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent_1["default"](getParentNode_1["default"](scrollParent))); | ||
} | ||
exports["default"] = getClippingParent; | ||
export default function getClippingParent(element) { | ||
var scrollParent = getScrollParent(element); | ||
var offsetParent = getOffsetParent(element); | ||
var win = getWindow(element); | ||
return offsetParent === win ? element.ownerDocument.documentElement : scrollParent.contains(offsetParent) ? scrollParent : getClippingParent(getScrollParent(getParentNode(scrollParent))); | ||
} |
@@ -1,25 +0,31 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getNodeScroll_1 = require("./getNodeScroll"); | ||
var getOffsetParent_1 = require("./getOffsetParent"); | ||
var sumScroll = function (scrollParents) { return scrollParents.reduce(function (scroll, scrollParent) { | ||
var nodeScroll = getNodeScroll_1["default"](scrollParent); | ||
import getNodeScroll from './getNodeScroll'; | ||
import getOffsetParent from './getOffsetParent'; | ||
var sumScroll = function sumScroll(scrollParents) { | ||
return scrollParents.reduce(function (scroll, scrollParent) { | ||
var nodeScroll = getNodeScroll(scrollParent); | ||
scroll.scrollTop += nodeScroll.scrollTop; | ||
scroll.scrollLeft += nodeScroll.scrollLeft; | ||
return scroll; | ||
}, { | ||
}, { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
}); }; | ||
function getCommonTotalScroll(reference, referenceScrollParents, popperScrollParents, limiter) { | ||
// if the scrollParent is shared between the two elements, we don't pick | ||
// it because it wouldn't add anything to the equation (they nulllify themselves) | ||
var nonCommonReference = referenceScrollParents.filter(function (node) { return !popperScrollParents.includes(node); }); // we then want to pick any scroll offset except for the one of the offsetParent | ||
// not sure why but that's how I got it working 😅 | ||
// TODO: improve this comment with proper explanation | ||
var offsetParent = getOffsetParent_1["default"](reference); | ||
var index = referenceScrollParents.findIndex(function (node) { return node === (limiter || offsetParent); }); | ||
var scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
return sumScroll(scrollParents); | ||
} | ||
exports["default"] = getCommonTotalScroll; | ||
}); | ||
}; | ||
export default function getCommonTotalScroll(reference, referenceScrollParents, popperScrollParents, limiter) { | ||
// if the scrollParent is shared between the two elements, we don't pick | ||
// it because it wouldn't add anything to the equation (they nulllify themselves) | ||
var nonCommonReference = referenceScrollParents.filter(function (node) { | ||
return !popperScrollParents.includes(node); | ||
}); // we then want to pick any scroll offset except for the one of the offsetParent | ||
// not sure why but that's how I got it working 😅 | ||
// TODO: improve this comment with proper explanation | ||
var offsetParent = getOffsetParent(reference); | ||
var index = referenceScrollParents.findIndex(function (node) { | ||
return node === (limiter || offsetParent); | ||
}); | ||
var scrollParents = referenceScrollParents.slice(0, index === -1 ? undefined : index); | ||
return sumScroll(scrollParents); | ||
} |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getWindow_1 = require("./getWindow"); | ||
function getComputedStyle(element) { | ||
return getWindow_1["default"](element).getComputedStyle(element); | ||
} | ||
exports["default"] = getComputedStyle; | ||
import getWindow from './getWindow'; | ||
export default function getComputedStyle(element) { | ||
return getWindow(element).getComputedStyle(element); | ||
} |
@@ -1,11 +0,9 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getElementClientRect_1 = require("./getElementClientRect"); | ||
var getWindow_1 = require("./getWindow"); | ||
exports["default"] = (function (element) { | ||
var win = getWindow_1["default"](element); | ||
var documentRect = getElementClientRect_1["default"](element.ownerDocument.documentElement); | ||
documentRect.height = Math.max(documentRect.height, win.innerHeight); | ||
documentRect.width = Math.max(documentRect.width, win.innerWidth); | ||
return documentRect; | ||
}); | ||
import getElementClientRect from './getElementClientRect'; | ||
import getWindow from './getWindow'; | ||
export default (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; | ||
}); |
@@ -1,17 +0,16 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getElementMargins_1 = require("./getElementMargins"); // Returns the width, height and offsets of the provided element | ||
exports["default"] = (function (element) { | ||
// get the basic client rect, it doesn't include margins | ||
var width = element.offsetWidth; | ||
var height = element.offsetHeight; | ||
var top = element.offsetTop; | ||
var left = element.offsetLeft; | ||
var margins = getElementMargins_1["default"](element); | ||
return { | ||
width: width + margins.left + margins.right, | ||
height: height + margins.top + margins.bottom, | ||
y: top - margins.top, | ||
x: left - margins.left | ||
}; | ||
}); | ||
import getElementMargins from './getElementMargins'; // Returns the width, height and offsets of the provided element | ||
export default (function (element) { | ||
// get the basic client rect, it doesn't include margins | ||
var width = element.offsetWidth; | ||
var height = element.offsetHeight; | ||
var top = element.offsetTop; | ||
var left = element.offsetLeft; | ||
var margins = getElementMargins(element); | ||
return { | ||
width: width + margins.left + margins.right, | ||
height: height + margins.top + margins.bottom, | ||
y: top - margins.top, | ||
x: left - margins.left | ||
}; | ||
}); |
@@ -1,17 +0,15 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getComputedStyle_1 = require("./getComputedStyle"); | ||
exports["default"] = (function (element) { | ||
// get the element margins, we need them to properly align the popper | ||
var styles = getComputedStyle_1["default"](element); | ||
var top = parseFloat(styles.marginTop) || 0; | ||
var right = parseFloat(styles.marginRight) || 0; | ||
var bottom = parseFloat(styles.marginBottom) || 0; | ||
var left = parseFloat(styles.marginLeft) || 0; | ||
return { | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left | ||
}; | ||
}); | ||
import getComputedStyle from './getComputedStyle'; | ||
export default (function (element) { | ||
// get the element margins, we need them to properly align the popper | ||
var styles = getComputedStyle(element); | ||
var top = parseFloat(styles.marginTop) || 0; | ||
var right = parseFloat(styles.marginRight) || 0; | ||
var bottom = parseFloat(styles.marginBottom) || 0; | ||
var left = parseFloat(styles.marginLeft) || 0; | ||
return { | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left | ||
}; | ||
}); |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function getHTMLElementScroll(element) { | ||
return { | ||
scrollLeft: element.scrollLeft, | ||
scrollTop: element.scrollTop | ||
}; | ||
} | ||
exports["default"] = getHTMLElementScroll; | ||
export default function getHTMLElementScroll(element) { | ||
return { | ||
scrollLeft: element.scrollLeft, | ||
scrollTop: element.scrollTop | ||
}; | ||
} |
@@ -1,14 +0,10 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getWindowScroll_1 = require("./getWindowScroll"); | ||
var getWindow_1 = require("./getWindow"); | ||
var getHTMLElementScroll_1 = require("./getHTMLElementScroll"); | ||
function getElementScroll(node) { | ||
if (node === getWindow_1["default"](node) || !(node instanceof HTMLElement)) { | ||
return getWindowScroll_1["default"](node); | ||
} | ||
else { | ||
return getHTMLElementScroll_1["default"](node); | ||
} | ||
} | ||
exports["default"] = getElementScroll; | ||
import getWindowScroll from './getWindowScroll'; | ||
import getWindow from './getWindow'; | ||
import getHTMLElementScroll from './getHTMLElementScroll'; | ||
export default function getElementScroll(node) { | ||
if (node === getWindow(node) || !(node instanceof HTMLElement)) { | ||
return getWindowScroll(node); | ||
} else { | ||
return getHTMLElementScroll(node); | ||
} | ||
} |
@@ -1,12 +0,12 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getWindow_1 = require("./getWindow"); | ||
function getOffsetParent(element) { | ||
var offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
var window = getWindow_1["default"](element); | ||
if (offsetParent && offsetParent.nodeName && offsetParent.nodeName.toUpperCase() === 'BODY') { | ||
return window; | ||
} | ||
return offsetParent || window; | ||
} | ||
exports["default"] = getOffsetParent; | ||
import getWindow from './getWindow'; | ||
import getNodeName from './getNodeName'; | ||
export default function getOffsetParent(element) { | ||
var offsetParent = element instanceof HTMLElement ? element.offsetParent : null; | ||
var window = getWindow(element); | ||
if (getNodeName(offsetParent) === 'BODY') { | ||
return window; | ||
} | ||
return offsetParent || window; | ||
} |
@@ -1,14 +0,14 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (element) { | ||
if (element.nodeName === 'HTML') { | ||
// DocumentElement detectedF | ||
return element; | ||
} | ||
return element.parentNode || // DOM Element detected | ||
// $FlowFixMe: need a better way to handle this... | ||
element.host || // ShadowRoot detected | ||
document.ownerDocument || // Fallback to ownerDocument if available | ||
document.documentElement // Or to documentElement if everything else fails | ||
; | ||
}); | ||
import getNodeName from './getNodeName'; | ||
export default (function (element) { | ||
if (getNodeName(element) === 'HTML') { | ||
// DocumentElement detectedF | ||
return element; | ||
} | ||
return element.parentNode || // DOM Element detected | ||
// $FlowFixMe: need a better way to handle this... | ||
element.host || // ShadowRoot detected | ||
document.ownerDocument || // Fallback to ownerDocument if available | ||
document.documentElement // Or to documentElement if everything else fails | ||
; | ||
}); |
@@ -1,21 +0,25 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getParentNode_1 = require("./getParentNode"); | ||
var getComputedStyle_1 = require("./getComputedStyle"); | ||
function getScrollParent(node) { | ||
if (!node) { | ||
return document.body; | ||
import getParentNode from './getParentNode'; | ||
import getComputedStyle from './getComputedStyle'; | ||
export default function getScrollParent(node) { | ||
if (!node) { | ||
return document.body; | ||
} | ||
if (['HTML', 'BODY', '#document'].includes(node.nodeName.toUpperCase())) { | ||
return node.ownerDocument.body; | ||
} | ||
if (node instanceof HTMLElement) { | ||
// Firefox want us to check `-x` and `-y` variations as well | ||
var _getComputedStyle = getComputedStyle(node), | ||
overflow = _getComputedStyle.overflow, | ||
overflowX = _getComputedStyle.overflowX, | ||
overflowY = _getComputedStyle.overflowY; | ||
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) { | ||
return node; | ||
} | ||
if (['HTML', 'BODY', '#document'].includes(node.nodeName.toUpperCase())) { | ||
return node.ownerDocument.body; | ||
} | ||
if (node instanceof HTMLElement) { | ||
// Firefox want us to check `-x` and `-y` variations as well | ||
var _a = getComputedStyle_1["default"](node), overflow = _a.overflow, overflowX = _a.overflowX, overflowY = _a.overflowY; | ||
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) { | ||
return node; | ||
} | ||
} | ||
return getScrollParent(getParentNode_1["default"](node)); | ||
} | ||
exports["default"] = getScrollParent; | ||
} | ||
return getScrollParent(getParentNode(node)); | ||
} |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function getWindow(node) { | ||
var ownerDocument = node.ownerDocument; | ||
return ownerDocument ? ownerDocument.defaultView : window; | ||
} | ||
exports["default"] = getWindow; | ||
export default function getWindow(node) { | ||
var ownerDocument = node.ownerDocument; | ||
return ownerDocument ? ownerDocument.defaultView : window; | ||
} |
@@ -1,13 +0,10 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getWindow_1 = require("./getWindow"); | ||
function getWindowScroll(node) { | ||
var win = getWindow_1["default"](node); | ||
var scrollLeft = win.pageXOffset; | ||
var scrollTop = win.pageYOffset; | ||
return { | ||
scrollLeft: scrollLeft, | ||
scrollTop: scrollTop | ||
}; | ||
} | ||
exports["default"] = getWindowScroll; | ||
import getWindow from './getWindow'; | ||
export default function getWindowScroll(node) { | ||
var win = getWindow(node); | ||
var scrollLeft = win.pageXOffset; | ||
var scrollTop = win.pageYOffset; | ||
return { | ||
scrollLeft: scrollLeft, | ||
scrollTop: scrollTop | ||
}; | ||
} |
@@ -1,13 +0,14 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getScrollParent_1 = require("./getScrollParent"); | ||
var getParentNode_1 = require("./getParentNode"); | ||
function listScrollParents(element, list) { | ||
if (list === void 0) { list = []; } | ||
var scrollParent = getScrollParent_1["default"](element); | ||
var isBody = scrollParent.nodeName === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var updatedList = list.concat(target); | ||
return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode_1["default"](target))); | ||
} | ||
exports["default"] = listScrollParents; | ||
import getScrollParent from './getScrollParent'; | ||
import getParentNode from './getParentNode'; | ||
import getNodeName from './getNodeName'; | ||
export default function listScrollParents(element, list) { | ||
if (list === void 0) { | ||
list = []; | ||
} | ||
var scrollParent = getScrollParent(element); | ||
var isBody = getNodeName(scrollParent) === 'BODY'; | ||
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent; | ||
var updatedList = list.concat(target); | ||
return isBody ? updatedList : updatedList.concat(listScrollParents(getParentNode(target))); | ||
} |
@@ -1,15 +0,19 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.top = 'top'; | ||
exports.bottom = 'bottom'; | ||
exports.right = 'right'; | ||
exports.left = 'left'; | ||
exports.auto = 'auto'; | ||
exports.basePlacements = [exports.top, exports.bottom, exports.right, exports.left]; | ||
exports.start = 'start'; | ||
exports.end = 'end'; | ||
exports.placements = exports.basePlacements.reduce(function (acc, placement) { return acc.concat([placement, placement + "-" + exports.start, placement + "-" + exports.end]); }, []); // modifiers that need to read the DOM | ||
exports.read = 'read'; // pure-logic modifiers | ||
exports.main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
exports.afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state) | ||
exports.write = 'write'; | ||
export var top = 'top'; | ||
export var bottom = 'bottom'; | ||
export var right = 'right'; | ||
export var left = 'left'; | ||
export var auto = 'auto'; | ||
export var basePlacements = [top, bottom, right, left]; | ||
export var start = 'start'; | ||
export var end = 'end'; | ||
export var placements = basePlacements.reduce(function (acc, placement) { | ||
return acc.concat([placement, placement + "-" + start, placement + "-" + end]); | ||
}, []); // modifiers that need to read the DOM | ||
export var read = 'read'; // pure-logic modifiers | ||
export var main = 'main'; // pure-logic modifiers that run after the main phase (such as computeStyles) | ||
export var afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state) | ||
export var write = 'write'; |
392
lib/index.js
@@ -1,172 +0,232 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) | ||
symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); | ||
keys.push.apply(keys, symbols); | ||
} return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); | ||
} | ||
else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} | ||
else { | ||
ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); | ||
} | ||
} return target; } | ||
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 _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 | ||
var getElementClientRect_1 = require("./dom-utils/getElementClientRect"); | ||
var listScrollParents_1 = require("./dom-utils/listScrollParents"); | ||
var getWindow_1 = require("./dom-utils/getWindow"); | ||
var getNodeScroll_1 = require("./dom-utils/getNodeScroll"); | ||
var getOffsetParent_1 = require("./dom-utils/getOffsetParent"); | ||
var getCommonTotalScroll_1 = require("./dom-utils/getCommonTotalScroll"); // Pure Utils | ||
var unwrapJqueryElement_1 = require("./utils/unwrapJqueryElement"); | ||
var orderModifiers_1 = require("./utils/orderModifiers"); | ||
var expandEventListeners_1 = require("./utils/expandEventListeners"); | ||
var computeOffsets_1 = require("./utils/computeOffsets"); | ||
var debounce_1 = require("./utils/debounce"); | ||
var validateModifiers_1 = require("./utils/validateModifiers"); // Default modifiers | ||
var modifiers = require("./modifiers/index"); | ||
import getElementClientRect from './dom-utils/getElementClientRect'; | ||
import listScrollParents from './dom-utils/listScrollParents'; | ||
import getWindow from './dom-utils/getWindow'; | ||
import getNodeScroll from './dom-utils/getNodeScroll'; | ||
import getOffsetParent from './dom-utils/getOffsetParent'; | ||
import getCommonTotalScroll from './dom-utils/getCommonTotalScroll'; // Pure Utils | ||
import unwrapJqueryElement from './utils/unwrapJqueryElement'; | ||
import orderModifiers from './utils/orderModifiers'; | ||
import expandEventListeners from './utils/expandEventListeners'; | ||
import computeOffsets from './utils/computeOffsets'; | ||
import format from './utils/format'; | ||
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 = 'Invalid `%s` argument provided to Popper.js, it must be either a valid DOM element or a jQuery-wrapped DOM element, you provided `%s`'; | ||
var areValidElements = function (a, b) { return a instanceof Element && b instanceof Element; }; | ||
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' | ||
placement: 'bottom', | ||
eventListeners: { | ||
scroll: true, | ||
resize: true | ||
}, | ||
modifiers: [], | ||
strategy: 'absolute' | ||
}; | ||
var Popper = /** @class */ (function () { | ||
function Popper(reference, popper, options) { | ||
if (options === void 0) { options = defaultOptions; } | ||
var _this = this; | ||
_defineProperty(this, "state", { | ||
placement: 'bottom', | ||
orderedModifiers: [], | ||
options: defaultOptions, | ||
modifiersData: {} | ||
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", debounce(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); // 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; // 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 _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 = getNodeScroll(getOffsetParent(popperElement)); // 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) | ||
}) | ||
}; // Modifiers have the ability to read the current Popper.js state, included | ||
// the popper offsets, and modify it to address specifc cases | ||
this.state.reset = false; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
var _this$state$orderedMo = this.state.orderedModifiers[index], | ||
fn = _this$state$orderedMo.fn, | ||
enabled = _this$state$orderedMo.enabled, | ||
options = _this$state$orderedMo.options; | ||
if (this.state.reset === true) { | ||
this.state.reset = false; | ||
index = 0; | ||
continue; | ||
} | ||
if (enabled && typeof fn === 'function') { | ||
this.state = fn(this.state, options); | ||
} | ||
} | ||
}; | ||
_proto.enableEventListeners = function enableEventListeners(eventListeners) { | ||
var _this2 = this; | ||
var _this$state$elements3 = this.state.elements, | ||
referenceElement = _this$state$elements3.reference, | ||
popperElement = _this$state$elements3.popper; | ||
var _expandEventListeners = expandEventListeners(eventListeners), | ||
scroll = _expandEventListeners.scroll, | ||
resize = _expandEventListeners.resize; | ||
if (scroll) { | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.addEventListener('scroll', _this2.update, { | ||
passive: true | ||
}); | ||
_defineProperty(this, "update", debounce_1["default"](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_1["default"](reference), | ||
popper: unwrapJqueryElement_1["default"](popper) | ||
}; | ||
var _a = this.state.elements, referenceElement = _a.reference, popperElement = _a.popper; // Store options into state | ||
this.state.options = _objectSpread({}, defaultOptions, {}, options); // 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 = options.placement; // Don't proceed if `reference` or `popper` are invalid elements | ||
if (!areValidElements(referenceElement, popperElement)) { | ||
return; | ||
} | ||
this.state.scrollParents = { | ||
reference: listScrollParents_1["default"](referenceElement), | ||
popper: listScrollParents_1["default"](popperElement) | ||
}; // Order `options.modifiers` so that the dependencies are fulfilled | ||
// once the modifiers are executed | ||
this.state.orderedModifiers = orderModifiers_1["default"](defaultModifiers.concat(this.state.options.modifiers)) // Apply user defined preferences to modifiers | ||
.map(function (modifier) { return _objectSpread({}, modifier, {}, _this.state.options.modifiers.find(function (_a) { | ||
var name = _a.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 (__DEV__) { | ||
validateModifiers_1["default"](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 (_a) { | ||
var onLoad = _a.onLoad, enabled = _a.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 | ||
// Syncronous and forcefully executed update | ||
// it will always be executed even if not necessary, usually NOT needed | ||
// use Popper#update instead | ||
Popper.prototype.forceUpdate = function () { | ||
var _a = this.state.elements, referenceElement = _a.reference, popperElement = _a.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_1["default"](referenceElement), | ||
popper: getElementClientRect_1["default"](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 = getNodeScroll_1["default"](getOffsetParent_1["default"](popperElement)); // 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_1["default"]({ | ||
reference: this.state.measures.reference, | ||
element: this.state.measures.popper, | ||
strategy: 'absolute', | ||
placement: this.state.placement, | ||
scroll: getCommonTotalScroll_1["default"](referenceElement, this.state.scrollParents.reference, this.state.scrollParents.popper) | ||
}) | ||
}; // Modifiers have the ability to read the current Popper.js state, included | ||
// the popper offsets, and modify it to address specifc cases | ||
this.state.reset = false; | ||
for (var index = 0; index < this.state.orderedModifiers.length; index++) { | ||
var _b = this.state.orderedModifiers[index], fn = _b.fn, enabled = _b.enabled, options = _b.options; | ||
if (this.state.reset === true) { | ||
this.state.reset = false; | ||
index = 0; | ||
continue; | ||
} | ||
if (enabled && typeof fn === 'function') { | ||
this.state = fn(this.state, options); | ||
} | ||
} | ||
}; | ||
Popper.prototype.enableEventListeners = function (eventListeners) { | ||
var _this = this; | ||
var _a = this.state.elements, referenceElement = _a.reference, popperElement = _a.popper; | ||
var _b = expandEventListeners_1["default"](eventListeners), scroll = _b.scroll, resize = _b.resize; | ||
if (scroll) { | ||
var scrollParents = this.state.scrollParents.reference.concat(this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { return scrollParent.addEventListener('scroll', _this.update, { | ||
passive: true | ||
}); }); | ||
} | ||
if (resize) { | ||
var window_1 = getWindow_1["default"](this.state.elements.popper); | ||
window_1.addEventListener('resize', this.update, { | ||
passive: true | ||
}); | ||
} | ||
}; | ||
return Popper; | ||
}()); | ||
exports["default"] = Popper; | ||
}); | ||
} | ||
if (resize) { | ||
var window = getWindow(this.state.elements.popper); | ||
window.addEventListener('resize', this.update, { | ||
passive: true | ||
}); | ||
} | ||
}; | ||
_proto.destroy = function destroy() { | ||
var _this3 = this; | ||
// Remove scroll event listeners | ||
var scrollParents = [].concat(this.state.scrollParents.reference, this.state.scrollParents.popper); | ||
scrollParents.forEach(function (scrollParent) { | ||
return scrollParent.removeEventListener('scroll', _this3.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 (_ref3) { | ||
var onDestroy = _ref3.onDestroy, | ||
enabled = _ref3.enabled; | ||
return enabled && onDestroy && onDestroy(_this3.state); | ||
}); | ||
}; | ||
return Popper; | ||
}(); | ||
export { Popper as default }; |
@@ -1,21 +0,37 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
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 | ||
// 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] : null; // Flow doesn't support to extend this property, but it's the most | ||
// effective way to apply styles to an HTMLElemen | ||
// $FlowIgnore | ||
Object.assign(state.elements[name].style, style); | ||
}); | ||
return state; | ||
export 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; | ||
} | ||
exports.applyStyles = applyStyles; | ||
exports["default"] = { | ||
name: 'applyStyles', | ||
enabled: true, | ||
phase: 'write', | ||
fn: applyStyles, | ||
requires: ['computeStyles'] | ||
}; | ||
export 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); | ||
}); | ||
} | ||
export default { | ||
name: 'applyStyles', | ||
enabled: true, | ||
phase: 'write', | ||
fn: applyStyles, | ||
onDestroy: onDestroy, | ||
requires: ['computeStyles'] | ||
}; |
@@ -1,69 +0,75 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
// This modifier takes the Popper.js state and prepares some StyleSheet properties | ||
// that can be applied to the popper element to make it render in the expected position. | ||
exports.mapStrategyToPosition = function (strategy) { | ||
switch (strategy) { | ||
case 'fixed': | ||
return 'fixed'; | ||
case 'absolute': | ||
default: | ||
return 'absolute'; | ||
} | ||
export var mapStrategyToPosition = function mapStrategyToPosition(strategy) { | ||
switch (strategy) { | ||
case 'fixed': | ||
return 'fixed'; | ||
case 'absolute': | ||
default: | ||
return 'absolute'; | ||
} | ||
}; | ||
exports.computePopperStyles = function (_a) { | ||
var offsets = _a.offsets, strategy = _a.strategy, gpuAcceleration = _a.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: exports.mapStrategyToPosition(strategy) | ||
}; | ||
} | ||
else { | ||
return { | ||
transform: "translate3d(" + offsets.x + "px, " + offsets.y + "px, 0)", | ||
position: exports.mapStrategyToPosition(strategy) | ||
}; | ||
} | ||
export 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) | ||
}; | ||
} | ||
}; | ||
exports.computeArrowStyles = function (_a) { | ||
var offsets = _a.offsets, gpuAcceleration = _a.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' | ||
}; | ||
} | ||
export 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) { | ||
var gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
state.styles = {}; // popper offsets are always available | ||
state.styles.popper = exports.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 = exports.computeArrowStyles({ | ||
offsets: state.offsets.arrow, | ||
gpuAcceleration: gpuAcceleration | ||
}); | ||
} | ||
return state; | ||
export function computeStyles(state, options) { | ||
var gpuAcceleration = options && options.gpuAcceleration != null ? options.gpuAcceleration : true; | ||
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; | ||
} | ||
exports.computeStyles = computeStyles; | ||
exports["default"] = { | ||
name: 'computeStyles', | ||
enabled: true, | ||
phase: 'afterMain', | ||
fn: computeStyles | ||
}; | ||
export default { | ||
name: 'computeStyles', | ||
enabled: true, | ||
phase: 'afterMain', | ||
fn: computeStyles | ||
}; |
@@ -1,72 +0,52 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) | ||
symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); | ||
keys.push.apply(keys, symbols); | ||
} return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); | ||
} | ||
else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} | ||
else { | ||
ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); | ||
} | ||
} return target; } | ||
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; } | ||
var getBoundingClientRect_1 = require("../dom-utils/getBoundingClientRect"); | ||
var getClippingParent_1 = require("../dom-utils/getClippingParent"); | ||
var getDocumentRect_1 = require("../dom-utils/getDocumentRect"); | ||
var computeOffsets_1 = require("../utils/computeOffsets"); | ||
var rectToClientRect_1 = require("../utils/rectToClientRect"); | ||
function detectOverflow(state, options) { | ||
if (options === void 0) { options = { | ||
boundaryElement: getClippingParent_1["default"](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('PopperJS: "detectOverflow" can accept as `boundaryElement` only a parent node of the provided popper.'); | ||
return state; | ||
} | ||
var boundaryClientRect = documentElement === options.boundaryElement ? rectToClientRect_1["default"](getDocumentRect_1["default"](documentElement)) : getBoundingClientRect_1["default"](options.boundaryElement); | ||
var referenceClientRect = getBoundingClientRect_1["default"](referenceElement); | ||
var popperOffsets = computeOffsets_1["default"]({ | ||
reference: referenceClientRect, | ||
element: popperRect, | ||
strategy: 'absolute', | ||
placement: state.options.placement, | ||
scroll: { | ||
scrollTop: 0, | ||
scrollLeft: 0 | ||
} | ||
}); | ||
var popperClientRect = rectToClientRect_1["default"](_objectSpread({}, 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 | ||
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 computeOffsets from '../utils/computeOffsets'; | ||
import rectToClientRect from '../utils/rectToClientRect'; | ||
export 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('PopperJS: "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.options.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; | ||
} | ||
exports.detectOverflow = detectOverflow; | ||
exports["default"] = { | ||
name: 'detectOverflow', | ||
enabled: true, | ||
phase: 'read', | ||
fn: detectOverflow, | ||
data: {} | ||
}; | ||
export default { | ||
name: 'detectOverflow', | ||
enabled: true, | ||
phase: 'read', | ||
fn: detectOverflow, | ||
data: {} | ||
}; |
@@ -1,48 +0,27 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) | ||
symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); | ||
keys.push.apply(keys, symbols); | ||
} return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); | ||
} | ||
else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} | ||
else { | ||
ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); | ||
} | ||
} return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { | ||
Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); | ||
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 getOppositePlacement from '../utils/getOppositePlacement'; | ||
import getBasePlacement from '../utils/getBasePlacement'; | ||
export function flip(state, options) { | ||
var placement = state.placement; | ||
var behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement(placement)]; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var flippedPlacement = behavior.find(function (newPlacement) { | ||
return overflow[getBasePlacement(newPlacement)] <= 0; | ||
}); | ||
if (flippedPlacement && flippedPlacement !== placement) { | ||
state = _extends({}, state, { | ||
placement: flippedPlacement, | ||
reset: true | ||
}); | ||
} | ||
return state; | ||
} | ||
else { | ||
obj[key] = value; | ||
} return obj; } | ||
var getOppositePlacement_1 = require("../utils/getOppositePlacement"); | ||
var getBasePlacement_1 = require("../utils/getBasePlacement"); | ||
function flip(state, options) { | ||
var placement = state.placement; | ||
var behavior = options && options.behavior ? options.behavior : [state.options.placement, getOppositePlacement_1["default"](placement)]; | ||
var overflow = state.modifiersData.detectOverflow; | ||
var flippedPlacement = behavior.find(function (newPlacement) { return overflow[getBasePlacement_1["default"](newPlacement)] <= 0; }); | ||
if (flippedPlacement && flippedPlacement !== placement) { | ||
state = _objectSpread({}, state, { | ||
placement: flippedPlacement, | ||
reset: true | ||
}); | ||
} | ||
return state; | ||
} | ||
exports.flip = flip; | ||
exports["default"] = { | ||
name: 'flip', | ||
enabled: true, | ||
phase: 'main', | ||
fn: flip | ||
}; | ||
export default { | ||
name: 'flip', | ||
enabled: true, | ||
phase: 'main', | ||
fn: flip | ||
}; |
@@ -1,12 +0,6 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var detectOverflow_1 = require("./detectOverflow"); | ||
exports.detectOverflow = detectOverflow_1["default"]; | ||
var computeStyles_1 = require("./computeStyles"); | ||
exports.computeStyles = computeStyles_1["default"]; | ||
var applyStyles_1 = require("./applyStyles"); | ||
exports.applyStyles = applyStyles_1["default"]; | ||
var offset_1 = require("./offset"); | ||
exports.offset = offset_1["default"]; | ||
var flip_1 = require("./flip"); | ||
exports.flip = flip_1["default"]; | ||
export { default as detectOverflow } from './detectOverflow'; | ||
export { default as computeStyles } from './computeStyles'; | ||
export { default as applyStyles } from './applyStyles'; | ||
export { default as offset } from './offset'; | ||
export { default as flip } from './flip'; | ||
export { default as preventOverflow } from './preventOverflow'; |
@@ -1,54 +0,36 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) | ||
symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); | ||
keys.push.apply(keys, symbols); | ||
} return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); | ||
} | ||
else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} | ||
else { | ||
ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); | ||
} | ||
} return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { | ||
Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); | ||
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'; | ||
export 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]; | ||
} | ||
else { | ||
obj[key] = value; | ||
} return obj; } | ||
var getBasePlacement_1 = require("../utils/getBasePlacement"); | ||
function distanceAndSkiddingToXY(placement, measures, getOffsets) { | ||
var basePlacement = getBasePlacement_1["default"](placement); | ||
var invertDistance = ['left', 'top'].includes(basePlacement) ? -1 : 1; | ||
var invertSkidding = ['top', 'bottom'].includes(basePlacement) ? -1 : 1; | ||
var _a = getOffsets(_objectSpread({}, measures, { | ||
placement: placement | ||
})), distance = _a[0], skidding = _a[1]; | ||
distance = (distance || 0) * invertDistance; | ||
skidding = (distance || 0) * invertSkidding; | ||
return ['left', 'right'].includes(basePlacement) ? [distance, skidding] : [skidding, distance]; | ||
export 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; | ||
} | ||
exports.distanceAndSkiddingToXY = distanceAndSkiddingToXY; | ||
function offset(state, options) { | ||
if (options && typeof options.offset === 'function') { | ||
var _a = distanceAndSkiddingToXY(state.placement, state.measures, options.offset), x = _a[0], y = _a[1]; | ||
state.offsets.popper.x += x; | ||
state.offsets.popper.y += y; | ||
} | ||
return state; | ||
} | ||
exports.offset = offset; | ||
exports["default"] = { | ||
name: 'offset', | ||
enabled: true, | ||
phase: 'main', | ||
fn: offset | ||
}; | ||
export default { | ||
name: 'offset', | ||
enabled: true, | ||
phase: 'main', | ||
fn: offset | ||
}; |
@@ -1,61 +0,75 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var getBasePlacement_1 = require("./getBasePlacement"); | ||
var getVariationPlacement_1 = require("./getVariationPlacement"); | ||
var getMainAxisFromPlacement_1 = require("./getMainAxisFromPlacement"); | ||
var getAltAxis_1 = require("./getAltAxis"); | ||
var enums_1 = require("../enums"); | ||
exports["default"] = (function (_a) { | ||
var reference = _a.reference, element = _a.element, strategy = _a.strategy, placement = _a.placement, scroll = _a.scroll; | ||
var basePlacement = placement ? getBasePlacement_1["default"](placement) : null; | ||
var variationPlacement = placement ? getVariationPlacement_1["default"](placement) : null; | ||
var scrollTop = scroll.scrollTop, scrollLeft = scroll.scrollLeft; | ||
var offsets; | ||
switch (basePlacement) { | ||
case enums_1.top: | ||
offsets = { | ||
x: reference.x + reference.width / 2 - element.width / 2 - scrollLeft, | ||
y: reference.y - element.height - scrollTop | ||
}; | ||
break; | ||
case enums_1.bottom: | ||
offsets = { | ||
x: reference.x + reference.width / 2 - element.width / 2 - scrollLeft, | ||
y: reference.y + reference.height - scrollTop | ||
}; | ||
break; | ||
case enums_1.right: | ||
offsets = { | ||
x: reference.x + reference.width - scrollLeft, | ||
y: reference.y + reference.height / 2 - element.height / 2 - scrollTop | ||
}; | ||
break; | ||
case enums_1.left: | ||
offsets = { | ||
x: reference.x - element.width - scrollLeft, | ||
y: reference.y + reference.height / 2 - element.height / 2 - scrollTop | ||
}; | ||
break; | ||
default: | ||
offsets = { | ||
x: reference.x - scrollLeft, | ||
y: reference.y - scrollTop | ||
}; | ||
import getBasePlacement from './getBasePlacement'; | ||
import getVariationPlacement from './getVariationPlacement'; | ||
import getMainAxisFromPlacement from './getMainAxisFromPlacement'; | ||
import getAltAxis from './getAltAxis'; | ||
import getAltLen from './getAltLen'; | ||
import { top, right, bottom, left, start, end } from '../enums'; | ||
export default (function (_ref) { | ||
var reference = _ref.reference, | ||
element = _ref.element, | ||
strategy = _ref.strategy, | ||
placement = _ref.placement, | ||
scroll = _ref.scroll; | ||
var basePlacement = placement ? getBasePlacement(placement) : null; | ||
var variationPlacement = placement ? getVariationPlacement(placement) : null; | ||
var scrollTop = scroll.scrollTop, | ||
scrollLeft = scroll.scrollLeft; | ||
var offsets; | ||
switch (basePlacement) { | ||
case top: | ||
offsets = { | ||
x: reference.x + reference.width / 2 - element.width / 2 - scrollLeft, | ||
y: reference.y - element.height - scrollTop | ||
}; | ||
break; | ||
case bottom: | ||
offsets = { | ||
x: reference.x + reference.width / 2 - element.width / 2 - scrollLeft, | ||
y: reference.y + reference.height - scrollTop | ||
}; | ||
break; | ||
case right: | ||
offsets = { | ||
x: reference.x + reference.width - scrollLeft, | ||
y: reference.y + reference.height / 2 - element.height / 2 - scrollTop | ||
}; | ||
break; | ||
case left: | ||
offsets = { | ||
x: reference.x - element.width - scrollLeft, | ||
y: reference.y + reference.height / 2 - element.height / 2 - scrollTop | ||
}; | ||
break; | ||
default: | ||
offsets = { | ||
x: reference.x - scrollLeft, | ||
y: reference.y - scrollTop | ||
}; | ||
} | ||
var mainAxis = placement ? getMainAxisFromPlacement(placement) : null; | ||
var altAxis = mainAxis ? getAltAxis(mainAxis) : null; | ||
var len = altAxis === 'x' ? 'width' : 'height'; | ||
var axis = [right, left].includes(basePlacement) ? mainAxis : altAxis; | ||
if (axis != null) { | ||
switch (variationPlacement) { | ||
case start: | ||
offsets[axis] -= element[len] / 2; | ||
break; | ||
case end: | ||
offsets[axis] += element[len] / 2; | ||
break; | ||
default: | ||
} | ||
var mainAxis = placement ? getMainAxisFromPlacement_1["default"](placement) : null; | ||
var altAxis = mainAxis ? getAltAxis_1["default"](mainAxis) : null; | ||
var len = altAxis === 'x' ? 'width' : 'height'; | ||
var axis = [enums_1.right, enums_1.left].includes(basePlacement) ? mainAxis : altAxis; | ||
if (axis != null) { | ||
switch (variationPlacement) { | ||
case enums_1.start: | ||
offsets[axis] -= element[len] / 2; | ||
break; | ||
case enums_1.end: | ||
offsets[axis] += element[len] / 2; | ||
break; | ||
default: | ||
} | ||
} | ||
return offsets; | ||
}); | ||
} | ||
return offsets; | ||
}); |
@@ -1,16 +0,16 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function microtaskDebounce(fn) { | ||
var called = false; | ||
return function () { return new Promise(function (resolve) { | ||
if (called) { | ||
return resolve(); | ||
} | ||
called = true; | ||
Promise.resolve().then(function () { | ||
called = false; | ||
resolve(fn()); | ||
}); | ||
}); }; | ||
} | ||
exports["default"] = microtaskDebounce; | ||
export default function microtaskDebounce(fn) { | ||
var called = false; | ||
return function () { | ||
return new Promise(function (resolve) { | ||
if (called) { | ||
return resolve(); | ||
} | ||
called = true; | ||
Promise.resolve().then(function () { | ||
called = false; | ||
resolve(fn()); | ||
}); | ||
}); | ||
}; | ||
} |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
// Expands the eventListeners value to an object containing the | ||
@@ -10,8 +8,8 @@ // `scroll` and `resize` booleans | ||
// false, false => false, false | ||
exports["default"] = (function (eventListeners) { | ||
var fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
return { | ||
scroll: typeof eventListeners.scroll === 'boolean' ? eventListeners.scroll : fallbackValue, | ||
resize: typeof eventListeners.resize === 'boolean' ? eventListeners.resize : fallbackValue | ||
}; | ||
}); | ||
export default (function (eventListeners) { | ||
var fallbackValue = typeof eventListeners === 'boolean' ? eventListeners : false; | ||
return { | ||
scroll: typeof eventListeners.scroll === 'boolean' ? eventListeners.scroll : fallbackValue, | ||
resize: typeof eventListeners.resize === 'boolean' ? eventListeners.resize : fallbackValue | ||
}; | ||
}); |
@@ -1,9 +0,9 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (str) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return args.slice().reduce(function (p, c) { return p.replace(/%s/, c); }, str); | ||
}); | ||
export default (function (str) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return [].concat(args).reduce(function (p, c) { | ||
return p.replace(/%s/, c); | ||
}, str); | ||
}); |
@@ -1,3 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (axis) { return axis === 'x' ? 'y' : 'x'; }); | ||
export default (function (axis) { | ||
return axis === 'x' ? 'y' : 'x'; | ||
}); |
@@ -1,3 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (len) { return len === 'width' ? 'height' : 'width'; }); | ||
export default (function (len) { | ||
return len === 'width' ? 'height' : 'width'; | ||
}); |
@@ -1,3 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (placement) { return placement.split('-')[0]; }); | ||
export default (function (placement) { | ||
return placement.split('-')[0]; | ||
}); |
@@ -1,3 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (placement) { return ['top', 'bottom'].includes(placement) ? 'x' : 'y'; }); | ||
export default (function (placement) { | ||
return ['top', 'bottom'].includes(placement) ? 'x' : 'y'; | ||
}); |
@@ -1,9 +0,11 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var hash = { | ||
left: 'right', | ||
right: 'left', | ||
bottom: 'top', | ||
top: 'bottom' | ||
left: 'right', | ||
right: 'left', | ||
bottom: 'top', | ||
top: 'bottom' | ||
}; | ||
exports["default"] = (function (placement) { return placement.replace(/left|right|bottom|top/g, function (matched) { return hash[matched]; }); }); | ||
export default (function (placement) { | ||
return placement.replace(/left|right|bottom|top/g, function (matched) { | ||
return hash[matched]; | ||
}); | ||
}); |
@@ -1,3 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (placement) { return placement.split('-')[1]; }); | ||
export default (function (placement) { | ||
return placement.split('-')[1]; | ||
}); |
@@ -1,32 +0,36 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
// source: https://stackoverflow.com/questions/49875255 | ||
var order = function (modifiers) { | ||
// indexed by name | ||
var mapped = modifiers.reduce(function (mem, i) { | ||
mem[i.name] = i; | ||
return mem; | ||
}, {}); // inherit all dependencies for a given name | ||
var inherited = function (i) { | ||
return mapped[i].requires ? mapped[i].requires.reduce(function (mem, i) { | ||
return mem.concat([i], inherited(i)); | ||
}, []) : []; | ||
}; // order ... | ||
var ordered = modifiers.sort(function (a, b) { | ||
return !!~inherited(b.name).indexOf(a.name) ? -1 : 1; | ||
}); | ||
return ordered; | ||
var order = function order(modifiers) { | ||
// indexed by name | ||
var mapped = modifiers.reduce(function (mem, i) { | ||
mem[i.name] = i; | ||
return mem; | ||
}, {}); // inherit all dependencies for a given name | ||
var inherited = function inherited(i) { | ||
return mapped[i].requires ? mapped[i].requires.reduce(function (mem, i) { | ||
return [].concat(mem, [i], inherited(i)); | ||
}, []) : []; | ||
}; // order ... | ||
var ordered = modifiers.sort(function (a, b) { | ||
return !!~inherited(b.name).indexOf(a.name) ? -1 : 1; | ||
}); | ||
return ordered; | ||
}; | ||
exports["default"] = (function (modifiers) { return order(modifiers.filter(function (_a) { | ||
var phase = _a.phase; | ||
export default (function (modifiers) { | ||
return [].concat(order(modifiers.filter(function (_ref) { | ||
var phase = _ref.phase; | ||
return phase === 'read'; | ||
})).concat(order(modifiers.filter(function (_a) { | ||
var phase = _a.phase; | ||
})), order(modifiers.filter(function (_ref2) { | ||
var phase = _ref2.phase; | ||
return phase === 'main'; | ||
})), order(modifiers.filter(function (_a) { | ||
var phase = _a.phase; | ||
})), order(modifiers.filter(function (_ref3) { | ||
var phase = _ref3.phase; | ||
return phase === 'afterMain'; | ||
})), order(modifiers.filter(function (_a) { | ||
var phase = _a.phase; | ||
})), order(modifiers.filter(function (_ref4) { | ||
var phase = _ref4.phase; | ||
return phase === 'write'; | ||
}))); }); | ||
}))); | ||
}); |
@@ -1,28 +0,5 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) | ||
symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); | ||
keys.push.apply(keys, symbols); | ||
} return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); | ||
} | ||
else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} | ||
else { | ||
ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); | ||
} | ||
} return target; } | ||
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; } | ||
exports["default"] = (function (rect) { return _objectSpread({}, rect, { | ||
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, { | ||
left: rect.x, | ||
@@ -32,2 +9,3 @@ top: rect.y, | ||
bottom: rect.y + rect.height | ||
}); }); | ||
}); | ||
}); |
@@ -1,3 +0,3 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = (function (element) { return element && element.jquery ? element[0] : element; }); | ||
export default (function (element) { | ||
return element && element.jquery ? element[0] : element; | ||
}); |
@@ -1,47 +0,59 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var format_1 = require("./format"); | ||
var enums_1 = require("../enums"); | ||
import format from './format'; | ||
import { read, main, write } from '../enums'; | ||
var ERROR_MESSAGE = 'PopperJS: modifier "%s" provided an invalid %s property, expected %s but got %s'; | ||
var VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'onLoad', 'requires', 'options']; | ||
exports["default"] = (function (modifiers) { | ||
modifiers.forEach(function (modifier) { | ||
Object.keys(modifier).forEach(function (key) { | ||
switch (key) { | ||
case 'name': | ||
if (typeof modifier.name !== 'string') { | ||
console.error(format_1["default"](ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\"")); | ||
} | ||
break; | ||
case 'enabled': | ||
if (typeof modifier.enabled !== 'boolean') { | ||
console.error(format_1["default"](ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\"")); | ||
} | ||
case 'phase': | ||
if (![enums_1.read, enums_1.main, enums_1.write].includes(modifier.phase)) { | ||
console.error(format_1["default"](ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', "\"" + String(modifier.phase) + "\"")); | ||
} | ||
break; | ||
case 'fn': | ||
if (typeof modifier.fn !== 'function') { | ||
console.error(format_1["default"](ERROR_MESSAGE, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
break; | ||
case 'onLoad': | ||
if (typeof modifier.onLoad !== 'function') { | ||
console.error(format_1["default"](ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
break; | ||
case 'requires': | ||
if (!Array.isArray(modifier.requires)) { | ||
console.error(format_1["default"](ERROR_MESSAGE, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\"")); | ||
} | ||
break; | ||
case 'options': | ||
break; | ||
default: | ||
console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) { return "\"" + s + "\""; }).join(', ') + "; but \"" + key + "\" was provided."); | ||
} | ||
}); | ||
export default (function (modifiers) { | ||
modifiers.forEach(function (modifier) { | ||
Object.keys(modifier).forEach(function (key) { | ||
switch (key) { | ||
case 'name': | ||
if (typeof modifier.name !== 'string') { | ||
console.error(format(ERROR_MESSAGE, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\"")); | ||
} | ||
break; | ||
case 'enabled': | ||
if (typeof modifier.enabled !== 'boolean') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\"")); | ||
} | ||
case 'phase': | ||
if (![read, main, write].includes(modifier.phase)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"phase"', 'either "read", "main" or "write"', "\"" + String(modifier.phase) + "\"")); | ||
} | ||
break; | ||
case 'fn': | ||
if (typeof modifier.fn !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
break; | ||
case 'onLoad': | ||
if (typeof modifier.onLoad !== 'function') { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"onLoad"', '"function"', "\"" + String(modifier.fn) + "\"")); | ||
} | ||
break; | ||
case 'requires': | ||
if (!Array.isArray(modifier.requires)) { | ||
console.error(format(ERROR_MESSAGE, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\"")); | ||
} | ||
break; | ||
case 'options': | ||
break; | ||
default: | ||
console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) { | ||
return "\"" + s + "\""; | ||
}).join(', ') + "; but \"" + key + "\" was provided."); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "@popperjs/core", | ||
"version": "2.0.0-next.6", | ||
"version": "2.0.0-next.7", | ||
"description": "A kickass library used to manage poppers in web applications", | ||
@@ -35,6 +35,15 @@ "main": "dist/cjs/popper.js", | ||
"babel": { | ||
"presets": [ | ||
[ | ||
"@babel/env", | ||
{ | ||
"loose": true, | ||
"modules": false | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"@babel/plugin-transform-flow-strip-types", | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-proposal-object-rest-spread" | ||
"dev-expression" | ||
], | ||
@@ -57,4 +66,3 @@ "env": { | ||
"@babel/core": "^7.1.5", | ||
"@babel/plugin-proposal-class-properties": "^7.1.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.7.4", | ||
"@babel/plugin-transform-flow-strip-types": "^7.0.0", | ||
@@ -64,2 +72,3 @@ "@babel/preset-env": "^7.1.5", | ||
"babel-jest": "^23.6.0", | ||
"babel-plugin-dev-expression": "^0.2.2", | ||
"concurrently": "^4.0.1", | ||
@@ -66,0 +75,0 @@ "cross-env": "^5.2.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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
430535
101
3271
2