UNPKG

front-ui-admin

Version:

Front UI

1,338 lines (1,171 loc) 440 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["front-ui-admin"] = factory(); else root["front-ui-admin"] = factory(); })((typeof self !== 'undefined' ? self : this), function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "fb15"); /******/ }) /************************************************************************/ /******/ ({ /***/ "00ee": /***/ (function(module, exports, __webpack_require__) { "use strict"; var wellKnownSymbol = __webpack_require__("b622"); var TO_STRING_TAG = wellKnownSymbol('toStringTag'); var test = {}; test[TO_STRING_TAG] = 'z'; module.exports = String(test) === '[object z]'; /***/ }), /***/ "0366": /***/ (function(module, exports, __webpack_require__) { "use strict"; var uncurryThis = __webpack_require__("4625"); var aCallable = __webpack_require__("59ed"); var NATIVE_BIND = __webpack_require__("40d5"); var bind = uncurryThis(uncurryThis.bind); // optional / simple context binding module.exports = function (fn, that) { aCallable(fn); return that === undefined ? fn : NATIVE_BIND ? bind(fn, that) : function (/* ...args */) { return fn.apply(that, arguments); }; }; /***/ }), /***/ "04f8": /***/ (function(module, exports, __webpack_require__) { "use strict"; /* eslint-disable es/no-symbol -- required for testing */ var V8_VERSION = __webpack_require__("1212"); var fails = __webpack_require__("d039"); var globalThis = __webpack_require__("cfe9"); var $String = globalThis.String; // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing module.exports = !!Object.getOwnPropertySymbols && !fails(function () { var symbol = Symbol('symbol detection'); // Chrome 38 Symbol has incorrect toString conversion // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances // nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will, // of course, fail. return !$String(symbol) || !(Object(symbol) instanceof Symbol) || // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances !Symbol.sham && V8_VERSION && V8_VERSION < 41; }); /***/ }), /***/ "06cf": /***/ (function(module, exports, __webpack_require__) { "use strict"; var DESCRIPTORS = __webpack_require__("83ab"); var call = __webpack_require__("c65b"); var propertyIsEnumerableModule = __webpack_require__("d1e7"); var createPropertyDescriptor = __webpack_require__("5c6c"); var toIndexedObject = __webpack_require__("fc6a"); var toPropertyKey = __webpack_require__("a04b"); var hasOwn = __webpack_require__("1a2d"); var IE8_DOM_DEFINE = __webpack_require__("0cfb"); // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; // `Object.getOwnPropertyDescriptor` method // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor exports.f = DESCRIPTORS ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { O = toIndexedObject(O); P = toPropertyKey(P); if (IE8_DOM_DEFINE) try { return $getOwnPropertyDescriptor(O, P); } catch (error) { /* empty */ } if (hasOwn(O, P)) return createPropertyDescriptor(!call(propertyIsEnumerableModule.f, O, P), O[P]); }; /***/ }), /***/ "07fa": /***/ (function(module, exports, __webpack_require__) { "use strict"; var toLength = __webpack_require__("50c4"); // `LengthOfArrayLike` abstract operation // https://tc39.es/ecma262/#sec-lengthofarraylike module.exports = function (obj) { return toLength(obj.length); }; /***/ }), /***/ "0b25": /***/ (function(module, exports, __webpack_require__) { "use strict"; var toIntegerOrInfinity = __webpack_require__("5926"); var toLength = __webpack_require__("50c4"); var $RangeError = RangeError; // `ToIndex` abstract operation // https://tc39.es/ecma262/#sec-toindex module.exports = function (it) { if (it === undefined) return 0; var number = toIntegerOrInfinity(it); var length = toLength(number); if (number !== length) throw new $RangeError('Wrong length or index'); return length; }; /***/ }), /***/ "0cfb": /***/ (function(module, exports, __webpack_require__) { "use strict"; var DESCRIPTORS = __webpack_require__("83ab"); var fails = __webpack_require__("d039"); var createElement = __webpack_require__("cc12"); // Thanks to IE8 for its funny defineProperty module.exports = !DESCRIPTORS && !fails(function () { // eslint-disable-next-line es/no-object-defineproperty -- required for testing return Object.defineProperty(createElement('div'), 'a', { get: function () { return 7; } }).a !== 7; }); /***/ }), /***/ "0d26": /***/ (function(module, exports, __webpack_require__) { "use strict"; var uncurryThis = __webpack_require__("e330"); var $Error = Error; var replace = uncurryThis(''.replace); var TEST = (function (arg) { return String(new $Error(arg).stack); })('zxcasd'); // eslint-disable-next-line redos/no-vulnerable, sonarjs/slow-regex -- safe var V8_OR_CHAKRA_STACK_ENTRY = /\n\s*at [^:]*:[^\n]*/; var IS_V8_OR_CHAKRA_STACK = V8_OR_CHAKRA_STACK_ENTRY.test(TEST); module.exports = function (stack, dropEntries) { if (IS_V8_OR_CHAKRA_STACK && typeof stack == 'string' && !$Error.prepareStackTrace) { while (dropEntries--) stack = replace(stack, V8_OR_CHAKRA_STACK_ENTRY, ''); } return stack; }; /***/ }), /***/ "0d51": /***/ (function(module, exports, __webpack_require__) { "use strict"; var $String = String; module.exports = function (argument) { try { return $String(argument); } catch (error) { return 'Object'; } }; /***/ }), /***/ "0e15": /***/ (function(module, exports, __webpack_require__) { /* eslint-disable no-undefined */ var throttle = __webpack_require__("597f"); /** * Debounce execution of a function. Debouncing, unlike throttling, * guarantees that a function is only executed a single time, either at the * very beginning of a series of calls, or at the very end. * * @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful. * @param {Boolean} [atBegin] Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call. * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset). * @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is, * to `callback` when the debounced-function is executed. * * @return {Function} A new, debounced function. */ module.exports = function ( delay, atBegin, callback ) { return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false); }; /***/ }), /***/ "1212": /***/ (function(module, exports, __webpack_require__) { "use strict"; var globalThis = __webpack_require__("cfe9"); var userAgent = __webpack_require__("b5db"); var process = globalThis.process; var Deno = globalThis.Deno; var versions = process && process.versions || Deno && Deno.version; var v8 = versions && versions.v8; var match, version; if (v8) { match = v8.split('.'); // in old Chrome, versions of V8 isn't V8 = Chrome / 10 // but their correct versions are not interesting for us version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]); } // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0` // so check `userAgent` even if `.v8` exists, but 0 if (!version && userAgent) { match = userAgent.match(/Edge\/(\d+)/); if (!match || match[1] >= 74) { match = userAgent.match(/Chrome\/(\d+)/); if (match) version = +match[1]; } } module.exports = version; /***/ }), /***/ "13d2": /***/ (function(module, exports, __webpack_require__) { "use strict"; var uncurryThis = __webpack_require__("e330"); var fails = __webpack_require__("d039"); var isCallable = __webpack_require__("1626"); var hasOwn = __webpack_require__("1a2d"); var DESCRIPTORS = __webpack_require__("83ab"); var CONFIGURABLE_FUNCTION_NAME = __webpack_require__("5e77").CONFIGURABLE; var inspectSource = __webpack_require__("8925"); var InternalStateModule = __webpack_require__("69f3"); var enforceInternalState = InternalStateModule.enforce; var getInternalState = InternalStateModule.get; var $String = String; // eslint-disable-next-line es/no-object-defineproperty -- safe var defineProperty = Object.defineProperty; var stringSlice = uncurryThis(''.slice); var replace = uncurryThis(''.replace); var join = uncurryThis([].join); var CONFIGURABLE_LENGTH = DESCRIPTORS && !fails(function () { return defineProperty(function () { /* empty */ }, 'length', { value: 8 }).length !== 8; }); var TEMPLATE = String(String).split('String'); var makeBuiltIn = module.exports = function (value, name, options) { if (stringSlice($String(name), 0, 7) === 'Symbol(') { name = '[' + replace($String(name), /^Symbol\(([^)]*)\).*$/, '$1') + ']'; } if (options && options.getter) name = 'get ' + name; if (options && options.setter) name = 'set ' + name; if (!hasOwn(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) { if (DESCRIPTORS) defineProperty(value, 'name', { value: name, configurable: true }); else value.name = name; } if (CONFIGURABLE_LENGTH && options && hasOwn(options, 'arity') && value.length !== options.arity) { defineProperty(value, 'length', { value: options.arity }); } try { if (options && hasOwn(options, 'constructor') && options.constructor) { if (DESCRIPTORS) defineProperty(value, 'prototype', { writable: false }); // in V8 ~ Chrome 53, prototypes of some methods, like `Array.prototype.values`, are non-writable } else if (value.prototype) value.prototype = undefined; } catch (error) { /* empty */ } var state = enforceInternalState(value); if (!hasOwn(state, 'source')) { state.source = join(TEMPLATE, typeof name == 'string' ? name : ''); } return value; }; // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative // eslint-disable-next-line no-extend-native -- required Function.prototype.toString = makeBuiltIn(function toString() { return isCallable(this) && getInternalState(this).source || inspectSource(this); }, 'toString'); /***/ }), /***/ "13d5": /***/ (function(module, exports, __webpack_require__) { "use strict"; var $ = __webpack_require__("23e7"); var $reduce = __webpack_require__("d58f").left; var arrayMethodIsStrict = __webpack_require__("a640"); var CHROME_VERSION = __webpack_require__("1212"); var IS_NODE = __webpack_require__("9adc"); // Chrome 80-82 has a critical bug // https://bugs.chromium.org/p/chromium/issues/detail?id=1049982 var CHROME_BUG = !IS_NODE && CHROME_VERSION > 79 && CHROME_VERSION < 83; var FORCED = CHROME_BUG || !arrayMethodIsStrict('reduce'); // `Array.prototype.reduce` method // https://tc39.es/ecma262/#sec-array.prototype.reduce $({ target: 'Array', proto: true, forced: FORCED }, { reduce: function reduce(callbackfn /* , initialValue */) { var length = arguments.length; return $reduce(this, callbackfn, length, length > 1 ? arguments[1] : undefined); } }); /***/ }), /***/ "14d9": /***/ (function(module, exports, __webpack_require__) { "use strict"; var $ = __webpack_require__("23e7"); var toObject = __webpack_require__("7b0b"); var lengthOfArrayLike = __webpack_require__("07fa"); var setArrayLength = __webpack_require__("3a34"); var doesNotExceedSafeInteger = __webpack_require__("3511"); var fails = __webpack_require__("d039"); var INCORRECT_TO_LENGTH = fails(function () { return [].push.call({ length: 0x100000000 }, 1) !== 4294967297; }); // V8 <= 121 and Safari <= 15.4; FF < 23 throws InternalError // https://bugs.chromium.org/p/v8/issues/detail?id=12681 var properErrorOnNonWritableLength = function () { try { // eslint-disable-next-line es/no-object-defineproperty -- safe Object.defineProperty([], 'length', { writable: false }).push(); } catch (error) { return error instanceof TypeError; } }; var FORCED = INCORRECT_TO_LENGTH || !properErrorOnNonWritableLength(); // `Array.prototype.push` method // https://tc39.es/ecma262/#sec-array.prototype.push $({ target: 'Array', proto: true, arity: 1, forced: FORCED }, { // eslint-disable-next-line no-unused-vars -- required for `.length` push: function push(item) { var O = toObject(this); var len = lengthOfArrayLike(O); var argCount = arguments.length; doesNotExceedSafeInteger(len + argCount); for (var i = 0; i < argCount; i++) { O[len] = arguments[i]; len++; } setArrayLength(O, len); return len; } }); /***/ }), /***/ "1626": /***/ (function(module, exports, __webpack_require__) { "use strict"; // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot var documentAll = typeof document == 'object' && document.all; // `IsCallable` abstract operation // https://tc39.es/ecma262/#sec-iscallable // eslint-disable-next-line unicorn/no-typeof-undefined -- required for testing module.exports = typeof documentAll == 'undefined' && documentAll !== undefined ? function (argument) { return typeof argument == 'function' || argument === documentAll; } : function (argument) { return typeof argument == 'function'; }; /***/ }), /***/ "16d2": /***/ (function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;__webpack_require__("d9e2"); __webpack_require__("e9f5"); __webpack_require__("910d"); __webpack_require__("7d54"); __webpack_require__("ab43"); /** * @fileOverview Kickass library to create and place poppers near their reference elements. * @version {{version}} * @license * Copyright (c) 2016 Federico Zivolo and contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ // // Cross module loader // Supported: Node, AMD, Browser globals // (function (root, factory) { if (true) { // AMD. Register as an anonymous module. !(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else {} })(this, function () { 'use strict'; var root = window; // default options var DEFAULTS = { // placement of the popper placement: 'bottom', gpuAcceleration: true, // shift popper from its origin by the given amount of pixels (can be negative) offset: 0, // the element which will act as boundary of the popper boundariesElement: 'viewport', // amount of pixel used to define a minimum distance between the boundaries and the popper boundariesPadding: 5, // popper will try to prevent overflow following this order, // by default, then, it could overflow on the left and on top of the boundariesElement preventOverflowOrder: ['left', 'right', 'top', 'bottom'], // the behavior used by flip to change the placement of the popper flipBehavior: 'flip', arrowElement: '[x-arrow]', arrowOffset: 0, // list of functions used to modify the offsets before they are applied to the popper modifiers: ['shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle'], modifiersIgnored: [], forceAbsolute: false }; /** * Create a new Popper.js instance * @constructor Popper * @param {HTMLElement} reference - The reference element used to position the popper * @param {HTMLElement|Object} popper * The HTML element used as popper, or a configuration used to generate the popper. * @param {String} [popper.tagName='div'] The tag name of the generated popper. * @param {Array} [popper.classNames=['popper']] Array of classes to apply to the generated popper. * @param {Array} [popper.attributes] Array of attributes to apply, specify `attr:value` to assign a value to it. * @param {HTMLElement|String} [popper.parent=window.document.body] The parent element, given as HTMLElement or as query string. * @param {String} [popper.content=''] The content of the popper, it can be text, html, or node; if it is not text, set `contentType` to `html` or `node`. * @param {String} [popper.contentType='text'] If `html`, the `content` will be parsed as HTML. If `node`, it will be appended as-is. * @param {String} [popper.arrowTagName='div'] Same as `popper.tagName` but for the arrow element. * @param {Array} [popper.arrowClassNames='popper__arrow'] Same as `popper.classNames` but for the arrow element. * @param {String} [popper.arrowAttributes=['x-arrow']] Same as `popper.attributes` but for the arrow element. * @param {Object} options * @param {String} [options.placement=bottom] * Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -right), * left(-start, -end)` * * @param {HTMLElement|String} [options.arrowElement='[x-arrow]'] * The DOM Node used as arrow for the popper, or a CSS selector used to get the DOM node. It must be child of * its parent Popper. Popper.js will apply to the given element the style required to align the arrow with its * reference element. * By default, it will look for a child node of the popper with the `x-arrow` attribute. * * @param {Boolean} [options.gpuAcceleration=true] * When this property is set to true, the popper position will be applied using CSS3 translate3d, allowing the * browser to use the GPU to accelerate the rendering. * If set to false, the popper will be placed using `top` and `left` properties, not using the GPU. * * @param {Number} [options.offset=0] * Amount of pixels the popper will be shifted (can be negative). * * @param {String|Element} [options.boundariesElement='viewport'] * The element which will define the boundaries of the popper position, the popper will never be placed outside * of the defined boundaries (except if `keepTogether` is enabled) * * @param {Number} [options.boundariesPadding=5] * Additional padding for the boundaries * * @param {Array} [options.preventOverflowOrder=['left', 'right', 'top', 'bottom']] * Order used when Popper.js tries to avoid overflows from the boundaries, they will be checked in order, * this means that the last ones will never overflow * * @param {String|Array} [options.flipBehavior='flip'] * The behavior used by the `flip` modifier to change the placement of the popper when the latter is trying to * overlap its reference element. Defining `flip` as value, the placement will be flipped on * its axis (`right - left`, `top - bottom`). * You can even pass an array of placements (eg: `['right', 'left', 'top']` ) to manually specify * how alter the placement when a flip is needed. (eg. in the above example, it would first flip from right to left, * then, if even in its new placement, the popper is overlapping its reference element, it will be moved to top) * * @param {Array} [options.modifiers=[ 'shift', 'offset', 'preventOverflow', 'keepTogether', 'arrow', 'flip', 'applyStyle']] * List of functions used to modify the data before they are applied to the popper, add your custom functions * to this array to edit the offsets and placement. * The function should reflect the @params and @returns of preventOverflow * * @param {Array} [options.modifiersIgnored=[]] * Put here any built-in modifier name you want to exclude from the modifiers list * The function should reflect the @params and @returns of preventOverflow * * @param {Boolean} [options.removeOnDestroy=false] * Set to true if you want to automatically remove the popper when you call the `destroy` method. */ function Popper(reference, popper, options) { this._reference = reference.jquery ? reference[0] : reference; this.state = {}; // if the popper variable is a configuration object, parse it to generate an HTMLElement // generate a default popper if is not defined var isNotDefined = typeof popper === 'undefined' || popper === null; var isConfig = popper && Object.prototype.toString.call(popper) === '[object Object]'; if (isNotDefined || isConfig) { this._popper = this.parse(isConfig ? popper : {}); } // otherwise, use the given HTMLElement as popper else { this._popper = popper.jquery ? popper[0] : popper; } // with {} we create a new object with the options inside it this._options = Object.assign({}, DEFAULTS, options); // refactoring modifiers' list this._options.modifiers = this._options.modifiers.map(function (modifier) { // remove ignored modifiers if (this._options.modifiersIgnored.indexOf(modifier) !== -1) return; // set the x-placement attribute before everything else because it could be used to add margins to the popper // margins needs to be calculated to get the correct popper offsets if (modifier === 'applyStyle') { this._popper.setAttribute('x-placement', this._options.placement); } // return predefined modifier identified by string or keep the custom one return this.modifiers[modifier] || modifier; }.bind(this)); // make sure to apply the popper position before any computation this.state.position = this._getPosition(this._popper, this._reference); setStyle(this._popper, { position: this.state.position, top: 0 }); // fire the first update to position the popper in the right place this.update(); // setup event listeners, they will take care of update the position in specific situations this._setupEventListeners(); return this; } // // Methods // /** * Destroy the popper * @method * @memberof Popper */ Popper.prototype.destroy = function () { this._popper.removeAttribute('x-placement'); this._popper.style.left = ''; this._popper.style.position = ''; this._popper.style.top = ''; this._popper.style[getSupportedPropertyName('transform')] = ''; this._removeEventListeners(); // remove the popper if user explicity asked for the deletion on destroy if (this._options.removeOnDestroy) { this._popper.remove(); } return this; }; /** * Updates the position of the popper, computing the new offsets and applying the new style * @method * @memberof Popper */ Popper.prototype.update = function () { var data = { instance: this, styles: {} }; // store placement inside the data object, modifiers will be able to edit `placement` if needed // and refer to _originalPlacement to know the original value data.placement = this._options.placement; data._originalPlacement = this._options.placement; // compute the popper and reference offsets and put them inside data.offsets data.offsets = this._getOffsets(this._popper, this._reference, data.placement); // get boundaries data.boundaries = this._getBoundaries(data, this._options.boundariesPadding, this._options.boundariesElement); data = this.runModifiers(data, this._options.modifiers); if (typeof this.state.updateCallback === 'function') { this.state.updateCallback(data); } }; /** * If a function is passed, it will be executed after the initialization of popper with as first argument the Popper instance. * @method * @memberof Popper * @param {Function} callback */ Popper.prototype.onCreate = function (callback) { // the createCallbacks return as first argument the popper instance callback(this); return this; }; /** * If a function is passed, it will be executed after each update of popper with as first argument the set of coordinates and informations * used to style popper and its arrow. * NOTE: it doesn't get fired on the first call of the `Popper.update()` method inside the `Popper` constructor! * @method * @memberof Popper * @param {Function} callback */ Popper.prototype.onUpdate = function (callback) { this.state.updateCallback = callback; return this; }; /** * Helper used to generate poppers from a configuration file * @method * @memberof Popper * @param config {Object} configuration * @returns {HTMLElement} popper */ Popper.prototype.parse = function (config) { var defaultConfig = { tagName: 'div', classNames: ['popper'], attributes: [], parent: root.document.body, content: '', contentType: 'text', arrowTagName: 'div', arrowClassNames: ['popper__arrow'], arrowAttributes: ['x-arrow'] }; config = Object.assign({}, defaultConfig, config); var d = root.document; var popper = d.createElement(config.tagName); addClassNames(popper, config.classNames); addAttributes(popper, config.attributes); if (config.contentType === 'node') { popper.appendChild(config.content.jquery ? config.content[0] : config.content); } else if (config.contentType === 'html') { popper.innerHTML = config.content; } else { popper.textContent = config.content; } if (config.arrowTagName) { var arrow = d.createElement(config.arrowTagName); addClassNames(arrow, config.arrowClassNames); addAttributes(arrow, config.arrowAttributes); popper.appendChild(arrow); } var parent = config.parent.jquery ? config.parent[0] : config.parent; // if the given parent is a string, use it to match an element // if more than one element is matched, the first one will be used as parent // if no elements are matched, the script will throw an error if (typeof parent === 'string') { parent = d.querySelectorAll(config.parent); if (parent.length > 1) { console.warn('WARNING: the given `parent` query(' + config.parent + ') matched more than one element, the first one will be used'); } if (parent.length === 0) { throw "ERROR: the given `parent` doesn't exists!"; } parent = parent[0]; } // if the given parent is a DOM nodes list or an array of nodes with more than one element, // the first one will be used as parent if (parent.length > 1 && parent instanceof Element === false) { console.warn('WARNING: you have passed as parent a list of elements, the first one will be used'); parent = parent[0]; } // append the generated popper to its parent parent.appendChild(popper); return popper; /** * Adds class names to the given element * @function * @ignore * @param {HTMLElement} target * @param {Array} classes */ function addClassNames(element, classNames) { classNames.forEach(function (className) { element.classList.add(className); }); } /** * Adds attributes to the given element * @function * @ignore * @param {HTMLElement} target * @param {Array} attributes * @example * addAttributes(element, [ 'data-info:foobar' ]); */ function addAttributes(element, attributes) { attributes.forEach(function (attribute) { element.setAttribute(attribute.split(':')[0], attribute.split(':')[1] || ''); }); } }; /** * Helper used to get the position which will be applied to the popper * @method * @memberof Popper * @param config {HTMLElement} popper element * @param reference {HTMLElement} reference element * @returns {String} position */ Popper.prototype._getPosition = function (popper, reference) { var container = getOffsetParent(reference); if (this._options.forceAbsolute) { return 'absolute'; } // Decide if the popper will be fixed // If the reference element is inside a fixed context, the popper will be fixed as well to allow them to scroll together var isParentFixed = isFixed(reference, container); return isParentFixed ? 'fixed' : 'absolute'; }; /** * Get offsets to the popper * @method * @memberof Popper * @access private * @param {Element} popper - the popper element * @param {Element} reference - the reference element (the popper will be relative to this) * @returns {Object} An object containing the offsets which will be applied to the popper */ Popper.prototype._getOffsets = function (popper, reference, placement) { placement = placement.split('-')[0]; var popperOffsets = {}; popperOffsets.position = this.state.position; var isParentFixed = popperOffsets.position === 'fixed'; // // Get reference element position // var referenceOffsets = getOffsetRectRelativeToCustomParent(reference, getOffsetParent(popper), isParentFixed); // // Get popper sizes // var popperRect = getOuterSizes(popper); // // Compute offsets of popper // // depending by the popper placement we have to compute its offsets slightly differently if (['right', 'left'].indexOf(placement) !== -1) { popperOffsets.top = referenceOffsets.top + referenceOffsets.height / 2 - popperRect.height / 2; if (placement === 'left') { popperOffsets.left = referenceOffsets.left - popperRect.width; } else { popperOffsets.left = referenceOffsets.right; } } else { popperOffsets.left = referenceOffsets.left + referenceOffsets.width / 2 - popperRect.width / 2; if (placement === 'top') { popperOffsets.top = referenceOffsets.top - popperRect.height; } else { popperOffsets.top = referenceOffsets.bottom; } } // Add width and height to our offsets object popperOffsets.width = popperRect.width; popperOffsets.height = popperRect.height; return { popper: popperOffsets, reference: referenceOffsets }; }; /** * Setup needed event listeners used to update the popper position * @method * @memberof Popper * @access private */ Popper.prototype._setupEventListeners = function () { // NOTE: 1 DOM access here this.state.updateBound = this.update.bind(this); root.addEventListener('resize', this.state.updateBound); // if the boundariesElement is window we don't need to listen for the scroll event if (this._options.boundariesElement !== 'window') { var target = getScrollParent(this._reference); // here it could be both `body` or `documentElement` thanks to Firefox, we then check both if (target === root.document.body || target === root.document.documentElement) { target = root; } target.addEventListener('scroll', this.state.updateBound); this.state.scrollTarget = target; } }; /** * Remove event listeners used to update the popper position * @method * @memberof Popper * @access private */ Popper.prototype._removeEventListeners = function () { // NOTE: 1 DOM access here root.removeEventListener('resize', this.state.updateBound); if (this._options.boundariesElement !== 'window' && this.state.scrollTarget) { this.state.scrollTarget.removeEventListener('scroll', this.state.updateBound); this.state.scrollTarget = null; } this.state.updateBound = null; }; /** * Computed the boundaries limits and return them * @method * @memberof Popper * @access private * @param {Object} data - Object containing the property "offsets" generated by `_getOffsets` * @param {Number} padding - Boundaries padding * @param {Element} boundariesElement - Element used to define the boundaries * @returns {Object} Coordinates of the boundaries */ Popper.prototype._getBoundaries = function (data, padding, boundariesElement) { // NOTE: 1 DOM access here var boundaries = {}; var width, height; if (boundariesElement === 'window') { var body = root.document.body, html = root.document.documentElement; height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth); boundaries = { top: 0, right: width, bottom: height, left: 0 }; } else if (boundariesElement === 'viewport') { var offsetParent = getOffsetParent(this._popper); var scrollParent = getScrollParent(this._popper); var offsetParentRect = getOffsetRect(offsetParent); // Thanks the fucking native API, `document.body.scrollTop` & `document.documentElement.scrollTop` var getScrollTopValue = function (element) { return element == document.body ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : element.scrollTop; }; var getScrollLeftValue = function (element) { return element == document.body ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : element.scrollLeft; }; // if the popper is fixed we don't have to substract scrolling from the boundaries var scrollTop = data.offsets.popper.position === 'fixed' ? 0 : getScrollTopValue(scrollParent); var scrollLeft = data.offsets.popper.position === 'fixed' ? 0 : getScrollLeftValue(scrollParent); boundaries = { top: 0 - (offsetParentRect.top - scrollTop), right: root.document.documentElement.clientWidth - (offsetParentRect.left - scrollLeft), bottom: root.document.documentElement.clientHeight - (offsetParentRect.top - scrollTop), left: 0 - (offsetParentRect.left - scrollLeft) }; } else { if (getOffsetParent(this._popper) === boundariesElement) { boundaries = { top: 0, left: 0, right: boundariesElement.clientWidth, bottom: boundariesElement.clientHeight }; } else { boundaries = getOffsetRect(boundariesElement); } } boundaries.left += padding; boundaries.right -= padding; boundaries.top = boundaries.top + padding; boundaries.bottom = boundaries.bottom - padding; return boundaries; }; /** * Loop trough the list of modifiers and run them in order, each of them will then edit the data object * @method * @memberof Popper * @access public * @param {Object} data * @param {Array} modifiers * @param {Function} ends */ Popper.prototype.runModifiers = function (data, modifiers, ends) { var modifiersToRun = modifiers.slice(); if (ends !== undefined) { modifiersToRun = this._options.modifiers.slice(0, getArrayKeyIndex(this._options.modifiers, ends)); } modifiersToRun.forEach(function (modifier) { if (isFunction(modifier)) { data = modifier.call(this, data); } }.bind(this)); return data; }; /** * Helper used to know if the given modifier depends from another one. * @method * @memberof Popper * @param {String} requesting - name of requesting modifier * @param {String} requested - name of requested modifier * @returns {Boolean} */ Popper.prototype.isModifierRequired = function (requesting, requested) { var index = getArrayKeyIndex(this._options.modifiers, requesting); return !!this._options.modifiers.slice(0, index).filter(function (modifier) { return modifier === requested; }).length; }; // // Modifiers // /** * Modifiers list * @namespace Popper.modifiers * @memberof Popper * @type {Object} */ Popper.prototype.modifiers = {}; /** * Apply the computed styles to the popper element * @method * @memberof Popper.modifiers * @argument {Object} data - The data object generated by `update` method * @returns {Object} The same data object */ Popper.prototype.modifiers.applyStyle = function (data) { // apply the final offsets to the popper // NOTE: 1 DOM access here var styles = { position: data.offsets.popper.position }; // round top and left to avoid blurry text var left = Math.round(data.offsets.popper.left); var top = Math.round(data.offsets.popper.top); // if gpuAcceleration is set to true and transform is supported, we use `translate3d` to apply the position to the popper // we automatically use the supported prefixed version if needed var prefixedProperty; if (this._options.gpuAcceleration && (prefixedProperty = getSupportedPropertyName('transform'))) { styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)'; styles.top = 0; styles.left = 0; } // othwerise, we use the standard `left` and `top` properties else { styles.left = left; styles.top = top; } // any property present in `data.styles` will be applied to the popper, // in this way we can make the 3rd party modifiers add custom styles to it // Be aware, modifiers could override the properties defined in the previous // lines of this modifier! Object.assign(styles, data.styles); setStyle(this._popper, styles); // set an attribute which will be useful to style the tooltip (use it to properly position its arrow) // NOTE: 1 DOM access here this._popper.setAttribute('x-placement', data.placement); // if the arrow modifier is required and the arrow style has been computed, apply the arrow style if (this.isModifierRequired(this.modifiers.applyStyle, this.modifiers.arrow) && data.offsets.arrow) { setStyle(data.arrowElement, data.offsets.arrow); } return data; }; /** * Modifier used to shift the popper on the start or end of its reference element side * @method * @memberof Popper.modifiers * @argument {Object} data - The data object generated by `update` method * @returns {Object} The data object, properly modified */ Popper.prototype.modifiers.shift = function (data) { var placement = data.placement; var basePlacement = placement.split('-')[0]; var shiftVariation = placement.split('-')[1]; // if shift shiftVariation is specified, run the modifier if (shiftVariation) { var reference = data.offsets.reference; var popper = getPopperClientRect(data.offsets.popper); var shiftOffsets = { y: { start: { top: reference.top }, end: { top: reference.top + reference.height - popper.height } }, x: { start: { left: reference.left }, end: { left: reference.left + reference.width - popper.width } } }; var axis = ['bottom', 'top'].indexOf(basePlacement) !== -1 ? 'x' : 'y'; data.offsets.popper = Object.assign(popper, shiftOffsets[axis][shiftVariation]); } return data; }; /** * Modifier used to make sure the popper does not overflows from it's boundaries * @method * @memberof Popper.modifiers * @argument {Object} data - The data object generated by `update` method * @returns {Object} The data object, properly modified */ Popper.prototype.modifiers.preventOverflow = function (data) { var order = this._options.preventOverflowOrder; var popper = getPopperClientRect(data.offsets.popper); var check = { left: function () { var left = popper.left; if (popper.left < data.boundaries.left) { left = Math.max(popper.left, data.boundaries.left); } return { left: left }; }, right: function () { var left = popper.left; if (popper.right > data.boundaries.right) { left = Math.min(popper.left, data.boundaries.right - popper.width); } return { left: left }; }, top: function () { var top = popper.top; if (popper.top < data.boundaries.top) { top = Math.max(popper.top, data.boundaries.top); } return { top: top }; }, bottom: function () { var top = popper.top; if (popper.bottom > data.boundaries.bottom) { top = Math.min(popper.top, data.boundaries.bottom - popper.height); } return { top: top }; } }; order.forEach(function (direction) { data.offsets.popper = Object.assign(popper, check[direction]()); }); return data; }; /** * Modifier used to make sure the popper is always near its reference * @method * @memberof Popper.modifiers * @argument {Object} data - The data object generated by _update method * @returns {Object} The data object, properly modified */ Popper.prototype.modifiers.keepTogether = function (data) { var popper = getPopperClientRect(data.offsets.popper); var reference = data.offsets.reference; var f = Math.floor; if (popper.right < f(reference.left)) { data.offsets.popper.left = f(reference.left) - popper.width; } if (popper.left > f(reference.right)) { data.offsets.popper.left = f(reference.right); } if (popper.bottom < f(reference.top)) { data.offsets.popper.top = f(reference.top) - popper.height; } if (popper.top > f(reference.bottom)) { data.offsets.popper.top = f(reference.bottom); } return data; }; /** * Modifier used to flip the placement of the popper when the latter is starting overlapping its reference element. * Requires the `preventOverflow` modifier before it in order to work. * **NOTE:** This modifier will run all its previous modifiers everytime it tries to flip the popper! * @method * @memberof Popper.modifiers * @argument {Object} data - The data object generated by _update method * @returns {Object} The data object, properly modified */ Popper.prototype.modifiers.flip = function (data) { // check if preventOverflow is in the list of modifiers before the flip modifier. // otherwise flip would not work as expected. if (!this.isModifierRequired(this.modifiers.flip, this.modifiers.preventOverflow)) { console.warn('WARNING: preventOverflow modifier is required by flip modifier in order to work, be sure to include it before flip!'); return data; } if (data.flipped && data.placement === data._originalPlacement) { // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides return data; } var placement = data.placement.split('-')[0]; var placementOpposite = getOppositePlacement(placement); var variation = data.placement.split('-')[1] || ''; var flipOrder = []; if (this._options.flipBehavior === 'flip') { flipOrder = [placement, placementOpposite]; } else { flipOrder = this._options.flipBehavior; } flipOrder.forEach(function (step, index) { if (placement !== step || flipOrder.length === index + 1) { return; } placement = data.placement.split('-')[0]; placementOpposite = getOppositePlacement(placement); var popperOffsets = getPopperClientRect(data.offsets.popper); // this boolean is used to distinguish right and bottom from top and left // they need different computations to get flipped var a = ['right', 'bottom'].indexOf(placement) !== -1; // using Math.floor because the reference offsets may contain decimals we are not going to consider here if (a && Math.floor(data.offsets.reference[placement]) > Math.floor(popperOffsets[placementOpposite]) || !a && Math.floor(data.offsets.reference[placement]) < Math.floor(popperOffsets[placementOpposite])) { // we'll use this boolean to detect any flip loop data.flipped = true; data.placement = flipOrder[index + 1]; if (variation) { data.placement += '-' + variation; } data.offsets.popper = this._getOffsets(this._popper, this._reference, data.placement).popper; data = this.runModifiers(data, this._options.modifiers, this._flip); } }.bind(this)); return data; }; /** * Modifier used to add an offset to the popper, useful if you more granularity positioning your popper. * The offsets will shift the popper on the side of its reference element. * @method * @memberof Popper.modifiers * @argument {Object} data - The data object generated by _update method * @returns {Object} T